@ankhorage/paradox 0.0.2 → 0.0.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +9 -0
  3. package/dist/analyze/analyze.d.ts +8 -0
  4. package/dist/analyze/analyze.js +34 -0
  5. package/dist/analyze/components.d.ts +5 -0
  6. package/dist/analyze/components.js +21 -0
  7. package/dist/analyze/exports.d.ts +16 -0
  8. package/dist/analyze/exports.js +52 -0
  9. package/dist/analyze/project.d.ts +5 -0
  10. package/dist/analyze/project.js +10 -0
  11. package/dist/analyze/types.d.ts +45 -0
  12. package/dist/analyze/types.js +1 -0
  13. package/dist/analyze/usage.d.ts +7 -0
  14. package/dist/analyze/usage.js +40 -0
  15. package/dist/analyze/utils/getComponentPropsType.d.ts +5 -0
  16. package/dist/analyze/utils/getComponentPropsType.js +21 -0
  17. package/dist/analyze/utils/getParadoxComment.d.ts +5 -0
  18. package/dist/analyze/utils/getParadoxComment.js +19 -0
  19. package/dist/analyze/utils/getPropsFromType.d.ts +6 -0
  20. package/dist/analyze/utils/getPropsFromType.js +19 -0
  21. package/dist/analyze/utils/isReactComponent.d.ts +5 -0
  22. package/dist/analyze/utils/isReactComponent.js +30 -0
  23. package/dist/analyze/utils/parseParadoxComment.d.ts +12 -0
  24. package/dist/analyze/utils/parseParadoxComment.js +25 -0
  25. package/{src/analyze/utils/resolveExportSymbol.ts → dist/analyze/utils/resolveExportSymbol.d.ts} +1 -4
  26. package/dist/analyze/utils/resolveExportSymbol.js +6 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +26 -0
  29. package/{src/config/defineParadoxConfig.ts → dist/config/defineParadoxConfig.d.ts} +1 -4
  30. package/dist/config/defineParadoxConfig.js +6 -0
  31. package/dist/config/types.d.ts +19 -0
  32. package/dist/config/types.js +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/model/buildModel.d.ts +36 -0
  35. package/dist/model/buildModel.js +65 -0
  36. package/dist/model/types.d.ts +42 -0
  37. package/dist/model/types.js +1 -0
  38. package/dist/paths/policy.d.ts +23 -0
  39. package/dist/paths/policy.js +105 -0
  40. package/dist/render/render.d.ts +6 -0
  41. package/dist/render/render.js +95 -0
  42. package/dist/render/types.d.ts +10 -0
  43. package/dist/render/types.js +1 -0
  44. package/dist/write/write.d.ts +9 -0
  45. package/dist/write/write.js +18 -0
  46. package/package.json +27 -3
  47. package/.changeset/README.md +0 -5
  48. package/.changeset/config.json +0 -11
  49. package/.changeset/stable-usage-model.md +0 -5
  50. package/.github/workflows/docs.yml +0 -45
  51. package/.prettierignore +0 -1
  52. package/.prettierrc.js +0 -5
  53. package/bun.lock +0 -663
  54. package/eslint.config.mjs +0 -12
  55. package/knip.json +0 -8
  56. package/paradox/components.md +0 -1
  57. package/paradox/exports.json +0 -12
  58. package/paradox/exports.md +0 -13
  59. package/paradox/paradox.json +0 -32
  60. package/paradox.config.ts +0 -18
  61. package/src/analyze/analyze.ts +0 -45
  62. package/src/analyze/components.ts +0 -27
  63. package/src/analyze/exports.ts +0 -87
  64. package/src/analyze/project.ts +0 -11
  65. package/src/analyze/types.ts +0 -53
  66. package/src/analyze/usage.ts +0 -53
  67. package/src/analyze/utils/getComponentPropsType.ts +0 -26
  68. package/src/analyze/utils/getParadoxComment.ts +0 -24
  69. package/src/analyze/utils/getPropsFromType.ts +0 -24
  70. package/src/analyze/utils/isReactComponent.ts +0 -35
  71. package/src/analyze/utils/parseParadoxComment.ts +0 -37
  72. package/src/cli.ts +0 -30
  73. package/src/config/types.ts +0 -22
  74. package/src/model/buildModel.ts +0 -112
  75. package/src/model/types.ts +0 -49
  76. package/src/render/render.ts +0 -115
  77. package/src/render/types.ts +0 -10
  78. package/src/write/write.ts +0 -25
  79. package/tests/__snapshots__/basic.components.md +0 -10
  80. package/tests/__snapshots__/basic.exports.md +0 -19
  81. package/tests/__snapshots__/basic.readme.md +0 -37
  82. package/tests/__snapshots__/multi-bin.readme.md +0 -16
  83. package/tests/analyze.test.ts +0 -153
  84. package/tests/fixtures/basic/package.json +0 -8
  85. package/tests/fixtures/basic/src/config.ts +0 -8
  86. package/tests/fixtures/basic/src/index.ts +0 -3
  87. package/tests/fixtures/basic/src/internal.ts +0 -6
  88. package/tests/fixtures/basic/src/ui.ts +0 -29
  89. package/tests/fixtures/basic/tsconfig.json +0 -11
  90. package/tests/fixtures/multi-bin/package.json +0 -9
  91. package/tests/fixtures/multi-bin/src/alpha.ts +0 -1
  92. package/tests/fixtures/multi-bin/src/beta.ts +0 -1
  93. package/tests/fixtures/multi-bin/src/index.ts +0 -4
  94. package/tests/fixtures/multi-bin/tsconfig.json +0 -11
  95. package/tsconfig.eslint.json +0 -16
  96. package/tsconfig.json +0 -14
  97. /package/{src/index.ts → dist/index.d.ts} +0 -0
