@lwrjs/view-registry 0.10.0-alpha.9 → 0.10.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 +29 -13
- package/build/cjs/linkers/legacy_view_bootstrap.cjs +115 -99
- package/build/cjs/linkers/preload-utils.cjs +84 -0
- package/build/cjs/linkers/utils.cjs +1 -40
- package/build/cjs/linkers/view_bootstrap.cjs +109 -92
- package/build/cjs/utils.cjs +5 -13
- package/build/cjs/view-handler.cjs +27 -10
- package/build/es/index.d.ts +3 -3
- package/build/es/index.js +30 -17
- package/build/es/linkers/legacy_view_bootstrap.d.ts +1 -1
- package/build/es/linkers/legacy_view_bootstrap.js +153 -135
- package/build/es/linkers/link-lwr-resources.d.ts +1 -1
- package/build/es/linkers/preload-utils.d.ts +17 -0
- package/build/es/linkers/preload-utils.js +77 -0
- package/build/es/linkers/utils.d.ts +1 -8
- package/build/es/linkers/utils.js +4 -53
- package/build/es/linkers/view_bootstrap.d.ts +1 -1
- package/build/es/linkers/view_bootstrap.js +141 -122
- package/build/es/utils.d.ts +2 -2
- package/build/es/utils.js +5 -13
- package/build/es/view-handler.d.ts +1 -1
- package/build/es/view-handler.js +24 -10
- package/package.json +9 -7
package/build/cjs/index.cjs
CHANGED
|
@@ -28,14 +28,15 @@ __export(exports, {
|
|
|
28
28
|
LwrViewRegistry: () => LwrViewRegistry
|
|
29
29
|
});
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
31
32
|
var import_utils = __toModule(require("./utils.cjs"));
|
|
32
33
|
var import_link_lwr_resources = __toModule(require("./linkers/link-lwr-resources.cjs"));
|
|
34
|
+
var import_lru_cache = __toModule(require("lru-cache"));
|
|
33
35
|
var import_view_handler = __toModule(require("./view-handler.cjs"));
|
|
34
36
|
var LwrViewRegistry = class {
|
|
35
37
|
constructor(context, globalConfig) {
|
|
36
38
|
this.viewProviders = [];
|
|
37
39
|
this.compiledViews = new Map();
|
|
38
|
-
this.viewDefinitions = new Map();
|
|
39
40
|
this.immutableAssets = new Map();
|
|
40
41
|
this.pendingViewDefinitions = new import_shared_utils.InflightTasks();
|
|
41
42
|
this.name = "lwr-view-registry";
|
|
@@ -49,14 +50,17 @@ var LwrViewRegistry = class {
|
|
|
49
50
|
this.globalData = context.globalData;
|
|
50
51
|
this.appEmitter = context.appEmitter;
|
|
51
52
|
const observer = context.appObserver;
|
|
53
|
+
this.viewDefinitions = new import_lru_cache.LRUCache({max: parseInt(process.env.VIEW_CACHE_SIZE || "500", 10)});
|
|
52
54
|
observer.onViewSourceChange(({payload}) => this.onViewSourceChange(payload));
|
|
53
55
|
observer.onModuleDefinitionChange(({payload}) => this.onModuleDefinitionChange(payload));
|
|
54
56
|
observer.onAssetSourceChange(({payload}) => this.onAssetSourceChange(payload));
|
|
55
57
|
}
|
|
56
58
|
async onModuleDefinitionChange(moduleDefinition) {
|
|
57
59
|
const versionedSpecifier = (0, import_shared_utils.getSpecifier)(moduleDefinition);
|
|
58
|
-
for (const [id,
|
|
59
|
-
const {
|
|
60
|
+
for (const [id, viewDefEntry] of this.viewDefinitions.entries()) {
|
|
61
|
+
const {
|
|
62
|
+
viewDefinition: {viewRecord}
|
|
63
|
+
} = viewDefEntry;
|
|
60
64
|
const uriMap = viewRecord.bootstrapModule?.flatGraph.uriMap;
|
|
61
65
|
if (uriMap) {
|
|
62
66
|
Object.keys(uriMap);
|
|
@@ -74,12 +78,12 @@ var LwrViewRegistry = class {
|
|
|
74
78
|
const {contentTemplate, rootComponent} = compiledView.viewId;
|
|
75
79
|
const compiledViewCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({contentTemplate, rootComponent});
|
|
76
80
|
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
77
|
-
for (const [id,
|
|
81
|
+
for (const [id, viewDefEntry] of this.viewDefinitions.entries()) {
|
|
78
82
|
const {
|
|
79
83
|
contentTemplate: eContentTempl,
|
|
80
84
|
layoutTemplate: eLayoutTemplate,
|
|
81
85
|
rootComponent: eRootComponent
|
|
82
|
-
} = view;
|
|
86
|
+
} = viewDefEntry.view;
|
|
83
87
|
if (eContentTempl === contentTemplate || eLayoutTemplate === contentTemplate || eRootComponent === rootComponent) {
|
|
84
88
|
this.viewDefinitions.delete(id);
|
|
85
89
|
}
|
|
@@ -87,8 +91,10 @@ var LwrViewRegistry = class {
|
|
|
87
91
|
}
|
|
88
92
|
onAssetSourceChange(asset) {
|
|
89
93
|
const assetId = asset.entry;
|
|
90
|
-
for (const [id,
|
|
91
|
-
const {
|
|
94
|
+
for (const [id, viewDefEntry] of this.viewDefinitions.entries()) {
|
|
95
|
+
const {
|
|
96
|
+
viewDefinition: {viewRecord}
|
|
97
|
+
} = viewDefEntry;
|
|
92
98
|
const someAssets = viewRecord.assetReferences?.some((ref) => {
|
|
93
99
|
return ref.override?.entry === assetId;
|
|
94
100
|
});
|
|
@@ -172,13 +178,23 @@ var LwrViewRegistry = class {
|
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
180
|
const pendingViewDefCacheKey = viewDefCacheKey + viewParamKey;
|
|
175
|
-
const viewDefinition = await this.pendingViewDefinitions.execute(pendingViewDefCacheKey, () =>
|
|
181
|
+
const viewDefinition = await this.pendingViewDefinitions.execute(pendingViewDefCacheKey, () => (0, import_instrumentation.getTracer)().trace({
|
|
182
|
+
name: import_instrumentation.ViewSpan.Render,
|
|
183
|
+
attributes: {
|
|
184
|
+
view: view.id,
|
|
185
|
+
ssr: view.bootstrap?.ssr === true
|
|
186
|
+
}
|
|
187
|
+
}, () => this.renderView(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions)));
|
|
176
188
|
if (cacheDisabled === false) {
|
|
177
|
-
this.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
189
|
+
const route = this.globalConfig.routes.find((r) => r.id === view.id);
|
|
190
|
+
const ttl = (0, import_shared_utils.shortestTtl)(viewDefinition.cache?.ttl, route?.cache?.ttl);
|
|
191
|
+
if (ttl !== 0) {
|
|
192
|
+
this.viewDefinitions.set(viewDefCacheKey, {
|
|
193
|
+
view,
|
|
194
|
+
viewDefinition,
|
|
195
|
+
paramKey: viewParamKey
|
|
196
|
+
}, {ttl: ttl ? ttl * 1e3 : void 0});
|
|
197
|
+
}
|
|
182
198
|
}
|
|
183
199
|
return viewDefinition;
|
|
184
200
|
}
|
|
@@ -30,6 +30,7 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
|
30
30
|
var import_identity = __toModule(require("@lwrjs/app-service/identity"));
|
|
31
31
|
var import_utils = __toModule(require("../utils.cjs"));
|
|
32
32
|
var import_utils2 = __toModule(require("./utils.cjs"));
|
|
33
|
+
var import_preload_utils = __toModule(require("./preload-utils.cjs"));
|
|
33
34
|
async function getHtmlResources(view, viewParams, resourceContext) {
|
|
34
35
|
const {
|
|
35
36
|
runtimeEnvironment,
|
|
@@ -39,8 +40,13 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
39
40
|
resourceRegistry,
|
|
40
41
|
viewMetadata
|
|
41
42
|
} = resourceContext;
|
|
43
|
+
const {lwrVersion, format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
|
|
44
|
+
const {customElements} = viewMetadata;
|
|
45
|
+
const version = lwrVersion;
|
|
46
|
+
const isAMD = format === "amd";
|
|
42
47
|
const {bundleConfig} = resourceContext;
|
|
43
48
|
const {external = {}} = bundleConfig;
|
|
49
|
+
const groups = isAMD ? bundleConfig.groups || {} : {};
|
|
44
50
|
const isExternal = function(rawSpecifier) {
|
|
45
51
|
const {specifier} = (0, import_shared_utils.explodeSpecifier)(rawSpecifier);
|
|
46
52
|
return Object.keys(external).some((e) => specifier === e);
|
|
@@ -52,10 +58,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
52
58
|
preloadModules: []
|
|
53
59
|
}
|
|
54
60
|
} = view;
|
|
55
|
-
const
|
|
56
|
-
const {
|
|
57
|
-
const version = lwrVersion;
|
|
58
|
-
const isAMD = format === "amd";
|
|
61
|
+
const defRegistry = bundle ? moduleBundler : moduleRegistry;
|
|
62
|
+
const depth = isAMD ? {static: import_shared_utils.GraphDepth.ALL, dynamic: 1} : {static: import_shared_utils.GraphDepth.NONE, dynamic: 0};
|
|
59
63
|
const appIdentity = {
|
|
60
64
|
appName,
|
|
61
65
|
format: runtimeEnvironment.format,
|
|
@@ -69,116 +73,132 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
69
73
|
const imports = {};
|
|
70
74
|
const rootComponents = [];
|
|
71
75
|
const requiredAmdModules = [];
|
|
72
|
-
const
|
|
76
|
+
const viewPreloads = {
|
|
77
|
+
uris: [],
|
|
78
|
+
specifiers: [],
|
|
79
|
+
groups: new Map()
|
|
80
|
+
};
|
|
73
81
|
const isSSR = view.bootstrap?.ssr;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} else {
|
|
83
|
-
fallbackShimBundle = "lwr-loader-shim-legacy.bundle.js";
|
|
84
|
-
def = await resourceRegistry.getResource({specifier: fallbackShimBundle, version}, runtimeEnvironment, runtimeParams);
|
|
85
|
-
}
|
|
82
|
+
let bootstrapModuleRef, versionedSpecifier = bootstrapSpecifier;
|
|
83
|
+
const customElementsRecords = [];
|
|
84
|
+
const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
|
|
85
|
+
const viewContainsLiveElements = !isSSR || flattenedElements.some(({props}) => (0, import_shared_utils.getHydrateDirective)(props));
|
|
86
|
+
if (viewContainsLiveElements) {
|
|
87
|
+
if (isAMD) {
|
|
88
|
+
const shimBundle = debug || minify === false ? "lwr-loader-shim-legacy.bundle.js" : "lwr-loader-shim-legacy.bundle.min.js";
|
|
89
|
+
let def = await resourceRegistry.getResource({specifier: shimBundle, version}, runtimeEnvironment, runtimeParams);
|
|
86
90
|
if (!def) {
|
|
87
|
-
|
|
91
|
+
let fallbackShimBundle;
|
|
92
|
+
if (shimBundle === "lwr-loader-shim-legacy.bundle.js") {
|
|
93
|
+
fallbackShimBundle = "lwr-loader-shim-legacy.bundle.min.js";
|
|
94
|
+
def = await resourceRegistry.getResource({specifier: fallbackShimBundle, version}, runtimeEnvironment, runtimeParams);
|
|
95
|
+
} else {
|
|
96
|
+
fallbackShimBundle = "lwr-loader-shim-legacy.bundle.js";
|
|
97
|
+
def = await resourceRegistry.getResource({specifier: fallbackShimBundle, version}, runtimeEnvironment, runtimeParams);
|
|
98
|
+
}
|
|
99
|
+
if (!def) {
|
|
100
|
+
throw Error("Failed to find definition of resource: " + shimBundle);
|
|
101
|
+
}
|
|
88
102
|
}
|
|
103
|
+
requiredResources.push(def);
|
|
104
|
+
const errorShimDef = await resourceRegistry.getResource({specifier: "lwr-error-shim.js", version}, runtimeEnvironment, runtimeParams);
|
|
105
|
+
if (!errorShimDef) {
|
|
106
|
+
throw Error("Failed to find definition of resource: lwr-error-shim.js");
|
|
107
|
+
}
|
|
108
|
+
requiredResources.push(errorShimDef);
|
|
89
109
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!isExternal(depSpecifier)) {
|
|
105
|
-
const uri2 = bootstrapModuleGraph.uriMap[depSpecifier];
|
|
106
|
-
preloadModulesMeta.set(depSpecifier, uri2);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if ((0, import_shared_utils.isBundler)(defRegistry)) {
|
|
110
|
-
for (const specifier of preloadModules) {
|
|
111
|
-
await (0, import_utils2.getPreloadModulesMeta)(specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
|
|
110
|
+
const bootstrapModuleGraph = await (0, import_shared_utils.getModuleGraphs)(bootstrapSpecifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
|
|
111
|
+
bootstrapModuleRef = {
|
|
112
|
+
specifier: bootstrapModuleGraph.graphs[0].specifier,
|
|
113
|
+
flatGraph: bootstrapModuleGraph,
|
|
114
|
+
resources: configResources
|
|
115
|
+
};
|
|
116
|
+
versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
|
|
117
|
+
const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
|
|
118
|
+
moduleResources.push((0, import_utils.getModuleResourceByUri)(uri, runtimeEnvironment, {isPreload: false, isSSR}));
|
|
119
|
+
for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
|
|
120
|
+
if (!isExternal(depSpecifier)) {
|
|
121
|
+
const uri2 = bootstrapModuleGraph.uriMap[depSpecifier];
|
|
122
|
+
(0, import_preload_utils.setPreloadModulesMeta)(depSpecifier, uri2, groups, viewPreloads);
|
|
123
|
+
}
|
|
112
124
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
imports[versionedSpecifier] = uri;
|
|
117
|
-
for (const staticDep of bootstrapModuleGraph.graphs[0].static) {
|
|
118
|
-
const uri2 = bootstrapModuleGraph.uriMap[staticDep];
|
|
119
|
-
imports[staticDep] = uri2;
|
|
120
|
-
if (services && services.length) {
|
|
121
|
-
requiredAmdModules.push(staticDep);
|
|
125
|
+
if ((0, import_shared_utils.isBundler)(defRegistry)) {
|
|
126
|
+
for (const specifier of preloadModules) {
|
|
127
|
+
await (0, import_preload_utils.getPreloadModulesMeta)(specifier, viewPreloads, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
if (isAMD) {
|
|
131
|
+
requiredAmdModules.push(versionedSpecifier);
|
|
132
|
+
imports[versionedSpecifier] = uri;
|
|
133
|
+
for (const staticDep of bootstrapModuleGraph.graphs[0].static) {
|
|
134
|
+
const uri2 = bootstrapModuleGraph.uriMap[staticDep];
|
|
135
|
+
imports[staticDep] = uri2;
|
|
136
|
+
if (services && services.length) {
|
|
137
|
+
requiredAmdModules.push(staticDep);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const dynamicDep of bootstrapModuleGraph.graphs[0].dynamicRefs) {
|
|
141
|
+
const uri2 = bootstrapModuleGraph.uriMap[dynamicDep];
|
|
142
|
+
if (uri2) {
|
|
143
|
+
imports[dynamicDep] = uri2;
|
|
144
|
+
} else {
|
|
145
|
+
import_shared_utils.logger.warn("Skipping unknown dynamic import " + dynamicDep);
|
|
146
|
+
}
|
|
130
147
|
}
|
|
131
148
|
}
|
|
132
149
|
}
|
|
133
|
-
const customElementsRecords = [];
|
|
134
|
-
const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
|
|
135
150
|
await Promise.all(flattenedElements.map(async ({tagName: element, props}) => {
|
|
136
151
|
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);
|
|
137
152
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
if (!isSSR || (0, import_shared_utils.getHydrateDirective)(props)) {
|
|
154
|
+
const specifier = graph.graphs[0].specifier;
|
|
155
|
+
const uri = graph.uriMap[specifier];
|
|
156
|
+
(0, import_preload_utils.setPreloadModulesMeta)(specifier, uri, groups, viewPreloads);
|
|
157
|
+
if (bundle) {
|
|
158
|
+
for (const depSpecifier of graph.graphs[0].static) {
|
|
159
|
+
if (!isExternal(depSpecifier)) {
|
|
160
|
+
const uri2 = graph.uriMap[depSpecifier];
|
|
161
|
+
(0, import_preload_utils.setPreloadModulesMeta)(depSpecifier, uri2, groups, viewPreloads);
|
|
162
|
+
}
|
|
146
163
|
}
|
|
147
164
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
165
|
+
rootComponents.push(specifier);
|
|
166
|
+
imports[specifier] = uri;
|
|
167
|
+
if (isAMD) {
|
|
168
|
+
for (const staticDep of graph.graphs[0].static) {
|
|
169
|
+
const uri2 = graph.uriMap[staticDep];
|
|
170
|
+
imports[staticDep] = uri2;
|
|
171
|
+
}
|
|
172
|
+
for (const dynamicDep of graph.graphs[0].dynamicRefs) {
|
|
173
|
+
const uri2 = graph.uriMap[dynamicDep];
|
|
174
|
+
imports[dynamicDep] = uri2;
|
|
175
|
+
}
|
|
159
176
|
}
|
|
160
177
|
}
|
|
161
178
|
}));
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
if (viewContainsLiveElements) {
|
|
180
|
+
configResources.unshift((0, import_utils2.getViewBootstrapConfigurationResource)({
|
|
181
|
+
id: view.id,
|
|
182
|
+
url: viewParams?.page?.url,
|
|
183
|
+
configAsSrc: view.bootstrap?.configAsSrc || false
|
|
184
|
+
}, {
|
|
185
|
+
appId: appIdentity.appName,
|
|
186
|
+
bootstrapModule: versionedSpecifier,
|
|
187
|
+
autoBoot: view.bootstrap?.autoBoot === false ? false : true,
|
|
188
|
+
importMappings: {
|
|
189
|
+
imports,
|
|
190
|
+
default: (0, import_shared_utils.getModuleUriPrefix)(runtimeEnvironment, runtimeParams)
|
|
191
|
+
},
|
|
192
|
+
rootComponents,
|
|
193
|
+
...isAMD && {requiredModules: requiredAmdModules},
|
|
194
|
+
...isAMD && {preloadModules: viewPreloads.specifiers}
|
|
195
|
+
}, runtimeEnvironment, runtimeParams));
|
|
196
|
+
}
|
|
178
197
|
if (!isAMD && hmrEnabled) {
|
|
179
|
-
configResources.unshift(
|
|
198
|
+
configResources.unshift((0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
|
|
180
199
|
}
|
|
181
|
-
|
|
200
|
+
const dedupedUris = [...new Set(viewPreloads.uris)];
|
|
201
|
+
for (const preloadUri of dedupedUris) {
|
|
182
202
|
moduleResources.push((0, import_utils.getModuleResourceByUri)(preloadUri, runtimeEnvironment, {isPreload: true, isSSR}));
|
|
183
203
|
}
|
|
184
204
|
const htmlResources = await Promise.all([...configResources, ...requiredResources, ...moduleResources].map(import_utils.generateHtmlTag));
|
|
@@ -187,11 +207,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
187
207
|
viewRecord: {
|
|
188
208
|
resources: requiredResources,
|
|
189
209
|
customElements: customElementsRecords,
|
|
190
|
-
bootstrapModule:
|
|
191
|
-
specifier: bootstrapModuleGraph.graphs[0].specifier,
|
|
192
|
-
flatGraph: bootstrapModuleGraph,
|
|
193
|
-
resources: configResources
|
|
194
|
-
}
|
|
210
|
+
bootstrapModule: bootstrapModuleRef
|
|
195
211
|
}
|
|
196
212
|
};
|
|
197
213
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/view-registry/src/linkers/preload-utils.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
getPreloadModulesMeta: () => getPreloadModulesMeta,
|
|
28
|
+
setPreloadModulesMeta: () => setPreloadModulesMeta
|
|
29
|
+
});
|
|
30
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
|
+
function setPreloadModulesMeta(specifier, uri, groups, preloads) {
|
|
32
|
+
const [removedVersion, version] = specifier.split("/v/");
|
|
33
|
+
const normalizedSpecifier = version === import_shared_utils.VERSION_NOT_PROVIDED ? removedVersion : specifier;
|
|
34
|
+
specifier = normalizedSpecifier;
|
|
35
|
+
const preloadModulesSpecifiers = preloads.specifiers;
|
|
36
|
+
const preloadBundleGroupsMap = preloads.groups;
|
|
37
|
+
const preloadModulesURIs = preloads.uris;
|
|
38
|
+
preloadModulesSpecifiers.push(specifier);
|
|
39
|
+
const {specifier: unversionedSpecifier} = (0, import_shared_utils.explodeSpecifier)(specifier);
|
|
40
|
+
const groupName = (0, import_shared_utils.getGroupName)(unversionedSpecifier, groups);
|
|
41
|
+
if (groupName && preloadBundleGroupsMap.has(groupName)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
preloadModulesURIs.push(uri);
|
|
45
|
+
groupName && preloadBundleGroupsMap.set(groupName, true);
|
|
46
|
+
}
|
|
47
|
+
async function getPreloadModulesMeta(specifier, viewPreloads, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending) {
|
|
48
|
+
const {exclude = [], external = {}, groups = {}} = bundleConfig;
|
|
49
|
+
const isExternal = function(rawSpecifier) {
|
|
50
|
+
const {specifier: specifier2} = (0, import_shared_utils.explodeSpecifier)(rawSpecifier);
|
|
51
|
+
return Object.keys(external).includes(specifier2);
|
|
52
|
+
};
|
|
53
|
+
const isExclude = function(specifier2) {
|
|
54
|
+
return exclude.includes(specifier2);
|
|
55
|
+
};
|
|
56
|
+
if (isExternal(specifier)) {
|
|
57
|
+
import_shared_utils.logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
58
|
+
} else {
|
|
59
|
+
const versionedModuleId = await (0, import_shared_utils.getVersionedModuleId)(specifier, moduleRegistry);
|
|
60
|
+
const versionedModuleSpecifier = (0, import_shared_utils.getSpecifier)({
|
|
61
|
+
specifier,
|
|
62
|
+
version: (0, import_shared_utils.normalizeVersionToUri)(versionedModuleId.version)
|
|
63
|
+
});
|
|
64
|
+
const uri = await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
65
|
+
const normalizedSpecifier = versionedModuleId.version === import_shared_utils.VERSION_NOT_PROVIDED ? specifier : versionedModuleSpecifier;
|
|
66
|
+
setPreloadModulesMeta(normalizedSpecifier, uri, groups, viewPreloads);
|
|
67
|
+
if (exclude.length || Object.keys(groups).length) {
|
|
68
|
+
const preloadModuleRecord = await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams);
|
|
69
|
+
const {imports} = preloadModuleRecord.bundleRecord;
|
|
70
|
+
if (imports) {
|
|
71
|
+
if (!pending) {
|
|
72
|
+
pending = new Map();
|
|
73
|
+
}
|
|
74
|
+
for (let i = 0; i < imports.length; i++) {
|
|
75
|
+
const imp = imports[i];
|
|
76
|
+
if (!pending.has(imp.specifier) && (isExclude(imp.specifier) || (0, import_shared_utils.isGroupie)(imp.specifier, groups))) {
|
|
77
|
+
pending.set(imp.specifier, true);
|
|
78
|
+
await getPreloadModulesMeta(imp.specifier, viewPreloads, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -25,7 +25,6 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
flattenCustomElements: () => flattenCustomElements,
|
|
28
|
-
getPreloadModulesMeta: () => getPreloadModulesMeta,
|
|
29
28
|
getViewBootstrapConfigurationResource: () => getViewBootstrapConfigurationResource,
|
|
30
29
|
getViewHmrConfigurationResource: () => getViewHmrConfigurationResource
|
|
31
30
|
});
|
|
@@ -54,7 +53,7 @@ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironm
|
|
|
54
53
|
...config,
|
|
55
54
|
endpoints
|
|
56
55
|
})});`,
|
|
57
|
-
`globalThis.process = { env: { NODE_ENV: "${runtimeEnvironment.serverMode}" } };`
|
|
56
|
+
`globalThis.process = { env: { NODE_ENV: "${runtimeEnvironment.serverMode}", SSR: false } };`
|
|
58
57
|
].filter(Boolean).join("\n");
|
|
59
58
|
if (viewInfo.configAsSrc) {
|
|
60
59
|
const viewUrl = viewInfo.url || "/";
|
|
@@ -121,41 +120,3 @@ function flattenCustomElements(arr, isSSR = false) {
|
|
|
121
120
|
flatten(arr);
|
|
122
121
|
return ret;
|
|
123
122
|
}
|
|
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
|
-
}
|