specthread 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checks/links.js +4 -3
- package/dist/gen/references.js +10 -5
- package/dist/utils/scan.d.ts +6 -2
- package/dist/utils/scan.js +3 -1
- package/package.json +1 -1
package/dist/checks/links.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RULE } from '../constants/rules.js';
|
|
2
2
|
/** 링크 유효성 - 대상 파일이 있는가, 앵커가 실제 헤딩을 가리키는가. */
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
|
-
import { join, dirname, normalize } from 'node:path';
|
|
5
|
-
import { REPO_ROOT } from '../utils/scan.js';
|
|
4
|
+
import { join, dirname, extname, normalize } from 'node:path';
|
|
5
|
+
import { REPO_ROOT, docExtSet } from '../utils/scan.js';
|
|
6
6
|
import { inChangeLog, inRefSection, isTargetDoc } from '../utils/scope.js';
|
|
7
7
|
/** 외부 링크는 파일 시스템에 없으니 확인하지 않는다 */
|
|
8
8
|
const isExternal = (target) => /^(https?:|mailto:)/.test(target);
|
|
@@ -14,6 +14,7 @@ const isExternal = (target) => /^(https?:|mailto:)/.test(target);
|
|
|
14
14
|
*/
|
|
15
15
|
export const checkLinks = (index) => {
|
|
16
16
|
const findings = [];
|
|
17
|
+
const docExts = docExtSet(index.config.fileKinds);
|
|
17
18
|
for (const file of index.files.values()) {
|
|
18
19
|
if (!isTargetDoc(file, index.config))
|
|
19
20
|
continue;
|
|
@@ -47,7 +48,7 @@ export const checkLinks = (index) => {
|
|
|
47
48
|
});
|
|
48
49
|
continue;
|
|
49
50
|
}
|
|
50
|
-
if (!link.anchor || !rel.
|
|
51
|
+
if (!link.anchor || !docExts.has(extname(rel).toLowerCase()))
|
|
51
52
|
continue;
|
|
52
53
|
const target = index.files.get(rel);
|
|
53
54
|
// 색인 범위 밖 문서 (archive 등) 는 앵커를 확인하지 않는다
|
package/dist/gen/references.js
CHANGED
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
* 불러 지금 내용과 비교한다. 검사기가 생성기를 부르는 것이 거꾸로 보이지만,
|
|
14
14
|
* _무엇이 옳은 내용인가_ 를 한곳에서만 정의하려면 이 방향이 맞다.
|
|
15
15
|
*/
|
|
16
|
-
import { basename, dirname, join, normalize } from "node:path";
|
|
16
|
+
import { basename, dirname, extname, join, normalize } from "node:path";
|
|
17
|
+
import { docExtSet } from "../utils/scan.js";
|
|
17
18
|
import { wantsRefSection } from "../utils/scope.js";
|
|
18
|
-
/** 코드·데이터 대상인지.
|
|
19
|
-
const isCode = (path) =>
|
|
19
|
+
/** 코드·데이터 대상인지. doc 확장자가 아니고 디렉터리도 아니면 코드로 본다 */
|
|
20
|
+
const isCode = (path, docExts) => {
|
|
21
|
+
const ext = extname(path).toLowerCase();
|
|
22
|
+
return ext !== "" && !docExts.has(ext);
|
|
23
|
+
};
|
|
20
24
|
/**
|
|
21
25
|
* 링크 대상의 리포 루트 기준 위치. 같은 파일 이름이 겹칠 때 라벨로 쓴다.
|
|
22
26
|
*
|
|
@@ -96,8 +100,9 @@ export const referenceBlock = (file, config) => {
|
|
|
96
100
|
return [];
|
|
97
101
|
const label = labels(file.path, targets);
|
|
98
102
|
const render = (list) => list.map((t) => line(t, label.get(t.path) ?? t.path));
|
|
99
|
-
const
|
|
100
|
-
const
|
|
103
|
+
const exts = docExtSet(config.fileKinds);
|
|
104
|
+
const docs = targets.filter((t) => !isCode(t.path, exts));
|
|
105
|
+
const code = targets.filter((t) => isCode(t.path, exts));
|
|
101
106
|
const out = [""];
|
|
102
107
|
// 비는 갈래는 제목도 내지 않는다. 빈 제목만 남으면 아직 안 채운 것처럼 읽힌다
|
|
103
108
|
if (docs.length > 0)
|
package/dist/utils/scan.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { DocIndex } from "../types.ts";
|
|
2
|
-
import type { SpecthreadConfig } from "../config.schema.ts";
|
|
1
|
+
import type { DocIndex, FileKind } from "../types.ts";
|
|
2
|
+
import type { FileKindsConfig, SpecthreadConfig } from "../config.schema.ts";
|
|
3
3
|
/** 프로젝트 루트 절대 경로. 색인 경로를 여기 기준 상대 경로로 통일하는 데 쓴다 */
|
|
4
4
|
export declare const REPO_ROOT: string;
|
|
5
|
+
/** config.fileKinds 에서 확장자 → kind 역매핑을 만든다 */
|
|
6
|
+
export declare const buildExtMap: (kinds: FileKindsConfig) => Map<string, FileKind>;
|
|
7
|
+
/** doc 확장자 Set. 링크 대상이 문서인지 판정할 때 쓴다 */
|
|
8
|
+
export declare const docExtSet: (kinds: FileKindsConfig) => Set<string>;
|
|
5
9
|
/**
|
|
6
10
|
* 색인을 만든다. 검사기와 생성기의 유일한 입력이다.
|
|
7
11
|
*
|
package/dist/utils/scan.js
CHANGED
|
@@ -11,7 +11,7 @@ import { makeRefContext, parseSectionRefs } from "./resolve.js";
|
|
|
11
11
|
/** 프로젝트 루트 절대 경로. 색인 경로를 여기 기준 상대 경로로 통일하는 데 쓴다 */
|
|
12
12
|
export const REPO_ROOT = normalize(process.cwd());
|
|
13
13
|
/** config.fileKinds 에서 확장자 → kind 역매핑을 만든다 */
|
|
14
|
-
const buildExtMap = (kinds) => {
|
|
14
|
+
export const buildExtMap = (kinds) => {
|
|
15
15
|
const map = new Map();
|
|
16
16
|
for (const ext of kinds.doc)
|
|
17
17
|
map.set(ext.toLowerCase(), "doc");
|
|
@@ -19,6 +19,8 @@ const buildExtMap = (kinds) => {
|
|
|
19
19
|
map.set(ext.toLowerCase(), "source");
|
|
20
20
|
return map;
|
|
21
21
|
};
|
|
22
|
+
/** doc 확장자 Set. 링크 대상이 문서인지 판정할 때 쓴다 */
|
|
23
|
+
export const docExtSet = (kinds) => new Set(kinds.doc.map((e) => e.toLowerCase()));
|
|
22
24
|
/** 확장자로 파일 종류를 결정한다. config.fileKinds 기반 */
|
|
23
25
|
const kindFromPath = (file, extMap) => {
|
|
24
26
|
const dot = file.lastIndexOf(".");
|