sveld 0.40.6 → 0.41.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/cli-entry.js CHANGED
@@ -1,11 +1,12 @@
1
- import{I,te,r,Bt,Ee,Se,W,L,H,J,K,Oe,Me,Fe}from"./chunk-9fmhgf46.js";import{existsSync as S}from"node:fs";import{join as x}from"node:path";var g="src/index.js",m={SUCCESS:0,USAGE_ERROR:1,GENERATION_FAILURE:2,BREAKING_CHANGE:3,DIAGNOSTICS:4},E=`Usage: sveld [options]
1
+ import{I,te,r,Bt,Ee,Se,W,L,H,J,K,Oe,Me,Fe}from"./chunk-h308tz7m.js";import{existsSync as w}from"node:fs";import{join as R}from"node:path";var h="src/index.js",S={SUCCESS:0,PROBLEMS:1,USAGE_OR_FAILURE:2},j=1;function C(t){return t.some((n,a)=>n==="--format=json"||n==="--format"&&t[a+1]==="json")}var O=`Usage: sveld [options]
2
2
 
3
3
  Generate TypeScript definitions and component documentation for a Svelte
4
4
  library. With no flags, only TypeScript definitions are generated for the
5
5
  entry resolved from package.json#svelte.
6
6
 
7
- --entry, --config, --cache, --check, and --types-format accept their
8
- value as --flag=value or as a separate --flag value argument.
7
+ --entry, --config, --cache, --check, --types-format, --format, and
8
+ --check-level accept their value as --flag=value or as a separate --flag
9
+ value argument.
9
10
 
10
11
  Options:
11
12
  --entry=<path> Entry point to uncompiled Svelte source (default: package.json "svelte" field)
@@ -20,19 +21,30 @@ Options:
20
21
  --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
22
  --check-examples[=syntax] Check @example blocks: TS/JS against the TypeScript program, svelte/html markup against svelte-ast; --check-examples=syntax runs only the markup path and never loads TypeScript
22
23
  --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
+ --strict[=errors] Exit with code 1 when diagnostics exist (implies --report-diagnostics); --strict=errors only fails on error-severity diagnostics
24
25
  --types-format=<format> ".d.ts" output format: "class" (default) or "component" (Svelte 5 Component<...>)
25
26
  --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[=<path>] Diff the parsed API against a committed snapshot; exit 1 on a breaking change (default path: COMPONENT_API.json)
27
28
  --check-level=<major|minor|patch> Minimum bump --check fails the run on (default: major)
28
29
  --format=<text|json|github> Output format for the --check report and the diagnostics summary (default: text); github also prints each diagnostic as a GitHub Actions annotation
29
30
  -h, --help Print this help message and exit
30
31
  -v, --version Print the installed sveld version and exit
31
32
 
32
33
  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
