@lwrjs/shared-utils 0.6.0-alpha.14 → 0.6.0-alpha.15

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.
@@ -38,7 +38,10 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
38
38
  for (const moduleId of moduleIds) {
39
39
  const specifier = (0, import_identity.getSpecifier)(moduleId);
40
40
  if (!visitedCache.has(specifier)) {
41
- const depth = {static: import_graph.GraphDepth.ALL, dynamic: 0};
41
+ const depth = {
42
+ static: runtimeEnvironment.format === "esm" ? import_graph.GraphDepth.NONE : import_graph.GraphDepth.ALL,
43
+ dynamic: runtimeEnvironment.format === "esm" ? 1 : 0
44
+ };
42
45
  const moduleGraph = await (0, import_graph.getModuleGraphs)(specifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, runtimeEnvironment.bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
43
46
  importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
44
47
  }
@@ -57,15 +60,20 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
57
60
  }
58
61
  const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, moduleRegistry, runtimeEnvironment, runtimeParams);
59
62
  let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
60
- const depSpecifiers = moduleGraph.graphs[0].static;
63
+ const depSpecifiers = runtimeEnvironment.format === "esm" ? moduleGraph.graphs[0].dynamicRefs : moduleGraph.graphs[0].static;
61
64
  for (const depSpecifier of depSpecifiers) {
62
65
  const depUri = moduleGraph.uriMap[depSpecifier];
63
66
  const depDef = moduleGraph.linkedDefinitions[depSpecifier];
64
- if (!depUri) {
65
- throw new Error("URI was not included in the graph for dependent: " + depSpecifier);
66
- }
67
- if (!depDef) {
68
- throw new Error("Linked dependent module definition was not included in the graph: " + depSpecifier);
67
+ const depMissing = !depUri || !depDef;
68
+ if (depMissing && runtimeEnvironment.format !== "esm") {
69
+ if (!depUri) {
70
+ throw new Error("URI was not included in the graph for dependent: " + depSpecifier);
71
+ }
72
+ if (!depDef) {
73
+ throw new Error("Linked dependent module definition was not included in the graph: " + depSpecifier);
74
+ }
75
+ } else if (depMissing) {
76
+ continue;
69
77
  }
70
78
  if (!importMetadata.imports[depUri]) {
71
79
  const depMetadata = await normalizeImportMetadata((0, import_identity.getSpecifier)(depDef), depUri, depDef, moduleRegistry, runtimeEnvironment, runtimeParams);
@@ -13,8 +13,12 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
13
13
  const specifier = getSpecifier(moduleId);
14
14
  // Check if we have already visited
15
15
  if (!visitedCache.has(specifier)) {
16
- // Traversal of the Module Graph is done to get all the URLS for discoverable static dependencies.
17
- const depth = { static: GraphDepth.ALL, dynamic: 0 };
16
+ // Traversal of the Module Graph is done to get all the URLs for discoverable dependencies.
17
+ // AMD gathers static imports while ESM gathers dynamic imports
18
+ const depth = {
19
+ static: runtimeEnvironment.format === 'esm' ? GraphDepth.NONE : GraphDepth.ALL,
20
+ dynamic: runtimeEnvironment.format === 'esm' ? 1 : 0,
21
+ };
18
22
  // eslint-disable-next-line no-await-in-loop
19
23
  const moduleGraph = await getModuleGraphs(specifier,
20
24
  // include uris and linked definitions
@@ -52,16 +56,27 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
52
56
  // Merge in the existing metadata with imports for the root specifier
53
57
  const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, moduleRegistry, runtimeEnvironment, runtimeParams);
54
58
  let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
55
- // root module dependencies
56
- const depSpecifiers = moduleGraph.graphs[0].static;
59
+ // root module dependencies:
60
+ // - static for AMD; dynamic dependencies require a new mapping request
61
+ // - dynamic for ESM; static dependencies are imported via fully qualified URLs
62
+ const depSpecifiers = runtimeEnvironment.format === 'esm'
63
+ ? moduleGraph.graphs[0].dynamicRefs
64
+ : moduleGraph.graphs[0].static;
57
65
  for (const depSpecifier of depSpecifiers) {
58
66
  const depUri = moduleGraph.uriMap[depSpecifier];
59
67
  const depDef = moduleGraph.linkedDefinitions[depSpecifier];
60
- if (!depUri) {
61
- throw new Error('URI was not included in the graph for dependent: ' + depSpecifier);
68
+ const depMissing = !depUri || !depDef;
69
+ if (depMissing && runtimeEnvironment.format !== 'esm') {
70
+ if (!depUri) {
71
+ throw new Error('URI was not included in the graph for dependent: ' + depSpecifier);
72
+ }
73
+ if (!depDef) {
74
+ throw new Error('Linked dependent module definition was not included in the graph: ' + depSpecifier);
75
+ }
62
76
  }
63
- if (!depDef) {
64
- throw new Error('Linked dependent module definition was not included in the graph: ' + depSpecifier);
77
+ else if (depMissing) {
78
+ // Ignore variable dynamic imports
79
+ continue;
65
80
  }
66
81
  if (!importMetadata.imports[depUri]) {
67
82
  // eslint-disable-next-line no-await-in-loop
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.14",
7
+ "version": "0.6.0-alpha.15",
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.0-alpha.14",
47
- "@lwrjs/types": "0.6.0-alpha.14",
46
+ "@lwrjs/diagnostics": "0.6.0-alpha.15",
47
+ "@lwrjs/types": "0.6.0-alpha.15",
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": "2850ceddcf17cdc561abbdbeb465edc5d5391cfa"
54
+ "gitHead": "ebff01c190ee6f2777028f103e51446a1a8f00f7"
55
55
  }