@lwrjs/module-bundler 0.6.0-alpha.4 → 0.6.0-alpha.8
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.
|
@@ -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 = [];
|
|
@@ -53,17 +53,15 @@ function bundleDefinitions(options) {
|
|
|
53
53
|
if (moduleDef && moduleDef.linkedModuleRecord) {
|
|
54
54
|
const d = moduleDef.linkedModuleRecord.dynamicImports || [];
|
|
55
55
|
d.forEach((e) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
}
|
|
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
|
+
});
|
|
67
65
|
});
|
|
68
66
|
}
|
|
69
67
|
if (exclude && moduleDef && importer && exclude.includes(moduleDef.specifier)) {
|
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;
|
|
@@ -53,20 +54,20 @@ var LwrModuleBundler = class {
|
|
|
53
54
|
const cacheDisabled = process.env.NOCACHE === "true";
|
|
54
55
|
if (!cacheDisabled) {
|
|
55
56
|
if (this.cache.has(cacheKey)) {
|
|
56
|
-
const
|
|
57
|
-
return
|
|
57
|
+
const bundleDef = this.cache.get(cacheKey);
|
|
58
|
+
return bundleDef;
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
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);
|
|
71
72
|
}
|
|
72
73
|
};
|
|
@@ -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
|
|
@@ -24,18 +24,16 @@ export function bundleDefinitions(options) {
|
|
|
24
24
|
if (moduleDef && moduleDef.linkedModuleRecord) {
|
|
25
25
|
const d = moduleDef.linkedModuleRecord.dynamicImports || [];
|
|
26
26
|
d.forEach((e) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
}
|
|
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
|
+
});
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
39
|
// if importer is null is the entry which we must ignore for externals
|
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;
|
|
@@ -31,25 +32,29 @@ export class LwrModuleBundler {
|
|
|
31
32
|
if (!cacheDisabled) {
|
|
32
33
|
// Return the cached bundle definition
|
|
33
34
|
if (this.cache.has(cacheKey)) {
|
|
35
|
+
// TODO add to profiling
|
|
36
|
+
// console.log('[INFO] Bundle Cache Hit: ', cacheKey);
|
|
34
37
|
const bundleDef = this.cache.get(cacheKey);
|
|
35
38
|
return bundleDef;
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
|
-
// Return the inflight bundle definition
|
|
39
|
-
if (this.inflightBundleDefinitions.has(cacheKey)) {
|
|
40
|
-
return this.inflightBundleDefinitions.get(cacheKey);
|
|
41
|
-
}
|
|
42
41
|
// Generate the bundle definition
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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);
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
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.6.0-alpha.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.8",
|
|
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.6.0-alpha.
|
|
33
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.8",
|
|
34
34
|
"rollup": "~2.45.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@lwrjs/types": "0.6.0-alpha.
|
|
37
|
+
"@lwrjs/types": "0.6.0-alpha.8"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=14.15.4 <17"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "f57b843b079ef42fdd1e727521e5a88e70bf850a"
|
|
43
43
|
}
|