Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(
private updater: FileSystemUpdater,
private inMemoryFileSystem: InMemoryFileSystem,
private logger: Logger = new NoopLogger()
) {
let rootPackageJsonLevel = Infinity;
// Find locations of package.jsons _not_ inside node_modules
this.subscriptions.add(
Observable.fromEvent<[string, string]>(inMemoryFileSystem, 'add', Array.of)
.subscribe(([uri, content]) => {
const parts = url.parse(uri);
if (!parts.pathname || !parts.pathname.endsWith('/package.json') || parts.pathname.includes('/node_modules/')) {
return;
}
this.packages.add(uri);
this.logger.log(`Found package ${uri}`);
// If the current root package.json is further nested than this one, replace it
const level = parts.pathname.split('/').length;
if (level < rootPackageJsonLevel) {
this.rootPackageJsonUri = uri;
rootPackageJsonLevel = level;
}
})
);
}
static toObservableProcess(process: ChildProcess) {
// a simple mapping function to preserve meta info around the data so that we
// can pump stdout and stderr through one common stream.
let mapFrom = (origin: string) => (data: Buffer | string) => ({ origin: origin, raw: data, str: data.toString() });
let stdOutStream = Observable
.fromEvent(process.stdout, 'data')
.map(mapFrom('stdout'))
.share();
// Since STDERR is a stream just like STDOUT it doesn't
// really work to propagate that with Observable/error.
// Instead we combine STDOUT and STDERR to one stream.
let stdErrStream = Observable
.fromEvent(process.stderr, 'data')
.map(mapFrom('stderr'))
.share();
let closeStream = Observable.fromEvent(process, 'close').share();
return Observable.merge(stdOutStream, stdErrStream).takeUntil(closeStream);
}
let mapFrom = (origin: string) => (data: Buffer | string) => ({ origin: origin, raw: data, str: data.toString() });
let stdOutStream = Observable
.fromEvent(process.stdout, 'data')
.map(mapFrom('stdout'))
.share();
// Since STDERR is a stream just like STDOUT it doesn't
// really work to propagate that with Observable/error.
// Instead we combine STDOUT and STDERR to one stream.
let stdErrStream = Observable
.fromEvent(process.stderr, 'data')
.map(mapFrom('stderr'))
.share();
let closeStream = Observable.fromEvent(process, 'close').share();
return Observable.merge(stdOutStream, stdErrStream).takeUntil(closeStream);
}
static toObservableProcess(process: ChildProcess) {
// a simple mapping function to preserve meta info around the data so that we
// can pump stdout and stderr through one common stream.
let mapFrom = (origin: string) => (data: Buffer | string) => ({ origin: origin, raw: data, str: data.toString() });
let stdOutStream = Observable
.fromEvent(process.stdout, 'data')
.map(mapFrom('stdout'))
.share();
// Since STDERR is a stream just like STDOUT it doesn't
// really work to propagate that with Observable/error.
// Instead we combine STDOUT and STDERR to one stream.
let stdErrStream = Observable
.fromEvent(process.stderr, 'data')
.map(mapFrom('stderr'))
.share();
let closeStream = Observable.fromEvent(process, 'close').share();
return Observable.merge(stdOutStream, stdErrStream).takeUntil(closeStream);
}
componentDidMount() {
this.autoscrollSubscription = Observable
.fromEvent(this.scrollMe, 'scroll')
.map(e => e.target.scrollTop + e.target.offsetHeight >= e.target.scrollHeight)
.distinctUntilChanged()
.subscribe(autoscroll =>
getStore().dispatch({ type: 'Set_Autoscroll', autoscroll } as ConsoleAction)
);
this.consoleSubscription = console$.subscribe(
entry => {
let newState: IConsoleViewState = { entries: [...this.state.entries, entry] };
this.setState(newState);
}
)
}