svelte-docinfo 0.5.5 → 0.7.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 (88) hide show
  1. package/README.md +54 -31
  2. package/dist/analyze-core.d.ts +179 -24
  3. package/dist/analyze-core.d.ts.map +1 -1
  4. package/dist/analyze-core.js +452 -32
  5. package/dist/analyze.d.ts +31 -6
  6. package/dist/analyze.d.ts.map +1 -1
  7. package/dist/analyze.js +25 -5
  8. package/dist/cli.d.ts +17 -7
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +8 -5
  11. package/dist/declaration-build.d.ts +14 -4
  12. package/dist/declaration-build.d.ts.map +1 -1
  13. package/dist/declaration-helpers.d.ts +65 -42
  14. package/dist/declaration-helpers.d.ts.map +1 -1
  15. package/dist/declaration-helpers.js +167 -72
  16. package/dist/dep-resolver.d.ts +38 -13
  17. package/dist/dep-resolver.d.ts.map +1 -1
  18. package/dist/dep-resolver.js +38 -20
  19. package/dist/diagnostics.d.ts +365 -14
  20. package/dist/diagnostics.d.ts.map +1 -1
  21. package/dist/diagnostics.js +98 -14
  22. package/dist/discovery.d.ts +7 -2
  23. package/dist/discovery.d.ts.map +1 -1
  24. package/dist/discovery.js +9 -3
  25. package/dist/exports.d.ts +39 -2
  26. package/dist/exports.d.ts.map +1 -1
  27. package/dist/exports.js +248 -43
  28. package/dist/files.d.ts +14 -2
  29. package/dist/files.d.ts.map +1 -1
  30. package/dist/files.js +48 -7
  31. package/dist/index.d.ts +5 -3
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -2
  34. package/dist/paths.d.ts +22 -1
  35. package/dist/paths.d.ts.map +1 -1
  36. package/dist/paths.js +22 -1
  37. package/dist/postprocess.d.ts +31 -10
  38. package/dist/postprocess.d.ts.map +1 -1
  39. package/dist/postprocess.js +112 -64
  40. package/dist/session.d.ts +101 -11
  41. package/dist/session.d.ts.map +1 -1
  42. package/dist/session.js +449 -119
  43. package/dist/source-config.d.ts +210 -33
  44. package/dist/source-config.d.ts.map +1 -1
  45. package/dist/source-config.js +313 -26
  46. package/dist/source.d.ts +35 -0
  47. package/dist/source.d.ts.map +1 -1
  48. package/dist/source.js +37 -0
  49. package/dist/svelte.d.ts +81 -23
  50. package/dist/svelte.d.ts.map +1 -1
  51. package/dist/svelte.js +546 -237
  52. package/dist/tsdoc.d.ts +59 -17
  53. package/dist/tsdoc.d.ts.map +1 -1
  54. package/dist/tsdoc.js +140 -43
  55. package/dist/types.d.ts +967 -45
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/types.js +244 -31
  58. package/dist/typescript-alias-registry.d.ts +76 -0
  59. package/dist/typescript-alias-registry.d.ts.map +1 -0
  60. package/dist/typescript-alias-registry.js +206 -0
  61. package/dist/typescript-exports.d.ts +20 -15
  62. package/dist/typescript-exports.d.ts.map +1 -1
  63. package/dist/typescript-exports.js +250 -123
  64. package/dist/typescript-extract-class.d.ts +3 -4
  65. package/dist/typescript-extract-class.d.ts.map +1 -1
  66. package/dist/typescript-extract-class.js +67 -48
  67. package/dist/typescript-extract-function.d.ts +6 -8
  68. package/dist/typescript-extract-function.d.ts.map +1 -1
  69. package/dist/typescript-extract-function.js +17 -12
  70. package/dist/typescript-extract-shared.d.ts +309 -29
  71. package/dist/typescript-extract-shared.d.ts.map +1 -1
  72. package/dist/typescript-extract-shared.js +951 -121
  73. package/dist/typescript-extract-type-json.d.ts +286 -0
  74. package/dist/typescript-extract-type-json.d.ts.map +1 -0
  75. package/dist/typescript-extract-type-json.js +854 -0
  76. package/dist/typescript-extract-type-properties.d.ts +2 -3
  77. package/dist/typescript-extract-type-properties.d.ts.map +1 -1
  78. package/dist/typescript-extract-type-properties.js +88 -82
  79. package/dist/typescript-extract-type.d.ts +6 -8
  80. package/dist/typescript-extract-type.d.ts.map +1 -1
  81. package/dist/typescript-extract-type.js +131 -33
  82. package/dist/typescript-program.d.ts +106 -23
  83. package/dist/typescript-program.d.ts.map +1 -1
  84. package/dist/typescript-program.js +180 -52
  85. package/dist/vite.d.ts +23 -8
  86. package/dist/vite.d.ts.map +1 -1
  87. package/dist/vite.js +25 -5
  88. package/package.json +4 -3
