Skip to content

Commit

Permalink
feat(remix-node)!: don't export fetch API (#7293)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Brophy <matt@brophy.org>
  • Loading branch information
MichaelDeBoey and brophdawg11 authored Sep 6, 2023
1 parent 2279d7e commit edffccb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 248 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-items-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/node": major
---

Stop exporting the `fetch` API in favor of using the version in the global scope - which is polyfilled via `installGlobals`
11 changes: 4 additions & 7 deletions packages/remix-architect/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import fsp from "node:fs/promises";
import path from "node:path";
import lambdaTester from "lambda-tester";
import type { APIGatewayProxyEventV2 } from "aws-lambda";
import {
createRequestHandler as createRemixRequestHandler,
Response as NodeResponse,
} from "@remix-run/node";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/node";

import {
createRequestHandler,
Expand Down Expand Up @@ -251,14 +248,14 @@ describe("architect createRemixRequest", () => {

describe("sendRemixResponse", () => {
it("handles regular responses", async () => {
let response = new NodeResponse("anything");
let response = new Response("anything");
let result = await sendRemixResponse(response);
expect(result.body).toBe("anything");
});

it("handles resource routes with regular data", async () => {
let json = JSON.stringify({ foo: "bar" });
let response = new NodeResponse(json, {
let response = new Response(json, {
headers: {
"Content-Type": "application/json",
"content-length": json.length.toString(),
Expand All @@ -273,7 +270,7 @@ describe("sendRemixResponse", () => {
it("handles resource routes with binary data", async () => {
let image = await fsp.readFile(path.join(__dirname, "554828.jpeg"));

let response = new NodeResponse(image, {
let response = new Response(image, {
headers: {
"content-type": "image/jpeg",
"content-length": image.length.toString(),
Expand Down
12 changes: 5 additions & 7 deletions packages/remix-express/__tests__/server-test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Readable } from "node:stream";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/node";
import express from "express";
import supertest from "supertest";
import { createRequest, createResponse } from "node-mocks-http";
import {
createRequestHandler as createRemixRequestHandler,
Response as NodeResponse,
} from "@remix-run/node";
import { Readable } from "node:stream";
import supertest from "supertest";

import {
createRemixHeaders,
Expand Down Expand Up @@ -103,7 +100,8 @@ describe("express createRequestHandler", () => {
it("handles body as stream", async () => {
mockedCreateRequestHandler.mockImplementation(() => async () => {
let stream = Readable.from("hello world");
return new NodeResponse(stream, { status: 200 }) as unknown as Response;
let webStream = Readable.toWeb(stream);
return new Response(webStream as ReadableStream, { status: 200 });
});

let request = supertest(createApp());
Expand Down
141 changes: 0 additions & 141 deletions packages/remix-node/__tests__/fetch-test.ts

This file was deleted.

75 changes: 0 additions & 75 deletions packages/remix-node/fetch.ts

This file was deleted.

18 changes: 8 additions & 10 deletions packages/remix-node/globals.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
fetch as nodeFetch,
FormData as NodeFormData,
Headers as NodeHeaders,
Request as NodeRequest,
Response as NodeResponse,
} from "@remix-run/web-fetch";
import { Blob as NodeBlob, File as NodeFile } from "@remix-run/web-file";
import {
ByteLengthQueuingStrategy as NodeByteLengthQueuingStrategy,
CountQueuingStrategy as NodeCountQueuingStrategy,
Expand All @@ -14,16 +22,6 @@ import {
WritableStreamDefaultWriter as NodeWritableStreamDefaultWriter,
} from "@remix-run/web-stream";

import {
Blob as NodeBlob,
File as NodeFile,
FormData as NodeFormData,
Headers as NodeHeaders,
Request as NodeRequest,
Response as NodeResponse,
fetch as nodeFetch,
} from "./fetch";

declare global {
namespace NodeJS {
interface ProcessEnv {
Expand Down
8 changes: 0 additions & 8 deletions packages/remix-node/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
export type {
HeadersInit,
RequestInfo,
RequestInit,
ResponseInit,
} from "./fetch";
export { fetch, FormData, Headers, Request, Response } from "./fetch";

export { installGlobals } from "./globals";

export { createFileSessionStorage } from "./sessions/fileStorage";
Expand Down

0 comments on commit edffccb

Please sign in to comment.