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

feat: remove references to fetch polyfills #114

Closed
wants to merge 9 commits into from
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-wombats-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mcansh/remix-fastify": minor
---

remove references to fetch polyfills
16 changes: 8 additions & 8 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
},
"dependencies": {
"@mcansh/remix-fastify": "workspace:*",
"@remix-run/node": "^1.19.1",
"@remix-run/react": "^1.19.1",
"fastify": "^4.21.0",
"@remix-run/node": "2.0.0-pre.9",
"@remix-run/react": "2.0.0-pre.9",
"fastify": "^4.22.2",
"isbot": "^3.6.13",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@remix-run/dev": "^1.19.1",
"@remix-run/eslint-config": "^1.19.1",
"@types/react": "^18.2.18",
"@remix-run/dev": "2.0.0-pre.9",
"@remix-run/eslint-config": "2.0.0-pre.9",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"eslint": "^8.46.0",
"eslint": "^8.48.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"engines": {
"node": ">=14"
Expand Down
8 changes: 1 addition & 7 deletions example/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ module.exports = {
assetsBuildDirectory: "public/build",
serverBuildPath: "build/index.mjs",
serverModuleFormat: "esm",
future: {
v2_dev: true,
v2_routeConvention: true,
v2_errorBoundary: true,
v2_meta: true,
v2_normalizeFormMethod: true,
},
future: {},
// just showing that you can customize this and it will work with the plugin
publicPath: "/modules/",
};
9 changes: 8 additions & 1 deletion example/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { installGlobals } from "@remix-run/node";

import * as serverBuild from "./build/index.mjs";

installGlobals();
let nodeMajor = Number(process.versions.node.split(".")[0]);

if (["true", "1"].includes(process.env.INSTALL_GLOBALS) || nodeMajor < 20) {
console.log(`installing remix globals`);
installGlobals();
} else {
console.log(`using existing globals`);
}

let MODE = process.env.NODE_ENV;

Expand Down
18 changes: 10 additions & 8 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"target": "es2019",
"strict": true,
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"skipLibCheck": true,
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"isolatedModules": true,
"resolveJsonModule": true,

// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
"dependencies": {
"@changesets/cli": "^2.26.2",
"@manypkg/get-packages": "^2.2.0",
"@remix-run/eslint-config": "1.19.1",
"@remix-run/eslint-config": "2.0.0-pre.9",
"@types/glob": "^8.1.0",
"eslint": "^8.46.0",
"eslint": "^8.48.0",
"eslint-plugin-prefer-let": "^3.0.1",
"fs-extra": "^11.1.1",
"glob": "^10.3.3",
"glob": "^10.3.4",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.0",
"publint": "^0.2.0",
"prettier": "^3.0.3",
"publint": "^0.2.2",
"react": "^18.2.0",
"semver": "^7.5.4",
"tsup": "^7.1.0",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"vitest": "^0.34.3"
}
}
137 changes: 30 additions & 107 deletions packages/remix-fastify/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import {
// We don't want to test that the remix server works here (that's what the
// playwright tests do), we just want to test the fastify adapter
vi.mock("@remix-run/node", async () => {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
let original = await vi.importActual<typeof import("@remix-run/node")>(
"@remix-run/node",
);
let original =
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
await vi.importActual<typeof import("@remix-run/node")>("@remix-run/node");
return {
...original,
createRequestHandler: vi.fn(),
Expand Down Expand Up @@ -168,88 +167,42 @@ describe("fastify createRequestHandler", () => {
describe("fastify createRemixHeaders", () => {
describe("creates fetch headers from fastify headers", () => {
it("handles empty headers", () => {
expect(createRemixHeaders({})).toMatchInlineSnapshot(`
Headers {
Symbol(query): [],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({});
expect(Array.from(headers.keys())).toHaveLength(0);
});

it("handles simple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar" })).toMatchInlineSnapshot(`
Headers {
Symbol(query): [
"x-foo",
"bar",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar" });
expect(headers.get("x-foo")).toBe("bar");
});

it("handles multiple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" }))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): [
"x-foo",
"bar",
"x-bar",
"baz",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar", "x-bar": "baz" });
expect(headers.get("x-foo")).toBe("bar");
});

it("handles headers with multiple values", () => {
expect(createRemixHeaders({ "x-foo": "bar, baz" }))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): [
"x-foo",
"bar, baz",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar, baz" });
expect(headers.get("x-foo")).toBe("bar, baz");
});

it("handles headers with multiple values and multiple headers", () => {
expect(createRemixHeaders({ "x-foo": "bar, baz", "x-bar": "baz" }))
.toMatchInlineSnapshot(`
Headers {
Symbol(query): [
"x-foo",
"bar, baz",
"x-bar",
"baz",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({ "x-foo": "bar, baz", "x-bar": "baz" });
expect(headers.get("x-foo")).toBe("bar, baz");
expect(headers.get("x-bar")).toBe("baz");
});

it("handles multiple set-cookie headers", () => {
expect(
createRemixHeaders({
"set-cookie": [
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
"__other=some_other_value; Path=/; Secure; HttpOnly; MaxAge=3600; SameSite=Lax",
],
}),
).toMatchInlineSnapshot(`
Headers {
Symbol(query): [
"set-cookie",
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
"set-cookie",
"__other=some_other_value; Path=/; Secure; HttpOnly; MaxAge=3600; SameSite=Lax",
],
Symbol(context): null,
}
`);
let headers = createRemixHeaders({
"set-cookie": [
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax",
"__other=some_other_value; Path=/; Secure; HttpOnly; MaxAge=3600; SameSite=Lax",
],
});

expect(headers.get("set-cookie")).toBe(
"__session=some_value; Path=/; Secure; HttpOnly; MaxAge=7200; SameSite=Lax, __other=some_other_value; Path=/; Secure; HttpOnly; MaxAge=3600; SameSite=Lax",
);
});
});
});
Expand All @@ -269,41 +222,11 @@ describe("fastify createRemixRequest", () => {

let fastifyReply = { raw: { on: vi.fn() } } as unknown as FastifyReply;

expect(createRemixRequest(fastifyRequest, fastifyReply))
.toMatchInlineSnapshot(`
NodeRequest {
"agent": undefined,
"compress": true,
"counter": 0,
"follow": 20,
"highWaterMark": 16384,
"insecureHTTPParser": false,
"size": 0,
Symbol(Body internals): {
"body": null,
"boundary": null,
"disturbed": false,
"error": null,
"size": 0,
"type": null,
},
Symbol(Request internals): {
"credentials": "same-origin",
"headers": Headers {
Symbol(query): [
"cache-control",
"max-age=300, s-maxage=3600",
"host",
"localhost:3000",
],
Symbol(context): null,
},
"method": "GET",
"parsedURL": "http://localhost:3000/foo/bar",
"redirect": "follow",
"signal": AbortSignal {},
},
}
`);
let request = createRemixRequest(fastifyRequest, fastifyReply);

expect(request.headers.get("cache-control")).toBe(
"max-age=300, s-maxage=3600",
);
expect(request.headers.get("host")).toBe("localhost:3000");
});
});
24 changes: 12 additions & 12 deletions packages/remix-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@
},
"dependencies": {
"@fastify/early-hints": "^1.0.1",
"@fastify/static": "^6.10.2",
"@remix-run/router": "^1.7.2",
"@fastify/static": "^6.11.0",
"@remix-run/router": "^1.8.0",
"fastify-plugin": "^4.5.1",
"fastify-racing": "^1.1.0",
"glob": "^10.3.3",
"glob": "^10.3.4",
"tiny-invariant": "^1.3.1"
},
"devDependencies": {
"@remix-run/node": "^1.19.1",
"@remix-run/react": "^1.19.1",
"@remix-run/server-runtime": "^1.19.1",
"@remix-run/node": "2.0.0-pre.9",
"@remix-run/react": "2.0.0-pre.9",
"@remix-run/server-runtime": "2.0.0-pre.9",
"@types/glob": "^8.1.0",
"@types/node": "^20.4.5",
"@types/react": "^18.2.18",
"@types/node": "^20.5.9",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@typescript/lib-dom": "npm:@types/web@^0.0.111",
"fastify": "^4.21.0",
"node-mocks-http": "^1.12.2",
"@typescript/lib-dom": "npm:@types/web@^0.0.114",
"fastify": "^4.22.2",
"node-mocks-http": "^1.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"peerDependencies": {
"@remix-run/node": "^1.6.0",
Expand Down
Loading