-
Notifications
You must be signed in to change notification settings - Fork 27
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
Declarations not genered to .mts
and .cts
files
#138
Comments
Hi and thanks for well explaining in issue. Primary support added vis #162. Please feel free to mention if you think something is not following up spec with new handler. |
@pi0 I have quickly checked the 1.3.0 and it doesn't seem to produce valid output in the updated playground: https://stackblitz.com/edit/node-yk5rfx?file=package.json&view=editor :( In the playground the output of mkdist should match the TypeScript output (
Currently it outputs (
The test is also indeed flawed. To simplify:
While updating I noticed I used |
.mts
and .cts
files
Environment
mkdist 1.1.2 on Node.js 16.14.2, v18.14.0.
Reproduction
.mts
and.cts
files in yoursrc
directory.mkdist -d --ext js
Example project files
StackBlitz example: https://stackblitz.com/edit/node-erv3qh?file=package.json&view=editor (use
pnpm build:tsc
to build with TypeScript andpnpm build:mkdist
to build withmkdist
,start
to run./dist/index.mjs
with Node).Describe the bug
mkdist
ignores.cts
and.mts
files and copies them as is instead of compiling them to.cjs
(+.d.cts
) and.mjs
(+.d.mts
) respectfully.Additional context
I could've tried to explain the importance of these file extensions on my own but Bing did a nicer job than me 😢
While this is a nice explanation, it fails to mention a few other important things:
If your file has a
.ts
extension, TypeScript always assumes the resulting file will have.js
extension. So if any of the files in your project imports the other file that has.ts
extension, and you useNode16
(NodeNext
) module resolution (which you very much should btw), TypeScript forces you to write import with.js
extension, which is incompatible withmkdist
, unless you force it in.js
extension mode (--ext js
), which you cannot do in environments likenuxt-module-builder
without patching it (which is exactly what I'm struggling with and what I am doing).The other important thing is that
.ts
,.cts
,.mts
on the declaration files imply the existence of the file with the same basename: that is,index.d.ts
says ‘the declaration file is forindex.js
’,a.d.cts
is ‘fora.cjs
’, andb.d.mts
is ‘forb.mjs
’. That becomes super important for libraries that ship with wildcardexports
inpackage.json
, as well helps you as developer to avoid writingtypes
condition which may or may not lead to a correct declaration file (withouttypes
export condition TypeScript looks for[basename].d.[ts/cts/mts]
).Logs
No response
Footnotes
https://www.typescriptlang.org/docs/handbook/esm-node.html ↩ ↩2
https://blog.logrocket.com/how-to-use-ecmascript-modules-with-node-js/ ↩
https://nodejs.org/api/packages.html ↩
The text was updated successfully, but these errors were encountered: