@lwrjs/module-bundler 0.9.0-alpha.2 → 0.9.0-alpha.21

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.
Files changed (30) hide show
  1. package/build/cjs/amd-bundle-provider.cjs +56 -0
  2. package/build/cjs/amd-runtime-bundle-provider.cjs +45 -0
  3. package/build/cjs/{esm/esm-bundler.cjs → esm-bundle-provider.cjs} +27 -6
  4. package/build/cjs/index.cjs +43 -16
  5. package/build/cjs/{amd/amd-bundler.cjs → utils/amd-common.cjs} +21 -17
  6. package/build/cjs/utils/bundle-common.cjs +44 -0
  7. package/build/cjs/utils/esbuild-utils.cjs +64 -0
  8. package/build/cjs/{amd → utils}/rollup-amd-bundler-plugin.cjs +1 -1
  9. package/build/cjs/{esm → utils}/rollup-esm-bundler-plugin.cjs +1 -1
  10. package/build/es/amd-bundle-provider.d.ts +9 -0
  11. package/build/es/amd-bundle-provider.js +27 -0
  12. package/build/es/amd-runtime-bundle-provider.d.ts +9 -0
  13. package/build/es/amd-runtime-bundle-provider.js +18 -0
  14. package/build/es/esm-bundle-provider.d.ts +9 -0
  15. package/build/es/{esm/esm-bundler.js → esm-bundle-provider.js} +25 -5
  16. package/build/es/index.d.ts +15 -5
  17. package/build/es/index.js +57 -18
  18. package/build/es/utils/amd-common.d.ts +3 -0
  19. package/build/es/{amd/amd-bundler.js → utils/amd-common.js} +27 -17
  20. package/build/es/utils/bundle-common.d.ts +3 -0
  21. package/build/es/utils/bundle-common.js +39 -0
  22. package/build/es/utils/esbuild-utils.d.ts +14 -0
  23. package/build/es/utils/esbuild-utils.js +52 -0
  24. package/build/es/{amd → utils}/rollup-amd-bundler-plugin.d.ts +0 -0
  25. package/build/es/{amd → utils}/rollup-amd-bundler-plugin.js +0 -0
  26. package/build/es/{esm → utils}/rollup-esm-bundler-plugin.d.ts +0 -0
  27. package/build/es/{esm → utils}/rollup-esm-bundler-plugin.js +0 -0
  28. package/package.json +31 -8
  29. package/build/es/amd/amd-bundler.d.ts +0 -3
  30. package/build/es/esm/esm-bundler.d.ts +0 -3
@@ -0,0 +1,56 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+
24
+ // packages/@lwrjs/module-bundler/src/amd-bundle-provider.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ default: () => amd_bundle_provider_default
28
+ });
29
+ var import_amd_common = __toModule(require("./utils/amd-common.cjs"));
30
+ var import_esbuild_utils = __toModule(require("./utils/esbuild-utils.cjs"));
31
+ var AmdBundlerProvider = class {
32
+ constructor(options, {config, moduleRegistry}) {
33
+ this.name = "amd-bundle-provider";
34
+ this.config = config;
35
+ this.moduleRegistry = moduleRegistry;
36
+ }
37
+ async bundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
38
+ if (runtimeEnvironment.format === "amd") {
39
+ const {moduleRegistry, config} = this;
40
+ const bundle = await (0, import_amd_common.amdBundler)(moduleId, moduleRegistry, false, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
41
+ const {
42
+ minify,
43
+ debug,
44
+ env: {NODE_ENV: envMode} = {NODE_ENV: "production"}
45
+ } = runtimeEnvironment;
46
+ const minified = !!minify && !debug;
47
+ if (minified) {
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});
51
+ }
52
+ return bundle;
53
+ }
54
+ }
55
+ };
56
+ var amd_bundle_provider_default = AmdBundlerProvider;
@@ -0,0 +1,45 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+
24
+ // packages/@lwrjs/module-bundler/src/amd-runtime-bundle-provider.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ default: () => amd_runtime_bundle_provider_default
28
+ });
29
+ var import_amd_common = __toModule(require("./utils/amd-common.cjs"));
30
+ var AmdBundlerProvider = class {
31
+ constructor(options, {config, moduleRegistry}) {
32
+ this.name = "amd-runtime-bundle-provider";
33
+ this.config = config;
34
+ this.moduleRegistry = moduleRegistry;
35
+ }
36
+ async bundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
37
+ if (runtimeEnvironment.format === "amd") {
38
+ const {moduleRegistry, config} = this;
39
+ const {minify, debug} = runtimeEnvironment;
40
+ const minified = minify && !debug;
41
+ return await (0, import_amd_common.amdBundler)(moduleId, moduleRegistry, minified, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
42
+ }
43
+ }
44
+ };
45
+ var amd_runtime_bundle_provider_default = AmdBundlerProvider;
@@ -21,15 +21,31 @@ var __toModule = (module2) => {
21
21
  return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
22
  };
