tsdx icon indicating copy to clipboard operation
tsdx copied to clipboard

yarn 2 compatibility

Open cspotcode opened this issue 5 years ago • 12 comments

I'm starting to work on yarn 2 compatibility. I'll see how far I can get.

Try it out today

Yarn 2 users, you can try this branch today and let me know what does / does not work.

# Install this version of tsdx
yarn add tsdx@github:cspotcode/tsdx.git#yarn2
# Now you can use tsdx
yarn tsdx test

I am also working at this other PR so that I can push frequently for CI to run without spamming this thread: https://github.com/cspotcode/tsdx/pull/4

Changes I've had to make:

  • yarn2 is built with this bugfix: https://github.com/yarnpkg/berry/pull/2215
  • Dependencies
    • Upgraded jest dependencies to 25.4, because jest-resolve 25.3 does not declare one of its own dependencies; causes an error
    • Added type-fest because it is referenced by src/templates/react.ts
    • Added @jest/types because it is referenced by src/createJestConfig.ts
    • Upgraded ts-jest to avoid error: Could not find source file:

Related issues that may / may not need fixes

  • [ ] https://github.com/formium/tsdx/issues/688
  • [ ] https://github.com/formium/tsdx/issues/458
    • [ ] tsdx test and tsdx build need to find typescript package even when it is not globally installed
    • [x] special rollup plugin is not needed. We depend on @rollup/[email protected], which depends on [email protected], which natively supports PnP
  • [ ] https://github.com/formium/tsdx/issues/688#issuecomment-681054218
    • babel-jest hoisting issue
    • sanity-check that npx tsdx create mylib works
  • [ ] https://github.com/formium/tsdx/issues/688#issuecomment-616978687
    • mentions that rollup-plugin-pnp-resolve was necessary; must test that it is not necessary and upgrade @rollup/plugin-node-resolve if necessary
    • https://github.com/upsetjs/upsetjs/blob/master/packages/model/tsdx.config.js

Simplifications since the last review

This is a list of undesirable changes from my initial submission that I have reverted

  • no more environment variable; we simply run yarn and use process.versions.pnp to detect yarn2
  • jest runs under pnp, no more spawning external yarn processes
  • no more need to add deps to test package.json's; we copy all deps from the root package.json automatically
  • no more hacky testing builds in an external process; we are back to simply require()ing them in-process
  • fixed a bug in yarn2's typescript patch, meaning less changes to package.json dependencies
  • stage-* directories are no longer being moved elsewhere

Related links: (note to self explain why they're relevant) https://github.com/facebook/jest/pull/10847 https://github.com/facebook/create-react-app/pull/5270

cspotcode avatar Nov 10 '20 20:11 cspotcode

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/formium/tsdx/a53gz5xvv
✅ Preview: https://tsdx-git-yarn2.formium.vercel.app

vercel[bot] avatar Nov 10 '20 20:11 vercel[bot]

This PR is marked draft because it is still a work in progress, so it's expected to be broken. I created it so I could ping @merceyz who wanted to follow along.

cspotcode avatar Nov 10 '20 21:11 cspotcode

I got all the tests passing in yarn2. PR is still marked "draft" because the yarn folks have sent a bugfix to jest that may allow me to simplify and speed up the changes I had to make here.

cspotcode avatar Nov 19 '20 00:11 cspotcode

rollup-plugin-pnp-resolve wasn't added but is mentioned in #688 (comment) and #458 (comment)

resolve, which is used by @rollup/plugin-node-resolve, has PnP support so that rollup plugin isn't needed anymore.

merceyz avatar Nov 24 '20 23:11 merceyz

@agilgur5 thanks for taking a look, I'm working through the review feedback. I've left comments on a few things, am pushing fixes for some, and for other things like jest presets, I'll need to do some research.

It has been helpful to let Github Actions run the tests while I work, which is why I've been pushing code here as I go. Understanding that you've muted this thread, is it ok if I keep pushing code as I go? I can ping you only once I've addressed all review feedback.

cspotcode avatar Nov 25 '20 00:11 cspotcode

I got rid of the npm misnomer and trimmed down the test matrix.

I've reverted the package.json changes. I did some testing and they were only necessary when running jest under PnP. In another branch I'm going to re-implement the changes to run jest under PnP, which should simplify the tests, eliminate some of the messier changes to test infra, and enable unit-testing. I'll see if/how many dependency changes are necessary.

cspotcode avatar Nov 25 '20 15:11 cspotcode

Great to see so much progress on this, if there is a list of follow up tasks that would be great to get some others to input on those.

I mentioned before I would like to sponsor such efforts and I'd like to honour that, please sign up for issuehunt!

timini avatar Nov 26 '20 10:11 timini

@timini how does issuehunt work? Do I need to sign up, or does the tsdx team need to sign up?

As far as getting other people involved with the remaining work, I added a checklist of tasks to the issue description, but at the moment it's a bit messy. I am also iterating in another branch and merging to this PR when major improvements are ready. Trying to cut down on spam over here. https://github.com/cspotcode/tsdx/pull/4

Perhaps more useful than the checklist, I added instructions for installing and testing this version of tsdx today. Yarn 2 users, please feel free to give it a shot on your projects and let me know what's still broken.

cspotcode avatar Dec 07 '20 03:12 cspotcode

Tested creating a yarn 2 monorepo using workspaces. So far i have no issues, i had to setup a tsconfig.json at the workspace root which is extended by the workspace packages

https://github.com/timini/tsdx-yarn-2-monorepo

timini avatar May 12 '21 11:05 timini

I have done very minimal project setup so far, but it looked promising, its based off https://github.com/cspotcode/tsdx#yarn2

I haven't tried with main line tsdx.

Are there any tests i should make? Is it possible to add tests for this kind of monorepo setup?

timini avatar May 12 '21 11:05 timini

OK i tested the same setup using main branch tsdx and encountered issues with yarn install. It seems those issues are resolved by https://github.com/cspotcode/tsdx#yarn2

timini avatar May 13 '21 11:05 timini

@timini the "changed I've had to make" section of the OP lists fixes I made for compatibility. The yarn2 bugfix has since been merged and released, so shouldn't be necessary any more. Are you using the latest stable yarn 2?

cspotcode avatar May 13 '21 13:05 cspotcode