This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

22
node_modules/@expo/spawn-async/LICENSE generated vendored Normal file
View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 650 Industries
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.

66
node_modules/@expo/spawn-async/README.md generated vendored Normal file
View File

@ -0,0 +1,66 @@
# spawn-async [![CircleCI](https://circleci.com/gh/expo/spawn-async.svg?style=svg)](https://circleci.com/gh/expo/spawn-async) [![Build Status](https://travis-ci.org/expo/spawn-async.svg?branch=master)](https://travis-ci.org/expo/spawn-async)
A cross-platform version of Node's `child_process.spawn` as an async function that returns a promise. Supports Node 8 LTS and up.
## Usage:
```js
import spawnAsync from '@expo/spawn-async';
(async function () {
let resultPromise = spawnAsync('echo', ['hello', 'world']);
let spawnedChildProcess = resultPromise.child;
try {
let {
pid,
output: [stdout, stderr],
stdout,
stderr,
status,
signal,
} = await resultPromise;
} catch (e) {
console.error(e.stack);
// The error object also has the same properties as the result object
}
})();
```
## API
`spawnAsync` takes the same arguments as [`child_process.spawn`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). Its options are the same as those of `child_process.spawn` plus:
- `ignoreStdio`: whether to ignore waiting for the child process's stdio streams to close before resolving the result promise. When ignoring stdio, the returned values for `stdout` and `stderr` will be empty strings. The default value of this option is `false`.
It returns a promise whose result is an object with these properties:
- `pid`: the process ID of the spawned child process
- `output`: an array with stdout and stderr's output
- `stdout`: a string of what the child process wrote to stdout
- `stderr`: a string of what the child process wrote to stderr
- `status`: the exit code of the child process
- `signal`: the signal (ex: `SIGTERM`) used to stop the child process if it did not exit on its own
If there's an error running the child process or it exits with a non-zero status code, `spawnAsync` rejects the returned promise. The Error object also has the properties listed above.
### Accessing the child process
Sometimes you may want to access the child process object--for example, if you wanted to attach event handlers to `stdio` or `stderr` and process data as it is available instead of waiting for the process to be resolved.
You can do this by accessing `.child` on the Promise that is returned by `spawnAsync`.
Here is an example:
```js
(async () => {
let ffmpeg$ = spawnAsync('ffmpeg', ['-i', 'path/to/source.flac', '-codec:a', 'libmp3lame', '-b:a', '320k', '-ar', '44100', 'path/to/output.mp3']);
let childProcess = ffmpeg$.child;
childProcess.stdout.on('data', (data) => {
console.log(`ffmpeg stdout: ${data}`);
});
childProcess.stderr.on('data', (data) => {
console.error(`ffmpeg stderr: ${data}`);
});
let result = await ffmpeg$;
console.log(`ffmpeg pid ${result.pid} exited with code ${result.code}`);
})();
```

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,120 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const spawnAsync_1 = __importDefault(require("../spawnAsync"));
it(`receives output from completed processes`, async () => {
let result = await spawnAsync_1.default('echo', ['hi']);
expect(typeof result.pid).toBe('number');
expect(result.stdout).toBe('hi\n');
expect(result.stderr).toBe('');
expect(result.output[0]).toBe(result.stdout);
expect(result.output[1]).toBe(result.stderr);
expect(result.status).toBe(0);
expect(result.signal).toBe(null);
});
it(`throws errors when processes return non-zero exit codes`, async () => {
let didThrow = false;
try {
await spawnAsync_1.default('false');
}
catch (e) {
didThrow = true;
expect(typeof e.pid).toBe('number');
expect(e.status).toBe(1);
expect(e.signal).toBe(null);
}
expect(didThrow).toBe(true);
});
it(`returns when processes are killed with signals with non-zero exit codes`, async () => {
let didThrow = false;
try {
await spawnAsync_1.default(path_1.default.join(__dirname, 'signal-self.sh'));
}
catch (e) {
didThrow = true;
expect(typeof e.pid).toBe('number');
expect(e.status).toBe(null);
expect(e.signal).toBe('SIGKILL');
}
expect(didThrow).toBe(true);
});
it(`throws errors when processes don't exist`, async () => {
let didThrow = false;
try {
await spawnAsync_1.default('nonexistent-program');
}
catch (e) {
didThrow = true;
expect(e.pid).not.toBeDefined();
expect(e.code).toBe('ENOENT');
expect(e.status).toBe(null);
expect(e.signal).toBe(null);
}
expect(didThrow).toBe(true);
});
it(`exposes the child process through a property named "child"`, async () => {
let spawnTask = spawnAsync_1.default('echo', ['hi']);
let childProcess = spawnTask.child;
expect(childProcess).toBeDefined();
let result = await spawnTask;
expect(result.pid).toBe(childProcess.pid);
});
it(`runs extra listeners added to the child process`, async () => {
let spawnTask = spawnAsync_1.default('echo', ['hi']);
let mockExitListener = jest.fn();
let mockCloseListener = jest.fn();
spawnTask.child.on('exit', mockExitListener);
spawnTask.child.on('close', mockCloseListener);
await spawnTask;
expect(mockExitListener).toHaveBeenCalledTimes(1);
expect(mockCloseListener).toHaveBeenCalledTimes(1);
});
it(`runs extra error listeners added to the child process when there is an error`, async () => {
let spawnTask = spawnAsync_1.default('nonexistent-program');
let mockErrorListener = jest.fn();
spawnTask.child.on('error', mockErrorListener);
await expect(spawnTask).rejects.toThrowError();
expect(mockErrorListener).toHaveBeenCalledTimes(1);
});
it(`returns empty strings when ignoring stdio`, async () => {
let result = await spawnAsync_1.default('echo', ['hi'], { ignoreStdio: true });
expect(typeof result.pid).toBe('number');
expect(result.stdout).toBe('');
expect(result.stderr).toBe('');
expect(result.output[0]).toBe(result.stdout);
expect(result.output[1]).toBe(result.stderr);
expect(result.status).toBe(0);
expect(result.signal).toBe(null);
});
it(`returns even if stdout is open when ignoring stdio`, async () => {
// Without ignoring stdio, the promise will never resolve as stdout remains open indefinitely
let sourceTask = spawnAsync_1.default('yes', [], { ignoreStdio: true });
expect(sourceTask.child.listenerCount('exit')).toBe(1);
expect(sourceTask.child.listenerCount('close')).toBe(0);
// Create a sink that keeps the source's stdout open even after the source process exits
let sinkTask = spawnAsync_1.default('cat');
sourceTask.child.stdout.pipe(sinkTask.child.stdin);
sinkTask.child.stdin.cork();
// Allow the source's stdout to buffer with a short delay
await new Promise(resolve => setTimeout(resolve, 5));
// The source's stdout stays open even after killing the process
sourceTask.child.kill();
await expect(sourceTask).rejects.toThrowError();
// Destroy the sink's stdin stream to let the process exit
sinkTask.child.stdin.destroy();
await expect(sinkTask).resolves.toMatchObject({ status: 0, stdout: '', stderr: '' });
});
it('throws errors with preserved stack traces when processes return non-zero exit codes', async () => {
expect.assertions(2);
try {
await spawnAsync_1.default('false');
}
catch (e) {
expect(e.stack).toMatch(/\n \.\.\.\n/);
expect(e.stack).toMatch(/at Object\.spawnAsync/);
}
});
//# sourceMappingURL=spawnAsync-test.js.map

