@lwrjs/static 0.11.0-alpha.4 → 0.11.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.
@@ -40,11 +40,12 @@ var StaticBundleProvider = class {
40
40
  this.siteBundles = context.siteMetadata.getSiteBundles();
41
41
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
42
42
  this.bundleConfig = context.config.bundleConfig;
43
+ this.i18n = context.config.i18n;
43
44
  }
44
45
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
45
46
  const {specifier, name, namespace, version} = moduleId;
46
47
  const localeId = runtimeParams?.locale || runtimeEnvironment.defaultLocale;
47
- const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, runtimeEnvironment.defaultLocale);
48
+ const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
48
49
  if (!metadata) {
49
50
  if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
50
51
  import_shared_utils.logger.warn(`[${this.name}] did not find requested specifier ${specifier}`);
@@ -38,13 +38,13 @@ var StaticModuleProvider = class {
38
38
  this.externals = Object.keys(context.config.bundleConfig.external || {});
39
39
  this.siteBundles = context.siteMetadata.getSiteBundles();
40
40
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
41
- this.runtimeEnvironment = context.runtimeEnvironment;
41
+ this.i18n = context.config.i18n;
42
42
  this.fingerprintIndex = buildFingerprintsIndex(context);
43
43
  }
44
44
  async getModule(moduleId, runtimeParams) {
45
45
  const {specifier} = moduleId;
46
- const localeId = runtimeParams?.locale || this.runtimeEnvironment.defaultLocale;
47
- const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.runtimeEnvironment.defaultLocale);
46
+ const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
47
+ const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
48
48
  if (metadata) {
49
49
  import_shared_utils.logger.warn(`[${this.name}] We should not be asking for module source we have in our site metadata ${moduleId.specifier}`);
50
50
  return void 0;
@@ -53,8 +53,8 @@ var StaticModuleProvider = class {
53
53
  }
54
54
  async getModuleEntry(moduleId, runtimeParams) {
55
55
  const {specifier, version} = moduleId;
56
- const localeId = runtimeParams?.locale || this.runtimeEnvironment.defaultLocale;
57
- const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.runtimeEnvironment.defaultLocale);
56
+ const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
57
+ const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
58
58
  if (metadata) {
59
59
  import_shared_utils.logger.info(`[${this.name}] Module Entry request for static bundle ${specifier}`);
60
60
  const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
@@ -31,21 +31,19 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
31
  function resolveStaticBundleVersion(metadataVersion, requestedVersion) {
32
32
  return metadataVersion || requestedVersion || import_shared_utils.VERSION_NOT_PROVIDED;
33
33
  }
34
- function getLocalizedBundle(specifier, siteBundles, localeId, defaultLocaleId) {
35
- if (localeId === defaultLocaleId) {
34
+ function getLocalizedBundle(specifier, siteBundles, localeId, i18n) {
35
+ if (localeId === i18n.defaultLocale) {
36
36
  return siteBundles.bundles[specifier];
37
37
  }
38
38
  const localizedBundle = siteBundles.bundles[`${specifier}|l/${localeId}`];
39
39
  if (localizedBundle) {
40
40
  return localizedBundle;
41
41
  }
42
- if ((0, import_shared_utils.hasCountryCode)(localeId)) {
43
- const stripedCode = (0, import_shared_utils.stripCountryCode)(localeId);
44
- if (stripedCode) {
45
- const localizedBundle2 = siteBundles.bundles[`${specifier}|l/${stripedCode}`];
46
- if (localizedBundle2) {
47
- return localizedBundle2;
48
- }
42
+ const fallbackId = (0, import_shared_utils.getFallbackLocale)(localeId, i18n);
43
+ if (fallbackId) {
44
+ const localizedBundle2 = siteBundles.bundles[`${specifier}|l/${fallbackId}`];
45
+ if (localizedBundle2) {
46
+ return localizedBundle2;
49
47
  }
50
48
  }
51
49
  return siteBundles.bundles[specifier];
@@ -4,6 +4,7 @@ export default class StaticBundleProvider implements BundleProvider {
4
4
  siteBundles: import("@lwrjs/types").SiteBundles;
5
5
  siteRootDir: string;
6
6
  bundleConfig: import("@lwrjs/types").BundleConfig;
7
+ i18n: import("@lwrjs/types").I18NConfig;
7
8
  constructor(_config: {}, context: ProviderContext);
8
9
  bundle<BundleIdentifier extends AbstractModuleId, RE extends RuntimeEnvironment>(moduleId: BundleIdentifier, runtimeEnvironment: RE, runtimeParams: RuntimeParams): Promise<BundleDefinition | undefined>;
9
10
  }
@@ -12,11 +12,12 @@ export default class StaticBundleProvider {
12
12
  this.siteBundles = context.siteMetadata.getSiteBundles();
13
13
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
14
14
  this.bundleConfig = context.config.bundleConfig;
15
+ this.i18n = context.config.i18n;
15
16
  }
16
17
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
17
18
  const { specifier, name, namespace, version } = moduleId;
18
19
  const localeId = (runtimeParams?.locale || runtimeEnvironment.defaultLocale);
19
- const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, runtimeEnvironment.defaultLocale);
20
+ const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
20
21
  if (!metadata) {
21
22
  // ignore ssr module requests
22
23
  if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
@@ -1,11 +1,11 @@
1
- import type { AbstractModuleId, ModuleCompiled, ModuleEntry, ModuleProvider, ProviderContext, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
1
+ import type { AbstractModuleId, I18NConfig, ModuleCompiled, ModuleEntry, ModuleProvider, ProviderContext, RuntimeParams } from '@lwrjs/types';
2
2
  export default class StaticModuleProvider implements ModuleProvider {
3
3
  name: string;
4
4
  siteBundles: import("@lwrjs/types").SiteBundles;
5
5
  siteRootDir: string;
6
6
  externals: string[];
7
7
  fingerprintIndex: Record<string, ModuleEntry>;
8
- runtimeEnvironment: RuntimeEnvironment;
8
+ i18n: I18NConfig;
9
9
  constructor(_config: {}, context: ProviderContext);
10
10
  getModule<T extends AbstractModuleId>(moduleId: T, runtimeParams: RuntimeParams): Promise<ModuleCompiled | undefined>;
11
11
  getModuleEntry<T extends AbstractModuleId>(moduleId: T, runtimeParams: RuntimeParams): Promise<ModuleEntry | undefined>;
@@ -10,14 +10,14 @@ export default class StaticModuleProvider {
10
10
  this.externals = Object.keys(context.config.bundleConfig.external || {});
11
11
  this.siteBundles = context.siteMetadata.getSiteBundles();
12
12
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
13
- this.runtimeEnvironment = context.runtimeEnvironment;
13
+ this.i18n = context.config.i18n;
14
14
  // If we are using fingerprints collect all the specifiers in the bundles and add them to an index for creating the mapping identities
15
15
  this.fingerprintIndex = buildFingerprintsIndex(context);
16
16
  }
17
17
  async getModule(moduleId, runtimeParams) {
18
18
  const { specifier } = moduleId;
19
- const localeId = (runtimeParams?.locale || this.runtimeEnvironment.defaultLocale);
20
- const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.runtimeEnvironment.defaultLocale);
19
+ const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
20
+ const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
21
21
  if (metadata) {
22
22
  logger.warn(`[${this.name}] We should not be asking for module source we have in our site metadata ${moduleId.specifier}`);
23
23
  // proceed to next provider
@@ -29,8 +29,8 @@ export default class StaticModuleProvider {
29
29
  async getModuleEntry(moduleId, runtimeParams) {
30
30
  // TODO shouldn't we be passing the runtime environment here to test?
31
31
  const { specifier, version } = moduleId;
32
- const localeId = (runtimeParams?.locale || this.runtimeEnvironment.defaultLocale);
33
- const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.runtimeEnvironment.defaultLocale);
32
+ const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
33
+ const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
34
34
  if (metadata) {
35
35
  logger.info(`[${this.name}] Module Entry request for static bundle ${specifier}`);
36
36
  // Have to make the bundle code available for SSR
@@ -1,4 +1,4 @@
1
- import type { SiteBundle, SiteBundles } from '@lwrjs/types';
1
+ import type { I18NConfig, SiteBundle, SiteBundles } from '@lwrjs/types';
2
2
  /**
3
3
  * Return the version for a static module bundle.
4
4
  *
@@ -8,5 +8,5 @@ export declare function resolveStaticBundleVersion(metadataVersion?: string, req
8
8
  /**
9
9
  * Get the most best match for a localized bundle
10
10
  */
11
- export declare function getLocalizedBundle(specifier: string, siteBundles: SiteBundles, localeId: string, defaultLocaleId: string): SiteBundle | undefined;
11
+ export declare function getLocalizedBundle(specifier: string, siteBundles: SiteBundles, localeId: string, i18n: I18NConfig): SiteBundle | undefined;
12
12
  //# sourceMappingURL=static-utils.d.ts.map
@@ -2,7 +2,7 @@
2
2
  * Try to add any code that is mrt specific here so that we can isolate details that would have to be refactored to run lambdas
3
3
  * on a different platform
4
4
  */
5
- import { hasCountryCode, stripCountryCode, VERSION_NOT_PROVIDED } from '@lwrjs/shared-utils';
5
+ import { getFallbackLocale, VERSION_NOT_PROVIDED } from '@lwrjs/shared-utils';
6
6
  /**
7
7
  * Return the version for a static module bundle.
8
8
  *
@@ -14,9 +14,9 @@ export function resolveStaticBundleVersion(metadataVersion, requestedVersion) {
14
14
  /**
15
15
  * Get the most best match for a localized bundle
16
16
  */
17
- export function getLocalizedBundle(specifier, siteBundles, localeId, defaultLocaleId) {
17
+ export function getLocalizedBundle(specifier, siteBundles, localeId, i18n) {
18
18
  // check if the locale is the default or not an additional locale
19
- if (localeId === defaultLocaleId) {
19
+ if (localeId === i18n.defaultLocale) {
20
20
  return siteBundles.bundles[specifier];
21
21
  }
22
22
  // Check if there was an exact match for the preferred locale
@@ -25,13 +25,11 @@ export function getLocalizedBundle(specifier, siteBundles, localeId, defaultLoca
25
25
  return localizedBundle;
26
26
  }
27
27
  // Else check if there is a match without the county code
28
- if (hasCountryCode(localeId)) {
29
- const stripedCode = stripCountryCode(localeId);
30
- if (stripedCode) {
31
- const localizedBundle = siteBundles.bundles[`${specifier}|l/${stripedCode}`];
32
- if (localizedBundle) {
33
- return localizedBundle;
34
- }
28
+ const fallbackId = getFallbackLocale(localeId, i18n);
29
+ if (fallbackId) {
30
+ const localizedBundle = siteBundles.bundles[`${specifier}|l/${fallbackId}`];
31
+ if (localizedBundle) {
32
+ return localizedBundle;
35
33
  }
36
34
  }
37
35
  // Else fall back to the non-localized bundle
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.11.0-alpha.4",
7
+ "version": "0.11.0-alpha.6",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -48,10 +48,10 @@
48
48
  "build/**/*.d.ts"
49
49
  ],
50
50
  "dependencies": {
51
- "@lwrjs/shared-utils": "0.11.0-alpha.4"
51
+ "@lwrjs/shared-utils": "0.11.0-alpha.6"
52
52
  },
53
53
  "devDependencies": {
54
- "@lwrjs/types": "0.11.0-alpha.4",
54
+ "@lwrjs/types": "0.11.0-alpha.6",
55
55
  "@types/express": "^4.17.17",
56
56
  "jest": "^26.6.3",
57
57
  "jest-express": "^1.12.0",
@@ -64,5 +64,5 @@
64
64
  "volta": {
65
65
  "extends": "../../../package.json"
66
66
  },
67
- "gitHead": "89a7e9815e0e381d9fd67212f0471d9a11f73985"
67
+ "gitHead": "571d4bac5650765aa818bcb9d5ed752a8cf041af"
68
68
  }