@lwrjs/shared-utils 0.10.0-alpha.12 → 0.10.0-alpha.14

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.
@@ -0,0 +1,28 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+
8
+ // packages/@lwrjs/shared-utils/src/bundle.ts
9
+ __markAsModule(exports);
10
+ __export(exports, {
11
+ getGroupName: () => getGroupName,
12
+ isGroupie: () => isGroupie
13
+ });
14
+ function getGroupName(rawSpecifier, groupsConfig) {
15
+ for (const [groupName, groupies] of Object.entries(groupsConfig)) {
16
+ if (groupies.indexOf(rawSpecifier) >= 0) {
17
+ return groupName;
18
+ }
19
+ }
20
+ }
21
+ function isGroupie(rawSpecifier, groupsConfig) {
22
+ for (const groupies of Object.values(groupsConfig)) {
23
+ if (groupies.indexOf(rawSpecifier) >= 0) {
24
+ return true;
25
+ }
26
+ }
27
+ return false;
28
+ }
package/build/cjs/env.cjs CHANGED
@@ -12,9 +12,10 @@ __export(exports, {
12
12
  });
13
13
  function getFeatureFlags() {
14
14
  return {
15
+ ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== void 0 && process.env.ASSETS_ON_LAMBDA.toLowerCase() === "true" ? true : false,
15
16
  LEGACY_LOADER: process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER.toLowerCase() === "true" ? true : false,
16
- SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.toLowerCase() === "true" ? true : false,
17
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
+ SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.toLowerCase() === "true" ? true : false,
19
+ UNVERSIONED_ALIASES: process.env.UNVERSIONED_ALIASES !== void 0 && process.env.UNVERSIONED_ALIASES.toLowerCase() === "true" ? true : false
19
20
  };
20
21
  }
package/build/cjs/fs.cjs CHANGED
@@ -32,7 +32,9 @@ __export(exports, {
32
32
  normalizeDirectory: () => normalizeDirectory,
33
33
  normalizeResourcePath: () => normalizeResourcePath,
34
34
  readFile: () => readFile,
35
- resolveFileExtension: () => resolveFileExtension
35
+ resolveFileExtension: () => resolveFileExtension,
36
+ streamToString: () => streamToString,
37
+ stringToStream: () => stringToStream
36
38
  });
37
39
  var import_fs = __toModule(require("fs"));
38
40
  var import_path = __toModule(require("path"));
@@ -40,6 +42,7 @@ var import_crypto = __toModule(require("crypto"));
40
42
  var import_identity = __toModule(require("./identity.cjs"));
41
43
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
42
44
  var import_mime_types = __toModule(require("mime-types"));
45
+ var import_stream = __toModule(require("stream"));
43
46
  var import_logger = __toModule(require("./logger.cjs"));
44
47
  var fileCount = 0;
45
48
  var files = new Map();
@@ -150,3 +153,32 @@ function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, basePath)
150
153
  }
151
154
  return specifier;
152
155
  }
156
+ function streamToString(stream, encoding = "utf8") {
157
+ const chunks = [];
158
+ return new Promise((resolve, reject) => {
159
+ stream.on("data", (c) => chunks.push(c));
160
+ stream.on("error", reject);
161
+ stream.on("end", () => resolve(Buffer.concat(chunks).toString(encoding)));
162
+ });
163
+ }
164
+ function stringToStream(str) {
165
+ let index = 0;
166
+ const isBuffer = Buffer.isBuffer(str);
167
+ const readable = new import_stream.Readable({
168
+ read(size) {
169
+ if (index >= str.length) {
170
+ this.push(null);
171
+ return;
172
+ }
173
+ let chunk;
174
+ if (isBuffer) {
175
+ chunk = str.subarray(index, index + size);
176
+ } else {
177
+ chunk = str.slice(index, index + size);
178
+ }
179
+ index += size;
180
+ this.push(chunk);
181
+ }
182
+ });
183
+ return readable;
184
+ }
@@ -24,7 +24,9 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/shared-utils/src/html-meta.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
+ HYDRATE_DIRECTIVE: () => HYDRATE_DIRECTIVE,
27
28
  extractMetadataFromHtml: () => extractMetadataFromHtml,
29
+ hasHydrateDirective: () => hasHydrateDirective,
28
30
  isRelative: () => isRelative,
29
31
  isSelfUrl: () => isSelfUrl
30
32
  });
@@ -117,3 +119,7 @@ async function extractMetadataFromHtml(htmlSource) {
117
119
  inputStream.pipe(parser);
118
120
  });
