fix: streams

This commit is contained in:
cha0s 2024-02-16 21:58:14 -06:00
parent f07af8fe6e
commit 3db7bb423f
2 changed files with 10 additions and 4 deletions

View File

@ -1,5 +1,6 @@
const {access} = require('fs/promises');
const {join} = require('path');
const {PassThrough} = require('stream');
const {hook: coreCommands} = require('@flecks/build/build/hooks/@flecks/build.commands');
const {rimraf} = require('@flecks/build/src/server');
@ -58,6 +59,7 @@ module.exports = (program, flecks) => {
'test',
{
env: {
DEBUG_COLORS: 'dumb' !== TERM,
FORCE_COLOR: 'dumb' !== TERM,
},
production,
@ -66,9 +68,9 @@ module.exports = (program, flecks) => {
},
);
if (!watch) {
const stdout = pipesink(child.stdout);
const stdio = pipesink(child.stderr.pipe(child.stdout.pipe(new PassThrough())));
if (0 !== await processCode(child)) {
const buffer = await stdout;
const buffer = await stdio;
if (!process.stdout.write(buffer)) {
await new Promise((resolve, reject) => {
process.stdout.on('error', reject);

View File

@ -2,6 +2,7 @@ import {mkdir} from 'fs/promises';
import {createServer} from 'net';
import {tmpdir} from 'os';
import {dirname, join} from 'path';
import {PassThrough} from 'stream';
import {id} from '@flecks/core/build/testing';
import {
@ -14,6 +15,7 @@ import {createApplication} from './create-application';
const {
FLECKS_CORE_ROOT = process.cwd(),
TERM,
} = process.env;
class SocketWrapper {
@ -135,10 +137,12 @@ export async function startServer({
stdio: 'pipe',
...opts,
env: {
DEBUG_COLORS: 'dumb' !== TERM,
FLECKS_ENV__flecks_server__stats: '{"preset": "none"}',
FLECKS_ENV__flecks_server__start: true,
FLECKS_CORE_ROOT: path,
FLECKS_SERVER_TEST_SOCKET: socketPath,
FORCE_COLOR: 'dumb' !== TERM,
NODE_ENV: 'test',
NODE_PATH: join(FLECKS_CORE_ROOT, '..', '..', 'node_modules'),
...opts.env,
@ -149,10 +153,10 @@ export async function startServer({
socketServer.close();
});
if (failOnErrorCode) {
const stderr = pipesink(server.stderr);
const stdio = pipesink(server.stderr.pipe(server.stdout.pipe(new PassThrough())));
server.on('exit', async (code) => {
if (!server.done && 0 !== code) {
const buffer = await stderr;
const buffer = await stdio;
if (!process.stderr.write(buffer)) {
await new Promise((resolve, reject) => {
process.stderr.on('error', reject);