23
23
 
24
- // packages/@lwrjs/module-bundler/src/esm/esm-bundler.ts
24
+ // packages/@lwrjs/module-bundler/src/esm-bundle-provider.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
- esmBundler: () => esmBundler
27
+ default: () => esm_bundle_provider_default
28
28
  });
29
29
  var import_rollup = __toModule(require("rollup"));
30
- var import_rollup_esm_bundler_plugin = __toModule(require("./rollup-esm-bundler-plugin.cjs"));
31
- async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, lwrConfig, bundleConfigOverride) {
32
- const {exclude, external = {}, alias = {}} = bundleConfigOverride ?? lwrConfig.bundleConfig;
30
+ var import_rollup_esm_bundler_plugin = __toModule(require("./utils/rollup-esm-bundler-plugin.cjs"));
31
+ var import_esbuild_utils = __toModule(require("./utils/esbuild-utils.cjs"));
32
+ var import_bundle_common = __toModule(require("./utils/bundle-common.cjs"));
33
+ var EsmBundlerProvider = class {
34
+ constructor(options, {config, moduleRegistry}) {
35
+ this.name = "esm-bundle-provider";
36
+ this.config = config;
37
+ this.moduleRegistry = moduleRegistry;
38
+ }
39
+ async bundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
40
+ if (runtimeEnvironment.format === "esm") {
41
+ const {moduleRegistry, config} = this;
42
+ return await esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
43
+ }
44
+ }
45
+ };
46
+ var esm_bundle_provider_default = EsmBundlerProvider;
47
+ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, {bundleConfig}, bundleConfigOverrides) {
48
+ const {exclude, external = {}, alias = {}} = (0, import_bundle_common.overrideBundleConfig)(bundleConfig, bundleConfigOverrides);
33
49
  const {sourceMapUrl} = runtimeEnvironment;
34
50
  const requiredImports = new Map();
35
51
  const dynamicImports = new Map();
@@ -58,9 +74,14 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
58
74
  });
59
75
  const bundleCode = result.output[0].code;
60
76
  const bundleMap = result.output[0].map;
61
- const code = sourceMapUrl ? `${bundleCode}
77
+ let code = sourceMapUrl ? `${bundleCode}
62
78
  //# sourceMappingURL=${sourceMapUrl}` : bundleCode;
63
79
  const {id, specifier, namespace, name, version} = rootModuleDef;
