plugins icon indicating copy to clipboard operation
plugins copied to clipboard

fix(*): provide typings for both cjs and es builds

Open Septh opened this issue 1 year ago • 13 comments

Rollup Plugin Name: all (except Beep)

This PR contains:

  • [x] bugfix
  • [ ] feature
  • [ ] refactor
  • [ ] documentation
  • [ ] other

Are tests included?

  • [x] yes (bugfixes and features will not be merged without tests)
  • [ ] no

Breaking Changes?

  • [ ] yes (breaking changes will not be merged unless absolutely necessary)
  • [x] no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers: resolves #1541, #1578 supersedes #1744

Description

As soon as you start using "moduleResolution": "Node16" (or "NodeNext") in tsconfig.json, TypeScript complains that the default export for the plugins in this repo "is not callable" because it "has no call signatures".

This PR fixes this by providing each package with distinct typings for the ESM build and the CJS build. It is a follow-up of the work @danielbayley started on #1744.

@shellscape > this passes all the current tests. However, given your past comment here, I think you'd prefer some specific tests to be added... Could you please just put me on the right track for this?

Septh avatar Oct 03 '24 11:10 Septh

Great addition. Thank you for taking this on (and sorry for the delay in getting eyes on this. I'm in Florida and was hit by two hurricanes in the last few weeks)

You're correct. We could merge this as-is, but we'd have no protection against regressions that others might introduce. Ideally, we'd have a .ts file for each plugin that would use the types that were generated, and checked by tsc for extra assurance. Alternatively, we could snapshot the types file content in tests as a looser form of assurance. Both are lifts, so I understand if it's something you're hesitant to do. Please let us know what you think.

shellscape avatar Oct 16 '24 02:10 shellscape

I went with the first option. 😄

Septh avatar Oct 16 '24 12:10 Septh

Impressive turn-around on that. A few things:

  • what's the significance of the Node16 vs Node10 directories - just support for type: module in package.json?
  • the current_package setup seems to be causing some problems on CI. I'd probably suggest just using from '../' and it should pick up the right files

shellscape avatar Oct 16 '24 13:10 shellscape

  • what's the significance of the Node16 vs Node10 directories - just support for type: module in package.json?

The names refer to the moduleResolution strategy set in tsconfig.json.

I'm testing the 4 possible cases :

  • Node16 within a type: "module" directory
  • Node16 within a type: "commonjs" directory
  • Node10 (aka Node) with module: "CommonJS" in tsconfig
  • and Node10 with module: "ESNext"
  • the current_package setup seems to be causing some problems on CI. I'd probably suggest just using from '../' and it should pick up the right files

That was my first shot, but it wasn't appropriate. I did some builds with --traceResolution and it appears that TypeScript resolves '../' as a straight relative identifier rather going through the whole Node resolution algorithm. This made the tests mostly irrelevant.

I borrowed the idea of linking the package to itself to node-resolve, so if it's not working in CI maybe I did something wrong? I made symbolic links, was this the right choice?

Septh avatar Oct 16 '24 15:10 Septh

I read on SO that symlinks have to be relative to the root of the repo (makes sense). Let's try again.

Septh avatar Oct 16 '24 16:10 Septh

I read on SO that symlinks have to be relative to the root of the repo (makes sens). Let's try again.

@Septh FYI, there's a useful little utility for that: https://github.com/brandt/symlinks.

danielbayley avatar Oct 16 '24 17:10 danielbayley

@shellscape > any chance you could review my latest push, please?

Septh avatar Nov 08 '24 10:11 Septh

@Septh taking a look now

shellscape avatar Dec 15 '24 16:12 shellscape

Looks like CI is failing on Windows. Not entirely sure why, but unfortunately I don't have the time to triage this for you, and we can't merge until that's passing.

shellscape avatar Dec 15 '24 16:12 shellscape

Looks like CI is failing on Windows. Not entirely sure why, but unfortunately I don't have the time to triage this for you, and we can't merge until that's passing.

Well, I'm not sure either what's going wrong. Maybe someone reading this can provide some help? 🙏

Septh avatar Dec 15 '24 17:12 Septh

that's probably unlikely, unfortunately. we have a severe lack of active maintainers.

shellscape avatar Dec 15 '24 17:12 shellscape

Looks like CI is failing on Windows. Not entirely sure why, but unfortunately I don't have the time to triage this for you, and we can't merge until that's passing.

@shellscape @Septh Looks like just some unrelated thing to do with the git config email… I had a similar problem in one of my worflows recently… The solutions was something like ${{ github.event.pusher.email }}… So I will see if I can find the time to take a look at this and see if we can get this PR over the line, and finally fix those types!

Also, see my https://github.com/rollup/plugins/pull/1743#issuecomment-2543948873 @shellscape…

danielbayley avatar Dec 29 '24 16:12 danielbayley

Any chance to get some traction on this? It's been an issue for a while now. Perhaps re-trigger CI in case issue was resolved elsewhere?

MeirionHughes avatar May 07 '25 12:05 MeirionHughes