- `,b=["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"],y=new Map([["-h","--help"],["-v","--version"],["-q","--quiet"]]),w=/[A-Z]/g,R=new Set(["glob","types","json","markdown","quiet","stdout","strict","report-diagnostics","check-examples","fail-fast","types-index-types"]),C=new Set(["entry","config","cache","check","types-format"]),O=new Set(["entry","config","types-format"]);function A(s){let n=s.replace(w,(o)=>`-${o.toLowerCase()}`);return I(n,b)}function j(s,n){let o=s.indexOf("="),t=o===-1?s.slice(2):s.slice(2,o),i=o===-1?!0:s.slice(o+1),e=!1;if(o===-1&&C.has(t)){if(n!==void 0&&!n.startsWith("--")&&!y.has(n))i=n,e=!0;else if(O.has(t))return{result:{kind:"usage-error",message:`sveld: --${t} requires a value (pass --${t}=<value> or --${t} <value>).`},consumedNext:!1,flag:t}}return{result:T(t,i,s),consumedNext:e,flag:t}}function u(s){return s}function T(s,n,o){let t=(c)=>({kind:"option",option:c}),i=n===!0||n==="true",e=typeof n==="string"?n:void 0;switch(s){case"help":return{kind:"help"};case"version":return{kind:"version"};case"glob":case"types":case"json":case"markdown":case"quiet":return t({[s]:i});case"stdout":if(i)return t({stdout:!0});if(n==="false")return t({stdout:!1});return{kind:"usage-error",message:`sveld: --stdout does not take a value; got "${n}".`};case"strict":if(i)return t({strict:!0});if(n==="false")return t({strict:!1});return t({strict:u(n)});case"report-diagnostics":return t({reportDiagnostics:i});case"check-examples":if(i)return t({checkExamples:!0});if(n==="false")return t({checkExamples:!1});return t({checkExamples:u(n)});case"fail-fast":return t({failFast:i});case"entry":return t(e===void 0?{}:{entry:e});case"config":return t(e===void 0?{}:{config:e});case"cache":if(n==="false")return t({cache:!1});return t({cache:e??!0});case"check":if(n==="false")return t({check:!1});return t({check:e??!0});case"types-format":return t(e===void 0?{}:{typesOptions:{format:u(e)}});case"types-index-types":return t({typesOptions:{indexTypes:i}});case"format":return t(e===void 0?{}:{format:u(e)});case"check-level":return t(e===void 0?{}:{checkLevel:u(e)});default:return{kind:"unknown",arg:o,suggestion:A(s)}}}function P(s){let n={},o=!1;for(let t=0;t<s.length;t++){let i=y.get(s[t])??s[t];if(!i.startsWith("--"))return{kind:"unknown",arg:i,positionalHint:o?!0:void 0};let{result:e,consumedNext:c,flag:l}=j(i,s[t+1]);if(e.kind!=="option")return e;if(n=L(n,e.option),o=R.has(l),c)t++}return{kind:"options",options:n}}function d(s,n){return s!==void 0&&!n.includes(s)}async function _(s){let n=(a)=>{console.error(a),s.exitCode=m.USAGE_ERROR},o=P(s.argv.slice(2));if(o.kind==="help"){console.log(E);return}if(o.kind==="version"){console.log(Bt.version);return}if(o.kind==="usage-error")return n(o.message);if(o.kind==="unknown"){let a=`sveld: unknown flag "${o.arg}".`;if(o.suggestion)a+=` Did you mean "--${o.suggestion}"?`;if(o.positionalHint)a+=" Values are passed as --flag=value or --flag value.";return console.error(a),n("Run sveld --help for a list of available flags.")}let t=o.options,i;try{i=await W(t.config,s.cwd(),!0)}catch(a){return n(a instanceof Error?a.message:String(a))}let e=L(i,t);if(H(e),e.stdout){if([e.json,e.markdown].filter(Boolean).length!==1)return n("sveld: --stdout requires exactly one of --json or --markdown.");if(e.types===!0)return n("sveld: --stdout cannot be combined with --types; type definitions span multiple files.");if(e.check)return n("sveld: --stdout cannot be combined with --check; both write their document to stdout.")}if(d(e.format,["text","json","github"]))return n(`sveld: --format must be "text", "json", or "github"; got "${e.format}".`);if(d(e.strict,[!0,!1,"errors"]))return n(`sveld: --strict must be "errors" when given a value; got "${e.strict}".`);if(d(e.checkLevel,["major","minor","patch"]))return n(`sveld: --check-level must be "major", "minor", or "patch"; got "${e.checkLevel}".`);if(d(e.checkExamples,[!0,!1,"syntax"]))return n(`sveld: --check-examples must be "syntax" when given a value; got "${e.checkExamples}".`);let c=e.typesOptions?.format;if(d(c,["class","component"]))return n(`sveld: --types-format must be "class" or "component"; got "${c}".`);J(e.quiet===!0);let l=Oe(e.entry),p;if(l.entry!==null)p=l.entry;else if(!l.configured&&S(x(s.cwd(),g)))console.error(`sveld: no entry point configured; using "${g}". Set package.json#svelte (or pass --entry) to silence this.`),p=te(r(g));else return n(`sveld: ${l.message}`);let h;try{h=await Me(p,e,e.stdout===!0)}catch(a){if(a instanceof K)return n(`sveld: ${a.message}`);console.error(a instanceof Error?a.message:String(a)),s.exitCode=m.GENERATION_FAILURE;return}let{result:v,check:f}=h,{exitCode:k}=Fe(v,f,e,p);if(f)if(e.format==="json")s.stdout.write(Se(f));else console.log(Ee(f));if(k!==m.SUCCESS)s.exitCode=k}export{_ as cli};
34
+ 0 done
35
+ 1 problems found: a component that failed to parse, a breaking API
36
+ change under --check, diagnostics under --strict, or a --check
37
+ snapshot from another schemaVersion
38
+ 2 called wrong, or couldn't finish: an unknown flag or bad value, a
39
+ missing entry, config file or --check snapshot, an unresolvable
40
+ re-export or path alias, or an unrecoverable error
41
+
42
+ For agents and scripts:
43
+ Run with --format=json and read stdout. --check prints its report as
44
+ one object ({ kind: "check-report", schemaVersion, bump, changes });
45
+ --report-diagnostics and --strict print { kind: "diagnostics",
46
+ schemaVersion, diagnostics } on stderr. An exit 2 prints
47
+ { schemaVersion, ok: false, error: { kind, message } } on stdout, where
48
+ kind is usage, config, entry, unresolved-module or failure.
49
+ `,A=["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"]]),P=/[A-Z]/g,T=new Set(["glob","types","json","markdown","quiet","stdout","strict","report-diagnostics","check-examples","fail-fast","types-index-types"]),_=new Set(["entry","config","cache","check","types-format","format","check-level"]),F=new Set(["entry","config","types-format","format","check-level"]);function G(t){let n=t.replace(P,(a)=>`-${a.toLowerCase()}`);return I(n,A)}function U(t,n){let a=t.indexOf("="),e=a===-1?t.slice(2):t.slice(2,a),s=a===-1?!0:t.slice(a+1),i=!1;if(a===-1&&_.has(e)){if(n!==void 0&&!n.startsWith("--")&&!x.has(n))s=n,i=!0;else if(F.has(e))return{result:{kind:"usage-error",message:`sveld: --${e} requires a value (pass --${e}=<value> or --${e} <value>).`},consumedNext:!1,flag:e}}return{result:q(e,s,t),consumedNext:i,flag:e}}function u(t){return t}function q(t,n,a){let e=(l)=>({kind:"option",option:l}),s=n===!0||n==="true",i=typeof n==="string"?n:void 0;switch(t){case"help":return{kind:"help"};case"version":return{kind:"version"};case"glob":case"types":case"json":case"markdown":case"quiet":return e({[t]:s});case"stdout":if(s)return e({stdout:!0});if(n==="false")return e({stdout:!1});return{kind:"usage-error",message:`sveld: --stdout does not take a value; got "${n}".`};case"strict":if(s)return e({strict:!0});if(n==="false")return e({strict:!1});return e({strict:u(n)});case"report-diagnostics":return e({reportDiagnostics:s});case"check-examples":if(s)return e({checkExamples:!0});if(n==="false")return e({checkExamples:!1});return e({checkExamples:u(n)});case"fail-fast":return e({failFast:s});case"entry":return e(i===void 0?{}:{entry:i});case"config":return e(i===void 0?{}:{config:i});case"cache":if(n==="false")return e({cache:!1});return e({cache:i??!0});case"check":if(n==="false")return e({check:!1});return e({check:i??!0});case"types-format":return e(i===void 0?{}:{typesOptions:{format:u(i)}});case"types-index-types":return e({typesOptions:{indexTypes:s}});case"format":return e(i===void 0?{}:{format:u(i)});case"check-level":return e(i===void 0?{}:{checkLevel:u(i)});default:return{kind:"unknown",arg:a,suggestion:G(t)}}}function N(t){let n={},a=!1;for(let e=0;e<t.length;e++){let s=x.get(t[e])??t[e];if(!s.startsWith("--"))return{kind:"unknown",arg:s,positionalHint:a?!0:void 0};let{result:i,consumedNext:l,flag:o}=U(s,t[e+1]);if(i.kind!=="option")return i;if(n=L(n,i.option),a=T.has(o),l)e++}return{kind:"options",options:n}}function d(t,n){return t!==void 0&&!n.includes(t)}async function V(t){let n=t.argv.slice(2),a=C(n),e=(c,g="usage")=>{if(a){let E={schemaVersion:j,ok:!1,error:{kind:g,message:c}};t.stdout.write(`${JSON.stringify(E,null,2)}
50
+ `)}else console.error(c);t.exitCode=S.USAGE_OR_FAILURE},s=N(n);if(s.kind==="help"){console.log(O);return}if(s.kind==="version"){console.log(Bt.version);return}if(s.kind==="usage-error")return e(s.message);if(s.kind==="unknown"){let c=`sveld: unknown flag "${s.arg}".`;if(s.suggestion)c+=` Did you mean "--${s.suggestion}"?`;if(s.positionalHint)c+=" Values are passed as --flag=value or --flag value.";let g="Run sveld --help for a list of available flags.";if(a)return e(`${c} ${g}`);return console.error(c),e(g)}let i=s.options,l;try{l=await W(i.config,t.cwd(),!0)}catch(c){return e(c instanceof Error?c.message:String(c),"config")}let o=L(l,i);if(a=o.format==="json",H(o),o.stdout){if([o.json,o.markdown].filter(Boolean).length!==1)return e("sveld: --stdout requires exactly one of --json or --markdown.");if(o.types===!0)return e("sveld: --stdout cannot be combined with --types; type definitions span multiple files.");if(o.check)return e("sveld: --stdout cannot be combined with --check; both write their document to stdout.")}if(d(o.format,["text","json","github"]))return e(`sveld: --format must be "text", "json", or "github"; got "${o.format}".`);if(d(o.strict,[!0,!1,"errors"]))return e(`sveld: --strict must be "errors" when given a value; got "${o.strict}".`);if(d(o.checkLevel,["major","minor","patch"]))return e(`sveld: --check-level must be "major", "minor", or "patch"; got "${o.checkLevel}".`);if(d(o.checkExamples,[!0,!1,"syntax"]))return e(`sveld: --check-examples must be "syntax" when given a value; got "${o.checkExamples}".`);let k=o.typesOptions?.format;if(d(k,["class","component"]))return e(`sveld: --types-format must be "class" or "component"; got "${k}".`);J(o.quiet===!0);let f=Oe(o.entry),p;if(f.entry!==null)p=f.entry;else if(!f.configured&&w(R(t.cwd(),h)))console.error(`sveld: no entry point configured; using "${h}". Set package.json#svelte (or pass --entry) to silence this.`),p=te(r(h));else return e(`sveld: ${f.message}`,"entry");let y;try{y=await Me(p,o,o.stdout===!0)}catch(c){if(c instanceof K)return e(`sveld: ${c.message}`,"unresolved-module");return e(c instanceof Error?c.message:String(c),"failure")}let{result:b,check:m}=y,{exitCode:v}=Fe(b,m,o,p);if(m)if(o.format==="json")t.stdout.write(Se(m));else console.log(Ee(m));if(v!==S.SUCCESS)t.exitCode=v}export{V as cli};
package/index.d.ts CHANGED
@@ -1053,15 +1053,17 @@ export interface SveldResult {
1053
1053
  */
1054
1054
  document: ComponentApiDocument;
1055
1055
  /**
1056
- * Suggested process exit code for this run, using the same mapping as the
1057
- * CLI (see {@link resolveExitCode}). `sveld()` never mutates
1058
- * `process.exitCode` itself; assign this value yourself if you want the
1059
- * process to exit non-zero.
1060
- */
1061
- exitCode: ExitCode;
1056
+ * Suggested process exit code for this run, as the CLI exits: `0` done,
1057
+ * `1` problems found, `2` the run couldn't do what it was asked.
1058
+ * `sveld()` never mutates `process.exitCode` itself; assign this value
1059
+ * yourself if you want the process to exit non-zero.
1060
+ */
1061
+ exitCode: 0 | 1 | 2;
1062
+ /** Why `exitCode` isn't `0`, each reason that applied, in this order. */
1063
+ failures: SveldFailure[];
1062
1064
  }
