@lwrjs/module-bundler 0.9.0-alpha.14 → 0.9.0-alpha.16
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-bundle-provider.cjs +7 -1
- package/build/cjs/esm-bundle-provider.cjs +3 -2
- package/build/cjs/index.cjs +26 -3
- package/build/cjs/utils/amd-common.cjs +4 -3
- package/build/cjs/utils/bundle-common.cjs +44 -0
- package/build/cjs/utils/esbuild-utils.cjs +15 -1
- package/build/es/amd-bundle-provider.d.ts +2 -2
- package/build/es/amd-bundle-provider.js +5 -2
- package/build/es/amd-runtime-bundle-provider.d.ts +2 -2
- package/build/es/esm-bundle-provider.d.ts +2 -2
- package/build/es/esm-bundle-provider.js +3 -2
- package/build/es/index.d.ts +5 -4
- package/build/es/index.js +31 -5
- package/build/es/utils/amd-common.d.ts +2 -2
- package/build/es/utils/amd-common.js +4 -3
- package/build/es/utils/bundle-common.d.ts +3 -0
- package/build/es/utils/bundle-common.js +39 -0
- package/build/es/utils/esbuild-utils.d.ts +8 -0
- package/build/es/utils/esbuild-utils.js +19 -1
- package/package.json +13 -6
|
@@ -38,10 +38,16 @@ var AmdBundlerProvider = class {
|
|
|
38
38
|
if (runtimeEnvironment.format === "amd") {
|
|
39
39
|
const {moduleRegistry, config} = this;
|
|
40
40
|
const bundle = await (0, import_amd_common.amdBundler)(moduleId, moduleRegistry, false, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
|
|
41
|
-
const {
|
|
41
|
+
const {
|
|
42
|
+
minify,
|
|
43
|
+
debug,
|
|
44
|
+
env: {NODE_ENV: envMode} = {NODE_ENV: "production"}
|
|
45
|
+
} = runtimeEnvironment;
|
|
42
46
|
const minified = !!minify && !debug;
|
|
43
47
|
if (minified) {
|
|
44
48
|
bundle.code = await (0, import_esbuild_utils.minifyJavascript)(bundle.code);
|
|
49
|
+
} else {
|
|
50
|
+
bundle.code = await (0, import_esbuild_utils.parseJavascript)(bundle.code, {envMode});
|
|
45
51
|
}
|
|
46
52
|
return bundle;
|
|
47
53
|
}
|
|
@@ -29,6 +29,7 @@ __export(exports, {
|
|
|
29
29
|
var import_rollup = __toModule(require("rollup"));
|
|
30
30
|
var import_rollup_esm_bundler_plugin = __toModule(require("./utils/rollup-esm-bundler-plugin.cjs"));
|
|
31
31
|
var import_esbuild_utils = __toModule(require("./utils/esbuild-utils.cjs"));
|
|
32
|
+
var import_bundle_common = __toModule(require("./utils/bundle-common.cjs"));
|
|
32
33
|
var EsmBundlerProvider = class {
|
|
33
34
|
constructor(options, {config, moduleRegistry}) {
|
|
34
35
|
this.name = "esm-bundle-provider";
|
|
@@ -43,8 +44,8 @@ var EsmBundlerProvider = class {
|
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
var esm_bundle_provider_default = EsmBundlerProvider;
|
|
46
|
-
async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, {bundleConfig},
|
|
47
|
-
const {exclude, external = {}, alias = {}} =
|
|
47
|
+
async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, {bundleConfig}, bundleConfigOverrides) {
|
|
48
|
+
const {exclude, external = {}, alias = {}} = (0, import_bundle_common.overrideBundleConfig)(bundleConfig, bundleConfigOverrides);
|
|
48
49
|
const {sourceMapUrl} = runtimeEnvironment;
|
|
49
50
|
const requiredImports = new Map();
|
|
50
51
|
const dynamicImports = new Map();
|
package/build/cjs/index.cjs
CHANGED
|
@@ -34,9 +34,9 @@ var LwrModuleBundler = class {
|
|
|
34
34
|
this.cache = new Map();
|
|
35
35
|
this.providers = [];
|
|
36
36
|
this.inflightBundleDefinitions = new import_shared_utils.InflightTasks();
|
|
37
|
-
this.config = globalConfig;
|
|
38
37
|
this.moduleRegistry = config.moduleRegistry;
|
|
39
38
|
this.appObserver = config.appObserver;
|
|
39
|
+
this.bundleConfig = Object.freeze(globalConfig.bundleConfig);
|
|
40
40
|
this.appObserver?.onModuleDefinitionChange(() => {
|
|
41
41
|
this.cache.clear();
|
|
42
42
|
});
|
|
@@ -77,7 +77,30 @@ var LwrModuleBundler = class {
|
|
|
77
77
|
}, this);
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
|
|
81
|
-
|
|
80
|
+
async resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
|
|
81
|
+
const bundleDefinition = await this.getModuleBundle(moduleId, runtimeEnvironment, runtimeParams);
|
|
82
|
+
if (!bundleDefinition) {
|
|
83
|
+
throw (0, import_diagnostics.createSingleDiagnosticError)({
|
|
84
|
+
description: import_diagnostics.descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier)
|
|
85
|
+
}, import_diagnostics.LwrUnresolvableError);
|
|
86
|
+
}
|
|
87
|
+
let uri;
|
|
88
|
+
if (bundleDefinition.src) {
|
|
89
|
+
uri = bundleDefinition.src;
|
|
90
|
+
} else {
|
|
91
|
+
let resolvedVersion = moduleId.version || bundleDefinition.version;
|
|
92
|
+
if (!resolvedVersion) {
|
|
93
|
+
const {version} = await this.moduleRegistry.getModuleEntry(moduleId);
|
|
94
|
+
resolvedVersion = version;
|
|
95
|
+
}
|
|
96
|
+
uri = String(await this.moduleRegistry.resolveModuleUri({...moduleId, version: resolvedVersion}, runtimeEnvironment, runtimeParams, signature));
|
|
97
|
+
}
|
|
98
|
+
return uri;
|
|
99
|
+
}
|
|
100
|
+
getPublicApi() {
|
|
101
|
+
return {
|
|
102
|
+
getModuleBundle: this.getModuleBundle.bind(this),
|
|
103
|
+
resolveModuleUri: this.resolveModuleUri.bind(this)
|
|
104
|
+
};
|
|
82
105
|
}
|
|
83
106
|
};
|
|
@@ -31,6 +31,7 @@ var import_rollup = __toModule(require("rollup"));
|
|
|
31
31
|
var import_plugin_replace = __toModule(require("@rollup/plugin-replace"));
|
|
32
32
|
var import_rollup_plugin_terser = __toModule(require("rollup-plugin-terser"));
|
|
33
33
|
var import_rollup_amd_bundler_plugin = __toModule(require("./rollup-amd-bundler-plugin.cjs"));
|
|
34
|
+
var import_bundle_common = __toModule(require("./bundle-common.cjs"));
|
|
34
35
|
var AMD_DEFINE = "LWR.define";
|
|
35
36
|
async function bundle(id, moduleGraphs, minify = false) {
|
|
36
37
|
const plugins = [(0, import_rollup_amd_bundler_plugin.bundleDefinitions)({moduleGraphs})];
|
|
@@ -46,8 +47,8 @@ async function bundle(id, moduleGraphs, minify = false) {
|
|
|
46
47
|
});
|
|
47
48
|
return output[0].code;
|
|
48
49
|
}
|
|
49
|
-
async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, {bundleConfig, amdLoader},
|
|
50
|
-
const {exclude, external} =
|
|
50
|
+
async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, {bundleConfig, amdLoader}, bundleConfigOverrides) {
|
|
51
|
+
const {exclude, external = {}} = (0, import_bundle_common.overrideBundleConfig)(bundleConfig, bundleConfigOverrides);
|
|
51
52
|
const requiredImports = new Map();
|
|
52
53
|
const dynamicImports = new Map();
|
|
53
54
|
const includedModules = [];
|
|
@@ -58,7 +59,7 @@ async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvir
|
|
|
58
59
|
dynamic: 0,
|
|
59
60
|
includeId: (moduleRef) => {
|
|
60
61
|
if (exclude?.includes(moduleRef.specifier) || moduleRef.specifier === amdLoader) {
|
|
61
|
-
requiredImports.set(`${
|
|
62
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
62
63
|
return false;
|
|
63
64
|
}
|
|
64
65
|
return true;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/@lwrjs/module-bundler/src/utils/bundle-common.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
overrideBundleConfig: () => overrideBundleConfig
|
|
12
|
+
});
|
|
13
|
+
function overrideBundleConfig(bundleConfig, bundleConfigOverrides) {
|
|
14
|
+
if (!bundleConfigOverrides) {
|
|
15
|
+
return bundleConfig;
|
|
16
|
+
}
|
|
17
|
+
const newBundleConfig = {
|
|
18
|
+
UNSAFE_lwrDefaultExclude: [
|
|
19
|
+
...bundleConfigOverrides.UNSAFE_lwrDefaultExclude || [
|
|
20
|
+
...bundleConfig.UNSAFE_lwrDefaultExclude || []
|
|
21
|
+
]
|
|
22
|
+
],
|
|
23
|
+
external: {...bundleConfigOverrides.external || {...bundleConfig.external || {}}},
|
|
24
|
+
alias: {...bundleConfigOverrides.alias || {...bundleConfig.alias || {}}}
|
|
25
|
+
};
|
|
26
|
+
if (bundleConfigOverrides.appendExcludes) {
|
|
27
|
+
newBundleConfig.exclude = appendAndDedupArrays(bundleConfig.exclude, bundleConfigOverrides.exclude);
|
|
28
|
+
} else {
|
|
29
|
+
newBundleConfig.exclude = [...bundleConfigOverrides.exclude || [...bundleConfig.exclude || []]];
|
|
30
|
+
}
|
|
31
|
+
return newBundleConfig;
|
|
32
|
+
}
|
|
33
|
+
function appendAndDedupArrays(a1, a2) {
|
|
34
|
+
let ret;
|
|
35
|
+
if (!a1 && a2) {
|
|
36
|
+
return a2.filter((item, pos) => a2.indexOf(item) === pos);
|
|
37
|
+
} else if (!a2 && a1) {
|
|
38
|
+
return a1.filter((item, pos) => a1.indexOf(item) === pos);
|
|
39
|
+
} else if (a1 && a2) {
|
|
40
|
+
const c = a1?.concat(a2);
|
|
41
|
+
return c.filter((item, pos) => c.indexOf(item) === pos);
|
|
42
|
+
}
|
|
43
|
+
return ret;
|
|
44
|
+
}
|
|
@@ -24,7 +24,8 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/module-bundler/src/utils/esbuild-utils.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
-
minifyJavascript: () => minifyJavascript
|
|
27
|
+
minifyJavascript: () => minifyJavascript,
|
|
28
|
+
parseJavascript: () => parseJavascript
|
|
28
29
|
});
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
31
|
var import_esbuild = __toModule(require("esbuild"));
|
|
@@ -48,3 +49,16 @@ async function minifyJavascript(source) {
|
|
|
48
49
|
throw error;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
52
|
+
async function parseJavascript(source, options) {
|
|
53
|
+
try {
|
|
54
|
+
const {code} = await esbuild.transform(source, {
|
|
55
|
+
loader: "js",
|
|
56
|
+
minify: false,
|
|
57
|
+
define: {"process.env.NODE_ENV": JSON.stringify(options.envMode)}
|
|
58
|
+
});
|
|
59
|
+
return code;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
import_shared_utils.logger.debug(error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AbstractModuleId,
|
|
1
|
+
import { AbstractModuleId, BundleConfigOverrides, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
export default class AmdBundlerProvider implements BundleProvider {
|
|
3
3
|
name: string;
|
|
4
4
|
config: ProviderAppConfig;
|
|
5
5
|
moduleRegistry: PublicModuleRegistry;
|
|
6
6
|
constructor(options: {}, { config, moduleRegistry }: ProviderContext);
|
|
7
|
-
bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?:
|
|
7
|
+
bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition | undefined>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=amd-bundle-provider.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { amdBundler } from './utils/amd-common.js';
|
|
2
|
-
import { minifyJavascript } from './utils/esbuild-utils.js';
|
|
2
|
+
import { minifyJavascript, parseJavascript } from './utils/esbuild-utils.js';
|
|
3
3
|
export default class AmdBundlerProvider {
|
|
4
4
|
constructor(options, { config, moduleRegistry }) {
|
|
5
5
|
this.name = 'amd-bundle-provider';
|
|
@@ -12,11 +12,14 @@ export default class AmdBundlerProvider {
|
|
|
12
12
|
const bundle = await amdBundler(moduleId, moduleRegistry, false, // we NEVER want to minify via rollup/terser with this bundler; it's too slow
|
|
13
13
|
runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
|
|
14
14
|
// Minification via esbuild for performance
|
|
15
|
-
const { minify, debug } = runtimeEnvironment;
|
|
15
|
+
const { minify, debug, env: { NODE_ENV: envMode } = { NODE_ENV: 'production' }, } = runtimeEnvironment;
|
|
16
16
|
const minified = !!minify && !debug;
|
|
17
17
|
if (minified) {
|
|
18
18
|
bundle.code = await minifyJavascript(bundle.code);
|
|
19
19
|
}
|
|
20
|
+
else {
|
|
21
|
+
bundle.code = await parseJavascript(bundle.code, { envMode });
|
|
22
|
+
}
|
|
20
23
|
return bundle;
|
|
21
24
|
}
|
|
22
25
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AbstractModuleId,
|
|
1
|
+
import { AbstractModuleId, BundleConfigOverrides, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
export default class AmdBundlerProvider implements BundleProvider {
|
|
3
3
|
name: string;
|
|
4
4
|
config: ProviderAppConfig;
|
|
5
5
|
moduleRegistry: PublicModuleRegistry;
|
|
6
6
|
constructor(options: {}, { config, moduleRegistry }: ProviderContext);
|
|
7
|
-
bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?:
|
|
7
|
+
bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition | undefined>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=amd-runtime-bundle-provider.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { AbstractModuleId,
|
|
1
|
+
import type { AbstractModuleId, BundleConfigOverrides, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
export default class EsmBundlerProvider implements BundleProvider {
|
|
3
3
|
name: string;
|
|
4
4
|
config: ProviderAppConfig;
|
|
5
5
|
moduleRegistry: PublicModuleRegistry;
|
|
6
6
|
constructor(options: {}, { config, moduleRegistry }: ProviderContext);
|
|
7
|
-
bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?:
|
|
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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { rollup } from 'rollup';
|
|
2
2
|
import { bundleDefinitions } from './utils/rollup-esm-bundler-plugin.js';
|
|
3
3
|
import { minifyJavascript } from './utils/esbuild-utils.js';
|
|
4
|
+
import { overrideBundleConfig } from './utils/bundle-common.js';
|
|
4
5
|
export default class EsmBundlerProvider {
|
|
5
6
|
constructor(options, { config, moduleRegistry }) {
|
|
6
7
|
this.name = 'esm-bundle-provider';
|
|
@@ -14,8 +15,8 @@ export default class EsmBundlerProvider {
|
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, { bundleConfig },
|
|
18
|
-
const { exclude, external = {}, alias = {} } =
|
|
18
|
+
async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, { bundleConfig }, bundleConfigOverrides) {
|
|
19
|
+
const { exclude, external = {}, alias = {} } = overrideBundleConfig(bundleConfig, bundleConfigOverrides);
|
|
19
20
|
const { sourceMapUrl } = runtimeEnvironment;
|
|
20
21
|
const requiredImports = new Map();
|
|
21
22
|
const dynamicImports = new Map();
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractModuleId, BundleConfig, BundleDefinition, BundleProvider, LwrAppObserver, ModuleBundler, ModuleId, ModuleRegistry, NormalizedLwrGlobalConfig, RuntimeEnvironment, RuntimeParams, SourceMapRuntimeEnvironment } from '@lwrjs/types';
|
|
1
|
+
import { AbstractModuleId, BundleConfig, BundleConfigOverrides, BundleDefinition, BundleProvider, LwrAppObserver, ModuleBundler, ModuleId, ModuleRegistry, NormalizedLwrGlobalConfig, PublicModuleBundler, RuntimeEnvironment, RuntimeParams, SourceMapRuntimeEnvironment } from '@lwrjs/types';
|
|
2
2
|
interface LwrModuleBundlerConfig {
|
|
3
3
|
moduleRegistry: ModuleRegistry;
|
|
4
4
|
appObserver?: LwrAppObserver;
|
|
@@ -6,13 +6,13 @@ interface LwrModuleBundlerConfig {
|
|
|
6
6
|
export declare class LwrModuleBundler implements ModuleBundler {
|
|
7
7
|
moduleRegistry: ModuleRegistry;
|
|
8
8
|
appObserver: LwrAppObserver | undefined;
|
|
9
|
-
config: NormalizedLwrGlobalConfig;
|
|
10
9
|
cache: Map<string, BundleDefinition>;
|
|
11
10
|
providers: BundleProvider[];
|
|
11
|
+
bundleConfig: BundleConfig;
|
|
12
12
|
private inflightBundleDefinitions;
|
|
13
13
|
constructor(config: LwrModuleBundlerConfig, globalConfig: NormalizedLwrGlobalConfig);
|
|
14
14
|
addBundleProviders(providers: BundleProvider[]): void;
|
|
15
|
-
getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams, bundleConfigOverrides?:
|
|
15
|
+
getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition>;
|
|
16
16
|
/**
|
|
17
17
|
* Resolve the URI to the bundle rooted at the `moduleId`
|
|
18
18
|
* @param moduleId - The id of the root module for the bundle
|
|
@@ -21,7 +21,8 @@ export declare class LwrModuleBundler implements ModuleBundler {
|
|
|
21
21
|
* @param signature - The signature of the bundle instance being referenced
|
|
22
22
|
* @returns the URI
|
|
23
23
|
*/
|
|
24
|
-
resolveModuleUri
|
|
24
|
+
resolveModuleUri(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, signature?: string): Promise<string>;
|
|
25
|
+
getPublicApi(): PublicModuleBundler;
|
|
25
26
|
}
|
|
26
27
|
export {};
|
|
27
28
|
//# sourceMappingURL=index.d.ts.map
|
package/build/es/index.js
CHANGED
|
@@ -9,9 +9,10 @@ export class LwrModuleBundler {
|
|
|
9
9
|
// Subsequent requests for the same bundle will await the original promise.
|
|
10
10
|
// Cache entries will be removed once the bundle is resolved.
|
|
11
11
|
this.inflightBundleDefinitions = new InflightTasks();
|
|
12
|
-
this.config = globalConfig;
|
|
13
12
|
this.moduleRegistry = config.moduleRegistry;
|
|
14
13
|
this.appObserver = config.appObserver;
|
|
14
|
+
// Freeze the bundle config to make sure it is not modified
|
|
15
|
+
this.bundleConfig = Object.freeze(globalConfig.bundleConfig);
|
|
15
16
|
this.appObserver?.onModuleDefinitionChange(() => {
|
|
16
17
|
// TODO: This is a very naive approach however
|
|
17
18
|
// this would only happen in non-prod environments
|
|
@@ -69,10 +70,35 @@ export class LwrModuleBundler {
|
|
|
69
70
|
* @param signature - The signature of the bundle instance being referenced
|
|
70
71
|
* @returns the URI
|
|
71
72
|
*/
|
|
72
|
-
resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
async resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
|
|
74
|
+
// First get the bundle definition to see if a src attribute is set.
|
|
75
|
+
const bundleDefinition = await this.getModuleBundle(moduleId, runtimeEnvironment, runtimeParams);
|
|
76
|
+
if (!bundleDefinition) {
|
|
77
|
+
throw createSingleDiagnosticError({
|
|
78
|
+
description: descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier),
|
|
79
|
+
}, LwrUnresolvableError);
|
|
80
|
+
}
|
|
81
|
+
let uri;
|
|
82
|
+
if (bundleDefinition.src) {
|
|
83
|
+
// If source is provided on the bundle definition use that
|
|
84
|
+
uri = bundleDefinition.src;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
let resolvedVersion = moduleId.version || bundleDefinition.version;
|
|
88
|
+
// If we do not know the verison, look it up.
|
|
89
|
+
if (!resolvedVersion) {
|
|
90
|
+
const { version } = await this.moduleRegistry.getModuleEntry(moduleId);
|
|
91
|
+
resolvedVersion = version;
|
|
92
|
+
}
|
|
93
|
+
uri = String(await this.moduleRegistry.resolveModuleUri({ ...moduleId, version: resolvedVersion }, runtimeEnvironment, runtimeParams, signature));
|
|
94
|
+
}
|
|
95
|
+
return uri;
|
|
96
|
+
}
|
|
97
|
+
getPublicApi() {
|
|
98
|
+
return {
|
|
99
|
+
getModuleBundle: this.getModuleBundle.bind(this),
|
|
100
|
+
resolveModuleUri: this.resolveModuleUri.bind(this),
|
|
101
|
+
};
|
|
76
102
|
}
|
|
77
103
|
}
|
|
78
104
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AbstractModuleId,
|
|
2
|
-
export declare function amdBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, minify: boolean | undefined, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams | undefined, { bundleConfig, amdLoader }: ProviderAppConfig,
|
|
1
|
+
import type { AbstractModuleId, BundleConfigOverrides, BundleDefinition, ModuleRegistry, ProviderAppConfig, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
|
+
export declare function amdBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, minify: boolean | undefined, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams | undefined, { bundleConfig, amdLoader }: ProviderAppConfig, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition>;
|
|
3
3
|
//# sourceMappingURL=amd-common.d.ts.map
|
|
@@ -3,6 +3,7 @@ import { rollup } from 'rollup';
|
|
|
3
3
|
import replace from '@rollup/plugin-replace';
|
|
4
4
|
import { terser } from 'rollup-plugin-terser';
|
|
5
5
|
import { bundleDefinitions } from './rollup-amd-bundler-plugin.js';
|
|
6
|
+
import { overrideBundleConfig } from './bundle-common.js';
|
|
6
7
|
const AMD_DEFINE = 'LWR.define';
|
|
7
8
|
async function bundle(id, moduleGraphs, minify = false) {
|
|
8
9
|
const plugins = [bundleDefinitions({ moduleGraphs })];
|
|
@@ -19,8 +20,8 @@ async function bundle(id, moduleGraphs, minify = false) {
|
|
|
19
20
|
});
|
|
20
21
|
return output[0].code;
|
|
21
22
|
}
|
|
22
|
-
export async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, { bundleConfig, amdLoader },
|
|
23
|
-
const { exclude, external } =
|
|
23
|
+
export async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, { bundleConfig, amdLoader }, bundleConfigOverrides) {
|
|
24
|
+
const { exclude, external = {} } = overrideBundleConfig(bundleConfig, bundleConfigOverrides);
|
|
24
25
|
const requiredImports = new Map();
|
|
25
26
|
const dynamicImports = new Map();
|
|
26
27
|
const includedModules = [];
|
|
@@ -32,7 +33,7 @@ export async function amdBundler(moduleId, moduleRegistry, minify = false, runti
|
|
|
32
33
|
includeId: (moduleRef) => {
|
|
33
34
|
// loader should be auto bundled with shim already
|
|
34
35
|
if (exclude?.includes(moduleRef.specifier) || moduleRef.specifier === amdLoader) {
|
|
35
|
-
requiredImports.set(`${
|
|
36
|
+
requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
|
|
36
37
|
return false;
|
|
37
38
|
}
|
|
38
39
|
return true;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function overrideBundleConfig(bundleConfig, bundleConfigOverrides) {
|
|
2
|
+
if (!bundleConfigOverrides) {
|
|
3
|
+
return bundleConfig;
|
|
4
|
+
}
|
|
5
|
+
// Replace properties that are overridden
|
|
6
|
+
const newBundleConfig = {
|
|
7
|
+
UNSAFE_lwrDefaultExclude: [
|
|
8
|
+
...(bundleConfigOverrides.UNSAFE_lwrDefaultExclude || [
|
|
9
|
+
...(bundleConfig.UNSAFE_lwrDefaultExclude || []),
|
|
10
|
+
]),
|
|
11
|
+
],
|
|
12
|
+
external: { ...(bundleConfigOverrides.external || { ...(bundleConfig.external || {}) }) },
|
|
13
|
+
alias: { ...(bundleConfigOverrides.alias || { ...(bundleConfig.alias || {}) }) },
|
|
14
|
+
};
|
|
15
|
+
// Append Excludes
|
|
16
|
+
if (bundleConfigOverrides.appendExcludes) {
|
|
17
|
+
newBundleConfig.exclude = appendAndDedupArrays(bundleConfig.exclude, bundleConfigOverrides.exclude);
|
|
18
|
+
// or Replace Excludes
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
newBundleConfig.exclude = [...(bundleConfigOverrides.exclude || [...(bundleConfig.exclude || [])])];
|
|
22
|
+
}
|
|
23
|
+
return newBundleConfig;
|
|
24
|
+
}
|
|
25
|
+
function appendAndDedupArrays(a1, a2) {
|
|
26
|
+
let ret;
|
|
27
|
+
if (!a1 && a2) {
|
|
28
|
+
return a2.filter((item, pos) => a2.indexOf(item) === pos);
|
|
29
|
+
}
|
|
30
|
+
else if (!a2 && a1) {
|
|
31
|
+
return a1.filter((item, pos) => a1.indexOf(item) === pos);
|
|
32
|
+
}
|
|
33
|
+
else if (a1 && a2) {
|
|
34
|
+
const c = a1?.concat(a2);
|
|
35
|
+
return c.filter((item, pos) => c.indexOf(item) === pos);
|
|
36
|
+
}
|
|
37
|
+
return ret;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=bundle-common.js.map
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
interface ParseOptions {
|
|
2
|
+
envMode: string;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* Minification via esbuild.
|
|
3
6
|
* When importing this module make sure the optional library 'esbuild' is installed.
|
|
4
7
|
*/
|
|
5
8
|
export declare function minifyJavascript(source: string): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Parse source to remove process.env.NODE_ENV without minify
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseJavascript(source: string, options: ParseOptions): Promise<string>;
|
|
13
|
+
export {};
|
|
6
14
|
//# sourceMappingURL=esbuild-utils.d.ts.map
|
|
@@ -2,7 +2,7 @@ import { logger } from '@lwrjs/shared-utils';
|
|
|
2
2
|
import esbuildEsm from 'esbuild';
|
|
3
3
|
// https://github.com/evanw/esbuild/issues/706
|
|
4
4
|
// Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
|
|
5
|
-
// https://github.com/salesforce-experience-platform/lwr/issues/1014
|
|
5
|
+
// https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
|
|
6
6
|
let esbuild = esbuildEsm;
|
|
7
7
|
if (!esbuildEsm) {
|
|
8
8
|
try {
|
|
@@ -31,4 +31,22 @@ export async function minifyJavascript(source) {
|
|
|
31
31
|
throw error;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse source to remove process.env.NODE_ENV without minify
|
|
36
|
+
*/
|
|
37
|
+
export async function parseJavascript(source, options) {
|
|
38
|
+
try {
|
|
39
|
+
const { code } = await esbuild.transform(source, {
|
|
40
|
+
loader: 'js',
|
|
41
|
+
minify: false,
|
|
42
|
+
// Remove assertions by tree shaking the computed expression
|
|
43
|
+
define: { 'process.env.NODE_ENV': JSON.stringify(options.envMode) },
|
|
44
|
+
});
|
|
45
|
+
return code;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
logger.debug(error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
34
52
|
//# sourceMappingURL=esbuild-utils.js.map
|
package/package.json
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.16",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/salesforce/lwr.git",
|
|
11
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
|
|
12
12
|
"directory": "packages/@lwrjs/module-registry"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/salesforce/lwr/issues"
|
|
15
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
18
|
"types": "build/es/index.d.ts",
|
|
@@ -36,19 +36,22 @@
|
|
|
36
36
|
"require": "./build/cjs/esm-bundle-provider.cjs"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -b"
|
|
41
|
+
},
|
|
39
42
|
"files": [
|
|
40
43
|
"build/**/*.js",
|
|
41
44
|
"build/**/*.cjs",
|
|
42
45
|
"build/**/*.d.ts"
|
|
43
46
|
],
|
|
44
47
|
"dependencies": {
|
|
45
|
-
"@lwrjs/shared-utils": "0.9.0-alpha.
|
|
48
|
+
"@lwrjs/shared-utils": "0.9.0-alpha.16",
|
|
46
49
|
"@rollup/plugin-replace": "^2.4.2",
|
|
47
50
|
"rollup": "~2.45.2",
|
|
48
51
|
"rollup-plugin-terser": "^7.0.2"
|
|
49
52
|
},
|
|
50
53
|
"devDependencies": {
|
|
51
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
54
|
+
"@lwrjs/types": "0.9.0-alpha.16"
|
|
52
55
|
},
|
|
53
56
|
"optionalDependencies": {
|
|
54
57
|
"esbuild": "^0.9.7"
|
|
@@ -56,5 +59,9 @@
|
|
|
56
59
|
"engines": {
|
|
57
60
|
"node": ">=14.15.4 <19"
|
|
58
61
|
},
|
|
59
|
-
"
|
|
62
|
+
"volta": {
|
|
63
|
+
"node": "14.19.1",
|
|
64
|
+
"yarn": "1.22.19"
|
|
65
|
+
},
|
|
66
|
+
"gitHead": "03fe3982780e7c63b96ef0733b58529057db61fa"
|
|
60
67
|
}
|