Skip to content

Commit

Permalink
fix(gpt-runner-cli): fix readable stream polyfill not working in node…
Browse files Browse the repository at this point in the history
…js 18+
  • Loading branch information
2214962083 committed Aug 15, 2023
1 parent a2329de commit b1b3052
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
37 changes: 22 additions & 15 deletions packages/gpt-runner-cli/src/cli-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ export async function startCli(cwd = PathUtils.resolve(process.cwd()), argv = pr
autoFreePort: true,
})

const startServerProcessPromise = execa('node', [startServerJsPath, '--port', String(finalPort)], {
env: {
...process.env,
...getRunServerEnv(),
GPTR_ONLY_LOAD_CONFIG_PATH: options.config || '',
},
})

startServerProcessPromise.on('error', (error) => {
try {
await execa('node', [startServerJsPath, '--port', String(finalPort)], {
env: {
...process.env,
...getRunServerEnv(),
GPTR_ONLY_LOAD_CONFIG_PATH: options.config || '',
},
stdio: 'inherit',
})?.pipeStdout?.(process.stdout)?.pipeStderr?.(process.stderr)
}
catch (error) {
consola.error(error)
})
}

const afterServerStartSuccess = async () => {
const getUrl = (isLocalIp = false) => {
Expand Down Expand Up @@ -101,12 +103,17 @@ export async function startCli(cwd = PathUtils.resolve(process.cwd()), argv = pr
}
}

waitPort({
port: finalPort,
output: 'silent',
}).then(afterServerStartSuccess).catch(consola.error)
try {
await waitPort({
port: finalPort,
output: 'silent',
})

await startServerProcessPromise
afterServerStartSuccess()
}
catch (error) {
consola.error(error)
}
})

cli.help()
Expand Down
4 changes: 2 additions & 2 deletions packages/gpt-runner-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.2",
"undici": "^5.23.0",
"web-streams-polyfill": "^3.2.1",
"zod": "^3.21.4",
"web-streams-polyfill": "^4.0.0-beta.3",
"zod": "^3.22.0",
"zod-to-json-schema": "^3.21.4"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/gpt-runner-shared/src/node/helpers/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Headers, Request, Response, fetch } from 'undici'
import { ReadableStream } from 'web-streams-polyfill'
import 'web-streams-polyfill/polyfill'
import { canUseNodeFetchWithoutCliFlag } from './check-node-version'

export function addNodejsPolyfill() {
Expand All @@ -10,6 +10,5 @@ export function addNodejsPolyfill() {
globalThis.Headers = Headers as any
globalThis.Request = Request as any
globalThis.Response = Response as any
globalThis.ReadableStream = ReadableStream as any
}
}
4 changes: 2 additions & 2 deletions packages/gpt-runner-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"cross-env": "^7.0.3",
"eventemitter": "^0.3.3",
"express": "^4.18.2",
"framer-motion": "^10.15.1",
"framer-motion": "^10.15.2",
"fs-extra": "^11.1.1",
"global-agent": "^3.0.0",
"i18next": "^23.4.4",
Expand Down Expand Up @@ -130,7 +130,7 @@
"vite": "^4.4.9",
"vite-plugin-monaco-editor": "^1.1.0",
"vite-plugin-svgr": "^3.2.0",
"web-streams-polyfill": "^3.2.1",
"web-streams-polyfill": "^4.0.0-beta.3",
"zustand": "^4.4.1"
}
}
38 changes: 23 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1b3052

Please sign in to comment.