| 22 | type Callback = (result: Result) => void; |
| 23 | |
| 24 | async function hasNativeFindSupport( |
| 25 | forceNodeFilesystemAPI: boolean, |
| 26 | ): Promise<boolean> { |
| 27 | if (forceNodeFilesystemAPI) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | try { |
| 32 | return await new Promise(resolve => { |
| 33 | // Check the find binary supports the non-POSIX -iname parameter wrapped in parens. |
| 34 | const args = [ |
| 35 | '.', |
| 36 | '-type', |
| 37 | 'f', |
| 38 | '(', |
| 39 | '-iname', |
| 40 | '*.ts', |
| 41 | '-o', |
| 42 | '-iname', |
| 43 | '*.js', |
| 44 | ')', |
| 45 | ]; |
| 46 | const child = spawn('find', args, {cwd: __dirname}); |
| 47 | child.on('error', () => { |
| 48 | resolve(false); |
| 49 | }); |
| 50 | child.on('exit', code => { |
| 51 | resolve(code === 0); |
| 52 | }); |
| 53 | }); |
| 54 | } catch { |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | function find( |
| 60 | roots: Array<string>, |