Skip to content

Commit 71b8eb3

Browse files
easingthemesclaude
andcommitted
feat!: replace rsyncwrapper with local rsync module
Add src/rsync.js as a drop-in replacement for rsyncwrapper, using child_process.spawn directly. Only implements the options this project uses. Single line change in rsyncCli.js to swap the import. BREAKING CHANGE: rsyncwrapper dependency removed, rsync command is now constructed and executed via a local module using child_process.spawn. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 76668b2 commit 71b8eb3

3 files changed

Lines changed: 90 additions & 82 deletions

File tree

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rsync.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const { spawn } = require('child_process');
2+
3+
const escapeSpaces = (str) => (typeof str === 'string' ? str.replace(/\b\s/g, '\\ ') : str);
4+
5+
const buildRsyncCommand = ({ src, dest, excludeFirst, port, privateKey, args, sshCmdArgs }) => {
6+
const cmdParts = [];
7+
8+
const sources = Array.isArray(src) ? src : [src];
9+
cmdParts.push(...sources.map(escapeSpaces));
10+
cmdParts.push(escapeSpaces(dest));
11+
12+
let sshCmd = `ssh -p ${port || 22} -i ${privateKey}`;
13+
if (sshCmdArgs && sshCmdArgs.length > 0) {
14+
sshCmd += ` ${sshCmdArgs.join(' ')}`;
15+
}
16+
cmdParts.push('--rsh', `"${sshCmd}"`);
17+
18+
cmdParts.push('--recursive');
19+
20+
if (Array.isArray(excludeFirst)) {
21+
excludeFirst.forEach((pattern) => {
22+
if (pattern) cmdParts.push(`--exclude=${escapeSpaces(pattern)}`);
23+
});
24+
}
25+
26+
if (Array.isArray(args)) {
27+
cmdParts.push(...args);
28+
}
29+
30+
return `rsync ${[...new Set(cmdParts)].join(' ')}`;
31+
};
32+
33+
module.exports = (options, callback) => {
34+
const cmd = buildRsyncCommand(options);
35+
const noop = () => {};
36+
const onStdout = options.onStdout || noop;
37+
const onStderr = options.onStderr || noop;
38+
39+
let stdout = '';
40+
let stderr = '';
41+
const proc = spawn('/bin/sh', ['-c', cmd]);
42+
43+
proc.stdout.on('data', (data) => { onStdout(data); stdout += data; });
44+
proc.stderr.on('data', (data) => { onStderr(data); stderr += data; });
45+
46+
proc.on('exit', (code) => {
47+
let error = null;
48+
if (code !== 0) {
49+
error = new Error(`rsync exited with code ${code}`);
50+
error.code = code;
51+
}
52+
callback(error, stdout, stderr, cmd);
53+
});
54+
};

0 commit comments

Comments
 (0)