Skip to content

Commit

Permalink
Project Render - improve exclude only logic
Browse files Browse the repository at this point in the history
Rather than use a glob like `**/*` (which will expand to include files in hidden directories or which might otherwise be excluded by engines), or a path like `.` which isn’t a glob and thus doesn’t expand, use the `addDir` function to build the render include list (and then use the excludes to filter this complete list). The `addDir` function will add all the files in the directory, excluding hidden files and engine ignore files, thus doing what we need.

See also:
a0e2369

196216b
  • Loading branch information
dragonstyle committed Jan 5, 2024
1 parent ece25c2 commit 8579ac7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/project/project-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ export function projectInputFiles(
}
};

const addDir = (dir: string) => {
const addDir = (dir: string, addfile: (file: string) => void) => {
// ignore selected other globs

for (
Expand All @@ -654,7 +654,7 @@ export function projectInputFiles(
) {
const pathRelative = pathWithForwardSlashes(relative(dir, walk.path));
if (!projectIgnores.some((regex) => regex.test(pathRelative))) {
addFile(walk.path);
addfile(walk.path);
}
}
};
Expand All @@ -680,7 +680,12 @@ export function projectInputFiles(
const renderFiles = metadata?.project[kProjectRender] ?? [];
// this triggers when renderFiles is empty as well, which is what we want
if (renderFiles.every((file) => file.startsWith("!"))) {
renderFiles.unshift(".");
// Add the project files in the current directory
const fileList: string[] = [];
addDir(".", (file: string) => {
fileList.push(file);
});
renderFiles.unshift(...fileList);
}
const exclude = projIgnoreGlobs.concat(outputDir ? [outputDir] : []);
const resolved = resolvePathGlobs(dir, renderFiles, exclude, {
Expand All @@ -689,7 +694,7 @@ export function projectInputFiles(
(ld.difference(resolved.include, resolved.exclude) as string[])
.forEach((file) => {
if (Deno.statSync(file).isDirectory) {
addDir(file);
addDir(file, addFile);
} else {
addFile(file);
}
Expand Down

0 comments on commit 8579ac7

Please sign in to comment.