@trigger.dev/python 0.0.0-prerelease-20250226191317 → 0.0.0-prerelease-20250227170700
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/README.md +9 -29
- package/dist/commonjs/extension.d.ts +2 -1
- package/dist/commonjs/extension.js +19 -44
- package/dist/commonjs/extension.js.map +1 -1
- package/dist/commonjs/index.d.ts +8 -4
- package/dist/commonjs/index.js +43 -77
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/extension.d.ts +2 -1
- package/dist/esm/extension.js +19 -44
- package/dist/esm/extension.js.map +1 -1
- package/dist/esm/index.d.ts +8 -4
- package/dist/esm/index.js +39 -76
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -9
- package/dist/commonjs/utils/tempFiles.d.ts +0 -8
- package/dist/commonjs/utils/tempFiles.js +0 -29
- package/dist/commonjs/utils/tempFiles.js.map +0 -1
- package/dist/esm/utils/tempFiles.d.ts +0 -8
- package/dist/esm/utils/tempFiles.js +0 -26
- package/dist/esm/utils/tempFiles.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ This extension introduces the <code>pythonExtension</code> build extension, whic
|
|
|
14
14
|
- <code>run</code>: Executes Python commands with proper environment setup.
|
|
15
15
|
- <code>runInline</code>: Executes inline Python code directly from Node.
|
|
16
16
|
- <code>runScript</code>: Executes standalone <code>.py</code> script files.
|
|
17
|
-
- **Custom Python Path:** In development, you can configure <code>
|
|
17
|
+
- **Custom Python Path:** In development, you can configure <code>pythonBinaryPath</code> to point to a custom Python installation.
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ This extension introduces the <code>pythonExtension</code> build extension, whic
|
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
24
|
import { defineConfig } from "@trigger.dev/sdk/v3";
|
|
25
|
-
import
|
|
25
|
+
import pythonExtension from "@trigger.dev/python/extension";
|
|
26
26
|
|
|
27
27
|
export default defineConfig({
|
|
28
28
|
project: "<project ref>",
|
|
@@ -30,8 +30,8 @@ export default defineConfig({
|
|
|
30
30
|
extensions: [
|
|
31
31
|
pythonExtension({
|
|
32
32
|
requirementsFile: "./requirements.txt", // Optional: Path to your requirements file
|
|
33
|
-
|
|
34
|
-
scripts: ["
|
|
33
|
+
pythonBinaryPath: path.join(rootDir, `.venv/bin/python`), // Optional: Custom Python binary path
|
|
34
|
+
scripts: ["my_script.py"], // List of Python scripts to include
|
|
35
35
|
}),
|
|
36
36
|
],
|
|
37
37
|
},
|
|
@@ -40,34 +40,13 @@ export default defineConfig({
|
|
|
40
40
|
|
|
41
41
|
2. (Optional) Create a <code>requirements.txt</code> file in your project root with the necessary Python dependencies.
|
|
42
42
|
|
|
43
|
-
```plaintext title="requirements.txt"
|
|
44
|
-
pandas==1.3.3
|
|
45
|
-
numpy==1.21.2
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
```typescript title="trigger.config.ts"
|
|
49
|
-
import { defineConfig } from "@trigger.dev/sdk/v3";
|
|
50
|
-
import { pythonExtension } from "@trigger.dev/python/extension";
|
|
51
|
-
|
|
52
|
-
export default defineConfig({
|
|
53
|
-
project: "<project ref>",
|
|
54
|
-
build: {
|
|
55
|
-
extensions: [
|
|
56
|
-
pythonExtension({
|
|
57
|
-
requirementsFile: "./requirements.txt",
|
|
58
|
-
}),
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
|
|
64
43
|
3. Execute Python scripts within your tasks using one of the provided functions:
|
|
65
44
|
|
|
66
45
|
### Running a Python Script
|
|
67
46
|
|
|
68
47
|
```typescript
|
|
69
48
|
import { task } from "@trigger.dev/sdk/v3";
|
|
70
|
-
import
|
|
49
|
+
import python from "@trigger.dev/python";
|
|
71
50
|
|
|
72
51
|
export const myScript = task({
|
|
73
52
|
id: "my-python-script",
|
|
@@ -82,7 +61,7 @@ export const myScript = task({
|
|
|
82
61
|
|
|
83
62
|
```typescript
|
|
84
63
|
import { task } from "@trigger.dev/sdk/v3";
|
|
85
|
-
import
|
|
64
|
+
import python from "@trigger.dev/python";
|
|
86
65
|
|
|
87
66
|
export const myTask = task({
|
|
88
67
|
id: "to_datetime-task",
|
|
@@ -90,7 +69,7 @@ export const myTask = task({
|
|
|
90
69
|
const result = await python.runInline(`
|
|
91
70
|
import pandas as pd
|
|
92
71
|
|
|
93
|
-
|
|
72
|
+
pandas.to_datetime("${+new Date() / 1000}")
|
|
94
73
|
`);
|
|
95
74
|
return result.stdout;
|
|
96
75
|
},
|
|
@@ -101,7 +80,7 @@ pd.to_datetime("${+new Date() / 1000}")
|
|
|
101
80
|
|
|
102
81
|
```typescript
|
|
103
82
|
import { task } from "@trigger.dev/sdk/v3";
|
|
104
|
-
import
|
|
83
|
+
import python from "@trigger.dev/python";
|
|
105
84
|
|
|
106
85
|
export const pythonVersionTask = task({
|
|
107
86
|
id: "python-version-task",
|
|
@@ -115,6 +94,7 @@ export const pythonVersionTask = task({
|
|
|
115
94
|
## Limitations
|
|
116
95
|
|
|
117
96
|
- This is a **partial implementation** and does not provide full Python support as an execution runtime for tasks.
|
|
97
|
+
- Only basic Python script execution is supported; scripts are not automatically copied to staging/production containers.
|
|
118
98
|
- Manual intervention may be required for installing and configuring binary dependencies in development environments.
|
|
119
99
|
|
|
120
100
|
## Additional Information
|
|
@@ -11,7 +11,7 @@ export type PythonOptions = {
|
|
|
11
11
|
*
|
|
12
12
|
* Example: `/usr/bin/python3` or `C:\\Python39\\python.exe`
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
pythonBinaryPath?: string;
|
|
15
15
|
/**
|
|
16
16
|
* An array of glob patterns that specify which Python scripts are allowed to be executed.
|
|
17
17
|
*
|
|
@@ -21,3 +21,4 @@ export type PythonOptions = {
|
|
|
21
21
|
scripts?: string[];
|
|
22
22
|
};
|
|
23
23
|
export declare function pythonExtension(options?: PythonOptions): BuildExtension;
|
|
24
|
+
export default pythonExtension;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.pythonExtension = pythonExtension;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
|
-
const
|
|
9
|
+
const core_1 = require("@trigger.dev/build/extensions/core");
|
|
10
10
|
const splitAndCleanComments = (str) => str
|
|
11
11
|
.split("\n")
|
|
12
12
|
.map((line) => line.trim())
|
|
@@ -26,12 +26,12 @@ class PythonExtension {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
async onBuildComplete(context, manifest) {
|
|
29
|
-
await (0,
|
|
29
|
+
await (0, core_1.additionalFiles)({
|
|
30
30
|
files: this.options.scripts ?? [],
|
|
31
|
-
}
|
|
31
|
+
}).onBuildComplete(context, manifest);
|
|
32
32
|
if (context.target === "dev") {
|
|
33
|
-
if (this.options.
|
|
34
|
-
process.env.PYTHON_BIN_PATH = this.options.
|
|
33
|
+
if (this.options.pythonBinaryPath) {
|
|
34
|
+
process.env.PYTHON_BIN_PATH = this.options.pythonBinaryPath;
|
|
35
35
|
}
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
@@ -57,52 +57,27 @@ class PythonExtension {
|
|
|
57
57
|
override: true,
|
|
58
58
|
},
|
|
59
59
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await (0, internal_1.addAdditionalFilesToBuild)("pythonExtension", {
|
|
66
|
-
files: [this.options.requirementsFile],
|
|
67
|
-
}, context, manifest);
|
|
68
|
-
// Add a layer to the build that installs the requirements
|
|
69
|
-
context.addLayer({
|
|
70
|
-
id: "python-dependencies",
|
|
71
|
-
image: {
|
|
72
|
-
instructions: splitAndCleanComments(`
|
|
73
|
-
# Copy the requirements file
|
|
74
|
-
COPY ${this.options.requirementsFile} .
|
|
75
|
-
# Install dependencies
|
|
76
|
-
RUN pip install --no-cache-dir -r ${this.options.requirementsFile}
|
|
77
|
-
`),
|
|
78
|
-
},
|
|
79
|
-
deploy: {
|
|
80
|
-
override: true,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
else if (this.options.requirements) {
|
|
85
|
-
context.addLayer({
|
|
86
|
-
id: "python-dependencies",
|
|
87
|
-
build: {
|
|
88
|
-
env: {
|
|
89
|
-
REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
|
|
90
|
-
},
|
|
60
|
+
context.addLayer({
|
|
61
|
+
id: "python-dependencies",
|
|
62
|
+
build: {
|
|
63
|
+
env: {
|
|
64
|
+
REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
|
|
91
65
|
},
|
|
92
|
-
|
|
93
|
-
|
|
66
|
+
},
|
|
67
|
+
image: {
|
|
68
|
+
instructions: splitAndCleanComments(`
|
|
94
69
|
ARG REQUIREMENTS_CONTENT
|
|
95
70
|
RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt
|
|
96
71
|
|
|
97
72
|
# Install dependencies
|
|
98
73
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
99
74
|
`),
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
75
|
+
},
|
|
76
|
+
deploy: {
|
|
77
|
+
override: true,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
106
80
|
}
|
|
107
81
|
}
|
|
82
|
+
exports.default = pythonExtension;
|
|
108
83
|
//# sourceMappingURL=extension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":";;;;;AAkCA,0CAEC;AApCD,sDAAyB;AACzB,8DAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":";;;;;AAkCA,0CAEC;AApCD,sDAAyB;AACzB,8DAAiC;AACjC,6DA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AEvC,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;gBAClC,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;YAC9D,CAAC;YAED,OAAO;QACT,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,IAAI,eAAe,CAAC,CAAC;QAEzD,OAAO,CAAC,QAAQ,CAAC;YACf,EAAE,EAAE,qBAAqB;YACzB,KAAK,EAAE;gBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;;;;SASnC,CAAC;aACH;YACD,MAAM,EAAE;gBACN,GAAG,EAAE;oBACH,eAAe,EAAE,sBAAsB;iBACxC;gBACD,QAAQ,EAAE,IAAI;aACf;SACF,CAAC,CAAC;QAEH,OAAO,CAAC,QAAQ,CAAC;YACf,EAAE,EAAE,qBAAqB;YACzB,KAAK,EAAE;gBACL,GAAG,EAAE;oBACH,oBAAoB,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;iBAClE;aACF;YACD,KAAK,EAAE;gBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;SAMnC,CAAC;aACH;YACD,MAAM,EAAE;gBACN,QAAQ,EAAE,IAAI;aACf;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,eAAe,CAAC"}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Options as XOptions, Result } from "tinyexec";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare const run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
3
|
+
export declare const runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
4
|
+
export declare const runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
7
|
+
runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
8
|
+
runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
|
|
6
9
|
};
|
|
10
|
+
export default _default;
|
package/dist/commonjs/index.js
CHANGED
|
@@ -3,88 +3,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.runInline = exports.runScript = exports.run = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
9
|
const v3_1 = require("@trigger.dev/sdk/v3");
|
|
10
10
|
const tinyexec_1 = require("tinyexec");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return await v3_1.logger.trace("python.run()", async (span) => {
|
|
17
|
-
const result = await (0, tinyexec_1.x)(pythonBin, scriptArgs, {
|
|
18
|
-
...options,
|
|
19
|
-
throwOnError: false, // Ensure errors are handled manually
|
|
20
|
-
});
|
|
21
|
-
if (result.exitCode) {
|
|
22
|
-
span.setAttribute("exitCode", result.exitCode);
|
|
23
|
-
}
|
|
24
|
-
if (result.exitCode !== 0) {
|
|
25
|
-
throw new Error(`${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
28
|
-
}, {
|
|
29
|
-
attributes: {
|
|
30
|
-
pythonBin,
|
|
31
|
-
args: scriptArgs.join(" "),
|
|
32
|
-
[v3_2.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
async runScript(scriptPath, scriptArgs = [], options = {}) {
|
|
37
|
-
(0, node_assert_1.default)(scriptPath, "Script path is required");
|
|
38
|
-
(0, node_assert_1.default)(node_fs_1.default.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
|
|
39
|
-
return await v3_1.logger.trace("python.runScript()", async (span) => {
|
|
40
|
-
span.setAttribute("scriptPath", scriptPath);
|
|
41
|
-
const result = await (0, tinyexec_1.x)(process.env.PYTHON_BIN_PATH || "python", [scriptPath, ...scriptArgs], {
|
|
42
|
-
...options,
|
|
43
|
-
throwOnError: false,
|
|
44
|
-
});
|
|
45
|
-
if (result.exitCode) {
|
|
46
|
-
span.setAttribute("exitCode", result.exitCode);
|
|
47
|
-
}
|
|
48
|
-
if (result.exitCode !== 0) {
|
|
49
|
-
throw new Error(`${scriptPath} ${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}, {
|
|
53
|
-
attributes: {
|
|
54
|
-
pythonBin: process.env.PYTHON_BIN_PATH || "python",
|
|
55
|
-
scriptPath,
|
|
56
|
-
args: scriptArgs.join(" "),
|
|
57
|
-
[v3_2.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
|
|
58
|
-
},
|
|
11
|
+
const run = async (scriptArgs = [], options = {}) => {
|
|
12
|
+
const pythonBin = process.env.PYTHON_BIN_PATH || "python";
|
|
13
|
+
return await v3_1.logger.trace("Python call", async (span) => {
|
|
14
|
+
span.addEvent("Properties", {
|
|
15
|
+
command: `${pythonBin} ${scriptArgs.join(" ")}`,
|
|
59
16
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return await v3_1.logger.trace("python.runInline()", async (span) => {
|
|
64
|
-
span.setAttribute("contentLength", scriptContent.length);
|
|
65
|
-
// Using the withTempFile utility to handle the temporary file
|
|
66
|
-
return await (0, tempFiles_js_1.withTempFile)(`script_${Date.now()}.py`, async (tempFilePath) => {
|
|
67
|
-
span.setAttribute("tempFilePath", tempFilePath);
|
|
68
|
-
const pythonBin = process.env.PYTHON_BIN_PATH || "python";
|
|
69
|
-
const result = await (0, tinyexec_1.x)(pythonBin, [tempFilePath], {
|
|
70
|
-
...options,
|
|
71
|
-
throwOnError: false,
|
|
72
|
-
});
|
|
73
|
-
if (result.exitCode) {
|
|
74
|
-
span.setAttribute("exitCode", result.exitCode);
|
|
75
|
-
}
|
|
76
|
-
if (result.exitCode !== 0) {
|
|
77
|
-
throw new Error(`Inline script exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}, scriptContent);
|
|
81
|
-
}, {
|
|
82
|
-
attributes: {
|
|
83
|
-
pythonBin: process.env.PYTHON_BIN_PATH || "python",
|
|
84
|
-
contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
|
|
85
|
-
[v3_2.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
|
|
86
|
-
},
|
|
17
|
+
const result = await (0, tinyexec_1.x)(pythonBin, scriptArgs, {
|
|
18
|
+
...options,
|
|
19
|
+
throwOnError: false, // Ensure errors are handled manually
|
|
87
20
|
});
|
|
88
|
-
|
|
21
|
+
span.addEvent("Output", { ...result });
|
|
22
|
+
if (result.exitCode !== 0) {
|
|
23
|
+
v3_1.logger.error(result.stderr, { ...result });
|
|
24
|
+
throw new Error(`Python command exited with non-zero code ${result.exitCode}`);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
exports.run = run;
|
|
30
|
+
const runScript = (scriptPath, scriptArgs = [], options = {}) => {
|
|
31
|
+
(0, node_assert_1.default)(scriptPath, "Script path is required");
|
|
32
|
+
(0, node_assert_1.default)(node_fs_1.default.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
|
|
33
|
+
return (0, exports.run)([scriptPath, ...scriptArgs], options);
|
|
34
|
+
};
|
|
35
|
+
exports.runScript = runScript;
|
|
36
|
+
const runInline = async (scriptContent, options = {}) => {
|
|
37
|
+
(0, node_assert_1.default)(scriptContent, "Script content is required");
|
|
38
|
+
const tmpFile = `/tmp/script_${Date.now()}.py`;
|
|
39
|
+
await node_fs_1.default.promises.writeFile(tmpFile, scriptContent, { mode: 0o600 });
|
|
40
|
+
try {
|
|
41
|
+
return await (0, exports.runScript)(tmpFile, [], options);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
try {
|
|
45
|
+
await node_fs_1.default.promises.unlink(tmpFile);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
v3_1.logger.warn(`Failed to clean up temporary file ${tmpFile}:`, {
|
|
49
|
+
error: error.stack || error.message,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
89
53
|
};
|
|
54
|
+
exports.runInline = runInline;
|
|
55
|
+
exports.default = { run: exports.run, runScript: exports.runScript, runInline: exports.runInline };
|
|
90
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,8DAAiC;AACjC,4CAA6C;AAC7C,uCAA0D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,8DAAiC;AACjC,4CAA6C;AAC7C,uCAA0D;AAEnD,MAAM,GAAG,GAAG,KAAK,EACtB,aAAuB,EAAE,EACzB,UAA6B,EAAE,EACd,EAAE;IACnB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ,CAAC;IAE1D,OAAO,MAAM,WAAM,CAAC,KAAK,CAAC,aAA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4B,CAAC,CAAC;IAEpD,MAAM,OAAO,GAAG,eAAe,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC;IAC/C,MAAM,iBAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAErE,IAAI,CAAC;QACH,OAAO,MAAM,IAAA,iBAAS,EAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,iBAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAM,CAAC,IAAI,CAAC,qCAAqC,OAAO,GAAG,EAAE;gBAC3D,KAAK,EAAG,KAAe,CAAC,KAAK,IAAK,KAAe,CAAC,OAAO;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,SAAS,aAiBpB;AAEF,kBAAe,EAAE,GAAG,EAAH,WAAG,EAAE,SAAS,EAAT,iBAAS,EAAE,SAAS,EAAT,iBAAS,EAAE,CAAC"}
|
package/dist/esm/extension.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type PythonOptions = {
|
|
|
11
11
|
*
|
|
12
12
|
* Example: `/usr/bin/python3` or `C:\\Python39\\python.exe`
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
pythonBinaryPath?: string;
|
|
15
15
|
/**
|
|
16
16
|
* An array of glob patterns that specify which Python scripts are allowed to be executed.
|
|
17
17
|
*
|
|
@@ -21,3 +21,4 @@ export type PythonOptions = {
|
|
|
21
21
|
scripts?: string[];
|
|
22
22
|
};
|
|
23
23
|
export declare function pythonExtension(options?: PythonOptions): BuildExtension;
|
|
24
|
+
export default pythonExtension;
|
package/dist/esm/extension.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import assert from "node:assert";
|
|
3
|
-
import {
|
|
3
|
+
import { additionalFiles } from "@trigger.dev/build/extensions/core";
|
|
4
4
|
const splitAndCleanComments = (str) => str
|
|
5
5
|
.split("\n")
|
|
6
6
|
.map((line) => line.trim())
|
|
@@ -20,12 +20,12 @@ class PythonExtension {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
async onBuildComplete(context, manifest) {
|
|
23
|
-
await
|
|
23
|
+
await additionalFiles({
|
|
24
24
|
files: this.options.scripts ?? [],
|
|
25
|
-
}
|
|
25
|
+
}).onBuildComplete(context, manifest);
|
|
26
26
|
if (context.target === "dev") {
|
|
27
|
-
if (this.options.
|
|
28
|
-
process.env.PYTHON_BIN_PATH = this.options.
|
|
27
|
+
if (this.options.pythonBinaryPath) {
|
|
28
|
+
process.env.PYTHON_BIN_PATH = this.options.pythonBinaryPath;
|
|
29
29
|
}
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
@@ -51,52 +51,27 @@ class PythonExtension {
|
|
|
51
51
|
override: true,
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
await addAdditionalFilesToBuild("pythonExtension", {
|
|
60
|
-
files: [this.options.requirementsFile],
|
|
61
|
-
}, context, manifest);
|
|
62
|
-
// Add a layer to the build that installs the requirements
|
|
63
|
-
context.addLayer({
|
|
64
|
-
id: "python-dependencies",
|
|
65
|
-
image: {
|
|
66
|
-
instructions: splitAndCleanComments(`
|
|
67
|
-
# Copy the requirements file
|
|
68
|
-
COPY ${this.options.requirementsFile} .
|
|
69
|
-
# Install dependencies
|
|
70
|
-
RUN pip install --no-cache-dir -r ${this.options.requirementsFile}
|
|
71
|
-
`),
|
|
72
|
-
},
|
|
73
|
-
deploy: {
|
|
74
|
-
override: true,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else if (this.options.requirements) {
|
|
79
|
-
context.addLayer({
|
|
80
|
-
id: "python-dependencies",
|
|
81
|
-
build: {
|
|
82
|
-
env: {
|
|
83
|
-
REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
|
|
84
|
-
},
|
|
54
|
+
context.addLayer({
|
|
55
|
+
id: "python-dependencies",
|
|
56
|
+
build: {
|
|
57
|
+
env: {
|
|
58
|
+
REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
|
|
85
59
|
},
|
|
86
|
-
|
|
87
|
-
|
|
60
|
+
},
|
|
61
|
+
image: {
|
|
62
|
+
instructions: splitAndCleanComments(`
|
|
88
63
|
ARG REQUIREMENTS_CONTENT
|
|
89
64
|
RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt
|
|
90
65
|
|
|
91
66
|
# Install dependencies
|
|
92
67
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
93
68
|
`),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
69
|
+
},
|
|
70
|
+
deploy: {
|
|
71
|
+
override: true,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
100
74
|
}
|
|
101
75
|
}
|
|
76
|
+
export default pythonExtension;
|
|
102
77
|
//# sourceMappingURL=extension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AA0BrE,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAE,EAA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AAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;gBAClC,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;YAC9D,CAAC;YAED,OAAO;QACT,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,IAAI,eAAe,CAAC,CAAC;QAEzD,OAAO,CAAC,QAAQ,CAAC;YACf,EAAE,EAAE,qBAAqB;YACzB,KAAK,EAAE;gBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;;;;SASnC,CAAC;aACH;YACD,MAAM,EAAE;gBACN,GAAG,EAAE;oBACH,eAAe,EAAE,sBAAsB;iBACxC;gBACD,QAAQ,EAAE,IAAI;aACf;SACF,CAAC,CAAC;QAEH,OAAO,CAAC,QAAQ,CAAC;YACf,EAAE,EAAE,qBAAqB;YACzB,KAAK,EAAE;gBACL,GAAG,EAAE;oBACH,oBAAoB,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;iBAClE;aACF;YACD,KAAK,EAAE;gBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;SAMnC,CAAC;aACH;YACD,MAAM,EAAE;gBACN,QAAQ,EAAE,IAAI;aACf;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,eAAe,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Options as XOptions, Result } from "tinyexec";
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare const run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
3
|
+
export declare const runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
4
|
+
export declare const runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
run: (scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
7
|
+
runScript: (scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>) => Promise<Result>;
|
|
8
|
+
runInline: (scriptContent: string, options?: Partial<XOptions>) => Promise<import("tinyexec").Output>;
|
|
6
9
|
};
|
|
10
|
+
export default _default;
|
package/dist/esm/index.js
CHANGED
|
@@ -2,83 +2,46 @@ import fs from "node:fs";
|
|
|
2
2
|
import assert from "node:assert";
|
|
3
3
|
import { logger } from "@trigger.dev/sdk/v3";
|
|
4
4
|
import { x } from "tinyexec";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return await logger.trace("python.run()", async (span) => {
|
|
11
|
-
const result = await x(pythonBin, scriptArgs, {
|
|
12
|
-
...options,
|
|
13
|
-
throwOnError: false, // Ensure errors are handled manually
|
|
14
|
-
});
|
|
15
|
-
if (result.exitCode) {
|
|
16
|
-
span.setAttribute("exitCode", result.exitCode);
|
|
17
|
-
}
|
|
18
|
-
if (result.exitCode !== 0) {
|
|
19
|
-
throw new Error(`${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}, {
|
|
23
|
-
attributes: {
|
|
24
|
-
pythonBin,
|
|
25
|
-
args: scriptArgs.join(" "),
|
|
26
|
-
[SemanticInternalAttributes.STYLE_ICON]: "brand-python",
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
async runScript(scriptPath, scriptArgs = [], options = {}) {
|
|
31
|
-
assert(scriptPath, "Script path is required");
|
|
32
|
-
assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
|
|
33
|
-
return await logger.trace("python.runScript()", async (span) => {
|
|
34
|
-
span.setAttribute("scriptPath", scriptPath);
|
|
35
|
-
const result = await x(process.env.PYTHON_BIN_PATH || "python", [scriptPath, ...scriptArgs], {
|
|
36
|
-
...options,
|
|
37
|
-
throwOnError: false,
|
|
38
|
-
});
|
|
39
|
-
if (result.exitCode) {
|
|
40
|
-
span.setAttribute("exitCode", result.exitCode);
|
|
41
|
-
}
|
|
42
|
-
if (result.exitCode !== 0) {
|
|
43
|
-
throw new Error(`${scriptPath} ${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}, {
|
|
47
|
-
attributes: {
|
|
48
|
-
pythonBin: process.env.PYTHON_BIN_PATH || "python",
|
|
49
|
-
scriptPath,
|
|
50
|
-
args: scriptArgs.join(" "),
|
|
51
|
-
[SemanticInternalAttributes.STYLE_ICON]: "brand-python",
|
|
52
|
-
},
|
|
5
|
+
export const run = async (scriptArgs = [], options = {}) => {
|
|
6
|
+
const pythonBin = process.env.PYTHON_BIN_PATH || "python";
|
|
7
|
+
return await logger.trace("Python call", async (span) => {
|
|
8
|
+
span.addEvent("Properties", {
|
|
9
|
+
command: `${pythonBin} ${scriptArgs.join(" ")}`,
|
|
53
10
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return await logger.trace("python.runInline()", async (span) => {
|
|
58
|
-
span.setAttribute("contentLength", scriptContent.length);
|
|
59
|
-
// Using the withTempFile utility to handle the temporary file
|
|
60
|
-
return await withTempFile(`script_${Date.now()}.py`, async (tempFilePath) => {
|
|
61
|
-
span.setAttribute("tempFilePath", tempFilePath);
|
|
62
|
-
const pythonBin = process.env.PYTHON_BIN_PATH || "python";
|
|
63
|
-
const result = await x(pythonBin, [tempFilePath], {
|
|
64
|
-
...options,
|
|
65
|
-
throwOnError: false,
|
|
66
|
-
});
|
|
67
|
-
if (result.exitCode) {
|
|
68
|
-
span.setAttribute("exitCode", result.exitCode);
|
|
69
|
-
}
|
|
70
|
-
if (result.exitCode !== 0) {
|
|
71
|
-
throw new Error(`Inline script exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}, scriptContent);
|
|
75
|
-
}, {
|
|
76
|
-
attributes: {
|
|
77
|
-
pythonBin: process.env.PYTHON_BIN_PATH || "python",
|
|
78
|
-
contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
|
|
79
|
-
[SemanticInternalAttributes.STYLE_ICON]: "brand-python",
|
|
80
|
-
},
|
|
11
|
+
const result = await x(pythonBin, scriptArgs, {
|
|
12
|
+
...options,
|
|
13
|
+
throwOnError: false, // Ensure errors are handled manually
|
|
81
14
|
});
|
|
82
|
-
|
|
15
|
+
span.addEvent("Output", { ...result });
|
|
16
|
+
if (result.exitCode !== 0) {
|
|
17
|
+
logger.error(result.stderr, { ...result });
|
|
18
|
+
throw new Error(`Python command exited with non-zero code ${result.exitCode}`);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
export const runScript = (scriptPath, scriptArgs = [], options = {}) => {
|
|
24
|
+
assert(scriptPath, "Script path is required");
|
|
25
|
+
assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
|
|
26
|
+
return run([scriptPath, ...scriptArgs], options);
|
|
27
|
+
};
|
|
28
|
+
export const runInline = async (scriptContent, options = {}) => {
|
|
29
|
+
assert(scriptContent, "Script content is required");
|
|
30
|
+
const tmpFile = `/tmp/script_${Date.now()}.py`;
|
|
31
|
+
await fs.promises.writeFile(tmpFile, scriptContent, { mode: 0o600 });
|
|
32
|
+
try {
|
|
33
|
+
return await runScript(tmpFile, [], options);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
try {
|
|
37
|
+
await fs.promises.unlink(tmpFile);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
logger.warn(`Failed to clean up temporary file ${tmpFile}:`, {
|
|
41
|
+
error: error.stack || error.message,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
83
45
|
};
|
|
46
|
+
export default { run, runScript, runInline };
|
|
84
47
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAA+B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,CAAC,EAA+B,MAAM,UAAU,CAAC;AAE1D,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EACtB,aAAuB,EAAE,EACzB,UAA6B,EAAE,EACd,EAAE;IACnB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ,CAAC;IAE1D,OAAO,MAAM,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACtD,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE;YAC1B,OAAO,EAAE,GAAG,SAAS,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;SAChD,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE;YAC5C,GAAG,OAAO;YACV,YAAY,EAAE,KAAK,EAAE,qCAAqC;SAC3D,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QAE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C,qCAAqC,OAAO,GAAG,EAAE;gBAC3D,KAAK,EAAG,KAAe,CAAC,KAAK,IAAK,KAAe,CAAC,OAAO;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trigger.dev/python",
|
|
3
|
-
"version": "0.0.0-prerelease-
|
|
3
|
+
"version": "0.0.0-prerelease-20250227170700",
|
|
4
4
|
"description": "Python runtime and build extension for Trigger.dev",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@trigger.dev/
|
|
40
|
+
"@trigger.dev/build": "0.0.0-prerelease-20250227170700",
|
|
41
|
+
"@trigger.dev/core": "0.0.0-prerelease-20250227170700",
|
|
42
|
+
"@trigger.dev/sdk": "0.0.0-prerelease-20250227170700",
|
|
41
43
|
"tinyexec": "^0.3.2"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
@@ -47,13 +49,7 @@
|
|
|
47
49
|
"typescript": "^5.5.4",
|
|
48
50
|
"tsx": "4.17.0",
|
|
49
51
|
"esbuild": "^0.23.0",
|
|
50
|
-
"@arethetypeswrong/cli": "^0.15.4"
|
|
51
|
-
"@trigger.dev/build": "0.0.0-prerelease-20250226191317",
|
|
52
|
-
"@trigger.dev/sdk": "0.0.0-prerelease-20250226191317"
|
|
53
|
-
},
|
|
54
|
-
"peerDependencies": {
|
|
55
|
-
"@trigger.dev/sdk": "0.0.0-prerelease-20250226191317",
|
|
56
|
-
"@trigger.dev/build": "0.0.0-prerelease-20250226191317"
|
|
52
|
+
"@arethetypeswrong/cli": "^0.15.4"
|
|
57
53
|
},
|
|
58
54
|
"engines": {
|
|
59
55
|
"node": ">=18.20.0"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
|
|
3
|
-
* @param filename The filename to use for the temporary file
|
|
4
|
-
* @param callback Function that receives the path to the temporary file
|
|
5
|
-
* @param content Optional content to write to the file
|
|
6
|
-
* @returns Whatever the callback returns
|
|
7
|
-
*/
|
|
8
|
-
export declare function withTempFile<T>(filename: string, callback: (filePath: string) => Promise<T>, content?: string | Buffer): Promise<T>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withTempFile = withTempFile;
|
|
4
|
-
const promises_1 = require("node:fs/promises");
|
|
5
|
-
const node_os_1 = require("node:os");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
/**
|
|
8
|
-
* Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
|
|
9
|
-
* @param filename The filename to use for the temporary file
|
|
10
|
-
* @param callback Function that receives the path to the temporary file
|
|
11
|
-
* @param content Optional content to write to the file
|
|
12
|
-
* @returns Whatever the callback returns
|
|
13
|
-
*/
|
|
14
|
-
async function withTempFile(filename, callback, content = "") {
|
|
15
|
-
// Create temporary directory with random suffix
|
|
16
|
-
const tempDir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "app-"));
|
|
17
|
-
const tempFile = (0, node_path_1.join)(tempDir, filename);
|
|
18
|
-
try {
|
|
19
|
-
// Write to the temporary file with appropriate permissions
|
|
20
|
-
await (0, promises_1.writeFile)(tempFile, content, { mode: 0o600 });
|
|
21
|
-
// Use the file
|
|
22
|
-
return await callback(tempFile);
|
|
23
|
-
}
|
|
24
|
-
finally {
|
|
25
|
-
// Clean up
|
|
26
|
-
await (0, promises_1.rm)(tempDir, { recursive: true, force: true });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=tempFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tempFiles.js","sourceRoot":"","sources":["../../../src/utils/tempFiles.ts"],"names":[],"mappings":";;AAWA,oCAkBC;AA7BD,+CAA0D;AAC1D,qCAAiC;AACjC,yCAAiC;AAEjC;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,QAA0C,EAC1C,UAA2B,EAAE;IAE7B,gDAAgD;IAChD,MAAM,OAAO,GAAG,MAAM,IAAA,kBAAO,EAAC,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzC,IAAI,CAAC;QACH,2DAA2D;QAC3D,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,eAAe;QACf,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,WAAW;QACX,MAAM,IAAA,aAAE,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
|
|
3
|
-
* @param filename The filename to use for the temporary file
|
|
4
|
-
* @param callback Function that receives the path to the temporary file
|
|
5
|
-
* @param content Optional content to write to the file
|
|
6
|
-
* @returns Whatever the callback returns
|
|
7
|
-
*/
|
|
8
|
-
export declare function withTempFile<T>(filename: string, callback: (filePath: string) => Promise<T>, content?: string | Buffer): Promise<T>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, writeFile, rm } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
/**
|
|
5
|
-
* Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
|
|
6
|
-
* @param filename The filename to use for the temporary file
|
|
7
|
-
* @param callback Function that receives the path to the temporary file
|
|
8
|
-
* @param content Optional content to write to the file
|
|
9
|
-
* @returns Whatever the callback returns
|
|
10
|
-
*/
|
|
11
|
-
export async function withTempFile(filename, callback, content = "") {
|
|
12
|
-
// Create temporary directory with random suffix
|
|
13
|
-
const tempDir = await mkdtemp(join(tmpdir(), "app-"));
|
|
14
|
-
const tempFile = join(tempDir, filename);
|
|
15
|
-
try {
|
|
16
|
-
// Write to the temporary file with appropriate permissions
|
|
17
|
-
await writeFile(tempFile, content, { mode: 0o600 });
|
|
18
|
-
// Use the file
|
|
19
|
-
return await callback(tempFile);
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
// Clean up
|
|
23
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=tempFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tempFiles.js","sourceRoot":"","sources":["../../../src/utils/tempFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,QAA0C,EAC1C,UAA2B,EAAE;IAE7B,gDAAgD;IAChD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzC,IAAI,CAAC;QACH,2DAA2D;QAC3D,MAAM,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,eAAe;QACf,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,WAAW;QACX,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
|