@lwrjs/shared-utils 0.6.0-alpha.9 → 0.6.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.
@@ -31,6 +31,5 @@ __exportStar(exports, __toModule(require("./typescript.cjs")));
31
31
  __exportStar(exports, __toModule(require("./import-metadata.cjs")));
32
32
  __exportStar(exports, __toModule(require("./graph.cjs")));
33
33
  __exportStar(exports, __toModule(require("./mappings.cjs")));
34
- __exportStar(exports, __toModule(require("./metrics.cjs")));
35
34
  __exportStar(exports, __toModule(require("./urls.cjs")));
36
35
  __exportStar(exports, __toModule(require("./env.cjs")));
@@ -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);
@@ -32,10 +32,12 @@ __export(exports, {
32
32
  });
33
33
  var import_path_to_regexp = __toModule(require("path-to-regexp"));
34
34
  var CONFIG_SUFFIX = "/config.js";
35
- function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams) {
35
+ var SIGNATURE_SIGIL = "s";
36
+ function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams, signature) {
36
37
  const encodeUrl = encodeURIComponent(routeInfo.url);
37
38
  const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams);
38
- return `${configUrlPrefix}/${encodeUrl}${CONFIG_SUFFIX}`;
39
+ const signatureSegment = signature ? `/${SIGNATURE_SIGIL}/${signature}` : "";
40
+ return `${configUrlPrefix}/${encodeUrl}${signatureSegment}${CONFIG_SUFFIX}`;
39
41
  }
40
42
  function getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams) {
41
43
  const {apiVersion, format} = runtimeEnvironment;
@@ -64,7 +66,11 @@ function getClientBootstrapConfigurationRoutes() {
64
66
  `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
65
67
  `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
66
68
  `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
67
- `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`
69
+ `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
70
+ `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
71
+ `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
72
+ `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
73
+ `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`
68
74
  ];
69
75
  }
70
76
  function extractRequestParams(parameterizedRoute, resolvedUrl, existingParams) {
@@ -10,7 +10,6 @@ export * from './typescript.js';
10
10
  export * from './import-metadata.js';
11
11
  export * from './graph.js';
12
12
  export * from './mappings.js';
13
- export * from './metrics.js';
14
13
  export * from './urls.js';
15
14
  export * from './env.js';
16
15
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -10,7 +10,6 @@ export * from './typescript.js';
10
10
  export * from './import-metadata.js';
11
11
  export * from './graph.js';
12
12
  export * from './mappings.js';
13
- export * from './metrics.js';
14
13
  export * from './urls.js';
15
14
  export * from './env.js';
16
15
  //# sourceMappingURL=index.js.map
@@ -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
@@ -2,7 +2,7 @@ import { RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
2
  export declare function getClientBootstrapConfigurationUri(routeInfo: {
3
3
  id: string;
4
4
  url: string;
5
- }, runtimeEnvironment: Required<Pick<RuntimeEnvironment, 'apiVersion' | 'format'>>, runtimeParams?: RuntimeParams): string;
5
+ }, runtimeEnvironment: Required<Pick<RuntimeEnvironment, 'apiVersion' | 'format'>>, runtimeParams?: RuntimeParams, signature?: string): string;
6
6
  export declare function getClientBootstrapConfigurationUriPrefix(routeInfo: {
7
7
  id: string;
8
8
  }, runtimeEnvironment: Required<Pick<RuntimeEnvironment, 'apiVersion' | 'format'>>, runtimeParams?: RuntimeParams): string;
package/build/es/urls.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { pathToRegexp } from 'path-to-regexp';
2
2
  const CONFIG_SUFFIX = '/config.js';
3
- export function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams) {
3
+ const SIGNATURE_SIGIL = 's';
4
+ export function getClientBootstrapConfigurationUri(routeInfo, runtimeEnvironment, runtimeParams, signature) {
4
5
  const encodeUrl = encodeURIComponent(routeInfo.url);
5
6
  const configUrlPrefix = getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams);
6
- return `${configUrlPrefix}/${encodeUrl}${CONFIG_SUFFIX}`;
7
+ const signatureSegment = signature ? `/${SIGNATURE_SIGIL}/${signature}` : '';
8
+ return `${configUrlPrefix}/${encodeUrl}${signatureSegment}${CONFIG_SUFFIX}`;
7
9
  }
8
10
  export function getClientBootstrapConfigurationUriPrefix(routeInfo, runtimeEnvironment, runtimeParams) {
9
11
  const { apiVersion, format } = runtimeEnvironment;
@@ -42,6 +44,11 @@ export function getClientBootstrapConfigurationRoutes() {
42
44
  `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
43
45
  `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
44
46
  `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath${CONFIG_SUFFIX}`,
47
+ // with signature
48
+ `/:apiVersion/application/:format/l/:locale/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
49
+ `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
50
+ `/:apiVersion/application/:format/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
51
+ `/:apiVersion/application/:format/e/:environment/ai/:appId/configuration/ci/:encodedViewPath/s/:signature${CONFIG_SUFFIX}`,
45
52
  ];
46
53
  }
47
54
  /**
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.9",
7
+ "version": "0.6.0",
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.9",
47
- "@lwrjs/types": "0.6.0-alpha.9",
46
+ "@lwrjs/diagnostics": "0.6.0",
47
+ "@lwrjs/types": "0.6.0",
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": "9cb371a5d01ef345660138a48fe0b3f0119d0799"
54
+ "gitHead": "31769655f0155ad7e54cf37bccdf72d0baaf44ab"
55
55
  }
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
- var __export = (target, all) => {
4
- for (var name in all)
5
- __defProp(target, name, {get: all[name], enumerable: true});
6
- };
7
-
8
- // packages/@lwrjs/shared-utils/src/metrics.ts
9
- __markAsModule(exports);
10
- __export(exports, {
11
- ON_APP_INIT: () => ON_APP_INIT,
12
- ON_APP_LOAD: () => ON_APP_LOAD
13
- });
14
- var ON_APP_LOAD = "lwr-bootstrap-on-app-load";
15
- var ON_APP_INIT = "lwr-bootstrap-on-app-init";
@@ -1,5 +0,0 @@
1
- import { LWRBootstrapMetrics } from '@lwrjs/types';
2
- declare const ON_APP_LOAD: LWRBootstrapMetrics;
3
- declare const ON_APP_INIT: LWRBootstrapMetrics;
4
- export { ON_APP_LOAD, ON_APP_INIT };
5
- //# sourceMappingURL=metrics.d.ts.map
@@ -1,6 +0,0 @@
1
- // Measure the point just before the app is requested
2
- const ON_APP_LOAD = 'lwr-bootstrap-on-app-load';
3
- // Measure the point where the app has been defined via customElements.define
4
- const ON_APP_INIT = 'lwr-bootstrap-on-app-init';
5
- export { ON_APP_LOAD, ON_APP_INIT };
6
- //# sourceMappingURL=metrics.js.map