@lwrjs/module-registry 0.12.0-alpha.3 → 0.12.0-alpha.31
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/cjs/externals-module-provider.cjs +79 -0
- package/build/cjs/index.cjs +17 -2
- package/build/cjs/linker/linker.cjs +5 -4
- package/build/cjs/linker/strategies/esm-strategy.cjs +4 -1
- package/build/es/externals-module-provider.d.ts +13 -0
- package/build/es/externals-module-provider.js +58 -0
- package/build/es/index.d.ts +2 -1
- package/build/es/index.js +23 -3
- package/build/es/linker/linker.d.ts +3 -3
- package/build/es/linker/linker.js +6 -6
- package/build/es/linker/strategies/esm-strategy.d.ts +1 -1
- package/build/es/linker/strategies/esm-strategy.js +4 -1
- package/package.json +11 -5
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
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);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/module-registry/src/externals-module-provider.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
default: () => externals_module_provider_default
|
|
28
|
+
});
|
|
29
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
|
+
var import_fs_extra = __toModule(require("fs-extra"));
|
|
31
|
+
var import_url = __toModule(require("url"));
|
|
32
|
+
var ExternalsModuleProvider = class {
|
|
33
|
+
constructor(_config, context) {
|
|
34
|
+
this.name = "externals-module-provider";
|
|
35
|
+
this.externals = context?.config.bundleConfig?.external || {};
|
|
36
|
+
}
|
|
37
|
+
async getModuleEntry(moduleId) {
|
|
38
|
+
const {specifier, version} = moduleId;
|
|
39
|
+
if (specifier && Object.prototype.hasOwnProperty.call(this.externals, specifier)) {
|
|
40
|
+
const entry = this.externals[specifier];
|
|
41
|
+
const resolvedVersion = version || import_shared_utils.VERSION_NOT_PROVIDED;
|
|
42
|
+
return {
|
|
43
|
+
virtual: true,
|
|
44
|
+
id: (0, import_shared_utils.getSpecifier)({...moduleId, version: resolvedVersion}),
|
|
45
|
+
entry,
|
|
46
|
+
specifier,
|
|
47
|
+
version: resolvedVersion
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
async getModule(moduleId) {
|
|
53
|
+
const moduleEntry = await this.getModuleEntry(moduleId);
|
|
54
|
+
if (moduleEntry) {
|
|
55
|
+
let originalSource = "";
|
|
56
|
+
let ownHash = "";
|
|
57
|
+
const srcUri = this.externals[moduleEntry.specifier];
|
|
58
|
+
if (srcUri && srcUri.startsWith(import_shared_utils.PROTOCOL_FILE)) {
|
|
59
|
+
const srcPath = import_url.default.fileURLToPath(srcUri);
|
|
60
|
+
originalSource = (await import_fs_extra.default.readFile(srcPath)).toString();
|
|
61
|
+
ownHash = (0, import_shared_utils.hashContent)(originalSource);
|
|
62
|
+
}
|
|
63
|
+
const {name, namespace} = (0, import_shared_utils.explodeSpecifier)(moduleEntry.specifier);
|
|
64
|
+
return {
|
|
65
|
+
id: moduleEntry.id,
|
|
66
|
+
moduleEntry,
|
|
67
|
+
specifier: moduleEntry.specifier,
|
|
68
|
+
name,
|
|
69
|
+
namespace,
|
|
70
|
+
version: moduleEntry.version,
|
|
71
|
+
compiledSource: originalSource,
|
|
72
|
+
ownHash,
|
|
73
|
+
originalSource
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var externals_module_provider_default = ExternalsModuleProvider;
|
package/build/cjs/index.cjs
CHANGED
|
@@ -101,6 +101,11 @@ var LwrModuleRegistry = class {
|
|
|
101
101
|
addModuleProviders(registries) {
|
|
102
102
|
this.providers.push(...registries);
|
|
103
103
|
}
|
|
104
|
+
getConfig() {
|
|
105
|
+
return {
|
|
106
|
+
bundleConfig: this.globalConfig.bundleConfig || {}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
104
109
|
getModuleEntry(moduleId, runtimeParams) {
|
|
105
110
|
return this.delegateGetModuleEntryOnServices(moduleId, runtimeParams);
|
|
106
111
|
}
|
|
@@ -152,7 +157,7 @@ var LwrModuleRegistry = class {
|
|
|
152
157
|
}
|
|
153
158
|
const moduleDef = await this.getModule(moduleId, runtimeParams);
|
|
154
159
|
const moduleLinked = await this.createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams);
|
|
155
|
-
if (format === "amd" && !bundle) {
|
|
160
|
+
if (format === "amd" && !bundle && !(0, import_shared_utils.isExternalFileSpecifier)(moduleLinked.specifier, this.getConfig().bundleConfig)) {
|
|
156
161
|
moduleLinked.linkedSource = (await (0, import_compiler.convertToAmd)(moduleLinked.linkedSource, {
|
|
157
162
|
id: moduleLinked.id
|
|
158
163
|
})).code;
|
|
@@ -209,7 +214,7 @@ var LwrModuleRegistry = class {
|
|
|
209
214
|
linkedModuleRecord
|
|
210
215
|
} = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
|
|
211
216
|
esmLoaderModule: loaderModuleEntry
|
|
212
|
-
}, this.interchangeableModules, this.globalConfig.bundleConfig
|
|
217
|
+
}, this.interchangeableModules, this.globalConfig.bundleConfig);
|
|
213
218
|
linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== import_shared_utils.ModuleNameType.unresolved);
|
|
214
219
|
return {
|
|
215
220
|
...moduleDef,
|
|
@@ -228,6 +233,9 @@ var LwrModuleRegistry = class {
|
|
|
228
233
|
for (const registry of this.providers) {
|
|
229
234
|
const result = await registry.getModuleEntry(moduleId, runtimeParams);
|
|
230
235
|
if (result) {
|
|
236
|
+
if (!result.version) {
|
|
237
|
+
result.version = import_shared_utils.VERSION_NOT_PROVIDED;
|
|
238
|
+
}
|
|
231
239
|
return result;
|
|
232
240
|
}
|
|
233
241
|
}
|
|
@@ -239,6 +247,12 @@ var LwrModuleRegistry = class {
|
|
|
239
247
|
for (const registry of this.providers) {
|
|
240
248
|
const result = await registry.getModule(moduleId, runtimeParams);
|
|
241
249
|
if (result) {
|
|
250
|
+
if (!result.version) {
|
|
251
|
+
result.version = import_shared_utils.VERSION_NOT_PROVIDED;
|
|
252
|
+
}
|
|
253
|
+
if (!result.moduleEntry.version) {
|
|
254
|
+
result.moduleEntry.version = import_shared_utils.VERSION_NOT_PROVIDED;
|
|
255
|
+
}
|
|
242
256
|
return result;
|
|
243
257
|
}
|
|
244
258
|
}
|
|
@@ -251,6 +265,7 @@ var LwrModuleRegistry = class {
|
|
|
251
265
|
getModuleEntry: this.getModuleEntry.bind(this),
|
|
252
266
|
getModule: this.getModule.bind(this),
|
|
253
267
|
getLinkedModule: this.getLinkedModule.bind(this),
|
|
268
|
+
getConfig: this.getConfig.bind(this),
|
|
254
269
|
resolveModuleUri: this.resolveModuleUri.bind(this)
|
|
255
270
|
};
|
|
256
271
|
}
|
|
@@ -29,9 +29,10 @@ __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, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules,
|
|
32
|
+
async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, bundleConfig) {
|
|
33
33
|
const {specifier, version, compiledSource, moduleRecord} = moduleDef;
|
|
34
34
|
const {imports, dynamicImports, importMeta} = moduleRecord;
|
|
35
|
+
const {exclude, external} = bundleConfig || {};
|
|
35
36
|
const codeStringBuilder = (0, import_shared_utils.createStringBuilder)(compiledSource);
|
|
36
37
|
const amdLoaderModule = config?.amdLoaderModule;
|
|
37
38
|
const esmLoaderModule = config?.esmLoaderModule;
|
|
@@ -64,7 +65,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
64
65
|
signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry, runtimeParams, exclude);
|
|
65
66
|
}
|
|
66
67
|
const {locations, sourceSpecifier} = importRef;
|
|
67
|
-
const link2 = strategy(importRef, runtimeEnvironment, runtimeParams, signature);
|
|
68
|
+
const link2 = strategy(importRef, runtimeEnvironment, runtimeParams, signature, void 0, external);
|
|
68
69
|
const linkedLocations = locations.map((location) => {
|
|
69
70
|
const {startColumn, endColumn} = location;
|
|
70
71
|
codeStringBuilder.overwrite(startColumn, endColumn, link2);
|
|
@@ -148,9 +149,9 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
148
149
|
codeStringBuilder.overwrite(location.startColumn, location.endColumn, "isServer");
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
|
-
const envSpecifier = "lwr/environment";
|
|
152
|
+
const {specifier: envSpecifier, version: envVersion} = await moduleRegistry.getModuleEntry({specifier: "lwr/environment"}, runtimeParams);
|
|
152
153
|
const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(envSpecifier);
|
|
153
|
-
const envLink = strategy({specifier: envSpecifier, version:
|
|
154
|
+
const envLink = strategy({specifier: envSpecifier, version: envVersion}, runtimeEnvironment, runtimeParams);
|
|
154
155
|
const envImport = `import { isServer } from "${envLink}";
|
|
155
156
|
`;
|
|
156
157
|
codeStringBuilder.prepend(envImport);
|
|
@@ -29,9 +29,12 @@ __export(exports, {
|
|
|
29
29
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
30
|
var SIGNATURE_SIGIL = "s";
|
|
31
31
|
var LATEST_SIG = "latest";
|
|
32
|
-
function linkEsm(moduleId, environment, params = {}, signature, bundleId) {
|
|
32
|
+
function linkEsm(moduleId, environment, params = {}, signature, bundleId, external) {
|
|
33
33
|
const {bundle, debug} = environment;
|
|
34
34
|
const {specifier, version} = moduleId;
|
|
35
|
+
if (external && external[specifier]) {
|
|
36
|
+
return specifier;
|
|
37
|
+
}
|
|
35
38
|
const uriPrefix = (0, import_shared_utils.getModuleUriPrefix)(environment, params, bundleId);
|
|
36
39
|
const vSpecifier = (0, import_shared_utils.getSpecifier)({specifier, version: (0, import_shared_utils.normalizeVersionToUri)(version)});
|
|
37
40
|
const encodedVSpecifier = encodeURIComponent(vSpecifier);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AbstractModuleId, ModuleCompiled, ModuleEntry, ModuleProvider, ProviderContext } from '@lwrjs/types';
|
|
2
|
+
/**
|
|
3
|
+
* Module provider to create module definitions based on the
|
|
4
|
+
* externals in the bundle configuration
|
|
5
|
+
*/
|
|
6
|
+
export default class ExternalsModuleProvider implements ModuleProvider {
|
|
7
|
+
name: string;
|
|
8
|
+
externals: Record<string, string>;
|
|
9
|
+
constructor(_config: never, context?: ProviderContext);
|
|
10
|
+
getModuleEntry(moduleId: AbstractModuleId): Promise<ModuleEntry | undefined>;
|
|
11
|
+
getModule(moduleId: AbstractModuleId): Promise<ModuleCompiled | undefined>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=externals-module-provider.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PROTOCOL_FILE, VERSION_NOT_PROVIDED, explodeSpecifier, getSpecifier, hashContent, } from '@lwrjs/shared-utils';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
/**
|
|
5
|
+
* Module provider to create module definitions based on the
|
|
6
|
+
* externals in the bundle configuration
|
|
7
|
+
*/
|
|
8
|
+
export default class ExternalsModuleProvider {
|
|
9
|
+
constructor(_config, context) {
|
|
10
|
+
this.name = 'externals-module-provider';
|
|
11
|
+
this.externals = context?.config.bundleConfig?.external || {};
|
|
12
|
+
}
|
|
13
|
+
async getModuleEntry(moduleId) {
|
|
14
|
+
const { specifier, version } = moduleId;
|
|
15
|
+
// TODO We should upgrade the compiler to ES2022 and use Object.hasOwn()
|
|
16
|
+
if (specifier && Object.prototype.hasOwnProperty.call(this.externals, specifier)) {
|
|
17
|
+
const entry = this.externals[specifier];
|
|
18
|
+
const resolvedVersion = version || VERSION_NOT_PROVIDED;
|
|
19
|
+
return {
|
|
20
|
+
virtual: true,
|
|
21
|
+
id: getSpecifier({ ...moduleId, version: resolvedVersion }),
|
|
22
|
+
entry,
|
|
23
|
+
specifier: specifier,
|
|
24
|
+
version: resolvedVersion,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// proceed to next provider
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
async getModule(moduleId) {
|
|
31
|
+
const moduleEntry = await this.getModuleEntry(moduleId);
|
|
32
|
+
if (moduleEntry) {
|
|
33
|
+
let originalSource = '';
|
|
34
|
+
let ownHash = '';
|
|
35
|
+
const srcUri = this.externals[moduleEntry.specifier];
|
|
36
|
+
if (srcUri && srcUri.startsWith(PROTOCOL_FILE)) {
|
|
37
|
+
const srcPath = url.fileURLToPath(srcUri);
|
|
38
|
+
originalSource = (await fs.readFile(srcPath)).toString();
|
|
39
|
+
ownHash = hashContent(originalSource);
|
|
40
|
+
}
|
|
41
|
+
const { name, namespace } = explodeSpecifier(moduleEntry.specifier);
|
|
42
|
+
return {
|
|
43
|
+
id: moduleEntry.id,
|
|
44
|
+
moduleEntry,
|
|
45
|
+
specifier: moduleEntry.specifier,
|
|
46
|
+
name,
|
|
47
|
+
namespace,
|
|
48
|
+
version: moduleEntry.version,
|
|
49
|
+
compiledSource: originalSource,
|
|
50
|
+
ownHash,
|
|
51
|
+
originalSource,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// proceed to next provider
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=externals-module-provider.js.map
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractModuleId, LinkedModuleDefinition, LwrAppEmitter, LwrAppObserver, ModuleDefinition, ModuleEntry, ModuleId, ModuleProvider, ModuleRegistry, NormalizedLwrGlobalConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
1
|
+
import type { AbstractModuleId, LinkedModuleDefinition, LwrAppEmitter, LwrAppObserver, ModuleDefinition, ModuleEntry, ModuleId, ModuleProvider, ModuleRegistry, ModuleRegistryConfig, NormalizedLwrGlobalConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
interface RegistryContext {
|
|
3
3
|
appObserver: LwrAppObserver;
|
|
4
4
|
appEmitter: LwrAppEmitter;
|
|
@@ -18,6 +18,7 @@ export declare class LwrModuleRegistry implements ModuleRegistry {
|
|
|
18
18
|
resolveModuleUriSync<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, signature: S, runtimeEnvironment: R, runtimeParams: RuntimeParams): string;
|
|
19
19
|
resolveModuleUri<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: R, runtimeParams: RuntimeParams, signature?: S): Promise<string>;
|
|
20
20
|
addModuleProviders(registries: ModuleProvider[]): void;
|
|
21
|
+
getConfig(): ModuleRegistryConfig;
|
|
21
22
|
getModuleEntry<T extends AbstractModuleId>(moduleId: T, runtimeParams: RuntimeParams): Promise<ModuleEntry>;
|
|
22
23
|
getModule<T extends AbstractModuleId>(moduleId: T, runtimeParams: RuntimeParams): Promise<ModuleDefinition>;
|
|
23
24
|
private createModuleDefinition;
|
package/build/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LwrUnresolvableError, createSingleDiagnosticError, descriptions, logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { discoverInterchangeableModules, getCacheKeyFromJson, InflightTasks, LATEST_SIGNATURE, ModuleNameType, getGroupName, } from '@lwrjs/shared-utils';
|
|
2
|
+
import { discoverInterchangeableModules, getCacheKeyFromJson, InflightTasks, LATEST_SIGNATURE, ModuleNameType, getGroupName, VERSION_NOT_PROVIDED, isExternalFileSpecifier, } from '@lwrjs/shared-utils';
|
|
3
3
|
// dependencies @locker/compiler and rollup are in this package.json is to satisfy the shared-utils/compiler optional dependencies
|
|
4
4
|
import { convertToAmd } from '@lwrjs/shared-utils/compiler';
|
|
5
5
|
import { link } from './linker/linker.js';
|
|
@@ -90,6 +90,11 @@ export class LwrModuleRegistry {
|
|
|
90
90
|
addModuleProviders(registries) {
|
|
91
91
|
this.providers.push(...registries);
|
|
92
92
|
}
|
|
93
|
+
getConfig() {
|
|
94
|
+
return {
|
|
95
|
+
bundleConfig: this.globalConfig.bundleConfig || {},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
93
98
|
getModuleEntry(moduleId, runtimeParams) {
|
|
94
99
|
return this.delegateGetModuleEntryOnServices(moduleId, runtimeParams);
|
|
95
100
|
}
|
|
@@ -143,7 +148,10 @@ export class LwrModuleRegistry {
|
|
|
143
148
|
const moduleDef = await this.getModule(moduleId, runtimeParams);
|
|
144
149
|
const moduleLinked = await this.createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams);
|
|
145
150
|
// the bundler will convert the linked source to AMD when bundling is enabled
|
|
146
|
-
if (format === 'amd' &&
|
|
151
|
+
if (format === 'amd' &&
|
|
152
|
+
!bundle &&
|
|
153
|
+
// Assume file based externals source are already in AMD
|
|
154
|
+
!isExternalFileSpecifier(moduleLinked.specifier, this.getConfig().bundleConfig)) {
|
|
147
155
|
// convert the linkedSource to the transport AMD format
|
|
148
156
|
moduleLinked.linkedSource = (await convertToAmd(moduleLinked.linkedSource, {
|
|
149
157
|
id: moduleLinked.id,
|
|
@@ -202,7 +210,7 @@ export class LwrModuleRegistry {
|
|
|
202
210
|
}
|
|
203
211
|
const { id, code: linkedSource, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
|
|
204
212
|
esmLoaderModule: loaderModuleEntry,
|
|
205
|
-
}, this.interchangeableModules, this.globalConfig.bundleConfig
|
|
213
|
+
}, this.interchangeableModules, this.globalConfig.bundleConfig);
|
|
206
214
|
// Filter out variable dynamic imports
|
|
207
215
|
linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== ModuleNameType.unresolved);
|
|
208
216
|
return {
|
|
@@ -224,6 +232,10 @@ export class LwrModuleRegistry {
|
|
|
224
232
|
// eslint-disable-next-line no-await-in-loop
|
|
225
233
|
const result = await registry.getModuleEntry(moduleId, runtimeParams);
|
|
226
234
|
if (result) {
|
|
235
|
+
// If version is not set in the provider set it to 'version-not-provided' so we know it has been resolved.
|
|
236
|
+
if (!result.version) {
|
|
237
|
+
result.version = VERSION_NOT_PROVIDED;
|
|
238
|
+
}
|
|
227
239
|
return result;
|
|
228
240
|
}
|
|
229
241
|
}
|
|
@@ -236,6 +248,13 @@ export class LwrModuleRegistry {
|
|
|
236
248
|
// eslint-disable-next-line no-await-in-loop
|
|
237
249
|
const result = await registry.getModule(moduleId, runtimeParams);
|
|
238
250
|
if (result) {
|
|
251
|
+
// If version is not set in the provider set it to 'version-not-provided' so we know it has been resolved.
|
|
252
|
+
if (!result.version) {
|
|
253
|
+
result.version = VERSION_NOT_PROVIDED;
|
|
254
|
+
}
|
|
255
|
+
if (!result.moduleEntry.version) {
|
|
256
|
+
result.moduleEntry.version = VERSION_NOT_PROVIDED;
|
|
257
|
+
}
|
|
239
258
|
return result;
|
|
240
259
|
}
|
|
241
260
|
}
|
|
@@ -248,6 +267,7 @@ export class LwrModuleRegistry {
|
|
|
248
267
|
getModuleEntry: this.getModuleEntry.bind(this),
|
|
249
268
|
getModule: this.getModule.bind(this),
|
|
250
269
|
getLinkedModule: this.getLinkedModule.bind(this),
|
|
270
|
+
getConfig: this.getConfig.bind(this),
|
|
251
271
|
resolveModuleUri: this.resolveModuleUri.bind(this),
|
|
252
272
|
};
|
|
253
273
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ModuleRecord, ModuleEntry, ModuleDefinition, RuntimeEnvironment, Specifier, RuntimeParams, InterchangeableModuleMap } from '@lwrjs/types';
|
|
1
|
+
import type { ModuleRecord, ModuleEntry, ModuleDefinition, RuntimeEnvironment, Specifier, RuntimeParams, InterchangeableModuleMap, BundleConfig } from '@lwrjs/types';
|
|
2
2
|
import type { LwrModuleRegistry } from '../index.js';
|
|
3
3
|
export interface LinkingStrategy {
|
|
4
4
|
(moduleId: {
|
|
5
5
|
specifier: Specifier;
|
|
6
6
|
version: string;
|
|
7
|
-
}, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, signature?: string): string;
|
|
7
|
+
}, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, signature?: string, bundleId?: string, external?: Record<string, string>): string;
|
|
8
8
|
}
|
|
9
9
|
interface AmdLinkerConfig {
|
|
10
10
|
amdLoaderModule: ModuleEntry;
|
|
@@ -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, versionStrategy: LinkingStrategy, uriStrategy: LinkingStrategy, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, config?: LinkerConfig, interchangeableModules?: InterchangeableModuleMap,
|
|
27
|
+
export declare function link(moduleRegistry: LwrModuleRegistry, moduleDef: ModuleDefinition, versionStrategy: LinkingStrategy, uriStrategy: LinkingStrategy, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, config?: LinkerConfig, interchangeableModules?: InterchangeableModuleMap, bundleConfig?: BundleConfig): Promise<ModuleLinkResult>;
|
|
28
28
|
export {};
|
|
29
29
|
//# sourceMappingURL=linker.d.ts.map
|
|
@@ -7,9 +7,10 @@ import { getBundleSignature } from '../signature.js';
|
|
|
7
7
|
* @param moduleRecord
|
|
8
8
|
* @param strategy
|
|
9
9
|
*/
|
|
10
|
-
export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules,
|
|
10
|
+
export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, bundleConfig) {
|
|
11
11
|
const { specifier, version, compiledSource, moduleRecord } = moduleDef;
|
|
12
12
|
const { imports, dynamicImports, importMeta } = moduleRecord;
|
|
13
|
+
const { exclude, external } = bundleConfig || {};
|
|
13
14
|
const codeStringBuilder = createStringBuilder(compiledSource);
|
|
14
15
|
const amdLoaderModule = config?.amdLoaderModule;
|
|
15
16
|
const esmLoaderModule = config?.esmLoaderModule;
|
|
@@ -40,14 +41,14 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
let signature;
|
|
43
|
-
// get signature for
|
|
44
|
+
// get signature for excluded modules when bundling esm
|
|
44
45
|
if (runtimeEnvironment.bundle &&
|
|
45
46
|
runtimeEnvironment.format === 'esm' &&
|
|
46
47
|
exclude?.includes(importRef.specifier)) {
|
|
47
48
|
signature = await getBundleSignature(importRef, moduleRegistry, runtimeParams, exclude);
|
|
48
49
|
}
|
|
49
50
|
const { locations, sourceSpecifier } = importRef;
|
|
50
|
-
const link = strategy(importRef, runtimeEnvironment, runtimeParams, signature);
|
|
51
|
+
const link = strategy(importRef, runtimeEnvironment, runtimeParams, signature, undefined, external);
|
|
51
52
|
// replace all locations of importee with the link
|
|
52
53
|
const linkedLocations = locations.map((location) => {
|
|
53
54
|
const { startColumn, endColumn } = location;
|
|
@@ -149,10 +150,9 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
149
150
|
codeStringBuilder.overwrite(location.startColumn, location.endColumn, 'isServer');
|
|
150
151
|
}
|
|
151
152
|
});
|
|
152
|
-
|
|
153
|
-
const envSpecifier = 'lwr/environment';
|
|
153
|
+
const { specifier: envSpecifier, version: envVersion } = await moduleRegistry.getModuleEntry({ specifier: 'lwr/environment' }, runtimeParams);
|
|
154
154
|
const { namespace, name } = explodeSpecifier(envSpecifier);
|
|
155
|
-
const envLink = strategy({ specifier: envSpecifier, version:
|
|
155
|
+
const envLink = strategy({ specifier: envSpecifier, version: envVersion }, runtimeEnvironment, runtimeParams);
|
|
156
156
|
const envImport = `import { isServer } from "${envLink}";\n`;
|
|
157
157
|
codeStringBuilder.prepend(envImport);
|
|
158
158
|
linkedImports.unshift({
|
|
@@ -2,5 +2,5 @@ import type { RuntimeEnvironment, RuntimeParams, Specifier } from '@lwrjs/types'
|
|
|
2
2
|
export default function linkEsm(moduleId: {
|
|
3
3
|
specifier: Specifier;
|
|
4
4
|
version: string;
|
|
5
|
-
}, environment: RuntimeEnvironment, params?: RuntimeParams, signature?: string, bundleId?: string): string;
|
|
5
|
+
}, environment: RuntimeEnvironment, params?: RuntimeParams, signature?: string, bundleId?: string, external?: Record<string, string>): string;
|
|
6
6
|
//# sourceMappingURL=esm-strategy.d.ts.map
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { getModuleUriPrefix, getSpecifier, normalizeVersionToUri, prettyModuleUriSuffix, } from '@lwrjs/shared-utils';
|
|
2
2
|
const SIGNATURE_SIGIL = 's';
|
|
3
3
|
const LATEST_SIG = 'latest';
|
|
4
|
-
export default function linkEsm(moduleId, environment, params = {}, signature, bundleId) {
|
|
4
|
+
export default function linkEsm(moduleId, environment, params = {}, signature, bundleId, external) {
|
|
5
5
|
const { bundle, debug } = environment;
|
|
6
6
|
const { specifier, version } = moduleId;
|
|
7
|
+
if (external && external[specifier]) {
|
|
8
|
+
return specifier;
|
|
9
|
+
}
|
|
7
10
|
const uriPrefix = getModuleUriPrefix(environment, params, bundleId);
|
|
8
11
|
const vSpecifier = getSpecifier({ specifier, version: normalizeVersionToUri(version) });
|
|
9
12
|
const encodedVSpecifier = encodeURIComponent(vSpecifier);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.12.0-alpha.
|
|
7
|
+
"version": "0.12.0-alpha.31",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
".": {
|
|
23
23
|
"import": "./build/es/index.js",
|
|
24
24
|
"require": "./build/cjs/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./externals-module-provider": {
|
|
27
|
+
"import": "./build/es/externals-module-provider.js",
|
|
28
|
+
"require": "./build/cjs/externals-module-provider.cjs"
|
|
25
29
|
}
|
|
26
30
|
},
|
|
27
31
|
"files": [
|
|
@@ -30,15 +34,17 @@
|
|
|
30
34
|
"build/**/*.d.ts"
|
|
31
35
|
],
|
|
32
36
|
"dependencies": {
|
|
33
|
-
"@lwrjs/
|
|
34
|
-
"@lwrjs/
|
|
37
|
+
"@lwrjs/config": "0.12.0-alpha.31",
|
|
38
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.31",
|
|
39
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.31",
|
|
40
|
+
"fs-extra": "^11.1.1",
|
|
35
41
|
"rollup": "^2.78.0"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
38
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
44
|
+
"@lwrjs/types": "0.12.0-alpha.31"
|
|
39
45
|
},
|
|
40
46
|
"engines": {
|
|
41
47
|
"node": ">=18.0.0"
|
|
42
48
|
},
|
|
43
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "ef2602996527852ec4694104723baae93a130b87"
|
|
44
50
|
}
|