@lwrjs/shared-utils 0.11.0-alpha.9 → 0.11.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/env.cjs +13 -0
- package/build/cjs/fs.cjs +4 -4
- package/build/cjs/html-meta.cjs +9 -5
- package/build/cjs/import-metadata.cjs +3 -3
- package/build/cjs/index.cjs +0 -1
- package/build/cjs/localization.cjs +38 -1
- package/build/cjs/urls.cjs +25 -0
- package/build/es/env.d.ts +5 -1
- package/build/es/env.js +19 -0
- package/build/es/fs.js +1 -1
- package/build/es/html-meta.d.ts +2 -2
- package/build/es/html-meta.js +9 -5
- package/build/es/import-metadata.js +1 -1
- package/build/es/index.d.ts +0 -1
- package/build/es/index.js +0 -1
- package/build/es/localization.d.ts +3 -1
- package/build/es/localization.js +41 -0
- package/build/es/urls.d.ts +9 -1
- package/build/es/urls.js +33 -0
- package/package.json +5 -17
- package/build/cjs/fs-watch.cjs +0 -43
- package/build/cjs/logger.cjs +0 -146
- package/build/cjs/typescript.cjs +0 -81
- package/build/es/fs-watch.d.ts +0 -17
- package/build/es/fs-watch.js +0 -27
- package/build/es/logger.d.ts +0 -23
- package/build/es/logger.js +0 -124
- package/build/es/typescript.d.ts +0 -7
- package/build/es/typescript.js +0 -70
package/build/cjs/env.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
// packages/@lwrjs/shared-utils/src/env.ts
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
|
+
buildEnvironmentContext: () => buildEnvironmentContext,
|
|
11
12
|
getFeatureFlags: () => getFeatureFlags
|
|
12
13
|
});
|
|
13
14
|
function getFeatureFlags() {
|
|
@@ -21,3 +22,15 @@ function getFeatureFlags() {
|
|
|
21
22
|
LWR_TRACING: process.env.LWR_TRACING !== void 0 && process.env.LWR_TRACING.toLowerCase() !== "off" ? true : false
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
function buildEnvironmentContext(runtimeParams) {
|
|
26
|
+
const basePath = runtimeParams.basePath;
|
|
27
|
+
const locale = runtimeParams.locale;
|
|
28
|
+
const assetBasePath = runtimeParams.assetBasePath;
|
|
29
|
+
const uiBasePath = runtimeParams.uiBasePath;
|
|
30
|
+
return {
|
|
31
|
+
basePath,
|
|
32
|
+
locale,
|
|
33
|
+
assetBasePath,
|
|
34
|
+
uiBasePath
|
|
35
|
+
};
|
|
36
|
+
}
|
package/build/cjs/fs.cjs
CHANGED
|
@@ -43,7 +43,7 @@ var import_identity = __toModule(require("./identity.cjs"));
|
|
|
43
43
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
44
44
|
var import_mime_types = __toModule(require("mime-types"));
|
|
45
45
|
var import_stream = __toModule(require("stream"));
|
|
46
|
-
var
|
|
46
|
+
var import_diagnostics2 = __toModule(require("@lwrjs/diagnostics"));
|
|
47
47
|
var fileCount = 0;
|
|
48
48
|
var files = new Map();
|
|
49
49
|
function hashContent(source) {
|
|
@@ -122,14 +122,14 @@ function normalizeResourcePath(rawPath, {rootDir, assets, contentDir, layoutsDir
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
function logMetrics(filePath) {
|
|
125
|
-
if (
|
|
125
|
+
if (import_diagnostics2.logger.currentLevel == import_diagnostics2.DEBUG || import_diagnostics2.logger.currentLevel == import_diagnostics2.VERBOSE) {
|
|
126
126
|
let count = files.get(filePath) || 0;
|
|
127
127
|
if (++count % 100 === 0) {
|
|
128
|
-
|
|
128
|
+
import_diagnostics2.logger.debug(`[${count}] Repeat Read ${filePath}`);
|
|
129
129
|
}
|
|
130
130
|
files.set(filePath, count);
|
|
131
131
|
if (++fileCount % 1e3 === 0) {
|
|
132
|
-
|
|
132
|
+
import_diagnostics2.logger.debug(`Open file count [${fileCount}]`);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}
|
package/build/cjs/html-meta.cjs
CHANGED
|
@@ -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
|
|
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);
|
|
@@ -28,7 +28,7 @@ __export(exports, {
|
|
|
28
28
|
getImportMetadata: () => getImportMetadata
|
|
29
29
|
});
|
|
30
30
|
var import_es_module_lexer = __toModule(require("es-module-lexer"));
|
|
31
|
-
var
|
|
31
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
32
|
var IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
33
33
|
var ModuleNameType;
|
|
34
34
|
(function(ModuleNameType2) {
|
|
@@ -53,8 +53,8 @@ async function getImportMetadata(compiledSource) {
|
|
|
53
53
|
const isStringLiteral = moduleSpecifier.startsWith("'") || moduleSpecifier.startsWith('"');
|
|
54
54
|
const moduleNameType = isStringLiteral ? ModuleNameType.string : ModuleNameType.unresolved;
|
|
55
55
|
moduleSpecifier = isStringLiteral ? moduleSpecifier.slice(1, -1) : moduleSpecifier;
|
|
56
|
-
if (
|
|
57
|
-
|
|
56
|
+
if (import_diagnostics.logger.currentLevel === import_diagnostics.DEBUG || import_diagnostics.logger.currentLevel === import_diagnostics.VERBOSE) {
|
|
57
|
+
import_diagnostics.logger.debug(`[import-metadata] Import from dynamic import ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.se)} -> ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.s)}`);
|
|
58
58
|
}
|
|
59
59
|
dynamicImports.push({
|
|
60
60
|
moduleSpecifier,
|
package/build/cjs/index.cjs
CHANGED
|
@@ -32,7 +32,6 @@ __exportStar(exports, __toModule(require("./graph.cjs")));
|
|
|
32
32
|
__exportStar(exports, __toModule(require("./mappings.cjs")));
|
|
33
33
|
__exportStar(exports, __toModule(require("./urls.cjs")));
|
|
34
34
|
__exportStar(exports, __toModule(require("./env.cjs")));
|
|
35
|
-
__exportStar(exports, __toModule(require("./logger.cjs")));
|
|
36
35
|
__exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
|
|
37
36
|
__exportStar(exports, __toModule(require("./bundle.cjs")));
|
|
38
37
|
__exportStar(exports, __toModule(require("./localization.cjs")));
|
|
@@ -8,9 +8,46 @@ var __export = (target, all) => {
|
|
|
8
8
|
// packages/@lwrjs/shared-utils/src/localization.ts
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
|
-
getFallbackLocale: () => getFallbackLocale
|
|
11
|
+
getFallbackLocale: () => getFallbackLocale,
|
|
12
|
+
sortLocalesByFallback: () => sortLocalesByFallback,
|
|
13
|
+
walkLocaleFallbacks: () => walkLocaleFallbacks
|
|
12
14
|
});
|
|
13
15
|
function getFallbackLocale(localeId, i18n) {
|
|
14
16
|
const locale = i18n.locales.find((l) => l.id === localeId);
|
|
15
17
|
return locale?.fallback;
|
|
16
18
|
}
|
|
19
|
+
async function walkLocaleFallbacks(initialLocale, i18n, test) {
|
|
20
|
+
const visited = new Set();
|
|
21
|
+
let localeId = initialLocale;
|
|
22
|
+
while (localeId && !visited.has(localeId)) {
|
|
23
|
+
const result = await test(localeId);
|
|
24
|
+
if (result) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
visited.add(localeId);
|
|
28
|
+
const config = i18n.locales.find((l) => l.id === localeId);
|
|
29
|
+
localeId = config && config.fallback;
|
|
30
|
+
}
|
|
31
|
+
if (!visited.has(i18n.defaultLocale)) {
|
|
32
|
+
return test(i18n.defaultLocale);
|
|
33
|
+
}
|
|
34
|
+
return void 0;
|
|
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/cjs/urls.cjs
CHANGED
|
@@ -29,10 +29,13 @@ __export(exports, {
|
|
|
29
29
|
getClientBootstrapConfigurationRoutes: () => getClientBootstrapConfigurationRoutes,
|
|
30
30
|
getClientBootstrapConfigurationUri: () => getClientBootstrapConfigurationUri,
|
|
31
31
|
getClientBootstrapConfigurationUriPrefix: () => getClientBootstrapConfigurationUriPrefix,
|
|
32
|
+
getViewUri: () => getViewUri,
|
|
32
33
|
isModuleOrBundleUrl: () => isModuleOrBundleUrl,
|
|
34
|
+
isURL: () => isURL,
|
|
33
35
|
removeClientBootstrapConfigurationSuffix: () => removeClientBootstrapConfigurationSuffix
|
|
34
36
|
});
|
|
35
37
|
var import_path_to_regexp = __toModule(require("path-to-regexp"));
|
|
38
|
+
var import_path = __toModule(require("path"));
|
|
36
39
|
var CONFIG_SUFFIX = "/config.js";
|
|
37
40
|
var SIGNATURE_SIGIL = "s";
|
|
38
41
|
function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams, signature) {
|
|
@@ -100,3 +103,25 @@ var isModuleOrBundleRegEx = /^\/.*\/(module|bundle)\//i;
|
|
|
100
103
|
function isModuleOrBundleUrl(url) {
|
|
101
104
|
return isModuleOrBundleRegEx.test(url);
|
|
102
105
|
}
|
|
106
|
+
function getViewUri(routePath, basePath, locale, i18n) {
|
|
107
|
+
if (isURL(routePath)) {
|
|
108
|
+
return routePath;
|
|
109
|
+
}
|
|
110
|
+
let url = basePath;
|
|
111
|
+
if (i18n.uriPattern === "path-prefix" && locale !== i18n.defaultLocale) {
|
|
112
|
+
url = import_path.default.join(url, `/${locale}`);
|
|
113
|
+
}
|
|
114
|
+
url = import_path.default.join(url, routePath);
|
|
115
|
+
if (i18n.uriPattern === "query-param" && locale !== i18n.defaultLocale) {
|
|
116
|
+
url = addQueryParamToAbsoluteURI(url, "locale", locale);
|
|
117
|
+
}
|
|
118
|
+
return url;
|
|
119
|
+
}
|
|
120
|
+
function isURL(uri) {
|
|
121
|
+
return /^https?:\/\//i.test(uri);
|
|
122
|
+
}
|
|
123
|
+
function addQueryParamToAbsoluteURI(absoluteURI, paramName, paramValue) {
|
|
124
|
+
const url = new URL(absoluteURI, "http://example.com");
|
|
125
|
+
url.searchParams.set(paramName, paramValue);
|
|
126
|
+
return url.pathname + url.search;
|
|
127
|
+
}
|
package/build/es/env.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import type { FeatureFlags } from '@lwrjs/types';
|
|
1
|
+
import type { EnvironmentContext, FeatureFlags, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
export declare function getFeatureFlags(): FeatureFlags;
|
|
3
|
+
/**
|
|
4
|
+
* Create a serializable context for the lwr/environment variable
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildEnvironmentContext(runtimeParams: RuntimeParams): EnvironmentContext;
|
|
3
7
|
//# sourceMappingURL=env.d.ts.map
|
package/build/es/env.js
CHANGED
|
@@ -35,4 +35,23 @@ export function getFeatureFlags() {
|
|
|
35
35
|
: false,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a serializable context for the lwr/environment variable
|
|
40
|
+
*/
|
|
41
|
+
export function buildEnvironmentContext(runtimeParams) {
|
|
42
|
+
// The baseBath from the config or set from the request (e.g. /shop)
|
|
43
|
+
const basePath = runtimeParams.basePath;
|
|
44
|
+
// The locale set from the request or the defaultLocale from the config (e.g. en-US)
|
|
45
|
+
const locale = runtimeParams.locale;
|
|
46
|
+
// Root base path for static assets (e.g. /shop/mobify/bundle/1234/site)
|
|
47
|
+
const assetBasePath = runtimeParams.assetBasePath;
|
|
48
|
+
// Base path for UI routing (e.g. /shop/en-US)
|
|
49
|
+
const uiBasePath = runtimeParams.uiBasePath;
|
|
50
|
+
return {
|
|
51
|
+
basePath,
|
|
52
|
+
locale,
|
|
53
|
+
assetBasePath,
|
|
54
|
+
uiBasePath,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
38
57
|
//# sourceMappingURL=env.js.map
|
package/build/es/fs.js
CHANGED
|
@@ -5,7 +5,7 @@ import { slugify } from './identity.js';
|
|
|
5
5
|
import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
|
|
6
6
|
import { lookup } from 'mime-types';
|
|
7
7
|
import { Readable } from 'stream';
|
|
8
|
-
import { DEBUG, logger, VERBOSE } from '
|
|
8
|
+
import { DEBUG, logger, VERBOSE } from '@lwrjs/diagnostics';
|
|
9
9
|
let fileCount = 0;
|
|
10
10
|
const files = new Map();
|
|
11
11
|
/**
|
package/build/es/html-meta.d.ts
CHANGED
|
@@ -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";
|
package/build/es/html-meta.js
CHANGED
|
@@ -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
|
|
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('-') &&
|
|
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);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse as parseImports } from 'es-module-lexer';
|
|
2
|
-
import { DEBUG, logger, VERBOSE } from '
|
|
2
|
+
import { DEBUG, logger, VERBOSE } from '@lwrjs/diagnostics';
|
|
3
3
|
const IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
4
4
|
export var ModuleNameType;
|
|
5
5
|
(function (ModuleNameType) {
|
package/build/es/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export * from './graph.js';
|
|
|
11
11
|
export * from './mappings.js';
|
|
12
12
|
export * from './urls.js';
|
|
13
13
|
export * from './env.js';
|
|
14
|
-
export * from './logger.js';
|
|
15
14
|
export * from './lwr-app-observer.js';
|
|
16
15
|
export * from './bundle.js';
|
|
17
16
|
export * from './localization.js';
|
package/build/es/index.js
CHANGED
|
@@ -11,7 +11,6 @@ export * from './graph.js';
|
|
|
11
11
|
export * from './mappings.js';
|
|
12
12
|
export * from './urls.js';
|
|
13
13
|
export * from './env.js';
|
|
14
|
-
export * from './logger.js';
|
|
15
14
|
export * from './lwr-app-observer.js';
|
|
16
15
|
export * from './bundle.js';
|
|
17
16
|
export * from './localization.js';
|
|
@@ -1,3 +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
|
+
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[];
|
|
3
5
|
//# sourceMappingURL=localization.d.ts.map
|
package/build/es/localization.js
CHANGED
|
@@ -3,4 +3,45 @@ export function getFallbackLocale(localeId, i18n) {
|
|
|
3
3
|
const locale = i18n.locales.find((l) => l.id === localeId);
|
|
4
4
|
return locale?.fallback;
|
|
5
5
|
}
|
|
6
|
+
// Utilities to walk locale fallback logic
|
|
7
|
+
export async function walkLocaleFallbacks(initialLocale, i18n, test) {
|
|
8
|
+
// Walk the locales
|
|
9
|
+
const visited = new Set();
|
|
10
|
+
let localeId = initialLocale;
|
|
11
|
+
while (localeId && !visited.has(localeId)) {
|
|
12
|
+
// eslint-disable-next-line no-await-in-loop
|
|
13
|
+
const result = await test(localeId);
|
|
14
|
+
if (result) {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
visited.add(localeId);
|
|
18
|
+
const config = i18n.locales.find((l) => l.id === localeId);
|
|
19
|
+
localeId = config && config.fallback;
|
|
20
|
+
}
|
|
21
|
+
// If we did not already visit the default locale give that a try
|
|
22
|
+
if (!visited.has(i18n.defaultLocale)) {
|
|
23
|
+
return test(i18n.defaultLocale);
|
|
24
|
+
}
|
|
25
|
+
// Did not find what we were looking for
|
|
26
|
+
return undefined;
|
|
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
|
+
}
|
|
6
47
|
//# sourceMappingURL=localization.js.map
|
package/build/es/urls.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
1
|
+
import type { I18NConfig, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
export declare function getClientBootstrapConfigurationUri(routeInfo: {
|
|
3
3
|
id: string;
|
|
4
4
|
url: string;
|
|
@@ -28,4 +28,12 @@ export declare function getClientBootstrapConfigurationRoutes(): string[];
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function extractRequestParams(parameterizedRoute: string, resolvedUrl: string, existingParams?: Record<string, string>): Record<string, string>;
|
|
30
30
|
export declare function isModuleOrBundleUrl(url: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Return a view route URL considering the basePath and the i18N config
|
|
33
|
+
*/
|
|
34
|
+
export declare function getViewUri(routePath: string, basePath: string, locale: string, i18n: I18NConfig): string;
|
|
35
|
+
/**
|
|
36
|
+
* Returns true is the URI starts with http:// or https://
|
|
37
|
+
*/
|
|
38
|
+
export declare function isURL(uri: string): boolean;
|
|
31
39
|
//# sourceMappingURL=urls.d.ts.map
|
package/build/es/urls.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { pathToRegexp } from 'path-to-regexp';
|
|
2
|
+
import path from 'path';
|
|
2
3
|
const CONFIG_SUFFIX = '/config.js';
|
|
3
4
|
const SIGNATURE_SIGIL = 's';
|
|
4
5
|
export function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams, signature) {
|
|
@@ -91,4 +92,36 @@ const isModuleOrBundleRegEx = /^\/.*\/(module|bundle)\//i;
|
|
|
91
92
|
export function isModuleOrBundleUrl(url) {
|
|
92
93
|
return isModuleOrBundleRegEx.test(url);
|
|
93
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Return a view route URL considering the basePath and the i18N config
|
|
97
|
+
*/
|
|
98
|
+
export function getViewUri(routePath, basePath, locale, i18n) {
|
|
99
|
+
// Use a regular expression to check if the URI has a domain
|
|
100
|
+
if (isURL(routePath)) {
|
|
101
|
+
return routePath;
|
|
102
|
+
}
|
|
103
|
+
let url = basePath;
|
|
104
|
+
if (i18n.uriPattern === 'path-prefix' && locale !== i18n.defaultLocale) {
|
|
105
|
+
url = path.join(url, `/${locale}`);
|
|
106
|
+
}
|
|
107
|
+
url = path.join(url, routePath);
|
|
108
|
+
if (i18n.uriPattern === 'query-param' && locale !== i18n.defaultLocale) {
|
|
109
|
+
url = addQueryParamToAbsoluteURI(url, 'locale', locale);
|
|
110
|
+
}
|
|
111
|
+
return url;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns true is the URI starts with http:// or https://
|
|
115
|
+
*/
|
|
116
|
+
export function isURL(uri) {
|
|
117
|
+
return /^https?:\/\//i.test(uri);
|
|
118
|
+
}
|
|
119
|
+
function addQueryParamToAbsoluteURI(absoluteURI, paramName, paramValue) {
|
|
120
|
+
// Use a dummy domain for parsing
|
|
121
|
+
const url = new URL(absoluteURI, 'http://example.com');
|
|
122
|
+
// Add the query parameter
|
|
123
|
+
url.searchParams.set(paramName, paramValue);
|
|
124
|
+
// Get the modified URI with the query parameter
|
|
125
|
+
return url.pathname + url.search;
|
|
126
|
+
}
|
|
94
127
|
//# sourceMappingURL=urls.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.
|
|
7
|
+
"version": "0.11.1",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -26,14 +26,6 @@
|
|
|
26
26
|
"import": "./build/es/index.js",
|
|
27
27
|
"require": "./build/cjs/index.cjs"
|
|
28
28
|
},
|
|
29
|
-
"./fs-watch": {
|
|
30
|
-
"import": "./build/es/fs-watch.js",
|
|
31
|
-
"require": "./build/cjs/fs-watch.cjs"
|
|
32
|
-
},
|
|
33
|
-
"./typescript": {
|
|
34
|
-
"import": "./build/es/typescript.js",
|
|
35
|
-
"require": "./build/cjs/typescript.cjs"
|
|
36
|
-
},
|
|
37
29
|
"./compiler": {
|
|
38
30
|
"import": "./build/es/compiler.js",
|
|
39
31
|
"require": "./build/cjs/compiler.cjs"
|
|
@@ -45,6 +37,7 @@
|
|
|
45
37
|
"build/**/*.d.ts"
|
|
46
38
|
],
|
|
47
39
|
"dependencies": {
|
|
40
|
+
"@lwrjs/diagnostics": "0.11.1",
|
|
48
41
|
"es-module-lexer": "^1.3.0",
|
|
49
42
|
"fast-json-stable-stringify": "^2.1.0",
|
|
50
43
|
"magic-string": "^0.30.0",
|
|
@@ -53,21 +46,16 @@
|
|
|
53
46
|
"parse5-sax-parser": "^6.0.1",
|
|
54
47
|
"path-to-regexp": "^6.2.0",
|
|
55
48
|
"resolve": "^1.22.1",
|
|
49
|
+
"rollup": "^2.78.0",
|
|
56
50
|
"slugify": "^1.4.5"
|
|
57
51
|
},
|
|
58
|
-
"peerDependencies": {
|
|
59
|
-
"chokidar": "^3.5.3",
|
|
60
|
-
"esbuild": "^0.9.7",
|
|
61
|
-
"rollup": "^2.78.0"
|
|
62
|
-
},
|
|
63
52
|
"devDependencies": {
|
|
64
|
-
"@lwrjs/
|
|
65
|
-
"@lwrjs/types": "0.11.0-alpha.9",
|
|
53
|
+
"@lwrjs/types": "0.11.1",
|
|
66
54
|
"@types/mime-types": "2.1.1",
|
|
67
55
|
"@types/path-to-regexp": "^1.7.0"
|
|
68
56
|
},
|
|
69
57
|
"engines": {
|
|
70
58
|
"node": ">=16.0.0"
|
|
71
59
|
},
|
|
72
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "b7c40fdcd86635dd4e368c0a2e91c5d3374c0fcf"
|
|
73
61
|
}
|
package/build/cjs/fs-watch.cjs
DELETED
|
@@ -1,43 +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/shared-utils/src/fs-watch.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
WatcherFactoryImpl: () => WatcherFactoryImpl
|
|
28
|
-
});
|
|
29
|
-
var import_chokidar = __toModule(require("chokidar"));
|
|
30
|
-
var import_object = __toModule(require("./object.cjs"));
|
|
31
|
-
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
-
var WatcherFactoryImpl = class {
|
|
33
|
-
createFileWatcher(options = {persistent: true, ignored: "**/node_modules/**"}) {
|
|
34
|
-
return import_chokidar.default.watch([], options);
|
|
35
|
-
}
|
|
36
|
-
setupWatcher(onModuleChange) {
|
|
37
|
-
const fileWatcher = this.createFileWatcher();
|
|
38
|
-
fileWatcher.on("change", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
39
|
-
fileWatcher.on("unlink", (0, import_object.debounce)((file) => onModuleChange(file), 500));
|
|
40
|
-
fileWatcher.on("add", (file) => import_logger.logger.info(`Watching: ${file}`));
|
|
41
|
-
return fileWatcher;
|
|
42
|
-
}
|
|
43
|
-
};
|
package/build/cjs/logger.cjs
DELETED
|
@@ -1,146 +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/shared-utils/src/logger.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
DEBUG: () => DEBUG,
|
|
28
|
-
ERROR: () => ERROR,
|
|
29
|
-
INFO: () => INFO,
|
|
30
|
-
VERBOSE: () => VERBOSE,
|
|
31
|
-
WARN: () => WARN,
|
|
32
|
-
logger: () => logger,
|
|
33
|
-
stringifyError: () => stringifyError
|
|
34
|
-
});
|
|
35
|
-
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
36
|
-
var VERBOSE = "verbose";
|
|
37
|
-
var DEBUG = "debug";
|
|
38
|
-
var INFO = "info";
|
|
39
|
-
var WARN = "warn";
|
|
40
|
-
var ERROR = "error";
|
|
41
|
-
var options = {};
|
|
42
|
-
var DUPES = new Set();
|
|
43
|
-
var currentLevel = process.env.LOG_LEVEL || INFO;
|
|
44
|
-
function log(level, message, additionalInfo) {
|
|
45
|
-
const LOG_LEVEL = process.env.LOG_LEVEL || INFO;
|
|
46
|
-
if (currentLevel !== LOG_LEVEL) {
|
|
47
|
-
currentLevel = LOG_LEVEL;
|
|
48
|
-
console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
|
|
49
|
-
}
|
|
50
|
-
let shouldLog = false;
|
|
51
|
-
switch (level) {
|
|
52
|
-
case VERBOSE:
|
|
53
|
-
shouldLog = LOG_LEVEL == VERBOSE;
|
|
54
|
-
break;
|
|
55
|
-
case DEBUG:
|
|
56
|
-
shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG;
|
|
57
|
-
break;
|
|
58
|
-
case INFO:
|
|
59
|
-
shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO;
|
|
60
|
-
break;
|
|
61
|
-
case WARN:
|
|
62
|
-
shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO || LOG_LEVEL == WARN;
|
|
63
|
-
break;
|
|
64
|
-
case ERROR:
|
|
65
|
-
shouldLog = true;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
if (shouldLog && options.dedupe && options.dedupe.has(level)) {
|
|
69
|
-
const key = `[${level}] : ${message}`;
|
|
70
|
-
if (DUPES.has(key)) {
|
|
71
|
-
shouldLog = false;
|
|
72
|
-
} else {
|
|
73
|
-
DUPES.add(key);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (shouldLog) {
|
|
77
|
-
const logMessage = `[${level}]${gap(message)}${message}`;
|
|
78
|
-
const additionalMessage = additionalInfo ? `Additional Info: ${JSON.stringify(additionalInfo)}` : void 0;
|
|
79
|
-
if (level == ERROR) {
|
|
80
|
-
console.error("[31m%s[0m", logMessage);
|
|
81
|
-
if (additionalInfo) {
|
|
82
|
-
console.error("\n[31m%s[0m", additionalMessage);
|
|
83
|
-
}
|
|
84
|
-
} else if (level == WARN) {
|
|
85
|
-
console.warn("[33m%s[0m", logMessage);
|
|
86
|
-
if (additionalInfo) {
|
|
87
|
-
console.warn("\n[33m%s[0m", additionalMessage);
|
|
88
|
-
}
|
|
89
|
-
} else if (level == DEBUG || level == VERBOSE) {
|
|
90
|
-
console.log("[2m%s[0m", logMessage);
|
|
91
|
-
if (additionalInfo) {
|
|
92
|
-
console.log("\n[2m%s[0m", additionalMessage);
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
console.log(logMessage);
|
|
96
|
-
if (additionalInfo) {
|
|
97
|
-
console.log(`
|
|
98
|
-
${additionalMessage}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
var stringifyError = (error) => {
|
|
104
|
-
if (error instanceof import_diagnostics.DiagnosticsError) {
|
|
105
|
-
return JSON.stringify({
|
|
106
|
-
message: error.message,
|
|
107
|
-
diagnostics: error.diagnostics,
|
|
108
|
-
stack: error.stack
|
|
109
|
-
});
|
|
110
|
-
} else if (typeof error === "string" || error instanceof String) {
|
|
111
|
-
return error;
|
|
112
|
-
} else {
|
|
113
|
-
const propertyNames = Object.getOwnPropertyNames(error);
|
|
114
|
-
const retObj = {};
|
|
115
|
-
for (let property, i = 0, len = propertyNames.length; i < len; ++i) {
|
|
116
|
-
property = propertyNames[i];
|
|
117
|
-
const descriptor = Object.getOwnPropertyDescriptor(error, property);
|
|
118
|
-
retObj[property] = descriptor?.value;
|
|
119
|
-
}
|
|
120
|
-
return JSON.stringify(retObj);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
function gap(message) {
|
|
124
|
-
return String(message)?.indexOf("[") === 0 ? "" : " ";
|
|
125
|
-
}
|
|
126
|
-
function logError(err, additionalInfo) {
|
|
127
|
-
if (err instanceof import_diagnostics.DiagnosticsError || !err || !err.message) {
|
|
128
|
-
log(ERROR, stringifyError(err), additionalInfo);
|
|
129
|
-
}
|
|
130
|
-
if (err && err.message) {
|
|
131
|
-
console.error("[31m%s[0m", `[${ERROR}]${gap(err.message)}${err.message}`);
|
|
132
|
-
console.error("[90m%s[0m", err);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
var logger = {
|
|
136
|
-
verbose: (message, additionalInfo) => log(VERBOSE, message, additionalInfo),
|
|
137
|
-
debug: (message, additionalInfo) => log(DEBUG, message, additionalInfo),
|
|
138
|
-
info: (message, additionalInfo) => log(INFO, message, additionalInfo),
|
|
139
|
-
warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
|
|
140
|
-
error: (error, additionalInfo) => logError(error, additionalInfo),
|
|
141
|
-
log,
|
|
142
|
-
setOptions: (opts) => {
|
|
143
|
-
options = opts;
|
|
144
|
-
},
|
|
145
|
-
currentLevel
|
|
146
|
-
};
|
package/build/cjs/typescript.cjs
DELETED
|
@@ -1,81 +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/shared-utils/src/typescript.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
transpileTs: () => transpileTs
|
|
28
|
-
});
|
|
29
|
-
var import_fs = __toModule(require("fs"));
|
|
30
|
-
var import_path = __toModule(require("path"));
|
|
31
|
-
var import_esbuild = __toModule(require("esbuild"));
|
|
32
|
-
var esbuild = import_esbuild.default;
|
|
33
|
-
if (!import_esbuild.default) {
|
|
34
|
-
try {
|
|
35
|
-
esbuild = require("esbuild");
|
|
36
|
-
} catch {
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
var isCommonJs = typeof module !== "undefined";
|
|
40
|
-
var ESBUILD_EXTENSION_PLUGIN = function(absFilePath, format) {
|
|
41
|
-
return {
|
|
42
|
-
name: "replace-extension-plugin",
|
|
43
|
-
setup(build) {
|
|
44
|
-
build.onResolve({filter: /.*/}, ({path, importer, resolveDir}) => {
|
|
45
|
-
if (path !== absFilePath) {
|
|
46
|
-
if (path.startsWith(".")) {
|
|
47
|
-
const importeeExt = (0, import_path.extname)(path);
|
|
48
|
-
const ext = importeeExt !== "" ? importeeExt : ".ts";
|
|
49
|
-
let absPath = (0, import_path.join)((0, import_path.dirname)(importer), `${path}${ext}`);
|
|
50
|
-
if (!import_fs.default.existsSync(absPath) && ext === ".js") {
|
|
51
|
-
absPath = absPath.replace(".js", ".ts");
|
|
52
|
-
}
|
|
53
|
-
return {path: absPath};
|
|
54
|
-
} else {
|
|
55
|
-
return {
|
|
56
|
-
external: true
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
async function transpileTs(tsAbsPath, {rootDir, cacheDir}) {
|
|
65
|
-
const format = isCommonJs ? "cjs" : "esm";
|
|
66
|
-
const ext = format === "esm" ? ".mjs" : ".cjs";
|
|
67
|
-
const pathRelativeToRoot = tsAbsPath.replace(new RegExp(`^${rootDir}`), "");
|
|
68
|
-
const outBasename = pathRelativeToRoot.replace(/\//g, "_");
|
|
69
|
-
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
70
|
-
const outfile = (0, import_path.join)(cacheDir, outFilename);
|
|
71
|
-
await esbuild.build({
|
|
72
|
-
format,
|
|
73
|
-
bundle: true,
|
|
74
|
-
logLevel: "error",
|
|
75
|
-
entryPoints: [tsAbsPath],
|
|
76
|
-
sourcemap: true,
|
|
77
|
-
outfile,
|
|
78
|
-
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)]
|
|
79
|
-
});
|
|
80
|
-
return outfile;
|
|
81
|
-
}
|
package/build/es/fs-watch.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Watcher, WatcherFactory, WatchOptions } from '@lwrjs/types';
|
|
2
|
-
/**
|
|
3
|
-
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
4
|
-
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
5
|
-
*/
|
|
6
|
-
export declare class WatcherFactoryImpl implements WatcherFactory {
|
|
7
|
-
/**
|
|
8
|
-
* Set up a watcher with the given options
|
|
9
|
-
* @param options
|
|
10
|
-
*/
|
|
11
|
-
createFileWatcher(options?: WatchOptions): Watcher;
|
|
12
|
-
/**
|
|
13
|
-
* Set up file watcher
|
|
14
|
-
*/
|
|
15
|
-
setupWatcher(onModuleChange: Function): Watcher;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=fs-watch.d.ts.map
|
package/build/es/fs-watch.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import chokidar from 'chokidar';
|
|
2
|
-
import { debounce } from './object.js';
|
|
3
|
-
import { logger } from './logger.js';
|
|
4
|
-
/**
|
|
5
|
-
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
6
|
-
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
7
|
-
*/
|
|
8
|
-
export class WatcherFactoryImpl {
|
|
9
|
-
/**
|
|
10
|
-
* Set up a watcher with the given options
|
|
11
|
-
* @param options
|
|
12
|
-
*/
|
|
13
|
-
createFileWatcher(options = { persistent: true, ignored: '**/node_modules/**' }) {
|
|
14
|
-
return chokidar.watch([], options);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Set up file watcher
|
|
18
|
-
*/
|
|
19
|
-
setupWatcher(onModuleChange) {
|
|
20
|
-
const fileWatcher = this.createFileWatcher();
|
|
21
|
-
fileWatcher.on('change', debounce((file) => onModuleChange(file), 500));
|
|
22
|
-
fileWatcher.on('unlink', debounce((file) => onModuleChange(file), 500));
|
|
23
|
-
fileWatcher.on('add', (file) => logger.info(`Watching: ${file}`));
|
|
24
|
-
return fileWatcher;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=fs-watch.js.map
|
package/build/es/logger.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type LEVEL = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
-
export declare const VERBOSE: LEVEL;
|
|
3
|
-
export declare const DEBUG: LEVEL;
|
|
4
|
-
export declare const INFO: LEVEL;
|
|
5
|
-
export declare const WARN: LEVEL;
|
|
6
|
-
export declare const ERROR: LEVEL;
|
|
7
|
-
type LoggerOptions = {
|
|
8
|
-
dedupe?: Set<string>;
|
|
9
|
-
};
|
|
10
|
-
declare function log(level: string, message: string, additionalInfo?: any): void;
|
|
11
|
-
export declare const stringifyError: (error: any) => string;
|
|
12
|
-
export declare const logger: {
|
|
13
|
-
verbose: (message: string, additionalInfo?: any) => void;
|
|
14
|
-
debug: (message: string, additionalInfo?: any) => void;
|
|
15
|
-
info: (message: string, additionalInfo?: any) => void;
|
|
16
|
-
warn: (message: string, additionalInfo?: any) => void;
|
|
17
|
-
error: (error: any, additionalInfo?: any) => void;
|
|
18
|
-
log: typeof log;
|
|
19
|
-
setOptions: (opts: LoggerOptions) => void;
|
|
20
|
-
currentLevel: string;
|
|
21
|
-
};
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/build/es/logger.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { DiagnosticsError } from '@lwrjs/diagnostics';
|
|
2
|
-
export const VERBOSE = 'verbose';
|
|
3
|
-
export const DEBUG = 'debug';
|
|
4
|
-
export const INFO = 'info';
|
|
5
|
-
export const WARN = 'warn';
|
|
6
|
-
export const ERROR = 'error';
|
|
7
|
-
let options = {};
|
|
8
|
-
const DUPES = new Set();
|
|
9
|
-
let currentLevel = process.env.LOG_LEVEL || INFO;
|
|
10
|
-
function log(level, message, additionalInfo) {
|
|
11
|
-
const LOG_LEVEL = process.env.LOG_LEVEL || INFO;
|
|
12
|
-
if (currentLevel !== LOG_LEVEL) {
|
|
13
|
-
currentLevel = LOG_LEVEL;
|
|
14
|
-
console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
|
|
15
|
-
}
|
|
16
|
-
let shouldLog = false;
|
|
17
|
-
switch (level) {
|
|
18
|
-
case VERBOSE:
|
|
19
|
-
shouldLog = LOG_LEVEL == VERBOSE;
|
|
20
|
-
break;
|
|
21
|
-
case DEBUG:
|
|
22
|
-
shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG;
|
|
23
|
-
break;
|
|
24
|
-
case INFO:
|
|
25
|
-
shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO;
|
|
26
|
-
break;
|
|
27
|
-
case WARN:
|
|
28
|
-
shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO || LOG_LEVEL == WARN;
|
|
29
|
-
break;
|
|
30
|
-
case ERROR:
|
|
31
|
-
shouldLog = true;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
// Check if we should suppress dupes and we have already logged this message
|
|
35
|
-
if (shouldLog && options.dedupe && options.dedupe.has(level)) {
|
|
36
|
-
const key = `[${level}] : ${message}`;
|
|
37
|
-
if (DUPES.has(key)) {
|
|
38
|
-
shouldLog = false;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
// add key to de-duplicate cache
|
|
42
|
-
DUPES.add(key);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (shouldLog) {
|
|
46
|
-
const logMessage = `[${level}]${gap(message)}${message}`;
|
|
47
|
-
const additionalMessage = additionalInfo
|
|
48
|
-
? `Additional Info: ${JSON.stringify(additionalInfo)}`
|
|
49
|
-
: undefined;
|
|
50
|
-
if (level == ERROR) {
|
|
51
|
-
console.error('\x1b[31m%s\x1b[0m', logMessage); // red
|
|
52
|
-
if (additionalInfo) {
|
|
53
|
-
console.error('\n\x1b[31m%s\x1b[0m', additionalMessage); // red
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (level == WARN) {
|
|
57
|
-
console.warn('\x1b[33m%s\x1b[0m', logMessage); // yellow
|
|
58
|
-
if (additionalInfo) {
|
|
59
|
-
console.warn('\n\x1b[33m%s\x1b[0m', additionalMessage); // yellow
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else if (level == DEBUG || level == VERBOSE) {
|
|
63
|
-
console.log('\x1b[2m%s\x1b[0m', logMessage); // dim
|
|
64
|
-
if (additionalInfo) {
|
|
65
|
-
console.log('\n\x1b[2m%s\x1b[0m', additionalMessage); // dim
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
console.log(logMessage);
|
|
70
|
-
if (additionalInfo) {
|
|
71
|
-
console.log(`\n${additionalMessage}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export const stringifyError = (error) => {
|
|
77
|
-
if (error instanceof DiagnosticsError) {
|
|
78
|
-
return JSON.stringify({
|
|
79
|
-
message: error.message,
|
|
80
|
-
diagnostics: error.diagnostics,
|
|
81
|
-
stack: error.stack,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
else if (typeof error === 'string' || error instanceof String) {
|
|
85
|
-
return error;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const propertyNames = Object.getOwnPropertyNames(error);
|
|
89
|
-
const retObj = {};
|
|
90
|
-
for (let property, i = 0, len = propertyNames.length; i < len; ++i) {
|
|
91
|
-
property = propertyNames[i];
|
|
92
|
-
const descriptor = Object.getOwnPropertyDescriptor(error, property);
|
|
93
|
-
retObj[property] = descriptor?.value;
|
|
94
|
-
}
|
|
95
|
-
return JSON.stringify(retObj);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
// Return a space if there should be a space between the message and the level
|
|
99
|
-
function gap(message) {
|
|
100
|
-
return String(message)?.indexOf('[') === 0 ? '' : ' ';
|
|
101
|
-
}
|
|
102
|
-
function logError(err, additionalInfo) {
|
|
103
|
-
if (err instanceof DiagnosticsError || !err || !err.message) {
|
|
104
|
-
log(ERROR, stringifyError(err), additionalInfo);
|
|
105
|
-
}
|
|
106
|
-
// If this is an error with a message update the message header and log as is...
|
|
107
|
-
if (err && err.message) {
|
|
108
|
-
console.error('\x1b[31m%s\x1b[0m', `[${ERROR}]${gap(err.message)}${err.message}`);
|
|
109
|
-
console.error('\x1b[90m%s\x1b[0m', err);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export const logger = {
|
|
113
|
-
verbose: (message, additionalInfo) => log(VERBOSE, message, additionalInfo),
|
|
114
|
-
debug: (message, additionalInfo) => log(DEBUG, message, additionalInfo),
|
|
115
|
-
info: (message, additionalInfo) => log(INFO, message, additionalInfo),
|
|
116
|
-
warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
|
|
117
|
-
error: (error, additionalInfo) => logError(error, additionalInfo),
|
|
118
|
-
log,
|
|
119
|
-
setOptions: (opts) => {
|
|
120
|
-
options = opts;
|
|
121
|
-
},
|
|
122
|
-
currentLevel,
|
|
123
|
-
};
|
|
124
|
-
//# sourceMappingURL=logger.js.map
|
package/build/es/typescript.d.ts
DELETED
package/build/es/typescript.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { join, dirname, extname } from 'path';
|
|
3
|
-
import esbuildEsm from 'esbuild';
|
|
4
|
-
// https://github.com/evanw/esbuild/issues/706
|
|
5
|
-
// Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
|
|
6
|
-
// https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
|
|
7
|
-
let esbuild = esbuildEsm;
|
|
8
|
-
if (!esbuildEsm) {
|
|
9
|
-
try {
|
|
10
|
-
esbuild = require('esbuild');
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
/* this is to support mjs/cjs dual impl */
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// This is important as it checks which compilation to use esm or cjs based on the current way NodeJS is configured
|
|
17
|
-
const isCommonJs = typeof module !== 'undefined';
|
|
18
|
-
/* istanbul ignore next */
|
|
19
|
-
const ESBUILD_EXTENSION_PLUGIN = function (absFilePath, format) {
|
|
20
|
-
return {
|
|
21
|
-
name: 'replace-extension-plugin',
|
|
22
|
-
setup(build) {
|
|
23
|
-
build.onResolve({ filter: /.*/ }, ({ path, importer, resolveDir }) => {
|
|
24
|
-
if (path !== absFilePath) {
|
|
25
|
-
if (path.startsWith('.')) {
|
|
26
|
-
const importeeExt = extname(path);
|
|
27
|
-
const ext = importeeExt !== '' ? importeeExt : '.ts';
|
|
28
|
-
let absPath = join(dirname(importer), `${path}${ext}`);
|
|
29
|
-
// If typescript import is a ".js" try to find the equivalent .ts
|
|
30
|
-
// We do this to keep consistency with TS resolution
|
|
31
|
-
if (!fs.existsSync(absPath) && ext === '.js') {
|
|
32
|
-
absPath = absPath.replace('.js', '.ts');
|
|
33
|
-
}
|
|
34
|
-
return { path: absPath };
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return {
|
|
38
|
-
external: true,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
// Transpile a typescript file and cache it
|
|
47
|
-
// The filename of the cached file is:
|
|
48
|
-
// - the path to the ts file relative to the project root
|
|
49
|
-
// - with all slashes replaced by underscores
|
|
50
|
-
// - and a new file extension of .mjs or .cjs
|
|
51
|
-
// eg: "/rootDir/path/to/file.ts" => "/cacheDir/path_to_file.*js"
|
|
52
|
-
export async function transpileTs(tsAbsPath, { rootDir, cacheDir }) {
|
|
53
|
-
const format = isCommonJs ? 'cjs' : 'esm';
|
|
54
|
-
const ext = format === 'esm' ? '.mjs' : '.cjs';
|
|
55
|
-
const pathRelativeToRoot = tsAbsPath.replace(new RegExp(`^${rootDir}`), '');
|
|
56
|
-
const outBasename = pathRelativeToRoot.replace(/\//g, '_'); // replace "/" with "_" in path
|
|
57
|
-
const outFilename = outBasename.replace(/\.ts$/, ext);
|
|
58
|
-
const outfile = join(cacheDir, outFilename);
|
|
59
|
-
await esbuild.build({
|
|
60
|
-
format,
|
|
61
|
-
bundle: true,
|
|
62
|
-
logLevel: 'error',
|
|
63
|
-
entryPoints: [tsAbsPath],
|
|
64
|
-
sourcemap: true,
|
|
65
|
-
outfile,
|
|
66
|
-
plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)],
|
|
67
|
-
});
|
|
68
|
-
return outfile;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=typescript.js.map
|