@lwrjs/module-bundler 0.9.0-alpha.15 → 0.9.0-alpha.17

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.
@@ -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 {minify, debug} = runtimeEnvironment;
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}, bundleConfigOverride) {
47
- const {exclude, external = {}, alias = {}} = bundleConfigOverride ?? bundleConfig;
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();
@@ -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,8 +77,25 @@ var LwrModuleBundler = class {
77
77
  }, this);
78
78
  });
79
79
  }
80
- resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
81
- return this.moduleRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature);
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;
82
99
  }
83
100
  getPublicApi() {
84
101
  return {
@@ -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,9 @@ 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}, bundleConfigOverride) {
50
- const {exclude, external} = bundleConfigOverride ?? bundleConfig;
50
+ async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, {bundleConfig, amdLoader}, bundleConfigOverrides) {
51
+ const {exclude, external = {}} = (0, import_bundle_common.overrideBundleConfig)(bundleConfig, bundleConfigOverrides);
52
+ const externalsArray = Object.keys(external);
51
53
  const requiredImports = new Map();
52
54
  const dynamicImports = new Map();
53
55
  const includedModules = [];
@@ -57,8 +59,10 @@ async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvir
57
59
  static: import_shared_utils.GraphDepth.ALL,
58
60
  dynamic: 0,
59
61
  includeId: (moduleRef) => {
60
- if (exclude?.includes(moduleRef.specifier) || moduleRef.specifier === amdLoader) {
61
- requiredImports.set(`${moduleId.specifier}_${moduleId.version}`, moduleRef);
62
+ if (externalsArray.includes(moduleRef.specifier) || moduleRef.specifier === amdLoader) {
63
+ return false;
64
+ } else if (exclude?.includes(moduleRef.specifier)) {
65
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
62
66
  return false;
63
67
  }
64
68
  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, BundleConfig, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
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?: BundleConfig): Promise<BundleDefinition | undefined>;
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, BundleConfig, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
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?: BundleConfig): Promise<BundleDefinition | undefined>;
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, BundleConfig, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
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?: BundleConfig): Promise<BundleDefinition | undefined>;
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 }, bundleConfigOverride) {
18
- const { exclude, external = {}, alias = {} } = bundleConfigOverride ?? bundleConfig;
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();
@@ -1,4 +1,4 @@
1
- import { AbstractModuleId, BundleConfig, BundleDefinition, BundleProvider, LwrAppObserver, ModuleBundler, ModuleId, ModuleRegistry, NormalizedLwrGlobalConfig, PublicModuleBundler, 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?: BundleConfig): Promise<BundleDefinition>;
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,7 @@ 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<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: R, runtimeParams?: RuntimeParams, signature?: S): S extends string ? string : Promise<string>;
24
+ resolveModuleUri(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, signature?: string): Promise<string>;
25
25
  getPublicApi(): PublicModuleBundler;
26
26
  }
27
27
  export {};
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,29 @@ 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
- // TODO: Integrate resolving from a site caches.
74
- // Fallback to resolving the URI from the registry.
75
- return this.moduleRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature);
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;
76
96
  }
77
97
  getPublicApi() {
78
98
  return {
@@ -1,3 +1,3 @@
1
- import { AbstractModuleId, BundleConfig, 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, bundleConfigOverride?: BundleConfig): Promise<BundleDefinition>;
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,9 @@ 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 }, bundleConfigOverride) {
23
- const { exclude, external } = bundleConfigOverride ?? bundleConfig;
23
+ export async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, { bundleConfig, amdLoader }, bundleConfigOverrides) {
24
+ const { exclude, external = {} } = overrideBundleConfig(bundleConfig, bundleConfigOverrides);
25
+ const externalsArray = Object.keys(external);
24
26
  const requiredImports = new Map();
25
27
  const dynamicImports = new Map();
26
28
  const includedModules = [];
@@ -30,9 +32,16 @@ export async function amdBundler(moduleId, moduleRegistry, minify = false, runti
30
32
  static: GraphDepth.ALL,
31
33
  dynamic: 0,
32
34
  includeId: (moduleRef) => {
33
- // loader should be auto bundled with shim already
34
- if (exclude?.includes(moduleRef.specifier) || moduleRef.specifier === amdLoader) {
35
- requiredImports.set(`${moduleId.specifier}_${moduleId.version}`, moduleRef);
35
+ // Do not bundle externals, including the loader module, which is auto bundled
36
+ // with the shim + loader combo
37
+ if (externalsArray.includes(moduleRef.specifier) || moduleRef.specifier === amdLoader) {
38
+ // Do not include externals in the required imports but also return false to indicate it should not be in the bundle
39
+ return false;
40
+ }
41
+ else if (exclude?.includes(moduleRef.specifier)) {
42
+ // If this is a bundle exclude return false to indicate it should not be in the bundle
43
+ // but add it to the requriedImports so it shows up as a static dependency of the bundle.
44
+ requiredImports.set(`${moduleRef.specifier}_${moduleRef.version}`, moduleRef);
36
45
  return false;
37
46
  }
38
47
  return true;
@@ -0,0 +1,3 @@
1
+ import type { BundleConfig, BundleConfigOverrides } from '@lwrjs/types';
2
+ export declare function overrideBundleConfig(bundleConfig: BundleConfig, bundleConfigOverrides?: BundleConfigOverrides): BundleConfig;
3
+ //# sourceMappingURL=bundle-common.d.ts.map
@@ -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.15",
7
+ "version": "0.9.0-alpha.17",
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.15",
48
+ "@lwrjs/shared-utils": "0.9.0-alpha.17",
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.15"
54
+ "@lwrjs/types": "0.9.0-alpha.17"
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
- "gitHead": "f32f103d2d5e516daccce1be69f68acd7b4b86fb"
62
+ "volta": {
63
+ "node": "14.19.1",
64
+ "yarn": "1.22.19"
65
+ },
66
+ "gitHead": "447417ff091802927b25cfc1bcb01da02264f41b"
60
67
  }