Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fd2fa5

Browse files
authored
Build: Fix the Windows build
This commit gets rid of rollup-plugin-hypothetical in favor of a simplerinline Rollup plugin that fits our need and is compatible with Windows.Fixesgh-4548Closesgh-4549
1 parent44ac8c8 commit9fd2fa5

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

‎build/tasks/build.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function( grunt ) {
1010
constfs=require("fs");
1111
constpath=require("path");
1212
constrollup=require("rollup");
13-
constrollupHypothetical=require("rollup-plugin-hypothetical");
13+
constrollupFileOverrides=require("./lib/rollup-plugin-file-overrides");
1414
constInsight=require("insight");
1515
constpkg=require("../../package.json");
1616
constsrcFolder=path.resolve(`${__dirname}/../../src`);
@@ -39,10 +39,18 @@ module.exports = function( grunt ) {
3939
outro:wrapper[1]
4040
.replace(/^\n*/,"")
4141
};
42-
constrollupHypotheticalOptions={
43-
allowFallthrough:true,
44-
files:{}
45-
};
42+
constfileOverrides=newMap();
43+
44+
functiongetOverride(filePath){
45+
returnfileOverrides.get(path.resolve(filePath));
46+
}
47+
48+
functionsetOverride(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*exportdefaultjQuery;\n*/,"\n");
197+
setOverride(inputRollupOptions.input,
198+
read(inputFileName).replace(/\n*exportdefaultjQuery;\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*)"jquery"(\,\s*)/,amdName ?"$1\""+amdName+"\"$2" :"");
220+
.replace(/(\s*)"jquery"(\,\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(constmoduleofexcluded){
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
constbundle=awaitrollup.rollup({
249259
...inputRollupOptions,
250-
plugins:[rollupHypothetical(rollupHypotheticalOptions)]
260+
plugins:[rollupFileOverrides(fileOverrides)]
251261
});
252262

253263
const{output:[{ code}]}=awaitbundle.generate(outputRollupOptions);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
3+
/**
4+
* A Rollup plugin accepting a file overrides map and changing
5+
* module sources to the overridden ones where provided. Files
6+
* without overrides are loaded from disk.
7+
*
8+
*@param {Map<string, string>} fileOverrides
9+
*/
10+
module.exports=(fileOverrides)=>{
11+
return{
12+
name:"jquery-file-overrides",
13+
load(id){
14+
if(fileOverrides.has(id)){
15+
16+
// Replace the module by a fake source.
17+
returnfileOverrides.get(id);
18+
}
19+
20+
// Handle this module via the file system.
21+
returnnull;
22+
}
23+
};
24+
};

‎package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"raw-body":"2.3.3",
6262
"requirejs":"2.3.6",
6363
"rollup":"1.25.2",
64-
"rollup-plugin-hypothetical":"2.1.0",
6564
"sinon":"7.3.1",
6665
"strip-json-comments":"2.0.1",
6766
"testswarm":"1.1.0",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp