putout 38.0.5 → 38.0.6

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
+ 2025.02.04, v38.0.6
2
+
3
+ feature:
4
+ - 487a24e4e @putout/cli-process-file: add
5
+ - 34c38b881 @putout/plugin-extract-keywords-from-variables: MemberExpression
6
+
1
7
  2025.02.03, v38.0.5
2
8
 
3
9
  feature:
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  const Report = require('@putout/engine-reporter/report');
4
+
5
+ const initProcessFile = require('@putout/cli-process-file');
4
6
  const {runWriter} = require('./writer.js');
5
- const initProcessFile = require('../process-file.js');
6
7
 
7
8
  const report = Report();
8
9
 
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const merge = require('../merge');
3
+ const {mergeOptions} = require('./merge-options');
4
4
  const {assign} = Object;
5
5
 
6
6
  module.exports = ({type}, options) => {
7
- const rules = type === 'module' ? esm() : commonjs();
8
- assign(options, merge(options, rules));
7
+ const config = type === 'module' ? esm() : commonjs();
8
+ assign(options, mergeOptions(options, config));
9
9
  };
10
10
 
11
11
  const commonjs = () => ({
@@ -10,9 +10,9 @@ const once = require('once');
10
10
  const tryCatch = require('try-catch');
11
11
  const escalade = require('escalade/sync');
12
12
 
13
- const parseMatch = require('./parse-match');
13
+ const {parseMatch} = require('./parse-match');
14
14
  const defaultOptions = require('../../putout.json');
15
- const merge = require('../merge');
15
+ const {mergeOptions} = require('./merge-options');
16
16
  const recursiveRead = require('./recursive-read');
17
17
  const applyModuleTypeRules = require('./apply-module-type-rules');
18
18
  const {validateOptions} = require('./validate-options');
@@ -47,9 +47,9 @@ module.exports = (info = {}, overrides = {}) => {
47
47
  options,
48
48
  ];
49
49
 
50
- const mergedOptions = merge(...optionsList);
50
+ const mergedOptions = mergeOptions(...optionsList);
51
51
 
52
- const mergedDefaultsMatch = merge(
52
+ const mergedDefaultsMatch = mergeOptions(
53
53
  mergedOptions,
54
54
  parseMatch(
55
55
  name,
@@ -58,7 +58,7 @@ module.exports = (info = {}, overrides = {}) => {
58
58
  options,
59
59
  );
60
60
 
61
- const mergedMatch = merge(customOptions, options, parseMatch(name, options.match));
61
+ const mergedMatch = mergeOptions(customOptions, options, parseMatch(name, options.match));
62
62
 
63
63
  const resultOptionsList = [
64
64
  readCodeMods({
@@ -74,7 +74,7 @@ module.exports = (info = {}, overrides = {}) => {
74
74
  mergedMatch,
75
75
  ];
76
76
 
77
- const finalMergedOptions = merge(...resultOptionsList);
77
+ const finalMergedOptions = mergeOptions(...resultOptionsList);
78
78
 
79
79
  validateOptions(finalMergedOptions);
80
80
 
@@ -34,7 +34,7 @@ const arrayUnion = (a, b) => {
34
34
 
35
35
  const arrayMerge = (a, b) => arrayUnion(b, a);
36
36
 
37
- module.exports = (...args) => {
37
+ module.exports.mergeOptions = (...args) => {
38
38
  return deepmerge.all(args, {
39
39
  arrayMerge,
40
40
  });
@@ -4,7 +4,7 @@ const picomatch = require('picomatch');
4
4
 
5
5
  const {keys, assign} = Object;
6
6
 
7
- module.exports = (name, match) => {
7
+ module.exports.parseMatch = (name, match) => {
8
8
  if (!match || !name)
9
9
  return {};
10
10
 
@@ -3,8 +3,8 @@
3
3
  const {dirname} = require('node:path');
4
4
  const escalade = require('escalade/sync');
5
5
 
6
- const merge = require('../merge');
7
- const parseMatch = require('./parse-match');
6
+ const {mergeOptions} = require('./merge-options');
7
+ const {parseMatch} = require('./parse-match');
8
8
 
9
9
  module.exports = (name, configName, overrides) => {
10
10
  if (name === '<input>')
@@ -19,10 +19,10 @@ module.exports = (name, configName, overrides) => {
19
19
  customRequire,
20
20
  });
21
21
 
22
- let mergedOptions = merge(...optionsList);
22
+ let mergedOptions = mergeOptions(...optionsList);
23
23
 
24
24
  for (const currentOptions of optionsList)
25
- mergedOptions = merge(
25
+ mergedOptions = mergeOptions(
26
26
  mergedOptions,
27
27
  currentOptions,
28
28
  parseMatch(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "38.0.5",
3
+ "version": "38.0.6",
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",
@@ -11,8 +11,10 @@
11
11
  "require": "./lib/putout.js",
12
12
  "import": "./lib/putout.mjs"
13
13
  },
14
+ "./parse-error": "./lib/parse-error.js",
14
15
  "./parse-options": "./lib/parse-options/index.js",
15
- "./process-file": "./lib/cli/process-file.js",
16
+ "./parse-match": "./lib/parse-options/parse-match.js",
17
+ "./merge-options": "./lib/parse-options/merge-options.js",
16
18
  "./exit-codes": "./lib/cli/exit-codes.mjs",
17
19
  "./exit-codes/cjs": "./lib/cli/exit-codes.js",
18
20
  "./cli": "./lib/cli/index.js",
@@ -54,6 +56,7 @@
54
56
  "@putout/cli-choose-formatter": "^4.0.0",
55
57
  "@putout/cli-keypress": "^2.0.0",
56
58
  "@putout/cli-match": "^2.0.0",
59
+ "@putout/cli-process-file": "^1.0.0",
57
60
  "@putout/cli-ruler": "^3.0.0",
58
61
  "@putout/cli-staged": "^1.0.0",
59
62
  "@putout/cli-validate-args": "^2.0.0",
@@ -207,7 +210,6 @@
207
210
  "nano-memoize": "^3.0.11",
208
211
  "once": "^1.4.0",
209
212
  "picomatch": "^4.0.2",
210
- "samadhi": "^2.10.0",
211
213
  "try-catch": "^3.0.0",
212
214
  "try-to-catch": "^3.0.0",
213
215
  "wraptile": "^3.0.0",
@@ -1,61 +0,0 @@
1
- import deepMerge from 'deepmerge';
2
-
3
- const {isArray} = Array;
4
- const maybeArray = (a) => isArray(a) ? a : [a];
5
-
6
- const DefaultMarkdown = {
7
- format: {
8
- endOfFile: '',
9
- },
10
- };
11
-
12
- const JSON = {
13
- format: {
14
- quote: '"',
15
- },
16
- semantics: {
17
- trailingComma: false,
18
- },
19
- };
20
-
21
- export const configurePrinter = (name, printerOptions) => {
22
- const [printer = 'putout', options = {}] = maybeArray(printerOptions);
23
- const ext = name
24
- .split('.')
25
- .pop();
26
-
27
- if (printer !== 'putout')
28
- return printerOptions;
29
-
30
- const mergedOptions = deepMerge(parseOptions(ext), options);
31
-
32
- return [printer, mergedOptions];
33
- };
34
-
35
- function parseOptions(ext) {
36
- if (ext === 'json')
37
- return JSON;
38
-
39
- if (ext === 'yml{json}')
40
- return JSON;
41
-
42
- if (ext === 'md{json}')
43
- return {
44
- format: {
45
- ...DefaultMarkdown.format,
46
- ...JSON.format,
47
- },
48
- semantics: {
49
- ...DefaultMarkdown.semantics,
50
- ...JSON.semantics,
51
- },
52
- };
53
-
54
- if (ext === 'md{js}')
55
- return DefaultMarkdown;
56
-
57
- if (ext === 'md{ts}')
58
- return DefaultMarkdown;
59
-
60
- return {};
61
- }
@@ -1,95 +0,0 @@
1
- 'use strict';
2
-
3
- const tryToCatch = require('try-to-catch');
4
- const eslint = require('@putout/eslint');
5
-
6
- const {putoutAsync} = require('../..');
7
- const merge = require('../merge');
8
- const parseMatch = require('../parse-options/parse-match');
9
-
10
- const {simpleImport} = require('./simple-import');
11
- const parseError = require('../parse-error');
12
-
13
- const getMatchedOptions = (name, options) => {
14
- if (!name.includes('{'))
15
- return options;
16
-
17
- return merge(options, parseMatch(name, options.match));
18
- };
19
-
20
- module.exports = ({fix, fixCount, isFlow, logError, raw}) => async function processFile({name, source, startLine, options, again}) {
21
- const {configurePrinter} = await import('./printer/printer.mjs');
22
- const isTS = /\.tsx?$/.test(name) || /{tsx?}$/.test(name);
23
- const {printer, ...matchedOptions} = getMatchedOptions(name, options);
24
-
25
- const [e, result] = await tryToCatch(putoutAsync, source, {
26
- fix,
27
- fixCount,
28
- isTS,
29
- isFlow,
30
- ...matchedOptions,
31
- printer: configurePrinter(name, printer),
32
- });
33
-
34
- if (!again && e) {
35
- raw && logError(e);
36
-
37
- const {lint} = await simpleImport('samadhi');
38
- const [code, places] = await lint(source, {
39
- startLine,
40
- fix,
41
- isTS,
42
- });
43
-
44
- if (!fix && places.length)
45
- return {
46
- code,
47
- places,
48
- };
49
-
50
- if (fix && !places.length)
51
- return await processFile({
52
- again: true,
53
- name,
54
- source: code,
55
- startLine,
56
- options,
57
- });
58
- }
59
-
60
- const {code = source} = result || {};
61
- const allPlaces = result ? result.places : parseError(e);
62
-
63
- const [newCode, newPlaces] = await eslint({
64
- name,
65
- code,
66
- fix,
67
- });
68
-
69
- allPlaces.push(...newPlaces);
70
-
71
- const places = formatPlaces(startLine, allPlaces);
72
-
73
- return {
74
- places,
75
- code: newCode,
76
- };
77
- };
78
-
79
- function formatPlaces(line = 1, places) {
80
- const newPlaces = [];
81
-
82
- for (const place of places) {
83
- const {position} = place;
84
-
85
- newPlaces.push({
86
- ...place,
87
- position: {
88
- ...position,
89
- line: line + position.line,
90
- },
91
- });
92
- }
93
-
94
- return newPlaces;
95
- }