daemonize-process 2.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +6 -8
  2. package/index.js +17 -16
  3. package/package.json +12 -16
  4. package/LICENSE +0 -22
package/README.md CHANGED
@@ -1,31 +1,29 @@
1
1
  # daemonize-process
2
- [![](https://img.shields.io/npm/v/daemonize-process.svg?style=flat)](https://www.npmjs.org/package/daemonize-process) [![](https://img.shields.io/npm/dm/daemonize-process.svg)](https://www.npmjs.org/package/daemonize-process) [![](https://api.travis-ci.org/silverwind/daemonize-process.svg?style=flat)](https://travis-ci.org/silverwind/daemonize-process)
2
+ [![](https://img.shields.io/npm/v/daemonize-process.svg?style=flat)](https://www.npmjs.org/package/daemonize-process) [![](https://img.shields.io/npm/dm/daemonize-process.svg)](https://www.npmjs.org/package/daemonize-process) [![](https://packagephobia.com/badge?p=daemonize-process)](https://packagephobia.com/result?p=daemonize-process)
3
3
 
4
4
  > Daemonize the current Node.js process
5
5
 
6
6
  The module re-spawns the current process and then exits, which will lead to the new child process being adopted by `init` or similar mechanisms, effectively putting the current process into the background.
7
7
 
8
- Differences to the popular `daemon` module include:
8
+ Differences to the `daemon` module include:
9
9
 
10
10
  - Exposes all options of `child_process.spawn`.
11
11
  - Cleans up `process.env` after itself.
12
- - Works on Node.js >= 8.
13
12
 
14
13
  ## Install
15
14
 
16
15
  ```console
17
- $ npm install daemonize-process
16
+ $ npm i daemonize-process
18
17
  ```
19
18
 
20
19
  ## Examples
21
20
 
22
21
  ```js
23
- require('daemonize-process')();
24
- ```
22
+ import {daemonizeProcess} from "daemonize-process";
25
23
 
26
- ```js
27
- import daemonizeProcess from 'daemonize-process';
28
24
  daemonizeProcess();
25
+
26
+ // below here the process is daemonized
29
27
  ```
30
28
 
31
29
  ## API
package/index.js CHANGED
@@ -1,27 +1,28 @@
1
- "use strict";
1
+ import {spawn} from "node:child_process";
2
+ import {env, cwd, execPath, argv, exit} from "node:process";
2
3
 
3
4
  const id = "_DAEMONIZE_PROCESS";
4
5
 
5
- module.exports = function(opts) {
6
- if (id in process.env) {
6
+ export function daemonizeProcess(opts = {}) {
7
+ if (id in env) {
7
8
  // In the child, clean up the tracking environment variable
8
- delete process.env[id];
9
+ delete env[id];
9
10
  } else {
10
11
  // In the parent, set the tracking environment variable, fork the child and exit
11
- opts = opts || {};
12
- const o = Object.assign({
12
+ const o = {
13
13
  // spawn options
14
- env: Object.assign(process.env, opts.env, {[id]: "1"}),
15
- cwd: process.cwd(),
14
+ env: Object.assign(env, opts.env, {[id]: "1"}),
15
+ cwd: cwd(),
16
16
  stdio: "ignore",
17
17
  detached: true,
18
18
  // custom options
19
- node: process.execPath,
20
- script: process.argv[1],
21
- arguments: process.argv.slice(2),
22
- exitCode: 0,
23
- }, opts);
24
- require("child_process").spawn(o.node, [o.script].concat(o.arguments), o).unref();
25
- process.exit(o.exitCode);
19
+ node: execPath,
20
+ script: argv[1],
21
+ arguments: argv.slice(2),
22
+ exitCode: 0, ...opts
23
+ };
24
+
25
+ spawn(o.node, [o.script].concat(o.arguments), o).unref();
26
+ exit(o.exitCode);
26
27
  }
27
- };
28
+ }
package/package.json CHANGED
@@ -1,29 +1,25 @@
1
1
  {
2
2
  "name": "daemonize-process",
3
- "version": "2.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "Daemonize the current Node.js process",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/daemonize-process",
7
7
  "license": "BSD-2-Clause",
8
- "scripts": {
9
- "test": "make test"
10
- },
8
+ "exports": "./index.js",
9
+ "type": "module",
10
+ "sideEffects": false,
11
11
  "engines": {
12
- "node": ">=6"
12
+ "node": ">=18"
13
13
  },
14
14
  "files": [
15
- "index.js"
16
- ],
17
- "keywords": [
18
- "daemonize",
19
- "daemon",
20
- "background",
21
- "process"
15
+ "./index.js"
22
16
  ],
23
17
  "devDependencies": {
24
- "eslint": "^5.12.1",
25
- "eslint-config-silverwind": "^2.0.14",
26
- "updates": "^6.2.1",
27
- "ver": "^3.0.1"
18
+ "eslint": "8.49.0",
19
+ "eslint-config-silverwind": "74.1.4",
20
+ "updates": "15.0.2",
21
+ "versions": "11.1.0",
22
+ "vitest": "0.34.4",
23
+ "vitest-config-silverwind": "3.0.0"
28
24
  }
29
25
  }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) silverwind
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
-
7
- 1. Redistributions of source code must retain the above copyright notice, this
8
- list of conditions and the following disclaimer.
9
- 2. Redistributions in binary form must reproduce the above copyright notice,
10
- this list of conditions and the following disclaimer in the documentation
11
- and/or other materials provided with the distribution.
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.