Skip to content

Commit

Permalink
Move server-runtime into react-router (#11698)
Browse files Browse the repository at this point in the history
* Move server-runtime into react-router

* Clean up comments

* Remove unused index

* Update changeset

* Fix test imports

* Set test env to jsdom

* Clean redundant diffs

* Fix EntryContext type errors

* Remove stray comment

* Fix tests in Node 18

* Lower filesize limit

* Remove server-runtime reexport modules
  • Loading branch information
markdalgleish committed Jun 21, 2024
1 parent 97be8ab commit 559b0eb
Show file tree
Hide file tree
Showing 96 changed files with 315 additions and 1,805 deletions.
1 change: 1 addition & 0 deletions .changeset/collapse-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

- Collapse `@remix-run/router` into `react-router`
- Collapse `react-router-dom` into `react-router`
- Collapse `@remix-run/server-runtime` into `react-router`
- Collapse `@remix-run/testing` into `react-router`
3 changes: 1 addition & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"@react-router/dev",
"@react-router/express",
"@react-router/node",
"@react-router/serve",
"@react-router/server-runtime"
"@react-router/serve"
]
],
"linked": [],
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ This repository is a monorepo containing the following packages:
- [`@react-router/express`](/packages/remix-express)
- [`@react-router/node`](/packages/remix-node)
- [`@react-router/serve`](/packages/remix-serve)
- [`@react-router/server-runtime`](/packages/remix-server-runtime)
- [`react-router`](/packages/react-router)
- [`react-router-dom`](/packages/react-router-dom)

