@lwrjs/shared-utils 0.11.0-alpha.12 → 0.11.0-alpha.14

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.
@@ -64,8 +64,12 @@ var isSelfUrlRegex = /^\s*(data:|#)/i;
64
64
  function hasHydrationDirective(attrs = {}) {
65
65
  return Object.keys(attrs).some((attr) => attr === HYDRATE_DIRECTIVE);
66
66
  }
67
- async function extractMetadataFromHtml(htmlSource, viewMetadata) {
68
- const {customElements, assetReferences, serverData} = viewMetadata;
67
+ async function extractMetadataFromHtml(htmlSource, viewMetadata, appConfig) {
68
+ const {customElements, assetReferences} = viewMetadata;
69
+ const {
70
+ bundleConfig: {external = {}}
71
+ } = appConfig;
72
+ const externals = Object.keys(external);
69
73
  return new Promise((resolve, reject) => {
70
74
  const openElements = new Set();
71
75
  const parser = new import_parse5_sax_parser.default({sourceCodeLocationInfo: true});
@@ -76,7 +80,7 @@ async function extractMetadataFromHtml(htmlSource, viewMetadata) {
76
80
  attrs,
77
81
  sourceCodeLocation
78
82
  }) => {
79
- if (tagName.includes("-") && !openElements.has(tagName)) {
83
+ if (tagName.includes("-") && !openElements.has(tagName) && !externals.includes((0, import_identity.kebabCaseToModuleSpecifier)(tagName))) {
80
84
  const {startOffset, endOffset} = sourceCodeLocation;
81
85
  const props = attrs.length ? attrs.reduce((obj, {name, value}) => {
82
86
  obj[(0, import_identity.getPropFromAttrName)(name)] = value === "" ? "true" : value;
@@ -122,9 +126,9 @@ async function extractMetadataFromHtml(htmlSource, viewMetadata) {
122
126
  });
123
127
  const inputStream = import_stream.Readable.from(htmlSource);
124
128
  inputStream.on("end", () => resolve({
129
+ ...viewMetadata,
125
130
  customElements: customElements.filter((ce) => !nestedIslands || hasHydrationDirective(ce.props)),
126
- assetReferences,
127
- serverData
131
+ assetReferences
128
132
  }));
129
133
  inputStream.on("error", (error) => reject(error));
130
134
  inputStream.pipe(parser);
@@ -1,11 +1,11 @@
1
- import type { RenderedViewMetadata } from '@lwrjs/types';
1
+ import type { NormalizedLwrGlobalConfig, RenderedViewMetadata } from '@lwrjs/types';
2
2
  export declare function isRelative(url: string): boolean;
3
3
  export declare function isSelfUrl(url: string): boolean;
4
4
  /**
5
5
  * Pull the custom elements and img tags out of an HTML string, to use as metadata
6
6
  * @param htmlSource - An HTML string to parse
7
7
  */
8
- export declare function extractMetadataFromHtml(htmlSource: string, viewMetadata: RenderedViewMetadata): Promise<RenderedViewMetadata>;
8
+ export declare function extractMetadataFromHtml(htmlSource: string, viewMetadata: RenderedViewMetadata, appConfig: NormalizedLwrGlobalConfig): Promise<RenderedViewMetadata>;
9
9
  export declare const HYDRATE_DIRECTIVE = "lwr:hydrate";
10
10
  export declare const HYDRATE_LOAD_VALUE = "load";
11
11
  export declare const HYDRATE_CLIENT_VALUE = "client-only";
@@ -1,4 +1,4 @@
1
- import { getPropFromAttrName } from './identity.js';
1
+ import { getPropFromAttrName, kebabCaseToModuleSpecifier } from './identity.js';
2
2
  import SAXParser from 'parse5-sax-parser';
3
3
  import { Readable } from 'stream';
4
4
  function parseAssetLocation(htmlSource, tagName, attrLocation) {
@@ -36,8 +36,10 @@ function hasHydrationDirective(attrs = {}) {
36
36
  * Pull the custom elements and img tags out of an HTML string, to use as metadata
37
37
  * @param htmlSource - An HTML string to parse
38
38
  */
39
- export async function extractMetadataFromHtml(htmlSource, viewMetadata) {
40
- const { customElements, assetReferences, serverData } = viewMetadata;
39
+ export async function extractMetadataFromHtml(htmlSource, viewMetadata, appConfig) {
40
+ const { customElements, assetReferences } = viewMetadata;
41
+ const { bundleConfig: { external = {} }, } = appConfig;
42
+ const externals = Object.keys(external);
41
43
  return new Promise((resolve, reject) => {
42
44
  const openElements = new Set();
43
45
  const parser = new SAXParser({ sourceCodeLocationInfo: true }); // TODO: Would we need this in the future?
@@ -46,7 +48,9 @@ export async function extractMetadataFromHtml(htmlSource, viewMetadata) {
46
48
  parser.on('startTag', ({ tagName, attrs, // attributes are passed into SSR
47
49
  sourceCodeLocation, }) => {
48
50
  // custom elements
49
- if (tagName.includes('-') && !openElements.has(tagName)) {
51
+ if (tagName.includes('-') &&
52
+ !openElements.has(tagName) &&
53
+ !externals.includes(kebabCaseToModuleSpecifier(tagName))) {
50
54
  const { startOffset, endOffset } = sourceCodeLocation;
51
55
  // transform attributes [{ name: 'some-attr', value: 'the value' }] into properties { someAttr: 'the value' }
52
56
  // leave props as undefined if there are no attributes
@@ -107,9 +111,9 @@ export async function extractMetadataFromHtml(htmlSource, viewMetadata) {
107
111
  // If nested islands are found, ONLY collect custom elements with the hydration directive
108
112
  // Otherwise, just collect top-level custom elements (ie: root components) as usual
109
113
  inputStream.on('end', () => resolve({
114
+ ...viewMetadata,
110
115
  customElements: customElements.filter((ce) => !nestedIslands || hasHydrationDirective(ce.props)),
111
116
  assetReferences,
112
- serverData,
113
117
  }));
114
118
  inputStream.on('error', (error) => reject(error));
115
119
  inputStream.pipe(parser);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.11.0-alpha.12",
7
+ "version": "0.11.0-alpha.14",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "build/**/*.d.ts"
38
38
  ],
39
39
  "dependencies": {
40
- "@lwrjs/diagnostics": "0.11.0-alpha.12",
40
+ "@lwrjs/diagnostics": "0.11.0-alpha.14",
41
41
  "es-module-lexer": "^1.3.0",
42
42
  "fast-json-stable-stringify": "^2.1.0",
43
43
  "magic-string": "^0.30.0",
@@ -50,12 +50,12 @@
50
50
  "slugify": "^1.4.5"
51
51
  },
52
52
  "devDependencies": {
53
- "@lwrjs/types": "0.11.0-alpha.12",
53
+ "@lwrjs/types": "0.11.0-alpha.14",
54
54
  "@types/mime-types": "2.1.1",
55
55
  "@types/path-to-regexp": "^1.7.0"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=16.0.0"
59
59
  },
60
- "gitHead": "e19ffe5a48dc2b2b6d74d8acfa9658bedb5dd1ff"
60
+ "gitHead": "d082cc49d9e2b5024d17a3da2c5c2bf585f811fe"
61
61
  }