( roots: Array<string>, extensions: Array<string>, ignore: IgnoreMatcher, enableSymlinks: boolean, callback: Callback, )
| 131 | } |
| 132 | |
| 133 | function findNative( |
| 134 | roots: Array<string>, |
| 135 | extensions: Array<string>, |
| 136 | ignore: IgnoreMatcher, |
| 137 | enableSymlinks: boolean, |
| 138 | callback: Callback, |
| 139 | ): void { |
| 140 | const args = [...roots]; |
| 141 | if (enableSymlinks) { |
| 142 | args.push('(', '-type', 'f', '-o', '-type', 'l', ')'); |
| 143 | } else { |
| 144 | args.push('-type', 'f'); |
| 145 | } |
| 146 | |
| 147 | if (extensions.length > 0) { |
| 148 | args.push('('); |
| 149 | } |
| 150 | for (const [index, ext] of extensions.entries()) { |
| 151 | if (index) { |
| 152 | args.push('-o'); |
| 153 | } |
| 154 | args.push('-iname', `*.${ext}`); |
| 155 | } |
| 156 | if (extensions.length > 0) { |
| 157 | args.push(')'); |
| 158 | } |
| 159 | |
| 160 | const child = spawn('find', args); |
| 161 | let stdout = ''; |
| 162 | if (child.stdout === null) { |
| 163 | throw new Error( |
| 164 | 'stdout is null - this should never happen. Please open up an issue at https://github.com/jestjs/jest', |
| 165 | ); |
| 166 | } |
| 167 | child.stdout.setEncoding('utf8'); |
| 168 | child.stdout.on('data', data => (stdout += data)); |
| 169 | |
| 170 | child.stdout.on('close', () => { |
| 171 | const lines = stdout |
| 172 | .trim() |
| 173 | .split('\n') |
| 174 | .filter(x => !ignore(x)); |
| 175 | const result: Result = []; |
| 176 | let count = lines.length; |
| 177 | if (count) { |
| 178 | for (const path of lines) { |
| 179 | fs.stat(path, (err, stat) => { |
| 180 | // Filter out symlinks that describe directories |
| 181 | if (!err && stat && !stat.isDirectory()) { |
| 182 | result.push([path, stat.mtime.getTime(), stat.size]); |
| 183 | } |
| 184 | if (--count === 0) { |
| 185 | callback(result); |
| 186 | } |
| 187 | }); |
| 188 | } |
| 189 | } else { |
| 190 | callback([]); |
no test coverage detected