sveld 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -0
- package/lib/ComponentParser.d.ts +5 -2
- package/lib/bundle.d.ts +17 -1
- package/lib/check.d.ts +37 -0
- package/lib/cli.d.ts +7 -0
- package/lib/dependency-graph.d.ts +20 -0
- package/lib/diagnostics.d.ts +2 -1
- package/lib/example-check.d.ts +22 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +670 -664
- package/lib/parse-cache.d.ts +28 -0
- package/lib/plugin.d.ts +11 -4
- package/lib/resolve-types.d.ts +23 -0
- package/lib/writer/built-in-writers.d.ts +1 -0
- package/lib/writer/document-model.d.ts +34 -0
- package/lib/writer/registry.d.ts +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ParsedComponent } from "./ComponentParser";
|
|
2
|
+
/** Default on-disk location for the persistent parse cache, relative to the project root. */
|
|
3
|
+
export declare const DEFAULT_CACHE_FILE: string;
|
|
4
|
+
/** Resolves the effective cache file path for `cache: true | string`. */
|
|
5
|
+
export declare function resolveCacheFilePath(rootDir: string, cache: boolean | string): string;
|
|
6
|
+
export declare function hashSource(source: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Cross-run parse cache. Entries match on file path and sha256 of source.
|
|
9
|
+
* Symbol-keyed TypeScript metadata is stored separately because JSON drops symbols.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ParseCache {
|
|
12
|
+
private readonly cacheFilePath;
|
|
13
|
+
private readonly file;
|
|
14
|
+
private readonly next;
|
|
15
|
+
/** Paths forced to miss this run (e.g. dependents of a changed `@extends` target). */
|
|
16
|
+
private readonly blocked;
|
|
17
|
+
constructor(cacheFilePath: string);
|
|
18
|
+
/** True when `get()` would return a hit for `resolvedPath` and `hash`. */
|
|
19
|
+
has(resolvedPath: string, hash: string): boolean;
|
|
20
|
+
/** Returns the cached parse for `resolvedPath` when its content hash still matches. */
|
|
21
|
+
get(resolvedPath: string, hash: string): ParsedComponent | null;
|
|
22
|
+
/** Records a freshly parsed component so it can be reused on a future run. */
|
|
23
|
+
set(resolvedPath: string, hash: string, parsed: ParsedComponent): void;
|
|
24
|
+
/** Skip cache for `resolvedPath` this run (e.g. an @extends dependent). */
|
|
25
|
+
invalidate(resolvedPath: string): void;
|
|
26
|
+
/** Persists this run's cache entries back to disk. */
|
|
27
|
+
save(): void;
|
|
28
|
+
}
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type GenerateBundleOptions, type GenerateBundleResult } from "./bundle";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import "./writer/built-in-writers";
|
|
3
|
+
import type { WriteJsonOptions } from "./writer/writer-json";
|
|
4
|
+
import type { WriteMarkdownOptions } from "./writer/writer-markdown";
|
|
5
|
+
import type { WriteTsDefinitionsOptions } from "./writer/writer-ts-definitions";
|
|
5
6
|
export type { CollectedComponents, ComponentDocApi, ComponentDocs, ComponentParseError, GenerateBundleOptions, GenerateBundleResult, ResolveComponentFilePath, } from "./bundle";
|
|
6
7
|
export { collectComponents, collectSvelteFilePaths, generateBundle, processComponent, readFileMap, reportParseErrors, toGenerateBundleOptions, } from "./bundle";
|
|
7
|
-
export interface PluginSveldOptions extends Pick<GenerateBundleOptions, "resolveTypes"> {
|
|
8
|
+
export interface PluginSveldOptions extends Pick<GenerateBundleOptions, "resolveTypes" | "cache" | "checkExamples"> {
|
|
8
9
|
/**
|
|
9
10
|
* Specify the entry point to uncompiled Svelte source.
|
|
10
11
|
* If not provided, sveld will use the "svelte" field from package.json.
|
|
@@ -19,6 +20,12 @@ export interface PluginSveldOptions extends Pick<GenerateBundleOptions, "resolve
|
|
|
19
20
|
jsonOptions?: Partial<Omit<WriteJsonOptions, "inputDir">>;
|
|
20
21
|
markdown?: boolean;
|
|
21
22
|
markdownOptions?: Partial<WriteMarkdownOptions>;
|
|
23
|
+
/**
|
|
24
|
+
* Run additional, userland-registered writers (via `registerWriter` from
|
|
25
|
+
* "sveld") beyond the built-in `json`/`markdown`/`types` outputs. Keyed by
|
|
26
|
+
* the writer's registered `name`, valued by that writer's options.
|
|
27
|
+
*/
|
|
28
|
+
additionalWriters?: Record<string, unknown>;
|
|
22
29
|
/**
|
|
23
30
|
* Abort the entire run when a single component fails to parse.
|
|
24
31
|
* When `false` (the default), parse failures are collected as diagnostics
|
package/lib/resolve-types.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import type { ParsedComponentTypeScriptMetadata, ResolvedComponentProp } from "./ComponentParser";
|
|
2
|
+
import type { ExampleCheckSource } from "./example-check";
|
|
2
3
|
export interface ResolveTarget {
|
|
3
4
|
moduleName: string;
|
|
4
5
|
filePath: string;
|
|
5
6
|
metadata: ParsedComponentTypeScriptMetadata;
|
|
6
7
|
}
|
|
8
|
+
export interface ExampleCheckTarget {
|
|
9
|
+
moduleName: string;
|
|
10
|
+
filePath: string;
|
|
11
|
+
sources: ExampleCheckSource[];
|
|
12
|
+
}
|
|
13
|
+
/** One `@example` block that failed to type-check. */
|
|
14
|
+
export interface ExampleCheckDiagnostic {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
7
19
|
/**
|
|
8
20
|
* Expands opaque imported `$props()` types using the project's TypeScript program.
|
|
9
21
|
* Loaded only when `resolveTypes` is enabled.
|
|
@@ -21,9 +33,20 @@ export declare class TypeResolver {
|
|
|
21
33
|
static create(cwd?: string): Promise<TypeResolver | null>;
|
|
22
34
|
/** Resolves every target in one program snapshot. */
|
|
23
35
|
expandAll(targets: ResolveTarget[]): Promise<Map<string, ResolvedComponentProp[]>>;
|
|
36
|
+
/**
|
|
37
|
+
* Type-checks every `@example` block in one program snapshot.
|
|
38
|
+
*
|
|
39
|
+
* Each example gets its own virtual file: a `declare`-style binding for the
|
|
40
|
+
* documented symbol (typed as `any` end-to-end, so types sveld can't see
|
|
41
|
+
* never cause a false positive), then the example body. Catches renamed
|
|
42
|
+
* or removed symbols and wrong arity. Not full type checking; it does not
|
|
43
|
+
* depend on the rest of the component's types.
|
|
44
|
+
*/
|
|
45
|
+
checkExamples(targets: ExampleCheckTarget[]): Promise<Map<string, ExampleCheckDiagnostic[]>>;
|
|
24
46
|
/** Closes the TypeScript server process. */
|
|
25
47
|
dispose(): Promise<void>;
|
|
26
48
|
private resolveFile;
|
|
27
49
|
private createFileSystem;
|
|
28
50
|
private virtualFileName;
|
|
51
|
+
private exampleFileName;
|
|
29
52
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EntryExports } from "../parse-entry-exports";
|
|
2
|
+
import type { ComponentDocApi, ComponentDocs } from "../plugin";
|
|
3
|
+
export declare const COMPONENT_API_SCHEMA_VERSION = 1;
|
|
4
|
+
/**
|
|
5
|
+
* Canonical, renderer-agnostic representation of a component collection.
|
|
6
|
+
*
|
|
7
|
+
* Every writer (JSON, Markdown, TypeScript definitions) builds this document
|
|
8
|
+
* via `buildComponentApiDocument` instead of independently sorting/filtering
|
|
9
|
+
* the raw `ComponentDocs` map, so sort order and field stripping can't drift
|
|
10
|
+
* between output formats.
|
|
11
|
+
*/
|
|
12
|
+
export interface ComponentApiDocument {
|
|
13
|
+
schemaVersion: 1;
|
|
14
|
+
generator: {
|
|
15
|
+
name: string;
|
|
16
|
+
version: string;
|
|
17
|
+
svelteVersion: string;
|
|
18
|
+
};
|
|
19
|
+
total: number;
|
|
20
|
+
components: ComponentDocApi[];
|
|
21
|
+
/** Only when `documentExports` is on. */
|
|
22
|
+
totalExports?: number;
|
|
23
|
+
exports?: EntryExports;
|
|
24
|
+
}
|
|
25
|
+
export interface BuildComponentApiDocumentOptions {
|
|
26
|
+
/** Entry-barrel exports when `documentExports` is on. */
|
|
27
|
+
entryExports?: EntryExports;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Builds the canonical document for a component collection: components
|
|
31
|
+
* sorted alphabetically by `moduleName`, with the Node-only `diagnostics`
|
|
32
|
+
* field stripped.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildComponentApiDocument(components: ComponentDocs, options?: BuildComponentApiDocumentOptions): ComponentApiDocument;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComponentDocs } from "../plugin";
|
|
2
|
+
/** Which component set a writer expects: exported-only, or every discovered component. */
|
|
3
|
+
export type WriterComponentSet = "exported" | "all";
|
|
4
|
+
/**
|
|
5
|
+
* A pluggable output format. Built-in writers (`json`, `markdown`, `types`)
|
|
6
|
+
* register themselves under these names; third parties can `registerWriter`
|
|
7
|
+
* their own to add new output formats without a core PR.
|
|
8
|
+
*/
|
|
9
|
+
export interface OutputWriter<TOptions = unknown> {
|
|
10
|
+
name: string;
|
|
11
|
+
/** Which component set this writer expects. @default "exported" */
|
|
12
|
+
componentSet?: WriterComponentSet;
|
|
13
|
+
write(components: ComponentDocs, options: TOptions): Promise<unknown> | unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare function registerWriter<TOptions = unknown>(writer: OutputWriter<TOptions>): void;
|
|
16
|
+
export declare function getWriter(name: string): OutputWriter<unknown> | undefined;
|
|
17
|
+
export declare function listWriters(): OutputWriter<unknown>[];
|