Commit 1c89db0

Anton Golub <antongolub@antongolub.com>
2025-06-18 08:56:19
refactor: obtain builtins from runtime (#1230)
1 parent 80d4e4e
build/cli.js
build/deps.cjs
@@ -13,6 +13,7 @@ __export(deps_exports, {
   parseDeps: () => parseDeps
 });
 module.exports = __toCommonJS(deps_exports);
+var import_node_module = require("module");
 var import_index = require("./index.cjs");
 var import_vendor = require("./vendor.cjs");
 function installDeps(dependencies, prefix, registry, installerType = "npm") {
@@ -40,64 +41,7 @@ var installers = {
     yield import_index.$`npm install --no-save --no-audit --no-fund ${registryFlag} ${prefixFlag} ${packages}`.nothrow();
   })
 };
-var builtins = /* @__PURE__ */ new Set([
-  "_http_agent",
-  "_http_client",
-  "_http_common",
-  "_http_incoming",
-  "_http_outgoing",
-  "_http_server",
-  "_stream_duplex",
-  "_stream_passthrough",
-  "_stream_readable",
-  "_stream_transform",
-  "_stream_wrap",
-  "_stream_writable",
-  "_tls_common",
-  "_tls_wrap",
-  "assert",
-  "async_hooks",
-  "buffer",
-  "child_process",
-  "cluster",
-  "console",
-  "constants",
-  "crypto",
-  "dgram",
-  "diagnostics_channel",
-  "dns",
-  "domain",
-  "events",
-  "fs",
-  "http",
-  "http2",
-  "https",
-  "inspector",
-  "module",
-  "net",
-  "os",
-  "path",
-  "perf_hooks",
-  "process",
-  "punycode",
-  "querystring",
-  "readline",
-  "repl",
-  "stream",
-  "string_decoder",
-  "sys",
-  "timers",
-  "tls",
-  "trace_events",
-  "tty",
-  "url",
-  "util",
-  "v8",
-  "vm",
-  "wasi",
-  "worker_threads",
-  "zlib"
-]);
+var builtins = new Set(import_node_module.builtinModules);
 var nameRe = new RegExp("^(?<name>(@[a-z\\d-~][\\w-.~]*\\/)?[a-z\\d-~][\\w-.~]*)\\/?.*$", "i");
 var versionRe = new RegExp("^@(?<version>[~^]?(v?[\\dx*]+([-.][\\d*a-z-]+)*))", "i");
 function parseDeps(content) {
src/deps.ts
@@ -12,6 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+import { builtinModules } from 'node:module'
 import { $, spinner } from './index.ts'
 import { depseek } from './vendor.ts'
 
@@ -58,64 +59,7 @@ const installers: Record<any, DepsInstaller> = {
   },
 }
 
-const builtins = new Set([
-  '_http_agent',
-  '_http_client',
-  '_http_common',
-  '_http_incoming',
-  '_http_outgoing',
-  '_http_server',
-  '_stream_duplex',
-  '_stream_passthrough',
-  '_stream_readable',
-  '_stream_transform',
-  '_stream_wrap',
-  '_stream_writable',
-  '_tls_common',
-  '_tls_wrap',
-  'assert',
-  'async_hooks',
-  'buffer',
-  'child_process',
-  'cluster',
-  'console',
-  'constants',
-  'crypto',
-  'dgram',
-  'diagnostics_channel',
-  'dns',
-  'domain',
-  'events',
-  'fs',
-  'http',
-  'http2',
-  'https',
-  'inspector',
-  'module',
-  'net',
-  'os',
-  'path',
-  'perf_hooks',
-  'process',
-  'punycode',
-  'querystring',
-  'readline',
-  'repl',
-  'stream',
-  'string_decoder',
-  'sys',
-  'timers',
-  'tls',
-  'trace_events',
-  'tty',
-  'url',
-  'util',
-  'v8',
-  'vm',
-  'wasi',
-  'worker_threads',
-  'zlib',
-])
+const builtins = new Set(builtinModules)
 
 const nameRe = /^(?<name>(@[a-z\d-~][\w-.~]*\/)?[a-z\d-~][\w-.~]*)\/?.*$/i
 const versionRe = /^@(?<version>[~^]?(v?[\dx*]+([-.][\d*a-z-]+)*))/i
.size-limit.json
@@ -29,7 +29,7 @@
       "build/globals.js",
       "build/deno.js"
     ],
-    "limit": "812.75 kB",
+    "limit": "812.05 kB",
     "brotli": false,
     "gzip": false
   },
@@ -62,7 +62,7 @@
       "README.md",
       "LICENSE"
     ],
-    "limit": "868.10 kB",
+    "limit": "867.40 kB",
     "brotli": false,
     "gzip": false
   }