Skip to content

Commit 5ca1b8a

Browse files
committed
fix(cli): find monorepo root before trying to search workspace for plugins
1 parent 34ff2f0 commit 5ca1b8a

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

cli/src/config.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { fatal, isFatal } from './errors';
1010
import { logger } from './log';
1111
import { tryFn } from './util/fn';
1212
import { formatJSObject } from './util/js';
13-
import { findNXMonorepoRoot, isNXMonorepo } from './util/monorepotools';
13+
import { findMonorepoRoot, findNXMonorepoRoot, isMonorepo, isNXMonorepo } from './util/monorepotools';
1414
import { requireTS, resolveNode } from './util/node';
1515
import { lazy } from './util/promise';
1616
import { getCommandOutput } from './util/subprocess';
@@ -40,10 +40,29 @@ export async function loadConfig(): Promise<Config> {
4040
return {};
4141
})();
4242

43+
const workspacesSetup = await (async (): Promise<Config['app']['workspaces'] | undefined> => {
44+
if (isMonorepo(appRootDir) && conf.extConfig.workspaces === 'npm') {
45+
const { fileType, path: rootOfMonorepo } = findMonorepoRoot(appRootDir);
46+
if (fileType === 'yaml') {
47+
return undefined;
48+
}
49+
const pkgJSONOfMonorepoRoot: { workspaces: string[] } | null = await tryFn(
50+
readJSON,
51+
resolve(rootOfMonorepo, 'package.json'),
52+
);
53+
const workspaces = pkgJSONOfMonorepoRoot?.workspaces ?? [];
54+
return {
55+
type: conf.extConfig.workspaces,
56+
workspaceDirs: workspaces,
57+
workspaceRoot: rootOfMonorepo,
58+
};
59+
}
60+
return undefined;
61+
})();
62+
4363
const appId = conf.extConfig.appId ?? '';
4464
const appName = conf.extConfig.appName ?? '';
4565
const webDir = conf.extConfig.webDir ?? 'www';
46-
const workspaces = conf.extConfig.workspaces;
4766
const cli = await loadCLIConfig(cliRootDir);
4867

4968
const config: Config = {
@@ -62,7 +81,7 @@ export async function loadConfig(): Promise<Config> {
6281
version: '1.0.0',
6382
...depsForNx,
6483
},
65-
workspaces,
84+
workspaces: workspacesSetup,
6685
...conf,
6786
},
6887
};

cli/src/definitions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export interface AppConfig {
6363
readonly extConfigName: string;
6464
readonly extConfigFilePath: string;
6565
readonly extConfig: ExternalConfig;
66-
readonly workspaces: 'npm' | undefined;
66+
readonly workspaces:
67+
| { type: 'npm'; workspaceDirs: string[]; workspaceRoot: string }
68+
| undefined;
6769
}
6870

6971
export interface AndroidConfig extends PlatformConfig {

cli/src/plugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ export function getIncludedPluginPackages(config: Config, platform: string): rea
5454
}
5555
}
5656
export async function getPlugins(config: Config, platform: string): Promise<Plugin[]> {
57-
if (config.app.workspaces === 'npm' && config.app.package.workspaces !== undefined) {
57+
if (config.app.workspaces?.type === 'npm') {
58+
const { workspaceDirs, workspaceRoot } = config.app.workspaces;
5859
const workspacePackages = await mapWorkspaces({
59-
cwd: config.app.rootDir,
60-
pkg: { workspaces: config.app.package.workspaces },
60+
cwd: workspaceRoot,
61+
pkg: { workspaces: workspaceDirs },
6162
});
6263
const resolvedWorkspacePackages = await Promise.all(
6364
Array.from(workspacePackages.entries()).map(async ([name, path]) => {

0 commit comments

Comments
 (0)