Skip to content

Commit 170c685

Browse files
authored
Explicit node imports (#4567)
To help with compatibility
1 parent 609f75a commit 170c685

File tree

9 files changed

+43
-18
lines changed

9 files changed

+43
-18
lines changed

pnpm-lock.yaml

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

sdk/typescript/eslint.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import eslint from "@eslint/js";
22
import { defineConfig } from "eslint/config";
33
import tseslint from "typescript-eslint";
4+
import nodeImport from "eslint-plugin-node-import";
45

5-
export default defineConfig(eslint.configs.recommended, tseslint.configs.recommended);
6+
export default defineConfig(eslint.configs.recommended, tseslint.configs.recommended, {
7+
plugins: {
8+
"node-import": nodeImport,
9+
},
10+
11+
rules: {
12+
"node-import/prefer-node-protocol": 2,
13+
},
14+
});

sdk/typescript/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@
5050
"eslint": "^9.36.0",
5151
"eslint-config-prettier": "^9.1.2",
5252
"eslint-plugin-jest": "^29.0.1",
53+
"eslint-plugin-node-import": "^1.0.5",
5354
"jest": "^29.7.0",
5455
"prettier": "^3.6.2",
5556
"ts-jest": "^29.3.4",
57+
"ts-jest-mock-import-meta": "^1.3.1",
5658
"ts-node": "^10.9.2",
5759
"tsup": "^8.5.0",
5860
"typescript": "^5.9.2",
59-
"typescript-eslint": "^8.45.0",
60-
"ts-jest-mock-import-meta": "^1.3.1"
61+
"typescript-eslint": "^8.45.0"
6162
}
6263
}

sdk/typescript/samples/basic_streaming.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { Codex } from "@openai/codex-sdk";
77
import type { ThreadEvent, ThreadItem } from "@openai/codex-sdk";
88
import path from "node:path";
99

10-
const executablePath =
10+
const codexPathOverride =
1111
process.env.CODEX_EXECUTABLE ??
1212
path.join(process.cwd(), "..", "..", "codex-rs", "target", "debug", "codex");
1313

14-
const codex = new Codex({ executablePath });
14+
const codex = new Codex({ codexPathOverride });
1515
const thread = codex.startThread();
1616
const rl = createInterface({ input, output });
1717

sdk/typescript/src/exec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from "child_process";
1+
import { spawn } from "node:child_process";
22

33
import readline from "node:readline";
44

@@ -49,7 +49,7 @@ export class CodexExec {
4949

5050
if (args.threadId) {
5151
commandArgs.push("resume", args.threadId);
52-
}
52+
}
5353

5454
const env = {
5555
...process.env,
@@ -67,7 +67,7 @@ export class CodexExec {
6767

6868
let spawnError: unknown | null = null;
6969
child.once("error", (err) => (spawnError = err));
70-
70+
7171
if (!child.stdin) {
7272
child.kill();
7373
throw new Error("Child process has no stdin");
@@ -104,7 +104,9 @@ export class CodexExec {
104104
resolve(code);
105105
} else {
106106
const stderrBuffer = Buffer.concat(stderrChunks);
107-
reject(new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString('utf8')}`));
107+
reject(
108+
new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString("utf8")}`),
109+
);
108110
}
109111
});
110112
});

sdk/typescript/tests/codexExecSpy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as child_process from "child_process";
1+
import * as child_process from "node:child_process";
22

3-
jest.mock("child_process", () => {
4-
const actual = jest.requireActual<typeof import("child_process")>("child_process");
3+
jest.mock("node:child_process", () => {
4+
const actual = jest.requireActual<typeof import("node:child_process")>("node:child_process");
55
return { ...actual, spawn: jest.fn(actual.spawn) };
66
});
77

8-
const actualChildProcess = jest.requireActual<typeof import("child_process")>("child_process");
8+
const actualChildProcess = jest.requireActual<typeof import("node:child_process")>("node:child_process");
99
const spawnMock = child_process.spawn as jest.MockedFunction<typeof actualChildProcess.spawn>;
1010

1111
export function codexExecSpy(): { args: string[][]; restore: () => void } {

sdk/typescript/tests/run.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import fs from "fs";
2-
import os from "os";
3-
import path from "path";
1+
import fs from "node:fs";
2+
import os from "node:os";
3+
import path from "node:path";
44

55
import { codexExecSpy } from "./codexExecSpy";
66
import { describe, expect, it } from "@jest/globals";

sdk/typescript/tests/runStreamed.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from "path";
1+
import path from "node:path";
22

33
import { describe, expect, it } from "@jest/globals";
44

sdk/typescript/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
"outDir": "dist",
2020
"stripInternal": true
2121
},
22-
"include": ["src", "tests", "tsup.config.ts"],
22+
"include": ["src", "tests", "tsup.config.ts", "samples"],
2323
"exclude": ["dist", "node_modules"]
2424
}

0 commit comments

Comments
 (0)