svelte-docinfo 0.1.0

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/LICENSE +21 -0
  2. package/README.md +349 -0
  3. package/dist/analyze-core.d.ts +1386 -0
  4. package/dist/analyze-core.d.ts.map +1 -0
  5. package/dist/analyze-core.js +324 -0
  6. package/dist/analyze.d.ts +137 -0
  7. package/dist/analyze.d.ts.map +1 -0
  8. package/dist/analyze.js +148 -0
  9. package/dist/cli.d.ts +102 -0
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +206 -0
  12. package/dist/concurrency.d.ts +38 -0
  13. package/dist/concurrency.d.ts.map +1 -0
  14. package/dist/concurrency.js +57 -0
  15. package/dist/declaration-build.d.ts +164 -0
  16. package/dist/declaration-build.d.ts.map +1 -0
  17. package/dist/declaration-build.js +15 -0
  18. package/dist/declaration-helpers.d.ts +169 -0
  19. package/dist/declaration-helpers.d.ts.map +1 -0
  20. package/dist/declaration-helpers.js +239 -0
  21. package/dist/dep-resolver.d.ts +166 -0
  22. package/dist/dep-resolver.d.ts.map +1 -0
  23. package/dist/dep-resolver.js +144 -0
  24. package/dist/diagnostics.d.ts +650 -0
  25. package/dist/diagnostics.d.ts.map +1 -0
  26. package/dist/diagnostics.js +377 -0
  27. package/dist/discovery.d.ts +115 -0
  28. package/dist/discovery.d.ts.map +1 -0
  29. package/dist/discovery.js +126 -0
  30. package/dist/exports.d.ts +105 -0
  31. package/dist/exports.d.ts.map +1 -0
  32. package/dist/exports.js +274 -0
  33. package/dist/files.d.ts +77 -0
  34. package/dist/files.d.ts.map +1 -0
  35. package/dist/files.js +95 -0
  36. package/dist/index.d.ts +32 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +30 -0
  39. package/dist/log.d.ts +32 -0
  40. package/dist/log.d.ts.map +1 -0
  41. package/dist/log.js +11 -0
  42. package/dist/logo.d.ts +8 -0
  43. package/dist/logo.d.ts.map +1 -0
  44. package/dist/logo.js +9 -0
  45. package/dist/main.d.ts +11 -0
  46. package/dist/main.d.ts.map +1 -0
  47. package/dist/main.js +18 -0
  48. package/dist/paths.d.ts +35 -0
  49. package/dist/paths.d.ts.map +1 -0
  50. package/dist/paths.js +34 -0
  51. package/dist/postprocess.d.ts +145 -0
  52. package/dist/postprocess.d.ts.map +1 -0
  53. package/dist/postprocess.js +305 -0
  54. package/dist/session.d.ts +248 -0
  55. package/dist/session.d.ts.map +1 -0
  56. package/dist/session.js +496 -0
  57. package/dist/source-config.d.ts +330 -0
  58. package/dist/source-config.d.ts.map +1 -0
  59. package/dist/source-config.js +356 -0
  60. package/dist/source.d.ts +126 -0
  61. package/dist/source.d.ts.map +1 -0
  62. package/dist/source.js +68 -0
  63. package/dist/svelte.d.ts +179 -0
  64. package/dist/svelte.d.ts.map +1 -0
  65. package/dist/svelte.js +898 -0
  66. package/dist/tsdoc.d.ts +145 -0
  67. package/dist/tsdoc.d.ts.map +1 -0
  68. package/dist/tsdoc.js +262 -0
  69. package/dist/types.d.ts +3381 -0
  70. package/dist/types.d.ts.map +1 -0
  71. package/dist/types.js +588 -0
  72. package/dist/typescript-exports.d.ts +91 -0
  73. package/dist/typescript-exports.d.ts.map +1 -0
  74. package/dist/typescript-exports.js +656 -0
  75. package/dist/typescript-extract-class.d.ts +29 -0
  76. package/dist/typescript-extract-class.d.ts.map +1 -0
  77. package/dist/typescript-extract-class.js +251 -0
  78. package/dist/typescript-extract-function.d.ts +47 -0
  79. package/dist/typescript-extract-function.d.ts.map +1 -0
  80. package/dist/typescript-extract-function.js +108 -0
  81. package/dist/typescript-extract-shared.d.ts +166 -0
  82. package/dist/typescript-extract-shared.d.ts.map +1 -0
  83. package/dist/typescript-extract-shared.js +528 -0
  84. package/dist/typescript-extract-type-properties.d.ts +34 -0
  85. package/dist/typescript-extract-type-properties.d.ts.map +1 -0
  86. package/dist/typescript-extract-type-properties.js +241 -0
  87. package/dist/typescript-extract-type.d.ts +48 -0
  88. package/dist/typescript-extract-type.d.ts.map +1 -0
  89. package/dist/typescript-extract-type.js +238 -0
  90. package/dist/typescript-program.d.ts +211 -0
  91. package/dist/typescript-program.d.ts.map +1 -0
  92. package/dist/typescript-program.js +290 -0
  93. package/dist/vite.d.ts +116 -0
  94. package/dist/vite.d.ts.map +1 -0
  95. package/dist/vite.js +418 -0
  96. package/package.json +131 -0
  97. package/virtual-svelte-docinfo.d.ts +49 -0
