Skip to content

Commit

Permalink
refactor: move web stuff into their own folder
Browse files Browse the repository at this point in the history
Refs: #2732
  • Loading branch information
ronag committed Feb 21, 2024
1 parent 02107fe commit 3f70317
Show file tree
Hide file tree
Showing 77 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion benchmarks/cacheGetFieldValues.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench, group, run } from 'mitata'
import { getFieldValues } from '../lib/cache/util.js'
import { getFieldValues } from '../lib/web/cache/util.js'

const values = [
'',
Expand Down
16 changes: 8 additions & 8 deletions index-fetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fetchImpl = require('./lib/fetch').fetch
const fetchImpl = require('./lib/web/fetch').fetch

module.exports.fetch = function fetch (resource, init = undefined) {
return fetchImpl(resource, init).catch((err) => {
Expand All @@ -10,12 +10,12 @@ module.exports.fetch = function fetch (resource, init = undefined) {
throw err
})
}
module.exports.FormData = require('./lib/fetch/formdata').FormData
module.exports.Headers = require('./lib/fetch/headers').Headers
module.exports.Response = require('./lib/fetch/response').Response
module.exports.Request = require('./lib/fetch/request').Request
module.exports.FormData = require('./lib/web/fetch/formdata').FormData
module.exports.Headers = require('./lib/web/fetch/headers').Headers
module.exports.Response = require('./lib/web/fetch/response').Response
module.exports.Request = require('./lib/web/fetch/request').Request

module.exports.WebSocket = require('./lib/websocket/websocket').WebSocket
module.exports.MessageEvent = require('./lib/websocket/events').MessageEvent
module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
module.exports.MessageEvent = require('./lib/web/websocket/events').MessageEvent

module.exports.EventSource = require('./lib/eventsource/eventsource').EventSource
module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource
30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function makeDispatcher (fn) {
module.exports.setGlobalDispatcher = setGlobalDispatcher
module.exports.getGlobalDispatcher = getGlobalDispatcher

const fetchImpl = require('./lib/fetch').fetch
const fetchImpl = require('./lib/web/fetch').fetch
module.exports.fetch = async function fetch (init, options = undefined) {
try {
return await fetchImpl(init, options)
Expand All @@ -106,39 +106,39 @@ module.exports.fetch = async function fetch (init, options = undefined) {
throw err
}
}
module.exports.Headers = require('./lib/fetch/headers').Headers
module.exports.Response = require('./lib/fetch/response').Response
module.exports.Request = require('./lib/fetch/request').Request
module.exports.FormData = require('./lib/fetch/formdata').FormData
module.exports.File = require('./lib/fetch/file').File
module.exports.FileReader = require('./lib/fileapi/filereader').FileReader
module.exports.Headers = require('./lib/web/fetch/headers').Headers
module.exports.Response = require('./lib/web/fetch/response').Response
module.exports.Request = require('./lib/web/fetch/request').Request
module.exports.FormData = require('./lib/web/fetch/formdata').FormData
module.exports.File = require('./lib/web/fetch/file').File
module.exports.FileReader = require('./lib/web/fileapi/filereader').FileReader

const { setGlobalOrigin, getGlobalOrigin } = require('./lib/fetch/global')
const { setGlobalOrigin, getGlobalOrigin } = require('./lib/web/fetch/global')

module.exports.setGlobalOrigin = setGlobalOrigin
module.exports.getGlobalOrigin = getGlobalOrigin

const { CacheStorage } = require('./lib/cache/cachestorage')
const { kConstruct } = require('./lib/cache/symbols')
const { CacheStorage } = require('./lib/web/cache/cachestorage')
const { kConstruct } = require('./lib/web/cache/symbols')

// Cache & CacheStorage are tightly coupled with fetch. Even if it may run
// in an older version of Node, it doesn't have any use without fetch.
module.exports.caches = new CacheStorage(kConstruct)

const { deleteCookie, getCookies, getSetCookies, setCookie } = require('./lib/cookies')
const { deleteCookie, getCookies, getSetCookies, setCookie } = require('./lib/web/cookies')

module.exports.deleteCookie = deleteCookie
module.exports.getCookies = getCookies
module.exports.getSetCookies = getSetCookies
module.exports.setCookie = setCookie

const { parseMIMEType, serializeAMimeType } = require('./lib/fetch/dataURL')
const { parseMIMEType, serializeAMimeType } = require('./lib/web/fetch/dataURL')

module.exports.parseMIMEType = parseMIMEType
module.exports.serializeAMimeType = serializeAMimeType

const { CloseEvent, ErrorEvent, MessageEvent } = require('./lib/websocket/events')
module.exports.WebSocket = require('./lib/websocket/websocket').WebSocket
const { CloseEvent, ErrorEvent, MessageEvent } = require('./lib/web/websocket/events')
module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
module.exports.CloseEvent = CloseEvent
module.exports.ErrorEvent = ErrorEvent
module.exports.MessageEvent = MessageEvent
Expand All @@ -154,6 +154,6 @@ module.exports.MockPool = MockPool
module.exports.MockAgent = MockAgent
module.exports.mockErrors = mockErrors

const { EventSource } = require('./lib/eventsource/eventsource')
const { EventSource } = require('./lib/web/eventsource/eventsource')

module.exports.EventSource = EventSource
5 changes: 0 additions & 5 deletions lib/cache/symbols.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ function write (client, request) {

if (util.isFormDataLike(body)) {
if (!extractBody) {
extractBody = require('./fetch/body.js').extractBody
extractBody = require('./web/fetch/body.js').extractBody
}

const [bodyStream, contentType] = extractBody(body)
Expand Down
2 changes: 1 addition & 1 deletion lib/mock/mock-interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MockInterceptor {
if (opts.query) {
opts.path = buildURL(opts.path, opts.query)
} else {
// Matches https://github.com/nodejs/undici/blob/main/lib/fetch/index.js#L1811
// Matches https://github.com/nodejs/undici/blob/main/lib/web/fetch/index.js#L1811
const parsedURL = new URL(opts.path, 'data://')
opts.path = parsedURL.pathname + parsedURL.search
}
Expand Down
4 changes: 2 additions & 2 deletions lib/cache/cache.js → lib/web/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

const { kConstruct } = require('./symbols')
const { urlEquals, getFieldValues } = require('./util')
const { kEnumerableProperty, isDisturbed } = require('../core/util')
const { kEnumerableProperty, isDisturbed } = require('../../core/util')
const { webidl } = require('../fetch/webidl')
const { Response, cloneResponse, fromInnerResponse } = require('../fetch/response')
const { Request, fromInnerRequest } = require('../fetch/request')
const { kState } = require('../fetch/symbols')
const { fetching } = require('../fetch/index')
const { urlIsHttpHttpsScheme, createDeferredPromise, readAllBytes } = require('../fetch/util')
const assert = require('node:assert')
const { getGlobalDispatcher } = require('../global')
const { getGlobalDispatcher } = require('../../global')

/**
* @see https://w3c.github.io/ServiceWorker/#dfn-cache-batch-operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { kConstruct } = require('./symbols')
const { Cache } = require('./cache')
const { webidl } = require('../fetch/webidl')
const { kEnumerableProperty } = require('../core/util')
const { kEnumerableProperty } = require('../../core/util')

class CacheStorage {
/**
Expand Down
5 changes: 5 additions & 0 deletions lib/web/cache/symbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

module.exports = {
kConstruct: require('../../core/symbols').kConstruct
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/cookies/util.js → lib/web/cookies/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const assert = require('node:assert')
const { kHeadersList } = require('../core/symbols')
const { kHeadersList } = require('../../core/symbols')

function isCTLExcludingHtab (value) {
if (value.length === 0) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { EventSourceStream } = require('./eventsource-stream')
const { parseMIMEType } = require('../fetch/dataURL')
const { MessageEvent } = require('../websocket/events')
const { isNetworkError } = require('../fetch/response')
const { getGlobalDispatcher } = require('../global')
const { getGlobalDispatcher } = require('../../global')
const { delay } = require('./util')

let experimentalWarned = false
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/fetch/body.js → lib/web/fetch/body.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Busboy = require('@fastify/busboy')
const util = require('../core/util')
const util = require('../../core/util')
const {
ReadableStreamFrom,
isBlobLike,
Expand All @@ -16,7 +16,7 @@ const { kState } = require('./symbols')
const { webidl } = require('./webidl')
const { Blob, File: NativeFile } = require('node:buffer')
const assert = require('node:assert')
const { isErrored } = require('../core/util')
const { isErrored } = require('../../core/util')
const { isArrayBuffer } = require('node:util/types')
const { File: UndiciFile } = require('./file')
const { serializeAMimeType } = require('./dataURL')
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { kConnected, kSize } = require('../core/symbols')
const { kConnected, kSize } = require('../../core/symbols')

class CompatWeakRef {
constructor (value) {
Expand Down
2 changes: 1 addition & 1 deletion lib/fetch/file.js → lib/web/fetch/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { kState } = require('./symbols')
const { isBlobLike } = require('./util')
const { webidl } = require('./webidl')
const { parseMIMEType, serializeAMimeType } = require('./dataURL')
const { kEnumerableProperty } = require('../core/util')
const { kEnumerableProperty } = require('../../core/util')
const encoder = new TextEncoder()

class File extends Blob {
Expand Down
2 changes: 1 addition & 1 deletion lib/fetch/formdata.js → lib/web/fetch/formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { isBlobLike, iteratorMixin } = require('./util')
const { kState } = require('./symbols')
const { kEnumerableProperty } = require('../core/util')
const { kEnumerableProperty } = require('../../core/util')
const { File: UndiciFile, FileLike, isFileLike } = require('./file')
const { webidl } = require('./webidl')
const { File: NativeFile } = require('node:buffer')
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/fetch/headers.js → lib/web/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

'use strict'

const { kHeadersList, kConstruct } = require('../core/symbols')
const { kHeadersList, kConstruct } = require('../../core/symbols')
const { kGuard } = require('./symbols')
const { kEnumerableProperty } = require('../core/util')
const { kEnumerableProperty } = require('../../core/util')
const {
iteratorMixin,
isValidHeaderName,
Expand Down
4 changes: 2 additions & 2 deletions lib/fetch/index.js → lib/web/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const {
} = require('./constants')
const EE = require('node:events')
const { Readable, pipeline } = require('node:stream')
const { addAbortListener, isErrored, isReadable, nodeMajor, nodeMinor, bufferToLowerCasedHeaderName } = require('../core/util')
const { addAbortListener, isErrored, isReadable, nodeMajor, nodeMinor, bufferToLowerCasedHeaderName } = require('../../core/util')
const { dataURLProcessor, serializeAMimeType, minimizeSupportedMimeType } = require('./dataURL')
const { getGlobalDispatcher } = require('../global')
const { getGlobalDispatcher } = require('../../global')
const { webidl } = require('./webidl')
const { STATUS_CODES } = require('node:http')
const GET_OR_HEAD = ['GET', 'HEAD']
Expand Down
6 changes: 3 additions & 3 deletions lib/fetch/request.js → lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

const { extractBody, mixinBody, cloneBody } = require('./body')
const { Headers, fill: fillHeaders, HeadersList } = require('./headers')
const { FinalizationRegistry } = require('../compat/dispatcher-weakref')()
const util = require('../core/util')
const { FinalizationRegistry } = require('./dispatcher-weakref')()
const util = require('../../core/util')
const {
isValidHTTPToken,
sameOrigin,
Expand All @@ -28,7 +28,7 @@ const { kHeaders, kSignal, kState, kGuard, kRealm } = require('./symbols')
const { webidl } = require('./webidl')
const { getGlobalOrigin } = require('./global')
const { URLSerializer } = require('./dataURL')
const { kHeadersList, kConstruct } = require('../core/symbols')
const { kHeadersList, kConstruct } = require('../../core/symbols')
const assert = require('node:assert')
const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners } = require('node:events')

Expand Down
4 changes: 2 additions & 2 deletions lib/fetch/response.js → lib/web/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { Headers, HeadersList, fill } = require('./headers')
const { extractBody, cloneBody, mixinBody } = require('./body')
const util = require('../core/util')
const util = require('../../core/util')
const { kEnumerableProperty } = util
const {
isValidReasonPhrase,
Expand All @@ -22,7 +22,7 @@ const { webidl } = require('./webidl')
const { FormData } = require('./formdata')
const { getGlobalOrigin } = require('./global')
const { URLSerializer } = require('./dataURL')
const { kHeadersList, kConstruct } = require('../core/symbols')
const { kHeadersList, kConstruct } = require('../../core/symbols')
const assert = require('node:assert')
const { types } = require('node:util')

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/fetch/util.js → lib/web/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { redirectStatusSet, referrerPolicySet: referrerPolicyTokens, badPortsSet
const { getGlobalOrigin } = require('./global')
const { collectASequenceOfCodePoints, collectAnHTTPQuotedString, removeChars, parseMIMEType } = require('./dataURL')
const { performance } = require('node:perf_hooks')
const { isBlobLike, ReadableStreamFrom, isValidHTTPToken } = require('../core/util')
const { isBlobLike, ReadableStreamFrom, isValidHTTPToken } = require('../../core/util')
const assert = require('node:assert')
const { isUint8Array } = require('node:util/types')
const { webidl } = require('./webidl')
Expand Down
2 changes: 1 addition & 1 deletion lib/fetch/webidl.js → lib/web/fetch/webidl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { types } = require('node:util')
const { toUSVString } = require('../core/util')
const { toUSVString } = require('../../core/util')

/** @type {import('../../types/webidl').Webidl} */
const webidl = {}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
kAborted
} = require('./symbols')
const { webidl } = require('../fetch/webidl')
const { kEnumerableProperty } = require('../core/util')
const { kEnumerableProperty } = require('../../core/util')

class FileReader extends EventTarget {
constructor () {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const {
kReceivedClose
} = require('./symbols')
const { fireEvent, failWebsocketConnection } = require('./util')
const { channels } = require('../core/diagnostics')
const { channels } = require('../../core/diagnostics')
const { CloseEvent } = require('./events')
const { makeRequest } = require('../fetch/request')
const { fetching } = require('../fetch/index')
const { Headers } = require('../fetch/headers')
const { getGlobalDispatcher } = require('../global')
const { kHeadersList } = require('../core/symbols')
const { getGlobalDispatcher } = require('../../global')
const { kHeadersList } = require('../../core/symbols')

/** @type {import('crypto')} */
let crypto
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/websocket/events.js → lib/web/websocket/events.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { webidl } = require('../fetch/webidl')
const { kEnumerableProperty } = require('../core/util')
const { kEnumerableProperty } = require('../../core/util')
const { MessagePort } = require('node:worker_threads')

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { Writable } = require('node:stream')
const { parserStates, opcodes, states, emptyBuffer } = require('./constants')
const { kReadyState, kSentClose, kResponse, kReceivedClose } = require('./symbols')
const { channels } = require('../core/diagnostics')
const { channels } = require('../../core/diagnostics')
const { isValidStatusCode, failWebsocketConnection, websocketMessageReceived } = require('./util')
const { WebsocketFrameSend } = require('./frame')

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/websocket/websocket.js → lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const { isEstablished, isClosing, isValidSubprotocol, failWebsocketConnection, f
const { establishWebSocketConnection } = require('./connection')
const { WebsocketFrameSend } = require('./frame')
const { ByteParser } = require('./receiver')
const { kEnumerableProperty, isBlobLike } = require('../core/util')
const { getGlobalDispatcher } = require('../global')
const { kEnumerableProperty, isBlobLike } = require('../../core/util')
const { getGlobalDispatcher } = require('../../global')
const { types } = require('node:util')

let experimentalWarned = false
Expand Down
2 changes: 1 addition & 1 deletion test/cache/get-field-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { deepStrictEqual, throws } = require('node:assert')
const { test } = require('node:test')
const { getFieldValues } = require('../../lib/cache/util')
const { getFieldValues } = require('../../lib/web/cache/util')

test('getFieldValues', () => {
throws(() => getFieldValues(null), {
Expand Down
2 changes: 1 addition & 1 deletion test/cookie/global-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
getSetCookies,
setCookie
} = require('../..')
const { getHeadersList } = require('../../lib/cookies/util')
const { getHeadersList } = require('../../lib/web/cookies/util')

describe('Using global Headers', async () => {
test('deleteCookies', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/eventsource/eventsource-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('node:assert')
const events = require('node:events')
const http = require('node:http')
const { test, describe } = require('node:test')
const { EventSource } = require('../../lib/eventsource/eventsource')
const { EventSource } = require('../../lib/web/eventsource/eventsource')

describe('EventSource - eventhandler idl', async () => {
const server = http.createServer((req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion test/eventsource/eventsource-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const events = require('node:events')
const http = require('node:http')
const { setTimeout } = require('node:timers/promises')
const { test, describe } = require('node:test')
const { EventSource } = require('../../lib/eventsource/eventsource')
const { EventSource } = require('../../lib/web/eventsource/eventsource')

describe('EventSource - close', () => {
test('should not emit error when closing the EventSource Instance', async () => {
Expand Down
Loading

0 comments on commit 3f70317

Please sign in to comment.