@putout/plugin-package-json 1.0.3 → 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 +14 -1
- package/lib/add-type/index.js +36 -0
- package/lib/index.js +1 -0
- package/lib/remove-nyc/index.js +11 -15
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -16,7 +16,8 @@ npm i @putout/plugin-package-json -D
|
|
|
16
16
|
```json
|
|
17
17
|
{
|
|
18
18
|
"rules": {
|
|
19
|
-
"package-json/remove-nyc": "on"
|
|
19
|
+
"package-json/remove-nyc": "on",
|
|
20
|
+
"package-json/add-type": "on"
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
```
|
|
@@ -70,6 +71,18 @@ File `.nycrc.json`:
|
|
|
70
71
|
}
|
|
71
72
|
```
|
|
72
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
|
+
|
|
73
86
|
## License
|
|
74
87
|
|
|
75
88
|
MIT
|
|
@@ -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,26 +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
5
|
module.exports.report = () => `Remove 'nyc' section of 'package.json', use file '.nycrc.json' intead`;
|
|
7
6
|
|
|
8
|
-
module.exports.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.filter(isNYC).length,
|
|
12
|
-
});
|
|
7
|
+
module.exports.fix = (path) => {
|
|
8
|
+
path.remove();
|
|
9
|
+
};
|
|
13
10
|
|
|
14
|
-
module.exports.
|
|
15
|
-
'__putout_processor_json(__a)': (
|
|
16
|
-
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']);
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
propPath.remove();
|
|
21
|
-
}
|
|
16
|
+
if (!nycPath)
|
|
17
|
+
return;
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
push(nycPath);
|
|
24
20
|
},
|
|
25
21
|
});
|
|
26
22
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-package-json#readme",
|
|
@@ -40,11 +41,11 @@
|
|
|
40
41
|
"nodemon": "^2.0.1"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
|
-
"putout": ">=
|
|
44
|
+
"putout": ">=23"
|
|
44
45
|
},
|
|
45
46
|
"license": "MIT",
|
|
46
47
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
48
|
+
"node": ">=14"
|
|
48
49
|
},
|
|
49
50
|
"publishConfig": {
|
|
50
51
|
"access": "public"
|