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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,16 @@ const assert = require("assert"); | |
// For Node.js <= 10 | ||
if (!assert.match) assert.match = (val, re) => assert(re.test(val)); | ||
|
||
const run = (function* () { | ||
const run = (async function* () { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Ohhh thanks for this! |
||
fs.writeFileSync("./file.txt", "Updated!"); | ||
|
||
files = [yield, yield].sort(); | ||
|
@@ -29,7 +30,7 @@ run.next(); | |
const batchedStrings = []; | ||
let batchId = 0; | ||
|
||
process.stdin.on("data", function listener(chunk) { | ||
process.stdin.on("data", async function listener(chunk) { | ||
const str = String(chunk).trim(); | ||
if (!str) return; | ||
|
||
|
@@ -50,7 +51,7 @@ process.stdin.on("data", function listener(chunk) { | |
console.log(str); | ||
} | ||
|
||
if (run.next(str).done) { | ||
if ((await run.next(str)).done) { | ||
process.exit(0); | ||
} | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const fs = require("fs"); | ||
const assert = require("assert"); | ||
|
||
// For Node.js <= 10 | ||
if (!assert.match) assert.match = (val, re) => assert(re.test(val)); | ||
|
||
const run = (async function* () { | ||
assert.match(yield, /Successfully compiled 4 files with Babel \(\d+ms\)\./); | ||
|
||
// wait 200ms for watcher setup | ||
await new Promise(resolve => setTimeout(resolve, 200)); | ||
// update ./module1/src/index.js | ||
fs.writeFileSync( | ||
"./module1/src/index.js", | ||
`let str = REPLACE_ME + REPLACE_ME;` | ||
); | ||
|
||
assert.match(yield, /Successfully compiled 1 file with Babel \(\d+ms\)\./); | ||
})(); | ||
|
||
run.next(); | ||
|
||
process.stdin.on("data", async function listener(chunk) { | ||
const str = String(chunk).trim(); | ||
if (!str) return; | ||
|
||
console.log(str); | ||
|
||
if ((await run.next(str)).done) { | ||
process.exit(0); | ||
} | ||
}); | ||
|
||
setTimeout(() => { | ||
console.error("EXECUTOR TIMEOUT"); | ||
process.exit(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could replace There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
}, 5000); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
function inlinePlugin(api, { filename }) { | ||
const { types: t } = api; | ||
|
||
const contents = api.cache.using(() => fs.readFileSync(filename, "utf8")); | ||
api.addExternalDependency(filename); | ||
|
||
return { | ||
visitor: { | ||
Identifier(path) { | ||
if (path.node.name === "REPLACE_ME") { | ||
path.replaceWith(t.stringLiteral(contents)); | ||
} | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
module.exports = { | ||
plugins: [ | ||
[inlinePlugin, { filename: path.resolve(__dirname, "./file.txt") }], | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hi :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let str = REPLACE_ME; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(REPLACE_ME); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let str = REPLACE_ME; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(REPLACE_ME); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"args": ["*/src", "--out-dir", "../lib", "--relative", "--watch"], | ||
"noBabelrc": true, | ||
"noDefaultPlugins": true, | ||
"minNodeVersion": 10 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let str = "Hi :)" + "Hi :)"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hi :)"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let str = "Hi :)"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hi :)"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Successfully compiled 4 files with Babel (123ms). | ||
Successfully compiled 1 file with Babel (123ms). |
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
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 foldermodule3/src
, it will not be added to the watcher.