@lwrjs/loader 0.17.2-alpha.3 → 0.17.2-alpha.5
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 +95 -25
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +4 -3
- package/build/assets/prod/lwr-loader-shim-legacy.js +27 -6
- package/build/assets/prod/lwr-loader-shim.bundle.js +93 -24
- package/build/assets/prod/lwr-loader-shim.bundle.min.js +4 -3
- package/build/assets/prod/lwr-loader-shim.js +27 -6
- package/build/cjs/modules/lwr/loader/constants/constants.cjs +8 -1
- package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +40 -6
- package/build/cjs/modules/lwr/loaderLegacy/constants/constants.cjs +8 -1
- package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +41 -7
- package/build/modules/lwr/esmLoader/esmLoader.js +1 -1
- package/build/modules/lwr/loader/constants/constants.d.ts +5 -0
- package/build/modules/lwr/loader/constants/constants.js +6 -0
- package/build/modules/lwr/loader/loader.d.ts +1 -0
- package/build/modules/lwr/loader/loader.js +66 -18
- package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.d.ts +4 -0
- package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.js +48 -14
- package/build/modules/lwr/loaderLegacy/constants/constants.d.ts +5 -0
- package/build/modules/lwr/loaderLegacy/constants/constants.js +6 -0
- package/build/modules/lwr/loaderLegacy/loaderLegacy.d.ts +1 -0
- package/build/modules/lwr/loaderLegacy/loaderLegacy.js +68 -19
- package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.d.ts +4 -0
- package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.js +50 -15
- package/build/shim/shim.d.ts +1 -0
- package/build/shim/shim.js +18 -1
- package/build/shim-legacy/shimLegacy.d.ts +1 -0
- package/build/shim-legacy/shimLegacy.js +18 -1
- package/build/types.d.ts +1 -0
- package/package.json +6 -6
|
@@ -36,11 +36,17 @@ var import_constants = __toModule(require("../constants/constants.cjs"));
|
|
|
36
36
|
var import_metrics = __toModule(require("lwr/metrics"));
|
|
37
37
|
var ModuleRegistry = class {
|
|
38
38
|
constructor(config) {
|
|
39
|
+
this.isAppMounted = false;
|
|
39
40
|
this.namedDefineRegistry = new Map();
|
|
40
41
|
this.moduleRegistry = new Map();
|
|
41
42
|
this.aliases = new Map();
|
|
42
43
|
this.baseUrl = config.baseUrl || "";
|
|
43
44
|
this.profiler = config.profiler;
|
|
45
|
+
this.warnings = {
|
|
46
|
+
[import_constants.MODULE_WARNING.MODULE_REDEFINE]: [],
|
|
47
|
+
[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
|
|
48
|
+
[import_constants.MODULE_WARNING.ALIAS_UPDATE]: []
|
|
49
|
+
};
|
|
44
50
|
}
|
|
45
51
|
clearRegistry() {
|
|
46
52
|
this.moduleRegistry = new Map();
|
|
@@ -142,8 +148,13 @@ var ModuleRegistry = class {
|
|
|
142
148
|
define(name, dependencies, exporter, signatures) {
|
|
143
149
|
const mod = this.namedDefineRegistry.get(name);
|
|
144
150
|
if (mod && mod.defined) {
|
|
145
|
-
if (import_dom.hasProcessEnv && process.env.NODE_ENV !== "production" && process.env.MRT_HMR !== "true"
|
|
146
|
-
|
|
151
|
+
if (import_dom.hasProcessEnv && process.env.NODE_ENV !== "production" && process.env.MRT_HMR !== "true") {
|
|
152
|
+
if (!this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
|
|
153
|
+
this.warnings[import_constants.MODULE_WARNING.MODULE_REDEFINE].push(name);
|
|
154
|
+
}
|
|
155
|
+
if (this.isAppMounted) {
|
|
156
|
+
this.logMessage("warning", `${import_constants.MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
|
|
157
|
+
}
|
|
147
158
|
}
|
|
148
159
|
this.lastDefine = mod;
|
|
149
160
|
return;
|
|
@@ -189,8 +200,13 @@ var ModuleRegistry = class {
|
|
|
189
200
|
}
|
|
190
201
|
};
|
|
191
202
|
this.namedDefineRegistry.set(id, moduleDef);
|
|
192
|
-
} else if (process.env.NODE_ENV !== "production"
|
|
193
|
-
|
|
203
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
204
|
+
if (!this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
|
|
205
|
+
this.warnings[import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
|
|
206
|
+
}
|
|
207
|
+
if (this.isAppMounted) {
|
|
208
|
+
this.logMessage("warning", `${import_constants.MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
|
|
209
|
+
}
|
|
194
210
|
}
|
|
195
211
|
});
|
|
196
212
|
}
|
|
@@ -276,11 +292,15 @@ var ModuleRegistry = class {
|
|
|
276
292
|
if (aliasId !== resolvedId) {
|
|
277
293
|
if (!this.aliases.has(aliasId)) {
|
|
278
294
|
this.aliases.set(aliasId, resolvedId);
|
|
279
|
-
} else if (import_dom.hasConsole) {
|
|
295
|
+
} else if (import_dom.hasConsole && process.env.NODE_ENV !== "production") {
|
|
280
296
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
281
297
|
if (currentResolvedId !== resolvedId) {
|
|
282
|
-
|
|
283
|
-
|
|
298
|
+
const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
|
|
299
|
+
if (!this.warnings[import_constants.MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
|
|
300
|
+
this.warnings[import_constants.MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
|
|
301
|
+
}
|
|
302
|
+
if (this.isAppMounted) {
|
|
303
|
+
this.logMessage("warning", `${import_constants.MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
|
|
284
304
|
}
|
|
285
305
|
}
|
|
286
306
|
}
|
|
@@ -473,4 +493,18 @@ var ModuleRegistry = class {
|
|
|
473
493
|
isValidResolveResponse(res) {
|
|
474
494
|
return res === null || typeof res === "string" || res && typeof res.url === "string";
|
|
475
495
|
}
|
|
496
|
+
getModuleWarnings(isAppMounted = false) {
|
|
497
|
+
this.isAppMounted = isAppMounted;
|
|
498
|
+
return this.warnings;
|
|
499
|
+
}
|
|
500
|
+
logMessage(logType, message) {
|
|
501
|
+
if (!import_dom.hasProcessEnv || !import_dom.hasConsole || process.env.NODE_ENV === "production") {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (logType == "warning") {
|
|
505
|
+
console.warn(message);
|
|
506
|
+
} else {
|
|
507
|
+
console.log(message);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
476
510
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR ESM Module Loader v0.17.2-alpha.
|
|
7
|
+
/* LWR ESM Module Loader v0.17.2-alpha.5 */
|
|
8
8
|
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
9
9
|
|
|
10
10
|
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare const MODULE_LOAD_TIMEOUT_TIMER: number;
|
|
2
|
+
export declare enum MODULE_WARNING {
|
|
3
|
+
MODULE_REDEFINE = "Module redefine attempted",
|
|
4
|
+
MODULE_ALREADY_LOADED = "Marking module(s) as externally loaded, but they are already loaded",
|
|
5
|
+
ALIAS_UPDATE = "Alias update attempt"
|
|
6
|
+
}
|
|
2
7
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
|
|
2
|
+
export var MODULE_WARNING;
|
|
3
|
+
(function (MODULE_WARNING) {
|
|
4
|
+
MODULE_WARNING["MODULE_REDEFINE"] = "Module redefine attempted";
|
|
5
|
+
MODULE_WARNING["MODULE_ALREADY_LOADED"] = "Marking module(s) as externally loaded, but they are already loaded";
|
|
6
|
+
MODULE_WARNING["ALIAS_UPDATE"] = "Alias update attempt";
|
|
7
|
+
})(MODULE_WARNING || (MODULE_WARNING = {}));
|
|
2
8
|
//# sourceMappingURL=constants.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Module Loader v0.17.2-alpha.
|
|
7
|
+
/* LWR Module Loader v0.17.2-alpha.5 */
|
|
8
8
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
function templateString(template, args) {
|
|
@@ -108,7 +108,7 @@ const STALE_HOOK_ERROR = Object.freeze({
|
|
|
108
108
|
level: 0,
|
|
109
109
|
message: 'An error occurred handling module conflict',
|
|
110
110
|
});
|
|
111
|
-
|
|
111
|
+
Object.freeze({
|
|
112
112
|
code: 3017,
|
|
113
113
|
level: 0,
|
|
114
114
|
message: 'Marking module(s) as externally loaded, but they are already loaded:',
|
|
@@ -597,6 +597,12 @@ function evaluateHandleStaleModuleHooks(
|
|
|
597
597
|
|
|
598
598
|
const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
|
|
599
599
|
|
|
600
|
+
var MODULE_WARNING; (function (MODULE_WARNING) {
|
|
601
|
+
const MODULE_REDEFINE = 'Module redefine attempted'; MODULE_WARNING["MODULE_REDEFINE"] = MODULE_REDEFINE;
|
|
602
|
+
const MODULE_ALREADY_LOADED = 'Marking module(s) as externally loaded, but they are already loaded'; MODULE_WARNING["MODULE_ALREADY_LOADED"] = MODULE_ALREADY_LOADED;
|
|
603
|
+
const ALIAS_UPDATE = 'Alias update attempt'; MODULE_WARNING["ALIAS_UPDATE"] = ALIAS_UPDATE;
|
|
604
|
+
})(MODULE_WARNING || (MODULE_WARNING = {}));
|
|
605
|
+
|
|
600
606
|
/*!
|
|
601
607
|
* Copyright (C) 2023 salesforce.com, inc.
|
|
602
608
|
*/
|
|
@@ -772,7 +778,7 @@ async function evaluateLoadHook(
|
|
|
772
778
|
});
|
|
773
779
|
}
|
|
774
780
|
|
|
775
|
-
/* global
|
|
781
|
+
/* global process console */
|
|
776
782
|
|
|
777
783
|
|
|
778
784
|
|
|
@@ -819,13 +825,20 @@ async function evaluateLoadHook(
|
|
|
819
825
|
|
|
820
826
|
class ModuleRegistry {
|
|
821
827
|
|
|
828
|
+
|
|
829
|
+
__init() {this.isAppMounted = false;}
|
|
822
830
|
|
|
823
|
-
constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);
|
|
831
|
+
constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);ModuleRegistry.prototype.__init4.call(this);
|
|
824
832
|
this.profiler = config.profiler;
|
|
825
833
|
this.resolver = new ImportMetadataResolver(
|
|
826
834
|
config,
|
|
827
835
|
this.importMetadataInvalidationCallback.bind(this),
|
|
828
836
|
);
|
|
837
|
+
this.warnings = {
|
|
838
|
+
[MODULE_WARNING.MODULE_REDEFINE]: [],
|
|
839
|
+
[MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
|
|
840
|
+
[MODULE_WARNING.ALIAS_UPDATE]: [],
|
|
841
|
+
};
|
|
829
842
|
}
|
|
830
843
|
|
|
831
844
|
async load(id, importer) {
|
|
@@ -957,11 +970,14 @@ class ModuleRegistry {
|
|
|
957
970
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
958
971
|
process.env.NODE_ENV !== 'production' &&
|
|
959
972
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
960
|
-
process.env.MRT_HMR !== 'true'
|
|
961
|
-
hasConsole
|
|
973
|
+
process.env.MRT_HMR !== 'true'
|
|
962
974
|
) {
|
|
963
|
-
|
|
964
|
-
|
|
975
|
+
if (!this.warnings[MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
|
|
976
|
+
this.warnings[MODULE_WARNING.MODULE_REDEFINE].push(name);
|
|
977
|
+
}
|
|
978
|
+
if (this.isAppMounted) {
|
|
979
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
|
|
980
|
+
}
|
|
965
981
|
}
|
|
966
982
|
this.lastDefine = mod;
|
|
967
983
|
return;
|
|
@@ -1015,9 +1031,13 @@ class ModuleRegistry {
|
|
|
1015
1031
|
};
|
|
1016
1032
|
this.namedDefineRegistry.set(id, moduleDef );
|
|
1017
1033
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1018
|
-
} else if (process.env.NODE_ENV !== 'production'
|
|
1019
|
-
|
|
1020
|
-
|
|
1034
|
+
} else if (process.env.NODE_ENV !== 'production') {
|
|
1035
|
+
if (!this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
|
|
1036
|
+
this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
|
|
1037
|
+
}
|
|
1038
|
+
if (this.isAppMounted) {
|
|
1039
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
|
|
1040
|
+
}
|
|
1021
1041
|
}
|
|
1022
1042
|
});
|
|
1023
1043
|
}
|
|
@@ -1025,13 +1045,13 @@ class ModuleRegistry {
|
|
|
1025
1045
|
|
|
1026
1046
|
|
|
1027
1047
|
// A registry for named AMD defines containing the *metadata* of AMD module
|
|
1028
|
-
|
|
1048
|
+
__init2() {this.namedDefineRegistry = new Map();}
|
|
1029
1049
|
|
|
1030
1050
|
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
1031
|
-
|
|
1051
|
+
__init3() {this.moduleRegistry = new Map();}
|
|
1032
1052
|
|
|
1033
1053
|
// Aliases of modules in the registry
|
|
1034
|
-
|
|
1054
|
+
__init4() {this.aliases = new Map();}
|
|
1035
1055
|
|
|
1036
1056
|
|
|
1037
1057
|
|
|
@@ -1111,10 +1131,12 @@ class ModuleRegistry {
|
|
|
1111
1131
|
// Warn the user if they were not aliasing to the resolvedId
|
|
1112
1132
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
1113
1133
|
if (currentResolvedId !== resolvedId) {
|
|
1114
|
-
|
|
1115
|
-
if (
|
|
1116
|
-
|
|
1117
|
-
|
|
1134
|
+
const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
|
|
1135
|
+
if (!this.warnings[MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
|
|
1136
|
+
this.warnings[MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
|
|
1137
|
+
}
|
|
1138
|
+
if (this.isAppMounted) {
|
|
1139
|
+
this.logMessage('warning', `${MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
|
|
1118
1140
|
}
|
|
1119
1141
|
}
|
|
1120
1142
|
}
|
|
@@ -1427,6 +1449,28 @@ class ModuleRegistry {
|
|
|
1427
1449
|
res === null || typeof res === 'string' || (res && typeof (res ).url === 'string')
|
|
1428
1450
|
);
|
|
1429
1451
|
}
|
|
1452
|
+
|
|
1453
|
+
getModuleWarnings(isAppMounted = false) {
|
|
1454
|
+
this.isAppMounted = isAppMounted;
|
|
1455
|
+
return this.warnings;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
logMessage(logType, message) {
|
|
1459
|
+
if (
|
|
1460
|
+
!hasProcessEnv ||
|
|
1461
|
+
!hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
|
|
1462
|
+
process.env.NODE_ENV === 'production'
|
|
1463
|
+
) {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
if (logType == 'warning') {
|
|
1467
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1468
|
+
console.warn(message);
|
|
1469
|
+
} else {
|
|
1470
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1471
|
+
console.log(message);
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1430
1474
|
}
|
|
1431
1475
|
|
|
1432
1476
|
/**
|
|
@@ -1560,6 +1604,10 @@ class Loader {
|
|
|
1560
1604
|
registerExternalModules(modules) {
|
|
1561
1605
|
this.registry.registerExternalModules(modules);
|
|
1562
1606
|
}
|
|
1607
|
+
|
|
1608
|
+
getModuleWarnings(isAppMounted = false) {
|
|
1609
|
+
return this.registry.getModuleWarnings(isAppMounted);
|
|
1610
|
+
}
|
|
1563
1611
|
}
|
|
1564
1612
|
|
|
1565
1613
|
export { Loader };
|
|
@@ -7,6 +7,8 @@ export type Module = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare class ModuleRegistry {
|
|
9
9
|
private profiler;
|
|
10
|
+
private warnings;
|
|
11
|
+
private isAppMounted;
|
|
10
12
|
constructor(config: LoaderConfig);
|
|
11
13
|
load(id: string, importer?: string): Promise<Module>;
|
|
12
14
|
resolve(id: string, importer?: string): Promise<string>;
|
|
@@ -43,5 +45,7 @@ export declare class ModuleRegistry {
|
|
|
43
45
|
private handleStaleModuleHook?;
|
|
44
46
|
registerHandleStaleModuleHook(handleStaleModule: HandleStaleModuleHook): void;
|
|
45
47
|
isValidResolveResponse(res: ResolveHookResponse): boolean;
|
|
48
|
+
getModuleWarnings(isAppMounted?: boolean): Record<string, string[]>;
|
|
49
|
+
logMessage(logType: string, message: string): void;
|
|
46
50
|
}
|
|
47
51
|
//# sourceMappingURL=moduleRegistry.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* global
|
|
2
|
-
import { invariant, NO_AMD_REQUIRE, LoaderError, FAIL_INSTANTIATE, FAILED_DEP, UNRESOLVED, INVALID_HOOK, INVALID_LOADER_SERVICE_RESPONSE,
|
|
1
|
+
/* global process console */
|
|
2
|
+
import { invariant, NO_AMD_REQUIRE, LoaderError, FAIL_INSTANTIATE, FAILED_DEP, UNRESOLVED, INVALID_HOOK, INVALID_LOADER_SERVICE_RESPONSE, MODULE_LOAD_TIMEOUT, EXPORTER_ERROR, } from '../errors/messages.js';
|
|
3
3
|
import { resolveIfNotPlainOrUrl, isUrl } from '../utils/url.js';
|
|
4
4
|
import { hasDocument, hasConsole, hasProcessEnv } from '../utils/dom.js';
|
|
5
5
|
import { loadModuleDef } from './scriptLoad.js';
|
|
@@ -7,9 +7,10 @@ import { ImportMetadataResolver } from './importMetadataResolver.js';
|
|
|
7
7
|
import { evaluateHandleStaleModuleHooks } from '../hooks/moduleInvalidation.js';
|
|
8
8
|
import { evaluateLoadHookResponse, evaluateLoadHook, isResponseAPromise, } from '../hooks/resolveAndLoadHook.js';
|
|
9
9
|
import { MODULE_DEFINE, MODULE_ERROR, MODULE_FETCH, MODULE_DYNAMIC_LOAD } from 'lwr/metrics';
|
|
10
|
-
import { MODULE_LOAD_TIMEOUT_TIMER } from '../constants/constants.js';
|
|
10
|
+
import { MODULE_LOAD_TIMEOUT_TIMER, MODULE_WARNING } from '../constants/constants.js';
|
|
11
11
|
export class ModuleRegistry {
|
|
12
12
|
constructor(config) {
|
|
13
|
+
this.isAppMounted = false;
|
|
13
14
|
// A registry for named AMD defines containing the *metadata* of AMD module
|
|
14
15
|
this.namedDefineRegistry = new Map();
|
|
15
16
|
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
@@ -18,6 +19,11 @@ export class ModuleRegistry {
|
|
|
18
19
|
this.aliases = new Map();
|
|
19
20
|
this.profiler = config.profiler;
|
|
20
21
|
this.resolver = new ImportMetadataResolver(config, this.importMetadataInvalidationCallback.bind(this));
|
|
22
|
+
this.warnings = {
|
|
23
|
+
[MODULE_WARNING.MODULE_REDEFINE]: [],
|
|
24
|
+
[MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
|
|
25
|
+
[MODULE_WARNING.ALIAS_UPDATE]: [],
|
|
26
|
+
};
|
|
21
27
|
}
|
|
22
28
|
async load(id, importer) {
|
|
23
29
|
const metadata = importer ? { importer } : {};
|
|
@@ -136,10 +142,13 @@ export class ModuleRegistry {
|
|
|
136
142
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
137
143
|
process.env.NODE_ENV !== 'production' &&
|
|
138
144
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
139
|
-
process.env.MRT_HMR !== 'true'
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
145
|
+
process.env.MRT_HMR !== 'true') {
|
|
146
|
+
if (!this.warnings[MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
|
|
147
|
+
this.warnings[MODULE_WARNING.MODULE_REDEFINE].push(name);
|
|
148
|
+
}
|
|
149
|
+
if (this.isAppMounted) {
|
|
150
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
|
|
151
|
+
}
|
|
143
152
|
}
|
|
144
153
|
this.lastDefine = mod;
|
|
145
154
|
return;
|
|
@@ -190,9 +199,13 @@ export class ModuleRegistry {
|
|
|
190
199
|
this.namedDefineRegistry.set(id, moduleDef);
|
|
191
200
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
192
201
|
}
|
|
193
|
-
else if (process.env.NODE_ENV !== 'production'
|
|
194
|
-
|
|
195
|
-
|
|
202
|
+
else if (process.env.NODE_ENV !== 'production') {
|
|
203
|
+
if (!this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
|
|
204
|
+
this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
|
|
205
|
+
}
|
|
206
|
+
if (this.isAppMounted) {
|
|
207
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
|
|
208
|
+
}
|
|
196
209
|
}
|
|
197
210
|
});
|
|
198
211
|
}
|
|
@@ -264,10 +277,12 @@ export class ModuleRegistry {
|
|
|
264
277
|
// Warn the user if they were not aliasing to the resolvedId
|
|
265
278
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
266
279
|
if (currentResolvedId !== resolvedId) {
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
280
|
+
const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
|
|
281
|
+
if (!this.warnings[MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
|
|
282
|
+
this.warnings[MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
|
|
283
|
+
}
|
|
284
|
+
if (this.isAppMounted) {
|
|
285
|
+
this.logMessage('warning', `${MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
|
|
271
286
|
}
|
|
272
287
|
}
|
|
273
288
|
}
|
|
@@ -534,5 +549,24 @@ export class ModuleRegistry {
|
|
|
534
549
|
isValidResolveResponse(res) {
|
|
535
550
|
return (res === null || typeof res === 'string' || (res && typeof res.url === 'string'));
|
|
536
551
|
}
|
|
552
|
+
getModuleWarnings(isAppMounted = false) {
|
|
553
|
+
this.isAppMounted = isAppMounted;
|
|
554
|
+
return this.warnings;
|
|
555
|
+
}
|
|
556
|
+
logMessage(logType, message) {
|
|
557
|
+
if (!hasProcessEnv ||
|
|
558
|
+
!hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
|
|
559
|
+
process.env.NODE_ENV === 'production') {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (logType == 'warning') {
|
|
563
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
564
|
+
console.warn(message);
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
568
|
+
console.log(message);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
537
571
|
}
|
|
538
572
|
//# sourceMappingURL=moduleRegistry.js.map
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare const MODULE_LOAD_TIMEOUT_TIMER: number;
|
|
2
|
+
export declare enum MODULE_WARNING {
|
|
3
|
+
MODULE_REDEFINE = "Module redefine attempted",
|
|
4
|
+
MODULE_ALREADY_LOADED = "Marking module(s) as externally loaded, but they are already loaded",
|
|
5
|
+
ALIAS_UPDATE = "Alias update attempt"
|
|
6
|
+
}
|
|
2
7
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
|
|
2
|
+
export var MODULE_WARNING;
|
|
3
|
+
(function (MODULE_WARNING) {
|
|
4
|
+
MODULE_WARNING["MODULE_REDEFINE"] = "Module redefine attempted";
|
|
5
|
+
MODULE_WARNING["MODULE_ALREADY_LOADED"] = "Marking module(s) as externally loaded, but they are already loaded";
|
|
6
|
+
MODULE_WARNING["ALIAS_UPDATE"] = "Alias update attempt";
|
|
7
|
+
})(MODULE_WARNING || (MODULE_WARNING = {}));
|
|
2
8
|
//# sourceMappingURL=constants.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Legacy Module Loader v0.17.2-alpha.
|
|
7
|
+
/* LWR Legacy Module Loader v0.17.2-alpha.5 */
|
|
8
8
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
function templateString(template, args) {
|
|
@@ -108,7 +108,7 @@ const STALE_HOOK_ERROR = Object.freeze({
|
|
|
108
108
|
level: 0,
|
|
109
109
|
message: 'An error occurred handling module conflict',
|
|
110
110
|
});
|
|
111
|
-
|
|
111
|
+
Object.freeze({
|
|
112
112
|
code: 3017,
|
|
113
113
|
level: 0,
|
|
114
114
|
message: 'Marking module(s) as externally loaded, but they are already loaded: {0}',
|
|
@@ -320,6 +320,12 @@ if (hasDocument) {
|
|
|
320
320
|
|
|
321
321
|
const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
|
|
322
322
|
|
|
323
|
+
var MODULE_WARNING; (function (MODULE_WARNING) {
|
|
324
|
+
const MODULE_REDEFINE = 'Module redefine attempted'; MODULE_WARNING["MODULE_REDEFINE"] = MODULE_REDEFINE;
|
|
325
|
+
const MODULE_ALREADY_LOADED = 'Marking module(s) as externally loaded, but they are already loaded'; MODULE_WARNING["MODULE_ALREADY_LOADED"] = MODULE_ALREADY_LOADED;
|
|
326
|
+
const ALIAS_UPDATE = 'Alias update attempt'; MODULE_WARNING["ALIAS_UPDATE"] = ALIAS_UPDATE;
|
|
327
|
+
})(MODULE_WARNING || (MODULE_WARNING = {}));
|
|
328
|
+
|
|
323
329
|
/*!
|
|
324
330
|
* Copyright (C) 2023 salesforce.com, inc.
|
|
325
331
|
*/
|
|
@@ -529,7 +535,7 @@ const MODULE_DYNAMIC_LOAD = `${LOADER_PREFIX}module.dynamicLoad`;
|
|
|
529
535
|
const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
|
|
530
536
|
const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
|
|
531
537
|
|
|
532
|
-
/* global
|
|
538
|
+
/* global process console */
|
|
533
539
|
|
|
534
540
|
|
|
535
541
|
|
|
@@ -583,10 +589,17 @@ const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
|
|
|
583
589
|
|
|
584
590
|
class ModuleRegistry {
|
|
585
591
|
|
|
592
|
+
|
|
593
|
+
__init() {this.isAppMounted = false;}
|
|
586
594
|
|
|
587
|
-
constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);
|
|
595
|
+
constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);ModuleRegistry.prototype.__init4.call(this);
|
|
588
596
|
this.baseUrl = config.baseUrl || '';
|
|
589
597
|
this.profiler = config.profiler;
|
|
598
|
+
this.warnings = {
|
|
599
|
+
[MODULE_WARNING.MODULE_REDEFINE]: [],
|
|
600
|
+
[MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
|
|
601
|
+
[MODULE_WARNING.ALIAS_UPDATE]: [],
|
|
602
|
+
};
|
|
590
603
|
}
|
|
591
604
|
|
|
592
605
|
clearRegistry() {
|
|
@@ -723,11 +736,14 @@ class ModuleRegistry {
|
|
|
723
736
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
724
737
|
process.env.NODE_ENV !== 'production' &&
|
|
725
738
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
726
|
-
process.env.MRT_HMR !== 'true'
|
|
727
|
-
hasConsole
|
|
739
|
+
process.env.MRT_HMR !== 'true'
|
|
728
740
|
) {
|
|
729
|
-
|
|
730
|
-
|
|
741
|
+
if (!this.warnings[MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
|
|
742
|
+
this.warnings[MODULE_WARNING.MODULE_REDEFINE].push(name);
|
|
743
|
+
}
|
|
744
|
+
if (this.isAppMounted) {
|
|
745
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
|
|
746
|
+
}
|
|
731
747
|
}
|
|
732
748
|
this.lastDefine = mod;
|
|
733
749
|
return;
|
|
@@ -789,9 +805,13 @@ class ModuleRegistry {
|
|
|
789
805
|
};
|
|
790
806
|
this.namedDefineRegistry.set(id, moduleDef );
|
|
791
807
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
792
|
-
} else if (process.env.NODE_ENV !== 'production'
|
|
793
|
-
|
|
794
|
-
|
|
808
|
+
} else if (process.env.NODE_ENV !== 'production') {
|
|
809
|
+
if (!this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
|
|
810
|
+
this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
|
|
811
|
+
}
|
|
812
|
+
if (this.isAppMounted) {
|
|
813
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
|
|
814
|
+
}
|
|
795
815
|
}
|
|
796
816
|
});
|
|
797
817
|
}
|
|
@@ -840,13 +860,13 @@ class ModuleRegistry {
|
|
|
840
860
|
|
|
841
861
|
|
|
842
862
|
// A registry for named AMD defines containing the *metadata* of AMD module
|
|
843
|
-
|
|
863
|
+
__init2() {this.namedDefineRegistry = new Map();}
|
|
844
864
|
|
|
845
865
|
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
846
|
-
|
|
866
|
+
__init3() {this.moduleRegistry = new Map();}
|
|
847
867
|
|
|
848
868
|
// Aliases of modules in the registry
|
|
849
|
-
|
|
869
|
+
__init4() {this.aliases = new Map();}
|
|
850
870
|
|
|
851
871
|
|
|
852
872
|
|
|
@@ -916,14 +936,17 @@ class ModuleRegistry {
|
|
|
916
936
|
if (aliasId !== resolvedId) {
|
|
917
937
|
if (!this.aliases.has(aliasId)) {
|
|
918
938
|
this.aliases.set(aliasId, resolvedId);
|
|
919
|
-
|
|
939
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
940
|
+
} else if (hasConsole && process.env.NODE_ENV !== 'production') {
|
|
920
941
|
// Warn the user if they were not aliasing to the resolvedId
|
|
921
942
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
922
943
|
if (currentResolvedId !== resolvedId) {
|
|
923
|
-
|
|
924
|
-
if (
|
|
925
|
-
|
|
926
|
-
|
|
944
|
+
const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
|
|
945
|
+
if (!this.warnings[MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
|
|
946
|
+
this.warnings[MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
|
|
947
|
+
}
|
|
948
|
+
if (this.isAppMounted) {
|
|
949
|
+
this.logMessage('warning', `${MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
|
|
927
950
|
}
|
|
928
951
|
}
|
|
929
952
|
}
|
|
@@ -1216,6 +1239,28 @@ class ModuleRegistry {
|
|
|
1216
1239
|
res === null || typeof res === 'string' || (res && typeof (res ).url === 'string')
|
|
1217
1240
|
);
|
|
1218
1241
|
}
|
|
1242
|
+
|
|
1243
|
+
getModuleWarnings(isAppMounted = false) {
|
|
1244
|
+
this.isAppMounted = isAppMounted;
|
|
1245
|
+
return this.warnings;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
logMessage(logType, message) {
|
|
1249
|
+
if (
|
|
1250
|
+
!hasProcessEnv ||
|
|
1251
|
+
!hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
|
|
1252
|
+
process.env.NODE_ENV === 'production'
|
|
1253
|
+
) {
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
if (logType == 'warning') {
|
|
1257
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1258
|
+
console.warn(message);
|
|
1259
|
+
} else {
|
|
1260
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1261
|
+
console.log(message);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1219
1264
|
}
|
|
1220
1265
|
|
|
1221
1266
|
// find the longest set of segments from path which are a key in matchObj
|
|
@@ -1629,6 +1674,10 @@ class Loader {
|
|
|
1629
1674
|
registerExternalModules(modules) {
|
|
1630
1675
|
this.registry.registerExternalModules(modules);
|
|
1631
1676
|
}
|
|
1677
|
+
|
|
1678
|
+
getModuleWarnings(isAppMounted = false) {
|
|
1679
|
+
return this.registry.getModuleWarnings(isAppMounted);
|
|
1680
|
+
}
|
|
1632
1681
|
}
|
|
1633
1682
|
|
|
1634
1683
|
export { Loader };
|
|
@@ -13,6 +13,8 @@ export type Module = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare class ModuleRegistry {
|
|
15
15
|
private profiler;
|
|
16
|
+
private warnings;
|
|
17
|
+
private isAppMounted;
|
|
16
18
|
constructor(config: LoaderConfig);
|
|
17
19
|
clearRegistry(): void;
|
|
18
20
|
load(id: string, importer?: string): Promise<Module>;
|
|
@@ -50,5 +52,7 @@ export declare class ModuleRegistry {
|
|
|
50
52
|
private handleStaleModuleHook?;
|
|
51
53
|
registerHandleStaleModuleHook(handleStaleModule: HandleStaleModuleHook): void;
|
|
52
54
|
isValidResolveResponse(res: ResolveHookResponse): boolean;
|
|
55
|
+
getModuleWarnings(isAppMounted?: boolean): Record<string, string[]>;
|
|
56
|
+
logMessage(logType: string, message: string): void;
|
|
53
57
|
}
|
|
54
58
|
//# sourceMappingURL=moduleRegistry.d.ts.map
|