@lwrjs/shared-utils 0.11.0-alpha.0 → 0.11.0-alpha.1
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/graph.cjs +3 -3
- package/build/cjs/identity.cjs +3 -2
- package/build/cjs/index.cjs +1 -0
- package/build/cjs/localization.cjs +54 -0
- package/build/cjs/mappings.cjs +3 -3
- package/build/es/graph.d.ts +1 -1
- package/build/es/graph.js +3 -3
- package/build/es/identity.d.ts +1 -1
- package/build/es/identity.js +3 -2
- package/build/es/index.d.ts +1 -0
- package/build/es/index.js +1 -0
- package/build/es/localization.d.ts +4 -0
- package/build/es/localization.js +29 -0
- package/build/es/mappings.js +3 -3
- package/build/es/serialize.d.ts +1 -1
- package/package.json +5 -5
package/build/cjs/graph.cjs
CHANGED
|
@@ -105,7 +105,7 @@ async function flatten(versionedSpecifier, flattened, idx, visited) {
|
|
|
105
105
|
}
|
|
106
106
|
async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited) {
|
|
107
107
|
const acc = visited || new Map();
|
|
108
|
-
const versionedModuleId = await (0, import_identity.getVersionedModuleId)(specifier, moduleRegistry);
|
|
108
|
+
const versionedModuleId = await (0, import_identity.getVersionedModuleId)(specifier, moduleRegistry, runtimeParams);
|
|
109
109
|
const depth = options.depth || {
|
|
110
110
|
static: GraphDepth.DIRECT,
|
|
111
111
|
dynamic: 1
|
|
@@ -121,7 +121,7 @@ async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry,
|
|
|
121
121
|
const uriMap = {};
|
|
122
122
|
if (options.includeUris) {
|
|
123
123
|
for (const visitedSpecifier of acc.keys()) {
|
|
124
|
-
const moduleId = await (0, import_identity.getVersionedModuleId)(visitedSpecifier, moduleRegistry);
|
|
124
|
+
const moduleId = await (0, import_identity.getVersionedModuleId)(visitedSpecifier, moduleRegistry, runtimeParams);
|
|
125
125
|
const uri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
|
|
126
126
|
uriMap[visitedSpecifier] = uri;
|
|
127
127
|
}
|
|
@@ -129,7 +129,7 @@ async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry,
|
|
|
129
129
|
const linkedDefinitions = {};
|
|
130
130
|
if (options.includeLinkedDefinitions) {
|
|
131
131
|
for (const visitedSpecifier of acc.keys()) {
|
|
132
|
-
const versionedModuleId2 = await (0, import_identity.getVersionedModuleId)(visitedSpecifier, moduleRegistry);
|
|
132
|
+
const versionedModuleId2 = await (0, import_identity.getVersionedModuleId)(visitedSpecifier, moduleRegistry, runtimeParams);
|
|
133
133
|
const module2 = isBundler(defRegistry) ? await defRegistry.getModuleBundle(versionedModuleId2, runtimeEnvironment, runtimeParams) : await defRegistry.getLinkedModule(versionedModuleId2, runtimeEnvironment, runtimeParams);
|
|
134
134
|
linkedDefinitions[visitedSpecifier] = module2;
|
|
135
135
|
}
|
package/build/cjs/identity.cjs
CHANGED
|
@@ -78,6 +78,7 @@ var DEFAULT_LWR_BOOTSTRAP_CONFIG = {
|
|
|
78
78
|
services: [],
|
|
79
79
|
configAsSrc: false,
|
|
80
80
|
ssr: false,
|
|
81
|
+
mixedMode: false,
|
|
81
82
|
module: void 0,
|
|
82
83
|
preloadModules: []
|
|
83
84
|
};
|
|
@@ -123,12 +124,12 @@ function getSpecifier({specifier, namespace, name = "", version}) {
|
|
|
123
124
|
const bareSpecifier = namespace ? `${namespace}/${name}` : name;
|
|
124
125
|
return version ? `${bareSpecifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}` : bareSpecifier;
|
|
125
126
|
}
|
|
126
|
-
async function getVersionedModuleId(rawSpecifier, moduleRegistry) {
|
|
127
|
+
async function getVersionedModuleId(rawSpecifier, moduleRegistry, runtimeParams) {
|
|
127
128
|
const moduleId = explodeSpecifier(rawSpecifier);
|
|
128
129
|
if (moduleId.version) {
|
|
129
130
|
return {...moduleId, version: normalizeVersionFromUri(moduleId.version)};
|
|
130
131
|
}
|
|
131
|
-
const moduleEntry = await moduleRegistry.getModuleEntry(moduleId);
|
|
132
|
+
const moduleEntry = await moduleRegistry.getModuleEntry(moduleId, runtimeParams);
|
|
132
133
|
return {...moduleId, version: moduleEntry.version};
|
|
133
134
|
}
|
|
134
135
|
var RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
|
package/build/cjs/index.cjs
CHANGED
|
@@ -35,3 +35,4 @@ __exportStar(exports, __toModule(require("./env.cjs")));
|
|
|
35
35
|
__exportStar(exports, __toModule(require("./logger.cjs")));
|
|
36
36
|
__exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
|
|
37
37
|
__exportStar(exports, __toModule(require("./bundle.cjs")));
|
|
38
|
+
__exportStar(exports, __toModule(require("./localization.cjs")));
|
|
@@ -0,0 +1,54 @@
|
|
|
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/shared-utils/src/localization.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
hasCountryCode: () => hasCountryCode,
|
|
28
|
+
stripCountryCode: () => stripCountryCode
|
|
29
|
+
});
|
|
30
|
+
var import_logger = __toModule(require("./logger.cjs"));
|
|
31
|
+
function hasCountryCode(locale) {
|
|
32
|
+
try {
|
|
33
|
+
const parsedLocale = new Intl.Locale(resolveLocaleId(locale));
|
|
34
|
+
return typeof parsedLocale.region === "string";
|
|
35
|
+
} catch (error) {
|
|
36
|
+
import_logger.logger.debug(`[static-util] Failed to parse country code from locale: ${locale}`, error);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function stripCountryCode(locale) {
|
|
41
|
+
try {
|
|
42
|
+
const parsedLocale = new Intl.Locale(resolveLocaleId(locale));
|
|
43
|
+
return parsedLocale.language;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
import_logger.logger.debug(`[static-util] Failed to strip country code from locale: ${locale}`, error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function resolveLocaleId(locale) {
|
|
49
|
+
const asLocalObj = locale;
|
|
50
|
+
if (asLocalObj.id !== void 0) {
|
|
51
|
+
return asLocalObj.id;
|
|
52
|
+
}
|
|
53
|
+
return locale;
|
|
54
|
+
}
|
package/build/cjs/mappings.cjs
CHANGED
|
@@ -37,7 +37,7 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
|
|
|
37
37
|
};
|
|
38
38
|
for (const moduleId of moduleIds) {
|
|
39
39
|
const requestedSpecifier = (0, import_identity.getSpecifier)(moduleId);
|
|
40
|
-
const specifier = await getVersionedSpecifier(moduleId, moduleRegistry);
|
|
40
|
+
const specifier = await getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams);
|
|
41
41
|
if (!visitedCache.has(specifier)) {
|
|
42
42
|
const depth = {
|
|
43
43
|
static: runtimeEnvironment.format === "esm" ? import_graph.GraphDepth.NONE : import_graph.GraphDepth.ALL,
|
|
@@ -136,12 +136,12 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
|
|
|
136
136
|
await Promise.all(promises);
|
|
137
137
|
return index;
|
|
138
138
|
}
|
|
139
|
-
async function getVersionedSpecifier(moduleId, moduleRegistry) {
|
|
139
|
+
async function getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams) {
|
|
140
140
|
if (!moduleId.importer || moduleId.version) {
|
|
141
141
|
return (0, import_identity.getSpecifier)(moduleId);
|
|
142
142
|
}
|
|
143
143
|
const versionedModuleEntry = await moduleRegistry.getModuleEntry({
|
|
144
144
|
...moduleId
|
|
145
|
-
});
|
|
145
|
+
}, runtimeParams);
|
|
146
146
|
return (0, import_identity.getSpecifier)(versionedModuleEntry);
|
|
147
147
|
}
|
package/build/es/graph.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export declare enum GraphDepth {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function isBundler(registry: PublicModuleRegistry | PublicModuleBundler): registry is PublicModuleBundler;
|
|
8
8
|
export declare function getModuleGraphs(specifier: string, // version | un-versioned specifiers
|
|
9
|
-
options: GraphOptions, moduleRegistry: ModuleRegistry, defRegistry: ModuleRegistry | ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams
|
|
9
|
+
options: GraphOptions, moduleRegistry: ModuleRegistry, defRegistry: ModuleRegistry | ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, visited?: Map<string, GraphNode>): Promise<FlattenedModuleGraphs>;
|
|
10
10
|
//# sourceMappingURL=graph.d.ts.map
|
package/build/es/graph.js
CHANGED
|
@@ -108,7 +108,7 @@ export async function getModuleGraphs(specifier, // version | un-versioned speci
|
|
|
108
108
|
options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited) {
|
|
109
109
|
const acc = visited || new Map();
|
|
110
110
|
// normalize the specifier
|
|
111
|
-
const versionedModuleId = await getVersionedModuleId(specifier, moduleRegistry);
|
|
111
|
+
const versionedModuleId = await getVersionedModuleId(specifier, moduleRegistry, runtimeParams);
|
|
112
112
|
const depth = options.depth || {
|
|
113
113
|
static: GraphDepth.DIRECT,
|
|
114
114
|
dynamic: 1,
|
|
@@ -127,7 +127,7 @@ options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited
|
|
|
127
127
|
if (options.includeUris) {
|
|
128
128
|
for (const visitedSpecifier of acc.keys()) {
|
|
129
129
|
// eslint-disable-next-line no-await-in-loop
|
|
130
|
-
const moduleId = await getVersionedModuleId(visitedSpecifier, moduleRegistry);
|
|
130
|
+
const moduleId = await getVersionedModuleId(visitedSpecifier, moduleRegistry, runtimeParams);
|
|
131
131
|
// eslint-disable-next-line no-await-in-loop
|
|
132
132
|
const uri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
|
|
133
133
|
uriMap[visitedSpecifier] = uri;
|
|
@@ -137,7 +137,7 @@ options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited
|
|
|
137
137
|
if (options.includeLinkedDefinitions) {
|
|
138
138
|
for (const visitedSpecifier of acc.keys()) {
|
|
139
139
|
// eslint-disable-next-line no-await-in-loop
|
|
140
|
-
const versionedModuleId = await getVersionedModuleId(visitedSpecifier, moduleRegistry);
|
|
140
|
+
const versionedModuleId = await getVersionedModuleId(visitedSpecifier, moduleRegistry, runtimeParams);
|
|
141
141
|
const module = isBundler(defRegistry)
|
|
142
142
|
? // eslint-disable-next-line no-await-in-loop
|
|
143
143
|
await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams)
|
package/build/es/identity.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ interface VersionedAbstractModuleId extends AbstractModuleId {
|
|
|
81
81
|
* @example - 'c/form/v/0.0.2' => {specifier: "c/form", version: "0.0.2"}
|
|
82
82
|
* @example - 'c/form/v/0_0_2' => {specifier: "c/form", version: "0.0.2"}
|
|
83
83
|
*/
|
|
84
|
-
export declare function getVersionedModuleId(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<VersionedAbstractModuleId>;
|
|
84
|
+
export declare function getVersionedModuleId(rawSpecifier: string, moduleRegistry: PublicModuleRegistry, runtimeParams: RuntimeParams): Promise<VersionedAbstractModuleId>;
|
|
85
85
|
interface PackageIdentity {
|
|
86
86
|
scope?: string;
|
|
87
87
|
packageName: string;
|
package/build/es/identity.js
CHANGED
|
@@ -22,6 +22,7 @@ export const DEFAULT_LWR_BOOTSTRAP_CONFIG = {
|
|
|
22
22
|
services: [],
|
|
23
23
|
configAsSrc: false,
|
|
24
24
|
ssr: false,
|
|
25
|
+
mixedMode: false,
|
|
25
26
|
module: undefined,
|
|
26
27
|
preloadModules: [],
|
|
27
28
|
};
|
|
@@ -119,13 +120,13 @@ export function getSpecifier({ specifier, namespace, name = '', version }) {
|
|
|
119
120
|
* @example - 'c/form/v/0.0.2' => {specifier: "c/form", version: "0.0.2"}
|
|
120
121
|
* @example - 'c/form/v/0_0_2' => {specifier: "c/form", version: "0.0.2"}
|
|
121
122
|
*/
|
|
122
|
-
export async function getVersionedModuleId(rawSpecifier, moduleRegistry) {
|
|
123
|
+
export async function getVersionedModuleId(rawSpecifier, moduleRegistry, runtimeParams) {
|
|
123
124
|
const moduleId = explodeSpecifier(rawSpecifier);
|
|
124
125
|
if (moduleId.version) {
|
|
125
126
|
return { ...moduleId, version: normalizeVersionFromUri(moduleId.version) };
|
|
126
127
|
}
|
|
127
128
|
// Get version from Module Registry
|
|
128
|
-
const moduleEntry = await moduleRegistry.getModuleEntry(moduleId);
|
|
129
|
+
const moduleEntry = await moduleRegistry.getModuleEntry(moduleId, runtimeParams);
|
|
129
130
|
return { ...moduleId, version: moduleEntry.version };
|
|
130
131
|
}
|
|
131
132
|
const RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
|
package/build/es/index.d.ts
CHANGED
package/build/es/index.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { logger } from './logger.js';
|
|
2
|
+
// Utilities for working with localized content
|
|
3
|
+
export function hasCountryCode(locale) {
|
|
4
|
+
try {
|
|
5
|
+
const parsedLocale = new Intl.Locale(resolveLocaleId(locale));
|
|
6
|
+
return typeof parsedLocale.region === 'string';
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
logger.debug(`[static-util] Failed to parse country code from locale: ${locale}`, error);
|
|
10
|
+
return false; // Invalid locale format
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function stripCountryCode(locale) {
|
|
14
|
+
try {
|
|
15
|
+
const parsedLocale = new Intl.Locale(resolveLocaleId(locale));
|
|
16
|
+
return parsedLocale.language;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
logger.debug(`[static-util] Failed to strip country code from locale: ${locale}`, error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function resolveLocaleId(locale) {
|
|
23
|
+
const asLocalObj = locale;
|
|
24
|
+
if (asLocalObj.id !== undefined) {
|
|
25
|
+
return asLocalObj.id;
|
|
26
|
+
}
|
|
27
|
+
return locale;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=localization.js.map
|
package/build/es/mappings.js
CHANGED
|
@@ -12,7 +12,7 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
|
|
|
12
12
|
for (const moduleId of moduleIds) {
|
|
13
13
|
const requestedSpecifier = getSpecifier(moduleId);
|
|
14
14
|
// eslint-disable-next-line no-await-in-loop
|
|
15
|
-
const specifier = await getVersionedSpecifier(moduleId, moduleRegistry);
|
|
15
|
+
const specifier = await getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams);
|
|
16
16
|
// Check if we have already visited
|
|
17
17
|
if (!visitedCache.has(specifier)) {
|
|
18
18
|
// Traversal of the Module Graph is done to get all the URLs for discoverable dependencies.
|
|
@@ -154,13 +154,13 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
|
|
|
154
154
|
await Promise.all(promises);
|
|
155
155
|
return index;
|
|
156
156
|
}
|
|
157
|
-
async function getVersionedSpecifier(moduleId, moduleRegistry) {
|
|
157
|
+
async function getVersionedSpecifier(moduleId, moduleRegistry, runtimeParams) {
|
|
158
158
|
if (!moduleId.importer || moduleId.version) {
|
|
159
159
|
return getSpecifier(moduleId);
|
|
160
160
|
}
|
|
161
161
|
const versionedModuleEntry = await moduleRegistry.getModuleEntry({
|
|
162
162
|
...moduleId,
|
|
163
|
-
});
|
|
163
|
+
}, runtimeParams);
|
|
164
164
|
return getSpecifier(versionedModuleEntry);
|
|
165
165
|
}
|
|
166
166
|
//# sourceMappingURL=mappings.js.map
|
package/build/es/serialize.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { LinkedModuleDefinition, ModuleJsonDefinition, ModuleRegistry, Runt
|
|
|
7
7
|
* @param moduleRegistry
|
|
8
8
|
* @returns - Promise to the JSON serialization of the module
|
|
9
9
|
*/
|
|
10
|
-
export declare function serializeModuleToJson(code: string | undefined, { specifier, version, ownHash, runtimeEnvironment, linkedConfig: { minified }, moduleRecord: { imports }, }: LinkedModuleDefinition, moduleRegistry: ModuleRegistry, runtimeParams
|
|
10
|
+
export declare function serializeModuleToJson(code: string | undefined, { specifier, version, ownHash, runtimeEnvironment, linkedConfig: { minified }, moduleRecord: { imports }, }: LinkedModuleDefinition, moduleRegistry: ModuleRegistry, runtimeParams: RuntimeParams): Promise<ModuleJsonDefinition>;
|
|
11
11
|
/**
|
|
12
12
|
* Replace a part of a source string at the indices with a different value
|
|
13
13
|
*
|
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.1",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"build/**/*.d.ts"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"es-module-lexer": "^1.
|
|
48
|
+
"es-module-lexer": "^1.3.0",
|
|
49
49
|
"fast-json-stable-stringify": "^2.1.0",
|
|
50
50
|
"magic-string": "^0.30.0",
|
|
51
51
|
"mime-types": "^2.1.33",
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
"rollup": "^2.78.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@lwrjs/diagnostics": "0.11.0-alpha.
|
|
65
|
-
"@lwrjs/types": "0.11.0-alpha.
|
|
64
|
+
"@lwrjs/diagnostics": "0.11.0-alpha.1",
|
|
65
|
+
"@lwrjs/types": "0.11.0-alpha.1",
|
|
66
66
|
"@types/mime-types": "2.1.1",
|
|
67
67
|
"@types/path-to-regexp": "^1.7.0"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=16.0.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "6a840d4694fac9f0be5c3a21707015379cbadad7"
|
|
73
73
|
}
|