Unverified Commit 9e59ff0a authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Update vendored `@mswjs/interceptors` to 0.41.9 (#96059)

The previous `@mswjs/interceptors` has a bug where the response it
forwarded never set the [`complete`
field](https://nodejs.org/api/http.html#messagecomplete). This wasn't an
issue so far (or not reported) but is an issue for `httpxy` which relies
on an accurate `complete` field.

Bumping `@mswjs/interceptor` now so that we can switch from `http-proxy`
to `httpxy`.
parent 3cd6d4dd
......@@ -299,6 +299,13 @@ impl ServerNftJsonAsset {
"**/next/dist/compiled/webpack/*",
"**/node_modules/webpack5/**/*",
"**/next/dist/server/lib/route-resolver*",
// The testmode interceptors bundle reads its HTTP parser WASM with a
// dynamic path, making the tracer include the bundle's whole
// directory. Test proxying is not supported in standalone output, so
// keep the parser asset (and the license file picked up by the
// directory glob) out of production traces.
"**/next/dist/compiled/@mswjs/interceptors/ClientRequest/LICENSE",
"**/next/dist/compiled/@mswjs/interceptors/ClientRequest/llhttp/**",
"**/next/dist/compiled/semver/semver/**/*.js",
"**/next/dist/compiled/jest-worker/**/*",
// -- The following were added for Turbopack specifically --
......
......@@ -162,7 +162,7 @@
"@jest/transform": "29.5.0",
"@jest/types": "29.5.0",
"@modelcontextprotocol/sdk": "1.18.1",
"@mswjs/interceptors": "0.23.0",
"@mswjs/interceptors": "0.42.0",
"@napi-rs/triples": "1.2.0",
"@next/font": "16.3.0-canary.97",
"@next/polyfill-module": "16.3.0-canary.97",
......
......@@ -226,6 +226,13 @@ export async function collectBuildTraces({
'**/next/dist/compiled/webpack/*',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/route-resolver*',
// The testmode interceptors bundle reads its HTTP parser WASM with a
// dynamic path, making nft trace the bundle's whole directory. Test
// proxying is not supported in standalone output, so keep the parser
// asset (and the license file picked up by the directory glob) out of
// production traces.
'**/next/dist/compiled/@mswjs/interceptors/ClientRequest/LICENSE',
'**/next/dist/compiled/@mswjs/interceptors/ClientRequest/llhttp/**/*',
'next/dist/compiled/semver/semver/**/*.js',
...(ciEnvironment.hasNextSupport
......
// @mswjs/interceptors uses `Promise.withResolvers`, which is only available
// since Node.js 22 while Next.js still supports Node.js 20.
if (typeof Promise.withResolvers !== 'function') {
Promise.withResolvers = function withResolvers() {
let resolve
let reject
const promise = new Promise((res, rej) => {
resolve = res
reject = rej
})
return { promise, resolve, reject }
}
}
// @mswjs/interceptors only ships ESM entry points. Re-export it through this
// CJS entry so ncc emits a CommonJS bundle that can be `require()`d.
module.exports = require('@mswjs/interceptors/ClientRequest')
......@@ -98,6 +98,14 @@ export async function handleFetch(
const resp = await originalFetch(`http://localhost:${proxyPort}`, {
method: 'POST',
body: JSON.stringify(proxyRequest),
// The header lets the ClientRequest interception in `httpget.ts` identify
// this request as part of the test proxy protocol. @mswjs/interceptors
// intercepts at the TCP level, so this request would otherwise be
// intercepted again when it's sent from within an interception listener,
// recursing indefinitely.
headers: {
'next-test-internal': '1',
},
next: {
// @ts-ignore
internal: true,
......
......@@ -5,9 +5,16 @@ type Fetch = typeof fetch
export function interceptHttpGet(originalFetch: Fetch): () => void {
const clientRequestInterceptor = new ClientRequestInterceptor()
clientRequestInterceptor.on('request', async ({ request }) => {
clientRequestInterceptor.on('request', async ({ request, controller }) => {
if (request.headers.get('next-test-internal') === '1') {
// A request that's part of the test proxy protocol itself, sent by
// `handleFetch` from within this listener. Not responding lets the
// interceptor perform it against the real server. Handling it here
// instead would recurse indefinitely.
return
}
const response = await handleFetch(originalFetch, request)
request.respondWith(response)
controller.respondWith(response)
})
clientRequestInterceptor.apply()
......
......@@ -21,13 +21,26 @@ const reader: TestRequestReader<IncomingMessage> = {
},
}
const interceptedSymbol = Symbol.for('next.testmode.intercepted')
export function interceptTestApis(): () => void {
// In development the render server runs in the same process as the router
// server, so both call this function. @mswjs/interceptors throws when its
// global replacements are applied a second time, so make repeated
// interception within the same process a no-op.
const globalState = globalThis as { [interceptedSymbol]?: boolean }
if (globalState[interceptedSymbol] === true) {
return () => {}
}
globalState[interceptedSymbol] = true
const originalFetch = global.fetch
const restoreFetch = interceptFetch(originalFetch)
const restoreHttpGet = interceptHttpGet(originalFetch)
// Cleanup.
return () => {
globalState[interceptedSymbol] = false
restoreFetch()
restoreHttpGet()
}
......
......@@ -147,15 +147,29 @@ externals['@mswjs/interceptors/ClientRequest'] =
'next/dist/compiled/@mswjs/interceptors/ClientRequest'
export async function ncc_mswjs_interceptors(task, opts) {
await task
.source(
relative(__dirname, require.resolve('@mswjs/interceptors/ClientRequest'))
)
// @mswjs/interceptors is ESM-only, compile to CJS through a stub entry
.source('src/bundles/mswjs-interceptors/index.js')
.ncc({
packageName: '@mswjs/interceptors/ClientRequest',
externals,
target: 'es5',
esm: false,
})
.target('src/compiled/@mswjs/interceptors/ClientRequest')
// The interceptor reads its HTTP parser WASM at runtime relative to the
// bundle. ncc cannot trace that file access, so copy the file explicitly.
const llhttpWasmTarget = join(
__dirname,
'src/compiled/@mswjs/interceptors/ClientRequest/llhttp'
)
await fs.mkdir(llhttpWasmTarget, { recursive: true })
await fs.copyFile(
join(
dirname(require.resolve('@mswjs/interceptors/ClientRequest')),
'../../llhttp/llhttp.wasm'
),
join(llhttpWasmTarget, 'llhttp.wasm')
)
}
export async function capsize_metrics() {
......
......@@ -1178,8 +1178,8 @@ importers:
specifier: 1.18.1
version: 1.18.1(patch_hash=680fe4edb7abd1de29d08cdf217a22506e815a8cc1c2282201d5d47aa3e5da12)
'@mswjs/interceptors':
specifier: 0.23.0
version: 0.23.0
specifier: 0.42.0
version: 0.42.0
'@napi-rs/triples':
specifier: 1.2.0
version: 1.2.0
......@@ -4478,14 +4478,14 @@ packages:
resolution: {integrity: sha512-0ZcCVQxifZmhwNBoQIrystCb+2sWBY2Zw8lpfJBPCHGCA/HWqehITeCRVIv4VMy8MPlaHo2w2pTHFV2pFfqKPw==}
engines: {node: '>=18'}
'@mswjs/interceptors@0.23.0':
resolution: {integrity: sha512-JytvDa7pBbxXvCTXBYQs+0eE6MqxpqH/H4peRNY6zVAlvJ6d/hAWLHAef1D9lWN4zuIigN0VkakGOAUrX7FWLg==}
engines: {node: '>=18'}
'@mswjs/interceptors@0.29.1':
resolution: {integrity: sha512-3rDakgJZ77+RiQUuSK69t1F0m8BQKA8Vh5DCS5V0DWvNY67zob2JhhQrhCO0AKLGINTRSFd1tBaHcJTkhefoSw==}
engines: {node: '>=18'}
'@mswjs/interceptors@0.42.0':
resolution: {integrity: sha512-HFjFa93wzY++HEC50SpTRMGCAlzA2y71a0H2io3vysc/QYQ0PJVrJuo3CXKcVPe5mOxT7FMwKBNuCouAoIeLxQ==}
engines: {node: '>=22'}
'@napi-rs/cli@2.18.4':
resolution: {integrity: sha512-SgJeA4df9DE2iAEpr3M2H0OKl/yjtg1BnRI5/JyowS71tUWhrfSu2LT0V3vlHET+g1hBVlrO60PmEXwUEKp8Mg==}
engines: {node: '>= 10'}
......@@ -4981,9 +4981,6 @@ packages:
resolution: {integrity: sha512-8iG+/yza7hwz1RrQ7i7uGpK2/tuItZxZq1aTmeg2TNp2xTUB8F8lZF/FcZvyyAxT8tpDMF74TjFGCDACkf1kAQ==}
engines: {node: '>= 18'}
'@open-draft/deferred-promise@2.1.0':
resolution: {integrity: sha512-Rzd5JrXZX8zErHzgcGyngh4fmEbSHqTETdGj9rXtejlqMIgXFlyKBA7Jn1Xp0Ls0M0Y22+xHcWiEzbmdWl0BOA==}
'@open-draft/deferred-promise@2.2.0':
resolution: {integrity: sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==}
......@@ -4993,6 +4990,9 @@ packages:
'@open-draft/until@2.1.0':
resolution: {integrity: sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==}
'@open-draft/until@3.0.1':
resolution: {integrity: sha512-s7/9ELP4aP9YZtW7RJaa0Xf3RISaRH9+EFN18FtykJYRHGNrl8f9ymvoNXzjhrjmftFvkQudtuDU9RYhk0xs3A==}
'@opentelemetry/api@1.4.1':
resolution: {integrity: sha512-O2yRJce1GOc6PAy3QxFM4NzFiWzvScDC1/5ihYBL6BUEVdq0XMWN01sppE+H6bBXbaFYipjwFLEWLg5PaSOThA==}
engines: {node: '>=8.0.0'}
......@@ -6616,6 +6616,9 @@ packages:
'@types/d3-time@3.0.3':
resolution: {integrity: sha512-2p6olUZ4w3s+07q3Tm2dbiMZy5pCDfYwtLXXHUnVzXgQlZ/OyPtUz6OL382BkOuGlLXqfT+wqv8Fw2v8/0geBw==}
'@types/debug@4.1.13':
resolution: {integrity: sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw==}
'@types/debug@4.1.5':
resolution: {integrity: sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==}
......@@ -6776,6 +6779,9 @@ packages:
'@types/minimist@1.2.5':
resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==}
'@types/ms@2.1.0':
resolution: {integrity: sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==}
'@types/mute-stream@0.0.4':
resolution: {integrity: sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==}
......@@ -11078,9 +11084,6 @@ packages:
header-case@2.0.4:
resolution: {integrity: sha512-H/vuk5TEEVZwrR0lp2zed9OCo1uAILMlx0JEMgC26rzyJJ3N1v6XkwHHXJQdR2doSjcGPM6OKPYoJgf0plJ11Q==}
headers-polyfill@3.1.2:
resolution: {integrity: sha512-tWCK4biJ6hcLqTviLXVR9DTRfYGQMXEIUj3gwJ2rZ5wO/at3XtkI4g8mCvFdUF9l1KMBNCfmNAdnahm1cgavQA==}
headers-polyfill@4.0.3:
resolution: {integrity: sha512-IScLbePpkvO846sIwOtOTDjutRMWdXdJmXdMvk6gCBHxFO8d+QKOQedyZSxFTTFYRSmlgSTDtXqqq4pcenBXLQ==}
......@@ -14062,12 +14065,12 @@ packages:
outdent@0.8.0:
resolution: {integrity: sha512-KiOAIsdpUTcAXuykya5fnVVT+/5uS0Q1mrkRHcF89tpieSmY33O/tmc54CqwA+bfhbtEfZUNLHaPUiB9X3jt1A==}
outvariant@1.4.0:
resolution: {integrity: sha512-AlWY719RF02ujitly7Kk/0QlV+pXGFDHrHf9O2OKqyqgBieaPOIeuSkL8sRK6j2WK+/ZAURq2kZsY0d8JapUiw==}
outvariant@1.4.2:
resolution: {integrity: sha512-Ou3dJ6bA/UJ5GVHxah4LnqDwZRwAmWxrG3wtrHrbGnP4RnLCtA64A4F+ae7Y8ww660JaddSoArUR5HjipWSHAQ==}
outvariant@1.4.3:
resolution: {integrity: sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA==}
own-keys@1.0.1:
resolution: {integrity: sha512-qFOyK5PjiWZd+QQIh+1jhdb9LpxTF0qs7Pm8o5QHYZ0M3vKqSqzsZaEB6oWlxZ+q2sJBMI/Ktgd2N5ZwQoRHfg==}
engines: {node: '>= 0.4'}
......@@ -15944,6 +15947,9 @@ packages:
resolution: {integrity: sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==}
engines: {node: '>= 4'}
rettime@0.11.11:
resolution: {integrity: sha512-ILJRqVWBCTlg9r42fFgwVZx1gnFAcQF8mRoMkbgQfIrjEDf9nbBFDFx00oloOa+Q869FUtaYDXZvEfnecQSCoQ==}
reusify@1.0.4:
resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==}
engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
......@@ -21148,15 +21154,6 @@ snapshots:
'@mswjs/cookies@1.1.0': {}
'@mswjs/interceptors@0.23.0':
dependencies:
'@open-draft/deferred-promise': 2.1.0
'@open-draft/logger': 0.3.0
'@open-draft/until': 2.1.0
headers-polyfill: 3.1.2
outvariant: 1.4.0
strict-event-emitter: 0.5.0
'@mswjs/interceptors@0.29.1':
dependencies:
'@open-draft/deferred-promise': 2.2.0
......@@ -21166,6 +21163,17 @@ snapshots:
outvariant: 1.4.2
strict-event-emitter: 0.5.1
'@mswjs/interceptors@0.42.0':
dependencies:
'@open-draft/until': 3.0.1
'@types/debug': 4.1.13
debug: 4.4.3
is-node-process: 1.2.0
outvariant: 1.4.3
rettime: 0.11.11
transitivePeerDependencies:
- supports-color
'@napi-rs/cli@2.18.4': {}
'@napi-rs/triples@1.2.0': {}
......@@ -21770,17 +21778,17 @@ snapshots:
'@octokit/webhooks-types': 7.1.0
aggregate-error: 3.1.0
'@open-draft/deferred-promise@2.1.0': {}
'@open-draft/deferred-promise@2.2.0': {}
'@open-draft/logger@0.3.0':
dependencies:
is-node-process: 1.2.0
outvariant: 1.4.0
outvariant: 1.4.3
'@open-draft/until@2.1.0': {}
'@open-draft/until@3.0.1': {}
'@opentelemetry/api@1.4.1': {}
'@opentelemetry/api@1.6.0': {}
......@@ -23407,6 +23415,10 @@ snapshots:
'@types/d3-time@3.0.3': {}
'@types/debug@4.1.13':
dependencies:
'@types/ms': 2.1.0
'@types/debug@4.1.5': {}
'@types/doctrine@0.0.9': {}
......@@ -23593,6 +23605,8 @@ snapshots:
'@types/minimist@1.2.5': {}
'@types/ms@2.1.0': {}
'@types/mute-stream@0.0.4':
dependencies:
'@types/node': 20.17.6(patch_hash=9c31d25336aea4076b3cb942c35e59fd160c540947f01ea455a060367153f9fd)
......@@ -28955,8 +28969,6 @@ snapshots:
capital-case: 1.0.4
tslib: 2.8.1
headers-polyfill@3.1.2: {}
headers-polyfill@4.0.3: {}
hermes-estree@0.25.1: {}
......@@ -32990,10 +33002,10 @@ snapshots:
outdent@0.8.0: {}
outvariant@1.4.0: {}
outvariant@1.4.2: {}
outvariant@1.4.3: {}
own-keys@1.0.1:
dependencies:
get-intrinsic: 1.3.0
......@@ -35080,6 +35092,8 @@ snapshots:
retry@0.13.1: {}
rettime@0.11.11: {}
reusify@1.0.4: {}
rewrite-imports@1.4.0: {}
......@@ -37,6 +37,7 @@ ignoredBuiltDependencies:
blockExoticSubdeps: true
minimumReleaseAge: 2880 # 48 hrs
minimumReleaseAgeExclude:
- '@mswjs/interceptors@0.42.0'
- '@next/*'
- '@turbo/*'
- '@vercel/*'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment