-
-
Notifications
You must be signed in to change notification settings - Fork 32
Description
It is not currently possible to import a transformer that is written a standard ES module. Only transformers written as CommonJS modules work currently.
Node has supported standard ES modules since v12, so that's all currently supported versions of Node: https://nodejs.org/en/about/releases/. Node packages are increasingly being published as ES modules instead of CommonJS, so it would be great to be able to use them here too! One huge advantage of ES modules is that they can run directly both in Node and browsers.
https://nodejs.org/api/esm.html#esm_introduction
Note this doesn't require writing ts-patch itself in ES modules, since there is bi-directional interoperability in Node. To import an ES module from a CommonJS module, use const mod = await import("./some-module.js") instead of require. To check if a module should be imported as an ES module, look in its package.json for the {"type": "module"} field.
I see a new version is being written at #40 -- I think this would be an awesome thing to include in the rewrite.
Thanks!