isaacs / node-primordials

https://isaacs.github.io/node-primordials/
11 stars 3 forks source link

Consider breaking Node.js process-related stuff into its own process.ts or something? #6

Open jcbhmr opened 1 year ago

jcbhmr commented 1 year ago

Also consider possibly not including it in the normal import primordials from "node-primordials" export. because:

  1. This is what causes #5
  2. It's not in the original Node.js primordial object, so why is it here?
jcbhmr commented 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")