summaryrefslogtreecommitdiffstats
path: root/node_modules/npm-run-all/lib/spawn-posix.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/npm-run-all/lib/spawn-posix.js
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/npm-run-all/lib/spawn-posix.js')
-rw-r--r--node_modules/npm-run-all/lib/spawn-posix.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/node_modules/npm-run-all/lib/spawn-posix.js b/node_modules/npm-run-all/lib/spawn-posix.js
new file mode 100644
index 0000000..604bfef
--- /dev/null
+++ b/node_modules/npm-run-all/lib/spawn-posix.js
@@ -0,0 +1,64 @@
+/**
+ * @module spawn-posix
+ * @author Toru Nagashima
+ * @copyright 2015 Toru Nagashima. All rights reserved.
+ * See LICENSE file in root directory for full license.
+ */
+"use strict"
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const crossSpawn = require("cross-spawn")
+const getDescendentProcessInfo = require("pidtree")
+
+//------------------------------------------------------------------------------
+// Helpers
+//------------------------------------------------------------------------------
+
+/**
+ * Kills the new process and its sub processes.
+ * @this ChildProcess
+ * @returns {void}
+ */
+function kill() {
+ getDescendentProcessInfo(this.pid, { root: true }, (err, pids) => {
+ if (err) {
+ return
+ }
+
+ for (const pid of pids) {
+ try {
+ process.kill(pid)
+ }
+ catch (_err) {
+ // ignore.
+ }
+ }
+ })
+}
+
+//------------------------------------------------------------------------------
+// Public Interface
+//------------------------------------------------------------------------------
+
+/**
+ * Launches a new process with the given command.
+ * This is almost same as `child_process.spawn`.
+ *
+ * This returns a `ChildProcess` instance.
+ * `kill` method of the instance kills the new process and its sub processes.
+ *
+ * @param {string} command - The command to run.
+ * @param {string[]} args - List of string arguments.
+ * @param {object} options - Options.
+ * @returns {ChildProcess} A ChildProcess instance of new process.
+ * @private
+ */
+module.exports = function spawn(command, args, options) {
+ const child = crossSpawn(command, args, options)
+ child.kill = kill
+
+ return child
+}