@lwrjs/shared-utils 0.13.0-alpha.3 → 0.13.0-alpha.30

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
@@ -12,8 +12,13 @@ __export(exports, {
12
12
  REQUEST_DEPTH_KEY: () => REQUEST_DEPTH_KEY,
13
13
  buildEnvironmentContext: () => buildEnvironmentContext,
14
14
  getFeatureFlags: () => getFeatureFlags,
15
+ isLambdaEnv: () => isLambdaEnv,
16
+ isLocalDev: () => isLocalDev,
15
17
  parseRequestDepthHeader: () => parseRequestDepthHeader
16
18
  });
19
+ if (getFeatureFlags().REEVALUATE_MODULES && !getFeatureFlags().LEGACY_LOADER) {
20
+ throw new Error("REEVALUATE_MODULES is only supported with LEGACY_LOADER");
21
+ }
17
22
  function getFeatureFlags() {
18
23
  return {
19
24
  ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== void 0 && process.env.ASSETS_ON_LAMBDA.toLowerCase() === "true" ? true : false,
@@ -21,9 +26,19 @@ function getFeatureFlags() {
21
26
  SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.toLowerCase() === "true" ? true : false,
22
27
  SSR_WITH_CSR_FALLBACK: process.env.SSR_WITH_CSR_FALLBACK !== void 0 && process.env.SSR_WITH_CSR_FALLBACK.toLowerCase() === "true" ? true : false,
23
28
  EXPERIMENTAL_UNVERSIONED_ALIASES: process.env.EXPERIMENTAL_UNVERSIONED_ALIASES !== void 0 && process.env.EXPERIMENTAL_UNVERSIONED_ALIASES.toLowerCase() === "true" ? true : false,
24
- LWR_TRACING: process.env.LWR_TRACING !== void 0 && process.env.LWR_TRACING.toLowerCase() !== "off" ? process.env.LWR_TRACING : false
29
+ LWR_TRACING: process.env.LWR_TRACING !== void 0 && process.env.LWR_TRACING.toLowerCase() !== "off" ? process.env.LWR_TRACING : false,
30
+ ENABLE_NONCE: process.env.ENABLE_NONCE !== void 0 && process.env.ENABLE_NONCE.toLowerCase() === "true" ? true : false,
31
+ SINGLE_RENDER_MODE: process.env.SINGLE_RENDER_MODE !== void 0 && process.env.SINGLE_RENDER_MODE.toLowerCase() === "true" ? true : false,
32
+ REEVALUATE_MODULES: process.env.REEVALUATE_MODULES !== void 0 && process.env.REEVALUATE_MODULES.toLowerCase() === "true" ? true : false,
33
+ MAX_VIEW_CACHE_TTL: process.env.MAX_VIEW_CACHE_TTL
25
34
  };
26
35
  }
36
+ function isLambdaEnv() {
37
+ return process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0;
38
+ }
39
+ function isLocalDev() {
40
+ return process.env.MRT_HMR === "true";
41
+ }
27
42
  function buildEnvironmentContext(runtimeParams) {
28
43
  const basePath = runtimeParams.basePath;
29
44
  const locale = runtimeParams.locale;
package/build/cjs/fs.cjs CHANGED
@@ -28,6 +28,7 @@ __export(exports, {
28
28
  PROTOCOL_HTTP: () => PROTOCOL_HTTP,
29
29
  PROTOCOL_HTTPS: () => PROTOCOL_HTTPS,
30
30
  canResolveView: () => canResolveView,
31
+ createIntegrityHash: () => createIntegrityHash,
31
32
  filterProtocolEntries: () => filterProtocolEntries,
32
33
  getViewSourceFromFile: () => getViewSourceFromFile,
33
34
  hashContent: () => hashContent,
@@ -60,6 +61,10 @@ var PROTOCOL_FILE = "file://";
60
61
  function hashContent(source) {
61
62
  return import_crypto.default.createHash("md5").update(source).digest("hex");
62
63
  }
64
+ function createIntegrityHash(source) {
65
+ const hash = import_crypto.default.createHash("sha256").update(source).digest("base64");
66
+ return `sha256-${hash}`;
67
+ }
63
68
  function readFile(filePath) {
64
69
  logMetrics(filePath);
65
70
  return import_fs_extra.default.readFileSync(filePath, "utf8");
@@ -27,7 +27,6 @@ __export(exports, {
27
27
  ASSETS_CACHE_DIR: () => ASSETS_CACHE_DIR,
28
28
  BUNDLE_SIGIL: () => BUNDLE_SIGIL,
29
29
  DEFAULT_LOCKER_TRUSTED_CMP: () => DEFAULT_LOCKER_TRUSTED_CMP,
30
- DEFAULT_LWR_BOOTSTRAP_CONFIG: () => DEFAULT_LWR_BOOTSTRAP_CONFIG,
31
30
  DEFAULT_LWR_LOCKER_CONFIG: () => DEFAULT_LWR_LOCKER_CONFIG,
32
31
  DEFAULT_TITLE: () => DEFAULT_TITLE,
33
32
  ENVIRONMENT_SIGIL: () => ENVIRONMENT_SIGIL,
@@ -35,10 +34,12 @@ __export(exports, {
35
34
  LATEST_SIGNATURE: () => LATEST_SIGNATURE,
36
35
  LOCALE_SIGIL: () => LOCALE_SIGIL,
37
36
  VERSION_NOT_PROVIDED: () => VERSION_NOT_PROVIDED,
37
+ VERSION_PREFIX: () => VERSION_PREFIX,
38
38
  VERSION_SIGIL: () => VERSION_SIGIL,
39
39
  explodeSpecifier: () => explodeSpecifier,
40
40
  explodeSpecifiers: () => explodeSpecifiers,
41
41
  getCacheKeyFromJson: () => import_fast_json_stable_stringify.default,
42
+ getLocalDevOverrideUrl: () => getLocalDevOverrideUrl,
42
43
  getMappingUriPrefix: () => getMappingUriPrefix,
43
44
  getModuleUriPrefix: () => getModuleUriPrefix,
44
45
  getPropFromAttrName: () => getPropFromAttrName,
@@ -57,9 +58,11 @@ __export(exports, {
57
58
  slugify: () => slugify,
58
59
  stringToVariableName: () => stringToVariableName
59
60
  });
61
+ var import_path = __toModule(require("path"));
60
62
  var import_slugify = __toModule(require("slugify"));
61
63
  var import_fast_json_stable_stringify = __toModule(require("fast-json-stable-stringify"));
62
- var VERSION_SIGIL = "/v/";
64
+ var VERSION_SIGIL = "v";
65
+ var VERSION_PREFIX = `/${VERSION_SIGIL}/`;
63
66
  var LOCALE_SIGIL = "l";
64
67
  var ENVIRONMENT_SIGIL = "e";
65
68
  var BUNDLE_SIGIL = "bi";
@@ -73,18 +76,6 @@ var DEFAULT_LWR_LOCKER_CONFIG = {
73
76
  enabled: false,
74
77
  trustedComponents: DEFAULT_LOCKER_TRUSTED_CMP
75
78
  };
76
- var DEFAULT_LWR_BOOTSTRAP_CONFIG = {
77
- autoBoot: true,
78
- syntheticShadow: false,
79
- workers: {},
80
- services: [],
81
- configAsSrc: false,
82
- ssr: false,
83
- preloadData: false,
84
- mixedMode: false,
85
- module: void 0,
86
- preloadModules: []
87
- };
88
79
  function normalizeVersionToUri(version) {
89
80
  return version.replace(/\./g, "_");
90
81
  }
@@ -122,10 +113,10 @@ function getSpecifier({specifier, namespace, name = "", version}) {
122
113
  if (specifier) {
123
114
  const versionMatch = specifier.match(/(.+)\/v\/[a-zA-Z0-9-_.]+$/);
124
115
  specifier = versionMatch ? versionMatch[1] : specifier;
125
- return version && version !== VERSION_NOT_PROVIDED ? `${specifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}` : specifier;
116
+ return version && version !== VERSION_NOT_PROVIDED ? `${specifier}${VERSION_PREFIX}${normalizeVersionToUri(version)}` : specifier;
126
117
  }
127
118
  const bareSpecifier = namespace ? `${namespace}/${name}` : name;
128
- return version && version !== VERSION_NOT_PROVIDED ? `${bareSpecifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}` : bareSpecifier;
119
+ return version && version !== VERSION_NOT_PROVIDED ? `${bareSpecifier}${VERSION_PREFIX}${normalizeVersionToUri(version)}` : bareSpecifier;
129
120
  }
130
121
  async function getVersionedModuleId(rawSpecifier, moduleRegistry, runtimeParams) {
131
122
  const moduleId = explodeSpecifier(rawSpecifier);
@@ -221,3 +212,10 @@ function stringToVariableName(inputString) {
221
212
  }
222
213
  return cleanedString;
223
214
  }
215
+ function getLocalDevOverrideUrl(cacheDir, specifier, filepath) {
216
+ if (!specifier.startsWith("@view"))
217
+ return filepath;
218
+ const dirname = import_path.default.basename(import_path.default.dirname(filepath));
219
+ const fileName = specifier.split("@view/")[1] + "_view.js";
220
+ return import_path.default.join(cacheDir, "overrides", dirname, fileName);
221
+ }
@@ -35,3 +35,4 @@ __exportStar(exports, __toModule(require("./env.cjs")));
35
35
  __exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
36
36
  __exportStar(exports, __toModule(require("./bundle.cjs")));
37
37
  __exportStar(exports, __toModule(require("./localization.cjs")));
38
+ __exportStar(exports, __toModule(require("./launch.cjs")));
@@ -0,0 +1,43 @@
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/launch.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ launch: () => launch
28
+ });
29
+ var import_os = __toModule(require("os"));
30
+ async function launch(port, https) {
31
+ const {exec} = await Promise.resolve().then(() => __toModule(require("child_process")));
32
+ let cmd = "open";
33
+ if (process.platform == "win32") {
34
+ cmd = "start";
35
+ } else if (process.platform == "linux") {
36
+ if (/microsoft/i.test((0, import_os.release)())) {
37
+ cmd = "cmd.exe /c start";
38
+ } else {
39
+ cmd = "xdg-open";
40
+ }
41
+ }
42
+ exec(`${cmd} ${https ? "https" : "http"}://localhost:${port}`);
43
+ }
@@ -62,8 +62,8 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
62
62
  }
63
63
  async function toImportMetadata(moduleGraph, existingImportMetadata = {imports: {}, index: {}}, moduleRegistry, runtimeEnvironment, runtimeParams = {}) {
64
64
  const specifier = moduleGraph.graphs[0].specifier;
65
- const uri = moduleGraph.uriMap[specifier];
66
- const definition = moduleGraph.linkedDefinitions[specifier];
65
+ const uri = lookupValueIgnoringVersion(moduleGraph.uriMap, specifier);
66
+ const definition = lookupValueIgnoringVersion(moduleGraph.linkedDefinitions, specifier);
67
67
  if (!uri) {
68
68
  throw new Error("URI was not included in the graph: " + specifier);
69
69
  }
@@ -83,8 +83,8 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
83
83
  if (isExternalSpecifier(depSpecifier, moduleRegistry.getConfig().bundleConfig)) {
84
84
  continue;
85
85
  }
86
- const depUri = moduleGraph.uriMap[depSpecifier];
87
- const depDef = moduleGraph.linkedDefinitions[depSpecifier];
86
+ const depUri = lookupValueIgnoringVersion(moduleGraph.uriMap, depSpecifier);
87
+ const depDef = lookupValueIgnoringVersion(moduleGraph.linkedDefinitions, depSpecifier);
88
88
  const depMissing = !depUri || !depDef;
89
89
  if (depMissing && runtimeEnvironment.format !== "esm") {
90
90
  if (!depUri) {
@@ -106,6 +106,18 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
106
106
  }
107
107
  return importMetadata;
108
108
  }
109
+ function lookupValueIgnoringVersion(map, specifier) {
110
+ const val = map[specifier];
111
+ if (val) {
112
+ return val;
113
+ }
114
+ const cleanedKey = (0, import_identity.explodeSpecifier)(specifier).specifier;
115
+ for (const mapKey of Object.keys(map)) {
116
+ if ((0, import_identity.explodeSpecifier)(mapKey).specifier === cleanedKey) {
117
+ return map[mapKey];
118
+ }
119
+ }
120
+ }
109
121
  function mergeImportMetadata(existing, newMetadata) {
110
122
  return {
111
123
  imports: {
@@ -66,14 +66,21 @@ async function serializeModuleToJson(code = "", {
66
66
  function replaceStringFromLocation(src, {startOffset, endOffset}, replaceValue) {
67
67
  return src.substr(0, startOffset) + replaceValue + src.substr(endOffset, src.length);
68
68
  }
69
- function shortestTtl(newTtl, oldTtl) {
69
+ function shortestTtl(newTtl, oldTtl, maxTtl) {
70
70
  if (newTtl === void 0 && oldTtl === void 0)
71
71
  return void 0;
72
72
  const newSeconds = typeof newTtl === "string" ? (0, import_ms.default)(newTtl) / 1e3 : newTtl;
73
73
  const oldSeconds = typeof oldTtl === "string" ? (0, import_ms.default)(oldTtl) / 1e3 : oldTtl;
74
- if (newSeconds === void 0)
75
- return oldSeconds;
76
- if (oldSeconds === void 0)
77
- return newSeconds;
78
- return newSeconds < oldSeconds ? newSeconds : oldSeconds;
74
+ const maxSeconds = typeof maxTtl === "string" ? (0, import_ms.default)(maxTtl) / 1e3 : maxTtl;
75
+ let shortest = void 0;
76
+ if (newSeconds !== void 0 && (shortest === void 0 || newSeconds < shortest)) {
77
+ shortest = newSeconds;
78
+ }
79
+ if (oldSeconds !== void 0 && (shortest === void 0 || oldSeconds < shortest)) {
80
+ shortest = oldSeconds;
81
+ }
82
+ if (maxSeconds !== void 0 && (shortest === void 0 || maxSeconds < shortest)) {
83
+ shortest = maxSeconds;
84
+ }
85
+ return shortest;
79
86
  }
package/build/es/env.d.ts CHANGED
@@ -1,7 +1,19 @@
1
1
  import type { EnvironmentContext, FeatureFlags, Headers, RuntimeParams } from '@lwrjs/types';
2
2
  export declare function getFeatureFlags(): FeatureFlags;
3
3
  /**
4
- * Create a serializable context for the lwr/environment variable
4
+ * This function is used to determine if the current environment is a lambda.
5
+ *
6
+ * @returns true if process is running in lambda environment
7
+ */
8
+ export declare function isLambdaEnv(): boolean;
9
+ /**
10
+ * This function is used to determine if lwr is running in the context of local development.
11
+ *
12
+ * @returns true if running in localdev mode
13
+ */
14
+ export declare function isLocalDev(): boolean;
15
+ /**
16
+ * Create a serializable context for user-land exposed environment variables
5
17
  */
6
18
  export declare function buildEnvironmentContext(runtimeParams: RuntimeParams): EnvironmentContext;
7
19
  export declare const REQUEST_DEPTH_HEADER = "X-SFDC-Request-Depth";
package/build/es/env.js CHANGED
@@ -1,3 +1,6 @@
1
+ if (getFeatureFlags().REEVALUATE_MODULES && !getFeatureFlags().LEGACY_LOADER) {
2
+ throw new Error('REEVALUATE_MODULES is only supported with LEGACY_LOADER');
3
+ }
1
4
  export function getFeatureFlags() {
2
5
  // Add any new feature flags here to parse from environment variables
3
6
  return {
@@ -28,10 +31,41 @@ export function getFeatureFlags() {
28
31
  LWR_TRACING: process.env.LWR_TRACING !== undefined && process.env.LWR_TRACING.toLowerCase() !== 'off'
29
32
  ? process.env.LWR_TRACING
30
33
  : false,
34
+ ENABLE_NONCE: process.env.ENABLE_NONCE !== undefined && process.env.ENABLE_NONCE.toLowerCase() === 'true'
35
+ ? true
36
+ : false,
37
+ // Forces SSR rendering to render only one page at a time
38
+ SINGLE_RENDER_MODE: process.env.SINGLE_RENDER_MODE !== undefined &&
39
+ process.env.SINGLE_RENDER_MODE.toLowerCase() === 'true'
40
+ ? true
41
+ : false,
42
+ // Forces SSR to re-evaluate modules for every page render. By default, modules are evaluated only once.
43
+ REEVALUATE_MODULES: process.env.REEVALUATE_MODULES !== undefined &&
44
+ process.env.REEVALUATE_MODULES.toLowerCase() === 'true'
45
+ ? true
46
+ : false,
47
+ MAX_VIEW_CACHE_TTL: process.env.MAX_VIEW_CACHE_TTL,
31
48
  };
32
49
  }
33
50
  /**
34
- * Create a serializable context for the lwr/environment variable
51
+ * This function is used to determine if the current environment is a lambda.
52
+ *
53
+ * @returns true if process is running in lambda environment
54
+ */
55
+ export function isLambdaEnv() {
56
+ return process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined;
57
+ }
58
+ /**
59
+ * This function is used to determine if lwr is running in the context of local development.
60
+ *
61
+ * @returns true if running in localdev mode
62
+ */
63
+ export function isLocalDev() {
64
+ // TODO still need to formalize environment variable names
65
+ return process.env.MRT_HMR === 'true';
66
+ }
67
+ /**
68
+ * Create a serializable context for user-land exposed environment variables
35
69
  */
36
70
  export function buildEnvironmentContext(runtimeParams) {
37
71
  // The baseBath from the config or set from the request (e.g. /shop)
package/build/es/fs.d.ts CHANGED
@@ -11,6 +11,10 @@ export declare const PROTOCOL_FILE = "file://";
11
11
  * @param source
12
12
  */
13
13
  export declare function hashContent(source: string | Buffer): string;
14
+ /**
15
+ * Create a Sub-resource Integrity Hash https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
16
+ */
17
+ export declare function createIntegrityHash(source: string | Buffer): string;
14
18
  /**
15
19
  * Read in the contents of the file path
16
20
  * @param filePath
package/build/es/fs.js CHANGED
@@ -20,6 +20,13 @@ export const PROTOCOL_FILE = 'file://';
20
20
  export function hashContent(source) {
21
21
  return crypto.createHash('md5').update(source).digest('hex');
22
22
  }
23
+ /**
24
+ * Create a Sub-resource Integrity Hash https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
25
+ */
26
+ export function createIntegrityHash(source) {
27
+ const hash = crypto.createHash('sha256').update(source).digest('base64');
28
+ return `sha256-${hash}`;
29
+ }
23
30
  /**
24
31
  * Read in the contents of the file path
25
32
  * @param filePath
@@ -1,6 +1,7 @@
1
1
  import getCacheKeyFromJson from 'fast-json-stable-stringify';
2
- import type { AbstractModuleId, AssetSource, BundleDefinition, ModuleDefinition, NormalizedLwrAppBootstrapConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
3
- export declare const VERSION_SIGIL = "/v/";
2
+ import type { AbstractModuleId, AssetSource, BundleDefinition, ModuleDefinition, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
3
+ export declare const VERSION_SIGIL = "v";
4
+ export declare const VERSION_PREFIX: string;
4
5
  export declare const LOCALE_SIGIL = "l";
5
6
  export declare const ENVIRONMENT_SIGIL = "e";
6
7
  export declare const BUNDLE_SIGIL = "bi";
@@ -14,7 +15,6 @@ export declare const DEFAULT_LWR_LOCKER_CONFIG: {
14
15
  enabled: boolean;
15
16
  trustedComponents: string[];
16
17
  };
17
- export declare const DEFAULT_LWR_BOOTSTRAP_CONFIG: NormalizedLwrAppBootstrapConfig;
18
18
  type ModuleIdentifierPartial = Partial<AbstractModuleId>;
19
19
  /**
20
20
  * Turn the dots in a version into underscores
@@ -147,4 +147,5 @@ export declare function isBundleDefinition(definition: ModuleDefinition | Bundle
147
147
  * @param name - Proposed name
148
148
  */
149
149
  export declare function stringToVariableName(inputString: string): string;
150
+ export declare function getLocalDevOverrideUrl(cacheDir: string, specifier: string, filepath: string): string;
150
151
  //# sourceMappingURL=identity.d.ts.map
@@ -1,6 +1,8 @@
1
+ import path from 'path';
1
2
  import slugifyText from 'slugify';
2
3
  import getCacheKeyFromJson from 'fast-json-stable-stringify';
3
- export const VERSION_SIGIL = '/v/';
4
+ export const VERSION_SIGIL = 'v';
5
+ export const VERSION_PREFIX = `/${VERSION_SIGIL}/`;
4
6
  export const LOCALE_SIGIL = 'l';
5
7
  export const ENVIRONMENT_SIGIL = 'e';
6
8
  export const BUNDLE_SIGIL = 'bi';
@@ -15,18 +17,6 @@ export const DEFAULT_LWR_LOCKER_CONFIG = {
15
17
  enabled: false,
16
18
  trustedComponents: DEFAULT_LOCKER_TRUSTED_CMP,
17
19
  };
18
- export const DEFAULT_LWR_BOOTSTRAP_CONFIG = {
19
- autoBoot: true,
20
- syntheticShadow: false,
21
- workers: {},
22
- services: [],
23
- configAsSrc: false,
24
- ssr: false,
25
- preloadData: false,
26
- mixedMode: false,
27
- module: undefined,
28
- preloadModules: [],
29
- };
30
20
  /**
31
21
  * Turn the dots in a version into underscores
32
22
  * @param version
@@ -99,13 +89,13 @@ export function getSpecifier({ specifier, namespace, name = '', version }) {
99
89
  specifier = versionMatch ? versionMatch[1] : specifier;
100
90
  // If a module has an explicit 'version-not-provided' version this will not be reflected in the specifier
101
91
  return version && version !== VERSION_NOT_PROVIDED
102
- ? `${specifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}`
92
+ ? `${specifier}${VERSION_PREFIX}${normalizeVersionToUri(version)}`
103
93
  : specifier;
104
94
  }
105
95
  const bareSpecifier = namespace ? `${namespace}/${name}` : name;
106
96
  // If a module has an explicit 'version-not-provided' version this will not be reflected in the specifier
107
97
  return version && version !== VERSION_NOT_PROVIDED
108
- ? `${bareSpecifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}`
98
+ ? `${bareSpecifier}${VERSION_PREFIX}${normalizeVersionToUri(version)}`
109
99
  : bareSpecifier;
110
100
  }
111
101
  /**
@@ -280,4 +270,11 @@ export function stringToVariableName(inputString) {
280
270
  }
281
271
  return cleanedString;
282
272
  }
273
+ export function getLocalDevOverrideUrl(cacheDir, specifier, filepath) {
274
+ if (!specifier.startsWith('@view'))
275
+ return filepath; // only @view modules get overridden
276
+ const dirname = path.basename(path.dirname(filepath));
277
+ const fileName = specifier.split('@view/')[1] + '_view.js';
278
+ return path.join(cacheDir, 'overrides', dirname, fileName);
279
+ }
283
280
  //# sourceMappingURL=identity.js.map
@@ -14,4 +14,5 @@ export * from './env.js';
14
14
  export * from './lwr-app-observer.js';
15
15
  export * from './bundle.js';
16
16
  export * from './localization.js';
17
+ export * from './launch.js';
17
18
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -14,4 +14,5 @@ export * from './env.js';
14
14
  export * from './lwr-app-observer.js';
15
15
  export * from './bundle.js';
16
16
  export * from './localization.js';
17
+ export * from './launch.js';
17
18
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Shared utility for launching a localhost browser window at a given port.
3
+ *
4
+ * @param port - the port number
5
+ * @param https - if true, use https
6
+ */
7
+ export declare function launch(port: number, https?: boolean): Promise<void>;
8
+ //# sourceMappingURL=launch.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { release } from 'os';
2
+ /**
3
+ * Shared utility for launching a localhost browser window at a given port.
4
+ *
5
+ * @param port - the port number
6
+ * @param https - if true, use https
7
+ */
8
+ export async function launch(port, https) {
9
+ const { exec } = await import('child_process');
10
+ let cmd = 'open';
11
+ if (process.platform == 'win32') {
12
+ cmd = 'start';
13
+ }
14
+ else if (process.platform == 'linux') {
15
+ if (/microsoft/i.test(release())) {
16
+ cmd = 'cmd.exe /c start';
17
+ }
18
+ else {
19
+ cmd = 'xdg-open';
20
+ }
21
+ }
22
+ exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
23
+ }
24
+ //# sourceMappingURL=launch.js.map
@@ -57,8 +57,8 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
57
57
  export async function toImportMetadata(moduleGraph, existingImportMetadata = { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams = {}) {
58
58
  // root module specifier
59
59
  const specifier = moduleGraph.graphs[0].specifier;
60
- const uri = moduleGraph.uriMap[specifier];
61
- const definition = moduleGraph.linkedDefinitions[specifier];
60
+ const uri = lookupValueIgnoringVersion(moduleGraph.uriMap, specifier);
61
+ const definition = lookupValueIgnoringVersion(moduleGraph.linkedDefinitions, specifier);
62
62
  if (!uri) {
63
63
  throw new Error('URI was not included in the graph: ' + specifier);
64
64
  }
@@ -86,8 +86,8 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
86
86
  // Ignore Externals
87
87
  continue;
88
88
  }
89
- const depUri = moduleGraph.uriMap[depSpecifier];
90
- const depDef = moduleGraph.linkedDefinitions[depSpecifier];
89
+ const depUri = lookupValueIgnoringVersion(moduleGraph.uriMap, depSpecifier);
90
+ const depDef = lookupValueIgnoringVersion(moduleGraph.linkedDefinitions, depSpecifier);
91
91
  const depMissing = !depUri || !depDef;
92
92
  if (depMissing && runtimeEnvironment.format !== 'esm') {
93
93
  if (!depUri) {
@@ -112,6 +112,21 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
112
112
  }
113
113
  return importMetadata;
114
114
  }
115
+ // Function to look up values ignoring the version part
116
+ function lookupValueIgnoringVersion(map, specifier) {
117
+ // early out on exact match
118
+ const val = map[specifier];
119
+ if (val) {
120
+ return val;
121
+ }
122
+ const cleanedKey = explodeSpecifier(specifier).specifier;
123
+ // Iterate over the map to find the first matching key without version
124
+ for (const mapKey of Object.keys(map)) {
125
+ if (explodeSpecifier(mapKey).specifier === cleanedKey) {
126
+ return map[mapKey];
127
+ }
128
+ }
129
+ }
115
130
  function mergeImportMetadata(existing, newMetadata) {
116
131
  // TODO should there be an error if the metadata conflicts?
117
132
  return {
@@ -25,5 +25,5 @@ export declare function replaceStringFromLocation(src: string, { startOffset, en
25
25
  * @param oldTtl - the current shortest TTL (if it exists)
26
26
  * @returns - the shorter of the two TTLs IN SECONDS, undefined if both TTLs are missing
27
27
  */
28
- export declare function shortestTtl(newTtl?: string | number, oldTtl?: string | number): number | undefined;
28
+ export declare function shortestTtl(newTtl?: string | number, oldTtl?: string | number, maxTtl?: string | number): number | undefined;
29
29
  //# sourceMappingURL=serialize.d.ts.map
@@ -49,15 +49,22 @@ export function replaceStringFromLocation(src, { startOffset, endOffset }, repla
49
49
  * @param oldTtl - the current shortest TTL (if it exists)
50
50
  * @returns - the shorter of the two TTLs IN SECONDS, undefined if both TTLs are missing
51
51
  */
52
- export function shortestTtl(newTtl, oldTtl) {
52
+ export function shortestTtl(newTtl, oldTtl, maxTtl) {
53
53
  if (newTtl === undefined && oldTtl === undefined)
54
54
  return undefined;
55
55
  const newSeconds = typeof newTtl === 'string' ? ms(newTtl) / 1000 : newTtl;
56
56
  const oldSeconds = typeof oldTtl === 'string' ? ms(oldTtl) / 1000 : oldTtl;
57
- if (newSeconds === undefined)
58
- return oldSeconds;
59
- if (oldSeconds === undefined)
60
- return newSeconds;
61
- return newSeconds < oldSeconds ? newSeconds : oldSeconds;
57
+ const maxSeconds = typeof maxTtl === 'string' ? ms(maxTtl) / 1000 : maxTtl;
58
+ let shortest = undefined;
59
+ if (newSeconds !== undefined && (shortest === undefined || newSeconds < shortest)) {
60
+ shortest = newSeconds;
61
+ }
62
+ if (oldSeconds !== undefined && (shortest === undefined || oldSeconds < shortest)) {
63
+ shortest = oldSeconds;
64
+ }
65
+ if (maxSeconds !== undefined && (shortest === undefined || maxSeconds < shortest)) {
66
+ shortest = maxSeconds;
67
+ }
68
+ return shortest;
62
69
  }
63
70
  //# sourceMappingURL=serialize.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.13.0-alpha.3",
7
+ "version": "0.13.0-alpha.30",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -37,25 +37,25 @@
37
37
  "build/**/*.d.ts"
38
38
  ],
39
39
  "dependencies": {
40
- "@lwrjs/diagnostics": "0.13.0-alpha.3",
41
- "es-module-lexer": "^1.3.0",
40
+ "@lwrjs/diagnostics": "0.13.0-alpha.30",
41
+ "es-module-lexer": "^1.5.4",
42
42
  "fast-json-stable-stringify": "^2.1.0",
43
43
  "magic-string": "^0.30.9",
44
44
  "mime-types": "^2.1.33",
45
45
  "ms": "^2.1.3",
46
46
  "parse5-sax-parser": "^6.0.1",
47
- "path-to-regexp": "^6.2.0",
47
+ "path-to-regexp": "^6.2.2",
48
48
  "resolve": "^1.22.8",
49
49
  "rollup": "^2.78.0",
50
50
  "slugify": "^1.4.5"
51
51
  },
52
52
  "devDependencies": {
53
- "@lwrjs/types": "0.13.0-alpha.3",
53
+ "@lwrjs/types": "0.13.0-alpha.30",
54
54
  "@types/mime-types": "2.1.4",
55
55
  "@types/path-to-regexp": "^1.7.0"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=18.0.0"
59
59
  },
60
- "gitHead": "f2435da0eb0cf643add2a7cf896b3372df75733e"
60
+ "gitHead": "8bf14ed00a95675fdb506e2cbdb6033324bf95bf"
61
61
  }