sveld 0.32.8 → 0.33.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 +169 -3
- package/lib/ComponentParser.d.ts +86 -10
- package/lib/bundle.d.ts +140 -0
- package/lib/cli.d.ts +10 -1
- package/lib/diagnostics.d.ts +29 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +709 -684
- package/lib/load-config.d.ts +44 -0
- package/lib/parse-entry-exports.d.ts +30 -0
- package/lib/plugin.d.ts +27 -40
- package/lib/resolve-types.d.ts +29 -0
- package/lib/sveld.d.ts +13 -1
- package/lib/watch.d.ts +34 -0
- package/lib/writer/markdown-format-utils.d.ts +30 -1
- package/lib/writer/markdown-render-utils.d.ts +2 -1
- package/lib/writer/writer-json.d.ts +3 -0
- package/lib/writer/writer-markdown.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PluginSveldOptions } from "./plugin";
|
|
2
|
+
/**
|
|
3
|
+
* Public shape of a `sveld.config.{js,ts,mjs}` file. Identical to the options
|
|
4
|
+
* accepted by the Vite/Rollup plugin and the CLI.
|
|
5
|
+
*/
|
|
6
|
+
export type SveldConfig = PluginSveldOptions;
|
|
7
|
+
/** Config file names probed at the project root. First existing file wins. */
|
|
8
|
+
export declare const CONFIG_FILE_NAMES: readonly ["sveld.config.js", "sveld.config.mjs", "sveld.config.ts"];
|
|
9
|
+
/**
|
|
10
|
+
* Identity helper that fully types a `sveld` config object.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // sveld.config.js
|
|
15
|
+
* import { defineConfig } from "sveld";
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({
|
|
18
|
+
* glob: true,
|
|
19
|
+
* json: true,
|
|
20
|
+
* markdown: true,
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function defineConfig(config: SveldConfig): SveldConfig;
|
|
25
|
+
/** Locate a `sveld.config.{js,mjs,ts}` file in `cwd`, or `null` if none exists. */
|
|
26
|
+
export declare function resolveConfigPath(cwd?: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Load and validate a `sveld` config file by absolute path.
|
|
29
|
+
*
|
|
30
|
+
* The package is ESM-only, so the file is loaded via dynamic `import()`. A
|
|
31
|
+
* cache-busting query is appended so repeated loads (e.g. across tests or
|
|
32
|
+
* watch runs) reflect the latest contents.
|
|
33
|
+
*
|
|
34
|
+
* @throws if the module cannot be imported (e.g. a syntax error or a config
|
|
35
|
+
* that throws at evaluation time) or if it does not default-export an object.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadConfigFrom(configPath: string): Promise<SveldConfig>;
|
|
38
|
+
/**
|
|
39
|
+
* Discover and load a `sveld.config.{js,mjs,ts}` file from `cwd`.
|
|
40
|
+
* Returns an empty object when no config file is present.
|
|
41
|
+
*/
|
|
42
|
+
export declare function loadConfig(cwd?: string): Promise<SveldConfig>;
|
|
43
|
+
/** Shallow-merge option sources. Later sources override earlier ones. */
|
|
44
|
+
export declare function mergeConfig<T extends PluginSveldOptions = PluginSveldOptions>(...sources: Array<Partial<T> | undefined>): Partial<T>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** One named export from the entry barrel (not a `.svelte` component). */
|
|
2
|
+
export interface EntryExport {
|
|
3
|
+
name: string;
|
|
4
|
+
kind: "const" | "let" | "var" | "function" | "class" | "type" | "interface" | "enum";
|
|
5
|
+
/** Type text from the source, when present. */
|
|
6
|
+
type?: string;
|
|
7
|
+
/** Initializer text for simple constants. */
|
|
8
|
+
value?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Declaring module, relative to the entry file. */
|
|
11
|
+
source?: string;
|
|
12
|
+
isTypeOnly: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type EntryExports = EntryExport[];
|
|
15
|
+
/**
|
|
16
|
+
* List consts, functions, and types exported from an entry barrel.
|
|
17
|
+
*
|
|
18
|
+
* Follows re-exports with AST-only traversal. Skips `.svelte` files.
|
|
19
|
+
*
|
|
20
|
+
* @param entryFile - Absolute path to the entry module.
|
|
21
|
+
* @returns Exports deduplicated by name, sorted alphabetically.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // entry: export { VERSION } from "./constants"; export type { Theme } from "./types";
|
|
26
|
+
* parseEntryExports("/abs/src/index.ts");
|
|
27
|
+
* // [{ name: "Theme", kind: "type", isTypeOnly: true, ... }, { name: "VERSION", kind: "const", ... }]
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseEntryExports(entryFile: string): EntryExports;
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,67 +1,55 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type ParsedComponent } from "./ComponentParser";
|
|
3
|
-
import { type ParsedExports } from "./parse-exports";
|
|
1
|
+
import { type GenerateBundleOptions, type GenerateBundleResult } from "./bundle";
|
|
4
2
|
import { type WriteJsonOptions } from "./writer/writer-json";
|
|
5
3
|
import { type WriteMarkdownOptions } from "./writer/writer-markdown";
|
|
6
4
|
import { type WriteTsDefinitionsOptions } from "./writer/writer-ts-definitions";
|
|
7
|
-
export
|
|
5
|
+
export type { CollectedComponents, ComponentDocApi, ComponentDocs, ComponentParseError, GenerateBundleOptions, GenerateBundleResult, ResolveComponentFilePath, } from "./bundle";
|
|
6
|
+
export { collectComponents, collectSvelteFilePaths, generateBundle, processComponent, readFileMap, reportParseErrors, toGenerateBundleOptions, } from "./bundle";
|
|
7
|
+
export interface PluginSveldOptions extends Pick<GenerateBundleOptions, "resolveTypes"> {
|
|
8
8
|
/**
|
|
9
9
|
* Specify the entry point to uncompiled Svelte source.
|
|
10
10
|
* If not provided, sveld will use the "svelte" field from package.json.
|
|
11
11
|
*/
|
|
12
12
|
entry?: string;
|
|
13
13
|
glob?: boolean;
|
|
14
|
+
/** Record consts, functions, and types from the entry barrel. Off by default. */
|
|
15
|
+
documentExports?: boolean;
|
|
14
16
|
types?: boolean;
|
|
15
17
|
typesOptions?: Partial<Omit<WriteTsDefinitionsOptions, "inputDir">>;
|
|
16
18
|
json?: boolean;
|
|
17
19
|
jsonOptions?: Partial<Omit<WriteJsonOptions, "inputDir">>;
|
|
18
20
|
markdown?: boolean;
|
|
19
21
|
markdownOptions?: Partial<WriteMarkdownOptions>;
|
|
22
|
+
/**
|
|
23
|
+
* Abort the entire run when a single component fails to parse.
|
|
24
|
+
* When `false` (the default), parse failures are collected as diagnostics
|
|
25
|
+
* and the remaining components still emit their output.
|
|
26
|
+
*/
|
|
27
|
+
failFast?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Regenerate output incrementally when `.svelte` source changes during
|
|
30
|
+
* `vite dev` / `vite build --watch`. Only the changed component and the
|
|
31
|
+
* components that depend on it via `@extendProps` / `@extends` are re-parsed.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
watch?: boolean;
|
|
20
35
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
/** Subset of Vite/Rollup's HMR context that the watch hook relies on. */
|
|
37
|
+
interface HotUpdateContext {
|
|
38
|
+
file: string;
|
|
24
39
|
}
|
|
25
|
-
export type ComponentDocs = Map<string, ComponentDocApi>;
|
|
26
40
|
interface SveldPlugin {
|
|
27
41
|
name: string;
|
|
28
42
|
apply?: "build" | "serve";
|
|
29
43
|
enforce?: "pre" | "post";
|
|
30
|
-
buildStart(): void
|
|
44
|
+
buildStart(): void | Promise<void>;
|
|
31
45
|
generateBundle(): Promise<void>;
|
|
32
46
|
writeBundle(): void;
|
|
47
|
+
/** Vite dev-server HMR hook (serve mode). */
|
|
48
|
+
handleHotUpdate?(ctx: HotUpdateContext): void;
|
|
49
|
+
/** Rollup/Vite watch hook (build `--watch`). */
|
|
50
|
+
watchChange?(id: string): void;
|
|
33
51
|
}
|
|
34
52
|
export default function pluginSveld(opts?: PluginSveldOptions): SveldPlugin;
|
|
35
|
-
interface GenerateBundleResult {
|
|
36
|
-
exports: ParsedExports;
|
|
37
|
-
components: ComponentDocs;
|
|
38
|
-
allComponentsForTypes: ComponentDocs;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Generates component documentation bundle from Svelte source files.
|
|
42
|
-
*
|
|
43
|
-
* Parses exports, discovers components (optionally via glob), and processes
|
|
44
|
-
* all Svelte files to extract component metadata. Returns both exported
|
|
45
|
-
* components (for JSON/Markdown) and all components (for TypeScript definitions).
|
|
46
|
-
*
|
|
47
|
-
* @param input - Entry point file or directory containing Svelte components
|
|
48
|
-
* @param glob - Whether to glob for all .svelte files in the directory
|
|
49
|
-
* @returns Bundle result containing exports, components, and allComponentsForTypes
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* // Generate from single file:
|
|
54
|
-
* const result = await generateBundle("./src/App.svelte", false);
|
|
55
|
-
*
|
|
56
|
-
* // Generate from directory with glob:
|
|
57
|
-
* const result = await generateBundle("./src", true);
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare function generateBundle(input: string, glob: boolean): Promise<{
|
|
61
|
-
exports: ParsedExports;
|
|
62
|
-
components: ComponentDocs;
|
|
63
|
-
allComponentsForTypes: ComponentDocs;
|
|
64
|
-
}>;
|
|
65
53
|
/**
|
|
66
54
|
* Writes output files based on plugin options.
|
|
67
55
|
*
|
|
@@ -84,4 +72,3 @@ export declare function generateBundle(input: string, glob: boolean): Promise<{
|
|
|
84
72
|
* ```
|
|
85
73
|
*/
|
|
86
74
|
export declare function writeOutput(result: GenerateBundleResult, opts: PluginSveldOptions, input: string): void;
|
|
87
|
-
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ParsedComponentTypeScriptMetadata, ResolvedComponentProp } from "./ComponentParser";
|
|
2
|
+
export interface ResolveTarget {
|
|
3
|
+
moduleName: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
metadata: ParsedComponentTypeScriptMetadata;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Expands opaque imported `$props()` types using the project's TypeScript program.
|
|
9
|
+
* Loaded only when `resolveTypes` is enabled.
|
|
10
|
+
*/
|
|
11
|
+
export declare class TypeResolver {
|
|
12
|
+
private readonly api;
|
|
13
|
+
private readonly symbolFlags;
|
|
14
|
+
private readonly tsconfigPath;
|
|
15
|
+
private readonly overlay;
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Loads `typescript` and the nearest `tsconfig.json`.
|
|
19
|
+
* Returns `null` when either is missing.
|
|
20
|
+
*/
|
|
21
|
+
static create(cwd?: string): Promise<TypeResolver | null>;
|
|
22
|
+
/** Resolves every target in one program snapshot. */
|
|
23
|
+
expandAll(targets: ResolveTarget[]): Promise<Map<string, ResolvedComponentProp[]>>;
|
|
24
|
+
/** Closes the TypeScript server process. */
|
|
25
|
+
dispose(): Promise<void>;
|
|
26
|
+
private resolveFile;
|
|
27
|
+
private createFileSystem;
|
|
28
|
+
private virtualFileName;
|
|
29
|
+
}
|
package/lib/sveld.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SveldDiagnostic } from "./diagnostics";
|
|
1
2
|
import { type PluginSveldOptions } from "./plugin";
|
|
2
3
|
interface SveldOptions extends Omit<PluginSveldOptions, "entry"> {
|
|
3
4
|
/**
|
|
@@ -6,6 +7,17 @@ interface SveldOptions extends Omit<PluginSveldOptions, "entry"> {
|
|
|
6
7
|
* the entry point from the `package.json#svelte` field.
|
|
7
8
|
*/
|
|
8
9
|
input?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Exit with code 1 when diagnostics are present. Default `false`.
|
|
12
|
+
*/
|
|
13
|
+
strict?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Result of a programmatic `sveld` run.
|
|
17
|
+
*/
|
|
18
|
+
interface SveldResult {
|
|
19
|
+
/** Diagnostics from this run. */
|
|
20
|
+
diagnostics: SveldDiagnostic[];
|
|
9
21
|
}
|
|
10
22
|
/**
|
|
11
23
|
* Programmatic entry point for sveld.
|
|
@@ -21,5 +33,5 @@ interface SveldOptions extends Omit<PluginSveldOptions, "entry"> {
|
|
|
21
33
|
* });
|
|
22
34
|
* ```
|
|
23
35
|
*/
|
|
24
|
-
export declare function sveld(opts?: SveldOptions): Promise<
|
|
36
|
+
export declare function sveld(opts?: SveldOptions): Promise<SveldResult>;
|
|
25
37
|
export {};
|
package/lib/watch.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type GenerateBundleResult } from "./bundle";
|
|
2
|
+
/** Result of an incremental update. */
|
|
3
|
+
export interface SveldBundleUpdate {
|
|
4
|
+
/** The full, updated bundle result (all components, with the affected ones re-parsed). */
|
|
5
|
+
result: GenerateBundleResult;
|
|
6
|
+
/**
|
|
7
|
+
* Absolute paths of the components that were re-parsed: the changed files
|
|
8
|
+
* plus their transitive `@extendProps` / `@extends` dependents. Other
|
|
9
|
+
* components are reused from the previous parse.
|
|
10
|
+
*/
|
|
11
|
+
reparsed: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A long-lived bundle that supports scoped, incremental re-parsing.
|
|
15
|
+
*
|
|
16
|
+
* `createSveldBundle` performs the initial full parse. `update` then re-parses
|
|
17
|
+
* only the components affected by a set of changed files, leaving every other
|
|
18
|
+
* component's previously-parsed output untouched. This is the core of the
|
|
19
|
+
* plugin's watch mode.
|
|
20
|
+
*/
|
|
21
|
+
export interface SveldBundle {
|
|
22
|
+
readonly result: GenerateBundleResult;
|
|
23
|
+
/** Re-parse the changed files plus their dependents and return the updated bundle. */
|
|
24
|
+
update(changedFilePaths: string[]): Promise<SveldBundleUpdate>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a watch-mode bundle for the given entry point, performing the initial
|
|
28
|
+
* full parse up front.
|
|
29
|
+
*
|
|
30
|
+
* @param input - Entry point file or directory containing Svelte components
|
|
31
|
+
* @param glob - Whether to glob for all `.svelte` files in the directory
|
|
32
|
+
* @param documentExports - Record consts, functions, and types from the entry barrel
|
|
33
|
+
*/
|
|
34
|
+
export declare function createSveldBundle(input: string, glob: boolean, documentExports?: boolean): Promise<SveldBundle>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { DeprecatedValue } from "../ComponentParser";
|
|
1
2
|
export declare const BACKTICK_REGEX: RegExp;
|
|
2
3
|
export declare const WHITESPACE_REGEX: RegExp;
|
|
3
4
|
export declare const MD_TYPE_UNDEFINED = "--";
|
|
4
5
|
export declare const PROP_TABLE_HEADER = "| Prop name | Required | Kind | Reactive | Binding | Type | Default value | Description |\n| :- | :- | :- | :- | :- | :- | :- | :- |\n";
|
|
5
|
-
export declare const SLOT_TABLE_HEADER = "| Slot name | Default | Props | Fallback |\n| :- | :- | :- | :- |\n";
|
|
6
|
+
export declare const SLOT_TABLE_HEADER = "| Slot name | Default | Props | Fallback | Description |\n| :- | :- | :- | :- | :- |\n";
|
|
6
7
|
export declare const EVENT_TABLE_HEADER = "| Event name | Type | Detail | Description |\n| :- | :- | :- | :- |\n";
|
|
8
|
+
export declare const EXPORT_TABLE_HEADER = "| Name | Kind | Type | Description |\n| :- | :- | :- | :- |\n";
|
|
7
9
|
/**
|
|
8
10
|
* Escape `|` and wrap a prop type for markdown table cells.
|
|
9
11
|
*
|
|
@@ -33,6 +35,16 @@ export declare function escapeHtml(text: string): string;
|
|
|
33
35
|
* ```
|
|
34
36
|
*/
|
|
35
37
|
export declare function formatPropValue(value: string | undefined): string;
|
|
38
|
+
/**
|
|
39
|
+
* Strike through deprecated prop, slot, and event names in markdown tables.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* formatNameWithDeprecation("size", "use width")
|
|
44
|
+
* // Returns: "<s>size</s><br />**Deprecated**: use width"
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function formatNameWithDeprecation(name: string, deprecated: DeprecatedValue | undefined): string;
|
|
36
48
|
/**
|
|
37
49
|
* Format a prop description; newlines become `<br />`.
|
|
38
50
|
*
|
|
@@ -63,6 +75,23 @@ export declare function formatSlotProps(props?: string): string;
|
|
|
63
75
|
* ```
|
|
64
76
|
*/
|
|
65
77
|
export declare function formatSlotFallback(fallback?: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* Format a slot/snippet description plus pass-through JSDoc tags for markdown
|
|
80
|
+
* table cells. Newlines become `<br />` and `<`, `>`, `|` are escaped so the
|
|
81
|
+
* content stays inside a single table cell.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* formatSlotDescription("Header content.", [{ name: "since", body: "1.0.0" }])
|
|
86
|
+
* // Returns: "Header content.<br />@since 1.0.0"
|
|
87
|
+
* formatSlotDescription(undefined, [])
|
|
88
|
+
* // Returns: "--"
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function formatSlotDescription(description?: string, tags?: Array<{
|
|
92
|
+
name: string;
|
|
93
|
+
body: string;
|
|
94
|
+
}>): string;
|
|
66
95
|
/**
|
|
67
96
|
* Format event detail types for markdown table cells.
|
|
68
97
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EntryExports } from "../parse-entry-exports";
|
|
1
2
|
import type { ComponentDocs } from "../plugin";
|
|
2
3
|
import type { AppendType } from "./MarkdownWriterBase";
|
|
3
4
|
/** Minimal markdown writer surface used by JSON and browser renderers. */
|
|
@@ -5,5 +6,5 @@ interface MarkdownDocument {
|
|
|
5
6
|
append(type: AppendType, raw?: string): MarkdownDocument;
|
|
6
7
|
tableOfContents(): MarkdownDocument;
|
|
7
8
|
}
|
|
8
|
-
export declare function renderComponentsToMarkdown(document: MarkdownDocument, components: ComponentDocs): void;
|
|
9
|
+
export declare function renderComponentsToMarkdown(document: MarkdownDocument, components: ComponentDocs, entryExports?: EntryExports): void;
|
|
9
10
|
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { EntryExports } from "../parse-entry-exports";
|
|
1
2
|
import type { ComponentDocs } from "../plugin";
|
|
2
3
|
export interface WriteJsonOptions {
|
|
3
4
|
input: string;
|
|
4
5
|
inputDir: string;
|
|
5
6
|
outFile: string;
|
|
6
7
|
outDir?: string;
|
|
8
|
+
/** Entry-barrel exports when `documentExports` is on. */
|
|
9
|
+
entryExports?: EntryExports;
|
|
7
10
|
}
|
|
8
11
|
/**
|
|
9
12
|
* Writes component documentation to JSON format.
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { EntryExports } from "../parse-entry-exports";
|
|
1
2
|
import type { ComponentDocs } from "../plugin";
|
|
2
3
|
import WriterMarkdown, { type AppendType } from "./WriterMarkdown";
|
|
3
4
|
export interface WriteMarkdownOptions {
|
|
4
5
|
write?: boolean;
|
|
5
6
|
outFile: string;
|
|
7
|
+
/** Entry-barrel exports when `documentExports` is on. */
|
|
8
|
+
entryExports?: EntryExports;
|
|
6
9
|
onAppend?: (type: AppendType, document: WriterMarkdown, components: ComponentDocs) => void;
|
|
7
10
|
}
|
|
8
11
|
/**
|