🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

getsuperpower

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getsuperpower - npm Package Compare versions

Comparing version
0.3.5
to
0.3.6
+56
src/process.ts
import { spawn } from "node:child_process";
export interface SubprocessCommand {
executable: string;
args: string[];
cwd: string;
env?: Record<string, string | undefined>;
}
export interface SubprocessResult {
stdout: string;
stderr: string;
exitCode: number;
}
export async function runSubprocess(command: SubprocessCommand): Promise<SubprocessResult> {
const subprocess = spawn(command.executable, command.args, {
cwd: command.cwd,
env: command.env,
stdio: ["ignore", "pipe", "pipe"],
});
let spawnErrorMessage = "";
const stdout = readStream(subprocess.stdout);
const stderr = readStream(subprocess.stderr);
const exitCode = new Promise<number>((resolve) => {
subprocess.once("error", (error) => {
spawnErrorMessage = error.message;
resolve(127);
});
subprocess.once("close", (code) => resolve(code ?? 1));
});
const [stdoutText, stderrText, code] = await Promise.all([stdout, stderr, exitCode]);
return {
stdout: stdoutText,
stderr: [stderrText, spawnErrorMessage].filter(Boolean).join("\n"),
exitCode: code,
};
}
function readStream(stream: NodeJS.ReadableStream | null): Promise<string> {
if (!stream) {
return Promise.resolve("");
}
return new Promise((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on("data", (chunk: Buffer | string) => {
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
});
stream.on("error", reject);
stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
});
}
+2
-2
{
"name": "getsuperpower",
"version": "0.3.5",
"version": "0.3.6",
"type": "module",

@@ -20,3 +20,3 @@ "repository": {

"dev": "bun src/cli.ts",
"build": "bun build --target=bun --outfile=dist/cli.js src/cli.ts",
"build": "bun build --target=node --outfile=dist/cli.js src/cli.ts",
"test": "bun test tests",

@@ -23,0 +23,0 @@ "ci:test": "find tests -maxdepth 1 -name '*.test.ts' ! -name '*.e2e.test.ts' -print0 | xargs -0 bun test",

@@ -1,2 +0,2 @@

#!/usr/bin/env bun
#!/usr/bin/env node

@@ -24,3 +24,3 @@ import { homedir } from "node:os";

const CLI_VERSION = "0.3.5";
const CLI_VERSION = "0.3.6";

@@ -27,0 +27,0 @@ interface CommanderVersionInternals {

@@ -21,2 +21,3 @@ import { existsSync } from "node:fs";

} from "./plugins";
import { runSubprocess } from "./process";
import {

@@ -568,15 +569,3 @@ createWorkflowBundleScaffold,

): Promise<GetSuperpowerExternalSkillCommandResult> {
const subprocess = Bun.spawn([command.executable, ...command.args], {
cwd: command.cwd,
stdout: "pipe",
stderr: "pipe",
env: command.env,
});
const [stdout, stderr, exitCode] = await Promise.all([
new Response(subprocess.stdout).text(),
new Response(subprocess.stderr).text(),
subprocess.exited,
]);
return { stdout, stderr, exitCode };
return runSubprocess(command);
}

@@ -583,0 +572,0 @@

@@ -6,2 +6,3 @@ import { existsSync } from "node:fs";

import { z } from "zod";
import { runSubprocess } from "../../process";

@@ -543,15 +544,3 @@ const workflowFileName = "workflow.json";

const subprocess = Bun.spawn([command.executable, ...command.args], {
cwd: command.cwd,
stdout: "pipe",
stderr: "pipe",
env: command.env,
});
const [stdout, stderr, exitCode] = await Promise.all([
new Response(subprocess.stdout).text(),
new Response(subprocess.stderr).text(),
subprocess.exited,
]);
return { stdout, stderr, exitCode };
return runSubprocess(command);
}

@@ -558,0 +547,0 @@

Sorry, the diff of this file is too big to display