New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: handle multiple input sources in watch mode #14281
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51335/ |
|
||
setTimeout(() => { | ||
console.error("EXECUTOR TIMEOUT"); | ||
process.exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could replace exit(1)
with exit(0)
in all the watch tests and use .log
instead of .error
, to see at which point they get stuck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I can't reproduce the timeout error on my local machine, now I have to abuse GitHub CI to see what happens.
let files = [yield, yield].sort(); | ||
assert.match(files[0], /src[\\/]index.js -> lib[\\/]index.js/); | ||
assert.match(files[1], /src[\\/]main.js -> lib[\\/]main.js/); | ||
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./); | ||
|
||
logFile("lib/index.js"); | ||
logFile("lib/main.js"); | ||
|
||
// wait 200ms for watcher setup | ||
await new Promise(resolve => setTimeout(resolve, 200)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh thanks for this!
// A map from absolute compiled file path to its base, from which | ||
// the output destination will be determined | ||
const filenameToBaseMap: Map<string, string> = new Map( | ||
filenames.map(filename => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering whether these could be globs or not, but they are already resolved at
babel/packages/babel-cli/src/babel/options.ts
Lines 192 to 197 in 1937284
let filenames = commander.args.reduce(function (globbed, input) { | |
let files = glob.sync(input); | |
if (!files.length) files = [input]; | |
globbed.push(...files); | |
return globbed; | |
}, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes they are resolved prior to watch setup, which means if you run babel */src --watch
and then create a new folder module3/src
, it will not be added to the watcher.
Interesting, tests are still failing even if I invoke initial build after the watcher claims ready: https://github.com/babel/babel/actions/runs/1866868095 I have revert this commit and will explore it in another PR. What a flaky test. Test is passing on my fork: https://github.com/JLHwung/babel/runs/5254435895 |
In this PR we fix a regression introduced in #14065. Currently we registered multiple listeners for each
--src
parameter, however, each listeners will be invoked unconditionally even only one of file specified by some--src
parameter are changed. Thereforebabel-cli
creates multiple compilation and, which is worse, outputs compiled files on unwanted paths.In this PR we determine the input base from the filename when multiple
--src
parameters are specified. A cache is introduced to avoid repeatedly searching--src
parameters.