@lwc/lwc-dev-server 9.0.0 → 9.0.1-alpha.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,19 @@
1
+ import type { ClientTarget } from '@lwc/lwc-dev-server-types';
2
+ import type { TransformOptions } from '@lwc/compiler';
3
+ export declare const clientLookup: Map<string, ClientConnection>;
4
+ /**
5
+ * Class representing a client that has connected to the dev server
6
+ */
7
+ export default class ClientConnection {
8
+ url: string;
9
+ target: ClientTarget;
10
+ activePaths: Map<string, TransformOptions>;
11
+ constructor(url: string, target: ClientTarget);
12
+ static getKey(url: string, target: ClientTarget): string;
13
+ addActivePaths(paths: {
14
+ modulePath: string;
15
+ compileOptions: TransformOptions;
16
+ }[]): void;
17
+ removeStalePaths(paths: string[]): void;
18
+ getCompileOptions(path: string): TransformOptions | undefined;
19
+ }
@@ -0,0 +1,30 @@
1
+ export const clientLookup = new Map();
2
+ /**
3
+ * Class representing a client that has connected to the dev server
4
+ */
5
+ export default class ClientConnection {
6
+ constructor(url, target) {
7
+ this.activePaths = new Map();
8
+ this.url = url;
9
+ this.target = target;
10
+ clientLookup.set(ClientConnection.getKey(this.url, this.target), this);
11
+ }
12
+ static getKey(url, target) {
13
+ return `${url}:${target}`;
14
+ }
15
+ addActivePaths(paths) {
16
+ paths.forEach(({ modulePath, compileOptions }) => {
17
+ const existing = this.activePaths.get(modulePath);
18
+ if (!existing) {
19
+ this.activePaths.set(modulePath, compileOptions);
20
+ }
21
+ });
22
+ }
23
+ removeStalePaths(paths) {
24
+ paths.forEach((p) => this.activePaths.delete(p));
25
+ }
26
+ getCompileOptions(path) {
27
+ return this.activePaths.get(path);
28
+ }
29
+ }
30
+ //# sourceMappingURL=clientConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientConnection.js","sourceRoot":"","sources":["../../../src/server/connection/clientConnection.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,YAAY,GAAkC,IAAI,GAAG,EAAE,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IAIjC,YAAY,GAAW,EAAE,MAAoB;QAD7C,gBAAW,GAAkC,IAAI,GAAG,EAAE,CAAC;QAEnD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,YAAY,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,GAAW,EAAE,MAAoB;QAC3C,OAAO,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,cAAc,CAAC,KAAiE;QAC5E,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,EAAE;YAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACZ,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;YACrD,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED,gBAAgB,CAAC,KAAe;QAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,iBAAiB,CAAC,IAAY;QAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACJ"}
@@ -0,0 +1,28 @@
1
+ /// <reference types="node" />
2
+ import { WebSocket } from 'ws';
3
+ import { Logger } from '../../types/index.js';
4
+ import type { HMR_Data } from '@lwc/lwc-dev-server-types';
5
+ export type Module = any;
6
+ export declare class Connection {
7
+ protocol: string;
8
+ host: string;
9
+ port: number;
10
+ logger: Logger;
11
+ httpsConfig?: Partial<{
12
+ cert: string;
13
+ key: string;
14
+ pfx: Buffer;
15
+ passphrase: string;
16
+ }> | undefined;
17
+ socket: WebSocket | undefined;
18
+ constructor(protocol: string, host: string, port: number, logger: Logger, httpsConfig?: Partial<{
19
+ cert: string;
20
+ key: string;
21
+ pfx: Buffer;
22
+ passphrase: string;
23
+ }> | undefined);
24
+ sendModule(modulePath: string, src: string): void;
25
+ initializeConnection(initCallback: () => void, messageCallback: (data: HMR_Data) => void): void;
26
+ send(data: HMR_Data): void;
27
+ close(): void;
28
+ }
@@ -0,0 +1,73 @@
1
+ /*
2
+ * Copyright (c) 2018, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ import * as http from 'http';
8
+ import * as https from 'https';
9
+ import { URL } from 'node:url';
10
+ import { WebSocketServer } from 'ws';
11
+ import { LogLevel } from '../../types/index.js';
12
+ export class Connection {
13
+ constructor(protocol, host, port, logger, httpsConfig) {
14
+ this.protocol = protocol;
15
+ this.host = host;
16
+ this.port = port;
17
+ this.logger = logger;
18
+ this.httpsConfig = httpsConfig;
19
+ }
20
+ sendModule(modulePath, src) {
21
+ this.send({
22
+ type: 'module-update',
23
+ data: [{ modulePath, src }],
24
+ });
25
+ }
26
+ initializeConnection(initCallback, messageCallback) {
27
+ const httpServer = this.httpsConfig
28
+ ? https.createServer(this.httpsConfig)
29
+ : http.createServer();
30
+ httpServer.on('request', requestHandler);
31
+ try {
32
+ const wss = new WebSocketServer({ server: httpServer });
33
+ wss.on('connection', (ws) => {
34
+ initCallback();
35
+ this.socket = ws;
36
+ this.socket.addEventListener('message', ({ data }) => {
37
+ if (data && typeof data === 'string') {
38
+ // When there is an update, handle the incoming message and request an updated module
39
+ messageCallback(JSON.parse(data));
40
+ }
41
+ });
42
+ });
43
+ httpServer.listen(this.port);
44
+ this.logger.log(LogLevel.info, `LWC Dev Server started at port:${this.port}`);
45
+ }
46
+ catch (e) {
47
+ this.logger.log(LogLevel.error, `Failed to start a WebSocket server with the following error: ${e}`);
48
+ process.exit(1);
49
+ }
50
+ }
51
+ send(data) {
52
+ if (this.socket && this.socket.readyState === this.socket.OPEN) {
53
+ this.socket.send(JSON.stringify(data));
54
+ }
55
+ }
56
+ close() {
57
+ this.socket?.close();
58
+ }
59
+ }
60
+ function requestHandler(req, res) {
61
+ // the second arg could really be anything, we're just interested in searchParams
62
+ // also req.url can never be undefined, it's just bad typing
63
+ const url = new URL(req.url, 'http://localhost');
64
+ const redirectUrl = url.searchParams.get('redirectUrl');
65
+ if (redirectUrl) {
66
+ res.statusCode = 302;
67
+ res.setHeader('Location', redirectUrl);
68
+ return res.end();
69
+ }
70
+ res.writeHead(200, { 'Content-Type': 'text/html' });
71
+ res.end(`Visit https://&lt;salesforce-url&gt;?aura.mode=devpreview`);
72
+ }
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/connection/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAa,MAAM,IAAI,CAAC;AAChD,OAAO,EAAe,QAAQ,EAAU,MAAM,sBAAsB,CAAC;AAMrE,MAAM,OAAO,UAAU;IAEnB,YACW,QAAgB,EAChB,IAAY,EACZ,IAAY,EACZ,MAAc,EACd,WAAyB;QAJzB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd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IAAI,CAAC,MAAM,CAAC,GAAG,CACX,QAAQ,CAAC,KAAK,EACd,gEAAgE,CAAC,EAAE,CACtE,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACL,CAAC;IAED,IAAI,CAAC,IAAc;QACf,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC7D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3C,CAAC;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;CACJ;AACD,SAAS,cAAc,CAAC,GAAyB,EAAE,GAAwB;IACvE,iFAAiF;IACjF,4DAA4D;IAC5D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAI,EAAE,kBAAkB,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACxD,IAAI,WAAW,EAAE,CAAC;QACd,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;QACrB,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACvC,OAAO,GAAG,CAAC,GAAG,EAAE,CAAC;IACrB,CAAC;IACD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;IACpD,GAAG,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAC;AACzE,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lwc/lwc-dev-server",
3
3
  "description": "A development server to get quick feedback on your LWC component development.",
4
- "version": "9.0.0",
4
+ "version": "9.0.1-alpha.0",
5
5
  "keywords": [
6
6
  "lwc dev server"
7
7
  ],
@@ -23,14 +23,14 @@
23
23
  "start": "node ./bin/dev-server.js start"
24
24
  },
25
25
  "dependencies": {
26
- "@lwc/sfdc-lwc-compiler": "9.0.0",
26
+ "@lwc/sfdc-lwc-compiler": "9.0.1-alpha.0",
27
27
  "chalk": "~5.3.0",
28
28
  "chokidar": "~3.6.0",
29
29
  "commander": "~10.0.0",
30
30
  "ws": "~8.16.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@lwc/lwc-dev-server-types": "9.0.0",
33
+ "@lwc/lwc-dev-server-types": "9.0.1-alpha.0",
34
34
  "@types/ws": "^8.5.10"
35
35
  },
36
36
  "peerDependencies": {