requirejs-esm 1.0.2 → 2.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/README.md +4 -0
- package/bin/esm2requirejs.js +10 -6
- package/dist/api.js +11 -14
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +11 -14
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -3
package/dist/plugin.js
CHANGED
|
@@ -129,21 +129,24 @@
|
|
|
129
129
|
|
|
130
130
|
// Ensures that every JavaScript dependency will be prefixed by `esm!`.
|
|
131
131
|
// Relative paths will be converted to be relative to the parent module.
|
|
132
|
-
function resolvePath$1 (sourcePath, currentFile, { pluginName }) {
|
|
132
|
+
function resolvePath$1 (sourcePath, currentFile, { pluginName, needsResolve } = {}) {
|
|
133
133
|
// Ignore paths with other plugins applied and the three built-in
|
|
134
134
|
// pseudo-modules of RequireJS.
|
|
135
|
-
if (
|
|
135
|
+
if (sourcePath.includes('!') || sourcePath === 'require' ||
|
|
136
136
|
sourcePath === 'module' || sourcePath === 'exports') return
|
|
137
137
|
|
|
138
138
|
// If `sourcePath` is relative to `currentFile` - starts with ./ or ../ -
|
|
139
139
|
// prepend the parent directory of `currentFile` to it. This was needed
|
|
140
140
|
// for modules located outside the source root (`baseUrl`), which were
|
|
141
141
|
// mapped there using the `paths` of `map` configuration properties.
|
|
142
|
-
if (sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
|
|
143
|
-
|
|
142
|
+
if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
|
|
143
|
+
sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
|
|
144
|
+
!(needsResolve && needsResolve(sourcePath, currentFile))) {
|
|
144
145
|
sourcePath = joinPath(parentDir(currentFile), sourcePath);
|
|
146
|
+
if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3);
|
|
145
147
|
}
|
|
146
|
-
|
|
148
|
+
|
|
149
|
+
return pluginName ? `${pluginName}!${sourcePath}` : sourcePath
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
let skipModules$1 = [];
|
|
@@ -85281,9 +85284,6 @@
|
|
|
85281
85284
|
|
|
85282
85285
|
// Updates dependency paths to be prefixed by `esm!` or otherwise updated.
|
|
85283
85286
|
function updateAmdDeps(amd, options) {
|
|
85284
|
-
const { resolvePath } = options;
|
|
85285
|
-
if (!resolvePath) return
|
|
85286
|
-
|
|
85287
85287
|
const { deps } = amd;
|
|
85288
85288
|
if (!deps) return
|
|
85289
85289
|
|
|
@@ -85291,6 +85291,7 @@
|
|
|
85291
85291
|
const { elements } = deps;
|
|
85292
85292
|
if (!elements.length) return
|
|
85293
85293
|
|
|
85294
|
+
const { resolvePath } = options;
|
|
85294
85295
|
let updated;
|
|
85295
85296
|
for (const element of elements) {
|
|
85296
85297
|
if (element.type === 'Literal') {
|
|
@@ -85669,11 +85670,8 @@
|
|
|
85669
85670
|
// Update dependency paths to be prefixed by `esm!` or otherwise updated.
|
|
85670
85671
|
function prepareImportPaths(importPaths, options ) {
|
|
85671
85672
|
const { resolvePath } = options;
|
|
85672
|
-
if (!resolvePath) return
|
|
85673
|
-
|
|
85674
85673
|
if (resolvePath) {
|
|
85675
85674
|
const { sourceFileName: parentName } = options;
|
|
85676
|
-
|
|
85677
85675
|
for (const importPath of importPaths) {
|
|
85678
85676
|
if (importPath.type === 'Literal') {
|
|
85679
85677
|
const moduleName = importPath.value;
|
|
@@ -85684,7 +85682,6 @@
|
|
|
85684
85682
|
}
|
|
85685
85683
|
}
|
|
85686
85684
|
}
|
|
85687
|
-
|
|
85688
85685
|
return arrayExpression(importPaths)
|
|
85689
85686
|
}
|
|
85690
85687
|
|
|
@@ -85693,7 +85690,7 @@
|
|
|
85693
85690
|
const { length } = amds;
|
|
85694
85691
|
if (length) {
|
|
85695
85692
|
options.amd = true;
|
|
85696
|
-
if (options.
|
|
85693
|
+
if (options.resolvePath) {
|
|
85697
85694
|
for (const amd of amds) {
|
|
85698
85695
|
options.updated |= updateAmdDeps(amd, options);
|
|
85699
85696
|
}
|
|
@@ -85714,7 +85711,7 @@
|
|
|
85714
85711
|
sourceMap
|
|
85715
85712
|
} = {}) {
|
|
85716
85713
|
// const ast = parse(text, { ecmaVersion, sourceType: 'module', locations: true })
|
|
85717
|
-
let ast = parseModule(text, { loc: true });
|
|
85714
|
+
let ast = parseModule(text, { next: true, loc: true });
|
|
85718
85715
|
|
|
85719
85716
|
const options = { sourceFileName: file, pluginName, resolvePath, originalResolvePath: resolvePath$1 };
|
|
85720
85717
|
transformModules(ast, options);
|