@lwrjs/static 0.12.0-alpha.3 → 0.12.0-alpha.30
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 +1 -3
- package/build/cjs/providers/static-bundle-provider.cjs +26 -9
- package/build/cjs/providers/static-module-provider.cjs +1 -1
- package/build/cjs/providers/static-resource-provider.cjs +13 -5
- package/build/cjs/site-metadata.cjs +2 -0
- package/build/es/providers/static-asset-provider.js +4 -7
- package/build/es/providers/static-bundle-provider.d.ts +10 -0
- package/build/es/providers/static-bundle-provider.js +49 -15
- package/build/es/providers/static-module-provider.js +1 -1
- package/build/es/providers/static-resource-provider.js +19 -6
- package/build/es/site-metadata.js +2 -0
- package/package.json +5 -5
|
@@ -68,10 +68,8 @@ var StaticAssetProvider = class {
|
|
|
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
|
-
const content =
|
|
71
|
+
const content = function(encoding) {
|
|
72
72
|
return import_fs_extra.default.readFileSync(siteAssetPath, encoding);
|
|
73
|
-
} : () => {
|
|
74
|
-
throw Error(`[${this.name}] Asset is not on lambda ${siteAssetPath}`);
|
|
75
73
|
};
|
|
76
74
|
const uri = this.assetsOnLambda ? fileAssetPath : import_path.default.join(this.siteRootDir, fileAssetPath);
|
|
77
75
|
import_diagnostics.logger.debug({label: `${this.name}`, message: `uri ${assetIdentifier.specifier} -> ${uri}`});
|
|
@@ -31,7 +31,6 @@ 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
33
|
var import_static_utils = __toModule(require("../utils/static-utils.cjs"));
|
|
34
|
-
var LWR_SSR_BUNDLE_PREFIX = "@lwrjs/lwc-ssr/";
|
|
35
34
|
var StaticBundleProvider = class {
|
|
36
35
|
constructor(_config, context) {
|
|
37
36
|
this.name = "static-bundle-provider";
|
|
@@ -54,17 +53,10 @@ var StaticBundleProvider = class {
|
|
|
54
53
|
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
55
54
|
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
56
55
|
if (!metadata) {
|
|
57
|
-
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
58
|
-
import_diagnostics.logger.warn({
|
|
59
|
-
label: `${this.name}`,
|
|
60
|
-
message: `did not find requested specifier ${specifier}`
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
56
|
return void 0;
|
|
64
57
|
}
|
|
65
58
|
const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
66
|
-
const
|
|
67
|
-
const code = skipDebugModeCode ? 'throw new Error("Unexpected code reference");' : (await import_fs_extra.default.readFile(bundlePath)).toString("utf-8");
|
|
59
|
+
const code = await this.getCode(bundlePath, debug, specifier, localeId);
|
|
68
60
|
const imports = metadata.imports.map((specifier2) => {
|
|
69
61
|
const importModule = (0, import_shared_utils.explodeSpecifier)(specifier2);
|
|
70
62
|
if (!importModule.version) {
|
|
@@ -105,5 +97,30 @@ var StaticBundleProvider = class {
|
|
|
105
97
|
src: bundlePath
|
|
106
98
|
};
|
|
107
99
|
}
|
|
100
|
+
async getCode(bundlePath, debug, specifier, localeId) {
|
|
101
|
+
const isLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0;
|
|
102
|
+
let bundleSourcePath = bundlePath;
|
|
103
|
+
try {
|
|
104
|
+
if (debug && isLambda) {
|
|
105
|
+
const siteBundles = this.siteBundles;
|
|
106
|
+
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
107
|
+
if (!metadata) {
|
|
108
|
+
import_diagnostics.logger.warn({
|
|
109
|
+
label: "static-bundle-provider",
|
|
110
|
+
message: `Unexpected code reference: ${specifier}`
|
|
111
|
+
});
|
|
112
|
+
return `throw new Error('Unexpected code reference: ${specifier}');`;
|
|
113
|
+
}
|
|
114
|
+
bundleSourcePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
115
|
+
}
|
|
116
|
+
return (await import_fs_extra.default.readFile(bundleSourcePath)).toString("utf-8");
|
|
117
|
+
} catch (err) {
|
|
118
|
+
import_diagnostics.logger.warn({
|
|
119
|
+
label: "static-bundle-provider",
|
|
120
|
+
message: `Unexpected code reference: ${specifier} ${bundleSourcePath}`
|
|
121
|
+
}, err);
|
|
122
|
+
return `throw new Error('Unexpected code reference: ${specifier} ${bundleSourcePath}');`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
108
125
|
};
|
|
109
126
|
var static_bundle_provider_default = StaticBundleProvider;
|
|
@@ -60,7 +60,7 @@ var StaticModuleProvider = class {
|
|
|
60
60
|
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
61
61
|
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
|
|
62
62
|
if (metadata) {
|
|
63
|
-
import_diagnostics.logger.
|
|
63
|
+
import_diagnostics.logger.debug({
|
|
64
64
|
label: `${this.name}`,
|
|
65
65
|
message: `Module Entry request for static bundle ${specifier}`
|
|
66
66
|
});
|
|
@@ -43,8 +43,9 @@ var StaticResourceProvider = class {
|
|
|
43
43
|
}
|
|
44
44
|
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
45
45
|
const {debug} = runtimeEnvironment;
|
|
46
|
-
const metadata =
|
|
47
|
-
|
|
46
|
+
const metadata = this.siteResources.resources[resourceIdentity.specifier];
|
|
47
|
+
const debugMetadata = this.debugSiteResources ? this.debugSiteResources.resources[resourceIdentity.specifier] : void 0;
|
|
48
|
+
if (!metadata && !debugMetadata) {
|
|
48
49
|
import_diagnostics.logger.warn({
|
|
49
50
|
label: `${this.name}`,
|
|
50
51
|
message: `Did not find requested specifier ${resourceIdentity.specifier}`
|
|
@@ -52,17 +53,24 @@ var StaticResourceProvider = class {
|
|
|
52
53
|
return void 0;
|
|
53
54
|
}
|
|
54
55
|
const resourcePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
56
|
+
const debugResourcePath = debugMetadata ? import_path.default.join(this.siteRootDir, debugMetadata.path) : void 0;
|
|
57
|
+
const isLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0;
|
|
58
|
+
const useDebug = debug && !isLambda && debugResourcePath;
|
|
55
59
|
const type = metadata.mimeType || (0, import_shared_utils.mimeLookup)(resourcePath) || "application/javascript";
|
|
56
60
|
return {
|
|
57
61
|
type,
|
|
58
62
|
stream: () => {
|
|
59
|
-
import_diagnostics.logger.
|
|
63
|
+
import_diagnostics.logger.debug({
|
|
60
64
|
label: `${this.name}`,
|
|
61
65
|
message: `Resource read from lambda ${resourceIdentity.specifier}`
|
|
62
66
|
});
|
|
63
|
-
|
|
67
|
+
if (useDebug) {
|
|
68
|
+
return import_fs_extra.default.createReadStream(debugResourcePath);
|
|
69
|
+
} else {
|
|
70
|
+
return import_fs_extra.default.createReadStream(resourcePath);
|
|
71
|
+
}
|
|
64
72
|
},
|
|
65
|
-
src: resourcePath,
|
|
73
|
+
src: useDebug ? debugResourcePath : resourcePath,
|
|
66
74
|
inline: metadata.inline
|
|
67
75
|
};
|
|
68
76
|
}
|
|
@@ -64,6 +64,8 @@ var SiteMetadataImpl = class {
|
|
|
64
64
|
}
|
|
65
65
|
async persistSiteMetadata() {
|
|
66
66
|
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
67
|
+
if (siteMetadataPath.indexOf("__skip_directory_creation__") !== -1)
|
|
68
|
+
return;
|
|
67
69
|
try {
|
|
68
70
|
if (!import_fs_extra.default.existsSync(siteMetadataPath)) {
|
|
69
71
|
await import_fs_extra.default.mkdir(siteMetadataPath, {recursive: true});
|
|
@@ -48,13 +48,10 @@ export default class StaticAssetProvider {
|
|
|
48
48
|
const ext = path.extname(`x.${siteAssetPath}`).toLowerCase().substring(1);
|
|
49
49
|
// Unless assets on lambda feature flag is set indicate the asset source is external
|
|
50
50
|
const type = this.assetsOnLambda ? 'asset' : 'external';
|
|
51
|
-
const content =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
: () => {
|
|
56
|
-
throw Error(`[${this.name}] Asset is not on lambda ${siteAssetPath}`);
|
|
57
|
-
};
|
|
51
|
+
const content = function (encoding) {
|
|
52
|
+
return fs.readFileSync(siteAssetPath, encoding);
|
|
53
|
+
};
|
|
54
|
+
// Create URI
|
|
58
55
|
const uri = this.assetsOnLambda ? fileAssetPath : path.join(this.siteRootDir, fileAssetPath);
|
|
59
56
|
logger.debug({ label: `${this.name}`, message: `uri ${assetIdentifier.specifier} -> ${uri}` });
|
|
60
57
|
return {
|
|
@@ -8,5 +8,15 @@ export default class StaticBundleProvider implements BundleProvider {
|
|
|
8
8
|
i18n: import("@lwrjs/types").I18NConfig;
|
|
9
9
|
constructor(_config: {}, context: ProviderContext);
|
|
10
10
|
bundle<BundleIdentifier extends AbstractModuleId, RE extends RuntimeEnvironment>(moduleId: BundleIdentifier, runtimeEnvironment: RE, runtimeParams: RuntimeParams): Promise<BundleDefinition | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the source code for the a static bundle
|
|
13
|
+
* If we are running in a lambda and the mode is debug we will return the prod source code instead of the debug source code
|
|
14
|
+
*
|
|
15
|
+
* @param bundlePath The default path for the bundle for prod read from .metadata/bundle-metadata.json, for debug .metadata/bundle-metadata-debug.json
|
|
16
|
+
* @param debug Is the request in debug mode?
|
|
17
|
+
* @param specifier Root specifier for the requested bundle
|
|
18
|
+
* @param localeId Locale id (e.g. en-US) for the current request
|
|
19
|
+
*/
|
|
20
|
+
getCode(bundlePath: string, debug: boolean, specifier: string, localeId: string): Promise<string>;
|
|
11
21
|
}
|
|
12
22
|
//# sourceMappingURL=static-bundle-provider.d.ts.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { explodeSpecifier, getSpecifier
|
|
2
|
+
import { explodeSpecifier, getSpecifier } from '@lwrjs/shared-utils';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { getLocalizedBundle, resolveStaticBundleVersion } from '../utils/static-utils.js';
|
|
6
|
-
const LWR_SSR_BUNDLE_PREFIX = '@lwrjs/lwc-ssr/';
|
|
7
6
|
export default class StaticBundleProvider {
|
|
8
7
|
constructor(_config, context) {
|
|
9
8
|
this.name = 'static-bundle-provider';
|
|
@@ -23,22 +22,12 @@ export default class StaticBundleProvider {
|
|
|
23
22
|
const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
|
|
24
23
|
const metadata = await getLocalizedBundle(specifier, siteBundles, localeId, this.i18n);
|
|
25
24
|
if (!metadata) {
|
|
26
|
-
// ignore ssr module requests
|
|
27
|
-
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
28
|
-
logger.warn({
|
|
29
|
-
label: `${this.name}`,
|
|
30
|
-
message: `did not find requested specifier ${specifier}`,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
25
|
return undefined;
|
|
34
26
|
}
|
|
35
|
-
//
|
|
27
|
+
// Default bundle source path
|
|
36
28
|
const bundlePath = path.join(this.siteRootDir, metadata.path);
|
|
37
|
-
//
|
|
38
|
-
const
|
|
39
|
-
const code = skipDebugModeCode
|
|
40
|
-
? 'throw new Error("Unexpected code reference");'
|
|
41
|
-
: (await fs.readFile(bundlePath)).toString('utf-8');
|
|
29
|
+
// Get the associated bundle source code
|
|
30
|
+
const code = await this.getCode(bundlePath, debug, specifier, localeId);
|
|
42
31
|
const imports = metadata.imports.map((specifier) => {
|
|
43
32
|
const importModule = explodeSpecifier(specifier);
|
|
44
33
|
if (!importModule.version) {
|
|
@@ -83,5 +72,50 @@ export default class StaticBundleProvider {
|
|
|
83
72
|
src: bundlePath,
|
|
84
73
|
};
|
|
85
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the source code for the a static bundle
|
|
77
|
+
* If we are running in a lambda and the mode is debug we will return the prod source code instead of the debug source code
|
|
78
|
+
*
|
|
79
|
+
* @param bundlePath The default path for the bundle for prod read from .metadata/bundle-metadata.json, for debug .metadata/bundle-metadata-debug.json
|
|
80
|
+
* @param debug Is the request in debug mode?
|
|
81
|
+
* @param specifier Root specifier for the requested bundle
|
|
82
|
+
* @param localeId Locale id (e.g. en-US) for the current request
|
|
83
|
+
*/
|
|
84
|
+
async getCode(bundlePath, debug, specifier, localeId) {
|
|
85
|
+
// Flag is used to indicate that we are running on a lambda
|
|
86
|
+
const isLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined;
|
|
87
|
+
// Default source code path determined from metadata based on debug mode
|
|
88
|
+
let bundleSourcePath = bundlePath;
|
|
89
|
+
try {
|
|
90
|
+
// This is the special case where the request is in debug mode and we are on the lambda
|
|
91
|
+
// So we will look up the prod source code instead of the debug source code
|
|
92
|
+
if (debug && isLambda) {
|
|
93
|
+
const siteBundles = this.siteBundles;
|
|
94
|
+
const metadata = await getLocalizedBundle(specifier, siteBundles, localeId, this.i18n);
|
|
95
|
+
if (!metadata) {
|
|
96
|
+
// We did not find the bundle prod bundle even though we did find it in the debug metadata before
|
|
97
|
+
logger.warn({
|
|
98
|
+
label: 'static-bundle-provider',
|
|
99
|
+
message: `Unexpected code reference: ${specifier}`,
|
|
100
|
+
});
|
|
101
|
+
// Returning source code that throws and error is someone tries to evaluate it
|
|
102
|
+
return `throw new Error('Unexpected code reference: ${specifier}');`;
|
|
103
|
+
}
|
|
104
|
+
// Overwrite the default source code path the prod source code path
|
|
105
|
+
bundleSourcePath = path.join(this.siteRootDir, metadata.path);
|
|
106
|
+
}
|
|
107
|
+
// Read the bundle source code.
|
|
108
|
+
return (await fs.readFile(bundleSourcePath)).toString('utf-8');
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
// Ran it an un-expected error reading the bundle source code
|
|
112
|
+
logger.warn({
|
|
113
|
+
label: 'static-bundle-provider',
|
|
114
|
+
message: `Unexpected code reference: ${specifier} ${bundleSourcePath}`,
|
|
115
|
+
}, err);
|
|
116
|
+
// Returning source code that throws and error is someone tries to evaluate it
|
|
117
|
+
return `throw new Error('Unexpected code reference: ${specifier} ${bundleSourcePath}');`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
86
120
|
}
|
|
87
121
|
//# sourceMappingURL=static-bundle-provider.js.map
|
|
@@ -36,7 +36,7 @@ export default class StaticModuleProvider {
|
|
|
36
36
|
const localeId = (runtimeParams?.locale || this.i18n.defaultLocale);
|
|
37
37
|
const metadata = await getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
|
|
38
38
|
if (metadata) {
|
|
39
|
-
logger.
|
|
39
|
+
logger.debug({
|
|
40
40
|
label: `${this.name}`,
|
|
41
41
|
message: `Module Entry request for static bundle ${specifier}`,
|
|
42
42
|
});
|
|
@@ -15,10 +15,11 @@ export default class StaticResourceProvider {
|
|
|
15
15
|
}
|
|
16
16
|
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
17
17
|
const { debug } = runtimeEnvironment;
|
|
18
|
-
const metadata =
|
|
18
|
+
const metadata = this.siteResources.resources[resourceIdentity.specifier];
|
|
19
|
+
const debugMetadata = this.debugSiteResources
|
|
19
20
|
? this.debugSiteResources.resources[resourceIdentity.specifier]
|
|
20
|
-
:
|
|
21
|
-
if (!metadata) {
|
|
21
|
+
: undefined;
|
|
22
|
+
if (!metadata && !debugMetadata) {
|
|
22
23
|
logger.warn({
|
|
23
24
|
label: `${this.name}`,
|
|
24
25
|
message: `Did not find requested specifier ${resourceIdentity.specifier}`,
|
|
@@ -26,19 +27,31 @@ export default class StaticResourceProvider {
|
|
|
26
27
|
return undefined;
|
|
27
28
|
}
|
|
28
29
|
const resourcePath = path.join(this.siteRootDir, metadata.path);
|
|
30
|
+
const debugResourcePath = debugMetadata ? path.join(this.siteRootDir, debugMetadata.path) : undefined;
|
|
31
|
+
const isLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined;
|
|
32
|
+
const useDebug = debug && !isLambda && debugResourcePath;
|
|
29
33
|
// Figure out mime type
|
|
30
34
|
const type = metadata.mimeType || mimeLookup(resourcePath) || 'application/javascript';
|
|
31
35
|
return {
|
|
32
36
|
type,
|
|
33
37
|
// Have to make the loader shim code available for SSR
|
|
34
38
|
stream: () => {
|
|
35
|
-
logger.
|
|
39
|
+
logger.debug({
|
|
36
40
|
label: `${this.name}`,
|
|
37
41
|
message: `Resource read from lambda ${resourceIdentity.specifier}`,
|
|
38
42
|
});
|
|
39
|
-
|
|
43
|
+
if (useDebug) {
|
|
44
|
+
// use the debug resource if:
|
|
45
|
+
// - debug mode is ON
|
|
46
|
+
// - isLambda is false
|
|
47
|
+
// - the debug version of the resource exists
|
|
48
|
+
return fs.createReadStream(debugResourcePath);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return fs.createReadStream(resourcePath);
|
|
52
|
+
}
|
|
40
53
|
},
|
|
41
|
-
src: resourcePath,
|
|
54
|
+
src: useDebug ? debugResourcePath : resourcePath,
|
|
42
55
|
inline: metadata.inline,
|
|
43
56
|
};
|
|
44
57
|
}
|
|
@@ -37,6 +37,8 @@ export class SiteMetadataImpl {
|
|
|
37
37
|
async persistSiteMetadata() {
|
|
38
38
|
// Create the metadata directory if if does not exist
|
|
39
39
|
const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
40
|
+
if (siteMetadataPath.indexOf('__skip_directory_creation__') !== -1)
|
|
41
|
+
return;
|
|
40
42
|
try {
|
|
41
43
|
if (!fs.existsSync(siteMetadataPath)) {
|
|
42
44
|
await fs.mkdir(siteMetadataPath, { recursive: true });
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.12.0-alpha.
|
|
7
|
+
"version": "0.12.0-alpha.30",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"build/**/*.d.ts"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@lwrjs/diagnostics": "0.12.0-alpha.
|
|
52
|
-
"@lwrjs/shared-utils": "0.12.0-alpha.
|
|
51
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.30",
|
|
52
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.30"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
55
|
+
"@lwrjs/types": "0.12.0-alpha.30",
|
|
56
56
|
"@types/express": "^4.17.21",
|
|
57
57
|
"jest": "^26.6.3",
|
|
58
58
|
"jest-express": "^1.12.0",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"volta": {
|
|
66
66
|
"extends": "../../../package.json"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "5273cb7ece90a3a28645cb1dfde9d315548605db"
|
|
69
69
|
}
|