putout 31.7.0 → 31.8.1

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,19 @@
1
+ 2023.08.31, v31.8.1
2
+
3
+ feature:
4
+ - c8319fbc9 package: @putout/plugin-for-of v3.0.0
5
+ - 969cd067f @putout/plugin-for-of: for-each: report
6
+ - 83fa6b0de @putout/plugin-nodejs: declare: process: improve Deno support
7
+
8
+ 2023.08.29, v31.8.0
9
+
10
+ feature:
11
+ - 182b6aaf7 @putout/engine-loader: re-structure
12
+ - 3ded6f846 putout: putoutAsync: simplify
13
+ - 06c131ab6 @putout/engine-loader: import: shorten
14
+ - d79e746e8 scripts: generate-schema: add
15
+ - 57d3261e4 @putout/plugin-minify: convert to ESM
16
+
1
17
  2023.08.28, v31.7.0
2
18
 
3
19
  feature:
package/bin/putout.mjs CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  readFile,
5
5
  writeFile,
6
6
  } from 'node:fs/promises';
7
+ import process from 'node:process';
7
8
  import cli from '../lib/cli/index.js';
8
9
 
9
10
  const {stdout} = process;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const process = require('process');
3
4
  const {join, dirname} = require('path');
4
5
 
5
6
  const buildPlugins = require('./build-plugins');
package/lib/cli/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const process = require('process');
3
4
  const tryToCatch = require('try-to-catch');
4
5
 
5
6
  const yargsParser = require('yargs-parser');
package/lib/loader.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import putout from './putout.js';
2
3
  import ignores from './ignores.js';
3
4
  import parseOptions from './parse-options/index.js';
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const process = require('process');
3
4
  const {homedir} = require('os');
4
5
  const {readdirSync} = require('fs');
5
6
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {platform} = process;
3
+ const {platform} = require('process');
4
4
 
