Skip to content

Commit e58d29c

Browse files
authored
fix(typescript): path validation issue in validatePaths function (#1800)
* fix(typescript): fix path validation issue in validatePaths function Current code allows paths that are below the 'file' option but not nested directories. For example if file option is set to "C:/examplelib/output" then "C:/examplelib" is fine while "C:/examplelib/output/decl" is not. The order change in this commit fixes this issue introduced in 12.1.1. * fix(typescript): adding test * fix(typescript): fix path validation issue in validatePaths function * fix(typescript): fix path validation issue in validatePaths function * chore: Formatting
1 parent 118d463 commit e58d29c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/typescript/src/options/validate.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,20 @@ export function validatePaths(
6565
`@rollup/plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside Rollup 'dir' option.`
6666
);
6767
}
68-
} else {
68+
} else if (dirProperty === 'outDir') {
6969
const fromTsDirToRollup = relative(compilerOptions[dirProperty]!, outputDir);
7070
if (fromTsDirToRollup.startsWith('..')) {
7171
context.error(
7272
`@rollup/plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside the same directory as the Rollup 'file' option.`
7373
);
7474
}
75+
} else {
76+
const fromTsDirToRollup = relative(outputDir, compilerOptions[dirProperty]!);
77+
if (fromTsDirToRollup.startsWith('..')) {
78+
context.error(
79+
`@rollup/plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside the same directory as the Rollup 'file' option.`
80+
);
81+
}
7582
}
7683
}
7784
}

packages/typescript/test/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ test.serial(
129129
}
130130
);
131131

132+
test.serial(
133+
'ensures declarationDir is allowed in Rollup output directory when output.file is used',
134+
async (t) => {
135+
const bundle = await rollup({
136+
input: 'fixtures/basic/main.ts',
137+
plugins: [
138+
typescript({
139+
tsconfig: 'fixtures/basic/tsconfig.json',
140+
declarationDir: 'fixtures/basic/dist/other',
141+
declaration: true
142+
})
143+
],
144+
onwarn
145+
});
146+
147+
// this should not throw an error
148+
await t.notThrowsAsync(() =>
149+
getCode(bundle, { format: 'es', file: 'fixtures/basic/dist/index.js' }, true)
150+
);
151+
}
152+
);
153+
132154
test.serial(
133155
'ensures output files can be written to subdirectories within the tsconfig outDir',
134156
async (t) => {

0 commit comments

Comments
 (0)