Skip to content

Commit

Permalink
chore(remix-dev): add warning when future.v2_routeConvention is not…
Browse files Browse the repository at this point in the history
… enabled

Signed-off-by: Logan McAnsh <logan@mcan.sh>

chore: update warning

test: update test to include v2_routeConvention error  message

Signed-off-by: Logan McAnsh <logan@mcan.sh>

update warning

Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh committed Mar 2, 2023
1 parent 342dc60 commit 23b5316
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
47 changes: 47 additions & 0 deletions integration/flat-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,53 @@ 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,
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(
`The old route convention has been deprecated in favor of "flat routes". Please enable it via your remix.config https://remix.run/docs/en/main/file-conventions/route-files-v2`
);
});
});

test.describe("emits warnings for route conflicts", async () => {
let buildStdio = new PassThrough();
let buildOutput: string;
Expand Down
5 changes: 4 additions & 1 deletion packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import stripAnsi from "strip-ansi";

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

beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterAll(() => server.close());
Expand Down Expand Up @@ -347,7 +348,9 @@ describe("the create command", () => {
"--no-typescript",
]);
expect(output.trim()).toBe(
getOptOutOfInstallMessage() +
flatRoutesWarning +
"\n\n" +
getOptOutOfInstallMessage() +
"\n\n" +
getSuccessMessage(path.join("<TEMP_DIR>", "template-to-js"))
);
Expand Down
12 changes: 9 additions & 3 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,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 @@ -727,3 +732,4 @@ let listFormat = new Intl.ListFormat("en", {
});

export let serverBuildTargetWarning = `The "serverBuildTarget" config option is deprecated. Use a combination of "publicPath", "serverBuildPath", "serverConditions", "serverDependenciesToBundle", "serverMainFields", "serverMinify", "serverModuleFormat" and/or "serverPlatform" instead.`;
export let flatRoutesWarning = `The old route convention has been deprecated in favor of "flat routes". Please enable it via your remix.config https://remix.run/docs/en/main/file-conventions/route-files-v2`;

0 comments on commit 23b5316

Please sign in to comment.