@lwrjs/client-modules 0.5.11 → 0.6.0-alpha.12

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.
@@ -1 +1 @@
1
- import{createElement as e}from"lwc";function o(o,t){return e(o,{is:t})}function t(e){return e.replace(/\/v\/[a-zA-Z0-9-_.]+$/,"").replace("/","-").replace(/([A-Z])/g,(e=>`-${e.toLowerCase()}`))}const n=/-([a-z])/g;function r(e){return e.replace(n,(e=>e[1].toUpperCase()))}function c(e){if("undefined"!=typeof customElements&&"undefined"!=typeof document){const n=document.querySelector("[lwr-root]");e.forEach((([e,c])=>{const l=t(e);let a=document.body.querySelector(l);if(a){document.querySelectorAll(l).forEach((e=>{const t=o(l,c);for(const{name:o,value:n}of e.attributes){t.setAttribute(o,n);const e=r(o);e in t&&(t[e]=n)}for(;e.childNodes.length>0;)t.appendChild(e.childNodes[0]);if(e.parentElement.replaceChild(t,e),globalThis.performance){const e="lwr-bootstrap-on-app-init";globalThis.performance.measure(e)}}))}else a=o(l,c),n?n.appendChild(a):document.body.appendChild(a)}))}}export{r as getPropFromAttrName,c as init,t as toKebabCase};
1
+ import{BOOTSTRAP_END as e}from"lwr/metrics";import{logOperationStart as o}from"lwr/profiler";import{createElement as t}from"lwc";function r(e,o){return t(e,{is:o})}function n(e){return e.replace(/\/v\/[a-zA-Z0-9-_.]+$/,"").replace("/","-").replace(/([A-Z])/g,(e=>`-${e.toLowerCase()}`))}const c=/-([a-z])/g;function l(e){return e.replace(c,(e=>e[1].toUpperCase()))}function i(t){if("undefined"!=typeof customElements&&"undefined"!=typeof document){const e=document.querySelector("[lwr-root]");t.forEach((([o,t])=>{const c=n(o);let i=document.body.querySelector(c);if(i){document.querySelectorAll(c).forEach((e=>{const o=r(c,t);for(const{name:t,value:r}of e.attributes){o.setAttribute(t,r);const e=l(t);e in o&&(o[e]=r)}for(;e.childNodes.length>0;)o.appendChild(e.childNodes[0]);if(e.parentElement.replaceChild(o,e),globalThis.performance){const e="lwr-bootstrap-on-app-init";globalThis.performance.measure(e)}}))}else i=r(c,t),e?e.appendChild(i):document.body.appendChild(i)}))}o({id:e})}export{l as getPropFromAttrName,i as init,n as toKebabCase};
@@ -1 +1 @@
1
- const e=[];let n;const o={addLoaderPlugin:()=>{console.warn("API is not supported in ESM format")},handleStaleModule:function(o){e.push(o),n||(n=new WebSocket(`ws://${location.host}`),n.addEventListener("message",(async({data:n})=>{const o=JSON.parse(n);if("moduleUpdate"===o.eventType){const{oldHash:n,newHash:a,module:{specifier:t}}=o.payload;for(let o=0;o<e.length;o++){if(null!==(0,e[o])({name:t,oldHash:n,newHash:a}))break}}})))}};export{o as services};
1
+ const o=[];let e;const t=globalThis.LWR;globalThis.LWR.define?globalThis.LWR=Object.freeze({define:globalThis.LWR.define}):delete globalThis.LWR;const n={addLoaderPlugin:()=>{console.warn("API is not supported in ESM format")},handleStaleModule:function(t){o.push(t),e||(e=new WebSocket(`ws://${location.host}`),e.addEventListener("message",(async({data:e})=>{const t=JSON.parse(e);if("moduleUpdate"===t.eventType){const{oldHash:e,newHash:n,module:{specifier:a}}=t.payload;for(let t=0;t<o.length;t++){if(null!==(0,o[t])({name:a,oldHash:e,newHash:n}))break}}})))},appMetadata:function(){const{bootstrapModule:o,rootComponent:e,rootComponents:n}=t;return{bootstrapModule:o,rootComponent:e,rootComponents:n}}()};export{n as services};
@@ -1,6 +1,8 @@
1
- // TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2083 is sorted
1
+ import { BOOTSTRAP_END } from 'lwr/metrics';
2
+ import { logOperationStart } from 'lwr/profiler'; // TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2083 is sorted
2
3
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
4
  // @ts-ignore