Expand Down
2 changes: 1 addition & 1 deletion integration/client-data-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/error-boundary-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/error-boundary-v2-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Page } from "@playwright/test";
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
4 changes: 2 additions & 2 deletions integration/error-data-request-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.describe("ErrorBoundary", () => {
`,

[`app/routes/loader-return-json.jsx`]: js`
import { json } from "@react-router/server-runtime";
import { json } from "react-router";
export async function loader() {
return json({ ok: true });
Expand All @@ -80,7 +80,7 @@ test.describe("ErrorBoundary", () => {
`,

[`app/routes/action-return-json.jsx`]: js`
import { json } from "@react-router/server-runtime";
import { json } from "react-router";
export async function action() {
return json({ ok: true });
Expand Down
9 changes: 5 additions & 4 deletions integration/error-sanitization-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { test, expect } from "@playwright/test";
import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "react-router";
import {
UNSAFE_ErrorResponseImpl as ErrorResponseImpl,
UNSAFE_ServerMode as ServerMode,
} from "react-router";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import type { Fixture } from "./helpers/create-fixture.js";
import {
createAppFixture,
Expand Down Expand Up @@ -77,8 +79,7 @@ const routeFiles = {

"app/routes/defer.tsx": js`
import * as React from 'react';
import { defer } from "@react-router/server-runtime";
import { Await, useAsyncError, useLoaderData, useRouteError } from "react-router";
import { defer, Await, useAsyncError, useLoaderData, useRouteError } from "react-router";
export function loader({ request }) {
if (new URL(request.url).searchParams.has('loader')) {
Expand Down
6 changes: 2 additions & 4 deletions integration/form-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ test.describe("Forms", () => {
`,

"app/routes/empty-file-upload.tsx": js`
import { json } from "@react-router/server-runtime";
import { Form, useActionData } from "react-router";
import { json, Form, useActionData } from "react-router";
export async function action({ request }) {
let formData = await request.formData();
Expand Down Expand Up @@ -454,8 +453,7 @@ test.describe("Forms", () => {
"myfile.txt": "stuff",

"app/routes/pathless-layout-parent.tsx": js`
import { json } from '@react-router/server-runtime'
import { Form, Outlet, useActionData } from "react-router"
import { json, Form, Outlet, useActionData } from "react-router"
export async function action({ request }) {
return json({ submitted: true });
Expand Down
5 changes: 2 additions & 3 deletions integration/headers-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import { createFixture, js } from "./helpers/create-fixture.js";
import type { Fixture } from "./helpers/create-fixture.js";

Expand Down Expand Up @@ -159,8 +159,7 @@ test.describe.skip("headers export", () => {
`,

"app/routes/cookie.tsx": js`
import { json } from "@react-router/server-runtime";
import { Outlet } from "react-router";
import { json, Outlet } from "react-router";
export function loader({ request }) {
if (new URL(request.url).searchParams.has("parent-throw")) {
Expand Down
10 changes: 6 additions & 4 deletions integration/helpers/create-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import stripIndent from "strip-indent";
import { sync as spawnSync, spawn } from "cross-spawn";
import type { JsonObject } from "type-fest";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import type { ServerBuild } from "@react-router/server-runtime";
import { createRequestHandler } from "@react-router/server-runtime";
import {
type ServerBuild,
createRequestHandler,
UNSAFE_ServerMode as ServerMode,
UNSAFE_decodeViaTurboStream as decodeViaTurboStream,
} from "react-router";
import { createRequestHandler as createExpressHandler } from "@react-router/express";
import { installGlobals } from "@react-router/node";
import { UNSAFE_decodeViaTurboStream as decodeViaTurboStream } from "react-router";

import { viteConfig } from "./vite.js";

Expand Down
1 change: 0 additions & 1 deletion integration/helpers/node-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@react-router/express": "workspace:*",
"@react-router/node": "workspace:*",
"@react-router/serve": "workspace:*",
"@react-router/server-runtime": "workspace:*",
"express": "^4.17.1",
"isbot": "^4.1.0",
"react": "^18.2.0",
Expand Down
1 change: 0 additions & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@react-router/dev": "workspace:*",
"@react-router/express": "workspace:*",
"@react-router/node": "workspace:*",
"@react-router/server-runtime": "workspace:*",
"@types/express": "^4.17.9",
"@vanilla-extract/css": "^1.10.0",
"@vanilla-extract/vite-plugin": "^3.9.2",
Expand Down
2 changes: 1 addition & 1 deletion integration/resource-routes-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/root-route-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";

import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";
import {
createAppFixture,
createFixture,
Expand Down
2 changes: 1 addition & 1 deletion integration/single-fetch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
js,
} from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import { UNSAFE_ServerMode as ServerMode } from "@react-router/server-runtime";
import { UNSAFE_ServerMode as ServerMode } from "react-router";

const ISO_DATE = "2024-03-12T12:00:00.000Z";

Expand Down
2 changes: 0 additions & 2 deletions jest/jest.config.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module.exports = {
"@react-router/express$": "<rootDir>/../remix-express/index.ts",
"@react-router/node$": "<rootDir>/../remix-node/index.ts",
"@react-router/serve$": "<rootDir>/../remix-serve/index.ts",
"@react-router/server-runtime$":
"<rootDir>/../remix-server-runtime/index.ts",
"^react-router$": "<rootDir>/../react-router/index.ts",
"^@web3-storage/multipart-parser$": require.resolve(
"@web3-storage/multipart-parser"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@
},
"filesize": {
"packages/react-router/dist/react-router.production.min.js": {
"none": "120 kB"
"none": "124 kB"
},
"packages/react-router/dist/umd/react-router.production.min.js": {
"none": "125 kB"
"none": "130 kB"
}
},
"pnpm": {
Expand Down
10 changes: 0 additions & 10 deletions packages/react-router/.eslintrc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
let restrictedGlobalsError = `Node globals are not allowed in this package.`;

module.exports = {
extends: "../../.eslintrc",
env: {
browser: true,
commonjs: true,
},
rules: {
strict: 0,
"no-restricted-syntax": ["error", "LogicalExpression[operator='??']"],
"no-restricted-globals": [
"error",
{ name: "__dirname", message: restrictedGlobalsError },
Expand Down
4 changes: 3 additions & 1 deletion packages/react-router/__tests__/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"jest": true
},
"rules": {
"no-console": 0
"no-console": 0,
"no-restricted-globals": "off",
"import/no-nodejs-modules": "off"
}
}
5 changes: 4 additions & 1 deletion packages/react-router/__tests__/router/data-strategy-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { DataStrategyFunction, DataStrategyMatch } from "../../lib/router";
import type {
unstable_DataStrategyFunction as DataStrategyFunction,
unstable_DataStrategyMatch as DataStrategyMatch,
} from "../../lib/router";
import { json } from "../../lib/router";
import { createDeferred, setup } from "./utils/data-router-setup";
import { createFormData, tick } from "./utils/utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { createCookieFactory, isCookie } from "../cookies";
import type { SignFunction, UnsignFunction } from "../crypto";
import {
createCookieFactory,
isCookie,
} from "../../lib/server-runtime/cookies";
import type {
SignFunction,
UnsignFunction,
} from "../../lib/server-runtime/crypto";

const sign: SignFunction = async (value, secret) => {
return JSON.stringify({ value, secret });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UNSAFE_decodeViaTurboStream as decodeViaTurboStream } from "react-router";

import type { ServerBuild } from "../build";
import { createRequestHandler } from "../server";
import type { ServerBuild } from "../../lib/server-runtime/build";
import { createRequestHandler } from "../../lib/server-runtime/server";

describe("loaders", () => {
// so that HTML/Fetch requests are the same, and so redirects don't hang on to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { parseMultipartFormData } from "../formData";
/**
* @jest-environment node
*/

import { parseMultipartFormData } from "../../lib/server-runtime/formData";

declare global {
interface RequestInit {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "react-router";

import type { ServerBuild } from "../build";
import { createRequestHandler } from "../server";
import { json } from "../responses";
import type { ServerBuild } from "../../lib/server-runtime/build";
import { createRequestHandler } from "../../lib/server-runtime/server";
import { json } from "../../lib/server-runtime/responses";

function getHandler(routeModule = {}, entryServerModule = {}) {
let routeId = "root";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { json } from "../responses";
import { createRequestHandler } from "../server";
import { json } from "../../lib/server-runtime/responses";
import { createRequestHandler } from "../../lib/server-runtime/server";

describe("createRequestHandler", () => {
it("retains request headers when stripping body off for loaders", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import vm from "vm";

import { escapeHtml } from "../markup";
import { escapeHtml } from "../../lib/server-runtime/markup";

describe("escapeHtml", () => {
// These tests are based on https://github.com/zertosh/htmlescape/blob/3e6cf0614dd0f778fd0131e69070b77282150c15/test/htmlescape-test.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { TypedResponse } from "../index";
import { json, redirect } from "../index";
/**
* @jest-environment node
*/

import type { TypedResponse } from "../../lib/server-runtime/responses";
import { json, redirect } from "../../lib/server-runtime/responses";
import { isEqual } from "./utils";

describe("json", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/**
* @jest-environment node
*/

import type { StaticHandlerContext } from "react-router";
import { json } from "react-router";

import { createRequestHandler } from "..";
import { ServerMode } from "../mode";
import type { ServerBuild } from "../build";
import { createRequestHandler } from "../../lib/server-runtime/server";
import { ServerMode } from "../../lib/server-runtime/mode";
import type { ServerBuild } from "../../lib/server-runtime/build";
import { mockServerBuild } from "./utils";

function spyConsole() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createCookieFactory } from "../cookies";
import type { SignFunction, UnsignFunction } from "../crypto";
import { createCookieFactory } from "../../lib/server-runtime/cookies";
import type {
SignFunction,
UnsignFunction,
} from "../../lib/server-runtime/crypto";
import {
createSession,
createSessionStorageFactory,
isSession,
} from "../sessions";
import { createCookieSessionStorageFactory } from "../sessions/cookieStorage";
import { createMemorySessionStorageFactory } from "../sessions/memoryStorage";
} from "../../lib/server-runtime/sessions";
import { createCookieSessionStorageFactory } from "../../lib/server-runtime/sessions/cookieStorage";
import { createMemorySessionStorageFactory } from "../../lib/server-runtime/sessions/memoryStorage";

function getCookieFromSetCookie(setCookie: string): string {
return setCookie.split(/;\s*/)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import type {
HandleErrorFunction,
HeadersFunction,
LoaderFunction,
} from "../";
import type { FutureConfig } from "../entry";
import type { EntryRoute, ServerRoute, ServerRouteManifest } from "../routes";
} from "../../lib/server-runtime";
import type { FutureConfig } from "../../lib/server-runtime/entry";
import type {
EntryRoute,
ServerRoute,
ServerRouteManifest,
} from "../../lib/server-runtime/routes";

export function mockServerBuild(
routes: Record<
Expand Down
5 changes: 5 additions & 0 deletions packages/react-router/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ if (!globalThis.TransformStream) {
const { TransformStream } = require("node:stream/web");
globalThis.TransformStream = TransformStream;
}

if (!globalThis.File) {
const { File } = require("undici");
globalThis.File = File;
}
Loading

0 comments on commit 559b0eb

Please sign in to comment.