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:
co-authored by
Marvin Hagemeister
Asher Gomez
parent
59fff11903
commit
e01ef2d8a0
@@ -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
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user