redput 3.0.1 → 3.2.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/ChangeLog CHANGED
@@ -1,3 +1,18 @@
1
+ 2025.04.09, v3.2.0
2
+
3
+ feature:
4
+ - c72e004 redput: @putout/plugin-esm v4.0.0
5
+ - c9d2274 redput: supertape v11.1.0
6
+ - fedbcd9 redput: putout v40.0.1
7
+ - 17990f1 redput: @putout/test v13.0.1
8
+ - e99321c redput: @putout/plugin-putout v25.0.0
9
+
10
+ 2025.03.23, v3.1.0
11
+
12
+ feature:
13
+ - 803ea39 redput: @putout/plugin-nodejs v15.0.0
14
+ - f913157 redput: add-rule: esm
15
+
1
16
  2025.03.22, v3.0.1
2
17
 
3
18
  fix:
@@ -1,7 +1,8 @@
1
1
  import putout from 'putout';
2
2
  import * as pluginPutout from '@putout/plugin-putout';
3
- import nodejs from '@putout/plugin-nodejs';
4
- import removeUnusedVariables from '@putout/plugin-remove-unused-variables';
3
+ import * as nodejs from '@putout/plugin-nodejs';
4
+ import * as removeUnusedVariables from '@putout/plugin-remove-unused-variables';
5
+ import * as esm from '@putout/plugin-esm';
5
6
  import * as insertGetRulePlugin from './plugin-insert-get-rule/index.js';
6
7
 
7
8
  export const addRule = (name, source, ruleOptions) => {
@@ -12,6 +13,8 @@ export const addRule = (name, source, ruleOptions) => {
12
13
  name,
13
14
  ruleOptions,
14
15
  }],
16
+ 'esm': 'off',
17
+ 'esm/add-index-to-import': 'on',
15
18
  'putout/declare': ['on', {
16
19
  dismiss: 'getRule',
17
20
  }],
@@ -21,8 +24,10 @@ export const addRule = (name, source, ruleOptions) => {
21
24
  ['putout', pluginPutout],
22
25
  ['remove-unused-variables', removeUnusedVariables],
23
26
  ['add-rule', insertGetRulePlugin],
27
+ ['esm', esm],
24
28
  ],
25
29
  });
26
30
 
27
31
  return code;
28
32
  };
33
+
@@ -4,7 +4,12 @@ import {
4
4
  template,
5
5
  } from 'putout';
6
6
 
7
- const {spreadElement, stringLiteral} = types;
7
+ const {
8
+ spreadElement,
9
+ stringLiteral,
10
+ isSpreadElement,
11
+ } = types;
12
+
8
13
  const {traverse} = operator;
9
14
 
10
15
  export const report = () => `Insert 'getRule()'`;
@@ -12,43 +17,65 @@ export const report = () => `Insert 'getRule()'`;
12
17
  const createRule = template('getRule(%%name%%)');
13
18
  const createRuleWithOptions = template('getRule(%%name%%, "off")');
14
19
 
15
- export const match = ({options}) => ({
16
- 'module.exports.rules = __object': ({__object}) => {
17
- let exists = false;
18
- const {name} = options;
19
-
20
- traverse(__object, {
21
- [`getRule('${name}')`]: () => {
22
- exists = true;
23
- },
24
- [`getRule('${name}', 'off')`]: () => {
25
- exists = true;
26
- },
27
- });
28
-
29
- return !exists;
30
- },
31
- });
20
+ export const match = ({options}) => {
21
+ const check = createCheck(options);
22
+
23
+ return {
24
+ 'module.exports.rules = __object': check,
25
+ 'export const rules = __object': check,
26
+ };
27
+ };
32
28
 