@@ -0,0 +1,42 @@
1
+ /***
2
+ * Serializable model consumed by renderers and writers.
3
+ */
4
+ export interface DocumentationModel {
5
+ packageName: string;
6
+ packageId: string;
7
+ description: string | null;
8
+ usage: UsageModel | null;
9
+ config: ConfigModel | null;
10
+ exports: ExportModel[];
11
+ components: ComponentModel[];
12
+ }
13
+ export interface UsageModel {
14
+ packageName: string;
15
+ commands: UsageCommandModel[];
16
+ }
17
+ export interface UsageCommandModel {
18
+ name: string;
19
+ command: string;
20
+ }
21
+ export interface ConfigModel {
22
+ exportName: string;
23
+ configFile: string;
24
+ factoryName: string | null;
25
+ }
26
+ export interface ExportModel {
27
+ name: string;
28
+ description: string | null;
29
+ kind: ExportKind;
30
+ }
31
+ export type ExportKind = 'function' | 'type' | 'unknown';
32
+ export interface ComponentModel {
33
+ name: string;
34
+ description: string | null;
35
+ props: PropModel[];
36
+ }
37
+ export interface PropModel {
38
+ name: string;
39
+ type: string;
40
+ required: boolean;
41
+ description: string | null;
42
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { ParadoxConfig } from '../config/types.js';
2
+ export interface ResolvedRuntimePaths {
3
+ cwd: string;
4
+ configFilePath: string;
5
+ configDir: string;
6
+ packageRoot: string;
7
+ outputDir: string;
8
+ outputRoot: string;
9
+ }
10
+ export declare function findParadoxConfigFile(startDir: string): Promise<string | null>;
11
+ export declare function loadParadoxConfig(configFilePath: string): Promise<ParadoxConfig>;
12
+ export declare function resolvePackageRoot(config: ParadoxConfig, configDir: string): Promise<string>;
13
+ export declare function resolveOutputRoot(config: ParadoxConfig, packageRoot: string): {
14
+ outputDir: string;
15
+ outputRoot: string;
16
+ };
17
+ export declare function resolveWriteTargets(packageRoot: string, outputRoot: string): {
18
+ exportsMarkdown: string;
19
+ componentsMarkdown: string;
20
+ exportsJson: string;
21
+ paradoxJson: string;
22
+ readme: string;
23
+ };
@@ -0,0 +1,105 @@
1
+ import { access } from 'node:fs/promises';
2
+ import { dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ const CONFIG_FILENAMES = [
5
+ 'paradox.config.ts',
6
+ 'paradox.config.js',
7
+ 'paradox.config.mjs',
8
+ 'paradox.config.cjs',
9
+ ];
10
+ export async function findParadoxConfigFile(startDir) {
11
+ let current = resolve(startDir);
12
+ let parent = dirname(current);
13
+ while (parent !== current) {
14
+ for (const filename of CONFIG_FILENAMES) {
15
+ const candidate = join(current, filename);
16
+ if (await pathExists(candidate))
17
+ return candidate;
18
+ }
19
+ current = parent;
20
+ parent = dirname(current);
21
+ }
22
+ for (const filename of CONFIG_FILENAMES) {
23
+ const candidate = join(current, filename);
24
+ if (await pathExists(candidate))
25
+ return candidate;
26
+ }
27
+ return null;
28
+ }
29
+ export async function loadParadoxConfig(configFilePath) {
30
+ const url = pathToFileURL(configFilePath).href;
31
+ const mod = (await import(url));
32
+ return mod.default ?? {};
33
+ }
34
+ export async function resolvePackageRoot(config, configDir) {
35
+ const configuredRoot = config.package?.root;
36
+ const resolvedRoot = configuredRoot
37
+ ? isAbsolute(configuredRoot)
38
+ ? configuredRoot
39
+ : resolve(configDir, configuredRoot)
40
+ : resolve(configDir);
41
+ await assertPathExists(join(resolvedRoot, 'package.json'), `Unable to find package.json at resolved package root: ${resolvedRoot}`);
42
+ return resolvedRoot;
43
+ }
44
+ export function resolveOutputRoot(config, packageRoot) {
45
+ const outputDir = config.output?.dir ?? 'paradox';
46
+ validateOutputDir(outputDir);
47
+ const outputRoot = resolve(packageRoot, outputDir);
48
+ assertWithinRoot(outputRoot, packageRoot, `Resolved output directory escapes package root: ${outputRoot}`);
49
+ return { outputDir, outputRoot };
50
+ }
51
+ export function resolveWriteTargets(packageRoot, outputRoot) {
52
+ return {
53
+ exportsMarkdown: join(outputRoot, 'exports.md'),
54
+ componentsMarkdown: join(outputRoot, 'components.md'),
55
+ exportsJson: join(outputRoot, 'exports.json'),
56
+ paradoxJson: join(outputRoot, 'paradox.json'),
57
+ readme: join(packageRoot, 'README.md'),
58
+ };
59
+ }
60
+ async function pathExists(path) {
61
+ try {
62
+ await access(path);
63
+ return true;
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ }
69
+ async function assertPathExists(path, message) {
70
+ if (!(await pathExists(path))) {
71
+ throw new Error(message);
72
+ }
73
+ }
74
+ function validateOutputDir(outputDir) {
75
+ const trimmed = outputDir.trim();
76
+ if (trimmed.length === 0) {
77
+ throw new Error('Invalid output.dir: must be a non-empty string.');
78
+ }
79
+ const normalized = normalize(trimmed);
80
+ if (normalized === '.' || normalized === '') {
81
+ throw new Error('Invalid output.dir: must not be ".".');
82
+ }
83
+ if (isAbsolute(normalized)) {
84
+ throw new Error('Invalid output.dir: must be a relative path inside the package root (absolute paths are not allowed).');
85
+ }
86
+ // Reject explicit parent traversal to keep writes deterministic and scoped.
87
+ for (const segment of splitPathSegments(trimmed)) {
88
+ if (segment === '..') {
89
+ throw new Error('Invalid output.dir: must not contain ".." path segments.');
90
+ }
91
+ }
92
+ }
93
+ function splitPathSegments(path) {
94
+ // Treat both separators as potential delimiters to stay robust across platforms/config styles.
95
+ const normalized = path.replaceAll('\\', '/');
96
+ return normalized.split('/').filter((segment) => segment.length > 0 && segment !== '.');
97
+ }
98
+ function assertWithinRoot(resolvedPath, root, message) {
99
+ const rel = relative(root, resolvedPath);
100
+ if (rel === '')
101
+ return;
102
+ if (rel === '..' || rel.startsWith(`..${sep}`)) {
103
+ throw new Error(message);
104
+ }
105
+ }
@@ -0,0 +1,6 @@
1
+ import type { DocumentationModel } from '../model/types.js';
2
+ import type { RenderResult } from './types.js';
3
+ /***
4
+ * Renders the documentation model into README and artifact files.
5
+ */
6
+ export declare function render(model: DocumentationModel): RenderResult;
@@ -0,0 +1,95 @@
1
+ /***
2
+ * Renders the documentation model into README and artifact files.
3
+ */
4
+ export function render(model) {
5
+ return {
6
+ readme: renderReadme(model),
7
+ exportsMarkdown: renderExports(model),
8
+ components: renderComponents(model),
9
+ exportsJson: `${JSON.stringify(model.exports, null, 2)}\n`,
10
+ paradoxJson: `${JSON.stringify(model, null, 2)}\n`,
11
+ };
12
+ }
13
+ function renderReadme(model) {
14
+ const lines = [`# ${model.packageName}`, ''];
15
+ if (model.description) {
16
+ lines.push(model.description, '');
17
+ }
18
+ if (model.usage !== null) {
19
+ lines.push('## Usage', '');
20
+ lines.push('```bash');
21
+ for (const command of model.usage.commands) {
22
+ lines.push(command.command);
23
+ }
24
+ lines.push('```', '');
25
+ }
26
+ if (model.config !== null) {
27
+ lines.push('## Configuration', '');
28
+ lines.push(`Create a \`${model.config.configFile}\` file:`, '');
29
+ lines.push('```ts');
30
+ if (model.config.factoryName !== null) {
31
+ lines.push(`import { ${model.config.factoryName} } from '${model.packageId}';`);
32
+ lines.push('');
33
+ lines.push(`export default ${model.config.factoryName}({`);
34
+ lines.push(' // ...');
35
+ lines.push('});');
36
+ }
37
+ else {
38
+ lines.push(`import type { ${model.config.exportName} } from '${model.packageId}';`);
39
+ lines.push('');
40
+ lines.push('const config = {');
41
+ lines.push(' // ...');
42
+ lines.push(`} satisfies ${model.config.exportName};`);
43
+ lines.push('');
44
+ lines.push('export default config;');
45
+ }
46
+ lines.push('```', '');
47
+ }
48
+ lines.push('## Path resolution', '');
49
+ lines.push('- Config discovery: searches upward from `process.cwd()` for `paradox.config.ts/js/mjs/cjs` (required; no fallback).');
50
+ lines.push('- Package root: defaults to the directory containing `paradox.config.*`; `package.root` (when relative) resolves relative to that directory.');
51
+ lines.push('- Output directory: defaults to `paradox/`; `output.dir` (when relative) resolves relative to the resolved package root and must stay inside it.');
52
+ lines.push('- Modes:');
53
+ lines.push(' - `safe`: writes generated artifacts only under the output directory');
54
+ lines.push(' - `write`: additionally updates `<packageRoot>/README.md`', '');
55
+ if (model.exports.length > 0) {
56
+ lines.push('## Public API', '');
57
+ for (const item of model.exports) {
58
+ lines.push(`### ${item.name}`, '');
59
+ lines.push(item.description ?? `\`${item.kind}\` export.`, '');
60
+ }
61
+ }
62
+ return `${lines.join('\n').trimEnd()}\n`;
63
+ }
64
+ function renderExports(model) {
65
+ const lines = ['# Public API', ''];
66
+ for (const item of model.exports) {
67
+ lines.push(`## ${item.name}`, '');
68
+ lines.push(`Kind: \`${item.kind}\``, '');
69
+ if (item.description) {
70
+ lines.push(item.description, '');
71
+ }
72
+ }
73
+ return `${lines.join('\n').trimEnd()}\n`;
74
+ }
75
+ function renderComponents(model) {
76
+ const lines = ['# Components', ''];
77
+ for (const component of model.components) {
78
+ lines.push(`## ${component.name}`, '');
79
+ if (component.description) {
80
+ lines.push(component.description, '');
81
+ }
82
+ if (component.props.length > 0) {
83
+ lines.push('| Prop | Type | Required | Description |');
84
+ lines.push('| --- | --- | --- | --- |');
85
+ for (const prop of component.props) {
86
+ lines.push(`| ${escapeTableCell(prop.name)} | \`${escapeTableCell(prop.type)}\` | ${prop.required ? 'yes' : 'no'} | ${escapeTableCell(prop.description ?? '')} |`);
87
+ }
88
+ lines.push('');
89
+ }
90
+ }
91
+ return `${lines.join('\n').trimEnd()}\n`;
92
+ }
93
+ function escapeTableCell(value) {
94
+ return value.replaceAll('|', '\\|');
95
+ }
@@ -0,0 +1,10 @@
1
+ /***
2
+ * Rendered documentation files ready to be written to disk.
3
+ */
4
+ export interface RenderResult {
5
+ readme: string;
6
+ exportsMarkdown: string;
7
+ components: string;
8
+ exportsJson: string;
9
+ paradoxJson: string;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { ParadoxConfig } from '../config/types.js';
2
+ import type { RenderResult } from '../render/types.js';
3
+ /***
4
+ * Writes generated documentation artifacts to the configured output paths.
5
+ */
6
+ export declare function write(result: RenderResult, config: ParadoxConfig, runtime: {
7
+ packageRoot: string;
8
+ outputRoot: string;
9
+ }): Promise<void>;
@@ -0,0 +1,18 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ /***
4
+ * Writes generated documentation artifacts to the configured output paths.
5
+ */
6
+ export async function write(result, config, runtime) {
7
+ const root = runtime.packageRoot;
8
+ const { outputRoot } = runtime;
9
+ const mode = config.mode ?? 'safe';
10
+ await mkdir(outputRoot, { recursive: true });
11
+ await writeFile(join(outputRoot, 'exports.md'), result.exportsMarkdown);
12
+ await writeFile(join(outputRoot, 'components.md'), result.components);
13
+ await writeFile(join(outputRoot, 'exports.json'), result.exportsJson);
14
+ await writeFile(join(outputRoot, 'paradox.json'), result.paradoxJson);
15
+ if (mode === 'write') {
16
+ await writeFile(join(root, 'README.md'), result.readme);
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,17 +1,40 @@
1
1
  {
2
2
  "name": "@ankhorage/paradox",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Deterministic documentation generator for TypeScript packages.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
+ "homepage": "https://github.com/ankhorage/paradox#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/ankhorage/paradox/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/ankhorage/paradox.git"
16
+ },
9
17
  "type": "module",
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "CHANGELOG.md",
31
+ "LICENSE"
32
+ ],
10
33
  "bin": {
11
- "paradox": "./src/cli.ts"
34
+ "paradox": "./dist/cli.js"
12
35
  },
13
36
  "scripts": {
14
- "build": "tsc --noEmit",
37
+ "build": "tsc -p tsconfig.build.json",
15
38
  "changeset": "changeset",
16
39
  "changeset:status": "changeset status --since=origin/main",
17
40
  "docs": "bun src/cli.ts",
@@ -20,6 +43,7 @@
20
43
  "format:check": "prettier --check .",
21
44
  "lint": "eslint . --max-warnings=0",
22
45
  "lint:fix": "eslint . --fix --max-warnings=0",
46
+ "prepack": "bun run build",
23
47
  "test": "bun test",
24
48
  "typecheck": "bun x tsc --noEmit -p tsconfig.json",
25
49
  "version-packages": "changeset version"
@@ -1,5 +0,0 @@
1
- # Changesets
2
-
3
- This directory stores release notes consumed by Changesets.
4
-
5
- Run `bun run changeset` to create a new changeset before publishing a package change.
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/@changesets/config@3.1.3/schema.json",
3
- "changelog": "@changesets/cli/changelog",
4
- "commit": false,
5
- "fixed": [],
6
- "linked": [],
7
- "access": "public",
8
- "baseBranch": "main",
9
- "updateInternalDependencies": "patch",
10
- "ignore": []
11
- }
@@ -1,5 +0,0 @@
1
- ---
2
- '@ankhorage/paradox': patch
3
- ---
4
-
5
- Stabilize usage metadata, documentation model serialization, and deterministic output ordering.
@@ -1,45 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- pull_request:
5
- push:
6
- branches:
7
- - main
8
-
9
- jobs:
10
- validate:
11
- runs-on: ubuntu-latest
12
-
13
- steps:
14
- - name: Checkout repository
15
- uses: actions/checkout@v4
16
-
17
- - name: Setup Bun
18
- uses: oven-sh/setup-bun@v2
19
- with:
20
- bun-version: '1.3.11'
21
-
22
- - name: Install dependencies
23
- run: bun install --frozen-lockfile
24
-
25
- - name: Run lint
26
- run: bun run lint
27
-
28
- - name: Check formatting
29
- run: bun run format:check
30
-
31
- - name: Run typecheck
32
- run: bun run typecheck
33
-
34
- - name: Run tests
35
- run: bun run test
36
-
37
- - name: Check changesets
38
- if: github.event_name == 'pull_request'
39
- run: bun run changeset:status
40
-
41
- - name: Generate docs
42
- run: bun run docs
43
-
44
- - name: Check generated docs
45
- run: git diff --exit-code
package/.prettierignore DELETED
@@ -1 +0,0 @@
1
- tests/__snapshots__/*.md
package/.prettierrc.js DELETED
@@ -1,5 +0,0 @@
1
- import { createRequire } from 'node:module';
2
-
3
- const require = createRequire(import.meta.url);
4
-
5
- export default require('@ankhorage/devtools/prettier');