Skip to content

[Feature] Support transformers written as ES modules #58

@aomarks

Description

@aomarks

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!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions