Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ export default [
]
},
eslintConfigs.recommended,
...tseslintConfigs.strict
...tseslintConfigs.strict,
{
rules: {
'@typescript-eslint/no-unused-vars': 'off'
}
}
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"scripts": {
"build": "tsc --noEmit",
"test": "npm run build && node --test dist/esm/test",
"test": "npm run prepare && echo \"no tests yet\"",
"lint": "eslint src",
"format": "prettier --write src",
"format:check": "prettier --check src",
Expand Down
62 changes: 26 additions & 36 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,39 +154,36 @@ export class ExecProcess implements Result {
await this._processClosed;
}

public then<TResult1 = Output, TResult2 = never>(
public async then<TResult1 = Output, TResult2 = never>(
onfulfilled?: ((value: Output) => TResult1 | PromiseLike<TResult1>) | null,
_onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null
): PromiseLike<TResult1 | TResult2> {
return new Promise<TResult1 | TResult2>(async (resolve, reject) => {
if (this._options?.stdin) {
await this._options.stdin;
}
): Promise<TResult1 | TResult2> {
if (this._options?.stdin) {
await this._options.stdin;
}

const proc = this._process;
const proc = this._process;

if (!proc) {
reject(new Error('No process was started'));
return;
}
if (!proc) {
throw new Error('No process was started');
}

const [stderr, stdout] = await Promise.all([
proc.stderr && readStreamAsString(proc.stderr),
proc.stdout && readStreamAsString(proc.stdout),
this._processClosed
]);

const result: Output = {
stderr: stderr ?? '',
stdout: stdout ?? ''
};

if (onfulfilled) {
resolve(onfulfilled(result));
} else {
resolve(result as TResult1);
}
});
const [stderr, stdout] = await Promise.all([
proc.stderr && readStreamAsString(proc.stderr),
proc.stdout && readStreamAsString(proc.stdout),
this._processClosed
]);

const result: Output = {
stderr: stderr ?? '',
stdout: stdout ?? ''
};

if (onfulfilled) {
return onfulfilled(result);
} else {
return result as TResult1;
}
}

public spawn(): void {
Expand Down Expand Up @@ -214,14 +211,7 @@ export class ExecProcess implements Result {
const {command: normalisedCommand, args: normalisedArgs} =
normaliseCommandAndArgs(this._command, this._args);

let handle;

try {
handle = spawn(normalisedCommand, normalisedArgs, nodeOptions);
} catch (err) {
// TODO (jg): handle errors
throw err;
}
const handle = spawn(normalisedCommand, normalisedArgs, nodeOptions);

this._process = handle;
handle.once('error', this._onError);
Expand Down