@lwrjs/module-bundler 0.15.0-alpha.3 → 0.15.0-alpha.30

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.
@@ -45,12 +45,14 @@ var AmdBundlerProvider = class {
45
45
  env: {NODE_ENV: envMode} = {NODE_ENV: "production"}
46
46
  } = runtimeEnvironment;
47
47
  const minified = !!minify && !debug;
48
+ let bundleCode;
48
49
  if (minified) {
49
- bundle.code = await (0, import_esbuild_utils.minifyJavascript)(bundle.code);
50
+ bundleCode = await (0, import_esbuild_utils.minifyJavascript)(await bundle.getCode());
50
51
  } else {
51
- bundle.code = await (0, import_esbuild_utils.parseJavascript)(bundle.code, {envMode});
52
+ bundleCode = await (0, import_esbuild_utils.parseJavascript)(await bundle.getCode(), {envMode});
52
53
  }
53
- bundle.integrity = (0, import_shared_utils.createIntegrityHash)(bundle.code);
54
+ bundle.integrity = (0, import_shared_utils.createIntegrityHash)(bundleCode);
55
+ bundle.getCode = () => Promise.resolve(bundleCode);
54
56
  return bundle;
55
57
  }
56
58
  }
@@ -41,7 +41,7 @@ var AmdBundlerProvider = class {
41
41
  const minified = minify && !debug;
42
42
  const bundle = await (0, import_amd_common.amdBundler)(moduleId, moduleRegistry, minified, runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
43
43
  if (bundle) {
44
- bundle.integrity = (0, import_shared_utils.createIntegrityHash)(bundle.code);
44
+ bundle.integrity = (0, import_shared_utils.createIntegrityHash)(await bundle.getCode());
45
45
  }
46
46
  return bundle;
47
47
  }
@@ -102,7 +102,7 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
102
102
  namespace,
103
103
  name,
104
104
  version,
105
- code,
105
+ getCode: () => Promise.resolve(code),
106
106
  config: {external, exclude},
107
107
  map: bundleMap,
108
108
  integrity: (0, import_shared_utils.createIntegrityHash)(code),
@@ -27,13 +27,19 @@ __export(exports, {
27
27
  LwrModuleBundler: () => LwrModuleBundler
28
28
  });
29
29
  var import_path = __toModule(require("path"));
30
+ var import_lru_cache = __toModule(require("lru-cache"));
30
31
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
31
32
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
33
  var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
33
34
  var TASK_POOL = new import_shared_utils.TaskPool();
34
35
  var LwrModuleBundler = class {
35
36
  constructor(config, globalConfig) {
36
- this.cache = new Map();
37
+ this.cache = new import_lru_cache.LRUCache({
38
+ max: parseInt(process.env.BUNDLE_CACHE_SIZE ?? "500", 10),
39
+ dispose: (_value, key) => {
40
+ import_diagnostics.logger.verbose(`Bundle evicted from cache: "${key}"`);
41
+ }
42
+ });
37
43
  this.providers = [];
38
44
  this.transformers = [];
39
45
  this.inflightBundleDefinitions = new import_shared_utils.InflightTasks();
@@ -55,12 +61,14 @@ var LwrModuleBundler = class {
55
61
  }
56
62
  async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
57
63
  const {format, minify, debug} = runtimeEnvironment;
64
+ const ssr = runtimeParams.ssr;
58
65
  const cacheKey = `${moduleId.specifier}|${moduleId.version}|${(0, import_shared_utils.getCacheKeyFromJson)({
59
66
  locale: runtimeParams.locale,
60
67
  format,
61
68
  minify,
62
69
  debug,
63
- bundleConfigOverrides
70
+ bundleConfigOverrides,
71
+ ssr
64
72
  })}`;
65
73
  const cacheDisabled = process.env.NOCACHE === "true";
66
74
  if (!cacheDisabled) {
@@ -122,7 +130,7 @@ var LwrModuleBundler = class {
122
130
  };
123
131
  for (const transformPlugin of this.transformers) {
124
132
  const resolveUriResult = await transformPlugin.transformUri?.(bundleUri, bundleDefinition, runtimeEnvironment);
125
- if (resolveUriResult && resolveUriResult.uri) {
133
+ if (resolveUriResult?.uri) {
126
134
  uri = resolveUriResult.uri;
127
135
  }
128
136
  }
@@ -210,13 +210,14 @@ async function amdBundler(rootModuleId, moduleRegistry, minify = false, runtimeE
210
210
  includedModules = cachedBundleGroupCode.includedModules;
211
211
  }
212
212
  const {id, name, namespace, version, specifier} = moduleGraphs.linkedDefinitions[rootModule.specifier];
213
+ const getCode = () => Promise.resolve(bundleCode);
213
214
  return {
214
215
  id,
215
216
  name,
216
217
  namespace,
217
218
  version,
218
219
  specifier,
219
- code: bundleCode,
220
+ getCode,
220
221
  config: {external, exclude},
221
222
  bundleRecord: {
222
223
  imports: Array.from(requiredImports.values()),
@@ -15,13 +15,16 @@ export default class AmdBundlerProvider {
15
15
  // Minification via esbuild for performance
16
16
  const { minify, debug, env: { NODE_ENV: envMode } = { NODE_ENV: 'production' }, } = runtimeEnvironment;
17
17
  const minified = !!minify && !debug;
18
+ let bundleCode;
18
19
  if (minified) {
19
- bundle.code = await minifyJavascript(bundle.code);
20
+ // TODO convert to getCode()
21
+ bundleCode = await minifyJavascript((await bundle.getCode()));
20
22
  }
21
23
  else {
22
- bundle.code = await parseJavascript(bundle.code, { envMode });
24
+ bundleCode = await parseJavascript((await bundle.getCode()), { envMode });
23
25
  }
24
- bundle.integrity = createIntegrityHash(bundle.code);
26
+ bundle.integrity = createIntegrityHash(bundleCode);
27
+ bundle.getCode = () => Promise.resolve(bundleCode);
25
28
  return bundle;
26
29
  }
27
30
  }
@@ -14,7 +14,7 @@ export default class AmdBundlerProvider {
14
14
  const bundle = await amdBundler(moduleId, moduleRegistry, minified, // will minify using rollup/terser if true - MRT runtime friendly
15
15
  runtimeEnvironment, runtimeParams, config, bundleConfigOverrides);
16
16
  if (bundle) {
17
- bundle.integrity = createIntegrityHash(bundle.code);
17
+ bundle.integrity = createIntegrityHash((await bundle.getCode()));
18
18
  }
19
19
  return bundle;
20
20
  }
@@ -76,7 +76,7 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
76
76
  namespace,
77
77
  name,
78
78
  version,
79
- code,
79
+ getCode: () => Promise.resolve(code),
80
80
  config: { external, exclude },
81
81
  map: bundleMap,
82
82
  integrity: createIntegrityHash(code),
@@ -1,4 +1,5 @@
1
1
  import type { AbstractModuleId, BundleConfig, BundleConfigOverrides, BundleDefinition, BundleProvider, LwrAppObserver, ModuleBundler, ModuleId, ModuleRegistry, NormalizedLwrGlobalConfig, PublicModuleBundler, RuntimeEnvironment, RuntimeParams, SourceMapRuntimeEnvironment, UriTransformPlugin } from '@lwrjs/types';
2
+ import { LRUCache } from 'lru-cache';
2
3
  interface LwrModuleBundlerConfig {
3
4
  moduleRegistry: ModuleRegistry;
4
5
  appObserver?: LwrAppObserver;
@@ -6,7 +7,7 @@ interface LwrModuleBundlerConfig {
6
7
  export declare class LwrModuleBundler implements ModuleBundler {
7
8
  moduleRegistry: ModuleRegistry;
8
9
  appObserver: LwrAppObserver | undefined;
9
- cache: Map<string, BundleDefinition>;
10
+ cache: LRUCache<string, BundleDefinition, unknown>;
10
11
  providers: BundleProvider[];
11
12
  transformers: UriTransformPlugin[];
12
13
  bundleConfig: BundleConfig;
@@ -19,7 +20,7 @@ export declare class LwrModuleBundler implements ModuleBundler {
19
20
  /**
20
21
  * Resolve the URI to the bundle rooted at the `moduleId`
21
22
  * @param moduleId - The id of the root module for the bundle
22
- * @param runtimeEnvironment - The runtime operating environnment
23
+ * @param runtimeEnvironment - The runtime operating environment
23
24
  * @param runtimeParams - The available runtime parameters provided in context to the request
24
25
  * @param signature - The signature of the bundle instance being referenced
25
26
  * @returns the URI
package/build/es/index.js CHANGED
@@ -1,11 +1,17 @@
1
1
  import { join } from 'path';
2
- import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
2
+ import { LRUCache } from 'lru-cache';
3
+ import { LwrUnresolvableError, createSingleDiagnosticError, descriptions, logger } from '@lwrjs/diagnostics';
3
4
  import { signBundle, getCacheKeyFromJson, InflightTasks, TaskPool } from '@lwrjs/shared-utils';
4
5
  import { getTracer, BundleSpan } from '@lwrjs/instrumentation';
5
6
  const TASK_POOL = new TaskPool();
6
7
  export class LwrModuleBundler {
7
8
  constructor(config, globalConfig) {
8
- this.cache = new Map();
9
+ this.cache = new LRUCache({
10
+ max: parseInt(process.env.BUNDLE_CACHE_SIZE ?? '500', 10),
11
+ dispose: (_value, key) => {
12
+ logger.verbose(`Bundle evicted from cache: "${key}"`);
13
+ },
14
+ });
9
15
  this.providers = [];
10
16
  this.transformers = [];
11
17
  // Pending bundle definitions are tracked to prevent concurrent resolution of the same bundle.
@@ -33,12 +39,14 @@ export class LwrModuleBundler {
33
39
  }
34
40
  async getModuleBundle(moduleId, runtimeEnvironment, runtimeParams = {}, bundleConfigOverrides) {
35
41
  const { format, minify, debug } = runtimeEnvironment;
42
+ const ssr = runtimeParams.ssr;
36
43
  const cacheKey = `${moduleId.specifier}|${moduleId.version}|${getCacheKeyFromJson({
37
44
  locale: runtimeParams.locale,
38
45
  format,
39
46
  minify,
40
47
  debug,
41
48
  bundleConfigOverrides,
49
+ ssr,
42
50
  })}`;
43
51
  const cacheDisabled = process.env.NOCACHE === 'true';
44
52
  if (!cacheDisabled) {
@@ -79,7 +87,7 @@ export class LwrModuleBundler {
79
87
  /**
80
88
  * Resolve the URI to the bundle rooted at the `moduleId`
81
89
  * @param moduleId - The id of the root module for the bundle
82
- * @param runtimeEnvironment - The runtime operating environnment
90
+ * @param runtimeEnvironment - The runtime operating environment
83
91
  * @param runtimeParams - The available runtime parameters provided in context to the request
84
92
  * @param signature - The signature of the bundle instance being referenced
85
93
  * @returns the URI
@@ -119,7 +127,7 @@ export class LwrModuleBundler {
119
127
  for (const transformPlugin of this.transformers) {
120
128
  // eslint-disable-next-line no-await-in-loop
121
129
  const resolveUriResult = await transformPlugin.transformUri?.(bundleUri, bundleDefinition, runtimeEnvironment);
122
- if (resolveUriResult && resolveUriResult.uri) {
130
+ if (resolveUriResult?.uri) {
123
131
  uri = resolveUriResult.uri;
124
132
  }
125
133
  }
@@ -225,13 +225,14 @@ export async function amdBundler(rootModuleId, moduleRegistry, minify = false, r
225
225
  includedModules = cachedBundleGroupCode.includedModules;
226
226
  }
227
227
  const { id, name, namespace, version, specifier } = moduleGraphs.linkedDefinitions[rootModule.specifier];
228
+ const getCode = () => Promise.resolve(bundleCode);
228
229
  return {
229
230
  id,
230
231
  name,
231
232
  namespace,
232
233
  version,
233
234
  specifier,
234
- code: bundleCode,
235
+ getCode,
235
236
  config: { external, exclude },
236
237
  bundleRecord: {
237
238
  imports: Array.from(requiredImports.values()),
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.15.0-alpha.3",
7
+ "version": "0.15.0-alpha.30",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -47,14 +47,15 @@
47
47
  "build/**/*.d.ts"
48
48
  ],
49
49
  "dependencies": {
50
- "@lwrjs/diagnostics": "0.15.0-alpha.3",
51
- "@lwrjs/instrumentation": "0.15.0-alpha.3",
52
- "@lwrjs/shared-utils": "0.15.0-alpha.3",
50
+ "@lwrjs/diagnostics": "0.15.0-alpha.30",
51
+ "@lwrjs/instrumentation": "0.15.0-alpha.30",
52
+ "@lwrjs/shared-utils": "0.15.0-alpha.30",
53
53
  "@rollup/plugin-replace": "^5.0.7",
54
- "rollup": "^2.78.0"
54
+ "lru-cache": "^10.4.3",
55
+ "rollup": "^2.79.2"
55
56
  },
56
57
  "devDependencies": {
57
- "@lwrjs/types": "0.15.0-alpha.3",
58
+ "@lwrjs/types": "0.15.0-alpha.30",
58
59
  "jest": "^26.6.3",
59
60
  "ts-jest": "^26.5.6"
60
61
  },
@@ -67,5 +68,5 @@
67
68
  "volta": {
68
69
  "extends": "../../../package.json"
69
70
  },
70
- "gitHead": "6dfe76aa313a8ee1cedcf33b466df48a8f1a62eb"
71
+ "gitHead": "b563560f1d3ccbb6d6bab8a8a5d7b6a8456b9c48"
71
72
  }