jprichardson / node-fs-extra

Node.js: extra methods for the fs object like copy(), remove(), mkdirs()
MIT License
9.44k stars 776 forks source link

fix: add package main field for TypeScript support #981

Closed mtdvlpr closed 1 year ago

mtdvlpr commented 1 year ago

Fixes #979

caugner commented 1 year ago

It doesn't resolve the issue with import ... from "fs-extra/esm" though. 🤔

mtdvlpr commented 1 year ago

It doesn't have to, right? Importing from fs-extra will get the esm version if I'm not mistaken.

caugner commented 1 year ago

It doesn't have to, right? Importing from fs-extra will get the esm version if I'm not mistaken.

If I understand @RyanZim's intention correctly, the separate fs-extra/esm export aims to avoid confusion. Adding the "module" field reintroduces that confusion, because you could then import from fs-extra and get the ESM module.

We could just add the main field for now, and that alone would resolve TypeScript issue.

RyanZim commented 1 year ago

I removed the main field, since it wasn't needed for backward compatibility with old Node versions, as we don't support Node versions old enough not to support exports. However, since it seems TS doesn't like this (potentially a bug? see https://github.com/jprichardson/node-fs-extra/issues/979#issuecomment-1331404978), it seems wise to add it back for now.

It doesn't resolve the issue with import ... from "fs-extra/esm" though.

I think that's fine; main is only needed for TS support, and if you're using TS, you already have named import support; there's no reason to use fs-extra/esm in TS.

@caugner is correct; we don't want to add module here, as that would be confusing.

RyanZim commented 1 year ago

Published in v11.1.0 :tada: