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
1 change: 1 addition & 0 deletions packages/kbn-optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"cpy": "^8.0.0",
"css-loader": "^3.4.2",
"del": "^5.1.0",
"execa": "^4.0.2",
"file-loader": "^4.2.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jest-diff": "^25.1.0",
Expand Down
14 changes: 8 additions & 6 deletions packages/kbn-optimizer/src/optimizer/observe_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

import { fork, ChildProcess } from 'child_process';
import { Readable } from 'stream';
import { inspect } from 'util';

import execa from 'execa';
import * as Rx from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';

Expand All @@ -42,7 +42,7 @@ export interface WorkerStarted {
export type WorkerStatus = WorkerStdio | WorkerStarted;

interface ProcResource extends Rx.Unsubscribable {
proc: ChildProcess;
proc: execa.ExecaChildProcess;
}
const isNumeric = (input: any) => String(input).match(/^[0-9]+$/);

Expand Down Expand Up @@ -70,20 +70,22 @@ function usingWorkerProc<T>(
config: OptimizerConfig,
workerConfig: WorkerConfig,
bundles: Bundle[],
fn: (proc: ChildProcess) => Rx.Observable<T>
fn: (proc: execa.ExecaChildProcess) => Rx.Observable<T>
) {
return Rx.using(
(): ProcResource => {
const args = [JSON.stringify(workerConfig), JSON.stringify(bundles.map((b) => b.toSpec()))];

const proc = fork(require.resolve('../worker/run_worker'), args, {
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
execArgv: [
const proc = execa.node(require.resolve('../worker/run_worker'), args, {
nodeOptions: [
...(inspectFlag && config.inspectWorkers
? [`${inspectFlag}=${inspectPortCounter++}`]
: []),
...(config.maxWorkerCount <= 3 ? ['--max-old-space-size=2048'] : []),
],
buffer: false,
stderr: 'pipe',
stdout: 'pipe',
});

return {
Expand Down
34 changes: 17 additions & 17 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34812,10 +34812,11 @@ const makeError = ({

const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});
const execaMessage = `Command ${prefix}: ${command}`;
const shortMessage = error instanceof Error ? `${execaMessage}\n${error.message}` : execaMessage;
const isError = Object.prototype.toString.call(error) === '[object Error]';
const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');

if (error instanceof Error) {
if (isError) {
error.originalMessage = error.message;
error.message = message;
} else {
Expand Down Expand Up @@ -36263,25 +36264,24 @@ module.exports = function (/*streams...*/) {

"use strict";

const mergePromiseProperty = (spawned, promise, property) => {
// Starting the main `promise` is deferred to avoid consuming streams
const value = typeof promise === 'function' ?
(...args) => promise()[property](...args) :
promise[property].bind(promise);

Object.defineProperty(spawned, property, {
value,
writable: true,
enumerable: false,
configurable: true
});
};
const nativePromisePrototype = (async () => {})().constructor.prototype;
const descriptors = ['then', 'catch', 'finally'].map(property => [
property,
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property)
]);

// The return value is a mixin of `childProcess` and `Promise`
const mergePromise = (spawned, promise) => {
mergePromiseProperty(spawned, promise, 'then');
mergePromiseProperty(spawned, promise, 'catch');
mergePromiseProperty(spawned, promise, 'finally');
for (const [property, descriptor] of descriptors) {
// Starting the main `promise` is deferred to avoid consuming streams
const value = typeof promise === 'function' ?
(...args) => Reflect.apply(descriptor.value, promise(), args) :
descriptor.value.bind(promise);

Reflect.defineProperty(spawned, property, {...descriptor, value});
}

return spawned;
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13092,10 +13092,10 @@ execa@^0.7.0:
signal-exit "^3.0.0"
strip-eof "^1.0.0"

execa@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.0.tgz#7f37d6ec17f09e6b8fc53288611695b6d12b9daf"
integrity sha512-JbDUxwV3BoT5ZVXQrSVbAiaXhXUkIwvbhPIwZ0N13kX+5yCzOhUNdocxB/UQRuYOHRYYwAxKYwJYc0T4D12pDA==
execa@^4.0.0, execa@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.2.tgz#ad87fb7b2d9d564f70d2b62d511bee41d5cbb240"
integrity sha512-QI2zLa6CjGWdiQsmSkZoGtDx2N+cQIGb3yNolGTdjSQzydzLgYYf8LRuagp7S7fPimjcrzUDSUFd/MgzELMi4Q==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
Expand Down