Skip to content

Commit

Permalink
Avoid using a cached version of package.json (#17717)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Oct 4, 2019
1 parent 23a7fc9 commit 251bc5c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions bin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ const success = chalk.bold.green;

// Utils

/**
* Small utility used to read an uncached version of a JSON file
*
* @param {string} fileName
*/
function readJSONFile( fileName ) {
const data = fs.readFileSync( fileName, 'utf8' );
return JSON.parse( data );
}

/**
* Asks the user for a confirmation to continue or abort otherwise
*
Expand Down Expand Up @@ -250,7 +260,7 @@ async function runReleaseBranchCreationStep( abortMessage ) {
await runStep( 'Creating the release branch', abortMessage, async () => {
const simpleGit = SimpleGit( gitWorkingDirectoryPath );
const packageJsonPath = gitWorkingDirectoryPath + '/package.json';
const packageJson = require( packageJsonPath );
const packageJson = readJSONFile( packageJsonPath );
const parsedVersion = semver.parse( packageJson.version );

// Follow the WordPress version guidelines to compute the version to be used
Expand Down Expand Up @@ -294,15 +304,15 @@ async function runReleaseBranchCheckoutStep( abortMessage ) {
await runStep( 'Getting into the release branch', abortMessage, async () => {
const simpleGit = SimpleGit( gitWorkingDirectoryPath );
const packageJsonPath = gitWorkingDirectoryPath + '/package.json';
const masterPackageJson = require( packageJsonPath );
const masterPackageJson = readJSONFile( packageJsonPath );
const masterParsedVersion = semver.parse( masterPackageJson.version );
releaseBranch = 'release/' + masterParsedVersion.major + '.' + masterParsedVersion.minor;

// Creating the release branch
await simpleGit.checkout( releaseBranch );
console.log( '>> The local release branch ' + success( releaseBranch ) + ' has been successfully checked out.' );

const releaseBranchPackageJson = require( packageJsonPath );
const releaseBranchPackageJson = readJSONFile( packageJsonPath );
const releaseBranchParsedVersion = semver.parse( releaseBranchPackageJson.version );

if ( releaseBranchParsedVersion.prerelease && releaseBranchParsedVersion.prerelease.length ) {
Expand Down Expand Up @@ -341,8 +351,8 @@ async function runBumpPluginVersionAndCommitStep( version, abortMessage ) {
const packageJsonPath = gitWorkingDirectoryPath + '/package.json';
const packageLockPath = gitWorkingDirectoryPath + '/package-lock.json';
const pluginFilePath = gitWorkingDirectoryPath + '/gutenberg.php';
const packageJson = require( packageJsonPath );
const packageLock = require( packageLockPath );
const packageJson = readJSONFile( packageJsonPath );
const packageLock = readJSONFile( packageLockPath );
const newPackageJson = {
...packageJson,
version,
Expand Down

0 comments on commit 251bc5c

Please sign in to comment.