-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
☂️TypeScript migration tracking issue #7807
Comments
I would love to contribute on this! Can i take |
Yeah, go for it! |
Hey @SimenB! |
That's awesome @r3nya! I'd say the easiest are Others that should be pretty straightforward are |
Thank you! I could take |
🎉 I've updated the OP |
@SimenB let me do a |
@r3nya go for it! :) |
So, |
|
Got it, thanks! I've created the PR :) |
I'll take |
@MohamadKh75 thanks! However, that depends on |
Happy to migrate |
Woo, do it 😀 |
Sure! then i start |
awesome! |
I'll try my luck with haste map 😄 |
I'd be happy to do |
Awesome, thanks! OP updated 🙂 |
Hi, can I do the first try for |
For sure! |
Woah, we're almost done! Awesome 😀 If you want, you can start converting the e2e tests? Just the ones in this directory, not the tests themselves: https://github.com/facebook/jest/tree/master/e2e/__tests__ I'll ping the ones that have claimed packages but not opened up a PR yet, might be more available. @mattphillips @lirbank @MohamadKh75 hey, one more ping. If you don't have time to migrate that's totally fine, but if so it'd be nice if someone else could pick up the package you've claimed 🙂 |
The link you provided returns a 404. But you're referring to the contents of the If that's the case I'll gladly take it up 👍 |
Yes! Not sure why GH messes up the link, what I pasted is |
Am I going to need to have a tsconfig.json in the |
I don't know. I don't think so (we won't be generating typings files here)? Try without 🙂 |
Sure thing. 💯 |
@SimenB There is also |
It has dependencies that have not been migrated. But I guess we can just do |
@SimenB Sorry for the lag, got sidetracked and was out all week. I'll get it done today! |
Awesome. I've added a |
I'm so sorry... i just had some unexpected problems... maybe i can help in other sections... 😞 |
No problem @MohamadKh75, thanks for reaching out! 🙂 You can do |
Hey can I take up |
Sure, go for it 🙂 |
Hey @loryman, I picked up |
Sure, go ahead! |
Holy shit, we're done! 🎉 Thank you so much to everyone who helped out. I did not think we'd be able to do this in just 4 weeks. Jest is now officially a TS repo. $ cloc packages --vcs git --exclude-dir __tests__,__mocks__
462 text files.
408 unique files.
76 files ignored.
github.com/AlDanial/cloc v 1.80 T=0.45 s (896.0 files/s, 98149.4 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
TypeScript 286 4581 4052 29135
JSON 82 0 0 2106
Markdown 19 571 0 1697
JavaScript 16 217 213 1497
PHP 1 22 14 150
-------------------------------------------------------------------------------
SUM: 404 5391 4279 34585
------------------------------------------------------------------------------- Next steps are as follows:
I'll be opening issues for these soon(ish). Thank you again to everybody who chipped in! |
Alpha released! Please do |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This issue is meant to track Jest's internal migration to TypeScript.
Process
We would love to get help from the community here. I've compiled a list of all the packages in this repo below - feel free to claim any package not claimed and submit a PR migrating it.
List
@jest/core
@jest/reporters
@jest/transform
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
diff-sequences
eslint-config-fb-strict
expect
jest
jest-changed-files
jest-circus
jest-cli
jest-config
jest-diff
jest-docblock
jest-each
jest-environment-jsdom
jest-environment-node
jest-get-type
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
jest-phabricator
jest-regex-util
jest-repl
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
jest-serializer
jest-snapshot
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
After all packages are migrated, we can start to migrate our integration tests. Depending on how this migration goes, we can track that in this issue as well, or we can track it separately later.
How
Order of packages to migrate
One thing to note is that because this repo is a monorepo, we have dependencies between packages. So we have to migrate leaf packages (without dependencies) first, then walk up the dependency tree until everything is migrated. Which means
jest-cli
will be the last package migrated.You can use yarn to figure out which packages depend on which internally:
yarn --silent workspaces info
. This will output a JSON object of all packages in the workspace. An example looks like this:The interesting part here is
workspaceDependencies
. If that array is empty, that's a perfect package to start migrating. If it is not empty, you'll want to make sure that every package listed in the array has been migrated already.Steps
tsconfig.json
from an already migrated packagereferences
types/
in the root of the repo for the package, move that into the package'ssrc
directory as a file namedtypes.ts
"types": "build/index.d.ts"
to package.json belowmain
js
extension tots
(ortsx
if they have jsx in them), fixing type errors as you goTo build, you can run
yarn build
oryarn watch
in the root of the repository.You can look at my PR for
pretty-format
for a look at how a migration might look.You can use
flow-to-typescript
to help in migration. However, since the syntax between Flow and Typescript is so similar, I personally only used it for the type definition files intypes
- for normal source files it was easier to rename the file tots(x)
and fix the syntax errors that my IDE showed me.*) Do this by comparing
git diff
s before and after migration (also please include this diff in the PR after opening it)yarn build
onmaster
git add -f packages/MY_PACKAGE/build*
git commit -m 'before migration'
yarn build
on your branch with the migrationrm packages/MY_PACKAGE/build*/**/*.ts packages/MY_PACKAGE/build*/**/*.map
git add -f packages/MY_PACKAGE/build*
git commit -m 'after migration'
git diff master packages/MY_PACKAGE/build*
git --no-pager diff master packages/MY_PACKAGE/build* | pbcopy
. Stick that in a code fence withdiff
syntax in the PR.Things to look out for during migration
The config doesn't allow implicit
any
Out current setup with flow allows this - just add an explicit
any
(or a stricter type if you're able) in those cases. If possible, please useunknown
instead ofany
.The module exports CommonJS
Convert
require
toimport
Useexports =
to replacemodules.exports
- this allows TypeScript to understand the export. We include a babel-plugin which transpiles this intomodule.exports
for the distributed code (and tests).Potential gotchas
Probably more, but I'll write down the ones I know of
types/
in the root of this repo, allowing us to use types across packages without dependencies on them (typically modules will depend ontypes/Config
which allow them to haveProjectConfig
as arguments). Since we'll be distributing the types, we need those dependencies to be explicit.jest-config
has today except for the default configs (so it can dropbabel-jest
, the test environments etc)types/TestResult
is used byjest-jasmine2
,jest-circus
andjest-cli
(for reporters). We need to figure out how to share that type effectively between packages.Another idea on how to solve "type sharing" is to use a separate
jest-types
project that's just types that are shared between modules.Ideas here are very much welcome!
EDIT: As of #7834, I've created a
@jest/types
packagePS: This will not affect anyone using Jest (unless you use the modules exported by Jest directly, which will become typed). This is strictly an internal refactor. We will not be considering adding types to be a breaking change.
PPS: It is currently a non-goal to distribute TS types for using Jest - that is excellently handled in
@types/jest
already. At some point we might want to distribute that with jest as well - but that's a separate issue.PPPS: This issue is not for discussions about the merits of the migration in and of itself - that feedback can be posted in the RFC. However, if you have experience migrating, building, testing or distributing a module written in TS, feel free to chime in with learnings from that process in this issue.
The text was updated successfully, but these errors were encountered: