@lwrjs/static 0.13.0-alpha.7 → 0.13.0-alpha.9
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 +1 -1
- package/build/cjs/providers/static-resource-provider.cjs +6 -6
- package/build/cjs/site-metadata.cjs +17 -0
- package/build/es/providers/static-bundle-provider.js +2 -2
- package/build/es/providers/static-resource-provider.d.ts +1 -2
- package/build/es/providers/static-resource-provider.js +11 -9
- package/build/es/site-metadata.d.ts +14 -1
- package/build/es/site-metadata.js +33 -2
- package/package.json +5 -5
|
@@ -103,7 +103,7 @@ var StaticBundleProvider = class {
|
|
|
103
103
|
return includedModule;
|
|
104
104
|
}
|
|
105
105
|
async getCode(bundlePath, debug, specifier, version, localeId) {
|
|
106
|
-
const isLambda =
|
|
106
|
+
const isLambda = (0, import_shared_utils.isLambdaEnv)();
|
|
107
107
|
let bundleSourcePath = bundlePath;
|
|
108
108
|
try {
|
|
109
109
|
if (debug && isLambda) {
|
|
@@ -30,6 +30,7 @@ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
31
|
var import_path = __toModule(require("path"));
|
|
32
32
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
33
|
+
var import_site_metadata = __toModule(require("../site-metadata.cjs"));
|
|
33
34
|
var StaticResourceProvider = class {
|
|
34
35
|
constructor(_config, context) {
|
|
35
36
|
this.name = "static-resource-provider";
|
|
@@ -37,15 +38,14 @@ var StaticResourceProvider = class {
|
|
|
37
38
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
38
39
|
}
|
|
39
40
|
this.resourceRegistry = context.resourceRegistry;
|
|
40
|
-
this.siteResources = context.siteMetadata.getSiteResources();
|
|
41
|
-
this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
|
|
42
41
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
42
|
+
this.siteMetadata = context.siteMetadata;
|
|
43
43
|
}
|
|
44
44
|
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
45
45
|
const {debug} = runtimeEnvironment;
|
|
46
|
-
const metadata = this.
|
|
47
|
-
const debugMetadata = this.
|
|
48
|
-
if (!metadata
|
|
46
|
+
const metadata = this.siteMetadata.getSiteResourcesDecisionTree().find((0, import_site_metadata.getSiteResourceId)(resourceIdentity));
|
|
47
|
+
const debugMetadata = this.siteMetadata.getSiteResourcesDecisionTree().find((0, import_site_metadata.getSiteResourceId)(resourceIdentity), true);
|
|
48
|
+
if (!metadata) {
|
|
49
49
|
import_diagnostics.logger.warn({
|
|
50
50
|
label: `${this.name}`,
|
|
51
51
|
message: `Did not find requested specifier ${resourceIdentity.specifier}`
|
|
@@ -54,7 +54,7 @@ var StaticResourceProvider = class {
|
|
|
54
54
|
}
|
|
55
55
|
const resourcePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
56
56
|
const debugResourcePath = debugMetadata ? import_path.default.join(this.siteRootDir, debugMetadata.path) : void 0;
|
|
57
|
-
const isLambda =
|
|
57
|
+
const isLambda = (0, import_shared_utils.isLambdaEnv)();
|
|
58
58
|
const useDebug = debug && !isLambda && debugResourcePath;
|
|
59
59
|
const type = metadata.mimeType || (0, import_shared_utils.mimeLookup)(resourcePath) || "application/javascript";
|
|
60
60
|
return {
|
|
@@ -28,6 +28,7 @@ __export(exports, {
|
|
|
28
28
|
SITE_VERSION_PREFIX: () => SITE_VERSION_PREFIX,
|
|
29
29
|
SiteMetadataImpl: () => SiteMetadataImpl,
|
|
30
30
|
getSiteBundleId: () => getSiteBundleId,
|
|
31
|
+
getSiteResourceId: () => getSiteResourceId,
|
|
31
32
|
parseSiteId: () => parseSiteId,
|
|
32
33
|
resolveStaticBundleVersion: () => resolveStaticBundleVersion
|
|
33
34
|
});
|
|
@@ -84,6 +85,18 @@ var SiteMetadataImpl = class {
|
|
|
84
85
|
}
|
|
85
86
|
return this.bundleDecisionTree;
|
|
86
87
|
}
|
|
88
|
+
getSiteResourcesDecisionTree() {
|
|
89
|
+
if (!this.resourceDecisionTree) {
|
|
90
|
+
this.resourceDecisionTree = new import_decision_tree.default();
|
|
91
|
+
for (const [key, resource] of Object.entries(this.siteResources.resources)) {
|
|
92
|
+
this.resourceDecisionTree.insert(key, resource, false);
|
|
93
|
+
}
|
|
94
|
+
for (const [key, resource] of Object.entries(this.debugSiteResources.resources)) {
|
|
95
|
+
this.resourceDecisionTree.insert(key, resource, true);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return this.resourceDecisionTree;
|
|
99
|
+
}
|
|
87
100
|
async persistSiteMetadata() {
|
|
88
101
|
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
89
102
|
if (siteMetadataPath.indexOf("__skip_directory_creation__") !== -1)
|
|
@@ -191,3 +204,7 @@ function getSiteBundleId({specifier, namespace, name = "", version}, locale, i18
|
|
|
191
204
|
const versionedSpecifier = version && version !== import_shared_utils.VERSION_NOT_PROVIDED ? `${specifier}${SITE_VERSION_PREFIX}${(0, import_shared_utils.normalizeVersionToUri)(version)}` : specifier;
|
|
192
205
|
return i18n?.defaultLocale === locale ? versionedSpecifier : `${versionedSpecifier}${SITE_LOCALE_PREFIX}${locale}`;
|
|
193
206
|
}
|
|
207
|
+
function getSiteResourceId({specifier, version}) {
|
|
208
|
+
const versionedSpecifier = version && version !== import_shared_utils.VERSION_NOT_PROVIDED ? `${specifier}${SITE_VERSION_PREFIX}${(0, import_shared_utils.normalizeVersionToUri)(version)}` : specifier;
|
|
209
|
+
return versionedSpecifier;
|
|
210
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { VERSION_SIGIL, explodeSpecifier, getSpecifier } from '@lwrjs/shared-utils';
|
|
2
|
+
import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isLambdaEnv } from '@lwrjs/shared-utils';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { getSiteBundleId, parseSiteId, resolveStaticBundleVersion } from '../site-metadata.js';
|
|
@@ -92,7 +92,7 @@ export default class StaticBundleProvider {
|
|
|
92
92
|
*/
|
|
93
93
|
async getCode(bundlePath, debug, specifier, version, localeId) {
|
|
94
94
|
// Flag is used to indicate that we are running on a lambda
|
|
95
|
-
const isLambda =
|
|
95
|
+
const isLambda = isLambdaEnv();
|
|
96
96
|
// Default source code path determined from metadata based on debug mode
|
|
97
97
|
let bundleSourcePath = bundlePath;
|
|
98
98
|
try {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { BootstrapRuntimeEnvironment, ProviderContext, ResourceDefinition, ResourceIdentifier, ResourceProvider } from '@lwrjs/types';
|
|
2
2
|
export default class StaticResourceProvider implements ResourceProvider {
|
|
3
3
|
name: string;
|
|
4
|
-
siteResources: import("@lwrjs/types").SiteResources;
|
|
5
|
-
debugSiteResources: import("@lwrjs/types").SiteResources;
|
|
6
4
|
siteRootDir: string;
|
|
5
|
+
siteMetadata: import("@lwrjs/types").SiteMetadata;
|
|
7
6
|
resourceRegistry: import("@lwrjs/types").PublicResourceRegistry;
|
|
8
7
|
constructor(_config: {}, context: ProviderContext);
|
|
9
8
|
getResource<Identifier extends ResourceIdentifier, RuntimeEnvironment extends BootstrapRuntimeEnvironment>(resourceIdentity: Identifier, runtimeEnvironment: RuntimeEnvironment): Promise<ResourceDefinition | undefined>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { mimeLookup } from '@lwrjs/shared-utils';
|
|
2
|
+
import { isLambdaEnv, mimeLookup } from '@lwrjs/shared-utils';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
|
+
import { getSiteResourceId } from '../site-metadata.js';
|
|
5
6
|
export default class StaticResourceProvider {
|
|
6
7
|
constructor(_config, context) {
|
|
7
8
|
this.name = 'static-resource-provider';
|
|
@@ -9,17 +10,18 @@ export default class StaticResourceProvider {
|
|
|
9
10
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
10
11
|
}
|
|
11
12
|
this.resourceRegistry = context.resourceRegistry;
|
|
12
|
-
this.siteResources = context.siteMetadata.getSiteResources();
|
|
13
|
-
this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
|
|
14
13
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
14
|
+
this.siteMetadata = context.siteMetadata;
|
|
15
15
|
}
|
|
16
16
|
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
17
17
|
const { debug } = runtimeEnvironment;
|
|
18
|
-
const metadata = this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const metadata = this.siteMetadata
|
|
19
|
+
.getSiteResourcesDecisionTree()
|
|
20
|
+
.find(getSiteResourceId(resourceIdentity));
|
|
21
|
+
const debugMetadata = this.siteMetadata
|
|
22
|
+
.getSiteResourcesDecisionTree()
|
|
23
|
+
.find(getSiteResourceId(resourceIdentity), true);
|
|
24
|
+
if (!metadata) {
|
|
23
25
|
logger.warn({
|
|
24
26
|
label: `${this.name}`,
|
|
25
27
|
message: `Did not find requested specifier ${resourceIdentity.specifier}`,
|
|
@@ -28,7 +30,7 @@ export default class StaticResourceProvider {
|
|
|
28
30
|
}
|
|
29
31
|
const resourcePath = path.join(this.siteRootDir, metadata.path);
|
|
30
32
|
const debugResourcePath = debugMetadata ? path.join(this.siteRootDir, debugMetadata.path) : undefined;
|
|
31
|
-
const isLambda =
|
|
33
|
+
const isLambda = isLambdaEnv();
|
|
32
34
|
const useDebug = debug && !isLambda && debugResourcePath;
|
|
33
35
|
// Figure out mime type
|
|
34
36
|
const type = metadata.mimeType || mimeLookup(resourcePath) || 'application/javascript';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractModuleId, I18NConfig, SiteAssets, SiteBundle, SiteBundles, SiteMetadata, SiteResources } from '@lwrjs/types';
|
|
1
|
+
import type { AbstractModuleId, I18NConfig, ResourceIdentifier, SiteAssets, SiteBundle, SiteBundles, SiteMetadata, SiteResource, SiteResources } from '@lwrjs/types';
|
|
2
2
|
import DecisionTree from './utils/decision-tree.js';
|
|
3
3
|
import { LOCALE_SIGIL, VERSION_SIGIL } from '@lwrjs/shared-utils';
|
|
4
4
|
type Options = {
|
|
@@ -20,6 +20,7 @@ export declare class SiteMetadataImpl implements SiteMetadata {
|
|
|
20
20
|
private debugSiteResources;
|
|
21
21
|
private siteAssets;
|
|
22
22
|
private bundleDecisionTree?;
|
|
23
|
+
private resourceDecisionTree?;
|
|
23
24
|
constructor(options: Options);
|
|
24
25
|
getSiteRootDir(): string;
|
|
25
26
|
getSiteBundles(): SiteBundles;
|
|
@@ -32,6 +33,11 @@ export declare class SiteMetadataImpl implements SiteMetadata {
|
|
|
32
33
|
* It is assumed this is static after creation subsequent calls will return the same instance.
|
|
33
34
|
*/
|
|
34
35
|
getSiteBundlesDecisionTree(): DecisionTree<SiteBundle>;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a decision tree for site resources.
|
|
38
|
+
* It is assumed this is static after creation subsequent calls will return the same instance.
|
|
39
|
+
*/
|
|
40
|
+
getSiteResourcesDecisionTree(): DecisionTree<SiteResource>;
|
|
35
41
|
persistSiteMetadata(): Promise<void>;
|
|
36
42
|
private readStaticBundleMetadata;
|
|
37
43
|
/**
|
|
@@ -61,5 +67,12 @@ export declare function parseSiteId(input: string): SiteArtifactId;
|
|
|
61
67
|
* @returns Site Bundle Identifier
|
|
62
68
|
*/
|
|
63
69
|
export declare function getSiteBundleId({ specifier, namespace, name, version }: Partial<AbstractModuleId>, locale?: string, i18n?: I18NConfig): string;
|
|
70
|
+
/**
|
|
71
|
+
* Get a Site Resource Identifier from a Resource Identifier
|
|
72
|
+
*
|
|
73
|
+
* @param resourceID -Resource Identifier
|
|
74
|
+
* @returns Site Bundle Identifier
|
|
75
|
+
*/
|
|
76
|
+
export declare function getSiteResourceId({ specifier, version }: Partial<ResourceIdentifier>): string;
|
|
64
77
|
export {};
|
|
65
78
|
//# sourceMappingURL=site-metadata.d.ts.map
|
|
@@ -47,17 +47,35 @@ export class SiteMetadataImpl {
|
|
|
47
47
|
this.bundleDecisionTree = new DecisionTree();
|
|
48
48
|
// Normalize i18NConfig fallback paths
|
|
49
49
|
const localeFallbacks = createFallbackMap(this.options.i18n);
|
|
50
|
-
// Add All the Bundles path keys [
|
|
50
|
+
// Add All the Bundles path keys [specifier][prod][version? (version || '') : ('' || '*')][localeId || fallbacks]
|
|
51
51
|
for (const [key, bundle] of Object.entries(this.siteBundles.bundles)) {
|
|
52
52
|
this.bundleDecisionTree.insert(key, bundle, false, localeFallbacks);
|
|
53
53
|
}
|
|
54
|
-
// Add All the Bundles path keys [
|
|
54
|
+
// Add All the Bundles path keys [specifier][debug][[version? (version || '') : ('' || '*')][localeId || fallbacks]
|
|
55
55
|
for (const [key, bundle] of Object.entries(this.debugSiteBundles.bundles)) {
|
|
56
56
|
this.bundleDecisionTree.insert(key, bundle, true, localeFallbacks);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
return this.bundleDecisionTree;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns a decision tree for site resources.
|
|
63
|
+
* It is assumed this is static after creation subsequent calls will return the same instance.
|
|
64
|
+
*/
|
|
65
|
+
getSiteResourcesDecisionTree() {
|
|
66
|
+
if (!this.resourceDecisionTree) {
|
|
67
|
+
this.resourceDecisionTree = new DecisionTree();
|
|
68
|
+
// Add All the prod resources path keys [specifier][prod][version? (version || '') : ('' || '*')][*]
|
|
69
|
+
for (const [key, resource] of Object.entries(this.siteResources.resources)) {
|
|
70
|
+
this.resourceDecisionTree.insert(key, resource, false);
|
|
71
|
+
}
|
|
72
|
+
// Add All the debug resources path keys [specifier][debug][version? (version || '') : ('' || '*')][*]
|
|
73
|
+
for (const [key, resource] of Object.entries(this.debugSiteResources.resources)) {
|
|
74
|
+
this.resourceDecisionTree.insert(key, resource, true);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return this.resourceDecisionTree;
|
|
78
|
+
}
|
|
61
79
|
async persistSiteMetadata() {
|
|
62
80
|
// Create the metadata directory if if does not exist
|
|
63
81
|
const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
@@ -205,4 +223,17 @@ export function getSiteBundleId({ specifier, namespace, name = '', version }, lo
|
|
|
205
223
|
? versionedSpecifier
|
|
206
224
|
: `${versionedSpecifier}${SITE_LOCALE_PREFIX}${locale}`;
|
|
207
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Get a Site Resource Identifier from a Resource Identifier
|
|
228
|
+
*
|
|
229
|
+
* @param resourceID -Resource Identifier
|
|
230
|
+
* @returns Site Bundle Identifier
|
|
231
|
+
*/
|
|
232
|
+
export function getSiteResourceId({ specifier, version }) {
|
|
233
|
+
// If a module has an explicit 'version-not-provided' version this will not be reflected in the specifier
|
|
234
|
+
const versionedSpecifier = version && version !== VERSION_NOT_PROVIDED
|
|
235
|
+
? `${specifier}${SITE_VERSION_PREFIX}${normalizeVersionToUri(version)}`
|
|
236
|
+
: specifier;
|
|
237
|
+
return versionedSpecifier;
|
|
238
|
+
}
|
|
208
239
|
//# sourceMappingURL=site-metadata.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.13.0-alpha.
|
|
7
|
+
"version": "0.13.0-alpha.9",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"build/**/*.d.ts"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@lwrjs/diagnostics": "0.13.0-alpha.
|
|
56
|
-
"@lwrjs/shared-utils": "0.13.0-alpha.
|
|
55
|
+
"@lwrjs/diagnostics": "0.13.0-alpha.9",
|
|
56
|
+
"@lwrjs/shared-utils": "0.13.0-alpha.9"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@lwrjs/types": "0.13.0-alpha.
|
|
59
|
+
"@lwrjs/types": "0.13.0-alpha.9",
|
|
60
60
|
"@types/express": "^4.17.21",
|
|
61
61
|
"jest": "^26.6.3",
|
|
62
62
|
"jest-express": "^1.12.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"volta": {
|
|
70
70
|
"extends": "../../../package.json"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "a2a9e1dbf39a7b04c7a43433e004895b6f4c51a3"
|
|
73
73
|
}
|