Skip to content

Commit

Permalink
feat(cli/migrate): show npm commands for manual steps in `replace-r…
Browse files Browse the repository at this point in the history
…emix-imports` migration
  • Loading branch information
pcattori committed Apr 6, 2022
1 parent bb12b9c commit 6c05072
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isAdapter, isRuntime } from "./transform";
import type { MigrationFunction } from "../../types";
import { readConfig } from "../../../../config";
import { hint } from "../../../../logging";
import * as colors from "../../../../colors";

const transformPath = join(__dirname, "transform");

Expand All @@ -25,41 +26,55 @@ function* getTasks({
runtime: string;
adapter?: string;
}): Generator<string> {
let commandTask = (message: string, command: string) =>
`${message}:\n\t${colors.hint(command)}`;
let remixRunPrefix = (dep: string) => "@remix-run/" + dep;
let remixDeps = findRemixDependencies(packageJson.dependencies);

// runtime not in deps
if (!remixDeps.includes(runtime)) {
yield `Install \`@remix-run/${runtime}\` as a dependency`;
yield commandTask(
`Install \`@remix-run/${runtime}\` as a dependency`,
`npm install @remix-run/${runtime}`
);
}

// other runtimes in deps
let otherRuntimes = remixDeps
.filter(isRuntime)
.filter((dep) => dep !== runtime);
if (otherRuntimes.length > 0) {
yield `Uninstall all unused runtimes: (${otherRuntimes
.map((r) => "@remix-run/" + r)
.join(",")})`;
yield commandTask(
"Uninstall all unused runtimes",
`npm uninstall ${otherRuntimes.map(remixRunPrefix).join(" ")}`
);
}

// adapter not in deps
if (adapter && !remixDeps.includes(adapter)) {
yield `Install \`@remix-run/${adapter}\` as a dependency`;
yield commandTask(
`Install \`@remix-run/${adapter}\` as a dependency`,
`npm install @remix-run/${adapter}`
);
}

// other adapters in deps
let otherAdapters = remixDeps
.filter(isAdapter)
.filter((dep) => dep !== adapter);
if (otherAdapters.length > 0) {
yield `Uninstall all unused adapters: (${otherRuntimes
.map((r) => "@remix-run/" + r)
.join(",")})`;
yield commandTask(
"Uninstall all unused adapters",
`npm uninstall ${otherAdapters.map(remixRunPrefix).join(" ")}`
);
}

// remix in deps
if (Object.keys(packageJson.dependencies || {}).includes("remix")) {
yield "Uninstall `remix` as a dependency";
yield commandTask(
"Uninstall `remix` as a dependency",
"npm uninstall remix"
);
}

// `remix setup` in `postinstall`
Expand Down

0 comments on commit 6c05072

Please sign in to comment.