@lwrjs/module-registry 0.12.0-alpha.20 → 0.12.0-alpha.22
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 +8 -2
- package/build/cjs/linker/linker.cjs +3 -2
- package/build/cjs/linker/strategies/esm-strategy.cjs +4 -1
- package/build/cjs/module-record.cjs +16 -0
- 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 +11 -3
- package/build/es/linker/linker.d.ts +3 -3
- package/build/es/linker/linker.js +4 -3
- package/build/es/linker/strategies/esm-strategy.d.ts +1 -1
- package/build/es/linker/strategies/esm-strategy.js +4 -1
- package/build/es/module-record.js +18 -1
- package/package.json +11 -6
|
@@ -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.isExternalSpecifier)(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,
|
|
@@ -251,6 +256,7 @@ var LwrModuleRegistry = class {
|
|
|
251
256
|
getModuleEntry: this.getModuleEntry.bind(this),
|
|
252
257
|
getModule: this.getModule.bind(this),
|
|
253
258
|
getLinkedModule: this.getLinkedModule.bind(this),
|
|
259
|
+
getConfig: this.getConfig.bind(this),
|
|
254
260
|
resolveModuleUri: this.resolveModuleUri.bind(this)
|
|
255
261
|
};
|
|
256
262
|
}
|
|
@@ -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);
|
|
@@ -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);
|
|
@@ -74,6 +74,8 @@ async function getModuleRecord(compiledModule, registry, runtimeParams) {
|
|
|
74
74
|
const dynamicImports = [];
|
|
75
75
|
const {compiledMetadata: defaultCompilerMetadata, moduleEntry, version} = compiledModule;
|
|
76
76
|
const compiledMetadata = defaultCompilerMetadata || {};
|
|
77
|
+
const {bundleConfig} = registry.getConfig();
|
|
78
|
+
const {external: externalsConfig} = bundleConfig || {};
|
|
77
79
|
const {
|
|
78
80
|
imports: compiledModuleImports,
|
|
79
81
|
dynamicImports: compiledModuleDynamicImports,
|
|
@@ -127,6 +129,20 @@ async function getModuleRecord(compiledModule, registry, runtimeParams) {
|
|
|
127
129
|
}
|
|
128
130
|
]
|
|
129
131
|
});
|
|
132
|
+
} else if (externalsConfig && externalsConfig[moduleSpecifier] !== void 0) {
|
|
133
|
+
dynamicImports.push({
|
|
134
|
+
specifier: moduleSpecifier,
|
|
135
|
+
sourceSpecifier: moduleSpecifier,
|
|
136
|
+
version: import_shared_utils.VERSION_NOT_PROVIDED,
|
|
137
|
+
name: moduleNameType,
|
|
138
|
+
moduleNameType,
|
|
139
|
+
locations: [
|
|
140
|
+
{
|
|
141
|
+
location,
|
|
142
|
+
importLocation
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
});
|
|
130
146
|
} else if (moduleSpecifier.startsWith(".")) {
|
|
131
147
|
const {locations, ...resolvedImport} = await resolveRelativeImport(registry, moduleSpecifier, moduleEntry, version, location, runtimeParams);
|
|
132
148
|
dynamicImports.push({
|
|
@@ -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, isExternalSpecifier, } 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,9 @@ 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
|
+
!isExternalSpecifier(moduleLinked.specifier, this.getConfig().bundleConfig)) {
|
|
147
154
|
// convert the linkedSource to the transport AMD format
|
|
148
155
|
moduleLinked.linkedSource = (await convertToAmd(moduleLinked.linkedSource, {
|
|
149
156
|
id: moduleLinked.id,
|
|
@@ -202,7 +209,7 @@ export class LwrModuleRegistry {
|
|
|
202
209
|
}
|
|
203
210
|
const { id, code: linkedSource, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
|
|
204
211
|
esmLoaderModule: loaderModuleEntry,
|
|
205
|
-
}, this.interchangeableModules, this.globalConfig.bundleConfig
|
|
212
|
+
}, this.interchangeableModules, this.globalConfig.bundleConfig);
|
|
206
213
|
// Filter out variable dynamic imports
|
|
207
214
|
linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== ModuleNameType.unresolved);
|
|
208
215
|
return {
|
|
@@ -248,6 +255,7 @@ export class LwrModuleRegistry {
|
|
|
248
255
|
getModuleEntry: this.getModuleEntry.bind(this),
|
|
249
256
|
getModule: this.getModule.bind(this),
|
|
250
257
|
getLinkedModule: this.getLinkedModule.bind(this),
|
|
258
|
+
getConfig: this.getConfig.bind(this),
|
|
251
259
|
resolveModuleUri: this.resolveModuleUri.bind(this),
|
|
252
260
|
};
|
|
253
261
|
}
|
|
@@ -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;
|
|
@@ -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);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { explodeSpecifier, getImportMetadata, ModuleNameType } from '@lwrjs/shared-utils';
|
|
2
|
+
import { explodeSpecifier, getImportMetadata, ModuleNameType, VERSION_NOT_PROVIDED, } from '@lwrjs/shared-utils';
|
|
3
3
|
async function resolveRelativeImport(registry, moduleSpecifier, importeeEntry, version, location, runtimeParams) {
|
|
4
4
|
// Resolve any relative parts in the import specifier
|
|
5
5
|
// eg: "c/app#app.html" => "c/app"
|
|
@@ -56,6 +56,8 @@ export async function getModuleRecord(compiledModule, registry, runtimeParams) {
|
|
|
56
56
|
const dynamicImports = [];
|
|
57
57
|
const { compiledMetadata: defaultCompilerMetadata, moduleEntry, version } = compiledModule;
|
|
58
58
|
const compiledMetadata = defaultCompilerMetadata || {};
|
|
59
|
+
const { bundleConfig } = registry.getConfig();
|
|
60
|
+
const { external: externalsConfig } = bundleConfig || {};
|
|
59
61
|
// Get imports metadata and merge with rest of compiledModule metadata
|
|
60
62
|
const { imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports, importMeta, } = await getImportMetadata(compiledModule.compiledSource);
|
|
61
63
|
Object.assign(compiledMetadata, {
|
|
@@ -112,6 +114,21 @@ export async function getModuleRecord(compiledModule, registry, runtimeParams) {
|
|
|
112
114
|
],
|
|
113
115
|
});
|
|
114
116
|
}
|
|
117
|
+
else if (externalsConfig && externalsConfig[moduleSpecifier] !== undefined) {
|
|
118
|
+
dynamicImports.push({
|
|
119
|
+
specifier: moduleSpecifier,
|
|
120
|
+
sourceSpecifier: moduleSpecifier,
|
|
121
|
+
version: VERSION_NOT_PROVIDED,
|
|
122
|
+
name: moduleNameType,
|
|
123
|
+
moduleNameType,
|
|
124
|
+
locations: [
|
|
125
|
+
{
|
|
126
|
+
location,
|
|
127
|
+
importLocation,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
115
132
|
else if (moduleSpecifier.startsWith('.')) {
|
|
116
133
|
// eslint-disable-next-line no-await-in-loop
|
|
117
134
|
const { locations, ...resolvedImport } = await resolveRelativeImport(registry, moduleSpecifier, moduleEntry, version, location, runtimeParams);
|
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.22",
|
|
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,16 +34,17 @@
|
|
|
30
34
|
"build/**/*.d.ts"
|
|
31
35
|
],
|
|
32
36
|
"dependencies": {
|
|
33
|
-
"@lwrjs/config": "0.12.0-alpha.
|
|
34
|
-
"@lwrjs/diagnostics": "0.12.0-alpha.
|
|
35
|
-
"@lwrjs/shared-utils": "0.12.0-alpha.
|
|
37
|
+
"@lwrjs/config": "0.12.0-alpha.22",
|
|
38
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.22",
|
|
39
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.22",
|
|
40
|
+
"fs-extra": "^11.1.1",
|
|
36
41
|
"rollup": "^2.78.0"
|
|
37
42
|
},
|
|
38
43
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
44
|
+
"@lwrjs/types": "0.12.0-alpha.22"
|
|
40
45
|
},
|
|
41
46
|
"engines": {
|
|
42
47
|
"node": ">=18.0.0"
|
|
43
48
|
},
|
|
44
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "6eb804007e93e513d4eb60fd321c088bad3c698e"
|
|
45
50
|
}
|