Skip to content

Commit

Permalink
refactor(dev): rewrite replace-remix-magic-exports as a babel codemod
Browse files Browse the repository at this point in the history
Compared to the previous jscodeshift-based migration:
- codemod no longer depends on a network connection
- babel's visitor API for traversing the AST is simpler
- not spinning up workers for applying code transforms

This ends up speeding up the codemod by ~10x and (hopefully 🤞) fixes
some of the issues we were seeing in CI on Windows (since we think
problems are mostly timeouts caused by slow tests or overhead for
workers).
  • Loading branch information
pcattori committed Nov 15, 2022
1 parent 474e80f commit c4cef84
Show file tree
Hide file tree
Showing 42 changed files with 1,518 additions and 1,785 deletions.
9 changes: 3 additions & 6 deletions packages/remix-dev/__tests__/cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("remix CLI", () => {
$ remix routes [projectDir]
$ remix watch [projectDir]
$ remix setup [remixPlatform]
$ remix migrate [-m migration] [projectDir]
$ remix codemod <codemod> [projectDir]
Options:
--help, -h Print this help message and exit
Expand All @@ -119,17 +119,14 @@ describe("remix CLI", () => {
--no-delete Skip deleting the \`remix.init\` script
\`routes\` Options:
--json Print the routes as JSON
\`migrate\` Options:
--debug Show debugging logs
\`codemod\` Options:
--dry Dry run (no changes are made to files)
--force Bypass Git safety checks and forcibly run migration
--migration, -m Name of the migration to run
--force Bypass Git safety checks
Values:
- projectDir The Remix project directory
- template The project template to use
- remixPlatform \`node\` or \`cloudflare\`
- migration One of the choices from https://github.com/remix-run/remix/blob/main/packages/remix-dev/cli/migrate/migrations/index.ts
Creating a new project:
Expand Down
47 changes: 0 additions & 47 deletions packages/remix-dev/cli/checkGitStatus.ts

This file was deleted.

40 changes: 38 additions & 2 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import { log } from "../logging";
import { createApp } from "./create";
import { getPreferredPackageManager } from "./getPreferredPackageManager";
import { setupRemix, isSetupPlatform, SetupPlatform } from "./setup";

export * as migrate from "./migrate";
import runCodemod from "../codemod";
import { CodemodError } from "../codemod/utils/error";
import { TaskError } from "../codemod/utils/task";

export async function create({
appTemplate,
Expand Down Expand Up @@ -340,6 +341,41 @@ export async function dev(
}
}

export async function codemod(
codemodName?: string,
projectDir?: string,
{ dry = false, force = false } = {}
) {
if (!codemodName) {
console.error(colors.red("Error: Missing codemod name"));
console.log(
"Usage: " +
colors.gray(
`remix codemod <${colors.arg("codemod")}> [${colors.arg(
"projectDir"
)}]`
)
);
process.exit(1);
}
try {
await runCodemod(projectDir ?? process.cwd(), codemodName, {
dry,
force,
});
} catch (error) {
if (error instanceof CodemodError) {
console.error(`${colors.red("Error:")} ${error.message}`);
if (error.additionalInfo) console.info(colors.gray(error.additionalInfo));
process.exit(1);
}
if (error instanceof TaskError) {
process.exit(1);
}
throw error;
}
}

function purgeAppRequireCache(buildPath: string) {
for (let key in require.cache) {
if (key.startsWith(buildPath)) {
Expand Down
2 changes: 0 additions & 2 deletions packages/remix-dev/cli/migrate/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/remix-dev/cli/migrate/migrations/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c4cef84

Please sign in to comment.