-
-
Notifications
You must be signed in to change notification settings - Fork 597
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(node): Add node flags to CLI #377
Changes from 5 commits
fbcb792
35c2961
ba81985
1e824af
65c0ab1
03e9f0e
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const spawn = require("cross-spawn"); | ||
const path = require("path"); | ||
|
||
module.exports = function(argv) { | ||
const args = [path.join(__dirname, "webpack.js")]; | ||
|
||
argv.slice(2).forEach((arg) => { | ||
if (arg.includes("node.")) { | ||
args.unshift(arg.replace("node.", "")); | ||
} else { | ||
args.push(arg); | ||
} | ||
}); | ||
|
||
const webpackCliProcess = spawn(process.execPath, args, { | ||
stdio: "inherit", | ||
}); | ||
|
||
webpackCliProcess.on("exit", (code, signal) => { | ||
process.on("exit", () => { | ||
if (signal) { | ||
process.kill(process.pid, signal); | ||
} else { | ||
process.exit(code); | ||
} | ||
}); | ||
}); | ||
|
||
// Terminate children | ||
// just in case the current one is terminated. | ||
process.on("SIGINT", () => { | ||
webpackCliProcess.kill("SIGINT"); | ||
webpackCliProcess.kill("SIGTERM"); | ||
}); | ||
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,13 @@ | |
"info" | ||
]; | ||
|
||
const nodeFlags = process.argv.filter((arg) => arg.includes("node.")); | ||
|
||
if (nodeFlags.length) { | ||
require("./process-node-flags")(process.argv); | ||
return; | ||
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. Why there's a 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. Same reason as used here. If we don't exit, yargs will warn saying these flags are unknown and the normal cli flow will follow, with this return, the other file can strip those flags, spawn another webpack-cli process and work as intended. 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. Tests added. Let me know if they aren't enough. I've tried to add as many flags as possible. 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. Okay great, thanks! |
||
} | ||
|
||
const NON_COMPILATION_CMD = process.argv.find(arg => { | ||
if (arg === "serve") { | ||
global.process.argv = global.process.argv.filter(a => a !== "serve"); | ||
|
@@ -261,8 +268,8 @@ For more information, see https://webpack.js.org/api/cli/.`); | |
*/ | ||
const stdout = argv.silent | ||
? { | ||
write: () => {} | ||
} // eslint-disable-line | ||
write: () => { } | ||
} // eslint-disable-line | ||
: process.stdout; | ||
|
||
function ifArg(name, fn, init) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "index"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
module.exports = function testAssertions(code, stdout, stderr) { | ||
expect(code).toBe(0); | ||
expect(stdout).toEqual(expect.anything()); | ||
expect(stdout[5]).toContain("main.js"); | ||
expect(stdout[7]).toMatch(/index\.js.*\{0\}/); | ||
expect(stderr).toHaveLength(0); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--node.no-deprecation | ||
--node.no-warnings | ||
./index.js |
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.
Could you add some jsdoc comments here?