@putout/operator-match-files 5.1.0 → 5.3.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
@@ -101,7 +101,7 @@ module.exports = matchFiles({
101
101
  });
102
102
  ```
103
103
 
104
- ### Exclude
104
+ ### `exclude`
105
105
 
106
106
  If you want to exclude some files, use:
107
107
 
@@ -138,6 +138,23 @@ module.exports = matchFiles({
138
138
  });
139
139
  ```
140
140
 
141
+ ### `filename`
142
+
143
+ You can pass default `filename`, so when no options provided it will be used.
144
+
145
+ ```js
146
+ const {operator} = require('putout');
147
+ const {matchFiles} = operator;
148
+ const updateTSConfig = require('../update-tsconfig');
149
+
150
+ module.exports = matchFiles({
151
+ filename: '*.d.ts',
152
+ files: {
153
+ '__name.ts -> __name.js': updateTSConfig,
154
+ },
155
+ });
156
+ ```
157
+
141
158
  ## License
142
159
 
143
160
  MIT
@@ -26,12 +26,14 @@ const {entries} = Object;
26
26
  const report = (path, {message}) => message;
27
27
 
28
28
  module.exports.matchFiles = (options) => {
29
+ const {filename} = options;
29
30
  const files = options.files ?? options;
30
31
  const exclude = options.exclude ?? [];
31
32
 
32
33
  check(files);
33
34
 
34
35
  const scan = createScan({
36
+ defaultFilename: filename,
35
37
  files,
36
38
  exclude,
37
39
  });
@@ -43,11 +45,11 @@ module.exports.matchFiles = (options) => {
43
45
  };
44
46
  };
45
47
 
46
- function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename, matchedJS, matchedAST, options}) {
48
+ function fix(inputFile, {dirPath, matchInputFilename, outputFilename, matchedJS, matchedAST, options}) {
47
49
  transform(matchedAST, matchedJS, options);
48
50
 
49
51
  const matchedJSON = magicPrint(outputFilename, matchedAST);
50
- const outputFile = getOutputFile(mainPath, {
52
+ const outputFile = getOutputFile({
51
53
  dirPath,
52
54
  matchInputFilename,
53
55
  outputFilename,
@@ -60,10 +62,12 @@ function fix(inputFile, {dirPath, mainPath, matchInputFilename, outputFilename,
60
62
  removeFile(inputFile);
61
63
  }
62
64
 
63
- const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) => {
65
+ const createScan = ({files, exclude, defaultFilename}) => (mainPath, {push, progress, options}) => {
64
66
  const allFiles = [];
65
67
  const cwd = getFilename(mainPath);
66
68
 
69
+ options.filename = options.filename ?? defaultFilename;
70
+
67
71
  for (const [filename, rawOptions] of entries(files)) {
68
72
  const [matchInputFilenameMask] = parseMatcher(filename, options);
69
73
  const inputFiles = findFile(mainPath, matchInputFilenameMask, exclude);
@@ -80,7 +84,6 @@ const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) =
80
84
  continue;
81
85
 
82
86
  allFiles.push({
83
- mainPath,
84
87
  dirPath,
85
88
  matchInputFilename,
86
89
  rawOptions,
@@ -101,7 +104,6 @@ const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) =
101
104
  inputFilename,
102
105
  outputFilename,
103
106
  rawOptions,
104
- mainPath,
105
107
  } = current;
106
108
 
107
109
  progress({
@@ -122,7 +124,6 @@ const createScan = ({files, exclude}) => (mainPath, {push, progress, options}) =
122
124
 
123
125
  push(inputFile, {
124
126
  dirPath,
125
- mainPath,
126
127
  matchInputFilename,
127
128
 
128
129
  outputFilename,
@@ -171,7 +172,7 @@ function check(files) {
171
172
  }
172
173
  }
173
174
 
174
- function getOutputFile(path, {dirPath, matchInputFilename, outputFilename, inputFile}) {
175
+ function getOutputFile({dirPath, matchInputFilename, outputFilename, inputFile}) {
175
176
  if (matchInputFilename === outputFilename)
176
177
  return inputFile;
177
178
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-match-files",
3
- "version": "5.1.0",
3
+ "version": "5.3.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",
@@ -24,7 +24,7 @@
24
24
  "report": "madrun report"
25
25
  },
26
26
  "dependencies": {
27
- "@putout/babel": "^2.0.0",
27
+ "@putout/babel": "^3.0.0",
28
28
  "@putout/engine-parser": "^11.0.1",
29
29
  "@putout/operator-filesystem": "^5.0.0",
30
30
  "@putout/operator-json": "^2.0.0"