@lwrjs/client-modules 0.6.0-alpha.7 → 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.
@@ -0,0 +1,21 @@
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`; // Loader: modules
7
+
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
+ export const MODULE_AVAILABILITY = `${LOADER_PREFIX}module.availability`; // Loader: mappings
16
+
17
+ export const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
18
+ export const MAPPINGS_FETCH_COUNT = `${MAPPINGS_FETCH}.count`;
19
+ export const MAPPINGS_FETCH_DURATION = `${MAPPINGS_FETCH}.duration`;
20
+ export const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
21
+ export const MAPPINGS_AVAILABILITY = `${LOADER_PREFIX}mappings.availability`;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * This module is called in the ABS module (app bootstrap module) to perform neccesary pre initialization steps for an LWR app.
3
+ * Note: this module should be imported before other dependencies in the ABS
4
+ */
5
+ const lwrGlobals = globalThis.LWR;
6
+
7
+ if (globalThis.LWR.define) {
8
+ // AMD only
9
+ globalThis.LWR = Object.freeze({
10
+ define: globalThis.LWR.define
11
+ });
12
+ } else {
13
+ delete globalThis.LWR;
14
+ }
15
+
16
+ export function getClientBootstrapConfig() {
17
+ return lwrGlobals;
18
+ }
@@ -0,0 +1,57 @@
1
+ var Phase;
2
+
3
+ (function (Phase) {
4
+ Phase[Phase["Start"] = 0] = "Start";
5
+ Phase[Phase["End"] = 1] = "End";
6
+ })(Phase || (Phase = {}));
7
+
8
+ // Attach a custom dispatcher
9
+ let customDispatcher;
10
+ export function attachDispatcher(dispatcher) {
11
+ customDispatcher = dispatcher;
12
+ } // Check if the Performance API is available
13
+ // e.g. JSDom (used in Jest) doesn't implement these
14
+
15
+ const perf = globalThis.performance;
16
+ const isPerfSupported = typeof perf !== 'undefined' && typeof perf.mark === 'function' && typeof perf.clearMarks === 'function' && typeof perf.measure === 'function' && typeof perf.clearMeasures === 'function'; // For marking request metrics
17
+ // Fallback to the Performance API if there is no custom dispatcher
18
+
19
+ export function logOperationStart({
20
+ id,
21
+ specifier
22
+ }) {
23
+ if (customDispatcher) {
24
+ customDispatcher({
25
+ id,
26
+ phase: Phase.Start,
27
+ specifier
28
+ });
29
+ } else if (isPerfSupported) {
30
+ perf.mark(id + (specifier ? `.${specifier}` : ''));
31
+ }
32
+ } // For measuring duration metrics
33
+ // Fallback to the Performance API if there is no custom dispatcher
34
+
35
+ /* istanbul ignore next */
36
+
37
+ export function logOperationEnd({
38
+ id,
39
+ specifier
40
+ }) {
41
+ if (customDispatcher) {
42
+ customDispatcher({
43
+ id,
44
+ phase: Phase.End,
45
+ specifier
46
+ });
47
+ } else if (isPerfSupported) {
48
+ const suffix = specifier ? `.${specifier}` : '';
49
+ const markName = id + suffix;
50
+ const measureName = `${id}.duration${suffix}`;
51
+ perf.measure(measureName, markName); // Clear the created mark and measure to avoid filling the performance entry buffer
52
+ // Even if they get deleted, existing PerformanceObservers preserve copies of the entries
53
+
54
+ perf.clearMarks(markName);
55
+ perf.clearMeasures(measureName);
56
+ }
57
+ }
@@ -1,11 +1,28 @@
1
1
  import { registerHandleStaleModuleHook } from './handleStaleModuleESM';
2
+ import { getClientBootstrapConfig } from 'lwr/preInit';
2
3
 
3
4
  const noop = () => {
4
5
  console.warn('API is not supported in ESM format');
5
6
  };
6
7
 
8
+ function getAppMetadata() {
9
+ const {
10
+ appId,
11
+ bootstrapModule,
12
+ rootComponent,
13
+ rootComponents
14
+ } = getClientBootstrapConfig();
15
+ return {
16
+ appId,
17
+ bootstrapModule,
18
+ rootComponent,
19
+ rootComponents
20
+ };
21
+ }
22
+
7
23
  export const services = {
8
24
  // addLoaderPlugin is only supported in AMD
9
25
  addLoaderPlugin: noop,
10
- handleStaleModule: registerHandleStaleModuleHook
26
+ handleStaleModule: registerHandleStaleModuleHook,
27
+ appMetadata: getAppMetadata()
11
28
  };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.7",
7
+ "version": "0.6.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -31,8 +31,8 @@
31
31
  "build:bundle": "rollup --config scripts/rollup.moduleBundle.config.cjs"
32
32
  },
33
33
  "dependencies": {
34
- "@locker/sandbox": "0.14.19",
35
- "@lwrjs/shared-utils": "0.6.0-alpha.7"
34
+ "@locker/sandbox": "0.15.6",
35
+ "@lwrjs/shared-utils": "0.6.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "rollup-plugin-terser": "^7.0.2"
@@ -45,15 +45,18 @@
45
45
  ],
46
46
  "expose": [
47
47
  "lwr/hmr",
48
+ "lwr/preInit",
48
49
  "lwr/init",
49
50
  "lwr/initSsr",
50
51
  "lwr/servicesESM",
51
52
  "lwr/lockerDefine",
52
- "lwr/lockerSandbox"
53
+ "lwr/lockerSandbox",
54
+ "lwr/metrics",
55
+ "lwr/profiler"
53
56
  ]
54
57
  },
55
58
  "engines": {
56
59
  "node": ">=14.15.4 <17"
57
60
  },
58
- "gitHead": "dc066450384dc1e27064b46ddd5f24543758a414"
61
+ "gitHead": "31769655f0155ad7e54cf37bccdf72d0baaf44ab"
59
62
  }