@lsdsoftware/utils 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './connect-socket.js';
2
2
  export * from './line-reader.js';
3
3
  export * from './semaphore.js';
4
- export * from './spawn-child.js';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './connect-socket.js';
2
2
  export * from './line-reader.js';
3
3
  export * from './semaphore.js';
4
- export * from './spawn-child.js';
@@ -1,4 +1,3 @@
1
1
  import './connect-socket.test.js';
2
2
  import './line-reader.test.js';
3
3
  import './semaphore.test.js';
4
- import './spawn-child.test.js';
@@ -1,4 +1,3 @@
1
1
  import './connect-socket.test.js';
2
2
  import './line-reader.test.js';
3
3
  import './semaphore.test.js';
4
- import './spawn-child.test.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lsdsoftware/utils",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "description": "Useful JavaScript utilities",
6
6
  "main": "dist/index.js",
7
7
  "files": [
@@ -1,9 +0,0 @@
1
- import { ChildProcess } from "child_process";
2
- import * as rxjs from "rxjs";
3
- export declare function spawnChild<T extends ChildProcess>(spawn: () => T): rxjs.Observable<{
4
- process: T;
5
- stdout$: rxjs.Observable<string | Buffer<ArrayBufferLike>>;
6
- stderr$: rxjs.Observable<string | Buffer<ArrayBufferLike>>;
7
- error$: rxjs.Observable<Error>;
8
- close$: rxjs.Observable<number | NodeJS.Signals>;
9
- }>;
@@ -1,15 +0,0 @@
1
- import * as rxjs from "rxjs";
2
- export function spawnChild(spawn) {
3
- const child = spawn();
4
- return rxjs.race(rxjs.fromEvent(child, 'error', (err) => err).pipe(rxjs.map(err => { throw err; })), rxjs.fromEvent(child, 'spawn').pipe(rxjs.take(1), rxjs.map(() => ({
5
- process: child,
6
- stdout$: child.stdout
7
- ? rxjs.fromEvent(child.stdout, 'data')
8
- : rxjs.EMPTY,
9
- stderr$: child.stderr
10
- ? rxjs.fromEvent(child.stderr, 'data')
11
- : rxjs.EMPTY,
12
- error$: rxjs.fromEvent(child, 'error'),
13
- close$: rxjs.fromEvent(child, 'close', (code, signal) => signal || code).pipe(rxjs.take(1)),
14
- }))));
15
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { describe, expect } from "@service-broker/test-utils";
2
- import assert from "assert";
3
- import { spawn } from "child_process";
4
- import * as rxjs from "rxjs";
5
- import { spawnChild } from "./spawn-child.js";
6
- describe('spawn-child', ({ test }) => {
7
- test('fail', () => rxjs.lastValueFrom(spawnChild(() => spawn('bad-cmd'))).then(() => assert(false, '!throw'), err => expect(err.code, 'ENOENT')));
8
- test('success', () => rxjs.lastValueFrom(spawnChild(() => spawn('echo Hello, world && echo Bye, world >&2 && exit 42', { shell: true })).pipe(rxjs.exhaustMap(child => rxjs.forkJoin({
9
- stdout: child.stdout$.pipe(rxjs.takeUntil(child.close$), rxjs.reduce((acc, chunk) => acc.concat(chunk), '')),
10
- stderr: child.stderr$.pipe(rxjs.takeUntil(child.close$), rxjs.reduce((acc, chunk) => acc.concat(chunk), '')),
11
- exitCode: child.close$
12
- })))).then(({ stdout, stderr, exitCode }) => {
13
- expect(stdout, 'Hello, world\n');
14
- expect(stderr, 'Bye, world\n');
15
- expect(exitCode, 42);
16
- }));
17
- });