@putout/plugin-package-json 1.0.0 → 2.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 +21 -11
- package/lib/add-type/index.js +36 -0
- package/lib/index.js +1 -0
- package/lib/remove-nyc/index.js +12 -18
- package/package.json +16 -13
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
# @putout/plugin-package-json [![NPM version][NPMIMGURL]][NPMURL]
|
|
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
|
|
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
|
|
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":
|
|
39
|
-
"all":
|
|
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":
|
|
61
|
-
"all":
|
|
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 {findProperties} = 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} = findProperties(__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
package/lib/remove-nyc/index.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const isNYC = (a) => a.value === 'nyc';
|
|
3
|
+
const {findProperties} = require('putout').operator;
|
|
5
4
|
|
|
6
|
-
module.exports.report = () =>
|
|
5
|
+
module.exports.report = () => `Remove 'nyc' section of 'package.json', use file '.nycrc.json' intead`;
|
|
7
6
|
|
|
8
|
-
module.exports.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.map(getValue)
|
|
12
|
-
.filter(isNYC);
|
|
13
|
-
},
|
|
14
|
-
});
|
|
7
|
+
module.exports.fix = (path) => {
|
|
8
|
+
path.remove();
|
|
9
|
+
};
|
|
15
10
|
|
|
16
|
-
module.exports.
|
|
17
|
-
'__putout_processor_json(__a)': (
|
|
18
|
-
const
|
|
11
|
+
module.exports.traverse = ({push}) => ({
|
|
12
|
+
'__putout_processor_json(__a)': (path) => {
|
|
13
|
+
const __aPath = path.get('arguments.0');
|
|
14
|
+
const {nycPath} = findProperties(__aPath, ['nyc']);
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
propPath.remove();
|
|
23
|
-
}
|
|
16
|
+
if (!nycPath)
|
|
17
|
+
return;
|
|
24
18
|
|
|
25
|
-
|
|
19
|
+
push(nycPath);
|
|
26
20
|
},
|
|
27
21
|
});
|
|
28
22
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-package-json",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.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": "
|
|
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": "^
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"lerna": "^
|
|
34
|
+
"@putout/test": "^4.0.0",
|
|
35
|
+
"c8": "^7.5.0",
|
|
36
|
+
"eslint": "^8.0.1",
|
|
37
|
+
"eslint-plugin-node": "^11.0.0",
|
|
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": ">=
|
|
44
|
+
"putout": ">=23"
|
|
42
45
|
},
|
|
43
46
|
"license": "MIT",
|
|
44
47
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
48
|
+
"node": ">=14"
|
|
46
49
|
},
|
|
47
50
|
"publishConfig": {
|
|
48
51
|
"access": "public"
|