feat(turbo): add support for turbo 2 configuration (#11680)

With the release of Turborepo 2 we're renaming `pipeline` to `tasks`. 

This PR updates the default settings logic to look in `tasks` for a
`build` task definition in addition to looking at `pipeline`. It also
updates the message to no longer mention Turbo configuration in
`package.json` as this is fully ignored in Turborepo 2.

Added a quick unit test to verify `build` task definitions are found in
the `tasks` section of `turbo.json`.

Please let me know if there are other tests/places I should update.
This commit is contained in:
Chris Olszewski
2024-06-04 10:36:35 -07:00
committed by GitHub
parent 4337ea0654
commit 5dedc7b2ce
6 changed files with 39 additions and 7 deletions

View File

@@ -7,10 +7,11 @@ import JSON5 from 'json5';
import semver from 'semver';
export class MissingBuildPipeline extends Error {
constructor() {
super(
'Missing required `build` pipeline in turbo.json or package.json Turbo configuration.'
);
constructor(usesTasks: boolean) {
const message = usesTasks
? 'Missing required `build` task in turbo.json.'
: 'Missing required `build` pipeline in turbo.json or package.json Turbo configuration.';
super(message);
}
}
@@ -65,12 +66,15 @@ export async function getMonorepoDefaultSettings(
]);
let hasBuildPipeline = false;
let hasTurboTasks = false;
let turboSemVer = null;
if (turboJSONBuf !== null) {
const turboJSON = JSON5.parse(turboJSONBuf.toString('utf-8'));
if (turboJSON?.pipeline?.build) {
hasTurboTasks = 'tasks' in (turboJSON || {});
if (turboJSON?.pipeline?.build || turboJSON?.tasks?.build) {
hasBuildPipeline = true;
}
}
@@ -89,7 +93,7 @@ export async function getMonorepoDefaultSettings(
}
if (!hasBuildPipeline) {
throw new MissingBuildPipeline();
throw new MissingBuildPipeline(hasTurboTasks);
}
if (projectPath === '/') {