@lwrjs/static 0.11.0-alpha.4 → 0.11.0-alpha.7
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-bundle-provider.cjs +6 -2
- package/build/cjs/providers/static-module-provider.cjs +5 -5
- package/build/cjs/providers/static-resource-provider.cjs +4 -2
- package/build/cjs/site-metadata.cjs +23 -9
- package/build/cjs/utils/static-utils.cjs +7 -9
- package/build/es/providers/static-bundle-provider.d.ts +2 -0
- package/build/es/providers/static-bundle-provider.js +6 -2
- package/build/es/providers/static-module-provider.d.ts +2 -2
- package/build/es/providers/static-module-provider.js +5 -5
- package/build/es/providers/static-resource-provider.d.ts +2 -1
- package/build/es/providers/static-resource-provider.js +6 -2
- package/build/es/site-metadata.d.ts +4 -0
- package/build/es/site-metadata.js +25 -9
- package/build/es/utils/static-utils.d.ts +2 -2
- package/build/es/utils/static-utils.js +8 -10
- package/package.json +4 -4
|
@@ -38,13 +38,17 @@ var StaticBundleProvider = class {
|
|
|
38
38
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
39
39
|
}
|
|
40
40
|
this.siteBundles = context.siteMetadata.getSiteBundles();
|
|
41
|
+
this.debugSiteBundles = context.siteMetadata.getDebugSiteBundles();
|
|
41
42
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
42
43
|
this.bundleConfig = context.config.bundleConfig;
|
|
44
|
+
this.i18n = context.config.i18n;
|
|
43
45
|
}
|
|
44
46
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
45
47
|
const {specifier, name, namespace, version} = moduleId;
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
+
const {debug, defaultLocale} = runtimeEnvironment;
|
|
49
|
+
const localeId = runtimeParams?.locale || defaultLocale;
|
|
50
|
+
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
51
|
+
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
48
52
|
if (!metadata) {
|
|
49
53
|
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
50
54
|
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.
|
|
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.
|
|
47
|
-
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.
|
|
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.
|
|
57
|
-
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.
|
|
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);
|
|
@@ -37,10 +37,12 @@ var StaticResourceProvider = class {
|
|
|
37
37
|
}
|
|
38
38
|
this.resourceRegistry = context.resourceRegistry;
|
|
39
39
|
this.siteResources = context.siteMetadata.getSiteResources();
|
|
40
|
+
this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
|
|
40
41
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
41
42
|
}
|
|
42
|
-
async getResource(resourceIdentity,
|
|
43
|
-
const
|
|
43
|
+
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
44
|
+
const {debug} = runtimeEnvironment;
|
|
45
|
+
const metadata = debug && this.debugSiteResources ? this.debugSiteResources.resources[resourceIdentity.specifier] : this.siteResources.resources[resourceIdentity.specifier];
|
|
44
46
|
if (!metadata) {
|
|
45
47
|
import_shared_utils.logger.warn(`[${this.name}] Did not find requested specifier ${resourceIdentity.specifier}`);
|
|
46
48
|
return void 0;
|
|
@@ -31,14 +31,18 @@ var import_fs_extra = __toModule(require("fs-extra"));
|
|
|
31
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
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
|
+
var DEBUG_STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata-debug.json");
|
|
34
35
|
var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
|
|
36
|
+
var DEBUG_STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata-debug.json");
|
|
35
37
|
var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
|
|
36
38
|
var SiteMetadataImpl = class {
|
|
37
39
|
constructor(options) {
|
|
38
40
|
this.options = options;
|
|
39
|
-
this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
41
|
+
this.siteBundles = this.readStaticBundleMetadata(options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
42
|
+
this.debugSiteBundles = this.readStaticBundleMetadata(options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
|
|
43
|
+
this.siteResources = this.readStaticResourceMetadata(options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
44
|
+
this.debugSiteResources = this.readStaticResourceMetadata(options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
|
|
45
|
+
this.siteAssets = this.readStaticAssetsMetadata(options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
42
46
|
}
|
|
43
47
|
getSiteRootDir() {
|
|
44
48
|
return this.options.rootDir;
|
|
@@ -46,9 +50,15 @@ var SiteMetadataImpl = class {
|
|
|
46
50
|
getSiteBundles() {
|
|
47
51
|
return this.siteBundles;
|
|
48
52
|
}
|
|
53
|
+
getDebugSiteBundles() {
|
|
54
|
+
return this.debugSiteBundles;
|
|
55
|
+
}
|
|
49
56
|
getSiteResources() {
|
|
50
57
|
return this.siteResources;
|
|
51
58
|
}
|
|
59
|
+
getDebugSiteResources() {
|
|
60
|
+
return this.debugSiteResources;
|
|
61
|
+
}
|
|
52
62
|
getSiteAssets() {
|
|
53
63
|
return this.siteAssets;
|
|
54
64
|
}
|
|
@@ -60,8 +70,12 @@ var SiteMetadataImpl = class {
|
|
|
60
70
|
}
|
|
61
71
|
const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
62
72
|
await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
|
|
73
|
+
const debugBundleMetadataPath = import_path.default.join(this.options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
|
|
74
|
+
await import_fs_extra.default.writeJSON(debugBundleMetadataPath, this.debugSiteBundles, {spaces: 2});
|
|
63
75
|
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
64
76
|
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
77
|
+
const debugResourceMetadataPath = import_path.default.join(this.options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
|
|
78
|
+
await import_fs_extra.default.writeJSON(debugResourceMetadataPath, this.siteResources, {spaces: 2});
|
|
65
79
|
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
66
80
|
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
67
81
|
} catch (err) {
|
|
@@ -69,11 +83,11 @@ var SiteMetadataImpl = class {
|
|
|
69
83
|
console.error(err);
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
|
-
readStaticBundleMetadata(staticRoot) {
|
|
86
|
+
readStaticBundleMetadata(staticRoot, metadataPath) {
|
|
73
87
|
let bundleMetadataPath;
|
|
74
88
|
let siteBundles = {bundles: {}};
|
|
75
89
|
try {
|
|
76
|
-
bundleMetadataPath = import_path.default.join(staticRoot,
|
|
90
|
+
bundleMetadataPath = import_path.default.join(staticRoot, metadataPath);
|
|
77
91
|
const savedMetadata = import_fs_extra.default.readJSONSync(bundleMetadataPath);
|
|
78
92
|
siteBundles = savedMetadata;
|
|
79
93
|
} catch (error) {
|
|
@@ -85,11 +99,11 @@ var SiteMetadataImpl = class {
|
|
|
85
99
|
}
|
|
86
100
|
return siteBundles;
|
|
87
101
|
}
|
|
88
|
-
readStaticResourceMetadata(staticRoot) {
|
|
102
|
+
readStaticResourceMetadata(staticRoot, metadataPath) {
|
|
89
103
|
let resourceMetadataPath;
|
|
90
104
|
let siteResources = {resources: {}};
|
|
91
105
|
try {
|
|
92
|
-
resourceMetadataPath = import_path.default.join(staticRoot,
|
|
106
|
+
resourceMetadataPath = import_path.default.join(staticRoot, metadataPath);
|
|
93
107
|
const savedMetadata = import_fs_extra.default.readJSONSync(resourceMetadataPath);
|
|
94
108
|
siteResources = savedMetadata;
|
|
95
109
|
} catch (error) {
|
|
@@ -101,13 +115,13 @@ var SiteMetadataImpl = class {
|
|
|
101
115
|
}
|
|
102
116
|
return siteResources;
|
|
103
117
|
}
|
|
104
|
-
readStaticAssetsMetadata(staticRoot) {
|
|
118
|
+
readStaticAssetsMetadata(staticRoot, metadataPath) {
|
|
105
119
|
let assetMetadataPath;
|
|
106
120
|
let siteAssets = {
|
|
107
121
|
assets: {}
|
|
108
122
|
};
|
|
109
123
|
try {
|
|
110
|
-
assetMetadataPath = import_path.default.join(staticRoot,
|
|
124
|
+
assetMetadataPath = import_path.default.join(staticRoot, metadataPath);
|
|
111
125
|
siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
|
|
112
126
|
} catch (error) {
|
|
113
127
|
if (error.code === "ENOENT") {
|
|
@@ -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,
|
|
35
|
-
if (localeId ===
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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];
|
|
@@ -2,8 +2,10 @@ import type { AbstractModuleId, BundleDefinition, BundleProvider, ProviderContex
|
|
|
2
2
|
export default class StaticBundleProvider implements BundleProvider {
|
|
3
3
|
name: string;
|
|
4
4
|
siteBundles: import("@lwrjs/types").SiteBundles;
|
|
5
|
+
debugSiteBundles?: import("@lwrjs/types").SiteBundles | undefined;
|
|
5
6
|
siteRootDir: string;
|
|
6
7
|
bundleConfig: import("@lwrjs/types").BundleConfig;
|
|
8
|
+
i18n: import("@lwrjs/types").I18NConfig;
|
|
7
9
|
constructor(_config: {}, context: ProviderContext);
|
|
8
10
|
bundle<BundleIdentifier extends AbstractModuleId, RE extends RuntimeEnvironment>(moduleId: BundleIdentifier, runtimeEnvironment: RE, runtimeParams: RuntimeParams): Promise<BundleDefinition | undefined>;
|
|
9
11
|
}
|
|
@@ -10,13 +10,17 @@ export default class StaticBundleProvider {
|
|
|
10
10
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
11
11
|
}
|
|
12
12
|
this.siteBundles = context.siteMetadata.getSiteBundles();
|
|
13
|
+
this.debugSiteBundles = context.siteMetadata.getDebugSiteBundles();
|
|
13
14
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
14
15
|
this.bundleConfig = context.config.bundleConfig;
|
|
16
|
+
this.i18n = context.config.i18n;
|
|
15
17
|
}
|
|
16
18
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
17
19
|
const { specifier, name, namespace, version } = moduleId;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
+
const { debug, defaultLocale } = runtimeEnvironment;
|
|
21
|
+
const localeId = (runtimeParams?.locale || defaultLocale);
|
|
22
|
+
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
23
|
+
const metadata = getLocalizedBundle(specifier, siteBundles, localeId, this.i18n);
|
|
20
24
|
if (!metadata) {
|
|
21
25
|
// ignore ssr module requests
|
|
22
26
|
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AbstractModuleId, ModuleCompiled, ModuleEntry, ModuleProvider, ProviderContext,
|
|
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
|
-
|
|
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.
|
|
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.
|
|
20
|
-
const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.
|
|
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.
|
|
33
|
-
const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.
|
|
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
|
|
@@ -2,9 +2,10 @@ import type { BootstrapRuntimeEnvironment, ProviderContext, ResourceDefinition,
|
|
|
2
2
|
export default class StaticResourceProvider implements ResourceProvider {
|
|
3
3
|
name: string;
|
|
4
4
|
siteResources: import("@lwrjs/types").SiteResources;
|
|
5
|
+
debugSiteResources: import("@lwrjs/types").SiteResources;
|
|
5
6
|
siteRootDir: string;
|
|
6
7
|
resourceRegistry: import("@lwrjs/types").PublicResourceRegistry;
|
|
7
8
|
constructor(_config: {}, context: ProviderContext);
|
|
8
|
-
getResource<Identifier extends ResourceIdentifier, RuntimeEnvironment extends BootstrapRuntimeEnvironment>(resourceIdentity: Identifier,
|
|
9
|
+
getResource<Identifier extends ResourceIdentifier, RuntimeEnvironment extends BootstrapRuntimeEnvironment>(resourceIdentity: Identifier, runtimeEnvironment: RuntimeEnvironment): Promise<ResourceDefinition | undefined>;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=static-resource-provider.d.ts.map
|
|
@@ -9,10 +9,14 @@ export default class StaticResourceProvider {
|
|
|
9
9
|
}
|
|
10
10
|
this.resourceRegistry = context.resourceRegistry;
|
|
11
11
|
this.siteResources = context.siteMetadata.getSiteResources();
|
|
12
|
+
this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
|
|
12
13
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
13
14
|
}
|
|
14
|
-
async getResource(resourceIdentity,
|
|
15
|
-
const
|
|
15
|
+
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
16
|
+
const { debug } = runtimeEnvironment;
|
|
17
|
+
const metadata = debug && this.debugSiteResources
|
|
18
|
+
? this.debugSiteResources.resources[resourceIdentity.specifier]
|
|
19
|
+
: this.siteResources.resources[resourceIdentity.specifier];
|
|
16
20
|
if (!metadata) {
|
|
17
21
|
logger.warn(`[${this.name}] Did not find requested specifier ${resourceIdentity.specifier}`);
|
|
18
22
|
return undefined;
|
|
@@ -5,12 +5,16 @@ type Options = {
|
|
|
5
5
|
export declare class SiteMetadataImpl implements SiteMetadata {
|
|
6
6
|
private options;
|
|
7
7
|
private siteBundles;
|
|
8
|
+
private debugSiteBundles;
|
|
8
9
|
private siteResources;
|
|
10
|
+
private debugSiteResources;
|
|
9
11
|
private siteAssets;
|
|
10
12
|
constructor(options: Options);
|
|
11
13
|
getSiteRootDir(): string;
|
|
12
14
|
getSiteBundles(): SiteBundles;
|
|
15
|
+
getDebugSiteBundles(): SiteBundles;
|
|
13
16
|
getSiteResources(): SiteResources;
|
|
17
|
+
getDebugSiteResources(): SiteResources;
|
|
14
18
|
getSiteAssets(): SiteAssets;
|
|
15
19
|
persistSiteMetadata(): Promise<void>;
|
|
16
20
|
private readStaticBundleMetadata;
|
|
@@ -3,14 +3,18 @@ import fs from 'fs-extra';
|
|
|
3
3
|
import { logger } from '@lwrjs/shared-utils';
|
|
4
4
|
const SITE_METADATA_PATH = '.metadata';
|
|
5
5
|
const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
|
|
6
|
+
const DEBUG_STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata-debug.json');
|
|
6
7
|
const STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata.json');
|
|
8
|
+
const DEBUG_STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata-debug.json');
|
|
7
9
|
const STATIC_ASSET_METADATA_PATH = path.join(SITE_METADATA_PATH, '/asset-metadata.json');
|
|
8
10
|
export class SiteMetadataImpl {
|
|
9
11
|
constructor(options) {
|
|
10
12
|
this.options = options;
|
|
11
|
-
this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
13
|
+
this.siteBundles = this.readStaticBundleMetadata(options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
14
|
+
this.debugSiteBundles = this.readStaticBundleMetadata(options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
|
|
15
|
+
this.siteResources = this.readStaticResourceMetadata(options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
16
|
+
this.debugSiteResources = this.readStaticResourceMetadata(options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
|
|
17
|
+
this.siteAssets = this.readStaticAssetsMetadata(options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
14
18
|
}
|
|
15
19
|
getSiteRootDir() {
|
|
16
20
|
return this.options.rootDir;
|
|
@@ -18,9 +22,15 @@ export class SiteMetadataImpl {
|
|
|
18
22
|
getSiteBundles() {
|
|
19
23
|
return this.siteBundles;
|
|
20
24
|
}
|
|
25
|
+
getDebugSiteBundles() {
|
|
26
|
+
return this.debugSiteBundles;
|
|
27
|
+
}
|
|
21
28
|
getSiteResources() {
|
|
22
29
|
return this.siteResources;
|
|
23
30
|
}
|
|
31
|
+
getDebugSiteResources() {
|
|
32
|
+
return this.debugSiteResources;
|
|
33
|
+
}
|
|
24
34
|
getSiteAssets() {
|
|
25
35
|
return this.siteAssets;
|
|
26
36
|
}
|
|
@@ -34,9 +44,15 @@ export class SiteMetadataImpl {
|
|
|
34
44
|
// Save Bundle Metadata
|
|
35
45
|
const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
36
46
|
await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
|
|
47
|
+
// Save Debug Bundle Metadata
|
|
48
|
+
const debugBundleMetadataPath = path.join(this.options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
|
|
49
|
+
await fs.writeJSON(debugBundleMetadataPath, this.debugSiteBundles, { spaces: 2 });
|
|
37
50
|
// Save Resource Metadata
|
|
38
51
|
const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
39
52
|
await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
53
|
+
// Save Debug Resource Metadata
|
|
54
|
+
const debugResourceMetadataPath = path.join(this.options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
|
|
55
|
+
await fs.writeJSON(debugResourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
40
56
|
// Save Resource Metadata
|
|
41
57
|
const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
42
58
|
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
|
@@ -46,11 +62,11 @@ export class SiteMetadataImpl {
|
|
|
46
62
|
console.error(err);
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
|
-
readStaticBundleMetadata(staticRoot) {
|
|
65
|
+
readStaticBundleMetadata(staticRoot, metadataPath) {
|
|
50
66
|
let bundleMetadataPath;
|
|
51
67
|
let siteBundles = { bundles: {} };
|
|
52
68
|
try {
|
|
53
|
-
bundleMetadataPath = path.join(staticRoot,
|
|
69
|
+
bundleMetadataPath = path.join(staticRoot, metadataPath);
|
|
54
70
|
const savedMetadata = fs.readJSONSync(bundleMetadataPath);
|
|
55
71
|
siteBundles = savedMetadata;
|
|
56
72
|
}
|
|
@@ -67,11 +83,11 @@ export class SiteMetadataImpl {
|
|
|
67
83
|
/**
|
|
68
84
|
* Read the metadata about the pre-built resources of the current site.
|
|
69
85
|
*/
|
|
70
|
-
readStaticResourceMetadata(staticRoot) {
|
|
86
|
+
readStaticResourceMetadata(staticRoot, metadataPath) {
|
|
71
87
|
let resourceMetadataPath;
|
|
72
88
|
let siteResources = { resources: {} };
|
|
73
89
|
try {
|
|
74
|
-
resourceMetadataPath = path.join(staticRoot,
|
|
90
|
+
resourceMetadataPath = path.join(staticRoot, metadataPath);
|
|
75
91
|
const savedMetadata = fs.readJSONSync(resourceMetadataPath);
|
|
76
92
|
siteResources = savedMetadata;
|
|
77
93
|
}
|
|
@@ -88,13 +104,13 @@ export class SiteMetadataImpl {
|
|
|
88
104
|
/**
|
|
89
105
|
* Read the metadata about the pre-built assets of the current site.
|
|
90
106
|
*/
|
|
91
|
-
readStaticAssetsMetadata(staticRoot) {
|
|
107
|
+
readStaticAssetsMetadata(staticRoot, metadataPath) {
|
|
92
108
|
let assetMetadataPath;
|
|
93
109
|
let siteAssets = {
|
|
94
110
|
assets: {},
|
|
95
111
|
};
|
|
96
112
|
try {
|
|
97
|
-
assetMetadataPath = path.join(staticRoot,
|
|
113
|
+
assetMetadataPath = path.join(staticRoot, metadataPath);
|
|
98
114
|
siteAssets = fs.readJSONSync(assetMetadataPath);
|
|
99
115
|
}
|
|
100
116
|
catch (error) {
|
|
@@ -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,
|
|
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 {
|
|
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,
|
|
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 ===
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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.
|
|
7
|
+
"version": "0.11.0-alpha.7",
|
|
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.
|
|
51
|
+
"@lwrjs/shared-utils": "0.11.0-alpha.7"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@lwrjs/types": "0.11.0-alpha.
|
|
54
|
+
"@lwrjs/types": "0.11.0-alpha.7",
|
|
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": "
|
|
67
|
+
"gitHead": "872180fbd00df214ab91971d7ec80ba138a73756"
|
|
68
68
|
}
|