├── .gitignore ├── package.json ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── ci.yml ├── .eslintrc.json ├── bower.json ├── README.md ├── LICENSE ├── src └── Node │ ├── Platform.purs │ ├── Process.js │ └── Process.purs └── CHANGELOG.md /.gitignore: -------------------------------------------------------------------------------- 1 | /.* 2 | !/.gitignore 3 | !/.eslintrc.json 4 | !/.github/ 5 | /bower_components/ 6 | /node_modules/ 7 | /output/ 8 | package-lock.json 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "clean": "rimraf output && rimraf .pulp-cache", 5 | "build": "eslint src && pulp build -- --censor-lib --strict" 6 | }, 7 | "devDependencies": { 8 | "eslint": "^7.15.0", 9 | "pulp": "16.0.0-0", 10 | "purescript-psa": "^0.8.2", 11 | "rimraf": "^3.0.2" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Description of the change** 2 | 3 | Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR. 4 | 5 | --- 6 | 7 | **Checklist:** 8 | 9 | - [ ] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)") 10 | - [ ] Linked any existing issues or proposals that this pull request should close 11 | - [ ] Updated or added relevant documentation 12 | - [ ] Added a test for the contribution (if applicable) 13 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 6, 4 | "sourceType": "module" 5 | }, 6 | "extends": "eslint:recommended", 7 | "env": { 8 | "node": true 9 | }, 10 | "rules": { 11 | "strict": [2, "global"], 12 | "block-scoped-var": 2, 13 | "consistent-return": 2, 14 | "eqeqeq": [2, "smart"], 15 | "guard-for-in": 2, 16 | "no-caller": 2, 17 | "no-extend-native": 2, 18 | "no-loop-func": 2, 19 | "no-new": 2, 20 | "no-param-reassign": 2, 21 | "no-return-assign": 2, 22 | "no-unused-expressions": 2, 23 | "no-use-before-define": 2, 24 | "radix": [2, "always"], 25 | "indent": [2, 2], 26 | "quotes": [2, "double"], 27 | "semi": [2, "always"] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purescript-node-process", 3 | "repository": { 4 | "type": "git", 5 | "url": "https://github.com/purescript-node/purescript-node-process.git" 6 | }, 7 | "license": "MIT", 8 | "ignore": [ 9 | "**/.*", 10 | "node_modules", 11 | "bower_components", 12 | "output" 13 | ], 14 | "dependencies": { 15 | "purescript-effect": "^4.0.0", 16 | "purescript-foreign-object": "^4.0.0", 17 | "purescript-foreign": "^7.0.0", 18 | "purescript-maybe": "^6.0.0", 19 | "purescript-node-event-emitter": "https://github.com/purescript-node/purescript-node-event-emitter.git#^3.0.0", 20 | "purescript-node-streams": "^9.0.0", 21 | "purescript-posix-types": "^6.0.0", 22 | "purescript-prelude": "^6.0.0", 23 | "purescript-unsafe-coerce": "^6.0.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # purescript-node-process 2 | 3 | [![Latest release](http://img.shields.io/github/release/purescript-node/purescript-node-process.svg)](https://github.com/purescript-node/purescript-node-process/releases) 4 | [![Build status](https://github.com/purescript-node/purescript-node-process/workflows/CI/badge.svg?branch=master)](https://github.com/purescript-node/purescript-node-process/actions?query=workflow%3ACI+branch%3Amaster) 5 | [![Pursuit](https://pursuit.purescript.org/packages/purescript-node-process/badge)](https://pursuit.purescript.org/packages/purescript-node-process) 6 | 7 | The Node.js global `process` object in PureScript. 8 | 9 | ## Installation 10 | 11 | ``` 12 | spago install node-process 13 | ``` 14 | 15 | ## Documentation 16 | 17 | Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-node-process). 18 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | 15 | - uses: purescript-contrib/setup-purescript@main 16 | with: 17 | purescript: "unstable" 18 | purs-tidy: "latest" 19 | 20 | - uses: actions/setup-node@v3 21 | with: 22 | node-version: "lts/*" 23 | 24 | - name: Install dependencies 25 | run: | 26 | npm install -g bower 27 | npm install 28 | bower install --production 29 | 30 | - name: Build source 31 | run: npm run-script build 32 | 33 | - name: Run tests 34 | run: | 35 | bower install 36 | npm run-script test --if-present 37 | 38 | - name: Check Formatting 39 | if: runner.os == 'Linux' 40 | run: | 41 | npx purs-tidy check src 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PureScript 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/Node/Platform.purs: -------------------------------------------------------------------------------- 1 | -- | This module defines data type for the different platforms supported by 2 | -- | Node.js 3 | module Node.Platform where 4 | 5 | import Prelude 6 | import Data.Maybe (Maybe(..)) 7 | 8 | -- | See [the Node docs](https://nodejs.org/dist/latest-v6.x/docs/api/os.html#os_os_platform). 9 | data Platform 10 | = AIX 11 | | Darwin 12 | | FreeBSD 13 | | Linux 14 | | OpenBSD 15 | | SunOS 16 | | Win32 17 | | Android 18 | 19 | -- | The String representation for a platform, recognised by Node.js. 20 | toString :: Platform -> String 21 | toString AIX = "aix" 22 | toString Darwin = "darwin" 23 | toString FreeBSD = "freebsd" 24 | toString Linux = "linux" 25 | toString OpenBSD = "openbsd" 26 | toString SunOS = "sunos" 27 | toString Win32 = "win32" 28 | toString Android = "android" 29 | 30 | -- | Attempt to parse a `Platform` value from a string, in the format returned 31 | -- | by Node.js' `process.platform`. 32 | fromString :: String -> Maybe Platform 33 | fromString "aix" = Just AIX 34 | fromString "darwin" = Just Darwin 35 | fromString "freebsd" = Just FreeBSD 36 | fromString "linux" = Just Linux 37 | fromString "openbsd" = Just OpenBSD 38 | fromString "sunos" = Just SunOS 39 | fromString "win32" = Just Win32 40 | fromString "android" = Just Android 41 | fromString _ = Nothing 42 | 43 | instance showPlatform :: Show Platform where 44 | show AIX = "AIX" 45 | show Darwin = "Darwin" 46 | show FreeBSD = "FreeBSD" 47 | show Linux = "Linux" 48 | show OpenBSD = "OpenBSD" 49 | show SunOS = "SunOS" 50 | show Win32 = "Win32" 51 | show Android = "Android" 52 | 53 | derive instance eqPlatform :: Eq Platform 54 | derive instance ordPlatform :: Ord Platform 55 | -------------------------------------------------------------------------------- /src/Node/Process.js: -------------------------------------------------------------------------------- 1 | import process from "process"; 2 | 3 | export { process }; 4 | export const abortImpl = process.abort ? () => process.abort() : null; 5 | export const argv = () => process.argv.slice(); 6 | export const argv0 = () => process.argv0; 7 | export const channelRefImpl = process.channel && process.channel.ref ? () => process.channel.ref() : null; 8 | export const channelUnrefImpl = process.channel && process.channel.unref ? () => process.channel.unref() : null; 9 | export const chdirImpl = (dir) => process.chdir(dir); 10 | export const config = () => Object.assign({}, process.config); 11 | export const connected = () => process.connected; 12 | export const cpuUsage = () => process.cpuUsage(); 13 | export const cpuUsageDiffImpl = (prevVal) => process.cpuUsage(prevVal); 14 | export const cwd = () => process.cwd(); 15 | export const debugPort = process.debugPort; 16 | export const disconnectImpl = process.disconnect ? () => process.disconnect() : null; 17 | export const getEnv = () => Object.assign({}, process.env); 18 | export const unsafeGetEnv = () => process.env; 19 | export const setEnvImpl = (key, val) => { 20 | process.env[key] = val; 21 | }; 22 | export const unsetEnvImpl = (key) => { 23 | delete process.env[key]; 24 | }; 25 | export const execArgv = () => process.execArgv.slice(); 26 | export const execPath = () => process.execPath; 27 | export const exit = () => process.exit(); 28 | export const exitImpl = (code) => process.exit(code); 29 | export const setExitCodeImpl = (code) => { 30 | process.exitCode = code; 31 | }; 32 | export const getExitCodeImpl = () => process.exitCode; 33 | export const getGidImpl = () => process.getgid(); 34 | export const getUidImpl = () => process.getuid(); 35 | export const hasUncaughtExceptionCaptureCallback = () => process.hasUncaughtExceptionCaptureCallback; 36 | export const killImpl = (pid) => process.kill(pid); 37 | export const killStrImpl = (pid, sig) => process.kill(pid, sig); 38 | export const killIntImpl = (pid, int) => process.kill(pid, int); 39 | export const memoryUsage = () => process.memoryUsage(); 40 | export const memoryUsageRss = () => process.memoryUsage.rss(); 41 | export const nextTickImpl = (cb) => process.nextTick(cb); 42 | export const nextTickCbImpl = (cb, args) => process.nextTick(cb, args); 43 | export const pid = process.pid; 44 | export const platformStr = process.platform; 45 | export const ppid = process.ppid; 46 | export const resourceUsage = () => process.resourceUsage; 47 | export const sendImpl = (msg, handle) => process.send(msg, handle); 48 | export const sendOptsImpl = (msg, handle, opts) => process.send(msg, handle, opts); 49 | export const sendCbImpl = (msg, handle, cb) => process.send(msg, handle, cb); 50 | export const sendOptsCbImpl = (msg, handle, opts, cb) => process.send(msg, handle, opts, cb); 51 | export const setUncaughtExceptionCaptureCallbackImpl = (cb) => process.setUncaughtExceptionCaptureCallback(cb); 52 | export const clearUncaughtExceptionCaptureCallback = () => process.setUncaughtExceptionCaptureCallback(null); 53 | export const stdin = process.stdin; 54 | export const stdout = process.stdout; 55 | export const stderr = process.stderr; 56 | export const stdinIsTTY = process.stdinIsTTY; 57 | export const stdoutIsTTY = process.stdoutIsTTY; 58 | export const stderrIsTTY = process.stderrIsTTY; 59 | export const getTitle = () => process.title; 60 | export const setTitleImpl = (v) => { 61 | process.title = v; 62 | }; 63 | export const uptime = () => process.uptime(); 64 | export const version = process.version; 65 | 66 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 4 | 5 | ## [Unreleased] 6 | 7 | Breaking changes: 8 | 9 | New features: 10 | 11 | Bugfixes: 12 | 13 | Other improvements: 14 | 15 | ## [v11.2.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.2.0) - 2023-07-25 16 | 17 | Bugfixes: 18 | - Update `node-streams` to `v9.0.0` to fix FFI issues (#45 by @JordanMartinez) 19 | 20 | ## [v11.1.1](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.1.1) - 2023-07-25 21 | 22 | Bugfixes: 23 | - Fixes FFI for `cwd` (#44 by @JordanMartinez) 24 | 25 | ## [v11.1.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.1.0) - 2023-07-24 26 | 27 | New Features: 28 | - Add FFI for `getUid`/`getPid` (#43 by @JordanMartinez) 29 | 30 | ## [v11.0.1](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.0.1) - 2023-07-21 31 | 32 | Bugfixes: 33 | - Fix FFI for `channelRef`/`channelUnref` (#42 by @JordanMartinez) 34 | 35 | ## [v11.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.0.0) - 2023-07-21 36 | 37 | Breaking changes: 38 | - Breaking changes to `exit` (#39 by @JordanMartinez) 39 | 40 | The `exit` API provides two versions: 41 | - unspecified exit code: `process.exit();` 42 | - specified exit code: `process.exit(1);` 43 | 44 | Previously, the type signature of `exit` only allowed 45 | the second usage. This change supports both. 46 | Followin the pattern used in other Node libraries 47 | of a `'` (prime) character indicating a 48 | variant of the function that takes a callback or optons 49 | are, the type signature of `exit` has changed: 50 | 51 | ```purs 52 | -- before: 53 | exit :: forall a. Int -> Effect a 54 | 55 | -- after: 56 | exit :: forall a. Effect a 57 | 58 | exit' :: forall a. Int -> Effect a 59 | ``` 60 | - Bump `node-streams` to `v8.0.0` (#40 by @JordanMartinez) 61 | - Migrate `onEventName` to `eventH`-style event handling API (#40 by @JordanMartinez) 62 | 63 | ```purs 64 | -- Before 65 | onExit \exitCode -> ... 66 | 67 | -- After 68 | process # on_ exitH \exitCode -> 69 | ``` 70 | 71 | See https://pursuit.purescript.org/packages/purescript-node-event-emitter/3.0.0/docs/Node.EventEmitter for more details. 72 | 73 | `onSignal` has many possible enumerations, so a generic one was provided instead: 74 | ```purs 75 | -- Before 76 | onSignalExit SIGTERM do 77 | ... 78 | 79 | -- After 80 | process # on_ (mkSignalH SIGTERM) do 81 | ... 82 | -- Or, is `Signal` doesn't have it 83 | process # on_ (mkSignalH' "SIGTERM") do 84 | ... 85 | ``` 86 | 87 | New features: 88 | - Add missing APIs (#39 by @JordanMartinez) 89 | 90 | - Process-related things 91 | - `abort` 92 | - `setExitCode` 93 | - `getExitCode` 94 | - `kill`/`killStr`/`kilInt` 95 | - `nextTick'` 96 | - `ppid` 97 | - Uncaught exception capture callback 98 | - `hasUncaughtExceptionCaptureCallback` 99 | - `setUncaughtExceptionCaptureCallback` 100 | - `clearUncaughtExceptionCaptureCallback` 101 | - `getTitle`/`setTitle` 102 | - ChildProcess-related things 103 | - `channelRef`/`channelUnref` 104 | - `connected` 105 | - `unsafeSend`/`unsafeSendOpts`/`unsafeSendCb`/`unsafeSendOptsCb` 106 | - Diagnostic-related things 107 | - `config` 108 | - `cpuUsage`/`cpuUsageDiff` 109 | - `debugPort` 110 | - `memoryUsage`/`memoryUsageRss` 111 | - `resourceUsage` 112 | - `uptime` 113 | 114 | Bugfixes: 115 | - Docs: discourage `exit` in favor of `setExitCode` (#39 by @JordanMartinez) 116 | 117 | Other improvements: 118 | - Bumped CI's node version to `lts/*` (#37 by @JordanMartinez) 119 | - Updated CI `actions/checkout` and `actions/setup-nodee` to `v3` (#37 by @JordanMartinez) 120 | - Format codebase & enforce formatting in CI via purs-tidy (#37 by @JordanMartinez) 121 | - Use uncurried FFI (#38 by @JordanMartinez) 122 | - Reordered export list (#39 by @JordanMartinez) 123 | 124 | ## [v10.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v10.0.0) - 2022-04-29 125 | 126 | Breaking changes: 127 | - Update project and deps to PureScript v0.15.0 (#34 by @nwolverson, @JordanMartinez, @sigma-andex) 128 | 129 | New features: 130 | 131 | Bugfixes: 132 | 133 | Other improvements: 134 | 135 | ## [v9.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v9.0.0) - 2022-04-27 136 | 137 | Due to implementing a breaking change incorrectly, use v10.0.0 instead. 138 | 139 | ## [v8.2.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v8.2.0) - 2021-05-06 140 | 141 | New features: 142 | - Export `nextTick` (#32 by @JordanMartinez) 143 | 144 | Other improvements: 145 | - Fix warnings revealed by v0.14.1 PS release (#32 by @JordanMartinez) 146 | 147 | ## [v8.1.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v8.1.0) - 2021-03-19 148 | 149 | New features: 150 | - Added `stdinIsTTY` as the counterpart of `process.stdin.isTTY` (#31 by @matoruru) 151 | 152 | ## [v8.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v8.0.0) - 2021-02-26 153 | 154 | Breaking changes: 155 | - Added support for PureScript 0.14 and dropped support for all previous versions (#24) 156 | 157 | New features: 158 | - Added functions to register handlers for the `uncaughtException` and `unhandledRejection` events on the process (#20) 159 | - Added `unsetEnv` for deleting environment variables (#21) 160 | 161 | Bugfixes: 162 | - Updated the implementations of `argv`, `execArgv`, and `getEnv` so they clone the argument array to ensure referential transparency (#26) 163 | 164 | Other improvements: 165 | - Migrated CI to GitHub Actions, updated installation instructions to use Spago, and migrated from `jshint` to `eslint` (#22) 166 | - Added a changelog and pull request template (#27) 167 | 168 | ## [v7.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v7.0.0) - 2019-03-15 169 | 170 | - Updated `purescript-foreign-object` dependency 171 | 172 | ## [v6.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v6.0.0) - 2018-05-29 173 | 174 | - Updated for 0.12 175 | 176 | ## [v5.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v5.0.0) - 2017-08-04 177 | 178 | - Added `OpenBSD`, `Android`, and `AIX` to `Platform` constructors (@AlexanderAA) 179 | - Made `Node.Process.platform` return a `Maybe Platform` to avoid crashes on unrecognised operating systems 180 | - Used `exception :: EXCEPTION` where appropriate instead of the previous `err :: EXCEPTION` to bring this library into line with the types used in recent versions of `purescript-exceptions` (@nwolverson) 181 | 182 | ## [v4.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v4.0.0) - 2017-04-05 183 | 184 | - Updated for 0.11 compiler (@simonyangme) 185 | 186 | ## [v3.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v3.0.0) - 2016-10-22 187 | 188 | - Updated dependencies 189 | 190 | ## [v2.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v2.0.0) - 2016-07-31 191 | 192 | - Updated dependencies 193 | 194 | ## [v1.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v1.0.0) - 2016-06-12 195 | 196 | - Compatibility with 0.9.x of the compiler. 197 | 198 | ## [v0.5.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v0.5.0) - 2016-03-31 199 | 200 | - Bumped dependencies 201 | 202 | ## [v0.1.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v0.1.0) - 2015-12-04 203 | 204 | - Initial release 205 | -------------------------------------------------------------------------------- /src/Node/Process.purs: -------------------------------------------------------------------------------- 1 | -- | Bindings to the global `process` object in Node.js. See also [the Node API documentation](https://nodejs.org/api/process.html) 2 | module Node.Process 3 | ( Process 4 | , process 5 | , beforeExitH 6 | , disconnectH 7 | , exitH 8 | , messageH 9 | , rejectionHandledH 10 | , uncaughtExceptionH 11 | , unhandledRejectionH 12 | , mkSignalH 13 | , mkSignalH' 14 | , warningH 15 | , workerH 16 | , abort 17 | , argv 18 | , argv0 19 | , channelRef 20 | , channelUnref 21 | , chdir 22 | , config 23 | , connected 24 | , CpuUsage 25 | , cpuUsageToRecord 26 | , cpuUsage 27 | , cpuUsageDiff 28 | , cwd 29 | , debugPort 30 | , disconnect 31 | , getEnv 32 | , lookupEnv 33 | , setEnv 34 | , unsetEnv 35 | , execArgv 36 | , execPath 37 | , exit 38 | , exit' 39 | , setExitCode 40 | , getExitCode 41 | , getGid 42 | , getUid 43 | , hasUncaughtExceptionCaptureCallback 44 | , kill 45 | , killStr 46 | , killInt 47 | , MemoryUsage 48 | , memoryUsage 49 | , memoryUsageRss 50 | , nextTick 51 | , nextTick' 52 | , pid 53 | , platform 54 | , platformStr 55 | , ppid 56 | , ResourceUsage 57 | , resourceUsage 58 | , unsafeSend 59 | , JsSendOptions 60 | , unsafeSendOpts 61 | , unsafeSendCb 62 | , unsafeSendOptsCb 63 | , setUncaughtExceptionCaptureCallback 64 | , clearUncaughtExceptionCaptureCallback 65 | , stdin 66 | , stdout 67 | , stderr 68 | , stdinIsTTY 69 | , stdoutIsTTY 70 | , stderrIsTTY 71 | , getTitle 72 | , setTitle 73 | , uptime 74 | , version 75 | ) where 76 | 77 | import Prelude 78 | 79 | import Data.Maybe (Maybe) 80 | import Data.Nullable (Nullable, toMaybe) 81 | import Data.Posix (Gid, Pid, Uid) 82 | import Data.Posix.Signal (Signal) 83 | import Data.Posix.Signal as Signal 84 | import Data.String as String 85 | import Effect (Effect) 86 | import Effect.Exception (Error) 87 | import Effect.Uncurried (EffectFn1, EffectFn2, EffectFn3, EffectFn4, mkEffectFn1, mkEffectFn2, runEffectFn1, runEffectFn2, runEffectFn3, runEffectFn4) 88 | import Foreign (Foreign) 89 | import Foreign.Object as FO 90 | import Node.EventEmitter (EventHandle(..)) 91 | import Node.EventEmitter.UtilTypes (EventHandle0, EventHandle1, EventHandle2) 92 | import Node.Platform (Platform) 93 | import Node.Platform as Platform 94 | import Node.Stream (Readable, Writable) 95 | import Prim.Row as Row 96 | 97 | foreign import data Process :: Type 98 | 99 | foreign import process :: Process 100 | 101 | -- | The 'beforeExit' event is emitted when Node.js empties its event loop and has no additional work to schedule. 102 | -- | Normally, the Node.js process will exit when there is no work scheduled, but a listener registered on the 103 | -- | 'beforeExit' event can make asynchronous calls, and thereby cause the Node.js process to continue. 104 | -- | 105 | -- | The listener callback function is invoked with the value of process.exitCode passed as the only argument. 106 | -- | The 'beforeExit' event is not emitted for conditions causing explicit termination, 107 | -- | such as calling `process.exit()` or uncaught exceptions. 108 | -- | The 'beforeExit' should not be used as an alternative to the 'exit' event unless the 109 | -- | intention is to schedule additional work. 110 | beforeExitH :: EventHandle1 Process Int 111 | beforeExitH = EventHandle "beforeExit" mkEffectFn1 112 | 113 | disconnectH :: EventHandle0 Process 114 | disconnectH = EventHandle "disconnect" identity 115 | 116 | -- | The 'exit' event is emitted when the Node.js process is about to exit as a result of either: 117 | -- | - The process.exit() method being called explicitly; 118 | -- | - The Node.js event loop no longer having any additional work to perform. 119 | -- | 120 | -- | Listener functions **must** only perform **synchronous** operations. 121 | -- | The Node.js process will exit immediately after calling the 'exit' event listeners causing 122 | -- | any additional work still queued in the event loop to be abandoned. 123 | -- | (Maintainer note: I believe the above translates to 124 | -- | "Only synchronous (i.e. `Effect`) code can be run in the resulting handler. 125 | -- | If you need asynchronous (i.e. `Aff`) code, use `beforeExitH`.") 126 | -- | 127 | -- | There is no way to prevent the exiting of the event loop at this point, and once all 'exit' 128 | -- | listeners have finished running the Node.js process will terminate. 129 | -- | The listener callback function is invoked with the exit code specified either by the 130 | -- | `process.exitCode` property, or the exitCode argument passed to the `process.exit()` method. 131 | exitH :: EventHandle1 Process Int 132 | exitH = EventHandle "exit" mkEffectFn1 133 | 134 | messageH :: EventHandle Process (Foreign -> Maybe Foreign -> Effect Unit) (EffectFn2 Foreign (Nullable Foreign) Unit) 135 | messageH = EventHandle "message" \cb -> mkEffectFn2 \a b -> cb a (toMaybe b) 136 | 137 | -- | The 'rejectionHandled' event is emitted whenever a Promise has been rejected and an error handler was attached to it (using promise.catch(), for example) later than one turn of the Node.js event loop. 138 | -- | 139 | -- | The Promise object would have previously been emitted in an 'unhandledRejection' event, but during the course of processing gained a rejection handler. 140 | -- | 141 | -- | There is no notion of a top level for a Promise chain at which rejections can always be handled. Being inherently asynchronous in nature, a Promise rejection can be handled at a future point in time, possibly much later than the event loop turn it takes for the 'unhandledRejection' event to be emitted. 142 | -- | 143 | -- | Another way of stating this is that, unlike in synchronous code where there is an ever-growing list of unhandled exceptions, with Promises there can be a growing-and-shrinking list of unhandled rejections. 144 | -- | 145 | -- | In synchronous code, the 'uncaughtException' event is emitted when the list of unhandled exceptions grows. 146 | -- | 147 | -- | In asynchronous code, the 'unhandledRejection' event is emitted when the list of unhandled rejections grows, and the 'rejectionHandled' event is emitted when the list of unhandled rejections shrinks. 148 | rejectionHandledH :: EventHandle1 Process Foreign 149 | rejectionHandledH = EventHandle "rejectionHandled" mkEffectFn1 150 | 151 | -- | Args: 152 | -- | - `err` The uncaught exception. 153 | -- | - `origin` Indicates if the exception originates from an unhandled rejection or from a synchronous error. 154 | -- | Can either be 'uncaughtException' or 'unhandledRejection'. 155 | -- | The latter is used when an exception happens in a Promise based async context (or if a Promise is rejected) 156 | -- | and `--unhandled-rejections` flag set to `strict` or `throw` (which is the default) and 157 | -- | the rejection is not handled, or when a rejection happens during the command line entry point's 158 | -- | ES module static loading phase. 159 | -- | 160 | -- | The 'uncaughtException' event is emitted when an uncaught JavaScript exception bubbles 161 | -- | all the way back to the event loop. By default, Node.js handles such exceptions 162 | -- | by printing the stack trace to `stderr` and exiting with code 1, 163 | -- | overriding any previously set `process.exitCode`. 164 | -- | Adding a handler for the 'uncaughtException' event overrides this default behavior. 165 | -- | Alternatively, change the process.exitCode in the 'uncaughtException' handler which will 166 | -- | result in the process exiting with the provided exit code. Otherwise, in the presence of 167 | -- | such handler the process will exit with 0. 168 | -- | 169 | -- | 'uncaughtException' is a crude mechanism for exception handling intended to be used only as a last resort. The event should not be used as an equivalent to On Error Resume Next. Unhandled exceptions inherently mean that an application is in an undefined state. Attempting to resume application code without properly recovering from the exception can cause additional unforeseen and unpredictable issues. 170 | -- | 171 | -- | Exceptions thrown from within the event handler will not be caught. Instead the process will exit with a non-zero exit code and the stack trace will be printed. This is to avoid infinite recursion. 172 | -- | 173 | -- | Attempting to resume normally after an uncaught exception can be similar to pulling out the power cord when upgrading a computer. Nine out of ten times, nothing happens. But the tenth time, the system becomes corrupted. 174 | -- | 175 | -- | The correct use of 'uncaughtException' is to perform synchronous cleanup of allocated resources (e.g. file descriptors, handles, etc) before shutting down the process. It is not safe to resume normal operation after 'uncaughtException'. 176 | -- | 177 | -- | To restart a crashed application in a more reliable way, whether 'uncaughtException' is emitted or not, an external monitor should be employed in a separate process to detect application failures and recover or restart as needed. 178 | uncaughtExceptionH :: EventHandle2 Process Error String 179 | uncaughtExceptionH = EventHandle "uncaughtException" \cb -> mkEffectFn2 \a b -> cb a b 180 | 181 | -- | Args: 182 | -- | - `reason` | The object with which the promise was rejected (typically an Error object). 183 | -- | - `promise` The rejected promise. 184 | -- | 185 | -- | The 'unhandledRejection' event is emitted whenever a Promise is rejected and no error handler is attached to the promise within a turn of the event loop. When programming with Promises, exceptions are encapsulated as "rejected promises". Rejections can be caught and handled using promise.catch() and are propagated through a Promise chain. The 'unhandledRejection' event is useful for detecting and keeping track of promises that were rejected whose rejections have not yet been handled. 186 | unhandledRejectionH :: EventHandle2 Process Foreign Foreign 187 | unhandledRejectionH = EventHandle "unhandledRejection" \cb -> mkEffectFn2 \a b -> cb a b 188 | 189 | -- | Args: 190 | -- | - `warning` Key properties of the warning are: 191 | -- | - `name` The name of the warning. Default: 'Warning'. 192 | -- | - `message` A system-provided description of the warning. 193 | -- | - `stack` A stack trace to the location in the code where the warning was issued. 194 | -- | 195 | -- | The 'warning' event is emitted whenever Node.js emits a process warning. 196 | -- | 197 | -- | A process warning is similar to an error in that it describes exceptional conditions that are being brought to the user's attention. However, warnings are not part of the normal Node.js and JavaScript error handling flow. Node.js can emit warnings whenever it detects bad coding practices that could lead to sub-optimal application performance, bugs, or security vulnerabilities. 198 | -- | By default, Node.js will print process warnings to stderr. The --no-warnings command-line option can be used to suppress the default console output but the 'warning' event will still be emitted by the process object. 199 | warningH :: EventHandle1 Process Error 200 | warningH = EventHandle "warning" mkEffectFn1 201 | 202 | -- | Args: 203 | -- | - `worker` The that was created. 204 | -- | 205 | -- | The 'worker' event is emitted after a new thread has been created. 206 | workerH :: EventHandle1 Process Foreign 207 | workerH = EventHandle "worker" mkEffectFn1 208 | 209 | -- | Rather than support an `EventHandle` for every possible `Signal`, 210 | -- | this function provides one a convenient way for constructing one for any given signal. 211 | -- | 212 | -- | See Node docs: https://nodejs.org/dist/latest-v18.x/docs/api/process.html#signal-events 213 | mkSignalH :: Signal -> EventHandle Process (Effect Unit) (Effect Unit) 214 | mkSignalH sig = EventHandle (Signal.toString sig) identity 215 | 216 | -- | Same as `mkSignalH` but allows for more options in case the `Signal` ADT is missing any. 217 | -- | 218 | -- | See Node docs: https://nodejs.org/dist/latest-v18.x/docs/api/process.html#signal-events 219 | mkSignalH' :: String -> EventHandle Process (Effect Unit) (Effect Unit) 220 | mkSignalH' sig = EventHandle (String.toUpper sig) identity 221 | 222 | -- | The `process.abort()` method causes the Node.js process to exit immediately and generate a core file. 223 | -- | This feature is not available in Worker threads. 224 | abort :: Maybe (Effect Unit) 225 | abort = toMaybe abortImpl 226 | 227 | foreign import abortImpl :: Nullable (Effect Unit) 228 | 229 | -- | Get a copy of the array containing the command line arguments. 230 | foreign import argv :: Effect (Array String) 231 | 232 | -- | The process.argv0 property stores a read-only copy of the original value of argv[0] passed when Node.js starts. 233 | foreign import argv0 :: Effect String 234 | 235 | -- | This method makes the IPC channel keep the event loop of the process running if .unref() has been called before. 236 | -- | Typically, this is managed through the number of 'disconnect' and 'message' listeners on the process object. 237 | -- | However, this method can be used to explicitly request a specific behavior. 238 | -- | 239 | -- | Context: if the Node.js process was spawned with an IPC channel (see the Child Process documentation), 240 | -- | the process.channel property is a reference to the IPC channel. If no IPC channel exists, this property is undefined. 241 | channelRef :: Maybe (Effect Unit) 242 | channelRef = toMaybe channelRefImpl 243 | 244 | foreign import channelRefImpl :: Nullable (Effect Unit) 245 | 246 | -- | This method makes the IPC channel not keep the event loop of the process running, 247 | -- | and lets it finish even while the channel is open. 248 | -- | Typically, this is managed through the number of 'disconnect' and 'message' listeners on the process object. 249 | -- | However, this method can be used to explicitly request a specific behavior. 250 | -- | 251 | -- | Context: if the Node.js process was spawned with an IPC channel (see the Child Process documentation), 252 | -- | the process.channel property is a reference to the IPC channel. If no IPC channel exists, this property is undefined. 253 | channelUnref :: Maybe (Effect Unit) 254 | channelUnref = toMaybe channelUnrefImpl 255 | 256 | foreign import channelUnrefImpl :: Nullable (Effect Unit) 257 | 258 | -- | Change the current working directory of the process. If the current 259 | -- | directory could not be changed, an exception will be thrown. 260 | chdir :: String -> Effect Unit 261 | chdir dir = runEffectFn1 chdirImpl dir 262 | 263 | foreign import chdirImpl :: EffectFn1 (String) (Unit) 264 | 265 | -- | Returns a copy of the Config value. 266 | -- | The process.config property returns an Object containing the JavaScript representation of the configure options used to compile the current Node.js executable. 267 | -- | This is the same as the config.gypi file that was produced when running the ./configure script. 268 | foreign import config :: Effect (Foreign) 269 | 270 | -- | If the Node.js process is spawned with an IPC channel (see the Child Process and Cluster documentation), the process.connected property will return true so long as the IPC channel is connected and will return false after process.disconnect() is called. 271 | -- | Once process.connected is false, it is no longer possible to send messages over the IPC channel using process.send(). 272 | foreign import connected :: Effect (Boolean) 273 | 274 | newtype CpuUsage = CpuUsage { user :: Int, system :: Int } 275 | 276 | derive instance Eq CpuUsage 277 | instance Show CpuUsage where 278 | show (CpuUsage r) = "(CpuUsage " <> show r <> ")" 279 | 280 | cpuUsageToRecord :: CpuUsage -> { user :: Int, system :: Int } 281 | cpuUsageToRecord (CpuUsage r) = r 282 | 283 | foreign import cpuUsage :: Effect (CpuUsage) 284 | 285 | cpuUsageDiff :: CpuUsage -> Effect CpuUsage 286 | cpuUsageDiff prev = runEffectFn1 cpuUsageDiffImpl prev 287 | 288 | foreign import cpuUsageDiffImpl :: EffectFn1 (CpuUsage) (CpuUsage) 289 | 290 | -- | Get the current working directory of the process. 291 | foreign import cwd :: Effect (String) 292 | 293 | foreign import debugPort :: Int 294 | 295 | -- | If the Node.js process is spawned with an IPC channel (see the Child Process and Cluster documentation), the process.disconnect() method will close the IPC channel to the parent process, allowing the child process to exit gracefully once there are no other connections keeping it alive. 296 | -- | The effect of calling process.disconnect() is the same as calling ChildProcess.disconnect() from the parent process. 297 | -- | 298 | -- | If the Node.js process was not spawned with an IPC channel, process.disconnect() will be undefined. 299 | disconnect :: Maybe (Effect Unit) 300 | disconnect = toMaybe disconnectImpl 301 | 302 | foreign import disconnectImpl :: Nullable (Effect Unit) 303 | 304 | -- | Get a copy of the current environment. 305 | -- | If you only want to look up a value without paying 306 | -- | for the overhead of the copy, use `lookupEnv`. 307 | foreign import getEnv :: Effect (FO.Object String) 308 | 309 | -- | Get the current environment object without copying it. 310 | -- | Any mutations to the returned object 311 | -- | or any mutations via `unsetEnv` and `setEnv` 312 | -- | will affect all values that were obtained 313 | -- | via this function. 314 | -- | Thus, this is an internal function that is 315 | -- | not exported. 316 | foreign import unsafeGetEnv :: Effect (FO.Object String) 317 | 318 | -- | Lookup a particular environment variable. 319 | lookupEnv :: String -> Effect (Maybe String) 320 | lookupEnv k = map (FO.lookup k) $ unsafeGetEnv 321 | 322 | -- | Set an environment variable. 323 | setEnv :: String -> String -> Effect Unit 324 | setEnv key value = runEffectFn2 setEnvImpl key value 325 | 326 | foreign import setEnvImpl :: EffectFn2 (String) (String) (Unit) 327 | 328 | -- | Delete an environment variable. 329 | -- | Use case: to hide secret environment variable from child processes. 330 | unsetEnv :: String -> Effect Unit 331 | unsetEnv key = runEffectFn1 unsetEnvImpl key 332 | 333 | foreign import unsetEnvImpl :: EffectFn1 (String) (Unit) 334 | 335 | -- | Get a copy of the Node-specific options passed to the `node` executable. 336 | foreign import execArgv :: Effect (Array String) 337 | 338 | -- | The absolute pathname of the `node` executable that started the 339 | -- | process. 340 | foreign import execPath :: Effect (String) 341 | 342 | -- | Cause the process to exit immediately without completing any pending asynchronous operations 343 | -- | including I/O operations to `process.stdout` and `process.stderr`. 344 | -- | Process will exit with the `process.exitCode` value if it has been set 345 | -- | or `0` (i.e. exit successfully) otherwise. 346 | -- | 347 | -- | Rather than using this function to exit, one should set `process.exitCode` and 348 | -- | let Node gracefully exit once all pending asynchronous operations have completed. 349 | -- | If it is necessary to terminate the Node.js process due to an error condition, 350 | -- | throwing an uncaught error and allowing the process to terminate accordingly 351 | -- | is safer than calling process.exit(). 352 | foreign import exit :: forall a. Effect a 353 | 354 | -- | Cause the process to exit immediately without completing any pending asynchronous operations 355 | -- | including I/O operations to `process.stdout` and `process.stderr`. 356 | -- | An exit code of 0 is normally considered successful, and anything else is considered a 357 | -- | failure. 358 | -- | 359 | -- | Rather than using this function to exit, one should set `process.exitCode` and 360 | -- | let Node gracefully exit once all pending asynchronous operations have completed. 361 | -- | If it is necessary to terminate the Node.js process due to an error condition, 362 | -- | throwing an uncaught error and allowing the process to terminate accordingly 363 | -- | is safer than calling process.exit(). 364 | exit' :: forall a. Int -> Effect a 365 | exit' code = runEffectFn1 exitImpl code 366 | 367 | foreign import exitImpl :: forall a. EffectFn1 (Int) (a) 368 | 369 | -- | Sets the exit code to use when the process exits. 370 | -- | An exit code of 0 is normally considered successful, and anything else is considered a 371 | -- | failure. 372 | -- | 373 | -- | In comparison to `exit`/`exit'`, this is the safer way 374 | -- | to exit a Node.js process because any pending asynchronous operations 375 | -- | including I/O operations to `process.stdout` and `process.stderr` 376 | -- | will complete before the `Node.js` process exits. 377 | setExitCode :: Int -> Effect Unit 378 | setExitCode code = runEffectFn1 setExitCodeImpl code 379 | 380 | foreign import setExitCodeImpl :: EffectFn1 (Int) (Unit) 381 | 382 | -- | Gets the currently set exit code. This will be `Nothing` 383 | -- | if the exit code has not been previously set. 384 | getExitCode :: Effect (Maybe Int) 385 | getExitCode = map toMaybe getExitCodeImpl 386 | 387 | foreign import getExitCodeImpl :: Effect (Nullable Int) 388 | 389 | getGid :: Effect (Maybe Gid) 390 | getGid = map toMaybe getGidImpl 391 | 392 | foreign import getGidImpl :: Effect (Nullable Gid) 393 | 394 | getUid :: Effect (Maybe Uid) 395 | getUid = map toMaybe getUidImpl 396 | 397 | foreign import getUidImpl :: Effect (Nullable Uid) 398 | 399 | foreign import hasUncaughtExceptionCaptureCallback :: Effect (Boolean) 400 | 401 | kill :: Pid -> Effect Unit 402 | kill p = runEffectFn1 killImpl p 403 | 404 | foreign import killImpl :: EffectFn1 (Pid) (Unit) 405 | 406 | killStr :: Pid -> String -> Effect Unit 407 | killStr p sig = runEffectFn2 killStrImpl p sig 408 | 409 | foreign import killStrImpl :: EffectFn2 (Pid) (String) (Unit) 410 | 411 | killInt :: Pid -> Int -> Effect Unit 412 | killInt p sig = runEffectFn2 killIntImpl p sig 413 | 414 | foreign import killIntImpl :: EffectFn2 (Pid) (Int) (Unit) 415 | 416 | -- | - `heapTotal` and `heapUsed` refer to V8's memory usage. 417 | -- | - `external` refers to the memory usage of C++ objects bound to JavaScript objects managed by V8. 418 | -- | - `rss`, Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the process, including all C++ and JavaScript objects and code. 419 | -- | - `arrayBuffers` refers to memory allocated for ArrayBuffers and SharedArrayBuffers, including all Node.js Buffers. This is also included in the external value. When Node.js is used as an embedded library, this value may be 0 because allocations for ArrayBuffers may not be tracked in that case. 420 | type MemoryUsage = 421 | { rss :: Int 422 | , heapTotal :: Int 423 | , heapUsed :: Int 424 | , external :: Int 425 | , arrayBuffers :: Int 426 | } 427 | 428 | -- | Returns an object describing the memory usage of the Node.js process measured in bytes. 429 | -- | When using Worker threads, `rss` will be a value that is valid for the entire process, while the other fields will only refer to the current thread. 430 | -- | The process.memoryUsage() method iterates over each page to gather information about memory usage which might be slow depending on the program memory allocations. 431 | -- | 432 | -- | Note: if one just wants the `rss` value, use `memoryUsageRss`, which is faster to compute. 433 | foreign import memoryUsage :: Effect (MemoryUsage) 434 | 435 | -- | The process.memoryUsage.rss() method returns an integer representing the Resident Set Size (RSS) in bytes. 436 | -- | The Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the process, including all C++ and JavaScript objects and code. 437 | -- | This is the same value as the rss property provided by process.memoryUsage() but process.memoryUsage.rss() is faster. 438 | foreign import memoryUsageRss :: Effect Int 439 | 440 | -- | Register a callback to run as soon as the current event loop runs to 441 | -- | completion. 442 | -- | One should use `queueMicroTask` instead for most situations instead of `nextTick`. 443 | -- | See Node docs for more info. 444 | nextTick :: Effect Unit -> Effect Unit 445 | nextTick cb = runEffectFn1 nextTickImpl cb 446 | 447 | foreign import nextTickImpl :: EffectFn1 (Effect Unit) (Unit) 448 | 449 | -- | Register a callback that will receive the record arg as an argument 450 | -- | to run as soon as the current event loop runs to completion. 451 | -- | One should use `queueMicroTask` instead for most situations instead of `nextTick`. 452 | -- | See Node docs for more info. 453 | nextTick' :: forall r. ({ | r } -> Effect Unit) -> { | r } -> Effect Unit 454 | nextTick' cb args = runEffectFn2 nextTickCbImpl (mkEffectFn1 cb) args 455 | 456 | foreign import nextTickCbImpl :: forall r. EffectFn2 (EffectFn1 { | r } Unit) ({ | r }) (Unit) 457 | 458 | -- | Returns the PID of the current process. 459 | foreign import pid :: Pid 460 | 461 | platform :: Maybe Platform 462 | platform = Platform.fromString platformStr 463 | 464 | foreign import platformStr :: String 465 | 466 | -- | Returns the PID of the parent of the current process. 467 | foreign import ppid :: Pid 468 | 469 | -- | - `userCPUTime` maps to ru_utime computed in microseconds. It is the same value as process.cpuUsage().user. 470 | -- | - `systemCPUTime` maps to ru_stime computed in microseconds. It is the same value as process.cpuUsage().system. 471 | -- | - `maxRSS` maps to ru_maxrss which is the maximum resident set size used in kilobytes. 472 | -- | - `sharedMemorySize` maps to ru_ixrss but is not supported by any platform. 473 | -- | - `unsharedDataSize` maps to ru_idrss but is not supported by any platform. 474 | -- | - `unsharedStackSize` maps to ru_isrss but is not supported by any platform. 475 | -- | - `minorPageFault` maps to ru_minflt which is the number of minor page faults for the process, see this article for more details. 476 | -- | - `majorPageFault` maps to ru_majflt which is the number of major page faults for the process, see this article for more details. This field is not supported on Windows. 477 | -- | - `swappedOut` maps to ru_nswap but is not supported by any platform. 478 | -- | - `fsRead` maps to ru_inblock which is the number of times the file system had to perform input. 479 | -- | - `fsWrite` maps to ru_oublock which is the number of times the file system had to perform output. 480 | -- | - `ipcSent` maps to ru_msgsnd but is not supported by any platform. 481 | -- | - `ipcReceived` maps to ru_msgrcv but is not supported by any platform. 482 | -- | - `signalsCount` maps to ru_nsignals but is not supported by any platform. 483 | -- | - `voluntaryContextSwitches` maps to ru_nvcsw which is the number of times a CPU context switch resulted due to a process voluntarily giving up the processor before its time slice was completed (usually to await availability of a resource). This field is not supported on Windows. 484 | -- | - `involuntaryContextSwitches` maps to ru_nivcsw which is the number of times a CPU context switch resulted due to a higher priority process becoming runnable or because the current process exceeded its time slice. This field is not supported on Windows. 485 | 486 | type ResourceUsage = 487 | { userCPUTime :: Int 488 | , systemCPUTime :: Int 489 | , maxRSS :: Int 490 | , sharedMemorySize :: Int 491 | , unsharedDataSize :: Int 492 | , unsharedStackSize :: Int 493 | , minorPageFault :: Int 494 | , majorPageFault :: Int 495 | , swappedOut :: Int 496 | , fsRead :: Int 497 | , fsWrite :: Int 498 | , ipcSent :: Int 499 | , ipcReceived :: Int 500 | , signalsCount :: Int 501 | , voluntaryContextSwitches :: Int 502 | , involuntaryContextSwitches :: Int 503 | } 504 | 505 | foreign import resourceUsage :: Effect (ResourceUsage) 506 | 507 | -- | Unsafe because child process must be a Node child process and an IPC channel must exist. 508 | unsafeSend :: forall messageRows. { | messageRows } -> Nullable Foreign -> Effect Boolean 509 | unsafeSend msg handle = runEffectFn2 sendImpl msg handle 510 | 511 | foreign import sendImpl :: forall messageRows. EffectFn2 ({ | messageRows }) (Nullable Foreign) (Boolean) 512 | 513 | -- | - `keepAlive` A value that can be used when passing instances of `net.Socket` as the `Handle`. When true, the socket is kept open in the sending process. Default: false. 514 | type JsSendOptions = 515 | ( keepAlive :: Boolean 516 | ) 517 | 518 | -- | Unsafe because process must be a Node child process and an IPC channel must exist. 519 | unsafeSendOpts 520 | :: forall r trash messageRows 521 | . Row.Union r trash JsSendOptions 522 | => { | messageRows } 523 | -> Nullable Foreign 524 | -> { | r } 525 | -> Effect Boolean 526 | unsafeSendOpts msg handle opts = runEffectFn3 sendOptsImpl msg handle opts 527 | 528 | foreign import sendOptsImpl :: forall messageRows r. EffectFn3 ({ | messageRows }) (Nullable Foreign) ({ | r }) (Boolean) 529 | 530 | -- | Unsafe because process must be a Node child process and an IPC channel must exist. 531 | unsafeSendCb 532 | :: forall messageRows 533 | . { | messageRows } 534 | -> Nullable Foreign 535 | -> (Maybe Error -> Effect Unit) 536 | -> Effect Boolean 537 | unsafeSendCb msg handle cb = runEffectFn3 sendCbImpl msg handle $ mkEffectFn1 \err -> cb $ toMaybe err 538 | 539 | foreign import sendCbImpl :: forall messageRows. EffectFn3 ({ | messageRows }) (Nullable Foreign) (EffectFn1 (Nullable Error) Unit) (Boolean) 540 | 541 | -- | Unsafe because process must be a Node child process and an IPC channel must exist. 542 | unsafeSendOptsCb 543 | :: forall r trash messageRows 544 | . Row.Union r trash JsSendOptions 545 | => { | messageRows } 546 | -> Nullable Foreign 547 | -> { | r } 548 | -> (Maybe Error -> Effect Unit) 549 | -> Effect Boolean 550 | unsafeSendOptsCb msg handle opts cb = runEffectFn4 sendOptsCbImpl msg handle opts $ mkEffectFn1 \err -> cb $ toMaybe err 551 | 552 | foreign import sendOptsCbImpl :: forall messageRows r. EffectFn4 ({ | messageRows }) (Nullable Foreign) ({ | r }) (EffectFn1 (Nullable Error) Unit) (Boolean) 553 | 554 | setUncaughtExceptionCaptureCallback :: Effect Unit -> Effect Unit 555 | setUncaughtExceptionCaptureCallback cb = runEffectFn1 setUncaughtExceptionCaptureCallbackImpl cb 556 | 557 | foreign import setUncaughtExceptionCaptureCallbackImpl :: EffectFn1 (Effect Unit) (Unit) 558 | 559 | foreign import clearUncaughtExceptionCaptureCallback :: Effect Unit 560 | 561 | -- | The standard input stream. Note that this stream will never emit an `end` 562 | -- | event, so any handlers attached via `onEnd` will never be called. 563 | foreign import stdin :: Readable () 564 | 565 | -- | The standard output stream. Note that this stream cannot be closed; calling 566 | -- | `end` will result in an exception being thrown. 567 | foreign import stdout :: Writable () 568 | 569 | -- | The standard error stream. Note that this stream cannot be closed; calling 570 | -- | `end` will result in an exception being thrown. 571 | foreign import stderr :: Writable () 572 | 573 | -- | Check whether the standard input stream appears to be attached to a TTY. 574 | -- | It is a good idea to check this before processing the input data from stdin. 575 | foreign import stdinIsTTY :: Boolean 576 | 577 | -- | Check whether the standard output stream appears to be attached to a TTY. 578 | -- | It is a good idea to check this before printing ANSI codes to stdout 579 | -- | (e.g. for coloured text in the terminal). 580 | foreign import stdoutIsTTY :: Boolean 581 | 582 | -- | Check whether the standard error stream appears to be attached to a TTY. 583 | -- | It is a good idea to check this before printing ANSI codes to stderr 584 | -- | (e.g. for coloured text in the terminal). 585 | foreign import stderrIsTTY :: Boolean 586 | 587 | -- | The process.title property returns the current process title (i.e. returns the current value of ps). 588 | foreign import getTitle :: Effect (String) 589 | 590 | -- | The process.title property returns the current process title (i.e. returns the current value of ps). 591 | -- | Assigning a new value to process.title modifies the current value of ps. 592 | -- | 593 | -- | When a new value is assigned, different platforms will impose different maximum length restrictions 594 | -- | on the title. Usually such restrictions are quite limited. For instance, on Linux and macOS, 595 | -- | process.title is limited to the size of the binary name plus the length of the command-line arguments 596 | -- | because setting the process.title overwrites the argv memory of the process. 597 | -- | Node.js v0.8 allowed for longer process title strings by also overwriting the environ memory but 598 | -- | that was potentially insecure and confusing in some (rather obscure) cases. 599 | -- | 600 | -- | Assigning a value to process.title might not result in an accurate label within process manager 601 | -- | applications such as macOS Activity Monitor or Windows Services Manager. 602 | setTitle :: String -> Effect Unit 603 | setTitle newTitle = runEffectFn1 setTitleImpl newTitle 604 | 605 | foreign import setTitleImpl :: EffectFn1 (String) (Unit) 606 | 607 | -- | The process.uptime() method returns the number of seconds the current Node.js process has been running. 608 | -- | The return value includes fractions of a second. Use `Data.Int.floor` to get whole seconds. 609 | foreign import uptime :: Effect (Number) 610 | 611 | -- | Get the Node.js version. 612 | foreign import version :: String 613 | --------------------------------------------------------------------------------