@putout/plugin-package-json 8.2.2 → 8.3.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.
@@ -3,10 +3,7 @@ import {operator, types} from 'putout';
3
3
  const {isObjectExpression} = types;
4
4
  const {getProperty, __json} = operator;
5
5
 
6
- export const report = ({node}) => {
7
- const key = node.key.value;
8
- const {value} = node.value;
9
-
6
+ export const report = ({key, value}) => {
10
7
  return `${key} -> ${value}`;
11
8
  };
12
9
 
@@ -26,7 +23,38 @@ export const traverse = ({push}) => ({
26
23
  return;
27
24
 
28
25
  for (const property of objectPath.get('properties')) {
29
- push(property);
26
+ const valuePath = property.get('value');
27
+ const keyPath = property.get('key');
28
+
29
+ if (valuePath.isObjectExpression()) {
30
+ processNested({
31
+ push,
32
+ keyPath,
33
+ valuePath,
34
+ });
35
+ continue;
36
+ }
37
+
38
+ push({
39
+ path: property,
40
+ key: keyPath.node.value,
41
+ value: valuePath.node.value,
42
+ });
30
43
  }
31
44
  },
32
45
  });
46
+
47
+ function processNested({push, keyPath, valuePath}) {
48
+ const root = keyPath.node.value;
49
+
50
+ for (const property of valuePath.get('properties')) {
51
+ const key = `${root}+${property.node.key.value}`;
52
+ const {value} = property.node.value;
53
+
54
+ push({
55
+ key,
56
+ value,
57
+ path: property,
58
+ });
59
+ }
60
+ }
@@ -21,8 +21,13 @@ const {
21
21
 
22
22
  export const report = () => `Avoid exports with missing files`;
23
23
 
24
- export const fix = (file, {ast, source}) => {
24
+ export const fix = (file, {key, ast, source}) => {
25
25
  transform(ast, source, {
26
+ rules: {
27
+ 'remove-keys': ['on', {
28
+ keys: [key],
29
+ }],
30
+ },
26
31
  plugins: [
27
32
  ['remove-keys', removeKeys],
28
33
  ],
@@ -60,7 +65,6 @@ export const scan = (root, {push, trackFile}) => {
60
65
 
61
66
  for (const [key, name] of tuples) {
62
67
  const full = join(dir, name);
63
-
64
68
  const [exportedFile] = findFile(dirPath, full);
65
69
 
66
70
  if (!exportedFile)
@@ -19,16 +19,39 @@ export const fix = (path) => {
19
19
 
20
20
  export const traverse = ({push, options}) => ({
21
21
  [__json](path) {
22
- const {keys = ['./loader']} = options;
23
-
22
+ const {keys = []} = options;
24
23
  const object = path.get('arguments.0');
25
24
  const exportsPath = getProperty(object, 'exports');
26
25
 
27
26
  for (const property of exportsPath.get('value.properties')) {
28
27
  const {value} = property.node.key;
29
28
 
30
- if (keys.includes(value))
31
- push(property);
29
+ for (const key of keys) {
30
+ if (key === value) {
31
+ push(property);
32
+ continue;
33
+ }
34
+
35
+ if (key.includes('+'))
36
+ processNested({
37
+ key,
38
+ value,
39
+ property,
40
+ push,
41
+ });
42
+ }
32
43
  }
33
44
  },
34
45
  });
46
+
47
+ function processNested({key, value, property, push}) {
48
+ const [one, two] = key.split('+');
49
+
50
+ if (one !== value)
51
+ return;
52
+
53
+ for (const current of property.get('value.properties')) {
54
+ if (two === current.node.key.value)
55
+ push(current);
56
+ }
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-package-json",
3
- "version": "8.2.2",
3
+ "version": "8.3.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin for package.json",