Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { fileURLToPath } from "url";
import { createRequire } from "module";
import { Outputs } from "./output/output.js";
import { validateMergeModuleWith } from "./validation/unusedMergeModuleWith.js";
import { validateFilePaths } from "./validation/filePaths.js";
import { diagnostic, diagnostics } from "./utils/loggers.js";
import { ValidatingFileRegistry } from "./utils/ValidatingFileRegistry.js";
import { Internationalization } from "./internationalization/internationalization.js";
Expand Down Expand Up @@ -703,6 +704,10 @@ export class Application extends AbstractComponent<
validateMergeModuleWith(project, this.logger);
}

if (checks.invalidPath) {
validateFilePaths(project, this.logger);
}

this.trigger(Application.EVENT_VALIDATE_PROJECT, project);

this.logger.verbose(`Validation took ${Date.now() - start}ms`);
Expand Down
14 changes: 14 additions & 0 deletions src/lib/models/FileRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ export class FileRegistry {
return this.names.get(id);
}

/**
* Iterate over all registered media file paths, yielding entries
* that do NOT have an associated reflection.
*/
getMediaPaths(): Iterable<NormalizedPath> {
const result: NormalizedPath[] = [];
for (const [id, path] of this.mediaToPath.entries()) {
if (!this.mediaToReflection.has(id)) {
result.push(path);
}
}
return result;
}

getNameToAbsoluteMap(): ReadonlyMap<string, string> {
const result = new Map<string, string>();
for (const [id, name] of this.names.entries()) {
Expand Down
4 changes: 0 additions & 4 deletions src/lib/output/plugins/AssetsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ export class AssetsPlugin extends RendererComponent {
for (const [fileName, absolute] of toCopy.entries()) {
if (isFile(absolute)) {
copySync(absolute, join(media, fileName));
} else {
this.application.logger.warn(
i18n.relative_path_0_is_not_a_file_and_will_not_be_copied_to_output(absolute),
);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/lib/validation/filePaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ProjectReflection } from "../models/index.js";
import { i18n, type Logger } from "#utils";
import { isFile } from "../utils/fs.js";

export function validateFilePaths(
project: ProjectReflection,
logger: Logger,
): void {
for (const absolute of project.files.getMediaPaths()) {
if (!isFile(absolute)) {
logger.validationWarning(
i18n.relative_path_0_is_not_a_file_and_will_not_be_copied_to_output(absolute),
);
}
}
}
46 changes: 46 additions & 0 deletions src/test/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { ok } from "assert";
import { join } from "path";
import { validateDocumentation } from "../lib/validation/documentation.js";
import { validateExports } from "../lib/validation/exports.js";
import { validateFilePaths } from "../lib/validation/filePaths.js";
import { getConverter2App, getConverter2Program, getConverter2Project } from "./programs.js";
import { TestLogger } from "./TestLogger.js";
import { fileURLToPath } from "url";
import { validateMergeModuleWith } from "../lib/validation/unusedMergeModuleWith.js";
import { normalizePath } from "#node-utils";

function convertValidationFile(...files: [string, ...string[]]) {
return getConverter2Project(files, "validation");
Expand Down Expand Up @@ -233,3 +235,47 @@ describe("validateMergeModuleWith", () => {
);
});
});

describe("validateFilePaths", () => {
it("Should warn if a registered path is a directory", () => {
const project = convertValidationFile("variable.ts");
// Register a directory path (the converter2 directory itself) without a reflection association
const dirPath = normalizePath(
join(fileURLToPath(import.meta.url), "../converter2"),
);
project.files.registerAbsolute(dirPath);

const logger = new TestLogger();
validateFilePaths(project, logger);

logger.expectMessage(
`warn: The relative path ${dirPath} is not a file and will not be copied to the output directory`,
);
});

it("Should not warn for registered files", () => {
const project = convertValidationFile("variable.ts");
const filePath = normalizePath(
join(fileURLToPath(import.meta.url), "../converter2/validation/variable.ts"),
);
project.files.registerAbsolute(filePath);

const logger = new TestLogger();
validateFilePaths(project, logger);

logger.expectNoOtherMessages();
});

it("Should not warn for directories with a reflection association", () => {
const project = convertValidationFile("variable.ts");
const dirPath = normalizePath(
join(fileURLToPath(import.meta.url), "../converter2"),
);
project.files.registerReflectionPath(dirPath, project);

const logger = new TestLogger();
validateFilePaths(project, logger);

logger.expectNoOtherMessages();
});
});
Loading