@idlebox/node 1.2.3 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/_fix_esm_loader.cjs +1 -1
  2. package/lib/child_process/respawn.cjs.map +1 -1
  3. package/lib/child_process/respawn.js.map +1 -1
  4. package/lib/error/pretty.cjs +13 -13
  5. package/lib/error/pretty.cjs.map +1 -1
  6. package/lib/error/pretty.js +13 -13
  7. package/lib/error/pretty.js.map +1 -1
  8. package/package.json +49 -45
  9. package/src/asyncLoad.ts +0 -32
  10. package/src/child_process/error.ts +0 -63
  11. package/src/child_process/execa.ts +0 -86
  12. package/src/child_process/lateError.ts +0 -53
  13. package/src/child_process/respawn.ts +0 -128
  14. package/src/cli-io/output.ts +0 -3
  15. package/src/crypto/md5.ts +0 -8
  16. package/src/crypto/sha256.ts +0 -8
  17. package/src/environment/findBinary.ts +0 -13
  18. package/src/environment/getEnvironment.ts +0 -56
  19. package/src/environment/pathEnvironment.ts +0 -45
  20. package/src/error/code.ts +0 -124
  21. package/src/error/pretty.ts +0 -215
  22. package/src/events/dumpEventEmitter.ts +0 -9
  23. package/src/fs/commandExists.ts +0 -48
  24. package/src/fs/exists.ts +0 -17
  25. package/src/fs/tempFolder.ts +0 -46
  26. package/src/fs/weiteChanged.ts +0 -46
  27. package/src/log/terminal.ts +0 -41
  28. package/src/path-resolve/findPackageRoot.ts +0 -20
  29. package/src/path-resolve/findUp.ts +0 -34
  30. package/src/path-resolve/getAllUp.ts +0 -15
  31. package/src/path-resolve/lrelative.ts +0 -20
  32. package/src/path-resolve/nodeResolvePathArray.ts +0 -10
  33. package/src/path-resolve/resolvePath.ts +0 -43
  34. package/src/stream/blackHoleStream.ts +0 -7
  35. package/src/stream/collectingStream.ts +0 -85
  36. package/src/stream/disposableStream.ts +0 -24
  37. package/src/stream/drainStream.ts +0 -19
  38. package/src/stream/loggerStream.ts +0 -61
  39. package/src/stream/streamPromise.ts +0 -23
  40. package/src/tsconfig.json +0 -10
