@wrongstack/tools 0.3.4 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bash.js +33 -3
- package/dist/bash.js.map +1 -1
- package/dist/builtin.js +46 -9
- package/dist/builtin.js.map +1 -1
- package/dist/index.js +46 -9
- package/dist/index.js.map +1 -1
- package/dist/pack.js +46 -9
- package/dist/pack.js.map +1 -1
- package/dist/patch.js +2 -1
- package/dist/patch.js.map +1 -1
- package/dist/read.js +8 -1
- package/dist/read.js.map +1 -1
- package/dist/write.js +4 -4
- package/dist/write.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -67,7 +67,14 @@ var readTool = {
|
|
|
67
67
|
async execute(input, ctx) {
|
|
68
68
|
if (!input?.path) throw new Error("read: path is required");
|
|
69
69
|
const absPath = safeResolve(input.path, ctx);
|
|
70
|
-
|
|
70
|
+
let stat9;
|
|
71
|
+
try {
|
|
72
|
+
stat9 = await fs4.stat(absPath);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
const code = err.code;
|
|
75
|
+
if (code === "ENOENT") throw new Error(`read: file not found "${input.path}"`);
|
|
76
|
+
throw new Error(`read: failed to stat "${input.path}": ${err instanceof Error ? err.message : String(err)}`);
|
|
77
|
+
}
|
|
71
78
|
if (!stat9.isFile()) throw new Error(`read: "${input.path}" is not a regular file`);
|
|
72
79
|
if (stat9.size > MAX_BYTES) {
|
|
73
80
|
throw new Error(`read: file too large (${stat9.size} bytes, limit ${MAX_BYTES})`);
|
|
@@ -125,11 +132,11 @@ var writeTool = {
|
|
|
125
132
|
existed = stat10.isFile();
|
|
126
133
|
if (existed) {
|
|
127
134
|
if (!ctx.hasRead(absPath)) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
135
|
+
prev = await fs4.readFile(absPath, "utf8");
|
|
136
|
+
ctx.recordRead(absPath, stat10.mtimeMs);
|
|
137
|
+
} else {
|
|
138
|
+
prev = await fs4.readFile(absPath, "utf8");
|
|
131
139
|
}
|
|
132
|
-
prev = await fs4.readFile(absPath, "utf8");
|
|
133
140
|
}
|
|
134
141
|
} catch (err) {
|
|
135
142
|
if (err.code !== "ENOENT") {
|
|
@@ -882,12 +889,41 @@ var bashTool = {
|
|
|
882
889
|
signal: opts.signal
|
|
883
890
|
});
|
|
884
891
|
if (input.background) {
|
|
885
|
-
|
|
886
|
-
|
|
892
|
+
let buf2 = "";
|
|
893
|
+
let truncated = false;
|
|
894
|
+
const child2 = spawn(shell, args, {
|
|
895
|
+
cwd: ctx.projectRoot,
|
|
896
|
+
env,
|
|
897
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
898
|
+
detached: true,
|
|
899
|
+
signal: opts.signal
|
|
900
|
+
});
|
|
901
|
+
const pid = child2.pid;
|
|
902
|
+
child2.stdout?.on("data", (chunk) => {
|
|
903
|
+
if (!truncated) {
|
|
904
|
+
const remain = MAX_OUTPUT - buf2.length;
|
|
905
|
+
if (remain > 0) {
|
|
906
|
+
buf2 += chunk.toString().slice(0, remain);
|
|
907
|
+
}
|
|
908
|
+
if (buf2.length >= MAX_OUTPUT) truncated = true;
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
child2.stderr?.on("data", (chunk) => {
|
|
912
|
+
if (!truncated) {
|
|
913
|
+
const remain = MAX_OUTPUT - buf2.length;
|
|
914
|
+
if (remain > 0) {
|
|
915
|
+
buf2 += chunk.toString().slice(0, remain);
|
|
916
|
+
}
|
|
917
|
+
if (buf2.length >= MAX_OUTPUT) truncated = true;
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
child2.on("close", () => {
|
|
921
|
+
});
|
|
922
|
+
if (typeof pid === "number") child2.unref();
|
|
887
923
|
yield {
|
|
888
924
|
type: "final",
|
|
889
925
|
output: {
|
|
890
|
-
output:
|
|
926
|
+
output: truncated ? buf2.slice(0, MAX_OUTPUT) + "\u2026[truncated]" : buf2,
|
|
891
927
|
exit_code: null,
|
|
892
928
|
timed_out: false,
|
|
893
929
|
pid
|
|
@@ -932,6 +968,7 @@ var bashTool = {
|
|
|
932
968
|
}
|
|
933
969
|
}, 2e3);
|
|
934
970
|
timers.push(killTimer);
|
|
971
|
+
killTimer.unref?.();
|
|
935
972
|
} catch {
|
|
936
973
|
}
|
|
937
974
|
}
|
|
@@ -2059,7 +2096,7 @@ var patchTool = {
|
|
|
2059
2096
|
};
|
|
2060
2097
|
}
|
|
2061
2098
|
}
|
|
2062
|
-
const tmpDir = await fs4.mkdtemp(path.join(
|
|
2099
|
+
const tmpDir = await fs4.mkdtemp(path.join(os.tmpdir(), ".wstack_patch_"));
|
|
2063
2100
|
try {
|
|
2064
2101
|
await fs4.chmod(tmpDir, 448).catch(() => {
|
|
2065
2102
|
});
|