@lwrjs/view-registry 0.9.0-alpha.32 → 0.9.0-alpha.33
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/linkers/legacy_view_bootstrap.cjs +15 -31
- package/build/cjs/linkers/utils.cjs +39 -0
- package/build/cjs/linkers/view_bootstrap.cjs +15 -31
- package/build/es/linkers/legacy_view_bootstrap.js +19 -41
- package/build/es/linkers/utils.d.ts +7 -1
- package/build/es/linkers/utils.js +51 -1
- package/build/es/linkers/view_bootstrap.js +19 -41
- package/package.json +6 -6
|
@@ -37,9 +37,10 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
37
37
|
moduleRegistry,
|
|
38
38
|
moduleBundler,
|
|
39
39
|
resourceRegistry,
|
|
40
|
-
viewMetadata
|
|
41
|
-
bundleConfig: {external = {}}
|
|
40
|
+
viewMetadata
|
|
42
41
|
} = resourceContext;
|
|
42
|
+
const {bundleConfig} = resourceContext;
|
|
43
|
+
const {external = {}} = bundleConfig;
|
|
43
44
|
const isExternal = function(rawSpecifier) {
|
|
44
45
|
const {specifier} = (0, import_shared_utils.explodeSpecifier)(rawSpecifier);
|
|
45
46
|
return Object.keys(external).some((e) => specifier === e);
|
|
@@ -61,7 +62,6 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
61
62
|
resourceType: import_identity.AppResourceEnum.MODULE
|
|
62
63
|
};
|
|
63
64
|
const bootstrapSpecifier = bootstrapModule || (0, import_identity.getAppSpecifier)(appIdentity);
|
|
64
|
-
const preloadModuleUris = new Set();
|
|
65
65
|
const moduleResources = [];
|
|
66
66
|
const requiredResources = [];
|
|
67
67
|
const configResources = [];
|
|
@@ -69,7 +69,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
69
69
|
const imports = {};
|
|
70
70
|
const rootComponents = [];
|
|
71
71
|
const requiredAmdModules = [];
|
|
72
|
-
const
|
|
72
|
+
const preloadModulesMeta = new Map();
|
|
73
73
|
const isSSR = view.bootstrap?.ssr;
|
|
74
74
|
if (isAMD) {
|
|
75
75
|
const shimBundle = debug || minify === false ? "lwr-loader-shim-legacy.bundle.js" : "lwr-loader-shim-legacy.bundle.min.js";
|
|
@@ -92,27 +92,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
92
92
|
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
|
|
93
93
|
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
94
94
|
if (!isExternal(depSpecifier)) {
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
const uri2 = bootstrapModuleGraph.uriMap[depSpecifier];
|
|
96
|
+
preloadModulesMeta.set(depSpecifier, uri2);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
const specifier
|
|
101
|
-
|
|
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 defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
110
|
-
preloadModuleUris.add(uri2);
|
|
111
|
-
if (versionedModuleId.version == import_shared_utils.VERSION_NOT_PROVIDED) {
|
|
112
|
-
preloadAmdModules.push(specifier);
|
|
113
|
-
} else {
|
|
114
|
-
preloadAmdModules.push(versionedModuleSpecifier);
|
|
115
|
-
}
|
|
99
|
+
if ((0, import_shared_utils.isBundler)(defRegistry)) {
|
|
100
|
+
for (const specifier of preloadModules) {
|
|
101
|
+
await (0, import_utils2.getPreloadModulesMeta)(specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
|
|
116
102
|
}
|
|
117
103
|
}
|
|
118
104
|
if (isAMD) {
|
|
@@ -141,19 +127,18 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
141
127
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
142
128
|
const specifier = graph.graphs[0].specifier;
|
|
143
129
|
const uri2 = graph.uriMap[specifier];
|
|
144
|
-
|
|
130
|
+
preloadModulesMeta.set(specifier, uri2);
|
|
145
131
|
if (bundle) {
|
|
146
132
|
for (const depSpecifier of graph.graphs[0].static) {
|
|
147
133
|
if (!isExternal(depSpecifier)) {
|
|
148
|
-
|
|
149
|
-
|
|
134
|
+
const uri3 = graph.uriMap[depSpecifier];
|
|
135
|
+
preloadModulesMeta.set(depSpecifier, uri3);
|
|
150
136
|
}
|
|
151
137
|
}
|
|
152
138
|
}
|
|
153
139
|
rootComponents.push(specifier);
|
|
154
140
|
imports[specifier] = uri2;
|
|
155
141
|
if (isAMD) {
|
|
156
|
-
preloadAmdModules.push(specifier);
|
|
157
142
|
for (const staticDep of graph.graphs[0].static) {
|
|
158
143
|
const uri3 = graph.uriMap[staticDep];
|
|
159
144
|
imports[staticDep] = uri3;
|
|
@@ -164,7 +149,6 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
164
149
|
}
|
|
165
150
|
}
|
|
166
151
|
}));
|
|
167
|
-
const dedupedPreloadAmdModules = [...new Set(preloadAmdModules)];
|
|
168
152
|
configResources.unshift(await (0, import_utils2.getViewBootstrapConfigurationResource)({
|
|
169
153
|
id: view.id,
|
|
170
154
|
url: viewParams?.page?.url,
|
|
@@ -179,13 +163,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
179
163
|
},
|
|
180
164
|
rootComponents,
|
|
181
165
|
...isAMD && {requiredModules: requiredAmdModules},
|
|
182
|
-
...isAMD && {preloadModules:
|
|
166
|
+
...isAMD && {preloadModules: Array.from(preloadModulesMeta.keys())}
|
|
183
167
|
}, runtimeEnvironment, runtimeParams));
|
|
184
168
|
if (!isAMD && hmrEnabled) {
|
|
185
169
|
configResources.unshift(await (0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
|
|
186
170
|
}
|
|
187
|
-
for (const preloadUri of
|
|
188
|
-
moduleResources.
|
|
171
|
+
for (const [, preloadUri] of preloadModulesMeta) {
|
|
172
|
+
moduleResources.push((0, import_utils.getModuleResourceByUri)(preloadUri, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
189
173
|
}
|
|
190
174
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(import_utils.generateHtmlTag));
|
|
191
175
|
return {
|
|
@@ -25,6 +25,7 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
flattenCustomElements: () => flattenCustomElements,
|
|
28
|
+
getPreloadModulesMeta: () => getPreloadModulesMeta,
|
|
28
29
|
getViewBootstrapConfigurationResource: () => getViewBootstrapConfigurationResource,
|
|
29
30
|
getViewHmrConfigurationResource: () => getViewHmrConfigurationResource
|
|
30
31
|
});
|
|
@@ -120,3 +121,41 @@ function flattenCustomElements(arr, isSSR = false) {
|
|
|
120
121
|
flatten(arr);
|
|
121
122
|
return ret;
|
|
122
123
|
}
|
|
124
|
+
async function getPreloadModulesMeta(specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending) {
|
|
125
|
+
const {exclude = [], external = {}} = bundleConfig;
|
|
126
|
+
const isExternal = function(rawSpecifier) {
|
|
127
|
+
const {specifier: specifier2} = (0, import_shared_utils.explodeSpecifier)(rawSpecifier);
|
|
128
|
+
return Object.keys(external).includes(specifier2);
|
|
129
|
+
};
|
|
130
|
+
const isExclude = function(specifier2) {
|
|
131
|
+
return exclude.includes(specifier2);
|
|
132
|
+
};
|
|
133
|
+
if (isExternal(specifier)) {
|
|
134
|
+
import_shared_utils.logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
135
|
+
} else {
|
|
136
|
+
const versionedModuleId = await (0, import_shared_utils.getVersionedModuleId)(specifier, moduleRegistry);
|
|
137
|
+
const versionedModuleSpecifier = (0, import_shared_utils.getSpecifier)({
|
|
138
|
+
specifier,
|
|
139
|
+
version: (0, import_shared_utils.normalizeVersionToUri)(versionedModuleId.version)
|
|
140
|
+
});
|
|
141
|
+
const uri = await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
142
|
+
const normalizedSpecifier = versionedModuleId.version === import_shared_utils.VERSION_NOT_PROVIDED ? specifier : versionedModuleSpecifier;
|
|
143
|
+
preloadModulesMeta.set(normalizedSpecifier, uri);
|
|
144
|
+
if (exclude.length) {
|
|
145
|
+
const preloadModuleRecord = await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
146
|
+
const {imports} = preloadModuleRecord.bundleRecord;
|
|
147
|
+
if (imports) {
|
|
148
|
+
if (!pending) {
|
|
149
|
+
pending = new Map();
|
|
150
|
+
}
|
|
151
|
+
for (let i = 0; i < imports.length; i++) {
|
|
152
|
+
const imp = imports[i];
|
|
153
|
+
if (!pending.has(imp.specifier) && isExclude(imp.specifier)) {
|
|
154
|
+
pending.set(imp.specifier, true);
|
|
155
|
+
await getPreloadModulesMeta(imp.specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -37,9 +37,10 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
37
37
|
moduleRegistry,
|
|
38
38
|
moduleBundler,
|
|
39
39
|
resourceRegistry,
|
|
40
|
-
viewMetadata
|
|
41
|
-
bundleConfig: {external = {}}
|
|
40
|
+
viewMetadata
|
|
42
41
|
} = resourceContext;
|
|
42
|
+
const {bundleConfig} = resourceContext;
|
|
43
|
+
const {external = {}} = bundleConfig;
|
|
43
44
|
const isExternal = function(rawSpecifier) {
|
|
44
45
|
const {specifier} = (0, import_shared_utils.explodeSpecifier)(rawSpecifier);
|
|
45
46
|
return Object.keys(external).some((e) => specifier === e);
|
|
@@ -62,7 +63,6 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
62
63
|
resourceType: import_identity.AppResourceEnum.MODULE
|
|
63
64
|
};
|
|
64
65
|
const bootstrapSpecifier = bootstrapModule || (0, import_identity.getAppSpecifier)(appIdentity);
|
|
65
|
-
const preloadModuleUris = new Set();
|
|
66
66
|
const moduleResources = [];
|
|
67
67
|
const requiredResources = [];
|
|
68
68
|
const configResources = [];
|
|
@@ -70,7 +70,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
70
70
|
const imports = {};
|
|
71
71
|
const rootComponents = [];
|
|
72
72
|
const requiredAmdModules = [];
|
|
73
|
-
const
|
|
73
|
+
const preloadModulesMeta = new Map();
|
|
74
74
|
const isSSR = view.bootstrap?.ssr;
|
|
75
75
|
if (isAMD) {
|
|
76
76
|
const shimBundle = debug || minify === false ? "lwr-loader-shim.bundle.js" : "lwr-loader-shim.bundle.min.js";
|
|
@@ -92,27 +92,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
92
92
|
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
|
|
93
93
|
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
94
94
|
if (!isExternal(depSpecifier)) {
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
const uri2 = bootstrapModuleGraph.uriMap[depSpecifier];
|
|
96
|
+
preloadModulesMeta.set(depSpecifier, uri2);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
const specifier
|
|
101
|
-
|
|
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 defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
110
|
-
preloadModuleUris.add(uri2);
|
|
111
|
-
if (versionedModuleId.version == import_shared_utils.VERSION_NOT_PROVIDED) {
|
|
112
|
-
preloadAmdModules.push(specifier);
|
|
113
|
-
} else {
|
|
114
|
-
preloadAmdModules.push(versionedModuleSpecifier);
|
|
115
|
-
}
|
|
99
|
+
if ((0, import_shared_utils.isBundler)(defRegistry)) {
|
|
100
|
+
for (const specifier of preloadModules) {
|
|
101
|
+
await (0, import_utils2.getPreloadModulesMeta)(specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
|
|
116
102
|
}
|
|
117
103
|
}
|
|
118
104
|
if (isAMD) {
|
|
@@ -142,19 +128,18 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
142
128
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
143
129
|
const specifier = graph.graphs[0].specifier;
|
|
144
130
|
const uri2 = graph.uriMap[specifier];
|
|
145
|
-
|
|
131
|
+
preloadModulesMeta.set(specifier, uri2);
|
|
146
132
|
if (bundle) {
|
|
147
133
|
for (const depSpecifier of graph.graphs[0].static) {
|
|
148
134
|
if (!isExternal(depSpecifier)) {
|
|
149
|
-
|
|
150
|
-
|
|
135
|
+
const uri3 = graph.uriMap[depSpecifier];
|
|
136
|
+
preloadModulesMeta.set(depSpecifier, uri3);
|
|
151
137
|
}
|
|
152
138
|
}
|
|
153
139
|
}
|
|
154
140
|
rootComponents.push(specifier);
|
|
155
141
|
imports[specifier] = uri2;
|
|
156
142
|
if (isAMD) {
|
|
157
|
-
preloadAmdModules.push(specifier);
|
|
158
143
|
for (const staticDep of graph.graphs[0].static) {
|
|
159
144
|
const uri3 = graph.uriMap[staticDep];
|
|
160
145
|
imports[staticDep] = uri3;
|
|
@@ -166,7 +151,6 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
166
151
|
}
|
|
167
152
|
importMetadata = await (0, import_shared_utils.toImportMetadata)(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
168
153
|
}
|
|
169
|
-
const dedupedPreloadAmdModules = [...new Set(preloadAmdModules)];
|
|
170
154
|
configResources.unshift(await (0, import_utils2.getViewBootstrapConfigurationResource)({
|
|
171
155
|
id: view.id,
|
|
172
156
|
url: viewParams?.page?.url,
|
|
@@ -179,13 +163,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
179
163
|
index: importMetadata?.index,
|
|
180
164
|
rootComponents,
|
|
181
165
|
...isAMD && {requiredModules: requiredAmdModules},
|
|
182
|
-
...isAMD && {preloadModules:
|
|
166
|
+
...isAMD && {preloadModules: Array.from(preloadModulesMeta.keys())}
|
|
183
167
|
}, runtimeEnvironment, runtimeParams));
|
|
184
168
|
if (!isAMD && hmrEnabled) {
|
|
185
169
|
configResources.unshift(await (0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
|
|
186
170
|
}
|
|
187
|
-
for (const preloadUri of
|
|
188
|
-
moduleResources.
|
|
171
|
+
for (const [, preloadUri] of preloadModulesMeta) {
|
|
172
|
+
moduleResources.push((0, import_utils.getModuleResourceByUri)(preloadUri, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
189
173
|
}
|
|
190
174
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(import_utils.generateHtmlTag));
|
|
191
175
|
const mapping = (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, runtimeParams);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { kebabCaseToModuleSpecifier, getModuleGraphs, GraphDepth, getModuleUriPrefix, logger,
|
|
1
|
+
import { kebabCaseToModuleSpecifier, getModuleGraphs, GraphDepth, getModuleUriPrefix, logger, explodeSpecifier, isBundler, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
|
|
3
3
|
import { generateHtmlTag, getModuleResourceByUri } from '../utils.js';
|
|
4
|
-
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
|
|
4
|
+
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, getPreloadModulesMeta, } from './utils.js';
|
|
5
5
|
export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
6
|
-
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata,
|
|
6
|
+
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata, } = resourceContext;
|
|
7
|
+
const { bundleConfig } = resourceContext;
|
|
8
|
+
const { external = {} } = bundleConfig;
|
|
7
9
|
const isExternal = function (rawSpecifier) {
|
|
8
10
|
const { specifier } = explodeSpecifier(rawSpecifier);
|
|
9
11
|
return Object.keys(external).some((e) => specifier === e);
|
|
@@ -28,7 +30,6 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
28
30
|
/*
|
|
29
31
|
Internal module and module dependency related resources used by the view to render view related components.
|
|
30
32
|
*/
|
|
31
|
-
const preloadModuleUris = new Set();
|
|
32
33
|
const moduleResources = [];
|
|
33
34
|
/*
|
|
34
35
|
External resources that the view depends. These resources include ones that an ViewDefinition client are required to load
|
|
@@ -49,7 +50,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
49
50
|
const requiredAmdModules = [];
|
|
50
51
|
// Collection of modules that will be preloaded. For AMD, it will be part of
|
|
51
52
|
// the preloadModules client bootstrap config
|
|
52
|
-
const
|
|
53
|
+
const preloadModulesMeta = new Map();
|
|
53
54
|
// Determine if server side rendering view modules
|
|
54
55
|
const isSSR = view.bootstrap?.ssr;
|
|
55
56
|
// ------ AMD Required module resources
|
|
@@ -86,36 +87,15 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
86
87
|
// PRELOAD the bootstrap module static dependencies as preloaded script resources
|
|
87
88
|
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
88
89
|
if (!isExternal(depSpecifier)) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
preloadAmdModules.push(depSpecifier);
|
|
90
|
+
const uri = bootstrapModuleGraph.uriMap[depSpecifier];
|
|
91
|
+
preloadModulesMeta.set(depSpecifier, uri);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
// PRELOAD configured preloadModules as preloaded script resources
|
|
95
|
-
|
|
96
|
-
const specifier
|
|
97
|
-
if (isExternal(specifier)) {
|
|
98
|
-
logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
95
|
+
if (isBundler(defRegistry)) {
|
|
96
|
+
for (const specifier of preloadModules) {
|
|
101
97
|
// eslint-disable-next-line no-await-in-loop
|
|
102
|
-
|
|
103
|
-
const versionedModuleSpecifier = getSpecifier({
|
|
104
|
-
specifier,
|
|
105
|
-
version: normalizeVersionToUri(versionedModuleId.version),
|
|
106
|
-
});
|
|
107
|
-
const uri = bootstrapModuleGraph.uriMap[versionedModuleSpecifier] ||
|
|
108
|
-
// eslint-disable-next-line no-await-in-loop
|
|
109
|
-
(await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams));
|
|
110
|
-
preloadModuleUris.add(uri);
|
|
111
|
-
// in AMD, we also need to tell the loader it's being preloaded
|
|
112
|
-
if (versionedModuleId.version == VERSION_NOT_PROVIDED) {
|
|
113
|
-
// If this is explicitly a non versioned specifier from static metadata key off the non versioned specifier
|
|
114
|
-
preloadAmdModules.push(specifier);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
preloadAmdModules.push(versionedModuleSpecifier);
|
|
118
|
-
}
|
|
98
|
+
await getPreloadModulesMeta(specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
|
|
119
99
|
}
|
|
120
100
|
}
|
|
121
101
|
if (isAMD) {
|
|
@@ -154,14 +134,13 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
154
134
|
// PRELOAD the custom element module as a link resource
|
|
155
135
|
const specifier = graph.graphs[0].specifier;
|
|
156
136
|
const uri = graph.uriMap[specifier];
|
|
157
|
-
|
|
137
|
+
preloadModulesMeta.set(specifier, uri);
|
|
158
138
|
// PRELOAD custom element static deps as link resources when bundling is ON
|
|
159
139
|
if (bundle) {
|
|
160
140
|
for (const depSpecifier of graph.graphs[0].static) {
|
|
161
141
|
if (!isExternal(depSpecifier)) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
preloadAmdModules.push(depSpecifier);
|
|
142
|
+
const uri = graph.uriMap[depSpecifier];
|
|
143
|
+
preloadModulesMeta.set(depSpecifier, uri);
|
|
165
144
|
}
|
|
166
145
|
}
|
|
167
146
|
}
|
|
@@ -169,7 +148,6 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
169
148
|
rootComponents.push(specifier);
|
|
170
149
|
imports[specifier] = uri;
|
|
171
150
|
if (isAMD) {
|
|
172
|
-
preloadAmdModules.push(specifier);
|
|
173
151
|
for (const staticDep of graph.graphs[0].static) {
|
|
174
152
|
const uri = graph.uriMap[staticDep];
|
|
175
153
|
// AMD ADD static module dep uri addressability
|
|
@@ -182,7 +160,6 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
182
160
|
}
|
|
183
161
|
}
|
|
184
162
|
}));
|
|
185
|
-
const dedupedPreloadAmdModules = [...new Set(preloadAmdModules)];
|
|
186
163
|
// ADD configuration of the bootstrapModule
|
|
187
164
|
configResources.unshift(await getViewBootstrapConfigurationResource({
|
|
188
165
|
id: view.id,
|
|
@@ -198,14 +175,15 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
198
175
|
},
|
|
199
176
|
rootComponents,
|
|
200
177
|
...(isAMD && { requiredModules: requiredAmdModules }),
|
|
201
|
-
|
|
178
|
+
// in AMD we need to tell the loader what modules we are preloading
|
|
179
|
+
...(isAMD && { preloadModules: Array.from(preloadModulesMeta.keys()) }),
|
|
202
180
|
}, runtimeEnvironment, runtimeParams));
|
|
203
181
|
if (!isAMD && hmrEnabled) {
|
|
204
182
|
configResources.unshift(await getViewHmrConfigurationResource(view, viewMetadata));
|
|
205
183
|
}
|
|
206
|
-
// PRELOAD script resources for preload module URIs
|
|
207
|
-
for (const preloadUri of
|
|
208
|
-
moduleResources.
|
|
184
|
+
// PRELOAD script resources for preload module URIs after the bootstrap module
|
|
185
|
+
for (const [, preloadUri] of preloadModulesMeta) {
|
|
186
|
+
moduleResources.push(getModuleResourceByUri(preloadUri, runtimeEnvironment, { isPreload: true, isSSR }));
|
|
209
187
|
}
|
|
210
188
|
// generate html partial
|
|
211
189
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(generateHtmlTag));
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata, CustomElementReference } from '@lwrjs/types';
|
|
1
|
+
import { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata, CustomElementReference, BundleConfig, ModuleBundler, ModuleRegistry } from '@lwrjs/types';
|
|
2
2
|
import { View, ViewInfo } from '@lwrjs/types';
|
|
3
3
|
export declare function getViewBootstrapConfigurationResource(viewInfo: ViewInfo, config: ClientBootstrapConfig, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): ResourceDefinition;
|
|
4
4
|
export declare function getViewHmrConfigurationResource(view: View, viewMetadata: RenderedViewMetadata): ResourceDefinition;
|
|
5
5
|
export declare function flattenCustomElements(arr: CustomElementReference[], isSSR?: boolean): CustomElementReference[];
|
|
6
|
+
/**
|
|
7
|
+
* Recursively gets preloadModules metadata starting with a specifer
|
|
8
|
+
* Note: don't call me unless you got bundles
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPreloadModulesMeta(specifier: string, // unversioned specifier
|
|
11
|
+
preloadModulesMeta: Map<string, string>, bundleConfig: BundleConfig, moduleRegistry: ModuleRegistry, defRegistry: ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, pending?: Map<string, boolean>): Promise<void>;
|
|
6
12
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getMappingUriPrefix, getModuleUriPrefix, getClientBootstrapConfigurationUri, hashContent, } from '@lwrjs/shared-utils';
|
|
1
|
+
import { getMappingUriPrefix, getModuleUriPrefix, getClientBootstrapConfigurationUri, hashContent, getVersionedModuleId, normalizeVersionToUri, logger, VERSION_NOT_PROVIDED, explodeSpecifier, getSpecifier, } from '@lwrjs/shared-utils';
|
|
2
2
|
const CONTENT_TYPE = 'application/javascript';
|
|
3
3
|
export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams) {
|
|
4
4
|
const { compat, debug, hmrEnabled, apiVersion, format } = runtimeEnvironment;
|
|
@@ -100,4 +100,54 @@ export function flattenCustomElements(arr, isSSR = false) {
|
|
|
100
100
|
flatten(arr);
|
|
101
101
|
return ret;
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Recursively gets preloadModules metadata starting with a specifer
|
|
105
|
+
* Note: don't call me unless you got bundles
|
|
106
|
+
*/
|
|
107
|
+
export async function getPreloadModulesMeta(specifier, // unversioned specifier
|
|
108
|
+
preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending) {
|
|
109
|
+
const { exclude = [], external = {} } = bundleConfig;
|
|
110
|
+
const isExternal = function (rawSpecifier) {
|
|
111
|
+
const { specifier } = explodeSpecifier(rawSpecifier);
|
|
112
|
+
return Object.keys(external).includes(specifier);
|
|
113
|
+
};
|
|
114
|
+
const isExclude = function (specifier) {
|
|
115
|
+
return exclude.includes(specifier);
|
|
116
|
+
};
|
|
117
|
+
if (isExternal(specifier)) {
|
|
118
|
+
logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// eslint-disable-next-line no-await-in-loop
|
|
122
|
+
const versionedModuleId = await getVersionedModuleId(specifier, moduleRegistry); // TODO replace moduleRegistry with defRegistry
|
|
123
|
+
const versionedModuleSpecifier = getSpecifier({
|
|
124
|
+
specifier,
|
|
125
|
+
version: normalizeVersionToUri(versionedModuleId.version),
|
|
126
|
+
});
|
|
127
|
+
const uri =
|
|
128
|
+
// eslint-disable-next-line no-await-in-loop
|
|
129
|
+
await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
130
|
+
// fallback to unversioned specifier if needed
|
|
131
|
+
const normalizedSpecifier = versionedModuleId.version === VERSION_NOT_PROVIDED ? specifier : versionedModuleSpecifier;
|
|
132
|
+
preloadModulesMeta.set(normalizedSpecifier, uri);
|
|
133
|
+
if (exclude.length) {
|
|
134
|
+
// check if we need to also preload any excluded dependencies of this preload module
|
|
135
|
+
const preloadModuleRecord = await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
136
|
+
const { imports } = preloadModuleRecord.bundleRecord;
|
|
137
|
+
if (imports) {
|
|
138
|
+
if (!pending) {
|
|
139
|
+
pending = new Map();
|
|
140
|
+
}
|
|
141
|
+
for (let i = 0; i < imports.length; i++) {
|
|
142
|
+
const imp = imports[i];
|
|
143
|
+
if (!pending.has(imp.specifier) && isExclude(imp.specifier)) {
|
|
144
|
+
pending.set(imp.specifier, true); // prevent dupe calls
|
|
145
|
+
// eslint-disable-next-line no-await-in-loop
|
|
146
|
+
await getPreloadModulesMeta(imp.specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
103
153
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { kebabCaseToModuleSpecifier, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, logger,
|
|
1
|
+
import { kebabCaseToModuleSpecifier, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, logger, explodeSpecifier, isBundler, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
|
|
3
3
|
import { generateHtmlTag, getModuleResourceByUri } from '../utils.js';
|
|
4
|
-
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
|
|
4
|
+
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, getPreloadModulesMeta, } from './utils.js';
|
|
5
5
|
export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
6
|
-
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata,
|
|
6
|
+
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata, } = resourceContext;
|
|
7
|
+
const { bundleConfig } = resourceContext;
|
|
8
|
+
const { external = {} } = bundleConfig;
|
|
7
9
|
const isExternal = function (rawSpecifier) {
|
|
8
10
|
const { specifier } = explodeSpecifier(rawSpecifier);
|
|
9
11
|
return Object.keys(external).some((e) => specifier === e);
|
|
@@ -29,7 +31,6 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
29
31
|
/*
|
|
30
32
|
Internal module and module dependency related resources used by the view to render view related components.
|
|
31
33
|
*/
|
|
32
|
-
const preloadModuleUris = new Set();
|
|
33
34
|
const moduleResources = [];
|
|
34
35
|
/*
|
|
35
36
|
External resources that the view depends. These resources include ones that an ViewDefinition client are required to load
|
|
@@ -50,7 +51,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
50
51
|
const requiredAmdModules = [];
|
|
51
52
|
// Collection of modules that will be preloaded. For AMD, it will be part of
|
|
52
53
|
// the preloadModules client bootstrap config
|
|
53
|
-
const
|
|
54
|
+
const preloadModulesMeta = new Map();
|
|
54
55
|
// Determine if server side rendering view modules
|
|
55
56
|
const isSSR = view.bootstrap?.ssr;
|
|
56
57
|
// ------ AMD Required module resources
|
|
@@ -83,36 +84,15 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
83
84
|
// PRELOAD the bootstrap module static dependencies as preloaded script resources
|
|
84
85
|
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
85
86
|
if (!isExternal(depSpecifier)) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
preloadAmdModules.push(depSpecifier);
|
|
87
|
+
const uri = bootstrapModuleGraph.uriMap[depSpecifier];
|
|
88
|
+
preloadModulesMeta.set(depSpecifier, uri);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
// PRELOAD configured preloadModules as preloaded script resources
|
|
92
|
-
|
|
93
|
-
const specifier
|
|
94
|
-
if (isExternal(specifier)) {
|
|
95
|
-
logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
92
|
+
if (isBundler(defRegistry)) {
|
|
93
|
+
for (const specifier of preloadModules) {
|
|
98
94
|
// eslint-disable-next-line no-await-in-loop
|
|
99
|
-
|
|
100
|
-
const versionedModuleSpecifier = getSpecifier({
|
|
101
|
-
specifier,
|
|
102
|
-
version: normalizeVersionToUri(versionedModuleId.version),
|
|
103
|
-
});
|
|
104
|
-
const uri = bootstrapModuleGraph.uriMap[versionedModuleSpecifier] ||
|
|
105
|
-
// eslint-disable-next-line no-await-in-loop
|
|
106
|
-
(await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams));
|
|
107
|
-
preloadModuleUris.add(uri);
|
|
108
|
-
// in AMD, we also need to tell the loader it's being preloaded
|
|
109
|
-
if (versionedModuleId.version == VERSION_NOT_PROVIDED) {
|
|
110
|
-
// If this is explicitly a non versioned specifier from static metadata key off the non versioned specifier
|
|
111
|
-
preloadAmdModules.push(specifier);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
preloadAmdModules.push(versionedModuleSpecifier);
|
|
115
|
-
}
|
|
95
|
+
await getPreloadModulesMeta(specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
|
|
116
96
|
}
|
|
117
97
|
}
|
|
118
98
|
if (isAMD) {
|
|
@@ -153,14 +133,13 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
153
133
|
// PRELOAD the custom element module as a link resource
|
|
154
134
|
const specifier = graph.graphs[0].specifier;
|
|
155
135
|
const uri = graph.uriMap[specifier];
|
|
156
|
-
|
|
136
|
+
preloadModulesMeta.set(specifier, uri);
|
|
157
137
|
// PRELOAD custom element static deps as link resources when bundling is ON
|
|
158
138
|
if (bundle) {
|
|
159
139
|
for (const depSpecifier of graph.graphs[0].static) {
|
|
160
140
|
if (!isExternal(depSpecifier)) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
preloadAmdModules.push(depSpecifier);
|
|
141
|
+
const uri = graph.uriMap[depSpecifier];
|
|
142
|
+
preloadModulesMeta.set(depSpecifier, uri);
|
|
164
143
|
}
|
|
165
144
|
}
|
|
166
145
|
}
|
|
@@ -168,7 +147,6 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
168
147
|
rootComponents.push(specifier);
|
|
169
148
|
imports[specifier] = uri;
|
|
170
149
|
if (isAMD) {
|
|
171
|
-
preloadAmdModules.push(specifier);
|
|
172
150
|
for (const staticDep of graph.graphs[0].static) {
|
|
173
151
|
const uri = graph.uriMap[staticDep];
|
|
174
152
|
// AMD ADD static module dep uri addressability
|
|
@@ -183,7 +161,6 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
183
161
|
// eslint-disable-next-line no-await-in-loop
|
|
184
162
|
importMetadata = await toImportMetadata(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
185
163
|
}
|
|
186
|
-
const dedupedPreloadAmdModules = [...new Set(preloadAmdModules)];
|
|
187
164
|
// ADD configuration of the bootstrapModule
|
|
188
165
|
configResources.unshift(await getViewBootstrapConfigurationResource({
|
|
189
166
|
id: view.id,
|
|
@@ -197,14 +174,15 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
197
174
|
index: importMetadata?.index,
|
|
198
175
|
rootComponents,
|
|
199
176
|
...(isAMD && { requiredModules: requiredAmdModules }),
|
|
200
|
-
|
|
177
|
+
// in AMD we need to tell the loader what modules we are preloading
|
|
178
|
+
...(isAMD && { preloadModules: Array.from(preloadModulesMeta.keys()) }),
|
|
201
179
|
}, runtimeEnvironment, runtimeParams));
|
|
202
180
|
if (!isAMD && hmrEnabled) {
|
|
203
181
|
configResources.unshift(await getViewHmrConfigurationResource(view, viewMetadata));
|
|
204
182
|
}
|
|
205
|
-
// PRELOAD script resources for preload module URIs
|
|
206
|
-
for (const preloadUri of
|
|
207
|
-
moduleResources.
|
|
183
|
+
// PRELOAD script resources for preload module URIs after the bootstrap module
|
|
184
|
+
for (const [, preloadUri] of preloadModulesMeta) {
|
|
185
|
+
moduleResources.push(getModuleResourceByUri(preloadUri, runtimeEnvironment, { isPreload: true, isSSR }));
|
|
208
186
|
}
|
|
209
187
|
// generate html partial
|
|
210
188
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(generateHtmlTag));
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.33",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/app-service": "0.9.0-alpha.
|
|
34
|
-
"@lwrjs/diagnostics": "0.9.0-alpha.
|
|
35
|
-
"@lwrjs/shared-utils": "0.9.0-alpha.
|
|
33
|
+
"@lwrjs/app-service": "0.9.0-alpha.33",
|
|
34
|
+
"@lwrjs/diagnostics": "0.9.0-alpha.33",
|
|
35
|
+
"@lwrjs/shared-utils": "0.9.0-alpha.33"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
38
|
+
"@lwrjs/types": "0.9.0-alpha.33"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=16.0.0 <20"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "5700e9661fe6946d4b7b78c5ecd86348c08f0559"
|
|
44
44
|
}
|