@tstdl/base 0.92.41 → 0.92.42

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/file/mime-type.js CHANGED
@@ -10,9 +10,12 @@ export function getMimeTypeExtensions(mimeType) {
10
10
  return mimeTypesMap.get(mimeType) ?? [];
11
11
  }
12
12
  async function spawnFileCommand(args, file) {
13
- const process = await spawnCommand('file', args, { stdinPipeOptions: { preventCancel: true } });
13
+ const process = await spawnCommand('file', args);
14
14
  if (isDefined(file)) {
15
- await process.write(file);
15
+ try {
16
+ await process.write(file);
17
+ }
18
+ catch { /* ignore as file command closes stdin early */ }
16
19
  }
17
20
  const { code } = await process.wait();
18
21
  if (code != 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.41",
3
+ "version": "0.92.42",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -2,7 +2,7 @@ import type { ChildProcessWithoutNullStreams } from 'node:child_process';
2
2
  export type SpawnCommandResult = TransformStream<Uint8Array, Uint8Array> & {
3
3
  process: ChildProcessWithoutNullStreams;
4
4
  stderr: ReadableStream<Uint8Array>;
5
- write(chunk: ReadableStream<Uint8Array> | Uint8Array | string): Promise<void>;
5
+ write(chunk: ReadableStream<Uint8Array> | Uint8Array | string, options?: StreamPipeOptions): Promise<void>;
6
6
  readOutputBytes(): Promise<Uint8Array>;
7
7
  readOutput(): Promise<string>;
8
8
  readErrorBytes(): Promise<Uint8Array>;
@@ -12,6 +12,4 @@ export type SpawnCommandResult = TransformStream<Uint8Array, Uint8Array> & {
12
12
  signal: string | null;
13
13
  }>;
14
14
  };
15
- export declare function spawnCommand(command: string, args?: string[], options?: {
16
- stdinPipeOptions?: StreamPipeOptions;
17
- }): Promise<SpawnCommandResult>;
15
+ export declare function spawnCommand(command: string, args?: string[]): Promise<SpawnCommandResult>;
package/process/spawn.js CHANGED
@@ -3,7 +3,7 @@ import { decodeTextStream, encodeUtf8Stream } from '../utils/encoding.js';
3
3
  import { readBinaryStream, readTextStream } from '../utils/stream/stream-reader.js';
4
4
  import { toReadableStream } from '../utils/stream/to-readable-stream.js';
5
5
  import { isReadableStream, isString, isUint8Array } from '../utils/type-guards.js';
6
- export async function spawnCommand(command, args, options) {
6
+ export async function spawnCommand(command, args) {
7
7
  const { spawn } = await dynamicImport('node:child_process');
8
8
  const { Readable, Writable } = await dynamicImport('node:stream');
9
9
  const process = spawn(command, args, { stdio: 'pipe' });
@@ -14,15 +14,15 @@ export async function spawnCommand(command, args, options) {
14
14
  const readable = Readable.toWeb(process.stdout);
15
15
  const writable = Writable.toWeb(process.stdin);
16
16
  const stderr = Readable.toWeb(process.stderr);
17
- async function write(data) {
17
+ async function write(data, options) {
18
18
  if (isReadableStream(data)) {
19
- await data.pipeTo(writable, options?.stdinPipeOptions);
19
+ await data.pipeTo(writable, options);
20
20
  }
21
21
  else if (isUint8Array(data)) {
22
- await toReadableStream(data).pipeTo(writable, options?.stdinPipeOptions);
22
+ await toReadableStream(data).pipeTo(writable, options);
23
23
  }
24
24
  else if (isString(data)) {
25
- await toReadableStream(data).pipeThrough(encodeUtf8Stream()).pipeTo(writable, options?.stdinPipeOptions);
25
+ await toReadableStream(data).pipeThrough(encodeUtf8Stream()).pipeTo(writable, options);
26
26
  }
27
27
  }
28
28
  async function readOutputBytes() {
@@ -31,10 +31,10 @@ export async function spawnCommand(command, args, options) {
31
31
  async function readOutput() {
32
32
  return readTextStream(readable.pipeThrough(decodeTextStream()));
33
33
  }
34
- async function readErrBytes() {
34
+ async function readErrorBytes() {
35
35
  return readBinaryStream(stderr);
36
36
  }
37
- async function readErr() {
37
+ async function readError() {
38
38
  return readTextStream(stderr.pipeThrough(decodeTextStream()));
39
39
  }
40
40
  const signalPromise = new Promise((resolve) => process.on('close', (code, signal) => resolve({ code, signal })));
@@ -46,8 +46,8 @@ export async function spawnCommand(command, args, options) {
46
46
  write,
47
47
  readOutputBytes,
48
48
  readOutput,
49
- readErrorBytes: readErrBytes,
50
- readError: readErr,
49
+ readErrorBytes,
50
+ readError,
51
51
  async wait() {
52
52
  return signalPromise;
53
53
  }