@lwc/lwc-dev-server 10.7.0 → 10.7.1
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/dist/server/bundler/lexBundler.d.ts +3 -3
- package/dist/server/bundler/lexBundler.js +13 -15
- package/dist/server/bundler/lexBundler.js.map +1 -1
- package/dist/server/bundler/lexBundler.spec.js +90 -48
- package/dist/server/bundler/lexBundler.spec.js.map +1 -1
- package/dist/server/connection/client.d.ts +5 -7
- package/dist/server/connection/client.js +23 -39
- package/dist/server/connection/client.js.map +1 -1
- package/dist/server/connection/client.spec.js +96 -58
- package/dist/server/connection/client.spec.js.map +1 -1
- package/dist/server/connection/connection.d.ts +3 -3
- package/dist/server/connection/connection.js +8 -1
- package/dist/server/connection/connection.js.map +1 -1
- package/dist/server/connection/connection.spec.js +3 -3
- package/dist/server/connection/connection.spec.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +3 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.spec.js +40 -26
- package/dist/server/index.spec.js.map +1 -1
- package/dist/server/moduleGraph/index.d.ts +16 -41
- package/dist/server/moduleGraph/index.js +68 -114
- package/dist/server/moduleGraph/index.js.map +1 -1
- package/dist/server/moduleGraph/index.spec.js +106 -49
- package/dist/server/moduleGraph/index.spec.js.map +1 -1
- package/dist/server/moduleGraph/module.d.ts +78 -0
- package/dist/server/moduleGraph/module.js +126 -0
- package/dist/server/moduleGraph/module.js.map +1 -0
- package/dist/server/moduleGraph/module.spec.d.ts +1 -0
- package/dist/server/moduleGraph/module.spec.js +70 -0
- package/dist/server/moduleGraph/module.spec.js.map +1 -0
- package/dist/server/moduleGraph/workspaceScanner/__tests__/fileReader.spec.js +3 -3
- package/dist/server/moduleGraph/workspaceScanner/__tests__/fileReader.spec.js.map +1 -1
- package/dist/server/moduleGraph/workspaceScanner/__tests__/internal.spec.js +6 -2
- package/dist/server/moduleGraph/workspaceScanner/__tests__/internal.spec.js.map +1 -1
- package/dist/server/moduleGraph/workspaceScanner/fileReader.d.ts +8 -2
- package/dist/server/moduleGraph/workspaceScanner/fileReader.js +16 -17
- package/dist/server/moduleGraph/workspaceScanner/fileReader.js.map +1 -1
- package/dist/server/moduleGraph/workspaceScanner/scanner.d.ts +6 -33
- package/dist/server/moduleGraph/workspaceScanner/scanner.js +9 -18
- package/dist/server/moduleGraph/workspaceScanner/scanner.js.map +1 -1
- package/dist/server/util/module-util.d.ts +10 -0
- package/dist/server/util/module-util.js +10 -0
- package/dist/server/util/module-util.js.map +1 -0
- package/dist/server/watcher/index.js +1 -2
- package/dist/server/watcher/index.js.map +1 -1
- package/dist/server/watcher/index.spec.js +1 -1
- package/dist/server/watcher/index.spec.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type DevServerContext } from '../../types/index.js';
|
|
2
|
+
import { ModulePart } from '../moduleGraph/module.js';
|
|
2
3
|
import type { TransformOptions } from '@lwc/compiler';
|
|
3
|
-
|
|
4
|
-
export declare function compile(ctx: DevServerContext, modulePath: string, options: TransformOptions, logger: Logger, lifecycle?: Lifecycle): Promise<{
|
|
4
|
+
export declare function compile(ctx: DevServerContext, { module, part }: ModulePart, compileOptions: TransformOptions): Promise<{
|
|
5
5
|
code: string | undefined;
|
|
6
|
-
warnings:
|
|
6
|
+
warnings: import("@lwc/errors").CompilerDiagnostic[];
|
|
7
7
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { compile as platformCompile } from '@lwc/sfdc-lwc-compiler';
|
|
2
2
|
import { Workspace } from '../../types/index.js';
|
|
3
3
|
import { measureOperationTime } from '../util/telemetry.js';
|
|
4
|
-
function transformOptionsToPlatformCompileConfig(ctx, transformOptions,
|
|
4
|
+
function transformOptionsToPlatformCompileConfig(ctx, transformOptions, files) {
|
|
5
5
|
const { enableDynamicComponents, enableLightningWebSecurityTransforms, experimentalComplexExpressions, apiVersion, name, namespace, experimentalDynamicComponent, outputConfig, } = transformOptions;
|
|
6
6
|
const options = {
|
|
7
7
|
// variable options
|
|
@@ -17,17 +17,14 @@ function transformOptionsToPlatformCompileConfig(ctx, transformOptions, modulePa
|
|
|
17
17
|
// Enable HMR always in dev server
|
|
18
18
|
enableHmr: true,
|
|
19
19
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return 'platform';
|
|
25
|
-
};
|
|
20
|
+
const bundleType = ctx.config.workspace === Workspace.Internal || ctx.config.workspace === Workspace.Mrt
|
|
21
|
+
? 'internal'
|
|
22
|
+
: 'platform';
|
|
26
23
|
const bundle = {
|
|
27
|
-
type:
|
|
24
|
+
type: bundleType,
|
|
28
25
|
name: name,
|
|
29
26
|
namespace: namespace ?? 'c',
|
|
30
|
-
files
|
|
27
|
+
files,
|
|
31
28
|
options,
|
|
32
29
|
};
|
|
33
30
|
const compilerConfigs = [
|
|
@@ -41,16 +38,17 @@ function transformOptionsToPlatformCompileConfig(ctx, transformOptions, modulePa
|
|
|
41
38
|
compilerConfigs,
|
|
42
39
|
};
|
|
43
40
|
}
|
|
44
|
-
export async function compile(ctx,
|
|
45
|
-
const
|
|
46
|
-
const
|
|
41
|
+
export async function compile(ctx, { module, part }, compileOptions) {
|
|
42
|
+
const sources = await module.getSources(part);
|
|
43
|
+
const compileConfig = transformOptionsToPlatformCompileConfig(ctx, compileOptions, sources);
|
|
44
|
+
const result = await measureOperationTime('compile-time', () => platformCompile(compileConfig), ctx.config.lifecycle);
|
|
47
45
|
if (!result.success) {
|
|
48
|
-
logger.error(`Failed to compile ${
|
|
49
|
-
return { code: undefined, warnings:
|
|
46
|
+
ctx.logger.error(`Failed to compile ${part}. \n\tDiagnostics: ${JSON.stringify(result.diagnostics)}`);
|
|
47
|
+
return { code: undefined, warnings: result.diagnostics };
|
|
50
48
|
}
|
|
51
49
|
return {
|
|
52
50
|
code: result.results?.[0].code,
|
|
53
|
-
warnings: result.diagnostics
|
|
51
|
+
warnings: result.diagnostics,
|
|
54
52
|
};
|
|
55
53
|
}
|
|
56
54
|
//# sourceMappingURL=lexBundler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexBundler.js","sourceRoot":"","sources":["../../../src/server/bundler/lexBundler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAW5D,SAAS,uCAAuC,CAC5C,GAAqB,EACrB,gBAAkC,EAClC,
|
|
1
|
+
{"version":3,"file":"lexBundler.js","sourceRoot":"","sources":["../../../src/server/bundler/lexBundler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAW5D,SAAS,uCAAuC,CAC5C,GAAqB,EACrB,gBAAkC,EAClC,KAAkB;IAElB,MAAM,EACF,uBAAuB,EACvB,oCAAoC,EACpC,8BAA8B,EAC9B,UAAU,EACV,IAAI,EACJ,SAAS,EACT,4BAA4B,EAC5B,YAAY,GACf,GAAG,gBAAgB,CAAC;IACrB,MAAM,OAAO,GAAkB;QAC3B,mBAAmB;QACnB,sBAAsB,EAAE,uBAAuB;QAC/C,oCAAoC,EAAE,oCAAoC;QAC1E,yBAAyB,EAAE,8BAA8B;QACzD,UAAU,EAAE,UAAU;QACtB,mBAAmB;QACnB,qBAAqB,EAAE,IAAI;QAC3B,aAAa,EAAE,SAAS;QACxB,iBAAiB,EAAE,IAAI;QACvB,wBAAwB,EAAE,IAAI;QAC9B,kCAAkC;QAClC,SAAS,EAAE,IAAI;KAClB,CAAC;IACF,MAAM,UAAU,GACZ,GAAG,CAAC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AE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI;QAC9B,QAAQ,EAAE,MAAM,CAAC,WAAW;KAC/B,CAAC;AACN,CAAC"}
|
|
@@ -1,71 +1,113 @@
|
|
|
1
1
|
import { compile as platformCompile } from '@lwc/sfdc-lwc-compiler';
|
|
2
|
-
import { Workspace } from '../../types/index';
|
|
2
|
+
import { Workspace } from '../../types/index.js';
|
|
3
3
|
import { compile } from './lexBundler';
|
|
4
|
-
|
|
4
|
+
// Mock dependencies
|
|
5
|
+
vi.mock('@lwc/sfdc-lwc-compiler', () => ({
|
|
6
|
+
compile: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
vi.mock('../util/telemetry.js', () => ({
|
|
9
|
+
measureOperationTime: vi.fn((name, fn) => fn()),
|
|
10
|
+
}));
|
|
11
|
+
const mockCompileOptions = {
|
|
12
|
+
enableDynamicComponents: true,
|
|
13
|
+
enableLightningWebSecurityTransforms: true,
|
|
14
|
+
experimentalComplexExpressions: true,
|
|
15
|
+
apiVersion: 50,
|
|
16
|
+
name: 'testModule',
|
|
17
|
+
namespace: 'c',
|
|
18
|
+
outputConfig: { sourcemap: true },
|
|
19
|
+
};
|
|
5
20
|
describe('compile', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const mockModulePath = 'src/modules/myModule';
|
|
9
|
-
const mockTransformOptions = {
|
|
10
|
-
enableDynamicComponents: true,
|
|
11
|
-
enableLightningWebSecurityTransforms: true,
|
|
12
|
-
experimentalComplexExpressions: true,
|
|
13
|
-
apiVersion: 50,
|
|
14
|
-
name: 'myModule',
|
|
15
|
-
namespace: 'c',
|
|
16
|
-
};
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
mockLogger = {
|
|
19
|
-
error: vi.fn(),
|
|
20
|
-
};
|
|
21
|
-
mockCtx = {
|
|
21
|
+
it('should compile successfully', async () => {
|
|
22
|
+
const ctx = {
|
|
22
23
|
config: {
|
|
23
24
|
workspace: Workspace.Internal,
|
|
24
25
|
},
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
logger: {
|
|
27
|
+
error: vi.fn(),
|
|
27
28
|
},
|
|
29
|
+
moduleGraph: {},
|
|
28
30
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
31
|
+
const module = {
|
|
32
|
+
getSources: vi.fn().mockResolvedValue({ 'test.js': 'console.log("test");' }),
|
|
33
|
+
};
|
|
34
|
+
const part = 'testPart';
|
|
35
|
+
vi.mocked(platformCompile).mockResolvedValue({
|
|
33
36
|
success: true,
|
|
34
|
-
results: [
|
|
37
|
+
results: [{ code: 'compiled code' }],
|
|
38
|
+
diagnostics: [],
|
|
39
|
+
version: '1.0.0',
|
|
40
|
+
timings: {},
|
|
41
|
+
});
|
|
42
|
+
const result = await compile(ctx, { module, part }, mockCompileOptions);
|
|
43
|
+
expect(platformCompile).toHaveBeenCalledWith({
|
|
44
|
+
bundle: {
|
|
45
|
+
files: {
|
|
46
|
+
'test.js': 'console.log("test");',
|
|
47
|
+
},
|
|
48
|
+
name: 'testModule',
|
|
49
|
+
namespace: 'c',
|
|
50
|
+
options: {
|
|
51
|
+
allowDynamicComponents: true,
|
|
52
|
+
apiVersion: 50,
|
|
53
|
+
disableProcessNodeEnv: true,
|
|
54
|
+
dynamicImport: 'allowed',
|
|
55
|
+
enableHmr: true,
|
|
56
|
+
enableLightningWebSecurityTransforms: true,
|
|
57
|
+
enableTemplateExpressions: true,
|
|
58
|
+
forceNamedExports: true,
|
|
59
|
+
strictCSSTokenCollection: true,
|
|
60
|
+
},
|
|
61
|
+
type: 'internal',
|
|
62
|
+
},
|
|
63
|
+
compilerConfigs: [
|
|
35
64
|
{
|
|
36
|
-
code: 'compiled code',
|
|
37
|
-
map: '',
|
|
38
|
-
imports: [],
|
|
39
|
-
diagnostics: [],
|
|
40
65
|
outputConfig: {
|
|
41
66
|
minify: false,
|
|
42
|
-
sourcemap:
|
|
43
|
-
lockerConfig: {},
|
|
44
|
-
env: { NODE_ENV: 'dev' },
|
|
67
|
+
sourcemap: true,
|
|
45
68
|
},
|
|
46
|
-
timings: {},
|
|
47
69
|
},
|
|
48
70
|
],
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
expect(platformCompile).toHaveBeenCalledWith(expect.any(Object));
|
|
56
|
-
expect(result.code).toBe('compiled code');
|
|
57
|
-
expect(result.warnings).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
expect(result).toEqual({
|
|
73
|
+
code: 'compiled code',
|
|
74
|
+
warnings: [],
|
|
75
|
+
});
|
|
76
|
+
expect(ctx.logger.error).not.toHaveBeenCalledWith(expect.any(String));
|
|
58
77
|
});
|
|
59
|
-
it('should
|
|
78
|
+
it('should handle compile errors', async () => {
|
|
79
|
+
const ctx = {
|
|
80
|
+
config: {
|
|
81
|
+
workspace: Workspace.Internal,
|
|
82
|
+
},
|
|
83
|
+
logger: {
|
|
84
|
+
error: vi.fn(),
|
|
85
|
+
},
|
|
86
|
+
moduleGraph: {},
|
|
87
|
+
};
|
|
88
|
+
const module = {
|
|
89
|
+
getSources: vi.fn().mockResolvedValue({ 'test.js': 'console.log("test");' }),
|
|
90
|
+
};
|
|
91
|
+
const part = 'testPart';
|
|
60
92
|
vi.mocked(platformCompile).mockResolvedValue({
|
|
93
|
+
version: '1.0.0',
|
|
94
|
+
timings: {},
|
|
61
95
|
success: false,
|
|
62
96
|
results: [],
|
|
63
|
-
diagnostics: [],
|
|
64
|
-
|
|
65
|
-
|
|
97
|
+
diagnostics: [{ code: 1010, level: 1, message: 'Error message' }],
|
|
98
|
+
});
|
|
99
|
+
const result = await compile(ctx, { module, part }, mockCompileOptions);
|
|
100
|
+
expect(result).toEqual({
|
|
101
|
+
code: undefined,
|
|
102
|
+
warnings: [
|
|
103
|
+
{
|
|
104
|
+
code: 1010,
|
|
105
|
+
level: 1,
|
|
106
|
+
message: 'Error message',
|
|
107
|
+
},
|
|
108
|
+
],
|
|
66
109
|
});
|
|
67
|
-
|
|
68
|
-
expect(result.code).toBeUndefined();
|
|
110
|
+
expect(ctx.logger.error).toHaveBeenCalledWith(`Failed to compile ${part}. \n\tDiagnostics: [{"code":1010,"level":1,"message":"Error message"}]`);
|
|
69
111
|
});
|
|
70
112
|
});
|
|
71
113
|
//# sourceMappingURL=lexBundler.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexBundler.spec.js","sourceRoot":"","sources":["../../../src/server/bundler/lexBundler.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEpE,OAAO,
|
|
1
|
+
{"version":3,"file":"lexBundler.spec.js","sourceRoot":"","sources":["../../../src/server/bundler/lexBundler.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEpE,OAAO,EAAgB,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,oBAAoB;AACpB,EAAE,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE;CACnB,CAAC,CAAC,CAAC;AACJ,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,oBAAoB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;CAClD,CAAC,CAAC,CAAC;AAEJ,MAAM,kBAAkB,GAAG;IACvB,uBAAuB,EAAE,IAAI;IAC7B,oCAAoC,EAAE,IAAI;IAC1C,8BAA8B,EAAE,IAAI;IACpC,UAAU,EAAE,EAAE;IACd,IAAI,EAAE,YAAY;IAClB,SAAS,EAAE,GAAG;IACd,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EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,kBAAkB,CAAC,CAAC;QACxE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACnB,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE;gBACN;oBACI,IAAI,EAAE,IAAI;oBACV,KAAK,EAAE,CAAC;oBACR,OAAO,EAAE,eAAe;iBAC3B;aACJ;SACJ,CAAC,CAAC;QACH,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,oBAAoB,CACzC,qBAAqB,IAAI,wEAAwE,CACpG,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { HMR_Data_Outbound, HMR_Data_Inbound } from '@lwc/lwc-dev-server-types';
|
|
2
|
+
import { TransformOptions } from '@lwc/compiler';
|
|
1
3
|
import { DevServerContext } from '../../types/devServer.js';
|
|
2
4
|
import { Connection } from './connection.js';
|
|
3
|
-
import type { HMR_Data } from '@lwc/lwc-dev-server-types';
|
|
4
|
-
import type { TransformOptions } from '@lwc/compiler';
|
|
5
5
|
/**
|
|
6
6
|
* Class representing a client that has connected to the dev server.
|
|
7
7
|
* This class represents a client that is connected and ready to receive hot module updates.
|
|
@@ -11,14 +11,12 @@ import type { TransformOptions } from '@lwc/compiler';
|
|
|
11
11
|
export declare class Client {
|
|
12
12
|
clientId: string;
|
|
13
13
|
url: string;
|
|
14
|
-
activePaths: Map<string, TransformOptions>;
|
|
15
14
|
connection: Connection;
|
|
16
15
|
ctx: DevServerContext;
|
|
16
|
+
compileOptions: Map<string, TransformOptions>;
|
|
17
17
|
constructor(clientId: string, url: string, connection: Connection, ctx: DevServerContext);
|
|
18
18
|
onClose(callback: () => void): void;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
send(data: HMR_Data): void;
|
|
22
|
-
messageCallback(data: HMR_Data): Promise<void>;
|
|
19
|
+
send(data: HMR_Data_Outbound): void;
|
|
20
|
+
messageCallback(data: HMR_Data_Inbound): Promise<void>;
|
|
23
21
|
close(): void;
|
|
24
22
|
}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { compile } from '../bundler/lexBundler.js';
|
|
2
|
-
|
|
3
|
-
'update',
|
|
4
|
-
'module-update',
|
|
5
|
-
'module-delete',
|
|
6
|
-
'error',
|
|
7
|
-
'auth-response',
|
|
8
|
-
]);
|
|
9
|
-
const ALLOWED_INBOUND_DATA_TYPES = new Set(['fetch', 'register']);
|
|
2
|
+
import { decodeModulePath } from '../util/module-util.js';
|
|
10
3
|
/**
|
|
11
4
|
* Class representing a client that has connected to the dev server.
|
|
12
5
|
* This class represents a client that is connected and ready to receive hot module updates.
|
|
@@ -15,41 +8,27 @@ const ALLOWED_INBOUND_DATA_TYPES = new Set(['fetch', 'register']);
|
|
|
15
8
|
*/
|
|
16
9
|
export class Client {
|
|
17
10
|
constructor(clientId, url, connection, ctx) {
|
|
18
|
-
this.activePaths = new Map();
|
|
19
11
|
this.clientId = clientId;
|
|
20
12
|
this.url = url;
|
|
21
13
|
this.connection = connection;
|
|
22
14
|
this.connection.receive(this.messageCallback.bind(this));
|
|
23
15
|
this.ctx = ctx;
|
|
16
|
+
this.compileOptions = new Map();
|
|
24
17
|
}
|
|
25
18
|
onClose(callback) {
|
|
26
19
|
this.connection.onClose(callback);
|
|
27
20
|
}
|
|
28
|
-
removeStalePaths(paths) {
|
|
29
|
-
paths.forEach((p) => this.activePaths.delete(p));
|
|
30
|
-
}
|
|
31
|
-
getCompileOptions(path) {
|
|
32
|
-
return this.activePaths.get(path);
|
|
33
|
-
}
|
|
34
21
|
send(data) {
|
|
35
|
-
if (!ALLOWED_OUTBOUND_DATA_TYPES.has(data.type)) {
|
|
36
|
-
this.ctx.logger.debug(`[LWC Dev Server] Blocking unexpected type of data being sent from server to hmr-client '${data.type}'`);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
22
|
this.connection.send(data);
|
|
40
23
|
}
|
|
41
24
|
async messageCallback(data) {
|
|
42
|
-
if (!ALLOWED_INBOUND_DATA_TYPES.has(data.type)) {
|
|
43
|
-
this.ctx.logger.debug(`[LWC Dev Server] Blocking unexpected type of data received from hmr-client '${data.type}'`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
25
|
const { ctx: { logger, moduleGraph, config: { lifecycle }, }, } = this;
|
|
47
26
|
switch (data.type) {
|
|
48
27
|
// In coming hot module
|
|
49
28
|
case 'fetch': {
|
|
50
29
|
const { data: { modulePath }, } = data;
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
30
|
+
const modulePart = this.ctx.moduleGraph.getModulePart(modulePath);
|
|
31
|
+
if (!modulePart) {
|
|
53
32
|
const error = {
|
|
54
33
|
type: 'error',
|
|
55
34
|
data: {
|
|
@@ -57,16 +36,17 @@ export class Client {
|
|
|
57
36
|
},
|
|
58
37
|
};
|
|
59
38
|
this.connection.send(error);
|
|
60
|
-
}
|
|
61
|
-
const compileOptions = this.getCompileOptions(modulePath);
|
|
62
|
-
if (!compileOptions) {
|
|
63
|
-
logger.debug(`Found no compile option for module path: ${modulePath}, check the __lwc_hmr_hot.register() call.`);
|
|
64
39
|
break;
|
|
65
40
|
}
|
|
66
41
|
logger.debug(`[LWC Dev Server] Compiling ${modulePath}`);
|
|
67
|
-
const
|
|
42
|
+
const compileOptions = this.compileOptions.get(modulePart.module.id());
|
|
43
|
+
if (!compileOptions) {
|
|
44
|
+
logger.error(`Found no compile option for module path: ${modulePart.module.id()}, check the __lwc_hmr_hot.register() call.`);
|
|
45
|
+
throw new Error(`No Compile Options for module path: ${modulePart.module.id()}`);
|
|
46
|
+
}
|
|
47
|
+
const result = await compile(this.ctx, modulePart, compileOptions);
|
|
68
48
|
if (!result.code) {
|
|
69
|
-
logger.error(`Compiling ${
|
|
49
|
+
logger.error(`Compiling ${modulePath} failed and there are compiler warnings: ${JSON.stringify(result.warnings)}`);
|
|
70
50
|
break;
|
|
71
51
|
}
|
|
72
52
|
logger.debug(`[LWC Dev Server] Sending an updated ${modulePath}`);
|
|
@@ -81,17 +61,21 @@ export class Client {
|
|
|
81
61
|
break;
|
|
82
62
|
}
|
|
83
63
|
case 'register': {
|
|
84
|
-
const
|
|
85
|
-
for (const { modulePath, compileOptions } of modules) {
|
|
86
|
-
|
|
64
|
+
const moduleParts = [];
|
|
65
|
+
for (const { modulePath, hash, compileOptions } of data.data.modules) {
|
|
66
|
+
const { id, part } = decodeModulePath(modulePath);
|
|
67
|
+
moduleParts.push({ id, part, hash });
|
|
68
|
+
this.compileOptions.set(id, compileOptions);
|
|
87
69
|
}
|
|
88
70
|
// Inform the hmr-client of available updates, this ensures that any local changes
|
|
89
71
|
// that haven't been deployed to the remote app are updated upon client registration.
|
|
90
|
-
const staleModules = moduleGraph.getStaleModules(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
72
|
+
const staleModules = moduleGraph.getStaleModules(moduleParts);
|
|
73
|
+
if (staleModules.size > 0) {
|
|
74
|
+
this.send({
|
|
75
|
+
type: 'update',
|
|
76
|
+
data: Array.from(staleModules).map((modulePath) => ({ modulePath })),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
95
79
|
break;
|
|
96
80
|
}
|
|
97
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/server/connection/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/server/connection/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D;;;;;GAKG;AACH,MAAM,OAAO,MAAM;IAMf,YAAY,QAAgB,EAAE,GAAW,EAAE,UAAsB,EAAE,GAAqB;QACpF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG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AC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;oBACrC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;gBAChD,CAAC;gBAED,kFAAkF;gBAClF,qFAAqF;gBACrF,MAAM,YAAY,GAAG,WAAW,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;gBAC9D,IAAI,YAAY,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;oBACxB,IAAI,CAAC,IAAI,CAAC;wBACN,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;qBACvE,CAAC,CAAC;gBACP,CAAC;gBACD,MAAM;YACV,CAAC;QACL,CAAC;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACJ"}
|
|
@@ -1,87 +1,125 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { Workspace } from '../../types/serverConfig';
|
|
3
1
|
import { compile } from '../bundler/lexBundler.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import { Module } from '../moduleGraph/module.js';
|
|
3
|
+
import { Client } from './client.js';
|
|
4
|
+
// Mock dependencies
|
|
5
|
+
vi.mock('../bundler/lexBundler.js', () => ({
|
|
6
|
+
compile: vi.fn(),
|
|
7
|
+
}));
|
|
6
8
|
describe('Client', () => {
|
|
9
|
+
let clientId;
|
|
10
|
+
let url;
|
|
11
|
+
let connection;
|
|
12
|
+
let ctx;
|
|
7
13
|
let client;
|
|
8
|
-
let mockConnection;
|
|
9
|
-
let mockCtx;
|
|
10
|
-
let mockConfig;
|
|
11
|
-
const mockClientId = 'client-id';
|
|
12
|
-
const mockUrl = 'http://localhost';
|
|
13
|
-
const mockModuleGraph = {
|
|
14
|
-
getFileByModulePath: vi.fn(),
|
|
15
|
-
registerActivePaths: vi.fn(),
|
|
16
|
-
getModuleBoundary: vi.fn(),
|
|
17
|
-
getStaleModules: vi.fn().mockReturnValue(['stale-module']),
|
|
18
|
-
};
|
|
19
|
-
const mockLogger = {
|
|
20
|
-
debug: vi.fn(),
|
|
21
|
-
};
|
|
22
14
|
beforeEach(() => {
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
clientId = 'test-client-id';
|
|
16
|
+
url = 'http://localhost';
|
|
17
|
+
connection = {
|
|
25
18
|
receive: vi.fn(),
|
|
19
|
+
send: vi.fn(),
|
|
26
20
|
onClose: vi.fn(),
|
|
27
21
|
close: vi.fn(),
|
|
28
22
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
ctx = {
|
|
24
|
+
logger: {
|
|
25
|
+
debug: vi.fn(),
|
|
26
|
+
},
|
|
27
|
+
moduleGraph: {
|
|
28
|
+
getModulePart: vi.fn(),
|
|
29
|
+
getStaleModules: vi.fn(),
|
|
30
|
+
},
|
|
31
|
+
config: {
|
|
32
|
+
lifecycle: {
|
|
33
|
+
emitTelemetry: vi.fn(),
|
|
34
|
+
},
|
|
35
|
+
},
|
|
34
36
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
client
|
|
37
|
+
client = new Client(clientId, url, connection, ctx);
|
|
38
|
+
});
|
|
39
|
+
it('should initialize with correct properties', () => {
|
|
40
|
+
expect(client.clientId).toBe(clientId);
|
|
41
|
+
expect(client.url).toBe(url);
|
|
42
|
+
expect(client.connection).toBe(connection);
|
|
43
|
+
expect(client.ctx).toBe(ctx);
|
|
44
|
+
expect(connection.receive).toHaveBeenCalledWith(expect.any(Function));
|
|
42
45
|
});
|
|
43
|
-
it('should
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
expect(
|
|
47
|
-
expect(client.ctx).toBe(mockCtx);
|
|
48
|
-
expect(mockConnection.receive).toHaveBeenCalled();
|
|
46
|
+
it('should handle onClose callback', () => {
|
|
47
|
+
const callback = vi.fn();
|
|
48
|
+
client.onClose(callback);
|
|
49
|
+
expect(connection.onClose).toHaveBeenCalledWith(callback);
|
|
49
50
|
});
|
|
50
|
-
it('should send data
|
|
51
|
+
it('should send data', () => {
|
|
51
52
|
const data = { type: 'update', data: [] };
|
|
52
53
|
client.send(data);
|
|
53
|
-
expect(
|
|
54
|
+
expect(connection.send).toHaveBeenCalledWith(data);
|
|
54
55
|
});
|
|
55
|
-
it('should
|
|
56
|
-
|
|
57
|
-
client.
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
it('should handle fetch message callbacks', async () => {
|
|
57
|
+
vi.mocked(ctx.moduleGraph.getStaleModules).mockReturnValue(new Set());
|
|
58
|
+
await client.messageCallback({
|
|
59
|
+
type: 'register',
|
|
60
|
+
data: {
|
|
61
|
+
modules: [{ compileOptions: {}, hash: 'hash1', modulePath: 'ns/name/cmp.js' }],
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const data = {
|
|
65
|
+
type: 'fetch',
|
|
66
|
+
data: { modulePath: 'ns/name/cmp.js' },
|
|
67
|
+
};
|
|
68
|
+
const modulePart = { module: new Module('', 'ns', 'name', {}), part: 'cmp.js' };
|
|
69
|
+
vi.mocked(ctx.moduleGraph.getModulePart).mockReturnValue(modulePart);
|
|
70
|
+
vi.mocked(compile).mockResolvedValue({ code: 'compiled code', warnings: [] });
|
|
71
|
+
await client.messageCallback(data);
|
|
72
|
+
expect(ctx.logger.debug).toHaveBeenCalledWith(`[LWC Dev Server] Compiling ns/name/cmp.js`);
|
|
73
|
+
expect(compile).toHaveBeenCalledWith(ctx, modulePart, {});
|
|
74
|
+
expect(ctx.logger.debug).toHaveBeenCalledWith(`[LWC Dev Server] Sending an updated ns/name/cmp.js`);
|
|
75
|
+
expect(connection.send).toHaveBeenCalledWith({
|
|
76
|
+
type: 'module-update',
|
|
77
|
+
data: [{ modulePath: 'ns/name/cmp.js', src: 'compiled code' }],
|
|
78
|
+
});
|
|
79
|
+
expect(ctx.config.lifecycle.emitTelemetry).toHaveBeenCalledWith({
|
|
80
|
+
eventName: 'compile-success',
|
|
81
|
+
module: 'ns/name/cmp.js',
|
|
82
|
+
});
|
|
60
83
|
});
|
|
61
|
-
it('should handle fetch message
|
|
62
|
-
const data = {
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
it('should handle fetch message callback with error', async () => {
|
|
85
|
+
const data = {
|
|
86
|
+
type: 'fetch',
|
|
87
|
+
data: { modulePath: 'src/ns/name/cmp.js' },
|
|
88
|
+
};
|
|
89
|
+
vi.mocked(ctx.moduleGraph.getModulePart).mockReturnValue(undefined);
|
|
65
90
|
await client.messageCallback(data);
|
|
66
|
-
expect(
|
|
67
|
-
|
|
91
|
+
expect(connection.send).toHaveBeenCalledWith({
|
|
92
|
+
type: 'error',
|
|
93
|
+
data: {
|
|
94
|
+
message: `Fetch of src/ns/name/cmp.js failed as it does not exist in dev server workspace`,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
68
97
|
});
|
|
69
|
-
it('should handle register message
|
|
98
|
+
it('should handle register message callback', async () => {
|
|
70
99
|
const data = {
|
|
71
100
|
type: 'register',
|
|
72
|
-
data: {
|
|
101
|
+
data: {
|
|
102
|
+
modules: [{ modulePath: 'ns/name/cmp.js', hash: 'hash1', compileOptions: {} }],
|
|
103
|
+
},
|
|
73
104
|
};
|
|
74
|
-
|
|
105
|
+
const staleModules = new Set(['ns/name/cmp.js']);
|
|
106
|
+
vi.mocked(ctx.moduleGraph.getStaleModules).mockReturnValue(staleModules);
|
|
75
107
|
await client.messageCallback(data);
|
|
76
|
-
expect(
|
|
77
|
-
|
|
108
|
+
expect(ctx.moduleGraph.getStaleModules).toHaveBeenCalledWith([
|
|
109
|
+
{
|
|
110
|
+
hash: 'hash1',
|
|
111
|
+
id: 'ns/name',
|
|
112
|
+
part: 'cmp.js',
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
115
|
+
expect(connection.send).toHaveBeenCalledWith({
|
|
78
116
|
type: 'update',
|
|
79
|
-
data:
|
|
117
|
+
data: Array.from(staleModules).map((modulePath) => ({ modulePath })),
|
|
80
118
|
});
|
|
81
119
|
});
|
|
82
120
|
it('should close the connection', () => {
|
|
83
121
|
client.close();
|
|
84
|
-
expect(
|
|
122
|
+
expect(connection.close).toHaveBeenCalled();
|
|
85
123
|
});
|
|
86
124
|
});
|
|
87
125
|
//# sourceMappingURL=client.spec.js.map
|