@lwrjs/static 0.17.2-alpha.3 → 0.17.2-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.
@@ -60,26 +60,45 @@ var StaticBundleProvider = class {
60
60
  }
61
61
  }
62
62
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
63
- const {specifier, name, namespace, version} = moduleId;
63
+ const {specifier, version} = moduleId;
64
64
  const {
65
- debug,
66
65
  i18n: {defaultLocale}
67
66
  } = runtimeEnvironment;
68
67
  const localeId = runtimeParams?.locale || defaultLocale;
69
68
  const ssr = runtimeParams?.ssr;
70
- const metadata = this.getBundleMetadata({moduleId, localeId, debug, ssr});
69
+ let debug = runtimeEnvironment.debug;
70
+ let metadata = this.getBundleMetadata({moduleId, localeId, debug, ssr});
71
+ if (!metadata && debug) {
72
+ metadata = this.getBundleMetadata({moduleId, localeId, debug: false, ssr});
73
+ if (metadata)
74
+ debug = false;
75
+ }
76
+ if (!metadata && (0, import_shared_utils.isExternalSpecifier)(moduleId.specifier, this.bundleConfig)) {
77
+ const {specifier: unversionedSepcifier} = (0, import_shared_utils.explodeSpecifier)(moduleId.specifier);
78
+ metadata = {
79
+ path: this.bundleConfig?.external?.[unversionedSepcifier],
80
+ imports: [],
81
+ dynamicImports: [],
82
+ version: moduleId.version
83
+ };
84
+ return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, async () => "", (0, import_shared_utils.normalizeFromFileURL)(metadata.path, this.siteRootDir) ?? metadata.path);
85
+ }
71
86
  if (!metadata) {
87
+ this.logBundleError(moduleId, localeId, debug, ssr);
72
88
  return void 0;
73
89
  }
74
90
  const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
75
- const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
76
- const codePromiser = this.getCodePromiser(resolvedBundlePath, {
91
+ const codePromiser = this.getCodePromiser(bundlePath, {
77
92
  specifier,
78
93
  version,
79
94
  locale: localeId,
80
95
  ssr,
81
96
  debug
82
97
  });
98
+ return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath);
99
+ }
100
+ async createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath) {
101
+ const {specifier, name, namespace, version} = moduleId;
83
102
  const imports = metadata.imports.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
84
103
  const dynamicImports = metadata.dynamicImports?.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
85
104
  const id = (0, import_shared_utils.getSpecifier)(moduleId);
@@ -179,26 +198,29 @@ var StaticBundleProvider = class {
179
198
  return code;
180
199
  };
181
200
  }
182
- getCodePath(bundlePath, debug, specifier, version, localeId, ssr) {
183
- const isLambda = (0, import_shared_utils.isLambdaEnv)();
184
- let bundleSourcePath = bundlePath;
185
- if (debug && isLambda) {
186
- const metadata = this.getBundleMetadata({
187
- moduleId: {specifier, version},
201
+ logBundleError(moduleId, localeId, debug, ssr) {
202
+ const moduleSpecifier = moduleId.namespace ? `${moduleId.namespace}/${moduleId.name}` : moduleId.name;
203
+ const siteBundleId = (0, import_site_metadata.getSiteBundleId)(moduleId, localeId, ssr, this.i18n);
204
+ const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
205
+ const siteDebugBundles = this.siteMetadata.getDebugSiteBundles()?.bundles || {};
206
+ const runtimeBundles = Object.keys(siteBundles).filter((key) => key.startsWith(moduleSpecifier));
207
+ const debugBundles = Object.keys(siteDebugBundles).filter((key) => key.startsWith(moduleSpecifier));
208
+ import_diagnostics.logger.error({
209
+ message: JSON.stringify({
210
+ message: "Failed to find static bundle",
211
+ moduleId,
188
212
  localeId,
189
- debug: false,
190
- ssr
191
- });
192
- if (!metadata) {
193
- import_diagnostics.logger.error({
194
- label: "static-bundle-provider",
195
- message: `Unexpected code reference: ${specifier}`
196
- });
197
- return BUNDLE_SOURCE_NOT_FOUND;
198
- }
199
- bundleSourcePath = import_path.default.join(this.siteRootDir, metadata.path);
200
- }
201
- return bundleSourcePath;
213
+ debug,
214
+ ssr,
215
+ moduleSpecifier,
216
+ siteBundleId,
217
+ debugBundles,
218
+ runtimeBundles,
219
+ totalBundlesCount: Object.keys(siteBundles).length,
220
+ totalDebugBundlesCount: Object.keys(siteDebugBundles).length
221
+ }),
222
+ label: "static-bundle-provider"
223
+ });
202
224
  }
203
225
  };
