Skip to content

Commit

Permalink
feat: add ability pipe stdio from the node child process (#2)
Browse files Browse the repository at this point in the history
* feat: add ability pipe stdio from the node child process

* Prepare minor release v2.1.0
  • Loading branch information
Brad-Turner authored Oct 23, 2023
1 parent 5fabadb commit b3cdb6c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Add ability to pipe stdio from the node child process.
- Update readme's github badges.

## 2.0.1
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/pino-pretty/.swtc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { type SwtcConfig } from 'swtc';
import { spawn } from 'node:child_process';

const pinoPretty = spawn('npx', ['pino-pretty'], { stdio: ['pipe', process.stdout, process.stderr], shell: true });

const config: SwtcConfig = {
entrypoint: '<entrypoint>',
stdio: ['pipe', pinoPretty.stdin, pinoPretty.stdin],
containers: [
// container definitions, etc...
],
};

export default config;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swtc",
"type": "module",
"version": "2.0.1",
"version": "2.1.0",
"description": "A thin wrapper around the testcontainers library, SWTC lets you easily start and configure a network of Docker services before running a node project.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
5 changes: 1 addition & 4 deletions src/swtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ export async function startWithTestContainers(config: SwtcConfig): Promise<void>
console.info('Containers are started and ready');
}

// start separate node process with watch
console.info(config.entrypoint);

const childProcessArgs = new Array<string>();
// if (config.envFile) childProcessArgs.push(`--env-file=${config.envFile}`);
if (config.esm) childProcessArgs.push(`--loader`, `ts-node/esm`);
if (config.watch) childProcessArgs.push(`--watch`);

spawn('node', [...childProcessArgs, config.entrypoint], { stdio: 'inherit' });
spawn('node', [...childProcessArgs, config.entrypoint], { stdio: config.stdio ?? 'inherit' });
}
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type StdioOptions } from 'node:child_process';
import { type GenericContainer } from './generic-container.js';

export type SyncOrAsyncHook<TParams extends unknown[], TOut = void> = (...parameters: TParams) => Promise<TOut> | TOut;
Expand All @@ -8,4 +9,5 @@ export interface SwtcConfig {
watch?: boolean;
esm?: boolean;
// envFile?: string;
stdio?: StdioOptions;
}

0 comments on commit b3cdb6c

Please sign in to comment.