-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codemod): add logic for major version bump (#8260)
### Description Add migration logic for the 1->2 move. For the major bump we run all existing transforms that are safe to be run twice to ensure that `turbo.json` is in the desired state. A few things to note: - We change the introduction version for the 2.0 codemods to the canary to allow for easier testing - I updated `migrate-dot-env` to work with either `pipeline` or `tasks` as there isn't a great way to order transforms that are introduced in the same version. - Add an idempotent flag to transformers that defaults to `true`. This is used to mark a transformation as one to avoid re-running. ### Testing Instructions Added unit test for major version migration. Manual testing on repos via `turbo build --filter='@turbo/codemod'` and then using `node ~/code/turbo/packages/turbo-codemod/dist/cli.js migrate --to 2.0.0-canary.0` (canary is necessary due to 2.0.0 not existing in npm yet).
- Loading branch information
1 parent
80b8e48
commit 35a0708
Showing
13 changed files
with
153 additions
and
14 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
packages/turbo-codemod/__tests__/__fixtures__/migrate/turbo-1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "turbo-1", | ||
"version": "1.0.0", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"turbo": "1.7.1" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/turbo-codemod/__tests__/__fixtures__/migrate/turbo-1/turbo.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"$schema": "https://turbo.build/schema.json", | ||
"pipeline": { | ||
"build": { | ||
"outputs": [".next/**", "!.next/cache/**"] | ||
}, | ||
"lint": { | ||
"dotEnv": [".env.local"], | ||
"outputs": [] | ||
}, | ||
"test": { | ||
"outputMode": "errors-only" | ||
}, | ||
"dev": { | ||
"cache": false | ||
} | ||
}, | ||
"experimentalUI": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -924,4 +924,94 @@ describe("migrate", () => { | |
// restore mocks | ||
mockedCheckGitStatus.mockRestore(); | ||
}); | ||
|
||
it("migrates across majors with all required codemods", async () => { | ||
const { root, readJson } = useFixture({ | ||
fixture: "turbo-1", | ||
}); | ||
|
||
const packageManager = "pnpm"; | ||
const packageManagerVersion = "1.2.3"; | ||
|
||
// setup mocks | ||
const mockedCheckGitStatus = jest | ||
.spyOn(checkGitStatus, "checkGitStatus") | ||
.mockReturnValue(undefined); | ||
const mockedGetCurrentVersion = jest | ||
.spyOn(getCurrentVersion, "getCurrentVersion") | ||
.mockReturnValue("1.99.99"); | ||
const mockedGetLatestVersion = jest | ||
.spyOn(getLatestVersion, "getLatestVersion") | ||
.mockResolvedValue("2.0.0"); | ||
const mockedGetTurboUpgradeCommand = jest | ||
.spyOn(getTurboUpgradeCommand, "getTurboUpgradeCommand") | ||
.mockResolvedValue("pnpm install -g turbo@latest"); | ||
const mockedGetAvailablePackageManagers = jest | ||
.spyOn(turboUtils, "getAvailablePackageManagers") | ||
.mockResolvedValue({ | ||
pnpm: packageManagerVersion, | ||
npm: undefined, | ||
yarn: undefined, | ||
bun: undefined, | ||
}); | ||
const mockedGetWorkspaceDetails = jest | ||
.spyOn(turboWorkspaces, "getWorkspaceDetails") | ||
.mockResolvedValue( | ||
getWorkspaceDetailsMockReturnValue({ | ||
root, | ||
packageManager, | ||
}) | ||
); | ||
|
||
await migrate(root, { | ||
force: false, | ||
dry: false, | ||
print: false, | ||
install: false, | ||
}); | ||
|
||
expect(readJson("package.json")).toStrictEqual({ | ||
dependencies: {}, | ||
devDependencies: { | ||
turbo: "1.7.1", | ||
}, | ||
name: "turbo-1", | ||
packageManager: "[email protected]", | ||
version: "1.0.0", | ||
}); | ||
expect(readJson("turbo.json")).toStrictEqual({ | ||
$schema: "https://turbo.build/schema.json", | ||
tasks: { | ||
build: { | ||
outputs: [".next/**", "!.next/cache/**"], | ||
}, | ||
dev: { | ||
cache: false, | ||
}, | ||
lint: { | ||
inputs: ["$TURBO_DEFAULT$", ".env.local"], | ||
outputs: [], | ||
}, | ||
test: { | ||
outputLogs: "errors-only", | ||
}, | ||
}, | ||
}); | ||
|
||
// verify mocks were called | ||
expect(mockedCheckGitStatus).toHaveBeenCalled(); | ||
expect(mockedGetCurrentVersion).toHaveBeenCalled(); | ||
expect(mockedGetLatestVersion).toHaveBeenCalled(); | ||
expect(mockedGetTurboUpgradeCommand).toHaveBeenCalled(); | ||
expect(mockedGetAvailablePackageManagers).toHaveBeenCalled(); | ||
expect(mockedGetWorkspaceDetails).toHaveBeenCalled(); | ||
|
||
// restore mocks | ||
mockedCheckGitStatus.mockRestore(); | ||
mockedGetCurrentVersion.mockRestore(); | ||
mockedGetLatestVersion.mockRestore(); | ||
mockedGetTurboUpgradeCommand.mockRestore(); | ||
mockedGetAvailablePackageManagers.mockRestore(); | ||
mockedGetWorkspaceDetails.mockRestore(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters