@lwrjs/module-bundler 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/esm-bundle-provider.cjs +7 -2
- package/build/cjs/index.cjs +4 -0
- package/build/cjs/utils/amd-common.cjs +12 -5
- package/build/es/esm-bundle-provider.d.ts +1 -1
- package/build/es/esm-bundle-provider.js +9 -2
- package/build/es/index.d.ts +1 -0
- package/build/es/index.js +4 -0
- package/build/es/utils/amd-common.js +17 -7
- package/package.json +6 -6
|
@@ -31,8 +31,9 @@ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
|
31
31
|
var import_rollup_esm_bundler_plugin = __toModule(require("./utils/rollup-esm-bundler-plugin.cjs"));
|
|
32
32
|
var import_esbuild_utils = __toModule(require("./utils/esbuild-utils.cjs"));
|
|
33
33
|
var import_bundle_common = __toModule(require("./utils/bundle-common.cjs"));
|
|
34
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
34
35
|
var EsmBundlerProvider = class {
|
|
35
|
-
constructor(
|
|
36
|
+
constructor(_options, {config, moduleRegistry}) {
|
|
36
37
|
this.name = "esm-bundle-provider";
|
|
37
38
|
this.config = config;
|
|
38
39
|
this.moduleRegistry = moduleRegistry;
|
|
@@ -72,11 +73,15 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
|
|
|
72
73
|
dynamicImports
|
|
73
74
|
})
|
|
74
75
|
],
|
|
76
|
+
external: Object.keys(external),
|
|
75
77
|
makeAbsoluteExternalsRelative: "ifRelativeSource"
|
|
76
78
|
});
|
|
77
79
|
return bundle.generate({
|
|
78
80
|
paths: (id2) => {
|
|
79
|
-
|
|
81
|
+
if (external[id2] && (external[id2].startsWith(import_shared_utils.PROTOCOL_HTTP) || external[id2].startsWith(import_shared_utils.PROTOCOL_HTTPS))) {
|
|
82
|
+
return external[id2];
|
|
83
|
+
}
|
|
84
|
+
return id2;
|
|
80
85
|
},
|
|
81
86
|
sourcemap: true
|
|
82
87
|
});
|
package/build/cjs/index.cjs
CHANGED
|
@@ -50,6 +50,9 @@ var LwrModuleBundler = class {
|
|
|
50
50
|
addBundleTransformers(transformers) {
|
|
51
51
|
this.transformers.push(...transformers);
|
|
52
52
|
}
|
|
53
|
+
getConfig() {
|
|
54
|
+
return this.bundleConfig;
|
|
55
|
+
}
|
|
53
56
|
async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
|
|
54
57
|
const {format, minify, debug} = runtimeEnvironment;
|
|
55
58
|
const cacheKey = `${moduleId.specifier}|${moduleId.version}|${(0, import_shared_utils.getCacheKeyFromJson)({
|
|
@@ -124,6 +127,7 @@ var LwrModuleBundler = class {
|
|
|
124
127
|
}
|
|
125
128
|
getPublicApi() {
|
|
126
129
|
return {
|
|
130
|
+
getConfig: this.getConfig.bind(this),
|
|
127
131
|
getModuleBundle: this.getModuleBundle.bind(this),
|
|
128
132
|
resolveModuleUri: this.resolveModuleUri.bind(this)
|
|
129
133
|
};
|
|
@@ -36,20 +36,24 @@ var AMD_DEFINE = "LWR.define";
|
|
|
36
36
|
var groupieCodeCache = new Map();
|
|
37
37
|
function includeIdFactory(graphSpecifier, external, exclude = [], requiredImports, groups) {
|
|
38
38
|
return (moduleRef) => {
|
|
39
|
+
const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
|
|
39
40
|
if (external[moduleRef.specifier] !== void 0) {
|
|
41
|
+
moduleRef.externalSrc = external[moduleRef.specifier];
|
|
42
|
+
if (moduleIsNotRoot) {
|
|
43
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || import_shared_utils.VERSION_NOT_PROVIDED}`, moduleRef);
|
|
44
|
+
}
|
|
40
45
|
return false;
|
|
41
46
|
}
|
|
42
47
|
const moduleRefIsGroupie = (0, import_shared_utils.isGroupie)(moduleRef.specifier, groups);
|
|
43
48
|
const rootModuleIsGroupie = (0, import_shared_utils.isGroupie)(graphSpecifier, groups);
|
|
44
|
-
const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
|
|
45
49
|
if (moduleRefIsGroupie) {
|
|
46
50
|
if (moduleIsNotRoot && !rootModuleIsGroupie) {
|
|
47
|
-
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
51
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || import_shared_utils.VERSION_NOT_PROVIDED}`, moduleRef);
|
|
48
52
|
}
|
|
49
53
|
return false;
|
|
50
54
|
} else if (exclude?.includes(moduleRef.specifier)) {
|
|
51
55
|
if (moduleIsNotRoot) {
|
|
52
|
-
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
56
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || import_shared_utils.VERSION_NOT_PROVIDED}`, moduleRef);
|
|
53
57
|
}
|
|
54
58
|
return false;
|
|
55
59
|
}
|
|
@@ -131,6 +135,9 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
|
|
|
131
135
|
} else {
|
|
132
136
|
bundleGroupsIncludedModules.push(id);
|
|
133
137
|
}
|
|
138
|
+
if ((0, import_shared_utils.isExternalSpecifier)(id, moduleRegistry.getConfig().bundleConfig)) {
|
|
139
|
+
return linkedDefinition.linkedSource;
|
|
140
|
+
}
|
|
134
141
|
return bundle(id, moduleGraphs, minify, unVersionedAliases);
|
|
135
142
|
}))).filter((x) => typeof x === "string");
|
|
136
143
|
return bundles;
|
|
@@ -175,8 +182,8 @@ async function amdBundler(rootModuleId, moduleRegistry, minify = false, runtimeE
|
|
|
175
182
|
for (const rawGroupieSpecifier of groupies) {
|
|
176
183
|
if (rawGroupieSpecifier !== rootModuleId.specifier) {
|
|
177
184
|
const groupieModuleGraph = groupModuleGraphsMap.get(rawGroupieSpecifier);
|
|
178
|
-
const
|
|
179
|
-
const groupieBundles = await getBundleCode(
|
|
185
|
+
const groupieSpecifier = groupieModuleGraph.graphs[0].specifier;
|
|
186
|
+
const groupieBundles = await getBundleCode(groupieSpecifier, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
|
|
180
187
|
bundles.push(...groupieBundles);
|
|
181
188
|
}
|
|
182
189
|
}
|
|
@@ -3,7 +3,7 @@ export default class EsmBundlerProvider implements BundleProvider {
|
|
|
3
3
|
name: string;
|
|
4
4
|
config: ProviderAppConfig;
|
|
5
5
|
moduleRegistry: PublicModuleRegistry;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(_options: {}, { config, moduleRegistry }: ProviderContext);
|
|
7
7
|
bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition | undefined>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=esm-bundle-provider.d.ts.map
|
|
@@ -3,8 +3,9 @@ import { BundleSpan, getTracer } from '@lwrjs/instrumentation';
|
|
|
3
3
|
import { bundleDefinitions } from './utils/rollup-esm-bundler-plugin.js';
|
|
4
4
|
import { minifyJavascript } from './utils/esbuild-utils.js';
|
|
5
5
|
import { overrideBundleConfig } from './utils/bundle-common.js';
|
|
6
|
+
import { PROTOCOL_HTTP, PROTOCOL_HTTPS } from '@lwrjs/shared-utils';
|
|
6
7
|
export default class EsmBundlerProvider {
|
|
7
|
-
constructor(
|
|
8
|
+
constructor(_options, { config, moduleRegistry }) {
|
|
8
9
|
this.name = 'esm-bundle-provider';
|
|
9
10
|
this.config = config;
|
|
10
11
|
this.moduleRegistry = moduleRegistry;
|
|
@@ -43,13 +44,19 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
|
|
|
43
44
|
dynamicImports,
|
|
44
45
|
}),
|
|
45
46
|
],
|
|
47
|
+
external: Object.keys(external),
|
|
46
48
|
makeAbsoluteExternalsRelative: 'ifRelativeSource', // Fix for breaking changes in https://github.com/rollup/rollup/pull/4021
|
|
47
49
|
});
|
|
48
50
|
return bundle.generate({
|
|
49
51
|
paths: (id) => {
|
|
50
52
|
// The fallback on id is important due to a rollup semantic issue:
|
|
51
53
|
// https://github.com/rollup/rollup/issues/3831
|
|
52
|
-
|
|
54
|
+
// If external is an http:// URL use that in the ESM Module
|
|
55
|
+
if (external[id] &&
|
|
56
|
+
(external[id].startsWith(PROTOCOL_HTTP) || external[id].startsWith(PROTOCOL_HTTPS))) {
|
|
57
|
+
return external[id];
|
|
58
|
+
}
|
|
59
|
+
return id;
|
|
53
60
|
},
|
|
54
61
|
sourcemap: true,
|
|
55
62
|
});
|
package/build/es/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class LwrModuleBundler implements ModuleBundler {
|
|
|
14
14
|
constructor(config: LwrModuleBundlerConfig, globalConfig: NormalizedLwrGlobalConfig);
|
|
15
15
|
addBundleProviders(providers: BundleProvider[]): void;
|
|
16
16
|
addBundleTransformers(transformers: UriTransformPlugin[]): void;
|
|
17
|
+
getConfig(): BundleConfig;
|
|
17
18
|
getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition>;
|
|
18
19
|
/**
|
|
19
20
|
* Resolve the URI to the bundle rooted at the `moduleId`
|
package/build/es/index.js
CHANGED
|
@@ -28,6 +28,9 @@ export class LwrModuleBundler {
|
|
|
28
28
|
addBundleTransformers(transformers) {
|
|
29
29
|
this.transformers.push(...transformers);
|
|
30
30
|
}
|
|
31
|
+
getConfig() {
|
|
32
|
+
return this.bundleConfig;
|
|
33
|
+
}
|
|
31
34
|
async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
|
|
32
35
|
const { format, minify, debug } = runtimeEnvironment;
|
|
33
36
|
const cacheKey = `${moduleId.specifier}|${moduleId.version}|${getCacheKeyFromJson({
|
|
@@ -121,6 +124,7 @@ export class LwrModuleBundler {
|
|
|
121
124
|
}
|
|
122
125
|
getPublicApi() {
|
|
123
126
|
return {
|
|
127
|
+
getConfig: this.getConfig.bind(this),
|
|
124
128
|
getModuleBundle: this.getModuleBundle.bind(this),
|
|
125
129
|
resolveModuleUri: this.resolveModuleUri.bind(this),
|
|
126
130
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, getCacheKeyFromJson, } from '@lwrjs/shared-utils';
|
|
1
|
+
import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, getCacheKeyFromJson, VERSION_NOT_PROVIDED, isExternalSpecifier, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { rollup } from 'rollup';
|
|
3
3
|
import replace from '@rollup/plugin-replace';
|
|
4
4
|
import { BundleSpan, getTracer } from '@lwrjs/instrumentation';
|
|
@@ -8,21 +8,27 @@ const AMD_DEFINE = 'LWR.define';
|
|
|
8
8
|
const groupieCodeCache = new Map();
|
|
9
9
|
function includeIdFactory(graphSpecifier, external, exclude = [], requiredImports, groups) {
|
|
10
10
|
return (moduleRef) => {
|
|
11
|
+
const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
|
|
11
12
|
// Do not bundle externals, including the loader module, which is auto bundled
|
|
12
13
|
// with the shim + loader combo
|
|
13
14
|
if (external[moduleRef.specifier] !== undefined) {
|
|
14
|
-
//
|
|
15
|
+
// Include externals just mark them as such
|
|
16
|
+
moduleRef.externalSrc = external[moduleRef.specifier];
|
|
17
|
+
if (moduleIsNotRoot) {
|
|
18
|
+
// Include externals in the required imports
|
|
19
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || VERSION_NOT_PROVIDED}`, moduleRef);
|
|
20
|
+
}
|
|
21
|
+
// return false to indicate it should not be in the bundle
|
|
15
22
|
return false;
|
|
16
23
|
}
|
|
17
24
|
const moduleRefIsGroupie = isGroupie(moduleRef.specifier, groups);
|
|
18
25
|
const rootModuleIsGroupie = isGroupie(graphSpecifier, groups);
|
|
19
|
-
const moduleIsNotRoot = graphSpecifier !== moduleRef.specifier;
|
|
20
26
|
if (moduleRefIsGroupie) {
|
|
21
27
|
// If this is part of bundle group return false to indicate it should not be in the bundle
|
|
22
28
|
// but add it to the requiredImports so it shows up as a static dependency of the bundle.
|
|
23
29
|
// However, skip this if the requested specifier is also part of the same group.
|
|
24
30
|
if (moduleIsNotRoot && !rootModuleIsGroupie) {
|
|
25
|
-
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
31
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || VERSION_NOT_PROVIDED}`, moduleRef);
|
|
26
32
|
}
|
|
27
33
|
return false;
|
|
28
34
|
}
|
|
@@ -30,7 +36,7 @@ function includeIdFactory(graphSpecifier, external, exclude = [], requiredImport
|
|
|
30
36
|
// If this is a bundle exclude return false to indicate it should not be in the bundle
|
|
31
37
|
// but add it to the requiredImports so it shows up as a static dependency of the bundle.
|
|
32
38
|
if (moduleIsNotRoot) {
|
|
33
|
-
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
39
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version || VERSION_NOT_PROVIDED}`, moduleRef);
|
|
34
40
|
}
|
|
35
41
|
return false;
|
|
36
42
|
}
|
|
@@ -128,6 +134,10 @@ async function getBundleCode(rootModule, moduleGraphs, includedModules, bundleGr
|
|
|
128
134
|
// we need to still keep track of roots for bundle groups
|
|
129
135
|
bundleGroupsIncludedModules.push(id);
|
|
130
136
|
}
|
|
137
|
+
// If this is a external dependency just return the linked source no need to bundle.
|
|
138
|
+
if (isExternalSpecifier(id, moduleRegistry.getConfig().bundleConfig)) {
|
|
139
|
+
return linkedDefinition.linkedSource;
|
|
140
|
+
}
|
|
131
141
|
// bundle all dependencies for the linked definition and convert to AMD
|
|
132
142
|
return bundle(id, moduleGraphs, minify, unVersionedAliases);
|
|
133
143
|
}))).filter((x) => typeof x === 'string');
|
|
@@ -180,9 +190,9 @@ export async function amdBundler(rootModuleId, moduleRegistry, minify = false, r
|
|
|
180
190
|
for (const rawGroupieSpecifier of groupies) {
|
|
181
191
|
if (rawGroupieSpecifier !== rootModuleId.specifier) {
|
|
182
192
|
const groupieModuleGraph = groupModuleGraphsMap.get(rawGroupieSpecifier);
|
|
183
|
-
const
|
|
193
|
+
const groupieSpecifier = groupieModuleGraph.graphs[0].specifier;
|
|
184
194
|
// eslint-disable-next-line no-await-in-loop
|
|
185
|
-
const groupieBundles = await getBundleCode(
|
|
195
|
+
const groupieBundles = await getBundleCode(groupieSpecifier, groupieModuleGraph, includedModules, bundleGroupsIncludedModules, dynamicImports, minify, !!runtimeEnvironment.featureFlags?.EXPERIMENTAL_UNVERSIONED_ALIASES, includeIdFactory(rawGroupieSpecifier, external, exclude, requiredImports, groups), moduleRegistry, runtimeEnvironment, runtimeParams, bundledSpecifiersMap);
|
|
186
196
|
bundles.push(...groupieBundles);
|
|
187
197
|
}
|
|
188
198
|
}
|
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",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"build/**/*.d.ts"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@lwrjs/diagnostics": "0.12.0-alpha.
|
|
51
|
-
"@lwrjs/instrumentation": "0.12.0-alpha.
|
|
52
|
-
"@lwrjs/shared-utils": "0.12.0-alpha.
|
|
50
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.22",
|
|
51
|
+
"@lwrjs/instrumentation": "0.12.0-alpha.22",
|
|
52
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.22",
|
|
53
53
|
"@rollup/plugin-replace": "^2.4.2",
|
|
54
54
|
"rollup": "^2.78.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
57
|
+
"@lwrjs/types": "0.12.0-alpha.22",
|
|
58
58
|
"jest": "^26.6.3",
|
|
59
59
|
"ts-jest": "^26.5.6"
|
|
60
60
|
},
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"volta": {
|
|
71
71
|
"extends": "../../../package.json"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "6eb804007e93e513d4eb60fd321c088bad3c698e"
|
|
74
74
|
}
|