[fs-detectors] Add fix for if monorepo and proj at root (#9353)

If there is a monorepo that has one project at the root level we want to
return commands without the relative to root prefixes

---------

Co-authored-by: Chris Barber <chris.barber@vercel.com>
This commit is contained in:
chloetedder
2023-02-03 15:56:22 -07:00
committed by GitHub
parent 8120fd3d7a
commit 2eef3e3ddb
6 changed files with 132 additions and 42 deletions

View File

@@ -21,12 +21,19 @@ export class MissingBuildTarget extends Error {
}
}
type MonorepoDefaultSettings = {
buildCommand?: string | null;
installCommand?: string | null;
commandForIgnoringBuildStep?: string;
monorepoManager: string;
} | null;
export async function getMonorepoDefaultSettings(
projectName: string,
projectPath: string,
relativeToRoot: string,
detectorFilesystem: DetectorFilesystem
) {
): Promise<MonorepoDefaultSettings> {
const [monorepoManager, packageManager] = await Promise.all([
detectFramework({
fs: detectorFilesystem,
@@ -64,14 +71,27 @@ export async function getMonorepoDefaultSettings(
throw new MissingBuildPipeline();
}
if (projectPath === '/') {
return {
monorepoManager: 'turbo',
buildCommand: 'npx turbo run build',
installCommand: packageManager ? `${packageManager} install` : null,
commandForIgnoringBuildStep: 'npx turbo-ignore',
};
}
return {
monorepoManager: 'turbo',
buildCommand: `cd ${relativeToRoot} && npx turbo run build --filter={${projectPath}}...`,
buildCommand: projectPath
? `cd ${relativeToRoot} && npx turbo run build --filter={${projectPath}}...`
: null,
installCommand:
packageManager === 'npm'
? `${packageManager} install --prefix=${relativeToRoot}`
: `${packageManager} install`,
commandForIgnoringBuildStep: `npx turbo-ignore`,
: packageManager
? `${packageManager} install`
: null,
commandForIgnoringBuildStep: 'npx turbo-ignore',
};
} else if (monorepoManager === 'nx') {
// No ENOENT handling required here since conditional wouldn't be `true` unless `nx.json` was found.
@@ -111,13 +131,24 @@ export async function getMonorepoDefaultSettings(
}
}
if (projectPath === '/') {
return {
monorepoManager: 'nx',
buildCommand: 'npx nx build',
installCommand: packageManager ? `${packageManager} install` : null,
};
}
return {
monorepoManager: 'nx',
buildCommand: `cd ${relativeToRoot} && npx nx build ${projectName}`,
buildCommand: projectName
? `cd ${relativeToRoot} && npx nx build ${projectName}`
: null,
installCommand:
packageManager === 'npm'
? `${packageManager} install --prefix=${relativeToRoot}`
: `${packageManager} install`,
: packageManager
? `${packageManager} install`
: null,
};
}
// TODO (@Ethan-Arrowood) - Revisit rush support when we can test it better