Skip to content
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): allow for files to be nested in folders within outDir #1783

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/typescript/src/options/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ export function validatePaths(
for (const dirProperty of DIRECTORY_PROPS) {
if (compilerOptions[dirProperty] && outputDir) {
// Checks if the given path lies within Rollup output dir
const fromRollupDirToTs = relative(outputDir, compilerOptions[dirProperty]!);
if (fromRollupDirToTs.startsWith('..')) {
if (outputOptions.dir) {
if (outputOptions.dir) {
const fromRollupDirToTs = relative(outputDir, compilerOptions[dirProperty]!);
if (fromRollupDirToTs.startsWith('..')) {
context.error(
`@rollup/plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside Rollup 'dir' option.`
);
} else {
}
} else {
const fromTsDirToRollup = relative(compilerOptions[dirProperty]!, outputDir);
if (fromTsDirToRollup.startsWith('..')) {
context.error(
`@rollup/plugin-typescript: Path of Typescript compiler option '${dirProperty}' must be located inside the same directory as the Rollup 'file' option.`
);
Expand Down
30 changes: 30 additions & 0 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,36 @@ test.serial(
}
);

test.serial(
'ensures output files can be written to subdirectories within the tsconfig outDir',
async (t) => {
const warnings = [];
const outputOpts = { format: 'es', file: 'fixtures/basic/dist/esm/main.js' };
const bundle = await rollup({
input: 'fixtures/basic/main.ts',
output: outputOpts,
plugins: [
typescript({
tsconfig: 'fixtures/basic/tsconfig.json',
outDir: 'fixtures/basic/dist'
})
],
onwarn(warning) {
warnings.push(warning);
}
});

// This should not throw an error
const output = await getFiles(bundle, outputOpts);

t.deepEqual(
output.map((out) => out.fileName),
['fixtures/basic/dist/esm/main.js']
);
t.is(warnings.length, 0);
}
);

test.serial('ensures multiple outputs can be built', async (t) => {
// In a rollup.config.js we would pass an array
// The rollup method that's exported as a library won't do that so we must make two calls
Expand Down
Loading