-
-
Notifications
You must be signed in to change notification settings - Fork 622
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
Merged
+106
−2
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fbcb792
feat: add support for node flags
matheus1lva 35c2961
tests: Fix node-flags test
matheus1lva ba81985
misc: Fix test failing due to not-found webpack-cli
matheus1lva 1e824af
misc: remove comment
matheus1lva 65c0ab1
misc: refactor removing unecessary args
matheus1lva 03e9f0e
tests: add more tests to prevent argument collision
matheus1lva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const spawn = require("cross-spawn"); | ||
const path = require("path"); | ||
/** | ||
* Lookup for prefixed arguments (node.) | ||
* place them before webpack cli arguments and spawns | ||
* a different process using these V8/Node flags. | ||
* By Doing that, user has the power to provide any node options, e.g --max-old-space-size=1024 | ||
* and these are going to be correctly used. | ||
* | ||
* @param {array} argv - Arguments input by the user directly to CLI | ||
* @returns {Void} void | ||
*/ | ||
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"); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--node.max_old_space_size=1024 | ||
--node.no-warnings | ||
--node.turbo_jt | ||
--display-used-exports | ||
--display-entrypoints | ||
--profile | ||
--bail | ||
--labeled-modules | ||
--optimize-minimize | ||
--mode production | ||
./index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--node.no-deprecation | ||
--node.no-warnings | ||
./index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--node.no-deprecation | ||
--node.no-warnings | ||
--display-used-exports | ||
--display-entrypoints | ||
--mode production | ||
./index.js |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why there's a
return
here?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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Okay great, thanks!