-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
fix(core): typings path and export #1708
Conversation
Typescript compiler doesn't seem to find the types unless the full path is specified
}, | ||
"require": { | ||
"default": "./dist/node/asciidoctor.cjs", | ||
"types": "./types/index.d.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we need to specify a d.cts
types file (CommonJS). Since we are using export default function
in index.d.ts
I don't think we should specify types
on require
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may be right regarding the d.cts
extension, seeing microsoft/TypeScript#52363
But if you look at the answers in the same thread, I think there's still need to specify the types
explicitly on the require
conditional, as there's not matching patch TypeScript will not load it.
My current project is configured for ESM so I could not test the CJS part, it would be helpful to check it on a real CJS project. I'll try to build a test project for that next monday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks that would be helpful!
If it works on CJS we can proceed and merge.
@Techassi if you could confirm that the above configuration works in a CJS project that would be great. |
I also don't use CJS style imports, but I can create a small test project and try it out. Providing the correct path is essential, as currently the |
I just tested it locally. This set of options in {
"exports": {
"require": {
"default": "./dist/node/asciidoctor.cjs",
"types": "./types/index.d.ts"
},
"import": {
"default": "./dist/node/asciidoctor.js",
"types": "./types/index.d.ts"
}
},
"types": "types/index.d.ts",
} We might want to change Side note: It might be good to drop CJS style imports (and types) altogether, as the JS ecosystem is moving to the more modern ESM style. It was quite a hassle to set up this local test project as most modern tooling defaults to ESM. |
OK, so even if the file
I found a rollup pluign: https://github.com/Swatinem/rollup-plugin-dts
We dropped CJS in the first release candidate of Asciidoctor.js but the community was vocal about keeping it. Asciidoctor.js code base is now using ESM and we are using rollup to produce CJS. We might remove CJS support in the next major release. |
Yes seems like it. I got the correct typing information when using CJS imports and the above
Oh yeah, I actually use it in one of my personal projects as well. Had great success working with it. It might require some output path adjustments tho.
I would love to see that! Thanks for getting this merged super quick. Will test it in the real project asap! |
Thanks @Techassi and @ggrossetie for picking up this and completing it 👍 |
Do you have any plans on when this will be released @ggrossetie? Currently, I still use a local dependency as a workaround. |
I will try to push a new release before my vacation (mid January) |
Typescript compiler doesn't seem to find the types unless the full path is specified.
And since the types path doesn't match the exports path, it needs to be added there as well