-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli(node): Add node flags to CLI (#377)
* feat: add support for node flags * tests: Fix node-flags test * misc: Fix test failing due to not-found webpack-cli * misc: remove comment * misc: refactor removing unecessary args * tests: add more tests to prevent argument collision
- Loading branch information
1 parent
106c092
commit 05204f8
Showing
11 changed files
with
106 additions
and
2 deletions.
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 |