@lwc/lwc-dev-server 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 +21 -0
- package/README.md +7 -0
- package/bin/dev-server.js +2 -0
- package/dist/cli/cli.d.ts +1 -0
- package/dist/cli/cli.js +4 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/commands/devServer.d.ts +4 -0
- package/dist/cli/commands/devServer.js +115 -0
- package/dist/cli/commands/devServer.js.map +1 -0
- package/dist/cli/commands/index.d.ts +2 -0
- package/dist/cli/commands/index.js +21 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/server/bundler/lexBundler.d.ts +6 -0
- package/dist/server/bundler/lexBundler.js +73 -0
- package/dist/server/bundler/lexBundler.js.map +1 -0
- package/dist/server/connection/clientConnection.d.ts +19 -0
- package/dist/server/connection/clientConnection.js +30 -0
- package/dist/server/connection/clientConnection.js.map +1 -0
- package/dist/server/connection/index.d.ts +28 -0
- package/dist/server/connection/index.js +73 -0
- package/dist/server/connection/index.js.map +1 -0
- package/dist/server/consoleLogger.d.ts +6 -0
- package/dist/server/consoleLogger.js +33 -0
- package/dist/server/consoleLogger.js.map +1 -0
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.js +95 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/moduleGraph/index.d.ts +25 -0
- package/dist/server/moduleGraph/index.js +45 -0
- package/dist/server/moduleGraph/index.js.map +1 -0
- package/dist/server/moduleGraph/workspaceScanner/fileReader.d.ts +9 -0
- package/dist/server/moduleGraph/workspaceScanner/fileReader.js +81 -0
- package/dist/server/moduleGraph/workspaceScanner/fileReader.js.map +1 -0
- package/dist/server/moduleGraph/workspaceScanner/index.d.ts +3 -0
- package/dist/server/moduleGraph/workspaceScanner/index.js +15 -0
- package/dist/server/moduleGraph/workspaceScanner/index.js.map +1 -0
- package/dist/server/moduleGraph/workspaceScanner/internal.d.ts +8 -0
- package/dist/server/moduleGraph/workspaceScanner/internal.js +23 -0
- package/dist/server/moduleGraph/workspaceScanner/internal.js.map +1 -0
- package/dist/server/moduleGraph/workspaceScanner/mrt.d.ts +5 -0
- package/dist/server/moduleGraph/workspaceScanner/mrt.js +19 -0
- package/dist/server/moduleGraph/workspaceScanner/mrt.js.map +1 -0
- package/dist/server/moduleGraph/workspaceScanner/salesforceCli.d.ts +8 -0
- package/dist/server/moduleGraph/workspaceScanner/salesforceCli.js +26 -0
- package/dist/server/moduleGraph/workspaceScanner/salesforceCli.js.map +1 -0
- package/dist/server/moduleGraph/workspaceScanner/scanner.d.ts +56 -0
- package/dist/server/moduleGraph/workspaceScanner/scanner.js +35 -0
- package/dist/server/moduleGraph/workspaceScanner/scanner.js.map +1 -0
- package/dist/server/util/fileUtil.d.ts +1 -0
- package/dist/server/util/fileUtil.js +8 -0
- package/dist/server/util/fileUtil.js.map +1 -0
- package/dist/server/watcher/index.d.ts +3 -0
- package/dist/server/watcher/index.js +11 -0
- package/dist/server/watcher/index.js.map +1 -0
- package/dist/types/devServer.d.ts +10 -0
- package/dist/types/devServer.js +2 -0
- package/dist/types/devServer.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/serverConfig.d.ts +64 -0
- package/dist/types/serverConfig.js +24 -0
- package/dist/types/serverConfig.js.map +1 -0
- package/package.json +41 -0
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/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli/cli.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;AACxB,GAAG,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { existsSync, readFileSync, lstatSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { Command, Option, InvalidArgumentError } from 'commander';
|
|
4
|
+
import { LogLevel } from '../../types/index.js';
|
|
5
|
+
import { LWCServer } from '../../server/index.js';
|
|
6
|
+
import ConsoleLogger from '../../server/consoleLogger.js';
|
|
7
|
+
export function startDevServer(config) {
|
|
8
|
+
return new LWCServer(config);
|
|
9
|
+
}
|
|
10
|
+
function getTargetOption() {
|
|
11
|
+
return new Option('-t, --target <target>', '[string] configured target for deployment')
|
|
12
|
+
.choices(['lex', 'mrt', 'mobile'])
|
|
13
|
+
.default('lex');
|
|
14
|
+
}
|
|
15
|
+
function getPortOption() {
|
|
16
|
+
return new Option('-p, --port <number>', `[number] set port`)
|
|
17
|
+
.env('PORT')
|
|
18
|
+
.argParser(parseNumArg)
|
|
19
|
+
.makeOptionMandatory();
|
|
20
|
+
}
|
|
21
|
+
function getWorkspaceOption() {
|
|
22
|
+
return new Option('-w, --workspace <workspace>', '[string] configured workspace for development')
|
|
23
|
+
.choices(['internal', 'SalesforceCLI', 'mrt'])
|
|
24
|
+
.default('internal');
|
|
25
|
+
}
|
|
26
|
+
function parseNumArg(value) {
|
|
27
|
+
const parsedValue = parseInt(value, 10);
|
|
28
|
+
if (isNaN(parsedValue)) {
|
|
29
|
+
throw new InvalidArgumentError('Not a number.');
|
|
30
|
+
}
|
|
31
|
+
return parsedValue;
|
|
32
|
+
}
|
|
33
|
+
const consoleLogger = new ConsoleLogger(LogLevel.info);
|
|
34
|
+
function normalizeConfig({ config, port, target, logLevel, workspace, }) {
|
|
35
|
+
let rootDir = process.cwd();
|
|
36
|
+
const configFile = path.resolve(rootDir, config);
|
|
37
|
+
const modulePaths = [];
|
|
38
|
+
if (!existsSync(configFile) || !lstatSync(configFile).isFile()) {
|
|
39
|
+
consoleLogger.log(LogLevel.error, `Failed to find a valid config file at ${configFile}.`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const parsedConfig = JSON.parse(readFileSync(configFile, 'utf-8'));
|
|
43
|
+
consoleLogger.log(LogLevel.debug, `Found config file at "${configFile}" and initializing dev server with it.`);
|
|
44
|
+
rootDir = parsedConfig.rootDir ?? rootDir;
|
|
45
|
+
if (parsedConfig.lwc?.modules) {
|
|
46
|
+
parsedConfig.lwc.modules.forEach((entry) => {
|
|
47
|
+
if (entry.dir) {
|
|
48
|
+
const resolvedDir = entry.dir.replace(/^\$rootDir/, rootDir);
|
|
49
|
+
if (existsSync(resolvedDir)) {
|
|
50
|
+
modulePaths.push(resolvedDir);
|
|
51
|
+
consoleLogger.log(LogLevel.debug, `FS-Watcher: Adding ${resolvedDir} to watch.`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
consoleLogger.log(LogLevel.warn, `FS-Watcher: ${resolvedDir} does not exist, ignoring.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const normalizedConfig = {
|
|
60
|
+
rootDir,
|
|
61
|
+
port,
|
|
62
|
+
protocol: 'wss',
|
|
63
|
+
host: 'localhost',
|
|
64
|
+
// Component paths to watch
|
|
65
|
+
paths: modulePaths,
|
|
66
|
+
targets: [target],
|
|
67
|
+
workspace,
|
|
68
|
+
logLevel,
|
|
69
|
+
};
|
|
70
|
+
if (parsedConfig.https) {
|
|
71
|
+
normalizedConfig.https = parseHttpsConfig(parsedConfig.https, path.dirname(configFile));
|
|
72
|
+
}
|
|
73
|
+
return normalizedConfig;
|
|
74
|
+
}
|
|
75
|
+
function parseHttpsConfig(config, configDir) {
|
|
76
|
+
if (typeof config !== 'object')
|
|
77
|
+
throw new Error('Expected config to be an object');
|
|
78
|
+
if (config === null)
|
|
79
|
+
throw new Error(`config can't be null`);
|
|
80
|
+
const result = {};
|
|
81
|
+
// could solve this repetition, but I don't know how to resolve typescript
|
|
82
|
+
if ('cert' in config && typeof config.cert === 'string') {
|
|
83
|
+
result.cert = readFileSync(path.resolve(configDir, config.cert), 'utf-8');
|
|
84
|
+
}
|
|
85
|
+
if ('key' in config && typeof config.key === 'string') {
|
|
86
|
+
result.key = readFileSync(path.resolve(configDir, config.key), 'utf-8');
|
|
87
|
+
}
|
|
88
|
+
if ('pfx' in config && typeof config.pfx === 'string') {
|
|
89
|
+
result.pfx = readFileSync(path.resolve(configDir, config.pfx));
|
|
90
|
+
}
|
|
91
|
+
if ('passphrase' in config && typeof config.passphrase === 'string') {
|
|
92
|
+
result.passphrase = config.passphrase;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
export function createDevServer() {
|
|
97
|
+
return new Command('start')
|
|
98
|
+
.aliases(['preview'])
|
|
99
|
+
.description('Start Dev Server')
|
|
100
|
+
.addOption(getPortOption())
|
|
101
|
+
.addOption(getTargetOption())
|
|
102
|
+
.addOption(getWorkspaceOption())
|
|
103
|
+
.action((_options, cmd) => {
|
|
104
|
+
const { config, port, target, logLevel, workspace } = cmd.optsWithGlobals();
|
|
105
|
+
const serverConfig = normalizeConfig({
|
|
106
|
+
config,
|
|
107
|
+
port,
|
|
108
|
+
target,
|
|
109
|
+
logLevel: LogLevel[logLevel],
|
|
110
|
+
workspace,
|
|
111
|
+
});
|
|
112
|
+
startDevServer(serverConfig);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=devServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devServer.js","sourceRoot":"","sources":["../../../src/cli/commands/devServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAa,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,aAAa,MAAM,+BAA+B,C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IACnE,CAAC;IACD,IAAI,YAAY,IAAI,MAAM,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QAClE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IAC1C,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,eAAe;IAC3B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;SACtB,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC;SACpB,WAAW,CAAC,kBAAkB,CAAC;SAC/B,SAAS,CAAC,aAAa,EAAE,CAAC;SAC1B,SAAS,CAAC,eAAe,EAAE,CAAC;SAC5B,SAAS,CAAC,kBAAkB,EAAE,CAAC;SAC/B,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAY,EAAE,EAAE;QAC/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC;QAC5E,MAAM,YAAY,GAAiB,eAAe,CAAC;YAC/C,MAAM;YACN,IAAI;YACJ,MAAM;YACN,QAAQ,EAAE,QAAQ,CAAC,QAAiC,CAAC;YACrD,SAAS;SACZ,CAAC,CAAC;QACH,cAAc,CAAC,YAAY,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { Command, Option } from 'commander';
|
|
3
|
+
import { createDevServer } from './devServer.js';
|
|
4
|
+
function getVersion() {
|
|
5
|
+
const { version } = JSON.parse(readFileSync(new URL('../../../package.json', import.meta.url), 'utf-8'));
|
|
6
|
+
return version;
|
|
7
|
+
}
|
|
8
|
+
export function createCLI() {
|
|
9
|
+
return new Command('lwc-dev-server')
|
|
10
|
+
.description('LWC Local Developement')
|
|
11
|
+
.addOption(new Option('-c, --config <file>', `[string] use specified lwc.config.json file`).default('lwc.config.json'))
|
|
12
|
+
.addOption(new Option('--rootDir <directory>', `[string] use specified root directory`).default(process.cwd(), '"."'))
|
|
13
|
+
.addOption(new Option('--logLevel <level>', `[string] use specified log level`)
|
|
14
|
+
.env('LWC_LOG_LEVEL')
|
|
15
|
+
.choices(['debug', 'verbose', 'info', 'warn', 'error', 'silent'])
|
|
16
|
+
.default('info'))
|
|
17
|
+
.addCommand(createDevServer())
|
|
18
|
+
.showHelpAfterError()
|
|
19
|
+
.version(getVersion());
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,SAAS,UAAU;IACf,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAC1B,YAAY,CAAC,IAAI,GAAG,CAAC,uBAAuB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAC3E,CAAC;IACF,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,SAAS;IACrB,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;SAC/B,WAAW,CAAC,wBAAwB,CAAC;SACrC,SAAS,CACN,IAAI,MAAM,CACN,qBAAqB,EACrB,6CAA6C,CAChD,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAC/B;SACA,SAAS,CACN,IAAI,MAAM,CAAC,uBAAuB,EAAE,uCAAuC,CAAC,CAAC,OAAO,CAChF,OAAO,CAAC,GAAG,EAAE,EACb,KAAK,CACR,CACJ;SACA,SAAS,CACN,IAAI,MAAM,CAAC,oBAAoB,EAAE,kCAAkC,CAAC;SAC/D,GAAG,CAAC,eAAe,CAAC;SACpB,OAAO,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;SAChE,OAAO,CAAC,MAAM,CAAC,CACvB;SACA,UAAU,CAAC,eAAe,EAAE,CAAC;SAC7B,kBAAkB,EAAE;SACpB,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type DevServer } from '../../types/index.js';
|
|
2
|
+
import type { TransformOptions } from '@lwc/compiler';
|
|
3
|
+
export declare function compile(devServer: DevServer, modulePath: string, options: TransformOptions): Promise<{
|
|
4
|
+
code: string | undefined;
|
|
5
|
+
warnings: string[];
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { compile as platformCompile } from '@lwc/sfdc-lwc-compiler';
|
|
4
|
+
import { Workspace, LogLevel } from '../../types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Fetch files and source related to the modulePath that is being hot loaded.
|
|
7
|
+
* @param {DevServer} devServer DevServer object for stateful information
|
|
8
|
+
* @param {string} name Name of the component being compiled
|
|
9
|
+
* @param {string} namespace The namespace of the component
|
|
10
|
+
* @param {string} modulePath The formatted path for the file being compiled.
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
function getBundleFiles(devServer, name, namespace, modulePath) {
|
|
14
|
+
const moduleDir = `${namespace}/${name}`;
|
|
15
|
+
const moduleFilePath = devServer.moduleGraph.getFileByModulePath(modulePath);
|
|
16
|
+
const fileEntry = path.relative(moduleDir, modulePath);
|
|
17
|
+
const src = fs.readFileSync(moduleFilePath, 'utf8');
|
|
18
|
+
return { [fileEntry]: src };
|
|
19
|
+
}
|
|
20
|
+
function transformOptionsToPlatformCompileConfig(devServer, transformOptions, modulePath) {
|
|
21
|
+
const { enableDynamicComponents, enableLightningWebSecurityTransforms, experimentalComplexExpressions, apiVersion, name, namespace, experimentalDynamicComponent, outputConfig, } = transformOptions;
|
|
22
|
+
const options = {
|
|
23
|
+
// variable options
|
|
24
|
+
allowDynamicComponents: enableDynamicComponents,
|
|
25
|
+
enableLightningWebSecurityTransforms: enableLightningWebSecurityTransforms,
|
|
26
|
+
enableTemplateExpressions: experimentalComplexExpressions,
|
|
27
|
+
apiVersion: apiVersion,
|
|
28
|
+
// Standard options
|
|
29
|
+
disableProcessNodeEnv: true,
|
|
30
|
+
dynamicImport: 'allowed',
|
|
31
|
+
forceNamedExports: true,
|
|
32
|
+
strictCSSTokenCollection: true,
|
|
33
|
+
// Enable HMR always in dev server
|
|
34
|
+
enableHmr: true,
|
|
35
|
+
};
|
|
36
|
+
const getBundleType = () => {
|
|
37
|
+
if (devServer.config?.workspace === Workspace.Internal ||
|
|
38
|
+
devServer.config?.workspace === Workspace.Mrt) {
|
|
39
|
+
return 'internal';
|
|
40
|
+
}
|
|
41
|
+
return 'platform';
|
|
42
|
+
};
|
|
43
|
+
const bundle = {
|
|
44
|
+
type: getBundleType(),
|
|
45
|
+
name: name,
|
|
46
|
+
namespace: namespace ?? 'c',
|
|
47
|
+
files: getBundleFiles(devServer, name, namespace ?? '', modulePath),
|
|
48
|
+
options,
|
|
49
|
+
};
|
|
50
|
+
const compilerConfigs = [
|
|
51
|
+
{
|
|
52
|
+
outputConfig: { compat: false, minify: false, sourcemap: !!outputConfig?.sourcemap },
|
|
53
|
+
experimentalDynamicComponent: experimentalDynamicComponent,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
return {
|
|
57
|
+
bundle,
|
|
58
|
+
compilerConfigs,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export async function compile(devServer, modulePath, options) {
|
|
62
|
+
const compileConfig = transformOptionsToPlatformCompileConfig(devServer, options, modulePath);
|
|
63
|
+
const result = await platformCompile(compileConfig);
|
|
64
|
+
if (!result.success) {
|
|
65
|
+
devServer.logger?.log(LogLevel.error, `Failed to compile ${modulePath}. Diagnostics: ${JSON.stringify(result.diagnostics)}`);
|
|
66
|
+
return { code: undefined, warnings: [result.diagnostics.toString()] };
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
code: result.results?.[0].code,
|
|
70
|
+
warnings: result.diagnostics.length ? [result.diagnostics.toString()] : [],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=lexBundler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexBundler.js","sourceRoot":"","sources":["../../../src/server/bundler/lexBundler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAkB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAU3E;;;;;;;GAOG;AACH,SAAS,cAAc,CACnB,SAAoB,EACpB,IAAY,EACZ,SAAiB,EACjB,UAAkB;IAElB,MAAM,SAAS,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;IACzC,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,cAAe,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,EAAE,CAAC,SAAS,CA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;KACJ,CAAC;IACF,OAAO;QACH,MAAM;QACN,eAAe;KAClB,CAAC;AACN,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CACzB,SAAoB,EACpB,UAAkB,EAClB,OAAyB;IAEzB,MAAM,aAAa,GAAG,uCAAuC,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IAC9F,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,aAAa,CAAC,CAAC;IAEpD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAClB,SAAS,CAAC,MAAM,EAAE,GAAG,CACjB,QAAQ,CAAC,KAAK,EACd,qBAAqB,UAAU,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CACxF,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;IAC1E,CAAC;IAED,OAAO;QACH,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI;QAC9B,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;KAC7E,CAAC;AACN,CAAC"}
|
|
@@ -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://<salesforce-url>?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,gBAAW,GAAX,WAAW,CAAc;IACjC,CAAC;IAEJ,UAAU,CAAC,UAAkB,EAAE,GAAW;QACtC,IAAI,CAAC,IAAI,CAAC;YACN,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;SAC9B,CAAC,CAAC;IACP,CAAC;IAED,oBAAoB,CAAC,YAAwB,EAAE,eAAyC;QACpF,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW;YAC/B,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC;YACtC,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QAC1B,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACzC,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;YAC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AG,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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { LogLevel } from '../types/index.js';
|
|
3
|
+
export default class ConsoleLogger {
|
|
4
|
+
constructor(logLevel) {
|
|
5
|
+
this.logLevel = logLevel;
|
|
6
|
+
}
|
|
7
|
+
log(level, message) {
|
|
8
|
+
let formatter;
|
|
9
|
+
if (this.logLevel >= level) {
|
|
10
|
+
switch (this.logLevel) {
|
|
11
|
+
case LogLevel.silent:
|
|
12
|
+
case LogLevel.debug:
|
|
13
|
+
formatter = chalk.gray;
|
|
14
|
+
break;
|
|
15
|
+
case LogLevel.error:
|
|
16
|
+
formatter = chalk.red;
|
|
17
|
+
break;
|
|
18
|
+
case LogLevel.warn:
|
|
19
|
+
formatter = chalk.yellow;
|
|
20
|
+
break;
|
|
21
|
+
case LogLevel.info:
|
|
22
|
+
formatter = chalk.green;
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
formatter = chalk.white;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log(formatter(message));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=consoleLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleLogger.js","sourceRoot":"","sources":["../../src/server/consoleLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAU,MAAM,mBAAmB,CAAC;AAErD,MAAM,CAAC,OAAO,OAAO,aAAa;IAE9B,YAAY,QAAkB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IACD,GAAG,CAAC,KAAe,EAAE,OAAe;QAChC,IAAI,SAAS,CAAC;QACd,IAAI,IAAI,CAAC,QAAQ,IAAI,KAAK,EAAE,CAAC;YACzB,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACpB,KAAK,QAAQ,CAAC,MAAM,CAAC;gBACrB,KAAK,QAAQ,CAAC,KAAK;oBACf,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;oBACvB,MAAM;gBACV,KAAK,QAAQ,CAAC,KAAK;oBACf,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC;oBACtB,MAAM;gBACV,KAAK,QAAQ,CAAC,IAAI;oBACd,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;oBACzB,MAAM;gBACV,KAAK,QAAQ,CAAC,IAAI;oBACd,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;oBACxB,MAAM;gBACV;oBACI,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC;oBACxB,MAAM;YACd,CAAC;YACD,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FSWatcher } from 'chokidar';
|
|
2
|
+
import { type DevServer, type Logger, type ServerConfig } from '../types/index.js';
|
|
3
|
+
import { Connection } from './connection/index.js';
|
|
4
|
+
import { ModuleGraph } from './moduleGraph/index.js';
|
|
5
|
+
import ClientConnection from './connection/clientConnection.js';
|
|
6
|
+
import type { HMR_Data } from '@lwc/lwc-dev-server-types';
|
|
7
|
+
export declare class LWCServer implements DevServer {
|
|
8
|
+
logger: Logger;
|
|
9
|
+
watcher: FSWatcher;
|
|
10
|
+
config: ServerConfig;
|
|
11
|
+
connection: Connection;
|
|
12
|
+
moduleGraph: ModuleGraph;
|
|
13
|
+
clients: ClientConnection[];
|
|
14
|
+
constructor(config: ServerConfig);
|
|
15
|
+
stopServer(): void;
|
|
16
|
+
changeHandler(filePath: string): void;
|
|
17
|
+
messageCallback(data: HMR_Data): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { LogLevel } from '../types/index.js';
|
|
4
|
+
import { startWatch } from './watcher/index.js';
|
|
5
|
+
import { Connection } from './connection/index.js';
|
|
6
|
+
import { compile } from './bundler/lexBundler.js';
|
|
7
|
+
import { ModuleGraph } from './moduleGraph/index.js';
|
|
8
|
+
import ConsoleLogger from './consoleLogger.js';
|
|
9
|
+
import ClientConnection, { clientLookup } from './connection/clientConnection.js';
|
|
10
|
+
export class LWCServer {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.clients = [];
|
|
13
|
+
this.logger = new ConsoleLogger(config.logLevel);
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.watcher = startWatch(this.config.paths);
|
|
16
|
+
this.connection = new Connection(this.config.protocol, this.config.host, this.config.port, this.logger, this.config.https);
|
|
17
|
+
this.connection.initializeConnection(() => { }, this.messageCallback.bind(this));
|
|
18
|
+
this.watcher.on('change', this.changeHandler.bind(this));
|
|
19
|
+
this.moduleGraph = new ModuleGraph(config.workspace, config.paths, this.logger);
|
|
20
|
+
}
|
|
21
|
+
stopServer() {
|
|
22
|
+
this.watcher.close();
|
|
23
|
+
this.connection.close;
|
|
24
|
+
}
|
|
25
|
+
changeHandler(filePath) {
|
|
26
|
+
const changedFile = path.resolve(filePath);
|
|
27
|
+
if (fs.lstatSync(changedFile).isFile()) {
|
|
28
|
+
const modulePath = this.moduleGraph.getModuleByFile(changedFile) ?? changedFile;
|
|
29
|
+
if (modulePath) {
|
|
30
|
+
const hotModule = { type: 'update', data: [{ modulePath }] };
|
|
31
|
+
this.connection.send(hotModule);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
messageCallback(data) {
|
|
36
|
+
switch (data.type) {
|
|
37
|
+
case 'init': {
|
|
38
|
+
const { data: { activePaths, url, target }, } = data;
|
|
39
|
+
// WebSocket will broadcast to all client connections, so hot module updates will be
|
|
40
|
+
// sent to all active connections from a client. This check avoids double registration
|
|
41
|
+
// for a given client url:target combination
|
|
42
|
+
if (clientLookup.has(ClientConnection.getKey(url, target))) {
|
|
43
|
+
this.logger.log(LogLevel.debug, `Existing connection for url: ${url} and target: ${target}, avoiding duplicate registration.`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const connection = new ClientConnection(url, target);
|
|
47
|
+
connection.addActivePaths(activePaths.map(({ data: { modulePath, compileOptions } }) => {
|
|
48
|
+
return { modulePath, compileOptions };
|
|
49
|
+
}));
|
|
50
|
+
this.clients.push(connection);
|
|
51
|
+
this.moduleGraph.registerActivePaths(activePaths);
|
|
52
|
+
this.logger.log(LogLevel.info, `New connection for url: ${url} and target: ${target} registered.`);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
// In coming hot module
|
|
57
|
+
case 'fetch': {
|
|
58
|
+
const { data: { modulePath }, } = data;
|
|
59
|
+
const moduleFilePath = this.moduleGraph.getFileByModulePath(modulePath);
|
|
60
|
+
if (!moduleFilePath) {
|
|
61
|
+
const error = {
|
|
62
|
+
type: 'error',
|
|
63
|
+
data: {
|
|
64
|
+
message: `Fetch of ${modulePath} failed as it does not exist in dev server workspace`,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
this.connection.send(error);
|
|
68
|
+
}
|
|
69
|
+
this.clients.forEach(async (client) => {
|
|
70
|
+
switch (client.target) {
|
|
71
|
+
case 'LEX': {
|
|
72
|
+
const compileOptions = client.getCompileOptions(modulePath);
|
|
73
|
+
if (!compileOptions) {
|
|
74
|
+
this.logger.log(LogLevel.debug, `Found no compile option for module path: ${modulePath}, check the __lwc_hmr_hot.register() call.`);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
const result = await compile(this, modulePath, compileOptions);
|
|
78
|
+
if (!result.code) {
|
|
79
|
+
this.logger.log(LogLevel.error, `Compiling ${moduleFilePath} failed and there are compiler warnings: ${JSON.stringify(result.warnings)}`);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
this.connection.sendModule(modulePath, result.code);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
this.logger.log(LogLevel.verbose, `Client target ${client.target} not supported currently.`);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=index.js.map
|