Skip to content

Commit c29e540

Browse files
authored
Release: Bump version in package-lock.json as well during the release
Also: * make argument parsing more resilient to different orders * catch pre-release versions when updating README * die on unrecognized parameters Closes gh-603
1 parent 9b39c2e commit c29e540

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

build/release.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,32 @@ steps(
5252
);
5353

5454
function initialize( next ) {
55+
var param;
5556

5657
// -d dryrun mode, no commands are executed at all
57-
if ( process.argv[ 2 ] === "-d" ) {
58-
process.argv.shift();
58+
if ( process.argv.includes( "-d" ) ) {
59+
process.argv.splice( process.argv.indexOf( "-d" ), 1 );
5960
dryrun = true;
6061
console.warn( "=== DRY RUN MODE ===" );
6162
}
6263

6364
// -r skip remote mode, no remote commands are executed
6465
// (git push, npm publish, cdn copy)
6566
// Reset with `git reset --hard HEAD~2 && git tag -d (version) && npm run build`
66-
if ( process.argv[ 2 ] === "-r" ) {
67-
process.argv.shift();
67+
if ( process.argv.includes( "-r" ) ) {
68+
process.argv.splice( process.argv.indexOf( "-r" ), 1 );
6869
skipRemote = true;
6970
console.warn( "=== SKIPREMOTE MODE ===" );
7071
}
7172

73+
param = process.argv.find( function( arg ) {
74+
return arg[ 0 ] === "-";
75+
} );
76+
77+
if ( param ) {
78+
die( "Unrecognized parameter: " + param );
79+
}
80+
7281
// First arg should be the version number being released; this is a proper subset
7382
// of a full semver, see https://github.com/mojombo/semver/issues/32
7483
// Examples: 1.0.1, 1.0.1-pre, 1.0.1-rc1, 1.0.1-rc1.1
@@ -147,8 +156,7 @@ function tagReleaseVersion( next ) {
147156
function updateVersions( next ) {
148157
updateSourceVersion( releaseVersion );
149158
updateReadmeVersion( releaseVersion );
150-
updatePackageVersion( releaseVersion );
151-
next();
159+
updatePackageVersion( releaseVersion, undefined, next );
152160
}
153161

154162
async function buildRelease( next ) {
@@ -211,9 +219,12 @@ async function publishToNPM( next ) {
211219

212220
function setNextVersion( next ) {
213221
updateSourceVersion( nextVersion );
214-
updatePackageVersion( nextVersion, "main" );
215-
git( [ "commit", "-a", "--no-verify", "-m", "Updating the source version to " + nextVersion ],
216-
next );
222+
updatePackageVersion( nextVersion, "main", function() {
223+
git(
224+
[ "commit", "-a", "--no-verify",
225+
"-m", "Updating the source version to " + nextVersion ],
226+
next );
227+
} );
217228
}
218229

219230
function pushToRemote( next ) {
@@ -244,12 +255,22 @@ function steps() {
244255
} )();
245256
}
246257

247-
function updatePackageVersion( ver, blobVer ) {
258+
function updatePackageVersion( ver, blobVer, next ) {
248259
status( "Updating " + packageFile + " version to " + ver );
249260
blobVer = blobVer || ver;
250-
pkg.version = ver;
251261
pkg.author.url = setBlobVersion( pkg.author.url, blobVer );
252262
writeJsonSync( packageFile, pkg );
263+
child.execFile( "npm", [
264+
"version",
265+
ver,
266+
"--no-git-tag-version"
267+
], function( error, stdout ) {
268+
if ( error ) {
269+
throw error;
270+
}
271+
console.log( stdout );
272+
next();
273+
} );
253274
}
254275

255276
function updateSourceVersion( ver ) {
@@ -271,7 +292,7 @@ function updateReadmeVersion() {
271292
} else {
272293
status( "Updating " + readmeFile );
273294
readme = readme.replace(
274-
/jquery-migrate-\d+\.\d+\.\d+(?:-\w+)?/g,
295+
/jquery-migrate-\d+\.\d+\.\d+(?:-\w+\.\d+)?/g,
275296
"jquery-migrate-" + releaseVersion
276297
);
277298
if ( !dryrun ) {

0 commit comments

Comments
 (0)