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: bring back old routing and serverBuildTarget deprecation warnings #5793

Merged
merged 3 commits into from
Mar 14, 2023
Merged
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
15 changes: 13 additions & 2 deletions docs/file-conventions/remix-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ to `"build/index.js"`.

## serverBuildTarget

<docs-warning>This option is deprecated and will likely be removed in a future
stable release. Use a combination of [`publicPath`][public-path],
<docs-warning>This option is deprecated and will be removed in the next major version release. Use a combination of [`publicPath`][public-path],
[`serverBuildPath`][server-build-path], [`serverConditions`][server-conditions],
[`serverDependenciesToBundle`][server-dependencies-to-bundle]
[`serverMainFields`][server-main-fields], [`serverMinify`][server-minify],
Expand All @@ -136,6 +135,18 @@ The `serverBuildTarget` can be one of the following:
- [`"node-cjs"`][node-cjs]
- [`"vercel"`][vercel]

**Migration Table:**

| serverBuildTarget | publicPath | serverBuildPath | serverConditions | serverMainFields | serverModuleFormat | serverPlatform | serverDependenciesToBundle | serverMinify |
| -------------------- | ------------------ | --------------------------------------- | ---------------- | ----------------------- | ------------------ | -------------- | -------------------------- | ------------ |
| `arc` | `/\_static/build/` | `server/index.js` | | `main, module` | `cjs` | `node` | | `false` |
| `cloudflare-pages` | `/build/` | `functions/[[path]].js` | `worker` | `browser, module, main` | `esm` | `neutral` | `all` | `true` |
| `cloudflare-workers` | `/build/` | `build/index.js` | `worker` | `browser, module, main` | `esm` | `neutral` | `all` | `true` |
| `deno` | `/build/` | `build/index.js` | `deno, worker` | `module, main` | `esm` | `neutral` | `all` | `false` |
| `netlify` | `/build/` | `.netlify/functions-internal/server.js` | | `main, module` | `cjs` | `node` | | `false` |
| `node-cjs` | `/build/` | `build/index.js` | | `main, module` | `cjs` | `node` | | `false` |
| `vercel` | `/build/` | `api/index.js` | | `main, module` | `cjs` | `node` | | `false` |

## serverConditions

The order of conditions to use when resolving server dependencies' `exports`
Expand Down
47 changes: 47 additions & 0 deletions integration/flat-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PlaywrightFixture } from "./helpers/playwright-fixture";
import type { Fixture, AppFixture } from "./helpers/create-fixture";
import { createFixtureProject } from "./helpers/create-fixture";
import { createAppFixture, createFixture, js } from "./helpers/create-fixture";
import { flatRoutesWarning } from "../packages/remix-dev/config";

let fixture: Fixture;
let appFixture: AppFixture;
Expand Down Expand Up @@ -147,6 +148,52 @@ test.describe("flat routes", () => {
}
});

test.describe("warns when v1 routesConvention is used", () => {
let buildStdio = new PassThrough();
let buildOutput: string;

let originalConsoleLog = console.log;
let originalConsoleWarn = console.warn;
let originalConsoleError = console.error;

test.beforeAll(async () => {
console.log = () => {};
console.warn = () => {};
console.error = () => {};
await createFixtureProject({
buildStdio,
future: { v2_routeConvention: false },
files: {
"routes/index.tsx": js`
export default function () {
return <p>routes/index</p>;
}
`,
},
});

let chunks: Buffer[] = [];
buildOutput = await new Promise<string>((resolve, reject) => {
buildStdio.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
buildStdio.on("error", (err) => reject(err));
buildStdio.on("end", () =>
resolve(Buffer.concat(chunks).toString("utf8"))
);
});
});

test.afterAll(() => {
console.log = originalConsoleLog;
console.warn = originalConsoleWarn;
console.error = originalConsoleError;
});

test("warns about conflicting routes", () => {
console.log(buildOutput);
expect(buildOutput).toContain(flatRoutesWarning);
});
});

