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
feat(typescript): write declaration files in configured directory for output.file
#1378
Conversation
@rollup/plugin-typescript
: Write declaration files in configured directory for output.file
output.file
Please see the Validate Monorepo workflow result. In a monorepo you cannot add a dependency manually without also running |
6377ea7
to
e276dd7
Compare
Oh thank you! Should be fixed now :) |
test.serial('supports emitting declarations in correct directory for output.file', async (t) => { | ||
// Ensure even when no `output.dir` is configured, declarations are emitted to configured `declarationDir` | ||
process.chdir('fixtures/basic'); | ||
const outputOpts = { format: 'es', file: 'dist/main.esm.js' }; |
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.
I'd like to also see a test where the output file doesn't match the declaration dir
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.
What do you mean? Something like this?:
output.file = 'dist/main.js'
declarationDir = 'types'
This will always result in dist/types/main.d.ts
, because rollup does not allow files outside the output.dir
or the base directory of the output.file
, see this rollups source.
Please note that we'll close this as stale if the PR hasn't received any attention from the author in 60 days. |
My problem is: I do not have a Windows machine to test this PR so I will have to blind guess how to fix the windows node tests |
I understand. This looks like path differences between windows and nix. I'll see if we can't get you some help for this. |
So I took these changes for a test drive in my Vite library project and was still having problems. What I also changed to fix things was to replace My tsconfig for reference: {
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"removeComments": true,
"declaration": true,
"emitDeclarationOnly": true,
"baseDir": ".",
"outDir": "dist",
"declarationDir": "dist",
"jsx": "react",
"strict": true,
"sourceMap": true,
"declarationMap": true,
"paths": {
"*": ["./src/*"],
"components/*": ["./src/components/*"]
}
},
"include": [
"src/**/*"
],
"exclude": [
"dist"
]
} and Vite config: export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: '[redacted]'
},
rollupOptions: {
plugins: [
typescript({
tsconfig: "./tsconfig.json",
}),
],
},
},
}); |
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
d4fb1b3
to
7390519
Compare
@shellscape @NotWoods I think I fixed the issues, can you trigger the CI? BTW: The last commit I pushed is for more readability (at least I think it is more self explaining code), if accepted I will squash it. |
This function returns the file names and content as rollup would write to filesystem. Emulating `handleGenerateWrite` and `writeOutputFile`. Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
This fixes writing declarations into the configured `declarationDir` when configured rollup build with `output.file` instead of `output.dir`. Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
… workaround Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
b56502c
to
68dd7dc
Compare
@halfmatthalfcat if you have a small reproduction repo (or repl.it or stackblitz) for @susnux to take a look at, that would be helpful |
Yes that would be really helpful, but I might also have fixed that issue as a rewrote the code while fixing the issues. |
I think we're good to go. Thanks for working through this with the team. |
Hello @susnux , If I have this rollup config :
And this package.json :
And this tsconfig.json :
The rollup command is failing because it didn't find the file : "lib/esm/types/index.d.ts" |
cc @NotWoods |
@rm116 You should upgrade Using the latest version everything from your example works for me. |
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:
output.file
is used, ifoutput.dir
is used everything should, as it does, be placed inside that directory)Description
If you configure rollup with
output.file = 'dist/main.js'
and typscript with'declarationDir: "dist"
Instead of writing the declarations into
dist/
they are written intodist/dist
, and the workaround from the README does not work anymore, if you set 'declarationDir: "."` no declarations are written at all.So this is fixes by only enforcing declarations inside
output.dir
but not insidedirname(output.file)
(see added test case).Additionally:
resolve
to get the package build.handleGenerateWrite
andwriteOutputFile
)