fix: cover every tracked release input
This commit is contained in:
@@ -131,11 +131,12 @@ function normalizeRepositoryPath(value: string, label: string): string {
|
||||
|
||||
function isWithinRoot(root: string, target: string): boolean {
|
||||
const relative = path.relative(root, target);
|
||||
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
||||
}
|
||||
|
||||
function belongsToRoots(file: string, roots: readonly string[]): boolean {
|
||||
return roots.some((root) => file === root || file.startsWith(`${root}/`));
|
||||
return (
|
||||
relative === "" ||
|
||||
(relative !== ".." &&
|
||||
!relative.startsWith(`..${path.sep}`) &&
|
||||
!path.isAbsolute(relative))
|
||||
);
|
||||
}
|
||||
|
||||
function parseGitFileList(result: GitFileListResult): string[] {
|
||||
@@ -261,9 +262,7 @@ export async function buildRepositoryFileInventory(
|
||||
|
||||
const trackedFiles = parseGitFileList(
|
||||
(options.runGit ?? defaultGitFileList)(repositoryRoot),
|
||||
)
|
||||
.filter((file) => belongsToRoots(file, trackedRoots))
|
||||
.sort();
|
||||
).sort();
|
||||
for (const root of trackedRoots) {
|
||||
if (!trackedFiles.some((file) => file === root || file.startsWith(`${root}/`))) {
|
||||
throw new Error(`required tracked file inventory is empty: ${root}`);
|
||||
@@ -309,9 +308,16 @@ export async function buildRepositoryFileInventory(
|
||||
}
|
||||
const uniqueTracked = [...trackedFiles].sort();
|
||||
const uniqueGenerated = [...generatedFiles].sort();
|
||||
const trackedSet = new Set(uniqueTracked);
|
||||
const collisions = uniqueGenerated.filter((file) => trackedSet.has(file));
|
||||
if (collisions.length > 0) {
|
||||
throw new TypeError(
|
||||
`tracked and generated inventory paths collide: ${collisions.join(", ")}`,
|
||||
);
|
||||
}
|
||||
return Object.freeze({
|
||||
trackedFiles: Object.freeze(uniqueTracked),
|
||||
generatedFiles: Object.freeze(uniqueGenerated),
|
||||
files: Object.freeze([...new Set([...uniqueTracked, ...uniqueGenerated])].sort()),
|
||||
files: Object.freeze([...uniqueTracked, ...uniqueGenerated].sort()),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user