@lwrjs/static 0.17.2-alpha.3 → 0.17.2-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-bundle-provider.cjs +46 -24
- package/build/cjs/transformers/mrt-static-uri-transformer.cjs +1 -1
- package/build/es/providers/static-bundle-provider.d.ts +11 -9
- package/build/es/providers/static-bundle-provider.js +63 -38
- package/build/es/transformers/mrt-static-uri-transformer.js +1 -1
- package/package.json +9 -9
|
@@ -60,26 +60,45 @@ var StaticBundleProvider = class {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
63
|
-
const {specifier,
|
|
63
|
+
const {specifier, version} = moduleId;
|
|
64
64
|
const {
|
|
65
|
-
debug,
|
|
66
65
|
i18n: {defaultLocale}
|
|
67
66
|
} = runtimeEnvironment;
|
|
68
67
|
const localeId = runtimeParams?.locale || defaultLocale;
|
|
69
68
|
const ssr = runtimeParams?.ssr;
|
|
70
|
-
|
|
69
|
+
let debug = runtimeEnvironment.debug;
|
|
70
|
+
let metadata = this.getBundleMetadata({moduleId, localeId, debug, ssr});
|
|
71
|
+
if (!metadata && debug) {
|
|
72
|
+
metadata = this.getBundleMetadata({moduleId, localeId, debug: false, ssr});
|
|
73
|
+
if (metadata)
|
|
74
|
+
debug = false;
|
|
75
|
+
}
|
|
76
|
+
if (!metadata && (0, import_shared_utils.isExternalSpecifier)(moduleId.specifier, this.bundleConfig)) {
|
|
77
|
+
const {specifier: unversionedSepcifier} = (0, import_shared_utils.explodeSpecifier)(moduleId.specifier);
|
|
78
|
+
metadata = {
|
|
79
|
+
path: this.bundleConfig?.external?.[unversionedSepcifier],
|
|
80
|
+
imports: [],
|
|
81
|
+
dynamicImports: [],
|
|
82
|
+
version: moduleId.version
|
|
83
|
+
};
|
|
84
|
+
return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, async () => "", (0, import_shared_utils.normalizeFromFileURL)(metadata.path, this.siteRootDir) ?? metadata.path);
|
|
85
|
+
}
|
|
71
86
|
if (!metadata) {
|
|
87
|
+
this.logBundleError(moduleId, localeId, debug, ssr);
|
|
72
88
|
return void 0;
|
|
73
89
|
}
|
|
74
90
|
const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
75
|
-
const
|
|
76
|
-
const codePromiser = this.getCodePromiser(resolvedBundlePath, {
|
|
91
|
+
const codePromiser = this.getCodePromiser(bundlePath, {
|
|
77
92
|
specifier,
|
|
78
93
|
version,
|
|
79
94
|
locale: localeId,
|
|
80
95
|
ssr,
|
|
81
96
|
debug
|
|
82
97
|
});
|
|
98
|
+
return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath);
|
|
99
|
+
}
|
|
100
|
+
async createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath) {
|
|
101
|
+
const {specifier, name, namespace, version} = moduleId;
|
|
83
102
|
const imports = metadata.imports.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
|
|
84
103
|
const dynamicImports = metadata.dynamicImports?.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
|
|
85
104
|
const id = (0, import_shared_utils.getSpecifier)(moduleId);
|
|
@@ -179,26 +198,29 @@ var StaticBundleProvider = class {
|
|
|
179
198
|
return code;
|
|
180
199
|
};
|
|
181
200
|
}
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
logBundleError(moduleId, localeId, debug, ssr) {
|
|
202
|
+
const moduleSpecifier = moduleId.namespace ? `${moduleId.namespace}/${moduleId.name}` : moduleId.name;
|
|
203
|
+
const siteBundleId = (0, import_site_metadata.getSiteBundleId)(moduleId, localeId, ssr, this.i18n);
|
|
204
|
+
const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
|
|
205
|
+
const siteDebugBundles = this.siteMetadata.getDebugSiteBundles()?.bundles || {};
|
|
206
|
+
const runtimeBundles = Object.keys(siteBundles).filter((key) => key.startsWith(moduleSpecifier));
|
|
207
|
+
const debugBundles = Object.keys(siteDebugBundles).filter((key) => key.startsWith(moduleSpecifier));
|
|
208
|
+
import_diagnostics.logger.error({
|
|
209
|
+
message: JSON.stringify({
|
|
210
|
+
message: "Failed to find static bundle",
|
|
211
|
+
moduleId,
|
|
188
212
|
localeId,
|
|
189
|
-
debug
|
|
190
|
-
ssr
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
return bundleSourcePath;
|
|
213
|
+
debug,
|
|
214
|
+
ssr,
|
|
215
|
+
moduleSpecifier,
|
|
216
|
+
siteBundleId,
|
|
217
|
+
debugBundles,
|
|
218
|
+
runtimeBundles,
|
|
219
|
+
totalBundlesCount: Object.keys(siteBundles).length,
|
|
220
|
+
totalDebugBundlesCount: Object.keys(siteDebugBundles).length
|
|
221
|
+
}),
|
|
222
|
+
label: "static-bundle-provider"
|
|
223
|
+
});
|
|
202
224
|
}
|
|
203
225
|
};
|
|
204
226
|
var static_bundle_provider_default = StaticBundleProvider;
|
|
@@ -43,7 +43,7 @@ function mrtStaticUriTransformer() {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
let basePathlessUri = uriDef.uri;
|
|
46
|
-
if (runtimeEnvironment?.basePath) {
|
|
46
|
+
if (runtimeEnvironment?.basePath && uriDef.uri.startsWith(runtimeEnvironment?.basePath)) {
|
|
47
47
|
basePathlessUri = uriDef.uri.replace(runtimeEnvironment?.basePath, "");
|
|
48
48
|
}
|
|
49
49
|
const uri = (0, import_shared_utils.getMrtArtifactUrl)(runtimeEnvironment?.basePath || "", basePathlessUri);
|
|
@@ -12,6 +12,7 @@ export default class StaticBundleProvider implements BundleProvider {
|
|
|
12
12
|
bundleCacheSize?: number;
|
|
13
13
|
}, context: ProviderContext);
|
|
14
14
|
bundle<BundleIdentifier extends AbstractModuleId, RE extends RuntimeEnvironment>(moduleId: BundleIdentifier, runtimeEnvironment: RE, runtimeParams: RuntimeParams): Promise<BundleDefinition | undefined>;
|
|
15
|
+
private createBundleDefinition;
|
|
15
16
|
getBundleMetadata({ moduleId, localeId, debug, ssr, }: {
|
|
16
17
|
moduleId: Partial<AbstractModuleId>;
|
|
17
18
|
localeId: string;
|
|
@@ -30,16 +31,17 @@ export default class StaticBundleProvider implements BundleProvider {
|
|
|
30
31
|
debug: boolean;
|
|
31
32
|
}): () => Promise<string>;
|
|
32
33
|
/**
|
|
33
|
-
*
|
|
34
|
-
* 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
|
|
34
|
+
* Logs an error when a bundle fails to load and provides debugging metadata.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
36
|
+
* This function logs details about the failed bundle load attempt, including the module ID,
|
|
37
|
+
* locale, debug mode, and SSR status. It also attempts to retrieve additional metadata
|
|
38
|
+
* about the site bundles and debug bundles associated with the module.
|
|
39
|
+
*
|
|
40
|
+
* @param {Partial<AbstractModuleId>} moduleId - The module identifier, which may include a namespace and name.
|
|
41
|
+
* @param {string} localeId - The locale associated with the bundle.
|
|
42
|
+
* @param {boolean} debug - Indicates whether debug mode is enabled.
|
|
43
|
+
* @param {boolean} ssr - Indicates whether the bundle is for server-side rendering (SSR).
|
|
42
44
|
*/
|
|
43
|
-
|
|
45
|
+
logBundleError(moduleId: Partial<AbstractModuleId>, localeId: string, debug: boolean, ssr: boolean): void;
|
|
44
46
|
}
|
|
45
47
|
//# sourceMappingURL=static-bundle-provider.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
-
import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isLambdaEnv } from '@lwrjs/shared-utils';
|
|
2
|
+
import { VERSION_SIGIL, explodeSpecifier, getSpecifier, isExternalSpecifier, isLambdaEnv, 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';
|
|
@@ -34,25 +34,48 @@ export default class StaticBundleProvider {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
async bundle(moduleId, runtimeEnvironment, runtimeParams) {
|
|
37
|
-
const { specifier,
|
|
38
|
-
const {
|
|
37
|
+
const { specifier, version } = moduleId;
|
|
38
|
+
const { i18n: { defaultLocale }, } = runtimeEnvironment;
|
|
39
39
|
const localeId = (runtimeParams?.locale || defaultLocale);
|
|
40
40
|
const ssr = runtimeParams?.ssr;
|
|
41
|
-
|
|
41
|
+
let debug = runtimeEnvironment.debug;
|
|
42
|
+
let metadata = this.getBundleMetadata({ moduleId, localeId, debug, ssr });
|
|
43
|
+
if (!metadata && debug) {
|
|
44
|
+
// Fallback to use prod bundles if the debug variant does not exist
|
|
45
|
+
// eg: debug bundles are not shipped to the Lambda
|
|
46
|
+
// eg: locally, an MRT bundle may or may not have debug metadata, depending on how it's generated
|
|
47
|
+
metadata = this.getBundleMetadata({ moduleId, localeId, debug: false, ssr });
|
|
48
|
+
if (metadata)
|
|
49
|
+
debug = false;
|
|
50
|
+
}
|
|
51
|
+
if (!metadata && isExternalSpecifier(moduleId.specifier, this.bundleConfig)) {
|
|
52
|
+
const { specifier: unversionedSepcifier } = explodeSpecifier(moduleId.specifier);
|
|
53
|
+
metadata = {
|
|
54
|
+
path: this.bundleConfig?.external?.[unversionedSepcifier],
|
|
55
|
+
imports: [],
|
|
56
|
+
dynamicImports: [],
|
|
57
|
+
version: moduleId.version,
|
|
58
|
+
};
|
|
59
|
+
return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, async () => '', normalizeFromFileURL(metadata.path, this.siteRootDir) ?? metadata.path);
|
|
60
|
+
}
|
|
42
61
|
if (!metadata) {
|
|
62
|
+
this.logBundleError(moduleId, localeId, debug, ssr);
|
|
43
63
|
return undefined;
|
|
44
64
|
}
|
|
45
65
|
// Default bundle source path
|
|
46
66
|
const bundlePath = path.join(this.siteRootDir, metadata.path);
|
|
47
67
|
// Get the associated bundle source code
|
|
48
|
-
const
|
|
49
|
-
const codePromiser = this.getCodePromiser(resolvedBundlePath, {
|
|
68
|
+
const codePromiser = this.getCodePromiser(bundlePath, {
|
|
50
69
|
specifier,
|
|
51
70
|
version,
|
|
52
71
|
locale: localeId,
|
|
53
72
|
ssr,
|
|
54
73
|
debug,
|
|
55
74
|
});
|
|
75
|
+
return this.createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath);
|
|
76
|
+
}
|
|
77
|
+
async createBundleDefinition(moduleId, metadata, localeId, debug, ssr, codePromiser, bundlePath) {
|
|
78
|
+
const { specifier, name, namespace, version } = moduleId;
|
|
56
79
|
const imports = metadata.imports.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
|
|
57
80
|
const dynamicImports = metadata.dynamicImports?.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug, false));
|
|
58
81
|
const id = getSpecifier(moduleId);
|
|
@@ -155,42 +178,44 @@ export default class StaticBundleProvider {
|
|
|
155
178
|
};
|
|
156
179
|
}
|
|
157
180
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
181
|
+
* Logs an error when a bundle fails to load and provides debugging metadata.
|
|
182
|
+
*
|
|
183
|
+
* This function logs details about the failed bundle load attempt, including the module ID,
|
|
184
|
+
* locale, debug mode, and SSR status. It also attempts to retrieve additional metadata
|
|
185
|
+
* about the site bundles and debug bundles associated with the module.
|
|
160
186
|
*
|
|
161
|
-
* @param
|
|
162
|
-
* @param
|
|
163
|
-
* @param
|
|
164
|
-
* @param
|
|
165
|
-
* @param localeId Locale id (e.g. en-US) for the current request
|
|
166
|
-
* @param ssr True if this is a server bundle
|
|
187
|
+
* @param {Partial<AbstractModuleId>} moduleId - The module identifier, which may include a namespace and name.
|
|
188
|
+
* @param {string} localeId - The locale associated with the bundle.
|
|
189
|
+
* @param {boolean} debug - Indicates whether debug mode is enabled.
|
|
190
|
+
* @param {boolean} ssr - Indicates whether the bundle is for server-side rendering (SSR).
|
|
167
191
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
192
|
+
logBundleError(moduleId, localeId, debug, ssr) {
|
|
193
|
+
const moduleSpecifier = moduleId.namespace
|
|
194
|
+
? `${moduleId.namespace}/${moduleId.name}`
|
|
195
|
+
: moduleId.name;
|
|
196
|
+
const siteBundleId = getSiteBundleId(moduleId, localeId, ssr, this.i18n);
|
|
197
|
+
// Retrieve site bundles and debug bundles
|
|
198
|
+
const siteBundles = this.siteMetadata.getSiteBundles()?.bundles || {};
|
|
199
|
+
const siteDebugBundles = this.siteMetadata.getDebugSiteBundles()?.bundles || {};
|
|
200
|
+
// Extract keys and filter bundles by module specifier
|
|
201
|
+
const runtimeBundles = Object.keys(siteBundles).filter((key) => key.startsWith(moduleSpecifier));
|
|
202
|
+
const debugBundles = Object.keys(siteDebugBundles).filter((key) => key.startsWith(moduleSpecifier));
|
|
203
|
+
logger.error({
|
|
204
|
+
message: JSON.stringify({
|
|
205
|
+
message: 'Failed to find static bundle',
|
|
206
|
+
moduleId,
|
|
178
207
|
localeId,
|
|
179
|
-
debug
|
|
208
|
+
debug,
|
|
180
209
|
ssr,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// Overwrite the default source code path the prod source code path
|
|
191
|
-
bundleSourcePath = path.join(this.siteRootDir, metadata.path);
|
|
192
|
-
}
|
|
193
|
-
return bundleSourcePath;
|
|
210
|
+
moduleSpecifier,
|
|
211
|
+
siteBundleId,
|
|
212
|
+
debugBundles,
|
|
213
|
+
runtimeBundles,
|
|
214
|
+
totalBundlesCount: Object.keys(siteBundles).length,
|
|
215
|
+
totalDebugBundlesCount: Object.keys(siteDebugBundles).length,
|
|
216
|
+
}),
|
|
217
|
+
label: 'static-bundle-provider',
|
|
218
|
+
});
|
|
194
219
|
}
|
|
195
220
|
}
|
|
196
221
|
//# sourceMappingURL=static-bundle-provider.js.map
|
|
@@ -20,7 +20,7 @@ export default function mrtStaticUriTransformer() {
|
|
|
20
20
|
}
|
|
21
21
|
// Remove the basePath from the uri
|
|
22
22
|
let basePathlessUri = uriDef.uri;
|
|
23
|
-
if (runtimeEnvironment?.basePath) {
|
|
23
|
+
if (runtimeEnvironment?.basePath && uriDef.uri.startsWith(runtimeEnvironment?.basePath)) {
|
|
24
24
|
basePathlessUri = uriDef.uri.replace(runtimeEnvironment?.basePath, '');
|
|
25
25
|
}
|
|
26
26
|
const uri = getMrtArtifactUrl(runtimeEnvironment?.basePath || '', basePathlessUri);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.17.2-alpha.
|
|
7
|
+
"version": "0.17.2-alpha.30",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -56,25 +56,25 @@
|
|
|
56
56
|
"build/**/*.d.ts"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@lwrjs/diagnostics": "0.17.2-alpha.
|
|
60
|
-
"@lwrjs/instrumentation": "0.17.2-alpha.
|
|
61
|
-
"@lwrjs/shared-utils": "0.17.2-alpha.
|
|
59
|
+
"@lwrjs/diagnostics": "0.17.2-alpha.30",
|
|
60
|
+
"@lwrjs/instrumentation": "0.17.2-alpha.30",
|
|
61
|
+
"@lwrjs/shared-utils": "0.17.2-alpha.30",
|
|
62
62
|
"lru-cache": "^10.4.3"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@lwrjs/types": "0.17.2-alpha.
|
|
65
|
+
"@lwrjs/types": "0.17.2-alpha.30",
|
|
66
66
|
"@types/express": "^4.17.21",
|
|
67
|
-
"jest": "
|
|
67
|
+
"jest": "29.7.0",
|
|
68
68
|
"jest-express": "^1.12.0",
|
|
69
69
|
"memfs": "^4.13.0",
|
|
70
70
|
"mock-res": "^0.6.0",
|
|
71
|
-
"ts-jest": "^
|
|
71
|
+
"ts-jest": "^29.2.6"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
74
|
+
"node": ">=20.0.0"
|
|
75
75
|
},
|
|
76
76
|
"volta": {
|
|
77
77
|
"extends": "../../../package.json"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "818bbb13d2d4b14d128c4c4f23229c9ce7458a23"
|
|
80
80
|
}
|