Skip to content

Commit

Permalink
fix(@turbo/codemode): no-op when turbo.json already contains tasks key (
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulkar authored Jun 13, 2024
1 parent da7508e commit 6add4d6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"outputs": ["dist"]
}
}
}
24 changes: 24 additions & 0 deletions packages/turbo-codemod/__tests__/rename-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,28 @@ describe("rename-pipeline", () => {
/No turbo\.json found at .*?\. Is the path correct\?/
);
});

it("does not do anything if there is already a top level tasks key", () => {
// load the fixture for the test
const { root, read } = useFixture({
fixture: "with-tasks",
});

// run the transformer
const result = transformer({
root,
options: { force: false, dryRun: false, print: false },
});

expect(JSON.parse(read("turbo.json") || "{}")).toStrictEqual({
$schema: "https://turbo.build/schema.json",
tasks: {
build: {
outputs: ["dist"],
},
},
});
expect(result.fatalError).toBeUndefined();
expect(result.changes).toStrictEqual({});
});
});
9 changes: 8 additions & 1 deletion packages/turbo-codemod/src/transforms/rename-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ export function transformer({
});
}

const turboJson: SchemaV1 = loadTurboJson(turboConfigPath);
const _turboJson: SchemaV1 | Schema = loadTurboJson(turboConfigPath);
if ("tasks" in _turboJson) {
// Don't do anything
log.info("turbo.json already has a tasks key, exiting");
return runner.finish();
}

const turboJson = _turboJson as SchemaV1;
runner.modifyFile({
filePath: turboConfigPath,
after: migrateConfig(turboJson),
Expand Down

0 comments on commit 6add4d6

Please sign in to comment.