@lwrjs/static 0.19.0-alpha.4 → 0.19.0-alpha.6

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,16 +62,14 @@ var StaticBundleProvider = class {
62
62
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
63
63
  const {specifier, version} = moduleId;
64
64
  const {
65
+ debug,
65
66
  i18n: {defaultLocale}
66
67
  } = runtimeEnvironment;
67
68
  const localeId = runtimeParams?.locale || defaultLocale;
68
69
  const ssr = runtimeParams?.ssr;
69
- let debug = runtimeEnvironment.debug;
70
70
  let metadata = this.getBundleMetadata({moduleId, localeId, debug, ssr});
71
71
  if (!metadata && debug) {
72
72
  metadata = this.getBundleMetadata({moduleId, localeId, debug: false, ssr});
73
- if (metadata)
74
- debug = false;
75
73
  }
76
74
  if (!metadata && (0, import_shared_utils.isExternalSpecifier)(moduleId.specifier, this.bundleConfig)) {
77
75
  const {specifier: unversionedSepcifier} = (0, import_shared_utils.explodeSpecifier)(moduleId.specifier);
@@ -88,7 +86,8 @@ var StaticBundleProvider = class {
88
86
  return void 0;
89
87
  }
90
88
  const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
91
- const codePromiser = this.getCodePromiser(bundlePath, {
89
+ const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
90
+ const codePromiser = this.getCodePromiser(resolvedBundlePath, {
92
91
  specifier,
93
92
  version,
94
93
  locale: localeId,
@@ -222,5 +221,26 @@ var StaticBundleProvider = class {
222
221
  label: "static-bundle-provider"
223
222
  });
224
223
  }
224
+ getCodePath(bundlePath, debug, specifier, version, localeId, ssr) {
225
+ const isLambda = (0, import_shared_utils.isLambdaEnv)() || process.env.FORCE_DEBUG_FALLBACK === "true";
226
+ let bundleSourcePath = bundlePath;
227
+ if (debug && isLambda) {
228
+ const metadata = this.getBundleMetadata({
229
+ moduleId: {specifier, version},
230
+ localeId,
231
+ debug: false,
232
+ ssr
233
+ });
234
+ if (!metadata) {
235
+ import_diagnostics.logger.error({
236
+ label: "static-bundle-provider",
237
+ message: `debug-to-prod fallback missing metadata for specifier: ${specifier}`
238
+ });
239
+ return BUNDLE_SOURCE_NOT_FOUND;
240
+ }
241
+ bundleSourcePath = import_path.default.join(this.siteRootDir, metadata.path);
242
+ }
243
+ return bundleSourcePath;
244
+ }
225
245
  };
226
246
  var static_bundle_provider_default = StaticBundleProvider;
@@ -125,7 +125,7 @@ var DecisionTreeImpl = class {
125
125
  const versions = versionChoice === CHOICE_EMPTY ? [...new Set([CHOICE_EMPTY, CHOICE_WILDCARD])] : [...new Set([versionChoice, CHOICE_EMPTY])];
126
126
  const envChoice = debug ? [CHOICE_DEBUG] : [CHOICE_PROD];
127
127
  const ssrChoice = match.variants[import_shared_utils.SSR_SIGIL] || CHOICE_EMPTY;
128
- const ssr = (0, import_shared_utils.getFeatureFlags)().SSR_COMPILER_ENABLED ? [ssrChoice] : ssrChoice ? [ssrChoice, CHOICE_WILDCARD] : [CHOICE_WILDCARD];
128
+ const ssr = (0, import_shared_utils.getFeatureFlags)().SSR_COMPILER_ENABLED ? [ssrChoice] : match.variants[import_shared_utils.SSR_SIGIL] ? [CHOICE_TRUE, CHOICE_EMPTY] : [CHOICE_EMPTY, CHOICE_TRUE];
129
129
  const localeChoice = match.variants[import_shared_utils.LOCALE_SIGIL];
130
130
  const localeId = localeFallbacks?.[localeChoice] ?? [CHOICE_WILDCARD];
131
131
  return this.getOrderedChoices([specifier], envChoice, ssr, versions, localeId);
@@ -43,5 +43,17 @@ export default class StaticBundleProvider implements BundleProvider {
43
43
  * @param {boolean} ssr - Indicates whether the bundle is for server-side rendering (SSR).
44
44
  */
45
45
  logBundleError(moduleId: Partial<AbstractModuleId>, localeId: string, debug: boolean, ssr: boolean): void;
46
+ /**
47
+ * Get the local source code path for the a static bundle
48
+ * 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
49
+ *
50
+ * @param bundlePath The default path for the bundle for prod read from .metadata/bundle-metadata.json, for debug .metadata/bundle-metadata-debug.json
51
+ * @param debug Is the request in debug mode?
52
+ * @param specifier Root specifier for the requested bundle
53
+ * @param version Root specifier version
54
+ * @param localeId Locale id (e.g. en-US) for the current request
55
+ * @param ssr True if this is a server bundle
56
+ */
57
+ getCodePath(bundlePath: string, debug: boolean, specifier: string, version: string | undefined, localeId: string, ssr: boolean): string;
46
58
  }
47
59
  //# sourceMappingURL=static-bundle-provider.d.ts.map
@@ -41,18 +41,15 @@ export default class StaticBundleProvider {
41
41
  }
42
42
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
43
43
  const { specifier, version } = moduleId;
44
- const { i18n: { defaultLocale }, } = runtimeEnvironment;
44
+ const { debug, i18n: { defaultLocale }, } = runtimeEnvironment;
45
45
  const localeId = (runtimeParams?.locale || defaultLocale);
46
46
  const ssr = runtimeParams?.ssr;
47
- let debug = runtimeEnvironment.debug;
48
47
  let metadata = this.getBundleMetadata({ moduleId, localeId, debug, ssr });
49
48
  if (!metadata && debug) {
50
49
  // Fallback to use prod bundles if the debug variant does not exist
51
50
  // eg: debug bundles are not shipped to the Lambda
52
51
  // eg: locally, an MRT bundle may or may not have debug metadata, depending on how it's generated
53
52
  metadata = this.getBundleMetadata({ moduleId, localeId, debug: false, ssr });
54
- if (metadata)
55
- debug = false;
56
53
  }
57
54
  if (!metadata && isExternalSpecifier(moduleId.specifier, this.bundleConfig)) {
58
55
  const { specifier: unversionedSepcifier } = explodeSpecifier(moduleId.specifier);
@@ -71,7 +68,8 @@ export default class StaticBundleProvider {
71
68
  // Default bundle source path
72
69
  const bundlePath = path.join(this.siteRootDir, metadata.path);
73
70
  // Get the associated bundle source code
74
- const codePromiser = this.getCodePromiser(bundlePath, {
71
+ const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
72
+ const codePromiser = this.getCodePromiser(resolvedBundlePath, {
75
73
  specifier,
76
74
  version,
77
75
  locale: localeId,
@@ -223,5 +221,43 @@ export default class StaticBundleProvider {
223
221
  label: 'static-bundle-provider',
224
222
  });
225
223
  }
224
+ /**
225
+ * Get the local source code path for the a static bundle
226
+ * 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
227
+ *
228
+ * @param bundlePath The default path for the bundle for prod read from .metadata/bundle-metadata.json, for debug .metadata/bundle-metadata-debug.json
229
+ * @param debug Is the request in debug mode?
230
+ * @param specifier Root specifier for the requested bundle
231
+ * @param version Root specifier version
232
+ * @param localeId Locale id (e.g. en-US) for the current request
233
+ * @param ssr True if this is a server bundle
234
+ */
235
+ getCodePath(bundlePath, debug, specifier, version, localeId, ssr) {
236
+ // Flag is used to indicate that we are running on a lambda
237
+ const isLambda = isLambdaEnv() || process.env.FORCE_DEBUG_FALLBACK === 'true'; // Env variable for testing purposes only
238
+ // Default source code path determined from metadata based on debug mode
239
+ let bundleSourcePath = bundlePath;
240
+ // This is the special case where the request is in debug mode and we are on the lambda
241
+ // So we will look up the prod source code instead of the debug source code
242
+ if (debug && isLambda) {
243
+ const metadata = this.getBundleMetadata({
244
+ moduleId: { specifier, version },
245
+ localeId,
246
+ debug: false,
247
+ ssr,
248
+ });
249
+ if (!metadata) {
250
+ // We did not find the bundle prod bundle even though we did find it in the debug metadata before
251
+ logger.error({
252
+ label: 'static-bundle-provider',
253
+ message: `debug-to-prod fallback missing metadata for specifier: ${specifier}`,
254
+ });
255
+ return BUNDLE_SOURCE_NOT_FOUND;
256
+ }
257
+ // Overwrite the default source code path the prod source code path
258
+ bundleSourcePath = path.join(this.siteRootDir, metadata.path);
259
+ }
260
+ return bundleSourcePath;
261
+ }
226
262
  }
227
263
  //# sourceMappingURL=static-bundle-provider.js.map
@@ -16,7 +16,7 @@ export default class DecisionTreeImpl<Artifact extends SiteArtifact> implements
16
16
  private deepInsert;
17
17
  find(siteArtifactId: string, debug?: boolean, ssr?: boolean, localeId?: string): Artifact | undefined;
18
18
  /**
19
- * Create a decision tree patch to look up the most appropriate bundle
19
+ * Create a decision tree path to look up the most appropriate bundle
20
20
  *
21
21
  * @param specifier Bundle specifier
22
22
  * @param version known version or will add the choice ''
@@ -119,7 +119,7 @@ export default class DecisionTreeImpl {
119
119
  return currentNode.artifact;
120
120
  }
121
121
  /**
122
- * Create a decision tree patch to look up the most appropriate bundle
122
+ * Create a decision tree path to look up the most appropriate bundle
123
123
  *
124
124
  * @param specifier Bundle specifier
125
125
  * @param version known version or will add the choice ''
@@ -162,9 +162,10 @@ export default class DecisionTreeImpl {
162
162
  const ssrChoice = match.variants[SSR_SIGIL] || CHOICE_EMPTY;
163
163
  const ssr = getFeatureFlags().SSR_COMPILER_ENABLED
164
164
  ? [ssrChoice]
165
- : ssrChoice
166
- ? [ssrChoice, CHOICE_WILDCARD]
167
- : [CHOICE_WILDCARD];
165
+ : // For SSR V1 |ssr will prefer true non ssr will prefer empty
166
+ match.variants[SSR_SIGIL]
167
+ ? [CHOICE_TRUE, CHOICE_EMPTY]
168
+ : [CHOICE_EMPTY, CHOICE_TRUE];
168
169
  const localeChoice = match.variants[LOCALE_SIGIL];
169
170
  // If there are no fallbacks, or localeChoice is not in fallbacks use the ['*'] wildcard choice
170
171
  const localeId = localeFallbacks?.[localeChoice] ?? [CHOICE_WILDCARD];
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.19.0-alpha.4",
7
+ "version": "0.19.0-alpha.6",
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.19.0-alpha.4",
60
- "@lwrjs/instrumentation": "0.19.0-alpha.4",
61
- "@lwrjs/shared-utils": "0.19.0-alpha.4",
59
+ "@lwrjs/diagnostics": "0.19.0-alpha.6",
60
+ "@lwrjs/instrumentation": "0.19.0-alpha.6",
61
+ "@lwrjs/shared-utils": "0.19.0-alpha.6",
62
62
  "lru-cache": "^10.4.3"
63
63
  },
64
64
  "devDependencies": {
65
- "@lwrjs/types": "0.19.0-alpha.4",
65
+ "@lwrjs/types": "0.19.0-alpha.6",
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": "83466768b57a140e1eefae560be386277b7100a9"
79
+ "gitHead": "25933a335c7f2f6ebc39381feda5f47e07e43faa"
80
80
  }