-
Notifications
You must be signed in to change notification settings - Fork 71
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
set declaration to be index.d.cts
for cjs
format
#448
Comments
current workaround: import typescript from 'rollup-plugin-typescript2'
import pkg from '../package.json' assert { type: 'json' }
import fs from 'fs'
function renameCjsTypeDeclaration() {
return {
name: 'renameCjsTypeDeclaration',
writeBundle: {
sequential: true,
order: 'post',
handler({ dir, format }) {
if (format === 'cjs') {
fs.rename('dist/cjs/index.d.ts', 'dist/cjs/index.d.cts', console.error)
}
},
},
}
}
export default {
input: 'src/index.ts',
output: [
{ file: pkg.exports['.'].import.default, format: 'esm' },
{ file: pkg.exports['.'].require.default, format: 'cjs' },
],
external: Object.keys(pkg.dependencies || []),
plugins: [
typescript({ tsconfigOverride: { exclude: ['test/**/*'] } }),
renameCjsTypeDeclaration(),
],
} |
index.d.ts
file to be index.d.cts
for the cjs
format instead?index.d.ts
file to be index.d.cts
for the cjs
format
So CJS and Rollup's CJS option have been available long before We could introduce an option to customize file endings. Another option could be to check the file ending of the output JS file and mirror that for the typings. As in, if outputting as That's a great, simple workaround in the meantime! Thanks for providing the code so that other users can do the same if needed! |
Would all the tooling that uses typings (debuggers, language servers, etc) expect correct extension though? Or do they usually have fallbacks to d.ts? If so, changing typing extension to match output extension would break or obsolete mostly workarounds. A minor version bump either way. |
I was more thinking in the opposite direction -- tools that don't yet support Either way, it is changed behavior. And yea, since rpt2 is still |
index.d.ts
file to be index.d.cts
for the cjs
formatindex.d.cts
for cjs
format
So there is potentially a small problem here. If your input is Rollup cannot convert a declaration file to |
Using multiple rollup configs instead of multiple outputs in one config might be needed, similar to what rpt2 does itself: https://github.com/ezolenko/rollup-plugin-typescript2/blob/master/rollup.config.self.js |
currently
With this plugin I generate
index.cjs
via rollup and this plugin generates theindex.d.ts
next to it.desired
how can I set the generated
index.d.ts
file to be calledindex.d.cts
instead?Versions
:rollup.config.js
:tsconfig.json
:package.json
The text was updated successfully, but these errors were encountered: