Skip to content

Commit 73b3b42

Browse files
committed
filter overlapping paths in supporting files
1 parent 98aa9ff commit 73b3b42

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

src/command/render/project.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ export async function renderProject(
294294
renderedFile.supporting = renderedFile.supporting.filter((file) =>
295295
file !== libDir
296296
);
297+
// ensure that we don't have overlapping paths in supporting
298+
renderedFile.supporting = renderedFile.supporting.filter((file) => {
299+
return !renderedFile.supporting!.some((dir) =>
300+
file.startsWith(dir) && file !== dir
301+
);
302+
});
297303
if (keepFiles) {
298304
renderedFile.supporting.map((file) => copyDir(file));
299305
} else {

src/command/render/render-files.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,6 @@ export async function renderFiles(
419419
);
420420
resourceFiles.push(...ojsResourceFiles);
421421

422-
// now that all execution is done and supportign files have been
423-
// contributed, normalize the supporting files so there is no overlap
424-
executeResult.supporting = normalizeSupporting(
425-
context.target.source,
426-
executeResult.supporting,
427-
);
428-
429422
// keep md if requested
430423
const keepMd = executionEngineKeepMd(context.target.input);
431424
if (keepMd && context.format.execute[kKeepMd]) {
@@ -495,27 +488,3 @@ class RenderInvalidYAMLError extends YAMLValidationError {
495488
super("Render failed due to invalid YAML.");
496489
}
497490
}
498-
499-
function normalizeSupporting(source: string, supporting: string[]): string[] {
500-
// first ensure all paths are absolute and normalized
501-
const dir = dirname(source);
502-
supporting = supporting.map((file) =>
503-
isAbsolute(file) ? file : join(dir, file)
504-
);
505-
506-
// filter on existence
507-
supporting = supporting.filter(existsSync);
508-
509-
// any file that is within another dir in the list is removed
510-
const parentDirs = supporting.filter((file) =>
511-
Deno.statSync(file).isDirectory
512-
);
513-
supporting = supporting.filter((file) =>
514-
!parentDirs.some((parentDir) =>
515-
file.startsWith(parentDir) && file !== parentDir
516-
)
517-
);
518-
519-
// now de-dupe and make all paths relative
520-
return ld.uniq(supporting.map((file) => relative(dir, file)));
521-
}

0 commit comments

Comments
 (0)