@ankhorage/paradox 0.0.3 → 0.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 859c537: Standardize CI/release workflow files and update the Bun tooling baseline.
8
+
9
+ ## 0.0.4
10
+
11
+ ### Patch Changes
12
+
13
+ - f5b89ce: Stabilize Paradox config discovery and output path resolution so generated artifacts are written under the resolved package output directory.
14
+
3
15
  ## 0.0.3
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -20,6 +20,15 @@ export default defineParadoxConfig({
20
20
  });
21
21
  ```
22
22
 
23
+ ## Path resolution
24
+
25
+ - Config discovery: searches upward from `process.cwd()` for `paradox.config.ts/js/mjs/cjs` (required; no fallback).
26
+ - Package root: defaults to the directory containing `paradox.config.*`; `package.root` (when relative) resolves relative to that directory.
27
+ - Output directory: defaults to `paradox/`; `output.dir` (when relative) resolves relative to the resolved package root and must stay inside it.
28
+ - Modes:
29
+ - `safe`: writes generated artifacts only under the output directory
30
+ - `write`: additionally updates `<packageRoot>/README.md`
31
+
23
32
  ## Public API
24
33
 
25
34
  ### defineParadoxConfig
@@ -3,4 +3,6 @@ import type { AnalysisResult } from './types.js';
3
3
  /***
4
4
  * Runs the source analysis pipeline for a configured package.
5
5
  */
6
- export declare function analyze(config: ParadoxConfig): Promise<AnalysisResult>;
6
+ export declare function analyze(config: ParadoxConfig, runtime: {
7
+ packageRoot: string;
8
+ }): Promise<AnalysisResult>;
@@ -7,8 +7,8 @@ import { createUsageFromPackageJson } from './usage.js';
7
7
  /***
8
8
  * Runs the source analysis pipeline for a configured package.
9
9
  */
10
- export async function analyze(config) {
11
- const root = config.package?.root ?? process.cwd();
10
+ export async function analyze(config, runtime) {
11
+ const root = runtime.packageRoot;
12
12
  const pkg = await readPackageJson(root);
13
13
  const usage = createUsageFromPackageJson(pkg);
14
14
  const project = createProject(root);
package/dist/cli.js CHANGED
@@ -1,21 +1,24 @@
1
1
  #!/usr/bin/env bun
2
- import { join } from 'node:path';
3
- import { pathToFileURL } from 'node:url';
2
+ import { dirname } from 'node:path';
4
3
  import { analyze } from './analyze/analyze.js';
5
4
  import { buildModel } from './model/buildModel.js';
5
+ import { findParadoxConfigFile, loadParadoxConfig, resolveOutputRoot, resolvePackageRoot, } from './paths/policy.js';
6
6
  import { render } from './render/render.js';
7
7
  import { write } from './write/write.js';
8
8
  async function main() {
9
- const config = await loadConfig(process.cwd());
10
- const analysis = await analyze(config);
9
+ const cwd = process.cwd();
10
+ const configFilePath = await findParadoxConfigFile(cwd);
11
+ if (!configFilePath) {
12
+ throw new Error(`Unable to find Paradox config. Looked for paradox.config.{ts,js,mjs,cjs} by searching upward from: ${cwd}`);
13
+ }
14
+ const configDir = dirname(configFilePath);
15
+ const config = await loadParadoxConfig(configFilePath);
16
+ const packageRoot = await resolvePackageRoot(config, configDir);
17
+ const { outputRoot } = resolveOutputRoot(config, packageRoot);
18
+ const analysis = await analyze(config, { packageRoot });
11
19
  const model = buildModel(analysis);
12
20
  const result = render(model);
13
- await write(result, config);
14
- }
15
- async function loadConfig(root) {
16
- const configUrl = pathToFileURL(join(root, 'paradox.config.ts')).href;
17
- const mod = (await import(configUrl));
18
- return mod.default ?? {};
21
+ await write(result, config, { packageRoot, outputRoot });
19
22
  }
20
23
  main().catch((error) => {
21
24
  console.error(error);
@@ -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
+ }
@@ -45,6 +45,13 @@ function renderReadme(model) {
45
45
  }
46
46
  lines.push('```', '');
47
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`', '');
48
55
  if (model.exports.length > 0) {
49
56
  lines.push('## Public API', '');
50
57
  for (const item of model.exports) {
@@ -3,4 +3,7 @@ import type { RenderResult } from '../render/types.js';
3
3
  /***
4
4
  * Writes generated documentation artifacts to the configured output paths.
5
5
  */
6
- export declare function write(result: RenderResult, config: ParadoxConfig): Promise<void>;
6
+ export declare function write(result: RenderResult, config: ParadoxConfig, runtime: {
7
+ packageRoot: string;
8
+ outputRoot: string;
9
+ }): Promise<void>;
@@ -3,15 +3,15 @@ import { join } from 'node:path';
3
3
  /***
4
4
  * Writes generated documentation artifacts to the configured output paths.
5
5
  */
6
- export async function write(result, config) {
7
- const root = config.package?.root ?? process.cwd();
8
- const outputDir = config.output?.dir ?? 'paradox';
6
+ export async function write(result, config, runtime) {
7
+ const root = runtime.packageRoot;
8
+ const { outputRoot } = runtime;
9
9
  const mode = config.mode ?? 'safe';
10
- await mkdir(join(root, outputDir), { recursive: true });
11
- await writeFile(join(root, outputDir, 'exports.md'), result.exportsMarkdown);
12
- await writeFile(join(root, outputDir, 'components.md'), result.components);
13
- await writeFile(join(root, outputDir, 'exports.json'), result.exportsJson);
14
- await writeFile(join(root, outputDir, 'paradox.json'), result.paradoxJson);
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
15
  if (mode === 'write') {
16
16
  await writeFile(join(root, 'README.md'), result.readme);
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/paradox",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Deterministic documentation generator for TypeScript packages.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -54,7 +54,8 @@
54
54
  "devDependencies": {
55
55
  "@ankhorage/devtools": "^1.0.0",
56
56
  "@changesets/cli": "^2.31.0",
57
- "@types/bun": "^1.1.14",
57
+ "@types/bun": "^1.3.13",
58
58
  "typescript": "^5.6.3"
59
- }
59
+ },
60
+ "packageManager": "bun@1.3.13"
60
61
  }