Skip to content

Commit 8ba1836

Browse files
committed
Make it work
1 parent 076b802 commit 8ba1836

File tree

15 files changed

+2606
-146
lines changed

15 files changed

+2606
-146
lines changed

.github/workflows/build.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: build
2+
23
env:
34
DEBUG: napi:*
45
APP_NAME: exec
56
CARGO_INCREMENTAL: '1'
7+
68
permissions:
79
contents: write
810
id-token: write
@@ -20,11 +22,16 @@ permissions:
2022
- .prettierignore
2123
- .prettierrc.yml
2224
pull_request: null
25+
2326
concurrency:
2427
group: ${{ github.workflow }}-${{ github.ref }}
2528
cancel-in-progress: true
29+
2630
jobs:
2731
build:
32+
name: Build ${{ matrix.settings.target }} with node@22
33+
runs-on: ${{ matrix.settings.host }}
34+
if: ${{ github.ref == 'refs/head/main' || startsWith(github.ref, 'refs/tags/') }}
2835
strategy:
2936
fail-fast: false
3037
matrix:
@@ -54,8 +61,6 @@ jobs:
5461
set -e &&
5562
rustup target add aarch64-unknown-linux-musl &&
5663
npm run build -- --target aarch64-unknown-linux-musl
57-
name: stable - ${{ matrix.settings.target }} - node@22
58-
runs-on: ${{ matrix.settings.host }}
5964
steps:
6065
- uses: actions/checkout@v4
6166
- name: Setup node
@@ -103,8 +108,9 @@ jobs:
103108
name: bindings-${{ matrix.settings.target }}
104109
path: ${{ env.APP_NAME }}.*.node
105110
if-no-files-found: error
111+
106112
test-macos-binding:
107-
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
113+
name: Test ${{ matrix.settings.target }} with node@${{ matrix.node }}
108114
needs:
109115
- build
110116
strategy:
@@ -142,8 +148,9 @@ jobs:
142148
shell: bash
143149
- name: Test bindings
144150
run: npm test
151+
145152
test-linux-x64-gnu-binding:
146-
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
153+
name: Test Linux-x64-gnu with node@${{ matrix.node }}
147154
needs:
148155
- build
149156
strategy:
@@ -173,8 +180,9 @@ jobs:
173180
shell: bash
174181
- name: Test bindings
175182
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim npm test
183+
176184
test-linux-x64-musl-binding:
177-
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
185+
name: Test x86_64-unknown-linux-musl with node@${{ matrix.node }}
178186
needs:
179187
- build
180188
strategy:
@@ -205,8 +213,9 @@ jobs:
205213
shell: bash
206214
- name: Test bindings
207215
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine npm test
216+
208217
test-linux-aarch64-gnu-binding:
209-
name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
218+
name: Test aarch64-unknown-linux-gnu with node@${{ matrix.node }}
210219
needs:
211220
- build
212221
strategy:
@@ -244,8 +253,9 @@ jobs:
244253
set -e
245254
npm test
246255
ls -la
256+
247257
test-linux-aarch64-musl-binding:
248-
name: Test bindings on aarch64-unknown-linux-musl - node@lts
258+
name: Test aarch64-unknown-linux-musl with node@22
249259
needs:
250260
- build
251261
runs-on: ubuntu-latest
@@ -270,11 +280,12 @@ jobs:
270280
- name: Setup and run tests
271281
uses: addnab/docker-run-action@v3
272282
with:
273-
image: node:lts-alpine
283+
image: node:22-alpine
274284
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
275285
run: |
276286
set -e
277287
npm test
288+
278289
publish:
279290
name: Publish
280291
runs-on: ubuntu-latest

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22

33
The [`execvp` function](https://linux.die.net/man/3/execvp) for Node.js.
44

5-
## Install this package
5+
```js
6+
import { execvp } from '@alphahydrae/exec';
7+
8+
execvp('ls', ['.']);
9+
10+
console.log(`
11+
This will never print because the executing Node.js
12+
program is replaced by the executed command, keeping
13+
the same process ID and file descriptors.
14+
`)
15+
```
16+
17+
If you're familiar with Bash's `exec` function, this is the same for Node.js.
18+
19+
This package was developed to be used in Node.js scripts that are frontends to
20+
execute other commands. For example, a script that would build and execute a
21+
complex SSH or Ansible command.
22+
23+
## Installation
624

725
```bash
826
npm i @alphahydrae/exec
@@ -18,3 +36,7 @@ npm i @alphahydrae/exec
1836
| Linux x64 musl ||||
1937
| Linux arm64 gnu ||||
2038
| Linux arm64 musl ||||
39+
40+
> The `exec` family of functions is part of the
41+
> [POSIX](https://en.wikipedia.org/wiki/POSIX) operating system API, so it will
42+
> not work on Windows.

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extern crate napi_build;
22

33
fn main() {
4-
napi_build::setup();
4+
napi_build::setup();
55
}

exec.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare function execvp(file: string, args: Array<string>): void;

exec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const { doNotCloseOnExit, execvp } = require('./index.js');
1+
const native = require('./index.js');
22

3-
doNotCloseOnExit(process.stdin.fd);
4-
doNotCloseOnExit(process.stdout.fd);
5-
doNotCloseOnExit(process.stderr.fd);
6-
execvp('ls', [process.argv0, 'tests']);
3+
module.exports.execvp = function (file, args) {
4+
native.doNotCloseOnExit(process.stdin.fd);
5+
native.doNotCloseOnExit(process.stdout.fd);
6+
native.doNotCloseOnExit(process.stderr.fd);
7+
native.execvp(file, [process.argv0, ...args]);
8+
};

npm/darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"engines": {
2525
"node": "^18 || ^20 || ^22"
2626
}
27-
}
27+
}

npm/darwin-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"engines": {
2525
"node": "^18 || ^20 || ^22"
2626
}
27-
}
27+
}

npm/linux-arm64-gnu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"engines": {
2828
"node": "^18 || ^20 || ^22"
2929
}
30-
}
30+
}

npm/linux-arm64-musl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"engines": {
2828
"node": "^18 || ^20 || ^22"
2929
}
30-
}
30+
}

npm/linux-x64-gnu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"engines": {
2828
"node": "^18 || ^20 || ^22"
2929
}
30-
}
30+
}

0 commit comments

Comments
 (0)