@idlebox/node 1.4.1 → 1.4.3
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.
- package/lib/cjs/__create_index.generated.cjs +6 -6
- package/lib/cjs/__create_index.generated.cjs.map +1 -1
- package/lib/cjs/child_process/error.cjs +6 -3
- package/lib/cjs/child_process/error.cjs.map +1 -1
- package/lib/cjs/child_process/execa.cjs +2 -2
- package/lib/cjs/child_process/execa.cjs.map +1 -1
- package/lib/cjs/child_process/lateError.cjs +26 -14
- package/lib/cjs/child_process/lateError.cjs.map +1 -1
- package/lib/cjs/child_process/respawn.cjs +4 -4
- package/lib/cjs/child_process/respawn.cjs.map +1 -1
- package/lib/cjs/cli-io/output.cjs +1 -1
- package/lib/cjs/cli-io/output.cjs.map +1 -1
- package/lib/cjs/environment/findBinary.cjs +4 -4
- package/lib/cjs/environment/findBinary.cjs.map +1 -1
- package/lib/cjs/environment/npmConfig.cjs +2 -2
- package/lib/cjs/environment/npmConfig.cjs.map +1 -1
- package/lib/cjs/environment/pathEnvironment.cjs +3 -3
- package/lib/cjs/environment/pathEnvironment.cjs.map +1 -1
- package/lib/cjs/error/nodejs-error-code.generated.cjs +268 -217
- package/lib/cjs/error/nodejs-error-code.generated.cjs.map +1 -1
- package/lib/cjs/error/types.cjs +6 -6
- package/lib/cjs/error/types.cjs.map +1 -1
- package/lib/cjs/fs/commandExists.cjs +3 -3
- package/lib/cjs/fs/commandExists.cjs.map +1 -1
- package/lib/cjs/fs/exists.cjs +3 -3
- package/lib/cjs/fs/exists.cjs.map +1 -1
- package/lib/cjs/fs/tempFolder.cjs +2 -2
- package/lib/cjs/fs/tempFolder.cjs.map +1 -1
- package/lib/cjs/fs/weiteChanged.cjs +3 -3
- package/lib/cjs/fs/weiteChanged.cjs.map +1 -1
- package/lib/cjs/path-resolve/findPackageRoot.cjs +2 -2
- package/lib/cjs/path-resolve/findPackageRoot.cjs.map +1 -1
- package/lib/cjs/path-resolve/findUp.cjs +57 -18
- package/lib/cjs/path-resolve/findUp.cjs.map +1 -1
- package/lib/cjs/stream/collectingStream.cjs +11 -11
- package/lib/cjs/stream/collectingStream.cjs.map +1 -1
- package/lib/cjs/stream/streamPromise.cjs +5 -4
- package/lib/cjs/stream/streamPromise.cjs.map +1 -1
- package/lib/esm/__create_index.generated.d.ts +2 -0
- package/lib/esm/__create_index.generated.d.ts.map +1 -1
- package/lib/esm/__create_index.generated.js +1 -2
- package/lib/esm/__create_index.generated.js.map +1 -1
- package/lib/esm/__virtual_tsconfig.tsbuildinfo +1 -1
- package/lib/esm/child_process/error.d.ts.map +1 -1
- package/lib/esm/child_process/error.js +6 -3
- package/lib/esm/child_process/error.js.map +1 -1
- package/lib/esm/child_process/execa.js +1 -1
- package/lib/esm/child_process/execa.js.map +1 -1
- package/lib/esm/child_process/lateError.d.ts +6 -5
- package/lib/esm/child_process/lateError.d.ts.map +1 -1
- package/lib/esm/child_process/lateError.js +23 -11
- package/lib/esm/child_process/lateError.js.map +1 -1
- package/lib/esm/child_process/respawn.js +2 -2
- package/lib/esm/child_process/respawn.js.map +1 -1
- package/lib/esm/cli-io/output.js +1 -1
- package/lib/esm/cli-io/output.js.map +1 -1
- package/lib/esm/environment/findBinary.js +2 -2
- package/lib/esm/environment/findBinary.js.map +1 -1
- package/lib/esm/environment/npmConfig.js +1 -1
- package/lib/esm/environment/npmConfig.js.map +1 -1
- package/lib/esm/environment/pathEnvironment.js +1 -1
- package/lib/esm/environment/pathEnvironment.js.map +1 -1
- package/lib/esm/error/nodejs-error-code.generated.d.ts +269 -218
- package/lib/esm/error/nodejs-error-code.generated.d.ts.map +1 -1
- package/lib/esm/error/nodejs-error-code.generated.js +268 -217
- package/lib/esm/error/nodejs-error-code.generated.js.map +1 -1
- package/lib/esm/error/types.d.ts +2 -2
- package/lib/esm/error/types.d.ts.map +1 -1
- package/lib/esm/error/types.js +2 -2
- package/lib/esm/error/types.js.map +1 -1
- package/lib/esm/fs/commandExists.js +1 -1
- package/lib/esm/fs/commandExists.js.map +1 -1
- package/lib/esm/fs/exists.js +1 -1
- package/lib/esm/fs/exists.js.map +1 -1
- package/lib/esm/fs/tempFolder.js +1 -1
- package/lib/esm/fs/tempFolder.js.map +1 -1
- package/lib/esm/fs/weiteChanged.js +1 -1
- package/lib/esm/fs/weiteChanged.js.map +1 -1
- package/lib/esm/path-resolve/findPackageRoot.js +1 -1
- package/lib/esm/path-resolve/findPackageRoot.js.map +1 -1
- package/lib/esm/path-resolve/findUp.d.ts +12 -0
- package/lib/esm/path-resolve/findUp.d.ts.map +1 -1
- package/lib/esm/path-resolve/findUp.js +57 -18
- package/lib/esm/path-resolve/findUp.js.map +1 -1
- package/lib/esm/stream/collectingStream.d.ts +1 -1
- package/lib/esm/stream/collectingStream.d.ts.map +1 -1
- package/lib/esm/stream/collectingStream.js +9 -9
- package/lib/esm/stream/collectingStream.js.map +1 -1
- package/lib/esm/stream/streamPromise.d.ts.map +1 -1
- package/lib/esm/stream/streamPromise.js +5 -4
- package/lib/esm/stream/streamPromise.js.map +1 -1
- package/package.json +5 -5
- package/src/child_process/error.ts +7 -3
- package/src/child_process/execa.ts +1 -1
- package/src/child_process/lateError.ts +27 -14
- package/src/child_process/respawn.ts +2 -2
- package/src/cli-io/output.ts +1 -1
- package/src/environment/findBinary.ts +2 -2
- package/src/environment/npmConfig.ts +1 -1
- package/src/environment/pathEnvironment.ts +1 -1
- package/src/error/cache.generated.json +467 -323
- package/src/error/nodejs-error-code.generated.ts +268 -218
- package/src/error/types.ts +2 -2
- package/src/fs/commandExists.ts +1 -1
- package/src/fs/exists.ts +1 -1
- package/src/fs/tempFolder.ts +1 -1
- package/src/fs/weiteChanged.ts +1 -1
- package/src/path-resolve/findPackageRoot.ts +1 -1
- package/src/path-resolve/findUp.ts +80 -19
- package/src/stream/collectingStream.ts +13 -13
- package/src/stream/streamPromise.ts +5 -4
package/src/error/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LinuxError } from './linux';
|
|
2
|
-
import { NodeError } from './nodejs-error-code.generated';
|
|
1
|
+
import { LinuxError } from './linux.js';
|
|
2
|
+
import { NodeError } from './nodejs-error-code.generated.js';
|
|
3
3
|
|
|
4
4
|
type NodeException<T extends string = any> = NodeJS.ErrnoException & { code: T };
|
|
5
5
|
|
package/src/fs/commandExists.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isWindows } from '@idlebox/common';
|
|
2
2
|
import { access, constants, accessSync } from 'fs';
|
|
3
|
-
import { PathEnvironment } from '../environment/pathEnvironment';
|
|
3
|
+
import { PathEnvironment } from '../environment/pathEnvironment.js';
|
|
4
4
|
|
|
5
5
|
const windowsExecExtensions = ['.exe', '.bat', '.cmd', '.com', '.ps1'];
|
|
6
6
|
|
package/src/fs/exists.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObjectEncodingOptions } from 'fs';
|
|
2
2
|
import { access, readFile } from 'fs/promises';
|
|
3
|
-
import { isNotExistsError } from '../error/types';
|
|
3
|
+
import { isNotExistsError } from '../error/types.js';
|
|
4
4
|
export { existsSync } from 'fs';
|
|
5
5
|
|
|
6
6
|
export async function exists(path: string) {
|
package/src/fs/tempFolder.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, readdirSync, rmdirSync, statSync, unlinkSync } from 'fs';
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
import { IDisposable } from '@idlebox/common';
|
|
4
|
-
import { existsSync } from './exists';
|
|
4
|
+
import { existsSync } from './exists.js';
|
|
5
5
|
|
|
6
6
|
let registered = false;
|
|
7
7
|
const tempFolders = new Set<string>();
|
package/src/fs/weiteChanged.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile as readFileAsync, readFileSync, writeFile as writeFileAsync, writeFileSync } from 'fs';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
|
-
import { exists, existsSync } from './exists';
|
|
3
|
+
import { exists, existsSync } from './exists.js';
|
|
4
4
|
|
|
5
5
|
const readFile = promisify(readFileAsync);
|
|
6
6
|
const writeFile = promisify(writeFileAsync);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import { dirname } from 'path';
|
|
3
|
-
import { findUpUntilSync } from './findUp';
|
|
3
|
+
import { findUpUntilSync } from './findUp.js';
|
|
4
4
|
|
|
5
5
|
export function findPackageRoot(packageName: string, require = createRequire(process.cwd())) {
|
|
6
6
|
try {
|
|
@@ -1,33 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { isWindows } from '@idlebox/common';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { deprecate } from 'node:util';
|
|
4
|
+
import { exists, existsSync } from '../fs/exists.js';
|
|
5
|
+
|
|
6
|
+
export interface IFindOptions {
|
|
7
|
+
/** 从哪开始找,必须是绝对路径 */
|
|
8
|
+
from: string;
|
|
9
|
+
/** 要找的文件 */
|
|
10
|
+
file: string | string[];
|
|
11
|
+
/** 最外层目录,超出或偏离都会停止搜索 */
|
|
12
|
+
top?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const isRoot = isWindows ? /^[A-Z]:[/\\]$/i : /^\/$/;
|
|
16
|
+
|
|
17
|
+
export async function findUpUntil(opts: IFindOptions): Promise<string | null>;
|
|
18
|
+
/** @deprecated */
|
|
19
|
+
export async function findUpUntil(from: string, file: string): Promise<string | null>;
|
|
20
|
+
|
|
21
|
+
export async function findUpUntil(opts: string | IFindOptions, file?: string): Promise<string | null> {
|
|
22
|
+
if (typeof opts === 'string') {
|
|
23
|
+
deprecate(findUpUntil, 'findUpUntil is deprecated. Use findUpUntil(opts) instead.');
|
|
24
|
+
opts = { from: opts, file: [file!] };
|
|
25
|
+
}
|
|
26
|
+
if (typeof opts.file === 'string') {
|
|
27
|
+
opts.file = [opts.file];
|
|
28
|
+
}
|
|
29
|
+
if (opts.top) {
|
|
30
|
+
opts.top = resolve(opts.top);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { from, file: files, top } = opts;
|
|
34
|
+
|
|
35
|
+
for (let _from = resolve(from); !isRoot.test(_from); _from = dirname(_from)) {
|
|
36
|
+
if (top && !_from.startsWith(top)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
const want = resolve(_from, file);
|
|
41
|
+
if (await exists(want)) {
|
|
42
|
+
return want;
|
|
43
|
+
}
|
|
9
44
|
}
|
|
10
45
|
}
|
|
11
46
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
47
|
+
for (const file of files) {
|
|
48
|
+
const final = resolve(from, '/', file);
|
|
49
|
+
if (await exists(final)) {
|
|
50
|
+
return final;
|
|
51
|
+
}
|
|
15
52
|
}
|
|
16
53
|
|
|
17
54
|
return null;
|
|
18
55
|
}
|
|
19
56
|
|
|
20
|
-
export function findUpUntilSync(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
57
|
+
export function findUpUntilSync(opts: IFindOptions): string | null;
|
|
58
|
+
/** @deprecated */
|
|
59
|
+
export function findUpUntilSync(from: string, file: string): string | null;
|
|
60
|
+
|
|
61
|
+
export function findUpUntilSync(opts: string | IFindOptions, file?: string): string | null {
|
|
62
|
+
if (typeof opts === 'string') {
|
|
63
|
+
deprecate(findUpUntil, 'findUpUntil is deprecated. Use findUpUntil(opts) instead.');
|
|
64
|
+
opts = { from: opts, file: [file!] };
|
|
65
|
+
}
|
|
66
|
+
if (typeof opts.file === 'string') {
|
|
67
|
+
opts.file = [opts.file];
|
|
68
|
+
}
|
|
69
|
+
if (opts.top) {
|
|
70
|
+
opts.top = resolve(opts.top);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const { from, file: files, top } = opts;
|
|
74
|
+
|
|
75
|
+
for (let _from = resolve(from); !isRoot.test(_from); _from = dirname(_from)) {
|
|
76
|
+
if (top && !_from.startsWith(top)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
const want = resolve(_from, file);
|
|
81
|
+
if (existsSync(want)) {
|
|
82
|
+
return want;
|
|
83
|
+
}
|
|
25
84
|
}
|
|
26
85
|
}
|
|
27
86
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
87
|
+
for (const file of files) {
|
|
88
|
+
const final = resolve(from, '/', file);
|
|
89
|
+
if (existsSync(final)) {
|
|
90
|
+
return final;
|
|
91
|
+
}
|
|
31
92
|
}
|
|
32
93
|
|
|
33
94
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Writable } from
|
|
2
|
-
import { streamPromise } from
|
|
1
|
+
import { Writable } from "stream";
|
|
2
|
+
import { streamPromise } from "./streamPromise.js";
|
|
3
3
|
|
|
4
4
|
export function streamToBuffer(stream: NodeJS.ReadableStream, raw: false): Promise<string>;
|
|
5
5
|
export function streamToBuffer(stream: NodeJS.ReadableStream, raw: true): Promise<Buffer>;
|
|
@@ -19,8 +19,8 @@ export class RawCollectingStream extends Writable {
|
|
|
19
19
|
super();
|
|
20
20
|
if (sourceStream) {
|
|
21
21
|
sourceStream.pipe(this);
|
|
22
|
-
sourceStream.on(
|
|
23
|
-
this.emit(
|
|
22
|
+
sourceStream.on("error", (e) => {
|
|
23
|
+
this.emit("error", e);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -30,7 +30,7 @@ export class RawCollectingStream extends Writable {
|
|
|
30
30
|
callback();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
getOutput() {
|
|
33
|
+
getOutput(): Buffer {
|
|
34
34
|
return this.buffer!;
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -41,29 +41,29 @@ export class RawCollectingStream extends Writable {
|
|
|
41
41
|
const buffer = this.buffer!;
|
|
42
42
|
delete this.buffer;
|
|
43
43
|
return buffer;
|
|
44
|
-
|
|
44
|
+
}));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export class CollectingStream extends Writable {
|
|
49
|
-
private buffer? =
|
|
49
|
+
private buffer? = "";
|
|
50
50
|
private _promise?: Promise<string>;
|
|
51
51
|
|
|
52
52
|
constructor(sourceStream?: NodeJS.ReadableStream) {
|
|
53
53
|
super();
|
|
54
54
|
if (sourceStream) {
|
|
55
55
|
sourceStream.pipe(this);
|
|
56
|
-
sourceStream.on(
|
|
57
|
-
this.emit(
|
|
56
|
+
sourceStream.on("error", (e) => {
|
|
57
|
+
this.emit("error", e);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
override _write(chunk: Buffer, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
63
63
|
if (!encoding) {
|
|
64
|
-
encoding =
|
|
65
|
-
} else if ((encoding as any) ===
|
|
66
|
-
encoding =
|
|
64
|
+
encoding = "utf8";
|
|
65
|
+
} else if ((encoding as any) === "buffer" || encoding === "binary") {
|
|
66
|
+
encoding = "utf8";
|
|
67
67
|
}
|
|
68
68
|
this.buffer += chunk.toString(encoding);
|
|
69
69
|
callback();
|
|
@@ -80,6 +80,6 @@ export class CollectingStream extends Writable {
|
|
|
80
80
|
const buffer = this.buffer!;
|
|
81
81
|
delete this.buffer;
|
|
82
82
|
return buffer;
|
|
83
|
-
|
|
83
|
+
}));
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -7,10 +7,11 @@ export function streamPromise(stream: NodeJS.ReadableStream | NodeJS.WritableStr
|
|
|
7
7
|
return Promise.resolve();
|
|
8
8
|
} else {
|
|
9
9
|
return new Promise((resolve, reject) => {
|
|
10
|
-
stream
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const r = stream as NodeJS.EventEmitter;
|
|
11
|
+
r.once('end', () => resolve());
|
|
12
|
+
r.once('finish', () => resolve());
|
|
13
|
+
r.once('close', () => resolve());
|
|
14
|
+
r.once('error', reject);
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
}
|