Merge pull request #55 from jfmengels/no-unnecessary-mkdir

Prevent creating folder if input and output file paths are the same
This commit is contained in:
Matthew Griffith 2021-10-05 13:32:14 -04:00 committed by GitHub
commit 8e61bed99f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,9 +102,10 @@ export async function run(
// Make sure all the folders up to the output file exist, if not create them.
// This mirrors elm make behavior.
const outputDirectory = path.dirname(options.outputFilePath);
if (!fs.existsSync(outputDirectory)) {
if (path.dirname(inputFilePath) !== outputDirectory && !fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory, { recursive: true });
}
fs.writeFileSync(options.outputFilePath, transformed);
const fileName = path.basename(inputFilePath);
log('Success!');