fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

39
node_modules/find-process/.github/workflows/nodejs.yml generated vendored Normal file
View File

@@ -0,0 +1,39 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Operating System Matrix
# ubuntu-latest: Latest Ubuntu version (currently 22.04)
# windows-latest: Latest Windows Server version (currently 2022)
# macos-12: macOS 12 Monterey (released 2021)
# macos-13: macOS 13 Ventura (released 2022)
# macos-14: macOS 14 Sonoma (released 2023)
# macos-15: macOS 15 Sequoia (released 2024)
os: [ubuntu-latest, windows-latest, macos-12, macos-13, macos-14, macos-15]
# Node.js Version Matrix
# 16: Node.js 16.x LTS (released 2020, EOL April 2024)
# 18: Node.js 18.x LTS (released 2022, EOL April 2025)
# 20: Node.js 20.x LTS (released 2023, EOL April 2026)
node: [16, 18, 20]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run build --if-present
- run: npm test

141
node_modules/find-process/HISTORY.md generated vendored Normal file
View File

@@ -0,0 +1,141 @@
1.4.7 / 2021-11-18
==================
* chore: bump to 1.4.7
* fix: fix undefined issue [#40](http://github.com/yibn2008/find-process/issues/40)
* fix: fix github actions
* fix: fix install method
1.4.6 / 2021-11-18
==================
* chore: bump to 1.4.6
* fix: fix number check issue
1.4.5 / 2021-09-21
==================
* chore: bump to 1.4.5
* fix: fix find-process
* chore(deps): bump path-parse from 1.0.6 to 1.0.7
* chore(deps): bump y18n from 4.0.0 to 4.0.1
1.4.4 / 2020-10-22
==================
* chore: bump to 1.4.4
* chore(deps): bump lodash from 4.17.15 to 4.17.20
* fix: Security updates, Windows unit tests
1.4.3 / 2019-11-15
==================
* chore: bump to 1.4.3
* fix: fix [#30](http://github.com/yibn2008/find-process/issues/30)
1.4.2 / 2019-06-14
==================
* chore: bump to 1.4.2
1.4.1 / 2019-03-22
==================
* chore: bump to 1.4.1
* fix: fix issue [#9](http://github.com/yibn2008/find-process/issues/9)
1.4.0 / 2019-03-22
==================
* chore: bump to 1.4.0
* feat: throw error when run on *nix system
1.3.0 / 2019-03-22
==================
* chore: bump to 1.3.0
* feat: support executable path
* docs: add bin prop to get execute path
1.2.3 / 2019-03-22
==================
* chore: bump to 1.2.3
1.2.2 / 2019-03-22
==================
* fix: fix name issue
* chore: bump to 1.2.2
1.2.1 / 2018-11-15
==================
* chore: add changelog
1.2.0 / 2018-10-19
==================
* fix some bugs
* support `android` platform
* add `strict` mode when finding by `name`
* for `pid`, `ppid`, `uid`, `gid`, always return number
* add official type declaration.
1.1.4 / 2018-10-19
==================
* chore: bump to 1.1.4
1.1.3 / 2018-08-20
==================
* chore: bump to 1.1.3
1.1.2 / 2018-08-14
==================
* chore: bump to 1.1.2
1.1.1 / 2018-04-16
==================
* fix: add ignore config
* chore: bump to 1.1.1
1.1.0 / 2017-07-14
==================
* chore: bump to 1.1.0
* feat: add cli bin support
* fix: fix issue [#2](http://github.com/yibn2008/find-process/issues/2)
1.0.5 / 2016-10-13
==================
* fix: incorrect error info
1.0.4 / 2016-03-20
==================
* fix #1
1.0.3 / 2016-02-04
==================
* Use standard coding style
* Remove unused deps
1.0.2 / 2016-02-02
==================
* Add gitignore keyword
* Add prepublish hook
* Fix: Error occured when pid not exists
1.0.1 / 2016-01-24
==================
* Initial version, support find process by port/pid/name

21
node_modules/find-process/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Zoujie
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

165
node_modules/find-process/README.md generated vendored Normal file
View File

@@ -0,0 +1,165 @@
# find-process
[![Node.js CI](https://github.com/yibn2008/find-process/actions/workflows/nodejs.yml/badge.svg)](https://github.com/yibn2008/find-process/actions/workflows/nodejs.yml)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
With find-process, you can:
- find the process which is listening specified port
- find the process by pid
- find the process by given name or name pattern
We have covered the difference of main OS platform, including **Mac OSX**, **Linux**, **Windows**
and **Android** (with [Termux](https://termux.com)).
## CLI
Install find-process as a CLI tool:
```sh
$ npm install find-process -g
```
Usage:
```sh
Usage: find-process [options] <keyword>
Options:
-V, --version output the version number
-t, --type <type> find process by keyword type (pid|port|name)
-p, --port find process by port
-h, --help output usage information
Examples:
$ find-process node # find by name "node"
$ find-process 111 # find by pid "111"
$ find-process -p 80 # find by port "80"
$ find-process -t port 80 # find by port "80"
```
Example:
![image](https://user-images.githubusercontent.com/4136679/62670202-f49a6b00-b9c4-11e9-8692-7003c6c31a8a.png)
## Node API
You can use npm to install:
```sh
$ npm install find-process --save
```
Usage:
```javascript
const find = require('find-process');
find('pid', 12345)
.then(function (list) {
console.log(list);
}, function (err) {
console.log(err.stack || err);
})
```
## Synopsis
```
Promise<Array> find(type, value, [options])
```
**Arguments**
- `type` the type of find, support: *port|pid|name*
- `value` the value of type, can be RegExp if type is *name*
- `options` this can either be the *object* described below or *boolean* to just set strict mode
- `options.strict` the optional strict mode is for checking *port*, *pid*, or *name* exactly matches the given one. (on Windows, `.exe` can be omitted)
- `options.logLevel` set the logging level to [`trace|debug|info|warn|error`](https://github.com/pimterry/loglevel#documentation). In practice this lets you silence a netstat warning on Linux.
**Return**
The return value of find-process is Promise, if you use **co** you can use `yield find(type, value)` directly.
The resolved value of promise is an array list of process (`[]` means it may be missing on some platforms):
```
[{
pid: <process id>,
ppid: [parent process id],
uid: [user id (for *nix)],
gid: [user group id (for *nix)],
name: <command/process name>,
bin: <execute path (for *nix)>,
cmd: <full command with args>
}, ...]
```
## Example
Find process which is listening port 80.
```javascript
const find = require('find-process');
find('port', 80)
.then(function (list) {
if (!list.length) {
console.log('port 80 is free now');
} else {
console.log('%s is listening port 80', list[0].name);
}
})
```
Find process by pid.
```javascript
const find = require('find-process');
find('pid', 12345)
.then(function (list) {
console.log(list);
}, function (err) {
console.log(err.stack || err);
});
```
Find all nginx process.
```javascript
const find = require('find-process');
find('name', 'nginx', true)
.then(function (list) {
console.log('there are %s nginx process(es)', list.length);
});
```
Find all nginx processes on Linux without logging a warning when run as a user who isn't root.
```javascript
const find = require('find-process');
find('name', 'nginx', {strict: true, logLevel: 'error'})
.then(function (list) {
console.log('there are %s nginx process(es)', list.length);
});
```
## Contributing
We're welcome to receive Pull Request of bugfix or new feature, but please check the list before sending PR:
- **Coding Style** Please follow the [Standard Style](https://github.com/feross/standard)
- **Documentation** Add documentation for every API change
- **Unit test** Please add unit test for bugfix or new feature
## License
[MIT](LICENSE)

77
node_modules/find-process/bin/find-process.js generated vendored Executable file
View File

@@ -0,0 +1,77 @@
#!/usr/bin/env node
'use strict'
const { program } = require('commander')
const chalk = require('chalk')
const log = require('loglevel').getLogger('find-process')
const find = require('..')
const pkg = require('../package.json')
let type, keyword
program
.version(pkg.version)
.option('-t, --type <type>', 'find process by keyword type (pid|port|name)')
.option('-p, --port', 'find process by port')
.arguments('<keyword>')
.action(function (kw) {
keyword = kw
})
.on('--help', () => {
console.log()
console.log(' Examples:')
console.log()
console.log(' $ find-process node # find by name "node"')
console.log(' $ find-process 111 # find by pid "111"')
console.log(' $ find-process -p 80 # find by port "80"')
console.log(' $ find-process -t port 80 # find by port "80"')
console.log()
})
.showHelpAfterError()
.parse(process.argv)
const opts = program.opts()
// check keyword
if (!keyword) {
console.error(chalk.red('Error: search keyword cannot be empty!'))
program.outputHelp()
process.exit(1)
}
// check type
if (opts.port) {
type = 'port'
} else if (!opts.type) {
// pid or port
if (/^\d+$/.test(keyword)) {
type = 'pid'
keyword = Number(keyword)
} else {
type = 'name'
}
} else {
type = opts.type
}
log.debug('find process by: type = %s, keyword = "%s"', type, keyword)
find(type, keyword)
.then(list => {
if (list.length) {
console.log('Found %s process' + (list.length === 1 ? '' : 'es') + '\n', list.length)
for (const item of list) {
console.log(chalk.cyan('[%s]'), item.name || 'unknown')
console.log('pid: %s', chalk.white(item.pid))
console.log('cmd: %s', chalk.white(item.cmd))
console.log()
}
} else {
console.log('No process found')
}
}, err => {
console.error(chalk.red(err.stack || err))
process.exit(1)
})

35
node_modules/find-process/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,35 @@
// https://github.com/pimterry/loglevel/blob/f5a642299bf77a81118d68766a168c9568ecd21b/index.d.ts#L14-L38
interface LogLevel {
TRACE: 0;
DEBUG: 1;
INFO: 2;
WARN: 3;
ERROR: 4;
SILENT: 5;
}
type LogLevelNumbers = LogLevel[keyof LogLevel];
type LogLevelDesc = LogLevelNumbers
| 'trace'
| 'debug'
| 'info'
| 'warn'
| 'error'
| 'silent'
| keyof LogLevel;
declare type Options = {
strict?: boolean;
logLevel?: LogLevelDesc;
}
declare function find(type: "name" | "pid" | "port", value: string | number | RegExp, strict?: boolean | Options): Promise<{
pid: number;
ppid?: number;
uid?: number;
gid?: number;
name: string;
cmd: string;
}[]>
export = find;

10
node_modules/find-process/index.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
/*
* @Author: zoujie.wzj
* @Date: 2016-01-23 17:32:07
* @Last Modified by: Zoujie
* @Last Modified time: 2016-02-04 17:13:18
*/
'use strict'
module.exports = require('./lib/find')

82
node_modules/find-process/lib/find.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
/*
* @Author: zoujie.wzj
* @Date: 2016-01-23 18:18:28
* @Last Modified by: Ayon Lee
* @Last Modified on: 2018-10-19
*/
'use strict'
const findPid = require('./find_pid')
const findProcess = require('./find_process')
const log = require('./logger')
const findBy = {
port (port, config) {
return findPid(port)
.then(pid => {
return findBy.pid(pid, config)
}, () => {
// return empty array when pid not found
return []
})
},
pid (pid, config) {
return findProcess({
pid,
config
})
},
name (name, config) {
return findProcess({
name,
config,
skipSelf: true
})
}
}
/**
* find process by condition
*
* return Promise: [{
* pid: <process id>,
* ppid: <process parent id>,
* uid: <user id (*nix)>,
* gid: <user group id (*nix)>,
* name: <command name>,
* cmd: <process run args>
* }, ...]
*
* If no process found, resolve process with empty array (only reject when error occured)
*
* @param {String} by condition: port/pid/name ...
* @param {Mixed} condition value
* @param {Boolean|Option}
* @return {Promise}
*/
function find (by, value, options) {
const config = Object.assign({
logLevel: 'warn',
strict: typeof options === 'boolean' ? options : false
}, options)
log.setLevel(config.logLevel)
return new Promise((resolve, reject) => {
if (!(by in findBy)) {
reject(new Error(`do not support find by "${by}"`))
} else {
const isNumber = /^\d+$/.test(value)
if (by === 'pid' && !isNumber) {
reject(new Error('pid must be a number'))
} else if (by === 'port' && !isNumber) {
reject(new Error('port must be a number'))
} else {
findBy[by](value, config).then(resolve, reject)
}
}
})
}
module.exports = find

211
node_modules/find-process/lib/find_pid.js generated vendored Normal file
View File

@@ -0,0 +1,211 @@
/*
* @Author: zoujie.wzj
* @Date: 2016-01-22 19:27:17
* @Last Modified by: Ayon Lee
* @Last Modified on: 2018-10-19
*/
'use strict'
// find pid by port
const os = require('os')
const fs = require('fs')
const utils = require('./utils')
const log = require('./logger')
const ensureDir = (path) => new Promise((resolve, reject) => {
if (fs.existsSync(path)) {
resolve()
} else {
fs.mkdir(path, err => {
err ? reject(err) : resolve()
})
}
})
const finders = {
darwin (port) {
return new Promise((resolve, reject) => {
utils.exec('netstat -anv -p TCP && netstat -anv -p UDP', function (err, stdout, stderr) {
if (err) {
reject(err)
} else {
err = stderr.toString().trim()
if (err) {
reject(err)
return
}
// Drop group header, e.g. "Active Internet connections"
const table = utils.stripLine(stdout.toString(), 1)
// Get the next line with the column headers
const headers = table.slice(0, table.indexOf('\n'))
// Drop the header line to get the table body
const body = utils.stripLine(table, 1)
// In macOS >=Sequoia, columns include `rxbytes` and `txbytes`, which
// shifts the PID column to index 10. Detect this with a search
// for rxbytes. (Parsing the headers more robustly isn't possible
// because some colmn names contain spaces, and others are only separated
// by a single space.)
const pidColumn = headers.indexOf('rxbytes') >= 0 ? 10 : 8
const found = utils.extractColumns(body, [0, 3, pidColumn], 10)
.filter(row => {
return !!String(row[0]).match(/^(udp|tcp)/)
})
.find(row => {
const matches = String(row[1]).match(/\.(\d+)$/)
if (matches && matches[1] === String(port)) {
return true
}
return false
})
if (found && found[2].length) {
resolve(parseInt(found[2], 10))
} else {
reject(new Error(`pid of port (${port}) not found`))
}
}
})
})
},
freebsd: 'darwin',
sunos: 'darwin',
linux (port) {
return new Promise((resolve, reject) => {
const cmd = 'netstat -tunlp'
utils.exec(cmd, function (err, stdout, stderr) {
if (err) {
reject(err)
} else {
const warn = stderr.toString().trim()
if (warn) {
// netstat -p ouputs warning if user is no-root
log.warn(warn)
}
// replace header
const data = utils.stripLine(stdout.toString(), 2)
const columns = utils.extractColumns(data, [3, 6], 7).find(column => {
const matches = String(column[0]).match(/:(\d+)$/)
if (matches && matches[1] === String(port)) {
return true
}
return false
})
if (columns && columns[1]) {
const pid = columns[1].split('/', 1)[0]
if (pid.length) {
resolve(parseInt(pid, 10))
} else {
reject(new Error(`pid of port (${port}) not found`))
}
} else {
reject(new Error(`pid of port (${port}) not found`))
}
}
})
})
},
win32 (port) {
return new Promise((resolve, reject) => {
utils.exec('netstat -ano', function (err, stdout, stderr) {
if (err) {
reject(err)
} else {
err = stderr.toString().trim()
if (err) {
reject(err)
return
}
// replace header
const data = utils.stripLine(stdout.toString(), 4)
const columns = utils.extractColumns(data, [1, 4], 5).find(column => {
const matches = String(column[0]).match(/:(\d+)$/)
if (matches && matches[1] === String(port)) {
return true
}
return false
})
if (columns && columns[1].length && parseInt(columns[1], 10) > 0) {
resolve(parseInt(columns[1], 10))
} else {
reject(new Error(`pid of port (${port}) not found`))
}
}
})
})
},
android (port) {
return new Promise((resolve, reject) => {
// on Android Termux, an warning will be emitted when executing `netstat`
// with option `-p` says 'showing only processes with your user ID', but
// it can still fetch the information we need. However, NodeJS treat this
// warning as an error, `util.exec()` will get nothing but the error. To
// get the true output of the command, we need to save it to a tmpfile and
// read that file instead.
const dir = os.tmpdir() + '/.find-process'
const file = dir + '/' + process.pid
const cmd = 'netstat -tunp >> "' + file + '"'
ensureDir(dir).then(() => {
utils.exec(cmd, () => {
fs.readFile(file, 'utf8', (err, data) => {
fs.unlink(file, () => { })
if (err) {
reject(err)
} else {
data = utils.stripLine(data, 2)
const columns = utils.extractColumns(data, [3, 6], 7).find(column => {
const matches = String(column[0]).match(/:(\d+)$/)
if (matches && matches[1] === String(port)) {
return true
}
return false
})
if (columns && columns[1]) {
const pid = columns[1].split('/', 1)[0]
if (pid.length) {
resolve(parseInt(pid, 10))
} else {
reject(new Error(`pid of port (${port}) not found`))
}
} else {
reject(new Error(`pid of port (${port}) not found`))
}
}
})
})
})
})
}
}
function findPidByPort (port) {
const platform = process.platform
return new Promise((resolve, reject) => {
if (!(platform in finders)) {
return reject(new Error(`platform ${platform} is unsupported`))
}
let findPid = finders[platform]
if (typeof findPid === 'string') {
findPid = finders[findPid]
}
findPid(port).then(resolve, reject)
})
}
module.exports = findPidByPort

249
node_modules/find-process/lib/find_process.js generated vendored Normal file
View File

@@ -0,0 +1,249 @@
/*
* @Author: zoujie.wzj
* @Date: 2016-01-23 18:25:37
* @Last Modified by: Sahel LUCAS--SAOUDI
* @Last Modified on: 2021-11-12
*/
'use strict'
const path = require('path')
const utils = require('./utils')
function matchName (text, name) {
if (!name) {
return true
}
// make sure text.match is valid, fix #30
if (text && text.match) {
return text.match(name)
}
return false
}
function fetchBin (cmd) {
const pieces = cmd.split(path.sep)
const last = pieces[pieces.length - 1]
if (last) {
pieces[pieces.length - 1] = last.split(' ')[0]
}
const fixed = []
for (const part of pieces) {
const optIdx = part.indexOf(' -')
if (optIdx >= 0) {
// case: /aaa/bbb/ccc -c
fixed.push(part.substring(0, optIdx).trim())
break
} else if (part.endsWith(' ')) {
// case: node /aaa/bbb/ccc.js
fixed.push(part.trim())
break
}
fixed.push(part)
}
return fixed.join(path.sep)
}
function fetchName (fullpath) {
if (process.platform === 'darwin') {
const idx = fullpath.indexOf('.app/')
if (idx >= 0) {
return path.basename(fullpath.substring(0, idx))
}
}
return path.basename(fullpath)
}
const finders = {
darwin (cond) {
return new Promise((resolve, reject) => {
let cmd
if ('pid' in cond) {
cmd = `ps -p ${cond.pid} -ww -o pid,ppid,uid,gid,args`
} else {
cmd = 'ps ax -ww -o pid,ppid,uid,gid,args'
}
utils.exec(cmd, function (err, stdout, stderr) {
if (err) {
if ('pid' in cond) {
// when pid not exists, call `ps -p ...` will cause error, we have to
// ignore the error and resolve with empty array
resolve([])
} else {
reject(err)
}
} else {
err = stderr.toString().trim()
if (err) {
reject(err)
return
}
const data = utils.stripLine(stdout.toString(), 1)
const columns = utils.extractColumns(data, [0, 1, 2, 3, 4], 5).filter(column => {
if (column[0] && cond.pid) {
return column[0] === String(cond.pid)
} else if (column[4] && cond.name) {
return matchName(column[4], cond.name)
} else {
return !!column[0]
}
})
let list = columns.map(column => {
const cmd = String(column[4])
const bin = fetchBin(cmd)
return {
pid: parseInt(column[0], 10),
ppid: parseInt(column[1], 10),
uid: parseInt(column[2], 10),
gid: parseInt(column[3], 10),
name: fetchName(bin),
bin,
cmd: column[4]
}
})
if (cond.config.strict && cond.name) {
list = list.filter(item => item.name === cond.name)
}
resolve(list)
}
})
})
},
linux: 'darwin',
sunos: 'darwin',
freebsd: 'darwin',
win32 (cond) {
return new Promise((resolve, reject) => {
const cmd = '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -className win32_process | select Name,ProcessId,ParentProcessId,CommandLine,ExecutablePath'
const lines = []
const proc = utils.spawn('powershell.exe', ['/c', cmd], { detached: false, windowsHide: true })
proc.stdout.on('data', data => {
lines.push(data.toString())
})
proc.on('error', err => {
reject(new Error('Command \'' + cmd + '\' failed with reason: ' + err.toString()))
})
proc.on('close', code => {
if (code !== 0) {
return reject(new Error('Command \'' + cmd + '\' terminated with code: ' + code))
}
const list = utils.parseTable(lines.join(''))
.filter(row => {
if ('pid' in cond) {
return row.ProcessId === String(cond.pid)
} else if (cond.name) {
const rowName = row.Name || '' // fix #40
if (cond.config.strict) {
return rowName === cond.name || (rowName.endsWith('.exe') && rowName.slice(0, -4) === cond.name)
} else {
// fix #9
return matchName(row.CommandLine || rowName, cond.name)
}
} else {
return true
}
})
.map(row => ({
pid: parseInt(row.ProcessId, 10),
ppid: parseInt(row.ParentProcessId, 10),
// uid: void 0,
// gid: void 0,
bin: row.ExecutablePath,
name: row.Name || '',
cmd: row.CommandLine
}))
resolve(list)
})
})
},
android (cond) {
return new Promise((resolve, reject) => {
const cmd = 'ps'
utils.exec(cmd, function (err, stdout, stderr) {
if (err) {
if ('pid' in cond) {
// when pid not exists, call `ps -p ...` will cause error, we have to
// ignore the error and resolve with empty array
resolve([])
} else {
reject(err)
}
} else {
err = stderr.toString().trim()
if (err) {
reject(err)
return
}
const data = utils.stripLine(stdout.toString(), 1)
const columns = utils.extractColumns(data, [0, 3], 4).filter(column => {
if (column[0] && cond.pid) {
return column[0] === String(cond.pid)
} else if (column[1] && cond.name) {
return matchName(column[1], cond.name)
} else {
return !!column[0]
}
})
let list = columns.map(column => {
const cmd = String(column[1])
const bin = fetchBin(cmd)
return {
pid: parseInt(column[0], 10),
// ppid: void 0,
// uid: void 0,
// gid: void 0,
name: fetchName(bin),
bin,
cmd
}
})
if (cond.config.strict && cond.name) {
list = list.filter(item => item.name === cond.name)
}
resolve(list)
}
})
})
}
}
function findProcess (cond) {
const platform = process.platform
return new Promise((resolve, reject) => {
if (!(platform in finders)) {
return reject(new Error(`platform ${platform} is unsupported`))
}
let find = finders[platform]
if (typeof find === 'string') {
find = finders[find]
}
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)
})
}
module.exports = findProcess

5
node_modules/find-process/lib/logger.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
'use strict'
const log = require('loglevel')
module.exports = log

167
node_modules/find-process/lib/utils.js generated vendored Normal file
View File

@@ -0,0 +1,167 @@
/*
* @Author: zoujie.wzj
* @Date: 2016-01-23 18:17:55
* @Last Modified by: Sahel LUCAS--SAOUDI
* @Last Modified on: 2021-11-12
*/
'use strict'
const cp = require('child_process')
const UNIT_MB = 1024 * 1024
const utils = {
/**
* exec command with maxBuffer size
*/
exec (cmd, callback) {
cp.exec(cmd, {
maxBuffer: 2 * UNIT_MB,
windowsHide: true
}, callback)
},
/**
* spawn command
*/
spawn (cmd, args, options) {
return cp.spawn(cmd, args, options)
},
/**
* Strip top lines of text
*
* @param {String} text
* @param {Number} num
* @return {String}
*/
stripLine (text, num) {
let idx = 0
while (num-- > 0) {
const nIdx = text.indexOf('\n', idx)
if (nIdx >= 0) {
idx = nIdx + 1
}
}
return idx > 0 ? text.substring(idx) : text
},
/**
* Split string and stop at max parts
*
* @param {Number} line
* @param {Number} max
* @return {Array}
*/
split (line, max) {
const cols = line.trim().split(/\s+/)
if (cols.length > max) {
cols[max - 1] = cols.slice(max - 1).join(' ')
}
return cols
},
/**
* Extract columns from table text
*
* Example:
*
* ```
* extractColumns(text, [0, 2], 3)
* ```
*
* From:
* ```
* foo bar bar2
* valx valy valz
* ```
*
* To:
* ```
* [ ['foo', 'bar2'], ['valx', 'valz'] ]
* ```
*
* @param {String} text raw table text
* @param {Array} idxes the column index list to extract
* @param {Number} max max column number of table
* @return {Array}
*/
extractColumns (text, idxes, max) {
const lines = text.split(/(\r\n|\n|\r)/)
const columns = []
if (!max) {
max = Math.max.apply(null, idxes) + 1
}
lines.forEach(line => {
const cols = utils.split(line, max)
const column = []
idxes.forEach(idx => {
column.push(cols[idx] || '')
})
columns.push(column)
})
return columns
},
/**
* parse table text to array
*
* From:
* ```
* Header1 : foo
* Header2 : bar
* Header3 : val
*
* Header1 : foo2
* Header2 : bar2
* Header3 : val2
* ```
*
* To:
* ```
* [{ Header1: 'foo', Header2: 'bar', Header3: 'val' }, ...]
* ```
*
* @param {String} data raw table data
* @return {Array}
*/
parseTable (data) {
const lines = data.split(/(\r\n\r\n|\r\n\n|\n\r\n|\n\n)/).filter(line => {
return line && line.trim().length > 0
}).map((e) => e.split(/(\r\n|\n|\r)/).filter(line => line.trim().length > 0))
// Join multi-ligne value
lines.forEach((line) => {
for (let index = 0; line[index];) {
const entry = line[index]
if (entry.startsWith(' ')) {
line[index - 1] += entry.trimLeft()
line.splice(index, 1)
} else {
index += 1
}
}
})
return lines.map(line => {
const row = {}
line.forEach((string) => {
const splitterIndex = string.indexOf(':')
const key = string.slice(0, splitterIndex).trim()
row[key] = string.slice(splitterIndex + 1).trim()
})
return row
})
}
}
module.exports = utils

71
node_modules/find-process/package.json generated vendored Normal file
View File

@@ -0,0 +1,71 @@
{
"name": "find-process",
"version": "1.4.11",
"description": "find process info by port/pid/name etc.",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha test/*.test.js && standard",
"lint": "standard --fix && npm-ensure -t deps"
},
"bin": {
"find-process": "bin/find-process.js"
},
"ensure": {
"deps": {
"checkDirs": [
"lib/*",
"bin/*",
"*.js"
]
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/yibn2008/find-process.git"
},
"keywords": [
"node",
"process",
"pid",
"port"
],
"standard": {
"globals": [
"describe",
"beforeEach",
"afterEach",
"it"
],
"ignore": [
"/node_modules",
"/doc",
"/example",
"/test",
"index.d.ts"
]
},
"author": "zoujie <yibn2008@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/yibn2008/find-process/issues"
},
"homepage": "https://github.com/yibn2008/find-process#readme",
"dependencies": {
"chalk": "~4.1.2",
"commander": "^12.1.0",
"loglevel": "^1.9.2"
},
"devDependencies": {
"mocha": "^11.0.1",
"npm-ensure": "^1.3.0",
"standard": "^17.1.2",
"eslint": "^9.17.0",
"glob": "^11.0.0",
"rimraf": "^6.0.1"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
},
"packageManager": "pnpm@9.15.1+sha512.1acb565e6193efbebda772702950469150cf12bcc764262e7587e71d19dc98a423dff9536e57ea44c49bdf790ff694e83c27be5faa23d67e0c033b583be4bfcf"
}