Skip to content

Commit a5c90d1

Browse files
authored
fix(typescript)!: incorrect declarations directory
BREAKING CHANGES: This fix changes the output directory for types with single-file builds
1 parent b734673 commit a5c90d1

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/typescript/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
157157
(parsedOptions.options.declaration
158158
? parsedOptions.options.declarationDir || parsedOptions.options.outDir
159159
: null);
160+
const cwd = normalizePath(process.cwd());
161+
if (
162+
parsedOptions.options.declaration &&
163+
parsedOptions.options.declarationDir &&
164+
baseDir?.startsWith(cwd)
165+
) {
166+
const declarationDir = baseDir.slice(cwd.length + 1);
167+
baseDir = baseDir.slice(0, -1 * declarationDir.length);
168+
}
160169
if (!baseDir && tsconfig) {
161170
baseDir = tsconfig.substring(0, tsconfig.lastIndexOf('/'));
162171
}

packages/typescript/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ test.serial('supports emitting types also for single file output', async (t) =>
153153

154154
t.deepEqual(
155155
output.map((out) => out.fileName),
156-
['main.js', 'main.d.ts']
156+
['main.js', 'dist/main.d.ts']
157157
);
158158
t.is(warnings.length, 0);
159159
});

0 commit comments

Comments
 (0)