Skip to content

Commit 526a576

Browse files
committed
fix: use new package that has no peerDependencies
1 parent ea20586 commit 526a576

10 files changed

Lines changed: 1710 additions & 2646 deletions

File tree

package.json

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
"dependencies": {
88
"@inquirer/prompts": "^5.3.8",
99
"@inquirer/select": "^2.4.7",
10-
"@lwc/lwc-dev-server": "~13.3.8",
11-
"@lwc/lwc-dev-server-65.0": "npm:@lwc/lwc-dev-server@~13.2.x",
12-
"@lwc/lwc-dev-server-66.0": "npm:@lwc/lwc-dev-server@~13.3.x",
13-
"@lwc/lwc-dev-server-67.0": "npm:@lwc/lwc-dev-server@~13.3.x",
14-
"@lwc/sfdc-lwc-compiler": "~13.3.8",
15-
"@lwc/sfdc-lwc-compiler-65.0": "npm:@lwc/sfdc-lwc-compiler@~13.2.x",
16-
"@lwc/sfdc-lwc-compiler-66.0": "npm:@lwc/sfdc-lwc-compiler@~13.3.x",
17-
"@lwc/sfdc-lwc-compiler-67.0": "npm:@lwc/sfdc-lwc-compiler@~13.3.x",
10+
"@lwc/sfdx-local-dev-dist": "13.3.11-alpha.0+3edb66b",
11+
"@lwc/sfdx-local-dev-dist-65.0": "npm:@lwc/sfdx-local-dev-dist@13.3.11-alpha.0+3edb66b",
12+
"@lwc/sfdx-local-dev-dist-66.0": "npm:@lwc/sfdx-local-dev-dist@13.3.11-alpha.0+3edb66b",
13+
"@lwc/sfdx-local-dev-dist-67.0": "npm:@lwc/sfdx-local-dev-dist@13.3.11-alpha.0+3edb66b",
1814
"@lwrjs/api": "0.18.3",
1915
"@oclif/core": "^4.5.6",
2016
"@salesforce/core": "^8.24.0",
@@ -23,10 +19,6 @@
2319
"@salesforce/sf-plugins-core": "^11.2.4",
2420
"axios": "^1.13.2",
2521
"glob": "^13.0.0",
26-
"lwc": "~8.27.0",
27-
"lwc-65.0": "npm:lwc@~8.23.x",
28-
"lwc-66.0": "npm:lwc@~8.24.x",
29-
"lwc-67.0": "npm:lwc@~8.24.x",
3022
"node-fetch": "^3.3.2",
3123
"open": "^10.2.0",
3224
"xml2js": "^0.6.2"
@@ -243,23 +235,17 @@
243235
"apiVersionMetadata": {
244236
"65.0": {
245237
"dependencies": {
246-
"@lwc/lwc-dev-server": "~13.2.x",
247-
"@lwc/sfdc-lwc-compiler": "~13.2.x",
248-
"lwc": "~8.23.x"
238+
"@lwc/sfdx-local-dev-dist": "13.3.11-alpha.0+3edb66b"
249239
}
250240
},
251241
"66.0": {
252242
"dependencies": {
253-
"@lwc/lwc-dev-server": "~13.3.x",
254-
"@lwc/sfdc-lwc-compiler": "~13.3.x",
255-
"lwc": "~8.24.x"
243+
"@lwc/sfdx-local-dev-dist": "13.3.11-alpha.0+3edb66b"
256244
}
257245
},
258246
"67.0": {
259247
"dependencies": {
260-
"@lwc/lwc-dev-server": "~13.3.x",
261-
"@lwc/sfdc-lwc-compiler": "~13.3.x",
262-
"lwc": "~8.24.x"
248+
"@lwc/sfdx-local-dev-dist": "13.3.11-alpha.0+3edb66b"
263249
}
264250
}
265251
},

src/configMeta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Workspace } from '@lwc/lwc-dev-server';
17+
import { Workspace } from '@lwc/sfdx-local-dev-dist';
1818
import { ConfigPropertyMeta, ConfigValue, Messages } from '@salesforce/core';
1919

2020
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);

src/lwc-dev-server/index.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616

