Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: purescript-node/purescript-node-process
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.0.0
Choose a base ref
...
head repository: purescript-node/purescript-node-process
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 6 files changed
  • 1 contributor

Commits on Jul 20, 2023

  1. Prep repo (#37)

    * Update CI node/actions version; add purs-tidy
    
    * Format code via purs-tidy
    
    * Add entry
    JordanMartinez authored Jul 20, 2023
    Copy the full SHA
    183ad05 View commit details

Commits on Jul 21, 2023

  1. Copy the full SHA
    e8c77e9 View commit details
  2. Add missing APIs from v18 (#39)

    * Add dependency on foreign
    
    * Implement missing APIs; break 'exit'
    JordanMartinez authored Jul 21, 2023
    Copy the full SHA
    b0d710e View commit details
  3. Copy the full SHA
    fb0d679 View commit details
  4. Copy the full SHA
    8139d19 View commit details
  5. Fix channel is undefined bug (#42)

    * Fix channel is undefined bug
    
    * Fix entry
    JordanMartinez authored Jul 21, 2023
    Copy the full SHA
    d640163 View commit details

Commits on Jul 25, 2023

  1. Add getUid/getGid (#43)

    * Add more FFI
    
    * Fix PR numbers
    JordanMartinez authored Jul 25, 2023
    Copy the full SHA
    38dcd31 View commit details

Commits on Jul 26, 2023

  1. Fix cwd FFI (#44)

    JordanMartinez authored Jul 26, 2023
    Copy the full SHA
    a41085c View commit details
  2. Copy the full SHA
    02fa21e View commit details
Showing with 728 additions and 191 deletions.
  1. +9 −3 .github/workflows/ci.yml
  2. +109 −0 CHANGELOG.md
  3. +3 −1 bower.json
  4. +16 −16 src/Node/Platform.purs
  5. +62 −67 src/Node/Process.js
  6. +529 −104 src/Node/Process.purs
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -10,15 +10,16 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
purs-tidy: "latest"

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: "lts/*"

- name: Install dependencies
run: |
@@ -33,3 +34,8 @@ jobs:
run: |
bower install
npm run-script test --if-present
- name: Check Formatting
if: runner.os == 'Linux'
run: |
npx purs-tidy check src
109 changes: 109 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -12,6 +12,115 @@ Bugfixes:

Other improvements:

## [v11.2.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.2.0) - 2023-07-25

Bugfixes:
- Update `node-streams` to `v9.0.0` to fix FFI issues (#45 by @JordanMartinez)

## [v11.1.1](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.1.1) - 2023-07-25

Bugfixes:
- Fixes FFI for `cwd` (#44 by @JordanMartinez)

## [v11.1.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.1.0) - 2023-07-24

New Features:
- Add FFI for `getUid`/`getPid` (#43 by @JordanMartinez)

## [v11.0.1](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.0.1) - 2023-07-21

Bugfixes:
- Fix FFI for `channelRef`/`channelUnref` (#42 by @JordanMartinez)

## [v11.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v11.0.0) - 2023-07-21

Breaking changes:
- Breaking changes to `exit` (#39 by @JordanMartinez)

The `exit` API provides two versions:
- unspecified exit code: `process.exit();`
- specified exit code: `process.exit(1);`

Previously, the type signature of `exit` only allowed
the second usage. This change supports both.
Followin the pattern used in other Node libraries
of a `'` (prime) character indicating a
variant of the function that takes a callback or optons
are, the type signature of `exit` has changed:

```purs
-- before:
exit :: forall a. Int -> Effect a
-- after:
exit :: forall a. Effect a
exit' :: forall a. Int -> Effect a
```
- Bump `node-streams` to `v8.0.0` (#40 by @JordanMartinez)
- Migrate `onEventName` to `eventH`-style event handling API (#40 by @JordanMartinez)

```purs
-- Before
onExit \exitCode -> ...
-- After
process # on_ exitH \exitCode ->
```

See https://pursuit.purescript.org/packages/purescript-node-event-emitter/3.0.0/docs/Node.EventEmitter for more details.

`onSignal` has many possible enumerations, so a generic one was provided instead:
```purs
-- Before
onSignalExit SIGTERM do
...
-- After
process # on_ (mkSignalH SIGTERM) do
...
-- Or, is `Signal` doesn't have it
process # on_ (mkSignalH' "SIGTERM") do
...
```

New features:
- Add missing APIs (#39 by @JordanMartinez)

- Process-related things
- `abort`
- `setExitCode`
- `getExitCode`
- `kill`/`killStr`/`kilInt`
- `nextTick'`
- `ppid`
- Uncaught exception capture callback
- `hasUncaughtExceptionCaptureCallback`
- `setUncaughtExceptionCaptureCallback`
- `clearUncaughtExceptionCaptureCallback`
- `getTitle`/`setTitle`
- ChildProcess-related things
- `channelRef`/`channelUnref`
- `connected`
- `unsafeSend`/`unsafeSendOpts`/`unsafeSendCb`/`unsafeSendOptsCb`
- Diagnostic-related things
- `config`
- `cpuUsage`/`cpuUsageDiff`
- `debugPort`
- `memoryUsage`/`memoryUsageRss`
- `resourceUsage`
- `uptime`

Bugfixes:
- Docs: discourage `exit` in favor of `setExitCode` (#39 by @JordanMartinez)

Other improvements:
- Bumped CI's node version to `lts/*` (#37 by @JordanMartinez)
- Updated CI `actions/checkout` and `actions/setup-nodee` to `v3` (#37 by @JordanMartinez)
- Format codebase & enforce formatting in CI via purs-tidy (#37 by @JordanMartinez)
- Use uncurried FFI (#38 by @JordanMartinez)
- Reordered export list (#39 by @JordanMartinez)

## [v10.0.0](https://github.com/purescript-node/purescript-node-process/releases/tag/v10.0.0) - 2022-04-29

Breaking changes:
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -14,8 +14,10 @@
"dependencies": {
"purescript-effect": "^4.0.0",
"purescript-foreign-object": "^4.0.0",
"purescript-foreign": "^7.0.0",
"purescript-maybe": "^6.0.0",
"purescript-node-streams": "^7.0.0",
"purescript-node-event-emitter": "https://github.com/purescript-node/purescript-node-event-emitter.git#^3.0.0",
"purescript-node-streams": "^9.0.0",
"purescript-posix-types": "^6.0.0",
"purescript-prelude": "^6.0.0",
"purescript-unsafe-coerce": "^6.0.0"
32 changes: 16 additions & 16 deletions src/Node/Platform.purs
Original file line number Diff line number Diff line change
@@ -18,36 +18,36 @@ data Platform

-- | The String representation for a platform, recognised by Node.js.
toString :: Platform -> String
toString AIX = "aix"
toString Darwin = "darwin"
toString AIX = "aix"
toString Darwin = "darwin"
toString FreeBSD = "freebsd"
toString Linux = "linux"
toString Linux = "linux"
toString OpenBSD = "openbsd"
toString SunOS = "sunos"
toString Win32 = "win32"
toString SunOS = "sunos"
toString Win32 = "win32"
toString Android = "android"

-- | Attempt to parse a `Platform` value from a string, in the format returned
-- | by Node.js' `process.platform`.
fromString :: String -> Maybe Platform
fromString "aix" = Just AIX
fromString "darwin" = Just Darwin
fromString "aix" = Just AIX
fromString "darwin" = Just Darwin
fromString "freebsd" = Just FreeBSD
fromString "linux" = Just Linux
fromString "linux" = Just Linux
fromString "openbsd" = Just OpenBSD
fromString "sunos" = Just SunOS
fromString "win32" = Just Win32
fromString "sunos" = Just SunOS
fromString "win32" = Just Win32
fromString "android" = Just Android
fromString _ = Nothing
fromString _ = Nothing

instance showPlatform :: Show Platform where
show AIX = "AIX"
show Darwin = "Darwin"
show AIX = "AIX"
show Darwin = "Darwin"
show FreeBSD = "FreeBSD"
show Linux = "Linux"
show Linux = "Linux"
show OpenBSD = "OpenBSD"
show SunOS = "SunOS"
show Win32 = "Win32"
show SunOS = "SunOS"
show Win32 = "Win32"
show Android = "Android"

derive instance eqPlatform :: Eq Platform
129 changes: 62 additions & 67 deletions src/Node/Process.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,65 @@
import process from "process";
export { process };

export function onBeforeExit(callback) {
return () => {
process.on("beforeExit", callback);
};
}

export function onExit(callback) {
return () => {
process.on("exit", code => {
callback(code)();
});
};
}

export function onUncaughtException(callback) {
return () => {
process.on("uncaughtException", error => {
callback(error)();
});
};
}

export function onUnhandledRejection(callback) {
return () => {
process.on("unhandledRejection", (error, promise) => {
callback(error)(promise)();
});
};
}

export function onSignalImpl(signal) {
return callback => () => {
process.on(signal, callback);
};
}

export function chdir(dir) {
return () => {
process.chdir(dir);
};
}

export function setEnv(var_) {
return val => () => {
process.env[var_] = val;
};
}

export function unsetEnv(var_) {
return () => {
delete process.env[var_];
};
}

export function exit(code) {
return () => {
process.exit(code);
};
}

export function copyArray(xs) {
return () => xs.slice();
}
export { process };
export const abortImpl = process.abort ? () => process.abort() : null;
export const argv = () => process.argv.slice();
export const argv0 = () => process.argv0;
export const channelRefImpl = process.channel && process.channel.ref ? () => process.channel.ref() : null;
export const channelUnrefImpl = process.channel && process.channel.unref ? () => process.channel.unref() : null;
export const chdirImpl = (dir) => process.chdir(dir);
export const config = () => Object.assign({}, process.config);
export const connected = () => process.connected;
export const cpuUsage = () => process.cpuUsage();
export const cpuUsageDiffImpl = (prevVal) => process.cpuUsage(prevVal);
export const cwd = () => process.cwd();
export const debugPort = process.debugPort;
export const disconnectImpl = process.disconnect ? () => process.disconnect() : null;
export const getEnv = () => Object.assign({}, process.env);
export const unsafeGetEnv = () => process.env;
export const setEnvImpl = (key, val) => {
process.env[key] = val;
};
export const unsetEnvImpl = (key) => {
delete process.env[key];
};
export const execArgv = () => process.execArgv.slice();
export const execPath = () => process.execPath;
export const exit = () => process.exit();
export const exitImpl = (code) => process.exit(code);
export const setExitCodeImpl = (code) => {
process.exitCode = code;
};
export const getExitCodeImpl = () => process.exitCode;
export const getGidImpl = () => process.getgid();
export const getUidImpl = () => process.getuid();
export const hasUncaughtExceptionCaptureCallback = () => process.hasUncaughtExceptionCaptureCallback;
export const killImpl = (pid) => process.kill(pid);
export const killStrImpl = (pid, sig) => process.kill(pid, sig);
export const killIntImpl = (pid, int) => process.kill(pid, int);
export const memoryUsage = () => process.memoryUsage();
export const memoryUsageRss = () => process.memoryUsage.rss();
export const nextTickImpl = (cb) => process.nextTick(cb);
export const nextTickCbImpl = (cb, args) => process.nextTick(cb, args);
export const pid = process.pid;
export const platformStr = process.platform;
export const ppid = process.ppid;
export const resourceUsage = () => process.resourceUsage;
export const sendImpl = (msg, handle) => process.send(msg, handle);
export const sendOptsImpl = (msg, handle, opts) => process.send(msg, handle, opts);
export const sendCbImpl = (msg, handle, cb) => process.send(msg, handle, cb);
export const sendOptsCbImpl = (msg, handle, opts, cb) => process.send(msg, handle, opts, cb);
export const setUncaughtExceptionCaptureCallbackImpl = (cb) => process.setUncaughtExceptionCaptureCallback(cb);
export const clearUncaughtExceptionCaptureCallback = () => process.setUncaughtExceptionCaptureCallback(null);
export const stdin = process.stdin;
export const stdout = process.stdout;
export const stderr = process.stderr;
export const stdinIsTTY = process.stdinIsTTY;
export const stdoutIsTTY = process.stdoutIsTTY;
export const stderrIsTTY = process.stderrIsTTY;
export const getTitle = () => process.title;
export const setTitleImpl = (v) => {
process.title = v;
};
export const uptime = () => process.uptime();
export const version = process.version;

export function copyObject(o) {
return () => Object.assign({}, o);
}
Loading