@lwrjs/shared-utils 0.12.0-alpha.26 → 0.12.0-alpha.28
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/build/cjs/mappings.cjs +23 -11
- package/build/es/mappings.d.ts +1 -0
- package/build/es/mappings.js +26 -13
- package/package.json +4 -4
package/build/cjs/mappings.cjs
CHANGED
|
@@ -25,11 +25,13 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
getImportMetadataMappings: () => getImportMetadataMappings,
|
|
28
|
+
isExternalFileSpecifier: () => isExternalFileSpecifier,
|
|
28
29
|
isExternalSpecifier: () => isExternalSpecifier,
|
|
29
30
|
toImportMetadata: () => toImportMetadata
|
|
30
31
|
});
|
|
31
32
|
var import_graph = __toModule(require("./graph.cjs"));
|
|
32
33
|
var import_identity = __toModule(require("./identity.cjs"));
|
|
34
|
+
var import_fs = __toModule(require("./fs.cjs"));
|
|
33
35
|
async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler) {
|
|
34
36
|
const visitedCache = new Map();
|
|
35
37
|
let importMetadata = {
|
|
@@ -47,7 +49,7 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
|
|
|
47
49
|
const moduleGraph = await (0, import_graph.getModuleGraphs)(specifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, runtimeEnvironment.bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
|
|
48
50
|
importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
49
51
|
}
|
|
50
|
-
if (requestedSpecifier !== specifier) {
|
|
52
|
+
if (moduleId.importer && requestedSpecifier !== specifier) {
|
|
51
53
|
const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${moduleId.importer}`;
|
|
52
54
|
const specifiersArray = Object.values(importMetadata.imports).find((a) => a.includes(specifier));
|
|
53
55
|
if (!specifiersArray) {
|
|
@@ -62,25 +64,28 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
|
|
|
62
64
|
const specifier = moduleGraph.graphs[0].specifier;
|
|
63
65
|
const uri = moduleGraph.uriMap[specifier];
|
|
64
66
|
const definition = moduleGraph.linkedDefinitions[specifier];
|
|
65
|
-
if (isExternalSpecifier(specifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
66
|
-
return {imports: {}, index: {}};
|
|
67
|
-
}
|
|
68
67
|
if (!uri) {
|
|
69
68
|
throw new Error("URI was not included in the graph: " + specifier);
|
|
70
69
|
}
|
|
71
70
|
if (!definition) {
|
|
72
71
|
throw new Error("Linked module definition was not included in the graph: " + specifier);
|
|
73
72
|
}
|
|
73
|
+
if (isExternalSpecifier(specifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
74
|
+
const externalMapping = {imports: {}, index: {}};
|
|
75
|
+
externalMapping.imports[uri] = [specifier];
|
|
76
|
+
externalMapping.index[specifier] = uri;
|
|
77
|
+
return externalMapping;
|
|
78
|
+
}
|
|
74
79
|
const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
75
80
|
let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
|
|
76
81
|
const depSpecifiers = runtimeEnvironment.format === "esm" ? moduleGraph.graphs[0].dynamicRefs : moduleGraph.graphs[0].static;
|
|
77
82
|
for (const depSpecifier of depSpecifiers) {
|
|
78
|
-
const depUri = moduleGraph.uriMap[depSpecifier];
|
|
79
|
-
const depDef = moduleGraph.linkedDefinitions[depSpecifier];
|
|
80
|
-
const depMissing = !depUri || !depDef;
|
|
81
83
|
if (isExternalSpecifier(depSpecifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
82
84
|
continue;
|
|
83
85
|
}
|
|
86
|
+
const depUri = moduleGraph.uriMap[depSpecifier];
|
|
87
|
+
const depDef = moduleGraph.linkedDefinitions[depSpecifier];
|
|
88
|
+
const depMissing = !depUri || !depDef;
|
|
84
89
|
if (depMissing && runtimeEnvironment.format !== "esm") {
|
|
85
90
|
if (!depUri) {
|
|
86
91
|
throw new Error("URI was not included in the graph for dependent: " + depSpecifier);
|
|
@@ -92,8 +97,11 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
|
|
|
92
97
|
continue;
|
|
93
98
|
}
|
|
94
99
|
if (!importMetadata.imports[depUri]) {
|
|
95
|
-
const
|
|
96
|
-
|
|
100
|
+
const depDefSpecifier = (0, import_identity.getSpecifier)(depDef);
|
|
101
|
+
if (!isExternalSpecifier(depDefSpecifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
102
|
+
const depMetadata = await normalizeImportMetadata(depDefSpecifier, depUri, depDef, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
103
|
+
importMetadata = mergeImportMetadata(importMetadata, depMetadata);
|
|
104
|
+
}
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
return importMetadata;
|
|
@@ -143,7 +151,7 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
|
|
|
143
151
|
return index;
|
|
144
152
|
}
|
|
145
153
|
async function getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams) {
|
|
146
|
-
if (
|
|
154
|
+
if (moduleId.version) {
|
|
147
155
|
return (0, import_identity.getSpecifier)(moduleId);
|
|
148
156
|
}
|
|
149
157
|
const versionedModuleEntry = await moduleRegistry.getModuleEntry({
|
|
@@ -153,5 +161,9 @@ async function getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams) {
|
|
|
153
161
|
}
|
|
154
162
|
function isExternalSpecifier(id, bundleConfig) {
|
|
155
163
|
const {specifier} = (0, import_identity.explodeSpecifier)(id);
|
|
156
|
-
return !!(bundleConfig?.external && bundleConfig.external
|
|
164
|
+
return !!(bundleConfig?.external && Object.prototype.hasOwnProperty.call(bundleConfig.external, specifier));
|
|
165
|
+
}
|
|
166
|
+
function isExternalFileSpecifier(id, bundleConfig) {
|
|
167
|
+
const {specifier} = (0, import_identity.explodeSpecifier)(id);
|
|
168
|
+
return !!(bundleConfig?.external && bundleConfig.external[specifier] && bundleConfig.external[specifier].startsWith(import_fs.PROTOCOL_FILE));
|
|
157
169
|
}
|
package/build/es/mappings.d.ts
CHANGED
|
@@ -17,4 +17,5 @@ export declare function getImportMetadataMappings(moduleIds: AbstractModuleId[],
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function toImportMetadata(moduleGraph: FlattenedModuleGraphs, existingImportMetadata: ImportMetadata | undefined, moduleRegistry: ModuleRegistry, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ImportMetadata>;
|
|
19
19
|
export declare function isExternalSpecifier(id: string, bundleConfig: BundleConfig): boolean;
|
|
20
|
+
export declare function isExternalFileSpecifier(id: string, bundleConfig: BundleConfig): boolean;
|
|
20
21
|
//# sourceMappingURL=mappings.d.ts.map
|
package/build/es/mappings.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getModuleGraphs, GraphDepth } from './graph.js';
|
|
2
2
|
import { explodeSpecifier, getSpecifier, isBundleDefinition, VERSION_NOT_PROVIDED } from './identity.js';
|
|
3
|
+
import { PROTOCOL_FILE } from './fs.js';
|
|
3
4
|
/**
|
|
4
5
|
* Get the Import Metadata for the LWR Mapping Api (https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api)
|
|
5
6
|
*/
|
|
@@ -30,7 +31,7 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
|
|
|
30
31
|
importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
31
32
|
}
|
|
32
33
|
// If the requested specifier is not the same as the versioned specifier, include the requested specifier's importer.
|
|
33
|
-
if (requestedSpecifier !== specifier) {
|
|
34
|
+
if (moduleId.importer && requestedSpecifier !== specifier) {
|
|
34
35
|
const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${moduleId.importer}`;
|
|
35
36
|
const specifiersArray = Object.values(importMetadata.imports).find((a) => a.includes(specifier));
|
|
36
37
|
if (!specifiersArray) {
|
|
@@ -58,16 +59,19 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
|
|
|
58
59
|
const specifier = moduleGraph.graphs[0].specifier;
|
|
59
60
|
const uri = moduleGraph.uriMap[specifier];
|
|
60
61
|
const definition = moduleGraph.linkedDefinitions[specifier];
|
|
61
|
-
if (isExternalSpecifier(specifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
62
|
-
// Ignore Externals
|
|
63
|
-
return { imports: {}, index: {} };
|
|
64
|
-
}
|
|
65
62
|
if (!uri) {
|
|
66
63
|
throw new Error('URI was not included in the graph: ' + specifier);
|
|
67
64
|
}
|
|
68
65
|
if (!definition) {
|
|
69
66
|
throw new Error('Linked module definition was not included in the graph: ' + specifier);
|
|
70
67
|
}
|
|
68
|
+
// Add a single entry for an external
|
|
69
|
+
if (isExternalSpecifier(specifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
70
|
+
const externalMapping = { imports: {}, index: {} };
|
|
71
|
+
externalMapping.imports[uri] = [specifier];
|
|
72
|
+
externalMapping.index[specifier] = uri;
|
|
73
|
+
return externalMapping;
|
|
74
|
+
}
|
|
71
75
|
// Merge in the existing metadata with imports for the root specifier
|
|
72
76
|
const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
73
77
|
let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
|
|
@@ -78,13 +82,13 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
|
|
|
78
82
|
? moduleGraph.graphs[0].dynamicRefs
|
|
79
83
|
: moduleGraph.graphs[0].static;
|
|
80
84
|
for (const depSpecifier of depSpecifiers) {
|
|
81
|
-
const depUri = moduleGraph.uriMap[depSpecifier];
|
|
82
|
-
const depDef = moduleGraph.linkedDefinitions[depSpecifier];
|
|
83
|
-
const depMissing = !depUri || !depDef;
|
|
84
85
|
if (isExternalSpecifier(depSpecifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
85
86
|
// Ignore Externals
|
|
86
87
|
continue;
|
|
87
88
|
}
|
|
89
|
+
const depUri = moduleGraph.uriMap[depSpecifier];
|
|
90
|
+
const depDef = moduleGraph.linkedDefinitions[depSpecifier];
|
|
91
|
+
const depMissing = !depUri || !depDef;
|
|
88
92
|
if (depMissing && runtimeEnvironment.format !== 'esm') {
|
|
89
93
|
if (!depUri) {
|
|
90
94
|
throw new Error('URI was not included in the graph for dependent: ' + depSpecifier);
|
|
@@ -98,9 +102,12 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
|
|
|
98
102
|
continue;
|
|
99
103
|
}
|
|
100
104
|
if (!importMetadata.imports[depUri]) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
const depDefSpecifier = getSpecifier(depDef);
|
|
106
|
+
if (!isExternalSpecifier(depDefSpecifier, moduleRegistry.getConfig().bundleConfig)) {
|
|
107
|
+
// eslint-disable-next-line no-await-in-loop
|
|
108
|
+
const depMetadata = await normalizeImportMetadata(depDefSpecifier, depUri, depDef, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
109
|
+
importMetadata = mergeImportMetadata(importMetadata, depMetadata);
|
|
110
|
+
}
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
return importMetadata;
|
|
@@ -162,7 +169,7 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
|
|
|
162
169
|
return index;
|
|
163
170
|
}
|
|
164
171
|
async function getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams) {
|
|
165
|
-
if (
|
|
172
|
+
if (moduleId.version) {
|
|
166
173
|
return getSpecifier(moduleId);
|
|
167
174
|
}
|
|
168
175
|
const versionedModuleEntry = await moduleRegistry.getModuleEntry({
|
|
@@ -172,6 +179,12 @@ async function getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams) {
|
|
|
172
179
|
}
|
|
173
180
|
export function isExternalSpecifier(id, bundleConfig) {
|
|
174
181
|
const { specifier } = explodeSpecifier(id);
|
|
175
|
-
return !!(bundleConfig?.external && bundleConfig.external
|
|
182
|
+
return !!(bundleConfig?.external && Object.prototype.hasOwnProperty.call(bundleConfig.external, specifier));
|
|
183
|
+
}
|
|
184
|
+
export function isExternalFileSpecifier(id, bundleConfig) {
|
|
185
|
+
const { specifier } = explodeSpecifier(id);
|
|
186
|
+
return !!(bundleConfig?.external &&
|
|
187
|
+
bundleConfig.external[specifier] &&
|
|
188
|
+
bundleConfig.external[specifier].startsWith(PROTOCOL_FILE));
|
|
176
189
|
}
|
|
177
190
|
//# sourceMappingURL=mappings.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.12.0-alpha.
|
|
7
|
+
"version": "0.12.0-alpha.28",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"build/**/*.d.ts"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@lwrjs/diagnostics": "0.12.0-alpha.
|
|
40
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.28",
|
|
41
41
|
"es-module-lexer": "^1.3.0",
|
|
42
42
|
"fast-json-stable-stringify": "^2.1.0",
|
|
43
43
|
"magic-string": "^0.30.7",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"slugify": "^1.4.5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
53
|
+
"@lwrjs/types": "0.12.0-alpha.28",
|
|
54
54
|
"@types/mime-types": "2.1.4",
|
|
55
55
|
"@types/path-to-regexp": "^1.7.0"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=18.0.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "5228219171bb2d28a4c7b32f1f6238e396ac3cbd"
|
|
61
61
|
}
|