From 3496c130f4ad24f9aadfe388a2671a1c2e9a47c5 Mon Sep 17 00:00:00 2001 From: Saeed Ganji Date: Wed, 21 Aug 2019 22:31:40 +0430 Subject: [PATCH] feat(base-package-manager): updated to keep track of child process Keeping track of the child process in base-package-manager so that later on the process could be killed --- lib/package-managers/base-package-manager.js | 2 +- skeleton/webpack/aurelia_project/tasks/run.ext | 14 ++++++-------- skeleton/webpack/package.json | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/package-managers/base-package-manager.js b/lib/package-managers/base-package-manager.js index bc7534b9d..fc66ab193 100644 --- a/lib/package-managers/base-package-manager.js +++ b/lib/package-managers/base-package-manager.js @@ -12,7 +12,7 @@ exports.BasePackageManager = class { run(command, args = [], workingDirectory = process.cwd()) { return new Promise((resolve, reject) => { - spawn( + this.proc = spawn( this.getExecutablePath(workingDirectory), [command, ...args], { stdio: 'inherit', cwd: workingDirectory } diff --git a/skeleton/webpack/aurelia_project/tasks/run.ext b/skeleton/webpack/aurelia_project/tasks/run.ext index 88f85bfd9..8987e7f98 100644 --- a/skeleton/webpack/aurelia_project/tasks/run.ext +++ b/skeleton/webpack/aurelia_project/tasks/run.ext @@ -2,12 +2,13 @@ import { NPM } from 'aurelia-cli'; import { CLIOptions } from 'aurelia-cli'; import * as project from '../aurelia.json'; -var find = require('find-process'); var kill = require('tree-kill'); const port = CLIOptions.getFlagValue('port') || project.platform.port; const host = CLIOptions.getFlagValue('host') || project.platform.host || "localhost"; +const npm = new NPM(); + const run = () => { console.log('`au run` is an alias of the `npm start`, you may use either of those; see README for more details.'); @@ -22,19 +23,16 @@ const run = () => { args.push(host); } - return (new NPM()).run('start', ['--', ...args]); + return npm.run('start', ['--', ...args]); } const shutdownAppServer = () => { return new Promise(resolve => { - find('port', port) - .then(function (list) { - if (list.length) { - kill(list[0].pid, 'SIGKILL', function (err) { + if(npm.proc){ + kill(npm.proc.pid, 'SIGKILL', function (err) { resolve(); }); - } - }); + } }); }; diff --git a/skeleton/webpack/package.json b/skeleton/webpack/package.json index 9a64c26b1..32fa4f47e 100644 --- a/skeleton/webpack/package.json +++ b/skeleton/webpack/package.json @@ -68,7 +68,6 @@ "html-loader": "", "istanbul-instrumenter-loader": "", "webpack-bundle-analyzer": "", - "find-process": "^1.4.2", "tree-kill": "^1.2.1", }, "scripts": {