feat(dev): Ignore common test files in routes and islands (#1039)

Co-authored-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Sebastian Gräßl
2023-09-11 16:05:55 +02:00
committed by GitHub
co-authored by Marvin Hagemeister Asher Gomez
parent 59fff11903
commit e01ef2d8a0
16 changed files with 142 additions and 5 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ export async function dev(
} else {
currentManifest = { islands: [], routes: [] };
}
const newManifest = await collect(dir);
const newManifest = await collect(dir, options);
Deno.env.set("FRSH_DEV_PREVIOUS_MANIFEST", JSON.stringify(newManifest));
const manifestChanged =
+10 -4
View File
@@ -1,7 +1,8 @@
import { gte, join, posix, relative, walk, WalkEntry } from "./deps.ts";
import { error } from "./error.ts";
import { FreshOptions } from "../server/mod.ts";
const MIN_DENO_VERSION = "1.31.0";
const TEST_FILE_PATTERN = /[._]test\.(?:[tj]sx?|[mc][tj]s)$/;
export function ensureMinDenoVersion() {
// Check that the minimum supported Deno version is being used.
@@ -23,6 +24,7 @@ export function ensureMinDenoVersion() {
async function collectDir(
dir: string,
callback: (entry: WalkEntry, dir: string) => void,
options: FreshOptions,
): Promise<void> {
// Check if provided path is a directory
try {
@@ -37,6 +39,7 @@ async function collectDir(
includeDirs: false,
includeFiles: true,
exts: ["tsx", "jsx", "ts", "js"],
skip: [options?.router?.ignoreFilePattern || TEST_FILE_PATTERN],
});
for await (const entry of routesFolder) {
@@ -50,7 +53,10 @@ export interface Manifest {
}
const GROUP_REG = /[/\\\\]\((_[^/\\\\]+)\)[/\\\\]/;
export async function collect(directory: string): Promise<Manifest> {
export async function collect(
directory: string,
options: FreshOptions = {},
): Promise<Manifest> {
const filePaths = new Set<string>();
const routes: string[] = [];
@@ -78,11 +84,11 @@ export async function collect(directory: string): Promise<Manifest> {
}
filePaths.add(normalized);
routes.push(rel);
}),
}, options),
collectDir(join(directory, "./islands"), (entry, dir) => {
const rel = join("islands", relative(dir, entry.path));
islands.push(rel);
}),
}, options),
]);
routes.sort();