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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) fuz.dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,349 @@
1
+ # svelte-docinfo
2
+
3
+ [<img src="static/logo.svg" alt="a cyan scroll with curling ends" align="right" width="192" height="192">](https://svelte-docinfo.fuz.dev/)
4
+
5
+ > static analysis for TypeScript and Svelte 📜
6
+ > [**svelte-docinfo.fuz.dev**](https://svelte-docinfo.fuz.dev/)
7
+
8
+ **svelte-docinfo** extracts JSON describing the exports
9
+ of TypeScript and Svelte modules for open ended use cases
10
+ like docs, code search, and dev tools.
11
+ It uses
12
+ [svelte2tsx](https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx)
13
+ and the TypeScript compiler API to resolve types, track exports, and extract semantic details.
14
+ The [npm package](https://www.npmjs.com/package/svelte-docinfo)
15
+ has a Vite plugin, CLI, and programmatic API.
16
+
17
+ ```bash
18
+ npm install svelte-docinfo -D
19
+ ```
20
+
21
+ [npm](https://www.npmjs.com/package/svelte-docinfo)
22
+
23
+ - [Quick start](#quick-start)
24
+ - [Vite plugin](#vite-plugin)
25
+ - [CLI](#cli)
26
+ - [API](#api)
27
+ - [Features](#features)
28
+ - [Documentation](#documentation)
29
+ - [Credits](#credits)
30
+ - [License](#license)
31
+
32
+ Dependencies are minimal and the tool's scope is limited to data, not presentation.
33
+ The [docs website](https://svelte-docinfo.fuz.dev/docs/api)
34
+ for svelte-docinfo is made using itself
35
+ and [fuz_ui](https://github.com/fuzdev/fuz_ui) components.
36
+
37
+ svelte-docinfo is largely inspired by [`sveld`](https://github.com/carbon-design-system/sveld),
38
+ but instead of AST-only inspection it uses the TypeScript compiler API for richer information,
39
+ and also analyzes TypeScript modules.
40
+ The docs [compare](https://svelte-docinfo.fuz.dev/docs/introduction#Compared-to-sveld) them.
41
+
42
+ This is an early release --
43
+ there are gaps to be filled and design choices to make,
44
+ but for Svelte 5 it's mostly complete and used in production websites.
45
+ Please open issues for bugs
46
+ and [discussions](https://github.com/fuzdev/svelte-docinfo/discussions)
47
+ for everything else!
48
+
49
+ **AI disclosure:** the code and docs beyond the intro were written by Claude Code with uneven human guidance.
50
+
51
+ ## Quick start
52
+
53
+ Given a project with a couple of files in `src/lib/`:
54
+
55
+ ```ts
56
+ // src/lib/math.ts
57
+
58
+ /**
59
+ * Add two numbers.
60
+ * @param a - first number
61
+ * @param b - second number
62
+ * @returns the sum
63
+ */
64
+ export const add = (a: number, b: number): number => a + b;
65
+ ```
66
+
67
+ ```svelte
68
+ <!-- src/lib/Calculator.svelte -->
69
+
70
+ <!--
71
+ @component
72
+ Calculator component for demonstrating Svelte analysis.
73
+ -->
74
+ <script lang="ts">
75
+ let {
76
+ result = $bindable(0),
77
+ mode = 'add',
78
+ disabled = false,
79
+ }: {
80
+ /** Current result (bindable). */
81
+ result?: number;
82
+ /** Operation mode. */
83
+ mode?: 'add' | 'multiply';
84
+ /** Disable the calculator. */
85
+ disabled?: boolean;
86
+ } = $props();
87
+ </script>
88
+ ```
89
+
90
+ Three ways to integrate `svelte-docinfo`:
91
+
92
+ 1. [Vite plugin](#vite-plugin) - recommended for SvelteKit and Vite projects. Serves a virtual module with HMR in dev mode:
93
+
94
+ ```ts
95
+ // vite.config.ts
96
+ import svelteDocinfo from 'svelte-docinfo/vite.js';
97
+
98
+ export default defineConfig({plugins: [sveltekit(), svelteDocinfo()]});
99
+ // then anywhere in your app: import {modules} from 'virtual:svelte-docinfo';
100
+ ```
101
+
102
+ 2. [CLI](#cli) - quick analysis from the command line, useful for ad-hoc inspection and shell pipelines:
103
+
104
+ ```bash
105
+ npx svelte-docinfo --pretty
106
+ ```
107
+
108
+ 3. [API](#api) - programmatic access for build tools, custom pipelines, and standalone scripts:
109
+
110
+ ```ts
111
+ import {analyzeFromFiles} from 'svelte-docinfo';
112
+
113
+ const {modules} = await analyzeFromFiles({projectRoot: process.cwd()});
114
+ ```
115
+
116
+ All three produce the same JSON shape:
117
+
118
+ ```json
119
+ {
120
+ "modules": [
121
+ {
122
+ "path": "Calculator.svelte",
123
+ "declarations": [
124
+ {
125
+ "name": "Calculator",
126
+ "kind": "component",
127
+ "docComment": "Calculator component for demonstrating Svelte analysis.",
128
+ "sourceLine": 5,
129
+ "props": [
130
+ {
131
+ "name": "result",
132
+ "type": "number",
133
+ "optional": true,
134
+ "description": "Current result (bindable).",
135
+ "defaultValue": "0",
136
+ "bindable": true
137
+ },
138
+ {
139
+ "name": "mode",
140
+ "type": "\"add\" | \"multiply\"",
141
+ "optional": true,
142
+ "description": "Operation mode.",
143
+ "defaultValue": "'add'"
144
+ },
145
+ {
146
+ "name": "disabled",
147
+ "type": "boolean",
148
+ "optional": true,
149
+ "description": "Disable the calculator.",
150
+ "defaultValue": "false"
151
+ }
152
+ ]
153
+ }
154
+ ]
155
+ },
156
+ {
157
+ "path": "math.ts",
158
+ "declarations": [
159
+ {
160
+ "name": "add",
161
+ "kind": "function",
162
+ "docComment": "Add two numbers.",
163
+ "typeSignature": "(a: number, b: number): number",
164
+ "sourceLine": 7,
165
+ "parameters": [
166
+ {"name": "a", "type": "number", "description": "first number"},
167
+ {"name": "b", "type": "number", "description": "second number"}
168
+ ],
169
+ "returnType": "number",
170
+ "returnDescription": "the sum"
171
+ }
172
+ ]
173
+ }
174
+ ]
175
+ }
176
+ ```
177
+
178
+ ## Vite plugin
179
+
180
+ 1. Add the plugin to `vite.config.ts`:
181
+
182
+ ```ts
183
+ import {defineConfig} from 'vite';
184
+ import {sveltekit} from '@sveltejs/kit/vite';
185
+ import svelteDocinfo from 'svelte-docinfo/vite.js';
186
+
187
+ export default defineConfig({
188
+ plugins: [sveltekit(), svelteDocinfo()],
189
+ });
190
+ ```
191
+
192
+ 2. Add TypeScript support in `app.d.ts`:
193
+
194
+ ```ts
195
+ /// <reference types="svelte-docinfo/virtual-svelte-docinfo.js" />
196
+ ```
197
+
198
+ 3. Import the virtual module anywhere in your app:
199
+
200
+ ```ts
201
+ import {modules, diagnostics} from 'virtual:svelte-docinfo';
202
+ // or: import data from 'virtual:svelte-docinfo';
203
+ ```
204
+
205
+ Plugin options:
206
+
207
+ | Option | Default | Description |
208
+ | --------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
209
+ | `projectRoot` | Vite's resolved `config.root` | Absolute path to project root. |
210
+ | `include` | — | Glob patterns to include (relative to `projectRoot`). Collapses `discovery: 'auto'` to glob; combining with `discovery: 'exports'` throws. |
211
+ | `exclude` | `['**/*.test.ts', '**/*.spec.ts']` | Glob patterns to exclude (fully replaces defaults — does not merge with `**/*.test.ts`, `**/*.spec.ts`). |
212
+ | `discovery` | `'auto'` | Discovery strategy: `'auto'` \| `'exports'` \| `'glob'`. `'exports'` is strict and fails if `package.json` exports is missing or empty. |
213
+ | `distDir` | `'dist'` | Dist directory name for exports-based discovery. |
214
+ | `sourceOptions` | `{sourcePaths: ['src/lib'], …}` | Partial overrides for default source options (SvelteKit `src/lib` layout). |
215
+ | `resolveDependencies` | `true` | Resolve import dependencies. When `false`, `dependencies`/`dependents` stay empty. |
216
+ | `onDuplicates` | — | Dispatch on duplicate declaration names: `'throw'` \| `'warn'` \| callback. Diagnostic emits regardless of dispatch. |
217
+ | `hmrDebounceMs` | `100` | HMR debounce delay in milliseconds. |
218
+
219
+ The options interface is `VitePluginSvelteDocinfoOptions` from `svelte-docinfo/vite.js` (not re-exported from the main barrel).
220
+ See the [docs site](https://svelte-docinfo.fuz.dev/) and [examples/vite/](examples/vite/README.md) for more.
221
+
222
+ > If TypeScript reports `Cannot find module 'virtual:svelte-docinfo'`, ensure the `/// <reference>` line is in your `app.d.ts`.
223
+
224
+ ## CLI
225
+
226
+ ```bash
227
+ npx svelte-docinfo # analyze cwd, print JSON to stdout
228
+ npx svelte-docinfo -o output.json # write to a file instead
229
+ npx svelte-docinfo ./packages/my-lib # analyze a specific directory
230
+ npx svelte-docinfo --pretty # pretty-print the JSON output
231
+ ```
232
+
233
+ Output is compact JSON by default. Use `--pretty` for readable output,
234
+ or pipe through `jq` for queries:
235
+
236
+ ```bash
237
+ npx svelte-docinfo | jq '.modules | length' # count modules
238
+ npx svelte-docinfo | jq -r '.modules[].declarations[].name' # list all exported names
239
+ ```
240
+
241
+ Info messages print to stderr; only JSON goes to stdout. The terminal interleaves
242
+ them visually, but `>` and `|` capture clean JSON. Use `-q`/`--quiet` to suppress info on
243
+ stderr (warnings and errors still print).
244
+
245
+ All CLI options:
246
+
247
+ | Flag | Description |
248
+ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
249
+ | `[project-root]` | Project root directory (default: cwd) |
250
+ | `-i, --include <pattern>` | Include pattern (repeatable, replaces exports discovery; incompatible with `--discovery exports`) |
251
+ | `-e, --exclude <pattern>` | Exclude glob, applied at discovery and analysis (repeatable; fully replaces defaults — does not merge with `**/*.test.ts`, `**/*.spec.ts`) |
252
+ | `-o, --output <file>` | Output file (default: stdout; pass `-` for explicit stdout, so `-o "$OUT"` works when `$OUT=-`) |
253
+ | `--discovery <mode>` | `auto` \| `exports` \| `glob` (default: `auto` — exports first, glob fallback). `exports` is strict and fails if package.json exports is missing |
254
+ | `--dist-dir <dir>` | Dist directory for exports discovery (default: dist) |
255
+ | `--source-dir <dir>` | Source directory relative to project root (default: src/lib). Repeatable for monorepos; drives the implicit include glob when no `--include` is provided |
256
+ | `--source-root <dir>` | Source root for module-path stripping (default: single source-dir or longest common prefix; pass `.` for project-relative paths) |
257
+ | `--on-duplicates <mode>` | Dispatch on duplicate declaration names: `throw` \| `warn` (default: emit `duplicate_declaration` diagnostic, no dispatch) |
258
+ | `--only <pattern>` | Glob filter applied to module paths in output (repeatable). Full project is still analyzed (re-exports/dependents stay correct); diagnostics aren't filtered |
259
+ | `--no-resolve-dependencies` | Disable dependency resolution |
260
+ | `--pretty` | Pretty-print JSON output (default: compact) |
261
+ | `-q, --quiet` | Suppress info messages on stderr (warnings and errors still print) |
262
+ | `-V, --version` | Show version number |
263
+
264
+ Exit codes: 0 (success), 1 (analysis errors), 2 (CLI errors).
265
+
266
+ See [examples/cli/](examples/cli/README.md) for more usage patterns.
267
+
268
+ ## API
269
+
270
+ Three entry points, same `AnalyzeResultJson` shape (`{modules, diagnostics}`):
271
+
272
+ | Function | Use when |
273
+ | ----------------------- | ------------------------------------------------------------------------------------------------- |
274
+ | `analyzeFromFiles` | One-shot. Standalone projects — handles file discovery and dependency resolution |
275
+ | `analyze` | One-shot. Build-tool integration — you supply `SourceFileInfo[]` already in memory |
276
+ | `createAnalysisSession` | Incremental. Long-lived consumers (Vite plugin, LSP-style tools) reusing parsed ASTs across calls |
277
+
278
+ For most projects, `analyzeFromFiles` is all you need. It reads your `package.json` exports
279
+ to discover source files, falling back to glob patterns:
280
+
281
+ ```ts
282
+ import {analyzeFromFiles} from 'svelte-docinfo';
283
+
284
+ const {modules} = await analyzeFromFiles({projectRoot: process.cwd()});
285
+ ```
286
+
287
+ Pass `include` for custom patterns or `discovery: 'glob'` to always use glob.
288
+ Use `discovery: 'exports'` for strict mode that throws if `package.json` has no usable `exports` field.
289
+ When you already have file contents in memory,
290
+ use `analyze` instead of `analyzeFromFiles` to skip file discovery.
291
+ For just the discovery step (without running analysis), use
292
+ `discoverSourceFiles` from `svelte-docinfo/discovery.js`.
293
+
294
+ For long-lived consumers (a Vite plugin reacting to file edits, an LSP-style tool),
295
+ `createAnalysisSession` returns a persistent handle that reuses parsed ASTs across calls
296
+ — see [examples/api/analyze-session.js](examples/api/analyze-session.js).
297
+
298
+ See [examples/api/](examples/api/README.md) for more patterns
299
+ including custom discovery, diagnostics, sessions, and error handling.
300
+
301
+ Import from `svelte-docinfo` for the common API,
302
+ or from subpaths like `svelte-docinfo/typescript-exports.js` for lower-level access.
303
+ See the [API docs](https://svelte-docinfo.fuz.dev/docs/api) for the full reference.
304
+
305
+ ## Features
306
+
307
+ - **Full type resolution**: infers complex types without manual annotations, including generics, imported types, and inferred return types
308
+ - **TSDoc/JSDoc parsing**: standard tags (`@param`, `@returns`, `@throws`, `@example`, `@deprecated`, `@see`, `@since`, `@default`) plus `@nodocs`, `@mutates`, and `@module` for file-level comments
309
+ - **Svelte 5 component props**: extracts prop types, descriptions, defaults, and bindability via svelte2tsx
310
+ - **Svelte 5 snippets**: `kind: 'snippet'` for template snippets (with structured parameters), `acceptsChildren` on components
311
+ - **Svelte 5 reactivity runes**: detects `$state`, `$state.raw`, `$derived`, `$derived.by` on variables and class fields (`reactivity` field) — syntactic detection, surfaces wherever the rune pattern appears
312
+ - **Class members**: public + protected fields, methods, constructors, getters/setters, generics; private (`private` and `#field`) excluded
313
+ - **Enums**: regular and const, with member values and per-member JSDoc
314
+ - **Function overloads**: all public overload signatures with per-overload JSDoc
315
+ - **Dependency graphs**: tracks imports between modules and computes dependents
316
+ - **Re-export tracking**: `alsoExportedFrom` arrays, `aliasOf` for renames, `starExports` for `export * from './x'`
317
+ - **Namespace re-exports**: `export * as ns from './x'` synthesized as `kind: 'namespace'`
318
+ - **Source locations**: file and line for every declaration
319
+ - **Build-tool agnostic**: works with any source: file system, build pipeline, or in-memory
320
+ - **Diagnostic collection**: accumulates warnings and errors without halting; `partial: true` flags incomplete declarations
321
+
322
+ Known gaps: standalone `namespace Foo {}` declarations and decorators are not yet supported. Svelte 4 legacy features (slots, events, context, `$restProps`) are out of scope — Svelte 5 snippets and callback props replace most of them.
323
+ [Issues](https://github.com/fuzdev/svelte-docinfo/issues) and
324
+ [discussions](https://github.com/fuzdev/svelte-docinfo/discussions) are welcome!
325
+
326
+ ## Documentation
327
+
328
+ - [svelte-docinfo.fuz.dev](https://svelte-docinfo.fuz.dev/) - docs site with guides, options reference, and API docs
329
+ - [examples/vite/](examples/vite/README.md) - Vite plugin with HMR
330
+ - [examples/cli/](examples/cli/README.md) - CLI usage and piping
331
+ - [examples/api/](examples/api/README.md) - API usage patterns
332
+
333
+ ## Credits
334
+
335
+ [`sveld`](https://github.com/carbon-design-system/sveld) was the main inspiration.
336
+
337
+ Extracted from [fuz_ui](https://github.com/fuzdev/fuz_ui),
338
+ which has example components using the data for docs websites.
339
+
340
+ `svelte-docinfo` is more featureful than it would be
341
+ otherwise thanks to LLM assistance, mostly Claude Code.
342
+
343
+ Built on [TypeScript](https://github.com/microsoft/TypeScript) and
344
+ [svelte2tsx](https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx),
345
+ see [package.json](package.json) for full dependencies.
346
+
347
+ ## License
348
+
349
+ [MIT](LICENSE)