Skip to content

Commit 98aa9ff

Browse files
committed
normalize supporting files from executeResult
1 parent 14d53b2 commit 98aa9ff

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/command/render/project.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,8 @@ export async function renderProject(
255255
);
256256

257257
if (outputDirAbsolute) {
258-
const handledDirs: string[] = [];
259258
// move or copy dir
260259
const relocateDir = (dir: string, copy = false) => {
261-
// ignore directories if they're prefixes of
262-
// previously-handled directories
263-
if (handledDirs.some((prevDir) => dir.startsWith(prevDir))) {
264-
console.log(`Skipping ${dir}.`);
265-
return;
266-
}
267-
handledDirs.push(dir);
268260
const targetDir = join(outputDirAbsolute, dir);
269261
if (existsSync(targetDir)) {
270262
Deno.removeSync(targetDir, { recursive: true });

src/command/render/render-files.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*
66
*/
77

8+
import { existsSync } from "fs/exists.ts";
9+
810
// ensures cell handlers are installed
911
import "../../core/handlers/handlers.ts";
1012

@@ -56,7 +58,7 @@ import {
5658
} from "./types.ts";
5759
import { error, info } from "log/mod.ts";
5860
import * as ld from "../../core/lodash.ts";
59-
import { basename, dirname, join, relative } from "path/mod.ts";
61+
import { basename, dirname, isAbsolute, join, relative } from "path/mod.ts";
6062
import { Format } from "../../config/types.ts";
6163
import { figuresDir, inputFilesDir } from "../../core/render.ts";
6264
import { removeIfEmptyDir, removeIfExists } from "../../core/path.ts";
@@ -417,6 +419,13 @@ export async function renderFiles(
417419
);
418420
resourceFiles.push(...ojsResourceFiles);
419421

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+
420429
// keep md if requested
421430
const keepMd = executionEngineKeepMd(context.target.input);
422431
if (keepMd && context.format.execute[kKeepMd]) {
@@ -486,3 +495,27 @@ class RenderInvalidYAMLError extends YAMLValidationError {
486495
super("Render failed due to invalid YAML.");
487496
}
488497
}
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)