@lwrjs/view-registry 0.6.0-alpha.1 → 0.6.0-alpha.10
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 +16 -9
- package/build/cjs/linkers/legacy_view_bootstrap.cjs +2 -1
- package/build/cjs/linkers/utils.cjs +21 -0
- package/build/cjs/linkers/view_bootstrap.cjs +2 -1
- package/build/cjs/utils.cjs +6 -6
- package/build/es/index.d.ts +4 -1
- package/build/es/index.js +20 -13
- package/build/es/linkers/legacy_view_bootstrap.js +3 -2
- package/build/es/linkers/utils.d.ts +2 -1
- package/build/es/linkers/utils.js +20 -0
- package/build/es/linkers/view_bootstrap.js +3 -2
- package/build/es/utils.js +4 -4
- package/build/es/view-handler.js +1 -0
- package/package.json +7 -8
- package/build/cjs/linkers/link-assets.cjs +0 -60
- package/build/es/linkers/link-assets.d.ts +0 -12
- package/build/es/linkers/link-assets.js +0 -33
package/build/cjs/index.cjs
CHANGED
|
@@ -29,7 +29,6 @@ __export(exports, {
|
|
|
29
29
|
});
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
31
|
var import_utils = __toModule(require("./utils.cjs"));
|
|
32
|
-
var import_link_assets = __toModule(require("./linkers/link-assets.cjs"));
|
|
33
32
|
var import_link_lwr_resources = __toModule(require("./linkers/link-lwr-resources.cjs"));
|
|
34
33
|
var import_view_handler = __toModule(require("./view-handler.cjs"));
|
|
35
34
|
var LwrViewRegistry = class {
|
|
@@ -45,6 +44,7 @@ var LwrViewRegistry = class {
|
|
|
45
44
|
this.moduleRegistry = context.moduleRegistry;
|
|
46
45
|
this.moduleBundler = context.moduleBundler;
|
|
47
46
|
this.assetRegistry = context.assetRegistry;
|
|
47
|
+
this.viewTransformers = context.viewTransformers || [];
|
|
48
48
|
this.globalConfig = globalConfig;
|
|
49
49
|
this.globalData = context.globalData;
|
|
50
50
|
this.appEmitter = context.appEmitter;
|
|
@@ -106,6 +106,9 @@ var LwrViewRegistry = class {
|
|
|
106
106
|
addViewProviders(providers) {
|
|
107
107
|
this.viewProviders.push(...providers);
|
|
108
108
|
}
|
|
109
|
+
addViewTransformers(transformers) {
|
|
110
|
+
this.viewTransformers.push(...transformers);
|
|
111
|
+
}
|
|
109
112
|
initializeViewProviders() {
|
|
110
113
|
return Promise.all(this.viewProviders.map((vp) => vp.initialize()));
|
|
111
114
|
}
|
|
@@ -272,20 +275,24 @@ var LwrViewRegistry = class {
|
|
|
272
275
|
} = viewContext;
|
|
273
276
|
const {skipMetadataCollection, freezeAssets} = renderOptions;
|
|
274
277
|
const {lwrResourcesId} = contentIds;
|
|
275
|
-
const {moduleRegistry,
|
|
278
|
+
const {moduleRegistry, resourceRegistry, moduleBundler} = this;
|
|
276
279
|
const runtimeEnvironment = {...runtimeEnv, immutableAssets: freezeAssets};
|
|
277
280
|
const {
|
|
278
281
|
renderedView: renderedViewContent,
|
|
279
282
|
metadata: renderedViewMetadata,
|
|
280
283
|
compiledView: {immutable = true}
|
|
281
284
|
} = renderedView;
|
|
282
|
-
const linkedMetadata = skipMetadataCollection ? await (0, import_shared_utils.extractMetadataFromHtml)(renderedViewContent)
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
+
const linkedMetadata = skipMetadataCollection ? renderedViewMetadata : await (0, import_shared_utils.extractMetadataFromHtml)(renderedViewContent);
|
|
286
|
+
const mergedViewContext = {
|
|
287
|
+
...viewContext,
|
|
285
288
|
runtimeEnvironment,
|
|
286
289
|
importer: importer || renderedView.compiledView.filePath
|
|
287
|
-
}
|
|
288
|
-
|
|
290
|
+
};
|
|
291
|
+
const stringBuilder = (0, import_shared_utils.createStringBuilder)(renderedViewContent);
|
|
292
|
+
for (const viewTransformer of this.viewTransformers) {
|
|
293
|
+
await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
294
|
+
}
|
|
295
|
+
const linkedAssetContent = stringBuilder.toString();
|
|
289
296
|
if (linkedAssetContent.includes(lwrResourcesId)) {
|
|
290
297
|
const {renderedView: linkedView, viewRecord} = await (0, import_link_lwr_resources.linkLwrResources)(linkedAssetContent, view, viewParams, {
|
|
291
298
|
lwrResourcesId,
|
|
@@ -300,7 +307,7 @@ var LwrViewRegistry = class {
|
|
|
300
307
|
renderedView: linkedView,
|
|
301
308
|
immutable,
|
|
302
309
|
viewRecord: {
|
|
303
|
-
assetReferences: (0, import_utils.reduceSourceAssetReferences)(
|
|
310
|
+
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences),
|
|
304
311
|
...viewRecord
|
|
305
312
|
}
|
|
306
313
|
};
|
|
@@ -309,7 +316,7 @@ var LwrViewRegistry = class {
|
|
|
309
316
|
renderedView: linkedAssetContent,
|
|
310
317
|
immutable,
|
|
311
318
|
viewRecord: {
|
|
312
|
-
assetReferences: (0, import_utils.reduceSourceAssetReferences)(
|
|
319
|
+
assetReferences: (0, import_utils.reduceSourceAssetReferences)(linkedMetadata.assetReferences)
|
|
313
320
|
}
|
|
314
321
|
};
|
|
315
322
|
}
|
|
@@ -98,7 +98,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
const customElementsRecords = [];
|
|
101
|
-
|
|
101
|
+
const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements);
|
|
102
|
+
await Promise.all(flattenedElements.map(async ({tagName: element}) => {
|
|
102
103
|
const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabcaseToCamelcase)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
103
104
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
104
105
|
const specifier = graph.graphs[0].specifier;
|
|
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/view-registry/src/linkers/utils.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
flattenCustomElements: () => flattenCustomElements,
|
|
27
28
|
getViewBootstrapConfigurationResource: () => getViewBootstrapConfigurationResource,
|
|
28
29
|
getViewHmrConfigurationResource: () => getViewHmrConfigurationResource
|
|
29
30
|
});
|
|
@@ -97,3 +98,23 @@ function getViewHmrConfigurationResource(view, viewMetadata) {
|
|
|
97
98
|
content: configString
|
|
98
99
|
};
|
|
99
100
|
}
|
|
101
|
+
function flattenCustomElements(arr) {
|
|
102
|
+
const ret = [];
|
|
103
|
+
const visitedTags = new Set();
|
|
104
|
+
function flatten(arr2) {
|
|
105
|
+
for (const val of arr2) {
|
|
106
|
+
const {tagName, children} = val;
|
|
107
|
+
if (!visitedTags.has(tagName)) {
|
|
108
|
+
ret.push({
|
|
109
|
+
tagName
|
|
110
|
+
});
|
|
111
|
+
visitedTags.add(tagName);
|
|
112
|
+
}
|
|
113
|
+
if (children) {
|
|
114
|
+
flatten(children);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
flatten(arr);
|
|
119
|
+
return ret;
|
|
120
|
+
}
|
|
@@ -99,7 +99,8 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
99
99
|
}
|
|
100
100
|
let importMetadata = await (0, import_shared_utils.toImportMetadata)(bootstrapModuleGraph, {imports: {}, index: {}}, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
101
101
|
const customElementsRecords = [];
|
|
102
|
-
|
|
102
|
+
const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements);
|
|
103
|
+
await Promise.all(flattenedElements.map(async ({tagName: element}) => {
|
|
103
104
|
const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabcaseToCamelcase)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
104
105
|
customElementsRecords.push({elementName: element, flatGraph: graph});
|
|
105
106
|
const specifier = graph.graphs[0].specifier;
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -39,9 +39,9 @@ __export(exports, {
|
|
|
39
39
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
40
40
|
var import_path = __toModule(require("path"));
|
|
41
41
|
var import_path2 = __toModule(require("path"));
|
|
42
|
-
var import_mime_types = __toModule(require("mime-types"));
|
|
43
|
-
var import_identity = __toModule(require("@lwrjs/app-service/identity"));
|
|
44
42
|
var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
|
|
43
|
+
var import_identity = __toModule(require("@lwrjs/app-service/identity"));
|
|
44
|
+
var import_shared_utils3 = __toModule(require("@lwrjs/shared-utils"));
|
|
45
45
|
function streamToString(stream) {
|
|
46
46
|
const chunks = [];
|
|
47
47
|
return new Promise((resolve, reject) => {
|
|
@@ -103,7 +103,7 @@ function normalizeRenderedResult({
|
|
|
103
103
|
assetReferences: metadata ? metadata.assetReferences : []
|
|
104
104
|
},
|
|
105
105
|
options: {
|
|
106
|
-
skipMetadataCollection: options ? options.skipMetadataCollection :
|
|
106
|
+
skipMetadataCollection: options ? options.skipMetadataCollection : false
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
}
|
|
@@ -118,7 +118,7 @@ function reduceSourceAssetReferences(assets) {
|
|
|
118
118
|
}
|
|
119
119
|
function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions, baseRenderOptions) {
|
|
120
120
|
return {
|
|
121
|
-
skipMetadataCollection:
|
|
121
|
+
skipMetadataCollection: false,
|
|
122
122
|
freezeAssets: runtimeEnvironment.immutableAssets,
|
|
123
123
|
skipCaching: false,
|
|
124
124
|
viewParamCacheKey: null,
|
|
@@ -181,7 +181,7 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
|
|
|
181
181
|
});
|
|
182
182
|
resources.push({
|
|
183
183
|
type: "application/javascript",
|
|
184
|
-
src: (0,
|
|
184
|
+
src: (0, import_shared_utils3.getClientBootstrapConfigurationUri)({url: viewRequest.url, id: route.id}, runtimeEnvironment, runtimeParams)
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
const mappingUrl = (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, runtimeParams);
|
|
@@ -201,7 +201,7 @@ async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEnvironme
|
|
|
201
201
|
});
|
|
202
202
|
viewRecord.assetReferences?.forEach((asset) => {
|
|
203
203
|
if (asset.override?.uri) {
|
|
204
|
-
const type = (0,
|
|
204
|
+
const type = (0, import_shared_utils2.mimeLookup)(asset.override?.uri);
|
|
205
205
|
resources.push({type, src: asset.override?.uri});
|
|
206
206
|
}
|
|
207
207
|
});
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { AssetRegistry, CompiledView, Json, LinkedModuleDefinition, LinkedViewDefinition, LwrAppEmitter, LwrAppObserver, ModuleBundler, ModuleRegistry, NormalizedLwrGlobalConfig, PublicViewRegistry, RenderOptions, ResourceRegistry, RuntimeEnvironment, RuntimeParams, View, ViewIdentity, ViewParams, ViewProvider, ViewRegistry } from '@lwrjs/types';
|
|
1
|
+
import { AssetRegistry, CompiledView, Json, LinkedModuleDefinition, LinkedViewDefinition, LwrAppEmitter, LwrAppObserver, ModuleBundler, ModuleRegistry, NormalizedLwrGlobalConfig, PublicViewRegistry, RenderOptions, ResourceRegistry, RuntimeEnvironment, RuntimeParams, View, ViewIdentity, ViewParams, ViewProvider, ViewRegistry, ViewTransformPlugin } from '@lwrjs/types';
|
|
2
2
|
import { AssetSource } from '@lwrjs/types';
|
|
3
3
|
export { LwrViewHandler } from './view-handler.js';
|
|
4
4
|
interface ViewProviderContext {
|
|
5
|
+
viewTransformers?: ViewTransformPlugin[];
|
|
5
6
|
appObserver: LwrAppObserver;
|
|
6
7
|
appEmitter: LwrAppEmitter;
|
|
7
8
|
assetRegistry: AssetRegistry;
|
|
@@ -30,6 +31,7 @@ export declare class LwrViewRegistry implements ViewRegistry {
|
|
|
30
31
|
globalData: Json;
|
|
31
32
|
runtimeEnvironment: RuntimeEnvironment;
|
|
32
33
|
immutableAssets: Map<string, string>;
|
|
34
|
+
viewTransformers: ViewTransformPlugin[];
|
|
33
35
|
private pendingViewDefinitions;
|
|
34
36
|
constructor(context: ViewProviderContext, globalConfig: NormalizedLwrGlobalConfig);
|
|
35
37
|
onModuleDefinitionChange(moduleDefinition: LinkedModuleDefinition): Promise<void>;
|
|
@@ -37,6 +39,7 @@ export declare class LwrViewRegistry implements ViewRegistry {
|
|
|
37
39
|
onAssetSourceChange(asset: AssetSource): void;
|
|
38
40
|
getPublicApi(): PublicViewRegistry;
|
|
39
41
|
addViewProviders(providers: ViewProvider[]): void;
|
|
42
|
+
addViewTransformers(transformers: ViewTransformPlugin[]): void;
|
|
40
43
|
initializeViewProviders(): Promise<void[]>;
|
|
41
44
|
delegateGetView(viewId: ViewIdentity): Promise<CompiledView>;
|
|
42
45
|
getView(viewId: ViewIdentity, skipCaching?: boolean): Promise<CompiledView>;
|
package/build/es/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { extractMetadataFromHtml, getCacheKeyFromJson, getSpecifier, normalizeResourcePath, } from '@lwrjs/shared-utils';
|
|
1
|
+
import { extractMetadataFromHtml, getCacheKeyFromJson, getSpecifier, normalizeResourcePath, createStringBuilder, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { normalizeRenderOptions, normalizeRenderedResult, reduceSourceAssetReferences } from './utils.js';
|
|
3
|
-
import { linkAssets } from './linkers/link-assets.js';
|
|
4
3
|
import { linkLwrResources } from './linkers/link-lwr-resources.js';
|
|
5
4
|
export { LwrViewHandler } from './view-handler.js';
|
|
6
5
|
export class LwrViewRegistry {
|
|
@@ -26,6 +25,7 @@ export class LwrViewRegistry {
|
|
|
26
25
|
this.moduleRegistry = context.moduleRegistry;
|
|
27
26
|
this.moduleBundler = context.moduleBundler;
|
|
28
27
|
this.assetRegistry = context.assetRegistry;
|
|
28
|
+
this.viewTransformers = context.viewTransformers || [];
|
|
29
29
|
this.globalConfig = globalConfig;
|
|
30
30
|
this.globalData = context.globalData;
|
|
31
31
|
this.appEmitter = context.appEmitter;
|
|
@@ -96,6 +96,9 @@ export class LwrViewRegistry {
|
|
|
96
96
|
addViewProviders(providers) {
|
|
97
97
|
this.viewProviders.push(...providers);
|
|
98
98
|
}
|
|
99
|
+
addViewTransformers(transformers) {
|
|
100
|
+
this.viewTransformers.push(...transformers);
|
|
101
|
+
}
|
|
99
102
|
initializeViewProviders() {
|
|
100
103
|
return Promise.all(this.viewProviders.map((vp) => vp.initialize()));
|
|
101
104
|
}
|
|
@@ -291,21 +294,25 @@ export class LwrViewRegistry {
|
|
|
291
294
|
const { view, viewParams, runtimeEnvironment: runtimeEnv, runtimeParams, renderOptions, contentIds, importer, } = viewContext;
|
|
292
295
|
const { skipMetadataCollection, freezeAssets } = renderOptions;
|
|
293
296
|
const { lwrResourcesId } = contentIds;
|
|
294
|
-
const { moduleRegistry,
|
|
297
|
+
const { moduleRegistry, resourceRegistry, moduleBundler } = this;
|
|
295
298
|
const runtimeEnvironment = { ...runtimeEnv, immutableAssets: freezeAssets };
|
|
296
299
|
// normalize/extract metadata
|
|
297
300
|
const { renderedView: renderedViewContent, metadata: renderedViewMetadata, compiledView: { immutable = true }, } = renderedView;
|
|
298
301
|
const linkedMetadata = skipMetadataCollection
|
|
299
|
-
?
|
|
300
|
-
:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
assetRegistry,
|
|
302
|
+
? renderedViewMetadata
|
|
303
|
+
: await extractMetadataFromHtml(renderedViewContent);
|
|
304
|
+
const mergedViewContext = {
|
|
305
|
+
...viewContext,
|
|
304
306
|
runtimeEnvironment,
|
|
305
307
|
importer: importer || renderedView.compiledView.filePath,
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
};
|
|
309
|
+
const stringBuilder = createStringBuilder(renderedViewContent);
|
|
310
|
+
for (const viewTransformer of this.viewTransformers) {
|
|
311
|
+
// eslint-disable-next-line no-await-in-loop
|
|
312
|
+
await viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata);
|
|
313
|
+
}
|
|
314
|
+
const linkedAssetContent = stringBuilder.toString();
|
|
315
|
+
// Link LWR related resources
|
|
309
316
|
if (linkedAssetContent.includes(lwrResourcesId)) {
|
|
310
317
|
// This calculation is expensive, only do it if lwr_resources is needed
|
|
311
318
|
// Link LWR View resources if necessary
|
|
@@ -323,7 +330,7 @@ export class LwrViewRegistry {
|
|
|
323
330
|
renderedView: linkedView,
|
|
324
331
|
immutable,
|
|
325
332
|
viewRecord: {
|
|
326
|
-
assetReferences: reduceSourceAssetReferences(
|
|
333
|
+
assetReferences: reduceSourceAssetReferences(linkedMetadata.assetReferences),
|
|
327
334
|
...viewRecord,
|
|
328
335
|
},
|
|
329
336
|
};
|
|
@@ -332,7 +339,7 @@ export class LwrViewRegistry {
|
|
|
332
339
|
renderedView: linkedAssetContent,
|
|
333
340
|
immutable,
|
|
334
341
|
viewRecord: {
|
|
335
|
-
assetReferences: reduceSourceAssetReferences(
|
|
342
|
+
assetReferences: reduceSourceAssetReferences(linkedMetadata.assetReferences),
|
|
336
343
|
},
|
|
337
344
|
};
|
|
338
345
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { kebabcaseToCamelcase, getModuleGraphs, GraphDepth, getModuleUriPrefix } from '@lwrjs/shared-utils';
|
|
2
2
|
import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
|
|
3
3
|
import { generateHtmlTag, getModuleResource, getModuleResourceByUri } from '../utils.js';
|
|
4
|
-
import { getViewBootstrapConfigurationResource, getViewHmrConfigurationResource } from './utils.js';
|
|
4
|
+
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
|
|
5
5
|
export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
6
6
|
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata, } = resourceContext;
|
|
7
7
|
const { id: appName, bootstrap: { services } = { services: [] } } = view;
|
|
@@ -102,7 +102,8 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
102
102
|
}
|
|
103
103
|
// ------- View related custom element moduleResources
|
|
104
104
|
const customElementsRecords = [];
|
|
105
|
-
|
|
105
|
+
const flattenedElements = flattenCustomElements(customElements);
|
|
106
|
+
await Promise.all(flattenedElements.map(async ({ tagName: element }) => {
|
|
106
107
|
const graph = await getModuleGraphs(kebabcaseToCamelcase(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
107
108
|
// add to the viewRecord
|
|
108
109
|
customElementsRecords.push({ elementName: element, flatGraph: graph });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata } from '@lwrjs/types';
|
|
1
|
+
import { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata, CustomElementReference } 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
|
+
export declare function flattenCustomElements(arr: CustomElementReference[]): CustomElementReference[];
|
|
5
6
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -76,4 +76,24 @@ export function getViewHmrConfigurationResource(view, viewMetadata) {
|
|
|
76
76
|
content: configString,
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
+
export function flattenCustomElements(arr) {
|
|
80
|
+
const ret = [];
|
|
81
|
+
const visitedTags = new Set();
|
|
82
|
+
function flatten(arr) {
|
|
83
|
+
for (const val of arr) {
|
|
84
|
+
const { tagName, children } = val;
|
|
85
|
+
if (!visitedTags.has(tagName)) {
|
|
86
|
+
ret.push({
|
|
87
|
+
tagName,
|
|
88
|
+
});
|
|
89
|
+
visitedTags.add(tagName);
|
|
90
|
+
}
|
|
91
|
+
if (children) {
|
|
92
|
+
flatten(children);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
flatten(arr);
|
|
97
|
+
return ret;
|
|
98
|
+
}
|
|
79
99
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { kebabcaseToCamelcase, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, } from '@lwrjs/shared-utils';
|
|
2
2
|
import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
|
|
3
3
|
import { generateHtmlTag, getModuleResource, getModuleResourceByUri } from '../utils.js';
|
|
4
|
-
import { getViewBootstrapConfigurationResource, getViewHmrConfigurationResource } from './utils.js';
|
|
4
|
+
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
|
|
5
5
|
export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
6
6
|
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata, } = resourceContext;
|
|
7
7
|
const { id: appName, bootstrap: { services } = { services: [] } } = view;
|
|
@@ -103,7 +103,8 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
103
103
|
let importMetadata = await toImportMetadata(bootstrapModuleGraph, { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
104
104
|
// ------- View related custom element moduleResources
|
|
105
105
|
const customElementsRecords = [];
|
|
106
|
-
|
|
106
|
+
const flattenedElements = flattenCustomElements(customElements);
|
|
107
|
+
await Promise.all(flattenedElements.map(async ({ tagName: element }) => {
|
|
107
108
|
const graph = await getModuleGraphs(kebabcaseToCamelcase(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
|
|
108
109
|
// add to the viewRecord
|
|
109
110
|
customElementsRecords.push({ elementName: element, flatGraph: graph });
|
package/build/es/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { explodeSpecifier, getMappingUriPrefix, getSpecifier, resolveFileExtension, transpileTs, DEFAULT_TITLE, } from '@lwrjs/shared-utils';
|
|
2
2
|
import libPath from 'path';
|
|
3
3
|
import { basename, extname } from 'path';
|
|
4
|
-
import {
|
|
4
|
+
import { mimeLookup } from '@lwrjs/shared-utils';
|
|
5
5
|
import { AppResourceEnum, getAppSpecifier, ResourceIdentityTypes, } from '@lwrjs/app-service/identity';
|
|
6
6
|
import { getClientBootstrapConfigurationUri } from '@lwrjs/shared-utils';
|
|
7
7
|
function streamToString(stream) {
|
|
@@ -65,7 +65,7 @@ export function normalizeRenderedResult({ renderedView, metadata, options, }) {
|
|
|
65
65
|
assetReferences: metadata ? metadata.assetReferences : [],
|
|
66
66
|
},
|
|
67
67
|
options: {
|
|
68
|
-
skipMetadataCollection: options ? options.skipMetadataCollection :
|
|
68
|
+
skipMetadataCollection: options ? options.skipMetadataCollection : false,
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
}
|
|
@@ -81,7 +81,7 @@ export function reduceSourceAssetReferences(assets) {
|
|
|
81
81
|
export function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions, baseRenderOptions) {
|
|
82
82
|
return {
|
|
83
83
|
// Default render options
|
|
84
|
-
skipMetadataCollection:
|
|
84
|
+
skipMetadataCollection: false,
|
|
85
85
|
freezeAssets: runtimeEnvironment.immutableAssets,
|
|
86
86
|
skipCaching: false,
|
|
87
87
|
viewParamCacheKey: null,
|
|
@@ -183,7 +183,7 @@ export async function toJsonFormat(viewRequest, viewDefinition, route, runtimeEn
|
|
|
183
183
|
// ADD assetReferences to the JSON resources
|
|
184
184
|
viewRecord.assetReferences?.forEach((asset) => {
|
|
185
185
|
if (asset.override?.uri) {
|
|
186
|
-
const type =
|
|
186
|
+
const type = mimeLookup(asset.override?.uri);
|
|
187
187
|
resources.push({ type, src: asset.override?.uri });
|
|
188
188
|
}
|
|
189
189
|
});
|
package/build/es/view-handler.js
CHANGED
|
@@ -3,6 +3,7 @@ import { generateHtmlTag, generatePageContext, getRouteHandler, isViewResponse,
|
|
|
3
3
|
import { resolve } from 'path';
|
|
4
4
|
export class LwrViewHandler {
|
|
5
5
|
constructor(context, globalConfig) {
|
|
6
|
+
// TODO convert to using InflightTasks in the shared utils
|
|
6
7
|
this.inflightRouteHandlerEvalMap = new Map();
|
|
7
8
|
this.routeHandlerFunctionMap = new Map();
|
|
8
9
|
this.viewRegistry = context.viewRegistry;
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.0-alpha.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.10",
|
|
8
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/salesforce/lwr.git",
|
|
@@ -30,16 +30,15 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/app-service": "0.6.0-alpha.
|
|
34
|
-
"@lwrjs/diagnostics": "0.6.0-alpha.
|
|
35
|
-
"@lwrjs/shared-utils": "0.6.0-alpha.
|
|
36
|
-
"magic-string": "^0.25.7"
|
|
33
|
+
"@lwrjs/app-service": "0.6.0-alpha.10",
|
|
34
|
+
"@lwrjs/diagnostics": "0.6.0-alpha.10",
|
|
35
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.10"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.6.0-alpha.
|
|
38
|
+
"@lwrjs/types": "0.6.0-alpha.10"
|
|
40
39
|
},
|
|
41
40
|
"engines": {
|
|
42
41
|
"node": ">=14.15.4 <17"
|
|
43
42
|
},
|
|
44
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "85914e17d6214748489426252dd8fa41c8938b8f"
|
|
45
44
|
}
|
|
@@ -1,60 +0,0 @@
|
|
|
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/link-assets.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
linkAssets: () => linkAssets
|
|
28
|
-
});
|
|
29
|
-
var import_magic_string = __toModule(require("magic-string"));
|
|
30
|
-
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
|
-
function rewriteDocumentWithImmutableUrls(renderedView, assetReferences) {
|
|
32
|
-
const codeStringBuilder = new import_magic_string.default(renderedView);
|
|
33
|
-
assetReferences.forEach((assetRef) => {
|
|
34
|
-
const {
|
|
35
|
-
override,
|
|
36
|
-
url,
|
|
37
|
-
location: {startOffset, endOffset}
|
|
38
|
-
} = assetRef;
|
|
39
|
-
startOffset !== endOffset && codeStringBuilder.overwrite(startOffset, endOffset, override?.uri || url);
|
|
40
|
-
});
|
|
41
|
-
return codeStringBuilder.toString();
|
|
42
|
-
}
|
|
43
|
-
async function linkAssets(source, assetReferences, {assetRegistry, runtimeEnvironment, importer}) {
|
|
44
|
-
const imageRefs = await Promise.all(assetReferences.map(async (ref) => {
|
|
45
|
-
const {url: specifier} = ref;
|
|
46
|
-
let override;
|
|
47
|
-
try {
|
|
48
|
-
override = await assetRegistry.resolveAssetUri({specifier, importer}, runtimeEnvironment);
|
|
49
|
-
} catch (e) {
|
|
50
|
-
if (e instanceof import_diagnostics.LwrUnresolvableError) {
|
|
51
|
-
console.warn("[WARN]: Asset was not found for " + ref.url);
|
|
52
|
-
return ref;
|
|
53
|
-
}
|
|
54
|
-
throw e;
|
|
55
|
-
}
|
|
56
|
-
return {...ref, override};
|
|
57
|
-
}));
|
|
58
|
-
const modifiedSource = rewriteDocumentWithImmutableUrls(source, imageRefs);
|
|
59
|
-
return {source: modifiedSource, assetReferences: imageRefs};
|
|
60
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AssetReference, PublicAssetRegistry, RuntimeEnvironment } from '@lwrjs/types';
|
|
2
|
-
interface LinkedAssetsContext {
|
|
3
|
-
assetRegistry: PublicAssetRegistry;
|
|
4
|
-
runtimeEnvironment: RuntimeEnvironment;
|
|
5
|
-
importer: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function linkAssets(source: string, assetReferences: AssetReference[], { assetRegistry, runtimeEnvironment, importer }: LinkedAssetsContext): Promise<{
|
|
8
|
-
source: string;
|
|
9
|
-
assetReferences: AssetReference[];
|
|
10
|
-
}>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=link-assets.d.ts.map
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import { LwrUnresolvableError } from '@lwrjs/diagnostics';
|
|
3
|
-
function rewriteDocumentWithImmutableUrls(renderedView, assetReferences) {
|
|
4
|
-
const codeStringBuilder = new MagicString(renderedView);
|
|
5
|
-
assetReferences.forEach((assetRef) => {
|
|
6
|
-
const { override, url, location: { startOffset, endOffset }, } = assetRef;
|
|
7
|
-
startOffset !== endOffset &&
|
|
8
|
-
codeStringBuilder.overwrite(startOffset, endOffset, override?.uri || url);
|
|
9
|
-
});
|
|
10
|
-
return codeStringBuilder.toString();
|
|
11
|
-
}
|
|
12
|
-
export async function linkAssets(source, assetReferences, { assetRegistry, runtimeEnvironment, importer }) {
|
|
13
|
-
const imageRefs = await Promise.all(assetReferences.map(async (ref) => {
|
|
14
|
-
const { url: specifier } = ref;
|
|
15
|
-
let override;
|
|
16
|
-
try {
|
|
17
|
-
override = await assetRegistry.resolveAssetUri({ specifier, importer }, runtimeEnvironment);
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
if (e instanceof LwrUnresolvableError) {
|
|
21
|
-
// the asset may not exist, in which case the URL is not overwritten. Log a warning so
|
|
22
|
-
// the developer can see the bad asset URL, and be able to correct it
|
|
23
|
-
console.warn('[WARN]: Asset was not found for ' + ref.url);
|
|
24
|
-
return ref;
|
|
25
|
-
}
|
|
26
|
-
throw e;
|
|
27
|
-
}
|
|
28
|
-
return { ...ref, override };
|
|
29
|
-
}));
|
|
30
|
-
const modifiedSource = rewriteDocumentWithImmutableUrls(source, imageRefs);
|
|
31
|
-
return { source: modifiedSource, assetReferences: imageRefs };
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=link-assets.js.map
|