@lwrjs/module-bundler 0.10.0-alpha.13 → 0.10.0-alpha.15
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/utils/amd-common.cjs +120 -33
- package/build/es/utils/amd-common.d.ts +1 -1
- package/build/es/utils/amd-common.js +143 -39
- package/package.json +14 -6
|
@@ -32,7 +32,30 @@ var import_plugin_replace = __toModule(require("@rollup/plugin-replace"));
|
|
|
32
32
|
var import_rollup_amd_bundler_plugin = __toModule(require("./rollup-amd-bundler-plugin.cjs"));
|
|
33
33
|
var import_bundle_common = __toModule(require("./bundle-common.cjs"));
|
|
34
34
|
var AMD_DEFINE = "LWR.define";
|
|
35
|
-
|
|
35
|
+
var groupieCodeCache = new Map();
|
|
36
|
+
function includeIdFactory(graphSpecifier, external, exclude = [], requiredImports, groups) {
|
|
37
|
+
return (moduleRef) => {
|
|
38
|
+
if (external[moduleRef.specifier]) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const moduleRefIsGroupie = (0, import_shared_utils.isGroupie)(moduleRef.specifier, groups);
|
|
42
|
+
const rootModuleIsGroupie = (0, import_shared_utils.isGroupie)(graphSpecifier, groups);
|
|
43
|
+
const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
|
|
44
|
+
if (moduleRefIsGroupie) {
|
|
45
|
+
if (moduleIsNotRoot && !rootModuleIsGroupie) {
|
|
46
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
} else if (exclude?.includes(moduleRef.specifier)) {
|
|
50
|
+
if (moduleIsNotRoot) {
|
|
51
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async function bundle(id, moduleGraphs, minify = false, unVersionedAliases = false) {
|
|
36
59
|
const plugins = [(0, import_rollup_amd_bundler_plugin.bundleDefinitions)({moduleGraphs})];
|
|
37
60
|
minify && plugins.push((0, import_plugin_replace.default)({
|
|
38
61
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
@@ -44,35 +67,41 @@ async function bundle(id, moduleGraphs, minify = false) {
|
|
|
44
67
|
exports: "named",
|
|
45
68
|
format: "amd"
|
|
46
69
|
});
|
|
47
|
-
|
|
70
|
+
let code = output[0].code;
|
|
71
|
+
if (unVersionedAliases) {
|
|
72
|
+
const idObject = (0, import_shared_utils.explodeSpecifier)(id);
|
|
73
|
+
const specifier = idObject.specifier;
|
|
74
|
+
const aliasModule = (0, import_shared_utils.createAmdAlias)(specifier, id);
|
|
75
|
+
code += aliasModule;
|
|
76
|
+
}
|
|
77
|
+
return code;
|
|
48
78
|
}
|
|
49
|
-
async function
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
65
|
-
return false;
|
|
79
|
+
async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, unVersionedAliases, includeId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, visitedSpecifiers) {
|
|
80
|
+
const modules = [rootModule, ...moduleGraphs.graphs[0].static];
|
|
81
|
+
const {moduleRecord} = await moduleRegistry.getModule((0, import_shared_utils.explodeSpecifier)(rootModule));
|
|
82
|
+
if (moduleRecord.importMeta) {
|
|
83
|
+
for (const specifier of modules) {
|
|
84
|
+
const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
|
|
85
|
+
const imports = linkedDefinition?.linkedModuleRecord.imports || [];
|
|
86
|
+
for (const imp of imports) {
|
|
87
|
+
const modId = (0, import_shared_utils.explodeSpecifier)(imp.specifier);
|
|
88
|
+
if (!modules.includes(imp.specifier) && includeId(modId)) {
|
|
89
|
+
modules.push(imp.specifier);
|
|
90
|
+
if (!moduleGraphs.linkedDefinitions[imp.specifier]) {
|
|
91
|
+
const missingLinkedModule = await moduleRegistry.getLinkedModule({specifier: modId.specifier, version: modId.version}, runtimeEnvironment, runtimeParams);
|
|
92
|
+
moduleGraphs.linkedDefinitions[imp.specifier] = missingLinkedModule;
|
|
93
|
+
}
|
|
66
94
|
}
|
|
67
|
-
return true;
|
|
68
95
|
}
|
|
69
96
|
}
|
|
70
|
-
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
97
|
+
}
|
|
98
|
+
const bundles = (await Promise.all(modules.reduce((filteredModules, specifier) => {
|
|
99
|
+
const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
|
|
100
|
+
if (visitedSpecifiers?.has(specifier)) {
|
|
101
|
+
return filteredModules;
|
|
102
|
+
} else {
|
|
103
|
+
visitedSpecifiers?.set(specifier, true);
|
|
104
|
+
}
|
|
76
105
|
if (!linkedDefinition) {
|
|
77
106
|
return filteredModules;
|
|
78
107
|
}
|
|
@@ -81,18 +110,76 @@ async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvir
|
|
|
81
110
|
dynamicImports.set(`${dynamicImport.specifier}_${dynamicImport.version}`, dynamicImport);
|
|
82
111
|
}
|
|
83
112
|
});
|
|
84
|
-
if (
|
|
113
|
+
if (specifier.includes("#")) {
|
|
85
114
|
return filteredModules;
|
|
86
115
|
}
|
|
87
116
|
filteredModules.unshift(linkedDefinition);
|
|
88
117
|
return filteredModules;
|
|
89
118
|
}, []).map((linkedDefinition) => {
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
includedModules.push(
|
|
119
|
+
const id = (0, import_shared_utils.getSpecifier)(linkedDefinition);
|
|
120
|
+
if (id !== rootModule) {
|
|
121
|
+
includedModules.push(id);
|
|
122
|
+
} else {
|
|
123
|
+
bundleGroupsIncludedModules.push(id);
|
|
93
124
|
}
|
|
94
|
-
return bundle(
|
|
95
|
-
}));
|
|
125
|
+
return bundle(id, moduleGraphs, minify, unVersionedAliases);
|
|
126
|
+
}))).filter(Boolean);
|
|
127
|
+
return bundles;
|
|
128
|
+
}
|
|
129
|
+
async function amdBundler(rootModuleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, {bundleConfig}, bundleConfigOverrides) {
|
|
130
|
+
const {exclude, external = {}, groups = {}} = (0, import_bundle_common.overrideBundleConfig)(bundleConfig, bundleConfigOverrides);
|
|
131
|
+
const requiredImports = new Map();
|
|
132
|
+
const dynamicImports = new Map();
|
|
133
|
+
const groupName = (0, import_shared_utils.getGroupName)(rootModuleId.specifier, groups);
|
|
134
|
+
const groupies = groupName && groups[groupName];
|
|
135
|
+
const cachedGroupieCode = groupName && groupieCodeCache.get(groupName);
|
|
136
|
+
const getModuleGraphsWrapper = (graphSpecifier) => {
|
|
137
|
+
const graphOptions = {
|
|
138
|
+
includeLinkedDefinitions: true,
|
|
139
|
+
depth: {
|
|
140
|
+
static: import_shared_utils.GraphDepth.ALL,
|
|
141
|
+
dynamic: 0,
|
|
142
|
+
includeId: includeIdFactory(graphSpecifier, external, exclude, requiredImports, groups)
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return (0, import_shared_utils.getModuleGraphs)(graphSpecifier, graphOptions, moduleRegistry, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
146
|
+
};
|
|
147
|
+
const moduleGraphs = await getModuleGraphsWrapper(rootModuleId.specifier);
|
|
148
|
+
const rootModule = moduleGraphs.graphs[0];
|
|
149
|
+
const groupModuleGraphsMap = new Map();
|
|
150
|
+
if (!cachedGroupieCode && groupies && groupies.length) {
|
|
151
|
+
for (const specifier2 of groupies) {
|
|
152
|
+
if (specifier2 !== rootModuleId.specifier) {
|
|
153
|
+
const groupieModuleGraph = await getModuleGraphsWrapper(specifier2);
|
|
154
|
+
groupModuleGraphsMap.set(specifier2, groupieModuleGraph);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
let bundleCode, includedModules, bundleGroupsIncludedModules;
|
|
159
|
+
const cachedBundleGroupCode = cachedGroupieCode;
|
|
160
|
+
const bundledSpecifiersMap = new Map();
|
|
161
|
+
if (!cachedBundleGroupCode) {
|
|
162
|
+
includedModules = [], bundleGroupsIncludedModules = [];
|
|
163
|
+
const bundles = await getBundleCode(rootModule.specifier, moduleGraphs, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rootModuleId.specifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
|
|
164
|
+
if (groupName) {
|
|
165
|
+
for (const rawGroupieSpecifier of groupies) {
|
|
166
|
+
if (rawGroupieSpecifier !== rootModuleId.specifier) {
|
|
167
|
+
const groupieModuleGraph = groupModuleGraphsMap.get(rawGroupieSpecifier);
|
|
168
|
+
const groupieSpecifer = groupieModuleGraph.graphs[0].specifier;
|
|
169
|
+
const groupieBundles = await getBundleCode(groupieSpecifer, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
|
|
170
|
+
bundles.push(...groupieBundles);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
bundleCode = bundles.join("");
|
|
175
|
+
if (groupName) {
|
|
176
|
+
includedModules.push(...bundleGroupsIncludedModules);
|
|
177
|
+
groupieCodeCache.set(groupName, {code: bundleCode, includedModules});
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
bundleCode = cachedBundleGroupCode.code;
|
|
181
|
+
includedModules = cachedBundleGroupCode.includedModules;
|
|
182
|
+
}
|
|
96
183
|
const {id, name, namespace, version, specifier} = moduleGraphs.linkedDefinitions[rootModule.specifier];
|
|
97
184
|
return {
|
|
98
185
|
id,
|
|
@@ -100,7 +187,7 @@ async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvir
|
|
|
100
187
|
namespace,
|
|
101
188
|
version,
|
|
102
189
|
specifier,
|
|
103
|
-
code:
|
|
190
|
+
code: bundleCode,
|
|
104
191
|
config: {external, exclude},
|
|
105
192
|
bundleRecord: {
|
|
106
193
|
imports: Array.from(requiredImports.values()),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AbstractModuleId, BundleConfigOverrides, BundleDefinition, ModuleRegistry, ProviderAppConfig, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
|
-
export declare function amdBundler(
|
|
2
|
+
export declare function amdBundler(rootModuleId: AbstractModuleId, moduleRegistry: ModuleRegistry, minify: boolean | undefined, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams | undefined, { bundleConfig }: ProviderAppConfig, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition>;
|
|
3
3
|
//# sourceMappingURL=amd-common.d.ts.map
|
|
@@ -1,14 +1,46 @@
|
|
|
1
|
-
import { GraphDepth, getModuleGraphs, getSpecifier } from '@lwrjs/shared-utils';
|
|
1
|
+
import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { rollup } from 'rollup';
|
|
3
3
|
import replace from '@rollup/plugin-replace';
|
|
4
4
|
import { bundleDefinitions } from './rollup-amd-bundler-plugin.js';
|
|
5
5
|
import { overrideBundleConfig } from './bundle-common.js';
|
|
6
6
|
const AMD_DEFINE = 'LWR.define';
|
|
7
|
-
|
|
7
|
+
const groupieCodeCache = new Map();
|
|
8
|
+
function includeIdFactory(graphSpecifier, external, exclude = [], requiredImports, groups) {
|
|
9
|
+
return (moduleRef) => {
|
|
10
|
+
// Do not bundle externals, including the loader module, which is auto bundled
|
|
11
|
+
// with the shim + loader combo
|
|
12
|
+
if (external[moduleRef.specifier]) {
|
|
13
|
+
// Do not include externals in the required imports but also return false to indicate it should not be in the bundle
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const moduleRefIsGroupie = isGroupie(moduleRef.specifier, groups);
|
|
17
|
+
const rootModuleIsGroupie = isGroupie(graphSpecifier, groups);
|
|
18
|
+
const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
|
|
19
|
+
if (moduleRefIsGroupie) {
|
|
20
|
+
// If this is part of bundle group return false to indicate it should not be in the bundle
|
|
21
|
+
// but add it to the requriedImports so it shows up as a static dependency of the bundle.
|
|
22
|
+
// However, skip this if the requested specifier is also part of the same group.
|
|
23
|
+
if (moduleIsNotRoot && !rootModuleIsGroupie) {
|
|
24
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
else if (exclude?.includes(moduleRef.specifier)) {
|
|
29
|
+
// If this is a bundle exclude return false to indicate it should not be in the bundle
|
|
30
|
+
// but add it to the requriedImports so it shows up as a static dependency of the bundle.
|
|
31
|
+
if (moduleIsNotRoot) {
|
|
32
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function bundle(id, moduleGraphs, minify = false, unVersionedAliases = false) {
|
|
8
40
|
const plugins = [bundleDefinitions({ moduleGraphs })];
|
|
9
41
|
minify &&
|
|
10
42
|
plugins.push(
|
|
11
|
-
// terser(), // Do not minify until needed for client modules. Server/SSR modules do not need to be
|
|
43
|
+
// terser(), // Do not minify until needed for client modules. Server/SSR modules do not need to be minified.
|
|
12
44
|
replace({
|
|
13
45
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
14
46
|
preventAssignment: false,
|
|
@@ -19,42 +51,47 @@ async function bundle(id, moduleGraphs, minify = false) {
|
|
|
19
51
|
exports: 'named',
|
|
20
52
|
format: 'amd',
|
|
21
53
|
});
|
|
22
|
-
|
|
54
|
+
let code = output[0].code;
|
|
55
|
+
if (unVersionedAliases) {
|
|
56
|
+
const idObject = explodeSpecifier(id);
|
|
57
|
+
const specifier = idObject.specifier;
|
|
58
|
+
const aliasModule = createAmdAlias(specifier, id);
|
|
59
|
+
code += aliasModule;
|
|
60
|
+
}
|
|
61
|
+
return code;
|
|
23
62
|
}
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// If this is a bundle exclude return false to indicate it should not be in the bundle
|
|
44
|
-
// but add it to the requriedImports so it shows up as a static dependency of the bundle.
|
|
45
|
-
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
46
|
-
return false;
|
|
63
|
+
async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, unVersionedAliases, includeId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, visitedSpecifiers) {
|
|
64
|
+
const modules = [rootModule, ...moduleGraphs.graphs[0].static];
|
|
65
|
+
const { moduleRecord } = await moduleRegistry.getModule(explodeSpecifier(rootModule));
|
|
66
|
+
// add static imports from the LinkedModuleDefinitions added during module linking
|
|
67
|
+
// they're not in the ModuleGraph imports b/c those are based on raw module source
|
|
68
|
+
if (moduleRecord.importMeta) {
|
|
69
|
+
// the only use case for this is "lwr/environment", so skip the logic when it's not needed
|
|
70
|
+
for (const specifier of modules) {
|
|
71
|
+
const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
|
|
72
|
+
const imports = linkedDefinition?.linkedModuleRecord.imports || [];
|
|
73
|
+
for (const imp of imports) {
|
|
74
|
+
const modId = explodeSpecifier(imp.specifier);
|
|
75
|
+
if (!modules.includes(imp.specifier) && includeId(modId)) {
|
|
76
|
+
modules.push(imp.specifier);
|
|
77
|
+
if (!moduleGraphs.linkedDefinitions[imp.specifier]) {
|
|
78
|
+
// eslint-disable-next-line no-await-in-loop
|
|
79
|
+
const missingLinkedModule = await moduleRegistry.getLinkedModule({ specifier: modId.specifier, version: modId.version }, runtimeEnvironment, runtimeParams);
|
|
80
|
+
moduleGraphs.linkedDefinitions[imp.specifier] = missingLinkedModule;
|
|
81
|
+
}
|
|
47
82
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const moduleGraphs = await getModuleGraphs(moduleId.specifier, graphOptions, moduleRegistry, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
53
|
-
const rootModule = moduleGraphs.graphs[0];
|
|
54
|
-
const modules = [rootModule.specifier, ...moduleGraphs.graphs[0].static];
|
|
55
|
-
const bundles = await Promise.all(modules
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const bundles = (await Promise.all(modules
|
|
56
87
|
.reduce((filteredModules, specifier) => {
|
|
57
88
|
const linkedDefinition = moduleGraphs.linkedDefinitions[specifier];
|
|
89
|
+
if (visitedSpecifiers?.has(specifier)) {
|
|
90
|
+
return filteredModules;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
visitedSpecifiers?.set(specifier, true);
|
|
94
|
+
}
|
|
58
95
|
// skip modules that do not have a linked definition
|
|
59
96
|
if (!linkedDefinition) {
|
|
60
97
|
return filteredModules;
|
|
@@ -75,12 +112,79 @@ export async function amdBundler(moduleId, moduleRegistry, minify = false, runti
|
|
|
75
112
|
}, [])
|
|
76
113
|
.map((linkedDefinition) => {
|
|
77
114
|
const id = getSpecifier(linkedDefinition);
|
|
78
|
-
if (id !== rootModule
|
|
115
|
+
if (id !== rootModule) {
|
|
79
116
|
includedModules.push(id);
|
|
80
117
|
}
|
|
118
|
+
else {
|
|
119
|
+
// we need to still keep track of roots for bundle groups
|
|
120
|
+
bundleGroupsIncludedModules.push(id);
|
|
121
|
+
}
|
|
81
122
|
// bundle all dependencies for the linked definition and convert to AMD
|
|
82
|
-
return bundle(id, moduleGraphs, minify);
|
|
83
|
-
}));
|
|
123
|
+
return bundle(id, moduleGraphs, minify, unVersionedAliases);
|
|
124
|
+
}))).filter(Boolean);
|
|
125
|
+
return bundles;
|
|
126
|
+
}
|
|
127
|
+
export async function amdBundler(rootModuleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, { bundleConfig }, bundleConfigOverrides) {
|
|
128
|
+
const { exclude, external = {}, groups = {} } = overrideBundleConfig(bundleConfig, bundleConfigOverrides);
|
|
129
|
+
// Note: the maps must be cleared each time we call getModuleGraph
|
|
130
|
+
const requiredImports = new Map();
|
|
131
|
+
const dynamicImports = new Map();
|
|
132
|
+
const groupName = getGroupName(rootModuleId.specifier, groups);
|
|
133
|
+
const groupies = groupName && groups[groupName];
|
|
134
|
+
const cachedGroupieCode = groupName && groupieCodeCache.get(groupName);
|
|
135
|
+
const getModuleGraphsWrapper = (graphSpecifier) => {
|
|
136
|
+
const graphOptions = {
|
|
137
|
+
includeLinkedDefinitions: true,
|
|
138
|
+
depth: {
|
|
139
|
+
static: GraphDepth.ALL,
|
|
140
|
+
dynamic: 0,
|
|
141
|
+
includeId: includeIdFactory(graphSpecifier, external, exclude, requiredImports, groups),
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
return getModuleGraphs(graphSpecifier, graphOptions, moduleRegistry, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
145
|
+
};
|
|
146
|
+
const moduleGraphs = await getModuleGraphsWrapper(rootModuleId.specifier);
|
|
147
|
+
const rootModule = moduleGraphs.graphs[0];
|
|
148
|
+
// we also need to get moduleGraphs for any group members this module belongs to
|
|
149
|
+
const groupModuleGraphsMap = new Map();
|
|
150
|
+
if (!cachedGroupieCode && groupies && groupies.length) {
|
|
151
|
+
for (const specifier of groupies) {
|
|
152
|
+
if (specifier !== rootModuleId.specifier) {
|
|
153
|
+
// eslint-disable-next-line no-await-in-loop
|
|
154
|
+
const groupieModuleGraph = await getModuleGraphsWrapper(specifier);
|
|
155
|
+
groupModuleGraphsMap.set(specifier, groupieModuleGraph);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
let bundleCode, includedModules, bundleGroupsIncludedModules;
|
|
160
|
+
// we don't need to recompute the bundle code if it already exists for this group
|
|
161
|
+
const cachedBundleGroupCode = cachedGroupieCode;
|
|
162
|
+
const bundledSpecifiersMap = new Map();
|
|
163
|
+
if (!cachedBundleGroupCode) {
|
|
164
|
+
(includedModules = []), (bundleGroupsIncludedModules = []);
|
|
165
|
+
const bundles = await getBundleCode(rootModule.specifier, moduleGraphs, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rootModuleId.specifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
|
|
166
|
+
if (groupName) {
|
|
167
|
+
// add groupies to bundles
|
|
168
|
+
for (const rawGroupieSpecifier of groupies) {
|
|
169
|
+
if (rawGroupieSpecifier !== rootModuleId.specifier) {
|
|
170
|
+
const groupieModuleGraph = groupModuleGraphsMap.get(rawGroupieSpecifier);
|
|
171
|
+
const groupieSpecifer = groupieModuleGraph.graphs[0].specifier;
|
|
172
|
+
// eslint-disable-next-line no-await-in-loop
|
|
173
|
+
const groupieBundles = await getBundleCode(groupieSpecifer, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
|
|
174
|
+
bundles.push(...groupieBundles);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
bundleCode = bundles.join('');
|
|
179
|
+
if (groupName) {
|
|
180
|
+
includedModules.push(...bundleGroupsIncludedModules);
|
|
181
|
+
groupieCodeCache.set(groupName, { code: bundleCode, includedModules });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
bundleCode = cachedBundleGroupCode.code;
|
|
186
|
+
includedModules = cachedBundleGroupCode.includedModules;
|
|
187
|
+
}
|
|
84
188
|
const { id, name, namespace, version, specifier } = moduleGraphs.linkedDefinitions[rootModule.specifier];
|
|
85
189
|
return {
|
|
86
190
|
id,
|
|
@@ -88,7 +192,7 @@ export async function amdBundler(moduleId, moduleRegistry, minify = false, runti
|
|
|
88
192
|
namespace,
|
|
89
193
|
version,
|
|
90
194
|
specifier,
|
|
91
|
-
code:
|
|
195
|
+
code: bundleCode,
|
|
92
196
|
config: { external, exclude },
|
|
93
197
|
bundleRecord: {
|
|
94
198
|
imports: Array.from(requiredImports.values()),
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.0-alpha.
|
|
7
|
+
"version": "0.10.0-alpha.15",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "tsc -b"
|
|
40
|
+
"build": "tsc -b",
|
|
41
|
+
"clean": "rm -rf build",
|
|
42
|
+
"test": "jest"
|
|
41
43
|
},
|
|
42
44
|
"files": [
|
|
43
45
|
"build/**/*.js",
|
|
@@ -45,13 +47,16 @@
|
|
|
45
47
|
"build/**/*.d.ts"
|
|
46
48
|
],
|
|
47
49
|
"dependencies": {
|
|
48
|
-
"@lwc/features": "2.
|
|
49
|
-
"@lwrjs/shared-utils": "0.10.0-alpha.
|
|
50
|
+
"@lwc/features": "2.46.0",
|
|
51
|
+
"@lwrjs/shared-utils": "0.10.0-alpha.15",
|
|
50
52
|
"@rollup/plugin-replace": "^2.4.2",
|
|
51
53
|
"rollup": "^2.78.0"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
54
|
-
"@lwrjs/types": "0.10.0-alpha.
|
|
56
|
+
"@lwrjs/types": "0.10.0-alpha.15",
|
|
57
|
+
"jest": "^26.6.3",
|
|
58
|
+
"ts-jest": "^26.5.6",
|
|
59
|
+
"typescript": "~4.3.5"
|
|
55
60
|
},
|
|
56
61
|
"optionalDependencies": {
|
|
57
62
|
"esbuild": "^0.9.7"
|
|
@@ -59,5 +64,8 @@
|
|
|
59
64
|
"engines": {
|
|
60
65
|
"node": ">=16.0.0 <20"
|
|
61
66
|
},
|
|
62
|
-
"
|
|
67
|
+
"volta": {
|
|
68
|
+
"extends": "../../../package.json"
|
|
69
|
+
},
|
|
70
|
+
"gitHead": "70557f63a46167c40cf1415f12af69f78ae402d6"
|
|
63
71
|
}
|