Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update undici to 4.0.0 #7931

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/packages/cli/helpers/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ async function main() {
path.join(require.resolve('open/package.json'), '../xdg-open'),
'./build/xdg-open',
),
copy({
from: path.resolve(__dirname, '../prisma-client/runtime/llhttp'),
to: './build/llhttp',
recursive: true,
parallelJobs: process.platform === 'win32' ? 1 : 20,
overwrite: true,
}),
])

await Promise.all([
Expand Down
22 changes: 18 additions & 4 deletions src/packages/client/helpers/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const execa = require('execa')
const fs = require('fs')
const fs = require('fs-extra')
const chalk = require('chalk')
const path = require('path')
const { promisify } = require('util')
const esbuild = require('esbuild')
const copyFile = promisify(fs.copyFile)
Expand Down Expand Up @@ -31,8 +32,15 @@ async function main() {
target: 'node12',
outfile: 'generator-build/index.js',
entryPoints: ['src/generator.ts'],
external: ['_http_common']
}),
// copy wasm files, etc necessary for undici
fs.copy(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar enough with esbuild. The problem is that undici uses path.resolve to establish a path to wasm files (https://github.com/nodejs/undici/blob/e705509ab22ab80aadf0fc1a394afff7dc014fdf/lib/client.js#L390-L398) and I wasn't able to find a plugin that could resolve that and copy files accordingly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't know what I'm doing myself.

path.resolve(
__dirname,
'../node_modules/@prisma/engine-core/node_modules/undici/lib/llhttp',
),
path.resolve(__dirname, '../generator-build/llhttp'),
),
])

await Promise.all([
Expand All @@ -42,7 +50,6 @@ async function main() {
target: 'node12',
outdir: 'runtime',
entryPoints: ['src/runtime/index.ts'],
external: ['_http_common']
}),
esbuild.build({
platform: 'node',
Expand All @@ -51,9 +58,16 @@ async function main() {
target: ['chrome58', 'firefox57', 'safari11', 'edge16'],
outdir: 'runtime',
entryPoints: ['src/runtime/index-browser.ts'],
external: ['_http_common']
}),
run('rollup -c'),
// copy wasm files, etc necessary for undici
fs.copy(
path.resolve(
__dirname,
'../node_modules/@prisma/engine-core/node_modules/undici/lib/llhttp',
),
path.resolve(__dirname, '../runtime/llhttp'),
),
])

await Promise.all([
Expand Down
1 change: 1 addition & 0 deletions src/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"eslint-plugin-prettier": "3.4.0",
"execa": "5.1.1",
"flat-map-polyfill": "0.3.8",
"fs-extra": "10.0.0",
"fs-monkey": "1.0.3",
"get-own-enumerable-property-symbols": "3.0.2",
"indent-string": "4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/packages/engine-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"new-github-issue-url": "^0.2.1",
"p-retry": "^4.2.0",
"terminal-link": "^2.1.1",
"undici": "3.3.6"
"undici": "^4.0.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why but pnpm also keeps the version 3.x.x which causes build of cli to fail if I remove _http_common from esbuild.external.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also experiencing errors when _http_common is removed from Webpack's externals

},
"files": [
"README.md",
Expand Down
10 changes: 7 additions & 3 deletions src/packages/engine-core/src/undici.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import getStream = require('get-stream')
import { Client, Pool } from 'undici'
import { Client, Dispatcher, Pool } from 'undici'
import { URL } from 'url'
export class Undici {
private pool: Pool
private closed = false
private url: string | URL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this one. unidici requires origin in Dispatcher.DispatchOptions even if it isn't required in their tests. I can remove this code and use type casting to Omit<Dispatcher.DispatchOptions, 'origin'> in this.pool.request() to fix that and get rid of this code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok and how exactly I'm on a phone

constructor(url: string | URL, moreArgs?: Pool.Options) {
this.url = url
this.pool = new Pool(url, {
connections: 100,
pipelining: 10,
keepAliveMaxTimeout: 600e3,
headersTimeout: 0,
bodyTimeout: 0,
...moreArgs,
})
}
request(
body: Client.DispatchOptions['body'],
body: Dispatcher.DispatchOptions['body'],
customHeaders?: Record<string, string>,
) {
return new Promise((resolve, reject) => {
this.pool.request(
{
origin: this.url,
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
...customHeaders,
},
body,
bodyTimeout: 0,
},
async (err, result) => {
if (err) {
Expand All @@ -45,6 +48,7 @@ export class Undici {
return new Promise((resolve, reject) => {
this.pool.request(
{
origin: this.url,
path: '/',
method: 'GET',
},
Expand Down