@lwrjs/static 0.11.0-alpha.9 → 0.11.1
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.
- package/build/cjs/providers/static-asset-provider.cjs +4 -3
- package/build/cjs/providers/static-bundle-provider.cjs +18 -5
- package/build/cjs/providers/static-module-provider.cjs +5 -4
- package/build/cjs/providers/static-resource-provider.cjs +3 -2
- package/build/cjs/site-metadata.cjs +6 -6
- package/build/cjs/utils/static-utils.cjs +5 -16
- package/build/es/providers/static-asset-provider.js +2 -1
- package/build/es/providers/static-bundle-provider.js +18 -4
- package/build/es/providers/static-module-provider.js +4 -3
- package/build/es/providers/static-resource-provider.js +2 -1
- package/build/es/site-metadata.js +3 -3
- package/build/es/utils/static-utils.d.ts +1 -1
- package/build/es/utils/static-utils.js +6 -21
- package/package.json +5 -4
|
@@ -26,6 +26,7 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
default: () => static_asset_provider_default
|
|
28
28
|
});
|
|
29
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
31
|
var import_path = __toModule(require("path"));
|
|
31
32
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
@@ -56,7 +57,7 @@ var StaticAssetProvider = class {
|
|
|
56
57
|
const metadata = this.siteAssets.assets[fileAssetPath];
|
|
57
58
|
if (!metadata) {
|
|
58
59
|
if (import_path.default.dirname(fileAssetPath) !== (this.basePath ? this.basePath : "/")) {
|
|
59
|
-
|
|
60
|
+
import_diagnostics.logger.warn(`[${this.name}] Did not find requested specifier ${fileAssetPath}`);
|
|
60
61
|
}
|
|
61
62
|
return void 0;
|
|
62
63
|
}
|
|
@@ -70,7 +71,7 @@ var StaticAssetProvider = class {
|
|
|
70
71
|
throw Error(`[${this.name}] Asset is not on lambda ${siteAssetPath}`);
|
|
71
72
|
};
|
|
72
73
|
const uri = this.assetsOnLambda ? fileAssetPath : import_path.default.join(this.siteRootDir, fileAssetPath);
|
|
73
|
-
|
|
74
|
+
import_diagnostics.logger.debug(`[${this.name}] uri ${assetIdentifier.specifier} -> ${uri}`);
|
|
74
75
|
return {
|
|
75
76
|
entry: siteAssetPath,
|
|
76
77
|
ext,
|
|
@@ -86,7 +87,7 @@ var StaticAssetProvider = class {
|
|
|
86
87
|
const {specifier} = assetId;
|
|
87
88
|
let normalizedSpecifier = specifier;
|
|
88
89
|
if (normalizedSpecifier.includes("?")) {
|
|
89
|
-
|
|
90
|
+
import_diagnostics.logger.debug(`[${this.name}] Removed query param from asset specifier: ${specifier}`);
|
|
90
91
|
normalizedSpecifier = normalizedSpecifier.split("?")[0];
|
|
91
92
|
}
|
|
92
93
|
if (normalizedSpecifier[0] === "$") {
|
|
@@ -26,6 +26,7 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
default: () => static_bundle_provider_default
|
|
28
28
|
});
|
|
29
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
31
|
var import_path = __toModule(require("path"));
|
|
31
32
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
@@ -45,18 +46,22 @@ var StaticBundleProvider = class {
|
|
|
45
46
|
}
|
|
46
47
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
47
48
|
const {specifier, name, namespace, version} = moduleId;
|
|
48
|
-
const {
|
|
49
|
+
const {
|
|
50
|
+
debug,
|
|
51
|
+
i18n: {defaultLocale}
|
|
52
|
+
} = runtimeEnvironment;
|
|
49
53
|
const localeId = runtimeParams?.locale || defaultLocale;
|
|
50
54
|
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
51
|
-
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
55
|
+
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
52
56
|
if (!metadata) {
|
|
53
57
|
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
54
|
-
|
|
58
|
+
import_diagnostics.logger.warn(`[${this.name}] did not find requested specifier ${specifier}`);
|
|
55
59
|
}
|
|
56
60
|
return void 0;
|
|
57
61
|
}
|
|
58
62
|
const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
59
|
-
const
|
|
63
|
+
const skipDebugModeCode = debug && (0, import_shared_utils.getFeatureFlags)().SSR_STATIC_BUNDLES;
|
|
64
|
+
const code = skipDebugModeCode ? 'throw new Error("Unexpected code reference");' : (await import_fs_extra.default.readFile(bundlePath)).toString("utf-8");
|
|
60
65
|
const imports = metadata.imports.map((specifier2) => {
|
|
61
66
|
const importModule = (0, import_shared_utils.explodeSpecifier)(specifier2);
|
|
62
67
|
if (!importModule.version) {
|
|
@@ -64,6 +69,13 @@ var StaticBundleProvider = class {
|
|
|
64
69
|
}
|
|
65
70
|
return importModule;
|
|
66
71
|
});
|
|
72
|
+
const dynamicImports = metadata.dynamicImports?.map((specifier2) => {
|
|
73
|
+
const dynamicImportModule = (0, import_shared_utils.explodeSpecifier)(specifier2);
|
|
74
|
+
if (!dynamicImportModule.version) {
|
|
75
|
+
dynamicImportModule.version = (0, import_static_utils.resolveStaticBundleVersion)(this.siteBundles.bundles[specifier2]?.version);
|
|
76
|
+
}
|
|
77
|
+
return dynamicImportModule;
|
|
78
|
+
});
|
|
67
79
|
const id = (0, import_shared_utils.getSpecifier)(moduleId);
|
|
68
80
|
const exploded = (0, import_shared_utils.explodeSpecifier)(id);
|
|
69
81
|
const resolvedName = name || exploded.name;
|
|
@@ -84,7 +96,8 @@ var StaticBundleProvider = class {
|
|
|
84
96
|
config: this.bundleConfig,
|
|
85
97
|
bundleRecord: {
|
|
86
98
|
includedModules: metadata.includedModules || [],
|
|
87
|
-
imports
|
|
99
|
+
imports,
|
|
100
|
+
dynamicImports
|
|
88
101
|
},
|
|
89
102
|
src: bundlePath
|
|
90
103
|
};
|
|
@@ -26,6 +26,7 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
default: () => static_module_provider_default
|
|
28
28
|
});
|
|
29
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
31
|
var import_path = __toModule(require("path"));
|
|
31
32
|
var import_static_utils = __toModule(require("../utils/static-utils.cjs"));
|
|
@@ -44,9 +45,9 @@ var StaticModuleProvider = class {
|
|
|
44
45
|
async getModule(moduleId, runtimeParams) {
|
|
45
46
|
const {specifier} = moduleId;
|
|
46
47
|
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
47
|
-
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
|
|
48
|
+
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
|
|
48
49
|
if (metadata) {
|
|
49
|
-
|
|
50
|
+
import_diagnostics.logger.warn(`[${this.name}] We should not be asking for module source we have in our site metadata ${moduleId.specifier}`);
|
|
50
51
|
return void 0;
|
|
51
52
|
}
|
|
52
53
|
return void 0;
|
|
@@ -54,9 +55,9 @@ var StaticModuleProvider = class {
|
|
|
54
55
|
async getModuleEntry(moduleId, runtimeParams) {
|
|
55
56
|
const {specifier, version} = moduleId;
|
|
56
57
|
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
57
|
-
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
|
|
58
|
+
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
|
|
58
59
|
if (metadata) {
|
|
59
|
-
|
|
60
|
+
import_diagnostics.logger.info(`[${this.name}] Module Entry request for static bundle ${specifier}`);
|
|
60
61
|
const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
61
62
|
const resolvedVersion = (0, import_static_utils.resolveStaticBundleVersion)(metadata.version, version);
|
|
62
63
|
return {
|
|
@@ -26,6 +26,7 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
default: () => static_resource_provider_default
|
|
28
28
|
});
|
|
29
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
31
|
var import_path = __toModule(require("path"));
|
|
31
32
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
@@ -44,7 +45,7 @@ var StaticResourceProvider = class {
|
|
|
44
45
|
const {debug} = runtimeEnvironment;
|
|
45
46
|
const metadata = debug && this.debugSiteResources ? this.debugSiteResources.resources[resourceIdentity.specifier] : this.siteResources.resources[resourceIdentity.specifier];
|
|
46
47
|
if (!metadata) {
|
|
47
|
-
|
|
48
|
+
import_diagnostics.logger.warn(`[${this.name}] Did not find requested specifier ${resourceIdentity.specifier}`);
|
|
48
49
|
return void 0;
|
|
49
50
|
}
|
|
50
51
|
const resourcePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
@@ -52,7 +53,7 @@ var StaticResourceProvider = class {
|
|
|
52
53
|
return {
|
|
53
54
|
type,
|
|
54
55
|
stream: () => {
|
|
55
|
-
|
|
56
|
+
import_diagnostics.logger.info(`[${this.name}] Resource read from lambda ${resourceIdentity.specifier}`);
|
|
56
57
|
return import_fs_extra.default.createReadStream(resourcePath);
|
|
57
58
|
},
|
|
58
59
|
src: resourcePath,
|
|
@@ -28,7 +28,7 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_path = __toModule(require("path"));
|
|
30
30
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
31
|
-
var
|
|
31
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
32
|
var SITE_METADATA_PATH = ".metadata";
|
|
33
33
|
var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
|
|
34
34
|
var DEBUG_STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata-debug.json");
|
|
@@ -79,8 +79,8 @@ var SiteMetadataImpl = class {
|
|
|
79
79
|
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
80
80
|
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
81
81
|
} catch (err) {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
import_diagnostics.logger.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
83
|
+
import_diagnostics.logger.error(err);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
readStaticBundleMetadata(staticRoot, metadataPath) {
|
|
@@ -92,7 +92,7 @@ var SiteMetadataImpl = class {
|
|
|
92
92
|
siteBundles = savedMetadata;
|
|
93
93
|
} catch (error) {
|
|
94
94
|
if (error.code === "ENOENT") {
|
|
95
|
-
|
|
95
|
+
import_diagnostics.logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
96
96
|
} else {
|
|
97
97
|
throw error;
|
|
98
98
|
}
|
|
@@ -108,7 +108,7 @@ var SiteMetadataImpl = class {
|
|
|
108
108
|
siteResources = savedMetadata;
|
|
109
109
|
} catch (error) {
|
|
110
110
|
if (error.code === "ENOENT") {
|
|
111
|
-
|
|
111
|
+
import_diagnostics.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
112
112
|
} else {
|
|
113
113
|
throw error;
|
|
114
114
|
}
|
|
@@ -125,7 +125,7 @@ var SiteMetadataImpl = class {
|
|
|
125
125
|
siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
|
|
126
126
|
} catch (error) {
|
|
127
127
|
if (error.code === "ENOENT") {
|
|
128
|
-
|
|
128
|
+
import_diagnostics.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
129
129
|
} else {
|
|
130
130
|
throw error;
|
|
131
131
|
}
|
|
@@ -31,20 +31,9 @@ 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,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (localizedBundle) {
|
|
40
|
-
return localizedBundle;
|
|
41
|
-
}
|
|
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;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return siteBundles.bundles[specifier];
|
|
34
|
+
async function getLocalizedBundle(specifier, siteBundles, initialLocaleId, i18n) {
|
|
35
|
+
return (0, import_shared_utils.walkLocaleFallbacks)(initialLocaleId, i18n, async (localeId) => {
|
|
36
|
+
const localizedSpecifier = localeId === i18n.defaultLocale ? specifier : `${specifier}|l/${localeId}`;
|
|
37
|
+
return siteBundles.bundles[localizedSpecifier];
|
|
38
|
+
});
|
|
50
39
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
+
import { hashContent, mimeLookup, normalizeResourcePath } from '@lwrjs/shared-utils';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import fs from 'fs-extra';
|
|
4
5
|
export default class StaticAssetProvider {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
+
import { explodeSpecifier, getSpecifier, getFeatureFlags } from '@lwrjs/shared-utils';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import fs from 'fs-extra';
|
|
4
5
|
import { getLocalizedBundle, resolveStaticBundleVersion } from '../utils/static-utils.js';
|
|
@@ -17,10 +18,10 @@ export default class StaticBundleProvider {
|
|
|
17
18
|
}
|
|
18
19
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
19
20
|
const { specifier, name, namespace, version } = moduleId;
|
|
20
|
-
const { debug, defaultLocale } = runtimeEnvironment;
|
|
21
|
+
const { debug, i18n: { defaultLocale }, } = runtimeEnvironment;
|
|
21
22
|
const localeId = (runtimeParams?.locale || defaultLocale);
|
|
22
23
|
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
23
|
-
const metadata = getLocalizedBundle(specifier, siteBundles, localeId, this.i18n);
|
|
24
|
+
const metadata = await getLocalizedBundle(specifier, siteBundles, localeId, this.i18n);
|
|
24
25
|
if (!metadata) {
|
|
25
26
|
// ignore ssr module requests
|
|
26
27
|
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
@@ -30,7 +31,11 @@ export default class StaticBundleProvider {
|
|
|
30
31
|
}
|
|
31
32
|
// Have to make the bundle code available for SSR
|
|
32
33
|
const bundlePath = path.join(this.siteRootDir, metadata.path);
|
|
33
|
-
|
|
34
|
+
// workaround: debug bundles don't exist for SSR in this scenario since it's never actually used
|
|
35
|
+
const skipDebugModeCode = debug && getFeatureFlags().SSR_STATIC_BUNDLES;
|
|
36
|
+
const code = skipDebugModeCode
|
|
37
|
+
? 'throw new Error("Unexpected code reference");'
|
|
38
|
+
: (await fs.readFile(bundlePath)).toString('utf-8');
|
|
34
39
|
const imports = metadata.imports.map((specifier) => {
|
|
35
40
|
const importModule = explodeSpecifier(specifier);
|
|
36
41
|
if (!importModule.version) {
|
|
@@ -39,6 +44,14 @@ export default class StaticBundleProvider {
|
|
|
39
44
|
}
|
|
40
45
|
return importModule;
|
|
41
46
|
});
|
|
47
|
+
const dynamicImports = metadata.dynamicImports?.map((specifier) => {
|
|
48
|
+
const dynamicImportModule = explodeSpecifier(specifier);
|
|
49
|
+
if (!dynamicImportModule.version) {
|
|
50
|
+
// Get version from metadata for un-versioned imports
|
|
51
|
+
dynamicImportModule.version = resolveStaticBundleVersion(this.siteBundles.bundles[specifier]?.version);
|
|
52
|
+
}
|
|
53
|
+
return dynamicImportModule;
|
|
54
|
+
});
|
|
42
55
|
const id = getSpecifier(moduleId);
|
|
43
56
|
const exploded = explodeSpecifier(id);
|
|
44
57
|
// Seem unlikely name was not in the moduleId but just incase set it form the exploded id
|
|
@@ -62,6 +75,7 @@ export default class StaticBundleProvider {
|
|
|
62
75
|
// TODO we need to solve include modules for fingerprints support
|
|
63
76
|
includedModules: metadata.includedModules || [],
|
|
64
77
|
imports,
|
|
78
|
+
dynamicImports,
|
|
65
79
|
},
|
|
66
80
|
src: bundlePath,
|
|
67
81
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
+
import { explodeSpecifier, getSpecifier } from '@lwrjs/shared-utils';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import { getLocalizedBundle, resolveStaticBundleVersion } from '../utils/static-utils.js';
|
|
4
5
|
export default class StaticModuleProvider {
|
|
@@ -17,7 +18,7 @@ export default class StaticModuleProvider {
|
|
|
17
18
|
async getModule(moduleId, runtimeParams) {
|
|
18
19
|
const { specifier } = moduleId;
|
|
19
20
|
const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
|
|
20
|
-
const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
|
|
21
|
+
const metadata = await getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
|
|
21
22
|
if (metadata) {
|
|
22
23
|
logger.warn(`[${this.name}] We should not be asking for module source we have in our site metadata ${moduleId.specifier}`);
|
|
23
24
|
// proceed to next provider
|
|
@@ -30,7 +31,7 @@ export default class StaticModuleProvider {
|
|
|
30
31
|
// TODO shouldn't we be passing the runtime environment here to test?
|
|
31
32
|
const { specifier, version } = moduleId;
|
|
32
33
|
const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
|
|
33
|
-
const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
|
|
34
|
+
const metadata = await getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
|
|
34
35
|
if (metadata) {
|
|
35
36
|
logger.info(`[${this.name}] Module Entry request for static bundle ${specifier}`);
|
|
36
37
|
// Have to make the bundle code available for SSR
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
|
-
import { logger } from '@lwrjs/
|
|
3
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
4
4
|
const SITE_METADATA_PATH = '.metadata';
|
|
5
5
|
const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
|
|
6
6
|
const DEBUG_STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata-debug.json');
|
|
@@ -58,8 +58,8 @@ export class SiteMetadataImpl {
|
|
|
58
58
|
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
|
59
59
|
}
|
|
60
60
|
catch (err) {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
logger.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
62
|
+
logger.error(err);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
readStaticBundleMetadata(staticRoot, metadataPath) {
|
|
@@ -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,
|
|
11
|
+
export declare function getLocalizedBundle(specifier: string, siteBundles: SiteBundles, initialLocaleId: string, i18n: I18NConfig): Promise<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 {
|
|
5
|
+
import { VERSION_NOT_PROVIDED, walkLocaleFallbacks } from '@lwrjs/shared-utils';
|
|
6
6
|
/**
|
|
7
7
|
* Return the version for a static module bundle.
|
|
8
8
|
*
|
|
@@ -14,25 +14,10 @@ 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,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return siteBundles.bundles[
|
|
21
|
-
}
|
|
22
|
-
// Check if there was an exact match for the preferred locale
|
|
23
|
-
const localizedBundle = siteBundles.bundles[`${specifier}|l/${localeId}`];
|
|
24
|
-
if (localizedBundle) {
|
|
25
|
-
return localizedBundle;
|
|
26
|
-
}
|
|
27
|
-
// Else check if there is a match without the county code
|
|
28
|
-
const fallbackId = getFallbackLocale(localeId, i18n);
|
|
29
|
-
if (fallbackId) {
|
|
30
|
-
const localizedBundle = siteBundles.bundles[`${specifier}|l/${fallbackId}`];
|
|
31
|
-
if (localizedBundle) {
|
|
32
|
-
return localizedBundle;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// Else fall back to the non-localized bundle
|
|
36
|
-
return siteBundles.bundles[specifier];
|
|
17
|
+
export async function getLocalizedBundle(specifier, siteBundles, initialLocaleId, i18n) {
|
|
18
|
+
return walkLocaleFallbacks(initialLocaleId, i18n, async (localeId) => {
|
|
19
|
+
const localizedSpecifier = localeId === i18n.defaultLocale ? specifier : `${specifier}|l/${localeId}`;
|
|
20
|
+
return siteBundles.bundles[localizedSpecifier];
|
|
21
|
+
});
|
|
37
22
|
}
|
|
38
23
|
//# sourceMappingURL=static-utils.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.
|
|
7
|
+
"version": "0.11.1",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -48,10 +48,11 @@
|
|
|
48
48
|
"build/**/*.d.ts"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@lwrjs/
|
|
51
|
+
"@lwrjs/diagnostics": "0.11.1",
|
|
52
|
+
"@lwrjs/shared-utils": "0.11.1"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@lwrjs/types": "0.11.
|
|
55
|
+
"@lwrjs/types": "0.11.1",
|
|
55
56
|
"@types/express": "^4.17.17",
|
|
56
57
|
"jest": "^26.6.3",
|
|
57
58
|
"jest-express": "^1.12.0",
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
"volta": {
|
|
65
66
|
"extends": "../../../package.json"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "b7c40fdcd86635dd4e368c0a2e91c5d3374c0fcf"
|
|
68
69
|
}
|