Skip to content

Commit

Permalink
Update to stop:npm-proxy for Windows (#2053)
Browse files Browse the repository at this point in the history
* npm stop proxy update for windows

* make lint happy

* added netstat to eslint dictionary

* adjusted shell prop

* specify listenting ports

---------

Co-authored-by: Vieltojarvi <[email protected]>
  • Loading branch information
ShadowCat567 and Vieltojarvi committed Sep 25, 2024
1 parent 80e493e commit d8692b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslint_dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"mysql",
"namespace",
"namespaces",
"netstat",
"nodejs",
"nodenext",
"nodir",
Expand Down
18 changes: 14 additions & 4 deletions scripts/stop_npm_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ await execa('npm', ['config', 'set', 'registry', NPM_REGISTRY]);
// returns the process id of the process listening on the specified port
let pid: number;
try {
const lsofResult = await execaCommand(
`lsof -n -t -iTCP:${VERDACCIO_PORT} -sTCP:LISTEN`
);
pid = Number.parseInt(lsofResult.stdout.toString());
if (process.platform === 'win32') {
const netStatResult = await execaCommand(
`netstat -n -a -o | grep LISTENING | grep ${VERDACCIO_PORT}`,
{ shell: 'bash' }
);
pid = Number.parseInt(
netStatResult.stdout.toString().split(/(\s)/).slice(-1)[0]
);
} else {
const lsofResult = await execaCommand(
`lsof -n -t -iTCP:${VERDACCIO_PORT} -sTCP:LISTEN`
);
pid = Number.parseInt(lsofResult.stdout.toString());
}
} catch (err) {
console.warn(
'Could not determine npm proxy process id. Most likely the process has already been stopped.'
Expand Down

0 comments on commit d8692b0

Please sign in to comment.