Skip to content

Commit

Permalink
fix: blocking stdout and stderr (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc authored Jan 30, 2024
1 parent 75b583f commit 69d8c76
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/bundler-okam/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ function lessLoader(fn, opts) {
// export for test only
exports._lessLoader = lessLoader;

// ref:
// https://github.com/vercel/next.js/pull/51883
function blockStdout() {
if (process.platform === 'darwin') {
// rust needs stdout to be blocking, otherwise it will throw an error (on macOS at least) when writing a lot of data (logs) to it
// see https://github.com/napi-rs/napi-rs/issues/1630
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
if (process.stdout._handle != null) {
process.stdout._handle.setBlocking(true);
}
if (process.stderr._handle != null) {
process.stderr._handle.setBlocking(true);
}
}
}

exports.build = async function (opts) {
assert(opts, 'opts should be supplied');
const {
Expand All @@ -55,6 +71,7 @@ exports.build = async function (opts) {
okamConfig.moduleIdStrategy = 'hashed';
}

blockStdout();
const { build } = require('@okamjs/okam');
try {
await build({
Expand Down Expand Up @@ -185,6 +202,7 @@ exports.dev = async function (opts) {
server.on('upgrade', wsProxy.upgrade);

// okam dev
blockStdout();
const { build } = require('@okamjs/okam');
const okamConfig = await getOkamConfig(opts);
okamConfig.hmr = { port: hmrPort, host: opts.host };
Expand Down

0 comments on commit 69d8c76

Please sign in to comment.