Log after subsequent compilations in --watch mode (#11220)
This commit is contained in:
parent
93978267ec
commit
698fe8ef50
@ -1,6 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import defaults from "lodash/defaults";
|
import defaults from "lodash/defaults";
|
||||||
|
import debounce from "lodash/debounce";
|
||||||
import { sync as makeDirSync } from "make-dir";
|
import { sync as makeDirSync } from "make-dir";
|
||||||
import slash from "slash";
|
import slash from "slash";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@ -138,6 +139,31 @@ export default async function({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let compiledFiles = 0;
|
||||||
|
let startTime = null;
|
||||||
|
|
||||||
|
const logSuccess = debounce(
|
||||||
|
function() {
|
||||||
|
if (startTime === null) {
|
||||||
|
// This should never happen, but just in case it's better
|
||||||
|
// to ignore the log message rather than making @babel/cli crash.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const diff = process.hrtime(startTime);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Successfully compiled ${compiledFiles} ${
|
||||||
|
compiledFiles !== 1 ? "files" : "file"
|
||||||
|
} with Babel (${diff[0] * 1e3 + Math.round(diff[1] / 1e6)}ms).`,
|
||||||
|
);
|
||||||
|
compiledFiles = 0;
|
||||||
|
startTime = null;
|
||||||
|
},
|
||||||
|
100,
|
||||||
|
{ trailing: true },
|
||||||
|
);
|
||||||
|
|
||||||
if (!cliOptions.skipInitialBuild) {
|
if (!cliOptions.skipInitialBuild) {
|
||||||
if (cliOptions.deleteDirOnStart) {
|
if (cliOptions.deleteDirOnStart) {
|
||||||
util.deleteDir(cliOptions.outDir);
|
util.deleteDir(cliOptions.outDir);
|
||||||
@ -145,17 +171,18 @@ export default async function({
|
|||||||
|
|
||||||
makeDirSync(cliOptions.outDir);
|
makeDirSync(cliOptions.outDir);
|
||||||
|
|
||||||
let compiledFiles = 0;
|
startTime = process.hrtime();
|
||||||
|
|
||||||
for (const filename of cliOptions.filenames) {
|
for (const filename of cliOptions.filenames) {
|
||||||
|
// compiledFiles is just incremented without reading its value, so we
|
||||||
|
// don't risk race conditions.
|
||||||
|
// eslint-disable-next-line require-atomic-updates
|
||||||
compiledFiles += await handle(filename);
|
compiledFiles += await handle(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cliOptions.quiet) {
|
if (!cliOptions.quiet) {
|
||||||
console.log(
|
logSuccess();
|
||||||
`Successfully compiled ${compiledFiles} ${
|
logSuccess.flush();
|
||||||
compiledFiles !== 1 ? "files" : "file"
|
|
||||||
} with Babel.`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,16 +199,30 @@ export default async function({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This, alongside with debounce, allows us to only log
|
||||||
|
// when we are sure that all the files have been compiled.
|
||||||
|
let processing = 0;
|
||||||
|
|
||||||
["add", "change"].forEach(function(type: string): void {
|
["add", "change"].forEach(function(type: string): void {
|
||||||
watcher.on(type, function(filename: string): void {
|
watcher.on(type, async function(filename: string) {
|
||||||
handleFile(
|
processing++;
|
||||||
filename,
|
if (startTime === null) startTime = process.hrtime();
|
||||||
filename === filenameOrDir
|
|
||||||
? path.dirname(filenameOrDir)
|
try {
|
||||||
: filenameOrDir,
|
await handleFile(
|
||||||
).catch(err => {
|
filename,
|
||||||
|
filename === filenameOrDir
|
||||||
|
? path.dirname(filenameOrDir)
|
||||||
|
: filenameOrDir,
|
||||||
|
);
|
||||||
|
|
||||||
|
compiledFiles++;
|
||||||
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
processing--;
|
||||||
|
if (processing === 0 && !cliOptions.quiet) logSuccess();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/foo/.foo.js -> lib/foo/.foo.js
|
src/foo/.foo.js -> lib/foo/.foo.js
|
||||||
src/foo/bar.js -> lib/foo/bar.js
|
src/foo/bar.js -> lib/foo/bar.js
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
src/.foo.js -> lib/.foo.js
|
src/.foo.js -> lib/.foo.js
|
||||||
src/bar/index.js -> lib/bar/index.js
|
src/bar/index.js -> lib/bar/index.js
|
||||||
src/foo/foo.js -> lib/foo/foo.js
|
src/foo/foo.js -> lib/foo/foo.js
|
||||||
Successfully compiled 3 files with Babel.
|
Successfully compiled 3 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/foo/bar.js -> lib/foo/bar.js
|
src/foo/bar.js -> lib/foo/bar.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/index.js -> lib/index.js
|
src/index.js -> lib/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/foo/bar.js -> lib/foo/bar.js
|
src/foo/bar.js -> lib/foo/bar.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/bar/index.js -> lib/bar/index.js
|
src/bar/index.js -> lib/bar/index.js
|
||||||
src/foo/foo.js -> lib/foo/foo.js
|
src/foo/foo.js -> lib/foo/foo.js
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/foobar/foo.js -> lib/foobar/foo.js
|
src/foobar/foo.js -> lib/foobar/foo.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -2,4 +2,4 @@ src/a.js -> lib/a.js
|
|||||||
src/b.js -> lib/b.js
|
src/b.js -> lib/b.js
|
||||||
src/baz/c.js -> lib/baz/c.js
|
src/baz/c.js -> lib/baz/c.js
|
||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 4 files with Babel.
|
Successfully compiled 4 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/bar/index.js -> lib/bar/index.js
|
src/bar/index.js -> lib/bar/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/a.foo.js -> lib/a.foo.js
|
src/a.foo.js -> lib/a.foo.js
|
||||||
src/baz/b.foo.js -> lib/baz/b.foo.js
|
src/baz/b.foo.js -> lib/baz/b.foo.js
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/bar/index.js -> lib/bar/index.js
|
src/bar/index.js -> lib/bar/index.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/bar.mjs -> lib/bar.mjs
|
src/bar.mjs -> lib/bar.mjs
|
||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/bar.mjs -> lib/bar.mjs
|
src/bar.mjs -> lib/bar.mjs
|
||||||
src/foo.jsx -> lib/foo.mjs
|
src/foo.jsx -> lib/foo.mjs
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -2,4 +2,4 @@ package1/src/bar/bar1.js -> package1/lib/bar/bar1.js
|
|||||||
package1/src/foo1.js -> package1/lib/foo1.js
|
package1/src/foo1.js -> package1/lib/foo1.js
|
||||||
package2/src/bar/bar2.js -> package2/lib/bar/bar2.js
|
package2/src/bar/bar2.js -> package2/lib/bar/bar2.js
|
||||||
package2/src/foo2.js -> package2/lib/foo2.js
|
package2/src/foo2.js -> package2/lib/foo2.js
|
||||||
Successfully compiled 4 files with Babel.
|
Successfully compiled 4 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/bar/bar.js -> lib/bar/bar.js
|
src/bar/bar.js -> lib/bar/bar.js
|
||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/bar/bar.js -> lib/bar/bar.js
|
src/bar/bar.js -> lib/bar/bar.js
|
||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
src/bar/bar.js -> lib/bar/bar.js
|
src/bar/bar.js -> lib/bar/bar.js
|
||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Successfully compiled 2 files with Babel.
|
Successfully compiled 2 files with Babel (123ms).
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Successfully compiled 0 files with Babel.
|
Successfully compiled 0 files with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
src/foo.js -> lib/foo.js
|
src/foo.js -> lib/foo.js
|
||||||
Successfully compiled 1 file with Babel.
|
Successfully compiled 1 file with Babel (123ms).
|
||||||
|
|||||||
@ -49,19 +49,19 @@ const saveInFiles = function(files) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const replacePaths = function(str, cwd) {
|
const normalizeOutput = function(str, cwd) {
|
||||||
let prev;
|
let prev;
|
||||||
do {
|
do {
|
||||||
prev = str;
|
prev = str;
|
||||||
str = str.replace(cwd, "<CWD>");
|
str = str.replace(cwd, "<CWD>");
|
||||||
} while (str !== prev);
|
} while (str !== prev);
|
||||||
|
|
||||||
return str;
|
return str.replace(/\(\d+ms\)/g, "(123ms)");
|
||||||
};
|
};
|
||||||
|
|
||||||
const assertTest = function(stdout, stderr, opts, cwd) {
|
const assertTest = function(stdout, stderr, opts, cwd) {
|
||||||
stdout = replacePaths(stdout, cwd);
|
stdout = normalizeOutput(stdout, cwd);
|
||||||
stderr = replacePaths(stderr, cwd);
|
stderr = normalizeOutput(stderr, cwd);
|
||||||
|
|
||||||
const expectStderr = opts.stderr.trim();
|
const expectStderr = opts.stderr.trim();
|
||||||
stderr = stderr.trim();
|
stderr = stderr.trim();
|
||||||
@ -84,6 +84,7 @@ const assertTest = function(stdout, stderr, opts, cwd) {
|
|||||||
if (opts.stdoutContains) {
|
if (opts.stdoutContains) {
|
||||||
expect(stdout).toContain(expectStdout);
|
expect(stdout).toContain(expectStdout);
|
||||||
} else {
|
} else {
|
||||||
|
fs.writeFileSync(opts.stdoutPath, stdout + "\n");
|
||||||
expect(stdout).toBe(expectStdout);
|
expect(stdout).toBe(expectStdout);
|
||||||
}
|
}
|
||||||
} else if (stdout) {
|
} else if (stdout) {
|
||||||
@ -230,6 +231,7 @@ fs.readdirSync(fixtureLoc).forEach(function(binName) {
|
|||||||
|
|
||||||
["stdout", "stdin", "stderr"].forEach(function(key) {
|
["stdout", "stdin", "stderr"].forEach(function(key) {
|
||||||
const loc = path.join(testLoc, key + ".txt");
|
const loc = path.join(testLoc, key + ".txt");
|
||||||
|
opts[key + "Path"] = loc;
|
||||||
if (fs.existsSync(loc)) {
|
if (fs.existsSync(loc)) {
|
||||||
opts[key] = helper.readFile(loc);
|
opts[key] = helper.readFile(loc);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user