Fix watch bug with output-dir paths. (#7875)
This commit is contained in:
parent
cec93c01ce
commit
df1afa3160
@ -9,11 +9,8 @@ import * as util from "./util";
|
||||
let compiledFiles = 0;
|
||||
|
||||
export default function(commander, filenames, opts) {
|
||||
function write(src, relative, base, callback) {
|
||||
if (typeof base === "function") {
|
||||
callback = base;
|
||||
base = undefined;
|
||||
}
|
||||
function write(src, base, callback) {
|
||||
let relative = path.relative(base, src);
|
||||
if (!util.isCompilableExtension(relative, commander.extensions)) {
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
@ -70,15 +67,11 @@ export default function(commander, filenames, opts) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleFile(src, filename, base, callback) {
|
||||
if (typeof base === "function") {
|
||||
callback = base;
|
||||
base = undefined;
|
||||
}
|
||||
|
||||
write(src, filename, base, function(err, res) {
|
||||
function handleFile(src, base, callback) {
|
||||
write(src, base, function(err, res) {
|
||||
if (err) return callback(err);
|
||||
if (!res && commander.copyFiles) {
|
||||
const filename = path.relative(base, src);
|
||||
const dest = getDest(commander, filename, base);
|
||||
outputFileSync(dest, fs.readFileSync(src));
|
||||
util.chmod(src, dest);
|
||||
@ -102,7 +95,7 @@ export default function(commander, filenames, opts) {
|
||||
const filename = files[index];
|
||||
const src = path.join(dirname, filename);
|
||||
|
||||
handleFile(src, filename, dirname, function(err) {
|
||||
handleFile(src, dirname, function(err) {
|
||||
if (err) return callback(err);
|
||||
index++;
|
||||
if (index !== files.length) {
|
||||
@ -128,12 +121,7 @@ export default function(commander, filenames, opts) {
|
||||
const files = util.readdir(dirname, commander.includeDotfiles);
|
||||
sequentialHandleFile(files, dirname, callback);
|
||||
} else {
|
||||
write(
|
||||
filename,
|
||||
path.basename(filename),
|
||||
path.dirname(filename),
|
||||
callback,
|
||||
);
|
||||
write(filename, path.dirname(filename), callback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,8 +151,8 @@ export default function(commander, filenames, opts) {
|
||||
if (commander.watch) {
|
||||
const chokidar = util.requireChokidar();
|
||||
|
||||
filenames.forEach(function(dirname) {
|
||||
const watcher = chokidar.watch(dirname, {
|
||||
filenames.forEach(function(filenameOrDir) {
|
||||
const watcher = chokidar.watch(filenameOrDir, {
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
@ -175,14 +163,15 @@ export default function(commander, filenames, opts) {
|
||||
|
||||
["add", "change"].forEach(function(type) {
|
||||
watcher.on(type, function(filename) {
|
||||
const relative = path.relative(dirname, filename) || filename;
|
||||
try {
|
||||
handleFile(filename, relative, function(err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
handleFile(
|
||||
filename,
|
||||
filename === filenameOrDir
|
||||
? path.dirname(filenameOrDir)
|
||||
: filenameOrDir,
|
||||
function(err) {
|
||||
if (err) console.error(err.stack);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user