File diff suppressed because one or more lines are too long

17
node_modules/@expo/spawn-async/build/spawnAsync.d.ts generated vendored Normal file
View File

@ -0,0 +1,17 @@
/// <reference types="node" />
import { ChildProcess, SpawnOptions as NodeSpawnOptions } from 'child_process';
export interface SpawnOptions extends NodeSpawnOptions {
ignoreStdio?: boolean;
}
export interface SpawnPromise<T> extends Promise<T> {
child: ChildProcess;
}
export interface SpawnResult {
pid: number;
output: string[];
stdout: string;
stderr: string;
status: number | null;
signal: string | null;
}
export default function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnOptions): SpawnPromise<SpawnResult>;

94
node_modules/@expo/spawn-async/build/spawnAsync.js generated vendored Normal file
View File

@ -0,0 +1,94 @@
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cross_spawn_1 = __importDefault(require("cross-spawn"));
function spawnAsync(command, args, options = {}) {
const fakeErr = new Error('fake error just to preserve stacktrace');
const previousStack = fakeErr.stack && fakeErr.stack.split('\n').splice(1);
const previousStackString = previousStack && [' ...', ...previousStack].join('\n');
let child;
let promise = new Promise((resolve, reject) => {
let { ignoreStdio } = options, nodeOptions = __rest(options, ["ignoreStdio"]);
// @ts-ignore: cross-spawn declares "args" to be a regular array instead of a read-only one
child = cross_spawn_1.default(command, args, nodeOptions);
let stdout = '';
let stderr = '';
if (!ignoreStdio) {
if (child.stdout) {
child.stdout.on('data', data => {
stdout += data;
});
}
if (child.stderr) {
child.stderr.on('data', data => {
stderr += data;
});
}
}
let completionListener = (code, signal) => {
child.removeListener('error', errorListener);
let result = {
pid: child.pid,
output: [stdout, stderr],
stdout,
stderr,
status: code,
signal,
};
if (code !== 0) {
let error = signal
? new Error(`${command} exited with signal: ${signal}`)
: new Error(`${command} exited with non-zero code: ${code}`);
if (error.stack && previousStackString) {
error.stack += `\n${previousStackString}`;
}
Object.assign(error, result);
reject(error);
}
else {
resolve(result);
}
};
let errorListener = (error) => {
if (ignoreStdio) {
child.removeListener('exit', completionListener);
}
else {
child.removeListener('close', completionListener);
}
Object.assign(error, {
pid: child.pid,
output: [stdout, stderr],
stdout,
stderr,
status: null,
signal: null,
});
reject(error);
};
if (ignoreStdio) {
child.once('exit', completionListener);
}
else {
child.once('close', completionListener);
}
child.once('error', errorListener);
});
// @ts-ignore: TypeScript isn't aware the Promise constructor argument runs synchronously and
// thinks `child` is not yet defined
promise.child = child;
return promise;
}
exports.default = spawnAsync;
//# sourceMappingURL=spawnAsync.js.map

