Skip to content

Commit

Permalink
Always ignore route files starting with . (#8801)
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Cattori <[email protected]>
  • Loading branch information
markdalgleish and pcattori authored Feb 20, 2024
1 parent 9cb876f commit c1a32c2
Show file tree
Hide file tree
Showing 24 changed files with 49 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-gifts-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Always ignore route files starting with `.`
6 changes: 3 additions & 3 deletions docs/file-conventions/remix-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
future: {
/* any enabled future flags */
},
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
publicPath: "/build/",
routes(defineRoutes) {
return defineRoutes((route) => {
Expand Down Expand Up @@ -84,7 +84,7 @@ The `future` config lets you opt-into future breaking changes via [Future Flags]
This is an array of globs (via [minimatch][minimatch]) that Remix will match to
files while reading your `app/routes` directory. If a file matches, it will be
ignored rather than treated like a route module. This is useful for ignoring
dotfiles (like `.DS_Store` files) or CSS/test files you wish to colocate.
CSS/test files you wish to colocate.

## publicPath

Expand Down Expand Up @@ -181,7 +181,7 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildPath: "build/index.js",
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
serverDependenciesToBundle: [
/^rehype.*/,
/^remark.*/,
Expand Down
4 changes: 2 additions & 2 deletions docs/future/vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { defineConfig } from "vite";
export default defineConfig({
plugins: [
remix({
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
}),
],
});
Expand Down Expand Up @@ -348,7 +348,7 @@ The subset of [supported Remix config options][supported-remix-config-options] s
export default defineConfig({
plugins: [
remix({
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
}),
],
});
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/migrating-react-router-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Every Remix app accepts a `remix.config.js` file in the project root. While its
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
appDirectory: "app",
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
assetsBuildDirectory: "public/build",
};
```
Expand Down
25 changes: 25 additions & 0 deletions integration/flat-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ test.describe("flat routes", () => {
}
`,

"app/routes/.dotfile": `
DOTFILE SHOULD BE IGNORED
`,

"app/routes/.route-with-unescaped-leading-dot.tsx": js`
throw new Error("This file should be ignored as a route");
`,

"app/routes/[.]route-with-escaped-leading-dot.tsx": js`
export default function () {
return <h2>Route With Escaped Leading Dot</h2>;
}
`,

"app/routes/dashboard/route.tsx": js`
import { Outlet } from "@remix-run/react";
Expand Down Expand Up @@ -148,6 +162,17 @@ test.describe("flat routes", () => {
</div>`);
});

test("renders matching routes (route with escaped leading dot)", async ({
page,
}) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/.route-with-escaped-leading-dot");
expect(await app.getHtml("#content")).toBe(`<div id="content">
<h1>Root</h1>
<h2>Route With Escaped Leading Dot</h2>
</div>`);
});

test("renders matching routes (nested)", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/dashboard");
Expand Down
1 change: 0 additions & 1 deletion integration/helpers/cf-template/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
server: "./server.ts",
serverConditions: ["workerd", "worker", "browser"],
serverDependenciesToBundle: [
Expand Down
1 change: 0 additions & 1 deletion integration/helpers/deno-template/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
ignoredRouteFiles: ["**/.*"],
server: "./server.ts",
serverConditions: ["deno", "worker"],
serverDependenciesToBundle: "all",
Expand Down
1 change: 0 additions & 1 deletion integration/helpers/node-template/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// publicPath: "/build/",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverBuildTarget: "node-cjs",
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// serverBuildPath: "build/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
server: "./server.ts",
serverBuildPath: "functions/[[path]].js",
serverConditions: ["workerd", "worker", "browser"],
Expand Down
1 change: 0 additions & 1 deletion packages/remix-dev/__tests__/fixtures/deno/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
ignoredRouteFiles: ["**/.*"],
server: "./server.ts",
serverConditions: ["deno", "worker"],
serverDependenciesToBundle: "all",
Expand Down
1 change: 0 additions & 1 deletion packages/remix-dev/__tests__/fixtures/node/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// publicPath: "/build/",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// serverBuildPath: "build/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/remix-dev/config/flat-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function flatRoutes(
ignoredFilePatterns: string[] = [],
prefix = "routes"
) {
let ignoredFileRegex = ignoredFilePatterns
let ignoredFileRegex = Array.from(new Set(["**/.*", ...ignoredFilePatterns]))
.map((re) => makeRe(re))
.filter((re: any): re is RegExp => !!re);
let routesDir = path.join(appDirectory, prefix);
Expand All @@ -104,7 +104,7 @@ export function flatRoutes(

let routes: string[] = [];
for (let entry of entries) {
let filepath = path.join(routesDir, entry.name);
let filepath = normalizeSlashes(path.join(routesDir, entry.name));

let route: string | null = null;
// If it's a directory, don't recurse into it, instead just look for a route module
Expand Down Expand Up @@ -302,7 +302,7 @@ function findRouteModuleForFile(
filepath: string,
ignoredFileRegex: RegExp[]
): string | null {
let relativePath = path.relative(appDirectory, filepath);
let relativePath = normalizeSlashes(path.relative(appDirectory, filepath));
let isIgnored = ignoredFileRegex.some((regex) => regex.test(relativePath));
if (isIgnored) return null;
return filepath;
Expand Down
2 changes: 1 addition & 1 deletion scripts/playground/template/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
cacheDirectory: "./node_modules/.cache/remix",
ignoredRouteFiles: ["**/.*", "**/*.css", "**/*.test.{js,jsx,ts,tsx}"],
ignoredRouteFiles: ["**/*.css", "**/*.test.{js,jsx,ts,tsx}"],
};
2 changes: 1 addition & 1 deletion templates/arc/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
publicPath: "/_static/build/",
server: "server.ts",
serverBuildPath: "server/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion templates/cloudflare-pages/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
server: "./server.ts",
serverBuildPath: "functions/[[path]].js",
serverConditions: ["workerd", "worker", "browser"],
Expand Down
2 changes: 1 addition & 1 deletion templates/cloudflare-workers/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
server: "./server.ts",
serverConditions: ["workerd", "worker", "browser"],
serverDependenciesToBundle: [
Expand Down
2 changes: 1 addition & 1 deletion templates/deno/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
server: "./server.ts",
serverConditions: ["deno", "worker"],
serverDependenciesToBundle: "all",
Expand Down
2 changes: 1 addition & 1 deletion templates/express/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
serverModuleFormat: "esm",
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
Expand Down
2 changes: 1 addition & 1 deletion templates/fly/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// publicPath: "/build/",
Expand Down
2 changes: 1 addition & 1 deletion templates/remix-javascript/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// publicPath: "/build/",
Expand Down
2 changes: 1 addition & 1 deletion templates/remix-tutorial/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
serverModuleFormat: "cjs",
};
2 changes: 1 addition & 1 deletion templates/remix/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
ignoredRouteFiles: ["**/*.css"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// publicPath: "/build/",
Expand Down

0 comments on commit c1a32c2

Please sign in to comment.