@@ -22,6 +22,33 @@ async function readJSON( filename ) {
2222 return JSON . parse ( await read ( filename ) ) ;
2323}
2424
25+ async function getOutputRollupOptions ( {
26+ esm = false
27+ } = { } ) {
28+ const wrapperFilePath = path . join ( "src" , `wrapper${
29+ esm ? "-esm" : ""
30+ } .js` ) ;
31+
32+ const wrapperSource = await read ( wrapperFilePath ) ;
33+
34+ // Catch `// @CODE` and subsequent comment lines event if they don't start
35+ // in the first column.
36+ const wrapper = wrapperSource . split (
37+ / [ \x20 \t ] * \/ \/ @ C O D E \n (?: [ \x20 \t ] * \/ \/ [ ^ \n ] + \n ) * /
38+ ) ;
39+
40+ return {
41+
42+ // The ESM format is not actually used as we strip it during the
43+ // build, inserting our own wrappers; it's just that it doesn't
44+ // generate any extra wrappers so there's nothing for us to remove.
45+ format : "esm" ,
46+
47+ intro : wrapper [ 0 ] . replace ( / \n * $ / , "" ) ,
48+ outro : wrapper [ 1 ] . replace ( / ^ \n * / , "" )
49+ } ;
50+ }
51+
2552async function writeCompiled ( { code, dir, filename, version } ) {
2653 const compiledContents = code
2754
@@ -34,12 +61,12 @@ async function writeCompiled( { code, dir, filename, version } ) {
3461
3562 await writeFile ( path . join ( dir , filename ) , compiledContents ) ;
3663 console . log ( `[${ getTimestamp ( ) } ] ${ filename } v${ version } created.` ) ;
37- await minify ( { dir, filename, version } ) ;
3864}
3965
4066export async function build ( {
4167 dir = "dist" ,
4268 filename = "jquery-migrate.js" ,
69+ esm = false ,
4370 watch = false ,
4471 version
4572} = { } ) {
@@ -59,24 +86,8 @@ export async function build( {
5986 } `;
6087 }
6188
62- // Catch `// @CODE` and subsequent comment lines event if they don't start
63- // in the first column.
64- const wrapperSrc = await read ( "src/wrapper.js" ) ;
65- const wrapper = wrapperSrc . split (
66- / [ \x20 \t ] * \/ \/ @ C O D E \n (?: [ \x20 \t ] * \/ \/ [ ^ \n ] + \n ) * /
67- ) ;
68-
6989 const inputRollupOptions = { } ;
70- const outputRollupOptions = {
71-
72- // The ESM format is not actually used as we strip it during
73- // the build; it's just that it doesn't generate any extra
74- // wrappers so there's nothing for us to remove.
75- format : "esm" ,
76-
77- intro : wrapper [ 0 ] . replace ( / \n * $ / , "" ) ,
78- outro : wrapper [ 1 ] . replace ( / ^ \n * / , "" )
79- } ;
90+ const outputRollupOptions = await getOutputRollupOptions ( { esm } ) ;
8091 const src = "src/migrate.js" ;
8192
8293 inputRollupOptions . input = path . resolve ( src ) ;
@@ -122,9 +133,33 @@ export async function build( {
122133 } = await bundle . generate ( outputRollupOptions ) ;
123134
124135 await writeCompiled ( { code, dir, filename, version } ) ;
136+ await minify ( { dir, filename, version } ) ;
137+ }
138+ }
125139
140+ export async function buildDefaultFiles ( {
141+ version = process . env . VERSION ,
142+ watch
143+ } = { } ) {
144+ await Promise . all ( [
145+ build ( { version, watch } ) ,
146+ build ( {
147+ dir : "dist-module" ,
148+ filename : "jquery-migrate.module.js" ,
149+ esm : true ,
150+ version,
151+ watch
152+ } )
153+ ] ) ;
154+
155+ if ( watch ) {
156+ console . log ( "Watching files..." ) ;
157+ } else {
126158 return compareSize ( {
127- files : [ "dist/jquery-migrate.min.js" ]
159+ files : [
160+ "dist/jquery-migrate.min.js" ,
161+ "dist-module/jquery-migrate.module.min.js"
162+ ]
128163 } ) ;
129164 }
130165}
0 commit comments