80
+ const {minify, debug} = runtimeEnvironment;
81
+ const minified = !!minify && !debug;
82
+ if (minified) {
83
+ code = await (0, import_esbuild_utils.minifyJavascript)(code);
84
+ }
64
85
  return {
65
86
  id,
66
87
  specifier,
@@ -26,24 +26,25 @@ __markAsModule(exports);
26
26
  __export(exports, {
27
27
  LwrModuleBundler: () => LwrModuleBundler
28
28
  });
29
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
29
30
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
- var import_amd_bundler = __toModule(require("./amd/amd-bundler.cjs"));
31
- var import_esm_bundler = __toModule(require("./esm/esm-bundler.cjs"));
32
31
  var TASK_POOL = new import_shared_utils.TaskPool();
33
32
  var LwrModuleBundler = class {
34
33
  constructor(config, globalConfig) {
35
34
  this.cache = new Map();
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;
40
- this.compiler = config.compiler;
39
+ this.bundleConfig = Object.freeze(globalConfig.bundleConfig);
41
40
  this.appObserver?.onModuleDefinitionChange(() => {
42
41
  this.cache.clear();
43
42
  });
44
43
  }
44
+ addBundleProviders(providers) {
45
+ this.providers.push(...providers);
46
+ }
45
47
  async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
46
- const {moduleRegistry} = this;
47
48
  const {format, minify, debug} = runtimeEnvironment;
48
49
  const cacheKey = `${moduleId.specifier}|${moduleId.version}|${(0, import_shared_utils.getCacheKeyFromJson)({
49
50
  locale: runtimeParams.locale,
@@ -61,19 +62,45 @@ var LwrModuleBundler = class {
61
62
  }
62
63
  return this.inflightBundleDefinitions.execute(cacheKey, () => {
63
64
  return TASK_POOL.execute(async () => {
64
- const pendingBundleDef = format === "amd" ? (0, import_amd_bundler.amdBundler)(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides) : (0, import_esm_bundler.esmBundler)(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides);
65
- pendingBundleDef.then(async (bundleDef) => {
66
- const minified = !!minify && !debug;
67
- if (minified) {
68
- bundleDef.code = (await this.compiler.minifyJavascript(bundleDef.code)).code;
69
- }
70
- if (!cacheDisabled) {
71
- this.cache.set(cacheKey, bundleDef);
65
+ for (const bundler of this.providers) {
66
+ const bundleDef = await bundler.bundle(moduleId, runtimeEnvironment, runtimeParams, bundleConfigOverrides);
67
+ if (bundleDef) {
68
+ if (!cacheDisabled) {
69
+ this.cache.set(cacheKey, bundleDef);
70
+ }
71
+ return bundleDef;
72
72
  }
73
- return bundleDef;
74
- });
75
- return pendingBundleDef;
73
+ }
74
+ throw (0, import_diagnostics.createSingleDiagnosticError)({
75
+ description: import_diagnostics.descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier)
76
+ }, import_diagnostics.LwrUnresolvableError);
76
77
  }, this);
77
78
  });
78
79
  }
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
+ };
105
+ }
79
106
  };
@@ -21,33 +21,35 @@ var __toModule = (module2) => {
21
21
  return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
22
  };
23
23
 
24
- // packages/@lwrjs/module-bundler/src/amd/amd-bundler.ts
24
+ // packages/@lwrjs/module-bundler/src/utils/amd-common.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  amdBundler: () => amdBundler
28
28
  });
29
- var import_compiler = __toModule(require("@lwrjs/compiler"));
30
29
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
30
  var import_rollup = __toModule(require("rollup"));
31
+ var import_plugin_replace = __toModule(require("@rollup/plugin-replace"));
32
+ var import_rollup_plugin_terser = __toModule(require("rollup-plugin-terser"));
32
33
  var import_rollup_amd_bundler_plugin = __toModule(require("./rollup-amd-bundler-plugin.cjs"));
33
- async function bundle(id, moduleGraphs) {
34
- const bundler = await (0, import_rollup.rollup)({
35
- input: id,
36
- plugins: [
37
- (0, import_rollup_amd_bundler_plugin.bundleDefinitions)({
38
- moduleGraphs
39
- })
40
- ]
41
- });
34
+ var import_bundle_common = __toModule(require("./bundle-common.cjs"));
35
+ var AMD_DEFINE = "LWR.define";
36
+ async function bundle(id, moduleGraphs, minify = false) {
37
+ const plugins = [(0, import_rollup_amd_bundler_plugin.bundleDefinitions)({moduleGraphs})];
38
+ minify && plugins.push((0, import_rollup_plugin_terser.terser)(), (0, import_plugin_replace.default)({
39
+ "process.env.NODE_ENV": JSON.stringify("production"),
40
+ preventAssignment: false
41
+ }));
42
+ const bundler = await (0, import_rollup.rollup)({input: id, plugins});
42
43
  const {output} = await bundler.generate({
43
- amd: {id, define: import_compiler.AMD_DEFINE},
44
+ amd: {id, define: AMD_DEFINE},
44
45
  exports: "named",
45
46
  format: "amd"
46
47
  });
47
48
  return output[0].code;
48
49
  }
49
- async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, {bundleConfig, amdLoader}, bundleConfigOverride) {
50
- const {exclude, external} = bundleConfigOverride ?? bundleConfig;
50
+ async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, {bundleConfig}, 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, runtimeEnvironment, runtimeP
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)) {
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;
@@ -88,7 +92,7 @@ async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
88
92
  if (id2 !== rootModule.specifier) {
89
93
  includedModules.push(id2);
90
94
  }
91
- return bundle(id2, moduleGraphs);
95
+ return bundle(id2, moduleGraphs, minify);
92
96
  }));
93
97
  const {id, name, namespace, version, specifier} = moduleGraphs.linkedDefinitions[rootModule.specifier];
94
98
  return {
@@ -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
+ }
@@ -0,0 +1,64 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __exportStar = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+
24
+ // packages/@lwrjs/module-bundler/src/utils/esbuild-utils.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ minifyJavascript: () => minifyJavascript,
28
+ parseJavascript: () => parseJavascript
29
+ });
30
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
+ var import_esbuild = __toModule(require("esbuild"));
32
+ var esbuild = import_esbuild.default;
33
+ if (!import_esbuild.default) {
34
+ try {
35
+ esbuild = require("esbuild");
36
+ } catch {
37
+ }
38
+ }
39
+ async function minifyJavascript(source) {
40
+ try {
41
+ const {code} = await esbuild.transform(source, {
42
+ loader: "js",
43
+ minify: true,
44
+ define: {"process.env.NODE_ENV": JSON.stringify("production")}
45
+ });
46
+ return code;
47
+ } catch (error) {
48
+ import_shared_utils.logger.debug(error);
49
+ throw error;
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
+ }
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  __defProp(target, name, {get: all[name], enumerable: true});
6
6
  };
7
7
 
8
- // packages/@lwrjs/module-bundler/src/amd/rollup-amd-bundler-plugin.ts
8
+ // packages/@lwrjs/module-bundler/src/utils/rollup-amd-bundler-plugin.ts
9
9
  __markAsModule(exports);
10
10
  __export(exports, {
11
11
  bundleDefinitions: () => bundleDefinitions
@@ -21,7 +21,7 @@ var __toModule = (module2) => {
21
21
  return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
22
  };
23
23
 
24
- // packages/@lwrjs/module-bundler/src/esm/rollup-esm-bundler-plugin.ts
24
+ // packages/@lwrjs/module-bundler/src/utils/rollup-esm-bundler-plugin.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  bundleDefinitions: () => bundleDefinitions
@@ -0,0 +1,9 @@
1
+ import { AbstractModuleId, BundleConfigOverrides, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
+ export default class AmdBundlerProvider implements BundleProvider {
3
+ name: string;
4
+ config: ProviderAppConfig;
5
+ moduleRegistry: PublicModuleRegistry;
6
+ constructor(options: {}, { config, moduleRegistry }: ProviderContext);
7
+ bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition | undefined>;
8
+ }
9
+ //# sourceMappingURL=amd-bundle-provider.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { amdBundler } from './utils/amd-common.js';
2
+ import { minifyJavascript, parseJavascript } from './utils/esbuild-utils.js';
3
+ export default class AmdBundlerProvider {
4
+ constructor(options, { config, moduleRegistry }) {
5
+ this.name = 'amd-bundle-provider';
6
+ this.config = config;
7
+ this.moduleRegistry = moduleRegistry;
8
+ }
9
+ async bundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
10
+ if (runtimeEnvironment.format === 'amd') {
11
+ const { moduleRegistry, config } = this;
12
+ const bundle = await amdBundler(moduleId, moduleRegistry, false, // we NEVER want to minify via rollup/terser with this bundler; it's too slow
13
+ runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
14
+ // Minification via esbuild for performance
15
+ const { minify, debug, env: { NODE_ENV: envMode } = { NODE_ENV: 'production' }, } = runtimeEnvironment;
16
+ const minified = !!minify && !debug;
17
+ if (minified) {
18
+ bundle.code = await minifyJavascript(bundle.code);
19
+ }
20
+ else {
21
+ bundle.code = await parseJavascript(bundle.code, { envMode });
22
+ }
23
+ return bundle;
24
+ }
25
+ }
26
+ }
27
+ //# sourceMappingURL=amd-bundle-provider.js.map
@@ -0,0 +1,9 @@
1
+ import { AbstractModuleId, BundleConfigOverrides, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
+ export default class AmdBundlerProvider implements BundleProvider {
3
+ name: string;
4
+ config: ProviderAppConfig;
5
+ moduleRegistry: PublicModuleRegistry;
6
+ constructor(options: {}, { config, moduleRegistry }: ProviderContext);
7
+ bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition | undefined>;
8
+ }
9
+ //# sourceMappingURL=amd-runtime-bundle-provider.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { amdBundler } from './utils/amd-common.js';
2
+ export default class AmdBundlerProvider {
3
+ constructor(options, { config, moduleRegistry }) {
4
+ this.name = 'amd-runtime-bundle-provider';
5
+ this.config = config;
6
+ this.moduleRegistry = moduleRegistry;
7
+ }
8
+ async bundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
9
+ if (runtimeEnvironment.format === 'amd') {
10
+ const { moduleRegistry, config } = this;
11
+ const { minify, debug } = runtimeEnvironment;
12
+ const minified = minify && !debug;
13
+ return await amdBundler(moduleId, moduleRegistry, minified, // will minify using rollup/terser if true - MRT runtime friendly
14
+ runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
15
+ }
16
+ }
17
+ }
18
+ //# sourceMappingURL=amd-runtime-bundle-provider.js.map
@@ -0,0 +1,9 @@
1
+ import type { AbstractModuleId, BundleConfigOverrides, BundleDefinition, BundleProvider, ProviderAppConfig, ProviderContext, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
+ export default class EsmBundlerProvider implements BundleProvider {
3
+ name: string;
4
+ config: ProviderAppConfig;
5
+ moduleRegistry: PublicModuleRegistry;
6
+ constructor(options: {}, { config, moduleRegistry }: ProviderContext);
7
+ bundle<T extends AbstractModuleId, R extends RuntimeEnvironment>(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition | undefined>;
8
+ }
9
+ //# sourceMappingURL=esm-bundle-provider.d.ts.map
@@ -1,7 +1,22 @@
1
1
  import { rollup } from 'rollup';
2
- import { bundleDefinitions } from './rollup-esm-bundler-plugin.js';
3
- export async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, lwrConfig, bundleConfigOverride) {
4
- const { exclude, external = {}, alias = {} } = bundleConfigOverride ?? lwrConfig.bundleConfig;
2
+ import { bundleDefinitions } from './utils/rollup-esm-bundler-plugin.js';
3
+ import { minifyJavascript } from './utils/esbuild-utils.js';
4
+ import { overrideBundleConfig } from './utils/bundle-common.js';
5
+ export default class EsmBundlerProvider {
6
+ constructor(options, { config, moduleRegistry }) {
7
+ this.name = 'esm-bundle-provider';
8
+ this.config = config;
9
+ this.moduleRegistry = moduleRegistry;
10
+ }
11
+ async bundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
12
+ if (runtimeEnvironment.format === 'esm') {
13
+ const { moduleRegistry, config } = this;
14
+ return await esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
15
+ }
16
+ }
17
+ }
18
+ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, { bundleConfig }, bundleConfigOverrides) {
19
+ const { exclude, external = {}, alias = {} } = overrideBundleConfig(bundleConfig, bundleConfigOverrides);
5
20
  const { sourceMapUrl } = runtimeEnvironment;
6
21
  const requiredImports = new Map();
7
22
  const dynamicImports = new Map();
@@ -32,8 +47,13 @@ export async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, r
32
47
  });
33
48
  const bundleCode = result.output[0].code;
34
49
  const bundleMap = result.output[0].map;
35
- const code = sourceMapUrl ? `${bundleCode}\n//# sourceMappingURL=${sourceMapUrl}` : bundleCode;
50
+ let code = sourceMapUrl ? `${bundleCode}\n//# sourceMappingURL=${sourceMapUrl}` : bundleCode;
36
51
  const { id, specifier, namespace, name, version } = rootModuleDef;
52
+ const { minify, debug } = runtimeEnvironment;
53
+ const minified = !!minify && !debug;
54
+ if (minified) {
55
+ code = await minifyJavascript(code);
56
+ }
37
57
  return {
38
58
  id,
39
59
  specifier,
@@ -50,4 +70,4 @@ export async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, r
50
70
  },
51
71
  };
52
72
  }
