version-io 5.0.0 → 6.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.
package/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2026.02.02, v6.0.0
2
+
3
+ feature:
4
+ - 97aea7c version-io: add -e
5
+ - dd68ea2 version-io: drop support of node < 22
6
+ - 0a6d90b version-io: try-to-catch v4.0.5
7
+ - a8c2a33 version-io: putout v41.16.0
8
+ - 566b17c version-io: madrun v12.1.3
9
+ - b9bb256 version-io: eslint-plugin-putout v30.0.2
10
+
1
11
  2025.03.30, v5.0.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Version-io
2
2
 
3
- Semantic versioning tool. Apply major, minor, patch and version to `package.json`.
3
+ Semantic versioning tool. Apply `major`, `minor`, `patch` and version to `package.json`.
4
4
 
5
5
  ## Install
6
6
 
@@ -30,24 +30,37 @@ Apply minor, major or patch:
30
30
  v1.1.0
31
31
  ```
32
32
 
33
+ Extended view:
34
+
35
+ ```
36
+ # version -e
37
+
38
+ 1 | {
39
+ 2 | "version": "5.0.0",
40
+ 3 | "engines": {
41
+ 4 | "node": ">=22"
42
+ 5 | }
43
+ 6 | }
44
+ ```
45
+
33
46
  ## Use as module
34
47
 
35
48
  Install `version-io` with:
36
49
 
37
50
  ```
38
- npm i version-io --save
51
+ npm i version-io -g
39
52
  ```
40
53
 
41
- Format: `version(number, callback);`
54
+ ## API
42
55
 
43
- - `number` could be new version number or `minor|major|patch`
56
+ ### `updateVersion(number: VersionNumber)`
44
57
 
45
- You could update version in `package.json` with:
58
+ - `VersionNumber` could be new version number or `minor|major|patch`
46
59
 
47
60
  ```js
48
- import versionio from 'version-io';
61
+ import {updateVersion} from 'version-io';
49
62
 
50
- const version = await versionio();
63
+ await updateVersion('patch');
51
64
  ```
52
65
 
53
66
  ## License
package/bin/version.js CHANGED
@@ -1,45 +1,59 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import process from 'node:process';
4
- import {createRequire} from 'node:module';
5
4
  import readjson from 'readjson';
6
- import tryToCatch from 'try-to-catch';
5
+ import {tryToCatch} from 'try-to-catch';
7
6
  import {packageUp} from 'package-up';
8
- import version from '../lib/version.js';
7
+ import {updateVersion} from '../lib/version.js';
8
+
9
+ const {stringify} = JSON;
9
10
 
10
- const require = createRequire(import.meta.url);
11
11
  const [arg] = process.argv.slice(2);
12
12
 
13
- main();
13
+ const isExtended = arg && arg === '-e';
14
14
 
15
- async function main() {
16
- if (/^(-v|--version)$/.test(arg))
17
- return console.log('v' + require('../package').version);
18
-
19
- if (arg) {
20
- const [e, data] = await tryToCatch(version, arg);
21
-
22
- if (e)
23
- return console.error(e.message);
24
-
25
- if (data)
26
- console.log(data);
27
-
28
- return;
29
- }
15
+ if (/^(-v|--version)$/.test(arg))
16
+ process.exit();
17
+
18
+ if (arg && !isExtended) {
19
+ const [e, data] = await tryToCatch(updateVersion, arg);
30
20
 
31
- const name = await packageUp();
21
+ if (e)
22
+ process.exit();
32
23
 
33
- if (!name)
34
- return console.error('package.json: not found');
24
+ if (data)
25
+ console.log(data);
35
26
 
36
- const [error, info] = await tryToCatch(readjson, name);
27
+ process.exit();
28
+ }
29
+
30
+ const name = await packageUp();
31
+
32
+ if (!name)
33
+ process.exit();
34
+
35
+ const [error, info] = await tryToCatch(readjson, name);
36
+
37
+ if (!error) {
38
+ if (!isExtended) {
39
+ console.log(info.version || '<no version>');
40
+ process.exit();
41
+ }
37
42
 
38
- if (!error)
39
- return console.log(info.version || 'no version');
43
+ const {codeFrameColumns} = await import('@putout/babel');
44
+ const result = stringify({
45
+ version: info.version,
46
+ engines: info.engines,
47
+ }, null, 4);
40
48
 
41
- if (error.code === 'ENOENT')
42
- return console.error('package.json: not found');
49
+ console.log(codeFrameColumns(result, {}, {
50
+ highlightCode: true,
51
+ }));
43
52
 
44
- return console.error('package.json:', error.message);
53
+ process.exit();
45
54
  }
55
+
56
+ if (error.code === 'ENOENT')
57
+ process.exit(1);
58
+
59
+ console.error('package.json:', error.message);
package/lib/version.js CHANGED
@@ -1,22 +1,27 @@
1
1
  import assert from 'node:assert';
2
- import readjson from 'readjson';
3
- import writejson from 'writejson';
2
+ import _readjson from 'readjson';
3
+ import _writejson from 'writejson';
4
4
  import minor from 'minor';
5
- import {packageUp} from 'package-up';
5
+ import {packageUp as _packageUp} from 'package-up';
6
6
 
7
- export default async (version) => {
7
+ export const updateVersion = async (version, overrides) => {
8
8
  assert(version, 'version could not be empty!');
9
9
 
10
+ const {
11
+ packageUp = _packageUp,
12
+ readjson = _readjson,
13
+ writejson = _writejson,
14
+ } = overrides;
15
+
10
16
  const name = await packageUp();
11
17
  const json = await readjson(name);
12
18
 
13
- if (!version)
14
- return `v${json.version}`;
15
-
16
- await update(name, version, json);
19
+ await update(name, version, json, {
20
+ writejson,
21
+ });
17
22
  };
18
23
 
19
- async function update(name, version, info) {
24
+ async function update(name, version, info, {writejson}) {
20
25
  const mmpRegExp = /major|minor|patch/;
21
26
  const vRegExp = /^v/;
22
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "version-io",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Semantic versioning tool. Apply major, minor, patch and version to package.json.",
@@ -14,24 +14,30 @@
14
14
  "url": "git+https://github.com/coderaiser/version-io.git"
15
15
  },
16
16
  "dependencies": {
17
+ "@putout/babel": "^5.2.11",
17
18
  "minor": "^1.2.0",
18
19
  "package-up": "^5.0.0",
19
20
  "readjson": "^2.0.1",
20
- "try-to-catch": "^3.0.0",
21
+ "try-to-catch": "^4.0.5",
21
22
  "writejson": "^3.0.0"
22
23
  },
23
24
  "engines": {
24
- "node": ">=20"
25
+ "node": ">=22"
25
26
  },
26
27
  "license": "MIT",
27
28
  "devDependencies": {
29
+ "c8": "^10.1.3",
28
30
  "eslint": "^9.23.0",
29
- "eslint-plugin-putout": "^26.1.0",
30
- "madrun": "^11.0.0",
31
- "putout": "^39.5.0"
31
+ "eslint-plugin-putout": "^30.0.2",
32
+ "madrun": "^12.1.3",
33
+ "putout": "^41.16.0",
34
+ "supertape": "^12.2.0"
32
35
  },
33
36
  "scripts": {
37
+ "test": "madrun test",
34
38
  "lint": "madrun lint",
35
- "fix:lint": "madrun fix:lint"
39
+ "fix:lint": "madrun fix:lint",
40
+ "coverage": "madrun coverage",
41
+ "report": "madrun report"
36
42
  }
37
43
  }