import {Command} from '@effect/platform';
import {start} from '@effect/platform/Command';
import {Effect, Layer, Stream, pipe} from 'effect';
import * as NodeCommandExecutor from '@effect/platform-node/CommandExecutor';
import * as NodeFileSystem from '@effect/platform-node/FileSystem';
const testLayer = NodeFileSystem.layer.pipe(
Layer.provide(NodeCommandExecutor.layer),
);
const toString = <E>(
stream: Stream.Stream<never, E, Uint8Array>,
): Effect.Effect<never, E, string> => {
return Stream.runFold(
Stream.decodeText(stream, 'utf-8'),
'',
(a, b) => a + b,
);
};
// This doesn't work unfortunately.
// There is no output at all
pipe(
Command.make('node', 'stdout.js'), // stdout.js is `console.log('out');`
start,
Effect.flatMap((process) =>
Effect.all({
stdout: toString(process.stdout),
stderr: toString(process.stderr),
exitCode: process.exitCode,
}),
),
Effect.tap(Effect.log),
Effect.provide(testLayer),
(e) => Effect.runCallback(e, () => console.log('Done')),
);
// This works as expected
// timestamp=2023-11-07T17:33:32.583Z level=INFO fiber=#1 message="{\"stdout\":\"out\n\",\"stderr\":\"err\n\",\"exitCode\":0}"
// Done2
pipe(
Command.make('node', 'stdoutanderr.js'), // stdoutanderr.js is `console.log('out'); console.error('err')`
start,
Effect.flatMap((process) =>
Effect.all({
stdout: toString(process.stdout),
stderr: toString(process.stderr),
exitCode: process.exitCode,
}),
),
Effect.tap(Effect.log),
Effect.provide(testLayer),
(e) => Effect.runCallback(e, () => console.log('Done2')),
);
import {Command} from '@effect/platform';
import {start} from '@effect/platform/Command';
import {Effect, Layer, Stream, pipe} from 'effect';
import * as NodeCommandExecutor from '@effect/platform-node/CommandExecutor';
import * as NodeFileSystem from '@effect/platform-node/FileSystem';
const testLayer = NodeFileSystem.layer.pipe(
Layer.provide(NodeCommandExecutor.layer),
);
const toString = <E>(
stream: Stream.Stream<never, E, Uint8Array>,
): Effect.Effect<never, E, string> => {
return Stream.runFold(
Stream.decodeText(stream, 'utf-8'),
'',
(a, b) => a + b,
);
};
// This doesn't work unfortunately.
// There is no output at all
pipe(
Command.make('node', 'stdout.js'), // stdout.js is `console.log('out');`
start,
Effect.flatMap((process) =>
Effect.all({
stdout: toString(process.stdout),
stderr: toString(process.stderr),
exitCode: process.exitCode,
}),
),
Effect.tap(Effect.log),
Effect.provide(testLayer),
(e) => Effect.runCallback(e, () => console.log('Done')),
);
// This works as expected
// timestamp=2023-11-07T17:33:32.583Z level=INFO fiber=#1 message="{\"stdout\":\"out\n\",\"stderr\":\"err\n\",\"exitCode\":0}"
// Done2
pipe(
Command.make('node', 'stdoutanderr.js'), // stdoutanderr.js is `console.log('out'); console.error('err')`
start,
Effect.flatMap((process) =>
Effect.all({
stdout: toString(process.stdout),
stderr: toString(process.stderr),
exitCode: process.exitCode,
}),
),
Effect.tap(Effect.log),
Effect.provide(testLayer),
(e) => Effect.runCallback(e, () => console.log('Done2')),
);