@lwrjs/view-registry 0.9.0-alpha.3 → 0.9.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/index.cjs +10 -4
- package/build/cjs/linkers/legacy_view_bootstrap.cjs +51 -19
- package/build/cjs/linkers/view_bootstrap.cjs +55 -21
- package/build/cjs/utils.cjs +8 -25
- package/build/cjs/view-handler.cjs +19 -30
- package/build/es/index.js +9 -2
- package/build/es/linkers/legacy_view_bootstrap.d.ts +2 -1
- package/build/es/linkers/legacy_view_bootstrap.js +69 -33
- package/build/es/linkers/link-lwr-resources.d.ts +2 -1
- package/build/es/linkers/utils.js +1 -0
- package/build/es/linkers/view_bootstrap.d.ts +2 -1
- package/build/es/linkers/view_bootstrap.js +72 -34
- package/build/es/utils.d.ts +2 -14
- package/build/es/utils.js +5 -27
- package/build/es/view-handler.d.ts +5 -5
- package/build/es/view-handler.js +18 -35
- package/package.json +9 -9
package/build/cjs/index.cjs
CHANGED
|
@@ -278,8 +278,11 @@ var LwrViewRegistry = class {
|
|
|
278
278
|
importer: importer || renderedView.compiledView.filePath
|
|
279
279
|
};
|
|
280
280
|
const stringBuilder = (0, import_shared_utils.createStringBuilder)(renderedViewContent);
|
|
281
|
+
let pageTtl;
|
|
281
282
|
for (const viewTransformer of this.viewTransformers) {
|
|
282
|
-
await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
283
|
+
const linkResults = await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
284
|
+
const ttl = linkResults && linkResults.cache?.ttl;
|
|
285
|
+
pageTtl = (0, import_shared_utils.shortestTtl)(ttl || void 0, pageTtl);
|
|
283
286
|
}
|
|
284
287
|
const linkedAssetContent = stringBuilder.toString();
|
|
285
288
|
if (linkedAssetContent.includes(lwrResourcesId)) {
|
|
@@ -290,7 +293,8 @@ var LwrViewRegistry = class {
|
|
|
290
293
|
moduleBundler,
|
|
291
294
|
resourceRegistry,
|
|
292
295
|
runtimeEnvironment,
|
|
293
|
-
runtimeParams
|
|
296
|
+
runtimeParams,
|
|
297
|
+
bundleConfig: this.globalConfig.bundleConfig
|
|
294
298
|
});
|
|
295
299
|
return {
|
|
296
300
|
renderedView: linkedView,
|
|
@@ -298,7 +302,8 @@ var LwrViewRegistry = class {
|
|
|
298
302
|
viewRecord: {
|
|
299
303
|
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences),
|
|
300
304
|
...viewRecord
|
|
301
|
-
}
|
|
305
|
+
},
|
|
306
|
+
cache: {ttl: pageTtl}
|
|
302
307
|
};
|
|
303
308
|
}
|
|
304
309
|
return {
|
|
@@ -306,7 +311,8 @@ var LwrViewRegistry = class {
|
|
|
306
311
|
immutable,
|
|
307
312
|
viewRecord: {
|
|
308
313
|
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences)
|
|
309
|
-
}
|
|
314
|
+
},
|
|
315
|
+
cache: {ttl: pageTtl}
|
|
310
316
|
};
|
|
311
317
|
}
|
|
312
318
|
};
|
|
@@ -37,9 +37,20 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
37
37
|
moduleRegistry,
|
|
38
38
|
moduleBundler,
|
|
39
39
|
resourceRegistry,
|
|
40
|
-
viewMetadata
|
|
40
|
+
viewMetadata,
|
|
41
|
+
bundleConfig: {external = {}}
|
|
41
42
|
} = resourceContext;
|
|
42
|
-
const
|
|
43
|
+
const isExternal = function(rawSpecifier) {
|
|
44
|
+
const {specifier} = (0, import_shared_utils.explodeSpecifier)(rawSpecifier);
|
|
45
|
+
return Object.keys(external).some((e) => specifier === e);
|
|
46
|
+
};
|
|
47
|
+
const {
|
|
48
|
+
id: appName,
|
|
49
|
+
bootstrap: {services, module: bootstrapModule, preloadModules = []} = {
|
|
50
|
+
services: [],
|
|
51
|
+
preloadModules: []
|
|
52
|
+
}
|
|
53
|
+
} = view;
|
|
43
54
|
const {lwrVersion, format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
|
|
44
55
|
const {customElements} = viewMetadata;
|
|
45
56
|
const version = lwrVersion;
|
|
@@ -49,7 +60,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
49
60
|
format: runtimeEnvironment.format,
|
|
50
61
|
resourceType: import_identity.AppResourceEnum.MODULE
|
|
51
62
|
};
|
|
52
|
-
const bootstrapSpecifier = (0, import_identity.getAppSpecifier)(appIdentity);
|
|
63
|
+
const bootstrapSpecifier = bootstrapModule || (0, import_identity.getAppSpecifier)(appIdentity);
|
|
64
|
+
const preloadModuleUris = new Set();
|
|
53
65
|
const moduleResources = [];
|
|
54
66
|
const requiredResources = [];
|
|
55
67
|
const configResources = [];
|
|
@@ -60,35 +72,44 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
60
72
|
const preloadAmdModules = [];
|
|
61
73
|
const isSSR = view.bootstrap?.ssr;
|
|
62
74
|
if (isAMD) {
|
|
63
|
-
const shimBundle =
|
|
75
|
+
const shimBundle = debug || minify === false ? "lwr-loader-shim-legacy.bundle.js" : "lwr-loader-shim-legacy.bundle.min.js";
|
|
64
76
|
const def = await resourceRegistry.getResource({specifier: shimBundle, version}, runtimeEnvironment, runtimeParams);
|
|
65
77
|
if (!def) {
|
|
66
78
|
throw Error("Failed to find definition of resource: " + shimBundle);
|
|
67
79
|
}
|
|
68
|
-
if (def.stream) {
|
|
69
|
-
def.stream.destroy();
|
|
70
|
-
}
|
|
71
80
|
requiredResources.push(def);
|
|
72
81
|
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
|
|
73
82
|
if (!errorShimDef) {
|
|
74
83
|
throw Error("Failed to find definition of resource: lwr-error-shim.js");
|
|
75
84
|
}
|
|
76
85
|
requiredResources.push(errorShimDef);
|
|
77
|
-
if (!bundle) {
|
|
78
|
-
requiredResources.push(await (0, import_utils.getModuleResource)({
|
|
79
|
-
specifier: "lwr/loaderLegacy",
|
|
80
|
-
version
|
|
81
|
-
}, runtimeEnvironment, {
|
|
82
|
-
isPreload: false,
|
|
83
|
-
isSSR
|
|
84
|
-
}, moduleRegistry, runtimeParams));
|
|
85
|
-
}
|
|
86
86
|
}
|
|
87
87
|
const depth = isAMD ? {static: import_shared_utils.GraphDepth.ALL, dynamic: 1} : {static: import_shared_utils.GraphDepth.NONE, dynamic: 0};
|
|
88
88
|
const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
|
|
89
89
|
const versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
|
|
90
90
|
const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
|
|
91
91
|
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
|
|
92
|
+
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
93
|
+
if (!isExternal(depSpecifier)) {
|
|
94
|
+
preloadModuleUris.add(bootstrapModuleGraph.uriMap[depSpecifier]);
|
|
95
|
+
preloadAmdModules.push(depSpecifier);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (let i = 0; i < preloadModules.length; i++) {
|
|
99
|
+
const specifier = preloadModules[i];
|
|
100
|
+
if (isExternal(specifier)) {
|
|
101
|
+
import_shared_utils.logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
102
|
+
} else {
|
|
103
|
+
const versionedModuleId = await (0, import_shared_utils.getVersionedModuleId)(specifier, moduleRegistry);
|
|
104
|
+
const versionedModuleSpecifier = (0, import_shared_utils.getSpecifier)({
|
|
105
|
+
specifier,
|
|
106
|
+
version: (0, import_shared_utils.normalizeVersionToUri)(versionedModuleId.version)
|
|
107
|
+
});
|
|
108
|
+
const uri2 = bootstrapModuleGraph.uriMap[versionedModuleSpecifier] || await moduleRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
109
|
+
preloadModuleUris.add(uri2);
|
|
110
|
+
preloadAmdModules.push(versionedModuleSpecifier);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
92
113
|
if (isAMD) {
|
|
93
114
|
requiredAmdModules.push(versionedSpecifier);
|
|
94
115
|
imports[versionedSpecifier] = uri;
|
|
@@ -96,7 +117,6 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
96
117
|
const uri2 = bootstrapModuleGraph.uriMap[staticDep];
|
|
97
118
|
imports[staticDep] = uri2;
|
|
98
119
|
if (services && services.length) {
|
|
99
|
-
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri2, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
100
120
|
requiredAmdModules.push(staticDep);
|
|
101
121
|
}
|
|
102
122
|
}
|
|
@@ -112,11 +132,19 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
112
132
|
const customElementsRecords = [];
|
|
113
133
|
const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
|
|
114
134
|
await Promise.all(flattenedElements.map(async ({tagName: element, props}) => {
|
|
115
|
-
const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.
|
|
135
|
+
const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabCaseToModuleSpecifier)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
116
136
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
117
137
|
const specifier = graph.graphs[0].specifier;
|
|
118
138
|
const uri2 = graph.uriMap[specifier];
|
|
119
139
|
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri2, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
140
|
+
if (bundle) {
|
|
141
|
+
for (const depSpecifier of graph.graphs[0].static) {
|
|
142
|
+
if (!isExternal(depSpecifier)) {
|
|
143
|
+
preloadModuleUris.add(graph.uriMap[depSpecifier]);
|
|
144
|
+
preloadAmdModules.push(depSpecifier);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
120
148
|
rootComponents.push(specifier);
|
|
121
149
|
imports[specifier] = uri2;
|
|
122
150
|
if (isAMD) {
|
|
@@ -131,6 +159,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
131
159
|
}
|
|
132
160
|
}
|
|
133
161
|
}));
|
|
162
|
+
const dedupedPreloadAmdModules = [...new Set(preloadAmdModules)];
|
|
134
163
|
configResources.unshift(await (0, import_utils2.getViewBootstrapConfigurationResource)({
|
|
135
164
|
id: view.id,
|
|
136
165
|
url: viewParams?.page?.url,
|
|
@@ -145,11 +174,14 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
145
174
|
},
|
|
146
175
|
rootComponents,
|
|
147
176
|
...isAMD && {requiredModules: requiredAmdModules},
|
|
148
|
-
...isAMD && {preloadModules:
|
|
177
|
+
...isAMD && {preloadModules: dedupedPreloadAmdModules}
|
|
149
178
|
}, runtimeEnvironment, runtimeParams));
|
|
150
179
|
if (!isAMD && hmrEnabled) {
|
|
151
180
|
configResources.unshift(await (0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
|
|
152
181
|
}
|
|
182
|
+
for (const preloadUri of preloadModuleUris) {
|
|
183
|
+
moduleResources.unshift((0, import_utils.getModuleResourceByUri)(preloadUri, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
184
|
+
}
|
|
153
185
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(import_utils.generateHtmlTag));
|
|
154
186
|
return {
|
|
155
187
|
partial: htmlResources.join("\n"),
|
|
@@ -37,11 +37,23 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
37
37
|
moduleRegistry,
|
|
38
38
|
moduleBundler,
|
|
39
39
|
resourceRegistry,
|
|
40
|
-
viewMetadata
|
|
40
|
+
viewMetadata,
|
|
41
|
+
bundleConfig: {external = {}}
|
|
41
42
|
} = resourceContext;
|
|
42
|
-
const
|
|
43
|
+
const isExternal = function(rawSpecifier) {
|
|
44
|
+
const {specifier} = (0, import_shared_utils.explodeSpecifier)(rawSpecifier);
|
|
45
|
+
return Object.keys(external).some((e) => specifier === e);
|
|
46
|
+
};
|
|
47
|
+
const {
|
|
48
|
+
id: appName,
|
|
49
|
+
bootstrap: {services, module: bootstrapModule, preloadModules = []} = {
|
|
50
|
+
services: [],
|
|
51
|
+
preloadModules: []
|
|
52
|
+
}
|
|
53
|
+
} = view;
|
|
43
54
|
const {lwrVersion, format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
|
|
44
55
|
const {customElements} = viewMetadata;
|
|
56
|
+
const defRegistry = bundle ? moduleBundler : moduleRegistry;
|
|
45
57
|
const version = lwrVersion;
|
|
46
58
|
const isAMD = format === "amd";
|
|
47
59
|
const appIdentity = {
|
|
@@ -49,7 +61,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
49
61
|
format: runtimeEnvironment.format,
|
|
50
62
|
resourceType: import_identity.AppResourceEnum.MODULE
|
|
51
63
|
};
|
|
52
|
-
const bootstrapSpecifier = (0, import_identity.getAppSpecifier)(appIdentity);
|
|
64
|
+
const bootstrapSpecifier = bootstrapModule || (0, import_identity.getAppSpecifier)(appIdentity);
|
|
65
|
+
const preloadModuleUris = new Set();
|
|
53
66
|
const moduleResources = [];
|
|
54
67
|
const requiredResources = [];
|
|
55
68
|
const configResources = [];
|
|
@@ -60,34 +73,44 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
60
73
|
const preloadAmdModules = [];
|
|
61
74
|
const isSSR = view.bootstrap?.ssr;
|
|
62
75
|
if (isAMD) {
|
|
63
|
-
const shimBundle =
|
|
76
|
+
const shimBundle = debug || minify === false ? "lwr-loader-shim.bundle.js" : "lwr-loader-shim.bundle.min.js";
|
|
64
77
|
const def = await resourceRegistry.getResource({specifier: shimBundle, version}, runtimeEnvironment, runtimeParams);
|
|
65
78
|
if (!def) {
|
|
66
79
|
throw Error("Failed to find definition of resource: " + shimBundle);
|
|
67
80
|
}
|
|
68
|
-
if (def.stream) {
|
|
69
|
-
def.stream.destroy();
|
|
70
|
-
}
|
|
71
81
|
requiredResources.push(def);
|
|
72
82
|
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
|
|
73
83
|
if (!errorShimDef) {
|
|
74
84
|
throw Error("Failed to find definition of resource: lwr-error-shim.js");
|
|
75
85
|
}
|
|
76
86
|
requiredResources.push(errorShimDef);
|
|
77
|
-
if (!bundle) {
|
|
78
|
-
requiredResources.push(await (0, import_utils.getModuleResource)({
|
|
79
|
-
specifier: "lwr/loader",
|
|
80
|
-
version
|
|
81
|
-
}, runtimeEnvironment, {
|
|
82
|
-
isSSR
|
|
83
|
-
}, moduleRegistry, runtimeParams));
|
|
84
|
-
}
|
|
85
87
|
}
|
|
86
88
|
const depth = isAMD ? {static: import_shared_utils.GraphDepth.ALL, dynamic: 1} : {static: import_shared_utils.GraphDepth.NONE, dynamic: 1};
|
|
87
|
-
const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry,
|
|
89
|
+
const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
|
|
88
90
|
const versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
|
|
89
91
|
const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
|
|
90
92
|
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
|
|
93
|
+
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
94
|
+
if (!isExternal(depSpecifier)) {
|
|
95
|
+
preloadModuleUris.add(bootstrapModuleGraph.uriMap[depSpecifier]);
|
|
96
|
+
preloadAmdModules.push(depSpecifier);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (let i = 0; i < preloadModules.length; i++) {
|
|
100
|
+
const specifier = preloadModules[i];
|
|
101
|
+
if (isExternal(specifier)) {
|
|
102
|
+
import_shared_utils.logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
103
|
+
} else {
|
|
104
|
+
const versionedModuleId = await (0, import_shared_utils.getVersionedModuleId)(specifier, moduleRegistry);
|
|
105
|
+
const versionedModuleSpecifier = (0, import_shared_utils.getSpecifier)({
|
|
106
|
+
specifier,
|
|
107
|
+
version: (0, import_shared_utils.normalizeVersionToUri)(versionedModuleId.version)
|
|
108
|
+
});
|
|
109
|
+
const uri2 = bootstrapModuleGraph.uriMap[versionedModuleSpecifier] || await moduleRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
110
|
+
preloadModuleUris.add(uri2);
|
|
111
|
+
preloadAmdModules.push(versionedModuleSpecifier);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
91
114
|
if (isAMD) {
|
|
92
115
|
requiredAmdModules.push(versionedSpecifier);
|
|
93
116
|
imports[versionedSpecifier] = uri;
|
|
@@ -95,7 +118,6 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
95
118
|
const uri2 = bootstrapModuleGraph.uriMap[staticDep];
|
|
96
119
|
imports[staticDep] = uri2;
|
|
97
120
|
if (services && services.length) {
|
|
98
|
-
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri2, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
99
121
|
requiredAmdModules.push(staticDep);
|
|
100
122
|
}
|
|
101
123
|
}
|
|
@@ -111,12 +133,20 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
111
133
|
let importMetadata = await (0, import_shared_utils.toImportMetadata)(bootstrapModuleGraph, {imports: {}, index: {}}, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
112
134
|
const customElementsRecords = [];
|
|
113
135
|
const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
|
|
114
|
-
|
|
115
|
-
const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.
|
|
136
|
+
for (const {tagName: element} of flattenedElements) {
|
|
137
|
+
const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabCaseToModuleSpecifier)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
116
138
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
117
139
|
const specifier = graph.graphs[0].specifier;
|
|
118
140
|
const uri2 = graph.uriMap[specifier];
|
|
119
141
|
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri2, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
142
|
+
if (bundle) {
|
|
143
|
+
for (const depSpecifier of graph.graphs[0].static) {
|
|
144
|
+
if (!isExternal(depSpecifier)) {
|
|
145
|
+
preloadModuleUris.add(graph.uriMap[depSpecifier]);
|
|
146
|
+
preloadAmdModules.push(depSpecifier);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
120
150
|
rootComponents.push(specifier);
|
|
121
151
|
imports[specifier] = uri2;
|
|
122
152
|
if (isAMD) {
|
|
@@ -131,7 +161,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
131
161
|
}
|
|
132
162
|
}
|
|
133
163
|
importMetadata = await (0, import_shared_utils.toImportMetadata)(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
134
|
-
}
|
|
164
|
+
}
|
|
165
|
+
const dedupedPreloadAmdModules = [...new Set(preloadAmdModules)];
|
|
135
166
|
configResources.unshift(await (0, import_utils2.getViewBootstrapConfigurationResource)({
|
|
136
167
|
id: view.id,
|
|
137
168
|
url: viewParams?.page?.url,
|
|
@@ -144,11 +175,14 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
144
175
|
index: importMetadata?.index,
|
|
145
176
|
rootComponents,
|
|
146
177
|
...isAMD && {requiredModules: requiredAmdModules},
|
|
147
|
-
...isAMD && {preloadModules:
|
|
178
|
+
...isAMD && {preloadModules: dedupedPreloadAmdModules}
|
|
148
179
|
}, runtimeEnvironment, runtimeParams));
|
|
149
180
|
if (!isAMD && hmrEnabled) {
|
|
150
181
|
configResources.unshift(await (0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
|
|
151
182
|
}
|
|
183
|
+
for (const preloadUri of preloadModuleUris) {
|
|
184
|
+
moduleResources.unshift((0, import_utils.getModuleResourceByUri)(preloadUri, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
185
|
+
}
|
|
152
186
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(import_utils.generateHtmlTag));
|
|
153
187
|
const mapping = (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, runtimeParams);
|
|
154
188
|
const endpoints = {
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -29,19 +29,15 @@ __export(exports, {
|
|
|
29
29
|
generatePageContext: () => generatePageContext,
|
|
30
30
|
getModuleResource: () => getModuleResource,
|
|
31
31
|
getModuleResourceByUri: () => getModuleResourceByUri,
|
|
32
|
-
getRouteHandler: () => getRouteHandler,
|
|
33
32
|
isViewResponse: () => isViewResponse,
|
|
34
33
|
normalizeRenderOptions: () => normalizeRenderOptions,
|
|
35
34
|
normalizeRenderedResult: () => normalizeRenderedResult,
|
|
36
35
|
reduceSourceAssetReferences: () => reduceSourceAssetReferences,
|
|
37
36
|
toJsonFormat: () => toJsonFormat
|
|
38
37
|
});
|
|
39
|
-
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
40
38
|
var import_path = __toModule(require("path"));
|
|
41
|
-
var
|
|
42
|
-
var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
|
|
39
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
43
40
|
var import_identity = __toModule(require("@lwrjs/app-service/identity"));
|
|
44
|
-
var import_shared_utils3 = __toModule(require("@lwrjs/shared-utils"));
|
|
45
41
|
function streamToString(stream) {
|
|
46
42
|
const chunks = [];
|
|
47
43
|
return new Promise((resolve, reject) => {
|
|
@@ -85,7 +81,7 @@ async function generateInlineTag({specifier, type, content, stream, nonce}) {
|
|
|
85
81
|
if (!content && !stream) {
|
|
86
82
|
throw new Error(`Invalid inline Resource Definition: must have either "content" or "stream": "${specifier}"`);
|
|
87
83
|
}
|
|
88
|
-
const code =
|
|
84
|
+
const code = stream ? await streamToString(stream()) : content;
|
|
89
85
|
return `<${tag}${typeStr}${nonceStr}>${code}</${tag}>`;
|
|
90
86
|
}
|
|
91
87
|
async function generateHtmlTag(definition) {
|
|
@@ -132,7 +128,7 @@ function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions, baseR
|
|
|
132
128
|
};
|
|
133
129
|
}
|
|
134
130
|
function getTitleFromFilePath(filePath) {
|
|
135
|
-
return filePath ? (0,
|
|
131
|
+
return filePath ? (0, import_path.basename)(filePath, (0, import_path.extname)(filePath)) : import_shared_utils.DEFAULT_TITLE;
|
|
136
132
|
}
|
|
137
133
|
function generatePageContext({requestPath: url}, {id, contentTemplate, properties}) {
|
|
138
134
|
const title = properties?.title || getTitleFromFilePath(contentTemplate);
|
|
@@ -141,19 +137,6 @@ function generatePageContext({requestPath: url}, {id, contentTemplate, propertie
|
|
|
141
137
|
function isViewResponse(response) {
|
|
142
138
|
return response.body !== void 0;
|
|
143
139
|
}
|
|
144
|
-
async function getRouteHandler(path, {cacheDir, rootDir}) {
|
|
145
|
-
try {
|
|
146
|
-
const fullPath = (0, import_shared_utils.resolveFileExtension)(path);
|
|
147
|
-
if (fullPath.endsWith(".ts")) {
|
|
148
|
-
path = await (0, import_shared_utils.transpileTs)(path, {rootDir, cacheDir: import_path.default.join(cacheDir, "routeHandlers")});
|
|
149
|
-
}
|
|
150
|
-
const moduleEntry = await Promise.resolve().then(() => __toModule(require(path)));
|
|
151
|
-
return moduleEntry.default || moduleEntry;
|
|
152
|
-
} catch (err) {
|
|
153
|
-
console.log(err);
|
|
154
|
-
throw new Error(`Unable to get routeHandler: ${path}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
140
|
async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironment, runtimeParams, moduleRegistry) {
|
|
158
141
|
const {viewRecord} = viewDefinition;
|
|
159
142
|
const {bootstrap, id: appName} = route;
|
|
@@ -186,7 +169,7 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
|
|
|
186
169
|
});
|
|
187
170
|
resources.push({
|
|
188
171
|
type: "application/javascript",
|
|
189
|
-
src: (0,
|
|
172
|
+
src: (0, import_shared_utils.getClientBootstrapConfigurationUri)({url: viewRequest.url, id: route.id}, runtimeEnvironment, runtimeParams)
|
|
190
173
|
});
|
|
191
174
|
}
|
|
192
175
|
const mappingUrl = (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, runtimeParams);
|
|
@@ -206,7 +189,7 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
|
|
|
206
189
|
});
|
|
207
190
|
viewRecord.assetReferences?.forEach((asset) => {
|
|
208
191
|
if (asset.override?.uri) {
|
|
209
|
-
const type = (0,
|
|
192
|
+
const type = (0, import_shared_utils.mimeLookup)(asset.override?.uri);
|
|
210
193
|
resources.push({type, src: asset.override?.uri});
|
|
211
194
|
}
|
|
212
195
|
});
|
|
@@ -229,10 +212,10 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
|
|
|
229
212
|
}
|
|
230
213
|
};
|
|
231
214
|
}
|
|
232
|
-
async function getModuleResource(moduleId, runtimeEnvironment, moduleResouceMeta,
|
|
215
|
+
async function getModuleResource(moduleId, runtimeEnvironment, moduleResouceMeta, defRegistry, runtimeParams) {
|
|
233
216
|
const {format} = runtimeEnvironment;
|
|
234
217
|
const {isSSR = false, isPreload = false} = moduleResouceMeta;
|
|
235
|
-
const moduleUri = await
|
|
218
|
+
const moduleUri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
|
|
236
219
|
return {
|
|
237
220
|
src: moduleUri,
|
|
238
221
|
type: format === "amd" ? "application/javascript" : "module",
|
|
@@ -267,7 +250,7 @@ async function createJsonModule(specifier, moduleRegistry, environment, params)
|
|
|
267
250
|
version,
|
|
268
251
|
ownHash,
|
|
269
252
|
links: {
|
|
270
|
-
self: moduleRegistry.resolveModuleUri(moduleIdentifier, environment, params, ownHash)
|
|
253
|
+
self: await moduleRegistry.resolveModuleUri(moduleIdentifier, environment, params, ownHash)
|
|
271
254
|
}
|
|
272
255
|
};
|
|
273
256
|
}
|
|
@@ -31,15 +31,13 @@ var import_utils = __toModule(require("./utils.cjs"));
|
|
|
31
31
|
var import_path = __toModule(require("path"));
|
|
32
32
|
var LwrViewHandler = class {
|
|
33
33
|
constructor(context, globalConfig) {
|
|
34
|
-
this.inflightRouteHandlerEvalMap = new Map();
|
|
35
|
-
this.routeHandlerFunctionMap = new Map();
|
|
36
|
-
this.viewRegistry = context.viewRegistry;
|
|
37
34
|
this.globalConfig = globalConfig;
|
|
35
|
+
this.routeHandlers = context.routeHandlers;
|
|
36
|
+
this.viewRegistry = context.viewRegistry;
|
|
38
37
|
this.moduleRegistry = context.moduleRegistry;
|
|
39
38
|
}
|
|
40
39
|
async getViewContent(viewRequest, route, runtimeEnvironment, runtimeParams = {}) {
|
|
41
|
-
|
|
42
|
-
if (routeHandler) {
|
|
40
|
+
if (route.routeHandler) {
|
|
43
41
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
44
42
|
if ((0, import_utils.isViewResponse)(response)) {
|
|
45
43
|
return response;
|
|
@@ -55,7 +53,8 @@ var LwrViewHandler = class {
|
|
|
55
53
|
body: viewDefinition2.renderedView,
|
|
56
54
|
metadata: {
|
|
57
55
|
viewDefinition: viewDefinition2
|
|
58
|
-
}
|
|
56
|
+
},
|
|
57
|
+
cache: {ttl: (0, import_shared_utils.shortestTtl)(response.cache?.ttl, viewDefinition2.cache?.ttl)}
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
60
|
const viewDefinition = await this.getDefaultRouteViewDefinition(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
@@ -63,12 +62,12 @@ var LwrViewHandler = class {
|
|
|
63
62
|
body: viewDefinition.renderedView,
|
|
64
63
|
metadata: {
|
|
65
64
|
viewDefinition
|
|
66
|
-
}
|
|
65
|
+
},
|
|
66
|
+
cache: viewDefinition.cache
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
async getViewJson(viewRequest, route, runtimeEnvironment, runtimeParams = {}) {
|
|
70
|
-
|
|
71
|
-
if (routeHandler) {
|
|
70
|
+
if (route.routeHandler) {
|
|
72
71
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
73
72
|
if ((0, import_utils.isViewResponse)(response)) {
|
|
74
73
|
return response;
|
|
@@ -84,9 +83,8 @@ var LwrViewHandler = class {
|
|
|
84
83
|
return await (0, import_utils.toJsonFormat)(viewRequest, viewDefinition, route, runtimeEnvironment, runtimeParams, this.moduleRegistry);
|
|
85
84
|
}
|
|
86
85
|
async getViewConfiguration(viewRequest, route, runtimeEnvironment, runtimeParams = {}) {
|
|
87
|
-
const {routeHandler} = route;
|
|
88
86
|
let viewDefinition;
|
|
89
|
-
if (routeHandler) {
|
|
87
|
+
if (route.routeHandler) {
|
|
90
88
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
91
89
|
if ((0, import_utils.isViewResponse)(response)) {
|
|
92
90
|
return;
|
|
@@ -126,28 +124,18 @@ var LwrViewHandler = class {
|
|
|
126
124
|
return viewDefinition;
|
|
127
125
|
}
|
|
128
126
|
async getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams = {}) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const {routeHandler} = route;
|
|
132
|
-
if (!routeHandler) {
|
|
133
|
-
throw new Error("Route Handler is required for a CustomView");
|
|
127
|
+
if (!route.routeHandler) {
|
|
128
|
+
throw new Error("Route handler is required for a CustomView");
|
|
134
129
|
}
|
|
135
|
-
|
|
136
|
-
if (!
|
|
137
|
-
|
|
138
|
-
if (inflightRouteHandlerPromise) {
|
|
139
|
-
routeHandlerFunction = await inflightRouteHandlerPromise;
|
|
140
|
-
} else {
|
|
141
|
-
const handlerPromise = (0, import_utils.getRouteHandler)(routeHandler, {cacheDir, rootDir});
|
|
142
|
-
this.inflightRouteHandlerEvalMap.set(routeHandler, handlerPromise);
|
|
143
|
-
routeHandlerFunction = await handlerPromise;
|
|
144
|
-
}
|
|
145
|
-
this.routeHandlerFunctionMap.set(routeHandler, routeHandlerFunction);
|
|
146
|
-
this.inflightRouteHandlerEvalMap.delete(routeHandler);
|
|
130
|
+
const routeHandler = this.routeHandlers[route.routeHandler];
|
|
131
|
+
if (!routeHandler) {
|
|
132
|
+
throw new Error(`Route handler does not exist for id: ${route.routeHandler}`);
|
|
147
133
|
}
|
|
134
|
+
const {rootDir, assets, contentDir, layoutsDir} = this.globalConfig;
|
|
135
|
+
const paths = {rootDir, assets, contentDir, layoutsDir};
|
|
148
136
|
const locale = runtimeParams.locale;
|
|
149
137
|
const viewApi = this.getBoundApi(route, runtimeEnvironment, runtimeParams);
|
|
150
|
-
const response = await
|
|
138
|
+
const response = await routeHandler({...viewRequest, locale}, {route, viewApi, ...paths});
|
|
151
139
|
return response;
|
|
152
140
|
}
|
|
153
141
|
getBoundApi(route, runtimeEnvironment, runtimeParams) {
|
|
@@ -169,7 +157,8 @@ var LwrViewHandler = class {
|
|
|
169
157
|
body: viewDefinition.renderedView,
|
|
170
158
|
metadata: {
|
|
171
159
|
viewDefinition
|
|
172
|
-
}
|
|
160
|
+
},
|
|
161
|
+
cache: viewDefinition.cache
|
|
173
162
|
};
|
|
174
163
|
}
|
|
175
164
|
};
|
package/build/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractMetadataFromHtml, getCacheKeyFromJson, getSpecifier, normalizeResourcePath, createStringBuilder, InflightTasks, } from '@lwrjs/shared-utils';
|
|
1
|
+
import { extractMetadataFromHtml, getCacheKeyFromJson, getSpecifier, normalizeResourcePath, createStringBuilder, shortestTtl, InflightTasks, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { normalizeRenderOptions, normalizeRenderedResult, reduceSourceAssetReferences } from './utils.js';
|
|
3
3
|
import { linkLwrResources } from './linkers/link-lwr-resources.js';
|
|
4
4
|
export { LwrViewHandler } from './view-handler.js';
|
|
@@ -295,9 +295,13 @@ export class LwrViewRegistry {
|
|
|
295
295
|
importer: importer || renderedView.compiledView.filePath,
|
|
296
296
|
};
|
|
297
297
|
const stringBuilder = createStringBuilder(renderedViewContent);
|
|
298
|
+
let pageTtl;
|
|
298
299
|
for (const viewTransformer of this.viewTransformers) {
|
|
299
300
|
// eslint-disable-next-line no-await-in-loop
|
|
300
|
-
await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
301
|
+
const linkResults = await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
302
|
+
// Keep track of the shortest TTL from each view transformer (e.g. lwcSsrViewTranformer)
|
|
303
|
+
const ttl = linkResults && linkResults.cache?.ttl;
|
|
304
|
+
pageTtl = shortestTtl(ttl || undefined, pageTtl);
|
|
301
305
|
}
|
|
302
306
|
const linkedAssetContent = stringBuilder.toString();
|
|
303
307
|
// Link LWR related resources
|
|
@@ -312,6 +316,7 @@ export class LwrViewRegistry {
|
|
|
312
316
|
resourceRegistry,
|
|
313
317
|
runtimeEnvironment,
|
|
314
318
|
runtimeParams,
|
|
319
|
+
bundleConfig: this.globalConfig.bundleConfig,
|
|
315
320
|
});
|
|
316
321
|
return {
|
|
317
322
|
// ...viewDefinition,
|
|
@@ -321,6 +326,7 @@ export class LwrViewRegistry {
|
|
|
321
326
|
assetReferences: reduceSourceAssetReferences(linkedMetadata.assetReferences),
|
|
322
327
|
...viewRecord,
|
|
323
328
|
},
|
|
329
|
+
cache: { ttl: pageTtl },
|
|
324
330
|
};
|
|
325
331
|
}
|
|
326
332
|
return {
|
|
@@ -329,6 +335,7 @@ export class LwrViewRegistry {
|
|
|
329
335
|
viewRecord: {
|
|
330
336
|
assetReferences: reduceSourceAssetReferences(linkedMetadata.assetReferences),
|
|
331
337
|
},
|
|
338
|
+
cache: { ttl: pageTtl },
|
|
332
339
|
};
|
|
333
340
|
}
|
|
334
341
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ModuleRegistry, RenderedViewMetadata, RenderedViewRecord, ResourceRegistry, RuntimeEnvironment, RuntimeParams, View, ViewParams, ModuleBundler } from '@lwrjs/types';
|
|
1
|
+
import { BundleConfig, ModuleRegistry, RenderedViewMetadata, RenderedViewRecord, ResourceRegistry, RuntimeEnvironment, RuntimeParams, View, ViewParams, ModuleBundler } from '@lwrjs/types';
|
|
2
2
|
export interface LwrResourcesLinkedContext extends ResourceContext {
|
|
3
3
|
lwrResourcesId: string;
|
|
4
4
|
}
|
|
@@ -9,6 +9,7 @@ interface ResourceContext {
|
|
|
9
9
|
moduleRegistry: ModuleRegistry;
|
|
10
10
|
moduleBundler: ModuleBundler;
|
|
11
11
|
resourceRegistry: ResourceRegistry;
|
|
12
|
+
bundleConfig: BundleConfig;
|
|
12
13
|
}
|
|
13
14
|
export declare function getHtmlResources(view: View, viewParams: ViewParams, resourceContext: ResourceContext): Promise<{
|
|
14
15
|
partial: string;
|