5
5
  module.exports = (a) => {
6
6
  a = wild(a);
package/lib/putout.js CHANGED
@@ -14,12 +14,6 @@ const {
14
14
 
15
15
  const {cutShebang, mergeShebang} = require('./shebang');
16
16
 
17
- const {
18
- putoutAsync,
19
- transformAsync,
20
- findPlacesAsync,
21
- } = require('./putout-async');
22
-
23
17
  const isString = (a) => typeof a === 'string';
24
18
 
25
19
  const defaultOpts = (opts = {}) => {
@@ -29,6 +23,7 @@ const defaultOpts = (opts = {}) => {
29
23
  fix = true,
30
24
  fixCount = 2,
31
25
  loadPlugins = loader.loadPlugins,
26
+ loadPluginsAsync = loader.loadPluginsAsync,
32
27
  runPlugins = runner.runPlugins,
33
28
  } = opts;
34
29
 
@@ -39,6 +34,7 @@ const defaultOpts = (opts = {}) => {
39
34
  fix,
40
35
  fixCount,
41
36
  loadPlugins,
37
+ loadPluginsAsync,
42
38
  runPlugins,
43
39
  };
44
40
  };
@@ -89,8 +85,52 @@ module.exports = (source, opts) => {
89
85
  };
90
86
  };
91
87
 
92
- module.exports.putoutAsync = putoutAsync;
93
- module.exports.findPlacesAsync = findPlacesAsync;
88
+ module.exports.putoutAsync = async (source, opts) => {
89
+ check(source);
90
+ opts = defaultOpts(opts);
91
+
92
+ const {
93
+ parser,
94
+ isTS,
95
+ isFlow,
96
+ isJSX,
97
+ sourceFileName,
98
+ sourceMapName,
99
+ printer,
100
+ } = opts;
101
+
102
+ const [clearSource, shebang] = cutShebang(source);
103
+
104
+ const ast = parse(clearSource, {
105
+ sourceFileName,
106
+ parser,
107
+ isTS,
108
+ isFlow,
109
+ isJSX,
110
+ printer,
111
+ });
112
+
113
+ const places = await transformAsync(ast, source, opts);
114
+
115
+ if (!opts.fix)
116
+ return {
117
+ code: source,
118
+ places,
119
+ };
120
+
121
+ const printed = print(ast, {
122
+ sourceMapName,
123
+ printer,
124
+ });
125
+
126
+ const code = mergeShebang(shebang, printed);
127
+
128
+ return {
129
+ code,
130
+ places,
131
+ };
132
+ };
133
+
94
134
  module.exports.transformAsync = transformAsync;
95
135
  module.exports.findPlaces = (ast, source, opts) => {
96
136
  return transform(ast, source, {
@@ -98,6 +138,44 @@ module.exports.findPlaces = (ast, source, opts) => {
98
138
  fix: false,
99
139
  });
100
140
  };
141
+ module.exports.findPlacesAsync = async (ast, source, opts) => {
142
+ return await transformAsync(ast, source, {
143
+ ...opts,
144
+ fix: false,
145
+ });
146
+ };
147
+
148
+ async function transformAsync(ast, source, opts) {
149
+ opts = defaultOpts(opts);
150
+
151
+ const {
152
+ plugins: pluginNames,
153
+ cache,
154
+ rules,
155
+ fix,
156
+ fixCount,
157
+ loadPluginsAsync,
158
+ runPlugins,
159
+ } = opts;
160
+
161
+ const [, shebang] = cutShebang(source);
162
+
163
+ const plugins = await loadPluginsAsync({
164
+ pluginNames,
165
+ cache,
166
+ rules,
167
+ });
168
+
169
+ const places = runPlugins({
170
+ ast,
171
+ shebang,
172
+ fix,
173
+ fixCount,
174
+ plugins,
175
+ });
176
+
177
+ return places;
178
+ }
101
179
 
102
180
  // why we pass 'source' to 'transform()'?
103
181
  // because we need to calculate position in a right way
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "31.7.0",
3
+ "version": "31.8.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json",
@@ -100,7 +100,7 @@
100
100
  "@putout/plugin-eslint": "^5.0.0",
101
101
  "@putout/plugin-extract-object-properties": "^9.0.0",
102
102
  "@putout/plugin-extract-sequence-expressions": "^3.0.0",
103
- "@putout/plugin-for-of": "^2.0.0",
103
+ "@putout/plugin-for-of": "^3.0.0",
104
104
  "@putout/plugin-github": "^7.0.0",
105
105
  "@putout/plugin-gitignore": "^3.0.0",
106
106
  "@putout/plugin-logical-expressions": "^4.0.0",
@@ -1,160 +0,0 @@
1
- 'use strict';
2
-
3
- const {traverse, types} = require('@putout/babel');
4
-
5
- const loader = require('@putout/engine-loader');
6
- const runner = require('@putout/engine-runner');
7
-
8
- const {
9
- parse,
10
- print,
11
- generate,
12
- template,
13
- } = require('@putout/engine-parser');
14
-
15
- const {cutShebang, mergeShebang} = require('./shebang');
16
-
17
- const isString = (a) => typeof a === 'string';
18
-
19
- const defaultOpts = (opts = {}) => {
20
- const {
21
- parser = 'babel',
22
- printer = opts.printer || 'putout',
23
- fix = true,
24
- fixCount = 2,
25
- loadPlugins = loader.loadPlugins,
26
- loadPluginsAsync = loader.loadPluginsAsync,
27
- runPlugins = runner.runPlugins,
28
- } = opts;
29
-
30
- return {
31
- ...opts,
32
- parser,
33
- printer,
34
- fix,
35
- fixCount,
36
- loadPlugins,
37
- loadPluginsAsync,
38
- runPlugins,
39
- };
40
- };
41
-
42
- module.exports.putoutAsync = async (source, opts) => {
43
- check(source);
44
- opts = defaultOpts(opts);
45
-
46
- const {
47
- parser,
48
- isTS,
49
- isFlow,
50
- isJSX,
51
- sourceFileName,
52
- sourceMapName,
53
- printer,
54
- } = opts;
55
-
56
- const [clearSource, shebang] = cutShebang(source);
57
-
58
- const ast = parse(clearSource, {
59
- sourceFileName,
60
- parser,
61
- isTS,
62
- isFlow,
63
- isJSX,
64
- printer,
65
- });
66
-
67
- const places = await transformAsync(ast, source, opts);
68
-
69
- if (!opts.fix)
70
- return {
71
- code: source,
72
- places,
73
- };
74
-
75
- const printed = print(ast, {
76
- sourceMapName,
77
- printer,
78
- });
79
-
80
- const code = mergeShebang(shebang, printed);
81
-
82
- return {
83
- code,
84
- places,
85
- };
86
- };
87
-
88
- module.exports.findPlacesAsync = async (ast, source, opts) => {
89
- return await transformAsync(ast, source, {
90
- ...opts,
91
- fix: false,
92
- });
93
- };
94
-
95
- // why we pass 'source' to 'transform()'?
96
- // because we need to calculate position in a right way
97
- // and determine is shebang is exists
98
- //
99
- // 25 return {¬
100
- // 26 line: shebang ? line + 1 : line,¬
101
- // 27 column,¬
102
- // 28 };¬
103
- //
104
- module.exports.transformAsync = transformAsync;
105
- async function transformAsync(ast, source, opts) {
106
- opts = defaultOpts(opts);
107
-
108
- const {
109
- plugins: pluginNames,
110
- cache,
111
- rules,
112
- fix,
113
- fixCount,
114
- loadPluginsAsync,
115
- runPlugins,
116
- } = opts;
117
-
118
- const [, shebang] = cutShebang(source);
119
-
120
- const plugins = await loadPluginsAsync({
121
- pluginNames,
122
- cache,
123
- rules,
124
- });
125
-
126
- const places = runPlugins({
127
- ast,
128
- shebang,
129
- fix,
130
- fixCount,
131
- plugins,
132
- });
133
-
134
- return places;
135
- }
136
-
137
- module.exports.parse = parse;
138
- module.exports.print = print;
139
- module.exports.traverse = traverse;
140
- module.exports.types = types;
141
- module.exports.template = template;
142
- module.exports.generate = generate;
143
- module.exports.initReport = require('./cli/report');
144
-
145
- module.exports.operator = {
146
- ...require('@putout/operate'),
147
- ...require('@putout/compare'),
148
- ...require('@putout/traverse'),
149
- ...require('@putout/operator-declare'),
150
- ...require('@putout/operator-regexp'),
151
- ...require('@putout/operator-add-args'),
152
- };
153
-
154
- module.exports.ignores = require('./ignores');
155
- module.exports.codeframe = require('./codeframe');
156
-
157
- function check(source) {
158
- if (!isString(source))
159
- throw Error(`☝️ Looks like 'source' has type '${typeof source}', expected: 'string'`);
160
- }