@lwrjs/shared-utils 0.7.0-alpha.1 → 0.7.0-alpha.4

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.
@@ -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);
@@ -218,7 +218,10 @@ function getModuleIdentity(req) {
218
218
  }
219
219
  function getMappingIdentity(req) {
220
220
  const {specifiers} = req.params;
221
- const moduleIds = explodeSpecifiers(specifiers);
221
+ const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
222
+ ...obj,
223
+ importer: req.query.importer
224
+ }));
222
225
  return {
223
226
  moduleIds
224
227
  };
@@ -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) {
50
+ const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${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/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);
@@ -281,7 +281,10 @@ export function getModuleIdentity(req) {
281
281
  }
282
282
  export function getMappingIdentity(req) {
283
283
  const { specifiers } = req.params;
284
- const moduleIds = explodeSpecifiers(specifiers);
284
+ const moduleIds = explodeSpecifiers(specifiers).map((obj) => ({
285
+ ...obj,
286
+ importer: req.query.importer,
287
+ }));
285
288
  return {
286
289
  moduleIds,
287
290
  };
@@ -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) {
34
+ const requestedSpecifierPlusImporter = `${requestedSpecifier}?importer=${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.7.0-alpha.1",
7
+ "version": "0.7.0-alpha.4",
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.7.0-alpha.1",
47
- "@lwrjs/types": "0.7.0-alpha.1",
46
+ "@lwrjs/diagnostics": "0.7.0-alpha.4",
47
+ "@lwrjs/types": "0.7.0-alpha.4",
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": "24245670d6908d37e465f2316f92385df63d22aa"
54
+ "gitHead": "611f98b00c050ddb2f0aca529c5d9a0d6e55cc3d"
55
55
  }