[fs-detectors] check turbo versions to allow for tags like "latest" (#9790)

When a project depends on `turbo` at version `latest`, this code was breaking because `latest` is not a valid range for `semver.intersects`.
This commit is contained in:
Sean Massa
2023-04-11 16:22:41 -05:00
committed by GitHub
parent 43a57a3a60
commit e302631ded
5 changed files with 30 additions and 1 deletions

View File

@@ -22,6 +22,18 @@ export class MissingBuildTarget extends Error {
}
}
function supportsRootCommand(turboSemVer: string | undefined) {
if (!turboSemVer) {
return false;
}
if (!semver.validRange(turboSemVer)) {
return false;
}
return !semver.intersects(turboSemVer, '<1.8.0');
}
type MonorepoDefaultSettings = {
buildCommand?: string | null;
installCommand?: string | null;
@@ -91,7 +103,7 @@ export async function getMonorepoDefaultSettings(
let buildCommand = null;
if (projectPath) {
if (turboSemVer && !semver.intersects(turboSemVer, '<1.8.0')) {
if (supportsRootCommand(turboSemVer)) {
buildCommand = `turbo run build`;
} else {
// We don't know for sure if the local `turbo` supports inference.

View File

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

View File

@@ -0,0 +1,5 @@
{
"name": "app-14",
"version": "0.0.1",
"main": "index.js"
}

View File

@@ -0,0 +1,2 @@
// TEST COMMENT TO VERIFY JSON5 SUPPORT
{ "pipeline": { "build": { "dependsOn": ["^build"], "outputs": ["dist/**"] } } }

View File

@@ -31,6 +31,7 @@ describe('getMonorepoDefaultSettings', () => {
['turbo-package-config', 'turbo', false, 'app-13', false, false],
['turbo-npm', 'turbo', true, 'app-15', false, false],
['turbo-npm-root-proj', 'turbo', true, 'app-root-proj', true, false],
['turbo-latest', 'turbo', false, 'app-14', false, false],
['nx', 'nx', false, 'app-12', false, false],
['nx-package-config', 'nx', false, 'app-11', false, false],
['nx-project-and-package-config-1', 'nx', false, 'app-10', false, false],