Skip to content
This repository was archived by the owner on Feb 25, 2024. It is now read-only.

Commit ff8784a

Browse files
authored
Merge pull request #93 from nodejs-monorepo-templates/fix-sane-fmt-file-listing
Fix sane-fmt touching file "within" symlinks
2 parents 29f0295 + 95a2bae commit ff8784a

File tree

3 files changed

+26
-162
lines changed

3 files changed

+26
-162
lines changed

tools/sane-fmt/index.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
'use strict'
22
const path = require('path')
33
const fs = require('fs')
4+
const { spawnSync } = require('child_process')
45
const process = require('process')
5-
const git = require('isomorphic-git')
6-
const { spawnSync } = require('exec-inline')
6+
const exec = require('exec-inline').spawnSync
77
const command = require.resolve('@sane-fmt/wasm32-wasi/bin')
88
const { project } = require('@tools/places')
99

1010
const argvPrefix = process.argv.slice(2)
1111
const TARGET_REGEX = /\.(js|ts)x?$/i
1212

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+
1326
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)
1531
.filter(filename => TARGET_REGEX.test(filename))
1632

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))
2439

2540
return [...new Set([...fromLS, ...fromStatus])]
2641
.filter(filename => fs.existsSync(path.resolve(project, filename)))
@@ -33,7 +48,7 @@ async function createArgv() {
3348

3449
async function execute() {
3550
const argv = await createArgv()
36-
return spawnSync(process.execPath, command, ...argv).exit()
51+
return exec(process.execPath, command, ...argv).exit()
3752
}
3853

3954
module.exports = {

tools/sane-fmt/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"main": "index.js",
66
"bin": "bin.js",
77
"dependencies": {
8-
"isomorphic-git": "^1.7.4",
98
"@sane-fmt/wasm32-wasi": "^0.4.5",
109
"exec-inline": "^0.0.5",
1110
"@tools/places": "file:../places"

tools/sane-fmt/pnpm-lock.yaml

Lines changed: 0 additions & 150 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)