Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writeFile } from 'fs/promises';
import { resolve } from 'path';
import type { Documentation } from 'react-docgen';

export default async function outputResult(
Expand All @@ -12,7 +13,12 @@ export default async function outputResult(
);

if (output) {
await writeFile(output, result, 'utf-8');
const resolvedOutput = resolve(output);
const cwd = resolve('.');
if (!resolvedOutput.startsWith(cwd)) {
throw new Error('Output path must be within the current working directory');
}
await writeFile(resolvedOutput, result, 'utf-8');
} else {
process.stdout.write(result + '\n');
}
Expand Down