fromdeno / deno2node

Compile your Deno project to run on Node.js.
MIT License
115 stars 3 forks source link

Feature request: choice of output extension #15

Closed Conaclos closed 2 years ago

Conaclos commented 2 years ago

Hi! Thanks for your work.

I would like to propose a CLI option to choose the output extension of files and imports. In some cases, it could be useful to output cjs extension or mjs extension. This is useful to publish node package that support both esm and commonjs.

wojpawlik commented 2 years ago

Glad you like my project :)

I doubt changing output extension is useful tho. { "type": "module" } package.json marks all .js files in the directory as ESM. If you write Node-only, Node.js ^12.20.0 || >=14.13.1 allows to use named imports on CJS. And if you need ESM for browsers, https://www.npmjs.com/package/sucrase can transpile to CJS (from ESM) way faster than deno2node.

Still, I wouldn't mind a PR extending https://github.com/wojpawlik/deno2node/blob/main/src/emit.ts to vary output extension based on "target".