@@ -1,128 +0,0 @@
1
- import { spawnSync } from 'child_process';
2
- import { createRequire } from 'module';
3
- import { platform } from 'os';
4
- import { findBinary } from '../environment/findBinary';
5
- import { spawnGetOutput } from './execa';
6
-
7
- const unshareArgs = ['--pid', '--cgroup', '--fork', '--mount-proc', '--propagation=slave'];
8
-
9
- if (platform() === 'linux' && process.getuid() !== 0) {
10
- unshareArgs.push('--map-root-user');
11
- }
12
-
13
- export function spawnRecreateEventHandlers() {
14
- process.on('SIGINT', () => shutdown_quit('SIGINT', 130));
15
- process.on('SIGTERM', () => shutdown_quit('SIGTERM', 143));
16
- process.on('SIGHUP', () => shutdown_quit('SIGHUP', 129));
17
- }
18
-
19
- function shutdown_quit(signal: string, code: number) {
20
- // console.error('receive signal', signal);
21
- if (process.listenerCount(signal) > 1) {
22
- return;
23
- }
24
- process.exit(code);
25
- }
26
-
27
- /**
28
- * Spawn a command, replace current node process
29
- * If can't do that (eg. on Windows), spawn as normal, but quit self after it quit.
30
- */
31
- export function trySpawnInScope(cmds: string[]): never {
32
- if (process.env.NEVER_UNSHARE || insideScope() || !supportScope()) {
33
- spawnSimulate(cmds[0], cmds.slice(1));
34
- } else {
35
- execLinux(cmds);
36
- }
37
- }
38
-
39
- /**
40
- * Self restart in a pid/cgroup namespace on linux.
41
- * Your application must inside mainFunc, not before or after it.
42
- *
43
- * ```typescript
44
- * import {respawnInScope} from '@idlebox/node'
45
- * respawnInScope(() => {
46
- * import('./real-application');
47
- * });
48
- * ```
49
- */
50
- export function respawnInScope(mainFunc: Function): unknown | never {
51
- if (process.env.NEVER_UNSHARE || insideScope() || !supportScope()) {
52
- spawnRecreateEventHandlers();
53
- mainFunc();
54
- return undefined;
55
- } else {
56
- execLinux(process.argv);
57
- }
58
- }
59
-
60
- let unshare: string;
61
-
62
- function insideScope() {
63
- return process.pid === 1;
64
- }
65
- function supportScope() {
66
- if (platform() === 'linux') {
67
- unshare = findBinary('unshare');
68
- if (!unshare) {
69
- return false;
70
- }
71
-
72
- try {
73
- const supported = spawnGetOutput({
74
- exec: [unshare, ...unshareArgs, 'echo', 'yes'],
75
- sync: true,
76
- });
77
- if (supported !== 'yes') {
78
- return false;
79
- }
80
- } catch {
81
- return false;
82
- }
83
-
84
- return true;
85
- } else {
86
- return false;
87
- }
88
- }
89
-
90
- function spawnSimulate(cmd: string, args: string[]): never {
91
- process.removeAllListeners('SIGINT');
92
- process.removeAllListeners('SIGTERM');
93
- const result = spawnSync(cmd, args, {
94
- stdio: 'inherit',
95
- windowsHide: true,
96
- env: {
97
- ...process.env,
98
- NEVER_UNSHARE: 'true',
99
- },
100
- });
101
- if (result.signal) {
102
- process.kill(process.pid, result.signal);
103
- throw new Error('self kill not quit');
104
- }
105
- process.exit(result.status || 0);
106
- }
107
-
108
- function execLinux(cmds: string[]): never {
109
- const args = [...unshareArgs, '--wd=' + process.cwd(), ...cmds];
110
-
111
- try {
112
- process.env.NEVER_UNSHARE = 'true';
113
- const require = createRequire(import.meta.url);
114
- const kexec = require('kexec');
115
-
116
- process.removeAllListeners('SIGINT');
117
- process.removeAllListeners('SIGTERM');
118
- kexec(unshare, args);
119
- console.error('[Linux] kexec failed.');
120
- } catch (err: any) {
121
- if (err.code === 'MODULE_NOT_FOUND' || err.code === 'UNDECLARED_DEPENDENCY') {
122
- spawnSimulate(unshare, args);
123
- } else {
124
- console.error('[Linux] <%s> kexec failed:', err.code, err);
125
- }
126
- }
127
- process.exit(1);
128
- }
@@ -1,3 +0,0 @@
1
- export function printLine(char = '-') {
2
- console.error(char.repeat(process.stderr.columns || 80));
3
- }
package/src/crypto/md5.ts DELETED
@@ -1,8 +0,0 @@
1
- import { createHash } from 'crypto';
2
-
3
- export function md5(data: Buffer) {
4
- return createHash('md5')
5
- .update(data)
6
- .digest()
7
- .toString('hex');
8
- }
@@ -1,8 +0,0 @@
1
- import { createHash } from 'crypto';
2
-
3
- export function sha256(data: Buffer) {
4
- return createHash('sha256')
5
- .update(data)
6
- .digest()
7
- .toString('hex');
8
- }
@@ -1,13 +0,0 @@
1
- import { PathArray } from '@idlebox/common';
2
- import { resolve } from 'path';
3
- import { existsSync } from '../fs/exists';
4
- import { PathEnvironment } from './pathEnvironment';
5
-
6
- export function findBinary(what: string, pathvar: PathArray = new PathEnvironment(), cwd = process.cwd()) {
7
- for (const path of pathvar.values()) {
8
- if (existsSync(path + '/' + what)) {
9
- return resolve(cwd, path, what);
10
- }
11
- }
12
- return '';
13
- }
@@ -1,56 +0,0 @@
1
- export interface IEnvironmentResult {
2
- value: string | undefined;
3
- name: string;
4
- }
5
-
6
- export function getEnvironment(name: string, env = process.env): IEnvironmentResult {
7
- if (env.hasOwnProperty(name)) {
8
- return {
9
- value: env[name],
10
- name: name,
11
- };
12
- }
13
- name = name.toLowerCase();
14
- for (const item of Object.keys(env)) {
15
- if (item.toLowerCase() === name) {
16
- return {
17
- value: env[item],
18
- name: item,
19
- };
20
- }
21
- }
22
-
23
- return {
24
- value: undefined,
25
- name,
26
- };
27
- }
28
-
29
- export function deleteEnvironment(name: string, env = process.env) {
30
- for (const item of Object.keys(env)) {
31
- if (item.toLowerCase() === name) {
32
- delete env[item];
33
- }
34
- }
35
- }
36
-
37
- export function cleanupEnvironment(name: string, env = process.env) {
38
- if (env.hasOwnProperty(name)) {
39
- for (const item of Object.keys(env)) {
40
- if (item.toLowerCase() === name && name !== item) {
41
- delete env[item];
42
- }
43
- }
44
- } else {
45
- let first = true;
46
- for (const item of Object.keys(env)) {
47
- if (item.toLowerCase() === name) {
48
- if (first) {
49
- first = false;
50
- continue;
51
- }
52
- delete env[item];
53
- }
54
- }
55
- }
56
- }
@@ -1,45 +0,0 @@
1
- import { PathArray } from '@idlebox/common';
2
- import { platform } from 'os';
3
- import { cleanupEnvironment, getEnvironment } from './getEnvironment';
4
-
5
- export const PATH_SEPARATOR = platform() === 'win32' ? ';' : ':';
6
- export class PathEnvironment extends PathArray {
7
- private readonly name: string;
8
- private readonly env: NodeJS.ProcessEnv;
9
-
10
- constructor(varName = platform() === 'win32' ? 'Path' : 'PATH', env: NodeJS.ProcessEnv = process.env) {
11
- const { name, value } = getEnvironment(varName, env);
12
- super('', PATH_SEPARATOR);
13
-
14
- this.name = name;
15
- this.env = env;
16
-
17
- if (value) super.add(value);
18
- cleanupEnvironment(varName);
19
- }
20
-
21
- add(p: string) {
22
- const pSize = this.size;
23
- super.add(p);
24
- if (pSize !== this.size) {
25
- this.save();
26
- }
27
- return this;
28
- }
29
- clear() {
30
- const change = this.size > 0;
31
- super.clear();
32
- if (change) this.save();
33
- }
34
- delete(p: string) {
35
- if (super.delete(p)) {
36
- this.save();
37
- return true;
38
- }
39
- return false;
40
- }
41
-
42
- save() {
43
- this.env[this.name] = this.toString();
44
- }
45
- }
package/src/error/code.ts DELETED
@@ -1,124 +0,0 @@
1
- export enum ERRNO_LINUX {
2
- EPERM = 1 /* Not super-user */,
3
- ENOENT = 2 /* No such file or directory */,
4
- ESRCH = 3 /* No such process */,
5
- EINTR = 4 /* Interrupted system call */,
6
- EIO = 5 /* I/O error */,
7
- ENXIO = 6 /* No such device or address */,
8
- E2BIG = 7 /* Arg list too long */,
9
- ENOEXEC = 8 /* Exec format error */,
10
- EBADF = 9 /* Bad file number */,
11
- ECHILD = 10 /* No children */,
12
- EAGAIN = 11 /* No more processes */,
13
- ENOMEM = 12 /* Not enough core */,
14
- EACCES = 13 /* Permission denied */,
15
- EFAULT = 14 /* Bad address */,
16
- ENOTBLK = 15 /* Block device required */,
17
- EBUSY = 16 /* Mount device busy */,
18
- EEXIST = 17 /* File exists */,
19
- EXDEV = 18 /* Cross-device link */,
20
- ENODEV = 19 /* No such device */,
21
- ENOTDIR = 20 /* Not a directory */,
22
- EISDIR = 21 /* Is a directory */,
23
- EINVAL = 22 /* Invalid argument */,
24
- ENFILE = 23 /* Too many open files in system */,
25
- EMFILE = 24 /* Too many open files */,
26
- ENOTTY = 25 /* Not a typewriter */,
27
- ETXTBSY = 26 /* Text file busy */,
28
- EFBIG = 27 /* File too large */,
29
- ENOSPC = 28 /* No space left on device */,
30
- ESPIPE = 29 /* Illegal seek */,
31
- EROFS = 30 /* Read only file system */,
32
- EMLINK = 31 /* Too many links */,
33
- EPIPE = 32 /* Broken pipe */,
34
- EDOM = 33 /* Math arg out of domain of func */,
35
- ERANGE = 34 /* Math result not representable */,
36
- ENOMSG = 35 /* No message of desired type */,
37
- EIDRM = 36 /* Identifier removed */,
38
- ECHRNG = 37 /* Channel number out of range */,
39
- EL2NSYNC = 38 /* Level 2 not synchronized */,
40
- EL3HLT = 39 /* Level 3 halted */,
41
- EL3RST = 40 /* Level 3 reset */,
42
- ELNRNG = 41 /* Link number out of range */,
43
- EUNATCH = 42 /* Protocol driver not attached */,
44
- ENOCSI = 43 /* No CSI structure available */,
45
- EL2HLT = 44 /* Level 2 halted */,
46
- EDEADLK = 45 /* Deadlock condition */,
47
- ENOLCK = 46 /* No record locks available */,
48
- EBADE = 50 /* Invalid exchange */,
49
- EBADR = 51 /* Invalid request descriptor */,
50
- EXFULL = 52 /* Exchange full */,
51
- ENOANO = 53 /* No anode */,
52
- EBADRQC = 54 /* Invalid request code */,
53
- EBADSLT = 55 /* Invalid slot */,
54
- EDEADLOCK = 56 /* File locking deadlock error */,
55
- EBFONT = 57 /* Bad font file fmt */,
56
- ENOSTR = 60 /* Device not a stream */,
57
- ENODATA = 61 /* No data (for no delay io) */,
58
- ETIME = 62 /* Timer expired */,
59
- ENOSR = 63 /* Out of streams resources */,
60
- ENONET = 64 /* Machine is not on the network */,
61
- ENOPKG = 65 /* Package not installed */,
62
- EREMOTE = 66 /* The object is remote */,
63
- ENOLINK = 67 /* The link has been severed */,
64
- EADV = 68 /* Advertise error */,
65
- ESRMNT = 69 /* Srmount error */,
66
- ECOMM = 70 /* Communication error on send */,
67
- EPROTO = 71 /* Protocol error */,
68
- EMULTIHOP = 74 /* Multihop attempted */,
69
- ELBIN = 75 /* Inode is remote (not really error) */,
70
- EDOTDOT = 76 /* Cross mount point (not really error) */,
71
- EBADMSG = 77 /* Trying to read unreadable message */,
72
- EFTYPE = 79 /* Inappropriate file type or format */,
73
- ENOTUNIQ = 80 /* Given log. name not unique */,
74
- EBADFD = 81 /* f.d. invalid for this operation */,
75
- EREMCHG = 82 /* Remote address changed */,
76
- ELIBACC = 83 /* Can't access a needed shared lib */,
77
- ELIBBAD = 84 /* Accessing a corrupted shared lib */,
78
- ELIBSCN = 85 /* .lib section in a.out corrupted */,
79
- ELIBMAX = 86 /* Attempting to link in too many libs */,
80
- ELIBEXEC = 87 /* Attempting to exec a shared library */,
81
- ENOSYS = 88 /* Function not implemented */,
82
- ENMFILE = 89 /* No more files */,
83
- ENOTEMPTY = 90 /* Directory not empty */,
84
- ENAMETOOLONG = 91 /* File or path name too long */,
85
- ELOOP = 92 /* Too many symbolic links */,
86
- EOPNOTSUPP = 95 /* Operation not supported on transport endpoint */,
87
- EPFNOSUPPORT = 96 /* Protocol family not supported */,
88
- ECONNRESET = 104 /* Connection reset by peer */,
89
- ENOBUFS = 105 /* No buffer space available */,
90
- EAFNOSUPPORT = 106 /* Address family not supported by protocol family */,
91
- EPROTOTYPE = 107 /* Protocol wrong type for socket */,
92
- ENOTSOCK = 108 /* Socket operation on non-socket */,
93
- ENOPROTOOPT = 109 /* Protocol not available */,
94
- ESHUTDOWN = 110 /* Can't send after socket shutdown */,
95
- ECONNREFUSED = 111 /* Connection refused */,
96
- EADDRINUSE = 112 /* Address already in use */,
97
- ECONNABORTED = 113 /* Connection aborted */,
98
- ENETUNREACH = 114 /* Network is unreachable */,
99
- ENETDOWN = 115 /* Network interface is not configured */,
100
- ETIMEDOUT = 116 /* Connection timed out */,
101
- EHOSTDOWN = 117 /* Host is down */,
102
- EHOSTUNREACH = 118 /* Host is unreachable */,
103
- EINPROGRESS = 119 /* Connection already in progress */,
104
- EALREADY = 120 /* Socket already connected */,
105
- EDESTADDRREQ = 121 /* Destination address required */,
106
- EMSGSIZE = 122 /* Message too long */,
107
- EPROTONOSUPPORT = 123 /* Unknown protocol */,
108
- ESOCKTNOSUPPORT = 124 /* Socket type not supported */,
109
- EADDRNOTAVAIL = 125 /* Address not available */,
110
- ENETRESET = 126,
111
- EISCONN = 127 /* Socket is already connected */,
112
- ENOTCONN = 128 /* Socket is not connected */,
113
- ETOOMANYREFS = 129,
114
- EPROCLIM = 130,
115
- EUSERS = 131,
116
- EDQUOT = 132,
117
- ESTALE = 133,
118
- ENOTSUP = 134 /* Not supported */,
119
- ENOMEDIUM = 135 /* No medium (in tape drive) */,
120
- ENOSHARE = 136 /* No such host or network path */,
121
- ECASECLASH = 137 /* Filename exists with different case */,
122
- EILSEQ = 138,
123
- EOVERFLOW = 139 /* Value too large for defined data type */,
124
- }
@@ -1,215 +0,0 @@
1
- import { isAbsolute } from '@idlebox/common';
2
-
3
- const regNormal = /^\s+at ([^\/\s]+)(?: \[as ([^\]]+)])? \(([^:]+)(:\d+)?(:\d+)\)$/;
4
-
5
- const enum regNormalMatch {
6
- fn = 1,
7
- fnAlias,
8
- file,
9
- row,
10
- column,
11
- }
12
-
13
- const regFunctionOnly = /^\s+at ([^\/\\\s]+(?: \[as ([^\]]+)])?)$/;
14
-
15
- const enum regFunctionMatch {
16
- fn = 1,
17
- fnAlias,
18
- }
19
-
20
- const regFileOnly = /^\s+at ([^:]+)(:\d+)?(:\d+)$/;
21
-
22
- const enum regFileOnlyMatch {
23
- file = 1,
24
- row,
25
- column,
26
- }
27
-
28
- const regSimpleFrame = /^\s+at ([^(]+) \(<anonymous>\)$/;
29
-
30
- const enum regSimpleFrameMatch {
31
- fn = 1,
32
- }
33
-
34
- let root = import.meta.url.replace(/^file:\/\//, '');
35
-
36
- export function setErrorLogRoot(_root: string) {
37
- root = _root;
38
- }
39
-
40
- interface IInternalData {
41
- raw?: string;
42
- fn?: string;
43
- as?: string;
44
- file?: string;
45
- line?: number;
46
- col?: number;
47
- abs?: boolean;
48
- }
49
-
50
- export function prettyPrintError(type: string, e: Error) {
51
- console.error(`------------------------------------------
52
- [${type}] ${prettyFormatError(e)}`);
53
- }
54
-
55
- function red(s: string) {
56
- return `\x1B[38;5;9m${s}\x1B[0m`;
57
- }
58
-
59
- export function prettyFormatError(e: Error) {
60
- if (!e || !e.message) {
61
- return red('Unknown Error') + '\n' + new Error().stack?.split('\n').slice(3).join('\n');
62
- }
63
- if (!e.stack) {
64
- return red(e.message + '\nNo stack trace');
65
- }
66
- const stackStr = e.stack.replace(/file:\/\//, '').split(/\n/g);
67
- debugger;
68
- let first = stackStr.shift()!;
69
- const stack: IInternalData[] = stackStr.map((line) => {
70
- if (regNormal.test(line)) {
71
- const m = regNormal.exec(line)!;
72
- return {
73
- fn: m[regNormalMatch.fn],
74
- as: m[regNormalMatch.fnAlias],
75
- file: m[regNormalMatch.file],
76
- line: parseInt(m[regNormalMatch.row].slice(1)),
77
- col: parseInt(m[regNormalMatch.column].slice(1)),
78
- abs: isAbsolute(m[regNormalMatch.file]),
79
- };
80
- } else if (regFunctionOnly.test(line)) {
81
- const m = regFunctionOnly.exec(line)!;
82
- return {
83
- fn: m[regFunctionMatch.fn],
84
- as: m[regFunctionMatch.fnAlias],
85
- file: undefined,
86
- line: undefined,
87
- col: undefined,
88
- abs: false,
89
- };
90
- } else if (regFileOnly.test(line)) {
91
- const m = regFileOnly.exec(line)!;
92
- return {
93
- fn: undefined,
94
- as: undefined,
95
- file: m[regFileOnlyMatch.file],
96
- line: parseInt(m[regFileOnlyMatch.row].slice(1)),
97
- col: parseInt(m[regFileOnlyMatch.column].slice(1)),
98
- abs: isAbsolute(m[regFileOnlyMatch.file]),
99
- };
100
- } else if (regSimpleFrame.test(line)) {
101
- const m = regSimpleFrame.exec(line)!;
102
- return {
103
- fn: m[regSimpleFrameMatch.fn],
104
- as: undefined,
105
- file: '<anonymous>',
106
- line: undefined,
107
- col: undefined,
108
- abs: false,
109
- };
110
- } else {
111
- return { raw: line.replace(/^ /, '') };
112
- }
113
- });
114
- const stackOutput = stack
115
- .filter(ignoreSomeFiles)
116
- .map(translateFunction)
117
- .map(({ raw, fn, file, as, abs, line, col }) => {
118
- let ret;
119
- if (raw) {
120
- return raw;
121
- }
122
-
123
- if (abs) {
124
- const isNodeModule = file?.includes('/node_modules/');
125
- const color = fn ? (isNodeModule ? '4' : '14') : '8';
126
- ret = ` at \x1b[38;5;${color}m`;
127
- if (as && fn && fn.startsWith('Object.')) {
128
- ret += as + ' [export]';
129
- } else {
130
- ret += formatFunctionName(fn, as);
131
- }
132
- ret += '\x1b[0m';
133
- if (file) {
134
- ret += ' (';
135
- if (!isNodeModule) {
136
- ret += '\x1b[38;5;2m';
137
- }
138
- ret += formatFileLine(file.replace(root, '.'), line, col);
139
- ret += '\x1B[0m)';
140
- }
141
- } else {
142
- ret = '\x1B[2m at ';
143
- if (fn) {
144
- ret += fn;
145
- }
146
- if (file) {
147
- if (fn) {
148
- ret += ' (';
149
- }
150
- ret += formatFileLine(file.replace(root, '.'), line, col);
151
- if (fn) {
152
- ret += ')';
153
- }
154
- }
155
- ret += '\x1B[0m';
156
- }
157
- return ret;
158
- });
159
-
160
- if ((e as any).code) {
161
- first = first.replace(/^(\S+):/, (_, name) => {
162
- return `${name}(code ${(e as any).code}):`;
163
- });
164
- }
165
-
166
- return first + '\n' + stackOutput.join('\n');
167
- }
168
-
169
- function formatFileLine(file: string, row?: number, col?: number) {
170
- return `${file}${row ? `:${row}` : ''}${col ? `:${col}` : ''}`;
171
- }
172
-
173
- function formatFunctionName(fn?: string, as?: string) {
174
- if (fn) {
175
- if (as) {
176
- return `${fn} [as ${as}]`;
177
- } else {
178
- return fn;
179
- }
180
- } else {
181
- return '[anonymous]';
182
- }
183
- }
184
-
185
- function translateFunction(data: IInternalData): IInternalData {
186
- if (!data.fn) {
187
- return data;
188
- }
189
- if (data.fn === 'Timeout._onTimeout') {
190
- data.fn = 'setTimeout';
191
- }
192
- if (data.fn.startsWith('Timeout.') && data.as === '_onTimeout') {
193
- data.fn = 'setTimeout->' + data.fn.slice(8);
194
- delete data.as;
195
- }
196
- return data;
197
- }
198
-
199
- function ignoreSomeFiles({ file }: IInternalData): boolean {
200
- if (!file) {
201
- return true;
202
- }
203
- if (file === 'internal/timers.js') {
204
- return false;
205
- }
206
- if (file === 'internal/modules/cjs/loader.js') {
207
- return false;
208
- }
209
- if (!file.includes('/')) {
210
- if (file.startsWith('_stream_')) {
211
- return false;
212
- }
213
- }
214
- return true;
215
- }
@@ -1,9 +0,0 @@
1
- import { EventEmitter } from 'events';
2
-
3
- export function dumpEventEmitterEmit(ev: EventEmitter) {
4
- const real = ev.emit;
5
- ev.emit = (event: string | symbol, ...args: any[]) => {
6
- console.log('[%s] emit:', ev.constructor.name, ...args);
7
- return real.call(ev, event, ...args);
8
- };
9
- }
@@ -1,48 +0,0 @@
1
- import { isWindows } from '@idlebox/common';
2
- import { access, constants, accessSync } from 'fs';
3
- import { PathEnvironment } from '../environment/pathEnvironment';
4
-
5
- const windowsExecExtensions = ['.exe', '.bat', '.cmd', '.com', '.ps1'];
6
-
7
- function exts(alterExt?: string[]) {
8
- if (alterExt) {
9
- const ret = [...alterExt];
10
- if (!isWindows) {
11
- ret.unshift('');
12
- }
13
- return ret;
14
- }
15
- if (isWindows) {
16
- return windowsExecExtensions;
17
- } else {
18
- return [''];
19
- }
20
- }
21
-
22
- export async function commandInPath(cmd: string, alterExt?: string[]): Promise<string | undefined> {
23
- const pathVar = new PathEnvironment();
24
- for (const item of pathVar.join(cmd)) {
25
- for (const ext of exts(alterExt)) {
26
- const found = await new Promise((resolve) => {
27
- access(item + ext, constants.X_OK, (e) => {
28
- if (e) resolve(false);
29
- else resolve(true);
30
- });
31
- });
32
- if (found) return item + ext;
33
- }
34
- }
35
- return undefined;
36
- }
37
- export function commmandInPathSync(cmd: string, alterExt?: string[]): string | undefined {
38
- const pathVar = new PathEnvironment();
39
- for (const item of pathVar.join(cmd)) {
40
- for (const ext of exts(alterExt)) {
41
- try {
42
- accessSync(item + ext, constants.X_OK);
43
- return item + ext;
44
- } catch {}
45
- }
46
- }
47
- return undefined;
48
- }
package/src/fs/exists.ts DELETED
@@ -1,17 +0,0 @@
1
- import { access, accessSync } from 'fs';
2
-
3
- export function existsSync(path: string): boolean {
4
- try {
5
- accessSync(path);
6
- return true;
7
- } catch (e) {
8
- return false;
9
- }
10
- }
11
-
12
- export function exists(path: string): Promise<boolean> {
13
- return new Promise((resolve) => {
14
- const wrappedCallback = (err: Error | null) => (err ? resolve(false) : resolve(true));
15
- access(path, wrappedCallback);
16
- });
17
- }