119
121
  }
122
+ var HYDRATE_DIRECTIVE = "lwr:hydrate";
123
+ function hasHydrateDirective(props = {}) {
124
+ return Object.keys(props).filter((propName) => propName === HYDRATE_DIRECTIVE).length > 0;
125
+ }
@@ -182,11 +182,11 @@ function slugify(name) {
182
182
  function getPropFromAttrName(propName) {
183
183
  return propName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
184
184
  }
185
- function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}) {
185
+ function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}, bundleId) {
186
186
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
187
187
  const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
188
188
  if (bundle) {
189
- return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/0/module/mi/`;
189
+ return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/${bundleId || "0"}/module/mi/`;
190
190
  } else {
191
191
  return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
192
192
  }
@@ -28,6 +28,7 @@ __export(exports, {
28
28
  getImportMetadata: () => getImportMetadata
29
29
  });
30
30
  var import_es_module_lexer = __toModule(require("es-module-lexer"));
31
+ var import_logger = __toModule(require("./logger.cjs"));
31
32
  var ModuleNameType;
32
33
  (function(ModuleNameType2) {
33
34
  ModuleNameType2["string"] = "string";
@@ -39,7 +40,8 @@ async function getImportMetadata(compiledSource) {
39
40
  const [moduleImportLocations] = await (0, import_es_module_lexer.parse)(compiledSource);
40
41
  for (const moduleImportLocation of moduleImportLocations) {
41
42
  let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
42
- const isDynamic = moduleImportLocation.d !== -1;
43
+ const isStatic = moduleImportLocation.d === -1;
44
+ const isDynamic = moduleImportLocation.d > -1;
43
45
  const location = {
44
46
  startColumn: moduleImportLocation.s,
45
47
  endColumn: moduleImportLocation.e
@@ -48,16 +50,19 @@ async function getImportMetadata(compiledSource) {
48
50
  const isStringLiteral = moduleSpecifier.startsWith("'") || moduleSpecifier.startsWith('"');
49
51
  const moduleNameType = isStringLiteral ? ModuleNameType.string : ModuleNameType.unresolved;
50
52
  moduleSpecifier = isStringLiteral ? moduleSpecifier.slice(1, -1) : moduleSpecifier;
53
+ if (import_logger.logger.currentLevel === import_logger.DEBUG || import_logger.logger.currentLevel === import_logger.VERBOSE) {
54
+ import_logger.logger.debug(`[import-metadata] Import from dynamic import ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.se)} -> ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.s)}`);
55
+ }
51
56
  dynamicImports.push({
52
57
  moduleSpecifier,
53
58
  moduleNameType,
54
59
  location,
55
60
  importLocation: {
56
- startColumn: moduleImportLocation.d,
61
+ startColumn: moduleImportLocation.ss,
57
62
  endColumn: moduleImportLocation.s
58
63
  }
59
64
  });
60
- } else {
65
+ } else if (isStatic) {
61
66
  imports.push({moduleSpecifier, location});
62
67
  }
63
68
  }
@@ -34,4 +34,4 @@ __exportStar(exports, __toModule(require("./urls.cjs")));
34
34
  __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
- __exportStar(exports, __toModule(require("./site-metadata.cjs")));
37
+ __exportStar(exports, __toModule(require("./bundle.cjs")));
@@ -0,0 +1,4 @@
1
+ import type { BundleGroups } from '@lwrjs/types';
2
+ export declare function getGroupName(rawSpecifier: string, groupsConfig: BundleGroups): string | undefined;
3
+ export declare function isGroupie(rawSpecifier: string, groupsConfig: BundleGroups): boolean;
4
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1,16 @@
1
+ export function getGroupName(rawSpecifier, groupsConfig) {
2
+ for (const [groupName, groupies] of Object.entries(groupsConfig)) {
3
+ if (groupies.indexOf(rawSpecifier) >= 0) {
4
+ return groupName;
5
+ }
6
+ }
7
+ }
8
+ export function isGroupie(rawSpecifier, groupsConfig) {
9
+ for (const groupies of Object.values(groupsConfig)) {
10
+ if (groupies.indexOf(rawSpecifier) >= 0) {
11
+ return true;
12
+ }
13
+ }
14
+ return false;
15
+ }
16
+ //# sourceMappingURL=bundle.js.map
package/build/es/env.js CHANGED
@@ -1,13 +1,13 @@
1
1
  export function getFeatureFlags() {
2
2
  // Add any new feature flags here to parse from environment variables
3
3
  return {
4
- // DEFAULT LEGACY_LOADER = false;
5
- LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER.toLowerCase() === 'true'
4
+ // Should we load load the assets from the lambda on MRT
5
+ ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== undefined &&
6
+ process.env.ASSETS_ON_LAMBDA.toLowerCase() === 'true'
6
7
  ? true
7
8
  : false,
8
- // SSR should concatenate bundles, default = false
9
- SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined &&
10
- process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
9
+ // DEFAULT LEGACY_LOADER = false;
10
+ LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER.toLowerCase() === 'true'
11
11
  ? true
12
12
  : false,
13
13
  // Should we use a js worker for SSR, sand-boxing = false (use locker for ssr sand-boxing)
@@ -15,9 +15,14 @@ export function getFeatureFlags() {
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'
18
+ // SSR should concatenate bundles, default = false
19
+ SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined &&
20
+ process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
21
+ ? true
22
+ : false,
23
+ // AMD Module Bundles include un-versioned aliases
24
+ UNVERSIONED_ALIASES: process.env.UNVERSIONED_ALIASES !== undefined &&
25
+ process.env.UNVERSIONED_ALIASES.toLowerCase() === 'true'
21
26
  ? true
22
27
  : false,
23
28
  };
package/build/es/fs.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { AssetIdentifier, ResourcePaths, ViewSource } from '@lwrjs/types';
3
3
  import { lookup } from 'mime-types';
4
+ import { Readable } from 'stream';
4
5
  /**
5
6
  * Create a hash string for a source
6
7
  * @param source
@@ -36,4 +37,6 @@ export { lookup as mimeLookup };
36
37
  * Tries to convert any URL or $aliased path into a canonical fs path
37
38
  */
38
39
  export declare function normalizeAssetSpecifier(assetId: AssetIdentifier, assetPathMap: Map<string, string>, resourcePaths: ResourcePaths, basePath: string): string;
40
+ export declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>;
41
+ export declare function stringToStream(str: string | Buffer): Readable;
39
42
  //# sourceMappingURL=fs.d.ts.map
package/build/es/fs.js CHANGED
@@ -4,6 +4,7 @@ import crypto from 'crypto';
4
4
  import { slugify } from './identity.js';
5
5
  import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
6
6
  import { lookup } from 'mime-types';
7
+ import { Readable } from 'stream';
7
8
  import { DEBUG, logger, VERBOSE } from './logger.js';
8
9
  let fileCount = 0;
9
10
  const files = new Map();
@@ -163,4 +164,34 @@ export function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, ba
163
164
  }
164
165
  return specifier;
165
166
  }
167
+ export function streamToString(stream, encoding = 'utf8') {
168
+ const chunks = [];
169
+ return new Promise((resolve, reject) => {
170
+ stream.on('data', (c) => chunks.push(c));
171
+ stream.on('error', reject);
172
+ stream.on('end', () => resolve(Buffer.concat(chunks).toString(encoding)));
173
+ });
174
+ }
175
+ export function stringToStream(str) {
176
+ let index = 0;
177
+ const isBuffer = Buffer.isBuffer(str);
178
+ const readable = new Readable({
179
+ read(size) {
180
+ if (index >= str.length) {
181
+ this.push(null);
182
+ return;
183
+ }
184
+ let chunk;
185
+ if (isBuffer) {
186
+ chunk = str.subarray(index, index + size);
187
+ }
188
+ else {
189
+ chunk = str.slice(index, index + size);
190
+ }
191
+ index += size;
192
+ this.push(chunk);
193
+ },
194
+ });
195
+ return readable;
196
+ }
166
197
  //# sourceMappingURL=fs.js.map
@@ -6,4 +6,6 @@ export declare function isSelfUrl(url: string): boolean;
6
6
  * @param htmlSource - An HTML string to parse
7
7
  */
8
8
  export declare function extractMetadataFromHtml(htmlSource: string): Promise<RenderedViewMetadata>;
9
+ export declare const HYDRATE_DIRECTIVE = "lwr:hydrate";
10
+ export declare function hasHydrateDirective(props?: {}): boolean;
9
11
  //# sourceMappingURL=html-meta.d.ts.map
@@ -105,4 +105,8 @@ export async function extractMetadataFromHtml(htmlSource) {
105
105
  inputStream.pipe(parser);
106
106
  });
107
107
  }
108
+ export const HYDRATE_DIRECTIVE = 'lwr:hydrate';
109
+ export function hasHydrateDirective(props = {}) {
110
+ return Object.keys(props).filter((propName) => propName === HYDRATE_DIRECTIVE).length > 0;
111
+ }
108
112
  //# sourceMappingURL=html-meta.js.map
@@ -15,7 +15,7 @@ export declare const DEFAULT_LWR_LOCKER_CONFIG: {
15
15
  trustedComponents: string[];
16
16
  };
17
17
  export declare const DEFAULT_LWR_BOOTSTRAP_CONFIG: NormalizedLwrAppBootstrapConfig;
18
- type ModuleIdentifierPartial = Partial<AbstractModuleId>;
18
+ declare type ModuleIdentifierPartial = Partial<AbstractModuleId>;
19
19
  /**
20
20
  * Turn the dots in a version into underscores
21
21
  * @param version
@@ -129,7 +129,7 @@ export declare function getPropFromAttrName(propName: string): string;
129
129
  * @param param0 - URI props from the Runtime Environment
130
130
  * @param param1 - URI props from the Runtime Params
131
131
  */
132
- export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams): string;
132
+ export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams, bundleId?: string): string;
133
133
  /**
134
134
  * Create a URI Mapping API URI prefix, stopping where the specifiers would be (at "mp/")
135
135
  * @param param0 - URI props from the Runtime Environment
@@ -221,11 +221,11 @@ export function getPropFromAttrName(propName) {
221
221
  * @param param0 - URI props from the Runtime Environment
222
222
  * @param param1 - URI props from the Runtime Params
223
223
  */
224
- export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}) {
224
+ export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}, bundleId) {
225
225
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
226
226
  const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : '';
227
227
  if (bundle) {
228
- return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/0/module/mi/`;
228
+ return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/${bundleId || '0'}/module/mi/`;
229
229
  }
230
230
  else {
231
231
  return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
@@ -1,4 +1,4 @@
1
- import { CompiledMetadata } from '@lwrjs/types';
1
+ import type { CompiledMetadata } from '@lwrjs/types';
2
2
  export declare enum ModuleNameType {
3
3
  string = "string",
4
4
  unresolved = "unresolved"
@@ -1,4 +1,5 @@
1
1
  import { parse as parseImports } from 'es-module-lexer';
2
+ import { DEBUG, logger, VERBOSE } from './logger.js';
2
3
  export var ModuleNameType;
3
4
  (function (ModuleNameType) {
4
5
  ModuleNameType["string"] = "string";
@@ -12,7 +13,8 @@ export async function getImportMetadata(compiledSource) {
12
13
  for (const moduleImportLocation of moduleImportLocations) {
13
14
  // This will give us the source specifier of the import (ex. import x from "bar" <= will get us bar)
14
15
  let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
15
- const isDynamic = moduleImportLocation.d !== -1;
16
+ const isStatic = moduleImportLocation.d === -1;
17
+ const isDynamic = moduleImportLocation.d > -1;
16
18
  const location = {
17
19
  startColumn: moduleImportLocation.s,
18
20
  endColumn: moduleImportLocation.e,
@@ -21,17 +23,21 @@ export async function getImportMetadata(compiledSource) {
21
23
  const isStringLiteral = moduleSpecifier.startsWith("'") || moduleSpecifier.startsWith('"');
22
24
  const moduleNameType = isStringLiteral ? ModuleNameType.string : ModuleNameType.unresolved;
23
25
  moduleSpecifier = isStringLiteral ? moduleSpecifier.slice(1, -1) : moduleSpecifier; // remove quotes
26
+ // Expecting: import(rootSpecifier) -> import(
27
+ if (logger.currentLevel === DEBUG || logger.currentLevel === VERBOSE) {
28
+ logger.debug(`[import-metadata] Import from dynamic import ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.se)} -> ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.s)}`);
29
+ }
24
30
  dynamicImports.push({
25
31
  moduleSpecifier,
26
32
  moduleNameType,
27
33
  location,
28
34
  importLocation: {
29
- startColumn: moduleImportLocation.d,
35
+ startColumn: moduleImportLocation.ss,
30
36
  endColumn: moduleImportLocation.s,
31
37
  },
32
38
  });
33
39
  }
34
- else {
40
+ else if (isStatic) {
35
41
  imports.push({ moduleSpecifier, location });
36
42
  }
37
43
  }
@@ -13,5 +13,5 @@ export * from './urls.js';
13
13
  export * from './env.js';
14
14
  export * from './logger.js';
15
15
  export * from './lwr-app-observer.js';
16
- export * from './site-metadata.js';
16
+ export * from './bundle.js';
17
17
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -13,5 +13,5 @@ export * from './urls.js';
13
13
  export * from './env.js';
14
14
  export * from './logger.js';
15
15
  export * from './lwr-app-observer.js';
16
- export * from './site-metadata.js';
16
+ export * from './bundle.js';
17
17
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,10 @@
1
- type LEVEL = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
1
+ declare type LEVEL = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
2
2
  export declare const VERBOSE: LEVEL;
3
3
  export declare const DEBUG: LEVEL;
4
4
  export declare const INFO: LEVEL;
5
5
  export declare const WARN: LEVEL;
6
6
  export declare const ERROR: LEVEL;
7
- type LoggerOptions = {
7
+ declare type LoggerOptions = {
8
8
  dedupe?: Set<string>;
9
9
  };
10
10
  declare function log(level: string, message: string, additionalInfo?: any): void;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.10.0-alpha.12",
7
+ "version": "0.10.0-alpha.14",
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": "^0.3.18",
48
+ "es-module-lexer": "^1.2.1",
49
49
  "fast-json-stable-stringify": "^2.1.0",
50
50
  "magic-string": "^0.30.0",
51
51
  "mime-types": "^2.1.33",
@@ -56,19 +56,19 @@
56
56
  "slugify": "^1.4.5"
57
57
  },
58
58
  "peerDependencies": {
59
- "@locker/compiler": "0.19.0",
59
+ "@locker/compiler": "0.19.5",
60
60
  "chokidar": "^3.5.3",
61
61
  "esbuild": "^0.9.7",
62
62
  "rollup": "^2.78.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@lwrjs/diagnostics": "0.10.0-alpha.12",
66
- "@lwrjs/types": "0.10.0-alpha.12",
65
+ "@lwrjs/diagnostics": "0.10.0-alpha.14",
66
+ "@lwrjs/types": "0.10.0-alpha.14",
67
67
  "@types/mime-types": "2.1.1",
68
68
  "@types/path-to-regexp": "^1.7.0"
69
69
  },
70
70
  "engines": {
71
71
  "node": ">=16.0.0 <20"
72
72
  },
73
- "gitHead": "c280f6e4914d67a58cb18a52d2320824c8ed4a7b"
73
+ "gitHead": "f80dc1c18719b77c183f339027313be11d69f9dc"
74
74
  }
@@ -1,121 +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/site-metadata.ts
25
- __markAsModule(exports);
26
- __export(exports, {
27
- SiteMetadataImpl: () => SiteMetadataImpl
28
- });
29
- var import_path = __toModule(require("path"));
30
- var import_fs_extra = __toModule(require("fs-extra"));
31
- var import_logger = __toModule(require("./logger.cjs"));
32
- var SITE_METADATA_PATH = ".metadata";
33
- var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
34
- var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
35
- var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
36
- var SiteMetadataImpl = class {
37
- constructor(options) {
38
- this.options = options;
39
- this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
40
- this.siteResources = this.readStaticResourceMetadata(options.rootDir);
41
- this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
42
- }
43
- getSiteRootDir() {
44
- return this.options.rootDir;
45
- }
46
- getSiteBundles() {
47
- return this.siteBundles;
48
- }
49
- getSiteResources() {
50
- return this.siteResources;
51
- }
52
- getSiteAssets() {
53
- return this.siteAssets;
54
- }
55
- async persistSiteMetadata() {
56
- const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
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);
70
- }
71
- }
72
- readStaticBundleMetadata(staticRoot) {
73
- let bundleMetadataPath;
74
- let siteBundles = {bundles: {}};
75
- try {
76
- bundleMetadataPath = import_path.default.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
77
- const savedMetadata = import_fs_extra.default.readJSONSync(bundleMetadataPath);
78
- siteBundles = savedMetadata;
79
- } catch (error) {
80
- if (error.code === "ENOENT") {
81
- import_logger.logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
82
- } else {
83
- throw error;
84
- }
85
- }
86
- return siteBundles;
87
- }
88
- readStaticResourceMetadata(staticRoot) {
89
- let resourceMetadataPath;
90
- let siteResources = {resources: {}};
91
- try {
92
- resourceMetadataPath = import_path.default.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
93
- const savedMetadata = import_fs_extra.default.readJSONSync(resourceMetadataPath);
94
- siteResources = savedMetadata;
95
- } catch (error) {
96
- if (error.code === "ENOENT") {
97
- import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
98
- } else {
99
- throw error;
100
- }
101
- }
102
- return siteResources;
103
- }
104
- readStaticAssetsMetadata(staticRoot) {
105
- let assetMetadataPath;
106
- let siteAssets = {
107
- assets: {}
108
- };
109
- try {
110
- assetMetadataPath = import_path.default.join(staticRoot, STATIC_ASSET_METADATA_PATH);
111
- siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
112
- } catch (error) {
113
- if (error.code === "ENOENT") {
114
- import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
115
- } else {
116
- throw error;
117
- }
118
- }
119
- return siteAssets;
120
- }
121
- };
@@ -1,27 +0,0 @@
1
- import type { SiteAssets, SiteBundles, SiteMetadata, SiteResources } from '@lwrjs/types';
2
- type Options = {
3
- rootDir: string;
4
- };
5
- export declare class SiteMetadataImpl implements SiteMetadata {
6
- private options;
7
- private siteBundles;
8
- private siteResources;
9
- private siteAssets;
10
- constructor(options: Options);
11
- getSiteRootDir(): string;
12
- getSiteBundles(): SiteBundles;
13
- getSiteResources(): SiteResources;
14
- getSiteAssets(): SiteAssets;
15
- persistSiteMetadata(): Promise<void>;
16
- private readStaticBundleMetadata;
17
- /**
18
- * Read the metadata about the pre-built resources of the current site.
19
- */
20
- private readStaticResourceMetadata;
21
- /**
22
- * Read the metadata about the pre-built assets of the current site.
23
- */
24
- private readStaticAssetsMetadata;
25
- }
26
- export {};
27
- //# sourceMappingURL=site-metadata.d.ts.map
@@ -1,111 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import { logger } from './logger.js';
4
- const SITE_METADATA_PATH = '.metadata';
5
- const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
6
- const STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata.json');
7
- const STATIC_ASSET_METADATA_PATH = path.join(SITE_METADATA_PATH, '/asset-metadata.json');
8
- export class SiteMetadataImpl {
9
- constructor(options) {
10
- this.options = options;
11
- this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
12
- this.siteResources = this.readStaticResourceMetadata(options.rootDir);
13
- this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
14
- }
15
- getSiteRootDir() {
16
- return this.options.rootDir;
17
- }
18
- getSiteBundles() {
19
- return this.siteBundles;
20
- }
21
- getSiteResources() {
22
- return this.siteResources;
23
- }
24
- getSiteAssets() {
25
- return this.siteAssets;
26
- }
27
- async persistSiteMetadata() {
28
- // Create the metadata directory if if does not exist
29
- const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
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);
47
- }
48
- }
49
- readStaticBundleMetadata(staticRoot) {
50
- let bundleMetadataPath;
51
- let siteBundles = { bundles: {} };
52
- try {
53
- bundleMetadataPath = path.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
54
- const savedMetadata = fs.readJSONSync(bundleMetadataPath);
55
- siteBundles = savedMetadata;
56
- }
57
- catch (error) {
58
- if (error.code === 'ENOENT') {
59
- logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
60
- }
61
- else {
62
- throw error;
63
- }
64
- }
65
- return siteBundles;
66
- }
67
- /**
68
- * Read the metadata about the pre-built resources of the current site.
69
- */
70
- readStaticResourceMetadata(staticRoot) {
71
- let resourceMetadataPath;
72
- let siteResources = { resources: {} };
73
- try {
74
- resourceMetadataPath = path.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
75
- const savedMetadata = fs.readJSONSync(resourceMetadataPath);
76
- siteResources = savedMetadata;
77
- }
78
- catch (error) {
79
- if (error.code === 'ENOENT') {
80
- logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
81
- }
82
- else {
83
- throw error;
84
- }
85
- }
86
- return siteResources;
87
- }
88
- /**
89
- * Read the metadata about the pre-built assets of the current site.
90
- */
91
- readStaticAssetsMetadata(staticRoot) {
92
- let assetMetadataPath;
93
- let siteAssets = {
94
- assets: {},
95
- };
96
- try {
97
- assetMetadataPath = path.join(staticRoot, STATIC_ASSET_METADATA_PATH);
98
- siteAssets = fs.readJSONSync(assetMetadataPath);
99
- }
100
- catch (error) {
101
- if (error.code === 'ENOENT') {
102
- logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
103
- }
104
- else {
105
- throw error;
106
- }
107
- }
108
- return siteAssets;
109
- }
110
- }
111
- //# sourceMappingURL=site-metadata.js.map