@lwrjs/static 0.11.0-alpha.1 → 0.11.0-alpha.11
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 +8 -3
- package/build/cjs/providers/static-module-provider.cjs +8 -7
- package/build/cjs/providers/static-resource-provider.cjs +7 -4
- package/build/cjs/site-metadata.cjs +29 -15
- package/build/cjs/utils/static-utils.cjs +5 -18
- package/build/es/providers/static-asset-provider.js +2 -1
- package/build/es/providers/static-bundle-provider.d.ts +2 -0
- package/build/es/providers/static-bundle-provider.js +8 -3
- package/build/es/providers/static-module-provider.d.ts +2 -2
- package/build/es/providers/static-module-provider.js +7 -6
- package/build/es/providers/static-resource-provider.d.ts +2 -1
- package/build/es/providers/static-resource-provider.js +8 -3
- package/build/es/site-metadata.d.ts +4 -0
- package/build/es/site-metadata.js +28 -12
- package/build/es/utils/static-utils.d.ts +2 -2
- package/build/es/utils/static-utils.js +6 -23
- 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"));
|
|
@@ -38,16 +39,20 @@ var StaticBundleProvider = class {
|
|
|
38
39
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
39
40
|
}
|
|
40
41
|
this.siteBundles = context.siteMetadata.getSiteBundles();
|
|
42
|
+
this.debugSiteBundles = context.siteMetadata.getDebugSiteBundles();
|
|
41
43
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
42
44
|
this.bundleConfig = context.config.bundleConfig;
|
|
45
|
+
this.i18n = context.config.i18n;
|
|
43
46
|
}
|
|
44
47
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
45
48
|
const {specifier, name, namespace, version} = moduleId;
|
|
46
|
-
const
|
|
47
|
-
const
|
|
49
|
+
const {debug, defaultLocale} = runtimeEnvironment;
|
|
50
|
+
const localeId = runtimeParams?.locale || defaultLocale;
|
|
51
|
+
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
52
|
+
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
48
53
|
if (!metadata) {
|
|
49
54
|
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
50
|
-
|
|
55
|
+
import_diagnostics.logger.warn(`[${this.name}] did not find requested specifier ${specifier}`);
|
|
51
56
|
}
|
|
52
57
|
return void 0;
|
|
53
58
|
}
|
|
@@ -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"));
|
|
@@ -38,25 +39,25 @@ var StaticModuleProvider = class {
|
|
|
38
39
|
this.externals = Object.keys(context.config.bundleConfig.external || {});
|
|
39
40
|
this.siteBundles = context.siteMetadata.getSiteBundles();
|
|
40
41
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
41
|
-
this.
|
|
42
|
+
this.i18n = context.config.i18n;
|
|
42
43
|
this.fingerprintIndex = buildFingerprintsIndex(context);
|
|
43
44
|
}
|
|
44
45
|
async getModule(moduleId, runtimeParams) {
|
|
45
46
|
const {specifier} = moduleId;
|
|
46
|
-
const localeId = runtimeParams?.locale || this.
|
|
47
|
-
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.
|
|
47
|
+
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
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;
|
|
53
54
|
}
|
|
54
55
|
async getModuleEntry(moduleId, runtimeParams) {
|
|
55
56
|
const {specifier, version} = moduleId;
|
|
56
|
-
const localeId = runtimeParams?.locale || this.
|
|
57
|
-
const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.
|
|
57
|
+
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
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"));
|
|
@@ -37,12 +38,14 @@ var StaticResourceProvider = class {
|
|
|
37
38
|
}
|
|
38
39
|
this.resourceRegistry = context.resourceRegistry;
|
|
39
40
|
this.siteResources = context.siteMetadata.getSiteResources();
|
|
41
|
+
this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
|
|
40
42
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
41
43
|
}
|
|
42
|
-
async getResource(resourceIdentity,
|
|
43
|
-
const
|
|
44
|
+
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
45
|
+
const {debug} = runtimeEnvironment;
|
|
46
|
+
const metadata = debug && this.debugSiteResources ? this.debugSiteResources.resources[resourceIdentity.specifier] : this.siteResources.resources[resourceIdentity.specifier];
|
|
44
47
|
if (!metadata) {
|
|
45
|
-
|
|
48
|
+
import_diagnostics.logger.warn(`[${this.name}] Did not find requested specifier ${resourceIdentity.specifier}`);
|
|
46
49
|
return void 0;
|
|
47
50
|
}
|
|
48
51
|
const resourcePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
@@ -50,7 +53,7 @@ var StaticResourceProvider = class {
|
|
|
50
53
|
return {
|
|
51
54
|
type,
|
|
52
55
|
stream: () => {
|
|
53
|
-
|
|
56
|
+
import_diagnostics.logger.info(`[${this.name}] Resource read from lambda ${resourceIdentity.specifier}`);
|
|
54
57
|
return import_fs_extra.default.createReadStream(resourcePath);
|
|
55
58
|
},
|
|
56
59
|
src: resourcePath,
|
|
@@ -28,17 +28,21 @@ __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
|
+
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,58 +70,62 @@ 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) {
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
import_diagnostics.logger.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
83
|
+
import_diagnostics.logger.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) {
|
|
80
94
|
if (error.code === "ENOENT") {
|
|
81
|
-
|
|
95
|
+
import_diagnostics.logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
82
96
|
} else {
|
|
83
97
|
throw error;
|
|
84
98
|
}
|
|
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) {
|
|
96
110
|
if (error.code === "ENOENT") {
|
|
97
|
-
|
|
111
|
+
import_diagnostics.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
98
112
|
} else {
|
|
99
113
|
throw error;
|
|
100
114
|
}
|
|
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") {
|
|
114
|
-
|
|
128
|
+
import_diagnostics.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
115
129
|
} else {
|
|
116
130
|
throw error;
|
|
117
131
|
}
|
|
@@ -31,22 +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
|
-
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
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
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
|
+
});
|
|
52
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 {
|
|
@@ -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
|
}
|
|
@@ -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 fs from 'fs-extra';
|
|
4
5
|
import { getLocalizedBundle, resolveStaticBundleVersion } from '../utils/static-utils.js';
|
|
@@ -10,13 +11,17 @@ export default class StaticBundleProvider {
|
|
|
10
11
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
11
12
|
}
|
|
12
13
|
this.siteBundles = context.siteMetadata.getSiteBundles();
|
|
14
|
+
this.debugSiteBundles = context.siteMetadata.getDebugSiteBundles();
|
|
13
15
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
14
16
|
this.bundleConfig = context.config.bundleConfig;
|
|
17
|
+
this.i18n = context.config.i18n;
|
|
15
18
|
}
|
|
16
19
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
17
20
|
const { specifier, name, namespace, version } = moduleId;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
21
|
+
const { debug, defaultLocale } = runtimeEnvironment;
|
|
22
|
+
const localeId = (runtimeParams?.locale || defaultLocale);
|
|
23
|
+
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
24
|
+
const metadata = await getLocalizedBundle(specifier, siteBundles, localeId, this.i18n);
|
|
20
25
|
if (!metadata) {
|
|
21
26
|
// ignore ssr module requests
|
|
22
27
|
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>;
|
|
@@ -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 {
|
|
@@ -10,14 +11,14 @@ export default class StaticModuleProvider {
|
|
|
10
11
|
this.externals = Object.keys(context.config.bundleConfig.external || {});
|
|
11
12
|
this.siteBundles = context.siteMetadata.getSiteBundles();
|
|
12
13
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
13
|
-
this.
|
|
14
|
+
this.i18n = context.config.i18n;
|
|
14
15
|
// If we are using fingerprints collect all the specifiers in the bundles and add them to an index for creating the mapping identities
|
|
15
16
|
this.fingerprintIndex = buildFingerprintsIndex(context);
|
|
16
17
|
}
|
|
17
18
|
async getModule(moduleId, runtimeParams) {
|
|
18
19
|
const { specifier } = moduleId;
|
|
19
|
-
const localeId = (runtimeParams?.locale || this.
|
|
20
|
-
const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.
|
|
20
|
+
const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
|
|
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
|
|
@@ -29,8 +30,8 @@ export default class StaticModuleProvider {
|
|
|
29
30
|
async getModuleEntry(moduleId, runtimeParams) {
|
|
30
31
|
// TODO shouldn't we be passing the runtime environment here to test?
|
|
31
32
|
const { specifier, version } = moduleId;
|
|
32
|
-
const localeId = (runtimeParams?.locale || this.
|
|
33
|
-
const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.
|
|
33
|
+
const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
|
|
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
|
|
@@ -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
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { logger
|
|
1
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
+
import { mimeLookup } from '@lwrjs/shared-utils';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import fs from 'fs-extra';
|
|
4
5
|
export default class StaticResourceProvider {
|
|
@@ -9,10 +10,14 @@ export default class StaticResourceProvider {
|
|
|
9
10
|
}
|
|
10
11
|
this.resourceRegistry = context.resourceRegistry;
|
|
11
12
|
this.siteResources = context.siteMetadata.getSiteResources();
|
|
13
|
+
this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
|
|
12
14
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
13
15
|
}
|
|
14
|
-
async getResource(resourceIdentity,
|
|
15
|
-
const
|
|
16
|
+
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
17
|
+
const { debug } = runtimeEnvironment;
|
|
18
|
+
const metadata = debug && this.debugSiteResources
|
|
19
|
+
? this.debugSiteResources.resources[resourceIdentity.specifier]
|
|
20
|
+
: this.siteResources.resources[resourceIdentity.specifier];
|
|
16
21
|
if (!metadata) {
|
|
17
22
|
logger.warn(`[${this.name}] Did not find requested specifier ${resourceIdentity.specifier}`);
|
|
18
23
|
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;
|
|
@@ -1,16 +1,20 @@
|
|
|
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
|
+
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,23 +44,29 @@ 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 });
|
|
43
59
|
}
|
|
44
60
|
catch (err) {
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
logger.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
62
|
+
logger.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,
|
|
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,27 +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
|
-
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
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Else fall back to the non-localized bundle
|
|
38
|
-
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
|
+
});
|
|
39
22
|
}
|
|
40
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.0-alpha.
|
|
7
|
+
"version": "0.11.0-alpha.11",
|
|
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.0-alpha.11",
|
|
52
|
+
"@lwrjs/shared-utils": "0.11.0-alpha.11"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@lwrjs/types": "0.11.0-alpha.
|
|
55
|
+
"@lwrjs/types": "0.11.0-alpha.11",
|
|
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": "acb9df6ee7887b683e28ad43e00df311256d6018"
|
|
68
69
|
}
|