@putout/plugin-package-json 1.0.1 → 3.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/README.md CHANGED
@@ -1,11 +1,9 @@
1
- # @putout/plugin-package-json [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
1
+ # @putout/plugin-package-json [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
3
3
  [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-package-json.svg?style=flat&longCache=true
4
4
  [NPMURL]: https://npmjs.org/package/@putout/plugin-package-json"npm"
5
- [DependencyStatusURL]: https://david-dm.org/coderaiser/package-json?path=packages/plugin-package-json
6
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/package-json.svg?path=packages/plugin-package-json
7
5
 
8
- `putout` plugin helps to automate fixing `package-json` config.
6
+ 🐊[`Putout`](https://github.com/coderaiser/putout) plugin helps to automate fixing `package-json` config.
9
7
 
10
8
  ## Install
11
9
 
@@ -18,14 +16,15 @@ npm i @putout/plugin-package-json -D
18
16
  ```json
19
17
  {
20
18
  "rules": {
21
- "package-json/remove-nyc": "on"
19
+ "package-json/remove-nyc": "on",
20
+ "package-json/add-type": "on"
22
21
  }
23
22
  }
24
23
  ```
25
24
 
26
25
  ## remove-nyc
27
26
 
28
- - additional fields in `package.json` produces more trafic then users of your package really need;
27
+ - additional fields in `package.json` produces more traffic then users of your package really need;
29
28
  - [c8](https://github.com/bcoe/c8) uses [same config name and format](https://github.com/bcoe/c8/blob/v7.3.5/lib/parse-args.js#L8) so transition between tools will be much easier;
30
29
 
31
30
  ### ❌ Incorrect code example
@@ -35,8 +34,8 @@ npm i @putout/plugin-package-json -D
35
34
  ```json
36
35
  {
37
36
  "nyc": {
38
- "check-coverage": true,
39
- "all": true,
37
+ "check-coverage": "on",
38
+ "all": "on",
40
39
  "exclude": [
41
40
  "**/*.spec.js",
42
41
  "**/fixture",
@@ -57,8 +56,8 @@ File `.nycrc.json`:
57
56
 
58
57
  ```json
59
58
  {
60
- "check-coverage": true,
61
- "all": true,
59
+ "check-coverage": "on",
60
+ "all": "on",
62
61
  "exclude": [
63
62
  "**/*.spec.js",
64
63
  "**/fixture",
@@ -72,7 +71,18 @@ File `.nycrc.json`:
72
71
  }
73
72
  ```
74
73
 
74
+ ## add-type
75
+
76
+ Add [`type`](https://nodejs.org/dist/latest-v17.x/docs/api/packages.html#type) field to `package.json`:
77
+
78
+ ```diff
79
+ {
80
+ "name": "hello",
81
+ "version": "1.0.0",
82
+ + "type": "commonjs"
83
+ }
84
+ ```
85
+
75
86
  ## License
76
87
 
77
88
  MIT
78
-
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ operator,
5
+ types,
6
+ } = require('putout');
7
+
8
+ const {
9
+ ObjectProperty,
10
+ StringLiteral,
11
+ } = types;
12
+
13
+ const {getProperties} = operator;
14
+
15
+ module.exports.report = () => `Add 'type' of module to 'package.json'`;
16
+
17
+ module.exports.traverse = ({push}) => ({
18
+ '__putout_processor_json(__a)': (path) => {
19
+ const __aPath = path.get('arguments.0');
20
+ const {versionPath, typePath} = getProperties(__aPath, ['version', 'type']);
21
+
22
+ if (typePath)
23
+ return;
24
+
25
+ if (!versionPath)
26
+ return;
27
+
28
+ push(versionPath);
29
+ },
30
+ });
31
+
32
+ module.exports.fix = (path) => {
33
+ const node = ObjectProperty(StringLiteral('type'), StringLiteral('commonjs'));
34
+ path.insertAfter(node);
35
+ };
36
+
package/lib/index.js CHANGED
@@ -6,5 +6,6 @@ const getRule = (a) => ({
6
6
 
7
7
  module.exports.rules = {
8
8
  ...getRule('remove-nyc'),
9
+ ...getRule('add-type'),
9
10
  };
10
11
 
@@ -1,29 +1,22 @@
1
1
  'use strict';
2
2
 
3
- const getKey = (a) => a.key;
4
- const isNYC = (a) => a.value === 'nyc';
3
+ const {getProperties} = require('putout').operator;
5
4
 
6
- module.exports.report = () => 'Remove nyc section of package.json, use file .nycrc.json intead';
5
+ module.exports.report = () => `Remove 'nyc' section of 'package.json', use file '.nycrc.json' intead`;
7
6
 
8
- module.exports.match = () => ({
9
- '__putout_processor_json(__a)': ({__a}) => {
10
- return __a.properties
11
- .map(getKey)
12
- .filter(isNYC)
13
- .length;
14
- },
15
- });
7
+ module.exports.fix = (path) => {
8
+ path.remove();
9
+ };
16
10
 
17
- module.exports.replace = () => ({
18
- '__putout_processor_json(__a)': ({}, path) => {
19
- const properties = path.get('arguments.0.properties');
11
+ module.exports.traverse = ({push}) => ({
12
+ '__putout_processor_json(__a)': (path) => {
13
+ const __aPath = path.get('arguments.0');
14
+ const {nycPath} = getProperties(__aPath, ['nyc']);
20
15
 
21
- for (const propPath of properties) {
22
- if (propPath.get('key.value').node === 'nyc')
23
- propPath.remove();
24
- }
16
+ if (!nycPath)
17
+ return;
25
18
 
26
- return path;
19
+ push(nycPath);
27
20
  },
28
21
  });
29
22
 
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@putout/plugin-package-json",
3
- "version": "1.0.1",
3
+ "version": "3.0.0",
4
+ "type": "commonjs",
4
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
6
  "description": "putout plugin for package.json",
6
- "homepage": "http://github.com/coderaiser/putout",
7
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-package-json#readme",
7
8
  "main": "lib/index.js",
8
9
  "release": false,
9
10
  "tag": false,
@@ -16,8 +17,11 @@
16
17
  "test": "madrun test",
17
18
  "watch:test": "madrun watch:test",
18
19
  "lint": "madrun lint",
20
+ "fresh:lint": "madrun fresh:lint",
21
+ "lint:fresh": "madrun lint:fresh",
19
22
  "fix:lint": "madrun fix:lint",
20
- "coverage": "madrun coverage"
23
+ "coverage": "madrun coverage",
24
+ "report": "madrun report"
21
25
  },
22
26
  "dependencies": {},
23
27
  "keywords": [
@@ -27,22 +31,21 @@
27
31
  "package-json"
28
32
  ],
29
33
  "devDependencies": {
30
- "@putout/test": "^3.0.0",
31
- "coveralls": "^3.0.0",
32
- "eslint": "^7.6.0",
34
+ "@putout/test": "^4.0.0",
35
+ "c8": "^7.5.0",
36
+ "eslint": "^8.0.1",
33
37
  "eslint-plugin-node": "^11.0.0",
34
- "eslint-plugin-putout": "^6.0.0",
35
- "lerna": "^3.8.5",
38
+ "eslint-plugin-putout": "^12.0.0",
39
+ "lerna": "^4.0.0",
36
40
  "madrun": "^8.0.1",
37
- "nodemon": "^2.0.1",
38
- "nyc": "^15.0.1"
41
+ "nodemon": "^2.0.1"
39
42
  },
40
43
  "peerDependencies": {
41
- "putout": ">=11"
44
+ "putout": ">=24"
42
45
  },
43
46
  "license": "MIT",
44
47
  "engines": {
45
- "node": ">=12"
48
+ "node": ">=14"
46
49
  },
47
50
  "publishConfig": {
48
51
  "access": "public"