[fs-detectors] getMonorepoDefaultSettings: Fix settings (#9315)

1. `commandForIgnoringBuildStep` should be run at the project directory level not the monorepo root level
2. Simplifying the `installCommand` because doesn't need the relative root unless it is `npm`
This commit is contained in:
chloetedder
2023-01-30 11:35:42 -07:00
committed by GitHub
parent fdf7fd6784
commit 31f3daa5b4
14 changed files with 48 additions and 26 deletions

View File

@@ -1229,13 +1229,13 @@ describe('build', () => {
turbo: {
name: 'Turbo',
buildCommand: 'cd ../.. && npx turbo run build --filter=app-1...',
installCommand: 'cd ../.. && yarn install',
ignoreCommand: 'cd ../.. && npx turbo-ignore',
installCommand: 'yarn install',
ignoreCommand: 'npx turbo-ignore',
},
nx: {
name: 'Nx',
buildCommand: 'cd ../.. && npx nx build app-1',
installCommand: 'cd ../.. && yarn install',
installCommand: 'yarn install',
},
// rush: {
// name: 'Rush',

View File

@@ -67,8 +67,11 @@ export async function getMonorepoDefaultSettings(
return {
monorepoManager: 'turbo',
buildCommand: `cd ${relativeToRoot} && npx turbo run build --filter={${projectPath}}...`,
installCommand: `cd ${relativeToRoot} && ${packageManager} install`,
commandForIgnoringBuildStep: `cd ${relativeToRoot} && npx turbo-ignore`,
installCommand:
packageManager === 'npm'
? `${packageManager} install --prefix=${relativeToRoot}`
: `${packageManager} install`,
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,7 +114,10 @@ export async function getMonorepoDefaultSettings(
return {
monorepoManager: 'nx',
buildCommand: `cd ${relativeToRoot} && npx nx build ${projectName}`,
installCommand: `cd ${relativeToRoot} && ${packageManager} install`,
installCommand:
packageManager === 'npm'
? `${packageManager} install --prefix=${relativeToRoot}`
: `${packageManager} install`,
};
}
// TODO (@Ethan-Arrowood) - Revisit rush support when we can test it better

View File

@@ -1,5 +1,5 @@
{
"name": "app-1",
"name": "app-11",
"version": "0.0.1",
"nx": {
"targets": {

View File

@@ -1,5 +1,5 @@
{
"name": "app-1",
"name": "app-10",
"version": "0.0.1",
"nx": {
"targets": {}

View File

@@ -1,5 +1,5 @@
{
"name": "app-1",
"name": "app-9",
"version": "0.0.1",
"nx": {
"targets": {

View File

@@ -1,4 +1,4 @@
{
"name": "app-1",
"name": "app-8",
"version": "0.0.1"
}

View File

@@ -1,4 +1,4 @@
{
"name": "app-1",
"name": "app-12",
"version": "0.0.1"
}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,9 @@
{
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"turbo": "1.6.3"
}
}

View File

@@ -0,0 +1,4 @@
{
"name": "app-15",
"version": "0.0.1"
}

View File

@@ -0,0 +1 @@
{ "pipeline": { "build": { "dependsOn": ["^build"], "outputs": ["dist/**"] } } }

View File

@@ -1,4 +1,4 @@
{
"name": "app-1",
"name": "app-13",
"version": "0.0.1"
}

View File

@@ -1,4 +1,4 @@
{
"name": "app-1",
"name": "app-14",
"version": "0.0.1"
}

View File

@@ -26,26 +26,27 @@ describe('getMonorepoDefaultSettings', () => {
});
test.each([
['turbo', 'turbo'],
['turbo-package-config', 'turbo'],
['nx', 'nx'],
['nx-package-config', 'nx'],
['nx-project-and-package-config-1', 'nx'],
['nx-project-and-package-config-2', 'nx'],
['nx-project-config', 'nx'],
])('fixture %s', async (fixture, expectedResultKey) => {
['turbo', 'turbo', false, 'app-14'],
['turbo-package-config', 'turbo', false, 'app-13'],
['turbo-npm', 'turbo', true, 'app-15'],
['nx', 'nx', false, 'app-12'],
['nx-package-config', 'nx', false, 'app-11'],
['nx-project-and-package-config-1', 'nx', false, 'app-10'],
['nx-project-and-package-config-2', 'nx', false, 'app-9'],
['nx-project-config', 'nx', false, 'app-8'],
])('fixture %s', async (fixture, expectedResultKey, isNpm, packageName) => {
const expectedResultMap: Record<string, Record<string, string>> = {
turbo: {
monorepoManager: 'turbo',
buildCommand:
'cd ../.. && npx turbo run build --filter={packages/app-1}...',
installCommand: 'cd ../.. && yarn install',
commandForIgnoringBuildStep: 'cd ../.. && npx turbo-ignore',
installCommand: isNpm ? 'npm install --prefix=../..' : 'yarn install',
commandForIgnoringBuildStep: 'npx turbo-ignore',
},
nx: {
monorepoManager: 'nx',
buildCommand: 'cd ../.. && npx nx build app-1',
installCommand: 'cd ../.. && yarn install',
buildCommand: `cd ../.. && npx nx build ${packageName}`,
installCommand: 'yarn install',
},
};
@@ -53,7 +54,7 @@ describe('getMonorepoDefaultSettings', () => {
path.join(__dirname, 'fixtures', 'get-monorepo-default-settings', fixture)
);
const result = await getMonorepoDefaultSettings(
'app-1',
packageName,
'packages/app-1',
'../..',
ffs