@lwrjs/shared-utils 0.9.0-alpha.9 → 0.9.0

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,80 @@
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/compiler.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ AMD_DEFINE: () => AMD_DEFINE,
28
+ convertToAmd: () => convertToAmd,
29
+ lockerize: () => lockerize
30
+ });
31
+ var import_identity = __toModule(require("./identity.cjs"));
32
+ var import_compiler = __toModule(require("@locker/compiler"));
33
+ var import_rollup = __toModule(require("rollup"));
34
+ var AMD_DEFINE = "LWR.define";
35
+ var AMD_ROLLUP_PLUGIN = function(rootId, source) {
36
+ return {
37
+ name: "lwr-amd-inline",
38
+ resolveId(id) {
39
+ return rootId === id ? id : void 0;
40
+ },
41
+ load(id) {
42
+ return rootId === id ? source : void 0;
43
+ }
44
+ };
45
+ };
46
+ async function convertToAmd(source, {id}, forceNamedExports = true) {
47
+ const bundler = await (0, import_rollup.rollup)({
48
+ input: id,
49
+ plugins: [AMD_ROLLUP_PLUGIN(id, source)],
50
+ onwarn(warning, warn) {
51
+ if (warning.code === "UNRESOLVED_IMPORT")
52
+ return;
53
+ warn(warning);
54
+ }
55
+ });
56
+ const {output} = await bundler.generate({
57
+ amd: {id, define: AMD_DEFINE},
58
+ exports: forceNamedExports ? "named" : "auto",
59
+ format: "amd"
60
+ });
61
+ const {code} = output[0];
62
+ return {code, map: null};
63
+ }
64
+ function lockerize({compiledSource: source, specifier, moduleEntry: {entry: filename}}, {trustedComponents}, sourcemap = false) {
65
+ const {namespace, name: rawName} = (0, import_identity.explodeSpecifier)(specifier);
66
+ const [name] = rawName.split("#");
67
+ const bareSpecifier = namespace ? `${namespace}/${name}` : name;
68
+ const isJS = filename.endsWith(".js") || filename.endsWith(".mjs") || filename.endsWith(".ts");
69
+ if (isJS && trustedComponents && !trustedComponents.includes(`${namespace}/*`) && !trustedComponents.includes(bareSpecifier)) {
70
+ const {code} = import_compiler.Compiler.compile(source, {
71
+ componentName: name,
72
+ filename,
73
+ sandboxKey: namespace || "sandbox",
74
+ sourcemap,
75
+ remapDynamicImport: true
76
+ });
77
+ return {code, map: null};
78
+ }
79
+ return {code: source, map: null};
80
+ }
package/build/cjs/env.cjs CHANGED
@@ -11,14 +11,10 @@ __export(exports, {
11
11
  getFeatureFlags: () => getFeatureFlags
12
12
  });
13
13
  function getFeatureFlags() {
14
- let legacyLoader = process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER === "true" ? true : false;
15
- try {
16
- if (LWR) {
17
- legacyLoader = LWR.LEGACY_LOADER;
18
- }
19
- } catch (e) {
20
- }
21
14
  return {
22
- LEGACY_LOADER: legacyLoader
15
+ 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
+ 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
23
19
  };
24
20
  }
@@ -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/fs-watch.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ WatcherFactoryImpl: () => WatcherFactoryImpl
28
+ });
29
+ var import_chokidar = __toModule(require("chokidar"));
30
+ var import_object = __toModule(require("./object.cjs"));
31
+ var import_logger = __toModule(require("./logger.cjs"));
32
+ var WatcherFactoryImpl = class {
33
+ createFileWatcher(options = {persistent: true, ignored: "**/node_modules/**"}) {
34
+ return import_chokidar.default.watch([], options);
35
+ }
36
+ setupWatcher(onModuleChange) {
37
+ const fileWatcher = this.createFileWatcher();
38
+ fileWatcher.on("change", (0, import_object.debounce)((file) => onModuleChange(file), 500));
39
+ fileWatcher.on("unlink", (0, import_object.debounce)((file) => onModuleChange(file), 500));
40
+ fileWatcher.on("add", (file) => import_logger.logger.info(`Watching: ${file}`));
41
+ return fileWatcher;
42
+ }
43
+ };
package/build/cjs/fs.cjs CHANGED
@@ -25,22 +25,19 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  canResolveView: () => canResolveView,
28
- createFileWatcher: () => createFileWatcher,
29
28
  getViewSourceFromFile: () => getViewSourceFromFile,
