@lwrjs/module-registry 0.6.4 → 0.7.0-alpha.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.
- package/build/cjs/index.cjs +13 -3
- package/build/cjs/linker/linker.cjs +3 -3
- package/build/cjs/signature.cjs +13 -16
- package/build/es/index.js +13 -3
- package/build/es/linker/linker.js +3 -3
- package/build/es/signature.d.ts +14 -1
- package/build/es/signature.js +39 -17
- package/package.json +5 -5
package/build/cjs/index.cjs
CHANGED
|
@@ -74,7 +74,7 @@ var LwrModuleRegistry = class {
|
|
|
74
74
|
const {bundle, format} = runtimeEnvironment;
|
|
75
75
|
if (bundle) {
|
|
76
76
|
return new Promise((resolve, reject) => {
|
|
77
|
-
(0, import_signature.getBundleSignature)(moduleId, this).then((bundleSignature) => resolve((0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, bundleSignature))).catch(reject);
|
|
77
|
+
(0, import_signature.getBundleSignature)(moduleId, this, this.globalConfig?.bundleConfig?.exclude).then((bundleSignature) => resolve((0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, bundleSignature))).catch(reject);
|
|
78
78
|
});
|
|
79
79
|
} else {
|
|
80
80
|
return new Promise((resolve, reject) => {
|
|
@@ -120,7 +120,7 @@ var LwrModuleRegistry = class {
|
|
|
120
120
|
async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
|
|
121
121
|
const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
|
|
122
122
|
const id = moduleEntry.id;
|
|
123
|
-
const {format, compat, debug, minify} = runtimeEnvironment;
|
|
123
|
+
const {format, compat, debug, minify, bundle} = runtimeEnvironment;
|
|
124
124
|
const locale = runtimeParams?.["locale"];
|
|
125
125
|
const environment = runtimeParams?.["environment"];
|
|
126
126
|
const {
|
|
@@ -134,6 +134,7 @@ var LwrModuleRegistry = class {
|
|
|
134
134
|
compat,
|
|
135
135
|
debug,
|
|
136
136
|
minify,
|
|
137
|
+
bundle,
|
|
137
138
|
lockerEnabled,
|
|
138
139
|
locale,
|
|
139
140
|
environment
|
|
@@ -147,7 +148,16 @@ var LwrModuleRegistry = class {
|
|
|
147
148
|
const moduleLinked = await this.createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams);
|
|
148
149
|
if (cacheDisabled === false) {
|
|
149
150
|
const linkedMap = this.moduleLinkedCache.get(id) || new Map();
|
|
150
|
-
linkedMap.set((0, import_shared_utils.getCacheKeyFromJson)({
|
|
151
|
+
linkedMap.set((0, import_shared_utils.getCacheKeyFromJson)({
|
|
152
|
+
format,
|
|
153
|
+
compat,
|
|
154
|
+
debug,
|
|
155
|
+
minify,
|
|
156
|
+
bundle,
|
|
157
|
+
lockerEnabled,
|
|
158
|
+
locale,
|
|
159
|
+
environment
|
|
160
|
+
}), moduleLinked);
|
|
151
161
|
this.moduleLinkedCache.set(id, linkedMap);
|
|
152
162
|
}
|
|
153
163
|
return moduleLinked;
|
|
@@ -61,7 +61,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
61
61
|
}
|
|
62
62
|
let signature;
|
|
63
63
|
if (runtimeEnvironment.bundle && runtimeEnvironment.format === "esm" && exclude?.includes(importRef.specifier)) {
|
|
64
|
-
signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry);
|
|
64
|
+
signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry, exclude);
|
|
65
65
|
}
|
|
66
66
|
const {locations, sourceSpecifier} = importRef;
|
|
67
67
|
const link2 = strategy(importRef, runtimeEnvironment, runtimeParams, signature);
|
|
@@ -83,7 +83,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
83
83
|
let signature;
|
|
84
84
|
const isStringLiteral = importRef.moduleNameType === import_shared_utils2.ModuleNameType.string;
|
|
85
85
|
if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === "esm") {
|
|
86
|
-
signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry);
|
|
86
|
+
signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry, exclude);
|
|
87
87
|
}
|
|
88
88
|
const link2 = isStringLiteral ? versionStrategy(importRef, runtimeEnvironment, runtimeParams, signature) : importRef.specifier;
|
|
89
89
|
const linkedLocations = locations.map(({location, importLocation}) => {
|
|
@@ -120,7 +120,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
120
120
|
const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(specifier2);
|
|
121
121
|
let signature;
|
|
122
122
|
if (esmLoaderModule && runtimeEnvironment.bundle) {
|
|
123
|
-
signature = await (0, import_signature.getBundleSignature)({version: version2, specifier: specifier2}, moduleRegistry);
|
|
123
|
+
signature = await (0, import_signature.getBundleSignature)({version: version2, specifier: specifier2}, moduleRegistry, exclude);
|
|
124
124
|
}
|
|
125
125
|
const loaderLink = strategy({specifier: specifier2, version: version2}, runtimeEnvironment, runtimeParams, signature);
|
|
126
126
|
codeStringBuilder.prepend(`import { load } from "${loaderLink}";
|
package/build/cjs/signature.cjs
CHANGED
|
@@ -32,34 +32,31 @@ var import_process = __toModule(require("process"));
|
|
|
32
32
|
var import_module = __toModule(require("module"));
|
|
33
33
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
34
34
|
var LWC_VERSION = getLWCVersion();
|
|
35
|
-
var ENABLED_FINGERPRINTS = (0, import_shared_utils.
|
|
35
|
+
var ENABLED_FINGERPRINTS = !(0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER;
|
|
36
36
|
var ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
|
|
37
|
-
async function getRecursiveModuleHash(
|
|
38
|
-
if (!
|
|
37
|
+
async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set()) {
|
|
38
|
+
if (!modules.length) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const definitions = await Promise.all(modules.map((module2) => registry.getModule(module2)));
|
|
42
|
+
const imports = new Map();
|
|
42
43
|
for (const definition of definitions) {
|
|
43
|
-
if (visitedDefinitions.has(definition.id)) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
44
|
const {ownHash, moduleRecord} = definition;
|
|
47
45
|
hash.update(ownHash);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
visitedDefinitions.add((0, import_shared_utils.getSpecifier)(definition));
|
|
47
|
+
moduleRecord.imports?.forEach((importReference) => {
|
|
48
|
+
imports.set((0, import_shared_utils.getSpecifier)(importReference), importReference);
|
|
49
|
+
});
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) => !visitedDefinitions.has(dependency.specifier) && !visitedDefinitions.has((0, import_shared_utils.getSpecifier)(dependency)));
|
|
52
|
+
if (dependencies.length) {
|
|
55
53
|
return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions);
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
async function getBundleSignature(moduleId, registry) {
|
|
59
|
-
const root = await registry.getModule(moduleId);
|
|
56
|
+
async function getBundleSignature(moduleId, registry, exclude) {
|
|
60
57
|
const hash = import_crypto.default.createHash("sha1");
|
|
61
58
|
hash.update(ENV_KEY);
|
|
62
|
-
await getRecursiveModuleHash([
|
|
59
|
+
await getRecursiveModuleHash([moduleId], registry, hash, new Set(exclude));
|
|
63
60
|
return hash.digest("hex");
|
|
64
61
|
}
|
|
65
62
|
function getLWCVersion() {
|
package/build/es/index.js
CHANGED
|
@@ -49,7 +49,7 @@ export class LwrModuleRegistry {
|
|
|
49
49
|
const { bundle, format } = runtimeEnvironment;
|
|
50
50
|
if (bundle) {
|
|
51
51
|
return new Promise((resolve, reject) => {
|
|
52
|
-
getBundleSignature(moduleId, this)
|
|
52
|
+
getBundleSignature(moduleId, this, this.globalConfig?.bundleConfig?.exclude)
|
|
53
53
|
.then((bundleSignature) => resolve(esmLinkingStrategy(moduleId, runtimeEnvironment, runtimeParams, bundleSignature)))
|
|
54
54
|
.catch(reject);
|
|
55
55
|
});
|
|
@@ -110,7 +110,7 @@ export class LwrModuleRegistry {
|
|
|
110
110
|
const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
|
|
111
111
|
const id = moduleEntry.id;
|
|
112
112
|
// cache key pivots from the runtimeEnvironment
|
|
113
|
-
const { format, compat, debug, minify } = runtimeEnvironment;
|
|
113
|
+
const { format, compat, debug, minify, bundle } = runtimeEnvironment;
|
|
114
114
|
const locale = runtimeParams?.['locale'];
|
|
115
115
|
const environment = runtimeParams?.['environment'];
|
|
116
116
|
const { locker: { enabled: lockerEnabled }, } = this.globalConfig;
|
|
@@ -122,6 +122,7 @@ export class LwrModuleRegistry {
|
|
|
122
122
|
compat,
|
|
123
123
|
debug,
|
|
124
124
|
minify,
|
|
125
|
+
bundle,
|
|
125
126
|
lockerEnabled,
|
|
126
127
|
locale,
|
|
127
128
|
environment,
|
|
@@ -136,7 +137,16 @@ export class LwrModuleRegistry {
|
|
|
136
137
|
// Add to cache
|
|
137
138
|
if (cacheDisabled === false) {
|
|
138
139
|
const linkedMap = this.moduleLinkedCache.get(id) || new Map();
|
|
139
|
-
linkedMap.set(getCacheKeyFromJson({
|
|
140
|
+
linkedMap.set(getCacheKeyFromJson({
|
|
141
|
+
format,
|
|
142
|
+
compat,
|
|
143
|
+
debug,
|
|
144
|
+
minify,
|
|
145
|
+
bundle,
|
|
146
|
+
lockerEnabled,
|
|
147
|
+
locale,
|
|
148
|
+
environment,
|
|
149
|
+
}), moduleLinked);
|
|
140
150
|
this.moduleLinkedCache.set(id, linkedMap);
|
|
141
151
|
}
|
|
142
152
|
return moduleLinked;
|
|
@@ -44,7 +44,7 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
44
44
|
if (runtimeEnvironment.bundle &&
|
|
45
45
|
runtimeEnvironment.format === 'esm' &&
|
|
46
46
|
exclude?.includes(importRef.specifier)) {
|
|
47
|
-
signature = await getBundleSignature(importRef, moduleRegistry);
|
|
47
|
+
signature = await getBundleSignature(importRef, moduleRegistry, exclude);
|
|
48
48
|
}
|
|
49
49
|
const { locations, sourceSpecifier } = importRef;
|
|
50
50
|
const link = strategy(importRef, runtimeEnvironment, runtimeParams, signature);
|
|
@@ -69,7 +69,7 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
69
69
|
const isStringLiteral = importRef.moduleNameType === ModuleNameType.string;
|
|
70
70
|
// get signature for dynamic imports when bundling esm
|
|
71
71
|
if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === 'esm') {
|
|
72
|
-
signature = await getBundleSignature(importRef, moduleRegistry);
|
|
72
|
+
signature = await getBundleSignature(importRef, moduleRegistry, exclude);
|
|
73
73
|
}
|
|
74
74
|
// always link [literal] dynamic imports as versioned specifiers (AMD strategy)
|
|
75
75
|
// linking them as URIs (ESM strategy) causes caching issues since they can contain stale signatures
|
|
@@ -119,7 +119,7 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
119
119
|
let signature;
|
|
120
120
|
if (esmLoaderModule && runtimeEnvironment.bundle) {
|
|
121
121
|
// Ensure the ESM loader is signed, or there may be a clash between this import and an existing one
|
|
122
|
-
signature = await getBundleSignature({ version, specifier }, moduleRegistry);
|
|
122
|
+
signature = await getBundleSignature({ version, specifier }, moduleRegistry, exclude);
|
|
123
123
|
}
|
|
124
124
|
const loaderLink = strategy({ specifier, version }, runtimeEnvironment, runtimeParams, signature);
|
|
125
125
|
// import {load} from 'loader/loader'
|
package/build/es/signature.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import { ModuleRegistry, ModuleId } from '@lwrjs/types';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Generate a bundle signature
|
|
4
|
+
*
|
|
5
|
+
* Traverses the module graph from the specified root module to generate a
|
|
6
|
+
* signature. Modules that are marked for exclusion will be skipped. The
|
|
7
|
+
* bundle signature will be generated based on the environment
|
|
8
|
+
* keys(i.e. LWC version) and the ownHash of each module in the graph.
|
|
9
|
+
*
|
|
10
|
+
* @param moduleId - root module id
|
|
11
|
+
* @param registry - module registry
|
|
12
|
+
* @param exclude - bundle config exclusions
|
|
13
|
+
* @returns a bungle signature
|
|
14
|
+
*/
|
|
15
|
+
export declare function getBundleSignature(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, registry: ModuleRegistry, exclude?: string[]): Promise<string>;
|
|
3
16
|
//# sourceMappingURL=signature.d.ts.map
|
package/build/es/signature.js
CHANGED
|
@@ -2,36 +2,58 @@ import crypto from 'crypto';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { cwd } from 'process';
|
|
4
4
|
import { createRequire } from 'module';
|
|
5
|
-
import {
|
|
5
|
+
import { getFeatureFlags, getSpecifier } from '@lwrjs/shared-utils';
|
|
6
6
|
const LWC_VERSION = getLWCVersion();
|
|
7
|
-
const ENABLED_FINGERPRINTS =
|
|
7
|
+
const ENABLED_FINGERPRINTS = !getFeatureFlags().LEGACY_LOADER;
|
|
8
8
|
const ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
|
|
9
|
-
async function getRecursiveModuleHash(
|
|
10
|
-
if (!
|
|
9
|
+
async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set()) {
|
|
10
|
+
if (!modules.length) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const definitions = await Promise.all(modules.map((module) => registry.getModule(module)));
|
|
14
|
+
const imports = new Map();
|
|
14
15
|
for (const definition of definitions) {
|
|
15
|
-
if (visitedDefinitions.has(definition.id)) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
16
|
const { ownHash, moduleRecord } = definition;
|
|
17
|
+
// include module in the bundle signature
|
|
19
18
|
hash.update(ownHash);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// track the module to ensure it is only processed once
|
|
20
|
+
visitedDefinitions.add(getSpecifier(definition));
|
|
21
|
+
// map imports to prevent processing duplicates
|
|
22
|
+
moduleRecord.imports?.forEach((importReference) => {
|
|
23
|
+
imports.set(getSpecifier(importReference), importReference);
|
|
24
|
+
});
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// filter out bundle config exclusions and already visited dependencies
|
|
27
|
+
const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) =>
|
|
28
|
+
// exclusions are not versioned
|
|
29
|
+
!visitedDefinitions.has(dependency.specifier) &&
|
|
30
|
+
// already visited dependencies will be versioned
|
|
31
|
+
!visitedDefinitions.has(getSpecifier(dependency)));
|
|
32
|
+
if (dependencies.length) {
|
|
27
33
|
return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions);
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Generate a bundle signature
|
|
38
|
+
*
|
|
39
|
+
* Traverses the module graph from the specified root module to generate a
|
|
40
|
+
* signature. Modules that are marked for exclusion will be skipped. The
|
|
41
|
+
* bundle signature will be generated based on the environment
|
|
42
|
+
* keys(i.e. LWC version) and the ownHash of each module in the graph.
|
|
43
|
+
*
|
|
44
|
+
* @param moduleId - root module id
|
|
45
|
+
* @param registry - module registry
|
|
46
|
+
* @param exclude - bundle config exclusions
|
|
47
|
+
* @returns a bungle signature
|
|
48
|
+
*/
|
|
49
|
+
export async function getBundleSignature(moduleId, registry, exclude) {
|
|
32
50
|
const hash = crypto.createHash('sha1');
|
|
33
51
|
hash.update(ENV_KEY);
|
|
34
|
-
|
|
52
|
+
// add bundle config exclusions to visited definitions to prevent including
|
|
53
|
+
// them in the bundle signature
|
|
54
|
+
// Note: if the root module is an excluded module, it will be included in
|
|
55
|
+
// the signature
|
|
56
|
+
await getRecursiveModuleHash([moduleId], registry, hash, new Set(exclude));
|
|
35
57
|
return hash.digest('hex');
|
|
36
58
|
}
|
|
37
59
|
/**
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.7.0-alpha.2",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/diagnostics": "0.
|
|
34
|
-
"@lwrjs/shared-utils": "0.
|
|
33
|
+
"@lwrjs/diagnostics": "0.7.0-alpha.2",
|
|
34
|
+
"@lwrjs/shared-utils": "0.7.0-alpha.2",
|
|
35
35
|
"es-module-lexer": "^0.3.18",
|
|
36
36
|
"ws": "^7.2.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.
|
|
39
|
+
"@lwrjs/types": "0.7.0-alpha.2",
|
|
40
40
|
"@types/es-module-lexer": "^0.3.0",
|
|
41
41
|
"@types/ws": "^7.2.4"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=14.15.4 <17"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "fc3a13d1c5440833eb2ec17fbf0e294554bafa08"
|
|
47
47
|
}
|