-
-
Notifications
You must be signed in to change notification settings - Fork 591
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)!: correctly resolve filenames of declaration files for output.file
#1728
Conversation
…es when output.file is used
… directory when using output.file
…when using output.file
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.
baseDir
, which is used to resolve the pathname for this.emitFile
using path.relative(baseDir, id)
, should just be the bundle output directory since id is the absolute file path we want to emit.
Thanks for the PR. Since this will change some expectations around outputs, we'll have to mark this as a breaking change. |
output.file
output.file
This change corrects a regression introduced by rollup#1728, preventing dual bundle configs from writing output files to directories nested within the directory defined in the tsconfig's outDir property. Example: ```js export default { input: 'src/index.ts', // Replace with the path to your entry TypeScript file output: [ { dir: 'dist/cjs', format: 'cjs', sourcemap: true, preserveModules: true }, { dir: 'dist/esm', format: 'esm', sourcemap: true, preserveModules: true } ], plugins: [ json(), resolve(), commonjs(), typescript({ tsconfig: 'tsconfig.json', compilerOptions: { /* Basic Options */ target: 'ES5', module: 'ES2020', lib: ['ES2019', 'ES2020'], allowJs: true, checkJs: false, /* Strict Type-Checking Options */ strict: true, /* Module Resolution Options */ moduleResolution: 'node', esModuleInterop: true, /* Advanced Options */ forceConsistentCasingInFileNames: true, skipDefaultLibCheck: true, skipLibCheck: true, outDir: path.join(__dirname, 'dist') } }) ], external: deps // Add any external dependencies you don't want to bundle }; ```
This change corrects a regression introduced by rollup#1728, preventing dual bundle configs from writing output files to directories nested within the directory defined in the tsconfig's outDir property. Example: ```js export default { input: 'src/index.ts', // Replace with the path to your entry TypeScript file output: [ { dir: 'dist/cjs', format: 'cjs', sourcemap: true, preserveModules: true }, { dir: 'dist/esm', format: 'esm', sourcemap: true, preserveModules: true } ], plugins: [ json(), resolve(), commonjs(), typescript({ tsconfig: 'tsconfig.json', compilerOptions: { /* Basic Options */ target: 'ES5', module: 'ES2020', lib: ['ES2019', 'ES2020'], allowJs: true, checkJs: false, /* Strict Type-Checking Options */ strict: true, /* Module Resolution Options */ moduleResolution: 'node', esModuleInterop: true, /* Advanced Options */ forceConsistentCasingInFileNames: true, skipDefaultLibCheck: true, skipLibCheck: true, outDir: path.join(__dirname, 'dist') } }) ], external: deps // Add any external dependencies you don't want to bundle }; ```
#1783) fix(typescript): allow for files to be nested within outDir This change corrects a regression introduced by #1728, preventing dual bundle configs from writing output files to directories nested within the directory defined in the tsconfig's outDir property. Example: ```js export default { input: 'src/index.ts', // Replace with the path to your entry TypeScript file output: [ { dir: 'dist/cjs', format: 'cjs', sourcemap: true, preserveModules: true }, { dir: 'dist/esm', format: 'esm', sourcemap: true, preserveModules: true } ], plugins: [ json(), resolve(), commonjs(), typescript({ tsconfig: 'tsconfig.json', compilerOptions: { /* Basic Options */ target: 'ES5', module: 'ES2020', lib: ['ES2019', 'ES2020'], allowJs: true, checkJs: false, /* Strict Type-Checking Options */ strict: true, /* Module Resolution Options */ moduleResolution: 'node', esModuleInterop: true, /* Advanced Options */ forceConsistentCasingInFileNames: true, skipDefaultLibCheck: true, skipLibCheck: true, outDir: path.join(__dirname, 'dist') } }) ], external: deps // Add any external dependencies you don't want to bundle }; ```
Rollup Plugin Name:
@rollup/plugin-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
Currently, when
output.file
is specified instead ofoutput.dir
, the filename for emitting declaration files withthis.emitFile
is resolved incorrectly. This means that given adeclarationDir
that is outside of the bundle output directory (which isoutput.dir || dirname(output.file!)
), the declarations will still be generated inside the bundle, albeit in a location not actually matchingdeclarationDir
that does not respect the absolute file path generated by typescript.Whereas when using
output.dir
,declarationDir
is actually validated and filenames for declarations are resolved correctly.For example, with
output.file = 'some-path/index.js'
anddeclarationDir = 'types'
, the declaration files will be generated atsome-path/types/index.d.ts
, instead oftypes/index.d.ts
which is the correct location (but invalid as it would be output the bundle directory). Whenoutput.dir = 'some-path'
is used instead, validation fails as expected.This can be fixed by just using
dirname(output.file)
in place ofoutput.dir
whenoutput.file
is specified, and including a validation check thatdeclarationDir
is valid when usingoutput.file
.