sveld 0.38.6 → 0.38.8
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/browser.d.ts +15 -9
- package/browser.js +136 -170
- package/chunk-4hn2yn5w.js +1 -0
- package/chunk-mnkbqz8m.js +40 -0
- package/chunk-sfnqvdg5.js +189 -0
- package/chunk-t6rwe82p.js +5 -0
- package/cli-entry.js +2 -2
- package/index.d.ts +26 -12
- package/index.js +1 -1
- package/package.json +1 -1
- package/schema/component-api.schema.json +1 -1
- package/chunk-deb45vqa.js +0 -5
- package/chunk-m4pg0axh.js +0 -234
- package/chunk-qfbb8a3r.js +0 -1
- package/chunk-v61086ex.js +0 -29
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{n,q}from"./chunk-sfnqvdg5.js";import{readdirSync as T,readFileSync as x,statSync as _}from"node:fs";import{createRequire as k}from"node:module";import c from"node:path";var P=/[^A-Za-z0-9_-]/g,R=/[^A-Za-z0-9_$]/g,C=/^[0-9]/,w=2,f=7,g=`TypeScript ${f} or later, which provides \`typescript/unstable/async\``;function I(e){if(!e)return!1;let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>=f}async function N(e){let t;try{let i=k(c.join(e,"package.json")).resolve("typescript/package.json");t=JSON.parse(x(i,"utf8")).version}catch{return{installed:!1}}if(!I(t))return{installed:!0,version:t};try{let s=await import("./chunk-1azsj0zd.js");return{installed:!0,version:t,module:s}}catch{return{installed:!0,version:t}}}class d{api=null;tsconfigPath;overlay=new Map;constructor(e){this.tsconfigPath=e}static async create(e=process.cwd(),{importTs:t=N}={}){let s=await t(e);if(!s.installed)return{ok:!1,reason:"not-installed",message:`requires the \`typescript\` package to be installed (${g}); none was found`};if(!s.module)return{ok:!1,reason:"unsupported-version",message:`requires ${g}; found \`typescript@${s.version??"unknown"}\` installed, which does not expose that module`};let i=q(e,["tsconfig.json"]);if(!i)return{ok:!1,reason:"no-tsconfig",message:`could not locate a tsconfig.json starting from "${e}"`};let r=new d(i);return r.api=new s.module.API({cwd:e,fs:r.createFileSystem()}),{ok:!0,resolver:r}}async checkExamples(e){let t=new Map,s=[];for(let r of e)for(let o of r.sources){let a=this.exampleFileName(r.filePath,r.moduleName,o.id);this.overlay.set(a,D(o)),s.push({filePath:r.filePath,source:o,file:a})}if(s.length===0)return t;let i=await this.api.updateSnapshot({openProject:this.tsconfigPath,fileChanges:{created:s.map((r)=>r.file)}});try{let r=await i.getDefaultProjectForFile(s[0].file);if(!r)return t;await Promise.all(s.map(async({filePath:o,source:a,file:p})=>{let[h,y]=await Promise.all([r.program.getSyntacticDiagnostics(p),r.program.getSemanticDiagnostics(p)]),u=[...h,...y];if(u.length===0)return;let E=this.overlay.get(p)??"",v=u.map((l)=>A(l,E)).sort((l,S)=>l.line-S.line).map((l)=>`Line ${l.line}: ${l.text}`).join(`
|
|
2
|
+
`),m=t.get(o)??[];m.push({id:a.id,name:a.name,message:v}),t.set(o,m)}))}finally{await i.dispose?.()}return t}async dispose(){this.overlay.clear(),await this.api?.close?.()}createFileSystem(){return{readFile:(e)=>this.overlay.get(n(e)),fileExists:(e)=>this.overlay.has(n(e))?!0:void 0,getAccessibleEntries:(e)=>{let t=n(e),s=Array.from(this.overlay.keys()).filter((o)=>n(c.dirname(o))===t);if(s.length===0)return;let i=[],r=[];try{for(let o of T(e)){let a=c.join(e,o);try{(_(a).isDirectory()?r:i).push(o)}catch{}}}catch{}for(let o of s){let a=c.basename(o);if(!i.includes(a))i.push(a)}return{files:i,directories:r}}}}exampleFileName(e,t,s){let i=c.dirname(c.resolve(e)),r=s.replace(P,"_");return n(c.join(i,`__sveld_example_${t}_${r}.ts`))}}function b(e){let t=e.replace(R,"_");if(t===""||C.test(t))return`_${t}`;return t}function D(e){return`const ${b(e.name)} = null as unknown as (${e.type});
|
|
3
|
+
${e.code}
|
|
4
|
+
`}function A(e,t){let s=e.pos??0,i=t.slice(0,s).split(`
|
|
5
|
+
`).length;return{line:Math.max(1,i-w+1),text:String(e.text??"").trim()}}export{d as TypeResolver};
|
package/cli-entry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{N,n,Nt,ge,ye,J,I,j,Z,F,V,Ie,Re,Le}from"./chunk-sfnqvdg5.js";import{existsSync as v}from"node:fs";import{join as S}from"node:path";var f="src/index.js",m={SUCCESS:0,USAGE_ERROR:1,GENERATION_FAILURE:2,BREAKING_CHANGE:3,DIAGNOSTICS:4},x=`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
|
|
@@ -35,4 +35,4 @@ Exit codes:
|
|
|
35
35
|
2 generation failure
|
|
36
36
|
3 breaking API change detected by --check
|
|
37
37
|
4 diagnostics present under --strict
|
|
38
|
-
`,
|
|
38
|
+
`,E=["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"],k=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"]),b=new Set(["entry","config","cache","check","types-format"]),C=new Set(["entry","config","types-format"]);function O(r){let s=r.replace(w,(o)=>`-${o.toLowerCase()}`);return N(s,E)}function A(r,s){let o=r.indexOf("="),t=o===-1?r.slice(2):r.slice(2,o),i=o===-1?!0:r.slice(o+1),e=!1;if(o===-1&&b.has(t)){if(s!==void 0&&!s.startsWith("--")&&!k.has(s))i=s,e=!0;else if(C.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:P(t,i,r),consumedNext:e,flag:t}}function P(r,s,o){let t=(c)=>({kind:"option",option:c}),i=s===!0||s==="true",e=typeof s==="string"?s:void 0;switch(r){case"help":return{kind:"help"};case"version":return{kind:"version"};case"glob":case"types":case"json":case"markdown":case"quiet":return t({[r]:i});case"stdout":if(i)return t({stdout:!0});if(s==="false")return t({stdout:!1});return{kind:"usage-error",message:`sveld: --stdout does not take a value; got "${s}".`};case"strict":if(i)return t({strict:!0});if(s==="false")return t({strict:!1});return t({strict:s});case"report-diagnostics":return t({reportDiagnostics:i});case"check-examples":if(i)return t({checkExamples:!0});if(s==="false")return t({checkExamples:!1});return t({checkExamples:s});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(s==="false")return t({cache:!1});return t({cache:e??!0});case"check":if(s==="false")return t({check:!1});return t({check:e??!0});case"types-format":return t(e===void 0?{}:{typesOptions:{format:e}});case"types-index-types":return t({typesOptions:{indexTypes:i}});case"format":return t(e===void 0?{}:{format:e});case"check-level":return t(e===void 0?{}:{checkLevel:e});default:return{kind:"unknown",arg:o,suggestion:O(r)}}}function T(r){let s={},o=!1;for(let t=0;t<r.length;t++){let i=k.get(r[t])??r[t];if(!i.startsWith("--"))return{kind:"unknown",arg:i,positionalHint:o?!0:void 0};let{result:e,consumedNext:c,flag:l}=A(i,r[t+1]);if(e.kind!=="option")return e;if(s=I(s,e.option),o=R.has(l),c)t++}return{kind:"options",options:s}}function u(r,s){return r!==void 0&&!s.includes(r)}async function _(r){let s=(a)=>{console.error(a),r.exitCode=m.USAGE_ERROR},o=T(r.argv.slice(2));if(o.kind==="help"){console.log(x);return}if(o.kind==="version"){console.log(Nt.version);return}if(o.kind==="usage-error")return s(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),s("Run sveld --help for a list of available flags.")}let t=o.options,i;try{i=await J(t.config,r.cwd(),!0)}catch(a){return s(a instanceof Error?a.message:String(a))}let e=I(i,t);if(j(e),e.stdout){if([e.json,e.markdown].filter(Boolean).length!==1)return s("sveld: --stdout requires exactly one of --json or --markdown.");if(e.types===!0)return s("sveld: --stdout cannot be combined with --types; type definitions span multiple files.");if(e.check)return s("sveld: --stdout cannot be combined with --check; both write their document to stdout.")}if(u(e.format,["text","json"]))return s(`sveld: --format must be "text" or "json"; got "${e.format}".`);if(u(e.strict,[!0,!1,"errors"]))return s(`sveld: --strict must be "errors" when given a value; got "${e.strict}".`);if(u(e.checkLevel,["major","minor","patch"]))return s(`sveld: --check-level must be "major", "minor", or "patch"; got "${e.checkLevel}".`);if(u(e.checkExamples,[!0,!1,"syntax"]))return s(`sveld: --check-examples must be "syntax" when given a value; got "${e.checkExamples}".`);let c=e.typesOptions?.format;if(u(c,["class","component"]))return s(`sveld: --types-format must be "class" or "component"; got "${c}".`);F(e.quiet===!0);let l=Ie(e.entry),p;if(l.entry!==null)p=l.entry;else if(!l.configured&&v(S(r.cwd(),f)))console.error(`sveld: no entry point configured; using "${f}". Set package.json#svelte (or pass --entry) to silence this.`),p=Z(n(f));else return s(`sveld: ${l.message}`);let g;try{g=await Re(p,e,e.stdout===!0)}catch(a){if(a instanceof V)return s(`sveld: ${a.message}`);console.error(a instanceof Error?a.message:String(a)),r.exitCode=m.GENERATION_FAILURE;return}let{result:y,check:d}=g,{exitCode:h}=Le(y,d,e);if(d)if(e.format==="json")r.stdout.write(ye(d));else console.log(ge(d));if(h!==m.SUCCESS)r.exitCode=h}export{_ as cli};
|
package/index.d.ts
CHANGED
|
@@ -171,9 +171,12 @@ interface ComponentPropReExport {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
interface ComponentClassMember {
|
|
174
|
-
/**
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
/**
|
|
175
|
+
* `"property"` covers fields, constructor parameter properties, and getter/setter pairs;
|
|
176
|
+
* `"index"` is an index signature (`[key: string]: unknown`).
|
|
177
|
+
*/
|
|
178
|
+
kind: "constructor" | "method" | "property" | "index";
|
|
179
|
+
/** Member name; `"constructor"` for the constructor, the bracketed key (`[key: string]`) for an index signature. */
|
|
177
180
|
name: string;
|
|
178
181
|
/** Property type text; `"any"` when neither TypeScript nor JSDoc types it. */
|
|
179
182
|
type?: string;
|
|
@@ -466,6 +469,7 @@ interface ParsedComponent {
|
|
|
466
469
|
diagnostics?: SveldDiagnostic[];
|
|
467
470
|
/** Writer-only TypeScript metadata. Not serialized to JSON. */
|
|
468
471
|
[PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
|
|
472
|
+
[PARSED_COMPONENT_PROP_IGNORES]?: Record<string, string[]>;
|
|
469
473
|
}
|
|
470
474
|
|
|
471
475
|
export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "slot-missing-type" | "slot-not-rendered" | "event-no-source" | "dispatch-escapes" | "example-compile-error" | "example-syntax-error" | "syntax-skipped" | "type-syntax-error" | "rest-props-unresolved" | "context-duplicate-key" | "context-key-unresolved" | "context-value-unresolved" | "spread-unresolved" | "export-unresolved" | "module-export-conflict" | "extend-props-target-missing" | "extend-props-duplicate" | "extend-props-override" | "jsdoc-unknown-tag" | "typedef-duplicate" | "property-duplicate" | "generics-conflict" | "event-description-ambiguous" | "jsdoc-tag-dropped" | "internal-typedef-referenced" | "cross-file-unresolved" | "export-ambiguous";
|
|
@@ -514,6 +518,8 @@ export interface DiagnosticsJson {
|
|
|
514
518
|
|
|
515
519
|
declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
|
|
516
520
|
|
|
521
|
+
declare const PARSED_COMPONENT_PROP_IGNORES: unique symbol;
|
|
522
|
+
|
|
517
523
|
export type SemverBump = "major" | "minor" | "patch" | "none";
|
|
518
524
|
|
|
519
525
|
export interface ApiChange {
|
|
@@ -659,12 +665,10 @@ export interface SveldRuntimeOptions extends PluginSveldOptions {
|
|
|
659
665
|
*/
|
|
660
666
|
check?: boolean | string;
|
|
661
667
|
/**
|
|
662
|
-
* Minimum bump `--check` fails the run (exit `3`) on: `"major"`
|
|
663
|
-
*
|
|
668
|
+
* Minimum bump `--check` fails the run (exit `3`) on: `"major"`
|
|
669
|
+
* (default), `"minor"`, or `"patch"`.
|
|
664
670
|
*/
|
|
665
671
|
checkLevel?: "major" | "minor" | "patch";
|
|
666
|
-
/** Suppress writer progress logs (`created "..."` / `unchanged "..."`). */
|
|
667
|
-
quiet?: boolean;
|
|
668
672
|
/**
|
|
669
673
|
* Print the single selected `json` / `markdown` document to stdout
|
|
670
674
|
* instead of writing it to disk. Requires exactly one of those two
|
|
@@ -673,9 +677,9 @@ export interface SveldRuntimeOptions extends PluginSveldOptions {
|
|
|
673
677
|
stdout?: boolean;
|
|
674
678
|
/**
|
|
675
679
|
* Output format for the `--check` report and the `--report-diagnostics` /
|
|
676
|
-
* `--strict` diagnostics summary: `"text"` (default) or `"json"`.
|
|
677
|
-
*
|
|
678
|
-
*
|
|
680
|
+
* `--strict` diagnostics summary: `"text"` (default) or `"json"`. The
|
|
681
|
+
* check report goes to stdout and the summary to stderr. `sveld()` prints
|
|
682
|
+
* only the summary.
|
|
679
683
|
*/
|
|
680
684
|
format?: "text" | "json";
|
|
681
685
|
}
|
|
@@ -694,7 +698,8 @@ interface PluginSveldOptions extends Pick<GenerateBundleOptions, "cache" | "chec
|
|
|
694
698
|
* Load `sveld.config.{js,mjs,ts}` and merge it with these options; these
|
|
695
699
|
* options win when a key is set in both. `true` resolves the config from
|
|
696
700
|
* the Vite project root (or `process.cwd()` if the plugin isn't running
|
|
697
|
-
* under Vite); a string is an explicit path to the config file itself
|
|
701
|
+
* under Vite); a string is an explicit path to the config file itself,
|
|
702
|
+
* which must exist.
|
|
698
703
|
* @default false
|
|
699
704
|
*/
|
|
700
705
|
config?: boolean | string;
|
|
@@ -917,4 +922,13 @@ export interface SveldResult {
|
|
|
917
922
|
|
|
918
923
|
type ExitCode = 0 | 1 | 2 | 3 | 4;
|
|
919
924
|
|
|
920
|
-
export
|
|
925
|
+
export interface SveldOptions extends Omit<SveldRuntimeOptions, "config"> {
|
|
926
|
+
/**
|
|
927
|
+
* Whether to load `sveld.config.{js,mjs,ts}` from the working directory and
|
|
928
|
+
* merge it under these options. `false` ignores it.
|
|
929
|
+
* @default true
|
|
930
|
+
*/
|
|
931
|
+
config?: boolean;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
export declare function sveld(opts?: SveldOptions): Promise<SveldResult>;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{H,
|
|
1
|
+
import{H,$e,h,It,Ne,ge,Rt,ye,$t,Lt,Bt}from"./chunk-sfnqvdg5.js";import{ee}from"./chunk-mnkbqz8m.js";export{Rt as CHECK_REPORT_SCHEMA_VERSION,ee as ComponentParser,$e as DIAGNOSTICS_SCHEMA_VERSION,H as DIAGNOSTIC_CODES,h as buildComponentApiDocument,Lt as default,$t as defineConfig,It as diffApiDocuments,ge as formatCheckReport,ye as formatCheckReportJson,Ne as runCheck,Bt as sveld};
|
package/package.json
CHANGED
|
@@ -267,7 +267,7 @@
|
|
|
267
267
|
"description": "A public member of a `kind: \"class\"` module export. Private, protected, and `@internal` members are left out.",
|
|
268
268
|
"properties": {
|
|
269
269
|
"kind": {
|
|
270
|
-
"enum": ["constructor", "method", "property"],
|
|
270
|
+
"enum": ["constructor", "method", "property", "index"],
|
|
271
271
|
"description": "`property` covers fields, constructor parameter properties, and getter/setter pairs."
|
|
272
272
|
},
|
|
273
273
|
"name": { "type": "string" },
|
package/chunk-deb45vqa.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{n}from"./chunk-m4pg0axh.js";import{existsSync as T,readdirSync as x,readFileSync as _,statSync as k}from"node:fs";import{createRequire as P}from"node:module";import c from"node:path";var R=/[^A-Za-z0-9_-]/g,C=/[^A-Za-z0-9_$]/g,w=/^[0-9]/,I=2,f=7,m=`TypeScript ${f} or later, which provides \`typescript/unstable/async\``;function N(e){if(!e)return!1;let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>=f}async function b(e){let t;try{let i=P(c.join(e,"package.json")).resolve("typescript/package.json");t=JSON.parse(_(i,"utf8")).version}catch{return{installed:!1}}if(!N(t))return{installed:!0,version:t};try{let s=await import("./chunk-1azsj0zd.js");return{installed:!0,version:t,module:s}}catch{return{installed:!0,version:t}}}class d{api=null;tsconfigPath;overlay=new Map;constructor(e){this.tsconfigPath=e}static async create(e=process.cwd(),{importTs:t=b}={}){let s=await t(e);if(!s.installed)return{ok:!1,reason:"not-installed",message:`requires the \`typescript\` package to be installed (${m}); none was found`};if(!s.module)return{ok:!1,reason:"unsupported-version",message:`requires ${m}; found \`typescript@${s.version??"unknown"}\` installed, which does not expose that module`};let i=F(e);if(!i)return{ok:!1,reason:"no-tsconfig",message:`could not locate a tsconfig.json starting from "${e}"`};let r=new d(i);return r.api=new s.module.API({cwd:e,fs:r.createFileSystem()}),{ok:!0,resolver:r}}async checkExamples(e){let t=new Map,s=[];for(let r of e)for(let o of r.sources){let a=this.exampleFileName(r.filePath,r.moduleName,o.id);this.overlay.set(a,j(o)),s.push({filePath:r.filePath,source:o,file:a})}if(s.length===0)return t;let i=await this.api.updateSnapshot({openProject:this.tsconfigPath,fileChanges:{created:s.map((r)=>r.file)}});try{let r=await i.getDefaultProjectForFile(s[0].file);if(!r)return t;await Promise.all(s.map(async({filePath:o,source:a,file:p})=>{let[h,y]=await Promise.all([r.program.getSyntacticDiagnostics(p),r.program.getSemanticDiagnostics(p)]),u=[...h,...y];if(u.length===0)return;let E=this.overlay.get(p)??"",v=u.map((l)=>A(l,E)).sort((l,S)=>l.line-S.line).map((l)=>`Line ${l.line}: ${l.text}`).join(`
|
|
2
|
-
`),g=t.get(o)??[];g.push({id:a.id,name:a.name,message:v}),t.set(o,g)}))}finally{await i.dispose?.()}return t}async dispose(){this.overlay.clear(),await this.api?.close?.()}createFileSystem(){return{readFile:(e)=>this.overlay.get(n(e)),fileExists:(e)=>this.overlay.has(n(e))?!0:void 0,getAccessibleEntries:(e)=>{let t=n(e),s=Array.from(this.overlay.keys()).filter((o)=>n(c.dirname(o))===t);if(s.length===0)return;let i=[],r=[];try{for(let o of x(e)){let a=c.join(e,o);try{(k(a).isDirectory()?r:i).push(o)}catch{}}}catch{}for(let o of s){let a=c.basename(o);if(!i.includes(a))i.push(a)}return{files:i,directories:r}}}}exampleFileName(e,t,s){let i=c.dirname(c.resolve(e)),r=s.replace(R,"_");return n(c.join(i,`__sveld_example_${t}_${r}.ts`))}}function D(e){let t=e.replace(C,"_");if(t===""||w.test(t))return`_${t}`;return t}function j(e){return`const ${D(e.name)} = null as unknown as (${e.type});
|
|
3
|
-
${e.code}
|
|
4
|
-
`}function A(e,t){let s=e.pos??0,i=t.slice(0,s).split(`
|
|
5
|
-
`).length;return{line:Math.max(1,i-I+1),text:String(e.text??"").trim()}}function F(e){let t=c.resolve(e);while(!0){let s=c.join(t,"tsconfig.json");if(T(s))return s;let i=c.dirname(t);if(i===t)return null;t=i}}export{d as TypeResolver};
|