Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Switch to nodenext resolution #1026

Merged
merged 7 commits into from
Nov 14, 2024
Merged

✨ Switch to nodenext resolution #1026

merged 7 commits into from
Nov 14, 2024

Conversation

coyotte508
Copy link
Member

@coyotte508 coyotte508 commented Nov 14, 2024

Seems necessary for #1025 - also handle #1001 (only for tasks at the moment) cc @martin-gorner

also so that https://arethetypeswrong.github.io/?p=@huggingface/tasks is ✔️ cc @Pierrci - in addition to the .cts exports

And finally export snippets types (https://github.com/huggingface-internal/moon-landing/pull/10998/files#r1841375306)

Types pass: https://arethetypeswrong.github.io/?p=%40huggingface%2Ftasks%400.13.0-test5 !

@coyotte508 coyotte508 requested a review from mishig25 as a code owner November 14, 2024 01:47
Copy link
Member Author

@coyotte508 coyotte508 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only way I found to have at the same time:

  • .d.cts and .d.ts generation
  • "go to source" still working

It's also possible to upgrade tsup and use --dts (instead of tsc) to generate the declaration files, but then the "go to source" won't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow that feels like kind of a dubious method tbh ^^'

iiuc from https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext, the most correct way to get cjs types would be to call tsc --emitDeclarationOnly --declaration --outDir xxx after temporarily removing type: "module" from the package.json and then rename+move those declaration files; did you try that by any chance?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to edit the package.json, you can run tsc with --module commonjs maybe.

But anyway I think the types are the same, only the js flies would be different. And with your solution we still need to rename / edit the .ts and .map files.

Thinking about it, we should not use tsup at all for the sourcemaps to work correctly. and in that case we do indeed need to run tsc twice. 🤔

But it was already broken, problaby

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @andrewbranch too on this btw, in case he has some insights for us by any chance on the best way to emit both ESM and CJS types through tsc directly (while transpiling the js itself through tsup) 🙏

Copy link
Member

@Pierrci Pierrci Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to edit the package.json, you can run tsc with --module commonjs maybe.

well, the thing is, it's not the same (from the link shared in my previous message):

CommonJS emit is similar to --module commonjs, but dynamic import() calls are not transformed.

^^ I guess this doesn't affect declaration files though, so maybe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have dynamic import calls anyway in @huggingface/tasks 🤓

(to keep in mind for @huggingface/hub though)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/isaacs/tshy automates this in a safe way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tysm for the pointer, we'll check it out!

@coyotte508 coyotte508 merged commit 06fb210 into main Nov 14, 2024
5 checks passed
@coyotte508 coyotte508 deleted the extension-fix branch November 14, 2024 21:19
Copy link
Member

@Pierrci Pierrci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raaaah you didn't let me the time lol

@@ -9,10 +9,9 @@
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/src/index.d.ts",
"types": "./dist/index.d.ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, do we need this at all? (given it's resolved automatically based on the require/import values anyway, iiuc)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@coyotte508 coyotte508 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know - maybe for non-node / older contexts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow that feels like kind of a dubious method tbh ^^'

iiuc from https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext, the most correct way to get cjs types would be to call tsc --emitDeclarationOnly --declaration --outDir xxx after temporarily removing type: "module" from the package.json and then rename+move those declaration files; did you try that by any chance?

@coyotte508
Copy link
Member Author

raaaah you didn't let me the time lol

yes sorry didn't want more merge conflicts with all the imports 🙈

coyotte508 added a commit that referenced this pull request Nov 15, 2024
Follow up to #1026

Benefit is that exports are better defined, and source-mapping works.

Also, move the generation scripts from `@huggingace/tasks` to
`@huggingface/tasks-gen` cc @Wauplin @SBrandeis

So that the dev dependencies are not tacked on `@huggingface/tasks`.
Some package managers, *cough* yarn *cough* like to download them when
importing a package, even if they're irrelevant.
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.

3 participants