Skip to content

Commit

Permalink
feat(dev): ignoredRouteFiles config option (remix-run#989)
Browse files Browse the repository at this point in the history
Added default setting in all template configs to ignore dotfiles
  • Loading branch information
chaance authored Dec 15, 2021
1 parent d4860a0 commit 45df222
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 21 deletions.
3 changes: 2 additions & 1 deletion examples/basic/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "build",
devServerPort: 8002
devServerPort: 8002,
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion examples/blog-tutorial/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "build",
devServerPort: 8002
devServerPort: 8002,
ignoredRouteFiles: [".*"]
};
1 change: 1 addition & 0 deletions examples/jokes/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
publicPath: "/build/",
serverBuildDirectory: "build",
devServerPort: 8003,
ignoredRouteFiles: [".*"],
};
3 changes: 1 addition & 2 deletions fixtures/gists-app/app/routes/.blargh
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Remix ignores dotfiles in the routes directory. This file only exists to ensure
that the app continues to build and run as if the file didn't exist.
this file should be ignored by Remix
2 changes: 2 additions & 0 deletions fixtures/gists-app/app/routes/blargh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this file should be ignored by Remix
export default {};
1 change: 1 addition & 0 deletions fixtures/gists-app/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
publicPath: "/build/",
serverBuildDirectory: "./build",
devServerPort: 8002,
ignoredRouteFiles: [".*", "blargh.ts"],

mdx: async filename => {
const [rehypeHighlight, remarkToc] = await Promise.all([
Expand Down
1 change: 1 addition & 0 deletions fixtures/tutorial/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
publicPath: "/build/",
serverBuildDirectory: "build",
devServerPort: 8002,
ignoredRouteFiles: [".*"],
routes(defineRoutes) {
return defineRoutes(route => {
route("*", "catchall.tsx");
Expand Down
3 changes: 2 additions & 1 deletion packages/create-remix/templates/_shared_js/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
appDirectory: "app",
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "server/build"
serverBuildDirectory: "server/build",
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion packages/create-remix/templates/_shared_ts/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
appDirectory: "app",
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "server/build"
serverBuildDirectory: "server/build",
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion packages/create-remix/templates/arc/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/_static/build/",
serverBuildDirectory: "server/build",
devServerPort: 8002
devServerPort: 8002,
ignoredRouteFiles: [".*"]
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "build",
devServerBroadcastDelay: 1000
devServerBroadcastDelay: 1000,
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion packages/create-remix/templates/express/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "server/build",
devServerPort: 8002
devServerPort: 8002,
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion packages/create-remix/templates/fly/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "build",
devServerPort: 8002
devServerPort: 8002,
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion packages/create-remix/templates/netlify/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "netlify/functions/server/build",
devServerPort: 8002
devServerPort: 8002,
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion packages/create-remix/templates/remix/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "build",
devServerPort: 8002
devServerPort: 8002,
ignoredRouteFiles: [".*"]
};
3 changes: 2 additions & 1 deletion packages/create-remix/templates/vercel/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
appDirectory: "app",
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "api/_build"
serverBuildDirectory: "api/_build",
ignoredRouteFiles: [".*"]
};
12 changes: 11 additions & 1 deletion packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export interface AppConfig {
* The output format of the server build. Defaults to "cjs".
*/
serverModuleFormat: "esm" | "cjs";

/**
* A list of filenames or a glob patterns to match files in the `app/routes`
* directory that Remix will ignore. Matching files will not be recognized as
* routes.
*/
ignoredRouteFiles?: string[];
}

/**
Expand Down Expand Up @@ -235,7 +242,10 @@ export async function readConfig(
root: { path: "", id: "root", file: rootRouteFile }
};
if (fs.existsSync(path.resolve(appDirectory, "routes"))) {
let conventionalRoutes = defineConventionalRoutes(appDirectory);
let conventionalRoutes = defineConventionalRoutes(
appDirectory,
appConfig.ignoredRouteFiles
);
for (let key of Object.keys(conventionalRoutes)) {
let route = conventionalRoutes[key];
routes[route.id] = { ...route, parentId: route.parentId || "root" };
Expand Down
19 changes: 12 additions & 7 deletions packages/remix-dev/config/routesConvention.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "fs";
import * as path from "path";
import minimatch from "minimatch";

import type { RouteManifest, DefineRouteFunction } from "./routes";
import { defineRoutes, createRouteId } from "./routes";
Expand All @@ -21,20 +22,24 @@ export function isRouteModuleFile(filename: string): boolean {
* For example, a file named `app/routes/gists/$username.tsx` creates a route
* with a path of `gists/:username`.
*/
export function defineConventionalRoutes(appDir: string): RouteManifest {
export function defineConventionalRoutes(
appDir: string,
ignoredFilePatterns?: string[]
): RouteManifest {
let files: { [routeId: string]: string } = {};

// First, find all route modules in app/routes
visitFiles(path.join(appDir, "routes"), file => {
let routeId = createRouteId(path.join("routes", file));

if (isRouteModuleFile(file)) {
files[routeId] = path.join("routes", file);
if (
ignoredFilePatterns &&
ignoredFilePatterns.some(pattern => minimatch(file, pattern))
) {
return;
}

// https://github.com/remix-run/remix/issues/391
if (path.basename(file).startsWith(".")) {
if (isRouteModuleFile(file)) {
let routeId = createRouteId(path.join("routes", file));
files[routeId] = path.join("routes", file);
return;
}

Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"fs-extra": "^10.0.0",
"lodash.debounce": "^4.0.8",
"meow": "^7.1.1",
"minimatch": "^3.0.4",
"pretty-ms": "^7.0.1",
"read-package-json-fast": "^2.0.2",
"remark-frontmatter": "^4.0.0",
Expand Down

0 comments on commit 45df222

Please sign in to comment.