@lwc/dev-server-plugin-lex 7.0.0-6.6.3

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.
package/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Terms of Use
2
+
3
+ Copyright 2022 Salesforce, Inc. All rights reserved.
4
+
5
+ These Terms of Use govern the download, installation, and/or use of this software provided by Salesforce, Inc. (“Salesforce”) (the “Software”), were last updated on April 15, 2022, ** and constitute a legally binding agreement between you and Salesforce. If you do not agree to these Terms of Use, do not install or use the Software.
6
+
7
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the Software and derivative works subject to these Terms. These Terms shall be included in all copies or substantial portions of the Software.
8
+
9
+ Subject to the limited rights expressly granted hereunder, Salesforce reserves all rights, title, and interest in and to all intellectual property subsisting in the Software. No rights are granted to you hereunder other than as expressly set forth herein. Users residing in countries on the United States Office of Foreign Assets Control sanction list, or which are otherwise subject to a US export embargo, may not use the Software.
10
+
11
+ Implementation of the Software may require development work, for which you are responsible. The Software may contain bugs, errors and incompatibilities and is made available on an AS IS basis without support, updates, or service level commitments.
12
+
13
+ Salesforce reserves the right at any time to modify, suspend, or discontinue, the Software (or any part thereof) with or without notice. You agree that Salesforce shall not be liable to you or to any third party for any modification, suspension, or discontinuance.
14
+
15
+ You agree to defend Salesforce against any claim, demand, suit or proceeding made or brought against Salesforce by a third party arising out of or accruing from (a) your use of the Software, and (b) any application you develop with the Software that infringes any copyright, trademark, trade secret, trade dress, patent, or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy (each a “Claim Against Salesforce”), and will indemnify Salesforce from any damages, attorney fees, and costs finally awarded against Salesforce as a result of, or for any amounts paid by Salesforce under a settlement approved by you in writing of, a Claim Against Salesforce, provided Salesforce (x) promptly gives you written notice of the Claim Against Salesforce, (y) gives you sole control of the defense and settlement of the Claim Against Salesforce (except that you may not settle any Claim Against Salesforce unless it unconditionally releases Salesforce of all liability), and (z) gives you all reasonable assistance, at your expense.
16
+
17
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA, OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
18
+
19
+ These Terms of Use shall be governed exclusively by the internal laws of the State of California, without regard to its conflicts of laws rules. Each party hereby consents to the exclusive jurisdiction of the state and federal courts located in San Francisco County, California to adjudicate any dispute arising out of or relating to these Terms of Use and the download, installation, and/or use of the Software. Except as expressly stated herein, these Terms of Use constitute the entire agreement between the parties, and supersede all prior and contemporaneous agreements, proposals, or representations, written or oral, concerning their subject matter. No modification, amendment, or waiver of any provision of these Terms of Use shall be effective unless it is by an update to these Terms of Use that Salesforce makes available, or is in writing and signed by the party against whom the modification, amendment, or waiver is to be asserted.
20
+
21
+ Data Privacy: Salesforce may collect, process, and store device, system, and other information related to your use of the Software. This information includes, but is not limited to, IP address, user metrics, and other data (“Usage Data”). Salesforce may use Usage Data for analytics, product development, and marketing purposes. You acknowledge that files generated in conjunction with the Software may contain sensitive or confidential data, and you are solely responsible for anonymizing and protecting such data.
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { transform as default } from './transform';
package/dist/main.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = void 0;
4
+ var transform_1 = require("./transform");
5
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return transform_1.transform; } });
6
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,yCAAmD;AAA1C,oGAAA,SAAS,OAAW"}
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from 'rollup';
2
+ import type { TransformOptions } from '@lwc/compiler';
3
+ export declare function transform(options: TransformOptions, rawSource: {
4
+ [path: string]: string;
5
+ }): Plugin;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.transform = void 0;
27
+ const path = __importStar(require("node:path"));
28
+ const node_crypto_1 = require("node:crypto");
29
+ const template_1 = require("./transformers/template");
30
+ const script_1 = require("./transformers/script");
31
+ const style_1 = require("./transformers/style");
32
+ function transform(options, rawSource) {
33
+ return {
34
+ name: 'lwc-hmr-lex',
35
+ transform(src, id) {
36
+ let transformer;
37
+ const hmrModuleContext = {
38
+ moduleHash: (0, node_crypto_1.createHash)('md5')
39
+ // Include the transformed source, incase raw source did not change but compiler introduced new transforms, the hash should change
40
+ .update(src, 'utf8')
41
+ // Include the raw source, certain content like white spaces might be lost during transformation
42
+ .update(Object.hasOwnProperty.call(rawSource, id) ? rawSource[id] : '')
43
+ .digest('hex'),
44
+ modulePath: `${options.namespace}/${options.name}/${id}`,
45
+ ownerPath: `${options.namespace}/${options.name}`,
46
+ };
47
+ switch (path.extname(id)) {
48
+ case '.html':
49
+ transformer = template_1.templateTransformer;
50
+ break;
51
+ case '.css':
52
+ transformer = style_1.styleTransformer;
53
+ break;
54
+ case '.ts':
55
+ case '.js':
56
+ transformer = script_1.scriptTransformer;
57
+ break;
58
+ default:
59
+ break;
60
+ }
61
+ return transformer ? transformer(src, id, options, hmrModuleContext) : undefined;
62
+ },
63
+ };
64
+ }
65
+ exports.transform = transform;
66
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,6CAAyC;AACzC,sDAA8D;AAC9D,kDAA0D;AAC1D,gDAAwD;AAKxD,SAAgB,SAAS,CACrB,OAAyB,EACzB,SAAqC;IAErC,OAAO;QACH,IAAI,EAAE,aAAa;QAEnB,SAAS,CAAC,GAAW,EAAE,EAAU;YAC7B,IAAI,WAAW,CAAC;YAChB,MAAM,gBAAgB,GAAqB;gBACvC,UAAU,EAAE,IAAA,wBAAU,EAAC,KAAK,CAAC;oBACzB,kIAAkI;qBACjI,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;oBACpB,gGAAgG;qBAC/F,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;qBACtE,MAAM,CAAC,KAAK,CAAC;gBAClB,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,IAAI,EAAE,EAAE;gBACxD,SAAS,EAAE,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE;aACpD,CAAC;YACF,QAAQ,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;gBACvB,KAAK,OAAO;oBACR,WAAW,GAAG,8BAAmB,CAAC;oBAClC,MAAM;gBAEV,KAAK,MAAM;oBACP,WAAW,GAAG,wBAAgB,CAAC;oBAC/B,MAAM;gBAEV,KAAK,KAAK,CAAC;gBACX,KAAK,KAAK;oBACN,WAAW,GAAG,0BAAiB,CAAC;oBAChC,MAAM;gBAEV;oBACI,MAAM;YACd,CAAC;YACD,OAAO,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrF,CAAC;KACJ,CAAC;AACN,CAAC;AAvCD,8BAuCC"}
@@ -0,0 +1,19 @@
1
+ import type { TransformResult } from 'rollup';
2
+ import type { TransformOptions } from '@lwc/compiler';
3
+ import type { HMRModuleContext } from '../types';
4
+ /**
5
+ * Transform a javascript(.js or .ts) file to add Hot Module Replacement related tranformations.
6
+ * Note 1: Transform the file using the `@lwc/compiler` before invoking this transformer.
7
+ *
8
+ * Note 2: This may eventually require a babel transform to add the moduleHash. The reason being,
9
+ * 1. Generated internal components(eg: forceGenerated) are bundled without `forceNamedExports`
10
+ * CompilerOptions. In this case, it might be necessary to add the `__lwc_hmr_context` property as
11
+ * an expando on the returned value. Since the generated components are not the target for dev
12
+ * server, we are skipping this in version 1.
13
+ * @param src : raw source code
14
+ * @param id : filename
15
+ * @param options: transform options
16
+ * @param hmrModuleContext: HMR Context for the file being handled
17
+ * @returns An object with the transformed code.
18
+ */
19
+ export declare function scriptTransformer(src: string, id: string, options: TransformOptions, hmrModuleContext: HMRModuleContext): TransformResult;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.scriptTransformer = void 0;
30
+ const path = __importStar(require("node:path"));
31
+ const magic_string_1 = __importDefault(require("magic-string"));
32
+ const errors_1 = require("@lwc/errors");
33
+ const IMPLICIT_DEFAULT_HTML_PATH = '@lwc/resources/empty_html.js';
34
+ /**
35
+ * Transform a javascript(.js or .ts) file to add Hot Module Replacement related tranformations.
36
+ * Note 1: Transform the file using the `@lwc/compiler` before invoking this transformer.
37
+ *
38
+ * Note 2: This may eventually require a babel transform to add the moduleHash. The reason being,
39
+ * 1. Generated internal components(eg: forceGenerated) are bundled without `forceNamedExports`
40
+ * CompilerOptions. In this case, it might be necessary to add the `__lwc_hmr_context` property as
41
+ * an expando on the returned value. Since the generated components are not the target for dev
42
+ * server, we are skipping this in version 1.
43
+ * @param src : raw source code
44
+ * @param id : filename
45
+ * @param options: transform options
46
+ * @param hmrModuleContext: HMR Context for the file being handled
47
+ * @returns An object with the transformed code.
48
+ */
49
+ function scriptTransformer(src, id, options, hmrModuleContext) {
50
+ if (src.trim() === '' || id === IMPLICIT_DEFAULT_HTML_PATH) {
51
+ return;
52
+ }
53
+ const pre = `import { hot as __lwc_hmr_hot } from 'lwc';\n`;
54
+ try {
55
+ let hotAccept = '';
56
+ // Add hmr hooks only for entry js file
57
+ if (path.parse(id).name === options.name) {
58
+ // For an entry file, accept self-updates
59
+ hotAccept = `
60
+ __lwc_hmr_hot.accept('${hmrModuleContext.modulePath}', (mod) => {
61
+ const { __lwc_hmr_context: new__lwc_hmr_context } = mod;
62
+ if (__lwc_hmr_context.moduleHash !== new__lwc_hmr_context.moduleHash) {
63
+ __lwc_hmr_hot.invalidate("JS change requires hot swapping at module boundary.")
64
+ }
65
+ });
66
+ `;
67
+ }
68
+ else {
69
+ // For a relative import, the entry module will accept hot update of dependencies
70
+ hotAccept = `
71
+ __lwc_hmr_hot.acceptDeps('${hmrModuleContext.ownerPath}', ['${hmrModuleContext.modulePath}'], (mod) => {
72
+ const { __lwc_hmr_context: new__lwc_hmr_context } = mod;
73
+ if (__lwc_hmr_context.moduleHash !== new__lwc_hmr_context.moduleHash) {
74
+ __lwc_hmr_hot.invalidate("JS change requires hot swapping at module boundary.");
75
+ }
76
+ });
77
+ `;
78
+ }
79
+ const post = `
80
+ export const __lwc_hmr_context = { moduleHash : '${hmrModuleContext.moduleHash}' };
81
+ if (__lwc_hmr_hot) {
82
+ __lwc_hmr_hot.register('${hmrModuleContext.modulePath}', '${hmrModuleContext.moduleHash}', ${JSON.stringify(options)});
83
+ ${hotAccept}
84
+ }
85
+ `;
86
+ const magicString = new magic_string_1.default(src);
87
+ magicString.prepend(pre);
88
+ magicString.append(post);
89
+ return {
90
+ code: magicString.toString(),
91
+ map: magicString.generateMap({ hires: true }),
92
+ };
93
+ }
94
+ catch (e) {
95
+ throw (0, errors_1.normalizeToCompilerError)(errors_1.TransformerErrors.JS_TRANSFORMER_ERROR, e, { filename: id });
96
+ }
97
+ }
98
+ exports.scriptTransformer = scriptTransformer;
99
+ //# sourceMappingURL=script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script.js","sourceRoot":"","sources":["../../src/transformers/script.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,gEAAuC;AACvC,wCAA0E;AAK1E,MAAM,0BAA0B,GAAG,8BAA8B,CAAC;AAElE;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iBAAiB,CAC7B,GAAW,EACX,EAAU,EACV,OAAyB,EACzB,gBAAkC;IAElC,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,0BAA0B,EAAE,CAAC;QACzD,OAAO;IACX,CAAC;IAED,MAAM,GAAG,GAAG,+CAA+C,CAAC;IAE5D,IAAI,CAAC;QACD,IAAI,SAAS,GAAG,EAAE,CAAC;QACnB,uCAAuC;QACvC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC;YACvC,yCAAyC;YACzC,SAAS,GAAG;4BACI,gBAAgB,CAAC,UAAU;;;;;;CAMtD,CAAC;QACM,CAAC;aAAM,CAAC;YACJ,iFAAiF;YACjF,SAAS,GAAG;gCACQ,gBAAgB,CAAC,SAAS,QAAQ,gBAAgB,CAAC,UAAU;;;;;;CAM5F,CAAC;QACM,CAAC;QAED,MAAM,IAAI,GAAG;mDAC8B,gBAAgB,CAAC,UAAU;;8BAEhD,gBAAgB,CAAC,UAAU,OAAO,gBAAgB,CAAC,UAAU,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;MAClH,SAAS;;CAEd,CAAC;QACM,MAAM,WAAW,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;QACzC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACzB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO;YACH,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE;YAC5B,GAAG,EAAE,WAAW,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SAChD,CAAC;IACN,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAA,iCAAwB,EAAC,0BAAiB,CAAC,oBAAoB,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IAChG,CAAC;AACL,CAAC;AAtDD,8CAsDC"}
@@ -0,0 +1,14 @@
1
+ import type { TransformResult } from 'rollup';
2
+ import type { TransformOptions } from '@lwc/compiler';
3
+ import type { HMRModuleContext } from '../types';
4
+ /**
5
+ * Transform a css file to add Hot Module Replacement related tranformations.
6
+ * Note: Transform the file using the `@lwc/compiler` before invoking this transformer.
7
+ *
8
+ * @param src : raw source code
9
+ * @param id : filename
10
+ * @param options: transform options
11
+ * @param hmrModuleContext: HMR Context for the file being handled
12
+ * @returns An object with the transformed code.
13
+ */
14
+ export declare function styleTransformer(src: string, id: string, options: TransformOptions, hmrModuleContext: HMRModuleContext): TransformResult;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.styleTransformer = void 0;
27
+ const path = __importStar(require("node:path"));
28
+ const errors_1 = require("@lwc/errors");
29
+ const STYLESHEET_IDENTIFIER = 'stylesheet';
30
+ /**
31
+ * Transform a css file to add Hot Module Replacement related tranformations.
32
+ * Note: Transform the file using the `@lwc/compiler` before invoking this transformer.
33
+ *
34
+ * @param src : raw source code
35
+ * @param id : filename
36
+ * @param options: transform options
37
+ * @param hmrModuleContext: HMR Context for the file being handled
38
+ * @returns An object with the transformed code.
39
+ */
40
+ function styleTransformer(src, id, options, hmrModuleContext) {
41
+ try {
42
+ // Transform only the main css file belonging to the component
43
+ // If the file only contains imports, ignore as well
44
+ if (src.trim() === '' ||
45
+ path.parse(id).name !== options.name ||
46
+ !src.includes(`function ${STYLESHEET_IDENTIFIER}(`)) {
47
+ return;
48
+ }
49
+ const code = `import { hot as __lwc_hmr_hot, swapStyle as __lwc_hmr_swapStyle } from 'lwc';
50
+
51
+ ${src}
52
+
53
+ export const __lwc_hmr_context = { moduleHash : '${hmrModuleContext.moduleHash}' };
54
+ if (__lwc_hmr_hot) {
55
+ __lwc_hmr_hot.register('${hmrModuleContext.modulePath}', '${hmrModuleContext.moduleHash}', ${JSON.stringify(options)});
56
+ __lwc_hmr_hot.accept('${hmrModuleContext.modulePath}', (mod) => {
57
+ const { __lwc_hmr_context: __new__lwc_hmr_context, default: __new_styles } = mod;
58
+ if (__lwc_hmr_context.moduleHash !== __new__lwc_hmr_context.moduleHash) {
59
+ if(newStyles) { // __new_styles can be undefined when the stylesheet contains only imports
60
+ __lwc_hmr_swapStyle(${STYLESHEET_IDENTIFIER}, __new_styles.at(-1)); // the default stylesheet is the last element
61
+ }
62
+ }
63
+ });
64
+ }
65
+ `;
66
+ return {
67
+ code,
68
+ map: { mappings: '' },
69
+ };
70
+ }
71
+ catch (e) {
72
+ throw (0, errors_1.normalizeToCompilerError)(errors_1.TransformerErrors.HTML_TRANSFORMER_ERROR, e, {
73
+ filename: id,
74
+ });
75
+ }
76
+ }
77
+ exports.styleTransformer = styleTransformer;
78
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.js","sourceRoot":"","sources":["../../src/transformers/style.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,wCAA0E;AAK1E,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C;;;;;;;;;GASG;AACH,SAAgB,gBAAgB,CAC5B,GAAW,EACX,EAAU,EACV,OAAyB,EACzB,gBAAkC;IAElC,IAAI,CAAC;QACD,8DAA8D;QAC9D,oDAAoD;QACpD,IACI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE;YACjB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI;YACpC,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,qBAAqB,GAAG,CAAC,EACrD,CAAC;YACC,OAAO;QACX,CAAC;QAED,MAAM,IAAI,GAAG;;EAEnB,GAAG;;mDAE8C,gBAAgB,CAAC,UAAU;;8BAEhD,gBAAgB,CAAC,UAAU,OAAO,gBAAgB,CAAC,UAAU,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;4BAC5F,gBAAgB,CAAC,UAAU;;;;sCAIjB,qBAAqB;;;;;CAK1D,CAAC;QACM,OAAO;YACH,IAAI;YACJ,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;SACxB,CAAC;IACN,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAA,iCAAwB,EAAC,0BAAiB,CAAC,sBAAsB,EAAE,CAAC,EAAE;YACxE,QAAQ,EAAE,EAAE;SACf,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AA3CD,4CA2CC"}
@@ -0,0 +1,16 @@
1
+ import type { TransformResult } from 'rollup';
2
+ import type { TransformOptions } from '@lwc/compiler';
3
+ import type { HMRModuleContext } from '../types';
4
+ /**
5
+ * Transform a compiled template file to add Hot Module Replacement related tranformations.
6
+ * Note 1: Transform the file using the `@lwc/compiler` before invoking this transformer.
7
+ * Note 2: Transfer the stylesheets from the old template to the hot template.
8
+ * This is based on an assumption that template can only have implicit stylesheet, so the
9
+ * swapped template would have the same set of style sheets
10
+ * @param src : raw source code
11
+ * @param id : filename
12
+ * @param options: transform options
13
+ * @param hmrModuleContext: HMR Context for the file being handled
14
+ * @returns An object with the transformed code.
15
+ */
16
+ export declare function templateTransformer(src: string, id: string, options: TransformOptions, hmrModuleContext: HMRModuleContext): TransformResult;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.templateTransformer = void 0;
4
+ const errors_1 = require("@lwc/errors");
5
+ /**
6
+ * Transform a compiled template file to add Hot Module Replacement related tranformations.
7
+ * Note 1: Transform the file using the `@lwc/compiler` before invoking this transformer.
8
+ * Note 2: Transfer the stylesheets from the old template to the hot template.
9
+ * This is based on an assumption that template can only have implicit stylesheet, so the
10
+ * swapped template would have the same set of style sheets
11
+ * @param src : raw source code
12
+ * @param id : filename
13
+ * @param options: transform options
14
+ * @param hmrModuleContext: HMR Context for the file being handled
15
+ * @returns An object with the transformed code.
16
+ */
17
+ function templateTransformer(src, id, options, hmrModuleContext) {
18
+ try {
19
+ if (src.trim() === '') {
20
+ return;
21
+ }
22
+ const code = `import { hot as __lwc_hmr_hot, swapTemplate as __lwc_hmr_swapTemplate } from 'lwc';
23
+
24
+ ${src}
25
+
26
+ if(typeof tmpl === 'function') {
27
+ tmpl.moduleHash = '${hmrModuleContext.moduleHash}';
28
+ if (__lwc_hmr_hot) {
29
+ __lwc_hmr_hot.register('${hmrModuleContext.modulePath}', '${hmrModuleContext.moduleHash}', ${JSON.stringify(options)});
30
+ __lwc_hmr_hot.accept('${hmrModuleContext.modulePath}', (mod) => {
31
+ if (tmpl.moduleHash !== mod.moduleHash) {
32
+ // Transfer the stylesheets from the old template to the hot template.
33
+ mod.stylesheets = tmpl.stylesheets;
34
+ __lwc_hmr_swapTemplate(tmpl, mod);
35
+ }
36
+ });
37
+ }
38
+ }
39
+ `;
40
+ return {
41
+ code,
42
+ map: { mappings: '' },
43
+ };
44
+ }
45
+ catch (e) {
46
+ throw (0, errors_1.normalizeToCompilerError)(errors_1.TransformerErrors.HTML_TRANSFORMER_ERROR, e, {
47
+ filename: id,
48
+ });
49
+ }
50
+ }
51
+ exports.templateTransformer = templateTransformer;
52
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/transformers/template.ts"],"names":[],"mappings":";;;AAAA,wCAA0E;AAK1E;;;;;;;;;;;GAWG;AACH,SAAgB,mBAAmB,CAC/B,GAAW,EACX,EAAU,EACV,OAAyB,EACzB,gBAAkC;IAElC,IAAI,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACpB,OAAO;QACX,CAAC;QACD,MAAM,IAAI,GAAG;;EAEnB,GAAG;;;yBAGoB,gBAAgB,CAAC,UAAU;;kCAElB,gBAAgB,CAAC,UAAU,OAAO,gBAAgB,CAAC,UAAU,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gCAC5F,gBAAgB,CAAC,UAAU;;;;;;;;;CAS1D,CAAC;QACM,OAAO;YACH,IAAI;YACJ,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;SACxB,CAAC;IACN,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAA,iCAAwB,EAAC,0BAAiB,CAAC,sBAAsB,EAAE,CAAC,EAAE;YACxE,QAAQ,EAAE,EAAE;SACf,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AArCD,kDAqCC"}
@@ -0,0 +1,5 @@
1
+ export interface HMRModuleContext {
2
+ moduleHash: string;
3
+ modulePath: string;
4
+ ownerPath: string;
5
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@lwc/dev-server-plugin-lex",
3
+ "description": "A rollup plugin to add Hot Module Replacement transformation to LWC components used in LEX.",
4
+ "version": "7.0.0-6.6.3",
5
+ "keywords": [
6
+ "lwc dev server",
7
+ "lwc hmr plugin"
8
+ ],
9
+ "main": "dist/main.js",
10
+ "typings": "dist/main.d.ts",
11
+ "files": [
12
+ "dist",
13
+ "LICENSE.txt"
14
+ ],
15
+ "license": "SEE LICENSE IN LICENSE.txt",
16
+ "scripts": {
17
+ "build": "tsc"
18
+ },
19
+ "dependencies": {
20
+ "@lwc/errors": "6.6.3",
21
+ "magic-string": "~0.30.10"
22
+ },
23
+ "devDependencies": {
24
+ "@lwc/compiler": "6.6.3"
25
+ }
26
+ }