Skip to content

Commit b1b3052

Browse files
committed
fix(gpt-runner-cli): fix readable stream polyfill not working in nodejs 18+
1 parent a2329de commit b1b3052

File tree

5 files changed

+50
-36
lines changed

5 files changed

+50
-36
lines changed

packages/gpt-runner-cli/src/cli-start.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,19 @@ export async function startCli(cwd = PathUtils.resolve(process.cwd()), argv = pr
5656
autoFreePort: true,
5757
})
5858

59-
const startServerProcessPromise = execa('node', [startServerJsPath, '--port', String(finalPort)], {
60-
env: {
61-
...process.env,
62-
...getRunServerEnv(),
63-
GPTR_ONLY_LOAD_CONFIG_PATH: options.config || '',
64-
},
65-
})
66-
67-
startServerProcessPromise.on('error', (error) => {
59+
try {
60+
await execa('node', [startServerJsPath, '--port', String(finalPort)], {
61+
env: {
62+
...process.env,
63+
...getRunServerEnv(),
64+
GPTR_ONLY_LOAD_CONFIG_PATH: options.config || '',
65+
},
66+
stdio: 'inherit',
67+
})?.pipeStdout?.(process.stdout)?.pipeStderr?.(process.stderr)
68+
}
69+
catch (error) {
6870
consola.error(error)
69-
})
71+
}
7072

7173
const afterServerStartSuccess = async () => {
7274
const getUrl = (isLocalIp = false) => {
@@ -101,12 +103,17 @@ export async function startCli(cwd = PathUtils.resolve(process.cwd()), argv = pr
101103
}
102104
}
103105

104-
waitPort({
105-
port: finalPort,
106-
output: 'silent',
107-
}).then(afterServerStartSuccess).catch(consola.error)
106+
try {
107+
await waitPort({
108+
port: finalPort,
109+
output: 'silent',
110+
})
108111

109-
await startServerProcessPromise
112+
afterServerStartSuccess()
113+
}
114+
catch (error) {
115+
consola.error(error)
116+
}
110117
})
111118

112119
cli.help()

packages/gpt-runner-shared/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
"socket.io": "^4.7.2",
112112
"socket.io-client": "^4.7.2",
113113
"undici": "^5.23.0",
114-
"web-streams-polyfill": "^3.2.1",
115-
"zod": "^3.21.4",
114+
"web-streams-polyfill": "^4.0.0-beta.3",
115+
"zod": "^3.22.0",
116116
"zod-to-json-schema": "^3.21.4"
117117
},
118118
"devDependencies": {

packages/gpt-runner-shared/src/node/helpers/polyfill.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Headers, Request, Response, fetch } from 'undici'
2-
import { ReadableStream } from 'web-streams-polyfill'
2+
import 'web-streams-polyfill/polyfill'
33
import { canUseNodeFetchWithoutCliFlag } from './check-node-version'
44

55
export function addNodejsPolyfill() {
@@ -10,6 +10,5 @@ export function addNodejsPolyfill() {
1010
globalThis.Headers = Headers as any
1111
globalThis.Request = Request as any
1212
globalThis.Response = Response as any
13-
globalThis.ReadableStream = ReadableStream as any
1413
}
1514
}

packages/gpt-runner-web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"cross-env": "^7.0.3",
102102
"eventemitter": "^0.3.3",
103103
"express": "^4.18.2",
104-
"framer-motion": "^10.15.1",
104+
"framer-motion": "^10.15.2",
105105
"fs-extra": "^11.1.1",
106106
"global-agent": "^3.0.0",
107107
"i18next": "^23.4.4",
@@ -130,7 +130,7 @@
130130
"vite": "^4.4.9",
131131
"vite-plugin-monaco-editor": "^1.1.0",
132132
"vite-plugin-svgr": "^3.2.0",
133-
"web-streams-polyfill": "^3.2.1",
133+
"web-streams-polyfill": "^4.0.0-beta.3",
134134
"zustand": "^4.4.1"
135135
}
136136
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)