@putout/plugin-package-json 6.0.0 β†’ 7.1.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
@@ -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,19 @@ 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
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/325233d19fde0acacadbcf1f42dd3bb2/124a50fe0e92c6c3cab24f8b87c33b202dc3e540).
105
+
106
+ ```diff
107
+ {
108
+ "name": "hello",
109
+ "version": "1.0.0",
110
+ + "type": "commonjs"
111
+ }
112
+ ```
113
+
100
114
  ## License
101
115
 
102
116
  MIT
@@ -1,18 +1,18 @@
1
- 'use strict';
2
-
3
- const {operator, types} = require('putout');
1
+ import {
2
+ operator,
3
+ types,
4
+ } from 'putout';
4
5
 
5
6
  const {ObjectProperty, StringLiteral} = types;
6
-
7
7
  const {
8
8
  getProperties,
9
9
  insertAfter,
10
10
  __json,
11
11
  } = operator;
12
12
 
13
- module.exports.report = () => `Add 'type' of module to 'package.json'`;
13
+ export const report = () => `Add 'type' of module to 'package.json'`;
14
14
 
15
- module.exports.traverse = ({push}) => ({
15
+ export const traverse = ({push}) => ({
16
16
  [__json]: (path) => {
17
17
  const __aPath = path.get('arguments.0');
18
18
  const {versionPath, typePath} = getProperties(__aPath, ['version', 'type']);
@@ -27,7 +27,7 @@ module.exports.traverse = ({push}) => ({
27
27
  },
28
28
  });
29
29
 
30
- module.exports.fix = (path) => {
30
+ export const fix = (path) => {
31
31
  const node = ObjectProperty(StringLiteral('type'), StringLiteral('commonjs'));
32
32
  insertAfter(path, node);
33
33
  };
@@ -0,0 +1,45 @@
1
+ import {
2
+ operator,
3
+ parse,
4
+ print,
5
+ transform,
6
+ } from 'putout';
7
+ import rules from '../package-json.js';
8
+
9
+ const {
10
+ readFileContent,
11
+ writeFileContent,
12
+ toJS,
13
+ fromJS,
14
+ } = operator;
15
+
16
+ const plugins = Object.entries(rules);
17
+
18
+ export const report = () => `Find 'package.json'`;
19
+
20
+ export const fix = (file, {ast, content}) => {
21
+ transform(ast, content, {
22
+ plugins,
23
+ });
24
+
25
+ writeFileContent(file, fromJS(print(ast)));
26
+ };
27
+
28
+ export const scan = (root, {push, trackFile}) => {
29
+ for (const file of trackFile(root, 'package.json')) {
30
+ const content = toJS(readFileContent(file));
31
+ const ast = parse(content);
32
+ const places = transform(ast, content, {
33
+ fix: false,
34
+ plugins,
35
+ });
36
+
37
+ if (!places.length)
38
+ continue;
39
+
40
+ push(file, {
41
+ content,
42
+ ast,
43
+ });
44
+ }
45
+ };
package/lib/index.js CHANGED
@@ -1,11 +1,7 @@
1
- 'use strict';
1
+ import packageJson from './package-json.js';
2
+ import * as findFile from './find-file/index.js';
2
3
 
3
- const addType = require('./add-type');
4
- const removeNyc = require('./remove-nyc');
5
- const removeCommitType = require('./remove-commit-type');
6
-
7
- module.exports.rules = {
8
- 'add-type': addType,
9
- 'remove-nyc': removeNyc,
10
- 'remove-commit-type': removeCommitType,
4
+ export const rules = {
5
+ ...packageJson,
6
+ 'find-file': ['off', findFile],
11
7
  };
@@ -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,18 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {
5
4
  getProperties,
6
5
  remove,
7
6
  __json,
8
7
  } = operator;
9
8
 
10
- module.exports.report = () => `Remove 'commitType=colon' field of 'package.json', it is 'colon' by default`;
9
+ export const report = () => `Remove 'commitType=colon' field of 'package.json', it is 'colon' by default`;
11
10
 
12
- module.exports.fix = (path) => {
11
+ export const fix = (path) => {
13
12
  remove(path);
14
13
  };
15
14
 
16
- module.exports.traverse = ({push}) => ({
15
+ export const traverse = ({push}) => ({
17
16
  [__json]: (path) => {
18
17
  const __aPath = path.get('arguments.0');
19
18
  const {commitTypePath} = getProperties(__aPath, ['commitType']);
@@ -1,19 +1,18 @@
1
- 'use strict';
1
+ import {operator} from 'putout';
2
2
 
3
- const {operator} = require('putout');
4
3
  const {
5
4
  remove,
6
5
  getProperties,
7
6
  __json,
8
7
  } = operator;
9
8
 
10
- module.exports.report = () => `Remove 'nyc' section of 'package.json', use file '.nycrc.json' instead`;
9
+ export const report = () => `Remove 'nyc' section of 'package.json', use file '.nycrc.json' instead`;
11
10
 
12
- module.exports.fix = (path) => {
11
+ export const fix = (path) => {
13
12
  remove(path);
14
13
  };
15
14
 
16
- module.exports.traverse = ({push}) => ({
15
+ export const traverse = ({push}) => ({
17
16
  [__json]: (path) => {
18
17
  const __aPath = path.get('arguments.0');
19
18
  const {nycPath} = getProperties(__aPath, ['nyc']);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/plugin-package-json",
3
- "version": "6.0.0",
4
- "type": "commonjs",
3
+ "version": "7.1.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": "^7.0.0",
34
+ "@putout/test": "^8.0.0",
35
35
  "c8": "^8.0.0",
36
36
  "eslint": "^8.0.1",
37
37
  "eslint-plugin-n": "^16.0.0",
38
- "eslint-plugin-putout": "^21.0.0",
38
+ "eslint-plugin-putout": "^22.0.0",
39
39
  "lerna": "^6.0.1",
40
- "madrun": "^9.0.0",
40
+ "madrun": "^10.0.0",
41
41
  "nodemon": "^3.0.1"
42
42
  },
43
43
  "peerDependencies": {
44
- "putout": ">=33"
44
+ "putout": ">=34"
45
45
  },
46
46
  "license": "MIT",
47
47
  "engines": {
48
- "node": ">=16"
48
+ "node": ">=18"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"