ts-import icon indicating copy to clipboard operation
ts-import copied to clipboard

Allow configuring transformation of output file paths

Open nicky1038 opened this issue 1 year ago • 0 comments

One can run node with custom ESM loaders. Though this API is experimental in Node.js, it was added way back in node 8 and can be very handy in some specific cases.

When a custom ESM loader is used, on dynamic import() call, this library will invoke custom ESM loader's logic of module location resolving, passing path of the resolved JS file into the ESM loader as an import() argument. The problem is that custom ESM loader may accept file path strings in shapes different from just "absolute path to file".

My case is: I would like to make Yarn PnP, ESM modules and Typescript work together. So, I would like to use this library with Yarn's .pnp.loader.esm ESM loader. This loader, unfortunately, accepts only URLs beginning from 'file://' and throw errors on regular absolute paths. That is, I cannot use this loader now, because absolute paths are exactly what this library passes into dynamic import().

So my suggestion is to allow users to configure a callback that will be used to transform output js paths into shape that users need, before passing the resulting paths to import() call.

What do you think? Could I make a PR?

nicky1038 avatar May 05 '23 03:05 nicky1038