Skip to content

Commit

Permalink
feature: fix issue #67 to skip find-process itself when search by name
Browse files Browse the repository at this point in the history
  • Loading branch information
yibn2008 committed Dec 28, 2024
1 parent b27e9e6 commit 65575f2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare type Options = {
logLevel?: LogLevelDesc;
}

declare function find(type: "name" | "pid" | "port", value: string | number | RegExp, strict?: boolean | Option): Promise<{
declare function find(type: "name" | "pid" | "port", value: string | number | RegExp, strict?: boolean | Options): Promise<{
pid: number;
ppid?: number;
uid?: number;
Expand Down
3 changes: 2 additions & 1 deletion lib/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const findBy = {
name (name, config) {
return findProcess({
name: name,
config
config,
skipSelf: true
})
}
}
Expand Down
11 changes: 10 additions & 1 deletion lib/find_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,16 @@ function findProcess (cond) {
find = finders[find]
}

find(cond).then(resolve, reject)
find(cond).then((result) => {
if (cond.skipSelf) {
// skip find-process itself
const filteredResult = result.filter(item => item.pid !== process.pid)

resolve(filteredResult)
} else {
resolve(result)
}
}, reject)
})
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"/node_modules",
"/doc",
"/example",
"/test"
"/test",
"index.d.ts"
]
},
"author": "zoujie <[email protected]>",
Expand Down

0 comments on commit 65575f2

Please sign in to comment.