Skip to content

Conversation

43081j
Copy link
Collaborator

@43081j 43081j commented Jun 14, 2025

Fixes #1429

cc @paulmillr

i ran it through arethetypeswrong and all seems to be good

43081j added 2 commits June 14, 2025 13:41
Switches the package to be ESM only.

In CJS projects, you can still `require("chokidar")` as long as you're
on Node 20.x.
@paulmillr
Copy link
Owner

Three things:

  1. why keep exports? They aren’t nevessary anymore
  2. Don’t we need “types” root property?
  3. Could you launch node index.ts? That would ensure nodejs can read typescript (erasable syntax)

@43081j
Copy link
Collaborator Author

43081j commented Jun 15, 2025

  1. It can be useful for controlling which files are exposed. We can simplify it to a flat object though. Without it, it'd probably work fine but mean people can import other files we ship too. No strong opinion though - I'd keep it but flatten it but happy to also remove it
  2. We don't anymore since the dts are alongside the js files, so typescript will pick them up automatically
  3. If it isn't already, it would be good to turn on erasable syntax only too

@paulmillr
Copy link
Owner

  1. “Files” control which files are in package, not “exports”. I think it doesn’t matter if *handler files are exposed.
  2. In the past there were some issues with ts not picking it up even while being in same root dir. maybe it’s fixed now
  3. jsbt has erasable syntax tsconfig setting, which we inherit — but useful to test it manually just in case

@43081j
Copy link
Collaborator Author

43081j commented Jun 15, 2025

  1. Files controls what we ship, exports controls what you can import. But again I don't mind either way since we're exporting every js file pretty much
  2. It should be fine now 👍
  3. I can add a test when I get chance

@43081j
Copy link
Collaborator Author

43081j commented Jun 15, 2025

we can't actually do the typescript test since chokidar itself can't be loaded that way

all of our imports correctly reference .js files right now, since that's what will exist at run-time

if we wanted to run chokidar itself from typescript sources, we'd need to configure typescript to use .ts extension in imports (i.e. transform import paths from .ts to .js at build time. since the run-time js still needs .js imports but the sources need .ts imports)

though im not sure any of this matters to us. anyone can import chokidar fine right now in their own typescript executed directly through node. the only people who would want to run chokidar itself on the command line are probably us

we could have a test that runs some typescript that imports chokidar, but what have we achieved by doing that? it just means importing chokidar works and we already know that

@paulmillr
Copy link
Owner

paulmillr commented Jun 15, 2025

transform import paths from .ts to .js at build time

that’s what I do in all noble repos. Jsbt is already prepared for it. It’s just an option in typescript

@43081j
Copy link
Collaborator Author

43081j commented Jun 15, 2025

Where would we be executing chokidar itself through node?

Won't it always be imported?

I know we can flip the flag in tsconfig. Just want to understand where we'd use it though

Either way we probably should tackle it in a separate issue/pr

@paulmillr paulmillr merged commit 3915541 into main Jun 18, 2025
52 of 55 checks passed
@43081j 43081j deleted the esm-only branch June 18, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Release pure esm v5 with node v20+ requirement

2 participants