@lwrjs/static 0.21.8 → 0.22.2
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 +2 -2
- package/build/cjs/providers/static-bundle-provider.cjs +2 -2
- package/build/cjs/providers/static-module-provider.cjs +2 -3
- package/build/cjs/providers/static-resource-provider.cjs +1 -1
- package/build/cjs/tools/dedupe-bundles.cjs +2 -2
- package/build/es/providers/static-asset-provider.js +4 -9
- package/build/es/providers/static-bundle-provider.js +4 -10
- package/build/es/providers/static-module-provider.js +4 -10
- package/build/es/providers/static-resource-provider.js +3 -6
- package/build/es/site-metadata.js +0 -8
- package/build/es/tools/dedupe-bundles.js +3 -3
- package/build/es/utils/decision-tree.js +5 -6
- package/package.json +7 -7
|
@@ -64,14 +64,14 @@ var StaticAssetProvider = class {
|
|
|
64
64
|
}
|
|
65
65
|
return void 0;
|
|
66
66
|
}
|
|
67
|
-
const siteAssetPath =
|
|
67
|
+
const siteAssetPath = (0, import_shared_utils.joinUrlPath)(this.siteRootDir, metadata.path);
|
|
68
68
|
const mime = metadata.mimeType || (0, import_shared_utils.mimeLookup)(siteAssetPath);
|
|
69
69
|
const ext = import_path.default.extname(`x.${siteAssetPath}`).toLowerCase().substring(1);
|
|
70
70
|
const type = this.assetsOnLambda ? "asset" : "external";
|
|
71
71
|
const content = function(encoding) {
|
|
72
72
|
return import_fs_extra.default.readFileSync(siteAssetPath, encoding);
|
|
73
73
|
};
|
|
74
|
-
const uri = this.assetsOnLambda ? fileAssetPath :
|
|
74
|
+
const uri = this.assetsOnLambda ? fileAssetPath : (0, import_shared_utils.joinUrlPath)(this.siteRootDir, fileAssetPath);
|
|
75
75
|
import_diagnostics.logger.debug({label: `${this.name}`, message: `uri ${assetIdentifier.specifier} -> ${uri}`});
|
|
76
76
|
return {
|
|
77
77
|
entry: siteAssetPath,
|
|
@@ -85,7 +85,7 @@ var StaticBundleProvider = class {
|
|
|
85
85
|
this.logBundleError(moduleId, localeId, debug, ssr);
|
|
86
86
|
return void 0;
|
|
87
87
|
}
|
|
88
|
-
const bundlePath =
|
|
88
|
+
const bundlePath = (0, import_shared_utils.joinUrlPath)(this.siteRootDir, metadata.path);
|
|
89
89
|
const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
|
|
90
90
|
const codePromiser = this.getCodePromiser(resolvedBundlePath, {
|
|
91
91
|
specifier,
|
|
@@ -238,7 +238,7 @@ var StaticBundleProvider = class {
|
|
|
238
238
|
});
|
|
239
239
|
return BUNDLE_SOURCE_NOT_FOUND;
|
|
240
240
|
}
|
|
241
|
-
bundleSourcePath =
|
|
241
|
+
bundleSourcePath = (0, import_shared_utils.joinUrlPath)(this.siteRootDir, metadata.path);
|
|
242
242
|
}
|
|
243
243
|
return bundleSourcePath;
|
|
244
244
|
}
|
|
@@ -28,7 +28,6 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
|
-
var import_path = __toModule(require("path"));
|
|
32
31
|
var import_site_metadata = __toModule(require("../site-metadata.cjs"));
|
|
33
32
|
var StaticModuleProvider = class {
|
|
34
33
|
constructor(_config, context) {
|
|
@@ -65,7 +64,7 @@ var StaticModuleProvider = class {
|
|
|
65
64
|
label: `${this.name}`,
|
|
66
65
|
message: `Module Entry request for static bundle ${specifier}`
|
|
67
66
|
});
|
|
68
|
-
const bundlePath =
|
|
67
|
+
const bundlePath = (0, import_shared_utils.joinUrlPath)(this.siteRootDir, metadata.path);
|
|
69
68
|
const resolvedVersion = (0, import_site_metadata.resolveStaticBundleVersion)(metadata.version, version);
|
|
70
69
|
return {
|
|
71
70
|
id: (0, import_shared_utils.getSpecifier)({...moduleId, version: resolvedVersion}),
|
|
@@ -105,7 +104,7 @@ function buildFingerprintsIndex(context) {
|
|
|
105
104
|
if (!context.runtimeEnvironment.featureFlags.LEGACY_LOADER) {
|
|
106
105
|
const bundles = context.siteMetadata?.getSiteBundles().bundles || {};
|
|
107
106
|
for (const bundle of Object.values(bundles)) {
|
|
108
|
-
const bundlePath =
|
|
107
|
+
const bundlePath = (0, import_shared_utils.joinUrlPath)(String(context.siteMetadata?.getSiteRootDir()), bundle.path);
|
|
109
108
|
const includedModules = bundle.includedModules || [];
|
|
110
109
|
for (const includedModule of includedModules) {
|
|
111
110
|
const versionedSpecifier = convertSiteIdToVersionedSpecifier(includedModule);
|
|
@@ -52,7 +52,7 @@ var StaticResourceProvider = class {
|
|
|
52
52
|
});
|
|
53
53
|
return void 0;
|
|
54
54
|
}
|
|
55
|
-
const resourcePath =
|
|
55
|
+
const resourcePath = (0, import_shared_utils.joinUrlPath)(this.siteRootDir, resourceMetadata.path);
|
|
56
56
|
const type = resourceMetadata.mimeType || (0, import_shared_utils.mimeLookup)(resourcePath) || "application/javascript";
|
|
57
57
|
return {
|
|
58
58
|
type,
|
|
@@ -48,7 +48,7 @@ async function dedupeBundles(rootDir, i18n) {
|
|
|
48
48
|
if (!localeId || localeId === i18n.defaultLocale) {
|
|
49
49
|
continue;
|
|
50
50
|
}
|
|
51
|
-
const currentPath =
|
|
51
|
+
const currentPath = (0, import_shared_utils.joinUrlPath)(rootDir, metadata.path);
|
|
52
52
|
const currentSrc = import_fs_extra.default.readFileSync(currentPath);
|
|
53
53
|
import_diagnostics.logger.debug({
|
|
54
54
|
label: `dedupeBundles`,
|
|
@@ -58,7 +58,7 @@ async function dedupeBundles(rootDir, i18n) {
|
|
|
58
58
|
const fallBackLocale = locale?.fallback ?? i18n.defaultLocale;
|
|
59
59
|
const fallbackMetadata = decisionTree.find(siteIdStr, false, false, fallBackLocale);
|
|
60
60
|
if (fallbackMetadata) {
|
|
61
|
-
const fallbackSrc = import_fs_extra.default.readFileSync(
|
|
61
|
+
const fallbackSrc = import_fs_extra.default.readFileSync((0, import_shared_utils.joinUrlPath)(rootDir, fallbackMetadata.path));
|
|
62
62
|
import_diagnostics.logger.debug({
|
|
63
63
|
label: `dedupeBundles`,
|
|
64
64
|
message: `fallback ${siteIdStr},${fallBackLocale} -> ${(0, import_shared_utils.hashContent)(fallbackSrc)}`
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { hashContent, mimeLookup, normalizeResourcePath } from '@lwrjs/shared-utils';
|
|
2
|
+
import { hashContent, joinUrlPath, mimeLookup, normalizeResourcePath } from '@lwrjs/shared-utils';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
export default class StaticAssetProvider {
|
|
6
|
-
name = 'static-asset-provider';
|
|
7
|
-
siteAssets;
|
|
8
|
-
resourcePaths;
|
|
9
|
-
siteRootDir;
|
|
10
|
-
basePath;
|
|
11
|
-
assetsOnLambda;
|
|
12
6
|
constructor(_config, context) {
|
|
7
|
+
this.name = 'static-asset-provider';
|
|
13
8
|
if (!context.siteMetadata) {
|
|
14
9
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
15
10
|
}
|
|
@@ -46,7 +41,7 @@ export default class StaticAssetProvider {
|
|
|
46
41
|
return undefined;
|
|
47
42
|
}
|
|
48
43
|
// FS path including ssg root
|
|
49
|
-
const siteAssetPath =
|
|
44
|
+
const siteAssetPath = joinUrlPath(this.siteRootDir, metadata.path);
|
|
50
45
|
// Figure out mime type
|
|
51
46
|
const mime = metadata.mimeType || mimeLookup(siteAssetPath);
|
|
52
47
|
// Normalize extension
|
|
@@ -57,7 +52,7 @@ export default class StaticAssetProvider {
|
|
|
57
52
|
return fs.readFileSync(siteAssetPath, encoding);
|
|
58
53
|
};
|
|
59
54
|
// Create URI
|
|
60
|
-
const uri = this.assetsOnLambda ? fileAssetPath :
|
|
55
|
+
const uri = this.assetsOnLambda ? fileAssetPath : joinUrlPath(this.siteRootDir, fileAssetPath);
|
|
61
56
|
logger.debug({ label: `${this.name}`, message: `uri ${assetIdentifier.specifier} -> ${uri}` });
|
|
62
57
|
return {
|
|
63
58
|
entry: siteAssetPath,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isExternalSpecifier, isLambdaEnv, normalizeFromFileURL, } from '@lwrjs/shared-utils';
|
|
2
|
+
import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isExternalSpecifier, isLambdaEnv, joinUrlPath, normalizeFromFileURL, } from '@lwrjs/shared-utils';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { LRUCache } from 'lru-cache';
|
|
@@ -8,14 +8,8 @@ import { cacheCountStore } from '@lwrjs/instrumentation';
|
|
|
8
8
|
import { getTracer, BundleSpan } from '@lwrjs/instrumentation';
|
|
9
9
|
const BUNDLE_SOURCE_NOT_FOUND = 'Bundle Source Path Not Found';
|
|
10
10
|
export default class StaticBundleProvider {
|
|
11
|
-
name = 'static-bundle-provider';
|
|
12
|
-
codeCache;
|
|
13
|
-
siteRootDir;
|
|
14
|
-
bundleConfig;
|
|
15
|
-
i18n;
|
|
16
|
-
siteMetadata;
|
|
17
|
-
bundleCacheSize;
|
|
18
11
|
constructor(config, context) {
|
|
12
|
+
this.name = 'static-bundle-provider';
|
|
19
13
|
if (!context.siteMetadata) {
|
|
20
14
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
21
15
|
}
|
|
@@ -66,7 +60,7 @@ export default class StaticBundleProvider {
|
|
|
66
60
|
return undefined;
|
|
67
61
|
}
|
|
68
62
|
// Default bundle source path
|
|
69
|
-
const bundlePath =
|
|
63
|
+
const bundlePath = joinUrlPath(this.siteRootDir, metadata.path);
|
|
70
64
|
// Get the associated bundle source code
|
|
71
65
|
const resolvedBundlePath = this.getCodePath(bundlePath, debug, specifier, version, localeId, ssr);
|
|
72
66
|
const codePromiser = this.getCodePromiser(resolvedBundlePath, {
|
|
@@ -255,7 +249,7 @@ export default class StaticBundleProvider {
|
|
|
255
249
|
return BUNDLE_SOURCE_NOT_FOUND;
|
|
256
250
|
}
|
|
257
251
|
// Overwrite the default source code path the prod source code path
|
|
258
|
-
bundleSourcePath =
|
|
252
|
+
bundleSourcePath = joinUrlPath(this.siteRootDir, metadata.path);
|
|
259
253
|
}
|
|
260
254
|
return bundleSourcePath;
|
|
261
255
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isLambdaEnv } from '@lwrjs/shared-utils';
|
|
3
|
-
import path from 'path';
|
|
2
|
+
import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isLambdaEnv, joinUrlPath } from '@lwrjs/shared-utils';
|
|
4
3
|
import { getSiteBundleId, parseSiteId, resolveStaticBundleVersion } from '../site-metadata.js';
|
|
5
4
|
export default class StaticModuleProvider {
|
|
6
|
-
name = 'static-module-provider';
|
|
7
|
-
siteRootDir;
|
|
8
|
-
externals;
|
|
9
|
-
fingerprintIndex;
|
|
10
|
-
i18n;
|
|
11
|
-
siteMetadata;
|
|
12
5
|
constructor(_config, context) {
|
|
6
|
+
this.name = 'static-module-provider';
|
|
13
7
|
if (!context.siteMetadata) {
|
|
14
8
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
15
9
|
}
|
|
@@ -47,7 +41,7 @@ export default class StaticModuleProvider {
|
|
|
47
41
|
message: `Module Entry request for static bundle ${specifier}`,
|
|
48
42
|
});
|
|
49
43
|
// Have to make the bundle code available for SSR
|
|
50
|
-
const bundlePath =
|
|
44
|
+
const bundlePath = joinUrlPath(this.siteRootDir, metadata.path);
|
|
51
45
|
const resolvedVersion = resolveStaticBundleVersion(metadata.version, version);
|
|
52
46
|
return {
|
|
53
47
|
id: getSpecifier({ ...moduleId, version: resolvedVersion }),
|
|
@@ -88,7 +82,7 @@ function buildFingerprintsIndex(context) {
|
|
|
88
82
|
if (!context.runtimeEnvironment.featureFlags.LEGACY_LOADER) {
|
|
89
83
|
const bundles = context.siteMetadata?.getSiteBundles().bundles || {};
|
|
90
84
|
for (const bundle of Object.values(bundles)) {
|
|
91
|
-
const bundlePath =
|
|
85
|
+
const bundlePath = joinUrlPath(String(context.siteMetadata?.getSiteRootDir()), bundle.path);
|
|
92
86
|
const includedModules = bundle.includedModules || [];
|
|
93
87
|
for (const includedModule of includedModules) {
|
|
94
88
|
const versionedSpecifier = convertSiteIdToVersionedSpecifier(includedModule);
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { mimeLookup } from '@lwrjs/shared-utils';
|
|
2
|
+
import { joinUrlPath, mimeLookup } from '@lwrjs/shared-utils';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { getSiteResourceId } from '../site-metadata.js';
|
|
6
6
|
export default class StaticResourceProvider {
|
|
7
|
-
name = 'static-resource-provider';
|
|
8
|
-
siteRootDir;
|
|
9
|
-
siteMetadata;
|
|
10
|
-
resourceRegistry;
|
|
11
7
|
constructor(_config, context) {
|
|
8
|
+
this.name = 'static-resource-provider';
|
|
12
9
|
if (!context.siteMetadata) {
|
|
13
10
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
14
11
|
}
|
|
@@ -32,7 +29,7 @@ export default class StaticResourceProvider {
|
|
|
32
29
|
});
|
|
33
30
|
return undefined;
|
|
34
31
|
}
|
|
35
|
-
const resourcePath =
|
|
32
|
+
const resourcePath = joinUrlPath(this.siteRootDir, resourceMetadata.path);
|
|
36
33
|
// Figure out mime type
|
|
37
34
|
const type = resourceMetadata.mimeType ||
|
|
38
35
|
mimeLookup(resourcePath) ||
|
|
@@ -13,14 +13,6 @@ export const SITE_VERSION_PREFIX = `|${VERSION_SIGIL}/`;
|
|
|
13
13
|
export const SITE_LOCALE_PREFIX = `|${LOCALE_SIGIL}/`;
|
|
14
14
|
export const SITE_SSR_PREFIX = `|${SSR_SIGIL}`;
|
|
15
15
|
export class SiteMetadataImpl {
|
|
16
|
-
options;
|
|
17
|
-
siteBundles;
|
|
18
|
-
debugSiteBundles;
|
|
19
|
-
siteResources;
|
|
20
|
-
debugSiteResources;
|
|
21
|
-
siteAssets;
|
|
22
|
-
bundleDecisionTree;
|
|
23
|
-
resourceDecisionTree;
|
|
24
16
|
constructor(options) {
|
|
25
17
|
this.options = options;
|
|
26
18
|
this.siteBundles = this.readStaticBundleMetadata(options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
@@ -2,7 +2,7 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { logger } from '@lwrjs/diagnostics';
|
|
4
4
|
import { SiteMetadataImpl, parseSiteId } from '../site-metadata.js';
|
|
5
|
-
import { LOCALE_SIGIL, hashContent } from '@lwrjs/shared-utils';
|
|
5
|
+
import { LOCALE_SIGIL, hashContent, joinUrlPath } from '@lwrjs/shared-utils';
|
|
6
6
|
export async function dedupeBundles(rootDir, i18n) {
|
|
7
7
|
const siteMetadata = new SiteMetadataImpl({
|
|
8
8
|
rootDir,
|
|
@@ -22,7 +22,7 @@ export async function dedupeBundles(rootDir, i18n) {
|
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
// Read the content from the current metadata
|
|
25
|
-
const currentPath =
|
|
25
|
+
const currentPath = joinUrlPath(rootDir, metadata.path);
|
|
26
26
|
const currentSrc = fs.readFileSync(currentPath);
|
|
27
27
|
logger.debug({
|
|
28
28
|
label: `dedupeBundles`,
|
|
@@ -34,7 +34,7 @@ export async function dedupeBundles(rootDir, i18n) {
|
|
|
34
34
|
const fallbackMetadata = decisionTree.find(siteIdStr, false, false, fallBackLocale);
|
|
35
35
|
if (fallbackMetadata) {
|
|
36
36
|
// Read the content of the fallback metadata
|
|
37
|
-
const fallbackSrc = fs.readFileSync(
|
|
37
|
+
const fallbackSrc = fs.readFileSync(joinUrlPath(rootDir, fallbackMetadata.path));
|
|
38
38
|
logger.debug({
|
|
39
39
|
label: `dedupeBundles`,
|
|
40
40
|
message: `fallback ${siteIdStr},${fallBackLocale} -> ${hashContent(fallbackSrc)}`,
|
|
@@ -33,7 +33,9 @@ const CHOICE_PROD = 'prod';
|
|
|
33
33
|
const CHOICE_DEBUG = 'debug';
|
|
34
34
|
// Tree of decisions to lead you to the right artifact
|
|
35
35
|
export default class DecisionTreeImpl {
|
|
36
|
-
|
|
36
|
+
constructor() {
|
|
37
|
+
this.root = new TreeNode(); // Root node does not hold any decision value
|
|
38
|
+
}
|
|
37
39
|
// Insert an artifact into the tree based on a path of decisions
|
|
38
40
|
insert(siteArtifactId, artifact, debug, localeFallbacks) {
|
|
39
41
|
// The decision path is the set of choices needed to get to the right metadata
|
|
@@ -178,12 +180,9 @@ export default class DecisionTreeImpl {
|
|
|
178
180
|
* It maintains the rank of all choices at this node, allowing a later node with a higher rank to replace the current one as the best option.
|
|
179
181
|
*/
|
|
180
182
|
class TreeNode {
|
|
181
|
-
decisionValue; // The decision value at this node (version ['1_0' or WILDCARD etc], localeId ['en-MX' or WILDCARD etc], etc.)
|
|
182
|
-
children = new Map(); // Maps a decision key to the next TreeNode
|
|
183
|
-
artifact = undefined; // Final artifact at a leaf node
|
|
184
|
-
parentPath; // parent path (i.e. foo/bar|DEBUG|1_0|WILD_CARD) just used for debugging
|
|
185
|
-
rank; // choice rank to prioritize lower ranked choices
|
|
186
183
|
constructor(value = '', parentPath = '') {
|
|
184
|
+
this.children = new Map(); // Maps a decision key to the next TreeNode
|
|
185
|
+
this.artifact = undefined; // Final artifact at a leaf node
|
|
187
186
|
this.decisionValue = value;
|
|
188
187
|
this.parentPath = parentPath;
|
|
189
188
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.22.2",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"build/**/*.d.ts"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@lwrjs/diagnostics": "0.
|
|
60
|
-
"@lwrjs/instrumentation": "0.
|
|
61
|
-
"@lwrjs/shared-utils": "0.
|
|
59
|
+
"@lwrjs/diagnostics": "0.22.2",
|
|
60
|
+
"@lwrjs/instrumentation": "0.22.2",
|
|
61
|
+
"@lwrjs/shared-utils": "0.22.2",
|
|
62
62
|
"lru-cache": "^10.4.3"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@lwrjs/types": "0.
|
|
65
|
+
"@lwrjs/types": "0.22.2",
|
|
66
66
|
"@types/express": "^4.17.21",
|
|
67
67
|
"jest": "29.7.0",
|
|
68
68
|
"jest-express": "^1.12.0",
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
"ts-jest": "^29.2.6"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
74
|
+
"node": ">=22.0.0"
|
|
75
75
|
},
|
|
76
76
|
"volta": {
|
|
77
77
|
"extends": "../../../package.json"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "30870e466e15e6691d238e75836e9266a45203e3"
|
|
80
80
|
}
|