putout 41.1.3 → 41.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.
Files changed (47) hide show
  1. package/ChangeLog +14 -0
  2. package/bin/{debugger-exit.mjs → debugger-exit.js} +1 -1
  3. package/bin/{putout.mjs → putout.js} +7 -7
  4. package/bin/{tracer.mjs → tracer.js} +4 -4
  5. package/lib/cli/build-plugins.js +1 -3
  6. package/lib/cli/exit-codes.cjs +20 -0
  7. package/lib/cli/exit-codes.js +16 -20
  8. package/lib/cli/{exit.mjs → exit.js} +1 -1
  9. package/lib/cli/get-options.js +7 -8
  10. package/lib/cli/index.js +33 -36
  11. package/lib/cli/parse-args.js +3 -5
  12. package/lib/cli/runner/reader.js +6 -9
  13. package/lib/cli/runner/runner.js +3 -5
  14. package/lib/cli/runner/writer.js +8 -11
  15. package/lib/cli/simple-import.js +1 -3
  16. package/lib/cli/supported-files.js +8 -10
  17. package/lib/codeframe.js +2 -4
  18. package/lib/default-options.js +4 -6
  19. package/lib/find-places.js +3 -5
  20. package/lib/ignores.js +3 -5
  21. package/lib/loader/{loader.mjs → loader.js} +2 -2
  22. package/lib/parse-error.js +1 -3
  23. package/lib/parse-options/apply-module-type-rules.js +2 -3
  24. package/lib/parse-options/index.js +69 -31
  25. package/lib/parse-options/merge-options.js +2 -4
  26. package/lib/parse-options/parse-match.js +2 -4
  27. package/lib/parse-options/parse-sep.js +3 -5
  28. package/lib/parse-options/read-rules.js +3 -6
  29. package/lib/parse-options/recursive-read.js +8 -8
  30. package/lib/parse-options/validate-options/index.js +5 -5
  31. package/lib/putout.cjs +142 -0
  32. package/lib/putout.js +3 -141
  33. package/lib/shebang.js +2 -4
  34. package/lib/transform.js +7 -10
  35. package/package.json +9 -11
  36. package/lib/cli/exit-codes.mjs +0 -16
  37. package/lib/putout.mjs +0 -4
  38. /package/bin/{communication.mjs → communication.js} +0 -0
  39. /package/bin/{drop-interactive.mjs → drop-interactive.js} +0 -0
  40. /package/bin/{is-stop.mjs → is-stop.js} +0 -0
  41. /package/bin/{trace.mjs → trace.js} +0 -0
  42. /package/bin/{write.mjs → write.js} +0 -0
  43. /package/lib/cli/{chalk.mjs → chalk.js} +0 -0
  44. /package/lib/cli/{get-files.mjs → get-files.js} +0 -0
  45. /package/lib/cli/{help.mjs → help.js} +0 -0
  46. /package/lib/lint/{json.mjs → json.js} +0 -0
  47. /package/lib/loader/{register.mjs → register.js} +0 -0
package/ChangeLog CHANGED
@@ -1,3 +1,17 @@
1
+ 2025.12.30, v41.2.0
2
+
3
+ feature:
4
+ - 7fe065bfe babel-plugin-putout: drop support of 🐊 < 19
5
+ - 4b4d7bdc6 putout: migrate to ESM
6
+ - 29b1533c8 @putout/test: @putout/cli-process-file v5.0.0
7
+ - c13c11a69 putout: parse-options: get rid of mock-require
8
+ - df24380aa @putout/plugin-nodejs: convert-commonjs-to-esm: exports: ObjectExpression: with literal values
9
+
10
+ 2025.12.30, v41.1.4
11
+
12
+ feature:
13
+ - bc7b89136 putout: cli: migrate to ESM
14
+
1
15
  2025.12.30, v41.1.3
2
16
 
3
17
  fix:
@@ -1,4 +1,4 @@
1
- import {bgBlueBright} from '../lib/cli/chalk.mjs';
1
+ import {bgBlueBright} from '../lib/cli/chalk.js';
2
2
 
