@lwrjs/shared-utils 0.9.0-alpha.24 → 0.9.0-alpha.27

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 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
+ }
@@ -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
- kebabCaseToModuleSpecifer: () => kebabCaseToModuleSpecifer,
49
+ kebabCaseToModuleSpecifier: () => kebabCaseToModuleSpecifier,
49
50
  moduleSpecifierToKebabCase: () => moduleSpecifierToKebabCase,
50
51
  normalizeVersionFromUri: () => normalizeVersionFromUri,
51
52
  normalizeVersionToUri: () => normalizeVersionToUri,
@@ -148,7 +149,7 @@ function parsePackageSpecifier(specifier) {
148
149
  subResource: matched[2] || ""
149
150
  };
150
151
  }
151
- function kebabCaseToModuleSpecifer(name) {
152
+ function kebabCaseToModuleSpecifier(name) {
152
153
  const newName = [];
153
154
  let nsFound = false;
154
155
  let upper = false;
@@ -197,6 +198,9 @@ var REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
197
198
  function isExternalUrl(url) {
198
199
  return REGEX_URL_SCHEMA_PREFIX.test(url);
199
200
  }
201
+ function isAssetSourceExternal(assetSource) {
202
+ return assetSource.type === "external" || !!assetSource.uri && isExternalUrl(assetSource.uri);
203
+ }
200
204
  function isBundleDefinition(definition) {
201
205
  return definition.bundleRecord !== void 0;
202
206
  }
@@ -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
- if (!await import_fs_extra.default.pathExists(siteMetadataPath)) {
58
- await import_fs_extra.default.mkdir(siteMetadataPath, {recursive: true});
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, sandboxing = false (use locker for ssr sandboxing)
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; // extensionless file, which is odd but...
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 tesing the extensions
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
@@ -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 kebabCaseToModuleSpecifer(name: string): string;
107
+ export declare function kebabCaseToModuleSpecifier(name: string): string;
108
108
  /**
109
- * Clone of lwr/init, reverse of kebabCaseToModuleSpecifer, strips off versions
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
@@ -164,7 +164,7 @@ export function parsePackageSpecifier(specifier) {
164
164
  * @param name A string in kebab case
165
165
  * @example - 'name-of-something' => 'name/ofSomething'
166
166
  */
167
- export function kebabCaseToModuleSpecifer(name) {
167
+ export function kebabCaseToModuleSpecifier(name) {
168
168
  const newName = [];
169
169
  let nsFound = false;
170
170
  let upper = false;
@@ -186,7 +186,7 @@ export function kebabCaseToModuleSpecifer(name) {
186
186
  return newName.join('');
187
187
  }
188
188
  /**
189
- * Clone of lwr/init, reverse of kebabCaseToModuleSpecifer, strips off versions
189
+ * Clone of lwr/init, reverse of kebabCaseToModuleSpecifier, strips off versions
190
190
  * @param specifier
191
191
  * @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
192
192
  */
@@ -245,6 +245,9 @@ const REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
245
245
  export function isExternalUrl(url) {
246
246
  return REGEX_URL_SCHEMA_PREFIX.test(url);
247
247
  }
248
+ export function isAssetSourceExternal(assetSource) {
249
+ return assetSource.type === 'external' || (!!assetSource.uri && isExternalUrl(assetSource.uri));
250
+ }
248
251
  // type guard for ViewDef responses
249
252
  export function isBundleDefinition(definition) {
250
253
  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
- if (!(await fs.pathExists(siteMetadataPath))) {
31
- await fs.mkdir(siteMetadataPath, { recursive: true });
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.24",
7
+ "version": "0.9.0-alpha.27",
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.24",
65
- "@lwrjs/types": "0.9.0-alpha.24",
64
+ "@lwrjs/diagnostics": "0.9.0-alpha.27",
65
+ "@lwrjs/types": "0.9.0-alpha.27",
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": "94326d9e8c80254cfab9c17b2235b10fdee13b4d"
72
+ "gitHead": "a7fcd8493b8a3286197e829b28b54670e7d4e97c"
73
73
  }