204
226
  var static_bundle_provider_default = StaticBundleProvider;
@@ -43,7 +43,7 @@ function mrtStaticUriTransformer() {
43
43
  };
44
44
  }
45
45
  let basePathlessUri = uriDef.uri;
46
- if (runtimeEnvironment?.basePath) {
46
+ if (runtimeEnvironment?.basePath && uriDef.uri.startsWith(runtimeEnvironment?.basePath)) {
47
47
  basePathlessUri = uriDef.uri.replace(runtimeEnvironment?.basePath, "");
48
48
  }
49
49
  const uri = (0, import_shared_utils.getMrtArtifactUrl)(runtimeEnvironment?.basePath || "", basePathlessUri);
@@ -12,6 +12,7 @@ export default class StaticBundleProvider implements BundleProvider {
12
12
  bundleCacheSize?: number;
13
13
  }, context: ProviderContext);
14
14
  bundle<BundleIdentifier extends AbstractModuleId, RE extends RuntimeEnvironment>(moduleId: BundleIdentifier, runtimeEnvironment: RE, runtimeParams: RuntimeParams): Promise<BundleDefinition | undefined>;
15
+ private createBundleDefinition;
15
16
  getBundleMetadata({ moduleId, localeId, debug, ssr, }: {
16
17
  moduleId: Partial<AbstractModuleId>;
17
18
  localeId: string;
@@ -30,16 +31,17 @@ export default class StaticBundleProvider implements BundleProvider {
30
31
  debug: boolean;
31
32
  }): () => Promise<string>;
32
33
  /**
33
- * Get the local source code path for the a static bundle
34
- * If we are running in a lambda and the mode is debug we will return the prod source code instead of the debug source code
34
+ * Logs an error when a bundle fails to load and provides debugging metadata.
35
35
  *
36
- * @param bundlePath The default path for the bundle for prod read from .metadata/bundle-metadata.json, for debug .metadata/bundle-metadata-debug.json
37
- * @param debug Is the request in debug mode?
38
- * @param specifier Root specifier for the requested bundle
39
- * @param version Root specifier version
40
- * @param localeId Locale id (e.g. en-US) for the current request
41
- * @param ssr True if this is a server bundle
36
+ * This function logs details about the failed bundle load attempt, including the module ID,
37
+ * locale, debug mode, and SSR status. It also attempts to retrieve additional metadata
38
+ * about the site bundles and debug bundles associated with the module.
39
+ *
40
+ * @param {Partial<AbstractModuleId>} moduleId - The module identifier, which may include a namespace and name.
41
+ * @param {string} localeId - The locale associated with the bundle.
42
+ * @param {boolean} debug - Indicates whether debug mode is enabled.
43
+ * @param {boolean} ssr - Indicates whether the bundle is for server-side rendering (SSR).
42
44
  */
43
- getCodePath(bundlePath: string, debug: boolean, specifier: string, version: string | undefined, localeId: string, ssr: boolean): string;
45
+ logBundleError(moduleId: Partial<AbstractModuleId>, localeId: string, debug: boolean, ssr: boolean): void;
44
46
  }
45
47
  //# sourceMappingURL=static-bundle-provider.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { logger } from '@lwrjs/diagnostics';
2
- import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isLambdaEnv } from '@lwrjs/shared-utils';
2
+ import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isExternalSpecifier, isLambdaEnv, normalizeFromFileURL, } from '@lwrjs/shared-utils';
3
3
  import path from 'path';
4
4
  import fs from 'fs-extra';
5
5
  import { LRUCache } from 'lru-cache';
@@ -34,25 +34,48 @@ export default class StaticBundleProvider {
34
34
  }
35
35
  }
36
36
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
37
- const { specifier, name, namespace, version } = moduleId;
38
- const { debug, i18n: { defaultLocale }, } = runtimeEnvironment;
37
+ const { specifier, version } = moduleId;
38
+ const { i18n: { defaultLocale }, } = runtimeEnvironment;
39
39
  const localeId = (runtimeParams?.locale || defaultLocale);
