Open jcbhmr opened 1 year ago
Actually, what about node:process
? Doesn't that give you "hard" references to things?
const { cwd } = require("node:process")
import { cwd } from "node:process"
👆 Small caveat with the import
one is that it might change due to https://nodejs.org/api/module.html#modulesyncbuiltinesmexports but that seems rare.
Heck, you can even take advantage of the import * as Name
being a module namespace (not the actual process object) and do this:
import * as process from "node:process"
console.log(globalThis.process === process)
//=> false
delete globalThis.process.cwd;
console.log(process.cwd())
//=> '/home/jcbhmr'
Foolproof way is:
const { ...process } = require("node:process")
// OR
import * as processNamespace from "node:process"
const { ...process } = processNamespace;
// OR
const { ...process } = await import("node:process")
Also consider possibly not including it in the normal
import primordials from "node-primordials"
export. because:It's not in the original Node.js primordial object, so why is it here?