@lwrjs/static 0.12.0-alpha.2 → 0.12.0-alpha.21
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 +2 -2
- package/build/cjs/providers/static-module-provider.cjs +1 -1
- package/build/cjs/providers/static-resource-provider.cjs +12 -5
- package/build/es/providers/static-asset-provider.js +4 -7
- package/build/es/providers/static-bundle-provider.js +5 -2
- package/build/es/providers/static-module-provider.js +1 -1
- package/build/es/providers/static-resource-provider.js +19 -7
- 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}`});
|
|
@@ -55,7 +55,7 @@ var StaticBundleProvider = class {
|
|
|
55
55
|
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
56
56
|
if (!metadata) {
|
|
57
57
|
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
58
|
-
import_diagnostics.logger.
|
|
58
|
+
import_diagnostics.logger.debug({
|
|
59
59
|
label: `${this.name}`,
|
|
60
60
|
message: `did not find requested specifier ${specifier}`
|
|
61
61
|
});
|
|
@@ -63,7 +63,7 @@ var StaticBundleProvider = class {
|
|
|
63
63
|
return void 0;
|
|
64
64
|
}
|
|
65
65
|
const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
66
|
-
const skipDebugModeCode = debug && (0, import_shared_utils.getFeatureFlags)().SSR_STATIC_BUNDLES;
|
|
66
|
+
const skipDebugModeCode = debug && (0, import_shared_utils.getFeatureFlags)().SSR_STATIC_BUNDLES && !process.env.SSR_DEBUG;
|
|
67
67
|
const code = skipDebugModeCode ? 'throw new Error("Unexpected code reference");' : (await import_fs_extra.default.readFile(bundlePath)).toString("utf-8");
|
|
68
68
|
const imports = metadata.imports.map((specifier2) => {
|
|
69
69
|
const importModule = (0, import_shared_utils.explodeSpecifier)(specifier2);
|
|
@@ -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,23 @@ 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 useDebug = debug && !(0, import_shared_utils.getFeatureFlags)().SSR_STATIC_BUNDLES && debugResourcePath;
|
|
55
58
|
const type = metadata.mimeType || (0, import_shared_utils.mimeLookup)(resourcePath) || "application/javascript";
|
|
56
59
|
return {
|
|
57
60
|
type,
|
|
58
61
|
stream: () => {
|
|
59
|
-
import_diagnostics.logger.
|
|
62
|
+
import_diagnostics.logger.debug({
|
|
60
63
|
label: `${this.name}`,
|
|
61
64
|
message: `Resource read from lambda ${resourceIdentity.specifier}`
|
|
62
65
|
});
|
|
63
|
-
|
|
66
|
+
if (useDebug) {
|
|
67
|
+
return import_fs_extra.default.createReadStream(debugResourcePath);
|
|
68
|
+
} else {
|
|
69
|
+
return import_fs_extra.default.createReadStream(resourcePath);
|
|
70
|
+
}
|
|
64
71
|
},
|
|
65
|
-
src: resourcePath,
|
|
72
|
+
src: useDebug ? debugResourcePath : resourcePath,
|
|
66
73
|
inline: metadata.inline
|
|
67
74
|
};
|
|
68
75
|
}
|
|
@@ -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 {
|
|
@@ -25,7 +25,7 @@ export default class StaticBundleProvider {
|
|
|
25
25
|
if (!metadata) {
|
|
26
26
|
// ignore ssr module requests
|
|
27
27
|
if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
|
|
28
|
-
logger.
|
|
28
|
+
logger.debug({
|
|
29
29
|
label: `${this.name}`,
|
|
30
30
|
message: `did not find requested specifier ${specifier}`,
|
|
31
31
|
});
|
|
@@ -35,7 +35,10 @@ export default class StaticBundleProvider {
|
|
|
35
35
|
// Have to make the bundle code available for SSR
|
|
36
36
|
const bundlePath = path.join(this.siteRootDir, metadata.path);
|
|
37
37
|
// workaround: debug bundles don't exist for SSR in this scenario since it's never actually used
|
|
38
|
-
const skipDebugModeCode = debug &&
|
|
38
|
+
const skipDebugModeCode = debug &&
|
|
39
|
+
getFeatureFlags().SSR_STATIC_BUNDLES &&
|
|
40
|
+
// TODO: remove once SSR_DEBUG is migrated to dev CLI
|
|
41
|
+
!process.env.SSR_DEBUG;
|
|
39
42
|
const code = skipDebugModeCode
|
|
40
43
|
? 'throw new Error("Unexpected code reference");'
|
|
41
44
|
: (await fs.readFile(bundlePath)).toString('utf-8');
|
|
@@ -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
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { mimeLookup } from '@lwrjs/shared-utils';
|
|
2
|
+
import { mimeLookup, getFeatureFlags } from '@lwrjs/shared-utils';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
export default class StaticResourceProvider {
|
|
@@ -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,30 @@ 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 useDebug = debug && !getFeatureFlags().SSR_STATIC_BUNDLES && debugResourcePath;
|
|
29
32
|
// Figure out mime type
|
|
30
33
|
const type = metadata.mimeType || mimeLookup(resourcePath) || 'application/javascript';
|
|
31
34
|
return {
|
|
32
35
|
type,
|
|
33
36
|
// Have to make the loader shim code available for SSR
|
|
34
37
|
stream: () => {
|
|
35
|
-
logger.
|
|
38
|
+
logger.debug({
|
|
36
39
|
label: `${this.name}`,
|
|
37
40
|
message: `Resource read from lambda ${resourceIdentity.specifier}`,
|
|
38
41
|
});
|
|
39
|
-
|
|
42
|
+
if (useDebug) {
|
|
43
|
+
// use the debug resource if:
|
|
44
|
+
// - debug mode is ON
|
|
45
|
+
// - SSR_STATIC_BUNDLES is OFF
|
|
46
|
+
// - the debug version of the resource exists
|
|
47
|
+
return fs.createReadStream(debugResourcePath);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return fs.createReadStream(resourcePath);
|
|
51
|
+
}
|
|
40
52
|
},
|
|
41
|
-
src: resourcePath,
|
|
53
|
+
src: useDebug ? debugResourcePath : resourcePath,
|
|
42
54
|
inline: metadata.inline,
|
|
43
55
|
};
|
|
44
56
|
}
|
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.21",
|
|
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.21",
|
|
52
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.21"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
55
|
+
"@lwrjs/types": "0.12.0-alpha.21",
|
|
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": "3d77678ca2f568fcbe29efa2bf7e6f75778be50c"
|
|
69
69
|
}
|