Skip to content

Commit

Permalink
feat: added "ip" support, bump deps, node >= 14
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed May 2, 2023
1 parent d91d611 commit 1356e36
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 8,542 deletions.
9 changes: 0 additions & 9 deletions .babelrc

This file was deleted.

3 changes: 3 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
};
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.*.js
9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI
on:
- push
- pull_request
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
node_version:
- 14
- 16
- 18
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
node_modules
coverage
.nyc_output
lib
locales/
package-lock.json
yarn.lock

Thumbs.db
tmp/
temp/
*.lcov
.env
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged && npm test
5 changes: 5 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'*.md': (filenames) => filenames.map((filename) => `remark ${filename} -qfo`),
'package.json': 'fixpack',
'*.js': 'xo --fix'
};
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
singleQuote: true,
bracketSpacing: true,
trailingComma: 'none'
};
1 change: 0 additions & 1 deletion .remarkignore

This file was deleted.

3 changes: 3 additions & 0 deletions .remarkrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: ['preset-github']
};
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .xo-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
prettier: true,
space: true,
extends: ['xo-lass']
};
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# parse-app-info

[![build status](https://img.shields.io/travis/cabinjs/parse-app-info.svg)](https://travis-ci.com/cabinjs/parse-app-info)
[![code coverage](https://img.shields.io/codecov/c/github/cabinjs/parse-app-info.svg)](https://codecov.io/gh/cabinjs/parse-app-info)
[![build status](https://github.com/cabinjs/parse-app-info/actions/workflows/ci.yml/badge.svg)](https://github.com/cabinjs/parse-app-info/actions/workflows/ci.yml)
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)
Expand All @@ -27,12 +26,6 @@
npm install parse-app-info
```

[yarn][]:

```sh
yarn add parse-app-info
```


## Usage

Expand All @@ -45,16 +38,17 @@ const appInfo = parseAppInfo();

## Available info

| Property | Description |
| ----------- | ----------------------------------- |
| environment | The value of NODE_ENV |
| hostname | Name of the computer |
| name | Name of the app from `package.json` |
| node | Version if node.js running the app |
| pid | Process ID as in `process.pid` |
| version | Version of the app `package.json` |
| cluster | Cluster info of the app |
| os | OS info of the app |
| Property | Description |
| ----------- | ---------------------------------------------------------------------------------------- |
| environment | The value of `process.env.NODE_ENV` or defaults to "development" |
| hostname | Hostame of the computer (uses `process.env.HOSTNAME` or defaults to `os.hostname()`) |
| ip | IP address of the computer (uses `process.env.IP_ADDRESS` or defaults to `ip.address()`) |
| name | Name of the app from `package.json` |
| node | Version of Node.js running the app |
| pid | Process ID from `process.pid` |
| version | Version of the app `package.json` |
| cluster | Cluster info of the app |
| os | OS info of the app |

Additional properties when the app is in a git repository

Expand All @@ -81,8 +75,6 @@ Additional properties when the app is in a git repository

[npm]: https://www.npmjs.com/

[yarn]: https://yarnpkg.com/

[cabin]: https://cabinjs.com

[node]: https://nodejs.org
27 changes: 12 additions & 15 deletions src/index.js → index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const process = require('process');
const cluster = require('cluster');
const os = require('os');

const process = require('node:process');
const cluster = require('node:cluster');
const os = require('node:os');
const LastCommitLog = require('last-commit-log');
const _ = require('lodash');
const readPkgUp = require('read-pkg-up');
const semver = require('semver');
const ip = require('ip');

const hasWorkerThreads = semver.satisfies(process.version, '>=12.11.0');
let worker_threads;
// eslint-disable-next-line node/no-unsupported-features/node-builtins
if (hasWorkerThreads) worker_threads = require('worker_threads');
if (hasWorkerThreads) worker_threads = require('node:worker_threads');

const usesClusterPrimary = semver.satisfies(process.version, '>=16.0.0');

const OS_METHODS = [
'arch',
Expand Down Expand Up @@ -61,8 +62,7 @@ function parseAppInfo() {
let packageInfo = {};
try {
packageInfo = readPkgUp.sync();
// eslint-disable-next-line no-unused-vars
} catch (err) {}
} catch {}

const info = {};
if (
Expand All @@ -80,17 +80,15 @@ function parseAppInfo() {
let gitTag;
try {
({ hash, gitTag } = lastCommitLog.getLastCommitSync());
// eslint-disable-next-line no-unused-vars
} catch (err) {}
} catch {}

const lastCommit = { hash };
if (gitTag) lastCommit.tag = gitTag;

const { NODE_ENV, HOSTNAME } = process.env;
const { NODE_ENV, HOSTNAME, IP_ADDRESS } = process.env;

const _cluster = _.pick(cluster, [
'worker',
'isMaster',
usesClusterPrimary ? 'isPrimary' : 'isMaster',
'isWorker',
'schedulingPolicy'
]);
Expand Down Expand Up @@ -168,13 +166,12 @@ function parseAppInfo() {
}

return {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
...info,
node: process.version,
// eslint-disable-next-line node/no-unsupported-features/es-syntax
...lastCommit,
environment: NODE_ENV || 'development',
hostname: HOSTNAME || os.hostname(),
ip: IP_ADDRESS || ip.address(),
pid: process.pid,
cluster: _cluster,
os: _os,
Expand Down
106 changes: 26 additions & 80 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
"description": "Parse information about a Node application process and its environment. Made for Cabin.",
"version": "4.0.3",
"author": "Philipp Kursawe <[email protected]> (https://pke.github.io)",
"ava": {
"failFast": true,
"verbose": true,
"helpers": [
"test/helpers/**/*"
]
},
"bugs": {
"url": "https://github.com/cabinjs/parse-app-info/issues",
"email": "[email protected]"
Expand All @@ -24,46 +17,37 @@
"Philipp Kursawe <[email protected]> (https://pke.github.io)"
],
"dependencies": {
"last-commit-log": "^3.1.1",
"ip": "^1.1.8",
"last-commit-log": "^3.3.0",
"lodash": "^4.17.21",
"read-pkg-up": "7",
"semver": "^7.3.5"
"semver": "^7.5.0"
},
"devDependencies": {
"@babel/cli": "^7.17.3",
"@babel/core": "^7.17.5",
"@babel/preset-env": "^7.16.11",
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"ava": "2.4.0",
"codecov": "latest",
"cross-env": "latest",
"eslint": "latest",
"eslint-config-xo-lass": "latest",
"eslint-plugin-node": "^11.1.0",
"fixpack": "latest",
"husky": "latest",
"lint-staged": "latest",
"@commitlint/cli": "^17.6.1",
"@commitlint/config-conventional": "^17.6.1",
"ava": "^5.2.0",
"cross-env": "^7.0.3",
"eslint": "^8.39.0",
"eslint-config-xo-lass": "^2.0.1",
"fixpack": "^4.0.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"mocked-env": "1.3.5",
"nyc": "latest",
"remark-cli": "latest",
"remark-preset-github": "latest",
"testdouble": "3.16.4",
"xo": "latest"
"nyc": "^15.1.0",
"remark-cli": "^11.0.0",
"remark-preset-github": "^4.0.4",
"rimraf": "^5.0.0",
"testdouble": "3.17.2",
"xo": "^0.54.2"
},
"engines": {
"node": ">=7.0.0"
"node": ">=14"
},
"files": [
"lib"
"index.js"
],
"homepage": "https://github.com/cabinjs/parse-app-info",
"husky": {
"hooks": {
"pre-commit": "lint-staged && npm test",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"keywords": [
"app",
"appinfo",
Expand All @@ -73,54 +57,16 @@
"last-commit"
],
"license": "MIT",
"lint-staged": {
"*.js": [
"xo --fix",
"git add"
],
"*.md": [
"remark . -qfo",
"git add"
],
"package.json": [
"fixpack",
"git add"
]
},
"main": "lib/index.js",
"prettier": {
"singleQuote": true,
"bracketSpacing": true,
"trailingComma": "none"
},
"remarkConfig": {
"plugins": [
"preset-github"
]
},
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/cabinjs/parse-app-info"
},
"scripts": {
"ava": "cross-env NODE_ENV=test ava",
"build": "npm run build:clean && npm run build:lib",
"build:clean": "rimraf lib",
"build:lib": "babel src --out-dir lib",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "xo && remark . -qfo && eslint lib",
"nyc": "cross-env NODE_ENV=test nyc ava",
"test": "npm run build && npm run lint && npm run ava",
"test-coverage": "npm run build && npm run lint && npm run nyc"
},
"xo": {
"prettier": true,
"space": true,
"extends": [
"xo-lass"
],
"rules": {
"unicorn/prefer-optional-catch-binding": "off"
}
"lint": "xo --fix && remark . -qfo && fixpack",
"prepare": "husky install",
"pretest": "npm run lint",
"test": "npm run test-coverage",
"test-coverage": "cross-env NODE_ENV=test nyc ava"
}
}
Loading

0 comments on commit 1356e36

Please sign in to comment.