-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(remix-dev): rewrite jscodeshift
-based migrations as babel
-based codemods
#4572
Conversation
🦋 Changeset detectedLatest commit: fd5742f The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e1d3a9b
to
c994670
Compare
0fd531f
to
f4c3bb0
Compare
conversion to javascript is not a "migration" in that it does not help the user to upgrade to a newer version of Remix
f4c3bb0
to
9e85517
Compare
c9d75bc
to
87c9473
Compare
87c9473
to
499ee93
Compare
jscodeshift
-based migrations as babel
-based codemods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WOW massive speed improvement! 😱
Also nice to now have a streamlined way of testing the CLI 😍
packages/remix-dev/__tests__/fixtures/replace-remix-magic-imports/package.json
Show resolved
Hide resolved
@@ -19,6 +19,8 @@ | |||
"skipLibCheck": true, | |||
|
|||
// Remix takes care of building everything in `remix build`. | |||
"noEmit": true | |||
"noEmit": true, | |||
"allowJs": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a good idea to keep this file in line with our templates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remix automatically adds these lines to the tsconfig if they are missing, which adds noise to the console for tests. So just decied to include it here since we enforce it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I know Remix automatically adds these.
That's why our templates have these values in tsconfig.json
by default.
What I was suggesting was: copy over the tsconfig.json
from one of our templates, so it's easier to auto-update (find/replace) if ever needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see! I do like the isolation of fixtures being self-contained, but also like your suggestion as well. Let me think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean to copy over the file automatically, just copying over the content manually
So if we ever have to add extra defaults, we can just do all files automatically & we don't have to think about this file being different
let gitStatus = await execa("git", ["status", "--porcelain"], { | ||
cwd: dir, | ||
encoding: "utf8", | ||
maxBuffer: TEN_MEBIBYTE, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was wondering if there's a special reason you switched from child_process
to execa
It would be one less dependency to use.
let gitStatus = await execa("git", ["status", "--porcelain"], { | |
cwd: dir, | |
encoding: "utf8", | |
maxBuffer: TEN_MEBIBYTE, | |
}); | |
let gitStatus = execFileSync("git", ["status", "--porcelain"], { | |
cwd: dir, | |
encoding: "utf8", | |
maxBuffer: TEN_MEBIBYTE, | |
})?.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I do think that execa
has a nicer API (autotrims output, provides more information about errors) but the main reason was due to it purported improvements for Windows support.
We were considering bundling all the CLI dependencies anyway so that running npx @remix-run/dev
or npx create-remix
wouldn't have to subsequently install a bunch of things. So I'll discuss this with the team to see if we think the benefits of execa
are worth the added dependency.
packages/remix-dev/codemod/replace-remix-magic-imports/transform.ts
Outdated
Show resolved
Hide resolved
packages/remix-dev/codemod/replace-remix-magic-imports/transform.ts
Outdated
Show resolved
Hide resolved
packages/remix-dev/codemod/replace-remix-magic-imports/transform.ts
Outdated
Show resolved
Hide resolved
packages/remix-dev/codemod/replace-remix-magic-imports/transform.ts
Outdated
Show resolved
Hide resolved
a6aeafb
to
2001d94
Compare
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).
…ce-remix-magic-imports`
some tests can make use of the built javascript artifacts (e.g. `cli.js`) to run 8-10x faster than running with source Typescript (e.g. `cli.ts`)
Windows sometimes throws `EBUSY: resource busy or locked, rmdir` errors when attempting to removing the temporary directory. Retrying a couple times seems to get it to succeed. See https://github.com/jprichardson/node-fs-extra/issues?q=EBUSY%3A+resource+busy+or+locked%2C+rmdir
2001d94
to
e58d1d3
Compare
🤖 Hello there, We just published version Thanks! |
…`-based codemods (#4572) * refactor(dev): extract `useColor` usages into `safe` utility * refactor(dev): remove outdated reference to compiler shims * fix(dev): remove access to `convert-to-javascript` migration via CLI conversion to javascript is not a "migration" in that it does not help the user to upgrade to a newer version of Remix * refactor(dev): rewrite `replace-remix-magic-exports` as a babel codemod 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). * test(dev): restore fixture this fixture was incorrectly included as part of dependency upgrades: - #3917 - #3929 it should not have been updated since it is supposed to represent a Remix 1.3.x codebase * test(dev): add tests for generic codemods and specifically for `replace-remix-magic-imports` * ci: run build before primary tests some tests can make use of the built javascript artifacts (e.g. `cli.js`) to run 8-10x faster than running with source Typescript (e.g. `cli.ts`) * test(dev): retry temp dir removal for windows ci Windows sometimes throws `EBUSY: resource busy or locked, rmdir` errors when attempting to removing the temporary directory. Retrying a couple times seems to get it to succeed. See https://github.com/jprichardson/node-fs-extra/issues?q=EBUSY%3A+resource+busy+or+locked%2C+rmdir * Create long-colts-remain.md
Summary
convert-to-javascript
migration from the CLI since it was never intended to be user-facing and was undocumentedconvert-to-javascript
code for use increate
command when users opt out of TSjscodeshift
as a dependency in@remix-run/dev
replace-remix-imports
migrationcodemod toreplace-remix-magic-imports
for clarityreplace-remix-magic-imports
codemodjscodeshift
APIjscodeshift
transform if needed in the futurejscodeshift
spun up workers to process file transformations, which had significant overhead and is why some Windows CI tests were flakeystdout
andstderr
for less noise when running testscli.js
when it is up-to-date with respect to the sourcecli.ts
for 2-5x faster testsreplace-remix-magic-imports
fixture to represent a Remix 1.3.x projectreplace-remix-magic-imports
codemod TUI is simplified to useora
spinners/✔️/𐄂 and runs completely without need for interactive user inputResults
The net effect is that codemod tests run 10-100x faster.
For example the
replace-remix-magic-imports
codemod test used to take ~30-35s.Now, the same test takes 0.8s when using build is up-to-date, and 2.5s when build is out-of-date.
This codemod does not use a network connection and does not spin up workers, increasing speed and reliability, especially for Windows CI tests.
BEFORE
AFTER
Testing strategy
Added tests for transform and codemod:
codemod-test.ts
: check that project is a cleangit
repo and the specified codemod existscodemod-replaceRemixMagicImports-test.ts
: check thatremix
package is removed, dependencies are updated, andremix setup
is removed frompostinstall
scripttransform-replaceRemixMagicImports-test.ts
: check that import declarations are overwritten correctlyTODO
git
in CICliError
with error message and additional info messages