package/dist/cli.d.ts ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * CLI for svelte-docinfo.
3
+ *
4
+ * Static analysis for TypeScript and Svelte source code.
5
+ *
6
+ * @example
7
+ * ```bash
8
+ * # Analyze current project
9
+ * svelte-docinfo
10
+ *
11
+ * # Analyze specific directory
12
+ * svelte-docinfo ./packages/my-lib
13
+ *
14
+ * # Write to file
15
+ * svelte-docinfo --output docs/library.json
16
+ * ```
17
+ *
18
+ * @module
19
+ */
20
+ import type { Discovery } from './discovery.js';
21
+ /** Allowed values for `--on-duplicates`. */
22
+ declare const ON_DUPLICATES_VALUES: readonly ["throw", "warn"];
23
+ type OnDuplicatesFlag = (typeof ON_DUPLICATES_VALUES)[number];
24
+ /**
25
+ * CLI options parsed from command line arguments.
26
+ */
27
+ export interface CliOptions {
28
+ /** File patterns to include (undefined = use exports discovery or defaults). */
29
+ include?: Array<string>;
30
+ /**
31
+ * File patterns to exclude (undefined = use defaults — test and spec files).
32
+ *
33
+ * When provided, **fully replaces** the defaults — no array merge. Passing
34
+ * a custom `--exclude` pattern drops the default test/spec filters unless
35
+ * the caller re-includes them explicitly.
36
+ */
37
+ exclude?: Array<string>;
38
+ /** Output file path (undefined = stdout). */
39
+ output?: string;
40
+ /**
41
+ * Whether to resolve dependencies. Mapped from the `--no-resolve-dependencies`
42
+ * flag (commander populates `true` by default; `false` when the flag is passed).
43
+ * Optional here so external callers can omit it; treated as `true` when undefined.
44
+ */
45
+ resolveDependencies?: boolean;
46
+ /**
47
+ * Discovery strategy (undefined = 'auto').
48
+ *
49
+ * Mapped from `--discovery <auto|exports|glob>`.
50
+ */
51
+ discovery?: Discovery;
52
+ /** Dist directory name for exports-based discovery (undefined = 'dist'). */
53
+ distDir?: string;
54
+ /**
55
+ * Source directories relative to project root (undefined = ['src/lib']).
56
+ *
57
+ * Repeatable. Drives the implicit include glob in the glob-discovery
58
+ * fallback (via `deriveIncludePatterns` inside `discoverSourceFiles`) so
59
+ * custom source directories survive without needing an explicit `--include`.
60
+ */
61
+ sourceDir?: Array<string>;
62
+ /**
63
+ * Source root for module path extraction, relative to project root
64
+ * (undefined = single sourceDir or longest common prefix).
65
+ *
66
+ * Module paths in output are stripped of `<projectRoot>/<sourceRoot>/`.
67
+ * Pass `.` (or `""`) to keep module paths project-relative — useful when
68
+ * `sourceDir` entries share no common prefix. The `.` form is normalized
69
+ * to `""` inside `normalizeSourceOptions`.
70
+ */
71
+ sourceRoot?: string;
72
+ /**
73
+ * Behavior when duplicate declaration names are found across modules
74
+ * (undefined = emit `duplicate_declaration` diagnostic, no dispatch).
75
+ *
76
+ * Duplicate detection always runs regardless of this option — the diagnostic
77
+ * is the data, this option is the dispatch action.
78
+ */
79
+ onDuplicates?: OnDuplicatesFlag;
80
+ /**
81
+ * Glob patterns to filter the emitted `modules` array against `ModuleJson.path`
82
+ * (undefined = emit all analyzed modules).
83
+ *
84
+ * Repeatable. Output-only filter: full-project analysis still runs so re-exports,
85
+ * dependents, and `alsoExportedFrom` stay correct against the complete owned set.
86
+ * Diagnostics aren't filtered — they may reference modules dropped from output.
87
+ */
88
+ only?: Array<string>;
89
+ /** Whether to suppress info messages to stderr. Treated as `false` when undefined. */
90
+ quiet?: boolean;
91
+ /** Whether to pretty-print JSON output. Treated as `false` when undefined. */
92
+ pretty?: boolean;
93
+ }
94
+ /**
95
+ * Run the CLI with the given arguments.
96
+ *
97
+ * @param argv - command line arguments (defaults to `process.argv`)
98
+ * @returns exit code: 0 for success, 1 if errors in diagnostics, 2 for CLI errors
99
+ */
100
+ export declare const runCli: (argv?: Array<string>) => Promise<number>;
101
+ export {};
102
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AASH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAS9C,4CAA4C;AAC5C,QAAA,MAAM,oBAAoB,4BAA6B,CAAC;AACxD,KAAK,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAS9D;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,gFAAgF;IAChF,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB,sFAAsF;IACtF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAU,OAAM,KAAK,CAAC,MAAM,CAAgB,KAAG,OAAO,CAAC,MAAM,CA2N/E,CAAC"}
package/dist/cli.js ADDED
@@ -0,0 +1,206 @@
1
+ /**
2
+ * CLI for svelte-docinfo.
3
+ *
4
+ * Static analysis for TypeScript and Svelte source code.
5
+ *
6
+ * @example
7
+ * ```bash
8
+ * # Analyze current project
9
+ * svelte-docinfo
10
+ *
11
+ * # Analyze specific directory
12
+ * svelte-docinfo ./packages/my-lib
13
+ *
14
+ * # Write to file
15
+ * svelte-docinfo --output docs/library.json
16
+ * ```
17
+ *
18
+ * @module
19
+ */
20
+ import { Command } from 'commander';
21
+ import { writeFile, readFile } from 'node:fs/promises';
22
+ import { resolve } from 'node:path';
23
+ import picomatch from 'picomatch';
24
+ import { analyzeFromFiles } from './analyze.js';
25
+ import { hasErrors } from './diagnostics.js';
26
+ import { compactReplacer } from './declaration-helpers.js';
27
+ /** Collect repeatable option values into an array. */
28
+ const collect = (value, previous) => previous ? [...previous, value] : [value];
29
+ /** Allowed values for `--on-duplicates`. */
30
+ const ON_DUPLICATES_VALUES = ['throw', 'warn'];
31
+ const isOnDuplicatesFlag = (value) => ON_DUPLICATES_VALUES.includes(value);
32
+ /** Allowed values for `--discovery`. */
33
+ const DISCOVERY_VALUES = ['auto', 'exports', 'glob'];
34
+ const isDiscoveryFlag = (value) => DISCOVERY_VALUES.includes(value);
35
+ /**
36
+ * Run the CLI with the given arguments.
37
+ *
38
+ * @param argv - command line arguments (defaults to `process.argv`)
39
+ * @returns exit code: 0 for success, 1 if errors in diagnostics, 2 for CLI errors
40
+ */
41
+ export const runCli = async (argv = process.argv) => {
42
+ // Track exit code from action (commander actions don't return values)
43
+ let exitCode = 0;
44
+ const program = new Command();
45
+ // Read version from package.json using URL resolution (works in both source and dist).
46
+ // Loud throw on lookup failure — silent fallback would let a broken install
47
+ // report `0.0.0` for `--version` indefinitely.
48
+ const pkg = await (async () => {
49
+ // Try dist path first, then source path
50
+ const attempted = [];
51
+ for (const relativePath of ['../package.json', '../../package.json']) {
52
+ const pkgUrl = new URL(relativePath, import.meta.url);
53
+ attempted.push(pkgUrl.href);
54
+ try {
55
+ const content = await readFile(pkgUrl, 'utf-8');
56
+ return JSON.parse(content);
57
+ }
58
+ catch {
59
+ continue;
60
+ }
61
+ }
62
+ throw new Error(`svelte-docinfo: failed to load package.json for version. Attempted: ${attempted.join(', ')}`);
63
+ })();
64
+ program
65
+ .name('svelte-docinfo')
66
+ .description('Static analysis for TypeScript and Svelte source code')
67
+ .version(pkg.version)
68
+ .argument('[project-root]', 'Project root directory', process.cwd())
69
+ .option('-i, --include <pattern>', 'Include pattern (repeatable, replaces exports discovery; ' +
70
+ 'incompatible with --discovery exports)', collect)
71
+ .option('-e, --exclude <pattern>', 'Exclude glob (applied at discovery and analysis, repeatable; ' +
72
+ 'fully replaces defaults — does not merge with **/*.test.ts, **/*.spec.ts)', collect)
73
+ .option('-o, --output <file>', 'Output file (default: stdout; pass `-` for explicit stdout)')
74
+ .option('--no-resolve-dependencies', 'Disable dependency resolution')
75
+ .option('--discovery <mode>', `Source file discovery strategy: ${DISCOVERY_VALUES.join('|')} ` +
76
+ '(default: auto — exports first, glob fallback). ' +
77
+ '`exports` is strict and fails if package.json exports is missing or empty ' +
78
+ '(also incompatible with --include).')
79
+ .option('--dist-dir <dir>', 'Dist directory for exports discovery (default: dist)')
80
+ .option('--source-dir <dir>', 'Source directory relative to project root (default: src/lib). ' +
81
+ 'Repeatable for monorepos. Drives the implicit include glob for the ' +
82
+ 'glob-discovery fallback when no --include is provided.', collect)
83
+ .option('--source-root <dir>', 'Prefix stripped from module paths in output (default: the source-dir, ' +
84
+ 'or longest common prefix when multiple). Pass `.` to keep paths project-relative.')
85
+ .option('--on-duplicates <mode>', `Dispatch on duplicate declaration names across modules: ${ON_DUPLICATES_VALUES.join('|')} ` +
86
+ '(default: emit duplicate_declaration diagnostic, no dispatch)')
87
+ .option('--only <pattern>', 'Glob filter applied to module paths in output (repeatable). ' +
88
+ 'Full project is still analyzed — re-exports/dependents stay correct — ' +
89
+ 'but only matching modules are emitted. Diagnostics are not filtered ' +
90
+ 'and may reference modules dropped from output.', collect)
91
+ .option('--pretty', 'Pretty-print JSON output', false)
92
+ .option('-q, --quiet', 'Suppress info messages on stderr (warnings and errors still print)', false)
93
+ .addHelpText('after', `
94
+ Examples:
95
+ $ svelte-docinfo Analyze current project
96
+ $ svelte-docinfo ./packages/my-lib Analyze specific directory
97
+ $ svelte-docinfo -o docs.json Write to file
98
+ $ svelte-docinfo --source-dir src Non-SvelteKit project (src/ root)
99
+ $ svelte-docinfo --source-dir src/lib --source-dir src/routes
100
+ Multiple source dirs (source-root auto-derived as 'src')
101
+ $ svelte-docinfo --source-dir src/lib --source-dir lib/utils --source-root .
102
+ No common prefix — module paths stay project-relative
103
+ $ svelte-docinfo --discovery glob Skip package.json exports
104
+ $ svelte-docinfo --discovery exports Strict — fail if exports missing
105
+ $ svelte-docinfo --on-duplicates throw Enforce flat namespace
106
+ $ svelte-docinfo --only 'components/**' Emit only modules under components/
107
+ $ svelte-docinfo --only '*.svelte' Emit only Svelte modules (top-level)
108
+ $ svelte-docinfo | jq . Pipe to jq for readable output`)
109
+ .action(async (projectRoot, raw) => {
110
+ try {
111
+ // Validate enum-shaped options before constructing the rest of the options.
112
+ // Commander accepts arbitrary strings; we narrow to the allowed sets.
113
+ if (raw.onDuplicates !== undefined && !isOnDuplicatesFlag(raw.onDuplicates)) {
114
+ throw new Error(`Invalid --on-duplicates value: "${raw.onDuplicates}". ` +
115
+ `Expected one of: ${ON_DUPLICATES_VALUES.join(', ')}`);
116
+ }
117
+ if (raw.discovery !== undefined && !isDiscoveryFlag(raw.discovery)) {
118
+ throw new Error(`Invalid --discovery value: "${raw.discovery}". ` +
119
+ `Expected one of: ${DISCOVERY_VALUES.join(', ')}`);
120
+ }
121
+ const options = {
122
+ include: raw.include,
123
+ exclude: raw.exclude,
124
+ output: raw.output,
125
+ resolveDependencies: raw.resolveDependencies,
126
+ discovery: raw.discovery,
127
+ distDir: raw.distDir,
128
+ sourceDir: raw.sourceDir,
129
+ sourceRoot: raw.sourceRoot,
130
+ onDuplicates: raw.onDuplicates,
131
+ only: raw.only,
132
+ quiet: raw.quiet,
133
+ pretty: raw.pretty,
134
+ };
135
+ const resolvedRoot = resolve(projectRoot);
136
+ // Stderr logger — `--quiet` only mutes info; warnings and errors always print
137
+ // so silent CI runs still surface actionable signal.
138
+ const log = {
139
+ info: options.quiet ? () => { } : (msg) => console.error(msg),
140
+ warn: (msg) => console.error(`warning: ${msg}`),
141
+ error: (msg) => console.error(`error: ${msg}`),
142
+ };
143
+ // Build sourceOptions only when source-dir or source-root is specified,
144
+ // so the default (`['src/lib']`) flows through `createSourceOptions`.
145
+ // `!== undefined` rather than truthy: `--source-root ''` (or `--source-root .`,
146
+ // aliased internally) is a valid opt-in for project-relative module paths
147
+ // when sourcePaths share no common prefix.
148
+ const sourceOptions = options.sourceDir !== undefined || options.sourceRoot !== undefined
149
+ ? {
150
+ ...(options.sourceDir !== undefined ? { sourcePaths: options.sourceDir } : {}),
151
+ ...(options.sourceRoot !== undefined ? { sourceRoot: options.sourceRoot } : {}),
152
+ }
153
+ : undefined;
154
+ const onDuplicates = options.onDuplicates;
155
+ const { modules, diagnostics } = await analyzeFromFiles({
156
+ projectRoot: resolvedRoot,
157
+ include: options.include,
158
+ exclude: options.exclude,
159
+ resolveDependencies: options.resolveDependencies,
160
+ discovery: options.discovery,
161
+ distDir: options.distDir,
162
+ ...(sourceOptions !== undefined ? { sourceOptions } : {}),
163
+ ...(onDuplicates !== undefined ? { onDuplicates } : {}),
164
+ log,
165
+ });
166
+ // `--only` is an output-only filter: analysis ran against the full
167
+ // owned set so re-exports/dependents/`alsoExportedFrom` are correct,
168
+ // then matching modules are kept for emission. Diagnostics pass
169
+ // through untouched — filtering them by the same patterns would
170
+ // silently drop warnings about modules the user excluded from output.
171
+ const matchOnly = options.only && picomatch(options.only);
172
+ const emittedModules = matchOnly ? modules.filter((m) => matchOnly(m.path)) : modules;
173
+ // `AnalyzeResultJson` is the wire-format contract — both `modules`
174
+ // and `diagnostics` default to `[]` on `.parse()`, so empty arrays
175
+ // stripped here round-trip losslessly through the schema. Consumers
176
+ // programmatically ingesting analysis JSON should parse through
177
+ // `AnalyzeResultJson` to restore defaults; raw-JSON consumers
178
+ // (`jq '.diagnostics | length'` returns `0` on `{}` since jq treats
179
+ // null length as 0) don't need the parse step.
180
+ const jsonOutput = JSON.stringify({ modules: emittedModules, diagnostics }, compactReplacer, options.pretty ? 2 : undefined);
181
+ // Write output. `-o -` is the conventional stdout sentinel
182
+ // (matches gzip, curl, cat); accept it as an explicit form so
183
+ // `svelte-docinfo -o "$OUT"` works when $OUT=-.
184
+ if (options.output && options.output !== '-') {
185
+ await writeFile(options.output, jsonOutput + '\n');
186
+ log.info(`Wrote output to ${options.output}`);
187
+ }
188
+ else {
189
+ console.log(jsonOutput);
190
+ }
191
+ exitCode = hasErrors(diagnostics) ? 1 : 0;
192
+ }
193
+ catch (error) {
194
+ // Friendly one-line error for users; full stack only on DEBUG=1
195
+ // so CI logs and bug reports can still capture it on demand.
196
+ const message = error instanceof Error ? error.message : String(error);
197
+ console.error(`error: ${message}`);
198
+ if (process.env.DEBUG) {
199
+ console.error(error);
200
+ }
201
+ exitCode = 2;
202
+ }
203
+ });
204
+ await program.parseAsync(argv);
205
+ return exitCode;
206
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Internal concurrency helpers — bounded `Promise.all` for the few sites
3
+ * where unbounded fan-out would risk resource exhaustion.
4
+ *
5
+ * - `MAX_FILE_CONCURRENCY` — parallel `readFile` cap. Bounds FD pressure so
6
+ * projects with thousands of source files don't trip `EMFILE` against the
7
+ * typical 1024-FD ulimit. Used by `files.globFiles` and `exports.discoverFromExports`.
8
+ * - `MAX_RESOLVE_CONCURRENCY` — parallel resolver-call cap for session phase 2.
9
+ * Async resolvers (Vite/Rollup `resolveId`, user-supplied) get backpressure
10
+ * instead of a 20k+ task fan-out at once. Sync resolvers (TS default,
11
+ * no-deps stub) settle in microtasks regardless of the bound.
12
+ *
13
+ * Same numerical value today, separately named so a future tuning pass can
14
+ * move them independently (FD pressure and resolver backpressure are unrelated
15
+ * limits that happen to coincide at this cap).
16
+ *
17
+ * @module
18
+ */
19
+ export declare const MAX_FILE_CONCURRENCY = 100;
20
+ export declare const MAX_RESOLVE_CONCURRENCY = 100;
21
+ /**
22
+ * Maps over `items` with a bounded number of in-flight promises, preserving
23
+ * input order.
24
+ *
25
+ * Fail-fast: when `fn` rejects, the outer promise rejects with that error and
26
+ * idle workers stop pulling from the queue (already-in-flight `fn` calls run
27
+ * to completion — there's no `AbortSignal` plumbing). Subsequent rejections
28
+ * from in-flight calls are swallowed by `Promise.all` (only the first wins),
29
+ * so a misbehaving `fn` can't surface a second error after the function
30
+ * returns.
31
+ *
32
+ * @param items - input array
33
+ * @param concurrency - maximum number of concurrent operations
34
+ * @param fn - mapping function (receives item and index)
35
+ * @returns array of results in input order
36
+ */
37
+ export declare const map_concurrent: <T, R>(items: ReadonlyArray<T>, concurrency: number, fn: (item: T, index: number) => Promise<R>) => Promise<Array<R>>;
38
+ //# sourceMappingURL=concurrency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/concurrency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,EAAE,CAAC,EACxC,OAAO,aAAa,CAAC,CAAC,CAAC,EACvB,aAAa,MAAM,EACnB,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,KACxC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAkBlB,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Internal concurrency helpers — bounded `Promise.all` for the few sites
3
+ * where unbounded fan-out would risk resource exhaustion.
4
+ *
5
+ * - `MAX_FILE_CONCURRENCY` — parallel `readFile` cap. Bounds FD pressure so
6
+ * projects with thousands of source files don't trip `EMFILE` against the
7
+ * typical 1024-FD ulimit. Used by `files.globFiles` and `exports.discoverFromExports`.
8
+ * - `MAX_RESOLVE_CONCURRENCY` — parallel resolver-call cap for session phase 2.
9
+ * Async resolvers (Vite/Rollup `resolveId`, user-supplied) get backpressure
10
+ * instead of a 20k+ task fan-out at once. Sync resolvers (TS default,
11
+ * no-deps stub) settle in microtasks regardless of the bound.
12
+ *
13
+ * Same numerical value today, separately named so a future tuning pass can
14
+ * move them independently (FD pressure and resolver backpressure are unrelated
15
+ * limits that happen to coincide at this cap).
16
+ *
17
+ * @module
18
+ */
19
+ export const MAX_FILE_CONCURRENCY = 100;
20
+ export const MAX_RESOLVE_CONCURRENCY = 100;
21
+ /**
22
+ * Maps over `items` with a bounded number of in-flight promises, preserving
23
+ * input order.
24
+ *
25
+ * Fail-fast: when `fn` rejects, the outer promise rejects with that error and
26
+ * idle workers stop pulling from the queue (already-in-flight `fn` calls run
27
+ * to completion — there's no `AbortSignal` plumbing). Subsequent rejections
28
+ * from in-flight calls are swallowed by `Promise.all` (only the first wins),
29
+ * so a misbehaving `fn` can't surface a second error after the function
30
+ * returns.
31
+ *
32
+ * @param items - input array
33
+ * @param concurrency - maximum number of concurrent operations
34
+ * @param fn - mapping function (receives item and index)
35
+ * @returns array of results in input order
36
+ */
37
+ export const map_concurrent = async (items, concurrency, fn) => {
38
+ const results = new Array(items.length);
39
+ let next = 0;
40
+ let failed = false;
41
+ const worker = async () => {
42
+ while (!failed) {
43
+ const i = next++;
44
+ if (i >= items.length)
45
+ return;
46
+ try {
47
+ results[i] = await fn(items[i], i);
48
+ }
49
+ catch (err) {
50
+ failed = true;
51
+ throw err;
52
+ }
53
+ }
54
+ };
55
+ await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => worker()));
56
+ return results;
57
+ };
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Types for incremental declaration construction during analysis.
3
+ *
4
+ * These types are used by the analysis layer (`typescript-extract-*.ts`,
5
+ * `typescript-exports.ts`, `svelte.ts`, `tsdoc.ts`) to build declarations before
6
+ * Zod validation. Most consumers work with the validated types from `types.ts`,
7
+ * but these are available for advanced use cases.
8
+ *
9
+ * @see `types.ts` for consumer-facing Zod schemas (`DeclarationJson`, `ModuleJson`)
10
+ * @see `typescript-exports.ts` and `typescript-extract-*.ts` for TypeScript declaration analysis
11
+ * @see `svelte.ts` for Svelte component analysis
12
+ *
13
+ * @module
14
+ */
15
+ import { z } from 'zod';
16
+ import type { DeclarationKind, DeclarationModifier, GenericParamJson, MemberKind, ParameterJson, OverloadJsonInput, ComponentPropJsonInput, Reactivity } from './types.js';
17
+ /**
18
+ * Information about a same-name re-export.
19
+ *
20
+ * Collected during phase 1 of analysis and passed to `mergeReExports`
21
+ * in phase 2 to build `alsoExportedFrom` arrays on canonical declarations.
22
+ */
23
+ export interface ReExportInfo {
24
+ /**
25
+ * Name of the re-exported declaration. `'default'` for default-slot
26
+ * re-exports (`export {default} from './x'`) — that's the canonical's
27
+ * actual symbol name in the original module.
28
+ */
29
+ name: string;
30
+ /** Module path (relative to `sourceRoot`) where the declaration is originally declared. */
31
+ originalModule: string;
32
+ }
33
+ /**
34
+ * Permissive type for constructing members incrementally before Zod validation.
35
+ *
36
+ * Used by internal analysis functions in `typescript-extract-*.ts` that build members
37
+ * by mutating a plain object. The discriminated union schema (`MemberJson`)
38
+ * validates the final shape at the `ModuleJson.parse()` boundary.
39
+ *
40
+ * Mirrors `DeclarationJsonBuild` for the same reason: construction sites
41
+ * determine `kind` at runtime, so TypeScript can't narrow the union during
42
+ * incremental field assignment.
43
+ */
44
+ export interface MemberJsonBuild {
45
+ name?: string;
46
+ kind: MemberKind;
47
+ docComment?: string;
48
+ typeSignature?: string;
49
+ modifiers?: Array<DeclarationModifier>;
50
+ sourceLine?: number;
51
+ genericParams?: Array<GenericParamJson>;
52
+ parameters?: Array<z.input<typeof ParameterJson>>;
53
+ returnType?: string;
54
+ returnDescription?: string;
55
+ overloads?: Array<OverloadJsonInput>;
56
+ examples?: Array<string>;
57
+ deprecatedMessage?: string;
58
+ seeAlso?: Array<string>;
59
+ throws?: Array<{
60
+ type?: string;
61
+ description: string;
62
+ }>;
63
+ since?: string;
64
+ mutates?: Record<string, string>;
65
+ reactivity?: Reactivity;
66
+ partial?: boolean;
67
+ /** Whether the member has a `?` token in its declaration. Function and variable members only. */
68
+ optional?: boolean;
69
+ /** Default value documented via `@default`. Variable members only. */
70
+ defaultValue?: string;
71
+ }
72
+ /**
73
+ * Permissive type for constructing declarations incrementally before Zod validation.
74
+ *
75
+ * Used by internal analysis functions (`analyzeDeclaration`, `extractFunctionInfo`, etc.)
76
+ * that build declarations by mutating a plain object. The discriminated union schema
77
+ * validates the final shape at the `ModuleJson.parse()` boundary.
78
+ */
79
+ export interface DeclarationJsonBuild {
80
+ name?: string;
81
+ kind: DeclarationKind;
82
+ docComment?: string;
83
+ typeSignature?: string;
84
+ modifiers?: Array<DeclarationModifier>;
85
+ sourceLine?: number;
86
+ parameters?: Array<z.input<typeof ParameterJson>>;
87
+ returnType?: string;
88
+ returnDescription?: string;
89
+ genericParams?: Array<GenericParamJson>;
90
+ overloads?: Array<OverloadJsonInput>;
91
+ examples?: Array<string>;
92
+ deprecatedMessage?: string;
93
+ seeAlso?: Array<string>;
94
+ throws?: Array<{
95
+ type?: string;
96
+ description: string;
97
+ }>;
98
+ since?: string;
99
+ mutates?: Record<string, string>;
100
+ extends?: string | Array<string>;
101
+ intersects?: Array<string>;
102
+ implements?: Array<string>;
103
+ members?: Array<MemberJsonBuild>;
104
+ props?: Array<ComponentPropJsonInput>;
105
+ acceptsChildren?: boolean;
106
+ lang?: 'js';
107
+ alsoExportedFrom?: Array<string>;
108
+ aliasOf?: {
109
+ module: string;
110
+ name: string;
111
+ };
112
+ reactivity?: Reactivity;
113
+ partial?: boolean;
114
+ /** Source module path for `kind: 'namespace'` declarations (`export * as ns from './x'`). */
115
+ module?: string;
116
+ /** Default value documented via `@default`. Variable declarations only. */
117
+ defaultValue?: string;
118
+ }
119
+ /**
120
+ * Result of analyzing a single declaration.
121
+ *
122
+ * Produced by `analyzeDeclaration` (in `typescript-exports.ts`) and Svelte component analysis.
123
+ * Used by `analyzeModule` to filter `@nodocs` declarations before output.
124
+ *
125
+ * Uses `DeclarationJsonBuild` (not `DeclarationJsonInput`) because declarations
126
+ * are constructed incrementally — Zod validation happens at the `ModuleJson.parse()` boundary.
127
+ */
128
+ export interface DeclarationAnalysis {
129
+ /** The analyzed declaration metadata (pre-validation). */
130
+ declaration: DeclarationJsonBuild;
131
+ /** Whether the declaration is marked `@nodocs` (should be excluded from documentation). */
132
+ nodocs: boolean;
133
+ }
134
+ /**
135
+ * Result of analyzing a module's exports.
136
+ *
137
+ * Produced by `analyzeExports` in `typescript-exports.ts`.
138
+ */
139
+ export interface ModuleExportsAnalysis {
140
+ /** Module-level documentation comment. */
141
+ moduleComment?: string;
142
+ /** All exported declarations with `@nodocs` flags — consumer filters based on policy. */
143
+ declarations: Array<DeclarationAnalysis>;
144
+ /** Same-name re-exports (for building `alsoExportedFrom` in post-processing). */
145
+ reExports: Array<ReExportInfo>;
146
+ /** Star exports (`export * from './module'`) — module paths that are fully re-exported. */
147
+ starExports: Array<string>;
148
+ }
149
+ /**
150
+ * Result of analyzing a module (TypeScript or Svelte).
151
+ *
152
+ * Produced by `analyzeTypescriptModule` and `analyzeSvelteModule`.
153
+ * Both analyzers return this same structure for uniform handling
154
+ * by `analyzeModule` in `analyze-core.ts`.
155
+ */
156
+ export interface ModuleAnalysis extends ModuleExportsAnalysis {
157
+ /** Module path relative to source root. */
158
+ path: string;
159
+ /** Dependencies (other source modules this module imports). Empty if none. */
160
+ dependencies: Array<string>;
161
+ /** Dependents (other source modules that import this module). Empty if none. */
162
+ dependents: Array<string>;
163
+ }
164
+ //# sourceMappingURL=declaration-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaration-build.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/declaration-build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,KAAK,EACX,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,UAAU,EACV,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,cAAc,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACxC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAC,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qB;IAC5D,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,gFAAgF;IAChF,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC1B"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Types for incremental declaration construction during analysis.
3
+ *
4
+ * These types are used by the analysis layer (`typescript-extract-*.ts`,
5
+ * `typescript-exports.ts`, `svelte.ts`, `tsdoc.ts`) to build declarations before
6
+ * Zod validation. Most consumers work with the validated types from `types.ts`,
7
+ * but these are available for advanced use cases.
8
+ *
9
+ * @see `types.ts` for consumer-facing Zod schemas (`DeclarationJson`, `ModuleJson`)
10
+ * @see `typescript-exports.ts` and `typescript-extract-*.ts` for TypeScript declaration analysis
11
+ * @see `svelte.ts` for Svelte component analysis
12
+ *
13
+ * @module
14
+ */
15
+ import { z } from 'zod';