Skip to content

Commit

Permalink
fix(typescript)!: incorrect declarations directory
Browse files Browse the repository at this point in the history
BREAKING CHANGES: This fix changes the output directory for types with single-file builds
  • Loading branch information
georg94 committed Nov 27, 2022
1 parent b734673 commit a5c90d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/typescript/src/index.ts
Expand Up @@ -157,6 +157,15 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
(parsedOptions.options.declaration
? parsedOptions.options.declarationDir || parsedOptions.options.outDir
: null);
const cwd = normalizePath(process.cwd());
if (
parsedOptions.options.declaration &&
parsedOptions.options.declarationDir &&
baseDir?.startsWith(cwd)
) {
const declarationDir = baseDir.slice(cwd.length + 1);
baseDir = baseDir.slice(0, -1 * declarationDir.length);
}
if (!baseDir && tsconfig) {
baseDir = tsconfig.substring(0, tsconfig.lastIndexOf('/'));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/test/test.js
Expand Up @@ -153,7 +153,7 @@ test.serial('supports emitting types also for single file output', async (t) =>

t.deepEqual(
output.map((out) => out.fileName),
['main.js', 'main.d.ts']
['main.js', 'dist/main.d.ts']
);
t.is(warnings.length, 0);
});
Expand Down

0 comments on commit a5c90d1

Please sign in to comment.