@lwrjs/loader 0.17.2-alpha.3 → 0.17.2-alpha.30
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/README.md +1 -0
- package/build/assets/prod/lwr-error-shim.js +1 -1
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +168 -46
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +4 -3
- package/build/assets/prod/lwr-loader-shim-legacy.js +58 -16
- package/build/assets/prod/lwr-loader-shim.bundle.js +180 -54
- package/build/assets/prod/lwr-loader-shim.bundle.min.js +4 -3
- package/build/assets/prod/lwr-loader-shim.js +58 -16
- package/build/cjs/modules/lwr/loader/constants/constants.cjs +8 -1
- package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +2 -2
- package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +49 -7
- package/build/cjs/modules/lwr/loaderLegacy/constants/constants.cjs +8 -1
- package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +50 -8
- 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 +122 -38
- package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.js +7 -7
- package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.d.ts +4 -0
- package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.js +66 -15
- 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 +110 -30
- package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.d.ts +4 -0
- package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.js +67 -16
- package/build/shim/shim.d.ts +2 -0
- package/build/shim/shim.js +45 -8
- package/build/shim-legacy/shimLegacy.d.ts +2 -0
- package/build/shim-legacy/shimLegacy.js +45 -8
- package/build/types.d.ts +1 -0
- package/package.json +8 -8
|
@@ -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.30 */
|
|
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:',
|
|
@@ -538,20 +538,21 @@ class ImportMetadataResolver {
|
|
|
538
538
|
if (!uri) {
|
|
539
539
|
throw new LoaderError(UNRESOLVEABLE_MAPPING_ERROR, [specifier]);
|
|
540
540
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
.json()
|
|
548
|
-
.then((ret) => {
|
|
549
|
-
return ret ;
|
|
550
|
-
})
|
|
551
|
-
.catch((err) => {
|
|
541
|
+
|
|
542
|
+
return globalThis
|
|
543
|
+
.fetch(uri)
|
|
544
|
+
.then((res) => {
|
|
545
|
+
if (!res.ok) {
|
|
546
|
+
this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
|
|
552
547
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
548
|
+
}
|
|
549
|
+
return res.json().then((ret) => {
|
|
550
|
+
return ret ;
|
|
553
551
|
});
|
|
554
|
-
|
|
552
|
+
})
|
|
553
|
+
.catch((err) => {
|
|
554
|
+
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
555
|
+
});
|
|
555
556
|
}
|
|
556
557
|
|
|
557
558
|
saveImportURIRecord(specifier, uri, identity, isRoot) {
|
|
@@ -597,20 +598,39 @@ function evaluateHandleStaleModuleHooks(
|
|
|
597
598
|
|
|
598
599
|
const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
|
|
599
600
|
|
|
601
|
+
var MODULE_WARNING; (function (MODULE_WARNING) {
|
|
602
|
+
const MODULE_REDEFINE = 'Module redefine attempted'; MODULE_WARNING["MODULE_REDEFINE"] = MODULE_REDEFINE;
|
|
603
|
+
const MODULE_ALREADY_LOADED = 'Marking module(s) as externally loaded, but they are already loaded'; MODULE_WARNING["MODULE_ALREADY_LOADED"] = MODULE_ALREADY_LOADED;
|
|
604
|
+
const ALIAS_UPDATE = 'Alias update attempt'; MODULE_WARNING["ALIAS_UPDATE"] = ALIAS_UPDATE;
|
|
605
|
+
})(MODULE_WARNING || (MODULE_WARNING = {}));
|
|
606
|
+
|
|
600
607
|
/*!
|
|
601
608
|
* Copyright (C) 2023 salesforce.com, inc.
|
|
602
609
|
*/
|
|
603
610
|
// @ts-ignore: Prevent cannot find name 'trustedTypes' error.
|
|
604
611
|
const SUPPORTS_TRUSTED_TYPES = typeof trustedTypes !== 'undefined';
|
|
605
|
-
|
|
612
|
+
const trustedTypePolicyRegistry = {
|
|
613
|
+
__proto__: null
|
|
614
|
+
};
|
|
615
|
+
function createDuplicateSafeTrustedTypesPolicy(name, options) {
|
|
616
|
+
// istanbul ignore next: not testable in coverage collection
|
|
617
|
+
if (trustedTypePolicyRegistry[name]) {
|
|
618
|
+
return trustedTypePolicyRegistry[name];
|
|
619
|
+
}
|
|
606
620
|
// @ts-ignore: Prevent cannot find name 'trustedTypes' error.
|
|
607
|
-
|
|
621
|
+
// eslint-disable-next-line no-return-assign
|
|
622
|
+
return trustedTypePolicyRegistry[name] = trustedTypes.createPolicy(name, options);
|
|
608
623
|
}
|
|
609
|
-
function
|
|
610
|
-
|
|
624
|
+
function createDuplicateSafeFallbackPolicy(name, options) {
|
|
625
|
+
if (trustedTypePolicyRegistry[name]) {
|
|
626
|
+
return trustedTypePolicyRegistry[name];
|
|
627
|
+
}
|
|
628
|
+
// @ts-ignore: Prevent cannot find name 'trustedTypes' error.
|
|
629
|
+
// eslint-disable-next-line no-return-assign
|
|
630
|
+
return trustedTypePolicyRegistry[name] = options;
|
|
611
631
|
}
|
|
612
632
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
|
|
613
|
-
const createPolicy = SUPPORTS_TRUSTED_TYPES ?
|
|
633
|
+
const createPolicy = SUPPORTS_TRUSTED_TYPES ? createDuplicateSafeTrustedTypesPolicy : createDuplicateSafeFallbackPolicy;
|
|
614
634
|
const policyOptions = {
|
|
615
635
|
createHTML(value) {
|
|
616
636
|
return value;
|
|
@@ -658,7 +678,7 @@ try {
|
|
|
658
678
|
// swallow
|
|
659
679
|
}
|
|
660
680
|
const trusted = createPolicy('trusted', policyOptions);
|
|
661
|
-
/*! version: 0.
|
|
681
|
+
/*! version: 0.24.6 */
|
|
662
682
|
|
|
663
683
|
/* global console,process */
|
|
664
684
|
|
|
@@ -728,7 +748,7 @@ async function evaluateLoadHookResponse(response, id) {
|
|
|
728
748
|
code = `${code}\n//# sourceURL=${id}`; // append sourceURL for debugging
|
|
729
749
|
try {
|
|
730
750
|
// TODO eval source maps for debugging
|
|
731
|
-
eval(trusted.createScript(code));
|
|
751
|
+
eval(trusted.createScript(code) );
|
|
732
752
|
} catch (e) {
|
|
733
753
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
734
754
|
if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
@@ -772,7 +792,7 @@ async function evaluateLoadHook(
|
|
|
772
792
|
});
|
|
773
793
|
}
|
|
774
794
|
|
|
775
|
-
/* global
|
|
795
|
+
/* global process console */
|
|
776
796
|
|
|
777
797
|
|
|
778
798
|
|
|
@@ -819,13 +839,20 @@ async function evaluateLoadHook(
|
|
|
819
839
|
|
|
820
840
|
class ModuleRegistry {
|
|
821
841
|
|
|
842
|
+
|
|
843
|
+
__init() {this.isAppMounted = false;}
|
|
822
844
|
|
|
823
|
-
constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);
|
|
845
|
+
constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);ModuleRegistry.prototype.__init4.call(this);
|
|
824
846
|
this.profiler = config.profiler;
|
|
825
847
|
this.resolver = new ImportMetadataResolver(
|
|
826
848
|
config,
|
|
827
849
|
this.importMetadataInvalidationCallback.bind(this),
|
|
828
850
|
);
|
|
851
|
+
this.warnings = {
|
|
852
|
+
[MODULE_WARNING.MODULE_REDEFINE]: [],
|
|
853
|
+
[MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
|
|
854
|
+
[MODULE_WARNING.ALIAS_UPDATE]: [],
|
|
855
|
+
};
|
|
829
856
|
}
|
|
830
857
|
|
|
831
858
|
async load(id, importer) {
|
|
@@ -957,11 +984,14 @@ class ModuleRegistry {
|
|
|
957
984
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
958
985
|
process.env.NODE_ENV !== 'production' &&
|
|
959
986
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
960
|
-
process.env.MRT_HMR !== 'true'
|
|
961
|
-
hasConsole
|
|
987
|
+
process.env.MRT_HMR !== 'true'
|
|
962
988
|
) {
|
|
963
|
-
|
|
964
|
-
|
|
989
|
+
if (!this.warnings[MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
|
|
990
|
+
this.warnings[MODULE_WARNING.MODULE_REDEFINE].push(name);
|
|
991
|
+
}
|
|
992
|
+
if (this.isAppMounted) {
|
|
993
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
|
|
994
|
+
}
|
|
965
995
|
}
|
|
966
996
|
this.lastDefine = mod;
|
|
967
997
|
return;
|
|
@@ -1015,9 +1045,13 @@ class ModuleRegistry {
|
|
|
1015
1045
|
};
|
|
1016
1046
|
this.namedDefineRegistry.set(id, moduleDef );
|
|
1017
1047
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1018
|
-
} else if (process.env.NODE_ENV !== 'production'
|
|
1019
|
-
|
|
1020
|
-
|
|
1048
|
+
} else if (process.env.NODE_ENV !== 'production') {
|
|
1049
|
+
if (!this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
|
|
1050
|
+
this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
|
|
1051
|
+
}
|
|
1052
|
+
if (this.isAppMounted) {
|
|
1053
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
|
|
1054
|
+
}
|
|
1021
1055
|
}
|
|
1022
1056
|
});
|
|
1023
1057
|
}
|
|
@@ -1025,13 +1059,13 @@ class ModuleRegistry {
|
|
|
1025
1059
|
|
|
1026
1060
|
|
|
1027
1061
|
// A registry for named AMD defines containing the *metadata* of AMD module
|
|
1028
|
-
|
|
1062
|
+
__init2() {this.namedDefineRegistry = new Map();}
|
|
1029
1063
|
|
|
1030
1064
|
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
1031
|
-
|
|
1065
|
+
__init3() {this.moduleRegistry = new Map();}
|
|
1032
1066
|
|
|
1033
1067
|
// Aliases of modules in the registry
|
|
1034
|
-
|
|
1068
|
+
__init4() {this.aliases = new Map();}
|
|
1035
1069
|
|
|
1036
1070
|
|
|
1037
1071
|
|
|
@@ -1111,10 +1145,12 @@ class ModuleRegistry {
|
|
|
1111
1145
|
// Warn the user if they were not aliasing to the resolvedId
|
|
1112
1146
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
1113
1147
|
if (currentResolvedId !== resolvedId) {
|
|
1114
|
-
|
|
1115
|
-
if (
|
|
1116
|
-
|
|
1117
|
-
|
|
1148
|
+
const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
|
|
1149
|
+
if (!this.warnings[MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
|
|
1150
|
+
this.warnings[MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
|
|
1151
|
+
}
|
|
1152
|
+
if (this.isAppMounted) {
|
|
1153
|
+
this.logMessage('warning', `${MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
|
|
1118
1154
|
}
|
|
1119
1155
|
}
|
|
1120
1156
|
}
|
|
@@ -1122,7 +1158,25 @@ class ModuleRegistry {
|
|
|
1122
1158
|
}
|
|
1123
1159
|
|
|
1124
1160
|
async getModuleDependencyRecord(dependency) {
|
|
1125
|
-
|
|
1161
|
+
// Initially resolve the dependency to get its ID, which may be a bundle URL.
|
|
1162
|
+
let resolvedDepId = await this.resolve(dependency);
|
|
1163
|
+
|
|
1164
|
+
// If the resolved dependency ID is a URL, it indicates that the dependency
|
|
1165
|
+
// is provided by a bundle that hasn't been fully instantiated yet.
|
|
1166
|
+
if (isUrl(resolvedDepId)) {
|
|
1167
|
+
// Retrieve the module record corresponding to the bundle URL.
|
|
1168
|
+
const existingRecord = this.moduleRegistry.get(resolvedDepId);
|
|
1169
|
+
|
|
1170
|
+
// If a module record for the bundle exists and we haven't already created an alias for this dependency,
|
|
1171
|
+
// then the bundle is still pending instantiation.
|
|
1172
|
+
if (existingRecord && !this.aliases.has(dependency)) {
|
|
1173
|
+
// Wait for the bundle's instantiation promise to resolve.
|
|
1174
|
+
await existingRecord.instantiation;
|
|
1175
|
+
// After instantiation, re-resolve the dependency.
|
|
1176
|
+
// This should now return the final alias (the logical module ID) instead of the raw bundle URL.
|
|
1177
|
+
resolvedDepId = await this.resolve(dependency);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1126
1180
|
return this.getModuleRecord(resolvedDepId, dependency);
|
|
1127
1181
|
}
|
|
1128
1182
|
|
|
@@ -1346,6 +1400,10 @@ class ModuleRegistry {
|
|
|
1346
1400
|
|
|
1347
1401
|
// Fallback to the last loader.define call
|
|
1348
1402
|
if (!moduleDef) {
|
|
1403
|
+
this.logMessage(
|
|
1404
|
+
'warning',
|
|
1405
|
+
`${moduleName} not found, falling back to the last loader.define call`,
|
|
1406
|
+
);
|
|
1349
1407
|
moduleDef = this.lastDefine;
|
|
1350
1408
|
}
|
|
1351
1409
|
|
|
@@ -1427,6 +1485,28 @@ class ModuleRegistry {
|
|
|
1427
1485
|
res === null || typeof res === 'string' || (res && typeof (res ).url === 'string')
|
|
1428
1486
|
);
|
|
1429
1487
|
}
|
|
1488
|
+
|
|
1489
|
+
getModuleWarnings(isAppMounted = false) {
|
|
1490
|
+
this.isAppMounted = isAppMounted;
|
|
1491
|
+
return this.warnings;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
logMessage(logType, message) {
|
|
1495
|
+
if (
|
|
1496
|
+
!hasProcessEnv ||
|
|
1497
|
+
!hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
|
|
1498
|
+
process.env.NODE_ENV === 'production'
|
|
1499
|
+
) {
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
if (logType == 'warning') {
|
|
1503
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1504
|
+
console.warn(message);
|
|
1505
|
+
} else {
|
|
1506
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
1507
|
+
console.log(message);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1430
1510
|
}
|
|
1431
1511
|
|
|
1432
1512
|
/**
|
|
@@ -1560,6 +1640,10 @@ class Loader {
|
|
|
1560
1640
|
registerExternalModules(modules) {
|
|
1561
1641
|
this.registry.registerExternalModules(modules);
|
|
1562
1642
|
}
|
|
1643
|
+
|
|
1644
|
+
getModuleWarnings(isAppMounted = false) {
|
|
1645
|
+
return this.registry.getModuleWarnings(isAppMounted);
|
|
1646
|
+
}
|
|
1563
1647
|
}
|
|
1564
1648
|
|
|
1565
1649
|
export { Loader };
|
|
@@ -177,19 +177,19 @@ export class ImportMetadataResolver {
|
|
|
177
177
|
if (!uri) {
|
|
178
178
|
throw new LoaderError(UNRESOLVEABLE_MAPPING_ERROR, [specifier]);
|
|
179
179
|
}
|
|
180
|
-
return globalThis
|
|
180
|
+
return globalThis
|
|
181
|
+
.fetch(uri)
|
|
182
|
+
.then((res) => {
|
|
181
183
|
if (!res.ok) {
|
|
182
184
|
this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
|
|
183
185
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
184
186
|
}
|
|
185
|
-
return res
|
|
186
|
-
.json()
|
|
187
|
-
.then((ret) => {
|
|
187
|
+
return res.json().then((ret) => {
|
|
188
188
|
return ret;
|
|
189
|
-
})
|
|
190
|
-
.catch((err) => {
|
|
191
|
-
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
192
189
|
});
|
|
190
|
+
})
|
|
191
|
+
.catch((err) => {
|
|
192
|
+
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
saveImportURIRecord(specifier, uri, identity, isRoot) {
|
|
@@ -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,17 +277,35 @@ 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
|
}
|
|
274
289
|
}
|
|
275
290
|
}
|
|
276
291
|
async getModuleDependencyRecord(dependency) {
|
|
277
|
-
|
|
292
|
+
// Initially resolve the dependency to get its ID, which may be a bundle URL.
|
|
293
|
+
let resolvedDepId = await this.resolve(dependency);
|
|
294
|
+
// If the resolved dependency ID is a URL, it indicates that the dependency
|
|
295
|
+
// is provided by a bundle that hasn't been fully instantiated yet.
|
|
296
|
+
if (isUrl(resolvedDepId)) {
|
|
297
|
+
// Retrieve the module record corresponding to the bundle URL.
|
|
298
|
+
const existingRecord = this.moduleRegistry.get(resolvedDepId);
|
|
299
|
+
// If a module record for the bundle exists and we haven't already created an alias for this dependency,
|
|
300
|
+
// then the bundle is still pending instantiation.
|
|
301
|
+
if (existingRecord && !this.aliases.has(dependency)) {
|
|
302
|
+
// Wait for the bundle's instantiation promise to resolve.
|
|
303
|
+
await existingRecord.instantiation;
|
|
304
|
+
// After instantiation, re-resolve the dependency.
|
|
305
|
+
// This should now return the final alias (the logical module ID) instead of the raw bundle URL.
|
|
306
|
+
resolvedDepId = await this.resolve(dependency);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
278
309
|
return this.getModuleRecord(resolvedDepId, dependency);
|
|
279
310
|
}
|
|
280
311
|
// execute the "top-level code" (the code outside of functions) of a module
|
|
@@ -463,6 +494,7 @@ export class ModuleRegistry {
|
|
|
463
494
|
moduleDef = moduleName && this.namedDefineRegistry.get(moduleName);
|
|
464
495
|
// Fallback to the last loader.define call
|
|
465
496
|
if (!moduleDef) {
|
|
497
|
+
this.logMessage('warning', `${moduleName} not found, falling back to the last loader.define call`);
|
|
466
498
|
moduleDef = this.lastDefine;
|
|
467
499
|
}
|
|
468
500
|
// This should not happen
|
|
@@ -534,5 +566,24 @@ export class ModuleRegistry {
|
|
|
534
566
|
isValidResolveResponse(res) {
|
|
535
567
|
return (res === null || typeof res === 'string' || (res && typeof res.url === 'string'));
|
|
536
568
|
}
|
|
569
|
+
getModuleWarnings(isAppMounted = false) {
|
|
570
|
+
this.isAppMounted = isAppMounted;
|
|
571
|
+
return this.warnings;
|
|
572
|
+
}
|
|
573
|
+
logMessage(logType, message) {
|
|
574
|
+
if (!hasProcessEnv ||
|
|
575
|
+
!hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
|
|
576
|
+
process.env.NODE_ENV === 'production') {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (logType == 'warning') {
|
|
580
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
581
|
+
console.warn(message);
|
|
582
|
+
}
|
|
583
|
+
else {
|
|
584
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
585
|
+
console.log(message);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
537
588
|
}
|
|
538
589
|
//# 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
|