@lwrjs/static 0.13.0-alpha.9 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/providers/static-bundle-provider.cjs +2 -1
- package/build/cjs/providers/static-module-provider.cjs +2 -2
- package/build/cjs/providers/static-resource-provider.cjs +11 -17
- package/build/cjs/site-metadata.cjs +1 -1
- package/build/es/providers/static-bundle-provider.d.ts +2 -2
- package/build/es/providers/static-bundle-provider.js +2 -1
- package/build/es/providers/static-module-provider.js +3 -3
- package/build/es/providers/static-resource-provider.d.ts +2 -2
- package/build/es/providers/static-resource-provider.js +18 -27
- package/build/es/site-metadata.js +1 -1
- package/package.json +6 -6
|
@@ -79,6 +79,7 @@ var StaticBundleProvider = class {
|
|
|
79
79
|
version: resolvedVersion,
|
|
80
80
|
specifier,
|
|
81
81
|
config: this.bundleConfig,
|
|
82
|
+
integrity: metadata.integrity,
|
|
82
83
|
bundleRecord: {
|
|
83
84
|
includedModules,
|
|
84
85
|
imports,
|
|
@@ -117,7 +118,7 @@ var StaticBundleProvider = class {
|
|
|
117
118
|
}
|
|
118
119
|
bundleSourcePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
119
120
|
}
|
|
120
|
-
return
|
|
121
|
+
return await import_fs_extra.default.readFile(bundleSourcePath, "utf-8");
|
|
121
122
|
} catch (err) {
|
|
122
123
|
import_diagnostics.logger.warn({
|
|
123
124
|
label: "static-bundle-provider",
|
|
@@ -45,10 +45,10 @@ var StaticModuleProvider = class {
|
|
|
45
45
|
async getModule(moduleId, runtimeParams) {
|
|
46
46
|
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
47
47
|
const metadata = this.getBundleMetadata(moduleId, localeId, false);
|
|
48
|
-
if (metadata) {
|
|
48
|
+
if (metadata && (0, import_shared_utils.isLambdaEnv)()) {
|
|
49
49
|
import_diagnostics.logger.warn({
|
|
50
50
|
label: `${this.name}`,
|
|
51
|
-
message: `We should not be asking for module source we have in our site metadata ${moduleId.specifier}`
|
|
51
|
+
message: `We should not be asking for module source we have in our site metadata: ${moduleId.specifier}`
|
|
52
52
|
});
|
|
53
53
|
return void 0;
|
|
54
54
|
}
|
|
@@ -41,22 +41,19 @@ var StaticResourceProvider = class {
|
|
|
41
41
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
42
42
|
this.siteMetadata = context.siteMetadata;
|
|
43
43
|
}
|
|
44
|
-
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
44
|
+
async getResource(resourceIdentity, runtimeEnvironment, runtimeParams) {
|
|
45
45
|
const {debug} = runtimeEnvironment;
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
46
|
+
const {ignoreDebug} = runtimeParams;
|
|
47
|
+
const resourceMetadata = this.siteMetadata.getSiteResourcesDecisionTree().find((0, import_site_metadata.getSiteResourceId)(resourceIdentity), debug && !ignoreDebug);
|
|
48
|
+
if (!resourceMetadata) {
|
|
49
49
|
import_diagnostics.logger.warn({
|
|
50
50
|
label: `${this.name}`,
|
|
51
51
|
message: `Did not find requested specifier ${resourceIdentity.specifier}`
|
|
52
52
|
});
|
|
53
53
|
return void 0;
|
|
54
54
|
}
|
|
55
|
-
const resourcePath = import_path.default.join(this.siteRootDir,
|
|
56
|
-
const
|
|
57
|
-
const isLambda = (0, import_shared_utils.isLambdaEnv)();
|
|
58
|
-
const useDebug = debug && !isLambda && debugResourcePath;
|
|
59
|
-
const type = metadata.mimeType || (0, import_shared_utils.mimeLookup)(resourcePath) || "application/javascript";
|
|
55
|
+
const resourcePath = import_path.default.join(this.siteRootDir, resourceMetadata.path);
|
|
56
|
+
const type = resourceMetadata.mimeType || (0, import_shared_utils.mimeLookup)(resourcePath) || "application/javascript";
|
|
60
57
|
return {
|
|
61
58
|
type,
|
|
62
59
|
stream: () => {
|
|
@@ -64,15 +61,12 @@ var StaticResourceProvider = class {
|
|
|
64
61
|
label: `${this.name}`,
|
|
65
62
|
message: `Resource read from lambda ${resourceIdentity.specifier}`
|
|
66
63
|
});
|
|
67
|
-
|
|
68
|
-
return import_fs_extra.default.createReadStream(debugResourcePath);
|
|
69
|
-
} else {
|
|
70
|
-
return import_fs_extra.default.createReadStream(resourcePath);
|
|
71
|
-
}
|
|
64
|
+
return import_fs_extra.default.createReadStream(resourcePath);
|
|
72
65
|
},
|
|
73
|
-
src:
|
|
74
|
-
inline:
|
|
75
|
-
|
|
66
|
+
src: resourcePath,
|
|
67
|
+
inline: resourceMetadata.inline,
|
|
68
|
+
integrity: resourceMetadata.integrity,
|
|
69
|
+
entry: import_path.default.resolve(resourcePath)
|
|
76
70
|
};
|
|
77
71
|
}
|
|
78
72
|
};
|
|
@@ -112,7 +112,7 @@ var SiteMetadataImpl = class {
|
|
|
112
112
|
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
113
113
|
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
114
114
|
const debugResourceMetadataPath = import_path.default.join(this.options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
|
|
115
|
-
await import_fs_extra.default.writeJSON(debugResourceMetadataPath, this.
|
|
115
|
+
await import_fs_extra.default.writeJSON(debugResourceMetadataPath, this.debugSiteResources, {spaces: 2});
|
|
116
116
|
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
117
117
|
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
118
118
|
} catch (err) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractModuleId, BundleDefinition, BundleProvider, ProviderContext, RuntimeEnvironment, RuntimeParams, SiteMetadata } from '@lwrjs/types';
|
|
1
|
+
import type { AbstractModuleId, BundleDefinition, BundleProvider, ProviderContext, RuntimeEnvironment, RuntimeParams, SiteBundle, SiteMetadata } from '@lwrjs/types';
|
|
2
2
|
export default class StaticBundleProvider implements BundleProvider {
|
|
3
3
|
name: string;
|
|
4
4
|
siteRootDir: string;
|
|
@@ -7,7 +7,7 @@ export default class StaticBundleProvider implements BundleProvider {
|
|
|
7
7
|
siteMetadata: SiteMetadata;
|
|
8
8
|
constructor(_config: {}, context: ProviderContext);
|
|
9
9
|
bundle<BundleIdentifier extends AbstractModuleId, RE extends RuntimeEnvironment>(moduleId: BundleIdentifier, runtimeEnvironment: RE, runtimeParams: RuntimeParams): Promise<BundleDefinition | undefined>;
|
|
10
|
-
|
|
10
|
+
getBundleMetadata(moduleId: Partial<AbstractModuleId>, localeId: string, debug: boolean): SiteBundle | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* Takes a key from the site bundle metadata and creates an appropriate runtime BaseModuleReference to use in the LWR runtime.
|
|
13
13
|
*/
|
|
@@ -51,6 +51,7 @@ export default class StaticBundleProvider {
|
|
|
51
51
|
version: resolvedVersion,
|
|
52
52
|
specifier: specifier,
|
|
53
53
|
config: this.bundleConfig,
|
|
54
|
+
integrity: metadata.integrity,
|
|
54
55
|
bundleRecord: {
|
|
55
56
|
// TODO we need to solve include modules for fingerprints support
|
|
56
57
|
includedModules,
|
|
@@ -113,7 +114,7 @@ export default class StaticBundleProvider {
|
|
|
113
114
|
bundleSourcePath = path.join(this.siteRootDir, metadata.path);
|
|
114
115
|
}
|
|
115
116
|
// Read the bundle source code.
|
|
116
|
-
return
|
|
117
|
+
return await fs.readFile(bundleSourcePath, 'utf-8');
|
|
117
118
|
}
|
|
118
119
|
catch (err) {
|
|
119
120
|
// Ran it an un-expected error reading the bundle source code
|
|
@@ -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 { getSiteBundleId, parseSiteId, resolveStaticBundleVersion } from '../site-metadata.js';
|
|
5
5
|
export default class StaticModuleProvider {
|
|
@@ -18,10 +18,10 @@ export default class StaticModuleProvider {
|
|
|
18
18
|
async getModule(moduleId, runtimeParams) {
|
|
19
19
|
const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
|
|
20
20
|
const metadata = this.getBundleMetadata(moduleId, localeId, false);
|
|
21
|
-
if (metadata) {
|
|
21
|
+
if (metadata && isLambdaEnv()) {
|
|
22
22
|
logger.warn({
|
|
23
23
|
label: `${this.name}`,
|
|
24
|
-
message: `We should not be asking for module source we have in our site metadata ${moduleId.specifier}`,
|
|
24
|
+
message: `We should not be asking for module source we have in our site metadata: ${moduleId.specifier}`,
|
|
25
25
|
});
|
|
26
26
|
// proceed to next provider
|
|
27
27
|
return undefined;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { BootstrapRuntimeEnvironment, ProviderContext, ResourceDefinition, ResourceIdentifier, ResourceProvider } from '@lwrjs/types';
|
|
1
|
+
import type { BootstrapRuntimeEnvironment, ProviderContext, ResourceDefinition, ResourceIdentifier, ResourceProvider, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
export default class StaticResourceProvider implements ResourceProvider {
|
|
3
3
|
name: string;
|
|
4
4
|
siteRootDir: string;
|
|
5
5
|
siteMetadata: import("@lwrjs/types").SiteMetadata;
|
|
6
6
|
resourceRegistry: import("@lwrjs/types").PublicResourceRegistry;
|
|
7
7
|
constructor(_config: {}, context: ProviderContext);
|
|
8
|
-
getResource<Identifier extends ResourceIdentifier, RuntimeEnvironment extends BootstrapRuntimeEnvironment>(resourceIdentity: Identifier, runtimeEnvironment: RuntimeEnvironment): Promise<ResourceDefinition | undefined>;
|
|
8
|
+
getResource<Identifier extends ResourceIdentifier, RuntimeEnvironment extends BootstrapRuntimeEnvironment>(resourceIdentity: Identifier, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams): Promise<ResourceDefinition | undefined>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=static-resource-provider.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import {
|
|
2
|
+
import { 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';
|
|
@@ -13,49 +13,40 @@ export default class StaticResourceProvider {
|
|
|
13
13
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
14
14
|
this.siteMetadata = context.siteMetadata;
|
|
15
15
|
}
|
|
16
|
-
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
16
|
+
async getResource(resourceIdentity, runtimeEnvironment, runtimeParams) {
|
|
17
17
|
const { debug } = runtimeEnvironment;
|
|
18
|
-
|
|
18
|
+
// HACK: this code is tricky because resource IDs are different between prod vs debug ("lwr-loader-shim.bundle.min.js" vs "lwr-loader-shim.bundle.js").
|
|
19
|
+
// 1. In debug mode on Lambda (during SSR), we need to ignore runtimeEnvironment.debug because we will always ask for the prod version (lwr-loader-shim.bundle.min.js)
|
|
20
|
+
// 2. But when we generate the view, we can't ignore runtimeEnvironment.debug because we need the debug version of the loader shim (lwr-loader-shim.bundle.js)
|
|
21
|
+
const { ignoreDebug } = runtimeParams;
|
|
22
|
+
const resourceMetadata = this.siteMetadata
|
|
19
23
|
.getSiteResourcesDecisionTree()
|
|
20
|
-
.find(getSiteResourceId(resourceIdentity));
|
|
21
|
-
|
|
22
|
-
.getSiteResourcesDecisionTree()
|
|
23
|
-
.find(getSiteResourceId(resourceIdentity), true);
|
|
24
|
-
if (!metadata) {
|
|
24
|
+
.find(getSiteResourceId(resourceIdentity), debug && !ignoreDebug);
|
|
25
|
+
if (!resourceMetadata) {
|
|
25
26
|
logger.warn({
|
|
26
27
|
label: `${this.name}`,
|
|
27
28
|
message: `Did not find requested specifier ${resourceIdentity.specifier}`,
|
|
28
29
|
});
|
|
29
30
|
return undefined;
|
|
30
31
|
}
|
|
31
|
-
const resourcePath = path.join(this.siteRootDir,
|
|
32
|
-
const debugResourcePath = debugMetadata ? path.join(this.siteRootDir, debugMetadata.path) : undefined;
|
|
33
|
-
const isLambda = isLambdaEnv();
|
|
34
|
-
const useDebug = debug && !isLambda && debugResourcePath;
|
|
32
|
+
const resourcePath = path.join(this.siteRootDir, resourceMetadata.path);
|
|
35
33
|
// Figure out mime type
|
|
36
|
-
const type =
|
|
34
|
+
const type = resourceMetadata.mimeType ||
|
|
35
|
+
mimeLookup(resourcePath) ||
|
|
36
|
+
'application/javascript';
|
|
37
37
|
return {
|
|
38
38
|
type,
|
|
39
|
-
// Have to make the loader shim code available for SSR
|
|
40
39
|
stream: () => {
|
|
41
40
|
logger.debug({
|
|
42
41
|
label: `${this.name}`,
|
|
43
42
|
message: `Resource read from lambda ${resourceIdentity.specifier}`,
|
|
44
43
|
});
|
|
45
|
-
|
|
46
|
-
// use the debug resource if:
|
|
47
|
-
// - debug mode is ON
|
|
48
|
-
// - isLambda is false
|
|
49
|
-
// - the debug version of the resource exists
|
|
50
|
-
return fs.createReadStream(debugResourcePath);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return fs.createReadStream(resourcePath);
|
|
54
|
-
}
|
|
44
|
+
return fs.createReadStream(resourcePath);
|
|
55
45
|
},
|
|
56
|
-
src:
|
|
57
|
-
inline:
|
|
58
|
-
|
|
46
|
+
src: resourcePath,
|
|
47
|
+
inline: resourceMetadata.inline,
|
|
48
|
+
integrity: resourceMetadata.integrity,
|
|
49
|
+
entry: path.resolve(resourcePath),
|
|
59
50
|
};
|
|
60
51
|
}
|
|
61
52
|
}
|
|
@@ -96,7 +96,7 @@ export class SiteMetadataImpl {
|
|
|
96
96
|
await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
97
97
|
// Save Debug Resource Metadata
|
|
98
98
|
const debugResourceMetadataPath = path.join(this.options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
|
|
99
|
-
await fs.writeJSON(debugResourceMetadataPath, this.
|
|
99
|
+
await fs.writeJSON(debugResourceMetadataPath, this.debugSiteResources, { spaces: 2 });
|
|
100
100
|
// Save Resource Metadata
|
|
101
101
|
const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
102
102
|
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.13.
|
|
7
|
+
"version": "0.13.1",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc -b",
|
|
46
|
-
"clean": "
|
|
46
|
+
"clean": "rimraf build node_modules",
|
|
47
47
|
"test": "jest"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"build/**/*.d.ts"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@lwrjs/diagnostics": "0.13.
|
|
56
|
-
"@lwrjs/shared-utils": "0.13.
|
|
55
|
+
"@lwrjs/diagnostics": "0.13.1",
|
|
56
|
+
"@lwrjs/shared-utils": "0.13.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@lwrjs/types": "0.13.
|
|
59
|
+
"@lwrjs/types": "0.13.1",
|
|
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": "548b27ed22f5bfba7031d6b356d64898e15bd609"
|
|
73
73
|
}
|