@lwrjs/shared-utils 0.6.4 → 0.7.0-alpha.2

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
@@ -8,10 +8,10 @@ var __export = (target, all) => {
8
8
  // packages/@lwrjs/shared-utils/src/env.ts
9
9
  __markAsModule(exports);
10
10
  __export(exports, {
11
- getExperimentalFeatures: () => getExperimentalFeatures
11
+ getFeatureFlags: () => getFeatureFlags
12
12
  });
13
- function getExperimentalFeatures() {
13
+ function getFeatureFlags() {
14
14
  return {
15
- ENABLE_FINGERPRINTS: process.env.ENABLE_FINGERPRINTS !== void 0 && process.env.ENABLE_FINGERPRINTS === "true" ? true : false
15
+ LEGACY_LOADER: process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER === "true" ? true : false
16
16
  };
17
17
  }
@@ -28,6 +28,7 @@ __export(exports, {
28
28
  getModuleGraphs: () => getModuleGraphs
29
29
  });
30
30
  var import_identity = __toModule(require("./identity.cjs"));
31
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
31
32
  var import_import_metadata = __toModule(require("./import-metadata.cjs"));
32
33
  var GraphDepth;
33
34
  (function(GraphDepth2) {
@@ -110,7 +111,9 @@ async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry,
110
111
  };
111
112
  const moduleDef = isBundler(defRegistry) ? await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams) : await defRegistry.getModule(versionedModuleId, runtimeParams);
112
113
  if (!moduleDef) {
113
- throw new Error("Missing module Definition");
114
+ throw (0, import_diagnostics.createSingleDiagnosticError)({
115
+ description: import_diagnostics.descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier)
116
+ }, import_diagnostics.LwrUnresolvableError);
114
117
  }
115
118
  const flattened = [];
116
119
  await traverse(moduleDef, depth, flattened, 0, acc, defRegistry, runtimeEnvironment, runtimeParams);
@@ -25,6 +25,7 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  ASSETS_CACHE_DIR: () => ASSETS_CACHE_DIR,
28
+ BUNDLE_SIGIL: () => BUNDLE_SIGIL,
28
29
  DEFAULT_LOCKER_TRUSTED_CMP: () => DEFAULT_LOCKER_TRUSTED_CMP,
29
30
  DEFAULT_LWR_BOOTSTRAP_CONFIG: () => DEFAULT_LWR_BOOTSTRAP_CONFIG,
30
31
  DEFAULT_LWR_LOCKER_CONFIG: () => DEFAULT_LWR_LOCKER_CONFIG,
@@ -61,6 +62,7 @@ var import_fast_json_stable_stringify = __toModule(require("fast-json-stable-str
61
62
  var VERSION_SIGIL = "/v/";
62
63
  var LOCALE_SIGIL = "l";
63
64
  var ENVIRONMENT_SIGIL = "e";
65
+ var BUNDLE_SIGIL = "bi";
64
66
  var LATEST_SIGNATURE = "latest";
65
67
  var DEFAULT_TITLE = "LWR App";
66
68
  var IMMUTABLE_ASSET_PREFIX = "/_immutable/";
@@ -188,14 +190,16 @@ function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {loc
188
190
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
189
191
  const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
190
192
  if (bundle) {
191
- return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/bi/0/module/mi/`;
193
+ return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/0/module/mi/`;
192
194
  } else {
193
195
  return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
194
196
  }
195
197
  }
196
- function getMappingUriPrefix({apiVersion, format, compat, basePath}, {locale} = {}) {
198
+ function getMappingUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}) {
197
199
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
198
- return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}/mp/`;
200
+ const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
201
+ const bundlePart = bundle ? `/${BUNDLE_SIGIL}/0` : "";
202
+ return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}${environmentPart}${bundlePart}/mp/`;
199
203
  }
200
204
  var REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
201
205
  function isExternalUrl(url) {
@@ -214,7 +218,11 @@ function getModuleIdentity(req) {
214
218
  }
215
219
  function getMappingIdentity(req) {
216
220
  const {specifiers} = req.params;
217
- const moduleIds = explodeSpecifiers(specifiers);
221
+ const modifiers = req.query.importer ? {importer: decodeURIComponent(req.query.importer)} : {};
222
+ const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
223
+ ...obj,
224
+ ...modifiers
225
+ }));
218
226
  return {
219
227
  moduleIds
220
228
  };
@@ -36,7 +36,8 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
36
36
  index: {}
37
37
  };
