@putout/plugin-package-json 5.0.1 → 7.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 +12 -15
- package/lib/find-file/index.js +54 -0
- package/lib/index.js +5 -10
- package/lib/package-json.js +11 -0
- package/lib/remove-commit-type/index.js +6 -6
- package/lib/remove-nyc/index.js +6 -7
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -18,7 +18,8 @@ npm i @putout/plugin-package-json -D
|
|
|
18
18
|
"rules": {
|
|
19
19
|
"package-json/add-type": "on",
|
|
20
20
|
"package-json/remove-nyc": "on",
|
|
21
|
-
"package-json/remove-commit-type": "on"
|
|
21
|
+
"package-json/remove-commit-type": "on",
|
|
22
|
+
"package-json/find-file": "off"
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
```
|
|
@@ -97,6 +98,18 @@ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/eb12c902c
|
|
|
97
98
|
}
|
|
98
99
|
```
|
|
99
100
|
|
|
101
|
+
## find-file
|
|
102
|
+
|
|
103
|
+
Find `package.json` inside of `.filesystem.json` and applies all other `package-json` rules:
|
|
104
|
+
|
|
105
|
+
```diff
|
|
106
|
+
{
|
|
107
|
+
"name": "hello",
|
|
108
|
+
"version": "1.0.0",
|
|
109
|
+
+ "type": "commonjs"
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
100
113
|
## License
|
|
101
114
|
|
|
102
115
|
MIT
|
package/lib/add-type/index.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
operator,
|
|
5
3
|
types,
|
|
6
|
-
}
|
|
4
|
+
} from 'putout';
|
|
7
5
|
|
|
6
|
+
const {ObjectProperty, StringLiteral} = types;
|
|
8
7
|
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
getProperties,
|
|
9
|
+
insertAfter,
|
|
10
|
+
__json,
|
|
11
|
+
} = operator;
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
export const report = () => `Add 'type' of module to 'package.json'`;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
module.exports.traverse = ({push}) => ({
|
|
18
|
-
'__putout_processor_json(__a)': (path) => {
|
|
15
|
+
export const traverse = ({push}) => ({
|
|
16
|
+
[__json]: (path) => {
|
|
19
17
|
const __aPath = path.get('arguments.0');
|
|
20
18
|
const {versionPath, typePath} = getProperties(__aPath, ['version', 'type']);
|
|
21
19
|
|
|
@@ -29,8 +27,7 @@ module.exports.traverse = ({push}) => ({
|
|
|
29
27
|
},
|
|
30
28
|
});
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
export const fix = (path) => {
|
|
33
31
|
const node = ObjectProperty(StringLiteral('type'), StringLiteral('commonjs'));
|
|
34
|
-
|
|
32
|
+
insertAfter(path, node);
|
|
35
33
|
};
|
|
36
|
-
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
operator,
|
|
3
|
+
parse,
|
|
4
|
+
print,
|
|
5
|
+
transform,
|
|
6
|
+
} from 'putout';
|
|
7
|
+
import rules from '../package-json.js';
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
findFile,
|
|
11
|
+
readFileContent,
|
|
12
|
+
writeFileContent,
|
|
13
|
+
toJS,
|
|
14
|
+
fromJS,
|
|
15
|
+
} = operator;
|
|
16
|
+
|
|
17
|
+
const plugins = Object.entries(rules);
|
|
18
|
+
|
|
19
|
+
export const report = () => `Find 'package.json'`;
|
|
20
|
+
|
|
21
|
+
export const fix = (file, {ast, content}) => {
|
|
22
|
+
transform(ast, content, {
|
|
23
|
+
plugins,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
writeFileContent(file, fromJS(print(ast)));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const scan = (root, {push, progress}) => {
|
|
30
|
+
const files = findFile(root, 'package.json');
|
|
31
|
+
const n = files.length;
|
|
32
|
+
|
|
33
|
+
for (const [i, file] of files.entries()) {
|
|
34
|
+
const content = toJS(readFileContent(file));
|
|
35
|
+
const ast = parse(content);
|
|
36
|
+
const places = transform(ast, content, {
|
|
37
|
+
fix: false,
|
|
38
|
+
plugins,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!places.length)
|
|
42
|
+
continue;
|
|
43
|
+
|
|
44
|
+
push(file, {
|
|
45
|
+
content,
|
|
46
|
+
ast,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
progress({
|
|
50
|
+
i,
|
|
51
|
+
n,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import packageJson from './package-json.js';
|
|
2
|
+
import * as findFile from './find-file/index.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
module.exports.rules = {
|
|
8
|
-
...getRule('add-type'),
|
|
9
|
-
...getRule('remove-nyc'),
|
|
10
|
-
...getRule('remove-commit-type'),
|
|
4
|
+
export const rules = {
|
|
5
|
+
...packageJson,
|
|
6
|
+
'find-file': ['off', findFile],
|
|
11
7
|
};
|
|
12
|
-
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as addType from './add-type/index.js';
|
|
2
|
+
import * as removeNyc from './remove-nyc/index.js';
|
|
3
|
+
import * as removeCommitType from './remove-commit-type/index.js';
|
|
4
|
+
|
|
5
|
+
const rules = {
|
|
6
|
+
'add-type': addType,
|
|
7
|
+
'remove-nyc': removeNyc,
|
|
8
|
+
'remove-commit-type': removeCommitType,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default rules;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import {operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {operator} = require('putout');
|
|
4
3
|
const {
|
|
5
4
|
getProperties,
|
|
6
5
|
remove,
|
|
6
|
+
__json,
|
|
7
7
|
} = operator;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export const report = () => `Remove 'commitType=colon' field of 'package.json', it is 'colon' by default`;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export const fix = (path) => {
|
|
12
12
|
remove(path);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export const traverse = ({push}) => ({
|
|
16
|
+
[__json]: (path) => {
|
|
17
17
|
const __aPath = path.get('arguments.0');
|
|
18
18
|
const {commitTypePath} = getProperties(__aPath, ['commitType']);
|
|
19
19
|
|
package/lib/remove-nyc/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import {operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {operator} = require('putout');
|
|
4
3
|
const {
|
|
5
4
|
remove,
|
|
6
5
|
getProperties,
|
|
6
|
+
__json,
|
|
7
7
|
} = operator;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
export const report = () => `Remove 'nyc' section of 'package.json', use file '.nycrc.json' instead`;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export const fix = (path) => {
|
|
12
12
|
remove(path);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export const traverse = ({push}) => ({
|
|
16
|
+
[__json]: (path) => {
|
|
17
17
|
const __aPath = path.get('arguments.0');
|
|
18
18
|
const {nycPath} = getProperties(__aPath, ['nyc']);
|
|
19
19
|
|
|
@@ -23,4 +23,3 @@ module.exports.traverse = ({push}) => ({
|
|
|
23
23
|
push(nycPath);
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
|
-
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-package-json",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin for package.json",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-package-json#readme",
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
"package-json"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@putout/test": "^
|
|
35
|
-
"c8": "^
|
|
34
|
+
"@putout/test": "^8.0.0",
|
|
35
|
+
"c8": "^8.0.0",
|
|
36
36
|
"eslint": "^8.0.1",
|
|
37
|
-
"eslint-plugin-n": "^
|
|
38
|
-
"eslint-plugin-putout": "^
|
|
37
|
+
"eslint-plugin-n": "^16.0.0",
|
|
38
|
+
"eslint-plugin-putout": "^22.0.0",
|
|
39
39
|
"lerna": "^6.0.1",
|
|
40
|
-
"madrun": "^
|
|
41
|
-
"nodemon": "^
|
|
40
|
+
"madrun": "^10.0.0",
|
|
41
|
+
"nodemon": "^3.0.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"putout": ">=
|
|
44
|
+
"putout": ">=34"
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|