File diff suppressed because one or more lines are too long

1
node_modules/@expo/spawn-async/index.js generated vendored Normal file
View File

@ -0,0 +1 @@
module.exports = require('./build/spawnAsync').default;

51
node_modules/@expo/spawn-async/package.json generated vendored Normal file
View File

@ -0,0 +1,51 @@
{
"name": "@expo/spawn-async",
"version": "1.5.0",
"description": "A Promise-based interface into processes created by child_process.spawn",
"main": "index.js",
"types": "./build/spawnAsync.d.ts",
"files": [
"build"
],
"engines": {
"node": ">=4"
},
"scripts": {
"build": "tsc",
"clean": "rm -rf build",
"prepare": "yarn clean && yarn build",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/expo/spawn-async.git"
},
"keywords": [
"spawn",
"child_process",
"async",
"promise",
"process"
],
"author": "Expo",
"license": "MIT",
"bugs": {
"url": "https://github.com/expo/spawn-async/issues"
},
"homepage": "https://github.com/expo/spawn-async#readme",
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"rootDir": "src"
},
"dependencies": {
"cross-spawn": "^6.0.5"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.0",
"@types/jest": "^23.3.9",
"jest": "^23.6.0",
"ts-jest": "^23.10.4",
"typescript": "^3.1.6"
}
}