@lwrjs/loader 0.17.2-alpha.4 → 0.17.2-alpha.6
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
|
@@ -1,14 +1,15 @@
|
|
|
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';
|
|
6
6
|
import { evaluateLoadHookResponse, evaluateLoadHook, isResponseAPromise, } from '../hooks/resolveAndLoadHook.js';
|
|
7
7
|
import { evaluateHandleStaleModuleHooks } from '../hooks/moduleInvalidation.js';
|
|
8
|
-
import { MODULE_LOAD_TIMEOUT_TIMER } from '../constants/constants.js';
|
|
8
|
+
import { MODULE_LOAD_TIMEOUT_TIMER, MODULE_WARNING } from '../constants/constants.js';
|
|
9
9
|
import { MODULE_DEFINE, MODULE_ERROR, MODULE_FETCH, MODULE_DYNAMIC_LOAD } from 'lwr/metrics';
|
|
10
10
|
export class ModuleRegistry {
|
|
11
11
|
constructor(config) {
|
|
12
|
+
this.isAppMounted = false;
|
|
12
13
|
// A registry for named AMD defines containing the *metadata* of AMD module
|
|
13
14
|
this.namedDefineRegistry = new Map();
|
|
14
15
|
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
@@ -17,6 +18,11 @@ export class ModuleRegistry {
|
|
|
17
18
|
this.aliases = new Map();
|
|
18
19
|
this.baseUrl = config.baseUrl || '';
|
|
19
20
|
this.profiler = config.profiler;
|
|
21
|
+
this.warnings = {
|
|
22
|
+
[MODULE_WARNING.MODULE_REDEFINE]: [],
|
|
23
|
+
[MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
|
|
24
|
+
[MODULE_WARNING.ALIAS_UPDATE]: [],
|
|
25
|
+
};
|
|
20
26
|
}
|
|
21
27
|
clearRegistry() {
|
|
22
28
|
this.moduleRegistry = new Map();
|
|
@@ -134,10 +140,13 @@ export class ModuleRegistry {
|
|
|
134
140
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
135
141
|
process.env.NODE_ENV !== 'production' &&
|
|
136
142
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
137
|
-
process.env.MRT_HMR !== 'true'
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
process.env.MRT_HMR !== 'true') {
|
|
144
|
+
if (!this.warnings[MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
|
|
145
|
+
this.warnings[MODULE_WARNING.MODULE_REDEFINE].push(name);
|
|
146
|
+
}
|
|
147
|
+
if (this.isAppMounted) {
|
|
148
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
|
|
149
|
+
}
|
|
141
150
|
}
|
|
142
151
|
this.lastDefine = mod;
|
|
143
152
|
return;
|
|
@@ -195,9 +204,13 @@ export class ModuleRegistry {
|
|
|
195
204
|
this.namedDefineRegistry.set(id, moduleDef);
|
|
196
205
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
197
206
|
}
|
|
198
|
-
else if (process.env.NODE_ENV !== 'production'
|
|
199
|
-
|
|
200
|
-
|
|
207
|
+
else if (process.env.NODE_ENV !== 'production') {
|
|
208
|
+
if (!this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
|
|
209
|
+
this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
|
|
210
|
+
}
|
|
211
|
+
if (this.isAppMounted) {
|
|
212
|
+
this.logMessage('warning', `${MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
|
|
213
|
+
}
|
|
201
214
|
}
|
|
202
215
|
});
|
|
203
216
|
}
|
|
@@ -296,15 +309,18 @@ export class ModuleRegistry {
|
|
|
296
309
|
if (aliasId !== resolvedId) {
|
|
297
310
|
if (!this.aliases.has(aliasId)) {
|
|
298
311
|
this.aliases.set(aliasId, resolvedId);
|
|
312
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
299
313
|
}
|
|
300
|
-
else if (hasConsole) {
|
|
314
|
+
else if (hasConsole && process.env.NODE_ENV !== 'production') {
|
|
301
315
|
// Warn the user if they were not aliasing to the resolvedId
|
|
302
316
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
303
317
|
if (currentResolvedId !== resolvedId) {
|
|
304
|
-
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
318
|
+
const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
|
|
319
|
+
if (!this.warnings[MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
|
|
320
|
+
this.warnings[MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
|
|
321
|
+
}
|
|
322
|
+
if (this.isAppMounted) {
|
|
323
|
+
this.logMessage('warning', `${MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
|
|
308
324
|
}
|
|
309
325
|
}
|
|
310
326
|
}
|
|
@@ -551,5 +567,24 @@ export class ModuleRegistry {
|
|
|
551
567
|
isValidResolveResponse(res) {
|
|
552
568
|
return (res === null || typeof res === 'string' || (res && typeof res.url === 'string'));
|
|
553
569
|
}
|
|
570
|
+
getModuleWarnings(isAppMounted = false) {
|
|
571
|
+
this.isAppMounted = isAppMounted;
|
|
572
|
+
return this.warnings;
|
|
573
|
+
}
|
|
574
|
+
logMessage(logType, message) {
|
|
575
|
+
if (!hasProcessEnv ||
|
|
576
|
+
!hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
|
|
577
|
+
process.env.NODE_ENV === 'production') {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (logType == 'warning') {
|
|
581
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
582
|
+
console.warn(message);
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
586
|
+
console.log(message);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
554
589
|
}
|
|
555
590
|
//# sourceMappingURL=moduleRegistry.js.map
|
package/build/shim/shim.d.ts
CHANGED
package/build/shim/shim.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* global document */
|
|
1
|
+
/* global document, process, console */
|
|
2
2
|
import { BOOTSTRAP_ERROR } from 'lwr/metrics';
|
|
3
3
|
import { logOperationStart, logOperationEnd } from 'lwr/profiler';
|
|
4
4
|
import { createLoader } from './loader.js';
|
|
@@ -7,6 +7,7 @@ import { customInit } from './customInit.js';
|
|
|
7
7
|
/* eslint-disable lwr/no-unguarded-apis */
|
|
8
8
|
const hasSetTimeout = typeof setTimeout === 'function';
|
|
9
9
|
const hasConsole = typeof console !== 'undefined';
|
|
10
|
+
const hasProcess = typeof process !== 'undefined';
|
|
10
11
|
/* eslint-enable lwr/no-unguarded-apis */
|
|
11
12
|
export default class LoaderShim {
|
|
12
13
|
constructor(global) {
|
|
@@ -101,6 +102,14 @@ export default class LoaderShim {
|
|
|
101
102
|
};
|
|
102
103
|
const loader = createLoader(this.loaderSpecifier, this.defineCache[this.loaderSpecifier], loaderConfig, this.config.preloadModules);
|
|
103
104
|
this.mountApp(loader);
|
|
105
|
+
if (loader &&
|
|
106
|
+
typeof loader.getModuleWarnings === 'function' &&
|
|
107
|
+
hasProcess &&
|
|
108
|
+
hasConsole &&
|
|
109
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
110
|
+
process.env.NODE_ENV !== 'production') {
|
|
111
|
+
this.logWarnings(loader.getModuleWarnings(true)); // the true indicates the app is mounted
|
|
112
|
+
}
|
|
104
113
|
}
|
|
105
114
|
catch (e) {
|
|
106
115
|
this.enterErrorState(e);
|
|
@@ -190,5 +199,13 @@ export default class LoaderShim {
|
|
|
190
199
|
this.enterErrorState(new Error('Failed to load required modules - timed out'));
|
|
191
200
|
}, REQUIRED_MODULES_TIMEOUT);
|
|
192
201
|
}
|
|
202
|
+
logWarnings(warnings) {
|
|
203
|
+
for (const warningKey in warnings) {
|
|
204
|
+
if (warnings[warningKey].length) {
|
|
205
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
206
|
+
console.warn(warningKey, warnings[warningKey]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
193
210
|
}
|
|
194
211
|
//# sourceMappingURL=shim.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* global document */
|
|
1
|
+
/* global document, process, console */
|
|
2
2
|
import { BOOTSTRAP_ERROR } from 'lwr/metrics';
|
|
3
3
|
import { logOperationStart, logOperationEnd } from 'lwr/profiler';
|
|
4
4
|
import { createLoader } from './loaderLegacy.js';
|
|
@@ -7,6 +7,7 @@ import { customInit } from '../shim/customInit.js';
|
|
|
7
7
|
/* eslint-disable lwr/no-unguarded-apis */
|
|
8
8
|
const hasSetTimeout = typeof setTimeout === 'function';
|
|
9
9
|
const hasConsole = typeof console !== 'undefined';
|
|
10
|
+
const hasProcess = typeof process !== 'undefined';
|
|
10
11
|
/* eslint-enable lwr/no-unguarded-apis */
|
|
11
12
|
export default class LoaderShim {
|
|
12
13
|
constructor(global) {
|
|
@@ -100,6 +101,14 @@ export default class LoaderShim {
|
|
|
100
101
|
};
|
|
101
102
|
const loader = createLoader(this.loaderModule, this.defineCache[this.loaderModule], loaderConfig, this.config.preloadModules);
|
|
102
103
|
this.mountApp(loader);
|
|
104
|
+
if (loader &&
|
|
105
|
+
typeof loader.getModuleWarnings === 'function' &&
|
|
106
|
+
hasProcess &&
|
|
107
|
+
hasConsole &&
|
|
108
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
109
|
+
process.env.NODE_ENV !== 'production') {
|
|
110
|
+
this.logWarnings(loader.getModuleWarnings(true)); // the true indicates the app is mounted
|
|
111
|
+
}
|
|
103
112
|
}
|
|
104
113
|
catch (e) {
|
|
105
114
|
this.enterErrorState(e);
|
|
@@ -184,5 +193,13 @@ export default class LoaderShim {
|
|
|
184
193
|
this.enterErrorState(new Error('Failed to load required modules - timed out'));
|
|
185
194
|
}, REQUIRED_MODULES_TIMEOUT);
|
|
186
195
|
}
|
|
196
|
+
logWarnings(warnings) {
|
|
197
|
+
for (const warningKey in warnings) {
|
|
198
|
+
if (warnings[warningKey].length) {
|
|
199
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
200
|
+
console.warn(warningKey, warnings[warningKey]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
187
204
|
}
|
|
188
205
|
//# sourceMappingURL=shimLegacy.js.map
|
package/build/types.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface BaseLoaderAPI {
|
|
|
18
18
|
registerExternalModules(modules: string[]): void;
|
|
19
19
|
services: Record<string, Function>;
|
|
20
20
|
clearRegistry: Function;
|
|
21
|
+
getModuleWarnings(isAppMounted: boolean): Record<string, string[]>;
|
|
21
22
|
}
|
|
22
23
|
export interface LoaderAPI extends BaseLoaderAPI {
|
|
23
24
|
registerImportMappings(mappings?: ImportMap): Promise<void>;
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.17.2-alpha.
|
|
8
|
+
"version": "0.17.2-alpha.6",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@locker/trusted-types": "0.23.6",
|
|
64
|
-
"@lwrjs/diagnostics": "0.17.2-alpha.
|
|
65
|
-
"@lwrjs/types": "0.17.2-alpha.
|
|
64
|
+
"@lwrjs/diagnostics": "0.17.2-alpha.6",
|
|
65
|
+
"@lwrjs/types": "0.17.2-alpha.6",
|
|
66
66
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
67
67
|
"@rollup/plugin-sucrase": "^5.0.2",
|
|
68
68
|
"@rollup/plugin-terser": "^0.4.4",
|
|
69
69
|
"rollup": "^2.79.2"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@lwrjs/client-modules": "0.17.2-alpha.
|
|
73
|
-
"@lwrjs/shared-utils": "0.17.2-alpha.
|
|
72
|
+
"@lwrjs/client-modules": "0.17.2-alpha.6",
|
|
73
|
+
"@lwrjs/shared-utils": "0.17.2-alpha.6"
|
|
74
74
|
},
|
|
75
75
|
"lwc": {
|
|
76
76
|
"modules": [
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"volta": {
|
|
91
91
|
"extends": "../../../package.json"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "e52a06333b7cd8d6d4bdc846ea9019d13f9fb85d"
|
|
94
94
|
}
|