sveld 0.35.1 → 0.36.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 (74) hide show
  1. package/README.md +33 -10
  2. package/cli.js +1 -1
  3. package/lib/browser.d.ts +660 -39
  4. package/lib/browser.js +205 -227
  5. package/lib/chunk-0fqdg2xa.js +20 -0
  6. package/lib/chunk-2vwf7nck.js +1 -0
  7. package/lib/chunk-8myyzjb1.js +4 -0
  8. package/lib/chunk-as5hgj7e.js +62 -0
  9. package/lib/chunk-denfbw92.js +13 -0
  10. package/lib/chunk-h1r040pg.js +6 -0
  11. package/lib/chunk-m538qnhp.js +230 -0
  12. package/lib/chunk-r4rrncmd.js +1 -0
  13. package/lib/chunk-t9d5k3p7.js +2 -0
  14. package/lib/chunk-tmj7vnjr.js +10 -0
  15. package/lib/chunk-xryt7ad2.js +3 -0
  16. package/lib/cli-entry.js +1 -0
  17. package/lib/index.d.ts +767 -10
  18. package/lib/index.js +1 -343
  19. package/package.json +1 -1
  20. package/lib/ComponentParser.d.ts +0 -822
  21. package/lib/ast-guards.d.ts +0 -18
  22. package/lib/brands.d.ts +0 -11
  23. package/lib/bundle.d.ts +0 -176
  24. package/lib/check.d.ts +0 -43
  25. package/lib/cli.d.ts +0 -28
  26. package/lib/create-exports.d.ts +0 -32
  27. package/lib/dependency-graph.d.ts +0 -20
  28. package/lib/diagnostics.d.ts +0 -34
  29. package/lib/element-tag-map.d.ts +0 -146
  30. package/lib/example-check.d.ts +0 -24
  31. package/lib/get-svelte-entry.d.ts +0 -4
  32. package/lib/load-config.d.ts +0 -62
  33. package/lib/parse-cache.d.ts +0 -28
  34. package/lib/parse-entry-exports.d.ts +0 -30
  35. package/lib/parse-exports.d.ts +0 -25
  36. package/lib/parser/bindings.d.ts +0 -6
  37. package/lib/parser/context.d.ts +0 -114
  38. package/lib/parser/contexts.d.ts +0 -19
  39. package/lib/parser/diagnostics.d.ts +0 -8
  40. package/lib/parser/events.d.ts +0 -23
  41. package/lib/parser/generics.d.ts +0 -24
  42. package/lib/parser/jsdoc.d.ts +0 -59
  43. package/lib/parser/props.d.ts +0 -73
  44. package/lib/parser/rest-props.d.ts +0 -6
  45. package/lib/parser/runes-detection.d.ts +0 -16
  46. package/lib/parser/runes-props.d.ts +0 -18
  47. package/lib/parser/scopes.d.ts +0 -58
  48. package/lib/parser/slots.d.ts +0 -29
  49. package/lib/parser/source-position.d.ts +0 -30
  50. package/lib/parser/type-resolution.d.ts +0 -32
  51. package/lib/parser/typescript-casts.d.ts +0 -2
  52. package/lib/path.d.ts +0 -3
  53. package/lib/plugin.d.ts +0 -85
  54. package/lib/resolve-alias.d.ts +0 -30
  55. package/lib/resolve-types.d.ts +0 -52
  56. package/lib/sveld.d.ts +0 -29
  57. package/lib/validate.d.ts +0 -13
  58. package/lib/watch.d.ts +0 -34
  59. package/lib/writer/MarkdownWriterBase.d.ts +0 -26
  60. package/lib/writer/Writer.d.ts +0 -53
  61. package/lib/writer/WriterMarkdown.d.ts +0 -33
  62. package/lib/writer/built-in-writers.d.ts +0 -1
  63. package/lib/writer/document-model.d.ts +0 -34
  64. package/lib/writer/format-generated-ts.d.ts +0 -8
  65. package/lib/writer/markdown-format-utils.d.ts +0 -104
  66. package/lib/writer/markdown-render-utils.d.ts +0 -10
  67. package/lib/writer/registry.d.ts +0 -17
  68. package/lib/writer/writer-custom-elements-core.d.ts +0 -86
  69. package/lib/writer/writer-custom-elements.d.ts +0 -15
  70. package/lib/writer/writer-json.d.ts +0 -37
  71. package/lib/writer/writer-markdown-core.d.ts +0 -32
  72. package/lib/writer/writer-markdown.d.ts +0 -25
  73. package/lib/writer/writer-ts-definitions-core.d.ts +0 -38
  74. package/lib/writer/writer-ts-definitions.d.ts +0 -70
