@lwrjs/module-registry 0.6.0-alpha.9 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,7 +109,8 @@ var LwrModuleRegistry = class {
109
109
  const moduleCompiled = await this.delegateGetModuleOnProviders(moduleId, runtimeParams);
110
110
  if (locker.enabled && !locker.clientOnly) {
111
111
  const {runtimeEnvironment} = this.context;
112
- const sourcemap = typeof runtimeEnvironment.sourceMapUrl === "string";
112
+ const {minify, sourceMapUrl} = runtimeEnvironment;
113
+ const sourcemap = typeof sourceMapUrl === "string" || !minify;
113
114
  const {code: lockerizedCode} = this.context.compiler.lockerize(moduleCompiled, locker, sourcemap);
114
115
  moduleCompiled.compiledSource = lockerizedCode;
115
116
  }
@@ -161,7 +162,7 @@ var LwrModuleRegistry = class {
161
162
  id,
162
163
  code: linkedES6,
163
164
  linkedModuleRecord
164
- } = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, runtimeEnvironment, runtimeParams, {
165
+ } = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, {
165
166
  amdLoaderModule: loaderModuleEntry
166
167
  }, this.interchangeableModules);
167
168
  const {code: amdSource} = await this.context.compiler.convertToAmd(linkedES6, {
@@ -185,10 +186,10 @@ var LwrModuleRegistry = class {
185
186
  } else {
186
187
  let loaderModuleEntry;
187
188
  const dynamicImports = moduleDef.moduleRecord.dynamicImports;
188
- if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports && dynamicImports.some((d) => d.moduleNameType === import_shared_utils.ModuleNameType.unresolved)) {
189
+ if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports) {
189
190
  loaderModuleEntry = await this.getModuleEntry({specifier: esmLoader}, runtimeParams);
190
191
  }
191
- const {code: esmLinkedSource, linkedModuleRecord} = await (0, import_linker.link)(this, moduleDef, import_esm_strategy.default, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
192
+ const {code: esmLinkedSource, linkedModuleRecord} = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
192
193
  esmLoaderModule: loaderModuleEntry
193
194
  }, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
194
195
  let transformedEsmCode = esmLinkedSource;
@@ -29,12 +29,13 @@ __export(exports, {
29
29
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
30
  var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
31
31
  var import_signature = __toModule(require("../signature.cjs"));
32
- async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
32
+ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
33
33
  const {specifier, version, compiledSource, moduleRecord} = moduleDef;
34
34
  const {imports, dynamicImports} = moduleRecord;
35
35
  const codeStringBuilder = (0, import_shared_utils.createStringBuilder)(compiledSource);
36
36
  const amdLoaderModule = config?.amdLoaderModule;
37
37
  const esmLoaderModule = config?.esmLoaderModule;
38
+ const strategy = amdLoaderModule ? versionStrategy : uriStrategy;
38
39
  const id = strategy({specifier, version}, runtimeEnvironment, runtimeParams);
39
40
  let linkedImports = [];
40
41
  let linkedDynamicImports = [];
@@ -84,14 +85,14 @@ async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironment, run
84
85
  if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === "esm") {
85
86
  signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry);
86
87
  }
87
- const link2 = isStringLiteral ? strategy(importRef, runtimeEnvironment, runtimeParams, signature) : importRef.specifier;
88
+ const link2 = isStringLiteral ? versionStrategy(importRef, runtimeEnvironment, runtimeParams, signature) : importRef.specifier;
88
89
  const linkedLocations = locations.map(({location, importLocation}) => {
89
90
  const {startColumn, endColumn} = location;
90
91
  const {startColumn: importStart, endColumn: importEnd} = importLocation;
91
92
  if (isStringLiteral) {
92
93
  codeStringBuilder.overwrite(startColumn + 1, endColumn - 1, link2);
93
94
  }
94
- if (amdLoaderModule || esmLoaderModule && !isStringLiteral) {
95
+ if (amdLoaderModule || esmLoaderModule) {
95
96
  codeStringBuilder.overwrite(importStart, importEnd, "load(");
96
97
  loaderSizeOffset = 2;
97
98
  if (!isStringLiteral) {
package/build/es/index.js CHANGED
@@ -96,7 +96,10 @@ export class LwrModuleRegistry {
96
96
  /** Locker before collecting dep module records so locker imports are processed normally */
97
97
  if (locker.enabled && !locker.clientOnly) {
98
98
  const { runtimeEnvironment } = this.context;
99
- const sourcemap = typeof runtimeEnvironment.sourceMapUrl === 'string';
99
+ // Locker should generate inline source maps in non-minified modes
100
+ // in addition to being explicitly enabled.
101
+ const { minify, sourceMapUrl } = runtimeEnvironment;
102
+ const sourcemap = typeof sourceMapUrl === 'string' || !minify;
100
103
  const { code: lockerizedCode } = this.context.compiler.lockerize(moduleCompiled, locker, sourcemap);
101
104
  moduleCompiled.compiledSource = lockerizedCode;
102
105
  }
@@ -147,7 +150,7 @@ export class LwrModuleRegistry {
147
150
  // Resolve the loader entry
148
151
  const loaderModuleEntry = await this.getModuleEntry({ specifier: amdLoader }, runtimeParams);
149
152
  // transforms compiledModule into linkedModule (which means the imports may have changed)
150
- const { id, code: linkedES6, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, runtimeEnvironment, runtimeParams, {
153
+ const { id, code: linkedES6, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, {
151
154
  amdLoaderModule: loaderModuleEntry,
152
155
  }, this.interchangeableModules);
153
156
  // convert the linkedSource to the transport AMD format.
@@ -175,14 +178,12 @@ export class LwrModuleRegistry {
175
178
  // resolve the loader entry if there are VARIABLE dynamic imports
176
179
  let loaderModuleEntry;
177
180
  const dynamicImports = moduleDef.moduleRecord.dynamicImports;
178
- if (moduleDef.moduleEntry.specifier !== esmLoader &&
179
- dynamicImports &&
180
- dynamicImports.some((d) => d.moduleNameType === ModuleNameType.unresolved)) {
181
- // ONLY include the ESM loader if there are VARIABLE dynamic imports
181
+ if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports) {
182
+ // ONLY include the ESM loader if there are dynamic imports
182
183
  // AND this is not the ESM loader itself (it uses a variable dynamic import we DO NOT want to link)
183
184
  loaderModuleEntry = await this.getModuleEntry({ specifier: esmLoader }, runtimeParams);
184
185
  }
185
- const { code: esmLinkedSource, linkedModuleRecord } = await link(this, moduleDef, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
186
+ const { code: esmLinkedSource, linkedModuleRecord } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
186
187
  esmLoaderModule: loaderModuleEntry,
187
188
  }, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
188
189
  let transformedEsmCode = esmLinkedSource;
@@ -24,6 +24,6 @@ export interface ModuleLinkResult {
24
24
  * @param moduleRecord
25
25
  * @param strategy
26
26
  */
27
- export declare function link(moduleRegistry: LwrModuleRegistry, moduleDef: ModuleDefinition, strategy: LinkingStrategy, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, config?: LinkerConfig, interchangeableModules?: InterchangeableModuleMap, exclude?: string[]): Promise<ModuleLinkResult>;
27
+ export declare function link(moduleRegistry: LwrModuleRegistry, moduleDef: ModuleDefinition, versionStrategy: LinkingStrategy, uriStrategy: LinkingStrategy, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, config?: LinkerConfig, interchangeableModules?: InterchangeableModuleMap, exclude?: string[]): Promise<ModuleLinkResult>;
28
28
  export {};
29
29
  //# sourceMappingURL=linker.d.ts.map
@@ -7,12 +7,13 @@ import { getBundleSignature } from '../signature.js';
7
7
  * @param moduleRecord
8
8
  * @param strategy
9
9
  */
10
- export async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
10
+ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
11
11
  const { specifier, version, compiledSource, moduleRecord } = moduleDef;
12
12
  const { imports, dynamicImports } = moduleRecord;
13
13
  const codeStringBuilder = createStringBuilder(compiledSource);
14
14
  const amdLoaderModule = config?.amdLoaderModule;
15
15
  const esmLoaderModule = config?.esmLoaderModule;
16
+ const strategy = amdLoaderModule ? versionStrategy : uriStrategy;
16
17
  const id = strategy({ specifier, version }, runtimeEnvironment, runtimeParams);
17
18
  // transform each import using the provided linking strategy.
18
19
  let linkedImports = [];
@@ -70,9 +71,11 @@ export async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironme
70
71
  if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === 'esm') {
71
72
  signature = await getBundleSignature(importRef, moduleRegistry);
72
73
  }
74
+ // always link [literal] dynamic imports as versioned specifiers (AMD strategy)
75
+ // linking them as URIs (ESM strategy) causes caching issues since they can contain stale signatures
73
76
  const link = isStringLiteral
74
- ? strategy(importRef, runtimeEnvironment, runtimeParams, signature) // dynamic import of a static string
75
- : importRef.specifier; // variable dynamic import; keep the variable name as-is
77
+ ? versionStrategy(importRef, runtimeEnvironment, runtimeParams, signature) // dynamic import of a static string
78
+ : importRef.specifier; // variable dynamic imports: keep the variable name as-is
76
79
  // transform locations
77
80
  // replace all locations of importee with the link
78
81
  const linkedLocations = locations.map(({ location, importLocation }) => {
@@ -82,9 +85,8 @@ export async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironme
82
85
  if (isStringLiteral) {
83
86
  codeStringBuilder.overwrite(startColumn + 1, endColumn - 1, link);
84
87
  }
85
- if (amdLoaderModule || (esmLoaderModule && !isStringLiteral)) {
88
+ if (amdLoaderModule || esmLoaderModule) {
86
89
  // replace the dynamic import with a configured loader
87
- // ONLY do this in ESM if the dynamic import is VARIABLE
88
90
  // e.g. - await import('dynamic/module'); -> await load('dynamic/module');
89
91
  codeStringBuilder.overwrite(importStart, importEnd, 'load(');
90
92
  loaderSizeOffset = 2;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.9",
7
+ "version": "0.6.2",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,18 +30,18 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/diagnostics": "0.6.0-alpha.9",
34
- "@lwrjs/shared-utils": "0.6.0-alpha.9",
33
+ "@lwrjs/diagnostics": "0.6.2",
34
+ "@lwrjs/shared-utils": "0.6.2",
35
35
  "es-module-lexer": "^0.3.18",
36
36
  "ws": "^7.2.5"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.6.0-alpha.9",
39
+ "@lwrjs/types": "0.6.2",
40
40
  "@types/es-module-lexer": "^0.3.0",
41
41
  "@types/ws": "^7.2.4"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=14.15.4 <17"
45
45
  },
46
- "gitHead": "9cb371a5d01ef345660138a48fe0b3f0119d0799"
46
+ "gitHead": "ef85bdc48adde58b7c648561d67acbb408bbe189"
47
47
  }