Skip to content

Commit

Permalink
chore: drop web streams polyfilling on globalThis
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Oct 19, 2023
1 parent a3aa659 commit fcf08e8
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 97 deletions.
1 change: 0 additions & 1 deletion packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
WorkerRenderOpts,
} from './types'

import '../server/node-polyfill-web-streams'
import '../server/node-environment'

process.env.NEXT_IS_EXPORT_WORKER = 'true'
Expand Down
23 changes: 2 additions & 21 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,8 @@ import type { AppRenderContext, GenerateFlight } from './app-render'

function nodeToWebReadableStream(nodeReadable: import('stream').Readable) {
if (process.env.NEXT_RUNTIME !== 'edge') {
const { Readable } = require('stream')
if ('toWeb' in Readable && typeof Readable.toWeb === 'function') {
return Readable.toWeb(nodeReadable)
}

const iterator = nodeReadable[Symbol.asyncIterator]()

return new ReadableStream({
pull: async (controller) => {
const { value, done } = await iterator.next()

if (done) {
controller.close()
} else {
controller.enqueue(value)
}
},
cancel: () => {
iterator.return?.()
},
})
const { Readable } = require('stream') as typeof import('stream')
return Readable.toWeb(nodeReadable)
} else {
throw new Error('Invalid runtime')
}
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/server/lib/incremental-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import FileSystemCache from './file-system-cache'
import path from '../../../shared/lib/isomorphic/path'
import { normalizePagePath } from '../../../shared/lib/page-path/normalize-page-path'

import '../../node-polyfill-web-streams'

import {
CACHE_ONE_YEAR,
NEXT_CACHE_REVALIDATED_TAGS_HEADER,
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/server/lib/router-utils/resolve-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import {
} from '../../../shared/lib/router/utils/prepare-destination'
import { createRequestResponseMocks } from '../mock-request'

import '../../node-polyfill-web-streams'

const debug = setupDebug('next:router-server:resolve-routes')

export function getResolveRoutes(
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './node-environment'
import './require-hook'
import './node-polyfill-form'
import './node-polyfill-web-streams'
import './node-polyfill-crypto'

import type { TLSSocket } from 'tls'
Expand Down
37 changes: 0 additions & 37 deletions packages/next/src/server/node-polyfill-web-streams.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next/src/server/pipe-readable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { ServerResponse } from 'node:http'

import './node-polyfill-web-streams'

import {
ResponseAbortedName,
createAbortController,
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ let postProcessHTML: typeof import('./post-process').postProcessHTML

const DOCTYPE = '<!DOCTYPE html>'

import './node-polyfill-web-streams'

if (process.env.NEXT_RUNTIME !== 'edge') {
tryGetPreviewData =
require('./api-utils/node/try-get-preview-data').tryGetPreviewData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { FlightRouterState } from '../app-render/types'

import '../node-polyfill-web-streams'

import { nonNullable } from '../../lib/non-nullable'
import { getTracer } from '../lib/trace/tracer'
import { AppRenderSpan } from '../lib/trace/constants'
Expand Down
21 changes: 0 additions & 21 deletions test/__mocks__/node-polyfill-web-streams.js

This file was deleted.

8 changes: 2 additions & 6 deletions test/lib/mocks-require-hook.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const mod = require('module')

const hookPropertyMap = new Map([
[
/node-polyfill-web-streams/,
require.resolve('../__mocks__/node-polyfill-web-streams.js'),
],
])
// REVIEW: is this necessary still?
const hookPropertyMap = new Map([[]])

function matchModule(request) {
for (const [key, value] of hookPropertyMap) {
Expand Down

0 comments on commit fcf08e8

Please sign in to comment.