@lwrjs/module-bundler 0.5.11-alpha.2 → 0.6.0-alpha.11
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/amd/amd-bundler.cjs +4 -8
- package/build/cjs/esm/esm-bundler.cjs +3 -2
- package/build/cjs/esm/rollup-esm-bundler-plugin.cjs +34 -18
- package/build/cjs/index.cjs +19 -17
- package/build/es/amd/amd-bundler.d.ts +2 -2
- package/build/es/amd/amd-bundler.js +4 -8
- package/build/es/esm/esm-bundler.d.ts +2 -2
- package/build/es/esm/esm-bundler.js +4 -3
- package/build/es/esm/rollup-esm-bundler-plugin.d.ts +1 -0
- package/build/es/esm/rollup-esm-bundler-plugin.js +44 -22
- package/build/es/index.d.ts +2 -2
- package/build/es/index.js +24 -18
- package/package.json +5 -5
|
@@ -27,8 +27,8 @@ __export(exports, {
|
|
|
27
27
|
amdBundler: () => amdBundler
|
|
28
28
|
});
|
|
29
29
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
|
-
async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, {bundleConfig, amdLoader}) {
|
|
31
|
-
const {exclude, external} = bundleConfig;
|
|
30
|
+
async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, {bundleConfig, amdLoader}, bundleConfigOverride) {
|
|
31
|
+
const {exclude, external} = bundleConfigOverride ?? bundleConfig;
|
|
32
32
|
const requiredImports = new Map();
|
|
33
33
|
const dynamicImports = new Map();
|
|
34
34
|
const visited = new Map();
|
|
@@ -50,16 +50,12 @@ async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
|
|
|
50
50
|
const rootModuleDef = moduleGraphs.linkedDefinitions[rootModule.specifier];
|
|
51
51
|
const {id, name, namespace, version, specifier} = rootModuleDef;
|
|
52
52
|
rootModuleDef?.linkedModuleRecord.dynamicImports?.forEach((e) => {
|
|
53
|
-
|
|
54
|
-
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
55
|
-
}
|
|
53
|
+
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
56
54
|
});
|
|
57
55
|
moduleGraphs.graphs[0].static.forEach((m) => {
|
|
58
56
|
const d = moduleGraphs.linkedDefinitions[m];
|
|
59
57
|
d?.linkedModuleRecord.dynamicImports?.forEach((e) => {
|
|
60
|
-
|
|
61
|
-
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
62
|
-
}
|
|
58
|
+
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
63
59
|
});
|
|
64
60
|
});
|
|
65
61
|
const code = [];
|
|
@@ -28,8 +28,8 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_rollup = __toModule(require("rollup"));
|
|
30
30
|
var import_rollup_esm_bundler_plugin = __toModule(require("./rollup-esm-bundler-plugin.cjs"));
|
|
31
|
-
async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {},
|
|
32
|
-
const {exclude, external = {}} = bundleConfig;
|
|
31
|
+
async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, lwrConfig, bundleConfigOverride) {
|
|
32
|
+
const {exclude, external = {}, alias = {}} = bundleConfigOverride ?? lwrConfig.bundleConfig;
|
|
33
33
|
const {sourceMapUrl} = runtimeEnvironment;
|
|
34
34
|
const requiredImports = new Map();
|
|
35
35
|
const dynamicImports = new Map();
|
|
@@ -42,6 +42,7 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
|
|
|
42
42
|
runtimeEnvironment,
|
|
43
43
|
moduleRegistry,
|
|
44
44
|
exclude,
|
|
45
|
+
alias,
|
|
45
46
|
runtimeParams,
|
|
46
47
|
requiredImports,
|
|
47
48
|
dynamicImports
|
|
@@ -32,12 +32,14 @@ function bundleDefinitions(options) {
|
|
|
32
32
|
rootModuleDef,
|
|
33
33
|
moduleRegistry,
|
|
34
34
|
exclude,
|
|
35
|
+
alias = {},
|
|
35
36
|
runtimeEnvironment,
|
|
36
37
|
runtimeParams,
|
|
37
38
|
requiredImports,
|
|
38
39
|
dynamicImports
|
|
39
40
|
} = options;
|
|
40
41
|
const visitedDefs = new Map([[rootModuleDef.specifier, rootModuleDef]]);
|
|
42
|
+
const visitedAliasUris = new Map();
|
|
41
43
|
return {
|
|
42
44
|
name: "bundle-plugin",
|
|
43
45
|
resolveDynamicImport() {
|
|
@@ -45,20 +47,21 @@ function bundleDefinitions(options) {
|
|
|
45
47
|
},
|
|
46
48
|
resolveId(id, importer) {
|
|
47
49
|
const moduleDef = visitedDefs.get(id);
|
|
50
|
+
if (visitedAliasUris.has(id)) {
|
|
51
|
+
return visitedAliasUris.get(id);
|
|
52
|
+
}
|
|
48
53
|
if (moduleDef && moduleDef.linkedModuleRecord) {
|
|
49
54
|
const d = moduleDef.linkedModuleRecord.dynamicImports || [];
|
|
50
55
|
d.forEach((e) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
}
|
|
56
|
+
const {namespace, name, version, sourceSpecifier, moduleNameType} = e;
|
|
57
|
+
dynamicImports.set(`${sourceSpecifier}_${version}`, {
|
|
58
|
+
namespace,
|
|
59
|
+
name,
|
|
60
|
+
specifier: sourceSpecifier,
|
|
61
|
+
version,
|
|
62
|
+
sourceSpecifier,
|
|
63
|
+
moduleNameType
|
|
64
|
+
});
|
|
62
65
|
});
|
|
63
66
|
}
|
|
64
67
|
if (exclude && moduleDef && importer && exclude.includes(moduleDef.specifier)) {
|
|
@@ -82,16 +85,29 @@ function bundleDefinitions(options) {
|
|
|
82
85
|
for (const refImport of imports) {
|
|
83
86
|
let refModuleDef = visitedDefs.get(refImport.specifier);
|
|
84
87
|
if (!refModuleDef) {
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
let specifier = (0, import_shared_utils.getSpecifier)({namespace: refImport.namespace, name: refImport.name});
|
|
89
|
+
let explodedSpecifier = refImport;
|
|
90
|
+
let aliasSpecifierUri;
|
|
91
|
+
const specifierUri = refImport.specifier;
|
|
92
|
+
const hasAlias = !!alias[specifier];
|
|
93
|
+
if (hasAlias) {
|
|
94
|
+
specifier = alias[specifier];
|
|
95
|
+
explodedSpecifier = (0, import_shared_utils.explodeSpecifier)(specifier);
|
|
96
|
+
const aliasModuleEntry = await moduleRegistry.getModuleEntry(explodedSpecifier, runtimeParams);
|
|
97
|
+
aliasSpecifierUri = await moduleRegistry.resolveModuleUri(aliasModuleEntry, runtimeEnvironment, runtimeParams);
|
|
98
|
+
}
|
|
87
99
|
refModuleDef = await moduleRegistry.getLinkedModule({
|
|
88
100
|
specifier,
|
|
89
|
-
namespace,
|
|
90
|
-
name,
|
|
91
|
-
scope,
|
|
92
|
-
version
|
|
101
|
+
namespace: explodedSpecifier.namespace,
|
|
102
|
+
name: explodedSpecifier.name,
|
|
103
|
+
scope: hasAlias ? void 0 : refImport.scope,
|
|
104
|
+
version: explodedSpecifier.version
|
|
93
105
|
}, runtimeEnvironment, runtimeParams);
|
|
94
|
-
visitedDefs.set(
|
|
106
|
+
visitedDefs.set(specifierUri, refModuleDef);
|
|
107
|
+
if (hasAlias) {
|
|
108
|
+
visitedDefs.set(aliasSpecifierUri, refModuleDef);
|
|
109
|
+
visitedAliasUris.set(specifierUri, aliasSpecifierUri);
|
|
110
|
+
}
|
|
95
111
|
}
|
|
96
112
|
}
|
|
97
113
|
return moduleDef.linkedSource;
|
package/build/cjs/index.cjs
CHANGED
|
@@ -29,10 +29,11 @@ __export(exports, {
|
|
|
29
29
|
var import_amd_bundler = __toModule(require("./amd/amd-bundler.cjs"));
|
|
30
30
|
var import_esm_bundler = __toModule(require("./esm/esm-bundler.cjs"));
|
|
31
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
|
+
var TASK_POOL = new import_shared_utils.TaskPool();
|
|
32
33
|
var LwrModuleBundler = class {
|
|
33
34
|
constructor(config, globalConfig) {
|
|
34
35
|
this.cache = new Map();
|
|
35
|
-
this.inflightBundleDefinitions = new
|
|
36
|
+
this.inflightBundleDefinitions = new import_shared_utils.InflightTasks();
|
|
36
37
|
this.config = globalConfig;
|
|
37
38
|
this.moduleRegistry = config.moduleRegistry;
|
|
38
39
|
this.appObserver = config.appObserver;
|
|
@@ -40,32 +41,33 @@ var LwrModuleBundler = class {
|
|
|
40
41
|
this.cache.clear();
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
|
-
async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}) {
|
|
44
|
+
async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
|
|
44
45
|
const {moduleRegistry} = this;
|
|
45
46
|
const {format, minify, debug} = runtimeEnvironment;
|
|
46
47
|
const cacheKey = `${moduleId.specifier}|${moduleId.version}|${(0, import_shared_utils.getCacheKeyFromJson)({
|
|
47
48
|
locale: runtimeParams.locale,
|
|
48
49
|
format,
|
|
49
50
|
minify,
|
|
50
|
-
debug
|
|
51
|
+
debug,
|
|
52
|
+
bundleConfigOverrides
|
|
51
53
|
})}`;
|
|
52
54
|
const cacheDisabled = process.env.NOCACHE === "true";
|
|
53
|
-
if (cacheDisabled
|
|
55
|
+
if (!cacheDisabled) {
|
|
54
56
|
if (this.cache.has(cacheKey)) {
|
|
55
|
-
const
|
|
56
|
-
return
|
|
57
|
+
const bundleDef = this.cache.get(cacheKey);
|
|
58
|
+
return bundleDef;
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
61
|
+
const createBundlePromiseCtor = async () => {
|
|
62
|
+
return TASK_POOL.execute(async () => {
|
|
63
|
+
return format === "amd" ? (0, import_amd_bundler.amdBundler)(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides) : (0, import_esm_bundler.esmBundler)(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides).then((bundleDef) => {
|
|
64
|
+
if (!cacheDisabled) {
|
|
65
|
+
this.cache.set(cacheKey, bundleDef);
|
|
66
|
+
}
|
|
67
|
+
return bundleDef;
|
|
68
|
+
});
|
|
69
|
+
}, this);
|
|
70
|
+
};
|
|
71
|
+
return this.inflightBundleDefinitions.execute(cacheKey, createBundlePromiseCtor, this);
|
|
70
72
|
}
|
|
71
73
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AbstractModuleId, BundleDefinition, ModuleRegistry, NormalizedLwrGlobalConfig, RuntimeEnvironment } from '@lwrjs/types';
|
|
2
|
-
export declare function amdBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, runtimeEnvironment: RuntimeEnvironment, runtimeParams:
|
|
1
|
+
import { AbstractModuleId, BundleConfig, BundleDefinition, ModuleRegistry, NormalizedLwrGlobalConfig, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
|
+
export declare function amdBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams | undefined, { bundleConfig, amdLoader }: NormalizedLwrGlobalConfig, bundleConfigOverride?: BundleConfig): Promise<BundleDefinition>;
|
|
3
3
|
//# sourceMappingURL=amd-bundler.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getModuleGraphs, GraphDepth } from '@lwrjs/shared-utils';
|
|
2
|
-
export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, { bundleConfig, amdLoader }) {
|
|
3
|
-
const { exclude, external } = bundleConfig;
|
|
2
|
+
export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, { bundleConfig, amdLoader }, bundleConfigOverride) {
|
|
3
|
+
const { exclude, external } = bundleConfigOverride ?? bundleConfig;
|
|
4
4
|
const requiredImports = new Map();
|
|
5
5
|
const dynamicImports = new Map();
|
|
6
6
|
const visited = new Map();
|
|
@@ -27,9 +27,7 @@ export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, r
|
|
|
27
27
|
// Collect dynamic imports
|
|
28
28
|
// Add dynamic imports from the root module
|
|
29
29
|
rootModuleDef?.linkedModuleRecord.dynamicImports?.forEach((e) => {
|
|
30
|
-
|
|
31
|
-
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
32
|
-
}
|
|
30
|
+
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
33
31
|
});
|
|
34
32
|
// Add any dynamic imports from each of the linked static imports in the moduleGraph
|
|
35
33
|
moduleGraphs.graphs[0].static.forEach((m) => {
|
|
@@ -37,9 +35,7 @@ export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, r
|
|
|
37
35
|
const d = moduleGraphs.linkedDefinitions[m];
|
|
38
36
|
// D would be null if excluded from the bundle
|
|
39
37
|
d?.linkedModuleRecord.dynamicImports?.forEach((e) => {
|
|
40
|
-
|
|
41
|
-
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
42
|
-
}
|
|
38
|
+
dynamicImports.set(`${e.specifier}_${e.version}`, e);
|
|
43
39
|
});
|
|
44
40
|
});
|
|
45
41
|
// loop in reverse for correct order
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AbstractModuleId, ModuleRegistry, BundleDefinition, SourceMapRuntimeEnvironment, BundleConfig } from '@lwrjs/types';
|
|
2
|
-
export declare function esmBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams:
|
|
1
|
+
import { AbstractModuleId, ModuleRegistry, BundleDefinition, RuntimeParams, SourceMapRuntimeEnvironment, BundleConfig, NormalizedLwrGlobalConfig } from '@lwrjs/types';
|
|
2
|
+
export declare function esmBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams: RuntimeParams | undefined, lwrConfig: NormalizedLwrGlobalConfig, bundleConfigOverride?: BundleConfig): Promise<BundleDefinition>;
|
|
3
3
|
//# sourceMappingURL=esm-bundler.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rollup } from 'rollup';
|
|
2
2
|
import { bundleDefinitions } from './rollup-esm-bundler-plugin.js';
|
|
3
|
-
export async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {},
|
|
4
|
-
const { exclude, external = {} } = bundleConfig;
|
|
3
|
+
export async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, lwrConfig, bundleConfigOverride) {
|
|
4
|
+
const { exclude, external = {}, alias = {} } = bundleConfigOverride ?? lwrConfig.bundleConfig;
|
|
5
5
|
const { sourceMapUrl } = runtimeEnvironment;
|
|
6
6
|
const requiredImports = new Map();
|
|
7
7
|
const dynamicImports = new Map();
|
|
@@ -14,12 +14,13 @@ export async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, r
|
|
|
14
14
|
runtimeEnvironment,
|
|
15
15
|
moduleRegistry,
|
|
16
16
|
exclude,
|
|
17
|
+
alias,
|
|
17
18
|
runtimeParams,
|
|
18
19
|
requiredImports,
|
|
19
20
|
dynamicImports,
|
|
20
21
|
}),
|
|
21
22
|
],
|
|
22
|
-
makeAbsoluteExternalsRelative: 'ifRelativeSource',
|
|
23
|
+
makeAbsoluteExternalsRelative: 'ifRelativeSource', // Fix for breaking changes in https://github.com/rollup/rollup/pull/4021
|
|
23
24
|
});
|
|
24
25
|
const result = await bundle.generate({
|
|
25
26
|
paths: (id) => {
|
|
@@ -7,6 +7,7 @@ export interface RollupBundlePluginOptions {
|
|
|
7
7
|
moduleRegistry: ModuleRegistry;
|
|
8
8
|
include?: string[];
|
|
9
9
|
exclude?: string[];
|
|
10
|
+
alias?: Record<string, string>;
|
|
10
11
|
requiredImports: Map<string, BaseModuleReference>;
|
|
11
12
|
dynamicImports: Map<string, BaseDynamicModuleReference>;
|
|
12
13
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-await-in-loop */
|
|
2
|
+
import { explodeSpecifier, getSpecifier } from '@lwrjs/shared-utils';
|
|
2
3
|
/*
|
|
3
4
|
* Note: The prefix "@bundle" is do allow rollup to pretty print the imports in case of an error
|
|
4
5
|
* Otherwise since the imports start with a "/" it think its an absolute path doing "../" all over the place
|
|
5
6
|
*/
|
|
6
7
|
export function bundleDefinitions(options) {
|
|
7
|
-
const { rootModuleDef, moduleRegistry, exclude, runtimeEnvironment, runtimeParams, requiredImports, dynamicImports, } = options;
|
|
8
|
+
const { rootModuleDef, moduleRegistry, exclude, alias = {}, runtimeEnvironment, runtimeParams, requiredImports, dynamicImports, } = options;
|
|
8
9
|
// Manually add the root to visited so it can be found on the load hook
|
|
9
10
|
const visitedDefs = new Map([[rootModuleDef.specifier, rootModuleDef]]);
|
|
11
|
+
const visitedAliasUris = new Map();
|
|
10
12
|
return {
|
|
11
13
|
name: 'bundle-plugin',
|
|
12
14
|
resolveDynamicImport() {
|
|
@@ -15,22 +17,23 @@ export function bundleDefinitions(options) {
|
|
|
15
17
|
},
|
|
16
18
|
resolveId(id, importer) {
|
|
17
19
|
const moduleDef = visitedDefs.get(id);
|
|
20
|
+
if (visitedAliasUris.has(id)) {
|
|
21
|
+
return visitedAliasUris.get(id);
|
|
22
|
+
}
|
|
18
23
|
// Collect dynamic import information here
|
|
19
24
|
if (moduleDef && moduleDef.linkedModuleRecord) {
|
|
20
25
|
const d = moduleDef.linkedModuleRecord.dynamicImports || [];
|
|
21
26
|
d.forEach((e) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
}
|
|
27
|
+
const { namespace, name, version, sourceSpecifier, moduleNameType } = e;
|
|
28
|
+
// Not sure why this has to be source specifier but things break otherwise
|
|
29
|
+
dynamicImports.set(`${sourceSpecifier}_${version}`, {
|
|
30
|
+
namespace,
|
|
31
|
+
name,
|
|
32
|
+
specifier: sourceSpecifier,
|
|
33
|
+
version,
|
|
34
|
+
sourceSpecifier,
|
|
35
|
+
moduleNameType,
|
|
36
|
+
});
|
|
34
37
|
});
|
|
35
38
|
}
|
|
36
39
|
// if importer is null is the entry which we must ignore for externals
|
|
@@ -60,19 +63,38 @@ export function bundleDefinitions(options) {
|
|
|
60
63
|
let refModuleDef = visitedDefs.get(refImport.specifier);
|
|
61
64
|
if (!refModuleDef) {
|
|
62
65
|
// The refeference imports have the specifier pointing to a URI.
|
|
63
|
-
// so we take the original instead
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
// so we take the original specifier instead
|
|
67
|
+
let specifier = getSpecifier({ namespace: refImport.namespace, name: refImport.name });
|
|
68
|
+
let explodedSpecifier = refImport;
|
|
69
|
+
let aliasSpecifierUri;
|
|
70
|
+
const specifierUri = refImport.specifier;
|
|
71
|
+
const hasAlias = !!alias[specifier];
|
|
72
|
+
if (hasAlias) {
|
|
73
|
+
// Override the original raw specifier and the exploded version
|
|
74
|
+
// so the code that will load will be the aliased
|
|
75
|
+
specifier = alias[specifier];
|
|
76
|
+
explodedSpecifier = explodeSpecifier(specifier);
|
|
77
|
+
// We also need to remap the original URI to point to the aliased URI so
|
|
78
|
+
// we endup having the same module identity (otherwise we will have duplicated code)
|
|
79
|
+
const aliasModuleEntry = await moduleRegistry.getModuleEntry(explodedSpecifier, runtimeParams);
|
|
80
|
+
aliasSpecifierUri = await moduleRegistry.resolveModuleUri(aliasModuleEntry, runtimeEnvironment, runtimeParams);
|
|
81
|
+
}
|
|
66
82
|
// eslint-disable-next-line no-await-in-loop
|
|
67
83
|
refModuleDef = await moduleRegistry.getLinkedModule({
|
|
68
84
|
specifier,
|
|
69
|
-
namespace,
|
|
70
|
-
name,
|
|
71
|
-
scope,
|
|
72
|
-
version,
|
|
85
|
+
namespace: explodedSpecifier.namespace,
|
|
86
|
+
name: explodedSpecifier.name,
|
|
87
|
+
scope: hasAlias ? undefined : refImport.scope,
|
|
88
|
+
version: explodedSpecifier.version,
|
|
73
89
|
}, runtimeEnvironment, runtimeParams);
|
|
74
90
|
// This specifier is the final URI specifier
|
|
75
|
-
visitedDefs.set(
|
|
91
|
+
visitedDefs.set(specifierUri, refModuleDef);
|
|
92
|
+
// If there is an alias we need to point the alias URI to the same code
|
|
93
|
+
// The resolveId must have both URIs (original, and alias) pointing to the same def
|
|
94
|
+
if (hasAlias) {
|
|
95
|
+
visitedDefs.set(aliasSpecifierUri, refModuleDef);
|
|
96
|
+
visitedAliasUris.set(specifierUri, aliasSpecifierUri);
|
|
97
|
+
}
|
|
76
98
|
}
|
|
77
99
|
}
|
|
78
100
|
return moduleDef.linkedSource;
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractModuleId, BundleDefinition, LwrAppObserver, ModuleBundler, ModuleRegistry, NormalizedLwrGlobalConfig, RuntimeParams, SourceMapRuntimeEnvironment } from '@lwrjs/types';
|
|
1
|
+
import { AbstractModuleId, BundleConfig, BundleDefinition, LwrAppObserver, ModuleBundler, ModuleRegistry, NormalizedLwrGlobalConfig, RuntimeParams, SourceMapRuntimeEnvironment } from '@lwrjs/types';
|
|
2
2
|
interface LwrModuleBundlerConfig {
|
|
3
3
|
moduleRegistry: ModuleRegistry;
|
|
4
4
|
appObserver: LwrAppObserver;
|
|
@@ -10,7 +10,7 @@ export declare class LwrModuleBundler implements ModuleBundler {
|
|
|
10
10
|
cache: Map<string, BundleDefinition>;
|
|
11
11
|
private inflightBundleDefinitions;
|
|
12
12
|
constructor(config: LwrModuleBundlerConfig, globalConfig: NormalizedLwrGlobalConfig);
|
|
13
|
-
getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<BundleDefinition>;
|
|
13
|
+
getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfig): Promise<BundleDefinition>;
|
|
14
14
|
}
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/build/es/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { amdBundler } from './amd/amd-bundler.js';
|
|
2
2
|
import { esmBundler } from './esm/esm-bundler.js';
|
|
3
|
-
import { getCacheKeyFromJson } from '@lwrjs/shared-utils';
|
|
3
|
+
import { getCacheKeyFromJson, InflightTasks, TaskPool } from '@lwrjs/shared-utils';
|
|
4
|
+
const TASK_POOL = new TaskPool();
|
|
4
5
|
export class LwrModuleBundler {
|
|
5
6
|
constructor(config, globalConfig) {
|
|
6
7
|
this.cache = new Map();
|
|
7
8
|
// Pending bundle definitions are tracked to prevent concurrent resolution of the same bundle.
|
|
8
9
|
// Subsequent requests for the same bundle will await the original promise.
|
|
9
10
|
// Cache entries will be removed once the bundle is resolved.
|
|
10
|
-
this.inflightBundleDefinitions = new
|
|
11
|
+
this.inflightBundleDefinitions = new InflightTasks();
|
|
11
12
|
this.config = globalConfig;
|
|
12
13
|
this.moduleRegistry = config.moduleRegistry;
|
|
13
14
|
this.appObserver = config.appObserver;
|
|
@@ -17,7 +18,7 @@ export class LwrModuleBundler {
|
|
|
17
18
|
this.cache.clear();
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}) {
|
|
21
|
+
async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
|
|
21
22
|
const { moduleRegistry } = this;
|
|
22
23
|
const { format, minify, debug } = runtimeEnvironment;
|
|
23
24
|
const cacheKey = `${moduleId.specifier}|${moduleId.version}|${getCacheKeyFromJson({
|
|
@@ -25,30 +26,35 @@ export class LwrModuleBundler {
|
|
|
25
26
|
format,
|
|
26
27
|
minify,
|
|
27
28
|
debug,
|
|
29
|
+
bundleConfigOverrides,
|
|
28
30
|
})}`;
|
|
29
31
|
const cacheDisabled = process.env.NOCACHE === 'true';
|
|
30
|
-
if (cacheDisabled
|
|
32
|
+
if (!cacheDisabled) {
|
|
31
33
|
// Return the cached bundle definition
|
|
32
34
|
if (this.cache.has(cacheKey)) {
|
|
35
|
+
// TODO add to profiling
|
|
36
|
+
// console.log('[INFO] Bundle Cache Hit: ', cacheKey);
|
|
33
37
|
const bundleDef = this.cache.get(cacheKey);
|
|
34
38
|
return bundleDef;
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
|
-
// Return the inflight bundle definition
|
|
38
|
-
if (this.inflightBundleDefinitions.has(cacheKey)) {
|
|
39
|
-
return this.inflightBundleDefinitions.get(cacheKey);
|
|
40
|
-
}
|
|
41
41
|
// Generate the bundle definition
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
const createBundlePromiseCtor = async () => {
|
|
43
|
+
// TODO add to profiling
|
|
44
|
+
// console.log('[INFO] Create Bundle: ', cacheKey);
|
|
45
|
+
// Run theses tasks in a task pool to throttle parallel requests.
|
|
46
|
+
return TASK_POOL.execute(async () => {
|
|
47
|
+
return format === 'amd'
|
|
48
|
+
? amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides)
|
|
49
|
+
: esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides).then((bundleDef) => {
|
|
50
|
+
if (!cacheDisabled) {
|
|
51
|
+
this.cache.set(cacheKey, bundleDef);
|
|
52
|
+
}
|
|
53
|
+
return bundleDef;
|
|
54
|
+
});
|
|
55
|
+
}, this);
|
|
56
|
+
};
|
|
57
|
+
return this.inflightBundleDefinitions.execute(cacheKey, createBundlePromiseCtor, this);
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.11",
|
|
8
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/salesforce/lwr.git",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/shared-utils": "0.
|
|
33
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.11",
|
|
34
34
|
"rollup": "~2.45.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@lwrjs/types": "0.
|
|
37
|
+
"@lwrjs/types": "0.6.0-alpha.11"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=14.15.4 <17"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "18ab72188c2d52e32cca47333951a9c76f996039"
|
|
43
43
|
}
|