@lwrjs/static 0.17.2-alpha.26 → 0.17.2-alpha.27

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.
@@ -62,37 +62,23 @@ var StaticBundleProvider = class {
62
62
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
63
63
  const {specifier, name, namespace, 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
+ }
71
76
  if (!metadata) {
72
- if (moduleId?.namespace === "@lwc" && moduleId?.name === "ssr-runtime") {
73
- import_diagnostics.logger.error(new Error("@lwc/ssr-runtime at..."));
74
- import_diagnostics.logger.error({msg: "@lwc/ssr-runtime input", moduleId, localeId, debug, ssr});
75
- try {
76
- const siteBundleId = (0, import_site_metadata.getSiteBundleId)(moduleId, localeId, ssr, this.i18n);
77
- const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
78
- const keys = Object.keys(siteBundles);
79
- const totalBundlesCount = keys?.length;
80
- const runtimeBundles = keys.filter((key) => key.startsWith("@lwc/ssr-runtime"));
81
- import_diagnostics.logger.error({
82
- msg: "@lwc/ssr-runtime metadata",
83
- siteBundleId,
84
- runtimeBundles,
85
- totalBundlesCount
86
- });
87
- } catch (error) {
88
- import_diagnostics.logger.error("Error retrieving siteBundles", {error});
89
- }
90
- }
77
+ this.logBundleError(moduleId, localeId, debug, ssr);
91
78
  return void 0;
92
79
  }
93
80
  const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
94
- const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
95
- const codePromiser = this.getCodePromiser(resolvedBundlePath, {
81
+ const codePromiser = this.getCodePromiser(bundlePath, {
96
82
  specifier,
97
83
  version,
98
84
  locale: localeId,
@@ -198,26 +184,29 @@ var StaticBundleProvider = class {
198
184
  return code;
199
185
  };
200
186
  }
201
- getCodePath(bundlePath, debug, specifier, version, localeId, ssr) {
202
- const isLambda = (0, import_shared_utils.isLambdaEnv)();
203
- let bundleSourcePath = bundlePath;
204
- if (debug && isLambda) {
205
- const metadata = this.getBundleMetadata({
206
- moduleId: {specifier, version},
187
+ logBundleError(moduleId, localeId, debug, ssr) {
188
+ const moduleSpecifier = moduleId.namespace ? `${moduleId.namespace}/${moduleId.name}` : moduleId.name;
189
+ const siteBundleId = (0, import_site_metadata.getSiteBundleId)(moduleId, localeId, ssr, this.i18n);
190
+ const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
191
+ const siteDebugBundles = this.siteMetadata.getDebugSiteBundles()?.bundles || {};
192
+ const runtimeBundles = Object.keys(siteBundles).filter((key) => key.startsWith(moduleSpecifier));
193
+ const debugBundles = Object.keys(siteDebugBundles).filter((key) => key.startsWith(moduleSpecifier));
194
+ import_diagnostics.logger.warn({
195
+ message: `Static bundle`,
196
+ additionalInfo: {
197
+ moduleId,
207
198
  localeId,
208
- debug: false,
209
- ssr
210
- });
211
- if (!metadata) {
212
- import_diagnostics.logger.error({
213
- label: "static-bundle-provider",
214
- message: `Unexpected code reference: ${specifier}`
215
- });
216
- return BUNDLE_SOURCE_NOT_FOUND;
217
- }
218
- bundleSourcePath = import_path.default.join(this.siteRootDir, metadata.path);
219
- }
220
- return bundleSourcePath;
199
+ debug,
200
+ ssr,
201
+ moduleSpecifier,
202
+ siteBundleId,
203
+ debugBundles,
204
+ runtimeBundles,
205
+ totalBundlesCount: Object.keys(siteBundles).length,
206
+ totalDebugBundlesCount: Object.keys(siteDebugBundles).length
207
+ },
208
+ label: "static-bundle-provider"
209
+ });
221
210
  }
222
211
  };
223
212
  var static_bundle_provider_default = StaticBundleProvider;
@@ -30,16 +30,17 @@ export default class StaticBundleProvider implements BundleProvider {
30
30
  debug: boolean;
31
31
  }): () => Promise<string>;
32
32
  /**
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
33
+ * Logs an error when a bundle fails to load and provides debugging metadata.
35
34
  *
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
35
+ * This function logs details about the failed bundle load attempt, including the module ID,
36
+ * locale, debug mode, and SSR status. It also attempts to retrieve additional metadata
37
+ * about the site bundles and debug bundles associated with the module.
38
+ *
39
+ * @param {Partial<AbstractModuleId>} moduleId - The module identifier, which may include a namespace and name.
40
+ * @param {string} localeId - The locale associated with the bundle.
41
+ * @param {boolean} debug - Indicates whether debug mode is enabled.
42
+ * @param {boolean} ssr - Indicates whether the bundle is for server-side rendering (SSR).
42
43
  */
43
- getCodePath(bundlePath: string, debug: boolean, specifier: string, version: string | undefined, localeId: string, ssr: boolean): string;
44
+ logBundleError(moduleId: Partial<AbstractModuleId>, localeId: string, debug: boolean, ssr: boolean): void;
44
45
  }
45
46
  //# sourceMappingURL=static-bundle-provider.d.ts.map
@@ -35,39 +35,27 @@ export default class StaticBundleProvider {
35
35
  }
36
36
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
37
37
  const { specifier, name, namespace, version } = moduleId;
38
- const { debug, i18n: { defaultLocale }, } = runtimeEnvironment;
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
+ }
42
51
  if (!metadata) {
43
- // Adding temporary logging to debug issue where @lwc/ssr-runtime is not found
44
- if (moduleId?.namespace === '@lwc' && moduleId?.name === 'ssr-runtime') {
45
- logger.error(new Error('@lwc/ssr-runtime at...'));
46
- logger.error({ msg: '@lwc/ssr-runtime input', moduleId, localeId, debug, ssr });
47
- try {
48
- const siteBundleId = getSiteBundleId(moduleId, localeId, ssr, this.i18n);
49
- const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
50
- const keys = Object.keys(siteBundles);
51
- const totalBundlesCount = keys?.length;
52
- const runtimeBundles = keys.filter((key) => key.startsWith('@lwc/ssr-runtime'));
53
- logger.error({
54
- msg: '@lwc/ssr-runtime metadata',
55
- siteBundleId,
56
- runtimeBundles,
57
- totalBundlesCount,
58
- });
59
- }
60
- catch (error) {
61
- logger.error('Error retrieving siteBundles', { error });
62
- }
63
- }
52
+ this.logBundleError(moduleId, localeId, debug, ssr);
64
53
  return undefined;
65
54
  }
66
55
  // Default bundle source path
67
56
  const bundlePath = path.join(this.siteRootDir, metadata.path);
68
57
  // Get the associated bundle source code
69
- const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
70
- const codePromiser = this.getCodePromiser(resolvedBundlePath, {
58
+ const codePromiser = this.getCodePromiser(bundlePath, {
71
59
  specifier,
72
60
  version,
73
61
  locale: localeId,
@@ -176,42 +164,44 @@ export default class StaticBundleProvider {
176
164
  };
177
165
  }
178
166
  /**
179
- * Get the local source code path for the a static bundle
180
- * 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
167
+ * Logs an error when a bundle fails to load and provides debugging metadata.
168
+ *
169
+ * This function logs details about the failed bundle load attempt, including the module ID,
170
+ * locale, debug mode, and SSR status. It also attempts to retrieve additional metadata
171
+ * about the site bundles and debug bundles associated with the module.
181
172
  *
182
- * @param bundlePath The default path for the bundle for prod read from .metadata/bundle-metadata.json, for debug .metadata/bundle-metadata-debug.json
183
- * @param debug Is the request in debug mode?
184
- * @param specifier Root specifier for the requested bundle
185
- * @param version Root specifier version
186
- * @param localeId Locale id (e.g. en-US) for the current request
187
- * @param ssr True if this is a server bundle
173
+ * @param {Partial<AbstractModuleId>} moduleId - The module identifier, which may include a namespace and name.
174
+ * @param {string} localeId - The locale associated with the bundle.
175
+ * @param {boolean} debug - Indicates whether debug mode is enabled.
176
+ * @param {boolean} ssr - Indicates whether the bundle is for server-side rendering (SSR).
188
177
  */
189
- getCodePath(bundlePath, debug, specifier, version, localeId, ssr) {
190
- // Flag is used to indicate that we are running on a lambda
191
- const isLambda = isLambdaEnv();
192
- // Default source code path determined from metadata based on debug mode
193
- let bundleSourcePath = bundlePath;
194
- // This is the special case where the request is in debug mode and we are on the lambda
195
- // So we will look up the prod source code instead of the debug source code
196
- if (debug && isLambda) {
197
- const metadata = this.getBundleMetadata({
198
- moduleId: { specifier, version },
178
+ logBundleError(moduleId, localeId, debug, ssr) {
179
+ const moduleSpecifier = moduleId.namespace
180
+ ? `${moduleId.namespace}/${moduleId.name}`
181
+ : moduleId.name;
182
+ const siteBundleId = getSiteBundleId(moduleId, localeId, ssr, this.i18n);
183
+ // Retrieve site bundles and debug bundles
184
+ const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
185
+ const siteDebugBundles = this.siteMetadata.getDebugSiteBundles()?.bundles || {};
186
+ // Extract keys and filter bundles by module specifier
187
+ const runtimeBundles = Object.keys(siteBundles).filter((key) => key.startsWith(moduleSpecifier));
188
+ const debugBundles = Object.keys(siteDebugBundles).filter((key) => key.startsWith(moduleSpecifier));
189
+ logger.warn({
190
+ message: `Static bundle`,
191
+ additionalInfo: {
192
+ moduleId,
199
193
  localeId,
200
- debug: false,
194
+ debug,
201
195
  ssr,
202
- });
203
- if (!metadata) {
204
- // We did not find the bundle prod bundle even though we did find it in the debug metadata before
205
- logger.error({
206
- label: 'static-bundle-provider',
207
- message: `Unexpected code reference: ${specifier}`,
208
- });
209
- return BUNDLE_SOURCE_NOT_FOUND;
210
- }
211
- // Overwrite the default source code path the prod source code path
212
- bundleSourcePath = path.join(this.siteRootDir, metadata.path);
213
- }
214
- return bundleSourcePath;
196
+ moduleSpecifier,
197
+ siteBundleId,
198
+ debugBundles,
199
+ runtimeBundles,
200
+ totalBundlesCount: Object.keys(siteBundles).length,
201
+ totalDebugBundlesCount: Object.keys(siteDebugBundles).length,
202
+ },
203
+ label: 'static-bundle-provider',
204
+ });
215
205
  }
216
206
  }
217
207
  //# sourceMappingURL=static-bundle-provider.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.26",
7
+ "version": "0.17.2-alpha.27",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -56,13 +56,13 @@
56
56
  "build/**/*.d.ts"
57
57
  ],
58
58
  "dependencies": {
59
- "@lwrjs/diagnostics": "0.17.2-alpha.26",
60
- "@lwrjs/instrumentation": "0.17.2-alpha.26",
61
- "@lwrjs/shared-utils": "0.17.2-alpha.26",
59
+ "@lwrjs/diagnostics": "0.17.2-alpha.27",
60
+ "@lwrjs/instrumentation": "0.17.2-alpha.27",
61
+ "@lwrjs/shared-utils": "0.17.2-alpha.27",
62
62
  "lru-cache": "^10.4.3"
63
63
  },
64
64
  "devDependencies": {
65
- "@lwrjs/types": "0.17.2-alpha.26",
65
+ "@lwrjs/types": "0.17.2-alpha.27",
66
66
  "@types/express": "^4.17.21",
67
67
  "jest": "29.7.0",
68
68
  "jest-express": "^1.12.0",
@@ -76,5 +76,5 @@
76
76
  "volta": {
77
77
  "extends": "../../../package.json"
78
78
  },
79
- "gitHead": "7aeb8ed681eced0cf80abc41b5adee3f3fd5160b"
79
+ "gitHead": "b6f4a80f77b05902c4365f1c1eb657d944d01db0"
80
80
  }