@lwrjs/shared-utils 0.11.0-alpha.13 → 0.11.0-alpha.15
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/html-meta.cjs
CHANGED
|
@@ -65,7 +65,7 @@ function hasHydrationDirective(attrs = {}) {
|
|
|
65
65
|
return Object.keys(attrs).some((attr) => attr === HYDRATE_DIRECTIVE);
|
|
66
66
|
}
|
|
67
67
|
async function extractMetadataFromHtml(htmlSource, viewMetadata, appConfig) {
|
|
68
|
-
const {customElements, assetReferences
|
|
68
|
+
const {customElements, assetReferences} = viewMetadata;
|
|
69
69
|
const {
|
|
70
70
|
bundleConfig: {external = {}}
|
|
71
71
|
} = appConfig;
|
|
@@ -126,9 +126,9 @@ async function extractMetadataFromHtml(htmlSource, viewMetadata, appConfig) {
|
|
|
126
126
|
});
|
|
127
127
|
const inputStream = import_stream.Readable.from(htmlSource);
|
|
128
128
|
inputStream.on("end", () => resolve({
|
|
129
|
+
...viewMetadata,
|
|
129
130
|
customElements: customElements.filter((ce) => !nestedIslands || hasHydrationDirective(ce.props)),
|
|
130
|
-
assetReferences
|
|
131
|
-
serverData
|
|
131
|
+
assetReferences
|
|
132
132
|
}));
|
|
133
133
|
inputStream.on("error", (error) => reject(error));
|
|
134
134
|
inputStream.pipe(parser);
|
|
@@ -9,6 +9,7 @@ var __export = (target, all) => {
|
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
11
|
getFallbackLocale: () => getFallbackLocale,
|
|
12
|
+
sortLocalesByFallback: () => sortLocalesByFallback,
|
|
12
13
|
walkLocaleFallbacks: () => walkLocaleFallbacks
|
|
13
14
|
});
|
|
14
15
|
function getFallbackLocale(localeId, i18n) {
|
|
@@ -32,3 +33,21 @@ async function walkLocaleFallbacks(initialLocale, i18n, test) {
|
|
|
32
33
|
}
|
|
33
34
|
return void 0;
|
|
34
35
|
}
|
|
36
|
+
function sortLocalesByFallback(i18n) {
|
|
37
|
+
const sortedLocales = [...i18n.locales];
|
|
38
|
+
return sortedLocales.sort((a, b) => {
|
|
39
|
+
if (a.id === i18n.defaultLocale)
|
|
40
|
+
return -1;
|
|
41
|
+
if (b.id === i18n.defaultLocale)
|
|
42
|
+
return 1;
|
|
43
|
+
if (a.fallback && !b.fallback)
|
|
44
|
+
return 1;
|
|
45
|
+
if (b.fallback && !a.fallback)
|
|
46
|
+
return -1;
|
|
47
|
+
if (a.fallback && b.id === a.fallback)
|
|
48
|
+
return 1;
|
|
49
|
+
if (b.fallback && a.id === b.fallback)
|
|
50
|
+
return -1;
|
|
51
|
+
return 0;
|
|
52
|
+
});
|
|
53
|
+
}
|
package/build/es/html-meta.js
CHANGED
|
@@ -37,7 +37,7 @@ function hasHydrationDirective(attrs = {}) {
|
|
|
37
37
|
* @param htmlSource - An HTML string to parse
|
|
38
38
|
*/
|
|
39
39
|
export async function extractMetadataFromHtml(htmlSource, viewMetadata, appConfig) {
|
|
40
|
-
const { customElements, assetReferences
|
|
40
|
+
const { customElements, assetReferences } = viewMetadata;
|
|
41
41
|
const { bundleConfig: { external = {} }, } = appConfig;
|
|
42
42
|
const externals = Object.keys(external);
|
|
43
43
|
return new Promise((resolve, reject) => {
|
|
@@ -111,9 +111,9 @@ export async function extractMetadataFromHtml(htmlSource, viewMetadata, appConfi
|
|
|
111
111
|
// If nested islands are found, ONLY collect custom elements with the hydration directive
|
|
112
112
|
// Otherwise, just collect top-level custom elements (ie: root components) as usual
|
|
113
113
|
inputStream.on('end', () => resolve({
|
|
114
|
+
...viewMetadata,
|
|
114
115
|
customElements: customElements.filter((ce) => !nestedIslands || hasHydrationDirective(ce.props)),
|
|
115
116
|
assetReferences,
|
|
116
|
-
serverData,
|
|
117
117
|
}));
|
|
118
118
|
inputStream.on('error', (error) => reject(error));
|
|
119
119
|
inputStream.pipe(parser);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { I18NConfig } from '@lwrjs/types';
|
|
1
|
+
import type { I18NConfig, Locale } from '@lwrjs/types';
|
|
2
2
|
export declare function getFallbackLocale(localeId: string, i18n: I18NConfig): string | undefined;
|
|
3
3
|
export declare function walkLocaleFallbacks<R>(initialLocale: string, i18n: I18NConfig, test: (locale: string) => Promise<R | undefined>): Promise<R | undefined>;
|
|
4
|
+
export declare function sortLocalesByFallback(i18n: I18NConfig): Locale[];
|
|
4
5
|
//# sourceMappingURL=localization.d.ts.map
|
package/build/es/localization.js
CHANGED
|
@@ -25,4 +25,23 @@ export async function walkLocaleFallbacks(initialLocale, i18n, test) {
|
|
|
25
25
|
// Did not find what we were looking for
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
|
+
// Sort locales with fallbacks based on fallback relationships
|
|
29
|
+
export function sortLocalesByFallback(i18n) {
|
|
30
|
+
const sortedLocales = [...i18n.locales];
|
|
31
|
+
return sortedLocales.sort((a, b) => {
|
|
32
|
+
if (a.id === i18n.defaultLocale)
|
|
33
|
+
return -1; // Move the default locales to the front.
|
|
34
|
+
if (b.id === i18n.defaultLocale)
|
|
35
|
+
return 1;
|
|
36
|
+
if (a.fallback && !b.fallback)
|
|
37
|
+
return 1; // Move locales with no fallback before the ones that do
|
|
38
|
+
if (b.fallback && !a.fallback)
|
|
39
|
+
return -1;
|
|
40
|
+
if (a.fallback && b.id === a.fallback)
|
|
41
|
+
return 1; // Move 'a' before 'b' if 'a' is a fallback for 'b'.
|
|
42
|
+
if (b.fallback && a.id === b.fallback)
|
|
43
|
+
return -1; // Move 'b' before 'a' if 'b' is a fallback for 'a'.
|
|
44
|
+
return 0;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
28
47
|
//# sourceMappingURL=localization.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.0-alpha.
|
|
7
|
+
"version": "0.11.0-alpha.15",
|
|
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.
|
|
40
|
+
"@lwrjs/diagnostics": "0.11.0-alpha.15",
|
|
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.
|
|
53
|
+
"@lwrjs/types": "0.11.0-alpha.15",
|
|
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": "
|
|
60
|
+
"gitHead": "3c6c6d17b2f57a5b67d32e40a1e574abb7d9afea"
|
|
61
61
|
}
|