├── .esm-wrapper.mjs ├── .gitignore ├── .npmignore ├── .taprc ├── .travis.yml ├── LICENSE ├── README.md ├── binding.cc ├── binding.gyp ├── index.d.ts ├── index.js ├── package.json └── test.js /.esm-wrapper.mjs: -------------------------------------------------------------------------------- 1 | import mod from "./index.js"; 2 | 3 | export default mod; 4 | export const nice = mod.nice; 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .nyc_output 2 | node_modules 3 | package-lock.json 4 | dist 5 | coverage 6 | .esm-wrapper.js 7 | build/ 8 | prebuilds/ 9 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github 2 | .nyc_output 3 | package-lock.json 4 | coverage 5 | examples 6 | -------------------------------------------------------------------------------- /.taprc: -------------------------------------------------------------------------------- 1 | check-coverage: true 2 | color: true 3 | coverage: true 4 | coverage-report: 5 | - html 6 | - text 7 | jobs: 2 8 | no-browser: true 9 | test-env: TS_NODE_PROJECT=test/tsconfig.json 10 | test-ignore: $. 11 | test-regex: ((\/|^)(tests?|__tests?__)\/.*|\.(tests?|spec)|^\/?tests?)\.([mc]js|[jt]sx?)$ 12 | timeout: 60 13 | ts: true 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | env: 4 | - CXX=clang++ npm_config_v8_enable_pointer_compression=0 npm_config_v8_enable_31bit_smis_on_64bit_arch=0 5 | 6 | language: node_js 7 | 8 | os: 9 | - linux 10 | - osx 11 | 12 | osx_image: xcode10 13 | 14 | node_js: 15 | - "10" 16 | - "12" 17 | - "14" 18 | 19 | install: 20 | - npm install --build-from-source 21 | 22 | before_deploy: 23 | - ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-`uname -m`.tar" 24 | - npm run prebuildify 25 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ARCH=ia32 npm run prebuildify; fi 26 | - tar --create --verbose --file="$ARCHIVE_NAME" --directory "$TRAVIS_BUILD_DIR/prebuilds" . 27 | 28 | deploy: 29 | provider: releases 30 | draft: false 31 | prerelease: true 32 | file: "$ARCHIVE_NAME" 33 | skip_cleanup: true 34 | on: 35 | tags: true 36 | node: 12 37 | api_key: $PREBUILD_GITHUB_TOKEN 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Anna Henningsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nice-napi – nice(2) bindings for Node.js 2 | 3 | https://linux.die.net/man/2/nice as a JS function. That’s it, that’s the module. 4 | 5 | ```js 6 | const nice = require('nice-napi'); 7 | nice(5); // Increase niceness by 5. 8 | ``` 9 | -------------------------------------------------------------------------------- /binding.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace Napi; 5 | 6 | Value Nice(const CallbackInfo& args) { 7 | int32_t inc = args[0].ToNumber(); 8 | errno = 0; 9 | int32_t ret = nice(inc); 10 | if (errno != 0) { 11 | throw Error::New( 12 | args.Env(), std::string("nice(): ") + strerror(errno)); 13 | } 14 | return Number::New(args.Env(), ret); 15 | } 16 | 17 | static Object Init(Env env, Object exports) { 18 | exports["nice"] = Function::New(env, Nice); 19 | return exports; 20 | } 21 | 22 | NODE_API_MODULE(nice_napi, Init) 23 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | 'targets': [{ 3 | 'target_name': 'nice_napi', 4 | 'sources': [ 'binding.cc' ], 5 | 'include_dirs': ["", 27 | "license": "MIT", 28 | "dependencies": { 29 | "node-addon-api": "^3.0.0", 30 | "node-gyp-build": "^4.2.2" 31 | }, 32 | "devDependencies": { 33 | "gen-esm-wrapper": "^1.0.6", 34 | "prebuildify": "^4.0.0", 35 | "prebuildify-ci": "^1.0.5" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const assert = require('assert'); 3 | const nice = require('./'); 4 | 5 | assert.strictEqual(nice.nice, nice); 6 | 7 | const cur = nice(0); 8 | assert.strictEqual(cur + 1, nice(1)); 9 | assert.strictEqual(cur + 1, nice(0)); 10 | 11 | if (+process.version.split('.')[0].slice(1) >= 12 && process.platform === 'linux') { 12 | let messages = 0; 13 | const { Worker } = require('worker_threads'); 14 | const w = new Worker(`require("worker_threads").parentPort.postMessage( 15 | require("./")(1))`, { eval: true }); 16 | w.on('message', (m) => { 17 | messages++; 18 | assert.strictEqual(cur + 1, nice(0)); 19 | assert.strictEqual(cur + 2, m); 20 | }); 21 | w.on('exit', () => { 22 | assert.strictEqual(messages, 1); 23 | assert.strictEqual(cur + 1, nice(0)); 24 | test2(); 25 | }); 26 | } else { 27 | test2(); 28 | } 29 | 30 | function test2() { 31 | nice(10000); 32 | assert.strictEqual(nice(0), nice(10000)); 33 | 34 | if (process.getuid() !== 0) { 35 | assert.throws(() => nice(-1), /nice\(\): Operation not permitted/); 36 | } 37 | } 38 | --------------------------------------------------------------------------------