Skip to content
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
3 changes: 3 additions & 0 deletions packages/babel-minify/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ function log(msg, exitCode = 0) {
}

function error(err) {
if (err.file) {
process.stderr.write("Error minifying file: " + err.file + "\n");
}
process.stderr.write(err + "\n");
process.exit(1);
}
Expand Down
25 changes: 18 additions & 7 deletions packages/babel-minify/src/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ const readFileAsync = promisify(fs.readFile);
const writeFileAsync = promisify(fs.writeFile);
const lstat = promisify(fs.lstat);

class MinifyFileError extends Error {
constructor(message, { file }) {
super(message);
this.file = file;
}
}

// set defaults
const readFile = file => readFileAsync(file, { encoding: "utf-8" });
const writeFile = (file, data) =>
writeFileAsync(file, data, { encoding: "utf-8" });

function isJsFile(file) {
return EXTENSIONS.some(ext => path.basename(file, ext) !== file);
return EXTENSIONS.some(ext => path.extname(file) === ext);
}

async function isDir(p) {
Expand Down Expand Up @@ -79,9 +86,9 @@ async function handleFiles(files, outputDir, options) {
return Promise.all(
files.map(file => {
const outputFilename = path.join(outputDir, path.basename(file));
return mkdirp(path.dirname(outputFilename)).then(() =>
handleFile(file, outputFilename, options)
);
return mkdirp(path.dirname(outputFilename))
.then(() => handleFile(file, outputFilename, options))
.catch(e => Promise.reject(new MinifyFileError(e.message, { file })));
})
);
}
Expand All @@ -99,9 +106,13 @@ async function handleDir(dir, outputDir, options) {
const outputFilename = path.join(outputDir, file);
const inputFilename = path.join(dir, file);

return mkdirp(path.dirname(outputFilename)).then(() =>
handleFile(inputFilename, outputFilename, options)
);
return mkdirp(path.dirname(outputFilename))
.then(() => handleFile(inputFilename, outputFilename, options))
.catch(e =>
Promise.reject(
new MinifyFileError(e.message, { file: inputFilename })
)
);
})
);
}
Expand Down