From 243b72b5e9e086434d4fc2b3fb15ff0a9332e9db Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Thu, 12 Dec 2024 15:16:50 -0700 Subject: [PATCH] WIP --- packages/turbo-workspaces/src/cli.ts | 5 ++++ packages/turbo-workspaces/src/convert.ts | 26 ++++++++++--------- packages/turbo-workspaces/src/types.ts | 1 + pnpm-lock.yaml | 21 ++++++++++++++- .../example-basic-npm/package.json | 3 +-- turborepo-tests/helpers/package.json | 8 +++++- turborepo-tests/helpers/setup_example_test.sh | 16 +++++++----- turborepo-tests/helpers/turbo.json | 5 +++- 8 files changed, 61 insertions(+), 24 deletions(-) diff --git a/packages/turbo-workspaces/src/cli.ts b/packages/turbo-workspaces/src/cli.ts index 8ff87fd35d446..607cc189303a8 100644 --- a/packages/turbo-workspaces/src/cli.ts +++ b/packages/turbo-workspaces/src/cli.ts @@ -25,6 +25,11 @@ workspacesCli "Do not run a package manager install after conversion", false ) + .option( + "--ignore-unchanged-package-manager", + "Always exit with a successful status (exit code 0)", + false + ) .option("--dry", "Dry run (no changes are made to files)", false) .option( "--force", diff --git a/packages/turbo-workspaces/src/convert.ts b/packages/turbo-workspaces/src/convert.ts index 6f7f55418a3d0..c6f3b893674a7 100644 --- a/packages/turbo-workspaces/src/convert.ts +++ b/packages/turbo-workspaces/src/convert.ts @@ -36,19 +36,21 @@ export async function convertProject({ `Converting project from ${project.packageManager} to ${convertTo.name}.` ); - if (project.packageManager === convertTo.name) { - throw new ConvertError("You are already using this package manager", { - type: "package_manager-already_in_use", - }); - } + if (!options?.ignoreUnchangedPackageManager) { + if (project.packageManager === convertTo.name) { + throw new ConvertError("You are already using this package manager", { + type: "package_manager-already_in_use", + }); + } - if (!convertTo.version) { - throw new ConvertError( - `${convertTo.name} is not installed, or could not be located`, - { - type: "package_manager-could_not_be_found", - } - ); + if (!convertTo.version) { + throw new ConvertError( + `${convertTo.name} is not installed, or could not be located`, + { + type: "package_manager-could_not_be_found", + } + ); + } } // this cast is safe since we've just verified that the version exists above diff --git a/packages/turbo-workspaces/src/types.ts b/packages/turbo-workspaces/src/types.ts index 2659c4fb5b1c3..1a65a9f3b26d6 100644 --- a/packages/turbo-workspaces/src/types.ts +++ b/packages/turbo-workspaces/src/types.ts @@ -92,6 +92,7 @@ export interface Options { dry?: boolean; skipInstall?: boolean; interactive?: boolean; + ignoreUnchangedPackageManager?: boolean; } export interface PackageManagerInstallDetails { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e72eca3c3c39..e95c9c8c2df48 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1008,7 +1008,11 @@ importers: specifier: workspace:* version: link:../helpers - turborepo-tests/helpers: {} + turborepo-tests/helpers: + dependencies: + '@turbo/workspaces': + specifier: workspace:* + version: link:../../packages/turbo-workspaces turborepo-tests/integration: dependencies: @@ -5601,6 +5605,7 @@ packages: /eslint-config-prettier@9.0.0(eslint@8.55.0): resolution: {integrity: sha512-IcJsTkJae2S35pRsRAwoCE+925rJJStOdkKnLVgtE+tEpqU0EVVM7OqrwxqgptKdX29NUwC82I5pXsGFIgSevw==} + hasBin: true peerDependencies: eslint: '>=7.0.0' dependencies: @@ -7653,6 +7658,7 @@ packages: /jest-cli@29.7.0(@types/node@18.17.4): resolution: {integrity: sha512-OVVobw2IubN/GSYsxETi+gOe7Ka59EFMR/twOU3Jb2GnKKeMGJB5SGUUrEz3SFVmJASUdZUzy83sLNNQ2gZslg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true peerDependencies: node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 peerDependenciesMeta: @@ -7680,6 +7686,7 @@ packages: /jest-cli@29.7.0(@types/node@18.17.4)(ts-node@10.9.2): resolution: {integrity: sha512-OVVobw2IubN/GSYsxETi+gOe7Ka59EFMR/twOU3Jb2GnKKeMGJB5SGUUrEz3SFVmJASUdZUzy83sLNNQ2gZslg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true peerDependencies: node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 peerDependenciesMeta: @@ -7707,6 +7714,7 @@ packages: /jest-cli@29.7.0(@types/node@20.5.7): resolution: {integrity: sha512-OVVobw2IubN/GSYsxETi+gOe7Ka59EFMR/twOU3Jb2GnKKeMGJB5SGUUrEz3SFVmJASUdZUzy83sLNNQ2gZslg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true peerDependencies: node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 peerDependenciesMeta: @@ -8139,6 +8147,7 @@ packages: /jest@29.7.0(@types/node@18.17.4): resolution: {integrity: sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true peerDependencies: node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 peerDependenciesMeta: @@ -8159,6 +8168,7 @@ packages: /jest@29.7.0(@types/node@18.17.4)(ts-node@10.9.2): resolution: {integrity: sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true peerDependencies: node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 peerDependenciesMeta: @@ -8179,6 +8189,7 @@ packages: /jest@29.7.0(@types/node@20.5.7): resolution: {integrity: sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + hasBin: true peerDependencies: node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 peerDependenciesMeta: @@ -10886,6 +10897,7 @@ packages: /ts-jest@29.2.5(@babel/core@7.25.2)(esbuild@0.14.49)(jest@29.7.0)(typescript@5.5.4): resolution: {integrity: sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==} engines: {node: ^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0} + hasBin: true peerDependencies: '@babel/core': '>=7.0.0-beta.0 <8' '@jest/transform': ^29.0.0 @@ -10924,6 +10936,7 @@ packages: /ts-jest@29.2.5(@babel/core@7.25.2)(esbuild@0.15.6)(jest@29.7.0)(typescript@5.5.4): resolution: {integrity: sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==} engines: {node: ^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0} + hasBin: true peerDependencies: '@babel/core': '>=7.0.0-beta.0 <8' '@jest/transform': ^29.0.0 @@ -10962,6 +10975,7 @@ packages: /ts-jest@29.2.5(@babel/core@7.25.2)(esbuild@0.17.18)(jest@29.7.0)(typescript@5.5.4): resolution: {integrity: sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==} engines: {node: ^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0} + hasBin: true peerDependencies: '@babel/core': '>=7.0.0-beta.0 <8' '@jest/transform': ^29.0.0 @@ -11013,6 +11027,7 @@ packages: /ts-node@10.9.2(@types/node@18.17.4)(typescript@5.5.4): resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} + hasBin: true peerDependencies: '@swc/core': '>=1.2.50' '@swc/wasm': '>=1.2.50' @@ -11060,6 +11075,7 @@ packages: /tsup@5.12.9(typescript@5.5.4): resolution: {integrity: sha512-dUpuouWZYe40lLufo64qEhDpIDsWhRbr2expv5dHEMjwqeKJS2aXA/FPqs1dxO4T6mBojo7rvo3jP9NNzaKyDg==} + hasBin: true peerDependencies: '@swc/core': ^1 postcss: ^8.4.12 @@ -11095,6 +11111,7 @@ packages: /tsup@6.7.0(ts-node@10.9.2)(typescript@5.5.4): resolution: {integrity: sha512-L3o8hGkaHnu5TdJns+mCqFsDBo83bJ44rlK7e6VdanIvpea4ArPcU3swWGsLVbXak1PqQx/V+SSmFPujBK+zEQ==} engines: {node: '>=14.18'} + hasBin: true peerDependencies: '@swc/core': ^1 postcss: ^8.4.12 @@ -11405,6 +11422,7 @@ packages: /update-browserslist-db@1.0.13(browserslist@4.22.2): resolution: {integrity: sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==} + hasBin: true peerDependencies: browserslist: '>= 4.21.0' dependencies: @@ -11415,6 +11433,7 @@ packages: /update-browserslist-db@1.1.0(browserslist@4.23.3): resolution: {integrity: sha512-EdRAaAyk2cUE1wOf2DkEhzxqOQvFOoRJFNS6NeyJ01Gp2beMRpBAINjM2iDXE3KCuKhwnvHIQCJm6ThL2Z+HzQ==} + hasBin: true peerDependencies: browserslist: '>= 4.21.0' dependencies: diff --git a/turborepo-tests/example-basic-npm/package.json b/turborepo-tests/example-basic-npm/package.json index 51ec598cf89bb..4b1a0832dcf6b 100644 --- a/turborepo-tests/example-basic-npm/package.json +++ b/turborepo-tests/example-basic-npm/package.json @@ -6,6 +6,5 @@ "dependencies": { "turborepo-tests-helpers": "workspace:*", "turborepo-examples": "workspace:*" - }, - "packageManager": "npm" + } } diff --git a/turborepo-tests/helpers/package.json b/turborepo-tests/helpers/package.json index a9925e7ad2b26..8d36bd73f3501 100644 --- a/turborepo-tests/helpers/package.json +++ b/turborepo-tests/helpers/package.json @@ -1,3 +1,9 @@ { - "name": "turborepo-tests-helpers" + "name": "turborepo-tests-helpers", + "scripts": { + "test": "" + }, + "dependencies": { + "@turbo/workspaces": "workspace:*" + } } diff --git a/turborepo-tests/helpers/setup_example_test.sh b/turborepo-tests/helpers/setup_example_test.sh index 66d25057991eb..43221445e325f 100644 --- a/turborepo-tests/helpers/setup_example_test.sh +++ b/turborepo-tests/helpers/setup_example_test.sh @@ -21,13 +21,15 @@ fi echo "node --version: $(node --version)" +echo "$PWD" + # Use the right command for each package manager if [ "$package_manager" == "npm" ]; then - package_manager_command="bash -c 'npx @turbo/workspaces convert . npm || true' && npm install" + package_manager_command="node ../../../packages/turbo-workspaces/dist/cli.js convert . npm --ignore-unchanged-package-manager || true && npm install" elif [ "$package_manager" == "pnpm" ]; then - package_manager_command="bash -c 'npx @turbo/workspaces convert . pnpm || true' && pnpm install" + package_manager_command="node ../../../packages/turbo-workspaces/dist/cli.js convert . pnpm --ignore-unchanged-package-manager || true && pnpm install" elif [ "$package_manager" == "yarn" ]; then - package_manager_command="bash -c 'npx @turbo/workspaces convert . yarn || true' && yarn" + package_manager_command="node ../../../packages/turbo-workspaces/dist/cli.js convert . yarn --ignore-unchanged-package-manager || true && yarn" fi # All examples implement these two tasks @@ -39,7 +41,7 @@ mkdir -p ../../examples-tests-tmp cd ../../examples-tests-tmp # Start up a fresh directory for the test -rm -rf "$example_path" || true +rm -rf "$example_path-$package_manager" || true rsync -avq \ --exclude='node_modules' \ --exclude="dist" \ @@ -47,10 +49,10 @@ rsync -avq \ --exclude=".expo" \ --exclude=".cache" \ --exclude=".next" \ - "../examples/$example_path" "." + "../examples/$example_path" "$example_path-$package_manager" -cd "$example_path" -"../../turborepo-tests/helpers/setup_git.sh" . +cd "$example_path-$package_manager/$example_path" +"../../../turborepo-tests/helpers/setup_git.sh" . # Make /tmp dir for writing dump logs mkdir -p ./tmp diff --git a/turborepo-tests/helpers/turbo.json b/turborepo-tests/helpers/turbo.json index 8d0c92396cf83..ffadf844931f1 100644 --- a/turborepo-tests/helpers/turbo.json +++ b/turborepo-tests/helpers/turbo.json @@ -3,6 +3,9 @@ "tasks": { // This needs to exist because upstream packages depend on it and // it's not defined at the root level. - "topo": {} + "topo": {}, + "test": { + "dependsOn": ["^build"] + } } }