Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions src/project/project-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export async function projectContext(
result,
projectConfig,
);
// if we are attemping to get the projectConext for a file and the
// if we are attemping to get the projectContext for a file and the
// file isn't in list of input files then return a single-file project
const fullPath = normalizePath(path);
if (Deno.statSync(fullPath).isFile && !files.includes(fullPath)) {
Expand Down Expand Up @@ -757,21 +757,21 @@ export async function projectInputFiles(
if (!engines.includes(engine.name)) {
engines.push(engine.name);
}
files.push(file);
const engineIntermediates = executionEngineIntermediateFiles(
engine,
file,
);
if (engineIntermediates) {
intermediateFiles.push(...engineIntermediates);
}
return file;
}
}
};

const addDir = async (dir: string) => {
const dirFiles: string[] = [];
// ignore selected other globs

for (
const walk of walkSync(
dir,
Expand All @@ -791,9 +791,13 @@ export async function projectInputFiles(
) {
const pathRelative = pathWithForwardSlashes(relative(dir, walk.path));
if (!projectIgnores.some((regex) => regex.test(pathRelative))) {
await addFile(walk.path);
const file = await addFile(walk.path);
if (file) {
dirFiles.push(file);
}
}
}
return dirFiles;
};

const renderFiles = metadata?.project[kProjectRender];
Expand All @@ -802,20 +806,36 @@ export async function projectInputFiles(
const resolved = resolvePathGlobs(dir, renderFiles, exclude, {
mode: "auto",
});
await Promise.all(
(ld.difference(resolved.include, resolved.exclude) as string[])
.map((file) => {
if (Deno.statSync(file).isDirectory) {
return addDir(file);
} else {
return addFile(file);
}
}),
const includedFiles = ld.difference(
resolved.include,
resolved.exclude,
) as string[];
const filePromises = includedFiles.map(async (file, index) => {
const result = Deno.statSync(file).isDirectory
? await addDir(file)
: await addFile(file);
return { index, result };
});
// Await for resolution of all files and reorder based on resolved file order
const sortedResults = (await Promise.all(filePromises)).sort((a, b) =>
a.index - b.index
);
// Return project input files in order of discovery
for (const { result } of sortedResults) {
if (Array.isArray(result)) {
// when files are added from a directory
files.push(...result);
} else if (result) {
// when a single file is added
files.push(result);
}
}
} else {
await addDir(dir);
const dirFiles = await addDir(dir);
files.push(...dirFiles);
}

// Be sure to exclude any known intermediate files
const inputFiles = ld.difference(
ld.uniq(files),
ld.uniq(intermediateFiles),
Expand Down