sveld 0.37.8 → 0.38.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.
- package/README.md +175 -4322
- package/cli.js +7 -0
- package/lib/browser.d.ts +114 -476
- package/lib/browser.js +176 -186
- package/lib/chunk-12m2j9sx.js +244 -0
- package/lib/chunk-4zz6y1q7.js +5 -0
- package/lib/chunk-bkyrjqfv.js +1 -0
- package/lib/chunk-m08z217p.js +36 -0
- package/lib/{chunk-0s0w60zm.js → chunk-mrkc1dc9.js} +9 -9
- package/lib/cli-entry.js +38 -1
- package/lib/index.d.ts +961 -2
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/lib/chunk-1tbcz36r.js +0 -1
- package/lib/chunk-2vte7cyp.js +0 -356
- package/lib/chunk-dh2cbpn0.js +0 -6
- package/lib/chunk-p9hkwnfy.js +0 -1
- package/lib/chunk-sg7vsn8d.js +0 -6
package/lib/cli-entry.js
CHANGED
|
@@ -1 +1,38 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{z,X,Q,k,t,xe,ee,te,I,re,ne,V,L,w,R,U,O,M,E,C,le,v,Se,fe}from"./chunk-12m2j9sx.js";import{existsSync as y}from"node:fs";import{join as S,resolve as A}from"node:path";var m="src/index.js",s={SUCCESS:0,USAGE_ERROR:1,GENERATION_FAILURE:2,BREAKING_CHANGE:3,DIAGNOSTICS:4},b=`Usage: sveld [options]
|
|
2
|
+
|
|
3
|
+
Generate TypeScript definitions and component documentation for a Svelte
|
|
4
|
+
library. With no flags, only TypeScript definitions are generated for the
|
|
5
|
+
entry resolved from package.json#svelte.
|
|
6
|
+
|
|
7
|
+
--entry, --config, --cache, --check, and --types-format accept their
|
|
8
|
+
value as --flag=value or as a separate --flag value argument.
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
--entry=<path> Entry point to uncompiled Svelte source (default: package.json "svelte" field)
|
|
12
|
+
--config=<path> Load this config file (relative to the working directory) instead of discovering sveld.config.{js,mjs,ts}
|
|
13
|
+
--glob Analyze all *.svelte files instead of the entry barrel
|
|
14
|
+
--types Generate TypeScript definitions (default: true)
|
|
15
|
+
--json Generate component documentation in JSON format
|
|
16
|
+
--markdown Generate component documentation in Markdown format
|
|
17
|
+
--fail-fast Abort the run when a single component fails to parse
|
|
18
|
+
-q, --quiet Suppress progress logs (errors, the diagnostics summary, and the --check report are unaffected)
|
|
19
|
+
--stdout Print the document from exactly one of --json or --markdown to stdout and write nothing to disk (rejects --types and --check)
|
|
20
|
+
--cache[=<path>] Persist parsed output and skip re-parsing unchanged files (on by default, default path: node_modules/.cache/sveld/parse-cache.json; pass --cache=false to disable)
|
|
21
|
+
--check-examples[=syntax] Check @example blocks: TS/JS against the TypeScript program, svelte/html markup against sveld's own parser; --check-examples=syntax runs only the markup path and never loads TypeScript
|
|
22
|
+
--report-diagnostics Print unresolved-type diagnostics to stderr
|
|
23
|
+
--strict[=errors] Exit with code 4 when diagnostics exist (implies --report-diagnostics); --strict=errors only fails on error-severity diagnostics
|
|
24
|
+
--types-format=<format> ".d.ts" output format: "class" (default) or "component" (Svelte 5 Component<...>)
|
|
25
|
+
--types-index-types Sets typesOptions.indexTypes; also re-exports generated types from index.d.ts (pass --types-index-types=false to disable)
|
|
26
|
+
--check[=<path>] Diff the parsed API against a committed snapshot; exit 3 on a breaking change (default path: COMPONENT_API.json)
|
|
27
|
+
--check-level=<major|minor|patch> Minimum bump --check fails the run on (default: major)
|
|
28
|
+
--format=<text|json> Output format for the --check report and the diagnostics summary (default: text)
|
|
29
|
+
-h, --help Print this help message and exit
|
|
30
|
+
-v, --version Print the installed sveld version and exit
|
|
31
|
+
|
|
32
|
+
Exit codes:
|
|
33
|
+
0 success
|
|
34
|
+
1 usage or configuration error
|
|
35
|
+
2 generation failure
|
|
36
|
+
3 breaking API change detected by --check
|
|
37
|
+
4 diagnostics present under --strict
|
|
38
|
+
`,_=["help","version","glob","types","json","markdown","quiet","stdout","strict","report-diagnostics","check-examples","fail-fast","entry","config","cache","check","check-level","types-format","types-index-types","format"],x=new Map([["-h","--help"],["-v","--version"],["-q","--quiet"]]),j=/[A-Z]/g,G=new Set(["glob","types","json","markdown","quiet","stdout","strict","report-diagnostics","check-examples","fail-fast","types-index-types"]),F=new Set(["entry","config","cache","check","types-format"]),T=new Set(["entry","config","types-format"]);function P(n){let e=n.replace(j,(i)=>`-${i.toLowerCase()}`);return k(e,_)}function N(n,e){let i=n.indexOf("="),r=i===-1?n.slice(2):n.slice(2,i),o=i===-1?!0:n.slice(i+1),c=!1;if(i===-1&&F.has(r)){if(e!==void 0&&!e.startsWith("--")&&!x.has(e))o=e,c=!0;else if(T.has(r))return{result:{kind:"usage-error",message:`sveld: --${r} requires a value (pass --${r}=<value> or --${r} <value>).`},consumedNext:!1,flag:r}}return{result:q(r,o,n),consumedNext:c,flag:r}}function q(n,e,i){switch(n){case"help":return{kind:"help"};case"version":return{kind:"version"};case"glob":case"types":case"json":case"markdown":case"quiet":return{kind:"option",option:{[n]:e===!0||e==="true"}};case"stdout":if(e===!0||e==="true")return{kind:"option",option:{stdout:!0}};if(e==="false")return{kind:"option",option:{stdout:!1}};return{kind:"usage-error",message:`sveld: --stdout does not take a value; got "${e}".`};case"strict":if(e===!0||e==="true")return{kind:"option",option:{strict:!0}};if(e==="false")return{kind:"option",option:{strict:!1}};return{kind:"option",option:{strict:e}};case"report-diagnostics":return{kind:"option",option:{reportDiagnostics:e===!0||e==="true"}};case"check-examples":if(e===!0||e==="true")return{kind:"option",option:{checkExamples:!0}};if(e==="false")return{kind:"option",option:{checkExamples:!1}};return{kind:"option",option:{checkExamples:e}};case"fail-fast":return{kind:"option",option:{failFast:e===!0||e==="true"}};case"entry":return typeof e==="string"?{kind:"option",option:{entry:e}}:{kind:"option",option:{}};case"config":return typeof e==="string"?{kind:"option",option:{config:e}}:{kind:"option",option:{}};case"cache":if(e==="false")return{kind:"option",option:{cache:!1}};return{kind:"option",option:{cache:typeof e==="string"?e:!0}};case"check":if(e==="false")return{kind:"option",option:{check:!1}};return{kind:"option",option:{check:typeof e==="string"?e:!0}};case"types-format":return typeof e==="string"?{kind:"option",option:{typesOptions:{format:e}}}:{kind:"option",option:{}};case"types-index-types":return{kind:"option",option:{typesOptions:{indexTypes:e===!0||e==="true"}}};case"format":return typeof e==="string"?{kind:"option",option:{format:e}}:{kind:"option",option:{}};case"check-level":return typeof e==="string"?{kind:"option",option:{checkLevel:e}}:{kind:"option",option:{}};default:return{kind:"unknown",arg:i,suggestion:P(n)}}}function D(n){let e={},i=!1;for(let r=0;r<n.length;r++){let o=x.get(n[r])??n[r];if(!o.startsWith("--"))return{kind:"unknown",arg:o,positionalHint:i?!0:void 0};let{result:c,consumedNext:f,flag:p}=N(o,n[r+1]);if(c.kind!=="option")return c;if(e=w(e,c.option),i=G.has(p),f)r++}return{kind:"options",options:e}}async function B(n){if(typeof n!=="string")return L();let e=A(n);if(!y(e))throw Error(`sveld: config file "${n}" does not exist.`);return V(e)}async function H(n){let e=D(n.argv.slice(2));if(e.kind==="help"){console.log(b);return}if(e.kind==="version"){console.log(xe.version);return}if(e.kind==="usage-error"){console.error(e.message),n.exitCode=s.USAGE_ERROR;return}if(e.kind==="unknown"){let a=`sveld: unknown flag "${e.arg}".`;if(e.suggestion)a+=` Did you mean "--${e.suggestion}"?`;if(e.positionalHint)a+=" Values are passed as --flag=value or --flag value.";console.error(a),console.error("Run sveld --help for a list of available flags."),n.exitCode=s.USAGE_ERROR;return}let i=e.options,r;try{r=await B(i.config)}catch(a){console.error(a instanceof Error?a.message:String(a)),n.exitCode=s.USAGE_ERROR;return}let o=w(r,i);if(R(o),o.stdout){if([o.json,o.markdown].filter(Boolean).length!==1){console.error("sveld: --stdout requires exactly one of --json or --markdown."),n.exitCode=s.USAGE_ERROR;return}if(o.types===!0){console.error("sveld: --stdout cannot be combined with --types; type definitions span multiple files."),n.exitCode=s.USAGE_ERROR;return}if(o.check){console.error("sveld: --stdout cannot be combined with --check; both write their document to stdout."),n.exitCode=s.USAGE_ERROR;return}}if(o.format!==void 0&&o.format!=="text"&&o.format!=="json"){console.error(`sveld: --format must be "text" or "json"; got "${o.format}".`),n.exitCode=s.USAGE_ERROR;return}if(o.strict!==void 0&&o.strict!==!0&&o.strict!==!1&&o.strict!=="errors"){console.error(`sveld: --strict must be "errors" when given a value; got "${o.strict}".`),n.exitCode=s.USAGE_ERROR;return}if(o.checkLevel!==void 0&&o.checkLevel!=="major"&&o.checkLevel!=="minor"&&o.checkLevel!=="patch"){console.error(`sveld: --check-level must be "major", "minor", or "patch"; got "${o.checkLevel}".`),n.exitCode=s.USAGE_ERROR;return}if(o.checkExamples!==void 0&&o.checkExamples!==!0&&o.checkExamples!==!1&&o.checkExamples!=="syntax"){console.error(`sveld: --check-examples must be "syntax" when given a value; got "${o.checkExamples}".`),n.exitCode=s.USAGE_ERROR;return}let c=o.typesOptions?.format;if(c!==void 0&&c!=="class"&&c!=="component"){console.error(`sveld: --types-format must be "class" or "component"; got "${c}".`),n.exitCode=s.USAGE_ERROR;return}O(o.quiet===!0);let f=le(o.entry),p;if(f.entry!==null)p=f.entry;else if(!f.configured&&y(S(n.cwd(),m)))console.error(`sveld: no entry point configured; using "${m}". Set package.json#svelte (or pass --entry) to silence this.`),p=U(t(m));else{console.error(`sveld: ${f.message}`),n.exitCode=s.USAGE_ERROR;return}let l,d;try{if(l=await C(p,o.glob===!0,E(o)),o.check)d=await I(l.components,ee(o),{entryExports:l.entryExports});if(o.stdout)await Se(l,o,p);else await v(l,o,p),l.cache?.save()}catch(a){if(a instanceof M){console.error(`sveld: ${a.message}`),n.exitCode=s.USAGE_ERROR;return}console.error(a instanceof Error?a.message:String(a)),n.exitCode=s.GENERATION_FAILURE;return}let g=o.reportDiagnostics||o.strict,u=z(l.diagnostics,g);if(g&&u.length>0)if(o.format==="json")n.stderr.write(Q(u));else console.error(X(u));if(d)if(o.format==="json")n.stdout.write(ne(d));else console.log(re(d));let h=fe({errors:l.errors,check:d,writesSnapshot:d?te(o,d.snapshotFile):!1,checkLevel:o.checkLevel,diagnostics:u,strict:o.strict});if(h!==s.SUCCESS)n.exitCode=h}export{H as cli};
|