From 9f0fb048399c7a1273dc452d01cca92b34f4675b Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Tue, 25 Jun 2024 19:22:54 -0600 Subject: [PATCH] Do not copy relative paths to directories Resolves #2617 --- CHANGELOG.md | 1 + src/lib/converter/comments/textParser.ts | 2 +- src/lib/internationalization/locales/jp.cts | 5 ++--- src/lib/internationalization/locales/zh.cts | 5 ++--- src/lib/internationalization/translatable.ts | 16 ++++++++-------- src/lib/models/FileRegistry.ts | 9 ++++----- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3321c0d42..b0d895c39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - `mailto:` links are no longer incorrectly recognized as relative paths, #2613. - Added `@since` to the default list of recognized tags, #2614. +- Relative paths to directories will no longer cause the directory to be copied into the media directory, #2617. ## v0.26.2 (2024-06-24) diff --git a/src/lib/converter/comments/textParser.ts b/src/lib/converter/comments/textParser.ts index 3fd836aa4..4662de653 100644 --- a/src/lib/converter/comments/textParser.ts +++ b/src/lib/converter/comments/textParser.ts @@ -101,7 +101,7 @@ export function textContent( data.pos = ref.end; if (!ref.target) { warning( - i18n.relative_path_0_does_not_exist( + i18n.relative_path_0_is_not_a_file_and_will_not_be_copied_to_output( token.text.slice(ref.pos, ref.end), ), { diff --git a/src/lib/internationalization/locales/jp.cts b/src/lib/internationalization/locales/jp.cts index 7145893c8..d7ffd796f 100644 --- a/src/lib/internationalization/locales/jp.cts +++ b/src/lib/internationalization/locales/jp.cts @@ -59,7 +59,7 @@ export = buildIncompleteTranslation({ "TypeDoc は、コメント付きの単一の @template タグで定義された複数の型パラメータをサポートしていません。", failed_to_find_jsdoc_tag_for_name_0: "コメントを解析した後、{0} の JSDoc タグが見つかりませんでした。バグレポートを提出してください。", - relative_path_0_does_not_exist: "相対パス {0} は存在しません", + // relative_path_0_is_not_a_file_and_will_not_be_copied_to_output inline_inheritdoc_should_not_appear_in_block_tag_in_comment_at_0: "インライン @inheritDoc タグはブロック タグ内に出現しないでください。{0} のコメントでは処理されません。", at_most_one_remarks_tag_expected_in_comment_at_0: @@ -169,8 +169,7 @@ export = buildIncompleteTranslation({ file_0_not_an_object: "ファイル {0} はオブジェクトではありません", serialized_project_referenced_0_not_part_of_project: "シリアル化されたプロジェクトは、プロジェクトの一部ではないリフレクション {0} を参照しました", - saved_relative_path_0_resolved_from_1_does_not_exist: - "シリアル化されたプロジェクトは {0} を参照していますが、{1} に関連して存在しません", + // saved_relative_path_0_resolved_from_1_is_not_a_file circular_reference_extends_0: '{0} の "extends" フィールドで循環参照が検出されました', failed_resolve_0_to_file_in_1: diff --git a/src/lib/internationalization/locales/zh.cts b/src/lib/internationalization/locales/zh.cts index fd1e5d51b..4692daf80 100644 --- a/src/lib/internationalization/locales/zh.cts +++ b/src/lib/internationalization/locales/zh.cts @@ -52,7 +52,7 @@ export = buildIncompleteTranslation({ "TypeDoc 不支持在带有注释的单个 @template 标记中定义多个类型参数", failed_to_find_jsdoc_tag_for_name_0: "解析注释后无法找到 {0} 的 JSDoc 标签,请提交错误报告", - relative_path_0_does_not_exist: "相对路径 {0} 不存在", + // relative_path_0_is_not_a_file_and_will_not_be_copied_to_output inline_inheritdoc_should_not_appear_in_block_tag_in_comment_at_0: "内联 @inheritDoc 标记不应出现在块标记内,因为它不会在 {0} 处的注释中被处理。", at_most_one_remarks_tag_expected_in_comment_at_0: @@ -145,8 +145,7 @@ export = buildIncompleteTranslation({ file_0_not_an_object: "文件 {0} 不是对象", serialized_project_referenced_0_not_part_of_project: "序列化项目引用了反射 {0},但它不是项目的一部分", - saved_relative_path_0_resolved_from_1_does_not_exist: - "序列化项目引用了 {0},相对于 {1} 而言,它并不存在", + // saved_relative_path_0_resolved_from_1_is_not_a_file circular_reference_extends_0: "{0} 的“extends”字段出现循环引用", failed_resolve_0_to_file_in_1: "无法将 {0} 解析为 {1} 中的文件", option_0_can_only_be_specified_by_config_file: diff --git a/src/lib/internationalization/translatable.ts b/src/lib/internationalization/translatable.ts index 5ddc73174..67fb8fd72 100644 --- a/src/lib/internationalization/translatable.ts +++ b/src/lib/internationalization/translatable.ts @@ -4,15 +4,15 @@ import type { modifierTags, } from "../utils/options/tsdoc-defaults"; -export function buildTranslation< - T extends BuiltinTranslatableStringConstraints, ->(translations: T) { +export function buildTranslation( + translations: BuiltinTranslatableStringConstraints, +) { return translations; } -export function buildIncompleteTranslation< - T extends Partial, ->(translations: T) { +export function buildIncompleteTranslation( + translations: Partial, +) { return translations; } @@ -72,7 +72,7 @@ export const translatable = { // comments/parser.ts multiple_type_parameters_on_template_tag_unsupported: `TypeDoc does not support multiple type parameters defined in a single @template tag with a comment`, failed_to_find_jsdoc_tag_for_name_0: `Failed to find JSDoc tag for {0} after parsing comment, please file a bug report`, - relative_path_0_does_not_exist: `The relative path {0} does not exist`, + relative_path_0_is_not_a_file_and_will_not_be_copied_to_output: `The relative path {0} is not a file and will not be copied to the output directory`, inline_inheritdoc_should_not_appear_in_block_tag_in_comment_at_0: "An inline @inheritDoc tag should not appear within a block tag as it will not be processed in comment at {0}", @@ -159,7 +159,7 @@ export const translatable = { // deserialization serialized_project_referenced_0_not_part_of_project: `Serialized project referenced reflection {0}, which was not a part of the project`, - saved_relative_path_0_resolved_from_1_does_not_exist: `Serialized project referenced {0}, which does not exist relative to {1}`, + saved_relative_path_0_resolved_from_1_is_not_a_file: `Serialized project referenced {0}, which does not exist or is not a file relative to {1}`, // options circular_reference_extends_0: `Circular reference encountered for "extends" field of {0}`, diff --git a/src/lib/models/FileRegistry.ts b/src/lib/models/FileRegistry.ts index e6331547f..cedd8add3 100644 --- a/src/lib/models/FileRegistry.ts +++ b/src/lib/models/FileRegistry.ts @@ -1,8 +1,7 @@ import { basename, dirname, parse, relative, resolve } from "path"; import type { Deserializer, Serializer } from "../serialization"; import type { FileRegistry as JSONFileRegistry } from "../serialization/schema"; -import { normalizePath } from "../utils"; -import { existsSync } from "fs"; +import { isFile, normalizePath } from "../utils"; import type { Reflection } from "./reflections"; export class FileRegistry { @@ -137,7 +136,7 @@ export class ValidatingFileRegistry extends FileRegistry { relativePath: string, ): number | undefined { const absolute = resolve(dirname(sourcePath), relativePath); - if (!existsSync(absolute)) { + if (!isFile(absolute)) { return; } return this.registerAbsolute(absolute); @@ -146,9 +145,9 @@ export class ValidatingFileRegistry extends FileRegistry { override fromObject(de: Deserializer, obj: JSONFileRegistry) { for (const [key, val] of Object.entries(obj.entries)) { const absolute = normalizePath(resolve(de.projectRoot, val)); - if (!existsSync(absolute)) { + if (!isFile(absolute)) { de.logger.warn( - de.logger.i18n.saved_relative_path_0_resolved_from_1_does_not_exist( + de.logger.i18n.saved_relative_path_0_resolved_from_1_is_not_a_file( val, de.projectRoot, ),