requirejs-esm 1.0.2 → 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/dist/api.js +10 -13
- package/dist/api.js.map +1 -1
- package/dist/plugin.js +10 -13
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -53,21 +53,24 @@
|
|
|
53
53
|
|
|
54
54
|
// Ensures that every JavaScript dependency will be prefixed by `esm!`.
|
|
55
55
|
// Relative paths will be converted to be relative to the parent module.
|
|
56
|
-
function resolvePath (sourcePath, currentFile, { pluginName }) {
|
|
56
|
+
function resolvePath (sourcePath, currentFile, { pluginName, needsResolve } = {}) {
|
|
57
57
|
// Ignore paths with other plugins applied and the three built-in
|
|
58
58
|
// pseudo-modules of RequireJS.
|
|
59
|
-
if (
|
|
59
|
+
if (sourcePath.includes('!') || sourcePath === 'require' ||
|
|
60
60
|
sourcePath === 'module' || sourcePath === 'exports') return
|
|
61
61
|
|
|
62
62
|
// If `sourcePath` is relative to `currentFile` - starts with ./ or ../ -
|
|
63
63
|
// prepend the parent directory of `currentFile` to it. This was needed
|
|
64
64
|
// for modules located outside the source root (`baseUrl`), which were
|
|
65
65
|
// mapped there using the `paths` of `map` configuration properties.
|
|
66
|
-
if (sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
|
|
67
|
-
|
|
66
|
+
if ((sourcePath.charAt(0) === '.' && (sourcePath.charAt(1) === '/' ||
|
|
67
|
+
sourcePath.charAt(1) === '.' && sourcePath.charAt(2) === '/')) &&
|
|
68
|
+
!(needsResolve && needsResolve(sourcePath, currentFile))) {
|
|
68
69
|
sourcePath = joinPath(parentDir(currentFile), sourcePath);
|
|
70
|
+
if (sourcePath.endsWith('.js')) sourcePath = sourcePath.substring(0, sourcePath.length - 3);
|
|
69
71
|
}
|
|
70
|
-
|
|
72
|
+
|
|
73
|
+
return pluginName ? `${pluginName}!${sourcePath}` : sourcePath
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
const errorMessages = {
|
|
@@ -85186,9 +85189,6 @@
|
|
|
85186
85189
|
|
|
85187
85190
|
// Updates dependency paths to be prefixed by `esm!` or otherwise updated.
|
|
85188
85191
|
function updateAmdDeps(amd, options) {
|
|
85189
|
-
const { resolvePath } = options;
|
|
85190
|
-
if (!resolvePath) return
|
|
85191
|
-
|
|
85192
85192
|
const { deps } = amd;
|
|
85193
85193
|
if (!deps) return
|
|
85194
85194
|
|
|
@@ -85196,6 +85196,7 @@
|
|
|
85196
85196
|
const { elements } = deps;
|
|
85197
85197
|
if (!elements.length) return
|
|
85198
85198
|
|
|
85199
|
+
const { resolvePath } = options;
|
|
85199
85200
|
let updated;
|
|
85200
85201
|
for (const element of elements) {
|
|
85201
85202
|
if (element.type === 'Literal') {
|
|
@@ -85574,11 +85575,8 @@
|
|
|
85574
85575
|
// Update dependency paths to be prefixed by `esm!` or otherwise updated.
|
|
85575
85576
|
function prepareImportPaths(importPaths, options ) {
|
|
85576
85577
|
const { resolvePath } = options;
|
|
85577
|
-
if (!resolvePath) return
|
|
85578
|
-
|
|
85579
85578
|
if (resolvePath) {
|
|
85580
85579
|
const { sourceFileName: parentName } = options;
|
|
85581
|
-
|
|
85582
85580
|
for (const importPath of importPaths) {
|
|
85583
85581
|
if (importPath.type === 'Literal') {
|
|
85584
85582
|
const moduleName = importPath.value;
|
|
@@ -85589,7 +85587,6 @@
|
|
|
85589
85587
|
}
|
|
85590
85588
|
}
|
|
85591
85589
|
}
|
|
85592
|
-
|
|
85593
85590
|
return arrayExpression(importPaths)
|
|
85594
85591
|
}
|
|
85595
85592
|
|
|
@@ -85598,7 +85595,7 @@
|
|
|
85598
85595
|
const { length } = amds;
|
|
85599
85596
|
if (length) {
|
|
85600
85597
|
options.amd = true;
|
|
85601
|
-
if (options.
|
|
85598
|
+
if (options.resolvePath) {
|
|
85602
85599
|
for (const amd of amds) {
|
|
85603
85600
|
options.updated |= updateAmdDeps(amd, options);
|
|
85604
85601
|
}
|