30
29
  hashContent: () => hashContent,
31
30
  mimeLookup: () => import_mime_types.lookup,
31
+ normalizeAssetSpecifier: () => normalizeAssetSpecifier,
32
32
  normalizeDirectory: () => normalizeDirectory,
33
33
  normalizeResourcePath: () => normalizeResourcePath,
34
34
  readFile: () => readFile,
35
- resolveFileExtension: () => resolveFileExtension,
36
- setupWatcher: () => setupWatcher
35
+ resolveFileExtension: () => resolveFileExtension
37
36
  });
38
37
  var import_fs = __toModule(require("fs"));
39
38
  var import_path = __toModule(require("path"));
40
39
  var import_crypto = __toModule(require("crypto"));
41
40
  var import_identity = __toModule(require("./identity.cjs"));
42
- var import_object = __toModule(require("./object.cjs"));
43
- var import_chokidar = __toModule(require("chokidar"));
44
41
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
45
42
  var import_mime_types = __toModule(require("mime-types"));
46
43
  var import_logger = __toModule(require("./logger.cjs"));
@@ -74,16 +71,6 @@ function resolveFileExtension(filePath) {
74
71
  throw new Error(`Unable to find file "${filePath}"`);
75
72
  }
76
73
  }
77
- function createFileWatcher(options = {persistent: true, ignored: "**/node_modules/**"}) {
78
- return import_chokidar.default.watch([], options);
79
- }
80
- function setupWatcher(onModuleChange) {
81
- const fileWatcher = createFileWatcher();
82
- fileWatcher.on("change", (0, import_object.debounce)((file) => onModuleChange(file), 500));
83
- fileWatcher.on("unlink", (0, import_object.debounce)((file) => onModuleChange(file), 500));
84
- fileWatcher.on("add", (file) => import_logger.logger.info(`Watching: ${file}`));
85
- return fileWatcher;
86
- }
87
74
  function canResolveView(source, type) {
88
75
  if (!source.endsWith(`.${type}`)) {
89
76
  return false;
@@ -140,3 +127,26 @@ function logMetrics(filePath) {
140
127
  }
141
128
  }
142
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
+ }
@@ -25,7 +25,8 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  GraphDepth: () => GraphDepth,
28
- getModuleGraphs: () => getModuleGraphs
28
+ getModuleGraphs: () => getModuleGraphs,
29
+ isBundler: () => isBundler
29
30
  });
30
31
  var import_identity = __toModule(require("./identity.cjs"));
31
32
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
@@ -93,7 +94,7 @@ async function traverse(module2, depth, flattened, graphIdx, visited, defRegistr
93
94
  }
