-
-
Notifications
You must be signed in to change notification settings - Fork 601
fix(typescript): fix declaration file generation for single file outputs #1201
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(typescript): fix declaration file generation for single file outputs #1201
Conversation
Previously, type declaration files were only emitted if outputOptions.dir was used and not outputOptions.file or, as a side effect, if the tsconfig file was specified via a qualified path. This commit fixes that, such that types are also emitted for single file builds.
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 for the PR. This looks good to me, nothing stands out of concern. Test looks good.
@shellscape FYI These changes seem to cause certain rollup-configs to break. Referencesrollup.js configimport nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import dts from 'rollup-plugin-dts'
import typescript from '@rollup/plugin-typescript'
import json from '@rollup/plugin-json'
import { terser } from 'rollup-plugin-terser'
import visualizer from 'rollup-plugin-visualizer'
import bundleSize from 'rollup-plugin-bundle-size'
import path from 'path'
const pkgJSON = require('./package.json')
export default [
{
input: 'src/index.ts',
output: [
{
file: pkgJSON.module,
format: 'esm',
},
{
file: pkgJSON.main,
format: 'cjs',
},
],
plugins: [
peerDepsExternal(),
nodeResolve(),
json(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
outputToFilesystem: true,
}),
terser(),
bundleSize(),
process.env.ANALYZE === 'true' &&
visualizer(() => ({
filename: path.join(__dirname, 'bundle-analysis.html'),
})),
],
external: Object.keys(pkgJSON.peerDependencies || {}),
},
{
input: 'dist/types/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
plugins: [nodeResolve({ preferBuiltins: true }), dts()],
},
] tsconfig.json{
"compilerOptions": {
"target": "ES5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"declaration": true,
"declarationDir": "types",
"rootDir": "src"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules",
"dist"
]
} Additionally here is the package in which the issue occurred. |
I've been experiencing the same issue the same issue as @trm217. Our types have always been output into Relevant configRollup.config.js (partial):
tsconfig.json (complete):
|
Rollup Plugin Name:
typescript
This PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Description
Previously, type declaration files were only emitted if
outputOptions.dir
wasused and not
outputOptions.file
or, as a side effect, if the tsconfig file wasspecified via a qualified path. This commit fixes that, such that types are
also emitted for single file builds.