53
- //# sourceMappingURL=esm-bundler.js.map
73
+ //# sourceMappingURL=esm-bundle-provider.js.map
@@ -1,18 +1,28 @@
1
- import { AbstractModuleId, BundleConfig, BundleDefinition, LwrAppObserver, ModuleBundler, ModuleRegistry, NormalizedLwrGlobalConfig, RuntimeParams, SourceMapRuntimeEnvironment, Compiler } 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
- compiler: Compiler;
4
3
  moduleRegistry: ModuleRegistry;
5
4
  appObserver?: LwrAppObserver;
6
5
  }
7
6
  export declare class LwrModuleBundler implements ModuleBundler {
8
- compiler: Compiler;
9
7
  moduleRegistry: ModuleRegistry;
10
8
  appObserver: LwrAppObserver | undefined;
11
- config: NormalizedLwrGlobalConfig;
12
9
  cache: Map<string, BundleDefinition>;
10
+ providers: BundleProvider[];
11
+ bundleConfig: BundleConfig;
13
12
  private inflightBundleDefinitions;
14
13
  constructor(config: LwrModuleBundlerConfig, globalConfig: NormalizedLwrGlobalConfig);
15
- getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfig): Promise<BundleDefinition>;
14
+ addBundleProviders(providers: BundleProvider[]): void;
15
+ getModuleBundle<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition>;
16
+ /**
17
+ * Resolve the URI to the bundle rooted at the `moduleId`
18
+ * @param moduleId - The id of the root module for the bundle
19
+ * @param runtimeEnvironment - The runtime operating environnment
20
+ * @param runtimeParams - The available runtime parameters provided in context to the request
21
+ * @param signature - The signature of the bundle instance being referenced
22
+ * @returns the URI
23
+ */
24
+ resolveModuleUri(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, signature?: string): Promise<string>;
25
+ getPublicApi(): PublicModuleBundler;
16
26
  }