package/README.md CHANGED
@@ -8,9 +8,9 @@
8
8
  svelte-docinfo extracts JSON describing the exports
9
9
  of TypeScript and Svelte modules for open-ended use cases
10
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+imports, and extract semantic details.
11
+ It uses the TypeScript compiler API
12
+ and [svelte2tsx](https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx)
13
+ to resolve types, track exports+imports, and extract semantic details.
14
14
  It includes a Vite plugin, CLI, and programmatic API
15
15
  in the [npm package](https://www.npmjs.com/package/svelte-docinfo).
16
16
 
@@ -139,6 +139,13 @@ All three produce the same JSON shape:
139
139
  {
140
140
  "name": "mode",
141
141
  "type": "\"add\" | \"multiply\"",
142
+ "typeInfo": {
143
+ "kind": "union",
144
+ "members": [
145
+ { "kind": "literal", "value": "add", "text": "\"add\"" },
146
+ { "kind": "literal", "value": "multiply", "text": "\"multiply\"" }
147
+ ]
148
+ },
142
149
  "optional": true,
143
150
  "description": "Operation mode.",
144
151
  "defaultValue": "'add'"
@@ -209,17 +216,24 @@ import { modules, diagnostics } from 'virtual:svelte-docinfo';
209
216
 
210
217
  Plugin options:
211
218
 
212
- | Option | Default | Description |
213
- | --------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
214
- | `projectRoot` | Vite's resolved `config.root` | Absolute path to project root. |
215
- | `include` | — | Glob patterns to include (relative to `projectRoot`). Collapses `discovery: 'auto'` to glob; combining with `discovery: 'exports'` throws. |
216
- | `exclude` | `['**/*.test.ts', '**/*.spec.ts']` | Glob patterns to exclude (fully replaces defaults — does not merge with `**/*.test.ts`, `**/*.spec.ts`). |
217
- | `discovery` | `'auto'` | Discovery strategy: `'auto'` \| `'exports'` \| `'glob'`. `'exports'` is strict and fails if `package.json` exports is missing or empty. |
218
- | `distDir` | `'dist'` | Dist directory name for exports-based discovery. |
219
- | `sourceOptions` | `{sourcePaths: ['src/lib'], …}` | Partial overrides for default source options (SvelteKit `src/lib` layout). |
220
- | `resolveDependencies` | `true` | Resolve import dependencies. When `false`, `dependencies`/`dependents` stay empty. |
221
- | `onDuplicates` | — | Dispatch on duplicate declaration names: `'throw'` \| `'warn'` \| callback. Diagnostic emits regardless of dispatch. |
222
- | `hmrDebounceMs` | `100` | HMR debounce delay in milliseconds. |
219
+ | Option | Default | Description |
220
+ | --------------------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
221
+ | `projectRoot` | Vite's resolved `config.root` | Absolute path to project root. |
222
+ | `include` | — | Glob patterns to include (relative to `projectRoot`; absolute inside it accepted). Collapses `discovery: 'auto'` to glob; combining with `discovery: 'exports'` throws. Widens the source scope — see the notes below. |
223
+ | `exclude` | `['**/*.test.ts', '**/*.spec.ts', '**/internal/**']` | Glob patterns to exclude. An array fully replaces the defaults; the callback form extends them (`(defaults) => [...defaults, '**/*.gen.ts']`). The always-on baseline below still applies. |
224
+ | `discovery` | `'auto'` | Discovery strategy: `'auto'` \| `'exports'` \| `'glob'`. `'exports'` is strict and fails if `package.json` exports is missing or empty. |
225
+ | `distDir` | `'dist'` | Dist directory name for exports-based discovery. |
226
+ | `sourceOptions` | `{sourcePaths: ['src/lib'], …}` | Partial overrides for default source options (SvelteKit `src/lib` layout). |
227
+ | `resolveDependencies` | `true` | Resolve import dependencies. When `false`, `dependencies`/`dependents` stay empty. |
228
+ | `onDuplicates` | — | Dispatch on duplicate declaration names: `'throw'` \| `'warn'` \| callback. Diagnostic emits regardless of dispatch. |
229
+ | `hmrDebounceMs` | `100` | HMR debounce delay in milliseconds. |
230
+
231
+ Source-scope notes (shared with the [CLI](#cli) and `analyzeFromFiles`):
232
+
233
+ - Explicit `include` patterns **widen the source scope**: each pattern's static base joins `sourceOptions.sourcePaths`, so include-discovered files emit modules (with paths relative to the widened set's common root) and the dev-mode watcher tracks them. A pattern with no base (`'**/*.ts'`, a literal root file) scopes the whole project root as source and logs an info line naming it.
234
+ - An **always-on baseline** applies beneath any `exclude`: `node_modules` and dot-directories below a matched source path are never source. It's matched relative to the matched source path — an explicit dot-directory source path (`sourcePaths: ['.hidden/src']`) still works — and is independent of `exclude` overrides. `dist`/`build`/`coverage` are ordinary names and stay in.
235
+ - The **`src/lib/internal/` convention**: `internal/` directories are excluded by default (the `**/internal/**` default pattern) — internal modules ship in the package for public modules to import but aren't documented. Packages typically pair the directory with an `"./internal/*": null` package.json exports entry blocking consumer imports; exports-based discovery honors null-target keys with Node's best-match resolution semantics, so blocked subpaths are never discovered. Internal modules stay live in dev: the analysis session owns them as watched context files, so editing an internal type re-analyzes the public modules that use it. A public re-export of an internal symbol (`export { x } from './internal/helper.js'`) documents at the re-export site as a full synthesized declaration. Re-include internal modules wholesale with the exclude callback: `exclude: (defaults) => defaults.filter((p) => p !== '**/internal/**')`.
236
+ - Paths and patterns resolve against `projectRoot`: absolute entries inside the root are accepted (stored root-relative), and anything resolving outside the root **throws** at options creation instead of silently emitting nothing — a root-anchored `'/src/lib'` is filesystem-absolute, not shorthand for `'src/lib'`.
223
237
 
224
238
  The options interface is `VitePluginSvelteDocinfoOptions` from `svelte-docinfo/vite.js` (not re-exported from the main barrel).
225
239
  See the [docs site](https://svelte-docinfo.fuz.dev/) and [examples/vite/](examples/vite/README.md) for more.
@@ -249,22 +263,24 @@ stderr (warnings and errors still print).
249
263
 
250
264
  All CLI options:
251
265
 
252
- | Flag | Description |
253
- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
254
- | `[project-root]` | Project root directory (default: cwd) |
255
- | `-i, --include <pattern>` | Include pattern (repeatable, replaces exports discovery; incompatible with `--discovery exports`) |
256
- | `-e, --exclude <pattern>` | Exclude glob, applied at discovery and analysis (repeatable; fully replaces defaults — does not merge with `**/*.test.ts`, `**/*.spec.ts`) |
257
- | `-o, --output <file>` | Output file (default: stdout; pass `-` for explicit stdout, so `-o "$OUT"` works when `$OUT=-`) |
258
- | `--discovery <mode>` | `auto` \| `exports` \| `glob` (default: `auto` — exports first, glob fallback). `exports` is strict and fails if package.json exports is missing |
259
- | `--dist-dir <dir>` | Dist directory for exports discovery (default: dist) |
260
- | `--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 |
261
- | `--source-root <dir>` | Source root for module-path stripping (default: single source-dir or longest common prefix; pass `.` for project-relative paths) |
262
- | `--on-duplicates <mode>` | Dispatch on duplicate declaration names: `throw` \| `warn` (default: emit `duplicate_declaration` diagnostic, no dispatch) |
263
- | `--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 |
264
- | `--no-resolve-dependencies` | Disable dependency resolution |
265
- | `--pretty` | Pretty-print JSON output (default: compact) |
266
- | `-q, --quiet` | Suppress info messages on stderr (warnings and errors still print) |
267
- | `-V, --version` | Show version number |
266
+ | Flag | Description |
267
+ | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
268
+ | `[project-root]` | Project root directory (default: cwd) |
269
+ | `-i, --include <pattern>` | Include pattern (repeatable, replaces exports discovery, widens the source scope; incompatible with `--discovery exports`) |
270
+ | `-e, --exclude <pattern>` | Exclude glob, applied at discovery and analysis (repeatable; fully replaces the defaults `**/*.test.ts`, `**/*.spec.ts`, `**/internal/**` — no merge; the always-on baseline applies beneath) |
271
+ | `-o, --output <file>` | Output file (default: stdout; pass `-` for explicit stdout, so `-o "$OUT"` works when `$OUT=-`) |
272
+ | `--discovery <mode>` | `auto` \| `exports` \| `glob` (default: `auto` — exports first, glob fallback). `exports` is strict and fails if package.json exports is missing |
273
+ | `--dist-dir <dir>` | Dist directory for exports discovery (default: dist) |
274
+ | `--source-dir <dir>` | Source directory, relative to project root or absolute inside it (default: src/lib). Repeatable for monorepos; drives the implicit include glob when no `--include` is provided |
275
+ | `--source-root <dir>` | Source root for module-path stripping (default: single source-dir or longest common prefix; pass `.` for project-relative paths) |
276
+ | `--on-duplicates <mode>` | Dispatch on duplicate declaration names: `throw` \| `warn` (default: emit `duplicate_declaration` diagnostic, no dispatch) |
277
+ | `--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 |
278
+ | `--no-resolve-dependencies` | Disable dependency resolution |
279
+ | `--pretty` | Pretty-print JSON output (default: compact) |
280
+ | `-q, --quiet` | Suppress info messages on stderr (warnings and errors still print) |
281
+ | `-V, --version` | Show version number |
282
+
283
+ The [Vite plugin](#vite-plugin)'s source-scope notes apply here too: explicit `--include` patterns widen the source scope (module paths become relative to the widened root, and a pattern with no base scopes the whole project root and logs an info line); `node_modules` and dot-directories below a source dir are always excluded regardless of `--exclude`; absolute paths and patterns inside the project root are accepted, and out-of-root ones fail loudly.
268
284
 
269
285
  Exit codes: 0 (success), 1 (analysis errors), 2 (CLI errors).
270
286
 
@@ -310,7 +326,10 @@ See the [API docs](https://svelte-docinfo.fuz.dev/docs/api) for the full referen
310
326
  ## Features
311
327
 
312
328
  - **Full type resolution**: infers complex types without manual annotations, including generics, imported types, and inferred return types
313
- - **TSDoc/JSDoc parsing**: standard tags (`@param`, `@returns`, `@throws`, `@example`, `@deprecated`, `@see`, `@since`, `@default`) plus `@nodocs`, `@mutates`, and `@module` for file-level comments
329
+ - **Structured types**: an optional `typeInfo` tree (`TypeJson`) beside the flat type strings on props, parameters, return types (`returnTypeInfo`, overloads included), type members, and variable/type declarations — union and intersection members (alias names kept, enum members as `{value, text}` pairs), reference type arguments (named generic instantiations like `Snippet<[a: string]>` classify as references), array and tuple elements (with `readonly` markers), so a union alias documents more than its own name — and absent wherever the flat string already says everything
330
+ - **TSDoc/JSDoc parsing**: the common doc tags (`@param`, `@returns`, `@throws`, `@example`, `@deprecated`, `@internal`, `@see`, `@since`, `@default`) plus `@nodocs`, `@mutates`, and `@module` for file-level comments; divergent spellings parse as synonyms (`@return`, TSDoc's `@defaultValue`). `@internal` is a marker (`internalMessage`, prose kept), not an exclusion — that's `@nodocs`
331
+ - **Alias-lost name recovery**: schema-inferred aliases (`type Foo = z.infer<typeof S>` — any indexed-access or conditional right-hand side) lose their name in the checker, which expands their structure at every use; `typeInfo` recovers the name as `{kind: 'reference', name}` from the written annotation where one exists, and — via an identity-keyed registry of the analyzed set's exported lost aliases — at unannotated inferred positions too, `null`-bearing optionals included; registry-recovered references also carry `module` (the declaring module's `ModuleJson.path`, always an emitted module) for collision-exact linking. Losses nothing recovers surface as `alias_lost` warnings (readable degradations like `z.enum` literal unions and `.brand()` intersections excluded)
332
+ - **Merged value+type symbols**: `export const Foo = z.strictObject({...})` + `export type Foo = z.infer<typeof Foo>` (one symbol, both spaces) documents the type meaning — structure and members like the un-merged equivalent — with `mergedValue: true` marking the name as also importable as a runtime value; JSDoc falls back to the const's docs, and `generateImport` emits a value import
314
333
  - **Svelte 5 component props**: extracts prop types, descriptions, defaults, and bindability via svelte2tsx
315
334
  - **Svelte 5 snippets**: `kind: 'snippet'` for template snippets (with structured parameters), `acceptsChildren` on components
316
335
  - **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
@@ -357,6 +376,10 @@ Built on [TypeScript](https://github.com/microsoft/TypeScript) and
357
376
  [svelte2tsx](https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx),
358
377
  see [package.json](package.json) for full dependencies.
359
378
 
379
+ ## Contributing
380
+
381
+ [fuz.dev/contributing](https://www.fuz.dev/contributing)
382
+
360
383
  ## License
361
384
 
362
385
  [MIT](LICENSE)