parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.37k stars 2.26k forks source link

Parcel 2: `@parcel/register` node require hook #2396

Open devongovett opened 5 years ago

devongovett commented 5 years ago

The idea here is to enable Parcel transformers and resolvers to be run in other places than just bundling via a package similar to babel-register or other require hooks in node. This way, you could run the same Parcel transformers that you run when bundling your app in your tests, which might run in node.

Currently it is very challenging to set up a real world app, even with Parcel, because you are still stuck configuring other tools like mocha, jest, babel, and others for your tests, not even your real app. If you could get the same zero configuration experience just by loading @parcel/require in node, that would be pretty great.

There are a bunch of Parcel features that would be great to be able to use in tests:

  1. The source and alias fields in package.json. No manually configuring babel-register to include certain node_modules. Using the Parcel resolver, this would be possible.
  2. Real Parcel transformers, no extra configuration. Normal babel-register might not be enough if you are using other compilers. We could even automatically handle things like CSS imports that won't work in node.
  3. Take advantage of Parcel's cache for faster test runs - no need to recompile every time.

@parcel/register would only run the Parcel transformer pipeline, not any packagers or actual bundling. It would operate on a per-file level, and hook into the node module system to compile and resolve modules.

pspeter3 commented 2 years ago

Is this available? For example, if you're using Jest, is it possible to use Parcel to transform the TypeScript?

pete55104 commented 2 years ago

This seems important, and I'm interested as well. In the process of converting a CRA react and node backend, and got as far as trying to run my Jest tests through parcel and ended up here. I'm interested in working on this feature, although I'd need some guidance. Let me see if I can get the existing @swc/Jest + babel tooling to work as a model.

How do I tell which version of swc a given parcel version is using? I'm on 2.2.1.

devongovett commented 2 years ago

I had started on it here. Haven't had time to work on it recently. Feel free to take a look if you want! https://github.com/parcel-bundler/parcel/compare/parcel-node

jteppinette commented 1 year ago

Without this, should there be a disclaimer that parcel doesn't support unit testing? One of the key features of parcel is the transformer pipeline, which is unsupported.

andymac4182 commented 7 months ago

@devongovett Any movement on this from you? Thoughts on starting with getting the new transform and resolve functions you have added to Parcel?

I can see the @parcel/register package that is available now. Curious if I am missing a jest one?