Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing node:process named exports #268

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const envConfig = env(nodeless, vercel, {});
- [node:path/posix](https://nodejs.org/api/path.html) - ✅ polyfilled all exports
- [node:path/win32](https://nodejs.org/api/path.html) - ✅ polyfilled all exports
- [node:perf_hooks](https://nodejs.org/api/perf_hooks.html) - ✅ polyfilled all exports
- [node:process](https://nodejs.org/api/process.html) - ✅ polyfilled 84/92 exports
- [node:process](https://nodejs.org/api/process.html) - ✅ polyfilled all exports
- [node:punycode](https://nodejs.org/api/punycode.html) - ✅ polyfilled all exports
- [node:querystring](https://nodejs.org/api/querystring.html) - ✅ polyfilled all exports
- [node:readline](https://nodejs.org/api/readline.html) - ✅ polyfilled all exports
Expand Down
12 changes: 4 additions & 8 deletions src/runtime/node/process/$cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,24 @@ export {
getuid,
hasUncaughtExceptionCaptureCallback,
hrtime,
// TODO: implemented yet in unenv
//initgroups,
initgroups,
kill,
listenerCount,
listeners,
loadEnvFile,
memoryUsage,
// TODO: implemented yet in unenv
//moduleLoadList,
moduleLoadList,
off,
on,
once,
// TODO: implemented yet in unenv
//openStdin,
openStdin,
pid,
platform,
ppid,
prependListener,
prependOnceListener,
rawListeners,
// TODO: implemented yet in unenv
//reallyExit,
reallyExit,
release,
removeAllListeners,
removeListener,
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/node/process/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import type nodeProcess from "node:process";

import { process as unenvProcess } from "./internal/process";

export * from "./internal/process";

export default unenvProcess satisfies typeof nodeProcess;
30 changes: 25 additions & 5 deletions src/runtime/node/process/internal/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { notImplemented } from "../../../_internal/utils";
import { env } from "./env";
import { hrtime, nextTick } from "./time";

export { hrtime } from "./time";
export { hrtime, nextTick } from "./time";

export { env } from "./env";

type Process = NodeJS.Process;

Expand Down Expand Up @@ -87,8 +89,10 @@ export const getgroups: Process["getgroups"] = function getgroups() {
// ---- Unimplemented utils ----

export const abort = notImplemented<Process["abort"]>("process.abort");

export const allowedNodeEnvironmentFlags: Process["allowedNodeEnvironmentFlags"] =
new Set();

export const arch: Process["arch"] = "" as any;
export const argv0: Process["argv0"] = "";
export const config: Process["config"] = empty;
Expand Down Expand Up @@ -204,11 +208,9 @@ const throwDeprecation: Process["throwDeprecation"] = false;
// --- Undocumented internals ---

export const assert = notImplemented("process.assert");
const openStdin = notImplemented("process.openStdin");

export const openStdin = notImplemented("process.openStdin");
export const _debugEnd = notImplemented("process._debugEnd");
export const _debugProcess = notImplemented("process._debugProcess");
export const _eventsCount = 0;
export const _fatalException = notImplemented("process._fatalException");
export const _getActiveHandles = notImplemented("process._getActiveHandles");
export const _getActiveRequests = notImplemented("process._getActiveRequests");
Expand All @@ -222,11 +224,25 @@ export const _stopProfilerIdleNotifier = notImplemented(
"process.__stopProfilerIdleNotifier",
);
export const _tickCallback = notImplemented("process._tickCallback");
export const _linkedBinding = notImplemented("process._linkedBinding");

export const domain = mock.__createMock__("process.domain");
export const initgroups = notImplemented("process.initgroups");
export const moduleLoadList = [] as string[];
export const reallyExit = noop;

export const _exiting = false;
export const _events = [];
export const _eventsCount = 0;
export const _maxListeners = 0;

export const process: Process & Record<string, any> = {
_events,
_eventsCount,
_exiting,
_maxListeners,
_debugEnd,
_debugProcess,
_eventsCount,
_fatalException,
_getActiveHandles,
_getActiveRequests,
Expand All @@ -236,6 +252,10 @@ export const process: Process & Record<string, any> = {
_startProfilerIdleNotifier,
_stopProfilerIdleNotifier,
_tickCallback,
domain,
initgroups,
moduleLoadList,
reallyExit,
exitCode,
abort,
addListener,
Expand Down