94
95
  async function flatten(versionedSpecifier, flattened, idx, visited) {
95
96
  const node = visited.get(versionedSpecifier);
96
- if (node) {
97
+ if (flattened[idx]?.static && node?.static) {
97
98
  node.static.forEach(async (imp) => {
98
99
  if (!flattened[idx].static.includes(imp)) {
99
100
  flattened[idx].static.push(imp);
@@ -121,7 +122,7 @@ async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry,
121
122
  if (options.includeUris) {
122
123
  for (const visitedSpecifier of acc.keys()) {
123
124
  const moduleId = await (0, import_identity.getVersionedModuleId)(visitedSpecifier, moduleRegistry);
124
- const uri = await moduleRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
125
+ const uri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
125
126
  uriMap[visitedSpecifier] = uri;
126
127
  }
127
128
  }
@@ -34,23 +34,20 @@ __export(exports, {
34
34
  IMMUTABLE_ASSET_PREFIX: () => IMMUTABLE_ASSET_PREFIX,
35
35
  LATEST_SIGNATURE: () => LATEST_SIGNATURE,
36
36
  LOCALE_SIGIL: () => LOCALE_SIGIL,
37
+ VERSION_NOT_PROVIDED: () => VERSION_NOT_PROVIDED,
37
38
  VERSION_SIGIL: () => VERSION_SIGIL,
38
39
  explodeSpecifier: () => explodeSpecifier,
39
40
  explodeSpecifiers: () => explodeSpecifiers,
40
- getAssetIdentity: () => getAssetIdentity,
41
41
  getCacheKeyFromJson: () => import_fast_json_stable_stringify.default,
42
- getMappingIdentity: () => getMappingIdentity,
43
42
  getMappingUriPrefix: () => getMappingUriPrefix,
44
- getModuleIdentity: () => getModuleIdentity,
45
43
  getModuleUriPrefix: () => getModuleUriPrefix,
46
44
  getPropFromAttrName: () => getPropFromAttrName,
47
- getResourceIdentity: () => getResourceIdentity,
48
45
  getSpecifier: () => getSpecifier,
49
46
  getVersionedModuleId: () => getVersionedModuleId,
50
- getVersionedSpecifier: () => getVersionedSpecifier,
47
+ isAssetSourceExternal: () => isAssetSourceExternal,
51
48
  isBundleDefinition: () => isBundleDefinition,
52
49
  isExternalUrl: () => isExternalUrl,
53
- kebabCaseToModuleSpecifer: () => kebabCaseToModuleSpecifer,
50
+ kebabCaseToModuleSpecifier: () => kebabCaseToModuleSpecifier,
54
51
  moduleSpecifierToKebabCase: () => moduleSpecifierToKebabCase,
55
52
  normalizeVersionFromUri: () => normalizeVersionFromUri,
56
53
  normalizeVersionToUri: () => normalizeVersionToUri,
@@ -68,6 +65,7 @@ var LATEST_SIGNATURE = "latest";
68
65
  var DEFAULT_TITLE = "LWR App";
69
66
  var IMMUTABLE_ASSET_PREFIX = "/_immutable/";
70
67
  var ASSETS_CACHE_DIR = "assetsCache";
68
+ var VERSION_NOT_PROVIDED = "version-not-provided";
71
69
  var DEFAULT_LOCKER_TRUSTED_CMP = ["@locker/*", "lwr/*", "@lwrjs/*", "lwc", "@lwc/*"];
72
70
  var DEFAULT_LWR_LOCKER_CONFIG = {
73
71
  enabled: false,
@@ -79,7 +77,9 @@ var DEFAULT_LWR_BOOTSTRAP_CONFIG = {
79
77
  workers: {},
80
78
  services: [],
81
79
  configAsSrc: false,
82
- ssr: false
80
+ ssr: false,
81
+ module: void 0,
82
+ preloadModules: []
83
83
  };
84
84
  function normalizeVersionToUri(version) {
85
85
  return version.replace(/\./g, "_");
@@ -123,21 +123,13 @@ function getSpecifier({specifier, namespace, name = "", version}) {
123
123
  const bareSpecifier = namespace ? `${namespace}/${name}` : name;
124
124
  return version ? `${bareSpecifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}` : bareSpecifier;
125
125
  }
126
- async function getVersionedSpecifier(rawSpecifier, moduleRegistry) {
127
- const {specifier, namespace, name, version} = explodeSpecifier(rawSpecifier);
128
- if (version) {
129
- return normalizeVersionToUri(rawSpecifier);
130
- }
131
- const moduleEntry = await moduleRegistry.getModuleEntry({specifier});
132
- return getSpecifier({namespace, name, version: normalizeVersionToUri(moduleEntry.version)});
133
- }
134
126
  async function getVersionedModuleId(rawSpecifier, moduleRegistry) {
135
- const {specifier, version} = explodeSpecifier(rawSpecifier);
136
- if (version) {
137
- return {specifier, version: normalizeVersionFromUri(version)};
127
+ const moduleId = explodeSpecifier(rawSpecifier);
128
+ if (moduleId.version) {
129
+ return {...moduleId, version: normalizeVersionFromUri(moduleId.version)};
138
130
  }
139
- const moduleEntry = await moduleRegistry.getModuleEntry({specifier});
140
- return {specifier, version: moduleEntry.version};
131
+ const moduleEntry = await moduleRegistry.getModuleEntry(moduleId);
132
+ return {...moduleId, version: moduleEntry.version};
141
133
  }
142
134
  var RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
143
135
  var RE_NORMAL = /^([^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
@@ -160,7 +152,7 @@ function parsePackageSpecifier(specifier) {
160
152
  subResource: matched[2] || ""
161
153
  };
162
154
  }
163
- function kebabCaseToModuleSpecifer(name) {
155
+ function kebabCaseToModuleSpecifier(name) {
164
156
  const newName = [];
165
157
  let nsFound = false;
166
158
  let upper = false;
@@ -209,55 +201,9 @@ var REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
209
201
  function isExternalUrl(url) {
210
202
  return REGEX_URL_SCHEMA_PREFIX.test(url);
211
203
  }
204
+ function isAssetSourceExternal(assetSource) {
205
+ return assetSource.type === "external" || !!assetSource.uri && isExternalUrl(assetSource.uri);
206
+ }
212
207
  function isBundleDefinition(definition) {
213
208
  return definition.bundleRecord !== void 0;
214
209
  }
215
- function validateSpecifier(specifer) {
216
- return specifer.indexOf("../") < 0;
217
- }
218
- function getModuleIdentity(req) {
219
- const {specifier, signature = LATEST_SIGNATURE} = req.params;
220
- if (validateSpecifier(specifier) === false) {
221
- throw new Error("dot-dot-slash is not allowed for module specifier");
222
- }
223
- const moduleId = explodeSpecifier(specifier);
224
- return {
225
- moduleId,
226
- signature
227
- };
228
- }
229
- function getMappingIdentity(req) {
230
- const {specifiers} = req.params;
231
- const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
232
- ...obj,
233
- importer: req.query.importer
234
- }));
235
- return {
236
- moduleIds
237
- };
238
- }
239
- function getResourceIdentity(req) {
240
- const {specifier, signature = LATEST_SIGNATURE} = req.params;
241
- if (validateSpecifier(specifier) === false) {
242
- throw new Error("dot-dot-slash is not allowed for resource specifier");
243
- }
244
- const resourceId = explodeSpecifier(specifier);
245
- return {
246
- resourceId,
247
- signature
248
- };
249
- }
250
- function getAssetIdentity(req) {
251
- const {signature = LATEST_SIGNATURE, assetType: type} = req.params;
252
- const [specifier] = req.originalUrl.split("?");
253
- if (validateSpecifier(specifier) === false) {
254
- throw new Error("dot-dot-slash is not allowed for asset specifier");
255
- }
256
- return {
257
- assetId: {
258
- specifier,
259
- type
260
- },
261
- signature
262
- };
263
- }
@@ -27,7 +27,6 @@ __exportStar(exports, __toModule(require("./link.cjs")));
27
27
  __exportStar(exports, __toModule(require("./object.cjs")));
28
28
  __exportStar(exports, __toModule(require("./serialize.cjs")));
29
29
  __exportStar(exports, __toModule(require("./tasks.cjs")));
30
- __exportStar(exports, __toModule(require("./typescript.cjs")));
31
30
  __exportStar(exports, __toModule(require("./import-metadata.cjs")));
32
31
  __exportStar(exports, __toModule(require("./graph.cjs")));
33
32
  __exportStar(exports, __toModule(require("./mappings.cjs")));
@@ -35,3 +34,4 @@ __exportStar(exports, __toModule(require("./urls.cjs")));
35
34
  __exportStar(exports, __toModule(require("./env.cjs")));
36
35
  __exportStar(exports, __toModule(require("./logger.cjs")));
37
36
  __exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
37
+ __exportStar(exports, __toModule(require("./site-metadata.cjs")));
@@ -42,10 +42,13 @@ var NoLwcModuleError = class extends Error {
42
42
  function isNpmModuleRecord(module2) {
43
43
  return module2.npm !== void 0;
44
44
  }
45
- function discoverInterchangeableModules(modules, interchangeableModules) {
45
+ function discoverInterchangeableModules(modules, interchangeableModules, visitedModules) {
46
46
  if (!interchangeableModules) {
47
47
  interchangeableModules = new Map();
48
48
  }
49
+ if (!visitedModules) {
50
+ visitedModules = new Set();
51
+ }
49
52
  if (modules.length === 0) {
50
53
  return interchangeableModules;
51
54
  }
@@ -54,6 +57,10 @@ function discoverInterchangeableModules(modules, interchangeableModules) {
54
57
  if (!isNpmModuleRecord(module2)) {
55
58
  continue;
56
59
  }
60
+ if (visitedModules?.has(module2.npm)) {
61
+ continue;
62
+ }
63
+ visitedModules.add(module2.npm);
57
64
  const packageJsonPath = import_resolve.default.sync(`${module2.npm}/package.json`);
58
65
  const packageJson = JSON.parse((0, import_fs2.readFile)(packageJsonPath));
59
66
  let lwcConfig = packageJson.lwc;
@@ -68,7 +75,7 @@ function discoverInterchangeableModules(modules, interchangeableModules) {
68
75
  interchangeableModules = normalizeInterchangeableModuleConfig(lwcConfig.interchangeableModules, interchangeableModules);
69
76
  }
70
77
  }
71
- return discoverInterchangeableModules(nestedModules, interchangeableModules);
78
+ return discoverInterchangeableModules(nestedModules, interchangeableModules, visitedModules);
72
79
  }
73
80
  function resolveCustomLWCMetadata(dir) {
74
81
  for (const configFile of CONFIG_FILES) {
@@ -74,19 +74,29 @@ function log(level, message, additionalInfo) {
74
74
  }
75
75
  }
76
76
  if (shouldLog) {
77
- let logMethod;
77
+ const logMessage = `[${level}]${gap(message)}${message}`;
78
+ const additionalMessage = additionalInfo ? `Additional Info: ${JSON.stringify(additionalInfo)}` : void 0;
78
79
  if (level == ERROR) {
79
- logMethod = console.error;
80
+ console.error("%s", logMessage);
81
+ if (additionalInfo) {
82
+ console.error("\n%s", additionalMessage);
83
+ }
80
84
  } else if (level == WARN) {
81
- logMethod = console.warn;
85
+ console.warn("%s", logMessage);
86
+ if (additionalInfo) {
87
+ console.warn("\n%s", additionalMessage);
88
+ }
89
+ } else if (level == DEBUG || level == VERBOSE) {
90
+ console.log("%s", logMessage);
91
+ if (additionalInfo) {
92
+ console.log("\n%s", additionalMessage);
93
+ }
82
94
  } else {
83
- logMethod = console.log;
84
- }
85
- if (additionalInfo) {
86
- logMethod(`[${level}] ${message}
87
- Additional Info: ${JSON.stringify(additionalInfo)}`);
88
- } else {
89
- logMethod(`[${level}] ${message}`);
95
+ console.log(logMessage);
96
+ if (additionalInfo) {
97
+ console.log(`
98
+ ${additionalMessage}`);
99
+ }
90
100
  }
91
101
  }
92
102
  }
@@ -110,12 +120,24 @@ var stringifyError = (error) => {
110
120
  return JSON.stringify(retObj);
111
121
  }
112
122
  };
123
+ function gap(message) {
124
+ return String(message)?.indexOf("[") === 0 ? "" : " ";
125
+ }
126
+ function logError(err, additionalInfo) {
127
+ if (err instanceof import_diagnostics.DiagnosticsError || !err || !err.message) {
128
+ log(ERROR, stringifyError(err), additionalInfo);
129
+ }
130
+ if (err && err.message) {
131
+ err.message = `[${ERROR}]${gap(err.message)}${err.message}`;
132
+ console.error("%s", err);
133
+ }
134
+ }
113
135
  var logger = {
114
136
  verbose: (message, additionalInfo) => log(VERBOSE, message, additionalInfo),
115
137
  debug: (message, additionalInfo) => log(DEBUG, message, additionalInfo),
116
138
  info: (message, additionalInfo) => log(INFO, message, additionalInfo),
117
139
  warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
118
- error: (error, additionalInfo) => log(ERROR, stringifyError(error), additionalInfo),
140
+ error: (error, additionalInfo) => logError(error, additionalInfo),
119
141
  log,
120
142
  setOptions: (opts) => {
121
143
  options = opts;
@@ -23,7 +23,8 @@ function _deepFreeze(obj, maxDepth, depth) {
23
23
  }
24
24
  }
25
25
  function deepFreeze(obj, maxDepth = 5) {
26
- return _deepFreeze(obj, maxDepth, 0);
26
+ const objClone = JSON.parse(JSON.stringify(obj));
27
+ return _deepFreeze(objClone, maxDepth, 0);
27
28
  }
28
29
  var debounce = (func, waitFor) => {
29
30
  const timeouts = new Map();
@@ -1,16 +1,34 @@
1
+ var __create = Object.create;
1
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;
2
7
  var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
8
  var __export = (target, all) => {
4
9
  for (var name in all)
5
10
  __defProp(target, name, {get: all[name], enumerable: true});
6
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
+ };
7
23
 
8
24
  // packages/@lwrjs/shared-utils/src/serialize.ts
9
25
  __markAsModule(exports);
10
26
  __export(exports, {
11
27
  replaceStringFromLocation: () => replaceStringFromLocation,
12
- serializeModuleToJson: () => serializeModuleToJson
28
+ serializeModuleToJson: () => serializeModuleToJson,
29
+ shortestTtl: () => shortestTtl
13
30
  });
31
+ var import_ms = __toModule(require("ms"));
14
32
  async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
15
33
  const {
16
34
  ownHash,
@@ -21,7 +39,7 @@ async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, ru
21
39
  version,
22
40
  ownHash,
23
41
  links: {
24
- self: moduleRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, ownHash)
42
+ self: await moduleRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, ownHash)
25
43
  }
26
44
  };
27
45
  }
@@ -48,3 +66,14 @@ async function serializeModuleToJson(code = "", {
48
66
  function replaceStringFromLocation(src, {startOffset, endOffset}, replaceValue) {
49
67
  return src.substr(0, startOffset) + replaceValue + src.substr(endOffset, src.length);
50
68
  }
69
+ function shortestTtl(newTtl, oldTtl) {
70
+ if (!newTtl && !oldTtl)
71
+ return void 0;
72
+ const newSeconds = typeof newTtl === "string" ? (0, import_ms.default)(newTtl) / 1e3 : newTtl;
73
+ const oldSeconds = typeof oldTtl === "string" ? (0, import_ms.default)(oldTtl) / 1e3 : oldTtl;
74
+ if (!newSeconds)
75
+ return oldSeconds;
76
+ if (!oldSeconds)
77
+ return newSeconds;
78
+ return newSeconds < oldSeconds ? newSeconds : oldSeconds;
79
+ }