Skip to content

Commit eb64b5a

Browse files
authored
Release: Build both script & module files on release, fix the map file
Previously, only script files - the ones in `dist` - were generated during the release, and the module ones - in `dist-module` - were not generated. Also, the CDN folder was only populated with script files, now module ones are also added. In addition to that, the map file had incorrect file references. All those issues are now fixed. Closes gh-613 Ref gh-614
1 parent a223f8a commit eb64b5a

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

build/release.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import child from "node:child_process";
1212
import path from "node:path";
1313
import chalk from "chalk";
1414
import enquirer from "enquirer";
15-
import { build } from "./tasks/build.js";
15+
import { buildDefaultFiles } from "./tasks/build.js";
1616

1717
var releaseVersion,
1818
nextVersion,
@@ -33,7 +33,8 @@ var releaseVersion,
3333
versionFile = path.join( "src", "version.js" ),
3434

3535
releaseDir = "CDN",
36-
distDir = "dist";
36+
distDir = "dist",
37+
distModuleDir = "dist-module";
3738

3839
steps(
3940
initialize,
@@ -160,7 +161,7 @@ function updateVersions( next ) {
160161
}
161162

162163
async function buildRelease( next ) {
163-
await build( { version: releaseVersion } );
164+
await buildDefaultFiles( { version: releaseVersion } );
164165
next();
165166
}
166167

@@ -174,11 +175,16 @@ function makeReleaseCopies( next ) {
174175
var releaseFiles = {
175176
"jquery-migrate-VER.js": passThrough,
176177
"jquery-migrate-VER.min.js": fixMinRef,
177-
"jquery-migrate-VER.min.map": fixMapRef
178+
"jquery-migrate-VER.min.map": fixMapRef,
179+
"jquery-migrate-VER.module.js": passThrough,
180+
"jquery-migrate-VER.module.min.js": fixMinRef,
181+
"jquery-migrate-VER.module.min.map": fixMapRef
178182
};
179183
Object.keys( releaseFiles ).forEach( function( key ) {
180184
var distFile = key.replace( /-VER/g, "" ),
181-
distPath = path.join( distDir, distFile ),
185+
distPath = distFile.includes( ".module." ) ?
186+
path.join( distModuleDir, distFile ) :
187+
path.join( distDir, distFile ),
182188
releaseFile = key.replace( /VER/g, releaseVersion ),
183189
releasePath = path.join( releaseDir, releaseFile );
184190

@@ -314,7 +320,7 @@ function writeJsonSync( fname, json ) {
314320
}
315321

316322
function fixMinRef( oldText ) {
317-
var mapRef = new RegExp( "^//# sourceMappingURL=jquery-migrate.min.map\\n?", "m" );
323+
var mapRef = new RegExp( "^//# sourceMappingURL=jquery-migrate\\..*\\.map\\n?", "m" );
318324

319325
// Remove the ref for now rather than try to fix it
320326
var newText = oldText.replace( mapRef, "" );
@@ -327,13 +333,21 @@ function fixMinRef( oldText ) {
327333
function fixMapRef( oldText, newFile ) {
328334
var mapJSON = JSON.parse( oldText );
329335
var sources = mapJSON.sources;
330-
if ( sources.join() !== "../src/migratemute.js,jquery-migrate.js" ) {
336+
if ( sources.join() !== "../src/migratemute.js,jquery-migrate.js" &&
337+
sources.join() !== "../src/migratemute.js,jquery-migrate.module.js" ) {
331338
throw Error( "fixMapRef: Unexpected sources entry: " + sources );
332339
}
333340

334341
// This file isn't published, not sure the best way to deal with that
335342
sources[ 0 ] = "migratemute.js";
336-
sources[ 1 ] = newFile.replace( /\.map$/, ".js" );
343+
sources[ 1 ] = newFile.replace( /\.min\.map$/, ".js" );
344+
345+
// Path to the minified file for which this is the map.
346+
// The minified file is originally created from a versionless file,
347+
// so this field needs to be regenerated to contain the version
348+
// if `newFile` contains it.
349+
mapJSON.file = newFile.replace( /\.min\.map$/, ".min.js" );
350+
337351
return JSON.stringify( mapJSON );
338352
}
339353

0 commit comments

Comments
 (0)