@lwrjs/view-registry 0.13.0-alpha.8 → 0.13.0
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/index.cjs +28 -29
- package/build/cjs/linkers/legacy_view_bootstrap.cjs +32 -12
- package/build/cjs/linkers/preload-utils.cjs +6 -3
- package/build/cjs/linkers/utils.cjs +7 -0
- package/build/cjs/linkers/view_bootstrap.cjs +25 -12
- package/build/cjs/utils.cjs +32 -15
- package/build/cjs/view-handler.cjs +6 -1
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +33 -31
- package/build/es/linkers/legacy_view_bootstrap.js +39 -14
- package/build/es/linkers/preload-utils.d.ts +2 -1
- package/build/es/linkers/preload-utils.js +8 -5
- package/build/es/linkers/utils.d.ts +2 -1
- package/build/es/linkers/utils.js +9 -0
- package/build/es/linkers/view_bootstrap.js +28 -11
- package/build/es/utils.d.ts +2 -2
- package/build/es/utils.js +33 -17
- package/build/es/view-handler.js +8 -1
- package/package.json +11 -8
package/build/cjs/index.cjs
CHANGED
|
@@ -57,7 +57,7 @@ var LwrViewRegistry = class {
|
|
|
57
57
|
observer.onAssetSourceChange(({payload}) => this.onAssetSourceChange(payload));
|
|
58
58
|
}
|
|
59
59
|
async onModuleDefinitionChange(moduleDefinition) {
|
|
60
|
-
if (
|
|
60
|
+
if ((0, import_shared_utils.isLocalDev)()) {
|
|
61
61
|
this.viewDefinitions.clear();
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
@@ -80,7 +80,7 @@ var LwrViewRegistry = class {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
async onViewSourceChange(compiledView) {
|
|
83
|
-
if (
|
|
83
|
+
if ((0, import_shared_utils.isLocalDev)()) {
|
|
84
84
|
this.viewDefinitions.clear();
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
@@ -136,17 +136,15 @@ var LwrViewRegistry = class {
|
|
|
136
136
|
}
|
|
137
137
|
throw new Error(`No View provider was able to resolve a view for template: ${viewId.contentTemplate}`);
|
|
138
138
|
}
|
|
139
|
-
async getView(viewId
|
|
139
|
+
async getView(viewId) {
|
|
140
140
|
const {contentTemplate, rootComponent} = viewId;
|
|
141
141
|
const compiledViewCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({contentTemplate, rootComponent});
|
|
142
142
|
import_diagnostics.logger.debug(`[view-registry][getView] compiledViewCacheKey=${compiledViewCacheKey}`);
|
|
143
|
-
if (
|
|
143
|
+
if (this.compiledViews.has(compiledViewCacheKey)) {
|
|
144
144
|
return this.compiledViews.get(compiledViewCacheKey);
|
|
145
145
|
}
|
|
146
146
|
const compiledView = await this.delegateGetView(viewId);
|
|
147
|
-
|
|
148
|
-
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
149
|
-
}
|
|
147
|
+
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
150
148
|
return compiledView;
|
|
151
149
|
}
|
|
152
150
|
hasViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
@@ -161,7 +159,8 @@ var LwrViewRegistry = class {
|
|
|
161
159
|
freezeAssets,
|
|
162
160
|
locale: runtimeParams?.locale,
|
|
163
161
|
basePath: runtimeParams?.basePath,
|
|
164
|
-
debug: runtimeEnvironment.debug
|
|
162
|
+
debug: runtimeEnvironment.debug,
|
|
163
|
+
nonceEnabled: (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE
|
|
165
164
|
});
|
|
166
165
|
import_diagnostics.logger.debug(`[view-registry][hasViewDefinition] viewDefId=${viewDefId}`);
|
|
167
166
|
const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
|
|
@@ -176,19 +175,19 @@ var LwrViewRegistry = class {
|
|
|
176
175
|
}
|
|
177
176
|
async getViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
178
177
|
try {
|
|
179
|
-
const {
|
|
178
|
+
const {freezeAssets, viewParamCacheKey} = (0, import_utils.normalizeRenderOptions)(this.runtimeEnvironment, renderOptions);
|
|
180
179
|
const viewDefCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({
|
|
181
180
|
...view,
|
|
182
181
|
freezeAssets,
|
|
183
182
|
locale: runtimeParams?.locale,
|
|
184
183
|
basePath: runtimeParams?.basePath,
|
|
185
|
-
debug: runtimeEnvironment.debug
|
|
184
|
+
debug: runtimeEnvironment.debug,
|
|
185
|
+
nonceEnabled: (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE
|
|
186
186
|
});
|
|
187
187
|
import_diagnostics.logger.debug(`[view-registry][getViewDefinition] viewDefCacheKey=${viewDefCacheKey}`);
|
|
188
188
|
const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
|
|
189
189
|
import_diagnostics.logger.debug(`[view-registry][getViewDefinition] viewParamKey=${viewParamKey}`);
|
|
190
|
-
|
|
191
|
-
if (cacheDisabled === false && this.viewDefinitions.has(viewDefCacheKey)) {
|
|
190
|
+
if (this.viewDefinitions.has(viewDefCacheKey)) {
|
|
192
191
|
const viewDefinition2 = this.viewDefinitions.get(viewDefCacheKey);
|
|
193
192
|
if (viewDefinition2 && viewDefinition2.paramKey === viewParamKey && viewDefinition2.viewDefinition.immutable) {
|
|
194
193
|
return viewDefinition2.viewDefinition;
|
|
@@ -205,17 +204,16 @@ var LwrViewRegistry = class {
|
|
|
205
204
|
}
|
|
206
205
|
}, () => this.renderView(view, updatableViewParams, runtimeEnvironment, runtimeParams, renderOptions)));
|
|
207
206
|
viewDefinition.nonce = (0, import_utils.getViewNonce)(updatableViewParams);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
207
|
+
const route = this.globalConfig.routes.find((r) => r.id === view.id);
|
|
208
|
+
const maxViewCacheTtl = (0, import_shared_utils.getFeatureFlags)().MAX_VIEW_CACHE_TTL;
|
|
209
|
+
const maxTtl = maxViewCacheTtl && parseInt(maxViewCacheTtl, 10);
|
|
210
|
+
const leastTtl = (0, import_shared_utils.shortestTtl)(viewDefinition.cache?.ttl, route?.cache?.ttl, maxTtl);
|
|
211
|
+
const ttl = leastTtl !== void 0 ? leastTtl === 0 ? 10 : leastTtl * 1e3 : void 0;
|
|
212
|
+
this.viewDefinitions.set(viewDefCacheKey, {
|
|
213
|
+
view,
|
|
214
|
+
viewDefinition,
|
|
215
|
+
paramKey: viewParamKey
|
|
216
|
+
}, {ttl});
|
|
219
217
|
return viewDefinition;
|
|
220
218
|
} catch (err) {
|
|
221
219
|
if (err instanceof import_diagnostics.DiagnosticsError) {
|
|
@@ -230,7 +228,7 @@ var LwrViewRegistry = class {
|
|
|
230
228
|
async renderView(view, viewParams, runtimeEnvironment, runtimeParams = {}, renderOptions) {
|
|
231
229
|
const {id, contentTemplate, rootComponent, layoutTemplate} = view;
|
|
232
230
|
const lwrResourcesId = `__LWR_RESOURCES__${Date.now()}`;
|
|
233
|
-
const renderedContent = await this.render({id, contentTemplate, rootComponent}, {...viewParams, lwr_resources: lwrResourcesId}, runtimeParams, renderOptions);
|
|
231
|
+
const renderedContent = await this.render({id, contentTemplate, rootComponent}, {...viewParams, lwr_resources: lwrResourcesId}, runtimeParams, runtimeEnvironment, renderOptions);
|
|
234
232
|
let normalizedRenderOptions = (0, import_utils.normalizeRenderOptions)(this.runtimeEnvironment, renderedContent.options, renderOptions);
|
|
235
233
|
const layout = layoutTemplate || renderedContent.compiledView.layoutTemplate;
|
|
236
234
|
if (!layout) {
|
|
@@ -250,7 +248,7 @@ var LwrViewRegistry = class {
|
|
|
250
248
|
...viewParams,
|
|
251
249
|
body: renderedContent.renderedView,
|
|
252
250
|
lwr_resources: lwrResourcesId
|
|
253
|
-
}, runtimeParams);
|
|
251
|
+
}, runtimeParams, runtimeEnvironment);
|
|
254
252
|
normalizedRenderOptions = (0, import_utils.normalizeRenderOptions)(this.runtimeEnvironment, renderedLayout.options, normalizedRenderOptions);
|
|
255
253
|
const renderedViewDef = await this.link({
|
|
256
254
|
...renderedLayout,
|
|
@@ -288,16 +286,16 @@ var LwrViewRegistry = class {
|
|
|
288
286
|
});
|
|
289
287
|
return renderedViewDef;
|
|
290
288
|
}
|
|
291
|
-
async render(viewId, viewParams, runtimeParams, renderOptions) {
|
|
289
|
+
async render(viewId, viewParams, runtimeParams, runtimeEnvironment, renderOptions) {
|
|
292
290
|
const globalContext = this.globalData;
|
|
293
291
|
const {id, rootComponent, contentTemplate} = viewId;
|
|
294
|
-
const compiledView = await this.getView({id, contentTemplate, rootComponent}
|
|
292
|
+
const compiledView = await this.getView({id, contentTemplate, rootComponent});
|
|
295
293
|
const result = await compiledView.render({
|
|
296
294
|
...runtimeParams,
|
|
297
295
|
...globalContext,
|
|
298
296
|
...compiledView.properties,
|
|
299
297
|
...viewParams
|
|
300
|
-
});
|
|
298
|
+
}, runtimeEnvironment);
|
|
301
299
|
const normalizedResult = (0, import_utils.normalizeRenderedResult)(result);
|
|
302
300
|
return {
|
|
303
301
|
compiledView,
|
|
@@ -363,7 +361,8 @@ var LwrViewRegistry = class {
|
|
|
363
361
|
renderedView: linkedAssetContent,
|
|
364
362
|
immutable,
|
|
365
363
|
viewRecord: {
|
|
366
|
-
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences)
|
|
364
|
+
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences),
|
|
365
|
+
moduleResources: []
|
|
367
366
|
},
|
|
368
367
|
cache: {ttl: pageTtl}
|
|
369
368
|
};
|
|
@@ -49,9 +49,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
49
49
|
resourceRegistry,
|
|
50
50
|
viewMetadata
|
|
51
51
|
} = resourceContext;
|
|
52
|
-
const {
|
|
52
|
+
const {format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
|
|
53
53
|
const {customElements, serverData, serverDebug} = viewMetadata;
|
|
54
|
-
const version = lwrVersion;
|
|
55
54
|
const isAMD = format === "amd";
|
|
56
55
|
const {bundleConfig} = resourceContext;
|
|
57
56
|
const {external = {}, exclude = []} = bundleConfig;
|
|
@@ -98,9 +97,11 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
98
97
|
const viewPreloads = {
|
|
99
98
|
uris: [],
|
|
100
99
|
specifiers: [],
|
|
101
|
-
groups: new Map()
|
|
100
|
+
groups: new Map(),
|
|
101
|
+
integrities: new Map()
|
|
102
102
|
};
|
|
103
103
|
const isSSR = view.bootstrap?.ssr;
|
|
104
|
+
const version = view.bootstrap?.lwrVersion;
|
|
104
105
|
const nonce = (0, import_utils.getViewNonce)(viewParams);
|
|
105
106
|
let bootstrapModuleRef, versionedSpecifier = bootstrapSpecifier;
|
|
106
107
|
const customElementsRecords = [];
|
|
@@ -128,7 +129,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
128
129
|
}
|
|
129
130
|
(0, import_utils.addExternalScriptNonce)(def, nonce);
|
|
130
131
|
requiredResources.push(def);
|
|
131
|
-
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
|
|
132
|
+
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, {...runtimeParams, ignoreDebug: true});
|
|
132
133
|
if (!errorShimDef) {
|
|
133
134
|
throw Error("Failed to find definition of resource: lwr-error-shim.js");
|
|
134
135
|
}
|
|
@@ -149,11 +150,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
149
150
|
if (!uri) {
|
|
150
151
|
throw Error(`Invalid Module Resource ${versionedSpecifier}`);
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
+
const integrity = (0, import_utils2.getBundleIntegrity)(bootstrapModuleGraph, versionedSpecifier);
|
|
154
|
+
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {integrity, isPreload: false, isSSR, nonce}));
|
|
153
155
|
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
154
156
|
const uri2 = getPreloadUri(depSpecifier, bootstrapModuleGraph.uriMap);
|
|
155
157
|
if (uri2) {
|
|
156
|
-
(0,
|
|
158
|
+
const integrity2 = (0, import_utils2.getBundleIntegrity)(bootstrapModuleGraph, depSpecifier);
|
|
159
|
+
(0, import_preload_utils.setPreloadModulesMeta)(depSpecifier, uri2, integrity2, groups, viewPreloads);
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
if ((0, import_shared_utils.isBundler)(defRegistry)) {
|
|
@@ -190,12 +193,14 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
190
193
|
if (!isSSR || (0, import_shared_utils.getHydrateDirective)(props)) {
|
|
191
194
|
const specifier = graph.graphs[0].specifier;
|
|
192
195
|
const uri = graph.uriMap[specifier];
|
|
193
|
-
(0,
|
|
196
|
+
const integrity = (0, import_utils2.getBundleIntegrity)(graph, specifier);
|
|
197
|
+
(0, import_preload_utils.setPreloadModulesMeta)(specifier, uri, integrity, groups, viewPreloads);
|
|
194
198
|
if (bundle) {
|
|
195
199
|
for (const depSpecifier of graph.graphs[0].static) {
|
|
196
|
-
const
|
|
197
|
-
if (
|
|
198
|
-
(0,
|
|
200
|
+
const depUri = getPreloadUri(depSpecifier, graph.uriMap);
|
|
201
|
+
if (depUri) {
|
|
202
|
+
const integrity2 = (0, import_utils2.getBundleIntegrity)(graph, depSpecifier);
|
|
203
|
+
(0, import_preload_utils.setPreloadModulesMeta)(depSpecifier, depUri, integrity2, groups, viewPreloads);
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
206
|
}
|
|
@@ -214,11 +219,19 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
214
219
|
}
|
|
215
220
|
}));
|
|
216
221
|
if (viewContainsLiveElements) {
|
|
222
|
+
if ((0, import_shared_utils.isLocalDev)()) {
|
|
223
|
+
const localDevSpecifier = "lwr_local_dev/bootstrap";
|
|
224
|
+
rootComponents.push(localDevSpecifier);
|
|
225
|
+
const localDevMod = await (0, import_utils.getModuleResource)({specifier: localDevSpecifier, version: ""}, runtimeEnvironment, {}, moduleRegistry, runtimeParams);
|
|
226
|
+
if (localDevMod.src)
|
|
227
|
+
imports[localDevSpecifier] = localDevMod.src;
|
|
228
|
+
}
|
|
217
229
|
configResources.unshift((0, import_utils2.getViewBootstrapConfigurationResource)({
|
|
218
230
|
id: view.id,
|
|
219
231
|
url: viewParams?.page?.url,
|
|
220
232
|
configAsSrc: view.bootstrap?.configAsSrc || false,
|
|
221
|
-
mixedMode: view.bootstrap?.mixedMode || false
|
|
233
|
+
mixedMode: view.bootstrap?.mixedMode || false,
|
|
234
|
+
nonce: viewParams?.page?.nonce
|
|
222
235
|
}, {
|
|
223
236
|
appId: appIdentity.appName,
|
|
224
237
|
bootstrapModule: versionedSpecifier,
|
|
@@ -238,7 +251,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
238
251
|
}
|
|
239
252
|
const dedupedUris = [...new Set(viewPreloads.uris)];
|
|
240
253
|
for (const preloadUri of dedupedUris) {
|
|
241
|
-
|
|
254
|
+
const integrity = viewPreloads.integrities.get(preloadUri);
|
|
255
|
+
moduleResources.push((0, import_utils.getModuleResourceByUri)(preloadUri, runtimeEnvironment, {
|
|
256
|
+
integrity,
|
|
257
|
+
isPreload: true,
|
|
258
|
+
isSSR,
|
|
259
|
+
nonce
|
|
260
|
+
}));
|
|
242
261
|
}
|
|
243
262
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(import_utils.generateHtmlTag));
|
|
244
263
|
return {
|
|
@@ -246,6 +265,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
246
265
|
viewRecord: {
|
|
247
266
|
resources: requiredResources,
|
|
248
267
|
customElements: customElementsRecords,
|
|
268
|
+
moduleResources,
|
|
249
269
|
bootstrapModule: bootstrapModuleRef
|
|
250
270
|
}
|
|
251
271
|
};
|
|
@@ -29,7 +29,7 @@ __export(exports, {
|
|
|
29
29
|
});
|
|
30
30
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
|
-
function setPreloadModulesMeta(specifier, uri, groups, preloads) {
|
|
32
|
+
function setPreloadModulesMeta(specifier, uri, integrity, groups, preloads) {
|
|
33
33
|
if (!uri) {
|
|
34
34
|
throw (0, import_diagnostics.createSingleDiagnosticError)({
|
|
35
35
|
description: import_diagnostics.descriptions.UNRESOLVABLE.PRELOAD_MODULE(specifier)
|
|
@@ -41,6 +41,7 @@ function setPreloadModulesMeta(specifier, uri, groups, preloads) {
|
|
|
41
41
|
const preloadModulesSpecifiers = preloads.specifiers;
|
|
42
42
|
const preloadBundleGroupsMap = preloads.groups;
|
|
43
43
|
const preloadModulesURIs = preloads.uris;
|
|
44
|
+
const preloadModuleIntegrities = preloads.integrities;
|
|
44
45
|
preloadModulesSpecifiers.push(specifier);
|
|
45
46
|
const {specifier: unversionedSpecifier} = (0, import_shared_utils.explodeSpecifier)(specifier);
|
|
46
47
|
const groupName = (0, import_shared_utils.getGroupName)(unversionedSpecifier, groups);
|
|
@@ -49,6 +50,7 @@ function setPreloadModulesMeta(specifier, uri, groups, preloads) {
|
|
|
49
50
|
}
|
|
50
51
|
preloadModulesURIs.push(uri);
|
|
51
52
|
groupName && preloadBundleGroupsMap.set(groupName, true);
|
|
53
|
+
preloadModuleIntegrities.set(uri, integrity);
|
|
52
54
|
}
|
|
53
55
|
async function getPreloadModulesMeta(specifier, viewPreloads, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending) {
|
|
54
56
|
const {exclude = [], external = {}, groups = {}} = bundleConfig;
|
|
@@ -72,9 +74,10 @@ async function getPreloadModulesMeta(specifier, viewPreloads, bundleConfig, modu
|
|
|
72
74
|
});
|
|
73
75
|
const uri = await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
74
76
|
const normalizedSpecifier = versionedModuleId.version === import_shared_utils.VERSION_NOT_PROVIDED ? specifier : versionedModuleSpecifier;
|
|
75
|
-
|
|
77
|
+
const preloadModuleRecord = await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
78
|
+
const {integrity} = preloadModuleRecord;
|
|
79
|
+
setPreloadModulesMeta(normalizedSpecifier, uri, integrity, groups, viewPreloads);
|
|
76
80
|
if (exclude.length || Object.keys(groups).length) {
|
|
77
|
-
const preloadModuleRecord = await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
78
81
|
const {imports} = preloadModuleRecord.bundleRecord;
|
|
79
82
|
if (imports) {
|
|
80
83
|
if (!pending) {
|
|
@@ -25,6 +25,7 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
flattenCustomElements: () => flattenCustomElements,
|
|
28
|
+
getBundleIntegrity: () => getBundleIntegrity,
|
|
28
29
|
getViewBootstrapConfigurationResource: () => getViewBootstrapConfigurationResource,
|
|
29
30
|
getViewHmrConfigurationResource: () => getViewHmrConfigurationResource
|
|
30
31
|
});
|
|
@@ -72,6 +73,7 @@ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironm
|
|
|
72
73
|
type: CONTENT_TYPE,
|
|
73
74
|
content: configString,
|
|
74
75
|
inline: false,
|
|
76
|
+
nonce: viewInfo.nonce,
|
|
75
77
|
src: url
|
|
76
78
|
};
|
|
77
79
|
} else {
|
|
@@ -129,3 +131,8 @@ function flattenCustomElements(arr, isSSR = false) {
|
|
|
129
131
|
flatten(arr);
|
|
130
132
|
return ret;
|
|
131
133
|
}
|
|
134
|
+
function getBundleIntegrity(bootstrapModuleGraph, versionedSpecifier) {
|
|
135
|
+
const def = bootstrapModuleGraph.linkedDefinitions[versionedSpecifier];
|
|
136
|
+
const integrity = def?.integrity;
|
|
137
|
+
return integrity;
|
|
138
|
+
}
|
|
@@ -41,10 +41,9 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
41
41
|
resourceRegistry,
|
|
42
42
|
viewMetadata
|
|
43
43
|
} = resourceContext;
|
|
44
|
-
const {
|
|
44
|
+
const {format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
|
|
45
45
|
const {customElements, serverData, serverDebug} = viewMetadata;
|
|
46
46
|
const defRegistry = bundle ? moduleBundler : moduleRegistry;
|
|
47
|
-
const version = lwrVersion;
|
|
48
47
|
const isAMD = format === "amd";
|
|
49
48
|
const depth = isAMD ? {static: import_shared_utils.GraphDepth.ALL, dynamic: 1} : {static: import_shared_utils.GraphDepth.NONE, dynamic: 1};
|
|
50
49
|
const {bundleConfig} = resourceContext;
|
|
@@ -87,9 +86,11 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
87
86
|
const viewPreloads = {
|
|
88
87
|
uris: [],
|
|
89
88
|
specifiers: [],
|
|
90
|
-
groups: new Map()
|
|
89
|
+
groups: new Map(),
|
|
90
|
+
integrities: new Map()
|
|
91
91
|
};
|
|
92
92
|
const isSSR = view.bootstrap?.ssr;
|
|
93
|
+
const version = view.bootstrap?.lwrVersion;
|
|
93
94
|
const nonce = (0, import_utils.getViewNonce)(viewParams);
|
|
94
95
|
let bootstrapModuleRef, versionedSpecifier = bootstrapSpecifier;
|
|
95
96
|
let importMetadata = {imports: {}};
|
|
@@ -108,7 +109,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
108
109
|
}
|
|
109
110
|
(0, import_utils.addExternalScriptNonce)(def, nonce);
|
|
110
111
|
requiredResources.push(def);
|
|
111
|
-
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
|
|
112
|
+
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, {...runtimeParams, ignoreDebug: true});
|
|
112
113
|
if (!errorShimDef) {
|
|
113
114
|
throw Error("Failed to find definition of resource: lwr-error-shim.js");
|
|
114
115
|
}
|
|
@@ -129,11 +130,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
129
130
|
if (!uri) {
|
|
130
131
|
throw Error(`Invalid Module Resource ${versionedSpecifier}`);
|
|
131
132
|
}
|
|
132
|
-
|
|
133
|
+
const integrity = (0, import_utils2.getBundleIntegrity)(bootstrapModuleGraph, versionedSpecifier);
|
|
134
|
+
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {integrity, isPreload: false, isSSR, nonce}));
|
|
133
135
|
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
134
136
|
const uri2 = getPreloadUri(depSpecifier, bootstrapModuleGraph.uriMap);
|
|
135
137
|
if (uri2) {
|
|
136
|
-
(0,
|
|
138
|
+
const integrity2 = (0, import_utils2.getBundleIntegrity)(bootstrapModuleGraph, depSpecifier);
|
|
139
|
+
(0, import_preload_utils.setPreloadModulesMeta)(depSpecifier, uri2, integrity2, groups, viewPreloads);
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
if ((0, import_shared_utils.isBundler)(defRegistry)) {
|
|
@@ -171,12 +174,14 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
171
174
|
if (!isSSR || (0, import_shared_utils.getHydrateDirective)(props)) {
|
|
172
175
|
const specifier = graph.graphs[0].specifier;
|
|
173
176
|
const uri = graph.uriMap[specifier];
|
|
174
|
-
(0,
|
|
177
|
+
const integrity = (0, import_utils2.getBundleIntegrity)(graph, specifier);
|
|
178
|
+
(0, import_preload_utils.setPreloadModulesMeta)(specifier, uri, integrity, groups, viewPreloads);
|
|
175
179
|
if (bundle) {
|
|
176
180
|
for (const depSpecifier of graph.graphs[0].static) {
|
|
177
|
-
const
|
|
178
|
-
if (
|
|
179
|
-
(0,
|
|
181
|
+
const depUri = getPreloadUri(depSpecifier, graph.uriMap);
|
|
182
|
+
if (depUri) {
|
|
183
|
+
const integrity2 = (0, import_utils2.getBundleIntegrity)(graph, depSpecifier);
|
|
184
|
+
(0, import_preload_utils.setPreloadModulesMeta)(depSpecifier, depUri, integrity2, groups, viewPreloads);
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
187
|
}
|
|
@@ -200,7 +205,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
200
205
|
id: view.id,
|
|
201
206
|
url: viewParams?.page?.url,
|
|
202
207
|
configAsSrc: view.bootstrap?.configAsSrc || false,
|
|
203
|
-
mixedMode: view.bootstrap?.mixedMode || false
|
|
208
|
+
mixedMode: view.bootstrap?.mixedMode || false,
|
|
209
|
+
nonce: viewParams?.page?.nonce
|
|
204
210
|
}, {
|
|
205
211
|
appId: appIdentity.appName,
|
|
206
212
|
bootstrapModule: versionedSpecifier,
|
|
@@ -218,7 +224,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
218
224
|
}
|
|
219
225
|
const dedupedUris = [...new Set(viewPreloads.uris)];
|
|
220
226
|
for (const preloadUri of dedupedUris) {
|
|
221
|
-
|
|
227
|
+
const integrity = viewPreloads.integrities.get(preloadUri);
|
|
228
|
+
moduleResources.push((0, import_utils.getModuleResourceByUri)(preloadUri, runtimeEnvironment, {
|
|
229
|
+
integrity,
|
|
230
|
+
isPreload: true,
|
|
231
|
+
isSSR,
|
|
232
|
+
nonce
|
|
233
|
+
}));
|
|
222
234
|
}
|
|
223
235
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(import_utils.generateHtmlTag));
|
|
224
236
|
const mapping = (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, runtimeParams);
|
|
@@ -234,6 +246,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
234
246
|
customElements: customElementsRecords,
|
|
235
247
|
endpoints,
|
|
236
248
|
importMetadata,
|
|
249
|
+
moduleResources,
|
|
237
250
|
bootstrapModule: bootstrapModuleRef
|
|
238
251
|
}
|
|
239
252
|
};
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -45,15 +45,22 @@ var import_crypto = __toModule(require("crypto"));
|
|
|
45
45
|
function generateExternalStyle(src) {
|
|
46
46
|
return `<link rel="stylesheet" href="${src}">`;
|
|
47
47
|
}
|
|
48
|
-
function generateExternalScript(type = "application/javascript", src, async, defer, nonce) {
|
|
48
|
+
function generateExternalScript(type = "application/javascript", src, async, defer, nonce, integrity) {
|
|
49
49
|
let scriptLoadOrder = "";
|
|
50
50
|
if (defer) {
|
|
51
51
|
scriptLoadOrder = " defer";
|
|
52
52
|
} else if (async) {
|
|
53
53
|
scriptLoadOrder = " async";
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
let cspHashAttr = "";
|
|
56
|
+
if ((0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE) {
|
|
57
|
+
if (integrity) {
|
|
58
|
+
cspHashAttr = ` integrity="${integrity}"`;
|
|
59
|
+
} else if (nonce) {
|
|
60
|
+
cspHashAttr = ` nonce="${nonce}"`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return `<script type="${type}"${scriptLoadOrder}${cspHashAttr} src="${src}"></script>`;
|
|
57
64
|
}
|
|
58
65
|
function generateLinkPreloadTag({href, type}) {
|
|
59
66
|
if (type === "module") {
|
|
@@ -62,19 +69,27 @@ function generateLinkPreloadTag({href, type}) {
|
|
|
62
69
|
return `<link rel="preload" href="${href}" type="${type}" />`;
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
|
-
function generateExternalTag({
|
|
72
|
+
function generateExternalTag({
|
|
73
|
+
type,
|
|
74
|
+
src = "",
|
|
75
|
+
async,
|
|
76
|
+
defer,
|
|
77
|
+
isPreload,
|
|
78
|
+
nonce,
|
|
79
|
+
integrity
|
|
80
|
+
}) {
|
|
66
81
|
if (isPreload) {
|
|
67
82
|
return generateLinkPreloadTag({href: src, type});
|
|
68
83
|
} else if (type === "text/css") {
|
|
69
84
|
return generateExternalStyle(src);
|
|
70
85
|
} else {
|
|
71
|
-
return generateExternalScript(type, src, async, defer, nonce);
|
|
86
|
+
return generateExternalScript(type, src, async, defer, nonce, integrity);
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
async function generateInlineTag({specifier, type, content, stream, nonce}) {
|
|
75
90
|
const typeStr = type === "text/css" ? "" : ` type="${type}"`;
|
|
76
91
|
const tag = type === "text/css" ? "style" : "script";
|
|
77
|
-
const nonceStr = nonce ? ` nonce="${nonce}"` : "";
|
|
92
|
+
const nonceStr = (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE && nonce && nonce ? ` nonce="${nonce}"` : "";
|
|
78
93
|
if (!content && !stream) {
|
|
79
94
|
throw new Error(`Invalid inline Resource Definition: must have either "content" or "stream": "${specifier}"`);
|
|
80
95
|
}
|
|
@@ -122,7 +137,6 @@ function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions, baseR
|
|
|
122
137
|
return {
|
|
123
138
|
skipMetadataCollection: false,
|
|
124
139
|
freezeAssets: runtimeEnvironment.immutableAssets,
|
|
125
|
-
skipCaching: false,
|
|
126
140
|
viewParamCacheKey: null,
|
|
127
141
|
...baseRenderOptions,
|
|
128
142
|
...overrideRenderOptions
|
|
@@ -228,7 +242,7 @@ async function getModuleResource(moduleId, runtimeEnvironment, moduleResourceMet
|
|
|
228
242
|
};
|
|
229
243
|
}
|
|
230
244
|
function getModuleResourceByUri(uri, runtimeEnvironment, moduleResourceMeta) {
|
|
231
|
-
const {isSSR = false, isPreload = false, nonce} = moduleResourceMeta;
|
|
245
|
+
const {integrity, isSSR = false, isPreload = false, nonce} = moduleResourceMeta;
|
|
232
246
|
const {format} = runtimeEnvironment;
|
|
233
247
|
return {
|
|
234
248
|
src: uri,
|
|
@@ -236,6 +250,7 @@ function getModuleResourceByUri(uri, runtimeEnvironment, moduleResourceMeta) {
|
|
|
236
250
|
async: !isSSR && isPreload,
|
|
237
251
|
defer: isSSR,
|
|
238
252
|
isPreload: format !== "amd" && isPreload,
|
|
253
|
+
integrity,
|
|
239
254
|
nonce
|
|
240
255
|
};
|
|
241
256
|
}
|
|
@@ -259,18 +274,20 @@ async function createJsonModule(specifier, moduleRegistry, environment, params)
|
|
|
259
274
|
};
|
|
260
275
|
}
|
|
261
276
|
function getViewNonce(viewParams) {
|
|
262
|
-
return viewParams?.page?.nonce;
|
|
277
|
+
return (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE ? viewParams?.page?.nonce : void 0;
|
|
263
278
|
}
|
|
264
279
|
function generateViewNonce(viewParams) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
viewParams.page
|
|
268
|
-
|
|
269
|
-
|
|
280
|
+
if ((0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE) {
|
|
281
|
+
const nonce = import_crypto.default.randomBytes(16).toString("base64");
|
|
282
|
+
if (!viewParams.page) {
|
|
283
|
+
viewParams.page = {nonce};
|
|
284
|
+
} else {
|
|
285
|
+
viewParams.page.nonce = nonce;
|
|
286
|
+
}
|
|
270
287
|
}
|
|
271
288
|
}
|
|
272
289
|
function addExternalScriptNonce(def, nonce) {
|
|
273
|
-
if (!def.inline) {
|
|
290
|
+
if (nonce && (0, import_shared_utils.getFeatureFlags)().ENABLE_NONCE && !def.inline) {
|
|
274
291
|
def.nonce = nonce;
|
|
275
292
|
}
|
|
276
293
|
}
|
|
@@ -130,6 +130,8 @@ var LwrViewHandler = class {
|
|
|
130
130
|
const paths = {rootDir, assets, contentDir, layoutsDir};
|
|
131
131
|
const locale = runtimeParams.locale;
|
|
132
132
|
const basePath = runtimeParams.basePath;
|
|
133
|
+
const assetBasePath = runtimeParams.assetBasePath;
|
|
134
|
+
const uiBasePath = runtimeParams.assetBasePath;
|
|
133
135
|
const viewApi = this.getBoundApi(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
134
136
|
const response = await (0, import_instrumentation.getTracer)().trace({
|
|
135
137
|
name: import_instrumentation.ViewSpan.ExecuteRouteHandler,
|
|
@@ -139,7 +141,7 @@ var LwrViewHandler = class {
|
|
|
139
141
|
}
|
|
140
142
|
}, async () => {
|
|
141
143
|
try {
|
|
142
|
-
return await routeHandlerFn({...viewRequest, locale, basePath}, {route, viewApi, ...paths}, routeHandlerOptions);
|
|
144
|
+
return await routeHandlerFn({...viewRequest, locale, basePath, assetBasePath, uiBasePath}, {route, viewApi, ...paths}, routeHandlerOptions);
|
|
143
145
|
} catch (err) {
|
|
144
146
|
if (err instanceof import_diagnostics.DiagnosticsError) {
|
|
145
147
|
throw err;
|
|
@@ -167,6 +169,9 @@ var LwrViewHandler = class {
|
|
|
167
169
|
async getViewResponse(viewRequest, route, runtimeEnvironment, runtimeParams = {}, view, viewParams, renderOptions) {
|
|
168
170
|
const {id, bootstrap} = route;
|
|
169
171
|
const managedView = {...view, id, bootstrap};
|
|
172
|
+
if (view.locale) {
|
|
173
|
+
runtimeParams.locale = view.locale;
|
|
174
|
+
}
|
|
170
175
|
const viewResponse = {
|
|
171
176
|
view: managedView,
|
|
172
177
|
viewParams,
|
package/build/es/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class LwrViewRegistry implements ViewRegistry {
|
|
|
42
42
|
addViewTransformers(transformers: ViewTransformPlugin[]): void;
|
|
43
43
|
initializeViewProviders(): Promise<void[]>;
|
|
44
44
|
delegateGetView(viewId: ViewIdentity): Promise<CompiledView>;
|
|
45
|
-
getView(viewId: ViewIdentity
|
|
45
|
+
getView(viewId: ViewIdentity): Promise<CompiledView>;
|
|
46
46
|
hasViewDefinition(view: View, viewParams: ViewParams, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, renderOptions?: RenderOptions): boolean;
|
|
47
47
|
getViewDefinition(view: View, viewParams: ViewParams, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, renderOptions?: RenderOptions): Promise<LinkedViewDefinition>;
|
|
48
48
|
private renderView;
|