33
- export const replace = ({options}) => ({
34
- 'module.exports.rules = __object': ({__object}, path) => {
35
- const {name, ruleOptions} = options;
36
-
37
- if (ruleOptions) {
38
- const node = spreadElement(createRuleWithOptions({
39
- name: stringLiteral(name),
40
- }));
41
-
42
- __object.properties.push(node);
43
- return path;
44
- }
45
-
46
- const node = spreadElement(createRule({
29
+ export const replace = ({options}) => {
30
+ const addRule = createAddRule(options);
31
+
32
+ return {
33
+ 'module.exports.rules = __object': addRule,
34
+ 'export const rules = __object': addRule,
35
+ };
36
+ };
37
+
38
+ const createAddRule = (options) => ({__object}, path) => {
39
+ const {name, ruleOptions} = options;
40
+
41
+ if (ruleOptions) {
42
+ const node = spreadElement(createRuleWithOptions({
47
43
  name: stringLiteral(name),
48
44
  }));
49
45
 
50
46
  __object.properties.push(node);
51
-
52
47
  return path;
53
- },
54
- });
48
+ }
49
+
50
+ const node = spreadElement(createRule({
51
+ name: stringLiteral(name),
52
+ }));
53
+
54
+ __object.properties.push(node);
55
+
56
+ return path;
57
+ };
58
+
59
+ const createCheck = (options) => ({__object}) => {
60
+ let exists = false;
61
+ const {name} = options;
62
+
63
+ for (const prop of __object.properties) {
64
+ if (isSpreadElement(prop))
65
+ continue;
66
+
67
+ if (prop.key.value === name)
68
+ return false;
69
+ }
70
+
71
+ traverse(__object, {
72
+ [`getRule('${name}')`]: () => {
73
+ exists = true;
74
+ },
75
+ [`getRule('${name}', 'off')`]: () => {
76
+ exists = true;
77
+ },
78
+ });
79
+
80
+ return !exists;
81
+ };
@@ -1,7 +1,7 @@
1
1
  import putout from 'putout';
2
2
  import * as putoutPlugin from '@putout/plugin-putout';
3
- import declare from '@putout/plugin-declare';
4
- import declareBeforeReference from '@putout/plugin-declare-before-reference';
3
+ import * as declare from '@putout/plugin-declare';
4
+ import * as declareBeforeReference from '@putout/plugin-declare-before-reference';
5
5
 
6
6
  export const prepareRule = (source) => {
7
7
  const {code} = putout(source, {
@@ -14,3 +14,4 @@ export const prepareRule = (source) => {
14
14
 
15
15
  return code;
16
16
  };
17
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redput",
3
- "version": "3.0.1",
3
+ "version": "3.2.0",
4
4
  "description": "CLI tool to convert source from 🐊Putout Editor to files",
5
5
  "main": "lib/redput.js",
6
6
  "bin": {
@@ -57,18 +57,19 @@
57
57
  "dependencies": {
58
58
  "@putout/plugin-declare": "^5.0.0",
59
59
  "@putout/plugin-declare-before-reference": "^6.2.0",
60
- "@putout/plugin-nodejs": "^14.0.1",
61
- "@putout/plugin-putout": "^24.0.0",
60
+ "@putout/plugin-esm": "^4.0.0",
61
+ "@putout/plugin-nodejs": "^15.0.0",
62
+ "@putout/plugin-putout": "^25.0.0",
62
63
  "@putout/plugin-remove-unused-variables": "^12.0.0",
63
64
  "node-fetch": "^3.3.2",
64
65
  "octokit": "^4.0.2",
65
- "putout": "^39.0.9",
66
+ "putout": "^40.0.1",
66
67
  "rendy": "^4.1.3",
67
68
  "try-catch": "^3.0.1",
68
69
  "try-to-catch": "^3.0.1"
69
70
  },
70
71
  "devDependencies": {
71
- "@putout/test": "^12.1.0",
72
+ "@putout/test": "^13.0.1",
72
73
  "c8": "^10.1.2",
73
74
  "escover": "^4.0.1",
74
75
  "eslint": "^9.0.0",
@@ -77,7 +78,7 @@
77
78
  "montag": "^1.2.1",
78
79
  "nodemon": "^3.0.1",
79
80
  "redlint": "^4.0.0",
80
- "supertape": "^10.1.0"
81
+ "supertape": "^11.1.0"
81
82
  },
82
83
  "publishConfig": {
83
84
  "access": "public"