1- import path from "node:path"
21import fs from "node:fs"
2+ import { builtinModules } from "node:module"
3+ import path from "node:path"
34import { rollup } from "rollup"
45import typescript from "@rollup/plugin-typescript"
56import resolve from "@rollup/plugin-node-resolve"
@@ -13,6 +14,19 @@ import {
1314 STATIC_ASSET_EXTENSIONS ,
1415} from "./static-asset-plugin"
1516
17+ const isNodeBuiltin = ( id : string ) => {
18+ const withoutNodePrefix = id . replace ( / ^ n o d e : / , "" )
19+
20+ return (
21+ builtinModules . includes ( id ) ||
22+ builtinModules . includes ( withoutNodePrefix ) ||
23+ builtinModules . includes ( `node:${ withoutNodePrefix } ` )
24+ )
25+ }
26+
27+ const isTscircuitDependency = ( id : string ) =>
28+ id === "tscircuit" || id . startsWith ( "tscircuit/" )
29+
1630const createExternalFunction =
1731 ( projectDir : string , tsconfigPath ?: string ) =>
1832 ( id : string ) : boolean => {
@@ -71,8 +85,18 @@ const createExternalFunction =
7185 return false // This is a local file, don't externalize
7286 }
7387
74- // Everything else (npm packages like 'react', 'tscircuit', etc.) is external
75- return true
88+ // Keep Node.js built-ins external
89+ if ( isNodeBuiltin ( id ) ) {
90+ return true
91+ }
92+
93+ // Always externalize tscircuit so it's not bundled with user output
94+ if ( isTscircuitDependency ( id ) ) {
95+ return true
96+ }
97+
98+ // Bundle all other dependencies into the output
99+ return false
76100 }
77101
78102export const transpileFile = async ( {
0 commit comments