38
38
  for (const moduleId of moduleIds) {
39
- const specifier = (0, import_identity.getSpecifier)(moduleId);
39
+ const requestedSpecifier = (0, import_identity.getSpecifier)(moduleId);
40
+ const specifier = await getVersionedSpecifier(moduleId, moduleRegistry);
40
41
  if (!visitedCache.has(specifier)) {
41
42
  const depth = {
42
43
  static: runtimeEnvironment.format === "esm" ? import_graph.GraphDepth.NONE : import_graph.GraphDepth.ALL,
@@ -45,6 +46,14 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
45
46
  const moduleGraph = await (0, import_graph.getModuleGraphs)(specifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, runtimeEnvironment.bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
46
47
  importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
47
48
  }
49
+ if (requestedSpecifier !== specifier && moduleId.importer) {
50
+ const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${encodeURIComponent(moduleId.importer)}`;
51
+ const specifiersArray = Object.values(importMetadata.imports).find((a) => a.includes(specifier));
52
+ if (!specifiersArray) {
53
+ throw new Error("Could not find: " + specifier + " in " + JSON.stringify(importMetadata.imports));
54
+ }
55
+ specifiersArray.push(requestedSpecifierPlusImporter);
56
+ }
48
57
  }
49
58
  return importMetadata;
50
59
  }
@@ -127,3 +136,12 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
127
136
  await Promise.all(promises);
128
137
  return index;
129
138
  }
139
+ async function getVersionedSpecifier(moduleId, moduleRegistry) {
140
+ if (!moduleId.importer || moduleId.version) {
141
+ return (0, import_identity.getSpecifier)(moduleId);
142
+ }
143
+ const versionedModuleEntry = await moduleRegistry.getModuleEntry({
144
+ ...moduleId
145
+ });
146
+ return (0, import_identity.getSpecifier)(versionedModuleEntry);
147
+ }
package/build/es/env.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { ExperimentalFeatures } from '@lwrjs/types';
2
- export declare function getExperimentalFeatures(): ExperimentalFeatures;
1
+ import { FeatureFlags } from '@lwrjs/types';
2
+ export declare function getFeatureFlags(): FeatureFlags;
3
3
  //# sourceMappingURL=env.d.ts.map
package/build/es/env.js CHANGED
@@ -1,9 +1,7 @@
1
- export function getExperimentalFeatures() {
1
+ export function getFeatureFlags() {
2
2
  return {
3
- // DEFAULT ENABLE_FINGERPRINTS = false;
4
- ENABLE_FINGERPRINTS: process.env.ENABLE_FINGERPRINTS !== undefined && process.env.ENABLE_FINGERPRINTS === 'true'
5
- ? true
6
- : false,
3
+ // DEFAULT LEGACY_LOADER = false;
4
+ LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER === 'true' ? true : false,
7
5
  };
8
6
  }
9
7
  //# sourceMappingURL=env.js.map
package/build/es/graph.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getSpecifier, getVersionedModuleId, isBundleDefinition } from './identity.js';
2
+ import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
2
3
  import { ModuleNameType } from './import-metadata.js';
3
4
  export var GraphDepth;
4
5
  (function (GraphDepth) {
@@ -116,7 +117,9 @@ options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited
116
117
  ? await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams)
117
118
  : await defRegistry.getModule(versionedModuleId, runtimeParams);
118
119
  if (!moduleDef) {
119
- throw new Error('Missing module Definition');
120
+ throw createSingleDiagnosticError({
121
+ description: descriptions.UNRESOLVABLE.MODULE_ENTRY(versionedModuleId.specifier),
122
+ }, LwrUnresolvableError);
120
123
  }
121
124
  const flattened = [];
122
125
  await traverse(moduleDef, depth, flattened, 0, acc, defRegistry, runtimeEnvironment, runtimeParams);
@@ -3,6 +3,7 @@ import { AbstractModuleId, AssetIdentity, BundleDefinition, MappingIdentity, Mid
3
3
  export declare const VERSION_SIGIL = "/v/";
4
4
  export declare const LOCALE_SIGIL = "l";
5
5
  export declare const ENVIRONMENT_SIGIL = "e";
6
+ export declare const BUNDLE_SIGIL = "bi";
6
7
  export declare const LATEST_SIGNATURE = "latest";
7
8
  export declare const DEFAULT_TITLE = "LWR App";
8
9
  export declare const IMMUTABLE_ASSET_PREFIX = "/_immutable/";
@@ -154,7 +155,7 @@ export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat,
154
155
  * @param param0 - URI props from the Runtime Environment
155
156
  * @param param1 - URI props from the Runtime Params
156
157
  */
157
- export declare function getMappingUriPrefix({ apiVersion, format, compat, basePath }: RuntimeEnvironment, { locale }?: RuntimeParams): string;
158
+ export declare function getMappingUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams): string;
158
159
  export { getCacheKeyFromJson };
159
160
  export declare function isExternalUrl(url: string): boolean;
160
161
  export declare function isBundleDefinition(definition: ModuleDefinition | BundleDefinition): definition is BundleDefinition;
@@ -3,6 +3,7 @@ import getCacheKeyFromJson from 'fast-json-stable-stringify';
3
3
  export const VERSION_SIGIL = '/v/';
4
4
  export const LOCALE_SIGIL = 'l';
5
5
  export const ENVIRONMENT_SIGIL = 'e';
6
+ export const BUNDLE_SIGIL = 'bi';
6
7
  export const LATEST_SIGNATURE = 'latest';
7
8
  export const DEFAULT_TITLE = 'LWR App';
8
9
  export const IMMUTABLE_ASSET_PREFIX = '/_immutable/';
@@ -244,7 +245,7 @@ export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePat
244
245
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
245
246
  const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : '';
246
247
  if (bundle) {
247
- return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/bi/0/module/mi/`;
248
+ return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/0/module/mi/`;
248
249
  }
249
250
  else {
250
251
  return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
@@ -255,9 +256,11 @@ export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePat
255
256
  * @param param0 - URI props from the Runtime Environment
256
257
  * @param param1 - URI props from the Runtime Params
257
258
  */
258
- export function getMappingUriPrefix({ apiVersion, format, compat, basePath }, { locale } = {}) {
259
+ export function getMappingUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}) {
259
260
  const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
260
- return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}/mp/`;
261
+ const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : '';
262
+ const bundlePart = bundle ? `/${BUNDLE_SIGIL}/0` : '';
263
+ return `${basePath}/${apiVersion}/mapping/${format}/${compat}${localePart}${environmentPart}${bundlePart}/mp/`;
261
264
  }
262
265
  export { getCacheKeyFromJson };
263
266
  const REGEX_URL_SCHEMA_PREFIX = /^(https?|\/\/)/;
@@ -278,7 +281,11 @@ export function getModuleIdentity(req) {
278
281
  }
279
282
  export function getMappingIdentity(req) {
280
283
  const { specifiers } = req.params;
281
- const moduleIds = explodeSpecifiers(specifiers);
284
+ const modifiers = req.query.importer ? { importer: decodeURIComponent(req.query.importer) } : {};
285
+ const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
286
+ ...obj,
287
+ ...modifiers,
288
+ }));
282
289
  return {
283
290
  moduleIds,
284
291
  };
@@ -10,7 +10,9 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
10
10
  index: {},
11
11
  };
