@putout/operator-match-files 3.3.0 → 3.4.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/README.md CHANGED
@@ -96,15 +96,31 @@ You can even use file matchers:
96
96
  Matchers: `__filename = __name.__ext`
97
97
 
98
98
  ```js
99
- const {operator} = require('putout');
100
- const {matchFiles} = operator;
101
- const updateTSConfig = require('../update-tsconfig');
102
-
103
99
  module.exports = matchFiles({
104
100
  '__name.json -> __name.js': updateTSConfig,
105
101
  });
106
102
  ```
107
103
 
104
+ ### Options
105
+
106
+ You can also pass `options`:
107
+
108
+ ```js
109
+ module.exports = matchFiles({
110
+ '.eslintrc.json -> eslint.config.js': {
111
+ rules: {
112
+ 'eslint/declare': {
113
+ type: 'esm',
114
+ },
115
+ },
116
+ plugins: [
117
+ ['eslint/convert-rc-to-flat', rcToFlat],
118
+ ['eslint/declare', declare],
119
+ ],
120
+ },
121
+ });
122
+ ```
123
+
108
124
  ## License
109
125
 
110
126
  MIT
@@ -34,10 +34,8 @@ module.exports.matchFiles = (files) => {
34
34
  };
35
35
  };
36
36
 
37
- function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename, matchedJS, matchedAST, plugins}) {
38
- transform(matchedAST, matchedJS, {
39
- plugins,
40
- });
37
+ function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename, matchedJS, matchedAST, options}) {
38
+ transform(matchedAST, matchedJS, options);
41
39
 
42
40
  const matchedJSON = magicPrint(outputFilename, matchedAST);
43
41
  const outputFile = getOutputFile(mainPath, {
@@ -57,7 +55,7 @@ const createScan = (files) => (mainPath, {push, progress, options}) => {
57
55
  const allFiles = [];
58
56
  const cwd = getFilename(mainPath);
59
57
 
60
- for (const [filename, plugin] of entries(files)) {
58
+ for (const [filename, rawOptions] of entries(files)) {
61
59
  const [matchInputFilename, outputFilename = matchInputFilename] = parseMatcher(filename, options);
62
60
  const inputFiles = findFile(mainPath, matchInputFilename);
63
61
 
@@ -72,7 +70,7 @@ const createScan = (files) => (mainPath, {push, progress, options}) => {
72
70
  mainPath,
73
71
  dirPath,
74
72
  matchInputFilename,
75
- plugin,
73
+ rawOptions,
76
74
  inputFile,
77
75
  inputFilename,
78
76
  outputFilename,
@@ -89,7 +87,7 @@ const createScan = (files) => (mainPath, {push, progress, options}) => {
89
87
  inputFile,
90
88
  inputFilename,
91
89
  outputFilename,
92
- plugin,
90
+ rawOptions,
93
91
  mainPath,
94
92
  } = current;
95
93
 
@@ -101,14 +99,8 @@ const createScan = (files) => (mainPath, {push, progress, options}) => {
101
99
  const fileContent = readFileContent(inputFile) || '{}';
102
100
  const [matchedJS, matchedAST] = magicParse(inputFilename, fileContent);
103
101
 
104
- const name = `match-file: ${inputFilename}`;
105
- const plugins = [
106
- [name, plugin],
107
- ];
108
-
109
- const places = findPlaces(matchedAST, matchedJS, {
110
- plugins,
111
- });
102
+ const options = parseOptions(inputFilename, rawOptions);
103
+ const places = findPlaces(matchedAST, matchedJS, options);
112
104
 
113
105
  if (!places.length)
114
106
  continue;
@@ -122,7 +114,7 @@ const createScan = (files) => (mainPath, {push, progress, options}) => {
122
114
 
123
115
  outputFilename,
124
116
  message,
125
- plugins,
117
+ options,
126
118
 
127
119
  matchedAST,
128
120
  matchedJS,
@@ -193,3 +185,18 @@ function parseMatcher(matcher, options) {
193
185
 
194
186
  return matcher.split(' -> ');
195
187
  }
188
+
189
+ function parseOptions(inputFilename, rawOptions) {
190
+ if (rawOptions.plugins)
191
+ return rawOptions;
192
+
193
+ const name = `match-file: ${inputFilename}`;
194
+
195
+ const plugins = [
196
+ [name, rawOptions],
197
+ ];
198
+
199
+ return {
200
+ plugins,
201
+ };
202
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-match-files",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout operator adds ability to match files to plugins",