requirejs-esm 1.0.0 → 1.0.1
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/dist/api.js +2 -0
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +69 -35
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -149,6 +146,25 @@
|
|
|
149
146
|
return `${pluginName}!${sourcePath}`
|
|
150
147
|
}
|
|
151
148
|
|
|
149
|
+
let skipModules$1 = [];
|
|
150
|
+
|
|
151
|
+
function setSkipModules(names) {
|
|
152
|
+
skipModules$1 = names;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Checks if a module name is included in the list of modules to skip
|
|
156
|
+
// the transformation.
|
|
157
|
+
function skipModule(name) {
|
|
158
|
+
for (const skipModule of skipModules$1) {
|
|
159
|
+
// Recognise an asterisk at the beginning
|
|
160
|
+
if (skipModule.startsWith('*')) {
|
|
161
|
+
if (name.indexOf(skipModule.substring(1)) >= 0) return true
|
|
162
|
+
}
|
|
163
|
+
// Accept a path prefix as well.
|
|
164
|
+
else if (name.startsWith(skipModule)) return true
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
152
168
|
const errorMessages = {
|
|
153
169
|
[0]: 'Unexpected token',
|
|
154
170
|
[28]: "Unexpected token: '%0'",
|
|
@@ -85755,6 +85771,34 @@
|
|
|
85755
85771
|
//>>excludeEnd('excludeEsm')
|
|
85756
85772
|
var plugin = {
|
|
85757
85773
|
load(name, req, onload, reqConfig) {
|
|
85774
|
+
//>>excludeStart('excludeEsm', pragmas.excludeEsm)
|
|
85775
|
+
const { isBuild } = reqConfig;
|
|
85776
|
+
// if (!bundledModules) {
|
|
85777
|
+
// bundledModules = new Set()
|
|
85778
|
+
// const { bundles } = reqConfig
|
|
85779
|
+
// if (bundles) {
|
|
85780
|
+
// verbose && console.log('esm: initialising bundles', name)
|
|
85781
|
+
// for (const bundle in bundles) {
|
|
85782
|
+
// for (const module of bundles[bundle]) {
|
|
85783
|
+
// bundledModules.add(module)
|
|
85784
|
+
// }
|
|
85785
|
+
// }
|
|
85786
|
+
// }
|
|
85787
|
+
// }
|
|
85788
|
+
|
|
85789
|
+
// Paths relative to the current directory include the file extension.
|
|
85790
|
+
// Otherwise the file extension must not be used for JavaScript modules.
|
|
85791
|
+
// The file name should include the orioginal extension in the source maps.
|
|
85792
|
+
const file = name.endsWith(fileExtension) ? name : name + fileExtension;
|
|
85793
|
+
// Compilation and bundling of module sub-trees can be skipped, if those
|
|
85794
|
+
// are mapped to the pseudo-path `empty:`, meaning that those modules
|
|
85795
|
+
// are external and will be loaded during the runtime.
|
|
85796
|
+
const url = req.toUrl(file);
|
|
85797
|
+
if (url.startsWith('empty:')) {
|
|
85798
|
+
verbose && console.log('esm: skipping', name, 'mapped to', url);
|
|
85799
|
+
return onload()
|
|
85800
|
+
}
|
|
85801
|
+
|
|
85758
85802
|
verbose && console.log('esm: loading', name);
|
|
85759
85803
|
// If the module has been already defined from a module bundle, it was
|
|
85760
85804
|
// already transpiled, when the output bundle was written. No need to
|
|
@@ -85769,24 +85813,14 @@
|
|
|
85769
85813
|
// If the whole application is transpiled, there is no need to transpile
|
|
85770
85814
|
// ESM modules or prefix dependencies of AMD modules. Even not yet defined
|
|
85771
85815
|
// modules can be loaded just by `require` to get better performance.
|
|
85772
|
-
if (!mixedAmdAndEsm && !
|
|
85773
|
-
onlyAmd || skipModule(name)
|
|
85816
|
+
if (!mixedAmdAndEsm && !isBuild && req.specified(name) ||
|
|
85817
|
+
/*bundledModules.has(name) ||*/ onlyAmd || skipModule(name) ||
|
|
85818
|
+
// If the module was bundled, it had to be already transpiled.
|
|
85819
|
+
!isBuild && childFile(url) !== childFile(file)) {
|
|
85774
85820
|
verbose && console.log('esm: delegating', name);
|
|
85821
|
+
//>>excludeEnd('excludeEsm')
|
|
85775
85822
|
return req([name], onload, onload.error)
|
|
85776
|
-
}
|
|
85777
85823
|
//>>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
85824
|
}
|
|
85791
85825
|
|
|
85792
85826
|
// Fetch the text of the source module by AJAX and transpile it.
|
|
@@ -85807,12 +85841,12 @@
|
|
|
85807
85841
|
// Always produce the source maps when transpiling in the browser, otherwise
|
|
85808
85842
|
// the debugging would me impossible. When building and bundling, check if
|
|
85809
85843
|
// the source maps were enabled for the output.
|
|
85810
|
-
sourceMap: sourceMap || !
|
|
85844
|
+
sourceMap: sourceMap || !isBuild
|
|
85811
85845
|
}));
|
|
85812
85846
|
if (!updated) {
|
|
85813
85847
|
verbose && console.log('esm: retaining', name);
|
|
85814
85848
|
// return req([name], onload, onload.error)
|
|
85815
|
-
} else if (
|
|
85849
|
+
} else if (isBuild && debugDir) {
|
|
85816
85850
|
writeText$1(`${debugDir}/${file}`, code);
|
|
85817
85851
|
}
|
|
85818
85852
|
} catch (error) {
|
|
@@ -85823,7 +85857,7 @@
|
|
|
85823
85857
|
}
|
|
85824
85858
|
|
|
85825
85859
|
// Remember the transpiled content for the writing phase during the build.
|
|
85826
|
-
if (
|
|
85860
|
+
if (isBuild) {
|
|
85827
85861
|
buildMap[name] = code;
|
|
85828
85862
|
}
|
|
85829
85863
|
|