1063
1065
 
1064
- type ExitCode = 0 | 1 | 2 | 3 | 4;
1066
+ export type SveldFailure = "missing-snapshot" | "outdated-snapshot" | "parse-error" | "breaking-change" | "diagnostics";
1065
1067
 
1066
1068
  export interface SveldOptions extends Omit<SveldRuntimeOptions, "config"> {
1067
1069
  /**
package/index.js CHANGED
@@ -1 +1 @@
1
- import{X,Ve,y,jt,Le,Ee,Vt,Se,Ut,Gt,Jt}from"./chunk-9fmhgf46.js";import{re}from"./chunk-0e70e5s3.js";export{Vt as CHECK_REPORT_SCHEMA_VERSION,re as ComponentParser,Ve as DIAGNOSTICS_SCHEMA_VERSION,X as DIAGNOSTIC_CODES,y as buildComponentApiDocument,Gt as default,Ut as defineConfig,jt as diffApiDocuments,Ee as formatCheckReport,Se as formatCheckReportJson,Le as runCheck,Jt as sveld};
1
+ import{X,Ve,y,jt,Le,Ee,Vt,Se,Ut,Gt,Jt}from"./chunk-h308tz7m.js";import{re}from"./chunk-zmd679kg.js";export{Vt as CHECK_REPORT_SCHEMA_VERSION,re as ComponentParser,Ve as DIAGNOSTICS_SCHEMA_VERSION,X as DIAGNOSTIC_CODES,y as buildComponentApiDocument,Gt as default,Ut as defineConfig,jt as diffApiDocuments,Ee as formatCheckReport,Se as formatCheckReportJson,Le as runCheck,Jt as sveld};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveld",
3
- "version": "0.40.6",
3
+ "version": "0.41.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Generate TypeScript definitions and component documentation for your Svelte components.",
6
6
  "type": "module",