5
+
4
6
  import { createElement } from 'lwc';
5
7
 
6
8
  function initializeWebComponent(elementName, Ctor) {
@@ -96,4 +98,8 @@ export function init(rootModules) {
96
98
  }
97
99
  });
98
100
  }
101
+
102
+ logOperationStart({
103
+ id: BOOTSTRAP_END
104
+ });
99
105
  }
@@ -0,0 +1,40 @@
1
+ // TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2083 is sorted
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-ignore
4
+ import { hydrateComponent } from 'lwc';
5
+ export function toKebabCase(specifier) {
6
+ return specifier.replace(/\/v\/[a-zA-Z0-9-_.]+$/, '').replace('/', '-').replace(/([A-Z])/g, c => `-${c.toLowerCase()}`);
7
+ }
8
+ /**
9
+ * This method maps between attribute names
10
+ * and the corresponding props name.
11
+ */
12
+
13
+ const CAMEL_REGEX = /-([a-z])/g;
14
+ export function getPropFromAttrName(propName) {
15
+ return propName.replace(CAMEL_REGEX, g => g[1].toUpperCase());
16
+ }
17
+ /**
18
+ * Hydrate the given components component(s).
19
+ * @param components - An array of arrays, each one holding a pair of
20
+ * bare specifier and corresponding LightningElement constructor
21
+ * @example - [['x/appRoot', appCtor], ['x/nav', navCtor]]
22
+ */
23
+
24
+ export function init(components) {
25
+ if (typeof document !== 'undefined') {
26
+ components.forEach(([moduleSpecifier, ctor]) => {
27
+ // Kebab-case the specifier
28
+ const elementName = toKebabCase(moduleSpecifier);
29
+ const customElements = document.querySelectorAll(elementName);
30
+ customElements.forEach(customElement => {
31
+ hydrateComponent(customElement, ctor, {});
32
+ });
33
+ });
34
+
35
+ if (globalThis.performance) {
36
+ const metric = 'lwr-bootstrap-on-app-init';
37
+ globalThis.performance.measure(metric);
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,19 @@
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`; // Loader: mappings
15
+
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`;
@@ -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,26 @@
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
+ bootstrapModule,
11
+ rootComponent,
12
+ rootComponents
13
+ } = getClientBootstrapConfig();
14
+ return {
15
+ bootstrapModule,
16
+ rootComponent,
17
+ rootComponents
18
+ };
19
+ }
20
+
7
21
  export const services = {
8
22
  // addLoaderPlugin is only supported in AMD
9
23
  addLoaderPlugin: noop,
10
- handleStaleModule: registerHandleStaleModuleHook
24
+ handleStaleModule: registerHandleStaleModuleHook,
25
+ appMetadata: getAppMetadata()
11
26
  };
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.5.11",
8
- "homepage": "https://lwr.dev/",
7
+ "version": "0.6.0-alpha.12",
8
+ "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/salesforce/lwr.git",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@locker/sandbox": "0.14.19",
35
- "@lwrjs/shared-utils": "0.5.11"
35
+ "@lwrjs/shared-utils": "0.6.0-alpha.12"
36
36
  },
37
37
  "devDependencies": {
38
38
  "rollup-plugin-terser": "^7.0.2"
@@ -45,14 +45,18 @@
45
45
  ],
46
46
  "expose": [
47
47
  "lwr/hmr",
48
+ "lwr/preInit",
48
49
  "lwr/init",
50
+ "lwr/initSsr",
49
51
  "lwr/servicesESM",
50
52
  "lwr/lockerDefine",
51
- "lwr/lockerSandbox"
53
+ "lwr/lockerSandbox",
54
+ "lwr/metrics",
55
+ "lwr/profiler"
52
56
  ]
53
57
  },
54
58
  "engines": {
55
59
  "node": ">=14.15.4 <17"
56
60
  },
57
- "gitHead": "2ee810c0a4f1f36d1e0f8378a1fe00c19b4c5bc1"
61
+ "gitHead": "876b56ca4f98f3299303f2193c0dec8f46a69b84"
58
62
  }