3
3
  export const onDebuggerExit = ({log, process, inspector}) => {
4
4
  const {pid} = process;
@@ -4,15 +4,15 @@ import process from 'node:process';
4
4
  import inspector from 'node:inspector';
5
5
  import {readFile, writeFile} from 'node:fs/promises';
6
6
  import {subscribe} from '@putout/engine-reporter/subscribe';
7
- import {createTrace} from './trace.mjs';
8
- import {createIsStop} from './is-stop.mjs';
9
- import {createWrite} from './write.mjs';
10
- import {createCommunication} from './communication.mjs';
7
+ import {createTrace} from './trace.js';
8
+ import {createIsStop} from './is-stop.js';
9
+ import {createWrite} from './write.js';
10
+ import {createCommunication} from './communication.js';
11
11
  import cli from '../lib/cli/index.js';
12
12
  import {parseArgs} from '../lib/cli/parse-args.js';
13
- import {createExit} from '../lib/cli/exit.mjs';
14
- import {onDebuggerExit} from './debugger-exit.mjs';
15
- import {dropInteractive} from './drop-interactive.mjs';
13
+ import {createExit} from '../lib/cli/exit.js';
14
+ import {onDebuggerExit} from './debugger-exit.js';
15
+ import {dropInteractive} from './drop-interactive.js';
16
16
 
17
17
  const halt = process.exit;
18
18
  const logError = console.error;
@@ -8,18 +8,18 @@ import process, {
8
8
  } from 'node:process';
9
9
  import {subscribe} from '@putout/engine-reporter/subscribe';
10
10
  import {parseArgs} from '../lib/cli/parse-args.js';
11
- import {createExit} from '../lib/cli/exit.mjs';
12
- import {dropInteractive} from './drop-interactive.mjs';
11
+ import {createExit} from '../lib/cli/exit.js';
12
+ import {dropInteractive} from './drop-interactive.js';
13
13
 
14
14
  const args = parseArgs(process.argv.slice(2));
15
15
  const write = stdout.write.bind(stdout);
16
16
 
17
17
  if (!args.worker) {
18
- await import('./putout.mjs');
18
+ await import('./putout.js');
19
19
  halt();
20
20
  }
21
21
 
22
- const slave = new URL('./putout.mjs', import.meta.url);
22
+ const slave = new URL('./putout.js', import.meta.url);
23
23
 
24
24
  const worker = new Worker(slave, {
25
25
  workerData: dropInteractive(process.argv),
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
1
  const name = '[transform]';
4
2
  const returns = (a) => () => a;
5
3
 
6
- module.exports = (line) => {
4
+ export default (line) => {
7
5
  if (!line)
8
6
  return [];
9
7
 
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ OK: 0,
5
+ PLACE: 1,
6
+ STAGE: 2,
7
+ NO_FILES: 3,
8
+ NO_PROCESSORS: 4,
9
+ NO_FORMATTER: 5,
10
+ WAS_STOP: 6,
11
+ INVALID_OPTION: 7,
12
+ CANNOT_LOAD_PROCESSOR: 8,
13
+ CANNOT_LOAD_FORMATTER: 9,
14
+ RULER_WITH_FIX: 10,
15
+ RULER_NO_FILES: 11,
16
+ INVALID_CONFIG: 12,
17
+ UNHANDLED: 13,
18
+ CANNOT_LINT_STAGED: 14,
19
+ INTERACTIVE_CANCELED: 15,
20
+ };
@@ -1,20 +1,16 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- OK: 0,
5
- PLACE: 1,
6
- STAGE: 2,
7
- NO_FILES: 3,
8
- NO_PROCESSORS: 4,
9
- NO_FORMATTER: 5,
10
- WAS_STOP: 6,
11
- INVALID_OPTION: 7,
12
- CANNOT_LOAD_PROCESSOR: 8,
13
- CANNOT_LOAD_FORMATTER: 9,
14
- RULER_WITH_FIX: 10,
15
- RULER_NO_FILES: 11,
16
- INVALID_CONFIG: 12,
17
- UNHANDLED: 13,
18
- CANNOT_LINT_STAGED: 14,
19
- INTERACTIVE_CANCELED: 15,
20
- };
1
+ export const OK = 0;
2
+ export const PLACE = 1;
3
+ export const STAGE = 2;
4
+ export const NO_FILES = 3;
5
+ export const NO_PROCESSORS = 4;
6
+ export const NO_FORMATTER = 5;
7
+ export const WAS_STOP = 6;
8
+ export const INVALID_OPTION = 7;
9
+ export const CANNOT_LOAD_PROCESSOR = 8;
10
+ export const CANNOT_LOAD_FORMATTER = 9;
11
+ export const RULER_WITH_FIX = 10;
12
+ export const RULER_NO_FILES = 11;
13
+ export const INVALID_CONFIG = 12;
14
+ export const UNHANDLED = 13;
15
+ export const CANNOT_LINT_STAGED = 14;
16
+ export const INTERACTIVE_CANCELED = 15;
@@ -1,4 +1,4 @@
1
- import {red} from './chalk.mjs';
1
+ import {red} from './chalk.js';
2
2
 
3
3
  export const createExit = ({halt, raw, logError}) => (code, e) => {
4
4
  if (!code)
@@ -1,11 +1,10 @@
1
- 'use strict';
2
-
3
- const process = require('node:process');
4
- const {join, dirname} = require('node:path');
5
-
6
- const buildPlugins = require('./build-plugins');
7
- const _parseOptions = require('../parse-options');
1
+ import process from 'node:process';
2
+ import {join, dirname} from 'node:path';
3
+ import {createRequire} from 'node:module';
4
+ import buildPlugins from './build-plugins.js';
5
+ import {parseOptions as _parseOptions} from '../parse-options/index.js';
8
6
 
7
+ const require = createRequire(import.meta.url);
9
8
  const {assign} = Object;
10
9
  const {env} = process;
11
10
 
@@ -24,7 +23,7 @@ const getMaybeConfig = () => {
24
23
  return config;
25
24
  };
26
25
 
27
- module.exports = (overrides = {}) => {
26
+ export default (overrides = {}) => {
28
27
  const {
29
28
  noConfig,
30
29
  plugins = [],
package/lib/cli/index.js CHANGED
@@ -1,34 +1,31 @@
1
- 'use strict';
2
-
3
- const process = require('node:process');
4
- const tryToCatch = require('try-to-catch');
5
-
6
- const {isCI: _isCI} = require('ci-info');
7
- const {nanomemoize} = require('nano-memoize');
8
- const tryCatch = require('try-catch');
9
- const wraptile = require('wraptile');
10
- const fullstore = require('fullstore');
11
- const _cliStaged = require('@putout/cli-staged');
12
-
13
- const {
14
- runProcessors: _runProcessors,
15
- getFilePatterns: _getFilePatterns,
16
- getProcessorRunners: _getProcessorRunners,
1
+ import process from 'node:process';
2
+ import {createRequire} from 'node:module';
3
+ import tryToCatch from 'try-to-catch';
4
+ import {isCI as _isCI} from 'ci-info';
5
+ import tryCatch from 'try-catch';
6
+ import wraptile from 'wraptile';
7
+ import fullstore from 'fullstore';
8
+ import nano from 'nano-memoize';
9
+ import * as _cliStaged from '@putout/cli-staged';
10
+ import {initReport as _initReport} from '@putout/engine-reporter/report';
11
+ import {keypress as _keypress} from '@putout/cli-keypress';
12
+ import {getFormatter} from '@putout/engine-reporter/formatter';
13
+ import {
14
+ runProcessors as _runProcessors,
15
+ getFilePatterns as _getFilePatterns,
16
+ getProcessorRunners as _getProcessorRunners,
17
17
  defaultProcessors,
18
- } = require('@putout/engine-processor');
18
+ } from '@putout/engine-processor';
19
+ import * as supportedFiles from './supported-files.js';
20
+ import _getOptions from './get-options.js';
21
+ import {argvConfig, parseArgs} from './parse-args.js';
22
+ import {getFiles as _getFiles} from './get-files.js';
23
+ import {simpleImport as _simpleImport} from './simple-import.js';
24
+ import {run} from './runner/runner.js';
19
25
 
20
- const {initReport: _initReport} = require('@putout/engine-reporter/report');
21
- const {keypress: _keypress} = require('@putout/cli-keypress');
22
-
23
- const supportedFiles = require('./supported-files');
24
- const _getOptions = require('./get-options');
25
- const {argvConfig, parseArgs} = require('./parse-args');
26
-
27
- const {getFiles: _getFiles} = require('./get-files.mjs');
28
- const {version, dependencies} = require('../../package.json');
26
+ const require = createRequire(import.meta.url);
29
27
  const {formatter: defaultFormatter} = require('../../putout.json');
30
- const {simpleImport: _simpleImport} = require('./simple-import');
31
- const {run} = require('./runner/runner.js');
28
+ const {version, dependencies} = require('../../package.json');
32
29
 
33
30
  const {
34
31
  OK,
@@ -46,11 +43,10 @@ const {
46
43
  INTERACTIVE_CANCELED,
47
44
  } = require('./exit-codes');
48
45
 
49
- const noop = () => {};
50
- const {keys} = Object;
46
+ const _getFormatter = nano.nanomemoize(getFormatter);
51
47
  const {isSupported} = supportedFiles;
52
- const _getFormatter = nanomemoize(require('@putout/engine-reporter/formatter').getFormatter);
53
-
48
+ const {keys} = Object;
49
+ const noop = () => {};
54
50
  const cwd = process.cwd();
55
51
  const {env} = process;
56
52
 
@@ -69,7 +65,7 @@ const parseIsStop = (passedIsStop, {keypress}) => {
69
65
  return isStop;
70
66
  };
71
67
 
72
- module.exports = async (overrides = {}) => {
68
+ export default async (overrides = {}) => {
73
69
  const {
74
70
  argv,
75
71
  halt,
@@ -123,7 +119,7 @@ module.exports = async (overrides = {}) => {
123
119
  plugins,
124
120
  } = args;
125
121
 
126
- const {createExit} = await simpleImport('./exit.mjs');
122
+ const {createExit} = await simpleImport('./exit.js');
127
123
 
128
124
  const exit = createExit({
129
125
  raw,
@@ -162,7 +158,7 @@ module.exports = async (overrides = {}) => {
162
158
  }
163
159
 
164
160
  if (args.help) {
165
- const {help} = await import('./help.mjs');
161
+ const {help} = await import('./help.js');
166
162
  log(help());
167
163
 
168
164
  return exit();
@@ -358,7 +354,8 @@ module.exports = async (overrides = {}) => {
358
354
  exit(exitCode);
359
355
  };
360
356
 
361
- module.exports._addOnce = addOnce;
357
+ export const _addOnce = addOnce;
358
+
362
359
  function addOnce(emitter, name, fn) {
363
360
  if (!emitter.listenerCount(name))
364
361
  emitter.on(name, fn);
@@ -1,11 +1,10 @@
1
- 'use strict';
1
+ import yargsParser from 'yargs-parser';
2
2
 
3
- const yargsParser = require('yargs-parser');
4
3
  const {isArray} = Array;
5
4
  const maybeFirst = (a) => isArray(a) ? a.pop() : a;
6
5
  const maybeArray = (a) => isArray(a) ? a : a.split(',');
7
6
 
8
- const argvConfig = {
7
+ export const argvConfig = {
9
8
  configuration: {
10
9
  'strip-aliased': true,
11
10
  'strip-dashed': true,
@@ -64,5 +63,4 @@ const argvConfig = {
64
63
  },
65
64
  };
66
65
 
67
- module.exports.argvConfig = argvConfig;
68
- module.exports.parseArgs = (argv) => yargsParser(argv, argvConfig);
66
+ export const parseArgs = (argv) => yargsParser(argv, argvConfig);
@@ -1,13 +1,10 @@
1
- 'use strict';
1
+ import tryToCatch from 'try-to-catch';
2
+ import {runProcessors as _runProcessors} from '@putout/engine-processor';
3
+ import {parseError} from '../../parse-error.js';
4
+ import {simpleImport} from '../simple-import.js';
5
+ import {ignores} from '../../ignores.js';
2
6
 
3
- const tryToCatch = require('try-to-catch');
4
- const {runProcessors: _runProcessors} = require('@putout/engine-processor');
5
-
6
- const parseError = require('../../parse-error.js');
7
- const {simpleImport} = require('../simple-import');
8
- const ignores = require('../../ignores.js');
9
-
10
- module.exports.runReader = async (overrides) => {
7
+ export const runReader = async (overrides) => {
11
8
  const {
12
9
  raw,
13
10
  log,
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import _initProcessFile from '@putout/cli-process-file';
2
+ import {runWriter} from './writer.js';
2
3
 
3
- const _initProcessFile = require('@putout/cli-process-file');
4
- const {runWriter} = require('./writer.js');
5
-
6
- module.exports.run = async (overrides) => {
4
+ export const run = async (overrides) => {
7
5
  const {
8
6
  transform,
9
7
  plugins,
@@ -1,13 +1,10 @@
1
- 'use strict';
2
-
3
- const {resolve} = require('node:path');
4
- const {cwd, env} = require('node:process');
5
- const {readFileSync} = require('node:fs');
6
-
7
- const tryCatch = require('try-catch');
8
- const _getOptions = require('../get-options.js');
9
- const {INVALID_CONFIG, NO_PROCESSORS} = require('../exit-codes.js');
10
- const {runReader} = require('./reader.js');
1
+ import {resolve} from 'node:path';
2
+ import {cwd, env} from 'node:process';
3
+ import {readFileSync} from 'node:fs';
4
+ import tryCatch from 'try-catch';
5
+ import _getOptions from '../get-options.js';
6
+ import {INVALID_CONFIG, NO_PROCESSORS} from '../exit-codes.js';
7
+ import {runReader} from './reader.js';
11
8
 
12
9
  const isParser = (rule) => rule.startsWith('parser');
13
10
  const isParsingError = ({rule}) => isParser(rule);
@@ -33,7 +30,7 @@ const createFormatterProxy = (options) => {
33
30
  });
34
31
  };
35
32
 
36
- module.exports.runWriter = async (overrides = {}) => {
33
+ export const runWriter = async (overrides = {}) => {
37
34
  const {
38
35
  readFile,
39
36
  report,
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.simpleImport = async (url) => {
1
+ export const simpleImport = async (url) => {
4
2
  const result = await import(url);
5
3
  return result.default || result;
6
4
  };
@@ -1,8 +1,6 @@
1
- 'use strict';
2
-
3
- const {normalize} = require('node:path');
4
- const picomatch = require('picomatch');
5
- const fullstore = require('fullstore');
1
+ import {normalize} from 'node:path';
2
+ import picomatch from 'picomatch';
3
+ import fullstore from 'fullstore';
6
4
 
7
5
  const noop = () => {};
8
6
  const isMatchStore = fullstore();
@@ -11,7 +9,7 @@ let patterns = [];
11
9
 
12
10
  const rmDuplicates = (a) => Array.from(new Set(a));
13
11
 
14
- module.exports.add = (array) => {
12
+ export const add = (array) => {
15
13
  patterns = rmDuplicates(patterns.concat(array));
16
14
 
17
15
  const isMatch = picomatch(patterns, {
@@ -22,16 +20,16 @@ module.exports.add = (array) => {
22
20
  isMatchStore(isMatch);
23
21
  };
24
22
 
25
- module.exports.isSupported = (name) => {
23
+ export const isSupported = (name) => {
26
24
  const isMatch = isMatchStore();
27
25
  return isMatch(name);
28
26
  };
29
27
 
30
- module.exports.clear = () => {
28
+ export const clear = () => {
31
29
  isMatchStore(noop);
32
30
  patterns = [];
33
31
  };
34
32
 
35
- module.exports.getSupportedGlob = (file) => normalize(`${file}/**/{${patterns.join(',')}}`);
33
+ export const getSupportedGlob = (file) => normalize(`${file}/**/{${patterns.join(',')}}`);
36
34
 
37
- module.exports.getPatterns = () => patterns;
35
+ export const getPatterns = () => patterns;
package/lib/codeframe.js CHANGED
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {codeFrameColumns} from '@putout/babel';
2
2
 
3
- const {codeFrameColumns} = require('@putout/babel');
4
-
5
- module.exports = ({source, error, highlightCode = true}) => {
3
+ export const codeframe = ({source, error, highlightCode = true}) => {
6
4
  const {message, loc} = error;
7
5
 
8
6
  if (!loc)
@@ -1,10 +1,8 @@
1
- 'use strict';
1
+ import * as loader from '@putout/engine-loader';
2
+ import runner from '@putout/engine-runner';
3
+ import {createProgress} from '@putout/engine-runner/progress';
2
4
 
3
- const loader = require('@putout/engine-loader');
4
- const runner = require('@putout/engine-runner');
5
- const {createProgress} = require('@putout/engine-runner/progress');
6
-
7
- module.exports.defaultOptions = (opts = {}) => {
5
+ export const defaultOptions = (opts = {}) => {
8
6
  const {
9
7
  parser = 'babel',
10
8
  printer = opts.printer || 'putout',
@@ -1,15 +1,13 @@
1
- 'use strict';
1
+ import {transform, transformAsync} from './transform.js';
2
2
 
3
- const {transform, transformAsync} = require('./transform');
4
-
5
- module.exports.findPlaces = (ast, source, opts) => {
3
+ export const findPlaces = (ast, source, opts) => {
6
4
  return transform(ast, source, {
7
5
  ...opts,
8
6
  fix: false,
9
7
  });
10
8
  };
11
9
 
12
- module.exports.findPlacesAsync = async (ast, source, opts) => {
10
+ export const findPlacesAsync = async (ast, source, opts) => {
13
11
  return await transformAsync(ast, source, {
14
12
  ...opts,
15
13
  fix: false,
package/lib/ignores.js CHANGED
@@ -1,12 +1,10 @@
1
- 'use strict';
2
-
3
- const {relative} = require('node:path');
4
- const ignore = require('ignore');
1
+ import {relative} from 'node:path';
2
+ import ignore from 'ignore';
5
3
 
6
4
  const isNegative = (a) => !a.indexOf('!');
7
5
  const positive = (a) => a.replace(/^!/, '');
8
6
 
9
- module.exports = (dirOpt, resolvedName, options = {}) => {
7
+ export const ignores = (dirOpt, resolvedName, options = {}) => {
10
8
  const relativeName = relative(dirOpt, resolvedName);
11
9
  const ignorer = ignore();
12
10
  const ignoreList = mergeIgnores(options.ignore || []);
@@ -1,8 +1,8 @@
1
1
  import process from 'node:process';
2
2
  import {Buffer} from 'node:buffer';
3
3
  import {putoutAsync} from '../putout.js';
4
- import ignores from '../ignores.js';
5
- import parseOptions from '../parse-options/index.js';
4
+ import {ignores} from '../ignores.js';
5
+ import {parseOptions} from '../parse-options/index.js';
6
6
 
7
7
  const cwd = process.cwd();
8
8
 
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports = (e, type = 'parser') => {
1
+ export const parseError = (e, type = 'parser') => {
4
2
  const {line, column} = e.loc || {
5
3
  line: 1,
6
4
  column: 1,
@@ -1,9 +1,8 @@
1
- 'use strict';
1
+ import {mergeOptions} from './merge-options.js';
2
2
 
3
- const {mergeOptions} = require('./merge-options');
4
3
  const {assign} = Object;
5
4
 
6
- module.exports = ({type}, options) => {
5
+ export default ({type}, options) => {
7
6
  const config = type === 'module' ? esm() : commonjs();
8
7
  assign(options, mergeOptions(options, config));
9
8
  };
@@ -1,26 +1,24 @@
1
- 'use strict';
2
-
3
- const process = require('node:process');
4
- const {homedir} = require('node:os');
5
- const {readdirSync: _readdirSync} = require('node:fs');
6
-
7
- const {dirname, join} = require('node:path');
8
-
9
- const once = require('once');
10
- const tryCatch = require('try-catch');
11
- const escalade = require('escalade/sync');
12
-
13
- const {parseMatch} = require('./parse-match');
14
- const defaultOptions = require('../../putout.json');
15
- const {mergeOptions} = require('./merge-options');
16
- const recursiveRead = require('./recursive-read');
17
- const applyModuleTypeRules = require('./apply-module-type-rules');
18
- const {validateOptions} = require('./validate-options');
19
- const {readRules} = require('./read-rules');
1
+ import process from 'node:process';
2
+ import {homedir as _homedir} from 'node:os';
3
+ import {readdirSync as _readdirSync} from 'node:fs';
4
+ import {dirname, join} from 'node:path';
5
+ import {createRequire} from 'node:module';
6
+ import once from 'once';
7
+ import tryCatch from 'try-catch';
8
+ import _escalade from 'escalade/sync';
9
+ import {parseMatch} from './parse-match.js';
10
+ import _defaultOptions from '../../putout.json' with {
11
+ type: 'json',
12
+ };
13
+ import {mergeOptions} from './merge-options.js';
14
+ import _recursiveRead from './recursive-read.js';
15
+ import applyModuleTypeRules from './apply-module-type-rules.js';
16
+ import {validateOptions} from './validate-options/index.js';
17
+ import {readRules} from './read-rules.js';
20
18
 
21
- const home = homedir();
19
+ const require = createRequire(import.meta.url);
22
20
 
23
- module.exports = (info = {}, overrides = {}) => {
21
+ export const parseOptions = (info = {}, overrides = {}) => {
24
22
  const {
25
23
  rulesdir,
26
24
  name = '',
@@ -33,10 +31,23 @@ module.exports = (info = {}, overrides = {}) => {
33
31
  const {
34
32
  cwd = process.cwd(),
35
33
  readdirSync = _readdirSync,
34
+ defaultOptions = _defaultOptions,
35
+ recursiveRead = _recursiveRead,
36
+ homedir = _homedir,
37
+ escalade = _escalade,
38
+ readPackageJson,
36
39
  } = overrides;
37
40
 
38
- const [dir, customOptions] = readOptions(name);
39
- const homeOptions = readHomeOptions();
41
+ const [dir, customOptions] = readOptions(name, {
42
+ recursiveRead,
43
+ escalade,
44
+ readPackageJson,
45
+ });
46
+
47
+ const homeOptions = readHomeOptions({
48
+ homedir,
49
+ });
50
+
40
51
  const defaultMatch = parseMatch(name, defaultOptions.match);
41
52
 
42
53
  const optionsList = [
@@ -64,6 +75,7 @@ module.exports = (info = {}, overrides = {}) => {
64
75
  readCodeMods({
65
76
  cwd,
66
77
  readdirSync,
78
+ homedir,
67
79
  }),
68
80
  readRules('./', rulesdir, {
69
81
  cwd,
@@ -86,12 +98,33 @@ module.exports = (info = {}, overrides = {}) => {
86
98
 
87
99
  const includes = (name) => (dir, names) => names.includes(name) && name;
88
100
 
89
- function _readOptions(name) {
90
- const [dir, options] = recursiveRead(name, '.putout.json');
101
+ function _readPackageJson(name, overrides) {
102
+ const {escalade} = overrides;
91
103
  const [, packagePath] = tryCatch(escalade, name, includes('package.json'));
92
104
 
93
105
  if (packagePath)
94
- applyModuleTypeRules(require(packagePath), options);
106
+ return [packagePath, require(packagePath)];
107
+
108
+ return [
109
+ '',
110
+ null,
111
+ ];
112
+ }
113
+
114
+ function _readOptions(name, overrides = {}) {
115
+ const {
116
+ recursiveRead,
117
+ escalade,
118
+ readPackageJson = _readPackageJson,
119
+ } = overrides;
120
+
121
+ const [dir, options] = recursiveRead(name, '.putout.json');
122
+ const [packagePath, packageJson] = readPackageJson(name, {
123
+ escalade,
124
+ });
125
+
126
+ if (packagePath)
127
+ applyModuleTypeRules(packageJson, options);
95
128
 
96
129
  if (dir)
97
130
  return [dir, options];
@@ -107,14 +140,19 @@ function _readOptions(name) {
107
140
  return ['', {}];
108
141
  }
109
142
 
110
- const _readHomeOptions = once(() => {
143
+ const _readHomeOptions = once(({homedir}) => {
144
+ const home = homedir();
111
145
  const name = join(home, '.putout.json');
112
146
  const [, data = {}] = tryCatch(require, name);
113
147
 
114
148
  return data;
115
149
  });
116
150
 
117
- const _readCodeMods = once(({cwd, readdirSync}) => readRules(home, '.putout', {
118
- cwd,
119
- readdirSync,
120
- }));
151
+ const _readCodeMods = ({cwd, readdirSync, homedir}) => {
152
+ const home = homedir();
153
+
154
+ return readRules(home, '.putout', {
155
+ cwd,
156
+ readdirSync,
157
+ });
158
+ };
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- const deepmerge = require('deepmerge');
1
+ import deepmerge from 'deepmerge';
4
2
 
5
3
  const {isArray} = Array;
6
4
  const isObject = (a) => typeof a === 'object';
@@ -34,7 +32,7 @@ const arrayUnion = (a, b) => {
34
32
 
35
33
  const arrayMerge = (a, b) => arrayUnion(b, a);
36
34
 
37
- module.exports.mergeOptions = (...args) => {
35
+ export const mergeOptions = (...args) => {
38
36
  return deepmerge.all(args, {
39
37
  arrayMerge,
40
38
  });
@@ -1,10 +1,8 @@
1
- 'use strict';
2
-
3
- const picomatch = require('picomatch');
1
+ import picomatch from 'picomatch';
4
2
 
5
3
  const {keys, assign} = Object;
6
4
 
7
- module.exports.parseMatch = (name, match) => {
5
+ export const parseMatch = (name, match) => {
8
6
  if (!match || !name)
9
7
  return {};
10
8
 
@@ -1,11 +1,9 @@
1
- 'use strict';
1
+ import process from 'node:process';
2
2
 
3
- const {platform} = require('node:process');
4
-
5
- module.exports = (a) => {
3
+ export default (a) => {
6
4
  a = wild(a);
7
5
 
8
- if (platform !== 'win32')
6
+ if (process.platform !== 'win32')
9
7
  return a;
10
8
 
11
9
  return a.replace(/\//g, `\\\\`);
@@ -1,8 +1,5 @@
1
- 'use strict';
2
-
3
- const {join} = require('node:path');
4
-
5
- const tryCatch = require('try-catch');
1
+ import {join} from 'node:path';
2
+ import tryCatch from 'try-catch';
6
3
 
7
4
  const isInclude = (a) => {
8
5
  if (a[0] === '.')
@@ -14,7 +11,7 @@ const isInclude = (a) => {
14
11
  return !a.endsWith('.md');
15
12
  };
16
13
 
17
- module.exports.readRules = (dirOpt, rulesDir, overrides) => {
14
+ export const readRules = (dirOpt, rulesDir, overrides) => {
18
15
  if (!rulesDir)
19
16
  return {};
20
17
 
@@ -1,16 +1,16 @@
1
- 'use strict';
1
+ import {dirname} from 'node:path';
2
+ import {createRequire} from 'node:module';
3
+ import escalade from 'escalade/sync';
4
+ import {mergeOptions} from './merge-options.js';
5
+ import {parseMatch} from './parse-match.js';
2
6
 
3
- const {dirname} = require('node:path');
4
- const escalade = require('escalade/sync');
7
+ const require = createRequire(import.meta.url);
5
8
 
6
- const {mergeOptions} = require('./merge-options');
7
- const {parseMatch} = require('./parse-match');
8
-
9
- module.exports = (name, configName, overrides) => {
9
+ export default (name, configName, overrides = {}) => {
10
10
  if (name === '<input>')
11
11
  return ['', {}];
12
12
 
13
- const customRequire = overrides?.require || require;
13
+ const customRequire = overrides.require || require;
14
14
  const dir = dirname(name);
15
15
 
16
16
  const [mainDir, optionsList] = getOptionsList({
@@ -1,7 +1,7 @@
1
- 'use strict';
2
-
3
- const Ajv = require('ajv');
4
- const schema = require('./schema.json');
1
+ import Ajv from 'ajv';
2
+ import schema from './schema.json' with {
3
+ type: 'json',
4
+ };
5
5
 
6
6
  const ajv = new Ajv({
7
7
  strict: true,
@@ -10,7 +10,7 @@ const ajv = new Ajv({
10
10
 
11
11
  const validate = ajv.compile(schema);
12
12
 
13
- module.exports.validateOptions = (options) => {
13
+ export const validateOptions = (options) => {
14
14
  validate(options);
15
15
 
16
16
  const [error] = validate.errors || [];
package/lib/putout.cjs ADDED
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ const {traverse, types} = require('@putout/babel');
4
+ const {
5
+ parse,
6
+ print,
7
+ generate,
8
+ template,
9
+ } = require('@putout/engine-parser');
10
+
11
+ const {cutShebang, mergeShebang} = require('./shebang');
12
+ const {defaultOptions} = require('./default-options');
13
+ const {transform, transformAsync} = require('./transform');
14
+
15
+ const {
16
+ findPlaces,
17
+ findPlacesAsync,
18
+ } = require('./find-places');
19
+
20
+ module.exports = putout;
21
+ module.exports.putout = putout;
22
+
23
+ function putout(source, opts) {
24
+ check(source);
25
+ opts = defaultOptions(opts);
26
+
27
+ const {
28
+ parser,
29
+ isTS,
30
+ isJSX,
31
+ printer,
32
+ } = opts;
33
+
34
+ const [clearSource, shebang] = cutShebang(source);
35
+
36
+ const ast = parse(clearSource, {
37
+ parser,
38
+ isTS,
39
+ isJSX,
40
+ printer,
41
+ });
42
+
43
+ const places = transform(ast, source, opts);
44
+
45
+ if (!opts.fix)
46
+ return {
47
+ code: source,
48
+ places,
49
+ };
50
+
51
+ const printed = print(ast, {
52
+ printer,
53
+ source,
54
+ });
55
+
56
+ const code = mergeShebang(shebang, printed);
57
+
58
+ return {
59
+ code,
60
+ places,
61
+ };
62
+ }
63
+
64
+ module.exports.putoutAsync = async (source, opts) => {
65
+ check(source);
66
+ opts = defaultOptions(opts);
67
+
68
+ const {
69
+ parser,
70
+ isTS,
71
+ isJSX,
72
+ printer,
73
+ } = opts;
74
+
75
+ const [clearSource, shebang] = cutShebang(source);
76
+
77
+ const ast = parse(clearSource, {
78
+ parser,
79
+ isTS,
80
+ isJSX,
81
+ printer,
82
+ });
83
+
84
+ const places = await transformAsync(ast, source, opts);
85
+
86
+ if (!opts.fix)
87
+ return {
88
+ code: source,
89
+ places,
90
+ };
91
+
92
+ const printed = print(ast, {
93
+ printer,
94
+ });
95
+
96
+ const code = mergeShebang(shebang, printed);
97
+
98
+ return {
99
+ code,
100
+ places,
101
+ };
102
+ };
103
+
104
+ module.exports.transform = transform;
105
+ module.exports.transformAsync = transformAsync;
106
+
107
+ module.exports.findPlaces = findPlaces;
108
+ module.exports.findPlacesAsync = findPlacesAsync;
109
+
110
+ module.exports.parse = parse;
111
+ module.exports.print = print;
112
+ module.exports.traverse = traverse;
113
+ module.exports.types = types;
114
+ module.exports.template = template;
115
+ module.exports.generate = generate;
116
+
117
+ module.exports.operator = {
118
+ ...require('@putout/operate'),
119
+ ...require('@putout/compare'),
120
+ ...require('@putout/traverse'),
121
+ ...require('@putout/operator-json'),
122
+ ...require('@putout/operator-jsx'),
123
+ ...require('@putout/operator-declare'),
124
+ ...require('@putout/operator-regexp'),
125
+ ...require('@putout/operator-add-args'),
126
+ ...require('@putout/operator-filesystem'),
127
+ ...require('@putout/operator-keyword'),
128
+ ...require('@putout/operator-match-files'),
129
+ ...require('@putout/operator-rename-files'),
130
+ ...require('@putout/operator-ignore'),
131
+ ...require('@putout/operator-parens'),
132
+ };
133
+
134
+ const {codeframe} = require('./codeframe');
135
+ const isString = (a) => typeof a === 'string';
136
+
137
+ module.exports.codeframe = codeframe;
138
+
139
+ function check(source) {
140
+ if (!isString(source))
141
+ throw Error(`☝️ Looks like 'source' has type '${typeof source}', expected: 'string'`);
142
+ }
package/lib/putout.js CHANGED
@@ -1,142 +1,4 @@
1
- 'use strict';
1
+ import {putout} from './putout.cjs';
2
2
 
3
- const {traverse, types} = require('@putout/babel');
4
- const {
5
- parse,
6
- print,
7
- generate,
8
- template,
9
- } = require('@putout/engine-parser');
10
-
11
- const {cutShebang, mergeShebang} = require('./shebang');
12
- const {defaultOptions} = require('./default-options');
13
- const {transform, transformAsync} = require('./transform');
14
-
15
- const {
16
- findPlaces,
17
- findPlacesAsync,
18
- } = require('./find-places');
19
-
20
- const isString = (a) => typeof a === 'string';
21
-
22
- module.exports = putout;
23
- module.exports.putout = putout;
24
-
25
- function putout(source, opts) {
26
- check(source);
27
- opts = defaultOptions(opts);
28
-
29
- const {
30
- parser,
31
- isTS,
32
- isJSX,
33
- printer,
34
- } = opts;
35
-
36
- const [clearSource, shebang] = cutShebang(source);
37
-
38
- const ast = parse(clearSource, {
39
- parser,
40
- isTS,
41
- isJSX,
42
- printer,
43
- });
44
-
45
- const places = transform(ast, source, opts);
46
-
47
- if (!opts.fix)
48
- return {
49
- code: source,
50
- places,
51
- };
52
-
53
- const printed = print(ast, {
54
- printer,
55
- source,
56
- });
57
-
58
- const code = mergeShebang(shebang, printed);
59
-
60
- return {
61
- code,
62
- places,
63
- };
64
- }
65
-
66
- module.exports.putoutAsync = async (source, opts) => {
67
- check(source);
68
- opts = defaultOptions(opts);
69
-
70
- const {
71
- parser,
72
- isTS,
73
- isJSX,
74
- printer,
75
- } = opts;
76
-
77
- const [clearSource, shebang] = cutShebang(source);
78
-
79
- const ast = parse(clearSource, {
80
- parser,
81
- isTS,
82
- isJSX,
83
- printer,
84
- });
85
-
86
- const places = await transformAsync(ast, source, opts);
87
-
88
- if (!opts.fix)
89
- return {
90
- code: source,
91
- places,
92
- };
93
-
94
- const printed = print(ast, {
95
- printer,
96
- });
97
-
98
- const code = mergeShebang(shebang, printed);
99
-
100
- return {
101
- code,
102
- places,
103
- };
104
- };
105
-
106
- module.exports.transform = transform;
107
- module.exports.transformAsync = transformAsync;
108
-
109
- module.exports.findPlaces = findPlaces;
110
- module.exports.findPlacesAsync = findPlacesAsync;
111
-
112
- module.exports.parse = parse;
113
- module.exports.print = print;
114
- module.exports.traverse = traverse;
115
- module.exports.types = types;
116
- module.exports.template = template;
117
- module.exports.generate = generate;
118
-
119
- module.exports.operator = {
120
- ...require('@putout/operate'),
121
- ...require('@putout/compare'),
122
- ...require('@putout/traverse'),
123
- ...require('@putout/operator-json'),
124
- ...require('@putout/operator-jsx'),
125
- ...require('@putout/operator-declare'),
126
- ...require('@putout/operator-regexp'),
127
- ...require('@putout/operator-add-args'),
128
- ...require('@putout/operator-filesystem'),
129
- ...require('@putout/operator-keyword'),
130
- ...require('@putout/operator-match-files'),
131
- ...require('@putout/operator-rename-files'),
132
- ...require('@putout/operator-ignore'),
133
- ...require('@putout/operator-parens'),
134
- };
135
-
136
- module.exports.ignores = require('./ignores');
137
- module.exports.codeframe = require('./codeframe');
138
-
139
- function check(source) {
140
- if (!isString(source))
141
- throw Error(`☝️ Looks like 'source' has type '${typeof source}', expected: 'string'`);
142
- }
3
+ export * from './putout.cjs';
4
+ export default putout;
package/lib/shebang.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict';
2
-
3
- module.exports.mergeShebang = (shebang, source) => {
1
+ export const mergeShebang = (shebang, source) => {
4
2
  if (!shebang)
5
3
  return source;
6
4
 
7
5
  return `${shebang}\n${source}`;
8
6
  };
9
7
 
10
- module.exports.cutShebang = (source) => {
8
+ export const cutShebang = (source) => {
11
9
  if (source.indexOf('#'))
12
10
  return [source, ''];
13
11
 
package/lib/transform.js CHANGED
@@ -1,11 +1,8 @@
1
- 'use strict';
2
-
3
- const tryCatch = require('try-catch');
4
-
5
- const {validateRulesRelations} = require('@putout/engine-loader');
6
- const {defaultOptions} = require('./default-options');
7
- const {cutShebang} = require('./shebang');
8
- const parseError = require('./parse-error');
1
+ import tryCatch from 'try-catch';
2
+ import {validateRulesRelations} from '@putout/engine-loader';
3
+ import {defaultOptions} from './default-options.js';
4
+ import {cutShebang} from './shebang.js';
5
+ import {parseError} from './parse-error.js';
9
6
 
10
7
  const maybeParseError = (a) => !a ? [] : parseError(a, 'loader');
11
8
 
@@ -18,7 +15,7 @@ const maybeParseError = (a) => !a ? [] : parseError(a, 'loader');
18
15
  // 27 column,¬
19
16
  // 28 };¬
20
17
  //
21
- module.exports.transform = (ast, source, opts) => {
18
+ export const transform = (ast, source, opts) => {
22
19
  opts = defaultOptions(opts);
23
20
 
24
21
  const {
@@ -60,7 +57,7 @@ module.exports.transform = (ast, source, opts) => {
60
57
  ];
61
58
  };
62
59
 
63
- module.exports.transformAsync = async (ast, source, opts) => {
60
+ export const transformAsync = async (ast, source, opts) => {
64
61
  opts = defaultOptions(opts);
65
62
 
66
63
  const {
package/package.json CHANGED
@@ -1,37 +1,36 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "41.1.3",
4
- "type": "commonjs",
3
+ "version": "41.2.0",
4
+ "type": "module",
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",
7
7
  "homepage": "http://github.com/coderaiser/putout#readme",
8
8
  "main": "./lib/putout.js",
9
9
  "exports": {
10
10
  ".": {
11
- "require": "./lib/putout.js",
12
- "import": "./lib/putout.mjs"
11
+ "require": "./lib/putout.cjs",
12
+ "import": "./lib/putout.js"
13
13
  },
14
14
  "./parse-error": "./lib/parse-error.js",
15
15
  "./parse-options": "./lib/parse-options/index.js",
16
16
  "./parse-match": "./lib/parse-options/parse-match.js",
17
17
  "./merge-options": "./lib/parse-options/merge-options.js",
18
18
  "./exit-codes": {
19
- "import": "./lib/cli/exit-codes.mjs",
20
- "require": "./lib/cli/exit-codes.js"
19
+ "import": "./lib/cli/exit-codes.js",
20
+ "require": "./lib/cli/exit-codes.cjs"
21
21
  },
22
- "./cli": "./lib/cli/index.js",
23
22
  "./cli/get-options": "./lib/cli/get-options.js",
24
23
  "./package.json": "./package.json",
25
24
  "./putout.json": "./putout.json",
26
- "./lint/json": "./lib/lint/json.mjs",
25
+ "./lint/json": "./lib/lint/json.js",
27
26
  "./transform": "./lib/transform.js",
28
27
  "./find-places": "./lib/find-places.js",
29
- "./register": "./lib/loader/register.mjs",
28
+ "./register": "./lib/loader/register.js",
30
29
  "./ignores": "./lib/ignores.js",
31
30
  "./simple-import": "./lib/cli/simple-import.js"
32
31
  },
33
32
  "bin": {
34
- "putout": "bin/tracer.mjs"
33
+ "putout": "bin/tracer.js"
35
34
  },
36
35
  "repository": {
37
36
  "type": "git",
@@ -220,7 +219,6 @@
220
219
  "eslint-plugin-putout": "^29.0.0",
221
220
  "just-camel-case": "^6.2.0",
222
221
  "madrun": "^11.0.0",
223
- "mock-require": "^3.0.2",
224
222
  "montag": "^1.2.1",
225
223
  "nodemon": "^3.0.1",
226
224
  "supertape": "^11.0.3"
@@ -1,16 +0,0 @@
1
- export const OK = 0;
2
- export const PLACE = 1;
3
- export const STAGE = 2;
4
- export const NO_FILES = 3;
5
- export const NO_PROCESSORS = 4;
6
- export const NO_FORMATTER = 5;
7
- export const WAS_STOP = 6;
8
- export const INVALID_OPTION = 7;
9
- export const CANNOT_LOAD_PROCESSOR = 8;
10
- export const CANNOT_LOAD_FORMATTER = 9;
11
- export const RULER_WITH_FIX = 10;
12
- export const RULER_NO_FILES = 11;
13
- export const INVALID_CONFIG = 12;
14
- export const UNHANDLED = 13;
15
- export const CANNOT_LINT_STAGED = 14;
16
- export const INTERACTIVE_CANCELED = 15;
package/lib/putout.mjs DELETED
@@ -1,4 +0,0 @@
1
- import putout from './putout.js';
2
-
3
- export * from './putout.js';
4
- export default putout;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes