Skip to content

Commit

Permalink
Merge pull request #936 from thefrontside/dynamic-import-node-main-v4
Browse files Browse the repository at this point in the history
🐛 dynamically import node process
  • Loading branch information
cowboyd authored Dec 18, 2024
2 parents 351b1a3 + daeef8d commit 92ab87c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Operation } from "./types.ts";
import { callcc } from "./callcc.ts";
import { run } from "./run.ts";
import { useScope } from "./scope.ts";
import process from "node:process";
import { call } from "./call.ts";

/**
* Halt process execution immediately and initiate shutdown. If a message is
Expand Down Expand Up @@ -96,6 +96,9 @@ export async function main(
}
},
*node() {
let { default: process } = yield* call(() =>
import("node:process")
);
hardexit = (status) => process.exit(status);
try {
process.on("SIGINT", interrupt.SIGINT);
Expand Down Expand Up @@ -164,7 +167,7 @@ function* withHost<T>(op: HostOperation<T>): Operation<T> {
// @see https://github.com/iliakan/detect-node/blob/master/index.js
} else if (
Object.prototype.toString.call(
typeof process !== "undefined" ? process : 0,
typeof globalThis.process !== "undefined" ? globalThis.process : 0,
) === "[object process]"
) {
return yield* op.node();
Expand Down

0 comments on commit 92ab87c

Please sign in to comment.