fix(mobile): resolve user avatars, chat alignment, timestamp formatting, and payslips API
This commit is contained in:
21
node_modules/tinyexec/LICENSE
generated
vendored
Normal file
21
node_modules/tinyexec/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Tinylibs
|
||||
|
||||
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.
|
||||
323
node_modules/tinyexec/README.md
generated
vendored
Normal file
323
node_modules/tinyexec/README.md
generated
vendored
Normal file
@@ -0,0 +1,323 @@
|
||||
# tinyexec 📟
|
||||
|
||||
> A minimal package for executing commands
|
||||
|
||||
This package was created to provide a minimal way of interacting with child
|
||||
processes without having to manually deal with streams, piping, etc.
|
||||
|
||||
## Installing
|
||||
|
||||
```sh
|
||||
$ npm i -S tinyexec
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
A process can be spawned and awaited like so:
|
||||
|
||||
```ts
|
||||
import {x} from 'tinyexec';
|
||||
|
||||
const result = await x('ls', ['-l']);
|
||||
|
||||
// result.stdout - the stdout as a string
|
||||
// result.stderr - the stderr as a string
|
||||
// result.exitCode - the process exit code as a number
|
||||
```
|
||||
|
||||
By default, tinyexec does not throw on non‑zero exit codes. Check `result.exitCode` or pass `{throwOnError: true}`.
|
||||
|
||||
Output is returned exactly as produced; trailing newlines are not trimmed. If you need trimming, do it explicitly:
|
||||
|
||||
```ts
|
||||
const clean = result.stdout.replace(/\r?\n$/, '');
|
||||
```
|
||||
|
||||
You may also iterate over the lines of output via an async loop:
|
||||
|
||||
```ts
|
||||
import {x} from 'tinyexec';
|
||||
|
||||
const proc = x('ls', ['-l']);
|
||||
|
||||
for await (const line of proc) {
|
||||
// line will be from stderr/stdout in the order you'd see it in a term
|
||||
}
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
Options can be passed to have finer control over spawning of the process:
|
||||
|
||||
```ts
|
||||
await x('ls', [], {
|
||||
timeout: 1000
|
||||
});
|
||||
```
|
||||
|
||||
The options object can have the following properties:
|
||||
|
||||
- `signal` - an `AbortSignal` to allow aborting of the execution
|
||||
- `timeout` - time in milliseconds at which the process will be forcibly killed
|
||||
- `persist` - if `true`, the process will continue after the host exits
|
||||
- `stdin` - `string` or another `Result` that will be used as the input to the process
|
||||
- `nodeOptions` - any valid options to node's underlying `spawn` function
|
||||
- `throwOnError` - if true, non-zero exit codes will throw an error
|
||||
- `nodePath` - if `false`, `node_modules/.bin` directories and the current node executable's directory will not be prepended to `PATH` (defaults to `true`)
|
||||
|
||||
### Passing a string to stdin
|
||||
|
||||
You can pass a string to `stdin`, which is useful for whitespace-sensitive values and for secrets that shouldn’t be exposed in shell history:
|
||||
|
||||
```ts
|
||||
const result = await x('gh', ['auth', 'login', '--with-token'], {
|
||||
stdin: process.env.GITHUB_TOKEN
|
||||
});
|
||||
|
||||
console.log(result.exitCode);
|
||||
```
|
||||
|
||||
### Piping to another process
|
||||
|
||||
You can pipe a process to another via the `pipe` method:
|
||||
|
||||
```ts
|
||||
const proc1 = x('ls', ['-l']);
|
||||
const proc2 = proc1.pipe('grep', ['.js']);
|
||||
const result = await proc2;
|
||||
|
||||
console.log(result.stdout);
|
||||
```
|
||||
|
||||
`pipe` takes the same options as a regular execution. For example, you can
|
||||
pass a timeout to the pipe call:
|
||||
|
||||
```ts
|
||||
proc1.pipe('grep', ['.js'], {
|
||||
timeout: 2000
|
||||
});
|
||||
```
|
||||
|
||||
### Killing a process
|
||||
|
||||
You can kill the process via the `kill` method:
|
||||
|
||||
```ts
|
||||
const proc = x('ls');
|
||||
|
||||
proc.kill();
|
||||
|
||||
// or with a signal
|
||||
proc.kill('SIGHUP');
|
||||
```
|
||||
|
||||
### Node modules/binaries
|
||||
|
||||
By default, node's available binaries from `node_modules` will be accessible
|
||||
in your command.
|
||||
|
||||
For example, in a repo which has `eslint` installed:
|
||||
|
||||
```ts
|
||||
await x('eslint', ['.']);
|
||||
```
|
||||
|
||||
In this example, `eslint` will come from the locally installed `node_modules`.
|
||||
|
||||
If you'd rather not have `node_modules/.bin` (or the directory of the current
|
||||
`node` executable) prepended to `PATH`, pass `nodePath: false`:
|
||||
|
||||
```ts
|
||||
await x('eslint', ['.'], {nodePath: false});
|
||||
```
|
||||
|
||||
### Using an abort signal
|
||||
|
||||
An abort signal can be passed to a process in order to abort it at a later
|
||||
time. This will result in the process being killed and `aborted` being set
|
||||
to `true`.
|
||||
|
||||
```ts
|
||||
const aborter = new AbortController();
|
||||
const proc = x('node', ['./foo.mjs'], {
|
||||
signal: aborter.signal
|
||||
});
|
||||
|
||||
// elsewhere...
|
||||
aborter.abort();
|
||||
|
||||
await proc;
|
||||
|
||||
proc.aborted; // true
|
||||
proc.killed; // true
|
||||
```
|
||||
|
||||
### Using with command strings
|
||||
|
||||
If you need to continue supporting commands as strings (e.g. "command arg0 arg1"),
|
||||
you can use [args-tokenizer](https://github.com/TrySound/args-tokenizer),
|
||||
a lightweight library for parsing shell command strings into an array.
|
||||
|
||||
```ts
|
||||
import {x} from 'tinyexec';
|
||||
import {tokenizeArgs} from 'args-tokenizer';
|
||||
|
||||
const commandString = 'echo "Hello, World!"';
|
||||
const [command, ...args] = tokenizeArgs(commandString);
|
||||
const result = await x(command, args);
|
||||
|
||||
result.stdout; // Hello, World!
|
||||
```
|
||||
|
||||
### Synchronous
|
||||
|
||||
You can use `xSync` for synchronous (blocking) execution:
|
||||
|
||||
```ts
|
||||
import {xSync} from 'tinyexec';
|
||||
|
||||
const result = xSync('ls', ['-l']);
|
||||
|
||||
// result.stdout - the stdout as a string
|
||||
// result.stderr - the stderr as a string
|
||||
// result.exitCode - the process exit code as a number
|
||||
```
|
||||
|
||||
Like the async API, you can iterate over lines:
|
||||
|
||||
```ts
|
||||
const result = xSync('ls', ['-l']);
|
||||
|
||||
for (const line of result) {
|
||||
// line will be from stdout then stderr
|
||||
}
|
||||
```
|
||||
|
||||
Since the synchronous API blocks the event loop, there are some features that are supported in the async API that the sync API does not support:
|
||||
|
||||
- `signal`
|
||||
- `persist`
|
||||
- `kill()` method
|
||||
- `stdin` piping
|
||||
- `pipe()` method
|
||||
|
||||
Other options like `timeout`, `throwOnError`, and `nodeOptions` work the same way.
|
||||
|
||||
## API
|
||||
|
||||
Calling `x(command[, args])` returns an awaitable `Result` which has the
|
||||
following API methods and properties available:
|
||||
|
||||
### `pipe(command[, args[, options]])`
|
||||
|
||||
Pipes the current command to another. For example:
|
||||
|
||||
```ts
|
||||
x('ls', ['-l'])
|
||||
.pipe('grep', ['js']);
|
||||
```
|
||||
|
||||
The parameters are as follows:
|
||||
|
||||
- `command` - the command to execute (_without any arguments_)
|
||||
- `args` - an array of arguments
|
||||
- `options` - options object
|
||||
|
||||
### `process`
|
||||
|
||||
The underlying Node.js `ChildProcess`. tinyexec keeps the surface minimal and does not re‑expose every child_process method/event. Use `proc.process` for advanced access (streams, events, etc.).
|
||||
|
||||
```ts
|
||||
const proc = x('node', ['./foo.mjs']);
|
||||
|
||||
proc.process?.stdout?.on('data', (chunk) => {
|
||||
// ...
|
||||
});
|
||||
proc.process?.once('close', (code) => {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
### `kill([signal])`
|
||||
|
||||
Kills the current process with the specified signal. By default, this will
|
||||
use the `SIGTERM` signal.
|
||||
|
||||
For example:
|
||||
|
||||
```ts
|
||||
const proc = x('ls');
|
||||
|
||||
proc.kill();
|
||||
```
|
||||
|
||||
### `pid`
|
||||
|
||||
The current process ID. For example:
|
||||
|
||||
```ts
|
||||
const proc = x('ls');
|
||||
|
||||
proc.pid; // number
|
||||
```
|
||||
|
||||
### `aborted`
|
||||
|
||||
Whether the process has been aborted or not (via the `signal` originally
|
||||
passed in the options object).
|
||||
|
||||
For example:
|
||||
|
||||
```ts
|
||||
const proc = x('ls');
|
||||
|
||||
proc.aborted; // bool
|
||||
```
|
||||
|
||||
### `killed`
|
||||
|
||||
Whether the process has been killed or not (e.g. via `kill()` or an abort
|
||||
signal).
|
||||
|
||||
For example:
|
||||
|
||||
```ts
|
||||
const proc = x('ls');
|
||||
|
||||
proc.killed; // bool
|
||||
```
|
||||
|
||||
### `exitCode`
|
||||
|
||||
The exit code received when the process completed execution.
|
||||
|
||||
For example:
|
||||
|
||||
```ts
|
||||
const proc = x('ls');
|
||||
|
||||
proc.exitCode; // number (e.g. 1)
|
||||
```
|
||||
|
||||
## Comparison with other libraries
|
||||
|
||||
`tinyexec` aims to provide a lightweight layer on top of Node's own
|
||||
`child_process` API.
|
||||
|
||||
Some clear benefits compared to other libraries are that `tinyexec` will be much lighter, have a much
|
||||
smaller footprint and will have a less abstract interface (less "magic"). It
|
||||
will also have equal security and cross-platform support to popular
|
||||
alternatives.
|
||||
|
||||
There are various features other libraries include which we are unlikely
|
||||
to ever implement, as they would prevent us from providing a lightweight layer.
|
||||
|
||||
For example, if you'd like write scripts rather than individual commands, and
|
||||
prefer to use templating, we'd definitely recommend
|
||||
[zx](https://github.com/google/zx). zx is a much higher level library which
|
||||
does some of the same work `tinyexec` does but behind a template string
|
||||
interface.
|
||||
|
||||
Similarly, libraries like `execa` will provide helpers for various things
|
||||
like passing files as input to processes. We opt not to support features like
|
||||
this since many of them are easy to do yourself (using Node's own APIs).
|
||||
99
node_modules/tinyexec/dist/main.d.mts
generated
vendored
Normal file
99
node_modules/tinyexec/dist/main.d.mts
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
import { ChildProcess, SpawnOptions, SpawnSyncOptions } from "node:child_process";
|
||||
import { Readable } from "node:stream";
|
||||
//#region src/normalize.d.ts
|
||||
interface NormalizedSpawnCommand {
|
||||
command: string;
|
||||
args: readonly string[];
|
||||
options: SpawnOptions;
|
||||
}
|
||||
/**
|
||||
* Normalizes the command and arguments to work cross-platform.
|
||||
* On Windows, this basically handles things like shebangs, calling
|
||||
* `node_modules/.bin` commands, and escaping meta characters.
|
||||
* On other platforms, it just returns the command and arguments as-is.
|
||||
*/
|
||||
declare function normalizeSpawnCommand(command: string, args?: readonly string[], options?: SpawnOptions): NormalizedSpawnCommand;
|
||||
//#endregion
|
||||
//#region src/non-zero-exit-error.d.ts
|
||||
declare class NonZeroExitError extends Error {
|
||||
readonly result: CommonOutputApi;
|
||||
readonly output?: Output | undefined;
|
||||
readonly exitCode: number;
|
||||
get signalCode(): string | null;
|
||||
constructor(result: CommonOutputApi, output?: Output | undefined, command?: string, args?: readonly string[]);
|
||||
}
|
||||
//#endregion
|
||||
//#region src/main.d.ts
|
||||
interface Output {
|
||||
stderr: string;
|
||||
stdout: string;
|
||||
exitCode: number | undefined;
|
||||
}
|
||||
interface PipeOptions extends Options {}
|
||||
type KillSignal = Parameters<ChildProcess['kill']>[0];
|
||||
interface CommonOutputApi {
|
||||
get pid(): number | undefined;
|
||||
get killed(): boolean;
|
||||
get exitCode(): number | undefined;
|
||||
get signalCode(): string | null;
|
||||
}
|
||||
interface OutputApi extends AsyncIterable<string>, CommonOutputApi {
|
||||
process: ChildProcess | undefined;
|
||||
get aborted(): boolean;
|
||||
pipe(command: string, args?: readonly string[], options?: Partial<PipeOptions>): Result;
|
||||
kill(signal?: KillSignal): boolean;
|
||||
}
|
||||
interface OutputApiSync extends Iterable<string>, CommonOutputApi {}
|
||||
type Result = PromiseLike<Output> & OutputApi;
|
||||
type SyncResult = Output & OutputApiSync;
|
||||
interface CommonOptions {
|
||||
timeout: number;
|
||||
throwOnError: boolean;
|
||||
nodePath: boolean;
|
||||
}
|
||||
interface Options extends CommonOptions {
|
||||
signal: AbortSignal;
|
||||
nodeOptions: SpawnOptions;
|
||||
persist: boolean;
|
||||
stdin: Result | ExecProcess | string;
|
||||
}
|
||||
interface SyncOptions extends CommonOptions {
|
||||
nodeOptions: SpawnSyncOptions;
|
||||
}
|
||||
interface TinyExec {
|
||||
(command: string, args?: readonly string[], options?: Partial<Options>): Result;
|
||||
}
|
||||
declare class ExecProcess implements Result {
|
||||
protected _process?: ChildProcess;
|
||||
protected _aborted: boolean;
|
||||
protected _options: Partial<Options>;
|
||||
protected _command: string;
|
||||
protected _args: readonly string[];
|
||||
protected _resolveClose?: () => void;
|
||||
protected _processClosed: Promise<void>;
|
||||
protected _thrownError?: Error;
|
||||
get process(): ChildProcess | undefined;
|
||||
get pid(): number | undefined;
|
||||
get exitCode(): number | undefined;
|
||||
get signalCode(): string | null;
|
||||
constructor(command: string, args?: readonly string[], options?: Partial<Options>);
|
||||
kill(signal?: KillSignal): boolean;
|
||||
get aborted(): boolean;
|
||||
get killed(): boolean;
|
||||
pipe(command: string, args?: readonly string[], options?: Partial<PipeOptions>): Result;
|
||||
[Symbol.asyncIterator](): AsyncIterator<string>;
|
||||
protected _waitForOutput(): Promise<Output>;
|
||||
then<TResult1 = Output, TResult2 = never>(onfulfilled?: ((value: Output) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
||||
protected _streamOut?: Readable;
|
||||
protected _streamErr?: Readable;
|
||||
spawn(): void;
|
||||
protected _resetState(): void;
|
||||
protected _onError: (err: Error) => void;
|
||||
protected _onClose: () => void;
|
||||
}
|
||||
declare function xSync(command: string, args?: readonly string[], options?: Partial<SyncOptions>): SyncResult;
|
||||
declare const x: TinyExec;
|
||||
declare const exec: TinyExec;
|
||||
declare const execSync: typeof xSync;
|
||||
//#endregion
|
||||
export { CommonOptions, CommonOutputApi, ExecProcess, KillSignal, NonZeroExitError, Options, Output, OutputApi, OutputApiSync, PipeOptions, Result, SyncOptions, SyncResult, TinyExec, exec, execSync, normalizeSpawnCommand, x, xSync };
|
||||
410
node_modules/tinyexec/dist/main.mjs
generated
vendored
Normal file
410
node_modules/tinyexec/dist/main.mjs
generated
vendored
Normal file
@@ -0,0 +1,410 @@
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { cwd } from "node:process";
|
||||
import { basename, delimiter, dirname, normalize, resolve } from "node:path";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { PassThrough } from "node:stream";
|
||||
import readline from "node:readline";
|
||||
import { closeSync, openSync, readSync, statSync } from "node:fs";
|
||||
//#region src/env.ts
|
||||
const isPathLikePattern = /^path$/i;
|
||||
const defaultEnvPathInfo = {
|
||||
key: "PATH",
|
||||
value: ""
|
||||
};
|
||||
function getPathFromEnv(env) {
|
||||
for (const key in env) {
|
||||
if (!Object.prototype.hasOwnProperty.call(env, key) || !isPathLikePattern.test(key)) continue;
|
||||
const value = env[key];
|
||||
if (!value) return defaultEnvPathInfo;
|
||||
return {
|
||||
key,
|
||||
value
|
||||
};
|
||||
}
|
||||
return defaultEnvPathInfo;
|
||||
}
|
||||
function addNodeBinToPath(cwd, path) {
|
||||
const parts = path.value.split(delimiter);
|
||||
const nodeBinPaths = [];
|
||||
let currentPath = cwd;
|
||||
let lastPath;
|
||||
do {
|
||||
nodeBinPaths.push(resolve(currentPath, "node_modules", ".bin"));
|
||||
lastPath = currentPath;
|
||||
currentPath = dirname(currentPath);
|
||||
} while (currentPath !== lastPath);
|
||||
nodeBinPaths.push(dirname(process.execPath));
|
||||
const newPath = nodeBinPaths.concat(parts).join(delimiter);
|
||||
return {
|
||||
key: path.key,
|
||||
value: newPath
|
||||
};
|
||||
}
|
||||
function computeEnv(cwd, env, nodePath = true) {
|
||||
const envWithDefault = {
|
||||
...process.env,
|
||||
...env
|
||||
};
|
||||
if (!nodePath) return envWithDefault;
|
||||
const envPathInfo = addNodeBinToPath(cwd, getPathFromEnv(envWithDefault));
|
||||
envWithDefault[envPathInfo.key] = envPathInfo.value;
|
||||
return envWithDefault;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/stream.ts
|
||||
const combineStreams = (streams) => {
|
||||
let streamCount = streams.length;
|
||||
const combined = new PassThrough();
|
||||
const maybeEmitEnd = () => {
|
||||
if (--streamCount === 0) combined.end();
|
||||
};
|
||||
for (const stream of streams) pipeline(stream, combined, { end: false }).then(maybeEmitEnd).catch(maybeEmitEnd);
|
||||
return combined;
|
||||
};
|
||||
//#endregion
|
||||
//#region src/normalize.ts
|
||||
const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
|
||||
const shebangRegExp = /^#!\s*(.+)/;
|
||||
const isWindowsExecutableRegExp = /\.(?:com|exe)$/i;
|
||||
const isNodeModulesCmdRegExp = /node_modules[\\/]\.bin[\\/][^\\/]+\.cmd$/i;
|
||||
const isWindows = process.platform === "win32";
|
||||
const defaultPathExt = [
|
||||
".EXE",
|
||||
".CMD",
|
||||
".BAT",
|
||||
".COM"
|
||||
];
|
||||
const noPathExt = [""];
|
||||
/**
|
||||
* Normalizes the command and arguments to work cross-platform.
|
||||
* On Windows, this basically handles things like shebangs, calling
|
||||
* `node_modules/.bin` commands, and escaping meta characters.
|
||||
* On other platforms, it just returns the command and arguments as-is.
|
||||
*/
|
||||
function normalizeSpawnCommand(command, args = [], options = {}) {
|
||||
if (options.shell === true || !isWindows) return {
|
||||
command,
|
||||
args,
|
||||
options
|
||||
};
|
||||
let file = resolveCommand(command, options);
|
||||
let shebang = null;
|
||||
if (file !== null) {
|
||||
const size = 150;
|
||||
const buffer = Buffer.alloc(size);
|
||||
let fd = null;
|
||||
try {
|
||||
fd = openSync(file, "r");
|
||||
readSync(fd, buffer, 0, size, 0);
|
||||
} catch {} finally {
|
||||
if (fd !== null) closeSync(fd);
|
||||
}
|
||||
const match = buffer.toString().match(shebangRegExp);
|
||||
if (match !== null) {
|
||||
const line = match[1].trim();
|
||||
const separatorIndex = line.indexOf(" ");
|
||||
const path = separatorIndex !== -1 ? line.slice(0, separatorIndex) : line;
|
||||
const argument = separatorIndex !== -1 ? line.slice(separatorIndex + 1) : "";
|
||||
const binary = basename(path);
|
||||
shebang = binary === "env" ? argument || null : binary;
|
||||
}
|
||||
}
|
||||
if (shebang !== null && file !== null) {
|
||||
args = [file, ...args];
|
||||
command = shebang;
|
||||
file = resolveCommand(command, options);
|
||||
}
|
||||
if (file === null || !isWindowsExecutableRegExp.test(file)) {
|
||||
const needsDoubleEscapeMetaChars = file !== null && isNodeModulesCmdRegExp.test(file);
|
||||
command = normalize(command);
|
||||
command = command.replace(metaCharsRegExp, "^$1");
|
||||
args = args.map((arg) => {
|
||||
arg = arg.replace(/(?=(\\+?)?)\1"/g, "$1$1\\\"");
|
||||
arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
||||
arg = `"${arg}"`;
|
||||
arg = arg.replace(metaCharsRegExp, "^$1");
|
||||
if (needsDoubleEscapeMetaChars) arg = arg.replace(metaCharsRegExp, "^$1");
|
||||
return arg;
|
||||
});
|
||||
args = [
|
||||
"/d",
|
||||
"/s",
|
||||
"/c",
|
||||
`"${[command, ...args].join(" ")}"`
|
||||
];
|
||||
command = options.env?.comspec ?? "cmd.exe";
|
||||
options = {
|
||||
...options,
|
||||
windowsVerbatimArguments: true
|
||||
};
|
||||
}
|
||||
return {
|
||||
command,
|
||||
args,
|
||||
options
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Resolves the command to an absolute path if possible.
|
||||
* Handles things like traversing PATH and adding extensions from PATHEXT
|
||||
*/
|
||||
function resolveCommand(command, options) {
|
||||
const cwd$3 = (options.cwd ?? cwd()).toString();
|
||||
const env = options.env ?? process.env;
|
||||
const PATH = getPathFromEnv(env).value;
|
||||
const pathEnv = command.includes("/") || command.includes("\\") ? [""] : [cwd$3, ...PATH.split(delimiter)];
|
||||
let pathExt = env.PATHEXT ? env.PATHEXT.split(delimiter) : defaultPathExt;
|
||||
if (command.includes(".") && pathExt[0] !== "") pathExt = ["", ...pathExt];
|
||||
for (const extensions of [pathExt, noPathExt]) for (const path of pathEnv) {
|
||||
const dest = resolve(cwd$3, path.startsWith("\"") && path.endsWith("\"") && path.length > 1 ? path.slice(1, -1) : path, command);
|
||||
for (const ext of extensions) {
|
||||
const destWithExt = dest + ext;
|
||||
try {
|
||||
if (statSync(destWithExt).isFile()) return destWithExt;
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/non-zero-exit-error.ts
|
||||
var NonZeroExitError = class extends Error {
|
||||
result;
|
||||
output;
|
||||
exitCode;
|
||||
get signalCode() {
|
||||
return this.result.signalCode;
|
||||
}
|
||||
constructor(result, output, command, args) {
|
||||
let target = "The process";
|
||||
if (command) target = `The command \`${args?.length ? `${command} ${args.map((a) => /[ "'`()]/.test(a) ? JSON.stringify(a) : a).join(" ")}` : command}\``;
|
||||
const exitCode = result.exitCode ?? 1;
|
||||
super(result.signalCode !== null ? `${target} was killed by the signal ${result.signalCode}` : `${target} exited with a non-zero status (${exitCode})`);
|
||||
this.result = result;
|
||||
this.output = output;
|
||||
this.exitCode = exitCode;
|
||||
Object.defineProperty(this, "result", {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
};
|
||||
//#endregion
|
||||
//#region src/main.ts
|
||||
const LINE_SEPARATOR_REGEX = /\r?\n/;
|
||||
const defaultOptions = {
|
||||
timeout: void 0,
|
||||
persist: false
|
||||
};
|
||||
const defaultSyncOptions = { timeout: void 0 };
|
||||
const defaultNodeOptions = { windowsHide: true };
|
||||
function combineSignals(signals) {
|
||||
const controller = new AbortController();
|
||||
for (const signal of signals) {
|
||||
if (signal.aborted) {
|
||||
controller.abort();
|
||||
return signal;
|
||||
}
|
||||
const onAbort = () => {
|
||||
controller.abort(signal.reason);
|
||||
};
|
||||
signal.addEventListener("abort", onAbort, { signal: controller.signal });
|
||||
}
|
||||
return controller.signal;
|
||||
}
|
||||
async function readStream(stream) {
|
||||
let output = "";
|
||||
try {
|
||||
for await (const chunk of stream) output += chunk.toString();
|
||||
} catch {}
|
||||
return output;
|
||||
}
|
||||
var ExecProcess = class {
|
||||
_process;
|
||||
_aborted = false;
|
||||
_options;
|
||||
_command;
|
||||
_args;
|
||||
_resolveClose;
|
||||
_processClosed;
|
||||
_thrownError;
|
||||
get process() {
|
||||
return this._process;
|
||||
}
|
||||
get pid() {
|
||||
return this._process?.pid;
|
||||
}
|
||||
get exitCode() {
|
||||
if (this._process && this._process.exitCode !== null) return this._process.exitCode;
|
||||
}
|
||||
get signalCode() {
|
||||
return this._process?.signalCode ?? null;
|
||||
}
|
||||
constructor(command, args, options) {
|
||||
this._options = {
|
||||
...defaultOptions,
|
||||
...options
|
||||
};
|
||||
this._command = command;
|
||||
this._args = args ?? [];
|
||||
this._processClosed = new Promise((resolve) => {
|
||||
this._resolveClose = resolve;
|
||||
});
|
||||
}
|
||||
kill(signal) {
|
||||
return this._process?.kill(signal) === true;
|
||||
}
|
||||
get aborted() {
|
||||
return this._aborted;
|
||||
}
|
||||
get killed() {
|
||||
return this._process?.killed === true;
|
||||
}
|
||||
pipe(command, args, options) {
|
||||
return exec(command, args, {
|
||||
...options,
|
||||
stdin: this
|
||||
});
|
||||
}
|
||||
async *[Symbol.asyncIterator]() {
|
||||
const proc = this._process;
|
||||
if (!proc) return;
|
||||
const streams = [];
|
||||
if (this._streamErr) streams.push(this._streamErr);
|
||||
if (this._streamOut) streams.push(this._streamOut);
|
||||
const streamCombined = combineStreams(streams);
|
||||
const rl = readline.createInterface({ input: streamCombined });
|
||||
for await (const chunk of rl) yield chunk.toString();
|
||||
await this._processClosed;
|
||||
proc.removeAllListeners();
|
||||
if (this._thrownError) throw this._thrownError;
|
||||
if (this._options?.throwOnError && (this.exitCode !== 0 && this.exitCode !== void 0 || this.signalCode !== null)) throw new NonZeroExitError(this, void 0, this._command, this._args);
|
||||
}
|
||||
async _waitForOutput() {
|
||||
const proc = this._process;
|
||||
if (!proc) throw new Error("No process was started");
|
||||
const [stdout, stderr] = await Promise.all([this._streamOut ? readStream(this._streamOut) : "", this._streamErr ? readStream(this._streamErr) : ""]);
|
||||
await this._processClosed;
|
||||
const { stdin } = this._options;
|
||||
if (stdin && typeof stdin !== "string") await stdin;
|
||||
proc.removeAllListeners();
|
||||
if (this._thrownError) throw this._thrownError;
|
||||
const result = {
|
||||
stderr,
|
||||
stdout,
|
||||
exitCode: this.exitCode
|
||||
};
|
||||
if (this._options.throwOnError && (this.exitCode !== 0 && this.exitCode !== void 0 || this.signalCode !== null)) throw new NonZeroExitError(this, result, this._command, this._args);
|
||||
return result;
|
||||
}
|
||||
then(onfulfilled, onrejected) {
|
||||
return this._waitForOutput().then(onfulfilled, onrejected);
|
||||
}
|
||||
_streamOut;
|
||||
_streamErr;
|
||||
spawn() {
|
||||
const cwd$1 = cwd();
|
||||
const options = this._options;
|
||||
const nodeOptions = {
|
||||
...defaultNodeOptions,
|
||||
...options.nodeOptions
|
||||
};
|
||||
const signals = [];
|
||||
this._resetState();
|
||||
if (options.timeout !== void 0) signals.push(AbortSignal.timeout(options.timeout));
|
||||
if (options.signal !== void 0) signals.push(options.signal);
|
||||
if (options.persist === true) nodeOptions.detached = true;
|
||||
if (signals.length > 0) nodeOptions.signal = combineSignals(signals);
|
||||
nodeOptions.env = computeEnv(cwd$1, nodeOptions.env, options.nodePath);
|
||||
const crossResult = normalizeSpawnCommand(this._command, this._args, nodeOptions);
|
||||
const handle = spawn(crossResult.command, crossResult.args, crossResult.options);
|
||||
if (handle.stderr) this._streamErr = handle.stderr;
|
||||
if (handle.stdout) this._streamOut = handle.stdout;
|
||||
this._process = handle;
|
||||
handle.once("error", this._onError);
|
||||
handle.once("close", this._onClose);
|
||||
if (handle.stdin) {
|
||||
const { stdin } = options;
|
||||
if (typeof stdin === "string") handle.stdin.end(stdin);
|
||||
else stdin?.process?.stdout?.pipe(handle.stdin);
|
||||
}
|
||||
}
|
||||
_resetState() {
|
||||
this._aborted = false;
|
||||
this._processClosed = new Promise((resolve) => {
|
||||
this._resolveClose = resolve;
|
||||
});
|
||||
this._thrownError = void 0;
|
||||
}
|
||||
_onError = (err) => {
|
||||
if (err.name === "AbortError" && (!(err.cause instanceof Error) || err.cause.name !== "TimeoutError")) {
|
||||
this._aborted = true;
|
||||
return;
|
||||
}
|
||||
this._thrownError = err;
|
||||
};
|
||||
_onClose = () => {
|
||||
if (this._resolveClose) this._resolveClose();
|
||||
};
|
||||
};
|
||||
function xSync(command, args, options) {
|
||||
const opts = {
|
||||
...defaultSyncOptions,
|
||||
...options
|
||||
};
|
||||
const cwd$2 = cwd();
|
||||
const nodeOptions = {
|
||||
windowsHide: true,
|
||||
...opts.nodeOptions
|
||||
};
|
||||
if (opts.timeout !== void 0) nodeOptions.timeout = opts.timeout;
|
||||
nodeOptions.env = computeEnv(cwd$2, nodeOptions.env, opts.nodePath);
|
||||
const crossResult = normalizeSpawnCommand(command, args ?? [], nodeOptions);
|
||||
const spawnResult = spawnSync(crossResult.command, crossResult.args, crossResult.options);
|
||||
if (spawnResult.error) throw spawnResult.error;
|
||||
const stdout = spawnResult.stdout?.toString() ?? "";
|
||||
const stderr = spawnResult.stderr?.toString() ?? "";
|
||||
const exitCode = spawnResult.status ?? void 0;
|
||||
const signalCode = spawnResult.signal ?? null;
|
||||
const killed = signalCode !== null;
|
||||
const result = {
|
||||
stdout,
|
||||
stderr,
|
||||
get exitCode() {
|
||||
return exitCode;
|
||||
},
|
||||
get signalCode() {
|
||||
return signalCode;
|
||||
},
|
||||
get pid() {
|
||||
return spawnResult.pid;
|
||||
},
|
||||
get killed() {
|
||||
return killed;
|
||||
},
|
||||
*[Symbol.iterator]() {
|
||||
for (const text of [stdout, stderr]) {
|
||||
if (!text) continue;
|
||||
const lines = text.split(LINE_SEPARATOR_REGEX);
|
||||
if (lines[lines.length - 1] === "") lines.pop();
|
||||
yield* lines;
|
||||
}
|
||||
}
|
||||
};
|
||||
if (opts.throwOnError && (exitCode !== 0 && exitCode !== void 0 || signalCode !== null)) throw new NonZeroExitError(result, {
|
||||
stdout: result.stdout,
|
||||
stderr: result.stderr,
|
||||
exitCode: result.exitCode
|
||||
}, command, args);
|
||||
return result;
|
||||
}
|
||||
const x = (command, args, userOptions) => {
|
||||
const proc = new ExecProcess(command, args, userOptions);
|
||||
proc.spawn();
|
||||
return proc;
|
||||
};
|
||||
const exec = x;
|
||||
const execSync = xSync;
|
||||
//#endregion
|
||||
export { ExecProcess, NonZeroExitError, exec, execSync, normalizeSpawnCommand, x, xSync };
|
||||
61
node_modules/tinyexec/package.json
generated
vendored
Normal file
61
node_modules/tinyexec/package.json
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "tinyexec",
|
||||
"version": "1.3.0",
|
||||
"type": "module",
|
||||
"description": "A minimal library for executing processes in Node",
|
||||
"main": "./dist/main.mjs",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"THIRD-PARTY-LICENSES.txt"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsdown",
|
||||
"dev": "tsdown --watch",
|
||||
"format": "prettier --write src",
|
||||
"format:check": "prettier --check src",
|
||||
"lint": "tsc --noEmit && eslint src && publint",
|
||||
"prepare": "npm run build",
|
||||
"test": "npm run build && npm run test:unit",
|
||||
"test:unit": "vitest run"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tinylibs/tinyexec.git"
|
||||
},
|
||||
"keywords": [
|
||||
"execa",
|
||||
"exec",
|
||||
"tiny",
|
||||
"child_process",
|
||||
"spawn"
|
||||
],
|
||||
"author": "James Garbutt (https://github.com/43081j)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/tinylibs/tinyexec/issues"
|
||||
},
|
||||
"homepage": "https://github.com/tinylibs/tinyexec#readme",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@types/node": "^26.1.2",
|
||||
"@vitest/coverage-v8": "^4.1.10",
|
||||
"eslint": "^10.8.0",
|
||||
"prettier": "^3.9.6",
|
||||
"publint": "^0.3.22",
|
||||
"tsdown": "^0.22.14",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript-eslint": "^8.65.0",
|
||||
"vitest": "^4.0.7"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/main.d.mts",
|
||||
"default": "./dist/main.mjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"types": "./dist/main.d.mts"
|
||||
}
|
||||
Reference in New Issue
Block a user