Skip to content

Commit 64ac0d2

Browse files
committed
Make this work in bun
1 parent 88906fc commit 64ac0d2

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/compiler/core.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,5 @@ export function isNodeLikeSystem(): boolean {
27132713
// use in performanceCore.ts.
27142714
return typeof process !== "undefined"
27152715
&& !!process.nextTick
2716-
&& !(process as any).browser
2717-
&& typeof (process as any).getBuiltinModule === "function";
2716+
&& !(process as any).browser;
27182717
}

src/compiler/nodeGetBuiltinModule.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
export function nodeCreateRequire(path: string): NodeJS.Require {
1+
export function nodeCreateRequire(path: string): (id: string) => any {
2+
/* eslint-disable no-restricted-globals */
3+
// If we're running in an environment that already has `require`, use it.
4+
// We're probably in bun or a bundler that provides `require` even within ESM.
5+
if (typeof require === "function" && typeof require.resolve === "function") {
6+
return id => {
7+
const p = require.resolve(id, { paths: [path] });
8+
return require(p);
9+
};
10+
}
11+
/* eslint-enable no-restricted-globals */
12+
13+
// Otherwise, try and build a `require` function from the `module` module.
214
const mod = nodeGetBuiltinModule("module") as typeof import("module") | undefined;
315
if (!mod) throw new Error("missing node:module");
416
return mod.createRequire(path);

0 commit comments

Comments
 (0)