@lwrjs/loader 0.6.0-alpha.11 → 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.
@@ -33,7 +33,7 @@ var import_scriptLoad = __toModule(require("./scriptLoad"));
33
33
  var import_importMetadataResolver = __toModule(require("./importMetadataResolver"));
34
34
  var import_moduleInvalidation = __toModule(require("../hooks/moduleInvalidation"));
35
35
  var import_resolveAndLoadHook = __toModule(require("../hooks/resolveAndLoadHook"));
36
- var import_metrics = __toModule(require("../../../../metrics"));
36
+ var import_metrics = __toModule(require("lwr/metrics"));
37
37
  var import_constants = __toModule(require("../constants/constants"));
38
38
  var ModuleRegistry = class {
39
39
  constructor(config) {
@@ -33,11 +33,13 @@ var import_scriptLoad = __toModule(require("./scriptLoad"));
33
33
  var import_resolveAndLoadHook = __toModule(require("../hooks/resolveAndLoadHook"));
34
34
  var import_moduleInvalidation = __toModule(require("../hooks/moduleInvalidation"));
35
35
  var import_constants = __toModule(require("../constants/constants"));
36
+ var import_metrics = __toModule(require("lwr/metrics"));
36
37
  var ModuleRegistry = class {
37
- constructor(baseUrl) {
38
+ constructor(config) {
38
39
  this.namedDefineRegistry = new Map();
39
40
  this.moduleRegistry = new Map();
40
- this.baseUrl = baseUrl;
41
+ this.baseUrl = config.baseUrl;
42
+ this.profiler = config.profiler;
41
43
  }
42
44
  async load(id, importer) {
43
45
  const resolvedId = await this.resolve(id, importer);
@@ -137,6 +139,7 @@ var ModuleRegistry = class {
137
139
  if (mod && mod.external) {
138
140
  mod.external.resolveExternal(moduleDef);
139
141
  }
142
+ this.profiler.logOperationStart({id: import_metrics.MODULE_DEFINE, specifier: name});
140
143
  this.namedDefineRegistry.set(name, moduleDef);
141
144
  this.lastDefine = moduleDef;
142
145
  if (signatures.hashes) {
@@ -353,6 +356,8 @@ var ModuleRegistry = class {
353
356
  return moduleDef;
354
357
  }
355
358
  const parentUrl = this.baseUrl;
359
+ const specifier = moduleName || originalId;
360
+ this.profiler.logOperationStart({id: import_metrics.MODULE_FETCH, specifier});
356
361
  return Promise.resolve().then(async () => {
357
362
  const loadHooks = this.loadHook;
358
363
  if (loadHooks) {
@@ -381,8 +386,10 @@ var ModuleRegistry = class {
381
386
  if (!moduleDef) {
382
387
  throw new import_messages.LoaderError(import_messages.FAIL_INSTANTIATE, [resolvedId]);
383
388
  }
389
+ this.profiler.logOperationEnd({id: import_metrics.MODULE_FETCH, specifier});
384
390
  return moduleDef;
385
391
  }).catch((e) => {
392
+ this.profiler.logOperationStart({id: import_metrics.MODULE_ERROR, specifier});
386
393
  throw e;
387
394
  });
388
395
  }
@@ -4,14 +4,25 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- /* LWR ESM Module Loader v0.6.0-alpha.11 */
7
+ /* LWR ESM Module Loader v0.6.0-alpha.15 */
8
8
  /**
9
9
  * Simplified version of the AMD Import Metadata Resolver.
10
10
  * Just reads the ImportMetadata at construction time.
11
11
  */
12
12
  class ImportResolver {
13
- constructor(importMetada) {
13
+ constructor(config) {
14
+ var _a, _b;
14
15
  this.importURICache = new Map();
16
+ this.modifiers = '';
17
+ this.normalizeMetadata(config);
18
+ // only fetch mappings if fingerprints is ON
19
+ this.mappingEndpoint = (config === null || config === void 0 ? void 0 : config.importMappings) ? undefined : (_a = config === null || config === void 0 ? void 0 : config.endpoints) === null || _a === void 0 ? void 0 : _a.uris.mapping;
20
+ if ((_b = config === null || config === void 0 ? void 0 : config.endpoints) === null || _b === void 0 ? void 0 : _b.modifiers) {
21
+ // Add URI modifiers to mapping endpoint query
22
+ this.modifiers = Object.entries(config.endpoints.modifiers).reduce((q, [k, v]) => (q += `${k}=${v}&`), '?');
23
+ }
24
+ }
25
+ normalizeMetadata(importMetada) {
15
26
  // Normalize the URI cache to optimize retrieval
16
27
  if (importMetada && importMetada.imports) {
17
28
  for (const [uri, value] of Object.entries(importMetada.imports)) {
@@ -24,8 +35,21 @@ class ImportResolver {
24
35
  }
25
36
  }
26
37
  }
27
- resolve(specifier) {
28
- return this.importURICache.get(specifier);
38
+ async fetchMappings(specifier) {
39
+ const mappingUri = `${this.mappingEndpoint}${encodeURIComponent(specifier)}${this.modifiers}`;
40
+ const res = await globalThis.fetch(mappingUri);
41
+ if (res.ok) {
42
+ const mappings = await res.json();
43
+ this.normalizeMetadata(mappings);
44
+ }
45
+ }
46
+ async resolve(specifier) {
47
+ let uri = this.importURICache.get(specifier);
48
+ if (!uri && this.mappingEndpoint) {
49
+ await this.fetchMappings(specifier);
50
+ uri = this.importURICache.get(specifier);
51
+ }
52
+ return uri;
29
53
  }
30
54
  }
31
55
 
@@ -54,21 +78,21 @@ let resolverLegacy;
54
78
  function init(config) {
55
79
  // Save config from globalThis.LWR
56
80
  esmLoaderConfig = config;
57
- const { imports, index, importMappings } = config;
58
- resolver = new ImportResolver({ imports, index });
81
+ const { imports, index, importMappings, endpoints } = config;
82
+ resolver = new ImportResolver({ imports, index, endpoints, importMappings });
59
83
  resolverLegacy = new ImportResolverLegacy(importMappings);
60
84
  }
61
- function load(specifier, importer) {
62
- const uri = resolveUrl(specifier, importer);
85
+ async function load(specifier, importer) {
86
+ const uri = await resolveUrl(specifier, importer);
63
87
  return import(uri);
64
88
  }
65
- function resolveUrl(specifier, importer) {
89
+ async function resolveUrl(specifier, importer) {
66
90
  let uri;
67
91
  if (!resolver || !resolverLegacy) {
68
92
  throw new Error('The ESM Loader was not initialized');
69
93
  }
70
94
  // Check if the URI is in the import metadata
71
- uri = resolver.resolve(specifier);
95
+ uri = await resolver.resolve(specifier);
72
96
  if (uri) {
73
97
  return uri;
74
98
  }
@@ -88,6 +112,10 @@ function resolveUrl(specifier, importer) {
88
112
  if (importer) {
89
113
  uri += `?importer=${encodeURIComponent(importer)}`;
90
114
  }
115
+ if (endpoints.modifiers) {
116
+ // Add URI modifiers to query
117
+ uri += Object.entries(endpoints.modifiers).reduce((q, [k, v]) => (q += `${k}=${v}&`), importer ? '&' : '?');
118
+ }
91
119
  }
92
120
  }
93
121
  return uri;
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- /* LWR Module Loader v0.6.0-alpha.11 */
7
+ /* LWR Module Loader v0.6.0-alpha.15 */
8
8
  const templateRegex = /\{([0-9]+)\}/g;
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  function templateString(template, args) {
@@ -301,12 +301,12 @@ if (hasDocument) {
301
301
  }
302
302
 
303
303
  // Bootstrap / shim
304
- // Loader: modules
304
+
305
305
  const LOADER_PREFIX = 'lwr.loader.';
306
306
  const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
307
307
  const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
308
- const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
309
- // Loader: mappings
308
+ const MODULE_ERROR = `${LOADER_PREFIX}module.error`; // Loader: mappings
309
+
310
310
  const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
311
311
  const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
312
312
 
@@ -1121,6 +1121,14 @@ class Loader {
1121
1121
  };
1122
1122
  }
1123
1123
  this.registry = new ModuleRegistry(Object.freeze({ endpoints: config.endpoints, baseUrl, profiler }));
1124
+ // TODO: W-10539691 - temp workaround for LWR-Java -- remove once appId is implemented there
1125
+ if (config.appMetadata && !config.appMetadata.appId) {
1126
+ // Parse the appId from the bootstrapModule
1127
+ // LWR-Java bootstrap module format: @lwr-bootstrap/my/app/v/0_0_1 -- my/app is the appId
1128
+ const match = config.appMetadata.bootstrapModule.match(/@lwr-bootstrap\/(.+)\/v\/.+/);
1129
+ const appId = match && match[1];
1130
+ config.appMetadata.appId = appId;
1131
+ }
1124
1132
  // TODO: https://github.com/salesforce/lwr/issues/1087
1125
1133
  this.services = Object.freeze({
1126
1134
  addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- /* LWR Legacy Module Loader v0.6.0-alpha.11 */
7
+ /* LWR Legacy Module Loader v0.6.0-alpha.15 */
8
8
  const templateRegex = /\{([0-9]+)\}/g;
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  function templateString(template, args) {
@@ -401,14 +401,22 @@ function evaluateHandleStaleModuleHooks(handleStaleModuleHooks, hookArgs) {
401
401
  }
402
402
  }
403
403
 
404
+ // Bootstrap / shim
405
+
406
+ const LOADER_PREFIX = 'lwr.loader.';
407
+ const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
408
+ const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
409
+ const MODULE_ERROR = `${LOADER_PREFIX}module.error`; // Loader: mappings
410
+
404
411
  /* global console,process */
405
412
  class ModuleRegistry {
406
- constructor(baseUrl) {
413
+ constructor(config) {
407
414
  // A registry for named AMD defines containing the *metadata* of AMD module
408
415
  this.namedDefineRegistry = new Map();
409
416
  // The evaluted module registry where the module identifier (name or URL?) is the key
410
417
  this.moduleRegistry = new Map();
411
- this.baseUrl = baseUrl;
418
+ this.baseUrl = config.baseUrl;
419
+ this.profiler = config.profiler;
412
420
  }
413
421
  async load(id, importer) {
414
422
  const resolvedId = await this.resolve(id, importer);
@@ -523,6 +531,7 @@ class ModuleRegistry {
523
531
  // if module is "external", resolve the external promise to notify any dependees
524
532
  mod.external.resolveExternal(moduleDef);
525
533
  }
534
+ this.profiler.logOperationStart({ id: MODULE_DEFINE, specifier: name });
526
535
  this.namedDefineRegistry.set(name, moduleDef);
527
536
  this.lastDefine = moduleDef;
528
537
  // Check signatures of dependencies against those in the namedDefineRegistry
@@ -793,6 +802,8 @@ class ModuleRegistry {
793
802
  return moduleDef;
794
803
  }
795
804
  const parentUrl = this.baseUrl; // only support baseUrl for now
805
+ const specifier = moduleName || originalId;
806
+ this.profiler.logOperationStart({ id: MODULE_FETCH, specifier });
796
807
  return Promise.resolve()
797
808
  .then(async () => {
798
809
  const loadHooks = this.loadHook;
@@ -830,9 +841,11 @@ class ModuleRegistry {
830
841
  if (!moduleDef) {
831
842
  throw new LoaderError(FAIL_INSTANTIATE, [resolvedId]);
832
843
  }
844
+ this.profiler.logOperationEnd({ id: MODULE_FETCH, specifier });
833
845
  return moduleDef;
834
846
  })
835
847
  .catch((e) => {
848
+ this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
836
849
  throw e;
837
850
  });
838
851
  }
@@ -1060,7 +1073,10 @@ async function evaluateImportMaps(baseUrl) {
1060
1073
  * The LWR loader is inspired and borrows from the algorithms and native browser principles of https://github.com/systemjs/systemjs
1061
1074
  */
1062
1075
  class Loader {
1063
- constructor(baseUrl) {
1076
+ constructor(config) {
1077
+ config = config || {};
1078
+ let baseUrl = config.baseUrl;
1079
+ let profiler = config.profiler;
1064
1080
  if (baseUrl) {
1065
1081
  // add a trailing slash, if it does not exist
1066
1082
  baseUrl = baseUrl.replace(/\/?$/, '/');
@@ -1072,10 +1088,23 @@ class Loader {
1072
1088
  throw new LoaderError(NO_BASE_URL);
1073
1089
  }
1074
1090
  this.baseUrl = baseUrl;
1075
- this.registry = new ModuleRegistry(baseUrl);
1091
+ if (!profiler) {
1092
+ // default noop profiler
1093
+ profiler = {
1094
+ logOperationStart: () => {
1095
+ /* noop */
1096
+ },
1097
+ logOperationEnd: () => {
1098
+ /* noop */
1099
+ },
1100
+ };
1101
+ }
1102
+ this.registry = new ModuleRegistry({ baseUrl, profiler });
1103
+ // TODO: https://github.com/salesforce/lwr/issues/1087
1076
1104
  this.services = Object.freeze({
1077
1105
  addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
1078
1106
  handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
1107
+ appMetadata: config.appMetadata,
1079
1108
  });
1080
1109
  }
1081
1110
  /**
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.6.0-alpha.11",
8
+ "version": "0.6.0-alpha.15",
9
9
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
10
10
  "repository": {
11
11
  "type": "git",
@@ -55,41 +55,32 @@
55
55
  "build:shim:bundle:minify": "MINIFY=true yarn build:shim:bundle",
56
56
  "build:shim": "rollup --config scripts/rollup-shim.config.cjs",
57
57
  "build:loader": "rollup --config scripts/rollup.config.cjs",
58
- "build": "tsc -b; yarn build:shim && yarn build:loader && yarn build:shim:bundle && yarn build:shim:bundle:minify"
58
+ "build:ts": "tsc -b",
59
+ "build": "yarn build:ts && yarn build:shim && yarn build:loader && yarn build:shim:bundle && yarn build:shim:bundle:minify"
59
60
  },
60
61
  "devDependencies": {
61
- "@lwrjs/compiler": "0.6.0-alpha.11",
62
- "@lwrjs/diagnostics": "0.6.0-alpha.11",
63
- "@lwrjs/types": "0.6.0-alpha.11",
62
+ "@lwrjs/compiler": "0.6.0-alpha.15",
63
+ "@lwrjs/diagnostics": "0.6.0-alpha.15",
64
+ "@lwrjs/types": "0.6.0-alpha.15",
64
65
  "rollup-plugin-terser": "^7.0.2"
65
66
  },
66
67
  "dependencies": {
67
- "@lwrjs/shared-utils": "0.6.0-alpha.11"
68
+ "@lwrjs/shared-utils": "0.6.0-alpha.15"
68
69
  },
69
70
  "lwc": {
70
71
  "modules": [
71
72
  {
72
73
  "dir": "build/modules"
73
- },
74
- {
75
- "name": "lwr/metrics",
76
- "path": "build/metrics.js"
77
- },
78
- {
79
- "name": "lwr/profiler",
80
- "path": "build/shim/profiler.js"
81
74
  }
82
75
  ],
83
76
  "expose": [
84
77
  "lwr/esmLoader",
85
78
  "lwr/loader",
86
- "lwr/loaderLegacy",
87
- "lwr/metrics",
88
- "lwr/profiler"
79
+ "lwr/loaderLegacy"
89
80
  ]
90
81
  },
91
82
  "engines": {
92
83
  "node": ">=14.15.4 <17"
93
84
  },
94
- "gitHead": "18ab72188c2d52e32cca47333951a9c76f996039"
85
+ "gitHead": "ebff01c190ee6f2777028f103e51446a1a8f00f7"
95
86
  }
@@ -1,43 +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/loader/src/metrics.ts
9
- __markAsModule(exports);
10
- __export(exports, {
11
- BOOTSTRAP_AVAILABILITY: () => BOOTSTRAP_AVAILABILITY,
12
- BOOTSTRAP_DURATION: () => BOOTSTRAP_DURATION,
13
- BOOTSTRAP_END: () => BOOTSTRAP_END,
14
- BOOTSTRAP_ERROR: () => BOOTSTRAP_ERROR,
15
- BOOTSTRAP_PREFIX: () => BOOTSTRAP_PREFIX,
16
- LOADER_PREFIX: () => LOADER_PREFIX,
17
- MAPPINGS_ERROR: () => MAPPINGS_ERROR,
18
- MAPPINGS_FETCH: () => MAPPINGS_FETCH,
19
- MAPPINGS_FETCH_COUNT: () => MAPPINGS_FETCH_COUNT,
20
- MAPPINGS_FETCH_DURATION: () => MAPPINGS_FETCH_DURATION,
21
- MODULE_DEFINE: () => MODULE_DEFINE,
22
- MODULE_DEFINE_COUNT: () => MODULE_DEFINE_COUNT,
23
- MODULE_ERROR: () => MODULE_ERROR,
24
- MODULE_FETCH: () => MODULE_FETCH,
25
- MODULE_FETCH_COUNT: () => MODULE_FETCH_COUNT,
26
- MODULE_FETCH_DURATION: () => MODULE_FETCH_DURATION
27
- });
28
- var BOOTSTRAP_PREFIX = "lwr.bootstrap.";
29
- var BOOTSTRAP_END = `${BOOTSTRAP_PREFIX}end`;
30
- var BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
31
- var BOOTSTRAP_DURATION = `${BOOTSTRAP_PREFIX}duration`;
32
- var BOOTSTRAP_AVAILABILITY = `${BOOTSTRAP_PREFIX}availability`;
33
- var LOADER_PREFIX = "lwr.loader.";
34
- var MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
35
- var MODULE_DEFINE_COUNT = `${MODULE_DEFINE}.count`;
36
- var MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
37
- var MODULE_FETCH_COUNT = `${MODULE_FETCH}.count`;
38
- var MODULE_FETCH_DURATION = `${MODULE_FETCH}.duration`;
39
- var MODULE_ERROR = `${LOADER_PREFIX}module.error`;
40
- var MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
41
- var MAPPINGS_FETCH_COUNT = `${MAPPINGS_FETCH}.count`;
42
- var MAPPINGS_FETCH_DURATION = `${MAPPINGS_FETCH}.duration`;
43
- var MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
@@ -1,18 +0,0 @@
1
- export declare type LWRMetric = 'lwr.bootstrap.end' | 'lwr.bootstrap.error' | 'lwr.loader.module.define' | 'lwr.loader.module.fetch' | 'lwr.loader.mappings.fetch' | 'lwr.loader.module.error' | 'lwr.loader.mappings.error';
2
- export declare const BOOTSTRAP_PREFIX = "lwr.bootstrap.";
3
- export declare const BOOTSTRAP_END: LWRMetric;
4
- export declare const BOOTSTRAP_ERROR: LWRMetric;
5
- export declare const BOOTSTRAP_DURATION: string;
6
- export declare const BOOTSTRAP_AVAILABILITY: string;
7
- export declare const LOADER_PREFIX = "lwr.loader.";
8
- export declare const MODULE_DEFINE: LWRMetric;
9
- export declare const MODULE_DEFINE_COUNT: string;
10
- export declare const MODULE_FETCH: LWRMetric;
11
- export declare const MODULE_FETCH_COUNT: string;
12
- export declare const MODULE_FETCH_DURATION: string;
13
- export declare const MODULE_ERROR: LWRMetric;
14
- export declare const MAPPINGS_FETCH: LWRMetric;
15
- export declare const MAPPINGS_FETCH_COUNT: string;
16
- export declare const MAPPINGS_FETCH_DURATION: string;
17
- export declare const MAPPINGS_ERROR: LWRMetric;
18
- //# sourceMappingURL=metrics.d.ts.map
package/build/metrics.js DELETED
@@ -1,20 +0,0 @@
1
- // Bootstrap / shim
2
- export const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
3
- export const BOOTSTRAP_END = `${BOOTSTRAP_PREFIX}end`;
4
- export const BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
5
- export const BOOTSTRAP_DURATION = `${BOOTSTRAP_PREFIX}duration`;
6
- export const BOOTSTRAP_AVAILABILITY = `${BOOTSTRAP_PREFIX}availability`;
7
- // Loader: modules
8
- export const LOADER_PREFIX = 'lwr.loader.';
9
- export const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
10
- export const MODULE_DEFINE_COUNT = `${MODULE_DEFINE}.count`;
11
- export const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
12
- export const MODULE_FETCH_COUNT = `${MODULE_FETCH}.count`;
13
- export const MODULE_FETCH_DURATION = `${MODULE_FETCH}.duration`;
14
- export const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
15
- // Loader: mappings
16
- export const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
17
- export const MAPPINGS_FETCH_COUNT = `${MAPPINGS_FETCH}.count`;
18
- export const MAPPINGS_FETCH_DURATION = `${MAPPINGS_FETCH}.duration`;
19
- export const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
20
- //# sourceMappingURL=metrics.js.map
@@ -1,23 +0,0 @@
1
- import { LWRMetric } from '../metrics';
2
- declare const enum Phase {
3
- Start = 0,
4
- End = 1
5
- }
6
- interface LWRLogInfo {
7
- id: LWRMetric;
8
- specifier?: string;
9
- }
10
- interface LWRDispatcherInfo extends LWRLogInfo {
11
- phase: Phase;
12
- }
13
- declare type LogOperation = (info: LWRLogInfo) => void;
14
- export declare type LogDispatcher = (info: LWRDispatcherInfo) => void;
15
- export interface ProfilerAPI {
16
- logOperationStart: LogOperation;
17
- logOperationEnd: LogOperation;
18
- }
19
- export declare function attachDispatcher(dispatcher: LogDispatcher): void;
20
- export declare function logOperationStart({ id, specifier }: LWRLogInfo): void;
21
- export declare function logOperationEnd({ id, specifier }: LWRLogInfo): void;
22
- export {};
23
- //# sourceMappingURL=profiler.d.ts.map
@@ -1,47 +0,0 @@
1
- var Phase;
2
- (function (Phase) {
3
- Phase[Phase["Start"] = 0] = "Start";
4
- Phase[Phase["End"] = 1] = "End";
5
- })(Phase || (Phase = {}));
6
- // Attach a custom dispatcher
7
- let customDispatcher;
8
- export function attachDispatcher(dispatcher) {
9
- customDispatcher = dispatcher;
10
- }
11
- // Check if the Performance API is available
12
- // e.g. JSDom (used in Jest) doesn't implement these
13
- const perf = globalThis.performance;
14
- const isPerfSupported = typeof perf !== 'undefined' &&
15
- typeof perf.mark === 'function' &&
16
- typeof perf.clearMarks === 'function' &&
17
- typeof perf.measure === 'function' &&
18
- typeof perf.clearMeasures === 'function';
19
- // For marking request metrics
20
- // Fallback to the Performance API if there is no custom dispatcher
21
- export function logOperationStart({ id, specifier }) {
22
- if (customDispatcher) {
23
- customDispatcher({ id, phase: Phase.Start, specifier });
24
- }
25
- else if (isPerfSupported) {
26
- perf.mark(id + (specifier ? `.${specifier}` : ''));
27
- }
28
- }
29
- // For measuring duration metrics
30
- // Fallback to the Performance API if there is no custom dispatcher
31
- /* istanbul ignore next */
32
- export function logOperationEnd({ id, specifier }) {
33
- if (customDispatcher) {
34
- customDispatcher({ id, phase: Phase.End, specifier });
35
- }
36
- else if (isPerfSupported) {
37
- const suffix = specifier ? `.${specifier}` : '';
38
- const markName = id + suffix;
39
- const measureName = `${id}.duration${suffix}`;
40
- perf.measure(measureName, markName);
41
- // Clear the created mark and measure to avoid filling the performance entry buffer
42
- // Even if they get deleted, existing PerformanceObservers preserve copies of the entries
43
- perf.clearMarks(markName);
44
- perf.clearMeasures(measureName);
45
- }
46
- }
47
- //# sourceMappingURL=profiler.js.map