Skip to content

Commit

Permalink
Make this work in bun
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jun 25, 2024
1 parent 88906fc commit 64ac0d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,5 @@ export function isNodeLikeSystem(): boolean {
// use in performanceCore.ts.
return typeof process !== "undefined"
&& !!process.nextTick
&& !(process as any).browser
&& typeof (process as any).getBuiltinModule === "function";
&& !(process as any).browser;
}
14 changes: 13 additions & 1 deletion src/compiler/nodeGetBuiltinModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
export function nodeCreateRequire(path: string): NodeJS.Require {
export function nodeCreateRequire(path: string): (id: string) => any {
/* eslint-disable no-restricted-globals */
// If we're running in an environment that already has `require`, use it.
// We're probably in bun or a bundler that provides `require` even within ESM.
if (typeof require === "function" && typeof require.resolve === "function") {
return id => {
const p = require.resolve(id, { paths: [path] });
return require(p);
};
}
/* eslint-enable no-restricted-globals */

// Otherwise, try and build a `require` function from the `module` module.
const mod = nodeGetBuiltinModule("module") as typeof import("module") | undefined;
if (!mod) throw new Error("missing node:module");
return mod.createRequire(path);
Expand Down

0 comments on commit 64ac0d2

Please sign in to comment.