Skip to content

Commit

Permalink
fix(cli): find monorepo root before trying to search workspace for pl…
Browse files Browse the repository at this point in the history
…ugins
  • Loading branch information
laine-hallot committed Oct 29, 2024
1 parent 05c66b4 commit d926beb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
25 changes: 22 additions & 3 deletions cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { fatal, isFatal } from './errors';
import { logger } from './log';
import { tryFn } from './util/fn';
import { formatJSObject } from './util/js';
import { findNXMonorepoRoot, isNXMonorepo } from './util/monorepotools';
import { findMonorepoRoot, findNXMonorepoRoot, isMonorepo, isNXMonorepo } from './util/monorepotools';
import { requireTS, resolveNode } from './util/node';
import { lazy } from './util/promise';
import { getCommandOutput } from './util/subprocess';
Expand Down Expand Up @@ -40,10 +40,29 @@ export async function loadConfig(): Promise<Config> {
return {};
})();

const workspacesSetup = await (async (): Promise<Config['app']['workspaces'] | undefined> => {
if (isMonorepo(appRootDir) && conf.extConfig.workspaces === 'npm') {
const { fileType, path: rootOfMonorepo } = findMonorepoRoot(appRootDir);
if (fileType === 'yaml') {
return undefined;
}
const pkgJSONOfMonorepoRoot: { workspaces: string[] } | null = await tryFn(
readJSON,
resolve(rootOfMonorepo, 'package.json'),
);
const workspaces = pkgJSONOfMonorepoRoot?.workspaces ?? [];
return {
type: conf.extConfig.workspaces,
workspaceDirs: workspaces,
workspaceRoot: rootOfMonorepo,
};
}
return undefined;
})();

const appId = conf.extConfig.appId ?? '';
const appName = conf.extConfig.appName ?? '';
const webDir = conf.extConfig.webDir ?? 'www';
const workspaces = conf.extConfig.workspaces;
const cli = await loadCLIConfig(cliRootDir);

const config: Config = {
Expand All @@ -62,7 +81,7 @@ export async function loadConfig(): Promise<Config> {
version: '1.0.0',
...depsForNx,
},
workspaces,
workspaces: workspacesSetup,
...conf,
},
};
Expand Down
4 changes: 3 additions & 1 deletion cli/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export interface AppConfig {
readonly extConfigName: string;
readonly extConfigFilePath: string;
readonly extConfig: ExternalConfig;
readonly workspaces: 'npm' | undefined;
readonly workspaces:
| { type: 'npm'; workspaceDirs: string[]; workspaceRoot: string }
| undefined;
}

export interface AndroidConfig extends PlatformConfig {
Expand Down
7 changes: 4 additions & 3 deletions cli/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export function getIncludedPluginPackages(config: Config, platform: string): rea
}
}
export async function getPlugins(config: Config, platform: string): Promise<Plugin[]> {
if (config.app.workspaces === 'npm' && config.app.package.workspaces !== undefined) {
if (config.app.workspaces?.type === 'npm') {
const { workspaceDirs, workspaceRoot } = config.app.workspaces;
const workspacePackages = await mapWorkspaces({
cwd: config.app.rootDir,
pkg: { workspaces: config.app.package.workspaces },
cwd: workspaceRoot,
pkg: { workspaces: workspaceDirs },
});
const resolvedWorkspacePackages = await Promise.all(
Array.from(workspacePackages.entries()).map(async ([name, path]) => {
Expand Down

0 comments on commit d926beb

Please sign in to comment.