requirejs-esm 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -4
- package/dist/api.js +30 -27
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +97 -62
- package/dist/plugin.js.map +1 -1
- package/package.json +26 -24
package/dist/plugin.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
2
|
typeof define === 'function' && define.amd ? define([
|
|
4
3
|
//>>excludeStart('excludeEsm', pragmas.excludeEsm)
|
|
5
4
|
'module'
|
|
6
5
|
//>>excludeEnd('excludeEsm')
|
|
7
6
|
], factory) :
|
|
7
|
+
//>>excludeStart('excludeEsm', pragmas.excludeEsm)
|
|
8
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
9
|
+
//>>excludeEnd('excludeEsm')
|
|
8
10
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.requirejsEsmPlugin = factory());
|
|
9
11
|
})(this, (function (
|
|
10
12
|
//>>excludeStart('excludeEsm', pragmas.excludeEsm)
|
|
@@ -66,23 +68,18 @@
|
|
|
66
68
|
|
|
67
69
|
var writeText$1 = writeText;
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (const skipModule of skipModules$1) {
|
|
79
|
-
// Recognise an asterisk at the beginning
|
|
80
|
-
if (skipModule.startsWith('*')) {
|
|
81
|
-
if (name.indexOf(skipModule.substring(1)) >= 0) return true
|
|
82
|
-
}
|
|
83
|
-
// Accept a path prefix as well.
|
|
84
|
-
else if (name.startsWith(skipModule)) return true
|
|
71
|
+
// Returns the child file name by cutting the directoris before the last slash,
|
|
72
|
+
// including the slash. If there is no slash in the path - the path is just
|
|
73
|
+
// a file name, it will return the file name. If the path includes a URL
|
|
74
|
+
// query starting with the question mark, it will cut it away including the
|
|
75
|
+
// question mark.
|
|
76
|
+
function childFile (path) {
|
|
77
|
+
const lastSlash = path.lastIndexOf('/');
|
|
78
|
+
if (lastSlash > 0) {
|
|
79
|
+
path = path.substring(lastSlash + 1);
|
|
85
80
|
}
|
|
81
|
+
const questionMark = path.lastIndexOf('?');
|
|
82
|
+
return questionMark > 0 ? path.substring(0, questionMark) : path
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
// Returns the parent directory by cutting the file name after the last slash,
|
|
@@ -132,21 +129,43 @@
|
|
|
132
129
|
|
|
133
130
|
// Ensures that every JavaScript dependency will be prefixed by `esm!`.
|
|
134
131
|
// Relative paths will be converted to be relative to the parent module.
|
|
135
|
-
function resolvePath$1 (sourcePath, currentFile, { pluginName }) {
|
|
132
|
+
function resolvePath$1 (sourcePath, currentFile, { pluginName, needsResolve } = {}) {
|
|
136
133
|
// Ignore paths with other plugins applied and the three built-in
|
|
137
134
|
// pseudo-modules of RequireJS.
|
|
138
|
-
if (
|
|
135
|
+
if (sourcePath.includes('!') || sourcePath === 'require' ||
|
|
139
136
|
sourcePath === 'module' || sourcePath === 'exports') return
|
|
140
137
|
|
|
141
138
|
// If `sourcePath` is relative to `currentFile` - starts with ./ or ../ -
|
|
142
139
|
// prepend the parent directory of `currentFile` to it. This was needed
|
|
143
140
|
// for modules located outside the source root (`baseUrl`), which were
|
|
144
141
|
// mapped there using the `paths` of `map` configuration properties.
|
|
145
|
-
if (sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
|
|
146
|
-
|
|
142
|
+
if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
|
|
143
|
+
sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
|
|
144
|
+
!(needsResolve && needsResolve(sourcePath, currentFile))) {
|
|
147
145
|
sourcePath = joinPath(parentDir(currentFile), sourcePath);
|
|
146
|
+
if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return pluginName ? `${pluginName}!${sourcePath}` : sourcePath
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let skipModules$1 = [];
|
|
153
|
+
|
|
154
|
+
function setSkipModules(names) {
|
|
155
|
+
skipModules$1 = names;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Checks if a module name is included in the list of modules to skip
|
|
159
|
+
// the transformation.
|
|
160
|
+
function skipModule(name) {
|
|
161
|
+
for (const skipModule of skipModules$1) {
|
|
162
|
+
// Recognise an asterisk at the beginning
|
|
163
|
+
if (skipModule.startsWith('*')) {
|
|
164
|
+
if (name.indexOf(skipModule.substring(1)) >= 0) return true
|
|
165
|
+
}
|
|
166
|
+
// Accept a path prefix as well.
|
|
167
|
+
else if (name.startsWith(skipModule)) return true
|
|
148
168
|
}
|
|
149
|
-
return `${pluginName}!${sourcePath}`
|
|
150
169
|
}
|
|
151
170
|
|
|
152
171
|
const errorMessages = {
|
|
@@ -1023,9 +1042,9 @@
|
|
|
1023
1042
|
mask |= 8;
|
|
1024
1043
|
break;
|
|
1025
1044
|
case 115:
|
|
1026
|
-
if (mask &
|
|
1045
|
+
if (mask & 32)
|
|
1027
1046
|
report(parser, 34, 's');
|
|
1028
|
-
mask |=
|
|
1047
|
+
mask |= 32;
|
|
1029
1048
|
break;
|
|
1030
1049
|
default:
|
|
1031
1050
|
report(parser, 33);
|
|
@@ -1938,7 +1957,7 @@
|
|
|
1938
1957
|
}
|
|
1939
1958
|
else if (ch === 61) {
|
|
1940
1959
|
advanceChar(parser);
|
|
1941
|
-
return
|
|
1960
|
+
return 8456256;
|
|
1942
1961
|
}
|
|
1943
1962
|
if (ch === 33) {
|
|
1944
1963
|
const index = parser.index + 1;
|
|
@@ -2121,7 +2140,7 @@
|
|
|
2121
2140
|
const ch = parser.currentChar;
|
|
2122
2141
|
if (ch === 61) {
|
|
2123
2142
|
advanceChar(parser);
|
|
2124
|
-
return
|
|
2143
|
+
return 8456257;
|
|
2125
2144
|
}
|
|
2126
2145
|
if (ch !== 62)
|
|
2127
2146
|
return 8456259;
|
|
@@ -5113,7 +5132,7 @@
|
|
|
5113
5132
|
nextToken(parser, context | 32768);
|
|
5114
5133
|
const argument = parser.flags & 1 || parser.token & 1048576
|
|
5115
5134
|
? null
|
|
5116
|
-
: parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.
|
|
5135
|
+
: parseExpressions(parser, context, 0, 1, parser.tokenPos, parser.linePos, parser.colPos);
|
|
5117
5136
|
matchOrInsertSemicolon(parser, context | 32768);
|
|
5118
5137
|
return finishNode(parser, context, start, line, column, {
|
|
5119
5138
|
type: 'ReturnStatement',
|
|
@@ -6229,7 +6248,7 @@
|
|
|
6229
6248
|
if ((context & 524288) < 1)
|
|
6230
6249
|
report(parser, 26);
|
|
6231
6250
|
if (context & 16384)
|
|
6232
|
-
report(parser,
|
|
6251
|
+
report(parser, 27);
|
|
6233
6252
|
parser.assignable = 2;
|
|
6234
6253
|
break;
|
|
6235
6254
|
}
|
|
@@ -6238,7 +6257,7 @@
|
|
|
6238
6257
|
if ((context & 262144) < 1)
|
|
6239
6258
|
report(parser, 27);
|
|
6240
6259
|
if (context & 16384)
|
|
6241
|
-
report(parser,
|
|
6260
|
+
report(parser, 27);
|
|
6242
6261
|
parser.assignable = 1;
|
|
6243
6262
|
break;
|
|
6244
6263
|
}
|
|
@@ -6269,10 +6288,10 @@
|
|
|
6269
6288
|
expr = parseUpdateExpression(parser, context, expr, start, line, column);
|
|
6270
6289
|
}
|
|
6271
6290
|
else if ((parser.token & 67108864) === 67108864) {
|
|
6272
|
-
context = (context | 134217728
|
|
6291
|
+
context = (context | 134217728) ^ 134217728;
|
|
6273
6292
|
switch (parser.token) {
|
|
6274
6293
|
case 67108877: {
|
|
6275
|
-
nextToken(parser, context | 1073741824);
|
|
6294
|
+
nextToken(parser, (context | 1073741824 | 8192) ^ 8192);
|
|
6276
6295
|
parser.assignable = 1;
|
|
6277
6296
|
const property = parsePropertyOrPrivatePropertyName(parser, context);
|
|
6278
6297
|
expr = finishNode(parser, context, start, line, column, {
|
|
@@ -6328,7 +6347,7 @@
|
|
|
6328
6347
|
break;
|
|
6329
6348
|
}
|
|
6330
6349
|
case 67108991: {
|
|
6331
|
-
nextToken(parser, context);
|
|
6350
|
+
nextToken(parser, (context | 1073741824 | 8192) ^ 8192);
|
|
6332
6351
|
parser.flags |= 2048;
|
|
6333
6352
|
parser.assignable = 2;
|
|
6334
6353
|
expr = parseOptionalChain(parser, context, expr, start, line, column);
|
|
@@ -8492,12 +8511,10 @@
|
|
|
8492
8511
|
}
|
|
8493
8512
|
else if (context & 1 && parser.token === 131) {
|
|
8494
8513
|
kind |= 4096;
|
|
8495
|
-
key = parsePrivateIdentifier(parser, context, tokenPos, linePos, colPos);
|
|
8496
|
-
context = context | 16384;
|
|
8514
|
+
key = parsePrivateIdentifier(parser, context | 16384, tokenPos, linePos, colPos);
|
|
8497
8515
|
}
|
|
8498
8516
|
else if (context & 1 && (parser.token & 1073741824) === 1073741824) {
|
|
8499
8517
|
kind |= 128;
|
|
8500
|
-
context = context | 16384;
|
|
8501
8518
|
}
|
|
8502
8519
|
else if (token === 122) {
|
|
8503
8520
|
key = parseIdentifier(parser, context, 0);
|
|
@@ -8863,7 +8880,7 @@
|
|
|
8863
8880
|
});
|
|
8864
8881
|
}
|
|
8865
8882
|
function parseJSXExpressionContainer(parser, context, inJSXChild, isAttr, start, line, column) {
|
|
8866
|
-
nextToken(parser, context);
|
|
8883
|
+
nextToken(parser, context | 32768);
|
|
8867
8884
|
const { tokenPos, linePos, colPos } = parser;
|
|
8868
8885
|
if (parser.token === 14)
|
|
8869
8886
|
return parseJSXSpreadChild(parser, context, tokenPos, linePos, colPos);
|
|
@@ -81765,6 +81782,9 @@
|
|
|
81765
81782
|
});
|
|
81766
81783
|
|
|
81767
81784
|
obj[impl][utils$1.wrapperSymbol] = obj;
|
|
81785
|
+
if (Impl.init) {
|
|
81786
|
+
Impl.init(obj[impl], privateData);
|
|
81787
|
+
}
|
|
81768
81788
|
return obj;
|
|
81769
81789
|
},
|
|
81770
81790
|
interface: URLSearchParams,
|
|
@@ -82316,6 +82336,9 @@
|
|
|
82316
82336
|
});
|
|
82317
82337
|
|
|
82318
82338
|
obj[impl][utils$1.wrapperSymbol] = obj;
|
|
82339
|
+
if (Impl.init) {
|
|
82340
|
+
Impl.init(obj[impl], privateData);
|
|
82341
|
+
}
|
|
82319
82342
|
return obj;
|
|
82320
82343
|
},
|
|
82321
82344
|
interface: URL,
|
|
@@ -85261,9 +85284,6 @@
|
|
|
85261
85284
|
|
|
85262
85285
|
// Updates dependency paths to be prefixed by `esm!` or otherwise updated.
|
|
85263
85286
|
function updateAmdDeps(amd, options) {
|
|
85264
|
-
const { resolvePath } = options;
|
|
85265
|
-
if (!resolvePath) return
|
|
85266
|
-
|
|
85267
85287
|
const { deps } = amd;
|
|
85268
85288
|
if (!deps) return
|
|
85269
85289
|
|
|
@@ -85271,6 +85291,7 @@
|
|
|
85271
85291
|
const { elements } = deps;
|
|
85272
85292
|
if (!elements.length) return
|
|
85273
85293
|
|
|
85294
|
+
const { resolvePath } = options;
|
|
85274
85295
|
let updated;
|
|
85275
85296
|
for (const element of elements) {
|
|
85276
85297
|
if (element.type === 'Literal') {
|
|
@@ -85649,11 +85670,8 @@
|
|
|
85649
85670
|
// Update dependency paths to be prefixed by `esm!` or otherwise updated.
|
|
85650
85671
|
function prepareImportPaths(importPaths, options ) {
|
|
85651
85672
|
const { resolvePath } = options;
|
|
85652
|
-
if (!resolvePath) return
|
|
85653
|
-
|
|
85654
85673
|
if (resolvePath) {
|
|
85655
85674
|
const { sourceFileName: parentName } = options;
|
|
85656
|
-
|
|
85657
85675
|
for (const importPath of importPaths) {
|
|
85658
85676
|
if (importPath.type === 'Literal') {
|
|
85659
85677
|
const moduleName = importPath.value;
|
|
@@ -85664,7 +85682,6 @@
|
|
|
85664
85682
|
}
|
|
85665
85683
|
}
|
|
85666
85684
|
}
|
|
85667
|
-
|
|
85668
85685
|
return arrayExpression(importPaths)
|
|
85669
85686
|
}
|
|
85670
85687
|
|
|
@@ -85673,7 +85690,7 @@
|
|
|
85673
85690
|
const { length } = amds;
|
|
85674
85691
|
if (length) {
|
|
85675
85692
|
options.amd = true;
|
|
85676
|
-
if (options.
|
|
85693
|
+
if (options.resolvePath) {
|
|
85677
85694
|
for (const amd of amds) {
|
|
85678
85695
|
options.updated |= updateAmdDeps(amd, options);
|
|
85679
85696
|
}
|
|
@@ -85755,6 +85772,34 @@
|
|
|
85755
85772
|
//>>excludeEnd('excludeEsm')
|
|
85756
85773
|
var plugin = {
|
|
85757
85774
|
load(name, req, onload, reqConfig) {
|
|
85775
|
+
//>>excludeStart('excludeEsm', pragmas.excludeEsm)
|
|
85776
|
+
const { isBuild } = reqConfig;
|
|
85777
|
+
// if (!bundledModules) {
|
|
85778
|
+
// bundledModules = new Set()
|
|
85779
|
+
// const { bundles } = reqConfig
|
|
85780
|
+
// if (bundles) {
|
|
85781
|
+
// verbose && console.log('esm: initialising bundles', name)
|
|
85782
|
+
// for (const bundle in bundles) {
|
|
85783
|
+
// for (const module of bundles[bundle]) {
|
|
85784
|
+
// bundledModules.add(module)
|
|
85785
|
+
// }
|
|
85786
|
+
// }
|
|
85787
|
+
// }
|
|
85788
|
+
// }
|
|
85789
|
+
|
|
85790
|
+
// Paths relative to the current directory include the file extension.
|
|
85791
|
+
// Otherwise the file extension must not be used for JavaScript modules.
|
|
85792
|
+
// The file name should include the orioginal extension in the source maps.
|
|
85793
|
+
const file = name.endsWith(fileExtension) ? name : name + fileExtension;
|
|
85794
|
+
// Compilation and bundling of module sub-trees can be skipped, if those
|
|
85795
|
+
// are mapped to the pseudo-path `empty:`, meaning that those modules
|
|
85796
|
+
// are external and will be loaded during the runtime.
|
|
85797
|
+
const url = req.toUrl(file);
|
|
85798
|
+
if (url.startsWith('empty:')) {
|
|
85799
|
+
verbose && console.log('esm: skipping', name, 'mapped to', url);
|
|
85800
|
+
return onload()
|
|
85801
|
+
}
|
|
85802
|
+
|
|
85758
85803
|
verbose && console.log('esm: loading', name);
|
|
85759
85804
|
// If the module has been already defined from a module bundle, it was
|
|
85760
85805
|
// already transpiled, when the output bundle was written. No need to
|
|
@@ -85769,24 +85814,14 @@
|
|
|
85769
85814
|
// If the whole application is transpiled, there is no need to transpile
|
|
85770
85815
|
// ESM modules or prefix dependencies of AMD modules. Even not yet defined
|
|
85771
85816
|
// modules can be loaded just by `require` to get better performance.
|
|
85772
|
-
if (!mixedAmdAndEsm && !
|
|
85773
|
-
onlyAmd || skipModule(name)
|
|
85817
|
+
if (!mixedAmdAndEsm && !isBuild && req.specified(name) ||
|
|
85818
|
+
/*bundledModules.has(name) ||*/ onlyAmd || skipModule(name) ||
|
|
85819
|
+
// If the module was bundled, it had to be already transpiled.
|
|
85820
|
+
!isBuild && childFile(url) !== childFile(file)) {
|
|
85774
85821
|
verbose && console.log('esm: delegating', name);
|
|
85822
|
+
//>>excludeEnd('excludeEsm')
|
|
85775
85823
|
return req([name], onload, onload.error)
|
|
85776
|
-
}
|
|
85777
85824
|
//>>excludeStart('excludeEsm', pragmas.excludeEsm)
|
|
85778
|
-
|
|
85779
|
-
// Paths relative to the current directory include the file extension.
|
|
85780
|
-
// Otherwise the file extension must not be used for JavaScript modules.
|
|
85781
|
-
// The file name should include the orioginal extension in the source maps.
|
|
85782
|
-
const file = name.endsWith(fileExtension) ? name : name + fileExtension;
|
|
85783
|
-
// Compilation and bundling of module sub-trees can be skipped, if those
|
|
85784
|
-
// are mapped to the pseudo-path `empty:`, meaning that those modules
|
|
85785
|
-
// are external and will be loaded during the runtime.
|
|
85786
|
-
const url = req.toUrl(file);
|
|
85787
|
-
if (url.startsWith('empty:')) {
|
|
85788
|
-
verbose && console.log('esm: skipping', name, 'mapped to', url);
|
|
85789
|
-
return onload()
|
|
85790
85825
|
}
|
|
85791
85826
|
|
|
85792
85827
|
// Fetch the text of the source module by AJAX and transpile it.
|
|
@@ -85807,12 +85842,12 @@
|
|
|
85807
85842
|
// Always produce the source maps when transpiling in the browser, otherwise
|
|
85808
85843
|
// the debugging would me impossible. When building and bundling, check if
|
|
85809
85844
|
// the source maps were enabled for the output.
|
|
85810
|
-
sourceMap: sourceMap || !
|
|
85845
|
+
sourceMap: sourceMap || !isBuild
|
|
85811
85846
|
}));
|
|
85812
85847
|
if (!updated) {
|
|
85813
85848
|
verbose && console.log('esm: retaining', name);
|
|
85814
85849
|
// return req([name], onload, onload.error)
|
|
85815
|
-
} else if (
|
|
85850
|
+
} else if (isBuild && debugDir) {
|
|
85816
85851
|
writeText$1(`${debugDir}/${file}`, code);
|
|
85817
85852
|
}
|
|
85818
85853
|
} catch (error) {
|
|
@@ -85823,7 +85858,7 @@
|
|
|
85823
85858
|
}
|
|
85824
85859
|
|
|
85825
85860
|
// Remember the transpiled content for the writing phase during the build.
|
|
85826
|
-
if (
|
|
85861
|
+
if (isBuild) {
|
|
85827
85862
|
buildMap[name] = code;
|
|
85828
85863
|
}
|
|
85829
85864
|
|