@lwrjs/shared-utils 0.9.0-alpha.26 → 0.9.0-alpha.28
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 +2 -1
- package/build/cjs/fs.cjs +24 -0
- package/build/cjs/identity.cjs +8 -3
- package/build/cjs/site-metadata.cjs +13 -8
- package/build/es/env.js +6 -1
- package/build/es/fs.d.ts +5 -1
- package/build/es/fs.js +33 -2
- package/build/es/identity.d.ts +4 -3
- package/build/es/identity.js +6 -2
- package/build/es/site-metadata.js +17 -11
- package/package.json +4 -4
package/build/cjs/env.cjs
CHANGED
|
@@ -14,6 +14,7 @@ function getFeatureFlags() {
|
|
|
14
14
|
return {
|
|
15
15
|
LEGACY_LOADER: process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER.toLowerCase() === "true" ? true : false,
|
|
16
16
|
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.toLowerCase() === "true" ? true : false,
|
|
17
|
-
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== void 0 && process.env.SSR_SANDBOX_WORKER.toLowerCase() === "true" ? true : false
|
|
17
|
+
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== void 0 && process.env.SSR_SANDBOX_WORKER.toLowerCase() === "true" ? true : false,
|
|
18
|
+
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== void 0 && process.env.ASSETS_ON_LAMBDA.toLowerCase() === "true" ? true : false
|
|
18
19
|
};
|
|
19
20
|
}
|
package/build/cjs/fs.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(exports, {
|
|
|
28
28
|
getViewSourceFromFile: () => getViewSourceFromFile,
|
|
29
29
|
hashContent: () => hashContent,
|
|
30
30
|
mimeLookup: () => import_mime_types.lookup,
|
|
31
|
+
normalizeAssetSpecifier: () => normalizeAssetSpecifier,
|
|
31
32
|
normalizeDirectory: () => normalizeDirectory,
|
|
32
33
|
normalizeResourcePath: () => normalizeResourcePath,
|
|
33
34
|
readFile: () => readFile,
|
|
@@ -126,3 +127,26 @@ function logMetrics(filePath) {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
}
|
|
130
|
+
function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, basePath) {
|
|
131
|
+
const {specifier, importer, type} = assetId;
|
|
132
|
+
if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
133
|
+
if (!importer) {
|
|
134
|
+
throw Error(`Unable to resolve relative import "${specifier}" without an importer.`);
|
|
135
|
+
}
|
|
136
|
+
return import_path.default.join(import_path.default.dirname(importer), specifier);
|
|
137
|
+
}
|
|
138
|
+
if (type === "content-asset") {
|
|
139
|
+
const originSpecifier = !basePath ? specifier : specifier.split(basePath)[1];
|
|
140
|
+
return import_path.default.join(resourcePaths.contentDir, originSpecifier);
|
|
141
|
+
}
|
|
142
|
+
if (specifier[0] === "$") {
|
|
143
|
+
return normalizeResourcePath(specifier, resourcePaths);
|
|
144
|
+
}
|
|
145
|
+
for (const [urlPath, fsPath] of assetPathMap.entries()) {
|
|
146
|
+
const slashPath = urlPath.endsWith("/") ? urlPath : `${urlPath}/`;
|
|
147
|
+
if (specifier.startsWith(slashPath) || specifier === urlPath) {
|
|
148
|
+
return specifier.replace(urlPath, fsPath);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return specifier;
|
|
152
|
+
}
|
package/build/cjs/identity.cjs
CHANGED
|
@@ -43,9 +43,10 @@ __export(exports, {
|
|
|
43
43
|
getPropFromAttrName: () => getPropFromAttrName,
|
|
44
44
|
getSpecifier: () => getSpecifier,
|
|
45
45
|
getVersionedModuleId: () => getVersionedModuleId,
|
|
46
|
+
isAssetSourceExternal: () => isAssetSourceExternal,
|
|
46
47
|
isBundleDefinition: () => isBundleDefinition,
|
|
47
48
|
isExternalUrl: () => isExternalUrl,
|
|
48
|
-
|
|
49
|
+
kebabCaseToModuleSpecifier: () => kebabCaseToModuleSpecifier,
|
|
49
50
|
moduleSpecifierToKebabCase: () => moduleSpecifierToKebabCase,
|
|
50
51
|
normalizeVersionFromUri: () => normalizeVersionFromUri,
|
|
51
52
|
normalizeVersionToUri: () => normalizeVersionToUri,
|
|
@@ -75,7 +76,8 @@ var DEFAULT_LWR_BOOTSTRAP_CONFIG = {
|
|
|
75
76
|
services: [],
|
|
76
77
|
configAsSrc: false,
|
|
77
78
|
ssr: false,
|
|
78
|
-
module: void 0
|
|
79
|
+
module: void 0,
|
|
80
|
+
preloadModules: []
|
|
79
81
|
};
|
|
80
82
|
function normalizeVersionToUri(version) {
|
|
81
83
|
return version.replace(/\./g, "_");
|
|
@@ -148,7 +150,7 @@ function parsePackageSpecifier(specifier) {
|
|
|
148
150
|
subResource: matched[2] || ""
|
|
149
151
|
};
|
|
150
152
|
}
|
|
151
|
-
function
|
|
153
|
+
function kebabCaseToModuleSpecifier(name) {
|
|
152
154
|
const newName = [];
|
|
153
155
|
let nsFound = false;
|
|
154
156
|
let upper = false;
|
|
@@ -197,6 +199,9 @@ var REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
|
|
|
197
199
|
function isExternalUrl(url) {
|
|
198
200
|
return REGEX_URL_SCHEMA_PREFIX.test(url);
|
|
199
201
|
}
|
|
202
|
+
function isAssetSourceExternal(assetSource) {
|
|
203
|
+
return assetSource.type === "external" || !!assetSource.uri && isExternalUrl(assetSource.uri);
|
|
204
|
+
}
|
|
200
205
|
function isBundleDefinition(definition) {
|
|
201
206
|
return definition.bundleRecord !== void 0;
|
|
202
207
|
}
|
|
@@ -54,15 +54,20 @@ var SiteMetadataImpl = class {
|
|
|
54
54
|
}
|
|
55
55
|
async persistSiteMetadata() {
|
|
56
56
|
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
57
|
-
|
|
58
|
-
await import_fs_extra.default.
|
|
57
|
+
try {
|
|
58
|
+
if (!await import_fs_extra.default.pathExists(siteMetadataPath)) {
|
|
59
|
+
await import_fs_extra.default.mkdir(siteMetadataPath, {recursive: true});
|
|
60
|
+
}
|
|
61
|
+
const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
62
|
+
await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
|
|
63
|
+
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
64
|
+
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
65
|
+
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
66
|
+
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
69
|
+
console.error(err);
|
|
59
70
|
}
|
|
60
|
-
const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
61
|
-
await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
|
|
62
|
-
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
63
|
-
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
64
|
-
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
65
|
-
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
66
71
|
}
|
|
67
72
|
readStaticBundleMetadata(staticRoot) {
|
|
68
73
|
let bundleMetadataPath;
|
package/build/es/env.js
CHANGED
|
@@ -10,11 +10,16 @@ export function getFeatureFlags() {
|
|
|
10
10
|
process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
|
|
11
11
|
? true
|
|
12
12
|
: false,
|
|
13
|
-
// Should we use a js worker for SSR,
|
|
13
|
+
// Should we use a js worker for SSR, sand-boxing = false (use locker for ssr sand-boxing)
|
|
14
14
|
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== undefined &&
|
|
15
15
|
process.env.SSR_SANDBOX_WORKER.toLowerCase() === 'true'
|
|
16
16
|
? true
|
|
17
17
|
: false,
|
|
18
|
+
// Should we load load the assets from the lambda on MRT
|
|
19
|
+
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== undefined &&
|
|
20
|
+
process.env.ASSETS_ON_LAMBDA.toLowerCase() === 'true'
|
|
21
|
+
? true
|
|
22
|
+
: false,
|
|
18
23
|
};
|
|
19
24
|
}
|
|
20
25
|
//# sourceMappingURL=env.js.map
|
package/build/es/fs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { ResourcePaths, ViewSource } from '@lwrjs/types';
|
|
2
|
+
import type { AssetIdentifier, ResourcePaths, ViewSource } from '@lwrjs/types';
|
|
3
3
|
import { lookup } from 'mime-types';
|
|
4
4
|
/**
|
|
5
5
|
* Create a hash string for a source
|
|
@@ -32,4 +32,8 @@ export declare function getViewSourceFromFile(source: string): ViewSource;
|
|
|
32
32
|
export declare function normalizeDirectory(dir: string, rootDir: string): string;
|
|
33
33
|
export declare function normalizeResourcePath(rawPath: string, { rootDir, assets, contentDir, layoutsDir }: ResourcePaths, allowUnresolvedAlias?: boolean): string;
|
|
34
34
|
export { lookup as mimeLookup };
|
|
35
|
+
/**
|
|
36
|
+
* Tries to convert any URL or $aliased path into a canonical fs path
|
|
37
|
+
*/
|
|
38
|
+
export declare function normalizeAssetSpecifier(assetId: AssetIdentifier, assetPathMap: Map<string, string>, resourcePaths: ResourcePaths, basePath: string): string;
|
|
35
39
|
//# sourceMappingURL=fs.d.ts.map
|
package/build/es/fs.js
CHANGED
|
@@ -36,10 +36,10 @@ export function resolveFileExtension(filePath) {
|
|
|
36
36
|
// No extension, if it exist, it can be a dir or a file
|
|
37
37
|
if (fs.existsSync(filePath)) {
|
|
38
38
|
if (fs.statSync(filePath).isFile()) {
|
|
39
|
-
return filePath; //
|
|
39
|
+
return filePath; // extension-less file, which is odd but...
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
|
-
filePath = pathLib.join(filePath, 'index'); // if is a dir we will be
|
|
42
|
+
filePath = pathLib.join(filePath, 'index'); // if is a dir we will be testing the extensions
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
// At this point we have a file with no extension so we try for the default (js,ts) or fail
|
|
@@ -132,4 +132,35 @@ function logMetrics(filePath) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Tries to convert any URL or $aliased path into a canonical fs path
|
|
137
|
+
*/
|
|
138
|
+
export function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, basePath) {
|
|
139
|
+
const { specifier, importer, type } = assetId;
|
|
140
|
+
if (specifier.startsWith('./') || specifier.startsWith('../')) {
|
|
141
|
+
if (!importer) {
|
|
142
|
+
throw Error(`Unable to resolve relative import "${specifier}" without an importer.`);
|
|
143
|
+
}
|
|
144
|
+
return pathLib.join(pathLib.dirname(importer), specifier);
|
|
145
|
+
}
|
|
146
|
+
if (type === 'content-asset') {
|
|
147
|
+
const originSpecifier = !basePath ? specifier : specifier.split(basePath)[1];
|
|
148
|
+
return pathLib.join(resourcePaths.contentDir, originSpecifier);
|
|
149
|
+
}
|
|
150
|
+
if (specifier[0] === '$') {
|
|
151
|
+
// This is a fs path containing an asset alias
|
|
152
|
+
return normalizeResourcePath(specifier, resourcePaths);
|
|
153
|
+
}
|
|
154
|
+
// This is an absolute path to the server
|
|
155
|
+
// Match in 2 ways:
|
|
156
|
+
// - Directories: the prefix of the asset specifier/path matches a configured assets[i].urlPath
|
|
157
|
+
// - Individual files: the asset specifier is equal to a configured assets[i].urlPath
|
|
158
|
+
for (const [urlPath, fsPath] of assetPathMap.entries()) {
|
|
159
|
+
const slashPath = urlPath.endsWith('/') ? urlPath : `${urlPath}/`;
|
|
160
|
+
if (specifier.startsWith(slashPath) || specifier === urlPath) {
|
|
161
|
+
return specifier.replace(urlPath, fsPath);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return specifier;
|
|
165
|
+
}
|
|
135
166
|
//# sourceMappingURL=fs.js.map
|
package/build/es/identity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import getCacheKeyFromJson from 'fast-json-stable-stringify';
|
|
2
|
-
import { AbstractModuleId, BundleDefinition, ModuleDefinition, NormalizedLwrAppBootstrapConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
|
+
import { AbstractModuleId, AssetSource, BundleDefinition, ModuleDefinition, NormalizedLwrAppBootstrapConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
3
3
|
export declare const VERSION_SIGIL = "/v/";
|
|
4
4
|
export declare const LOCALE_SIGIL = "l";
|
|
5
5
|
export declare const ENVIRONMENT_SIGIL = "e";
|
|
@@ -104,9 +104,9 @@ export declare function parsePackageSpecifier(specifier: string): PackageIdentit
|
|
|
104
104
|
* @param name A string in kebab case
|
|
105
105
|
* @example - 'name-of-something' => 'name/ofSomething'
|
|
106
106
|
*/
|
|
107
|
-
export declare function
|
|
107
|
+
export declare function kebabCaseToModuleSpecifier(name: string): string;
|
|
108
108
|
/**
|
|
109
|
-
* Clone of lwr/init, reverse of
|
|
109
|
+
* Clone of lwr/init, reverse of kebabCaseToModuleSpecifier, strips off versions
|
|
110
110
|
* @param specifier
|
|
111
111
|
* @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
|
|
112
112
|
*/
|
|
@@ -137,5 +137,6 @@ export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat,
|
|
|
137
137
|
export declare function getMappingUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams): string;
|
|
138
138
|
export { getCacheKeyFromJson };
|
|
139
139
|
export declare function isExternalUrl(url: string): boolean;
|
|
140
|
+
export declare function isAssetSourceExternal(assetSource: AssetSource): boolean;
|
|
140
141
|
export declare function isBundleDefinition(definition: ModuleDefinition | BundleDefinition): definition is BundleDefinition;
|
|
141
142
|
//# sourceMappingURL=identity.d.ts.map
|
package/build/es/identity.js
CHANGED
|
@@ -22,6 +22,7 @@ export const DEFAULT_LWR_BOOTSTRAP_CONFIG = {
|
|
|
22
22
|
configAsSrc: false,
|
|
23
23
|
ssr: false,
|
|
24
24
|
module: undefined,
|
|
25
|
+
preloadModules: [],
|
|
25
26
|
};
|
|
26
27
|
/**
|
|
27
28
|
* Turn the dots in a version into underscores
|
|
@@ -164,7 +165,7 @@ export function parsePackageSpecifier(specifier) {
|
|
|
164
165
|
* @param name A string in kebab case
|
|
165
166
|
* @example - 'name-of-something' => 'name/ofSomething'
|
|
166
167
|
*/
|
|
167
|
-
export function
|
|
168
|
+
export function kebabCaseToModuleSpecifier(name) {
|
|
168
169
|
const newName = [];
|
|
169
170
|
let nsFound = false;
|
|
170
171
|
let upper = false;
|
|
@@ -186,7 +187,7 @@ export function kebabCaseToModuleSpecifer(name) {
|
|
|
186
187
|
return newName.join('');
|
|
187
188
|
}
|
|
188
189
|
/**
|
|
189
|
-
* Clone of lwr/init, reverse of
|
|
190
|
+
* Clone of lwr/init, reverse of kebabCaseToModuleSpecifier, strips off versions
|
|
190
191
|
* @param specifier
|
|
191
192
|
* @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
|
|
192
193
|
*/
|
|
@@ -245,6 +246,9 @@ const REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
|
|
|
245
246
|
export function isExternalUrl(url) {
|
|
246
247
|
return REGEX_URL_SCHEMA_PREFIX.test(url);
|
|
247
248
|
}
|
|
249
|
+
export function isAssetSourceExternal(assetSource) {
|
|
250
|
+
return assetSource.type === 'external' || (!!assetSource.uri && isExternalUrl(assetSource.uri));
|
|
251
|
+
}
|
|
248
252
|
// type guard for ViewDef responses
|
|
249
253
|
export function isBundleDefinition(definition) {
|
|
250
254
|
return definition.bundleRecord !== undefined;
|
|
@@ -27,18 +27,24 @@ export class SiteMetadataImpl {
|
|
|
27
27
|
async persistSiteMetadata() {
|
|
28
28
|
// Create the metadata directory if if does not exist
|
|
29
29
|
const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
30
|
-
|
|
31
|
-
await fs.
|
|
30
|
+
try {
|
|
31
|
+
if (!(await fs.pathExists(siteMetadataPath))) {
|
|
32
|
+
await fs.mkdir(siteMetadataPath, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
// Save Bundle Metadata
|
|
35
|
+
const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
36
|
+
await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
|
|
37
|
+
// Save Resource Metadata
|
|
38
|
+
const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
39
|
+
await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
40
|
+
// Save Resource Metadata
|
|
41
|
+
const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
42
|
+
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
console.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
46
|
+
console.error(err);
|
|
32
47
|
}
|
|
33
|
-
// Save Bundle Metadata
|
|
34
|
-
const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
35
|
-
await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
|
|
36
|
-
// Save Resource Metadata
|
|
37
|
-
const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
38
|
-
await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
39
|
-
// Save Resource Metadata
|
|
40
|
-
const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
41
|
-
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
|
42
48
|
}
|
|
43
49
|
readStaticBundleMetadata(staticRoot) {
|
|
44
50
|
let bundleMetadataPath;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.28",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -61,13 +61,13 @@
|
|
|
61
61
|
"rollup": "~2.45.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@lwrjs/diagnostics": "0.9.0-alpha.
|
|
65
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
64
|
+
"@lwrjs/diagnostics": "0.9.0-alpha.28",
|
|
65
|
+
"@lwrjs/types": "0.9.0-alpha.28",
|
|
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 <20"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "da7d0c58d2e34958a289a18f43c5998e85e72986"
|
|
73
73
|
}
|