@lwrjs/npm-module-provider 0.17.2-alpha.8 → 0.17.2
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.
|
@@ -52,6 +52,22 @@ var ExternalsPlugin = function({external}) {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
};
|
|
55
|
+
function resolveExportsIteratively(entry, preferred = ["import", "module", "default", "browser"]) {
|
|
56
|
+
let current = entry;
|
|
57
|
+
while (current && typeof current === "object") {
|
|
58
|
+
let found = false;
|
|
59
|
+
for (const condition of preferred) {
|
|
60
|
+
if (current[condition] !== void 0) {
|
|
61
|
+
current = current[condition];
|
|
62
|
+
found = true;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!found)
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return typeof current === "string" ? current : void 0;
|
|
70
|
+
}
|
|
55
71
|
async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
56
72
|
let res;
|
|
57
73
|
try {
|
|
@@ -61,10 +77,12 @@ async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
|
61
77
|
packageFilter: function(pkg) {
|
|
62
78
|
const {exports: exports2, browser} = pkg;
|
|
63
79
|
if (exports2 && exports2["."]) {
|
|
64
|
-
const
|
|
65
|
-
|
|
80
|
+
const resolved = resolveExportsIteratively(exports2["."]);
|
|
81
|
+
if (resolved) {
|
|
82
|
+
pkg.main = resolved;
|
|
83
|
+
}
|
|
66
84
|
} else if (browser && typeof browser === "string") {
|
|
67
|
-
pkg.main =
|
|
85
|
+
pkg.main = browser;
|
|
68
86
|
} else if (pkg.module) {
|
|
69
87
|
pkg.main = pkg.module;
|
|
70
88
|
}
|
package/build/es/index.js
CHANGED
|
@@ -2,9 +2,11 @@ import path from 'path';
|
|
|
2
2
|
import { hashContent, readFile } from '@lwrjs/shared-utils';
|
|
3
3
|
import { resolveNpmModuleSpecifier as resolveNpm } from './resolveNpmModules.js';
|
|
4
4
|
export default class NpmModuleProvider {
|
|
5
|
+
name = 'npm-module-provider';
|
|
6
|
+
providerConfig;
|
|
7
|
+
webModulesCacheDir;
|
|
8
|
+
moduleEntryVersionCache = new Map();
|
|
5
9
|
constructor(providerConfig = {}, { config: { cacheDir } }) {
|
|
6
|
-
this.name = 'npm-module-provider';
|
|
7
|
-
this.moduleEntryVersionCache = new Map();
|
|
8
10
|
this.webModulesCacheDir = path.join(cacheDir, 'web_modules');
|
|
9
11
|
this.providerConfig = providerConfig;
|
|
10
12
|
}
|
|
@@ -28,6 +28,24 @@ const ExternalsPlugin = function ({ external }) {
|
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
+
// Helper function using an iterative approach to resolve export entries.
|
|
32
|
+
function resolveExportsIteratively(entry, preferred = ['import', 'module', 'default', 'browser']) {
|
|
33
|
+
let current = entry;
|
|
34
|
+
// Loop until we reach a string or cannot go further.
|
|
35
|
+
while (current && typeof current === 'object') {
|
|
36
|
+
let found = false;
|
|
37
|
+
for (const condition of preferred) {
|
|
38
|
+
if (current[condition] !== undefined) {
|
|
39
|
+
current = current[condition];
|
|
40
|
+
found = true;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!found)
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return typeof current === 'string' ? current : undefined;
|
|
48
|
+
}
|
|
31
49
|
export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
32
50
|
let res;
|
|
33
51
|
try {
|
|
@@ -36,24 +54,22 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
|
36
54
|
res = resolve.sync(specifier, {
|
|
37
55
|
packageFilter: function (pkg) {
|
|
38
56
|
const { exports, browser } = pkg;
|
|
57
|
+
// 1. Handle the "exports" field (and nested conditions)
|
|
39
58
|
if (exports && exports['.']) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(typeof root?.browser === 'string' ? root.browser : undefined) ||
|
|
45
|
-
root?.import?.browser?.default ||
|
|
46
|
-
root?.import?.default ||
|
|
47
|
-
(typeof root?.import === 'string' ? root.import : undefined) ||
|
|
48
|
-
root?.default;
|
|
59
|
+
const resolved = resolveExportsIteratively(exports['.']);
|
|
60
|
+
if (resolved) {
|
|
61
|
+
pkg.main = resolved;
|
|
62
|
+
}
|
|
49
63
|
}
|
|
64
|
+
// 2. Fall back to the "browser" field (if it's a string)
|
|
50
65
|
else if (browser && typeof browser === 'string') {
|
|
51
|
-
pkg.main =
|
|
66
|
+
pkg.main = browser;
|
|
52
67
|
}
|
|
68
|
+
// 3. Next check the "module" field.
|
|
53
69
|
else if (pkg.module) {
|
|
54
70
|
pkg.main = pkg.module;
|
|
55
71
|
}
|
|
56
|
-
//
|
|
72
|
+
// Grab package.json version (if set) before we go.
|
|
57
73
|
if (pkg.version) {
|
|
58
74
|
pkgVersion = pkg.version;
|
|
59
75
|
}
|
|
@@ -62,7 +78,7 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
|
62
78
|
});
|
|
63
79
|
}
|
|
64
80
|
catch (error) {
|
|
65
|
-
// Just return undefined
|
|
81
|
+
// Just return undefined for module not found.
|
|
66
82
|
if (error.code === 'MODULE_NOT_FOUND') {
|
|
67
83
|
logger.debug({
|
|
68
84
|
label: 'npm-module-provider',
|
|
@@ -76,7 +92,7 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
|
76
92
|
if (!res) {
|
|
77
93
|
return undefined;
|
|
78
94
|
}
|
|
79
|
-
//
|
|
95
|
+
// Ensure package version is set.
|
|
80
96
|
if (pkgVersion === undefined) {
|
|
81
97
|
throw new Error('Failed to find version in package.json');
|
|
82
98
|
}
|
|
@@ -107,11 +123,9 @@ export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
|
107
123
|
}
|
|
108
124
|
}
|
|
109
125
|
class Queue {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.pendingPromise = false;
|
|
114
|
-
}
|
|
126
|
+
queue = [];
|
|
127
|
+
workingOnPromise = false;
|
|
128
|
+
pendingPromise = false;
|
|
115
129
|
enqueue(promise) {
|
|
116
130
|
return new Promise((resolve, reject) => {
|
|
117
131
|
this.queue.push({ promise, resolve, reject });
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.17.2
|
|
7
|
+
"version": "0.17.2",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -36,22 +36,22 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
39
|
-
"@lwrjs/diagnostics": "0.17.2
|
|
40
|
-
"@lwrjs/shared-utils": "0.17.2
|
|
39
|
+
"@lwrjs/diagnostics": "0.17.2",
|
|
40
|
+
"@lwrjs/shared-utils": "0.17.2",
|
|
41
41
|
"esbuild": "^0.9.7",
|
|
42
42
|
"resolve": "^1.22.8"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@lwrjs/types": "0.17.2
|
|
46
|
-
"jest": "
|
|
45
|
+
"@lwrjs/types": "0.17.2",
|
|
46
|
+
"jest": "29.7.0",
|
|
47
47
|
"memfs": "^4.13.0",
|
|
48
|
-
"ts-jest": "^
|
|
48
|
+
"ts-jest": "^29.2.6"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
51
|
+
"node": ">=20.0.0"
|
|
52
52
|
},
|
|
53
53
|
"volta": {
|
|
54
54
|
"extends": "../../../package.json"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "d64d8888a28da36c05e3d8d9baf51416551863a9"
|
|
57
57
|
}
|