Skip to content

Commit ddc706a

Browse files
committed
replace execa by tinyexec
1 parent ca51709 commit ddc706a

File tree

3 files changed

+18
-113
lines changed

3 files changed

+18
-113
lines changed

packages/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
"dependencies": {
7272
"@trigger.dev/core": "workspace:3.3.13",
7373
"@trigger.dev/sdk": "workspace:3.3.13",
74-
"execa": "^9.5.2",
7574
"pkg-types": "^1.1.3",
75+
"tinyexec": "^0.3.2",
7676
"tinyglobby": "^0.2.2",
7777
"tsconfck": "3.1.3"
7878
},

packages/build/src/extensions/python.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import fs from "node:fs";
22
import assert from "node:assert";
3-
import { execa } from "execa";
43
import { additionalFiles } from "./core/additionalFiles.js";
54
import { BuildManifest } from "@trigger.dev/core/v3";
65
import { BuildContext, BuildExtension } from "@trigger.dev/core/v3/build";
76
import { logger } from "@trigger.dev/sdk/v3";
8-
9-
import type { VerboseObject } from "execa";
7+
import { x, Options as XOptions, Result } from "tinyexec";
108

119
export type PythonOptions = {
1210
requirements?: string[];
@@ -30,8 +28,6 @@ export type PythonOptions = {
3028
scripts?: string[];
3129
};
3230

33-
type ExecaOptions = Parameters<typeof execa>[1];
34-
3531
const splitAndCleanComments = (str: string) =>
3632
str
3733
.split("\n")
@@ -124,26 +120,24 @@ class PythonExtension implements BuildExtension {
124120

125121
export const run = async (
126122
scriptArgs: string[] = [],
127-
options: ExecaOptions = {}
128-
): Promise<ReturnType<typeof execa>> => {
123+
options: Partial<XOptions> = {}
124+
): Promise<Result> => {
129125
const pythonBin = process.env.PYTHON_BIN_PATH || "python";
130126

131-
const result = await execa({
132-
shell: true,
133-
verbose: (line: string, obj: VerboseObject) => logger.debug(obj.message, obj),
127+
const result = await x(pythonBin, scriptArgs, {
134128
...options,
135-
})(pythonBin, scriptArgs);
129+
throwOnError: false, // Ensure errors are handled manually
130+
});
136131

137132
try {
138-
assert(!result.failed, `Python command failed: ${result.stderr}\nCommand: ${result.command}`);
139133
assert(
140134
result.exitCode === 0,
141135
`Python command exited with non-zero code ${result.exitCode}\nStdout: ${result.stdout}\nStderr: ${result.stderr}`
142136
);
143137
} catch (error) {
144138
logger.error("Python command execution failed", {
145139
error: error instanceof Error ? error.message : error,
146-
command: result.command,
140+
command: `${pythonBin} ${scriptArgs.join(" ")}`,
147141
stdout: result.stdout,
148142
stderr: result.stderr,
149143
exitCode: result.exitCode,
@@ -157,25 +151,23 @@ export const run = async (
157151
export const runScript = (
158152
scriptPath: string,
159153
scriptArgs: string[] = [],
160-
options: ExecaOptions = {}
154+
options: Partial<XOptions> = {}
161155
) => {
162156
assert(scriptPath, "Script path is required");
163157
assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
164158

165159
return run([scriptPath, ...scriptArgs], options);
166160
};
167161

168-
export const runInline = async (scriptContent: string, options: ExecaOptions = {}) => {
162+
export const runInline = async (scriptContent: string, options: Partial<XOptions> = {}) => {
169163
assert(scriptContent, "Script content is required");
170164

171-
// Create a temporary file with restricted permissions
172165
const tmpFile = `/tmp/script_${Date.now()}.py`;
173166
await fs.promises.writeFile(tmpFile, scriptContent, { mode: 0o600 });
174167

175168
try {
176169
return await runScript(tmpFile, [], options);
177170
} finally {
178-
// Clean up temporary file
179171
await fs.promises.unlink(tmpFile);
180172
}
181173
};

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)