40
40
  const ssr = runtimeParams?.ssr;
41
- const metadata = this.getBundleMetadata({ moduleId, localeId, debug, ssr });
41
+ let debug = runtimeEnvironment.debug;
42
+ let metadata = this.getBundleMetadata({ moduleId, localeId, debug, ssr });
43
+ if (!metadata && debug) {
44
+ // Fallback to use prod bundles if the debug variant does not exist
45
+ // eg: debug bundles are not shipped to the Lambda
46
+ // eg: locally, an MRT bundle may or may not have debug metadata, depending on how it's generated
47
+ metadata = this.getBundleMetadata({ moduleId, localeId, debug: false, ssr });
48
+ if (metadata)
49
+ debug = false;
50
+ }
51
+ if (!metadata && isExternalSpecifier(moduleId.specifier, this.bundleConfig)) {
52
+ const { specifier: unversionedSepcifier } = explodeSpecifier(moduleId.specifier);
53
+ metadata = {
54
+ path: this.bundleConfig?.external?.[unversionedSepcifier],
55
+ imports: [],
56
+ dynamicImports: [],
57
+ version: moduleId.version,
58
+ };
59
+ return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, async () => '', normalizeFromFileURL(metadata.path, this.siteRootDir) ?? metadata.path);
60
+ }
42
61
  if (!metadata) {
62
+ this.logBundleError(moduleId, localeId, debug, ssr);
43
63
  return undefined;
44
64
  }
45
65
  // Default bundle source path
46
66
  const bundlePath = path.join(this.siteRootDir, metadata.path);
47
67
  // Get the associated bundle source code
48
- const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
49
- const codePromiser = this.getCodePromiser(resolvedBundlePath, {
68
+ const codePromiser = this.getCodePromiser(bundlePath, {
50
69
  specifier,
51
70
  version,
52
71
  locale: localeId,
53
72
  ssr,
54
73
  debug,
55
74
  });
75
+ return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath);
76
+ }
77
+ async createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath) {
78
+ const { specifier, name, namespace, version } = moduleId;
56
79
  const imports = metadata.imports.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
57
80
  const dynamicImports = metadata.dynamicImports?.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
58
81
  const id = getSpecifier(moduleId);
@@ -155,42 +178,44 @@ export default class StaticBundleProvider {
155
178
  };
156
179
  }
157
180
  /**
158
- * Get the local source code path for the a static bundle
159
- * If we are running in a lambda and the mode is debug we will return the prod source code instead of the debug source code
181
+ * Logs an error when a bundle fails to load and provides debugging metadata.
182
+ *
183
+ * This function logs details about the failed bundle load attempt, including the module ID,
184
+ * locale, debug mode, and SSR status. It also attempts to retrieve additional metadata
185
+ * about the site bundles and debug bundles associated with the module.
160
186
  *
161
- * @param bundlePath The default path for the bundle for prod read from .metadata/bundle-metadata.json, for debug .metadata/bundle-metadata-debug.json
162
- * @param debug Is the request in debug mode?
163
- * @param specifier Root specifier for the requested bundle
164
- * @param version Root specifier version
165
- * @param localeId Locale id (e.g. en-US) for the current request
166
- * @param ssr True if this is a server bundle
187
+ * @param {Partial<AbstractModuleId>} moduleId - The module identifier, which may include a namespace and name.
188
+ * @param {string} localeId - The locale associated with the bundle.
189
+ * @param {boolean} debug - Indicates whether debug mode is enabled.
190
+ * @param {boolean} ssr - Indicates whether the bundle is for server-side rendering (SSR).
167
191
  */
