@ankhorage/paradox 0.2.3 → 0.2.4
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/CHANGELOG.md +6 -0
- package/dist/analyze/analyze.js +2 -1
- package/dist/analyze/documentation/collectDocumentationCommentsAsync.js +2 -7
- package/dist/analyze/exports.js +2 -7
- package/dist/analyze/modules.js +5 -10
- package/dist/analyze/readmeConfig.js +2 -7
- package/dist/analyze/readmeUsage.js +2 -7
- package/dist/analyze/semantic/createTypeScriptProgram.js +2 -2
- package/dist/analyze/semantic/utils.d.ts +0 -1
- package/dist/analyze/semantic/utils.js +3 -5
- package/dist/analyze/sequenceScenarios.js +3 -2
- package/dist/analyze/sourceFunctions.js +3 -8
- package/dist/analyze/utils/getExportMetadata.js +3 -8
- package/dist/analyze/utils/normalizeTypeText.js +3 -5
- package/dist/paths/policy.js +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/analyze/analyze.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { resolvePolicyStatus } from '@ankhorage/policy/status';
|
|
4
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
4
5
|
import { validateCollaborators } from '../config/utils/validateCollaborators.js';
|
|
5
6
|
import { validateDonationAccount } from '../config/utils/validateDonationAccount.js';
|
|
6
7
|
import { analyzeBadges } from './badges.js';
|
|
@@ -72,7 +73,7 @@ export async function analyze(config, runtime) {
|
|
|
72
73
|
exports,
|
|
73
74
|
components,
|
|
74
75
|
sourceFunctions,
|
|
75
|
-
entrypoints: entrypoints.map(
|
|
76
|
+
entrypoints: entrypoints.map(toPortablePath).sort(),
|
|
76
77
|
modules,
|
|
77
78
|
badges,
|
|
78
79
|
sequenceScenarios,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readdir, readFile } from 'node:fs/promises';
|
|
2
2
|
import { extname, join, relative } from 'node:path';
|
|
3
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
3
4
|
import { parseParadoxComment } from '../utils/parseParadoxComment.js';
|
|
4
5
|
const SOURCE_EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.json5']);
|
|
5
6
|
const SCANNED_ROOTS = ['src', 'examples'];
|
|
@@ -47,7 +48,7 @@ async function collectRootSourceFilesAsync(root) {
|
|
|
47
48
|
*/
|
|
48
49
|
async function collectFileCommentsAsync(root, filePath) {
|
|
49
50
|
const source = await readFile(filePath, 'utf-8');
|
|
50
|
-
const sourcePath =
|
|
51
|
+
const sourcePath = toPortablePath(relative(root, filePath));
|
|
51
52
|
return [...source.matchAll(COMMENT_PATTERN)].map((match) => {
|
|
52
53
|
const [raw] = match;
|
|
53
54
|
return {
|
|
@@ -64,9 +65,3 @@ async function collectFileCommentsAsync(root, filePath) {
|
|
|
64
65
|
function isMissingPathError(error) {
|
|
65
66
|
return error instanceof Error && 'code' in error && error.code === 'ENOENT';
|
|
66
67
|
}
|
|
67
|
-
/***
|
|
68
|
-
* Normalizes filesystem separators for stable documentation paths.
|
|
69
|
-
*/
|
|
70
|
-
function toPosixPath(path) {
|
|
71
|
-
return path.replaceAll('\\', '/');
|
|
72
|
-
}
|
package/dist/analyze/exports.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isAbsolute, join, normalize, relative } from 'node:path';
|
|
2
2
|
import { uniqueSortedStrings } from '@ankhorage/utility/array';
|
|
3
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
3
4
|
import { Node } from 'ts-morph';
|
|
4
5
|
import { getExportMetadata } from './utils/getExportMetadata.js';
|
|
5
6
|
import { getParadoxComment } from './utils/getParadoxComment.js';
|
|
@@ -12,7 +13,7 @@ export function analyzeExports(project, options) {
|
|
|
12
13
|
const exportsByName = new Map();
|
|
13
14
|
let config = null;
|
|
14
15
|
for (const sourceFile of getEntryPointSourceFiles(project, options)) {
|
|
15
|
-
const entrypointPath =
|
|
16
|
+
const entrypointPath = toPortablePath(relative(options.root, sourceFile.getFilePath()));
|
|
16
17
|
const exported = sourceFile.getExportSymbols();
|
|
17
18
|
for (const symbol of exported) {
|
|
18
19
|
const resolved = resolveExportSymbol(symbol);
|
|
@@ -107,12 +108,6 @@ function inferKind(node) {
|
|
|
107
108
|
return 'value';
|
|
108
109
|
return 'unknown';
|
|
109
110
|
}
|
|
110
|
-
/***
|
|
111
|
-
* Normalizes platform-specific path separators for generated documentation output.
|
|
112
|
-
*/
|
|
113
|
-
function toPosixPath(path) {
|
|
114
|
-
return path.replaceAll('\\', '/');
|
|
115
|
-
}
|
|
116
111
|
/***
|
|
117
112
|
* Creates empty documentation metadata for exports without Paradox comments.
|
|
118
113
|
*/
|
package/dist/analyze/modules.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isAbsolute, join, normalize, relative } from 'node:path';
|
|
2
2
|
import { uniqueSortedStrings } from '@ankhorage/utility/array';
|
|
3
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
3
4
|
/***
|
|
4
5
|
* Builds a deterministic module relationship graph for documentation renderers.
|
|
5
6
|
*/
|
|
@@ -11,14 +12,14 @@ export function analyzeModules(project, options) {
|
|
|
11
12
|
.getSourceFiles()
|
|
12
13
|
.filter((sourceFile) => {
|
|
13
14
|
const filePath = normalize(sourceFile.getFilePath());
|
|
14
|
-
const normalizedPath =
|
|
15
|
+
const normalizedPath = toPortablePath(filePath);
|
|
15
16
|
return (!sourceFile.isDeclarationFile() &&
|
|
16
17
|
filePath.startsWith(rootPath) &&
|
|
17
18
|
!excludedPaths.has(filePath) &&
|
|
18
19
|
!normalizedPath.includes('/node_modules/'));
|
|
19
20
|
})
|
|
20
21
|
.map((sourceFile) => {
|
|
21
|
-
const path =
|
|
22
|
+
const path = toPortablePath(relative(options.root, sourceFile.getFilePath()));
|
|
22
23
|
const dependencies = sourceFile
|
|
23
24
|
.getImportDeclarations()
|
|
24
25
|
.map((declaration) => declaration.getModuleSpecifierSourceFile())
|
|
@@ -26,8 +27,8 @@ export function analyzeModules(project, options) {
|
|
|
26
27
|
.map((dependency) => normalize(dependency.getFilePath()))
|
|
27
28
|
.filter((dependency) => dependency.startsWith(rootPath) &&
|
|
28
29
|
!excludedPaths.has(dependency) &&
|
|
29
|
-
!
|
|
30
|
-
.map((dependency) =>
|
|
30
|
+
!toPortablePath(dependency).includes('/node_modules/'))
|
|
31
|
+
.map((dependency) => toPortablePath(relative(options.root, dependency)));
|
|
31
32
|
const exports = sourceFile
|
|
32
33
|
.getExportSymbols()
|
|
33
34
|
.map((symbol) => symbol.getName())
|
|
@@ -41,9 +42,3 @@ export function analyzeModules(project, options) {
|
|
|
41
42
|
})
|
|
42
43
|
.sort((left, right) => left.path.localeCompare(right.path));
|
|
43
44
|
}
|
|
44
|
-
/***
|
|
45
|
-
* Normalizes platform-specific path separators for generated documentation output.
|
|
46
|
-
*/
|
|
47
|
-
function toPosixPath(path) {
|
|
48
|
-
return path.replaceAll('\\', '/');
|
|
49
|
-
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { extname, relative } from 'node:path';
|
|
3
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
3
4
|
/***
|
|
4
5
|
* Collects the concrete Paradox configuration instance as a README configuration example.
|
|
5
6
|
*/
|
|
@@ -7,7 +8,7 @@ export async function analyzeReadmeConfig(options) {
|
|
|
7
8
|
if (options.configFilePath === null)
|
|
8
9
|
return null;
|
|
9
10
|
const source = await readFile(options.configFilePath, 'utf-8');
|
|
10
|
-
const sourcePath =
|
|
11
|
+
const sourcePath = toPortablePath(relative(options.root, options.configFilePath));
|
|
11
12
|
return {
|
|
12
13
|
language: getLanguage(sourcePath),
|
|
13
14
|
code: source.trim(),
|
|
@@ -25,9 +26,3 @@ function getLanguage(sourcePath) {
|
|
|
25
26
|
return 'js';
|
|
26
27
|
return '';
|
|
27
28
|
}
|
|
28
|
-
/***
|
|
29
|
-
* Normalizes filesystem separators for stable documentation paths.
|
|
30
|
-
*/
|
|
31
|
-
function toPosixPath(path) {
|
|
32
|
-
return path.replaceAll('\\', '/');
|
|
33
|
-
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readdir } from 'node:fs/promises';
|
|
2
2
|
import { extname, join, relative } from 'node:path';
|
|
3
3
|
import { DOCUMENTATION_POLICY } from '@ankhorage/policy/documentation';
|
|
4
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
4
5
|
import { Project } from 'ts-morph';
|
|
5
6
|
import { getParadoxComment } from './utils/getParadoxComment.js';
|
|
6
7
|
import { parseParadoxComment } from './utils/parseParadoxComment.js';
|
|
@@ -41,7 +42,7 @@ async function collectSourceFilesAsync(root) {
|
|
|
41
42
|
*/
|
|
42
43
|
function analyzeUsageFile(root, project, filePath) {
|
|
43
44
|
const sourceFile = project.getSourceFile(filePath) ?? project.addSourceFileAtPath(filePath);
|
|
44
|
-
const sourcePath =
|
|
45
|
+
const sourcePath = toPortablePath(relative(root, filePath));
|
|
45
46
|
return sourceFile.getStatements().flatMap((statement) => {
|
|
46
47
|
const comment = getParadoxComment(statement);
|
|
47
48
|
if (comment === null)
|
|
@@ -140,9 +141,3 @@ function isMissingPathError(error) {
|
|
|
140
141
|
typeof error.code === 'string' &&
|
|
141
142
|
error.code === 'ENOENT');
|
|
142
143
|
}
|
|
143
|
-
/***
|
|
144
|
-
* Normalizes filesystem separators for stable documentation paths.
|
|
145
|
-
*/
|
|
146
|
-
function toPosixPath(path) {
|
|
147
|
-
return path.replaceAll('\\', '/');
|
|
148
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAbsolute, join, normalize } from 'node:path';
|
|
2
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
2
3
|
import { Project } from 'ts-morph';
|
|
3
|
-
import { toPosixPath } from './utils.js';
|
|
4
4
|
/***
|
|
5
5
|
* Creates or reuses a ts-morph project for analysis.
|
|
6
6
|
*/
|
|
@@ -17,7 +17,7 @@ export function createTypeScriptProgram(options) {
|
|
|
17
17
|
project,
|
|
18
18
|
typeChecker: project.getTypeChecker(),
|
|
19
19
|
root,
|
|
20
|
-
entrypoints: entrypoints.map((entrypoint) =>
|
|
20
|
+
entrypoints: entrypoints.map((entrypoint) => toPortablePath(entrypoint)),
|
|
21
21
|
entrypointFilePaths,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare function toPosixPath(path: string): string;
|
|
2
1
|
export declare function relativeToRoot(root: string, filePath: string): string;
|
|
3
2
|
export declare function isPathInsideRoot(root: string, filePath: string): boolean;
|
|
4
3
|
export declare function isNodeModulePath(filePath: string): boolean;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { normalize, relative } from 'node:path';
|
|
2
|
-
|
|
3
|
-
return path.replaceAll('\\', '/');
|
|
4
|
-
}
|
|
2
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
5
3
|
export function relativeToRoot(root, filePath) {
|
|
6
|
-
return
|
|
4
|
+
return toPortablePath(relative(root, filePath));
|
|
7
5
|
}
|
|
8
6
|
export function isPathInsideRoot(root, filePath) {
|
|
9
7
|
return normalize(filePath).startsWith(normalize(root));
|
|
10
8
|
}
|
|
11
9
|
export function isNodeModulePath(filePath) {
|
|
12
|
-
return
|
|
10
|
+
return toPortablePath(filePath).includes('/node_modules/');
|
|
13
11
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isAbsolute, join, normalize } from 'node:path';
|
|
2
2
|
import { uniqueSortedStrings } from '@ankhorage/utility/array';
|
|
3
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
3
4
|
import { Node as MorphNode, } from 'ts-morph';
|
|
4
|
-
import { relativeToRoot
|
|
5
|
+
import { relativeToRoot } from './semantic/utils.js';
|
|
5
6
|
import { getParadoxComment } from './utils/getParadoxComment.js';
|
|
6
7
|
import { parseParadoxComment } from './utils/parseParadoxComment.js';
|
|
7
8
|
/***
|
|
@@ -73,7 +74,7 @@ function resolveBinSourceFile(project, root, targetPath) {
|
|
|
73
74
|
return null;
|
|
74
75
|
}
|
|
75
76
|
function getBinSourceCandidates(targetPath) {
|
|
76
|
-
const normalized =
|
|
77
|
+
const normalized = toPortablePath(targetPath).replace(/^\.\//, '');
|
|
77
78
|
const candidates = [];
|
|
78
79
|
if (/^src\/.*\.tsx?$/.test(normalized)) {
|
|
79
80
|
candidates.push(normalized);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { relative } from 'node:path';
|
|
2
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
2
3
|
import { Node } from 'ts-morph';
|
|
3
4
|
import { getParadoxComment } from './utils/getParadoxComment.js';
|
|
4
5
|
import { parseParadoxComment } from './utils/parseParadoxComment.js';
|
|
@@ -11,7 +12,7 @@ export function analyzeSourceFunctions(project, root) {
|
|
|
11
12
|
.flatMap((sourceFile) => {
|
|
12
13
|
if (sourceFile.isDeclarationFile())
|
|
13
14
|
return [];
|
|
14
|
-
const filePath =
|
|
15
|
+
const filePath = toPortablePath(relative(root, sourceFile.getFilePath()));
|
|
15
16
|
if (!filePath.startsWith('src/'))
|
|
16
17
|
return [];
|
|
17
18
|
return sourceFile.getDescendants().flatMap((node) => {
|
|
@@ -50,15 +51,9 @@ function createSourceFunction(name, node, root) {
|
|
|
50
51
|
see: parsedComment?.see ?? [],
|
|
51
52
|
security: parsedComment?.security ?? [],
|
|
52
53
|
sourceLocation: {
|
|
53
|
-
filePath:
|
|
54
|
+
filePath: toPortablePath(relative(root, sourceFile.getFilePath())),
|
|
54
55
|
line,
|
|
55
56
|
column,
|
|
56
57
|
},
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
|
-
/***
|
|
60
|
-
* Normalizes platform-specific path separators for generated documentation output.
|
|
61
|
-
*/
|
|
62
|
-
function toPosixPath(path) {
|
|
63
|
-
return path.replaceAll('\\', '/');
|
|
64
|
-
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { relative } from 'node:path';
|
|
2
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
2
3
|
import { Node, } from 'ts-morph';
|
|
3
4
|
import { getParadoxComment } from './getParadoxComment.js';
|
|
4
5
|
import { normalizeTypeText } from './normalizeTypeText.js';
|
|
@@ -7,7 +8,7 @@ import { parseParadoxComment } from './parseParadoxComment.js';
|
|
|
7
8
|
* Extracts computed metadata for an exported declaration.
|
|
8
9
|
*/
|
|
9
10
|
export function getExportMetadata(options) {
|
|
10
|
-
const modulePath =
|
|
11
|
+
const modulePath = toPortablePath(relative(options.root, options.node.getSourceFile().getFilePath()));
|
|
11
12
|
const sourceLocation = getSourceLocation(options.node, options.root);
|
|
12
13
|
const signatures = getSignatures(options.symbol, options.node, options.root);
|
|
13
14
|
const members = getMembers(options.node, options.root);
|
|
@@ -33,7 +34,7 @@ function getSourceLocation(node, root) {
|
|
|
33
34
|
const sourceFile = node.getSourceFile();
|
|
34
35
|
const { column, line } = sourceFile.getLineAndColumnAtPos(node.getStart(false));
|
|
35
36
|
return {
|
|
36
|
-
filePath:
|
|
37
|
+
filePath: toPortablePath(relative(root, sourceFile.getFilePath())),
|
|
37
38
|
line,
|
|
38
39
|
column,
|
|
39
40
|
};
|
|
@@ -259,12 +260,6 @@ function collectRelatedSymbols(exportName, ...values) {
|
|
|
259
260
|
}
|
|
260
261
|
return [...related].sort((left, right) => left.localeCompare(right));
|
|
261
262
|
}
|
|
262
|
-
/***
|
|
263
|
-
* Normalizes platform-specific path separators for generated documentation output.
|
|
264
|
-
*/
|
|
265
|
-
function toPosixPath(path) {
|
|
266
|
-
return path.replaceAll('\\', '/');
|
|
267
|
-
}
|
|
268
263
|
/***
|
|
269
264
|
* Returns unique items by a caller-provided key while preserving first occurrence order.
|
|
270
265
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
1
2
|
/***
|
|
2
3
|
* Removes machine-specific absolute paths from TypeScript import type text.
|
|
3
4
|
*/
|
|
@@ -13,7 +14,7 @@ export function normalizeTypeText(typeText, packageRoot) {
|
|
|
13
14
|
return normalized + typeText.slice(cursor);
|
|
14
15
|
}
|
|
15
16
|
function normalizeImportPath(importPath, packageRoot) {
|
|
16
|
-
const normalizedPath =
|
|
17
|
+
const normalizedPath = toPortablePath(importPath);
|
|
17
18
|
const nodeModulesMarker = '/node_modules/';
|
|
18
19
|
const nodeModulesIndex = normalizedPath.lastIndexOf(nodeModulesMarker);
|
|
19
20
|
if (nodeModulesIndex >= 0) {
|
|
@@ -22,12 +23,9 @@ function normalizeImportPath(importPath, packageRoot) {
|
|
|
22
23
|
if (normalizedPath.startsWith('node_modules/')) {
|
|
23
24
|
return normalizedPath.slice('node_modules/'.length);
|
|
24
25
|
}
|
|
25
|
-
const normalizedRoot = packageRoot ?
|
|
26
|
+
const normalizedRoot = packageRoot ? toPortablePath(packageRoot).replace(/\/$/, '') : null;
|
|
26
27
|
if (normalizedRoot && normalizedPath.startsWith(`${normalizedRoot}/`)) {
|
|
27
28
|
return `./${normalizedPath.slice(normalizedRoot.length + 1)}`;
|
|
28
29
|
}
|
|
29
30
|
return normalizedPath;
|
|
30
31
|
}
|
|
31
|
-
function toPosixPath(value) {
|
|
32
|
-
return value.replaceAll('\\', '/');
|
|
33
|
-
}
|
package/dist/paths/policy.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { access } from 'node:fs/promises';
|
|
2
2
|
import { dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { toPortablePath } from '@ankhorage/utility/node/path';
|
|
4
5
|
const CONFIG_FILENAMES = [
|
|
5
6
|
'paradox.config.ts',
|
|
6
7
|
'paradox.config.js',
|
|
@@ -105,7 +106,7 @@ function validateOutputDir(outputDir) {
|
|
|
105
106
|
* Splits a configured path into normalized non-empty path segments.
|
|
106
107
|
*/
|
|
107
108
|
function splitPathSegments(path) {
|
|
108
|
-
const normalized = path
|
|
109
|
+
const normalized = toPortablePath(path);
|
|
109
110
|
return normalized.split('/').filter((segment) => segment.length > 0 && segment !== '.');
|
|
110
111
|
}
|
|
111
112
|
/***
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/paradox",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Deterministic documentation generator for TypeScript packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@ankhorage/policy": "^0.3.1",
|
|
75
|
-
"@ankhorage/utility": "^1.8.
|
|
75
|
+
"@ankhorage/utility": "^1.8.1",
|
|
76
76
|
"ts-morph": "^28.0.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|