12
12
  for (const moduleId of moduleIds) {
13
- const specifier = getSpecifier(moduleId);
13
+ const requestedSpecifier = getSpecifier(moduleId);
14
+ // eslint-disable-next-line no-await-in-loop
15
+ const specifier = await getVersionedSpecifier(moduleId, moduleRegistry);
14
16
  // Check if we have already visited
15
17
  if (!visitedCache.has(specifier)) {
16
18
  // Traversal of the Module Graph is done to get all the URLs for discoverable dependencies.
@@ -27,6 +29,15 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
27
29
  // eslint-disable-next-line no-await-in-loop
28
30
  importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
29
31
  }
32
+ // If the requested specifier is not the same as the versioned specifier, include the requested specifier's importer.
33
+ if (requestedSpecifier !== specifier && moduleId.importer) {
34
+ const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${encodeURIComponent(moduleId.importer)}`;
35
+ const specifiersArray = Object.values(importMetadata.imports).find((a) => a.includes(specifier));
36
+ if (!specifiersArray) {
37
+ throw new Error('Could not find: ' + specifier + ' in ' + JSON.stringify(importMetadata.imports));
38
+ }
39
+ specifiersArray.push(requestedSpecifierPlusImporter);
40
+ }
30
41
  }
31
42
  return importMetadata;
32
43
  }
@@ -141,4 +152,13 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
141
152
  await Promise.all(promises);
142
153
  return index;
143
154
  }
155
+ async function getVersionedSpecifier(moduleId, moduleRegistry) {
156
+ if (!moduleId.importer || moduleId.version) {
157
+ return getSpecifier(moduleId);
158
+ }
159
+ const versionedModuleEntry = await moduleRegistry.getModuleEntry({
160
+ ...moduleId,
161
+ });
162
+ return getSpecifier(versionedModuleEntry);
163
+ }
144
164
  //# sourceMappingURL=mappings.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.4",
7
+ "version": "0.7.0-alpha.2",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -43,13 +43,13 @@
43
43
  "slugify": "^1.4.5"
44
44
  },
45
45
  "devDependencies": {
46
- "@lwrjs/diagnostics": "0.6.4",
47
- "@lwrjs/types": "0.6.4",
46
+ "@lwrjs/diagnostics": "0.7.0-alpha.2",
47
+ "@lwrjs/types": "0.7.0-alpha.2",
48
48
  "@types/mime-types": "2.1.1",
49
49
  "@types/path-to-regexp": "^1.7.0"
50
50
  },
51
51
  "engines": {
52
52
  "node": ">=14.15.4 <17"
53
53
  },
54
- "gitHead": "80b73fe4558dc3db0afcdbe80eb17f5a1464e34e"
54
+ "gitHead": "fc3a13d1c5440833eb2ec17fbf0e294554bafa08"
55
55
  }