putout 34.10.0 → 34.11.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,9 @@
1
+ 2024.01.17, v34.11.0
2
+
3
+ feature:
4
+ - 27b2f7bda putout: add trace support
5
+ - 286e90e7b @putout/plugin-promise: convert-new-promise-to-async: exclude resolve inside event listener'
6
+
1
7
  2024.01.16, v34.10.0
2
8
 
3
9
  fix:
package/bin/putout.mjs CHANGED
@@ -1,22 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import {
4
+ parentPort,
5
+ workerData,
6
+ } from 'node:worker_threads';
7
+ import process from 'node:process';
3
8
  import {
4
9
  readFile,
5
10
  writeFile,
6
11
  } from 'node:fs/promises';
7
- import process from 'node:process';
12
+ import {createTrace} from './trace.mjs';
8
13
  import cli from '../lib/cli/index.js';
9
14
 
10
15
  const {stdout} = process;
11
16
  const write = stdout.write.bind(stdout);
12
17
  const logError = console.error;
13
18
 
14
- await cli({
19
+ const trace = createTrace(parentPort);
20
+
21
+ export default await cli({
15
22
  write,
16
23
  halt: process.exit,
17
- argv: process.argv.slice(2),
24
+ argv: [
25
+ ...process.argv.slice(2),
26
+ ...(workerData || []).slice(2),
27
+ ],
18
28
  log: console.log,
19
29
  logError,
20
30
  readFile,
21
31
  writeFile,
32
+ trace,
22
33
  });
package/bin/trace.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export const createTrace = (parentPort) => (event, data) => {
2
+ parentPort?.postMessage([event, data]);
3
+ };
package/bin/tracer.mjs ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {Worker} from 'node:worker_threads';
4
+ import keyPress from '@putout/cli-keypress';
5
+ import progressBar from '@putout/formatter-progress-bar';
6
+ import process from 'node:process';
7
+
8
+ const slave = new URL('./putout.mjs', import.meta.url);
9
+
10
+ const worker = new Worker(slave, {
11
+ workerData: process.argv,
12
+ stdin: true,
13
+ });
14
+
15
+ const {isStop} = keyPress();
16
+
17
+ worker.on('message', ([event, data]) => {
18
+ let end = false;
19
+
20
+ if (event !== 'progress')
21
+ return;
22
+
23
+ if (isStop())
24
+ data.index = data.count - 1;
25
+
26
+ if (data.index === data.count - 1)
27
+ end = true;
28
+
29
+ process.stdout.write(progressBar(data));
30
+
31
+ if (end)
32
+ process.exit();
33
+ });
package/lib/cli/index.js CHANGED
@@ -45,6 +45,7 @@ const {
45
45
  INTERACTIVE_CANCELED,
46
46
  } = require('./exit-codes');
47
47
 
48
+ const noop = () => {};
48
49
  const {keys} = Object;
49
50
  const {isSupported} = supportedFiles;
50
51
  const getFormatter = nanomemoize(require('./formatter/formatter').getFormatter);
@@ -60,7 +61,9 @@ const getExitCode = (wasStop) => wasStop() ? WAS_STOP : OK;
60
61
  const isStr = (a) => typeof a === 'string';
61
62
  const {isArray} = Array;
62
63
 
63
- module.exports = async ({argv, halt, log, write, logError, readFile, writeFile}) => {
64
+ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile, trace = noop}) => {
65
+ trace('start');
66
+
64
67
  const {isStop} = keyPress();
65
68
  const wasStop = fullstore();
66
69
 
@@ -193,7 +196,6 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
193
196
 
194
197
  if (isStr(args.match)) {
195
198
  const {match} = await simpleImport('@putout/cli-match');
196
-
197
199
  const {code, message} = await match({
198
200
  pattern: args.match,
199
201
  cwd,
@@ -312,6 +314,7 @@ module.exports = async ({argv, halt, log, write, logError, readFile, writeFile})
312
314
  };
313
315
 
314
316
  const {places, exited} = await run({
317
+ trace,
315
318
  fix,
316
319
  exit,
317
320
  readFile,
package/lib/cli/report.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isArray} = Array;
4
+ const noop = () => {};
4
5
 
5
6
  module.exports = () => {
6
7
  let filesCount = 0;
@@ -14,6 +15,7 @@ module.exports = () => {
14
15
  places,
15
16
  index = 0,
16
17
  count = 1,
18
+ trace = noop,
17
19
  formatterOptions = {},
18
20
  } = options;
19
21
 
@@ -25,6 +27,18 @@ module.exports = () => {
25
27
 
26
28
  errorsCount += places.length;
27
29
 
30
+ trace('progress', {
31
+ rule,
32
+ name,
33
+ options: formatterOptions,
34
+ source,
35
+ places,
36
+ index,
37
+ count,
38
+ filesCount,
39
+ errorsCount,
40
+ });
41
+
28
42
  return await formatter({
29
43
  rule,
30
44
  name,
@@ -7,7 +7,7 @@ const parseError = require('../parse-error.js');
7
7
  const {simpleImport} = require('../simple-import');
8
8
  const ignores = require('../../ignores.js');
9
9
 
10
- module.exports.lint = async ({raw, log, dir, resolvedName, options, readFile, fix, processFile, processorRunners}) => {
10
+ module.exports.runReader = async ({raw, log, dir, resolvedName, options, readFile, fix, processFile, processorRunners}) => {
11
11
  let isProcessed = true;
12
12
  let places = [];
13
13
  let rawSource = '';
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const runWorker = require('./worker.js');
3
+ const {runWriter} = require('./writer.js');
4
4
  const initProcessFile = require('../process-file.js');
5
5
  const Report = require('../report.js');
6
6
 
7
7
  const report = Report();
8
8
 
9
- module.exports.run = async ({transform, plugins, noConfig, readFile, writeFile, exit, isStop, wasStop, names, write, log, rulesdir, fix, processorRunners, fileCache, currentFormat, formatterOptions, options, raw}) => {
9
+ module.exports.run = async ({transform, plugins, noConfig, readFile, writeFile, exit, isStop, wasStop, names, write, log, rulesdir, fix, processorRunners, fileCache, currentFormat, formatterOptions, options, raw, trace}) => {
10
10
  const processFile = initProcessFile(options);
11
11
  const {length} = names;
12
12
  const places = [];
@@ -16,10 +16,11 @@ module.exports.run = async ({transform, plugins, noConfig, readFile, writeFile,
16
16
  break;
17
17
 
18
18
  wasStop(isStop());
19
+
19
20
  const currentIndex = isStop() ? length - 1 : index;
20
21
  const name = names[index];
21
22
 
22
- const {exited, places: currentPlaces = []} = await runWorker({
23
+ const {exited, places: currentPlaces = []} = await runWriter({
23
24
  readFile,
24
25
  writeFile,
25
26
  exit,
@@ -40,6 +41,7 @@ module.exports.run = async ({transform, plugins, noConfig, readFile, writeFile,
40
41
  noConfig,
41
42
  plugins,
42
43
  transform,
44
+ trace,
43
45
  });
44
46
 
45
47
  places.push(...currentPlaces);
@@ -7,7 +7,7 @@ const {readFileSync} = require('fs');
7
7
  const tryCatch = require('try-catch');
8
8
  const getOptions = require('../get-options.js');
9
9
  const {INVALID_CONFIG, NO_PROCESSORS} = require('../exit-codes.js');
10
- const {lint} = require('./lint.js');
10
+ const {runReader} = require('./reader.js');
11
11
 
12
12
  const isParser = (rule) => rule.startsWith('parser');
13
13
  const isParsingError = ({rule}) => isParser(rule);
@@ -26,9 +26,8 @@ const createFormatterProxy = (options) => {
26
26
  });
27
27
  };
28
28
 
29
- module.exports = async ({readFile, report, writeFile, exit, raw, write, log, currentFormat, rulesdir, formatterOptions, noConfig, transform, plugins, index, fix, processFile, processorRunners, fileCache, name, count}) => {
29
+ module.exports.runWriter = async ({readFile, report, writeFile, exit, raw, write, log, currentFormat, rulesdir, formatterOptions, noConfig, transform, plugins, index, fix, processFile, processorRunners, fileCache, name, count, trace}) => {
30
30
  const resolvedName = resolve(name).replace(/^\./, cwd);
31
-
32
31
  const [configError, options] = tryCatch(getOptions, {
33
32
  name: resolvedName,
34
33
  rulesdir,
@@ -40,9 +39,8 @@ module.exports = async ({readFile, report, writeFile, exit, raw, write, log, cur
40
39
  if (configError)
41
40
  return exit(INVALID_CONFIG, configError);
42
41
 
43
- const {dir} = options;
44
-
45
42
  const success = await runCache({
43
+ trace,
46
44
  options,
47
45
  fileCache,
48
46
  report,
@@ -60,12 +58,14 @@ module.exports = async ({readFile, report, writeFile, exit, raw, write, log, cur
60
58
  success,
61
59
  };
62
60
 
61
+ const {dir} = options;
62
+
63
63
  const {
64
64
  places,
65
65
  isProcessed,
66
66
  rawSource,
67
67
  processedSource,
68
- } = await lint({
68
+ } = await runReader({
69
69
  raw,
70
70
  dir,
71
71
  fix,
@@ -84,6 +84,7 @@ module.exports = async ({readFile, report, writeFile, exit, raw, write, log, cur
84
84
  places,
85
85
  index,
86
86
  count,
87
+ trace,
87
88
  });
88
89
 
89
90
  write(line || '');
@@ -107,7 +108,7 @@ module.exports = async ({readFile, report, writeFile, exit, raw, write, log, cur
107
108
  };
108
109
  };
109
110
 
110
- async function runCache({fileCache, report, write, formatterOptions, currentFormat, name, resolvedName, index, count, options}) {
111
+ async function runCache({fileCache, report, write, formatterOptions, currentFormat, name, resolvedName, index, count, options, trace}) {
111
112
  if (!fileCache.canUseCache(name, options))
112
113
  return false;
113
114
 
@@ -118,6 +119,7 @@ async function runCache({fileCache, report, write, formatterOptions, currentForm
118
119
  places,
119
120
  index,
120
121
  count,
122
+ trace,
121
123
  });
122
124
 
123
125
  const line = await report(currentFormat, formatterProxy);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "34.10.0",
3
+ "version": "34.11.0",
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",
@@ -26,7 +26,8 @@
26
26
  "./ignores": "./lib/ignores.js"
27
27
  },
28
28
  "bin": {
29
- "putout": "bin/putout.mjs"
29
+ "putout": "bin/putout.mjs",
30
+ "trace": "bin/tracer.mjs"
30
31
  },
31
32
  "repository": {
32
33
  "type": "git",
@@ -34,16 +35,16 @@
34
35
  },
35
36
  "scripts": {
36
37
  "wisdom": "madrun wisdom",
37
- "test:raw": "madrun test:raw",
38
38
  "test": "madrun test",
39
+ "test:raw": "madrun test:raw",
39
40
  "watch:test": "madrun watch:test",
40
41
  "lint": "madrun lint",
42
+ "trace": "madrun trace",
41
43
  "fresh:lint": "madrun fresh:lint",
42
44
  "fix:lint": "madrun fix:lint",
43
45
  "fix:lint:fresh": "madrun fix:lint:fresh",
44
46
  "lint:progress": "madrun lint:progress",
45
47
  "lint:fresh": "madrun lint:fresh",
46
- "coverage:raw": "madrun coverage:raw",
47
48
  "coverage": "madrun coverage",
48
49
  "report": "madrun report"
49
50
  },