test.describe("emits warnings for route conflicts", async () => {
let buildStdio = new PassThrough();
let buildOutput: string;
Expand Down
1 change: 1 addition & 0 deletions integration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"rootDir": "."
},
"references": [
{ "path": "../packages/remix-dev" },
{ "path": "../packages/remix-express" },
{ "path": "../packages/remix-react" },
{ "path": "../packages/remix-server-runtime" }
Expand Down
4 changes: 3 additions & 1 deletion packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import stripAnsi from "strip-ansi";

import { run } from "../cli/run";
import { server } from "./msw";
import { errorBoundaryWarning } from "../config";
import { errorBoundaryWarning, flatRoutesWarning } from "../config";

beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterAll(() => server.close());
Expand Down Expand Up @@ -349,6 +349,8 @@ describe("the create command", () => {
]);
expect(output.trim()).toBe(
errorBoundaryWarning +
"\n" +
flatRoutesWarning +
"\n\n" +
getOptOutOfInstallMessage() +
"\n\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverBuildTarget: "node-cjs",
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
Expand Down
10 changes: 8 additions & 2 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import path from "path";

import type { RemixConfig } from "../config";
import { readConfig } from "../config";
import { serverBuildTargetWarning, readConfig } from "../config";

const remixRoot = path.resolve(__dirname, "./fixtures/stack");

describe("readConfig", () => {
let config: RemixConfig;
let warnStub;
beforeEach(async () => {
let consoleWarn = console.warn;
warnStub = jest.fn();
console.warn = warnStub;
config = await readConfig(remixRoot);
console.warn = consoleWarn;
});

it("generates a config", async () => {
expect(warnStub).toHaveBeenCalledWith(serverBuildTargetWarning);
expect(config).toMatchInlineSnapshot(
{
rootDirectory: expect.any(String),
Expand Down Expand Up @@ -69,7 +75,7 @@ describe("readConfig", () => {
},
},
"serverBuildPath": Any<String>,
"serverBuildTarget": undefined,
"serverBuildTarget": "node-cjs",
"serverBuildTargetEntryModule": "export * from \\"@remix-run/dev/server-build\\";",
"serverConditions": undefined,
"serverDependenciesToBundle": Array [],
Expand Down
22 changes: 18 additions & 4 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ export async function readConfig(
}
}

if (appConfig.serverBuildTarget) {
warnOnce(serverBuildTargetWarning, "v2_serverBuildTarget");
}

if (!appConfig.future?.v2_errorBoundary) {
warnOnce(errorBoundaryWarning, "v2_errorBoundary");
}
Expand Down Expand Up @@ -564,9 +568,14 @@ export async function readConfig(
root: { path: "", id: "root", file: rootRouteFile },
};

let routesConvention = appConfig.future?.v2_routeConvention
? flatRoutes
: defineConventionalRoutes;
let routesConvention: typeof flatRoutes;

if (appConfig.future?.v2_routeConvention) {
routesConvention = flatRoutes;
} else {
warnOnce(flatRoutesWarning, "v2_routeConvention");
routesConvention = defineConventionalRoutes;
}

if (fse.existsSync(path.resolve(appDirectory, "routes"))) {
let conventionalRoutes = routesConvention(
Expand Down Expand Up @@ -730,10 +739,15 @@ let listFormat = new Intl.ListFormat("en", {
type: "conjunction",
});


export let serverBuildTargetWarning = `⚠️ DEPRECATED: The "serverBuildTarget" config option is deprecated. Use a combination of "publicPath", "serverBuildPath", "serverConditions", "serverDependenciesToBundle", "serverMainFields", "serverMinify", "serverModuleFormat" and/or "serverPlatform" instead.`;

export let flatRoutesWarning = `⚠️ DEPRECATED: The old nested folders route convention has been deprecated in favor of "flat routes". Please enable the new routing convention via the \`future.v2_routeConvention\` flag in your \`remix.config.js\` file. For more information, please see https://remix.run/docs/en/main/file-conventions/route-files-v2.`;

export const errorBoundaryWarning =
"⚠️ DEPRECATED: The separation of `CatchBoundary` and `ErrorBoundary` has " +
"been deprecated and Remix v2 will use a singular `ErrorBoundary` for " +
"all thrown values (`Response` and `Error`). Please migrate to the new " +
"behavior in Remix v1 via the `future.v2_errorBoundary` flag in your " +
"`remix.config.js` file. For more information, see " +
"https://remix.run/docs/route/error-boundary-v2";
"https://remix.run/docs/route/error-boundary-v2";