1717
import process from 'node:process';
18-
import type { LWCServer, ServerConfig, Workspace } from '@lwc/lwc-dev-server';
18+
import type { LWCServer, ServerConfig, Workspace } from '@lwc/sfdx-local-dev-dist';
1919
import { Connection, Lifecycle, Logger, SfProject } from '@salesforce/core';
2020
import { SSLCertificateData } from '@salesforce/lwc-dev-mobile-core';
2121
import { glob } from 'glob';
22-
import { loadLwcDevServer } from '../shared/dependencyLoader.js';
22+
import { loadLwcModule } from '../shared/dependencyLoader.js';
2323
import {
2424
ConfigUtils,
2525
LOCAL_DEV_SERVER_DEFAULT_HTTP_PORT,
@@ -50,25 +50,30 @@ async function createLWCServerConfig(
5050
httpsPort: LOCAL_DEV_SERVER_DEFAULT_HTTP_PORT + 1,
5151
};
5252

53+
const resolvedWorkspace: Workspace = (workspace ??
54+
(await ConfigUtils.getLocalDevServerWorkspace()) ??
55+
LOCAL_DEV_SERVER_DEFAULT_WORKSPACE) as Workspace;
56+
5357
const serverConfig: ServerConfig = {
5458
rootDir,
5559
// use custom port if any is provided, or fetch from config file (if any), otherwise use the default port
5660
port: ports.httpPort,
5761
paths: namespacePaths,
5862
// use custom workspace if any is provided, or fetch from config file (if any), otherwise use the default workspace
59-
workspace: workspace ?? (await ConfigUtils.getLocalDevServerWorkspace()) ?? LOCAL_DEV_SERVER_DEFAULT_WORKSPACE,
63+
workspace: resolvedWorkspace,
6064
identityToken: token,
61-
lifecycle: Lifecycle.getInstance(),
65+
lifecycle: Lifecycle.getInstance() as unknown as ServerConfig['lifecycle'],
6266
clientType,
6367
namespace: typeof namespace === 'string' && namespace.trim().length > 0 ? namespace.trim() : undefined,
6468
};
6569

6670
if (certData?.pemCertificate && certData.pemPrivateKey) {
67-
serverConfig.https = {
71+
const httpsConfig: ServerConfig['https'] = {
6872
cert: certData.pemCertificate,
6973
key: certData.pemPrivateKey,
7074
port: ports.httpsPort,
7175
};
76+
serverConfig.https = httpsConfig;
7277
}
7378

7479
return serverConfig;
@@ -87,18 +92,25 @@ export async function startLWCServer(
8792
const orgApiVersion = connection.version;
8893
logger.trace(`Starting LWC server for org API version: ${orgApiVersion}`);
8994

90-
const lwcDevServerModule = await loadLwcDevServer(orgApiVersion);
95+
const lwcDevServerModule = await loadLwcModule(orgApiVersion);
9196

92-
const config = await createLWCServerConfig(rootDir, token, clientType, serverPorts, certData, workspace);
97+
const config: ServerConfig = await createLWCServerConfig(
98+
rootDir,
99+
token,
100+
clientType,
101+
serverPorts,
102+
certData,
103+
workspace,
104+
);
93105

94106
logger.trace(`Starting LWC Dev Server with config: ${JSON.stringify(config)}`);
95-
let lwcDevServer = (await lwcDevServerModule.startLwcDevServer(config, logger)) as LWCServer | null;
107+
const lwcDevServerResult = await lwcDevServerModule.startLwcDevServer(config, logger);
108+
const lwcDevServer = lwcDevServerResult as LWCServer;
96109

97110
const cleanup = (): void => {
98111
if (lwcDevServer) {
99112
logger.trace('Stopping LWC Dev Server');
100113
lwcDevServer.stopServer();
101-
lwcDevServer = null;
102114
}
103115
};
104116

@@ -108,5 +120,5 @@ export async function startLWCServer(
108120
'SIGTERM', // when a user kills the process
109121
].forEach((signal) => process.on(signal, cleanup));
110122

111-
return lwcDevServer as LWCServer;
123+
return lwcDevServer;
112124
}

src/shared/configUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Workspace } from '@lwc/lwc-dev-server';
17+
import { Workspace } from '@lwc/sfdx-local-dev-dist';
1818
import { SSLCertificateData } from '@salesforce/lwc-dev-mobile-core';
1919
import { Config, ConfigAggregator } from '@salesforce/core';
2020
import configMeta, { ConfigVars, SerializedSSLCertificateData } from './../configMeta.js';

src/shared/dependencyLoader.ts

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ type PackageJson = {
2424
const packageJson = packageJsonImport as unknown as PackageJson;
2525

2626
/**
27-
* Type for dynamically loaded LWC server module
27+
* Type for dynamically loaded LWC module from @lwc/sfdx-local-dev-dist
2828
*/
29-
export type LwcDevServerModule = {
29+
export type LwcModule = {
30+
[key: string]: unknown;
3031
startLwcDevServer: (config: unknown, logger: Logger) => Promise<unknown>;
3132
LWCServer: unknown;
3233
Workspace: unknown;
@@ -58,50 +59,23 @@ function resolveApiVersion(orgApiVersion: string): string {
5859
}
5960

6061
/**
61-
* Internal helper to dynamically load an aliased dependency
62+
* Loads the LWC module for the specified org API version
63+
* Uses dynamic import to load the aliased package at runtime
64+
*
65+
* @param orgApiVersion - The API version from the org (e.g., '65.0.1')
66+
* @returns The loaded module from @lwc/sfdx-local-dev-dist
6267
*/
63-
async function loadDependency<T>(orgApiVersion: string, packagePrefix: string, friendlyName: string): Promise<T> {
68+
export async function loadLwcModule(orgApiVersion: string): Promise<LwcModule> {
6469
const version = resolveApiVersion(orgApiVersion);
65-
const packageName = `${packagePrefix}${version}`;
70+
const packageName = `@lwc/sfdx-local-dev-dist-${version}`;
6671

6772
try {
68-
return (await import(packageName)) as T;
73+
return (await import(packageName)) as LwcModule;
6974
} catch (error) {
7075
throw new Error(
71-
`Failed to load ${friendlyName} for version '${version}'. ` +
76+
`Failed to load LWC module for version '${version}'. ` +
7277
`Package '${packageName}' could not be imported. ` +
7378
`Error: ${error instanceof Error ? error.message : String(error)}`,
7479
);
7580
}
7681
}
77-
78-
/**
79-
* Loads the LWC dev server module for the specified org API version
80-
* Uses dynamic import to load the aliased package at runtime
81-
*
82-
* @param orgApiVersion - The API version from the org (e.g., '65.0.1')
83-
* @returns The loaded module
84-
*/
85-
export async function loadLwcDevServer(orgApiVersion: string): Promise<LwcDevServerModule> {
86-
return loadDependency<LwcDevServerModule>(orgApiVersion, '@lwc/lwc-dev-server-', 'LWC dev server');
87-
}
88-
89-
/**
90-
* Loads the LWC compiler module for the specified org API version
91-
*
92-
* @param orgApiVersion - The API version from the org (e.g., '65.0.1')
93-
* @returns The loaded compiler module
94-
*/
95-
export async function loadLwcCompiler(orgApiVersion: string): Promise<unknown> {
96-
return loadDependency<unknown>(orgApiVersion, '@lwc/sfdc-lwc-compiler-', 'LWC compiler');
97-
}
98-
99-
/**
100-
* Loads the base LWC module for the specified org API version
101-
*
102-
* @param orgApiVersion - The API version from the org (e.g., '65.0.1')
103-
* @returns The loaded LWC module
104-
*/
105-
export async function loadLwc(orgApiVersion: string): Promise<unknown> {
106-
return loadDependency<unknown>(orgApiVersion, 'lwc-', 'LWC');
107-
}

src/types/aliased-deps.d.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
declare module '@lwc/lwc-dev-server-65.0' {
18-
export * from '@lwc/lwc-dev-server';
17+
// Type declarations for @lwc/sfdx-local-dev-dist aliases
18+
// The main package @lwc/sfdx-local-dev-dist provides its own type definitions
19+
declare module '@lwc/sfdx-local-dev-dist-65.0' {
20+
export * from '@lwc/sfdx-local-dev-dist';
1921
}
2022

21-
declare module '@lwc/lwc-dev-server-66.0' {
22-
export * from '@lwc/lwc-dev-server';
23+
declare module '@lwc/sfdx-local-dev-dist-66.0' {
24+
export * from '@lwc/sfdx-local-dev-dist';
2325
}
2426

25-
declare module '@lwc/lwc-dev-server-67.0' {
26-
export * from '@lwc/lwc-dev-server';
27-
}
28-
29-
declare module '@lwc/sfdc-lwc-compiler-65.0' {
30-
export * from '@lwc/sfdc-lwc-compiler';
31-
}
32-
33-
declare module '@lwc/sfdc-lwc-compiler-66.0' {
34-
export * from '@lwc/sfdc-lwc-compiler';
35-
}
36-
37-
declare module '@lwc/sfdc-lwc-compiler-67.0' {
38-
export * from '@lwc/sfdc-lwc-compiler';
39-
}
40-
41-
declare module 'lwc-65.0' {
42-
export * from 'lwc';
43-
}
44-
45-
declare module 'lwc-66.0' {
46-
export * from 'lwc';
47-
}
48-
49-
declare module 'lwc-67.0' {
50-
export * from 'lwc';
27+
declare module '@lwc/sfdx-local-dev-dist-67.0' {
28+
export * from '@lwc/sfdx-local-dev-dist';
5129
}

test/lwc-dev-server/index.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616

1717
import { expect } from 'chai';
18-
import { LWCServer, Workspace } from '@lwc/lwc-dev-server';
18+
import type { LWCServer } from '@lwc/sfdx-local-dev-dist';
19+
import { Workspace } from '@lwc/sfdx-local-dev-dist';
1920
import esmock from 'esmock';
2021
import { TestContext } from '@salesforce/core/testSetup';
2122
import * as devServer from '../../src/lwc-dev-server/index.js';
@@ -30,7 +31,7 @@ describe('lwc-dev-server', () => {
3031

3132
before(async () => {
3233
lwcDevServer = await esmock<typeof devServer>('../../src/lwc-dev-server/index.js', {
33-
'@lwc/lwc-dev-server': {
34+
'@lwc/sfdx-local-dev-dist': {
3435
startLwcDevServer: async () => server,
3536
},
3637
});

test/shared/configUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { expect } from 'chai';
18-
import { Workspace } from '@lwc/lwc-dev-server';
18+
import { Workspace } from '@lwc/sfdx-local-dev-dist';
1919
import { Config, ConfigAggregator } from '@salesforce/core';
2020
import { TestContext } from '@salesforce/core/testSetup';
2121
import { ConfigUtils, LocalWebServerIdentityData } from '../../src/shared/configUtils.js';
@@ -58,7 +58,7 @@ describe('configUtils', () => {
5858
$$.SANDBOX.stub(Config, 'addAllowedProperties').withArgs($$.SANDBOX.match.any);
5959
$$.SANDBOX.stub(Config.prototype, 'set').withArgs(
6060
ConfigVars.LOCAL_WEB_SERVER_IDENTITY_DATA,
61-
$$.SANDBOX.match.string
61+
$$.SANDBOX.match.string,
6262
);
6363
$$.SANDBOX.stub(Config.prototype, 'write').resolves();
6464
const identityData: LocalWebServerIdentityData = {

test/shared/dependencyLoader.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,26 @@
1515
*/
1616

1717
import { expect } from 'chai';
18-
import { loadLwcDevServer, loadLwcCompiler, loadLwc } from '../../src/shared/dependencyLoader.js';
18+
import { loadLwcModule } from '../../src/shared/dependencyLoader.js';
1919

2020
describe('DependencyLoader', () => {
21-
it('exists and has expected methods', () => {
22-
expect(typeof loadLwcDevServer).to.equal('function');
23-
expect(typeof loadLwcCompiler).to.equal('function');
24-
expect(typeof loadLwc).to.equal('function');
21+
it('exists and has expected method', () => {
22+
expect(typeof loadLwcModule).to.equal('function');
2523
});
2624

2725
it('loads the aliased package (real import call)', async () => {
2826
// This will actually try to call import() which should work since we ran yarn install.
2927
// However, loading LWC modules in Node might still trigger ReferenceErrors if browser globals are missing.
3028
// We use a try-catch to handle both cases and just verify the attempt was made.
3129
try {
32-
const module = await loadLwcDevServer('65.0');
30+
const module = await loadLwcModule('65.0');
3331
expect(module).to.exist;
3432
} catch (error) {
3533
// If it fails with a ReferenceError or similar, it's still "working" in terms of
3634
// attempting to load the right package name.
3735
const errorMessage = (error as Error).message;
3836
if (errorMessage.includes('could not be imported')) {
39-
expect(errorMessage).to.include('@lwc/lwc-dev-server-65.0');
37+
expect(errorMessage).to.include('@lwc/sfdx-local-dev-dist-65.0');
4038
} else {
4139
// Other errors (like ReferenceError: Element is not defined) mean the package WAS found and loaded
4240
expect(errorMessage).to.not.include('could not be imported');

0 commit comments

Comments
 (0)