@idlebox/node 1.4.3 → 1.4.4
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/asyncLoad.cjs +4 -1
- package/lib/cjs/asyncLoad.cjs.map +1 -1
- package/lib/cjs/child_process/error.cjs +8 -8
- package/lib/cjs/child_process/error.cjs.map +1 -1
- package/lib/cjs/child_process/execa.cjs +4 -4
- package/lib/cjs/child_process/execa.cjs.map +1 -1
- package/lib/cjs/child_process/lateError.cjs.map +1 -1
- package/lib/cjs/child_process/respawn.cjs +10 -14
- 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/crypto/md5.cjs +2 -2
- package/lib/cjs/crypto/md5.cjs.map +1 -1
- package/lib/cjs/crypto/sha256.cjs +2 -5
- package/lib/cjs/crypto/sha256.cjs.map +1 -1
- package/lib/cjs/environment/findBinary.cjs +3 -3
- package/lib/cjs/environment/findBinary.cjs.map +1 -1
- package/lib/cjs/environment/npmConfig.cjs +4 -6
- 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/fs/commandExists.cjs +4 -6
- package/lib/cjs/fs/commandExists.cjs.map +1 -1
- package/lib/cjs/fs/emptyDir.cjs +3 -3
- package/lib/cjs/fs/emptyDir.cjs.map +1 -1
- package/lib/cjs/fs/exists.cjs +4 -6
- package/lib/cjs/fs/exists.cjs.map +1 -1
- package/lib/cjs/fs/tempFolder.cjs +10 -10
- package/lib/cjs/fs/tempFolder.cjs.map +1 -1
- package/lib/cjs/fs/weiteChanged.cjs +8 -8
- package/lib/cjs/fs/weiteChanged.cjs.map +1 -1
- package/lib/cjs/log/terminal.cjs.map +1 -1
- package/lib/cjs/path-resolve/findPackageRoot.cjs +6 -8
- package/lib/cjs/path-resolve/findPackageRoot.cjs.map +1 -1
- package/lib/cjs/path-resolve/getAllUp.cjs +2 -2
- package/lib/cjs/path-resolve/getAllUp.cjs.map +1 -1
- package/lib/cjs/path-resolve/lrelative.cjs +5 -5
- package/lib/cjs/path-resolve/lrelative.cjs.map +1 -1
- package/lib/cjs/path-resolve/nodeResolvePathArray.cjs +3 -3
- package/lib/cjs/path-resolve/nodeResolvePathArray.cjs.map +1 -1
- package/lib/cjs/path-resolve/resolvePath.cjs +10 -12
- package/lib/cjs/path-resolve/resolvePath.cjs.map +1 -1
- package/lib/cjs/stream/blackHoleStream.cjs +2 -2
- package/lib/cjs/stream/blackHoleStream.cjs.map +1 -1
- package/lib/cjs/stream/collectingStream.cjs +14 -16
- package/lib/cjs/stream/collectingStream.cjs.map +1 -1
- package/lib/cjs/stream/drainStream.cjs.map +1 -1
- package/lib/cjs/stream/loggerStream.cjs +7 -7
- package/lib/cjs/stream/loggerStream.cjs.map +1 -1
- package/lib/cjs/stream/streamPromise.cjs +8 -10
- package/lib/cjs/stream/streamPromise.cjs.map +1 -1
- package/lib/esm/asyncLoad.d.ts +1 -1
- package/lib/esm/asyncLoad.d.ts.map +1 -1
- package/lib/esm/asyncLoad.js +4 -1
- package/lib/esm/asyncLoad.js.map +1 -1
- package/lib/esm/child_process/error.js +8 -8
- package/lib/esm/child_process/error.js.map +1 -1
- package/lib/esm/child_process/execa.d.ts.map +1 -1
- package/lib/esm/child_process/execa.js +4 -4
- package/lib/esm/child_process/execa.js.map +1 -1
- package/lib/esm/child_process/lateError.d.ts +1 -1
- package/lib/esm/child_process/lateError.d.ts.map +1 -1
- package/lib/esm/child_process/lateError.js.map +1 -1
- package/lib/esm/child_process/respawn.d.ts.map +1 -1
- package/lib/esm/child_process/respawn.js +7 -11
- 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/crypto/md5.js +1 -1
- package/lib/esm/crypto/md5.js.map +1 -1
- package/lib/esm/crypto/sha256.d.ts.map +1 -1
- package/lib/esm/crypto/sha256.js +2 -5
- package/lib/esm/crypto/sha256.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.d.ts.map +1 -1
- package/lib/esm/environment/npmConfig.js +3 -5
- 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/events/dumpEventEmitter.d.ts +1 -1
- package/lib/esm/events/dumpEventEmitter.d.ts.map +1 -1
- package/lib/esm/fs/commandExists.d.ts.map +1 -1
- package/lib/esm/fs/commandExists.js +2 -4
- package/lib/esm/fs/commandExists.js.map +1 -1
- package/lib/esm/fs/emptyDir.js +2 -2
- package/lib/esm/fs/emptyDir.js.map +1 -1
- package/lib/esm/fs/exists.d.ts +2 -2
- package/lib/esm/fs/exists.d.ts.map +1 -1
- package/lib/esm/fs/exists.js +3 -5
- package/lib/esm/fs/exists.js.map +1 -1
- package/lib/esm/fs/tempFolder.d.ts +1 -1
- package/lib/esm/fs/tempFolder.d.ts.map +1 -1
- package/lib/esm/fs/tempFolder.js +4 -4
- package/lib/esm/fs/tempFolder.js.map +1 -1
- package/lib/esm/fs/weiteChanged.js +2 -2
- package/lib/esm/fs/weiteChanged.js.map +1 -1
- package/lib/esm/log/terminal.d.ts +1 -1
- package/lib/esm/log/terminal.d.ts.map +1 -1
- package/lib/esm/log/terminal.js.map +1 -1
- package/lib/esm/path-resolve/findPackageRoot.d.ts.map +1 -1
- package/lib/esm/path-resolve/findPackageRoot.js +4 -6
- package/lib/esm/path-resolve/findPackageRoot.js.map +1 -1
- package/lib/esm/path-resolve/getAllUp.d.ts.map +1 -1
- package/lib/esm/path-resolve/getAllUp.js +2 -2
- package/lib/esm/path-resolve/getAllUp.js.map +1 -1
- package/lib/esm/path-resolve/lrelative.js +3 -3
- package/lib/esm/path-resolve/lrelative.js.map +1 -1
- package/lib/esm/path-resolve/nodeResolvePathArray.js +1 -1
- package/lib/esm/path-resolve/nodeResolvePathArray.js.map +1 -1
- package/lib/esm/path-resolve/resolvePath.d.ts +3 -9
- package/lib/esm/path-resolve/resolvePath.d.ts.map +1 -1
- package/lib/esm/path-resolve/resolvePath.js +3 -5
- package/lib/esm/path-resolve/resolvePath.js.map +1 -1
- package/lib/esm/stream/blackHoleStream.d.ts +1 -1
- package/lib/esm/stream/blackHoleStream.d.ts.map +1 -1
- package/lib/esm/stream/blackHoleStream.js +1 -1
- package/lib/esm/stream/blackHoleStream.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 +13 -15
- package/lib/esm/stream/collectingStream.js.map +1 -1
- package/lib/esm/stream/disposableStream.d.ts +2 -2
- package/lib/esm/stream/disposableStream.d.ts.map +1 -1
- package/lib/esm/stream/drainStream.d.ts.map +1 -1
- package/lib/esm/stream/drainStream.js.map +1 -1
- package/lib/esm/stream/loggerStream.d.ts +1 -1
- package/lib/esm/stream/loggerStream.d.ts.map +1 -1
- package/lib/esm/stream/loggerStream.js +5 -5
- package/lib/esm/stream/loggerStream.js.map +1 -1
- package/lib/esm/stream/streamPromise.d.ts.map +1 -1
- package/lib/esm/stream/streamPromise.js +8 -10
- package/lib/esm/stream/streamPromise.js.map +1 -1
- package/package.json +3 -3
- package/src/asyncLoad.ts +6 -3
- package/src/child_process/error.ts +8 -8
- package/src/child_process/execa.ts +5 -4
- package/src/child_process/lateError.ts +1 -1
- package/src/child_process/respawn.ts +8 -10
- package/src/cli-io/output.ts +1 -1
- package/src/crypto/md5.ts +1 -1
- package/src/crypto/sha256.ts +2 -5
- package/src/environment/findBinary.ts +2 -2
- package/src/environment/npmConfig.ts +3 -4
- package/src/environment/pathEnvironment.ts +1 -1
- package/src/error/cache.generated.json +3970 -4281
- package/src/error/nodejs-error-code.generator.ts +7 -7
- package/src/error/types.ts +1 -1
- package/src/events/dumpEventEmitter.ts +1 -1
- package/src/fs/commandExists.ts +2 -3
- package/src/fs/emptyDir.ts +2 -2
- package/src/fs/exists.ts +4 -5
- package/src/fs/tempFolder.ts +5 -5
- package/src/fs/weiteChanged.ts +2 -2
- package/src/log/terminal.ts +1 -1
- package/src/path-resolve/findPackageRoot.ts +4 -5
- package/src/path-resolve/getAllUp.ts +3 -3
- package/src/path-resolve/lrelative.ts +3 -3
- package/src/path-resolve/nodeResolvePathArray.ts +1 -1
- package/src/path-resolve/resolvePath.ts +6 -13
- package/src/stream/blackHoleStream.ts +1 -1
- package/src/stream/collectingStream.ts +13 -14
- package/src/stream/disposableStream.ts +2 -2
- package/src/stream/drainStream.ts +1 -6
- package/src/stream/loggerStream.ts +13 -7
- package/src/stream/streamPromise.ts +8 -11
- package/src/tsconfig.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as assert from 'assert';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import { readFile, writeFile } from 'fs/promises';
|
|
4
|
-
import { resolve } from 'path';
|
|
1
|
+
import * as assert from 'node:assert';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
5
|
import type API_JSON from './cache.generated.json';
|
|
6
6
|
|
|
7
7
|
const temp = resolve(__dirname, 'cache.generated.json');
|
|
@@ -30,9 +30,9 @@ export async function generate() {
|
|
|
30
30
|
return section.modules!;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
throw new Error(
|
|
33
|
+
throw new Error(`missing section: ${id}`);
|
|
34
34
|
}
|
|
35
|
-
content +=
|
|
35
|
+
content += 'export enum NodeError {\n';
|
|
36
36
|
for (const err of get_id('node.js_error_codes')) {
|
|
37
37
|
content += line(err.textRaw, err.desc, false);
|
|
38
38
|
}
|
|
@@ -42,7 +42,7 @@ export async function generate() {
|
|
|
42
42
|
}
|
|
43
43
|
content += '}\n\n';
|
|
44
44
|
|
|
45
|
-
content +=
|
|
45
|
+
content += 'export enum OpenSSLError {\n';
|
|
46
46
|
for (const section of get_id('openssl_error_codes')) {
|
|
47
47
|
for (const err of (section as any).modules) {
|
|
48
48
|
content += line(err.textRaw, err.desc, false);
|
package/src/error/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface OpenSSLException extends Error {
|
|
|
15
15
|
* ERR_MODULE_NOT_FOUND: import() not found
|
|
16
16
|
*/
|
|
17
17
|
export function isModuleResolutionError(
|
|
18
|
-
ex: unknown
|
|
18
|
+
ex: unknown
|
|
19
19
|
): ex is NodeException<NodeError.MODULE_NOT_FOUND | NodeError.ERR_MODULE_NOT_FOUND> {
|
|
20
20
|
return isNodeError(ex) && (ex.code === NodeError.MODULE_NOT_FOUND || ex.code === NodeError.ERR_MODULE_NOT_FOUND);
|
|
21
21
|
}
|
package/src/fs/commandExists.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isWindows } from '@idlebox/common';
|
|
2
|
-
import { access, constants, accessSync } from 'fs';
|
|
2
|
+
import { access, constants, accessSync } from 'node:fs';
|
|
3
3
|
import { PathEnvironment } from '../environment/pathEnvironment.js';
|
|
4
4
|
|
|
5
5
|
const windowsExecExtensions = ['.exe', '.bat', '.cmd', '.com', '.ps1'];
|
|
@@ -14,9 +14,8 @@ function exts(alterExt?: string[]) {
|
|
|
14
14
|
}
|
|
15
15
|
if (isWindows) {
|
|
16
16
|
return windowsExecExtensions;
|
|
17
|
-
} else {
|
|
18
|
-
return [''];
|
|
19
17
|
}
|
|
18
|
+
return [''];
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export async function commandInPath(cmd: string, alterExt?: string[]): Promise<string | undefined> {
|
package/src/fs/emptyDir.ts
CHANGED
package/src/fs/exists.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ObjectEncodingOptions } from 'fs';
|
|
2
|
-
import { access, readFile } from 'fs/promises';
|
|
1
|
+
import type { ObjectEncodingOptions } from 'node:fs';
|
|
2
|
+
import { access, readFile } from 'node:fs/promises';
|
|
3
3
|
import { isNotExistsError } from '../error/types.js';
|
|
4
|
-
export { existsSync } from 'fs';
|
|
4
|
+
export { existsSync } from 'node:fs';
|
|
5
5
|
|
|
6
6
|
export async function exists(path: string) {
|
|
7
7
|
try {
|
|
@@ -22,9 +22,8 @@ async function _readFileIfExists(file: string, encoding?: NodeJS.BufferEncoding
|
|
|
22
22
|
if (isNotExistsError(e)) {
|
|
23
23
|
if (typeof encoding === 'string' || typeof encoding?.encoding === 'string') {
|
|
24
24
|
return '';
|
|
25
|
-
} else {
|
|
26
|
-
return Buffer.allocUnsafe(0);
|
|
27
25
|
}
|
|
26
|
+
return Buffer.allocUnsafe(0);
|
|
28
27
|
}
|
|
29
28
|
throw e;
|
|
30
29
|
}
|
package/src/fs/tempFolder.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { mkdirSync, readdirSync, rmdirSync, statSync, unlinkSync } from 'fs';
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
import { IDisposable } from '@idlebox/common';
|
|
1
|
+
import { mkdirSync, readdirSync, rmdirSync, statSync, unlinkSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import type { IDisposable } from '@idlebox/common';
|
|
4
4
|
import { existsSync } from './exists.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const registered = false;
|
|
7
7
|
const tempFolders = new Set<string>();
|
|
8
8
|
|
|
9
9
|
export function createTempFolder(fullPath: string): IDisposable {
|
|
10
10
|
if (existsSync(fullPath)) {
|
|
11
|
-
throw new Error(
|
|
11
|
+
throw new Error(`temp folder already exists: ${fullPath}`);
|
|
12
12
|
}
|
|
13
13
|
if (!registered) {
|
|
14
14
|
process.on('beforeExit', onBeforeExit);
|
package/src/fs/weiteChanged.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { readFile as readFileAsync, readFileSync, writeFile as writeFileAsync, writeFileSync } from 'fs';
|
|
2
|
-
import { promisify } from 'util';
|
|
1
|
+
import { readFile as readFileAsync, readFileSync, writeFile as writeFileAsync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
3
|
import { exists, existsSync } from './exists.js';
|
|
4
4
|
|
|
5
5
|
const readFile = promisify(readFileAsync);
|
package/src/log/terminal.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import { dirname } from 'path';
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
3
|
import { findUpUntilSync } from './findUp.js';
|
|
4
4
|
|
|
5
5
|
export function findPackageRoot(packageName: string, require = createRequire(process.cwd())) {
|
|
6
6
|
try {
|
|
7
|
-
return dirname(require.resolve(packageName
|
|
7
|
+
return dirname(require.resolve(`${packageName}package.json`));
|
|
8
8
|
} catch (e: any) {
|
|
9
9
|
if (e.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
10
10
|
const main = require.resolve(packageName);
|
|
@@ -13,8 +13,7 @@ export function findPackageRoot(packageName: string, require = createRequire(pro
|
|
|
13
13
|
throw new Error(`Package ${packageName} do not have a package.json`);
|
|
14
14
|
}
|
|
15
15
|
return dirname(pkgJson);
|
|
16
|
-
} else {
|
|
17
|
-
throw e;
|
|
18
16
|
}
|
|
17
|
+
throw e;
|
|
19
18
|
}
|
|
20
19
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export function getAllPathUpToRoot(from: string, append
|
|
1
|
+
export function getAllPathUpToRoot(from: string, append = '') {
|
|
2
2
|
const parts = from.split(/\/\\/g).filter((e) => e);
|
|
3
3
|
const dirs: string[] = [];
|
|
4
4
|
let p = '';
|
|
5
5
|
|
|
6
6
|
if (append) {
|
|
7
|
-
append =
|
|
7
|
+
append = `/${append}`;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
for (const i of parts) {
|
|
11
|
-
p +=
|
|
11
|
+
p += `/${i}`;
|
|
12
12
|
dirs.push(p + append);
|
|
13
13
|
}
|
|
14
14
|
return dirs;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { isAbsolute } from 'path';
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
2
|
|
|
3
3
|
export function lrelative(from: string, to: string) {
|
|
4
4
|
if (!isAbsolute(from)) {
|
|
5
|
-
throw new Error(
|
|
5
|
+
throw new Error(`lrelative: from is not absolute: ${from}`);
|
|
6
6
|
}
|
|
7
7
|
if (!isAbsolute(to)) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error(`lrelative: to is not absolute: ${to}`);
|
|
9
9
|
}
|
|
10
10
|
const fa = from.split(/[\/\\]/g).filter((e) => e);
|
|
11
11
|
const ta = to.split(/[\/\\]/g).filter((e) => e);
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { isWindows } from '@idlebox/common';
|
|
2
|
-
import { tmpdir } from 'os';
|
|
3
|
-
import { normalize, relative, resolve } from 'path';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { normalize, relative, resolve } from 'node:path';
|
|
4
4
|
|
|
5
5
|
const winSlash = /\\/g;
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
(...pathSegments: string[]): string;
|
|
9
|
-
}
|
|
7
|
+
export type ResolvePathFunction = (...pathSegments: string[]) => string;
|
|
10
8
|
|
|
11
|
-
export
|
|
12
|
-
(from: string, to: string): string;
|
|
13
|
-
}
|
|
9
|
+
export type JoinPathFunction = (from: string, to: string) => string;
|
|
14
10
|
|
|
15
11
|
export const resolvePath: ResolvePathFunction = isWindows ? resolveWindowsPath : resolve;
|
|
16
12
|
|
|
@@ -18,9 +14,7 @@ function resolveWindowsPath(...pathSegments: string[]): string {
|
|
|
18
14
|
return resolve(...pathSegments).replace(winSlash, '/');
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
export
|
|
22
|
-
(path: string): string;
|
|
23
|
-
}
|
|
17
|
+
export type NormalizePathFunction = (path: string) => string;
|
|
24
18
|
|
|
25
19
|
export const normalizePath: NormalizePathFunction = isWindows ? normalizeWindowsPath : normalize;
|
|
26
20
|
|
|
@@ -31,9 +25,8 @@ function normalizeWindowsPath(path: string): string {
|
|
|
31
25
|
export function osTempDir(name?: string) {
|
|
32
26
|
if (name) {
|
|
33
27
|
return resolvePath(tmpdir(), name);
|
|
34
|
-
} else {
|
|
35
|
-
return resolvePath(tmpdir());
|
|
36
28
|
}
|
|
29
|
+
return resolvePath(tmpdir());
|
|
37
30
|
}
|
|
38
31
|
|
|
39
32
|
function relativeWindowsPath(from: string, to: string) {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Writable } from
|
|
2
|
-
import { streamPromise } from
|
|
1
|
+
import { Writable } from 'node: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>;
|
|
6
6
|
export function streamToBuffer(stream: NodeJS.ReadableStream, raw: boolean): Promise<string | Buffer> {
|
|
7
7
|
if (raw) {
|
|
8
8
|
return new RawCollectingStream(stream).promise();
|
|
9
|
-
} else {
|
|
10
|
-
return new CollectingStream(stream).promise();
|
|
11
9
|
}
|
|
10
|
+
return new CollectingStream(stream).promise();
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export class RawCollectingStream extends Writable {
|
|
@@ -19,8 +18,8 @@ export class RawCollectingStream extends Writable {
|
|
|
19
18
|
super();
|
|
20
19
|
if (sourceStream) {
|
|
21
20
|
sourceStream.pipe(this);
|
|
22
|
-
sourceStream.on(
|
|
23
|
-
this.emit(
|
|
21
|
+
sourceStream.on('error', (e) => {
|
|
22
|
+
this.emit('error', e);
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
25
|
}
|
|
@@ -39,31 +38,31 @@ export class RawCollectingStream extends Writable {
|
|
|
39
38
|
? this._promise
|
|
40
39
|
: (this._promise = streamPromise(this).then(() => {
|
|
41
40
|
const buffer = this.buffer!;
|
|
42
|
-
|
|
41
|
+
this.buffer = undefined;
|
|
43
42
|
return buffer;
|
|
44
43
|
}));
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
export class CollectingStream extends Writable {
|
|
49
|
-
private buffer? =
|
|
48
|
+
private buffer? = '';
|
|
50
49
|
private _promise?: Promise<string>;
|
|
51
50
|
|
|
52
51
|
constructor(sourceStream?: NodeJS.ReadableStream) {
|
|
53
52
|
super();
|
|
54
53
|
if (sourceStream) {
|
|
55
54
|
sourceStream.pipe(this);
|
|
56
|
-
sourceStream.on(
|
|
57
|
-
this.emit(
|
|
55
|
+
sourceStream.on('error', (e) => {
|
|
56
|
+
this.emit('error', e);
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
override _write(chunk: Buffer, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
63
62
|
if (!encoding) {
|
|
64
|
-
encoding =
|
|
65
|
-
} else if ((encoding as any) ===
|
|
66
|
-
encoding =
|
|
63
|
+
encoding = 'utf8';
|
|
64
|
+
} else if ((encoding as any) === 'buffer' || encoding === 'binary') {
|
|
65
|
+
encoding = 'utf8';
|
|
67
66
|
}
|
|
68
67
|
this.buffer += chunk.toString(encoding);
|
|
69
68
|
callback();
|
|
@@ -78,7 +77,7 @@ export class CollectingStream extends Writable {
|
|
|
78
77
|
? this._promise
|
|
79
78
|
: (this._promise = streamPromise(this).then(() => {
|
|
80
79
|
const buffer = this.buffer!;
|
|
81
|
-
|
|
80
|
+
this.buffer = undefined;
|
|
82
81
|
return buffer;
|
|
83
82
|
}));
|
|
84
83
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Readable, Writable } from 'stream';
|
|
2
|
-
import { IDisposable } from '@idlebox/common';
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
2
|
+
import type { IDisposable } from '@idlebox/common';
|
|
3
3
|
|
|
4
4
|
export function disposableStream<T extends Writable | Readable>(stream: T): T & IDisposable {
|
|
5
5
|
if ((stream as any).dispose) {
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
export function drainStream(
|
|
2
|
-
stream: NodeJS.ReadableStream,
|
|
3
|
-
size: number,
|
|
4
|
-
start: number = 0,
|
|
5
|
-
extra: number = 0
|
|
6
|
-
): Promise<Buffer> {
|
|
1
|
+
export function drainStream(stream: NodeJS.ReadableStream, size: number, start = 0, extra = 0): Promise<Buffer> {
|
|
7
2
|
// buff will alloc as start+size+extra, but return will always start+RealStreamSize+extra
|
|
8
3
|
const buff = Buffer.allocUnsafe(start + size + extra);
|
|
9
4
|
let cur = start;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { Transform } from 'stream';
|
|
1
|
+
import { Transform } from 'node:stream';
|
|
2
2
|
|
|
3
3
|
export type LogFunction = (message: string, ...args: any[]) => void;
|
|
4
4
|
|
|
5
5
|
export class LoggerStream extends Transform {
|
|
6
6
|
private readonly prefix: string;
|
|
7
7
|
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(
|
|
9
|
+
private readonly logFn: LogFunction,
|
|
10
|
+
prefix?: string
|
|
11
|
+
) {
|
|
9
12
|
super();
|
|
10
|
-
this.prefix = prefix ? prefix
|
|
13
|
+
this.prefix = prefix ? `${prefix} %s` : '%s';
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
override _transform(chunk: Buffer, encoding: BufferEncoding, callback: Function): void {
|
|
@@ -28,15 +31,18 @@ export class LoggerStream extends Transform {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
function pad2(s: string) {
|
|
31
|
-
return s.length === 1 ?
|
|
34
|
+
return s.length === 1 ? `0${s}` : s;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
export class HexDumpLoggerStream extends Transform {
|
|
35
38
|
private readonly prefix: string;
|
|
36
39
|
|
|
37
|
-
constructor(
|
|
40
|
+
constructor(
|
|
41
|
+
private readonly logFn: LogFunction,
|
|
42
|
+
prefix?: string
|
|
43
|
+
) {
|
|
38
44
|
super();
|
|
39
|
-
this.prefix = prefix ? prefix
|
|
45
|
+
this.prefix = prefix ? `${prefix} ` : '';
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
override _transform(chunk: Buffer, encoding: BufferEncoding, callback: Function): void {
|
|
@@ -52,7 +58,7 @@ export class HexDumpLoggerStream extends Transform {
|
|
|
52
58
|
.join(' ');
|
|
53
59
|
itr += 16;
|
|
54
60
|
|
|
55
|
-
this.logFn(this.prefix + l
|
|
61
|
+
this.logFn(`${this.prefix + l} ${r}`);
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
this.push(chunk, encoding);
|
|
@@ -5,20 +5,17 @@
|
|
|
5
5
|
export function streamPromise(stream: NodeJS.ReadableStream | NodeJS.WritableStream): Promise<void> {
|
|
6
6
|
if (streamHasEnd(stream)) {
|
|
7
7
|
return Promise.resolve();
|
|
8
|
-
} else {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
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);
|
|
15
|
-
});
|
|
16
8
|
}
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
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);
|
|
15
|
+
});
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export function streamHasEnd(S: NodeJS.ReadableStream | NodeJS.WritableStream) {
|
|
20
19
|
const stream = S as any;
|
|
21
|
-
return
|
|
22
|
-
(stream._writableState && stream._writableState.ended) || (stream._readableState && stream._readableState.ended)
|
|
23
|
-
);
|
|
20
|
+
return stream._writableState?.ended || stream._readableState?.ended;
|
|
24
21
|
}
|
package/src/tsconfig.json
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"typeRoots": ["../node_modules/@types", "../node_modules"],
|
|
5
5
|
"outDir": "../lib/esm",
|
|
6
6
|
"rootDir": "./",
|
|
7
|
-
"types": ["node"]
|
|
7
|
+
"types": ["node"],
|
|
8
8
|
},
|
|
9
9
|
// "files": ["preload.ts"],
|
|
10
10
|
// "include": ["**/*.ts"],
|
|
11
|
-
"exclude": ["**/*.generator.ts"]
|
|
11
|
+
"exclude": ["**/*.generator.ts"],
|
|
12
12
|
}
|