package/README.md CHANGED
@@ -130,6 +130,7 @@ export default class Button extends SvelteComponentTyped<
130
130
  - [Installation](#installation)
131
131
  - [Vite](#vite)
132
132
  - [CLI](#cli)
133
+ - [Exit codes](#exit-codes)
133
134
  - [CI: API-drift checks (`--check`)](#ci-api-drift-checks---check)
134
135
  - [Node.js](#nodejs)
135
136
  - [Browser](#browser)
@@ -375,7 +376,7 @@ By default, nothing is printed. Opt in when you are working on types or want CI
375
376
  await sveld({ json: true, reportDiagnostics: true });
376
377
  ```
377
378
 
378
- Use `strict: true` (or `--strict`) to exit with code `1` when diagnostics exist. `strict` implies `reportDiagnostics`, so CI always shows why the run failed.
379
+ Use `strict: true` (or `--strict`) to exit with code `4` when diagnostics exist. `strict` implies `reportDiagnostics`, so CI always shows why the run failed.
379
380
 
380
381
  ```ts
381
382
  await sveld({ json: true, strict: true });
@@ -471,13 +472,35 @@ npx sveld --json --markdown
471
472
 
472
473
  If no entry point can be resolved (no `package.json#svelte` field and no `--entry`), the CLI exits `1` and prints the reason to `stderr`. If `src/index.js` happens to exist relative to your working directory, sveld falls back to it and prints a one-line note asking you to set `package.json#svelte` (or `--entry`) instead of relying on the fallback.
473
474
 
474
- Flags are kebab-case: `--entry`, `--glob`, `--types`, `--json`, `--markdown`, `--fail-fast`, `--cache`, `--resolve-types`, `--check-examples`, `--report-diagnostics`, `--strict`, `--check`, `--types-format`. The camelCase spellings `--resolveTypes` and `--checkExamples` still work as deprecated aliases for compatibility with existing scripts. An unrecognized flag (e.g. `--markdwon`) prints `Unknown flag: --markdwon` to `stderr`, exits `1`, and skips generation; sveld takes no positional arguments, so any non-flag argument errors the same way.
475
+ Flags are kebab-case: `--entry`, `--glob`, `--types`, `--json`, `--markdown`, `--fail-fast`, `--dry-run`, `--cache`, `--resolve-types`, `--check-examples`, `--report-diagnostics`, `--strict`, `--check`, `--types-format`, `--quiet`, `--stdout`, `--format`. The camelCase spellings `--resolveTypes` and `--checkExamples` still work as deprecated aliases for compatibility with existing scripts. `--entry`, `--cache`, `--check`, and `--types-format` take their value either as `--flag=value` or as a separate `--flag value` argument (`sveld --entry src/index.js` and `sveld --entry=src/index.js` are equivalent); if the next argument starts with `--` it's not consumed as a value, so `--cache` and `--check` fall back to their default location and `--entry` and `--types-format` report a usage error naming the flag. Boolean flags (`--json`, `--glob`, `--strict`, and the like) never consume a following argument. An unrecognized flag (e.g. `--markdwon`) prints `Unknown flag: --markdwon` to `stderr`, exits `1`, and skips generation; when a close match exists it appends a suggestion, e.g. `Unknown flag: --markdwon Did you mean --markdown?`. sveld takes no positional arguments, so any non-flag argument errors the same way.
476
+
477
+ Writer progress lines (`created "..."` / `unchanged "..."`) print to `stderr`, keeping `stdout` reserved for machine-readable data. Pass `--quiet` (or `quiet: true` in `sveld.config.*`) to suppress them; it does not suppress error messages, the diagnostics summary (`--report-diagnostics` / `--strict`), or the `--check` report.
478
+
479
+ Pass `--dry-run` to resolve the entry, load config, and parse components through the real pipeline (so parse errors, diagnostics, `--strict`, and `--check` all behave as in a real run), then print `would write "<path>"` to `stdout` for each output file instead of writing it, e.g. `sveld --json --markdown --dry-run`. Nothing is written, including the parse cache. `--check` never writes regardless of `--dry-run`, since it only diffs against the committed snapshot.
480
+
481
+ Pass `--stdout` alongside exactly one of `--json`, `--markdown`, or `--custom-elements` to print that single document to `stdout` instead of writing it to disk, e.g. `sveld --json --stdout | jq '.components[].moduleName'`. Zero or more than one of those three flags, `--types`, or `--check` combined with `--stdout` is a usage error that prints to `stderr` and exits `1` without generating anything; the default `.d.ts` generation is skipped in `--stdout` mode since type definitions span multiple files.
482
+
483
+ `--stdout=ndjson` (only valid with `--json`) prints one minified JSON object per exported component per line instead of the single combined document, in the same order as the combined document's `components` array, e.g. `sveld --json --stdout=ndjson | jq -c 'select(.props | length > 0)'`. Lines are only written after the run completes (component records are only final after cross-component resolution), so this is a line-oriented serialization format, not incremental streaming. Bare `--stdout` (or `--stdout=json`) keeps the single-document behavior; any other value is a usage error.
484
+
485
+ `--format=json` switches the `--check` report and the `--report-diagnostics` / `--strict` diagnostics summary from prose to JSON, so scripts and agents don't have to regex the text output, e.g. `sveld --json --check --format=json | jq '.bump'`. Channels are unchanged: the check report prints to `stdout` and the diagnostics summary to `stderr`, same as the text format. The default remains `--format=text`; an unrecognized value (e.g. `--format=yaml`) is a usage error that prints to `stderr` and exits `1` without generating anything.
475
486
 
476
487
  Run `npx sveld --help` for the full flag list with descriptions, or `npx sveld --version` to print the installed version.
477
488
 
489
+ ### Exit codes
490
+
491
+ | Code | Meaning |
492
+ |------|---------|
493
+ | `0` | Success |
494
+ | `1` | Usage or configuration error (unknown flag, bad flag value, unresolvable entry) |
495
+ | `2` | Generation failure (a component failed to parse under `--fail-fast`, or an unrecoverable pipeline error) |
496
+ | `3` | Breaking API change detected by `--check` |
497
+ | `4` | Diagnostics present under `--strict` |
498
+
499
+ Every failure is still reported to its usual channel even when more than one applies in a single run (e.g. a breaking change under `--check` alongside diagnostics under `--strict`); the process exits with the lowest applicable code. All failure codes are nonzero, so existing `if sveld; then ...` and `set -e` scripts that only check for success keep working unmodified.
500
+
478
501
  ### CI: API-drift checks (`--check`)
479
502
 
480
- `--check` diffs the parsed component API against a committed `COMPONENT_API.json` snapshot, assigns a semver bump to each change, and exits `1` when it finds a breaking change.
503
+ `--check` diffs the parsed component API against a committed `COMPONENT_API.json` snapshot, assigns a semver bump to each change, and exits `3` when it finds a breaking change.
481
504
 
482
505
  1. Generate and commit the snapshot once: `npx sveld --json`, then commit `COMPONENT_API.json`.
483
506
  2. Add `npx sveld --check` to CI:
@@ -501,7 +524,9 @@ Removed props, events, or slots, and props that become required, are breaking (`
501
524
 
502
525
  Use `--check=<path>` to diff against a snapshot at a custom location (defaults to `jsonOptions.outFile`, or `COMPONENT_API.json`).
503
526
 
504
- The CLI exits non-zero on any fatal error (an unreadable entry, a config file that throws, etc.), not just on `--strict`/`--check` findings, so it's safe to use either flag as a CI gate.
527
+ The CLI exits non-zero on any fatal error (an unreadable entry, a config file that throws, etc.), not just on `--strict`/`--check` findings, so it's safe to use either flag as a CI gate. See [Exit codes](#exit-codes) for how these are differentiated.
528
+
529
+ Pass `--format=json` for a machine-readable report on `stdout` instead of the prose above, e.g. `sveld --check --format=json | jq '.bump'` or `sveld --check --format=json | jq '.changes[] | select(.bump == "major")'`.
505
530
 
506
531
  ### Node.js
507
532
 
@@ -683,12 +708,8 @@ The `svelte` condition lets bundlers that understand it (Vite, Rollup, webpack v
683
708
  - **`glob`** (boolean, optional): Enable glob mode to analyze all `*.svelte` files.
684
709
  - **`documentExports`** (boolean, optional): Include consts, functions, and types from the entry barrel in JSON (`exports`) and Markdown ("Exports"). Off by default. See [Documenting Entry Exports](#documenting-entry-exports).
685
710
  - **`types`** (boolean, optional, default: `true`): Generate TypeScript definitions.
686
- <<<<<<< HEAD
687
711
  - **`typesOptions`** (object, optional): Options for TypeScript definition generation, including `outDir`, `preamble`, and `format`.
688
712
  - **`format`** (`"class"` | `"component"`, optional, default: `"class"`): `.d.ts` output shape. `"class"` extends `SvelteComponentTyped`; `"component"` emits the Svelte 5 `Component` type. Also available as `--types-format`. See [`.d.ts` output format](#dts-output-format-typesoptionsformat).
689
- =======
690
- - **`typesOptions`** (object, optional): Options for TypeScript definition generation, including `outDir` and `preamble`.
691
- >>>>>>> 0724225 (feat(writer)!: remove prettier entirely)
692
713
  - **`json`** (boolean, optional): Generate component documentation in JSON format.
693
714
  - **`jsonOptions`** (object, optional): Options for JSON output.
694
715
  - **`markdown`** (boolean, optional): Generate component documentation in Markdown format.
@@ -701,8 +722,10 @@ The `svelte` condition lets bundlers that understand it (Vite, Rollup, webpack v
701
722
  - **`cache`** (boolean | string, optional, default: `true`): Write parsed component output to disk and skip re-parsing unchanged files on later runs. On by default, writing to `node_modules/.cache/sveld/parse-cache.json`; a string sets a custom path; pass `false` to disable. Also available as `--cache` / `--cache=<path>` / `--cache=false`. See [Persistent parse cache](#persistent-parse-cache-cache).
702
723
  - **`checkExamples`** (boolean, optional, default: `false`): Run plain TS/JS `@example` blocks through the TypeScript program. Broken ones get an `example-compile-error` diagnostic. Also available as `--check-examples` (`--checkExamples` remains as a deprecated alias). See [Compile-checked `@example` blocks](#compile-checked-example-blocks-checkexamples).
703
724
  - **`reportDiagnostics`** (boolean, optional, default: `false`): Print unresolved-type diagnostics to stderr (CLI) or `console.warn` (programmatic API). Also available as `--report-diagnostics`. See [Type inference diagnostics](#type-inference-diagnostics).
704
- - **`strict`** (boolean, optional, default: `false`): Exit with code `1` when diagnostics exist. Implies `reportDiagnostics`. Also available as `--strict`. See [Type inference diagnostics](#type-inference-diagnostics).
705
- - **`check`** (boolean | string, optional, default: `false`): Diff the parsed component API against a committed snapshot and assign a semver bump to each change. `true` uses the `json` writer's `outFile` (or `COMPONENT_API.json`); a string sets a custom snapshot path. Also available as `--check` / `--check=<path>`. On the CLI this exits `1` on a breaking change; from `sveld()` it's returned on `SveldResult.check` for you to act on. See [CI: API-drift checks (`--check`)](#ci-api-drift-checks---check).
725
+ - **`strict`** (boolean, optional, default: `false`): Exit with code `4` when diagnostics exist. Implies `reportDiagnostics`. Also available as `--strict`. See [Type inference diagnostics](#type-inference-diagnostics).
726
+ - **`check`** (boolean | string, optional, default: `false`): Diff the parsed component API against a committed snapshot and assign a semver bump to each change. `true` uses the `json` writer's `outFile` (or `COMPONENT_API.json`); a string sets a custom snapshot path. Also available as `--check` / `--check=<path>`. On the CLI this exits `3` on a breaking change; from `sveld()` it's returned on `SveldResult.check` for you to act on. See [CI: API-drift checks (`--check`)](#ci-api-drift-checks---check).
727
+ - **`quiet`** (boolean, optional, default: `false`): Suppress writer progress logs (`created "..."` / `unchanged "..."`), which print to `stderr` by default. Does not suppress error messages, the diagnostics summary, or the `--check` report. Also available as `--quiet`.
728
+ - **`dryRun`** (boolean, optional, default: `false`): Resolve the entry, load config, and parse components through the real pipeline, then print `would write "<path>"` to `stdout` for each output file instead of writing it, including the parse cache. Diagnostics, `strict`, and `check` behave as in a real run. CLI-only via `--dry-run`; the Vite plugin does not expose this option.
706
729
 
707
730
  By default, only TypeScript definitions are generated.
708
731
 
package/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import("./lib/index.js")
3
+ import("./lib/cli-entry.js")
4
4
  .then(({ cli }) => cli(process))
5
5
  .catch((error) => {
6
6
  console.error(error);