aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-codemod/src/commands/migrate/steps/getCurrentVersion.ts
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /packages/turbo-codemod/src/commands/migrate/steps/getCurrentVersion.ts
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'packages/turbo-codemod/src/commands/migrate/steps/getCurrentVersion.ts')
-rw-r--r--packages/turbo-codemod/src/commands/migrate/steps/getCurrentVersion.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/turbo-codemod/src/commands/migrate/steps/getCurrentVersion.ts b/packages/turbo-codemod/src/commands/migrate/steps/getCurrentVersion.ts
new file mode 100644
index 0000000..3644f8b
--- /dev/null
+++ b/packages/turbo-codemod/src/commands/migrate/steps/getCurrentVersion.ts
@@ -0,0 +1,45 @@
+import path from "path";
+import { existsSync } from "fs-extra";
+
+import getPackageManager from "../../../utils/getPackageManager";
+import { exec } from "../utils";
+import type { MigrateCommandOptions } from "../types";
+
+function getCurrentVersion(
+ directory: string,
+ opts: MigrateCommandOptions
+): string | undefined {
+ const { from } = opts;
+ if (from) {
+ return from;
+ }
+
+ // try global first
+ const turboVersionFromGlobal = exec(`turbo --version`, { cwd: directory });
+
+ if (turboVersionFromGlobal) {
+ return turboVersionFromGlobal;
+ }
+
+ // try to use the package manager to find the version
+ const packageManager = getPackageManager({ directory });
+ if (packageManager) {
+ if (packageManager === "yarn") {
+ return exec(`yarn turbo --version`, { cwd: directory });
+ }
+ if (packageManager === "pnpm") {
+ return exec(`pnpm turbo --version`, { cwd: directory });
+ } else {
+ // this doesn't work for npm, so manually build the binary path
+ const turboBin = path.join(directory, "node_modules", ".bin", "turbo");
+ if (existsSync(turboBin)) {
+ return exec(`${turboBin} --version`, { cwd: directory });
+ }
+ }
+ }
+
+ // unable to determine local version,
+ return undefined;
+}
+
+export default getCurrentVersion;