168
- getCodePath(bundlePath, debug, specifier, version, localeId, ssr) {
169
- // Flag is used to indicate that we are running on a lambda
170
- const isLambda = isLambdaEnv();
171
- // Default source code path determined from metadata based on debug mode
172
- let bundleSourcePath = bundlePath;
173
- // This is the special case where the request is in debug mode and we are on the lambda
174
- // So we will look up the prod source code instead of the debug source code
175
- if (debug && isLambda) {
176
- const metadata = this.getBundleMetadata({
177
- moduleId: { specifier, version },
192
+ logBundleError(moduleId, localeId, debug, ssr) {
193
+ const moduleSpecifier = moduleId.namespace
194
+ ? `${moduleId.namespace}/${moduleId.name}`
195
+ : moduleId.name;
196
+ const siteBundleId = getSiteBundleId(moduleId, localeId, ssr, this.i18n);
197
+ // Retrieve site bundles and debug bundles
198
+ const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
199
+ const siteDebugBundles = this.siteMetadata.getDebugSiteBundles()?.bundles || {};
200
+ // Extract keys and filter bundles by module specifier
201
+ const runtimeBundles = Object.keys(siteBundles).filter((key) => key.startsWith(moduleSpecifier));
202
+ const debugBundles = Object.keys(siteDebugBundles).filter((key) => key.startsWith(moduleSpecifier));
203
+ logger.error({
204
+ message: JSON.stringify({
205
+ message: 'Failed to find static bundle',
206
+ moduleId,
178
207
  localeId,
179
- debug: false,
208
+ debug,
180
209
  ssr,
181
- });
182
- if (!metadata) {
183
- // We did not find the bundle prod bundle even though we did find it in the debug metadata before
184
- logger.error({
185
- label: 'static-bundle-provider',
186
- message: `Unexpected code reference: ${specifier}`,
187
- });
188
- return BUNDLE_SOURCE_NOT_FOUND;
189
- }
190
- // Overwrite the default source code path the prod source code path
191
- bundleSourcePath = path.join(this.siteRootDir, metadata.path);
192
- }
193
- return bundleSourcePath;
210
+ moduleSpecifier,
211
+ siteBundleId,
212
+ debugBundles,
213
+ runtimeBundles,
214
+ totalBundlesCount: Object.keys(siteBundles).length,
215
+ totalDebugBundlesCount: Object.keys(siteDebugBundles).length,
216
+ }),
217
+ label: 'static-bundle-provider',
218
+ });
194
219
  }
195
220
  }
196
221
  //# sourceMappingURL=static-bundle-provider.js.map
@@ -20,7 +20,7 @@ export default function mrtStaticUriTransformer() {
20
20
  }
21
21
  // Remove the basePath from the uri
22
22
  let basePathlessUri = uriDef.uri;
23
- if (runtimeEnvironment?.basePath) {
23
+ if (runtimeEnvironment?.basePath && uriDef.uri.startsWith(runtimeEnvironment?.basePath)) {
24
24
  basePathlessUri = uriDef.uri.replace(runtimeEnvironment?.basePath, '');
25
25
  }
26
26
  const uri = getMrtArtifactUrl(runtimeEnvironment?.basePath || '', basePathlessUri);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.3",
7
+ "version": "0.17.2-alpha.30",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -56,25 +56,25 @@
56
56
  "build/**/*.d.ts"
57
57
  ],
58
58
  "dependencies": {
59
- "@lwrjs/diagnostics": "0.17.2-alpha.3",
60
- "@lwrjs/instrumentation": "0.17.2-alpha.3",
61
- "@lwrjs/shared-utils": "0.17.2-alpha.3",
59
+ "@lwrjs/diagnostics": "0.17.2-alpha.30",
60
+ "@lwrjs/instrumentation": "0.17.2-alpha.30",
61
+ "@lwrjs/shared-utils": "0.17.2-alpha.30",
62
62
  "lru-cache": "^10.4.3"
63
63
  },
64
64
  "devDependencies": {
65
- "@lwrjs/types": "0.17.2-alpha.3",
65
+ "@lwrjs/types": "0.17.2-alpha.30",
66
66
  "@types/express": "^4.17.21",
67
- "jest": "^26.6.3",
67
+ "jest": "29.7.0",
68
68
  "jest-express": "^1.12.0",
69
69
  "memfs": "^4.13.0",
70
70
  "mock-res": "^0.6.0",
71
- "ts-jest": "^26.5.6"
71
+ "ts-jest": "^29.2.6"
72
72
  },
73
73
  "engines": {
74
- "node": ">=18.0.0"
74
+ "node": ">=20.0.0"
75
75
  },
76
76
  "volta": {
77
77
  "extends": "../../../package.json"
78
78
  },
79
- "gitHead": "43757693dfca356cff105d4896a7a3cbf11ac017"
79
+ "gitHead": "818bbb13d2d4b14d128c4c4f23229c9ce7458a23"
80
80
  }