|
1 | 1 | 'use strict' |
2 | 2 | const path = require('path') |
3 | 3 | const fs = require('fs') |
| 4 | +const { spawnSync } = require('child_process') |
4 | 5 | const process = require('process') |
5 | | -const git = require('isomorphic-git') |
6 | 6 | const exec = require('exec-inline').spawnSync |
7 | 7 | const command = require.resolve('@sane-fmt/wasm32-wasi/bin') |
8 | 8 | const { project } = require('@tools/places') |
9 | 9 |
|
10 | 10 | const argvPrefix = process.argv.slice(2) |
11 | 11 | const TARGET_REGEX = /\.(js|ts)x?$/i |
12 | 12 |
|
| 13 | +function execCmd(command, args, options) { |
| 14 | + const { error, status, stdout } = spawnSync(command, args, { |
| 15 | + encoding: 'utf8', |
| 16 | + stdio: ['pipe', 'pipe', 'inherit'], |
| 17 | + ...options, |
| 18 | + }) |
| 19 | + |
| 20 | + if (error) throw error |
| 21 | + if (status) throw new Error(`Failed to execute ${command} ${args.join(' ')}`) |
| 22 | + |
| 23 | + return stdout |
| 24 | +} |
| 25 | + |
13 | 26 | async function listTargets() { |
14 | | - const fromLS = (await git.listFiles({ fs, dir: project })) |
| 27 | + const fromLS = execCmd('git', ['ls-files'], { cwd: project }) |
| 28 | + .split('\n') |
| 29 | + .map(line => line.trim()) |
| 30 | + .filter(Boolean) |
15 | 31 | .filter(filename => TARGET_REGEX.test(filename)) |
16 | 32 |
|
17 | | - const fromStatus = ( |
18 | | - await git.statusMatrix({ |
19 | | - fs, |
20 | | - dir: project, |
21 | | - filter: filename => TARGET_REGEX.test(filename), |
22 | | - }) |
23 | | - ).map(([filename]) => filename) |
| 33 | + const fromStatus = execCmd('git', ['status', '--porcelain=v1'], { cwd: project }) |
| 34 | + .split('\n') |
| 35 | + .map(line => line.trim()) |
| 36 | + .filter(Boolean) |
| 37 | + .map(line => line.slice(3)) |
| 38 | + .filter(filename => TARGET_REGEX.test(filename)) |
24 | 39 |
|
25 | 40 | return [...new Set([...fromLS, ...fromStatus])] |
26 | 41 | .filter(filename => fs.existsSync(path.resolve(project, filename))) |
|
0 commit comments