Skip to content

Commit d6f8753

Browse files
committed
fix: consider lwc dirs nested under package directories
1 parent 7c8d5e5 commit d6f8753

File tree

3 files changed

+84
-55
lines changed

3 files changed

+84
-55
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {
8-
"@lwrjs/api": "0.14.3",
8+
"@inquirer/prompts": "^5.3.8",
9+
"@inquirer/select": "^2.4.7",
910
"@lwc/lwc-dev-server": "^9.5.1",
1011
"@lwc/sfdc-lwc-compiler": "^9.5.1",
12+
"@lwrjs/api": "0.14.3",
1113
"@oclif/core": "^4.0.17",
1214
"@salesforce/core": "^8.2.7",
1315
"@salesforce/kit": "^3.1.6",
1416
"@salesforce/lwc-dev-mobile-core": "4.0.0-alpha.9",
1517
"@salesforce/sf-plugins-core": "^11.2.4",
16-
"@inquirer/select": "^2.4.7",
17-
"@inquirer/prompts": "^5.3.8",
1818
"axios": "^1.7.7",
19+
"glob": "^11.0.0",
1920
"lwc": "7.1.3",
2021
"lwr": "0.14.3",
2122
"node-fetch": "^3.3.2"

src/lwc-dev-server/index.ts

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,18 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { existsSync, lstatSync, readFileSync } from 'node:fs';
98
import path from 'node:path';
109
import process from 'node:process';
11-
import { LWCServer, LogLevel, ServerConfig, startLwcDevServer, Workspace } from '@lwc/lwc-dev-server';
12-
import { Lifecycle, Logger } from '@salesforce/core';
10+
import { LWCServer, ServerConfig, startLwcDevServer, Workspace } from '@lwc/lwc-dev-server';
11+
import { Lifecycle, Logger, SfProject } from '@salesforce/core';
1312
import { SSLCertificateData } from '@salesforce/lwc-dev-mobile-core';
13+
import { globSync } from 'glob';
1414
import {
1515
ConfigUtils,
1616
LOCAL_DEV_SERVER_DEFAULT_HTTP_PORT,
1717
LOCAL_DEV_SERVER_DEFAULT_WORKSPACE,
1818
} from '../shared/configUtils.js';
1919

20-
/**
21-
* Map sf cli log level to lwc dev server log level
22-
* https://github.com/salesforcecli/cli/wiki/Code-Your-Plugin#logging-levels
23-
*
24-
* @param cliLogLevel
25-
* @returns number
26-
*/
27-
function mapLogLevel(cliLogLevel: number): number {
28-
switch (cliLogLevel) {
29-
case 10:
30-
return LogLevel.verbose;
31-
case 20:
32-
return LogLevel.debug;
33-
case 30:
34-
return LogLevel.info;
35-
case 40:
36-
return LogLevel.warn;
37-
case 50:
38-
return LogLevel.error;
39-
case 60:
40-
return LogLevel.silent;
41-
default:
42-
return LogLevel.error;
43-
}
44-
}
45-
4620
async function createLWCServerConfig(
4721
logger: Logger,
4822
rootDir: string,
@@ -52,28 +26,19 @@ async function createLWCServerConfig(
5226
certData?: SSLCertificateData,
5327
workspace?: Workspace
5428
): Promise<ServerConfig> {
55-
const sfdxConfig = path.resolve(rootDir, 'sfdx-project.json');
29+
const project = await SfProject.resolve();
30+
const projectJson = await project.resolveProjectConfig();
31+
const packageDirectories = projectJson.packageDirectories;
32+
const namespacePaths: string[] = [];
5633

57-
if (!existsSync(sfdxConfig) || !lstatSync(sfdxConfig).isFile()) {
58-
throw new Error(`sfdx-project.json not found in ${rootDir}`);
34+
if (!packageDirectories || !Array.isArray(packageDirectories)) {
35+
throw new Error('No package directories defined.');
5936
}
6037

61-
const sfdxConfigJson = readFileSync(sfdxConfig, 'utf-8');
62-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
63-
const { packageDirectories } = JSON.parse(sfdxConfigJson);
64-
const namespacePaths: string[] = [];
65-
6638
for (const dir of packageDirectories) {
67-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
68-
if (dir.path) {
69-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
70-
const resolvedDir = path.resolve(rootDir, dir.path, 'main', 'default');
71-
if (existsSync(resolvedDir) && lstatSync(resolvedDir).isDirectory()) {
72-
logger.debug(`Adding ${resolvedDir} to namespace paths`);
73-
namespacePaths.push(resolvedDir);
74-
} else {
75-
logger.warn(`Skipping ${resolvedDir} because it does not exist or is not a directory`);
76-
}
39+
if (dir && typeof dir === 'object' && 'path' in dir && typeof dir.path === 'string') {
40+
const packageDirectory = path.resolve(rootDir, dir.path);
41+
namespacePaths.push(...globSync(`${packageDirectory}/*/*/lwc`));
7742
}
7843
}
7944

@@ -91,7 +56,6 @@ async function createLWCServerConfig(
9156
// use custom workspace if any is provided, or fetch from config file (if any), otherwise use the default workspace
9257
workspace: workspace ?? (await ConfigUtils.getLocalDevServerWorkspace()) ?? LOCAL_DEV_SERVER_DEFAULT_WORKSPACE,
9358
identityToken: token,
94-
logLevel: mapLogLevel(logger.getLevel()),
9559
lifecycle: Lifecycle.getInstance(),
9660
clientType,
9761
};
@@ -119,7 +83,7 @@ export async function startLWCServer(
11983
const config = await createLWCServerConfig(logger, rootDir, token, clientType, serverPorts, certData, workspace);
12084

12185
logger.trace(`Starting LWC Dev Server with config: ${JSON.stringify(config)}`);
122-
let lwcDevServer: LWCServer | null = await startLwcDevServer(config);
86+
let lwcDevServer: LWCServer | null = await startLwcDevServer(config, logger);
12387

12488
const cleanup = (): void => {
12589
if (lwcDevServer) {

yarn.lock

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9245,6 +9245,18 @@ glob@^10.3.10:
92459245
package-json-from-dist "^1.0.0"
92469246
path-scurry "^1.11.1"
92479247

9248+
glob@^11.0.0:
9249+
version "11.0.0"
9250+
resolved "https://nexus-proxy.repo.local.sfdc.net/nexus/content/groups/npm-all/glob/-/glob-11.0.0.tgz#6031df0d7b65eaa1ccb9b29b5ced16cea658e77e"
9251+
integrity sha512-9UiX/Bl6J2yaBbxKoEBRm4Cipxgok8kQYcOPEhScPwebu2I0HoQOuYdIO6S3hLuWoZgpDpwQZMzTFxgpkyT76g==
9252+
dependencies:
9253+
foreground-child "^3.1.0"
9254+
jackspeak "^4.0.1"
9255+
minimatch "^10.0.0"
9256+
minipass "^7.1.2"
9257+
package-json-from-dist "^1.0.0"
9258+
path-scurry "^2.0.0"
9259+
92489260
glob@^8.0.3, glob@^8.1.0:
92499261
version "8.1.0"
92509262
resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e"
@@ -10500,6 +10512,13 @@ jackspeak@^3.1.2:
1050010512
optionalDependencies:
1050110513
"@pkgjs/parseargs" "^0.11.0"
1050210514

10515+
jackspeak@^4.0.1:
10516+
version "4.0.2"
10517+
resolved "https://nexus-proxy.repo.local.sfdc.net/nexus/content/groups/npm-all/jackspeak/-/jackspeak-4.0.2.tgz#11f9468a3730c6ff6f56823a820d7e3be9bef015"
10518+
integrity sha512-bZsjR/iRjl1Nk1UkjGpAzLNfQtzuijhn2g+pbZb98HQ1Gk8vM9hfbxeMBP+M2/UUdwj0RqGG3mlvk2MsAqwvEw==
10519+
dependencies:
10520+
"@isaacs/cliui" "^8.0.2"
10521+
1050310522
jake@^10.8.5:
1050410523
version "10.9.2"
1050510524
resolved "https://registry.yarnpkg.com/jake/-/jake-10.9.2.tgz#6ae487e6a69afec3a5e167628996b59f35ae2b7f"
@@ -11553,6 +11572,11 @@ lru-cache@^10.0.1, lru-cache@^10.2.0, lru-cache@^10.4.3:
1155311572
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119"
1155411573
integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==
1155511574

11575+
lru-cache@^11.0.0:
11576+
version "11.0.1"
11577+
resolved "https://nexus-proxy.repo.local.sfdc.net/nexus/content/groups/npm-all/lru-cache/-/lru-cache-11.0.1.tgz#3a732fbfedb82c5ba7bca6564ad3f42afcb6e147"
11578+
integrity sha512-CgeuL5uom6j/ZVrg7G/+1IXqRY8JXX4Hghfy5YE0EhoYQWvndP1kufu58cmZLNIDKnRhZrXfdS9urVWx98AipQ==
11579+
1155611580
lru-cache@^5.1.1:
1155711581
version "5.1.1"
1155811582
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
@@ -12059,6 +12083,13 @@ minimatch@9.0.3:
1205912083
dependencies:
1206012084
brace-expansion "^2.0.1"
1206112085

12086+
minimatch@^10.0.0:
12087+
version "10.0.1"
12088+
resolved "https://nexus-proxy.repo.local.sfdc.net/nexus/content/groups/npm-all/minimatch/-/minimatch-10.0.1.tgz#ce0521856b453c86e25f2c4c0d03e6ff7ddc440b"
12089+
integrity sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==
12090+
dependencies:
12091+
brace-expansion "^2.0.1"
12092+
1206212093
minimatch@^5.0.1, minimatch@^5.1.6, minimatch@~5.1.1:
1206312094
version "5.1.6"
1206412095
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"
@@ -12903,6 +12934,14 @@ path-scurry@^1.11.1:
1290312934
lru-cache "^10.2.0"
1290412935
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
1290512936

12937+
path-scurry@^2.0.0:
12938+
version "2.0.0"
12939+
resolved "https://nexus-proxy.repo.local.sfdc.net/nexus/content/groups/npm-all/path-scurry/-/path-scurry-2.0.0.tgz#9f052289f23ad8bf9397a2a0425e7b8615c58580"
12940+
integrity sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==
12941+
dependencies:
12942+
lru-cache "^11.0.0"
12943+
minipass "^7.1.2"
12944+
1290612945
path-to-regexp@0.1.7:
1290712946
version "0.1.7"
1290812947
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
@@ -14485,7 +14524,16 @@ string-length@^4.0.1:
1448514524
char-regex "^1.0.2"
1448614525
strip-ansi "^6.0.0"
1448714526

14488-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
14527+
"string-width-cjs@npm:string-width@^4.2.0":
14528+
version "4.2.3"
14529+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
14530+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
14531+
dependencies:
14532+
emoji-regex "^8.0.0"
14533+
is-fullwidth-code-point "^3.0.0"
14534+
strip-ansi "^6.0.1"
14535+
14536+
string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1448914537
version "4.2.3"
1449014538
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1449114539
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -14589,7 +14637,14 @@ stringify-entities@^3.0.1:
1458914637
character-entities-legacy "^1.0.0"
1459014638
xtend "^4.0.0"
1459114639

14592-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
14640+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
14641+
version "6.0.1"
14642+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
14643+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
14644+
dependencies:
14645+
ansi-regex "^5.0.1"
14646+
14647+
strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1459314648
version "6.0.1"
1459414649
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1459514650
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -15885,7 +15940,7 @@ workerpool@^6.5.1:
1588515940
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544"
1588615941
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==
1588715942

15888-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
15943+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
1588915944
version "7.0.0"
1589015945
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1589115946
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -15903,6 +15958,15 @@ wrap-ansi@^6.2.0:
1590315958
string-width "^4.1.0"
1590415959
strip-ansi "^6.0.0"
1590515960

15961+
wrap-ansi@^7.0.0:
15962+
version "7.0.0"
15963+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
15964+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
15965+
dependencies:
15966+
ansi-styles "^4.0.0"
15967+
string-width "^4.1.0"
15968+
strip-ansi "^6.0.0"
15969+
1590615970
wrap-ansi@^8.1.0:
1590715971
version "8.1.0"
1590815972
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)