Skip to content

Commit fccdf67

Browse files
chore: use node's spawn instead of tinyexec dep (#1227)
1 parent a7869c9 commit fccdf67

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

lib/plugin/git/Git.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EOL } from 'node:os';
2-
import { x } from 'tinyexec';
2+
import { spawn } from 'node:child_process';
33
import matcher from 'wildcard-match';
44
import { format, e, fixArgs, once, castArray } from '../../util.js';
55
import GitBase from '../GitBase.js';
@@ -11,11 +11,13 @@ const options = { write: false };
1111

1212
const docs = 'https://git.io/release-it-git';
1313

14-
const isGitRepo = () =>
15-
x('git', ['rev-parse', '--git-dir'], { throwOnError: true }).then(
16-
() => true,
17-
() => false
18-
);
14+
async function isGitRepo() {
15+
return await new Promise((resolve) => {
16+
const proc = spawn('git', ['rev-parse', '--git-dir']);
17+
proc.on('close', code => resolve(code === 0));
18+
proc.on('error', () => resolve(false));
19+
});
20+
}
1921

2022
class Git extends GitBase {
2123
constructor(...args) {

lib/shell.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import util from 'node:util';
2-
import childProcess from 'node:child_process';
3-
import { x } from 'tinyexec';
2+
import childProcess, { spawn } from 'node:child_process';
43
import { format } from './util.js';
54

65
const debug = util.debug('release-it:shell');
@@ -68,21 +67,52 @@ class Shell {
6867
});
6968
}
7069

71-
async execWithArguments(command, options, { isExternal }) {
70+
async execWithArguments(command, options = {}, { isExternal } = {}) {
7271
const [program, ...programArgs] = command;
7372

7473
try {
75-
const { stdout: out, stderr } = await x(program, programArgs, { throwOnError: true });
76-
const stdout = out === '""' ? '' : out;
77-
this.log.verbose(stdout, { isExternal });
78-
debug({ command, options, stdout, stderr });
79-
return Promise.resolve((stdout || stderr).trim());
74+
return await new Promise((resolve, reject) => {
75+
const proc = spawn(program, programArgs, {
76+
// we want to capture all output from the process so the extra 2 pipe
77+
stdio: ['inherit', 'pipe', 'pipe'],
78+
...options,
79+
});
80+
81+
let stdout = '';
82+
let stderr = '';
83+
84+
proc.stdout.on('data', data => {
85+
stdout += data.toString();
86+
});
87+
88+
proc.stderr.on('data', data => {
89+
stderr += data.toString();
90+
});
91+
92+
proc.on('close', (code) => {
93+
stdout = stdout === '""' ? '' : stdout;
94+
this.log.verbose(stdout, { isExternal });
95+
debug({ command, options, stdout, stderr });
96+
97+
if (code === 0) {
98+
resolve((stdout || stderr).trim());
99+
} else {
100+
if (stdout) {
101+
this.log.log(`\n${stdout}`);
102+
}
103+
debug({ code, command, options, stdout, stderr });
104+
reject(new Error(stderr || stdout || `Process exited with code ${code}`));
105+
}
106+
});
107+
108+
proc.on('error', err => {
109+
debug(err);
110+
reject(new Error(err.message));
111+
});
112+
});
80113
} catch (err) {
81-
if (err.output.stdout) {
82-
this.log.log(`\n${err.output.stdout}`);
83-
}
84114
debug(err);
85-
return Promise.reject(new Error(err.output.stderr || err.output.stdout || err.message));
115+
return Promise.reject(err);
86116
}
87117
}
88118
}

package-lock.json

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

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
"os-name": "6.0.0",
9898
"proxy-agent": "6.5.0",
9999
"semver": "7.7.1",
100-
"tinyexec": "1.0.1",
101100
"tinyglobby": "0.2.13",
102101
"undici": "6.21.2",
103102
"url-join": "5.0.0",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy