Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew committed Dec 12, 2024
1 parent 29c4b91 commit 243b72b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 24 deletions.
5 changes: 5 additions & 0 deletions packages/turbo-workspaces/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 14 additions & 12 deletions packages/turbo-workspaces/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/turbo-workspaces/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface Options {
dry?: boolean;
skipInstall?: boolean;
interactive?: boolean;
ignoreUnchangedPackageManager?: boolean;
}

export interface PackageManagerInstallDetails {
Expand Down
21 changes: 20 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions turborepo-tests/example-basic-npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"dependencies": {
"turborepo-tests-helpers": "workspace:*",
"turborepo-examples": "workspace:*"
},
"packageManager": "npm"
}
}
8 changes: 7 additions & 1 deletion turborepo-tests/helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"name": "turborepo-tests-helpers"
"name": "turborepo-tests-helpers",
"scripts": {
"test": ""
},
"dependencies": {
"@turbo/workspaces": "workspace:*"
}
}
16 changes: 9 additions & 7 deletions turborepo-tests/helpers/setup_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,18 +41,18 @@ 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" \
--exclude=".turbo" \
--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
Expand Down
5 changes: 4 additions & 1 deletion turborepo-tests/helpers/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
}

0 comments on commit 243b72b

Please sign in to comment.