sveld 0.34.0 → 0.34.1
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 +57 -1
- package/lib/cli.d.ts +3 -1
- package/lib/index.js +2 -2
- package/lib/sveld.d.ts +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -254,6 +254,58 @@ The check is narrow on purpose. It catches renamed or removed symbols and wrong
|
|
|
254
254
|
|
|
255
255
|
Needs `typescript` and a `tsconfig.json`, same as `resolveTypes`. Use `--strict` (or the `strict` option) to fail CI when an example breaks.
|
|
256
256
|
|
|
257
|
+
#### Type inference diagnostics
|
|
258
|
+
|
|
259
|
+
`sveld` collects unresolved-type diagnostics on every run: props that fall back to `any`, context values typed as `any`, `@event` tags with no dispatch or callback, and (when `checkExamples` is enabled) `example-compile-error`. They are always returned from the programmatic `sveld()` API in `SveldResult.diagnostics`.
|
|
260
|
+
|
|
261
|
+
With `reportDiagnostics` or `strict`, the grouped summary looks like this:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
sveld: 4 unresolved types found.
|
|
265
|
+
|
|
266
|
+
Props without inferred types (1):
|
|
267
|
+
./icons/Add.svelte
|
|
268
|
+
- Prop "title" type could not be inferred; falling back to "any".
|
|
269
|
+
|
|
270
|
+
Context values typed as `any` (1):
|
|
271
|
+
./ThemeProvider.svelte
|
|
272
|
+
- Context "theme" variable "themeStore" has no type annotation; defaulted to "any".
|
|
273
|
+
|
|
274
|
+
@event tags with no dispatch or callback (2):
|
|
275
|
+
./Modal.svelte
|
|
276
|
+
- @event "open" has no matching dispatch or callback prop.
|
|
277
|
+
- @event "close" has no matching dispatch or callback prop.
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
When `checkExamples` is also enabled, `@example` compile failures appear as a fourth group:
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
@example blocks that failed to compile (1):
|
|
284
|
+
./Component.svelte
|
|
285
|
+
- Line 1: Cannot find name 'formatValue'.
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
By default, nothing is printed. Opt in when you are working on types or want CI output:
|
|
289
|
+
|
|
290
|
+
```ts
|
|
291
|
+
await sveld({ json: true, reportDiagnostics: true });
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Use `strict: true` (or `--strict`) to exit with code `1` when diagnostics exist. `strict` implies `reportDiagnostics`, so CI always shows why the run failed.
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
await sveld({ json: true, strict: true });
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
CLI equivalent:
|
|
301
|
+
|
|
302
|
+
```sh
|
|
303
|
+
npx sveld --json --report-diagnostics
|
|
304
|
+
npx sveld --json --strict
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`--check` is separate: it diffs `COMPONENT_API.json` for API drift and semver classification, not inference warnings.
|
|
308
|
+
|
|
257
309
|
## Usage
|
|
258
310
|
|
|
259
311
|
### Installation
|
|
@@ -365,7 +417,7 @@ If no `input` is specified, `sveld` will infer the entry point based on the `pac
|
|
|
365
417
|
import { sveld } from "sveld";
|
|
366
418
|
import pkg from "./package.json" with { type: "json" };
|
|
367
419
|
|
|
368
|
-
sveld({
|
|
420
|
+
const { diagnostics } = await sveld({
|
|
369
421
|
input: "./src/index.js",
|
|
370
422
|
glob: true,
|
|
371
423
|
markdown: true,
|
|
@@ -385,6 +437,8 @@ sveld({
|
|
|
385
437
|
});
|
|
386
438
|
```
|
|
387
439
|
|
|
440
|
+
`diagnostics` is always populated; printing is opt-in via `reportDiagnostics` or `strict` (see [Type inference diagnostics](#type-inference-diagnostics)).
|
|
441
|
+
|
|
388
442
|
#### `jsonOptions.outDir`
|
|
389
443
|
|
|
390
444
|
With `json: true`, `sveld` writes `COMPONENT_API.json` at the project root. The file documents all components.
|
|
@@ -462,6 +516,8 @@ TypeScript definitions land in the `types` folder by default. Include that folde
|
|
|
462
516
|
- **`resolveTypes`** (boolean, optional, default: `false`): Load the TypeScript program to expand opaque imported whole-object `$props()` types into JSON. See [Opt-in semantic resolution](#opt-in-semantic-resolution-resolvetypes).
|
|
463
517
|
- **`cache`** (boolean | string, optional, default: `false`): Write parsed component output to disk and skip re-parsing unchanged files on later runs. `true` uses `node_modules/.cache/sveld/parse-cache.json`; a string sets a custom path. Also available as `--cache` / `--cache=<path>`. See [Persistent parse cache](#persistent-parse-cache-cache).
|
|
464
518
|
- **`checkExamples`** (boolean, optional, default: `false`): Run plain TS/JS `@example` blocks through the TypeScript program. Broken ones get an `example-compile-error` diagnostic. See [Compile-checked `@example` blocks](#compile-checked-example-blocks-checkexamples).
|
|
519
|
+
- **`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).
|
|
520
|
+
- **`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).
|
|
465
521
|
|
|
466
522
|
By default, only TypeScript definitions are generated.
|
|
467
523
|
|
package/lib/cli.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type PluginSveldOptions } from "./plugin";
|
|
2
2
|
/** CLI options layered on top of the shared plugin options. */
|
|
3
3
|
interface CliOptions extends PluginSveldOptions {
|
|
4
|
-
/**
|
|
4
|
+
/** Print unresolved-type diagnostics to stderr. */
|
|
5
|
+
reportDiagnostics?: boolean;
|
|
6
|
+
/** Set exit code 1 when diagnostics are present. Implies `reportDiagnostics`. */
|
|
5
7
|
strict?: boolean;
|
|
6
8
|
/**
|
|
7
9
|
* Diff the parsed component API against a committed snapshot (default:
|
package/lib/index.js
CHANGED
|
@@ -610,7 +610,7 @@ ${_u}`:_u}}this.addDispatchedEvent({name:$,detail:ll,has_argument:!1,description
|
|
|
610
610
|
`);let f=this.sourceLinesCache,[h,v,t]=Kr.getVarNameRegexes(u);for(let $=0;$<f.length;$++){let y=f[$].trim(),a=y.match(h),V=y.match(v),Q=y.match(t);if(a||V||Q)for(let A=$-1;A>=0;A--){let C=f[A].trim();if(C&&!C.startsWith("*")&&!C.startsWith("/*")&&!C.startsWith("//"))break;if(C.startsWith("/**")){let G=[];for(let k=A;k<$;k++)G.push(f[k]);let W=G.join(`
|
|
611
611
|
`),m=Sq(W,{spacing:"preserve"}),{type:E,description:_}=this.getCommentTags(m);if(E)return{type:this.aliasType(E.type),description:_||E.description};break}}}return null}parseContextValue(u,l){if(!u||typeof u!=="object"||!("type"in u))return null;if(u.type==="ObjectExpression"){let r=[];if(!R2u(u))return null;let f=u;for(let h of f.properties){if(h.type!=="Property")continue;let v=this.getPropertyName(h.key);if(!v)continue;let t="any",$;if(r7(h.value)){let y=h.value.name,a=this.findVariableTypeAndDescription(y);if(a)t=a.type,$=a.description;else if(this.recordDiagnostic("context-any-type",v,`Context "${l}" property "${v}" has no type annotation; defaulted to "any".`),this.options?.verbose)console.warn(`Warning: Context "${l}" property "${v}" has no type annotation. Using "any".`)}else if(h.value&&typeof h.value==="object"&&"type"in h.value&&(h.value.type==="ArrowFunctionExpression"||h.value.type==="FunctionExpression"))t=`(${h.value.params?.map((V)=>{if(r7(V))return`${V.name||"arg"}: any`;return"arg: any"}).join(", ")||""}) => any`;else if(ap(h.value))t=h.value.value==null?"null":typeof h.value.value;r.push({name:v,type:t,description:$,optional:!1})}return{key:l,typeName:this.generateContextTypeName(l),properties:r,description:void 0}}else if(r7(u)){let r=u.name,f=this.findVariableTypeAndDescription(r);if(f)return{key:l,typeName:this.generateContextTypeName(l),properties:[{name:r,type:f.type,description:f.description,optional:!1}]};if(this.recordDiagnostic("context-any-type",r,`Context "${l}" variable "${r}" has no type annotation; defaulted to "any".`),this.options?.verbose)console.warn(`Warning: Context "${l}" variable "${r}" has no type annotation. Using "any".`);return{key:l,typeName:this.generateContextTypeName(l),properties:[{name:r,type:"any",description:void 0,optional:!1}]}}return null}resolveContextKey(u,l=0){if(!u||typeof u!=="object"||!("type"in u))return null;let r=u;if(r.type==="Literal")return typeof r.value==="string"?r.value:r.value==null?null:String(r.value);if(r.type==="TemplateLiteral"){if(r.quasis?.length===1){let f=r.quasis[0].value.cooked;return f==null?null:f}return null}if(r.type==="CallExpression"||r.type==="NewExpression")return this.resolveSymbolKeyDescription(r);if(r.type==="Identifier"){if(l>=5)return null;let f=this.resolveConstInitializer(r.name);if(f&&typeof f==="object"&&"type"in f){let h=f;if((h.type==="CallExpression"||h.type==="NewExpression")&&this.resolveSymbolKeyDescription(h)==="")return r.name;return this.resolveContextKey(h,l+1)}return null}return null}resolveSymbolKeyDescription(u){let l=u.callee;if(!l||typeof l!=="object"||!("type"in l))return null;let r=l.type==="Identifier"&&l.name==="Symbol",f=l.type==="MemberExpression"&&!l.computed&&l.object.type==="Identifier"&&l.object.name==="Symbol"&&l.property.type==="Identifier"&&l.property.name==="for";if(!r&&!f)return null;let h=u.arguments[0];if(!h||typeof h!=="object"||!("type"in h))return"";if(h.type==="Literal"&&typeof h.value==="string")return h.value;if(h.type==="TemplateLiteral"&&h.quasis?.length===1)return h.quasis[0].value.cooked??"";return""}parseSetContextCall(u,l){if(!u||typeof u!=="object"||!("type"in u)||u.type!=="CallExpression")return;let r=u,f=r.arguments[0];if(!f)return;let h=this.resolveContextKey(f);if(!h){let $=this.componentFilePath?` in ${this.componentFilePath}`:"";console.warn(`Warning: Could not resolve setContext key${$}. Use a string literal, const-bound string, or Symbol(). Skipping context type generation.`);return}let v=r.arguments[1];if(!v)return;let t=this.parseContextValue(v,h);if(t)if(this.contexts.has(h)){if(this.options?.verbose)console.warn(`Warning: Multiple setContext calls with key "${h}". Using first occurrence.`)}else this.contexts.set(h,t)}accumulateGeneric(u,l){if(this.generics)this.generics=[`${this.generics[0]},${u}`,`${this.generics[1]}, ${l}`];else this.generics=[u,l]}cleanup(){this.syntaxMode="legacy",this.scriptLanguage=void 0,this.source=void 0,this.compiled=void 0,this.parsed=void 0,this.rest_props=void 0,this.extends=void 0,this.componentComment=void 0,this.componentCommentSource=void 0,this.reactive_vars.clear(),this.vars.clear(),this.funcDecls.clear(),this.props.clear(),this.moduleExports.clear(),this.slots.clear(),this.events.clear(),this.eventDescriptions.clear(),this.forwardedEvents.clear(),this.typedefs.clear(),this.generics=null,this.deferredSlotBlockGenerics.length=0,this.bindings.clear(),this.contexts.clear(),this.variableInfoCache.clear(),this.propLocalToPublicName.clear(),this.restPropLocals.clear(),this.wholePropsLocals.clear(),this.snippetPropLocals.clear(),this.runesPropsDeclarationMetadataByDeclaratorStart.clear(),this.explicitPropTypesByName.clear(),this.typeImportBindingsByLocalName.clear(),this.localTypeDeclarationsByName.clear(),this.typedRunesPropsDeclarations.length=0,this.componentScope.clear(),this.scopeDeclarations=new WeakMap,this.activeScopes.length=0,this.diagnosticRecords.length=0,this.componentFilePath="",this.jsDocEventNames.clear(),this.sourceLinesCache=void 0,this.sourceLineStartOffsetsCache=void 0}static SCRIPT_BLOCK_REGEX=/(<script[^>]*>)([\s\S]*?)(<\/script>)/gi;static TS_DIRECTIVE_REGEX=/\/\/\s*@ts-[^\n\r]*/g;static stripTypeScriptDirectivesFromScripts(u){return Kr.SCRIPT_BLOCK_REGEX.lastIndex=0,u.replace(Kr.SCRIPT_BLOCK_REGEX,(l,r,f,h)=>{Kr.TS_DIRECTIVE_REGEX.lastIndex=0;let v=f.replace(Kr.TS_DIRECTIVE_REGEX,"");return r+v+h})}parseSvelteComponent(u,l){if(this.options?.verbose)console.log(`[parsing] "${l.moduleName}" ${l.filePath}`);this.cleanup(),this.componentFilePath=l.filePath;let r=Kr.stripTypeScriptDirectivesFromScripts(u);this.source=r,this.buildRunesPropTypeMetadata();let f=w2u(r,{generate:!1,modernAst:!1});if(this.compiled=f,this.syntaxMode=f.metadata.runes?"runes":"legacy",this.parsed=f.ast||Qv(r,{modern:!1}),this.sourceLinesCache=this.source.split(`
|
|
612
612
|
`),this.buildVariableInfoCache(),this.parseCustomTypes(),this.parsed?.module)Nq(this.parsed?.module,{enter:(E)=>{if(E.type==="ExportNamedDeclaration"){if(E.declaration==null)return;if(!E.declaration||typeof E.declaration!=="object"||!("type"in E.declaration))return;let _,k,fu,uu=!1,qu,iu,U,X=!1,I,J,d,hu,ru;if(E.declaration.type==="FunctionDeclaration"){let Bu=E.declaration;if(!Bu.id?.name)return;_=Bu.id.name,k="function",qu=void 0,iu="() => any",X=!0,uu=!0}else if(E.declaration.type==="VariableDeclaration"){let Bu=E.declaration,bu=Bu.declarations[0];if(!bu||typeof bu!=="object"||!("id"in bu))return;let{id:nu,init:cu}=bu;if(!nu||typeof nu!=="object"||!("name"in nu))return;let ll=nu.name;_=ll,k=L2u(Bu.kind);let rl=cu==null?{isFunction:!1}:this.processInitializer(cu);({value:qu,type:hu,isFunction:X,defaultValue:d}=rl),ru=rl,U=this.getExplicitPropType(ll),iu=U??hu}else return;let D=this.processNodeJSDoc(E);if(D){if(D.type&&U===void 0)iu=D.type;if(I=D.params,J=D.returnType,D.description)fu=D.description}if(U===void 0&&D?.type===void 0&&ru?.resolvedType)iu=ru.resolvedType;if(fu===void 0&&ru?.resolvedDescription)fu=ru.resolvedDescription;if(I===void 0&&ru?.resolvedParams)I=ru.resolvedParams;if(J===void 0&&ru?.resolvedReturnType)J=ru.resolvedReturnType;if(uu&&iu==="() => any"&&J)if(I&&I.length>0)iu=`(${I.map((nu)=>{let cu=nu.optional?"?":"";return`${nu.name}${cu}: ${nu.type}`}).join(", ")}) => ${J}`;else iu=`() => ${J}`;if(!fu&&iu&&this.typedefs.has(iu))fu=this.typedefs.get(iu)?.description;let N=this.resolveTypeSource({hasTypeScriptType:U!==void 0,hasJSDocType:D?.type!==void 0||D?.params!==void 0||D?.returnType!==void 0||ru?.resolvedType!==void 0,inferredType:hu,finalType:iu});this.addModuleExport(_,{name:_,kind:k,description:fu,deprecated:D?.deprecated,tags:D?.tags,type:iu,typeSource:N,value:qu,defaultValue:d,params:I,returnType:J,isFunction:X,isFunctionDeclaration:uu,isRequired:!1,constant:k==="const",reactive:!1,source:this.sourceRangeFromNode(E)})}}});let h,v=[],t={type:"ComponentRoot",instance:this.parsed.instance,html:this.parsed.html};if(this.buildScopeDeclarations(t),this.activeScopes.push(this.componentScope),Nq(t,{enter:(E,_,k)=>{let fu=this.scopeDeclarations.get(E);if(fu)this.activeScopes.push(fu);if(E.type==="AssignmentExpression")this.markReactivePropsFromMutationTarget(E.left);if(E.type==="UpdateExpression")this.markReactivePropsFromMutationTarget(E.argument);if(E.type==="CallExpression"){let uu=E,qu=uu.callee&&typeof uu.callee==="object"&&"name"in uu.callee?uu.callee.name:void 0;if(qu==="createEventDispatcher"){if(_&&typeof _==="object"&&"id"in _&&_.id&&typeof _.id==="object"&&"name"in _.id)h=_.id.name}if(qu==="setContext")this.parseSetContextCall(E,_??void 0);if(qu)v.push({name:qu,arguments:uu.arguments,source:this.sourceRangeFromNode(uu)})}if(E&&typeof E==="object"&&"type"in E&&String(E.type)==="Spread"){let uu=E;if(uu.expression?.name==="$$restProps"||this.restPropLocals.has(uu.expression?.name??""))this.maybeSetRestProps(_)}if(E.type==="FunctionDeclaration"){let uu=E;if(uu.id?.name)this.funcDecls.set(uu.id.name,uu)}if(E.type==="VariableDeclaration"){if(this.vars.add(E),_&&typeof _==="object"&&"type"in _&&_.type==="Program"&&E.declarations.some((uu)=>C2(uu.init,"$props")))this.parseRunesPropsDeclaration(E)}if(E.type==="ExportNamedDeclaration"){if(E.declaration==null&&E.specifiers.length===0)return;let uu;if(E.declaration==null&&E.specifiers[0]?.type==="ExportSpecifier"){let rl=E.specifiers[0],Ul=rl.local&&typeof rl.local==="object"&&"name"in rl.local?rl.local.name:void 0,Bl=rl.exported&&typeof rl.exported==="object"&&"name"in rl.exported?rl.exported.name:void 0;if(!Ul||!Bl)return;let _u;for(let Wu of Array.from(this.vars))if(Wu.declarations.some((Hl)=>Hl.id&&typeof Hl.id==="object"&&("type"in Hl.id)&&Hl.id.type==="Identifier"&&Hl.id.name===Ul)){_u=Wu;break}E.declaration=_u,uu=Bl}if(E.declaration==null)return;if(!E.declaration||typeof E.declaration!=="object"||!("type"in E.declaration))return;let qu,iu,U=!1,X,I,J,d=!1,hu,ru,D=!1,N,Bu,bu,nu;if(E.declaration.type==="FunctionDeclaration"){let rl=E.declaration;if(!rl.id?.name)return;uu??=rl.id.name,N=rl.id.name,qu="function",X=void 0,I="() => any",d=!0,U=!0,D=!1}else if(E.declaration.type==="VariableDeclaration"){let rl=E.declaration,Ul=rl.declarations[0];if(!Ul||typeof Ul!=="object"||!("id"in Ul))return;let{id:Bl,init:_u}=Ul;if(Bl&&typeof Bl==="object"&&"name"in Bl){let Hl=Bl.name;N=Hl,uu??=Hl,J=this.getExplicitPropType(Hl)}else return;qu=L2u(rl.kind),D=qu==="let"&&_u==null;let Wu=_u==null?{isFunction:!1}:this.processInitializer(_u);({value:X,type:bu,isFunction:d,defaultValue:Bu}=Wu),nu=Wu,I=J??bu}else return;let cu=this.processNodeJSDoc(E);if(cu){if(cu.type&&J===void 0)I=cu.type;if(hu=cu.params,ru=cu.returnType,cu.description)iu=cu.description}if(J===void 0&&cu?.type===void 0&&nu?.resolvedType)I=nu.resolvedType;if(iu===void 0&&nu?.resolvedDescription)iu=nu.resolvedDescription;if(hu===void 0&&nu?.resolvedParams)hu=nu.resolvedParams;if(ru===void 0&&nu?.resolvedReturnType)ru=nu.resolvedReturnType;if(U&&I==="() => any"&&ru)if(hu&&hu.length>0)I=`(${hu.map((Bl)=>{let _u=Bl.optional?"?":"";return`${Bl.name}${_u}: ${Bl.type}`}).join(", ")}) => ${ru}`;else I=`() => ${ru}`;if(!iu&&I&&this.typedefs.has(I))iu=this.typedefs.get(I)?.description;let ll=this.resolveTypeSource({hasTypeScriptType:J!==void 0,hasJSDocType:cu?.type!==void 0||cu?.params!==void 0||cu?.returnType!==void 0||nu?.resolvedType!==void 0,inferredType:bu,finalType:I});this.addProp(uu,{name:uu,...N!==void 0&&N!==uu?{localName:N}:{},kind:qu,description:iu,binding:cu?.binding,deprecated:cu?.deprecated,tags:cu?.tags,type:I,typeSource:ll,value:X,defaultValue:Bu,params:hu,returnType:ru,isFunction:d,isFunctionDeclaration:U,isRequired:D,constant:qu==="const",reactive:this.reactive_vars.has(uu),source:this.sourceRangeFromNode(E)})}if(E&&typeof E==="object"&&"type"in E&&String(E.type)==="Comment"){let qu=E?.data?.trim()??"";if(H2u.test(qu))this.componentComment=qu.replace(H2u,"").replace(G_u,""),this.componentCommentSource=this.sourceRangeFromNode(E)}if(E&&typeof E==="object"&&"type"in E&&String(E.type)==="Slot"){let uu=E,qu=uu.attributes?.find((X)=>X.name==="name")?.value?.[0]?.data,iu=(uu.attributes||[]).filter((X)=>X.name!=="name").reduce((X,I)=>{let J={value:void 0,replace:!1},d=I.value;if(d===void 0)return X;if(d[0]){let hu=d[0],{type:ru,expression:D,raw:N,start:Bu,end:bu}=hu;if(ru==="Text"&&N!==void 0)J.value=N;else if(ru==="AttributeShorthand"&&D&&typeof D==="object"&&"name"in D)J.value=D.name,J.replace=!0;if(D&&typeof D==="object"&&"type"in D){if(D.type==="Literal"&&"value"in D)J.value=String(D.value);else if(D.type==="MemberExpression")J.value=this.resolveMemberExpressionType(D);else if(D.type!=="Identifier"){if(Bu!==void 0&&bu!==void 0){if(D.type==="ObjectExpression"||D.type==="TemplateLiteral")J.value=this.sourceAtPos(Bu+1,bu-1)}}}}if(I.name)X[I.name]=J;return X},{}),U=uu.children?.map(({start:X,end:I})=>{if(X===void 0||I===void 0)return"";return this.sourceAtPos(X,I)??""}).join("").trim();this.addSlot({slot_name:qu,slot_props:JSON.stringify(iu,null,2),slot_fallback:U,source:this.sourceRangeFromNode(E)})}if(E&&typeof E==="object"&&"type"in E&&String(E.type)==="RenderTag"){let uu=E,qu=this.extractRenderTagInfo(uu.expression);if(qu){let iu;if(qu.arguments.length===0)iu=JSON.stringify({},null,2);else if(qu.arguments.length===1&&typeof qu.arguments[0]==="object"&&qu.arguments[0]&&"type"in qu.arguments[0]&&qu.arguments[0].type==="ObjectExpression")iu=JSON.stringify(this.buildSlotPropsFromObjectExpression(qu.arguments[0]),null,2);else this.logUnsupportedRunesPattern(`Skipping unsupported {@render ...} argument for snippet prop "${qu.publicName}".`);let U=qu.publicName==="children"?void 0:qu.publicName,X=U===void 0?V2u:U;if(iu!==void 0)this.addSlot({slot_name:U,slot_props:iu,source:this.sourceRangeFromNode(E)});if(iu!==void 0||this.slots.has(X))this.snippetPropLocals.add(qu.trackingName)}}if(E&&typeof E==="object"&&"type"in E&&String(E.type)==="EventHandler"){let uu=E;if(uu.expression==null&&uu.name){if(_!=null&&typeof _==="object"&&"name"in _){let qu=typeof _.name==="string"?_.name:void 0,iu="type"in _?String(_.type):void 0;if(qu&&iu){let U=iu==="InlineComponent"?{type:"InlineComponent",name:qu}:{type:"Element",name:qu};this.forwardedEvents.set(uu.name,U);let X=this.events.get(uu.name),I=this.eventDescriptions.get(uu.name),J=X?.deprecated;if(!X)this.events.set(uu.name,{type:"forwarded",name:uu.name,element:U,description:I,deprecated:J,source:this.sourceRangeFromNode(E)});else if(X.type==="forwarded"&&I&&!X.description)this.events.set(uu.name,{...X,description:I,deprecated:X.deprecated??J,source:X.source||this.sourceRangeFromNode(E)})}}}}if(_&&typeof _==="object"&&"type"in _&&(String(_.type)==="Element"||String(_.type)==="InlineComponent")&&E&&typeof E==="object"&&"type"in E&&String(E.type)==="Binding"){let uu=E;if(uu.expression?.name){let qu=this.resolveIdentifierToReactiveProp(uu.expression.name);if(qu)this.reactive_vars.add(qu)}if(String(_.type)==="Element"&&uu.name==="this"&&uu.expression?.name&&"name"in _&&typeof _.name==="string"){let qu=this.resolveIdentifierToReactiveProp(uu.expression.name);if(!qu)return;let iu=_.name;if(this.bindings.has(qu)){let U=this.bindings.get(qu);if(U&&!U.elements.includes(iu))this.bindings.set(qu,{...U,elements:[...U.elements,iu]})}else this.bindings.set(qu,{elements:[iu]})}}},leave:(E)=>{if(this.scopeDeclarations.has(E))this.activeScopes.pop()}}),h!==void 0){for(let E of v)if(E.name===h){let _=E.arguments[0],k=_&&typeof _==="object"&&"value"in _?_.value:void 0,fu=E.arguments[1],uu=fu&&typeof fu==="object"&&"value"in fu?fu.value:void 0;if(k!=null)this.addDispatchedEvent({name:String(k),detail:uu==null?"":String(uu),has_argument:Boolean(fu),source:E.source})}}let $=new Set;if(h!==void 0){for(let E of v)if(E.name===h){let _=E.arguments[0],k=_&&typeof _==="object"&&"value"in _?_.value:void 0;if(k!=null)$.add(String(k))}}this.forwardedEvents.forEach((E,_)=>{let k=this.events.get(_);if(k&&k.type==="dispatched"&&!$.has(_)){let fu=this.eventDescriptions.get(_),uu={type:"forwarded",name:_,element:E,description:fu,deprecated:k.deprecated,tags:k.tags,source:k.source};if(k.detail!==void 0&&k.detail!=="undefined")uu.detail=k.detail;this.events.set(_,uu)}}),this.normalizeRunesCallbackProps($);let y=this.syntaxMode==="runes"?new Set(Array.from(this.snippetPropLocals,(E)=>this.resolvePublicPropName(E))):new Set,a=Kr.mapToArray(this.props).filter((E)=>!y.has(E.name)).map((E)=>{if(this.bindings.has(E.name)){let _=this.bindings.get(E.name)?.elements.sort().map((k)=>A2u(k)).join(" | ");return{...E,type:`null | ${_}`,typeSource:"inferred",reactive:E.reactive||this.reactive_vars.has(E.name)}}return{...E,reactive:E.reactive||this.reactive_vars.has(E.name)}});this.activeScopes.length=0;let V=Kr.mapToArray(this.slots).map((E)=>{try{if(!E.slot_props)return E;let _=JSON.parse(E.slot_props),k=[];for(let uu of Object.keys(_)){if(_[uu].replace&&_[uu].value!==void 0)_[uu].value=this.getPropTypeByLocalOrPublic(_[uu].value);if(_[uu].value===void 0)_[uu].value="any";k.push(`${uu}: ${_[uu].value}`)}let fu=k.length===0?"Record<string, never>":`{ ${k.join(", ")} }`;return{...E,slot_props:fu}}catch(_){return E}}).sort((E,_)=>{let k=E.name??"",fu=_.name??"";if(k<fu)return-1;if(k>fu)return 1;return 0});if(this.deferredSlotBlockGenerics.length>0){let E=[...a.map((_)=>_.type??""),...V.map((_)=>_.slot_props??"")].join(`
|
|
613
|
-
`);for(let{name:_,constraint:k}of this.deferredSlotBlockGenerics){let fu=_.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(!new RegExp(`\\b${fu}\\b`).test(E))continue;this.accumulateGeneric(_,k)}}let Q=Kr.mapToArray(this.moduleExports),A=Kr.mapToArray(this.events).map((E)=>{switch(E.type){case"forwarded":return{...E,element:E.element.name};case"dispatched":return E;default:return E}}).sort((E,_)=>{let k=E.name.localeCompare(_.name);if(k!==0)return k;let fu=E.type.localeCompare(_.type);if(fu!==0)return fu;if(E.type==="forwarded"&&_.type==="forwarded"){let uu=E.element.localeCompare(_.element);if(uu!==0)return uu}return(E.detail??"").localeCompare(_.detail??"")}),C=Kr.mapToArray(this.typedefs),G=Kr.mapToArray(this.contexts);for(let E of a)if(E.typeSource==="unknown")this.recordDiagnostic("prop-unknown-type",E.name,`Prop "${E.name}" type could not be inferred; falling back to "${E.type??"any"}".`);for(let E of this.jsDocEventNames){if($.has(E))continue;if(this.forwardedEvents.has(E))continue;if(this.props.has(`on${E}`))continue;this.recordDiagnostic("event-no-source",E,`@event "${E}" has no matching dispatch or callback prop.`)}let W={source:this.sourceRangeFromOffsets(0,this.source?.length),syntaxMode:this.syntaxMode,...this.scriptLanguage?{scriptLanguage:this.scriptLanguage}:{},props:a,moduleExports:Q,slots:V,events:A,typedefs:C,generics:this.generics,rest_props:this.rest_props,extends:this.extends,componentComment:this.componentComment,componentCommentSource:this.componentCommentSource,contexts:G,diagnostics:this.diagnosticRecords.slice()},m=this.buildTypeScriptMetadata();if(m)W[i7]=m;return W}}import{readFile as X_u}from"node:fs/promises";import W_u from"node:path";var DA="5.56.3";var Z2u="sveld",mA="0.34.
|
|
613
|
+
`);for(let{name:_,constraint:k}of this.deferredSlotBlockGenerics){let fu=_.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(!new RegExp(`\\b${fu}\\b`).test(E))continue;this.accumulateGeneric(_,k)}}let Q=Kr.mapToArray(this.moduleExports),A=Kr.mapToArray(this.events).map((E)=>{switch(E.type){case"forwarded":return{...E,element:E.element.name};case"dispatched":return E;default:return E}}).sort((E,_)=>{let k=E.name.localeCompare(_.name);if(k!==0)return k;let fu=E.type.localeCompare(_.type);if(fu!==0)return fu;if(E.type==="forwarded"&&_.type==="forwarded"){let uu=E.element.localeCompare(_.element);if(uu!==0)return uu}return(E.detail??"").localeCompare(_.detail??"")}),C=Kr.mapToArray(this.typedefs),G=Kr.mapToArray(this.contexts);for(let E of a)if(E.typeSource==="unknown")this.recordDiagnostic("prop-unknown-type",E.name,`Prop "${E.name}" type could not be inferred; falling back to "${E.type??"any"}".`);for(let E of this.jsDocEventNames){if($.has(E))continue;if(this.forwardedEvents.has(E))continue;if(this.props.has(`on${E}`))continue;this.recordDiagnostic("event-no-source",E,`@event "${E}" has no matching dispatch or callback prop.`)}let W={source:this.sourceRangeFromOffsets(0,this.source?.length),syntaxMode:this.syntaxMode,...this.scriptLanguage?{scriptLanguage:this.scriptLanguage}:{},props:a,moduleExports:Q,slots:V,events:A,typedefs:C,generics:this.generics,rest_props:this.rest_props,extends:this.extends,componentComment:this.componentComment,componentCommentSource:this.componentCommentSource,contexts:G,diagnostics:this.diagnosticRecords.slice()},m=this.buildTypeScriptMetadata();if(m)W[i7]=m;return W}}import{readFile as X_u}from"node:fs/promises";import W_u from"node:path";var DA="5.56.3";var Z2u="sveld",mA="0.34.1";var _A=1;function Zh(u,l={}){let r=Array.from(u,([,h])=>{let{diagnostics:v,...t}=h;return t}).sort((h,v)=>h.moduleName.localeCompare(v.moduleName)),f={schemaVersion:_A,generator:{name:Z2u,version:mA,svelteVersion:DA},total:r.length,components:r};if(l.entryExports&&l.entryExports.length>0)f.totalExports=l.entryExports.length,f.exports=l.entryExports;return f}var b2u={none:0,patch:1,minor:2,major:3};function I_u(u,l){return b2u[l]>b2u[u]?l:u}function z_u(u){return u.reduce((l,r)=>I_u(l,r.bump),"none")}function Q2u(u){let l=[],r=0,f="",h=null;for(let v=0;v<u.length;v++){let t=u[v];if(h){if(f+=t,t==="\\")v++,f+=u[v]??"";else if(t===h)h=null;continue}if(t==='"'||t==="'"||t==="`"){h=t,f+=t;continue}if(t==="<"||t==="("||t==="{"||t==="[")r++;if(t===">"||t===")"||t==="}"||t==="]")r--;if(t==="|"&&r===0){l.push(f.trim()),f="";continue}f+=t}return l.push(f.trim()),new Set(l.filter((v)=>v.length>0))}function Mp(u,l){if(u===l)return"none";if(u===void 0||l===void 0)return"major";let r=Q2u(u),f=Q2u(l),h=[...f].some((t)=>!r.has(t)),v=[...r].some((t)=>!f.has(t));if(!h&&!v)return"none";if(h&&!v)return"minor";if(v&&!h)return"major";return"major"}function Y2u(u,l,r,f){let h=l==="prop"?"prop":"export",v=[],t=new Map(r.map((y)=>[y.name,y])),$=new Map(f.map((y)=>[y.name,y]));for(let[y,a]of $){if(t.has(y))continue;v.push({component:u,kind:l,name:y,bump:a.isRequired?"major":"minor",message:`${h} "${y}" added${a.isRequired?" (required)":""}`})}for(let[y]of t){if($.has(y))continue;v.push({component:u,kind:l,name:y,bump:"major",message:`${h} "${y}" removed`})}for(let[y,a]of t){let V=$.get(y);if(!V)continue;if(a.isRequired!==V.isRequired)v.push({component:u,kind:l,name:y,bump:V.isRequired?"major":"minor",message:`${h} "${y}" became ${V.isRequired?"required":"optional"}`});let Q=Mp(a.type,V.type);if(Q!=="none")v.push({component:u,kind:l,name:y,bump:Q,message:`${h} "${y}" type changed from \`${a.type??"unknown"}\` to \`${V.type??"unknown"}\``})}return v}function E_u(u,l,r){let f=[],h=new Map(l.map((t)=>[t.name,t])),v=new Map(r.map((t)=>[t.name,t]));for(let[t]of v){if(h.has(t))continue;f.push({component:u,kind:"event",name:t,bump:"minor",message:`event "${t}" added`})}for(let[t]of h){if(v.has(t))continue;f.push({component:u,kind:"event",name:t,bump:"major",message:`event "${t}" removed`})}for(let[t,$]of h){let y=v.get(t);if(!y)continue;if($.type!==y.type){f.push({component:u,kind:"event",name:t,bump:"major",message:`event "${t}" changed from ${$.type} to ${y.type}`});continue}let a=$.type==="dispatched"?$.detail:void 0,V=y.type==="dispatched"?y.detail:void 0,Q=Mp(a,V);if(Q!=="none")f.push({component:u,kind:"event",name:t,bump:Q,message:`event "${t}" detail changed from \`${a??"unknown"}\` to \`${V??"unknown"}\``})}return f}function J2u(u){return u.name??"default"}function T_u(u,l,r){let f=[],h=new Map(l.map((t)=>[J2u(t),t])),v=new Map(r.map((t)=>[J2u(t),t]));for(let[t]of v){if(h.has(t))continue;f.push({component:u,kind:"slot",name:t,bump:"minor",message:`slot "${t}" added`})}for(let[t]of h){if(v.has(t))continue;f.push({component:u,kind:"slot",name:t,bump:"major",message:`slot "${t}" removed`})}for(let[t,$]of h){let y=v.get(t);if(!y)continue;let a=Mp($.slot_props,y.slot_props);if(a!=="none")f.push({component:u,kind:"slot",name:t,bump:a,message:`slot "${t}" props changed from \`${$.slot_props??"none"}\` to \`${y.slot_props??"none"}\``})}return f}var c_u=new Set(["description","source","componentCommentSource","tags"]);function FA(u){if(Array.isArray(u))return u.map(FA);if(u!==null&&typeof u==="object"){let l={};for(let[r,f]of Object.entries(u)){if(c_u.has(r))continue;l[r]=FA(f)}return l}return u}var j_u=["generics","rest_props","extends","contexts","typedefs"];function D_u(u,l,r){let f=[];for(let h of j_u){let v=JSON.stringify(FA(l[h])),t=JSON.stringify(FA(r[h]));if(v!==t)f.push({component:u,kind:"shape",name:h,bump:"major",message:`"${h}" changed (breaking)`})}return f}function m_u(u,l){let r=l.moduleName;return[...Y2u(r,"prop",u.props,l.props),...Y2u(r,"moduleExport",u.moduleExports,l.moduleExports),...E_u(r,u.events,l.events),...T_u(r,u.slots,l.slots),...D_u(r,u,l)]}function G2u(u,l){let r=[],f=new Map(u.components.map((v)=>[v.moduleName,v])),h=new Map(l.components.map((v)=>[v.moduleName,v]));for(let[v]of h){if(f.has(v))continue;r.push({component:v,kind:"component",bump:"minor",message:`component "${v}" added`})}for(let[v]of f){if(h.has(v))continue;r.push({component:v,kind:"component",bump:"major",message:`component "${v}" removed`})}for(let[v,t]of f){let $=h.get(v);if(!$)continue;r.push(...m_u(t,$))}return r}async function __u(u){let l;try{l=await X_u(W_u.resolve(u),"utf-8")}catch(r){if(r.code==="ENOENT")return null;throw r}try{return JSON.parse(l)}catch{throw Error(`sveld: could not parse "${u}" as JSON. Is it a sveld COMPONENT_API.json snapshot?`)}}async function Cp(u,l,r={}){let f=await __u(l);if(f===null)return{snapshotExists:!1,snapshotFile:l,changes:[],bump:"none"};if(f.schemaVersion!==_A)return{snapshotExists:!0,snapshotFile:l,changes:[{component:"*",kind:"shape",bump:"none",message:`snapshot schemaVersion ${f.schemaVersion} does not match the current schemaVersion ${_A}; skipping diff`}],bump:"none"};let h=Zh(u,{entryExports:r.entryExports}),v=G2u(f,h);return{snapshotExists:!0,snapshotFile:l,changes:v,bump:z_u(v)}}var F_u={major:"BREAKING",minor:"additive",patch:"patch",none:"no change"};function Lp(u){if(!u.snapshotExists)return`sveld --check: no snapshot found at "${u.snapshotFile}". Run \`sveld --json\` and commit the output first.`;if(u.changes.length===0)return`sveld --check: no API changes detected against "${u.snapshotFile}".`;let l=[],r=u.changes.length;l.push(`sveld --check: ${r} API change${r===1?"":"s"} detected against "${u.snapshotFile}".`),l.push(`Suggested semver bump: ${u.bump}.`);let f=new Map;for(let h of u.changes){let v=f.get(h.component)??[];v.push(h),f.set(h.component,v)}for(let[h,v]of f){l.push(""),l.push(` ${h}`);for(let t of v)l.push(` [${F_u[t.bump]}] ${t.message}`)}return l.join(`
|
|
614
614
|
`)}var gwu=di(I2u(),1),Kwu=di(c2u(),1),xwu=di(D2u(),1),ewu=di(Vwu(),1);import zp,{dirname as Tp,resolve as U2,extname as rSu,normalize as fSu,sep as iSu}from"path";import p2,{realpathSync as hSu}from"fs";import{promisify as Z2}from"util";import{pathToFileURL as KA,fileURLToPath as kwu}from"url";var _wu=di(jwu(),1);import{extname as jZl,sep as mwu,resolve as xku,posix as eku}from"path";function nku(u){return Array.isArray(u)}function Dwu(u){if(nku(u))return u;if(u==null)return[];return[u]}function oku(u,l){if(l===!1)return u;let r=xku(l||"").split(mwu).join("/").replace(/[-^$*+?.()|[\]{}]/g,"\\$&");return eku.join(r,u)}var Fwu=function(l,r,f){let h=f&&f.resolve,v=(y)=>y instanceof RegExp?y:{test:(a)=>{let V=oku(y,h);return _wu.default(V,{dot:!0})(a)}},t=Dwu(l).map(v),$=Dwu(r).map(v);return function(a){if(typeof a!=="string")return!1;if(/\0/.test(a))return!1;let V=a.split(mwu).join("/");for(let Q=0;Q<$.length;++Q)if($[Q].test(V))return!1;for(let Q=0;Q<t.length;++Q)if(t[Q].test(V))return!0;return!t.length}},dku="break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public",uSu="arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl",lSu=new Set(`${dku} ${uSu}`.split(" "));lSu.add("");var sSu="13.3.0";Z2(p2.access);var nwu=Z2(p2.readFile),owu=Z2(p2.realpath),cp=Z2(p2.stat);async function xA(u){try{return(await cp(u)).isFile()}catch{return!1}}async function Ep(u){return await xA(u)?owu(u):u}var dwu=(u)=>{if(u.code==="ENOENT")return!1;throw u},jp=(u)=>{let l=new Map,r=async(f,h)=>{if(l.has(f)===!1)l.set(f,u(f).catch((v)=>{throw l.delete(f),v}));try{let t=await l.get(f);return h(null,t)}catch(v){return h(v)}};return r.clear=()=>l.clear(),r},Dp=jp(async(u)=>{try{return(await cp(u)).isDirectory()}catch(l){return dwu(l)}}),mp=jp(async(u)=>{try{return(await cp(u)).isFile()}catch(l){return dwu(l)}}),_p=jp(nwu);function vSu(u){let l=[];if(u.customResolveOptions){let{customResolveOptions:r}=u;if(r.moduleDirectory)u.moduleDirectories=Array.isArray(r.moduleDirectory)?r.moduleDirectory:[r.moduleDirectory],l.push("node-resolve: The `customResolveOptions.moduleDirectory` option has been deprecated. Use `moduleDirectories`, which must be an array.");if(r.preserveSymlinks)throw Error("node-resolve: `customResolveOptions.preserveSymlinks` is no longer an option. We now always use the rollup `preserveSymlinks` option.");["basedir","package","extensions","includeCoreModules","readFile","isFile","isDirectory","realpath","packageFilter","pathFilter","paths","packageIterator"].forEach((f)=>{if(r[f])throw Error(`node-resolve: \`customResolveOptions.${f}\` is no longer an option. If you need this, please open an issue.`)})}return{warnings:l}}function u9u(u){if(u.startsWith(".")||u.startsWith("/"))return null;let l=u.split("/");if(l[0][0]==="@")return`${l[0]}/${l[1]}`;return l[0]}function tSu(u){let l;if(u.mainFields)({mainFields:l}=u);else l=["module","main"];if(u.browser&&l.indexOf("browser")===-1)return["browser"].concat(l);if(!l.length)throw Error("Please ensure at least one `mainFields` value is specified");return l}function l9u(u){let{cache:l,extensions:r,pkg:f,mainFields:h,preserveSymlinks:v,useBrowserOverrides:t,rootDir:$,ignoreSideEffectsForRoot:y}=u,{pkgPath:a}=u;if(l.has(a))return l.get(a);if(!v)a=hSu(a);let V=Tp(a),Q={packageJson:{...f},packageJsonPath:a,root:V,resolvedMainField:"main",browserMappedMain:!1,resolvedEntryPoint:""},A=!1;for(let W=0;W<h.length;W++){let m=h[W];if(typeof f[m]==="string"){f.main=f[m],Q.resolvedMainField=m,A=!0;break}}let C={cachedPkg:f,hasModuleSideEffects:()=>null,hasPackageEntry:A!==!1||h.indexOf("main")!==-1,packageBrowserField:t&&typeof f.browser==="object"&&Object.keys(f.browser).reduce((W,m)=>{let E=f.browser[m];if(E&&E[0]===".")E=U2(V,E);if(W[m]=E,m[0]==="."){let _=U2(V,m);if(W[_]=E,!rSu(m))r.reduce((k,fu)=>{return k[_+fu]=k[m],k},W)}return W},{}),packageInfo:Q},G=C.packageBrowserField;if(t&&typeof f.browser==="object"&&G.hasOwnProperty(f.main))Q.resolvedEntryPoint=G[f.main],Q.browserMappedMain=!0;else Q.resolvedEntryPoint=U2(V,f.main||"index.js"),Q.browserMappedMain=!1;if(!y||$!==V){let W=f.sideEffects;if(typeof W==="boolean")C.hasModuleSideEffects=()=>W;else if(Array.isArray(W)){let m=W.map((E)=>{if(E.includes("/"))return E;return`**/${E}`});C.hasModuleSideEffects=Fwu(m,null,{resolve:V})}}return l.set(a,C),C}function wSu(u){if(Array.isArray(u))return u;else if(typeof u==="object")return Object.values(u);return[u]}function qSu(u,l){return l.some((r)=>u.endsWith(r))}async function r9u(u,l){let{root:r}=zp.parse(u),f=u;while(f!==r&&!qSu(f,l)){let h=zp.join(f,"package.json");if(await xA(h)){let v=p2.readFileSync(h,"utf-8");return{pkgJson:JSON.parse(v),pkgPath:f,pkgJsonPath:h}}f=zp.resolve(f,"..")}return null}function $Su(u){try{return!!new URL(u)}catch(l){return!1}}function f9u(u){return typeof u==="object"&&Object.keys(u).every((l)=>!l.startsWith("."))}function Swu(u){return typeof u==="object"&&!f9u(u)}function PSu(u){let l=Object.keys(u);return l.some((r)=>r.startsWith("."))&&l.some((r)=>!r.startsWith("."))}function i9u(u,l){return`Could not resolve import "${u}" in ${l}`}function Fp(u,l,r){let{importSpecifier:f,importer:h,pkgJsonPath:v}=u;return`${i9u(f,h)} using ${r?"imports":"exports"} defined in ${v}.${l?` ${l}`:""}`}class y7 extends Error{}class h9u extends y7{constructor(u,l){super(Fp(u,`Invalid "exports" field. ${l}`))}}class Ov extends y7{constructor(u,l,r){super(Fp(u,r,l))}}class H2 extends y7{constructor(u,l){super(Fp(u,l))}}function Nwu(u,l){return u.split("/").slice(1).some((r)=>[".","..",...l].includes(r))}async function B2(u,{target:l,subpath:r,pattern:f,internal:h}){if(typeof l==="string"){if(!f&&r.length>0&&!l.endsWith("/"))throw new Ov(u);if(!l.startsWith("./")){if(h&&!["/","../"].some((t)=>l.startsWith(t))&&!$Su(l)){if(f){let $=await u.resolveId(l.replace(/\*/g,r),u.pkgURL.href);return $?KA($.location).href:null}let t=await u.resolveId(`${l}${r}`,u.pkgURL.href);return t?KA(t.location).href:null}throw new H2(u,`Invalid mapping: "${l}".`)}if(Nwu(l,u.moduleDirs))throw new H2(u,`Invalid mapping: "${l}".`);let v=new URL(l,u.pkgURL);if(!v.href.startsWith(u.pkgURL.href))throw new H2(u,`Resolved to ${v.href} which is outside package ${u.pkgURL.href}`);if(Nwu(r,u.moduleDirs))throw new Ov(u);if(f)return v.href.replace(/\*/g,r);return new URL(r,v).href}if(Array.isArray(l)){let v;for(let t of l)try{let $=await B2(u,{target:t,subpath:r,pattern:f,internal:h});if($!==void 0)return $}catch($){if(!($ instanceof H2))throw $;else v=$}if(v)throw v;return null}if(l&&typeof l==="object"){for(let[v,t]of Object.entries(l))if(v==="default"||u.conditions.includes(v)){let $=await B2(u,{target:t,subpath:r,pattern:f,internal:h});if($!==void 0)return $}return}if(l===null)return null;throw new H2(u,"Invalid exports field.")}async function s9u(u,{matchKey:l,matchObj:r,internal:f}){if(!l.endsWith("*")&&l in r){let v=r[l];return await B2(u,{target:v,subpath:"",internal:f})}let h=Object.keys(r).filter((v)=>v.endsWith("/")||v.endsWith("*")).sort((v,t)=>t.length-v.length);for(let v of h){let t=v.substring(0,v.length-1);if(v.endsWith("*")&&l.startsWith(t)){let $=r[v],y=l.substring(v.length-1);return await B2(u,{target:$,subpath:y,pattern:!0,internal:f})}if(l.startsWith(v)){let $=r[v],y=l.substring(v.length);return await B2(u,{target:$,subpath:y,internal:f})}}throw new Ov(u,f)}async function RSu(u,l,r){if(PSu(r))throw new h9u(u,"All keys must either start with ./, or without one.");if(l==="."){let f;if(typeof r==="string"||Array.isArray(r)||f9u(r))f=r;else if(Swu(r))f=r["."];if(f){let h=await B2(u,{target:f,subpath:""});if(h)return h}}else if(Swu(r)){let f=await s9u(u,{matchKey:l,matchObj:r});if(f)return f}throw new Ov(u)}async function ySu({importSpecifier:u,importer:l,moduleDirs:r,conditions:f,resolveId:h}){let v=await r9u(l,r);if(!v)throw Error(i9u(". Could not find a parent package.json."));let{pkgPath:t,pkgJsonPath:$,pkgJson:y}=v,a=KA(`${t}/`),V={importer:l,importSpecifier:u,moduleDirs:r,pkgURL:a,pkgJsonPath:$,conditions:f,resolveId:h},{imports:Q}=y;if(!Q)throw new Ov(V,!0);if(u==="#"||u.startsWith("#/"))throw new Ov(V,!0,"Invalid import specifier.");return s9u(V,{matchKey:u,matchObj:Q,internal:!0})}var v9u=Z2(ewu.default),ASu=Z2(p2.readFile);async function aSu(u,l,r,f){if(u){let h=await r9u(u,f);if(h&&h.pkgJson.name===l)return h}try{let h=await v9u(`${l}/package.json`,r),v=JSON.parse(await ASu(h,"utf-8"));return{pkgJsonPath:h,pkgJson:v,pkgPath:Tp(h)}}catch(h){return null}}async function t9u({importSpecifier:u,packageInfoCache:l,extensions:r,mainFields:f,preserveSymlinks:h,useBrowserOverrides:v,baseDir:t,moduleDirectories:$,rootDir:y,ignoreSideEffectsForRoot:a}){let V=()=>null,Q=!0,A=!1,C,W={basedir:t,readFile:_p,isFile:mp,isDirectory:Dp,extensions:r,includeCoreModules:!1,moduleDirectory:$,preserveSymlinks:h,packageFilter:(E,_)=>{let k=l9u({cache:l,extensions:r,pkg:E,pkgPath:_,mainFields:f,preserveSymlinks:h,useBrowserOverrides:v,rootDir:y,ignoreSideEffectsForRoot:a});return{packageInfo:C,hasModuleSideEffects:V,hasPackageEntry:Q,packageBrowserField:A}=k,k.cachedPkg}},m;try{m=await v9u(u,W)}catch(E){if(E.code!=="MODULE_NOT_FOUND")throw E;return null}return{location:h?m:await Ep(m),hasModuleSideEffects:V,hasPackageEntry:Q,packageBrowserField:A,packageInfo:C}}async function MSu({importer:u,importSpecifier:l,exportConditions:r,packageInfoCache:f,extensions:h,mainFields:v,preserveSymlinks:t,useBrowserOverrides:$,baseDir:y,moduleDirectories:a,rootDir:V,ignoreSideEffectsForRoot:Q}){if(l.startsWith("#")){let C=await ySu({importSpecifier:l,importer:u,moduleDirs:a,conditions:r,resolveId(W){return t9u({importSpecifier:W,packageInfoCache:f,extensions:h,mainFields:v,preserveSymlinks:t,useBrowserOverrides:$,baseDir:y,moduleDirectories:a})}}),G=kwu(C);return{location:t?G:await Ep(G),hasModuleSideEffects:()=>null,hasPackageEntry:!0,packageBrowserField:!1,packageInfo:void 0}}let A=u9u(l);if(A){let C=()=>null,G=!0,W=!1,m,k=await aSu(u,A,{basedir:y,readFile:_p,isFile:mp,isDirectory:Dp,extensions:h,includeCoreModules:!1,moduleDirectory:a,preserveSymlinks:t,packageFilter:(fu,uu)=>{let qu=l9u({cache:f,extensions:h,pkg:fu,pkgPath:uu,mainFields:v,preserveSymlinks:t,useBrowserOverrides:$,rootDir:V,ignoreSideEffectsForRoot:Q});return{packageInfo:m,hasModuleSideEffects:C,hasPackageEntry:G,packageBrowserField:W}=qu,qu.cachedPkg}},a);if(k&&k.pkgJson.exports){let{pkgJson:fu,pkgJsonPath:uu}=k,qu=A===l?".":`.${l.substring(A.length)}`,iu=uu.replace("package.json",""),U=KA(iu),I=await RSu({importer:u,importSpecifier:l,moduleDirs:a,pkgURL:U,pkgJsonPath:uu,conditions:r},qu,fu.exports),J=kwu(I);if(J)return{location:t?J:await Ep(J),hasModuleSideEffects:C,hasPackageEntry:G,packageBrowserField:W,packageInfo:m}}}return null}async function CSu({importer:u,importSpecifierList:l,exportConditions:r,warn:f,packageInfoCache:h,extensions:v,mainFields:t,preserveSymlinks:$,useBrowserOverrides:y,baseDir:a,moduleDirectories:V,rootDir:Q,ignoreSideEffectsForRoot:A}){for(let C=0;C<l.length;C++){let G=await t9u({importer:u,importSpecifier:l[C],exportConditions:r,warn:f,packageInfoCache:h,extensions:v,mainFields:t,preserveSymlinks:$,useBrowserOverrides:y,baseDir:a,moduleDirectories:V,rootDir:Q,ignoreSideEffectsForRoot:A});if(G)return G}return null}async function LSu({importer:u,importSpecifierList:l,exportConditions:r,warn:f,packageInfoCache:h,extensions:v,mainFields:t,preserveSymlinks:$,useBrowserOverrides:y,baseDir:a,moduleDirectories:V,rootDir:Q,ignoreSideEffectsForRoot:A}){try{let C=await MSu({importer:u,importSpecifier:l[0],exportConditions:r,packageInfoCache:h,extensions:v,mainFields:t,preserveSymlinks:$,useBrowserOverrides:y,baseDir:a,moduleDirectories:V,rootDir:Q,ignoreSideEffectsForRoot:A});if(C)return C}catch(C){if(C instanceof y7)return f(C),null;throw C}return CSu({importer:u,importSpecifierList:l,exportConditions:r,warn:f,packageInfoCache:h,extensions:v,mainFields:t,preserveSymlinks:$,useBrowserOverrides:y,baseDir:a,moduleDirectories:V,rootDir:Q,ignoreSideEffectsForRoot:A})}var gA="\x00node-resolve:empty.js",w9u=(u)=>{Object.freeze(u);for(let l of Object.values(u))if(typeof l==="object"&&!Object.isFrozen(l))w9u(l);return u},q9u=["default","module"],VSu=[...q9u,"import"],HSu=[...q9u,"require"],$9u={dedupe:[],extensions:[".mjs",".js",".json",".node"],resolveOnly:[],moduleDirectories:["node_modules"],ignoreSideEffectsForRoot:!1},NZl=w9u(Kwu.default({},$9u));function P9u(u={}){let{warnings:l}=vSu(u),r={...$9u,...u},{extensions:f,jail:h,moduleDirectories:v,ignoreSideEffectsForRoot:t}=r,$=[...VSu,...r.exportConditions||[]],y=[...HSu,...r.exportConditions||[]],a=new Map,V=new Map,Q=tSu(r),A=Q.indexOf("browser")!==-1,C=r.preferBuiltins===!0||r.preferBuiltins===!1,G=C?r.preferBuiltins:!0,W=U2(r.rootDir||process.cwd()),{dedupe:m}=r,E;if(typeof m!=="function")m=(iu)=>r.dedupe.includes(iu)||r.dedupe.includes(u9u(iu));let _=(iu)=>{let U=iu.map((X)=>{if(X instanceof RegExp)return X;let I=X.replace(/[\\^$*+?.()|[\]{}]/g,"\\$&");return new RegExp(`^${I}$`)});return(X)=>!U.length||U.some((I)=>I.test(X))},k=typeof r.resolveOnly==="function"?r.resolveOnly:_(r.resolveOnly),fu=new Map,uu,qu=async(iu,U,X,I)=>{let[J,d]=U.split("?"),hu=`${d?`?${d}`:""}`;U=J;let ru=!X||m(U)?W:Tp(X),D=fu.get(X);if(A&&D){let Mu=U2(ru,U);if(D[U]===!1||D[Mu]===!1)return{id:gA};let ju=U[0]!=="."&&D[U]||D[Mu]||D[`${Mu}.js`]||D[`${Mu}.json`];if(ju)U=ju}let N=U.split(/[/\\]/),Bu=N.shift(),bu=!1;if(Bu[0]==="@"&&N.length>0)Bu+=`/${N.shift()}`;else if(Bu[0]===".")Bu=U2(ru,U),bu=!0;if(!bu&&!k(Bu)){if(wSu(E.input).includes(U))return null;return!1}let nu=[U];if(X===void 0&&!U[0].match(/^\.?\.?\//))nu.push(`./${U}`);if(X&&U.endsWith(".js")){for(let Mu of[".ts",".tsx"])if(X.endsWith(Mu)&&f.includes(Mu))nu.push(U.replace(/.js$/,Mu))}let cu=(...Mu)=>iu.warn(...Mu),rl=I&&I["node-resolve"]&&I["node-resolve"].isRequire?y:$;if(A&&!rl.includes("browser"))rl.push("browser");let Ul=await LSu({importer:X,importSpecifierList:nu,exportConditions:rl,warn:cu,packageInfoCache:a,extensions:f,mainFields:Q,preserveSymlinks:uu,useBrowserOverrides:A,baseDir:ru,moduleDirectories:v,rootDir:W,ignoreSideEffectsForRoot:t}),Bl=gwu.default(U),_u=Bl&&G?{packageInfo:void 0,hasModuleSideEffects:()=>null,hasPackageEntry:!0,packageBrowserField:!1}:Ul;if(!_u)return null;let{packageInfo:Wu,hasModuleSideEffects:Hl,hasPackageEntry:du,packageBrowserField:Vu}=_u,{location:Ju}=_u;if(Vu){if(Object.prototype.hasOwnProperty.call(Vu,Ju)){if(!Vu[Ju])return fu.set(Ju,Vu),{id:gA};Ju=Vu[Ju]}fu.set(Ju,Vu)}if(du&&!uu){if(await xA(Ju))Ju=await owu(Ju)}if(V.set(Ju,Wu),du){if(Bl&&G){if(!C&&Ul&&_u!==U)iu.warn(`preferring built-in module '${U}' over local alternative at '${Ul.location}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`);return!1}else if(h&&Ju.indexOf(fSu(h.trim(iSu)))!==0)return null}if(r.modulesOnly&&await xA(Ju)){let Mu=await nwu(Ju,"utf-8");if(xwu.default(Mu))return{id:`${Ju}${hu}`,moduleSideEffects:Hl(Ju)};return null}return{id:`${Ju}${hu}`,moduleSideEffects:Hl(Ju)}};return{name:"node-resolve",version:sSu,buildStart(iu){E=iu;for(let U of l)this.warn(U);({preserveSymlinks:uu}=iu)},generateBundle(){_p.clear(),mp.clear(),Dp.clear()},async resolveId(iu,U,X){if(iu===gA)return iu;if(/\0/.test(iu))return null;if(/\0/.test(U))U=void 0;let I=await qu(this,iu,U,X.custom);if(I){let J=await this.resolve(I.id,U,Object.assign({skipSelf:!0},X));if(J){if(J.external)return!1;if(J.id!==I.id)return J;return{...I,meta:J.meta}}}return I},load(iu){if(iu===gA)return"export default {};";return null},getPackageInfoForId(iu){return V.get(iu)}}}l7u();var oau=di(D7u(),1);var Rou={"prop-unknown-type":"Props without inferred types","context-any-type":"Context values typed as `any`","event-no-source":"@event tags with no dispatch or callback","example-compile-error":"@example blocks that failed to compile"},you=["prop-unknown-type","context-any-type","event-no-source","example-compile-error"];function qM(u){let l=new Set,r=[];for(let f of u){let h=`${f.component}:${f.kind}:${f.name}`;if(l.has(h))continue;l.add(h),r.push(f)}return r}function $M(u){if(u.length===0)return"sveld: all types resolved.";let l=[],r=u.length;l.push(`sveld: ${r} unresolved type${r===1?"":"s"} found.`);for(let f of you){let h=u.filter((t)=>t.kind===f);if(h.length===0)continue;l.push(""),l.push(`${Rou[f]} (${h.length}):`);let v=new Map;for(let t of h){let $=v.get(t.component)??[];$.push(t),v.set(t.component,$)}for(let[t,$]of v){l.push(` ${t}`);for(let y of $)l.push(` - ${y.message}`)}}return l.join(`
|
|
615
615
|
`)}import{existsSync as F7u,readFileSync as Aou}from"node:fs";import{join as k7u}from"node:path";function xb(u){return u}function ps(u){if(u==="")return u;return u.startsWith(".")?u:`./${u}`}function rw(u){return typeof u==="object"&&u!==null}function m7u(u){if(!rw(u))return{};let l=u.svelte;return typeof l==="string"?{svelte:l}:{}}function _7u(u){if(!rw(u))return{};let l={};if(typeof u.extends==="string")l.extends=u.extends;if(rw(u.compilerOptions)){let r={};if(typeof u.compilerOptions.baseUrl==="string")r.baseUrl=u.compilerOptions.baseUrl;if(rw(u.compilerOptions.paths)){let f={};for(let[h,v]of Object.entries(u.compilerOptions.paths))if(Array.isArray(v)&&v.every((t)=>typeof t==="string"))f[h]=v;if(Object.keys(f).length>0)r.paths=f}if(Object.keys(r).length>0)l.compilerOptions=r}return l}function fw(u){if(u){let r=k7u(process.cwd(),u);if(F7u(r))return xb(u);return console.log(`Invalid entry point: ${r}.`),null}let l=k7u(process.cwd(),"package.json");if(!F7u(l))return console.log(`Could not locate a package.json file.
|
|
616
616
|
`),null;try{let r=m7u(JSON.parse(Aou(l,"utf-8")));if(r.svelte?.trim())return xb(r.svelte);return console.log(`Could not determine an entry point.
|
|
@@ -754,4 +754,4 @@ ${HC({typedefs:l.typedefs})}
|
|
|
754
754
|
|
|
755
755
|
`),this}append(u,l){switch(u){case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":{let r=Number(u.slice(-1));if(this.sourceParts.push(`${"#".repeat(r)} ${l}`),this.hasToC&&u==="h2")this.toc.push({array:Array.from({length:(r-1)*2}),raw:l??""});break}case"quote":this.sourceParts.push(`> ${l}`);break;case"p":this.sourceParts.push(l??"");break;case"divider":this.sourceParts.push("---");break;case"raw":this.sourceParts.push(l??"");break}if(u!=="raw")this.appendLineBreaks();return this}tableOfContents(){return this.sourceParts.push("<!-- __TOC__ -->"),this.hasToC=!0,this.appendLineBreaks(),this}end(){return this.sourceParts.join("").replace("<!-- __TOC__ -->",this.toc.map(({array:l,raw:r})=>{return`${l.join(" ")} - [${r}](#${r.toLowerCase().replace(KY,"").replace(UC,"-")})`}).join(`
|
|
756
756
|
`))}}class bC extends Vw{onAppend;markdownBase;constructor(u){super({parser:"markdown",printWidth:80});this.onAppend=u.onAppend,this.markdownBase=new eY}get source(){return this.markdownBase.source}get hasToC(){return this.markdownBase.hasToC}get toc(){return this.markdownBase.toc}appendLineBreaks(){return this.markdownBase.appendLineBreaks(),this}append(u,l){return this.markdownBase.append(u,l),this.onAppend?.call(this,u,this),this}tableOfContents(){return this.markdownBase.tableOfContents(),this}end(){return this.markdownBase.end()}}async function nY(u,l){let r=l?.write!==!1,f=new bC({onAppend:(h,v)=>{l.onAppend?.call(null,h,v,u)}});if(Nau(f,u,l.entryExports),r){let h=lsl(process.cwd(),l.outFile);await f.write(h,f.end()),console.log(`created "${l.outFile}".`)}return f.end()}import{join as eau}from"node:path";var gau=/\.svelte$/;function Kau(u){let l=new Map;for(let[f,h]of Object.entries(u)){let v=l.get(h.source)||[];v.push({id:f,exportee:h}),l.set(h.source,v)}let r=[];for(let[f,h]of l){let v=gau.test(f),t=h.some(({id:A,exportee:C})=>A!=="default"&&C.default),$=h.some(({exportee:A})=>!A.default),y=v&&t&&$,a=[],V=[],Q=[];for(let{id:A,exportee:C}of h){if(A==="default"){V.push(`export { default } from "${f}";`);continue}if(C.default)if(C.mixed)V.push(`export { default as ${A} } from "${f}";`),V.push(`export { default } from "${f}";`);else Q.push(`default as ${A}`);else if(v&&!y)Q.push(`default as ${A}`);else a.push(A)}if(Q.length>0&&a.length>0)r.push(`export { ${[...Q,...a].join(", ")} } from "${f}";`);else{if(a.length>0)r.push(`export { ${a.join(", ")} } from "${f}";`);if(Q.length>0)r.push(`export { ${Q.join(", ")} } from "${f}";`)}r.push(...V)}return r.join(`
|
|
757
|
-
`)}function xau(u){return u.replace(gau,".svelte.d.ts")}async function oY(u,l){let r=eau(process.cwd(),l.outDir,"index.d.ts"),f=Jau(l.printWidth),h=l.preamble+Kau(l.exports),t=Zh(u).components.map(async($)=>{let y=xau(eau(l.outDir,$.filePath));await f.write(y,gY($))});await Promise.all([...t,f.write(r,h)]),console.log("created TypeScript definitions.")}j$({name:"json",componentSet:"exported",write:FY});j$({name:"markdown",componentSet:"exported",write:nY});j$({name:"types",componentSet:"all",write:oY});var fsl=50,isl=/\.svelte$/;function nau(u){let l=u?.watch===!0,r,f,h=null,v,t=new Set,$=async()=>{if(h==null||f==null||t.size===0)return;let a=Array.from(t);t.clear();try{let{result:V}=await h.update(a);ht(V,u||{},f)}catch(V){console.error("sveld: failed to regenerate types in watch mode:",V)}},y=(a)=>{if(!l||h==null||!isl.test(a))return;t.add(a),clearTimeout(v),v=setTimeout($,fsl)};return{name:"vite-plugin-sveld",apply:l?void 0:"build",enforce:"post",async buildStart(){if(f=fw(u?.entry),l&&f!=null)h=await Yau(f,u?.glob===!0,u?.documentExports===!0),ht(h.result,u||{},f)},async generateBundle(){if(l)return;if(f!=null)r=await it(f,u?.glob===!0,ft(u))},writeBundle(){if(l)return;if(f!=null)ht(r,u||{},f)},handleHotUpdate(a){y(a.file)},watchChange(a){y(a)}}}function dY(u,l,r){let f=yC(u);if(!f)throw Error(`sveld: built-in writer "${u}" is not registered.`);return f.write(l,r)}function ht(u,l,r){let f=rsl(r);if(l?.types!==!1)dY("types",u.allComponentsForTypes,{outDir:"types",preamble:"",...l?.typesOptions,exports:u.exports,inputDir:f});if(l?.json)dY("json",u.components,{outFile:"COMPONENT_API.json",...l?.jsonOptions,input:r,inputDir:f,entryExports:u.entryExports});if(l?.markdown)dY("markdown",u.components,{outFile:"COMPONENT_INDEX.md",...l?.markdownOptions,entryExports:u.entryExports});for(let[h,v]of Object.entries(l?.additionalWriters??{})){let t=yC(h);if(!t){console.warn(`sveld: no writer registered with name "${h}"; skipping.`);continue}let $=t.componentSet==="all"?u.allComponentsForTypes:u.components;t.write($,v)}}function hsl(u){if(!u.startsWith("--"))return{};let l=u.indexOf("="),r=l===-1?u.slice(2):u.slice(2,l),f=l===-1?!0:u.slice(l+1);switch(r){case"glob":case"types":case"json":case"markdown":case"strict":case"resolveTypes":case"checkExamples":return{[r]:f===!0||f==="true"};case"fail-fast":return{failFast:f===!0||f==="true"};case"entry":return typeof f==="string"?{entry:f}:{};case"cache":if(f==="false")return{cache:!1};return{cache:typeof f==="string"?f:!0};case"check":if(f==="false")return{check:!1};return{check:typeof f==="string"?f:!0};default:return{}}}function ssl(u){if(typeof u.check==="string")return u.check;return u.jsonOptions?.outFile??"COMPONENT_API.json"}function vsl(u){let l={};for(let r of u)Object.assign(l,hsl(r));return l}async function tsl(u){let l=vsl(u.argv.slice(2)),r=await PM(),f=RM(r,l),h=fw(f.entry)||"src/index.js";await(await Tb({input:h,plugins:[oau.default(),P9u()]})).generate({});let t=await it(h,f.glob===!0,ft(f)),$;if(f.check)$=await Cp(t.components,ssl(f),{entryExports:t.entryExports});ht(t,f,h);let{diagnostics:y}=t;if(console.
|
|
757
|
+
`)}function xau(u){return u.replace(gau,".svelte.d.ts")}async function oY(u,l){let r=eau(process.cwd(),l.outDir,"index.d.ts"),f=Jau(l.printWidth),h=l.preamble+Kau(l.exports),t=Zh(u).components.map(async($)=>{let y=xau(eau(l.outDir,$.filePath));await f.write(y,gY($))});await Promise.all([...t,f.write(r,h)]),console.log("created TypeScript definitions.")}j$({name:"json",componentSet:"exported",write:FY});j$({name:"markdown",componentSet:"exported",write:nY});j$({name:"types",componentSet:"all",write:oY});var fsl=50,isl=/\.svelte$/;function nau(u){let l=u?.watch===!0,r,f,h=null,v,t=new Set,$=async()=>{if(h==null||f==null||t.size===0)return;let a=Array.from(t);t.clear();try{let{result:V}=await h.update(a);ht(V,u||{},f)}catch(V){console.error("sveld: failed to regenerate types in watch mode:",V)}},y=(a)=>{if(!l||h==null||!isl.test(a))return;t.add(a),clearTimeout(v),v=setTimeout($,fsl)};return{name:"vite-plugin-sveld",apply:l?void 0:"build",enforce:"post",async buildStart(){if(f=fw(u?.entry),l&&f!=null)h=await Yau(f,u?.glob===!0,u?.documentExports===!0),ht(h.result,u||{},f)},async generateBundle(){if(l)return;if(f!=null)r=await it(f,u?.glob===!0,ft(u))},writeBundle(){if(l)return;if(f!=null)ht(r,u||{},f)},handleHotUpdate(a){y(a.file)},watchChange(a){y(a)}}}function dY(u,l,r){let f=yC(u);if(!f)throw Error(`sveld: built-in writer "${u}" is not registered.`);return f.write(l,r)}function ht(u,l,r){let f=rsl(r);if(l?.types!==!1)dY("types",u.allComponentsForTypes,{outDir:"types",preamble:"",...l?.typesOptions,exports:u.exports,inputDir:f});if(l?.json)dY("json",u.components,{outFile:"COMPONENT_API.json",...l?.jsonOptions,input:r,inputDir:f,entryExports:u.entryExports});if(l?.markdown)dY("markdown",u.components,{outFile:"COMPONENT_INDEX.md",...l?.markdownOptions,entryExports:u.entryExports});for(let[h,v]of Object.entries(l?.additionalWriters??{})){let t=yC(h);if(!t){console.warn(`sveld: no writer registered with name "${h}"; skipping.`);continue}let $=t.componentSet==="all"?u.allComponentsForTypes:u.components;t.write($,v)}}function hsl(u){if(!u.startsWith("--"))return{};let l=u.indexOf("="),r=l===-1?u.slice(2):u.slice(2,l),f=l===-1?!0:u.slice(l+1);switch(r){case"glob":case"types":case"json":case"markdown":return{[r]:f===!0||f==="true"};case"strict":return{strict:f===!0||f==="true"};case"report-diagnostics":return{reportDiagnostics:f===!0||f==="true"};case"resolveTypes":case"checkExamples":return{[r]:f===!0||f==="true"};case"fail-fast":return{failFast:f===!0||f==="true"};case"entry":return typeof f==="string"?{entry:f}:{};case"cache":if(f==="false")return{cache:!1};return{cache:typeof f==="string"?f:!0};case"check":if(f==="false")return{check:!1};return{check:typeof f==="string"?f:!0};default:return{}}}function ssl(u){if(typeof u.check==="string")return u.check;return u.jsonOptions?.outFile??"COMPONENT_API.json"}function vsl(u){let l={};for(let r of u)Object.assign(l,hsl(r));return l}async function tsl(u){let l=vsl(u.argv.slice(2)),r=await PM(),f=RM(r,l),h=fw(f.entry)||"src/index.js";await(await Tb({input:h,plugins:[oau.default(),P9u()]})).generate({});let t=await it(h,f.glob===!0,ft(f)),$;if(f.check)$=await Cp(t.components,ssl(f),{entryExports:t.entryExports});ht(t,f,h);let{diagnostics:y}=t;if((f.reportDiagnostics||f.strict)&&y.length>0)console.error($M(y));if($){if(console.log(Lp($)),$.bump==="major")u.exitCode=1}if(f.strict&&y.length>0)u.exitCode=1}async function wsl(u){let{input:l,strict:r,reportDiagnostics:f,...h}=u??{},v=await PM(),t=fw(l??v.entry);if(t===null)return{diagnostics:[]};let $=RM(v,h,{entry:t}),y=await it(t,$.glob===!0,ft($));ht(y,$,t);let{diagnostics:a}=y;if((f||r)&&a.length>0)console.warn($M(a));if(r&&a.length>0)process.exitCode=1;return{diagnostics:a}}export{wsl as sveld,Cp as runCheck,j$ as registerWriter,ahl as listWriters,yC as getWriter,Lp as formatCheckReport,G2u as diffApiDocuments,Vou as defineConfig,nau as default,tsl as cli,Zh as buildComponentApiDocument,Kr as ComponentParser};
|
package/lib/sveld.d.ts
CHANGED
|
@@ -8,7 +8,12 @@ interface SveldOptions extends Omit<PluginSveldOptions, "entry"> {
|
|
|
8
8
|
*/
|
|
9
9
|
input?: string;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Print unresolved-type diagnostics to stderr. Default `false`.
|
|
12
|
+
*/
|
|
13
|
+
reportDiagnostics?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Exit with code 1 when diagnostics are present. Implies `reportDiagnostics`.
|
|
16
|
+
* Default `false`.
|
|
12
17
|
*/
|
|
13
18
|
strict?: boolean;
|
|
14
19
|
}
|