Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Explicit node imports (#4567)

pakrym-oai170c685882bf
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0f4465a220..75db5f5971 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -34,6 +34,9 @@ importers:
eslint-plugin-jest:
specifier: ^29.0.1
+ eslint-plugin-node-import:
+ specifier: ^1.0.5
+ version: 1.0.5([email protected])
jest:
specifier: ^29.7.0
@@ -1084,6 +1087,12 @@ packages:
jest:
optional: true
+ resolution: {integrity: sha512-razzgbr3EcB5+bm8/gqTqzTJ7Bpiu8PIChiAMRfZCNigr9GZBtnVSI+wPw+RGbWYCCIzWAsK/A7ihoAeSz5j7A==}
+ engines: {node: ^14.18.0 || ^16.0.0 || >= 18.0.0}
+ peerDependencies:
+ eslint: '>=7'
+
resolution: {integrity: sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
@@ -3244,6 +3253,10 @@ snapshots:
- supports-color
- typescript
+ dependencies:
+ eslint: 9.36.0
+
dependencies:
esrecurse: 4.3.0
diff --git a/sdk/typescript/eslint.config.js b/sdk/typescript/eslint.config.js
index accb022be1..742f6fc8fd 100644
--- a/sdk/typescript/eslint.config.js
+++ b/sdk/typescript/eslint.config.js
@@ -1,5 +1,14 @@
import eslint from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
+import nodeImport from "eslint-plugin-node-import";
-export default defineConfig(eslint.configs.recommended, tseslint.configs.recommended);
+export default defineConfig(eslint.configs.recommended, tseslint.configs.recommended, {
+ plugins: {
+ "node-import": nodeImport,
+ },
+
+ rules: {
+ "node-import/prefer-node-protocol": 2,
+ },
+});
diff --git a/sdk/typescript/package.json b/sdk/typescript/package.json
index d248ba07f3..835da304b0 100644
--- a/sdk/typescript/package.json
+++ b/sdk/typescript/package.json
@@ -50,13 +50,14 @@
"eslint": "^9.36.0",
"eslint-config-prettier": "^9.1.2",
"eslint-plugin-jest": "^29.0.1",
+ "eslint-plugin-node-import": "^1.0.5",
"jest": "^29.7.0",
"prettier": "^3.6.2",
"ts-jest": "^29.3.4",
+ "ts-jest-mock-import-meta": "^1.3.1",
"ts-node": "^10.9.2",
"tsup": "^8.5.0",
"typescript": "^5.9.2",
- "typescript-eslint": "^8.45.0",
- "ts-jest-mock-import-meta": "^1.3.1"
+ "typescript-eslint": "^8.45.0"
}
}
diff --git a/sdk/typescript/samples/basic_streaming.ts b/sdk/typescript/samples/basic_streaming.ts
index 801b52e76f..97098d8a69 100755
--- a/sdk/typescript/samples/basic_streaming.ts
+++ b/sdk/typescript/samples/basic_streaming.ts
@@ -7,11 +7,11 @@ import { Codex } from "@openai/codex-sdk";
import type { ThreadEvent, ThreadItem } from "@openai/codex-sdk";
import path from "node:path";
-const executablePath =
+const codexPathOverride =
process.env.CODEX_EXECUTABLE ??
path.join(process.cwd(), "..", "..", "codex-rs", "target", "debug", "codex");
-const codex = new Codex({ executablePath });
+const codex = new Codex({ codexPathOverride });
const thread = codex.startThread();
const rl = createInterface({ input, output });
diff --git a/sdk/typescript/src/exec.ts b/sdk/typescript/src/exec.ts
index d11c2a1646..cdb1982f0d 100644
--- a/sdk/typescript/src/exec.ts
+++ b/sdk/typescript/src/exec.ts
@@ -1,4 +1,4 @@
-import { spawn } from "child_process";
+import { spawn } from "node:child_process";
import readline from "node:readline";
@@ -49,7 +49,7 @@ export class CodexExec {
if (args.threadId) {
commandArgs.push("resume", args.threadId);
- }
+ }
const env = {
...process.env,
@@ -67,7 +67,7 @@ export class CodexExec {
let spawnError: unknown | null = null;
child.once("error", (err) => (spawnError = err));
-
+
if (!child.stdin) {
child.kill();
throw new Error("Child process has no stdin");
@@ -104,7 +104,9 @@ export class CodexExec {
resolve(code);
} else {
const stderrBuffer = Buffer.concat(stderrChunks);
- reject(new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString('utf8')}`));
+ reject(
+ new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString("utf8")}`),
+ );
}
});
});
diff --git a/sdk/typescript/tests/codexExecSpy.ts b/sdk/typescript/tests/codexExecSpy.ts
index daf8123cb7..3715f71e0b 100644
--- a/sdk/typescript/tests/codexExecSpy.ts
+++ b/sdk/typescript/tests/codexExecSpy.ts
@@ -1,11 +1,11 @@
-import * as child_process from "child_process";
+import * as child_process from "node:child_process";
-jest.mock("child_process", () => {
- const actual = jest.requireActual<typeof import("child_process")>("child_process");
+jest.mock("node:child_process", () => {
+ const actual = jest.requireActual<typeof import("node:child_process")>("node:child_process");
return { ...actual, spawn: jest.fn(actual.spawn) };
});
-const actualChildProcess = jest.requireActual<typeof import("child_process")>("child_process");
+const actualChildProcess = jest.requireActual<typeof import("node:child_process")>("node:child_process");
const spawnMock = child_process.spawn as jest.MockedFunction<typeof actualChildProcess.spawn>;
export function codexExecSpy(): { args: string[][]; restore: () => void } {
diff --git a/sdk/typescript/tests/run.test.ts b/sdk/typescript/tests/run.test.ts
index 7c243b8e79..5b8de3c8d4 100644
--- a/sdk/typescript/tests/run.test.ts
+++ b/sdk/typescript/tests/run.test.ts
@@ -1,6 +1,6 @@
-import fs from "fs";
-import os from "os";
-import path from "path";
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
import { codexExecSpy } from "./codexExecSpy";
import { describe, expect, it } from "@jest/globals";
diff --git a/sdk/typescript/tests/runStreamed.test.ts b/sdk/typescript/tests/runStreamed.test.ts
index 9f60cef02e..1db273b98a 100644
--- a/sdk/typescript/tests/runStreamed.test.ts
+++ b/sdk/typescript/tests/runStreamed.test.ts
@@ -1,4 +1,4 @@
-import path from "path";
+import path from "node:path";
import { describe, expect, it } from "@jest/globals";
diff --git a/sdk/typescript/tsconfig.json b/sdk/typescript/tsconfig.json
index cdbc4f30c2..8d62e06941 100644
--- a/sdk/typescript/tsconfig.json
+++ b/sdk/typescript/tsconfig.json
@@ -19,6 +19,6 @@
"outDir": "dist",
"stripInternal": true
},
- "include": ["src", "tests", "tsup.config.ts"],
+ "include": ["src", "tests", "tsup.config.ts", "samples"],
"exclude": ["dist", "node_modules"]
}