@lwrjs/loader 0.24.2 → 0.24.3
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/assets/prod/lwr-error-shim.js +1 -1
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +22 -9
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +3 -3
- package/build/assets/prod/lwr-loader-shim-legacy.js +5 -5
- package/build/assets/prod/lwr-loader-shim.bundle.js +22 -9
- package/build/assets/prod/lwr-loader-shim.bundle.min.js +3 -3
- package/build/assets/prod/lwr-loader-shim.js +5 -5
- package/build/cjs/index.cjs +35 -25
- package/build/cjs/modules/lwr/esmLoader/esmLoader.cjs +32 -22
- package/build/cjs/modules/lwr/esmLoader/importResolver.cjs +23 -8
- package/build/cjs/modules/lwr/esmLoader/importResolverLegacy.cjs +24 -7
- package/build/cjs/modules/lwr/loader/constants/constants.cjs +20 -7
- package/build/cjs/modules/lwr/loader/errors/messages.cjs +15 -18
- package/build/cjs/modules/lwr/loader/errors/reportError.cjs +16 -20
- package/build/cjs/modules/lwr/loader/errors/utils.cjs +17 -4
- package/build/cjs/modules/lwr/loader/hooks/moduleInvalidation.cjs +18 -21
- package/build/cjs/modules/lwr/loader/hooks/resolveAndLoadHook.cjs +38 -37
- package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +46 -26
- package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +124 -76
- package/build/cjs/modules/lwr/loader/moduleRegistry/scriptLoad.cjs +16 -19
- package/build/cjs/modules/lwr/loader/utils/dom.cjs +17 -4
- package/build/cjs/modules/lwr/loader/utils/url.cjs +21 -25
- package/build/cjs/modules/lwr/loader/utils/validation.cjs +22 -7
- package/build/cjs/modules/lwr/loader/validateLoadSpecifier.cjs +18 -5
- package/build/cjs/modules/lwr/loaderLegacy/constants/constants.cjs +20 -7
- package/build/cjs/modules/lwr/loaderLegacy/errors/messages.cjs +15 -18
- package/build/cjs/modules/lwr/loaderLegacy/errors/reportError.cjs +16 -20
- package/build/cjs/modules/lwr/loaderLegacy/errors/utils.cjs +17 -4
- package/build/cjs/modules/lwr/loaderLegacy/hooks/moduleInvalidation.cjs +18 -21
- package/build/cjs/modules/lwr/loaderLegacy/hooks/resolveAndLoadHook.cjs +38 -37
- package/build/cjs/modules/lwr/loaderLegacy/importMap/dom.cjs +25 -25
- package/build/cjs/modules/lwr/loaderLegacy/importMap/importMap.cjs +32 -25
- package/build/cjs/modules/lwr/loaderLegacy/importMap/importMapResolver.cjs +16 -19
- package/build/cjs/modules/lwr/loaderLegacy/importMap/utils.cjs +15 -18
- package/build/cjs/modules/lwr/loaderLegacy/importResolver/importResolver.cjs +15 -2
- package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +105 -76
- package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/scriptLoad.cjs +16 -19
- package/build/cjs/modules/lwr/loaderLegacy/utils/dom.cjs +17 -4
- package/build/cjs/modules/lwr/loaderLegacy/utils/url.cjs +21 -25
- package/build/cjs/modules/lwr/loaderLegacy/utils/validation.cjs +18 -19
- package/build/cjs/package.d.cjs +1 -0
- package/build/cjs/types.cjs +15 -2
- package/build/modules/lwr/esmLoader/esmLoader.js +1 -1
- package/build/modules/lwr/loader/hooks/resolveAndLoadHook.js +15 -3
- package/build/modules/lwr/loader/loader.js +17 -4
- package/build/modules/lwr/loaderLegacy/hooks/resolveAndLoadHook.js +15 -3
- package/build/modules/lwr/loaderLegacy/loaderLegacy.js +17 -4
- package/package.json +6 -6
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
9
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
15
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
16
|
+
return to;
|
|
22
17
|
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
19
|
|
|
24
20
|
// packages/@lwrjs/loader/src/modules/lwr/loader/hooks/resolveAndLoadHook.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var resolveAndLoadHook_exports = {};
|
|
22
|
+
__export(resolveAndLoadHook_exports, {
|
|
27
23
|
evaluateLoadHook: () => evaluateLoadHook,
|
|
28
24
|
evaluateLoadHookResponse: () => evaluateLoadHookResponse,
|
|
29
25
|
isCustomResponse: () => isCustomResponse,
|
|
30
26
|
isFetchResponse: () => isFetchResponse,
|
|
31
27
|
isResponseAPromise: () => isResponseAPromise
|
|
32
28
|
});
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
29
|
+
module.exports = __toCommonJS(resolveAndLoadHook_exports);
|
|
30
|
+
var import_messages = require("../errors/messages.cjs");
|
|
31
|
+
var import_constants = require("../constants/constants.cjs");
|
|
32
|
+
var import_dom = require("../utils/dom.cjs");
|
|
33
|
+
var import_trusted_types = require("@locker/trusted-types");
|
|
37
34
|
var lastWindowError;
|
|
38
35
|
if (import_dom.hasDocument) {
|
|
39
36
|
globalThis.addEventListener("error", (evt) => {
|
|
40
37
|
lastWindowError = evt.error;
|
|
41
38
|
});
|
|
42
39
|
}
|
|
43
|
-
|
|
40
|
+
function resetLastWindowError() {
|
|
41
|
+
lastWindowError = null;
|
|
42
|
+
}
|
|
43
|
+
if (true) {
|
|
44
44
|
if (!import_dom.hasSetTimeout && import_dom.hasConsole) {
|
|
45
45
|
console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
function isCustomResponse(
|
|
49
|
-
return Object.prototype.hasOwnProperty.call(
|
|
48
|
+
function isCustomResponse(response2) {
|
|
49
|
+
return Object.prototype.hasOwnProperty.call(response2, "data") && !Object.prototype.hasOwnProperty.call(response2, "blob");
|
|
50
50
|
}
|
|
51
|
-
function isFetchResponse(
|
|
52
|
-
return typeof
|
|
51
|
+
function isFetchResponse(response2) {
|
|
52
|
+
return typeof response2.blob === "function";
|
|
53
53
|
}
|
|
54
|
-
function isResponseAPromise(
|
|
55
|
-
return !!(
|
|
54
|
+
function isResponseAPromise(response2) {
|
|
55
|
+
return !!(response2 && response2.then);
|
|
56
56
|
}
|
|
57
57
|
async function evaluateLoadHookResponse(response, id) {
|
|
58
58
|
return Promise.resolve().then(async () => {
|
|
@@ -76,34 +76,35 @@ async function evaluateLoadHookResponse(response, id) {
|
|
|
76
76
|
}
|
|
77
77
|
code = `${code}
|
|
78
78
|
//# sourceURL=${id}`;
|
|
79
|
+
resetLastWindowError();
|
|
79
80
|
try {
|
|
80
81
|
eval(import_trusted_types.trusted.createScript(code));
|
|
81
82
|
} catch (e) {
|
|
82
|
-
if (
|
|
83
|
+
if (import_dom.hasConsole) {
|
|
83
84
|
console.error(e);
|
|
84
85
|
}
|
|
85
86
|
throw new import_messages.LoaderError(import_messages.FAIL_LOAD, [`"${id}": ${e instanceof Error ? e.message : String(e)}`]);
|
|
86
87
|
}
|
|
87
88
|
if (lastWindowError) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
]);
|
|
89
|
+
const message = lastWindowError instanceof Error ? lastWindowError.message : String(lastWindowError);
|
|
90
|
+
resetLastWindowError();
|
|
91
|
+
throw new import_messages.LoaderError(import_messages.FAIL_LOAD, [`"${id}": window error ${message}`]);
|
|
91
92
|
}
|
|
92
93
|
return true;
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
|
-
async function evaluateLoadHook(
|
|
96
|
+
async function evaluateLoadHook(id2, hookPromise) {
|
|
96
97
|
if (!import_dom.hasSetTimeout) {
|
|
97
98
|
return hookPromise;
|
|
98
99
|
}
|
|
99
100
|
return new Promise((resolve, reject) => {
|
|
100
101
|
const timer = setTimeout(() => {
|
|
101
|
-
reject(new import_messages.LoaderError(import_messages.MODULE_LOAD_TIMEOUT, [
|
|
102
|
+
reject(new import_messages.LoaderError(import_messages.MODULE_LOAD_TIMEOUT, [id2]));
|
|
102
103
|
}, import_constants.MODULE_LOAD_TIMEOUT_TIMER);
|
|
103
|
-
hookPromise.then((
|
|
104
|
-
resolve(
|
|
104
|
+
hookPromise.then((response2) => {
|
|
105
|
+
resolve(response2);
|
|
105
106
|
}).catch(() => {
|
|
106
|
-
reject(new import_messages.LoaderError(import_messages.FAIL_HOOK_LOAD, [
|
|
107
|
+
reject(new import_messages.LoaderError(import_messages.FAIL_HOOK_LOAD, [id2]));
|
|
107
108
|
}).finally(() => {
|
|
108
109
|
clearTimeout(timer);
|
|
109
110
|
});
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
9
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
15
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
16
|
+
return to;
|
|
22
17
|
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
19
|
|
|
24
20
|
// packages/@lwrjs/loader/src/modules/lwr/loader/moduleRegistry/importMetadataResolver.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var importMetadataResolver_exports = {};
|
|
22
|
+
__export(importMetadataResolver_exports, {
|
|
27
23
|
ImportMetadataResolver: () => ImportMetadataResolver
|
|
28
24
|
});
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
25
|
+
module.exports = __toCommonJS(importMetadataResolver_exports);
|
|
26
|
+
var import_messages = require("../errors/messages.cjs");
|
|
27
|
+
var import_url = require("../utils/url.cjs");
|
|
28
|
+
var import_metrics = require("lwr/metrics");
|
|
32
29
|
var ImportMetadataResolver = class {
|
|
33
30
|
constructor(config, invalidationCallback) {
|
|
34
|
-
|
|
35
|
-
this.
|
|
31
|
+
// Default to empty mappings
|
|
32
|
+
this.importURICache = /* @__PURE__ */ new Map();
|
|
33
|
+
this.pendingURICache = /* @__PURE__ */ new Map();
|
|
36
34
|
this.loadMappingHooks = [];
|
|
37
35
|
this.config = config;
|
|
38
36
|
this.invalidationCallback = invalidationCallback;
|
|
@@ -92,9 +90,16 @@ var ImportMetadataResolver = class {
|
|
|
92
90
|
});
|
|
93
91
|
}
|
|
94
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the raw URI stored for a specifier, or `undefined` if not yet mapped.
|
|
95
|
+
* Used by the runtime `importMap()` path to detect cross-call duplicates while
|
|
96
|
+
* allowing truly idempotent re-registrations (same specifier, same URI) to pass
|
|
97
|
+
* through silently.
|
|
98
|
+
*/
|
|
95
99
|
getMappingUri(specifier) {
|
|
96
100
|
return this.importURICache.get(specifier)?.uri;
|
|
97
101
|
}
|
|
102
|
+
// Get URL from the local cache or return undefiend
|
|
98
103
|
getURI(specifier) {
|
|
99
104
|
return this.importURICache && this.importURICache.has(specifier) ? (0, import_url.resolveUrl)(this.importURICache.get(specifier).uri, this.getBaseUrl()) : void 0;
|
|
100
105
|
}
|
|
@@ -107,6 +112,16 @@ var ImportMetadataResolver = class {
|
|
|
107
112
|
}
|
|
108
113
|
return void 0;
|
|
109
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Resolves a the URI for a specified module. It will return the value in this order:
|
|
117
|
+
*
|
|
118
|
+
* 1) Mapping from local URI cache
|
|
119
|
+
* 2) The URI if a specifier is already an absolute URI
|
|
120
|
+
* 3) Mapping fetched from a registered loader hook
|
|
121
|
+
* 4)
|
|
122
|
+
* @param specifier
|
|
123
|
+
* @returns module URI
|
|
124
|
+
*/
|
|
110
125
|
async resolve(specifier) {
|
|
111
126
|
let uri = this.getURI(specifier);
|
|
112
127
|
if (uri) {
|
|
@@ -118,7 +133,7 @@ var ImportMetadataResolver = class {
|
|
|
118
133
|
if (pending) {
|
|
119
134
|
return pending;
|
|
120
135
|
}
|
|
121
|
-
this.config.profiler.logOperationStart({id: import_metrics.MAPPINGS_FETCH, specifier});
|
|
136
|
+
this.config.profiler.logOperationStart({ id: import_metrics.MAPPINGS_FETCH, specifier });
|
|
122
137
|
const fetchMappingService = this.hasMappingHooks() ? this.evaluateMappingHooks : this.fetchNewMappings;
|
|
123
138
|
const promise = fetchMappingService.bind(this)(specifier).then((importMetadata) => {
|
|
124
139
|
if (!importMetadata || !importMetadata.imports) {
|
|
@@ -129,7 +144,7 @@ var ImportMetadataResolver = class {
|
|
|
129
144
|
if (!uri) {
|
|
130
145
|
throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
|
|
131
146
|
}
|
|
132
|
-
this.config.profiler.logOperationEnd({id: import_metrics.MAPPINGS_FETCH, specifier});
|
|
147
|
+
this.config.profiler.logOperationEnd({ id: import_metrics.MAPPINGS_FETCH, specifier });
|
|
133
148
|
return uri;
|
|
134
149
|
}).finally(() => {
|
|
135
150
|
this.pendingURICache.delete(specifier);
|
|
@@ -141,13 +156,18 @@ var ImportMetadataResolver = class {
|
|
|
141
156
|
hasMappingHooks() {
|
|
142
157
|
return this.loadMappingHooks.length > 0;
|
|
143
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Evaluates mapping hooks. Returns first match. If all hooks return null call the mapping service.
|
|
161
|
+
* @param specifier Request module identifier
|
|
162
|
+
* @returns Import Metadata from the module root
|
|
163
|
+
*/
|
|
144
164
|
async evaluateMappingHooks(specifier) {
|
|
145
165
|
const loadMappingHooks = this.loadMappingHooks;
|
|
146
166
|
if (loadMappingHooks.length) {
|
|
147
167
|
const knownModules = Array.from(this.importURICache.keys());
|
|
148
168
|
for (let i = 0; i < loadMappingHooks.length; i++) {
|
|
149
169
|
const loadMappingHook = loadMappingHooks[i];
|
|
150
|
-
const response = await loadMappingHook(specifier, {knownModules});
|
|
170
|
+
const response = await loadMappingHook(specifier, { knownModules });
|
|
151
171
|
if (response || response === void 0) {
|
|
152
172
|
return response;
|
|
153
173
|
}
|
|
@@ -165,7 +185,7 @@ var ImportMetadataResolver = class {
|
|
|
165
185
|
}
|
|
166
186
|
return globalThis.fetch(uri).then((res) => {
|
|
167
187
|
if (!res.ok) {
|
|
168
|
-
this.config.profiler.logOperationStart({id: import_metrics.MAPPINGS_ERROR, specifier});
|
|
188
|
+
this.config.profiler.logOperationStart({ id: import_metrics.MAPPINGS_ERROR, specifier });
|
|
169
189
|
throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
|
|
170
190
|
}
|
|
171
191
|
return res.json().then((ret) => {
|
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
9
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
15
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
16
|
+
return to;
|
|
22
17
|
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
19
|
|
|
24
20
|
// packages/@lwrjs/loader/src/modules/lwr/loader/moduleRegistry/moduleRegistry.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var moduleRegistry_exports = {};
|
|
22
|
+
__export(moduleRegistry_exports, {
|
|
27
23
|
ModuleRegistry: () => ModuleRegistry
|
|
28
24
|
});
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
25
|
+
module.exports = __toCommonJS(moduleRegistry_exports);
|
|
26
|
+
var import_messages = require("../errors/messages.cjs");
|
|
27
|
+
var import_url = require("../utils/url.cjs");
|
|
28
|
+
var import_dom = require("../utils/dom.cjs");
|
|
29
|
+
var import_scriptLoad = require("./scriptLoad.cjs");
|
|
30
|
+
var import_importMetadataResolver = require("./importMetadataResolver.cjs");
|
|
31
|
+
var import_moduleInvalidation = require("../hooks/moduleInvalidation.cjs");
|
|
32
|
+
var import_resolveAndLoadHook = require("../hooks/resolveAndLoadHook.cjs");
|
|
33
|
+
var import_metrics = require("lwr/metrics");
|
|
34
|
+
var import_constants = require("../constants/constants.cjs");
|
|
38
35
|
var ModuleRegistry = class {
|
|
39
36
|
constructor(config) {
|
|
40
37
|
this.isAppMounted = false;
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
|
|
38
|
+
// A registry for named AMD defines containing the *metadata* of AMD module
|
|
39
|
+
this.namedDefineRegistry = /* @__PURE__ */ new Map();
|
|
40
|
+
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
41
|
+
this.moduleRegistry = /* @__PURE__ */ new Map();
|
|
42
|
+
// Aliases of modules in the registry
|
|
43
|
+
this.aliases = /* @__PURE__ */ new Map();
|
|
44
44
|
this.profiler = config.profiler;
|
|
45
|
-
this.resolver = new import_importMetadataResolver.ImportMetadataResolver(
|
|
45
|
+
this.resolver = new import_importMetadataResolver.ImportMetadataResolver(
|
|
46
|
+
config,
|
|
47
|
+
this.importMetadataInvalidationCallback.bind(this)
|
|
48
|
+
);
|
|
46
49
|
this.warnings = {
|
|
47
50
|
[import_constants.MODULE_WARNING.MODULE_REDEFINE]: [],
|
|
48
51
|
[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
|
|
@@ -50,7 +53,7 @@ var ModuleRegistry = class {
|
|
|
50
53
|
};
|
|
51
54
|
}
|
|
52
55
|
async load(id, importer) {
|
|
53
|
-
const metadata = importer ? {importer} : {};
|
|
56
|
+
const metadata = importer ? { importer } : {};
|
|
54
57
|
this.profiler.logOperationStart({
|
|
55
58
|
id: import_metrics.MODULE_DYNAMIC_LOAD,
|
|
56
59
|
specifier: id,
|
|
@@ -75,7 +78,7 @@ var ModuleRegistry = class {
|
|
|
75
78
|
if (resolveHooks) {
|
|
76
79
|
for (let i = 0; i < resolveHooks.length; i++) {
|
|
77
80
|
const resolveHook = resolveHooks[i];
|
|
78
|
-
const response = resolveHook(aliasedId, {parentUrl});
|
|
81
|
+
const response = resolveHook(aliasedId, { parentUrl });
|
|
79
82
|
let result;
|
|
80
83
|
if (response || response === null) {
|
|
81
84
|
result = (0, import_resolveAndLoadHook.isResponseAPromise)(response) ? await response : response;
|
|
@@ -114,7 +117,9 @@ var ModuleRegistry = class {
|
|
|
114
117
|
const resolvedUrl = this.resolver.resolveLocal(resolvedOrPlain);
|
|
115
118
|
if (resolvedUrl) {
|
|
116
119
|
if (this.namedDefineRegistry.has(resolvedOrPlain)) {
|
|
117
|
-
const namedDefineRecord = this.namedDefineRegistry.get(
|
|
120
|
+
const namedDefineRecord = this.namedDefineRegistry.get(
|
|
121
|
+
resolvedOrPlain
|
|
122
|
+
);
|
|
118
123
|
if (namedDefineRecord.external || namedDefineRecord.defined) {
|
|
119
124
|
const record = this.moduleRegistry.get(resolvedUrl);
|
|
120
125
|
if (!record || !this.aliases.has(resolvedOrPlain)) {
|
|
@@ -149,7 +154,12 @@ var ModuleRegistry = class {
|
|
|
149
154
|
define(name, dependencies, exporter) {
|
|
150
155
|
const mod = this.namedDefineRegistry.get(name);
|
|
151
156
|
if (mod && mod.defined) {
|
|
152
|
-
if (
|
|
157
|
+
if (
|
|
158
|
+
// note: we always expect process.env.NODE_ENV to be replaced at build time
|
|
159
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
160
|
+
import_dom.hasProcessEnv && // eslint-disable-next-line lwr/no-unguarded-apis
|
|
161
|
+
process.env.MRT_HMR !== "true"
|
|
162
|
+
) {
|
|
153
163
|
if (!this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
|
|
154
164
|
this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].push(name);
|
|
155
165
|
}
|
|
@@ -169,10 +179,15 @@ var ModuleRegistry = class {
|
|
|
169
179
|
if (mod && mod.external) {
|
|
170
180
|
mod.external.resolveExternal(moduleDef);
|
|
171
181
|
}
|
|
172
|
-
this.profiler.logOperationStart({id: import_metrics.MODULE_DEFINE, specifier: name});
|
|
182
|
+
this.profiler.logOperationStart({ id: import_metrics.MODULE_DEFINE, specifier: name });
|
|
173
183
|
this.namedDefineRegistry.set(name, moduleDef);
|
|
174
184
|
this.lastDefine = moduleDef;
|
|
175
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Marks modules as "externally" loaded/provided, so that the loader does not attempt to fetch them.
|
|
188
|
+
*
|
|
189
|
+
* @param modules - list of module identifiers
|
|
190
|
+
*/
|
|
176
191
|
registerExternalModules(modules) {
|
|
177
192
|
modules.map((id) => {
|
|
178
193
|
if (!this.namedDefineRegistry.has(id)) {
|
|
@@ -195,7 +210,7 @@ var ModuleRegistry = class {
|
|
|
195
210
|
}
|
|
196
211
|
};
|
|
197
212
|
this.namedDefineRegistry.set(id, moduleDef);
|
|
198
|
-
} else if (
|
|
213
|
+
} else if (true) {
|
|
199
214
|
if (!this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
|
|
200
215
|
this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
|
|
201
216
|
}
|
|
@@ -208,6 +223,18 @@ var ModuleRegistry = class {
|
|
|
208
223
|
getImportMetadataResolver() {
|
|
209
224
|
return this.resolver;
|
|
210
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Gets or creates a module record for the given resolved ID and original ID.
|
|
228
|
+
*
|
|
229
|
+
* This function handles the complex logic of module resolution and ensures that:
|
|
230
|
+
* 1. Modules loaded via different paths (aliases, direct specifiers, URLs) return the same instance
|
|
231
|
+
* 2. Bundle URLs are properly resolved to their final specifier names after instantiation
|
|
232
|
+
* 3. Alias mappings are maintained for future lookups
|
|
233
|
+
*
|
|
234
|
+
* @param resolvedId - The resolved module identifier (could be a URL or specifier)
|
|
235
|
+
* @param originalId - The original module specifer that was requested
|
|
236
|
+
* @returns Promise<ModuleRecord> - The module record for the module
|
|
237
|
+
*/
|
|
211
238
|
async getModuleRecord(resolvedId, originalId) {
|
|
212
239
|
const existingRecord = this.moduleRegistry.get(resolvedId);
|
|
213
240
|
if (existingRecord) {
|
|
@@ -253,12 +280,19 @@ var ModuleRegistry = class {
|
|
|
253
280
|
});
|
|
254
281
|
const newModuleRecord = {
|
|
255
282
|
id: resolvedId,
|
|
283
|
+
// Use resolved ID as the record identifier
|
|
256
284
|
originalId,
|
|
257
|
-
|
|
285
|
+
// Keep track of the original requested ID
|
|
286
|
+
module: /* @__PURE__ */ Object.create(null),
|
|
287
|
+
// Empty object for module exports
|
|
258
288
|
dependencyRecords,
|
|
289
|
+
// Promise for dependency module records
|
|
259
290
|
instantiation,
|
|
291
|
+
// Promise for module definition
|
|
260
292
|
evaluated: false,
|
|
293
|
+
// Track if module has been evaluated
|
|
261
294
|
evaluationPromise: null
|
|
295
|
+
// Promise for module evaluation
|
|
262
296
|
};
|
|
263
297
|
this.moduleRegistry.set(resolvedId, newModuleRecord);
|
|
264
298
|
if (resolvedId !== originalId) {
|
|
@@ -270,7 +304,7 @@ var ModuleRegistry = class {
|
|
|
270
304
|
if (aliasId !== resolvedId) {
|
|
271
305
|
if (!this.aliases.has(aliasId)) {
|
|
272
306
|
this.aliases.set(aliasId, resolvedId);
|
|
273
|
-
} else if (
|
|
307
|
+
} else if (import_dom.hasConsole) {
|
|
274
308
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
275
309
|
if (currentResolvedId !== resolvedId) {
|
|
276
310
|
const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
|
|
@@ -295,6 +329,7 @@ var ModuleRegistry = class {
|
|
|
295
329
|
}
|
|
296
330
|
return this.getModuleRecord(resolvedDepId, dependency);
|
|
297
331
|
}
|
|
332
|
+
// execute the "top-level code" (the code outside of functions) of a module
|
|
298
333
|
async topLevelEvaluation(moduleRecord) {
|
|
299
334
|
return this.evaluateModule(moduleRecord, {});
|
|
300
335
|
}
|
|
@@ -304,26 +339,28 @@ var ModuleRegistry = class {
|
|
|
304
339
|
evaluationMap[moduleRecord.id] = true;
|
|
305
340
|
await this.evaluateModuleDependencies(dependencyModuleRecords, evaluationMap);
|
|
306
341
|
}
|
|
307
|
-
const {exporter, dependencies} = await moduleRecord.instantiation;
|
|
308
|
-
const
|
|
309
|
-
const depsMapped = dependencies ? await Promise.all(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
342
|
+
const { exporter, dependencies } = await moduleRecord.instantiation;
|
|
343
|
+
const exports = {};
|
|
344
|
+
const depsMapped = dependencies ? await Promise.all(
|
|
345
|
+
dependencies.map(async (dep) => {
|
|
346
|
+
if (dep === "exports") {
|
|
347
|
+
return exports;
|
|
348
|
+
}
|
|
349
|
+
const resolvedDepId = await this.resolve(dep);
|
|
350
|
+
const moduleRecord2 = this.moduleRegistry.get(resolvedDepId);
|
|
351
|
+
if (!moduleRecord2) {
|
|
352
|
+
throw new import_messages.LoaderError(import_messages.FAILED_DEP, [resolvedDepId]);
|
|
353
|
+
}
|
|
354
|
+
const module2 = moduleRecord2.module;
|
|
355
|
+
if (!moduleRecord2.evaluated) {
|
|
356
|
+
return this.getCircularDependencyWrapper(module2);
|
|
357
|
+
}
|
|
358
|
+
if (module2) {
|
|
359
|
+
return module2.__defaultInterop ? module2.default : module2;
|
|
360
|
+
}
|
|
316
361
|
throw new import_messages.LoaderError(import_messages.FAILED_DEP, [resolvedDepId]);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (!moduleRecord2.evaluated) {
|
|
320
|
-
return this.getCircularDependencyWrapper(module2);
|
|
321
|
-
}
|
|
322
|
-
if (module2) {
|
|
323
|
-
return module2.__defaultInterop ? module2.default : module2;
|
|
324
|
-
}
|
|
325
|
-
throw new import_messages.LoaderError(import_messages.FAILED_DEP, [resolvedDepId]);
|
|
326
|
-
})) : [];
|
|
362
|
+
})
|
|
363
|
+
) : [];
|
|
327
364
|
if (moduleRecord.evaluated) {
|
|
328
365
|
return moduleRecord.module;
|
|
329
366
|
}
|
|
@@ -334,14 +371,14 @@ var ModuleRegistry = class {
|
|
|
334
371
|
throw new import_messages.LoaderError(import_messages.EXPORTER_ERROR, [moduleRecord.id, e.message || e]);
|
|
335
372
|
}
|
|
336
373
|
if (moduleDefault !== void 0) {
|
|
337
|
-
moduleDefault = {default: moduleDefault};
|
|
338
|
-
Object.defineProperty(moduleDefault, "__defaultInterop", {value: true});
|
|
374
|
+
moduleDefault = { default: moduleDefault };
|
|
375
|
+
Object.defineProperty(moduleDefault, "__defaultInterop", { value: true });
|
|
339
376
|
} else {
|
|
340
|
-
if (this.isNamedExportDefaultOnly(
|
|
341
|
-
Object.defineProperty(
|
|
377
|
+
if (this.isNamedExportDefaultOnly(exports)) {
|
|
378
|
+
Object.defineProperty(exports, "__useDefault", { value: true });
|
|
342
379
|
}
|
|
343
380
|
}
|
|
344
|
-
const moduleExports = moduleDefault ||
|
|
381
|
+
const moduleExports = moduleDefault || exports;
|
|
345
382
|
for (const key in moduleExports) {
|
|
346
383
|
Object.defineProperty(moduleRecord.module, key, {
|
|
347
384
|
enumerable: true,
|
|
@@ -354,21 +391,24 @@ var ModuleRegistry = class {
|
|
|
354
391
|
});
|
|
355
392
|
}
|
|
356
393
|
if (moduleExports.__useDefault) {
|
|
357
|
-
Object.defineProperty(moduleRecord.module, "__useDefault", {value: true});
|
|
394
|
+
Object.defineProperty(moduleRecord.module, "__useDefault", { value: true });
|
|
358
395
|
}
|
|
359
396
|
if (moduleExports.__defaultInterop) {
|
|
360
|
-
Object.defineProperty(moduleRecord.module, "__defaultInterop", {value: true});
|
|
397
|
+
Object.defineProperty(moduleRecord.module, "__defaultInterop", { value: true });
|
|
361
398
|
}
|
|
362
399
|
if (moduleExports.__esModule) {
|
|
363
|
-
Object.defineProperty(moduleRecord.module, "__esModule", {value: true});
|
|
400
|
+
Object.defineProperty(moduleRecord.module, "__esModule", { value: true });
|
|
364
401
|
}
|
|
365
402
|
moduleRecord.evaluated = true;
|
|
366
403
|
Object.freeze(moduleRecord.module);
|
|
367
404
|
return moduleRecord.module;
|
|
368
405
|
}
|
|
369
|
-
|
|
370
|
-
|
|
406
|
+
// Determines if named exports module has only default export
|
|
407
|
+
isNamedExportDefaultOnly(exports) {
|
|
408
|
+
return exports !== void 0 && Object.getOwnPropertyNames(exports).length === 2 && Object.prototype.hasOwnProperty.call(exports, "default") && Object.prototype.hasOwnProperty.call(exports, "__esModule");
|
|
371
409
|
}
|
|
410
|
+
// Wrap the dependency in a function that can be called and detected by __circular__ property.
|
|
411
|
+
// The LWC engine checks for __circular__ to detect circular dependencies.
|
|
372
412
|
getCircularDependencyWrapper(module2) {
|
|
373
413
|
const tmp = () => {
|
|
374
414
|
return module2.__useDefault || module2.__defaultInterop ? module2.default : module2;
|
|
@@ -397,14 +437,17 @@ var ModuleRegistry = class {
|
|
|
397
437
|
}
|
|
398
438
|
const parentUrl = this.resolver.getBaseUrl();
|
|
399
439
|
const specifier = moduleName || originalId;
|
|
400
|
-
this.profiler.logOperationStart({id: import_metrics.MODULE_FETCH, specifier});
|
|
440
|
+
this.profiler.logOperationStart({ id: import_metrics.MODULE_FETCH, specifier });
|
|
401
441
|
return Promise.resolve().then(async () => {
|
|
402
442
|
const loadHooks = this.loadHook;
|
|
403
443
|
if (loadHooks) {
|
|
404
444
|
for (let i = 0; i < loadHooks.length; i++) {
|
|
405
445
|
const loadHook = loadHooks[i];
|
|
406
446
|
const response = loadHook(resolvedId, parentUrl);
|
|
407
|
-
const result = (0, import_resolveAndLoadHook.isResponseAPromise)(response) ?
|
|
447
|
+
const result = (0, import_resolveAndLoadHook.isResponseAPromise)(response) ? (
|
|
448
|
+
// eslint-disable-next-line no-await-in-loop
|
|
449
|
+
await (0, import_resolveAndLoadHook.evaluateLoadHook)(resolvedId, response)
|
|
450
|
+
) : response;
|
|
408
451
|
if (result === void 0) {
|
|
409
452
|
throw new import_messages.LoaderError(import_messages.INVALID_LOADER_SERVICE_RESPONSE);
|
|
410
453
|
}
|
|
@@ -421,17 +464,20 @@ var ModuleRegistry = class {
|
|
|
421
464
|
}).then(() => {
|
|
422
465
|
moduleDef = moduleName && this.namedDefineRegistry.get(moduleName);
|
|
423
466
|
if (!moduleDef) {
|
|
424
|
-
this.logMessage(
|
|
467
|
+
this.logMessage(
|
|
468
|
+
"warning",
|
|
469
|
+
`${moduleName} not found, falling back to the last loader.define call`
|
|
470
|
+
);
|
|
425
471
|
moduleDef = this.lastDefine;
|
|
426
472
|
}
|
|
427
473
|
if (!moduleDef) {
|
|
428
474
|
throw new import_messages.LoaderError(import_messages.FAIL_INSTANTIATE, [resolvedId]);
|
|
429
475
|
}
|
|
430
|
-
this.profiler.logOperationEnd({id: import_metrics.MODULE_FETCH, specifier});
|
|
476
|
+
this.profiler.logOperationEnd({ id: import_metrics.MODULE_FETCH, specifier });
|
|
431
477
|
return moduleDef;
|
|
432
478
|
}).catch((e) => {
|
|
433
479
|
if (!(e instanceof import_messages.LoaderError)) {
|
|
434
|
-
this.profiler.logOperationStart({id: import_metrics.MODULE_ERROR, specifier});
|
|
480
|
+
this.profiler.logOperationStart({ id: import_metrics.MODULE_ERROR, specifier });
|
|
435
481
|
}
|
|
436
482
|
throw e;
|
|
437
483
|
});
|
|
@@ -440,7 +486,7 @@ var ModuleRegistry = class {
|
|
|
440
486
|
if (typeof hooks !== "object") {
|
|
441
487
|
throw new import_messages.LoaderError(import_messages.INVALID_HOOK);
|
|
442
488
|
}
|
|
443
|
-
const {loadModule: loadHook, resolveModule: resolveHook, loadMapping} = hooks;
|
|
489
|
+
const { loadModule: loadHook, resolveModule: resolveHook, loadMapping } = hooks;
|
|
444
490
|
if (resolveHook) {
|
|
445
491
|
if (this.resolveHook) {
|
|
446
492
|
this.resolveHook.push(resolveHook);
|
|
@@ -459,7 +505,7 @@ var ModuleRegistry = class {
|
|
|
459
505
|
this.resolver.addLoadMappingHook(loadMapping);
|
|
460
506
|
}
|
|
461
507
|
}
|
|
462
|
-
importMetadataInvalidationCallback({name, oldUrl, newUrl}) {
|
|
508
|
+
importMetadataInvalidationCallback({ name, oldUrl, newUrl }) {
|
|
463
509
|
const handleStaleModuleHooks = this.handleStaleModuleHook;
|
|
464
510
|
if (handleStaleModuleHooks) {
|
|
465
511
|
(0, import_moduleInvalidation.evaluateHandleStaleModuleHooks)(handleStaleModuleHooks, {
|
|
@@ -468,7 +514,7 @@ var ModuleRegistry = class {
|
|
|
468
514
|
newUrl
|
|
469
515
|
});
|
|
470
516
|
} else {
|
|
471
|
-
if (
|
|
517
|
+
if (import_dom.hasConsole) {
|
|
472
518
|
console.warn(`stale module detected ${name}, current URL:${oldUrl}, new URL:${newUrl}`);
|
|
473
519
|
}
|
|
474
520
|
}
|
|
@@ -488,7 +534,9 @@ var ModuleRegistry = class {
|
|
|
488
534
|
return this.warnings;
|
|
489
535
|
}
|
|
490
536
|
logMessage(logType, message) {
|
|
491
|
-
if (!import_dom.hasConsole ||
|
|
537
|
+
if (!import_dom.hasConsole || // note: we always expect this to be replaced at build time
|
|
538
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
539
|
+
false) {
|
|
492
540
|
return;
|
|
493
541
|
}
|
|
494
542
|
if (logType == "warning") {
|