17
27
  export {};
18
28
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -1,26 +1,28 @@
1
+ import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
1
2
  import { getCacheKeyFromJson, InflightTasks, TaskPool } from '@lwrjs/shared-utils';
2
- import { amdBundler } from './amd/amd-bundler.js';
3
- import { esmBundler } from './esm/esm-bundler.js';
4
3
  const TASK_POOL = new TaskPool();
5
4
  export class LwrModuleBundler {
6
5
  constructor(config, globalConfig) {
7
6
  this.cache = new Map();
7
+ this.providers = [];
8
8
  // Pending bundle definitions are tracked to prevent concurrent resolution of the same bundle.
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;
15
- this.compiler = config.compiler;
14
+ // Freeze the bundle config to make sure it is not modified
15
+ this.bundleConfig = Object.freeze(globalConfig.bundleConfig);
16
16
  this.appObserver?.onModuleDefinitionChange(() => {
17
17
  // TODO: This is a very naive approach however
18
18
  // this would only happen in non-prod environments
19
19
  this.cache.clear();
20
20
  });
21
21
  }
22
+ addBundleProviders(providers) {
23
+ this.providers.push(...providers);
24
+ }
22
25
  async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
23
- const { moduleRegistry } = this;
24
26
  const { format, minify, debug } = runtimeEnvironment;
25
27
  const cacheKey = `${moduleId.specifier}|${moduleId.version}|${getCacheKeyFromJson({
26
28
  locale: runtimeParams.locale,
@@ -44,22 +46,59 @@ export class LwrModuleBundler {
44
46
  // console.log('[INFO] Create Bundle: ', cacheKey);
45
47
  // Run theses tasks in a task pool to throttle parallel requests.
46
48
  return TASK_POOL.execute(async () => {
47
- const pendingBundleDef = format === 'amd'
48
- ? amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides)
49
- : esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams, this.config, bundleConfigOverrides);
50
- pendingBundleDef.then(async (bundleDef) => {
51
- const minified = !!minify && !debug;
52
- if (minified) {
53
- bundleDef.code = (await this.compiler.minifyJavascript(bundleDef.code)).code;
54
- }
55
- if (!cacheDisabled) {
56
- this.cache.set(cacheKey, bundleDef);
49
+ for (const bundler of this.providers) {
50
+ // eslint-disable-next-line no-await-in-loop
51
+ const bundleDef = await bundler.bundle(moduleId, runtimeEnvironment, runtimeParams, bundleConfigOverrides);
52
+ if (bundleDef) {
53
+ if (!cacheDisabled) {
54
+ this.cache.set(cacheKey, bundleDef);
55
+ }
56
+ return bundleDef;
57
57
  }
58
- return bundleDef;
59
- });
60
- return pendingBundleDef;
58
+ }
59
+ throw createSingleDiagnosticError({
60
+ description: descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier),
61
+ }, LwrUnresolvableError);
61
62
  }, this);
62
63
  });
63
64
  }
65
+ /**
66
+ * Resolve the URI to the bundle rooted at the `moduleId`
67
+ * @param moduleId - The id of the root module for the bundle
68
+ * @param runtimeEnvironment - The runtime operating environnment
69
+ * @param runtimeParams - The available runtime parameters provided in context to the request
70
+ * @param signature - The signature of the bundle instance being referenced
71
+ * @returns the URI
72
+ */
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
+ };
102
+ }
64
103
  }
65
104
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
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 }: ProviderAppConfig, bundleConfigOverrides?: BundleConfigOverrides): Promise<BundleDefinition>;
3
+ //# sourceMappingURL=amd-common.d.ts.map
@@ -1,16 +1,18 @@
1
- import { AMD_DEFINE } from '@lwrjs/compiler';
2
1
  import { GraphDepth, getModuleGraphs, getSpecifier } from '@lwrjs/shared-utils';
3
2
  import { rollup } from 'rollup';
3
+ import replace from '@rollup/plugin-replace';
4
+ import { terser } from 'rollup-plugin-terser';
4
5
  import { bundleDefinitions } from './rollup-amd-bundler-plugin.js';
5
- async function bundle(id, moduleGraphs) {
6
- const bundler = await rollup({
7
- input: id,
8
- plugins: [
9
- bundleDefinitions({
10
- moduleGraphs,
11
- }),
12
- ],
13
- });
6
+ import { overrideBundleConfig } from './bundle-common.js';
7
+ const AMD_DEFINE = 'LWR.define';
8
+ async function bundle(id, moduleGraphs, minify = false) {
9
+ const plugins = [bundleDefinitions({ moduleGraphs })];
10
+ minify &&
11
+ plugins.push(terser(), replace({
12
+ 'process.env.NODE_ENV': JSON.stringify('production'),
13
+ preventAssignment: false,
14
+ }));
15
+ const bundler = await rollup({ input: id, plugins });
14
16
  const { output } = await bundler.generate({
15
17
  amd: { id, define: AMD_DEFINE },
16
18
  exports: 'named',
@@ -18,8 +20,9 @@ async function bundle(id, moduleGraphs) {
18
20
  });
19
21
  return output[0].code;
20
22
  }
21
- export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams = {}, { bundleConfig, amdLoader }, bundleConfigOverride) {
22
- const { exclude, external } = bundleConfigOverride ?? bundleConfig;
23
+ export async function amdBundler(moduleId, moduleRegistry, minify = false, runtimeEnvironment, runtimeParams = {}, { bundleConfig }, bundleConfigOverrides) {
24
+ const { exclude, external = {} } = overrideBundleConfig(bundleConfig, bundleConfigOverrides);
25
+ const externalsArray = Object.keys(external);
23
26
  const requiredImports = new Map();
24
27
  const dynamicImports = new Map();
25
28
  const includedModules = [];
@@ -29,9 +32,16 @@ export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, r
29
32
  static: GraphDepth.ALL,
30
33
  dynamic: 0,
31
34
  includeId: (moduleRef) => {
32
- // loader should be auto bundled with shim already
33
- if (exclude?.includes(moduleRef.specifier) || moduleRef.specifier === amdLoader) {
34
- 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)) {
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);
35
45
  return false;
36
46
  }
37
47
  return true;
@@ -68,7 +78,7 @@ export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, r
68
78
  includedModules.push(id);
69
79
  }
70
80
  // bundle all dependencies for the linked definition and convert to AMD
71
- return bundle(id, moduleGraphs);
81
+ return bundle(id, moduleGraphs, minify);
72
82
  }));
73
83
  const { id, name, namespace, version, specifier } = moduleGraphs.linkedDefinitions[rootModule.specifier];
74
84
  return {
@@ -86,4 +96,4 @@ export async function amdBundler(moduleId, moduleRegistry, runtimeEnvironment, r
86
96
  },
87
97
  };
88
98
  }
89
- //# sourceMappingURL=amd-bundler.js.map
99
+ //# sourceMappingURL=amd-common.js.map
@@ -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
@@ -0,0 +1,14 @@
1
+ interface ParseOptions {
2
+ envMode: string;
3
+ }
4
+ /**
5
+ * Minification via esbuild.
6
+ * When importing this module make sure the optional library 'esbuild' is installed.
7
+ */
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 {};
14
+ //# sourceMappingURL=esbuild-utils.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { logger } from '@lwrjs/shared-utils';
2
+ import esbuildEsm from 'esbuild';
3
+ // https://github.com/evanw/esbuild/issues/706
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-emu/lwr/issues/1014
6
+ let esbuild = esbuildEsm;
7
+ if (!esbuildEsm) {
8
+ try {
9
+ esbuild = require('esbuild');
10
+ }
11
+ catch {
12
+ /* this is to support mjs/cjs dual impl */
13
+ }
14
+ }
15
+ /**
16
+ * Minification via esbuild.
17
+ * When importing this module make sure the optional library 'esbuild' is installed.
18
+ */
19
+ export async function minifyJavascript(source) {
20
+ try {
21
+ const { code } = await esbuild.transform(source, {
22
+ loader: 'js',
23
+ minify: true,
24
+ // Remove assertions by tree shaking the computed expression
25
+ define: { 'process.env.NODE_ENV': JSON.stringify('production') },
26
+ });
27
+ return code;
28
+ }
29
+ catch (error) {
30
+ logger.debug(error);
31
+ throw error;
32
+ }
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
+ }
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.2",
7
+ "version": "0.9.0-alpha.21",
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",
@@ -22,23 +22,46 @@
22
22
  ".": {
23
23
  "import": "./build/es/index.js",
24
24
  "require": "./build/cjs/index.cjs"
25
+ },
26
+ "./amd-bundle-provider": {
27
+ "import": "./build/es/amd-bundle-provider.js",
28
+ "require": "./build/cjs/amd-bundle-provider.cjs"
29
+ },
30
+ "./amd-runtime-bundle-provider": {
31
+ "import": "./build/es/amd-runtime-bundle-provider.js",
32
+ "require": "./build/cjs/amd-runtime-bundle-provider.cjs"
33
+ },
34
+ "./esm-bundle-provider": {
35
+ "import": "./build/es/esm-bundle-provider.js",
36
+ "require": "./build/cjs/esm-bundle-provider.cjs"
25
37
  }
26
38
  },
39
+ "scripts": {
40
+ "build": "tsc -b"
41
+ },
27
42
  "files": [
28
43
  "build/**/*.js",
29
44
  "build/**/*.cjs",
30
45
  "build/**/*.d.ts"
31
46
  ],
32
47
  "dependencies": {
33
- "@lwrjs/compiler": "0.9.0-alpha.2",
34
- "@lwrjs/shared-utils": "0.9.0-alpha.2",
35
- "rollup": "~2.45.2"
48
+ "@lwrjs/shared-utils": "0.9.0-alpha.21",
49
+ "@rollup/plugin-replace": "^2.4.2",
50
+ "rollup": "~2.45.2",
51
+ "rollup-plugin-terser": "^7.0.2"
36
52
  },
37
53
  "devDependencies": {
38
- "@lwrjs/types": "0.9.0-alpha.2"
54
+ "@lwrjs/types": "0.9.0-alpha.21"
55
+ },
56
+ "optionalDependencies": {
57
+ "esbuild": "^0.9.7"
39
58
  },
40
59
  "engines": {
41
60
  "node": ">=14.15.4 <19"
42
61
  },
43
- "gitHead": "bcf63de23d1a2a53fb0e961dba4396e8753710dd"
62
+ "volta": {
63
+ "node": "14.19.1",
64
+ "yarn": "1.22.19"
65
+ },
66
+ "gitHead": "a89adcac80601f657becd6fd734c765e6b2a2745"
44
67
  }
@@ -1,3 +0,0 @@
1
- import { AbstractModuleId, BundleConfig, BundleDefinition, ModuleRegistry, NormalizedLwrGlobalConfig, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
- export declare function amdBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams | undefined, { bundleConfig, amdLoader }: NormalizedLwrGlobalConfig, bundleConfigOverride?: BundleConfig): Promise<BundleDefinition>;
3
- //# sourceMappingURL=amd-bundler.d.ts.map
@@ -1,3 +0,0 @@
1
- import { AbstractModuleId, ModuleRegistry, BundleDefinition, RuntimeParams, SourceMapRuntimeEnvironment, BundleConfig, NormalizedLwrGlobalConfig } from '@lwrjs/types';
2
- export declare function esmBundler(moduleId: AbstractModuleId, moduleRegistry: ModuleRegistry, runtimeEnvironment: SourceMapRuntimeEnvironment, runtimeParams: RuntimeParams | undefined, lwrConfig: NormalizedLwrGlobalConfig, bundleConfigOverride?: BundleConfig): Promise<BundleDefinition>;
3
- //# sourceMappingURL=esm-bundler.d.ts.map