@@ -10,7 +10,7 @@ module.exports = function( grunt ) {
1010 const fs = require ( "fs" ) ;
1111 const path = require ( "path" ) ;
1212 const rollup = require ( "rollup" ) ;
13- const rollupHypothetical = require ( "rollup-plugin-hypothetical " ) ;
13+ const rollupFileOverrides = require ( "./lib/ rollup-plugin-file-overrides " ) ;
1414 const Insight = require ( "insight" ) ;
1515 const pkg = require ( "../../package.json" ) ;
1616 const srcFolder = path . resolve ( `${ __dirname } /../../src` ) ;
@@ -39,10 +39,18 @@ module.exports = function( grunt ) {
3939 outro : wrapper [ 1 ]
4040 . replace ( / ^ \n * / , "" )
4141 } ;
42- const rollupHypotheticalOptions = {
43- allowFallthrough : true ,
44- files : { }
45- } ;
42+ const fileOverrides = new Map ( ) ;
43+
44+ function getOverride ( filePath ) {
45+ return fileOverrides . get ( path . resolve ( filePath ) ) ;
46+ }
47+
48+ function setOverride ( filePath , source ) {
49+
50+ // We want normalized paths in overrides as they will be matched
51+ // against normalized paths in the file overrides Rollup plugin.
52+ fileOverrides . set ( path . resolve ( filePath ) , source ) ;
53+ }
4654
4755 grunt . registerMultiTask (
4856 "build" ,
@@ -186,14 +194,14 @@ module.exports = function( grunt ) {
186194
187195 // Remove the jQuery export from the entry file, we'll use our own
188196 // custom wrapper.
189- rollupHypotheticalOptions . files [ inputRollupOptions . input ] = read ( inputFileName )
190- . replace ( / \n * e x p o r t d e f a u l t j Q u e r y ; \n * / , "\n" ) ;
197+ setOverride ( inputRollupOptions . input ,
198+ read ( inputFileName ) . replace ( / \n * e x p o r t d e f a u l t j Q u e r y ; \n * / , "\n" ) ) ;
191199
192200 // Replace exports/global with a noop noConflict
193201 if ( ( index = excluded . indexOf ( "exports/global" ) ) > - 1 ) {
194- rollupHypotheticalOptions . files [ `${ srcFolder } /exports/global.js` ] =
202+ setOverride ( `${ srcFolder } /exports/global.js` ,
195203 "import jQuery from \"../core.js\";\n\n" +
196- "jQuery.noConflict = function() {};" ;
204+ "jQuery.noConflict = function() {};" ) ;
197205 excluded . splice ( index , 1 ) ;
198206 }
199207
@@ -207,9 +215,10 @@ module.exports = function( grunt ) {
207215 }
208216
209217 // Remove the comma for anonymous defines
210- rollupHypotheticalOptions . files [ `${ srcFolder } /exports/amd.js` ] =
218+ setOverride ( `${ srcFolder } /exports/amd.js` ,
211219 read ( "exports/amd.js" )
212- . replace ( / ( \s * ) " j q u e r y " ( \, \s * ) / , amdName ? "$1\"" + amdName + "\"$2" : "" ) ;
220+ . replace ( / ( \s * ) " j q u e r y " ( \, \s * ) / ,
221+ amdName ? "$1\"" + amdName + "\"$2" : "" ) ) ;
213222 }
214223
215224 grunt . verbose . writeflags ( excluded , "Excluded" ) ;
@@ -225,7 +234,7 @@ module.exports = function( grunt ) {
225234
226235 // Replace excluded modules with empty sources.
227236 for ( const module of excluded ) {
228- rollupHypotheticalOptions . files [ `${ srcFolder } /${ module } .js` ] = "" ;
237+ setOverride ( `${ srcFolder } /${ module } .js` , "" ) ;
229238 }
230239 }
231240
@@ -234,20 +243,21 @@ module.exports = function( grunt ) {
234243
235244 // Remove the default inclusions, they will be overwritten with the explicitly
236245 // included ones.
237- rollupHypotheticalOptions . files [ inputRollupOptions . input ] = "" ;
246+ setOverride ( inputRollupOptions . input , "" ) ;
238247
239248 }
240249
241250 // Import the explicitly included modules.
242251 if ( included . length ) {
243- rollupHypotheticalOptions . files [ inputRollupOptions . input ] += included
244- . map ( module => `import "./${ module } .js";` )
245- . join ( "\n" ) ;
252+ setOverride ( inputRollupOptions . input ,
253+ getOverride ( inputRollupOptions . input ) + included
254+ . map ( module => `import "./${ module } .js";` )
255+ . join ( "\n" ) ) ;
246256 }
247257
248258 const bundle = await rollup . rollup ( {
249259 ...inputRollupOptions ,
250- plugins : [ rollupHypothetical ( rollupHypotheticalOptions ) ]
260+ plugins : [ rollupFileOverrides ( fileOverrides ) ]
251261 } ) ;
252262
253263 const { output : [ { code } ] } = await bundle . generate ( outputRollupOptions ) ;
0 commit comments