svelte-prune 0.0.0 → 0.10.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/LICENSE +2 -2
- package/README.md +529 -2
- package/analysis-a7wbx6mr.js +1 -0
- package/index-34y0pc8q.js +2 -0
- package/index-4960rqxx.js +3 -0
- package/index-4992cggh.js +5 -0
- package/index-6g116bmb.js +2 -0
- package/index-gdmk0qve.js +2 -0
- package/index-n6hffmks.js +22 -0
- package/index-wkcyw7a9.js +9 -0
- package/index-xt8m9vw2.js +2 -0
- package/index-zq01wexv.js +2 -0
- package/index.d.ts +209 -0
- package/index.js +1 -0
- package/internal-analysis.d.ts +602 -0
- package/internal-analysis.js +1 -0
- package/internal.d.ts +451 -0
- package/internal.js +1 -0
- package/loader.js +1 -0
- package/package.json +53 -3
- package/tailwind-sources-w3ata1x1.js +1 -0
- package/variant-tables-tr82shep.js +1 -0
- package/vite.d.ts +119 -0
- package/vite.js +1 -0
- package/webpack.d.ts +195 -0
- package/webpack.js +1 -0
- package/index.ts +0 -1
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import { type Binding, type Scopes } from "svelte-ast/scope";
|
|
2
|
+
|
|
3
|
+
import { type AST, type Expression } from "svelte-ast/walk";
|
|
4
|
+
|
|
5
|
+
import { type AST } from "svelte-ast/walk";
|
|
6
|
+
|
|
7
|
+
import type { Binding } from "svelte-ast/scope";
|
|
8
|
+
|
|
9
|
+
import { type Expression, type Identifier } from "svelte-ast/walk";
|
|
10
|
+
|
|
11
|
+
export type UsageResult = {
|
|
12
|
+
analysis: UsageAnalysis;
|
|
13
|
+
library: Library;
|
|
14
|
+
/** Export names of the library's components that can render (`Button`). */
|
|
15
|
+
liveComponents: Set<string>;
|
|
16
|
+
isPruned(cls: string): boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** For a failed analysis's warning: the feature it turns off, and what happens instead. */
|
|
20
|
+
export type Failure = {
|
|
21
|
+
feature: string;
|
|
22
|
+
fallback: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Collects call sites module by module during a build, then analyzes them
|
|
27
|
+
* against the library modules the bundle holds.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createUsageCollector(spec: LibrarySpec, projectRoot: string, failed: Failure): {
|
|
30
|
+
/** `code` is what the bundler hands the plugin. */
|
|
31
|
+
add(id: string, code: string): void;
|
|
32
|
+
/** Forgets modules no longer in the build (`vite build --watch`). */
|
|
33
|
+
retain(graph: Set<string>): void;
|
|
34
|
+
/**
|
|
35
|
+
* `bundledIds` are the library's `.svelte` module paths in the bundle;
|
|
36
|
+
* `imports`, the module graph's edges into the library. A component
|
|
37
|
+
* imported in a way the analysis didn't read (an alias) keeps every
|
|
38
|
+
* variant.
|
|
39
|
+
*/
|
|
40
|
+
analyze(bundledIds: Iterable<string>, options: UsageOptions, imports: Iterable<LibraryImport>): Promise<UsageResult | {
|
|
41
|
+
warning: string;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type UsageCollector = ReturnType<typeof createUsageCollector>;
|
|
46
|
+
|
|
47
|
+
/** `components` (names or paths) is the bundle; one no file renders keeps every variant. */
|
|
48
|
+
export declare function analyzeFiles(input: {
|
|
49
|
+
library: LibrarySpec;
|
|
50
|
+
projectRoot: string;
|
|
51
|
+
files: Iterable<{
|
|
52
|
+
file: string;
|
|
53
|
+
code: string;
|
|
54
|
+
}>;
|
|
55
|
+
components: Iterable<string>;
|
|
56
|
+
options: UsageOptions;
|
|
57
|
+
failure: Failure;
|
|
58
|
+
/** `collectAppUsage(files)`, if the caller already has it. */
|
|
59
|
+
appUsage?: AppUsage;
|
|
60
|
+
}): Promise<UsageResult | {
|
|
61
|
+
warning: string;
|
|
62
|
+
}>;
|
|
63
|
+
|
|
64
|
+
/** Per component, the prop values the app passes and why some stay open. */
|
|
65
|
+
export declare function formatPropAwareReport(result: UsageResult, prunedClasses: ReadonlySet<string>, root: string): string[];
|
|
66
|
+
|
|
67
|
+
type RewrittenSource = {
|
|
68
|
+
code: string;
|
|
69
|
+
map: SourceMap;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** Library components rewritten for an app, by real path of their source. */
|
|
73
|
+
export type SpecializedComponents = {
|
|
74
|
+
sources: Map<string, RewrittenSource>;
|
|
75
|
+
edits: number;
|
|
76
|
+
/** App components whose props came from their analyzed call sites: nothing else may render them. */
|
|
77
|
+
closed: Set<string>;
|
|
78
|
+
/** How many of the app's own components `sources` holds. */
|
|
79
|
+
apps: number;
|
|
80
|
+
/** Module keys of the library components that can render. */
|
|
81
|
+
renderable: ReadonlySet<string>;
|
|
82
|
+
/** tailwind-variants tables rewritten (`sources` holds their modules). */
|
|
83
|
+
tables: Pick<RewrittenTables, "pruned" | "emptied" | "keys" | "compounds"> & {
|
|
84
|
+
modules: number;
|
|
85
|
+
};
|
|
86
|
+
report: () => string[];
|
|
87
|
+
/**
|
|
88
|
+
* Whether the analysis read `importer`'s import of library module `id` (real
|
|
89
|
+
* paths): `false` for one it can't see (an alias), `true` for a module whose
|
|
90
|
+
* imports it doesn't read (a script, a stylesheet).
|
|
91
|
+
*/
|
|
92
|
+
readImport: (importer: string, id: string) => boolean;
|
|
93
|
+
/**
|
|
94
|
+
* With `styles` in the `LibrarySpec`: removes the rules of `css` that need
|
|
95
|
+
* a class the library's stylesheets define and nothing can render.
|
|
96
|
+
*/
|
|
97
|
+
pruneStyles?: StylePruner;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Rewrites each library component `files` render, and each app component whose every call site they hold. */
|
|
101
|
+
export declare function specializeFiles(input: {
|
|
102
|
+
library: LibrarySpec;
|
|
103
|
+
projectRoot: string;
|
|
104
|
+
files: Array<{
|
|
105
|
+
file: string;
|
|
106
|
+
code: string;
|
|
107
|
+
}>;
|
|
108
|
+
options?: SpecializeOptions;
|
|
109
|
+
/** Aliased `.svelte` imports the bundler resolved, by `importKey`. */
|
|
110
|
+
resolvedImports?: ReadonlyMap<string, string>;
|
|
111
|
+
failure: Failure;
|
|
112
|
+
/** Classes `pruneStyles` keeps whatever renders: ones the app builds from data. */
|
|
113
|
+
safelist?: readonly SafelistEntry[];
|
|
114
|
+
}): Promise<SpecializedComponents | {
|
|
115
|
+
warning: string;
|
|
116
|
+
}>;
|
|
117
|
+
|
|
118
|
+
export type UsageOptions = {
|
|
119
|
+
/** Components that keep every variant, as if rendered with any props. */
|
|
120
|
+
exclude?: string[];
|
|
121
|
+
/** Values for props the analysis can't read, by component then prop; spreads still keep everything. */
|
|
122
|
+
assume?: Record<string, Record<string, Array<string | number | boolean | null>>>;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
type UsageAnalysis = {
|
|
126
|
+
/** Library module keys that can render. */
|
|
127
|
+
liveComponents: Set<string>;
|
|
128
|
+
usages: Map<string, ComponentUsage>;
|
|
129
|
+
/** `.x--btn--danger` when no button is danger, and every class of a component that can't render. */
|
|
130
|
+
isPruned(cls: string): boolean;
|
|
131
|
+
/** The scope `key` was last walked in; `undefined` if it can't render. */
|
|
132
|
+
scopeFor(key: string): Scope | undefined;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
type ModuleUsage = {
|
|
136
|
+
/** Library keys (`Button/Button.svelte`), or absolute paths of app files. */
|
|
137
|
+
sites: CallSite[];
|
|
138
|
+
/** Every bundled library component may render with any props. */
|
|
139
|
+
openAll: boolean;
|
|
140
|
+
/** A `.svelte` import it can't follow: every app component is open. */
|
|
141
|
+
openApps?: boolean;
|
|
142
|
+
/** Every `contextKeyPrefix` string, not just `setContext` arguments. */
|
|
143
|
+
providedContexts: Set<string>;
|
|
144
|
+
/** It may pass `setContext` a library key it doesn't spell out. */
|
|
145
|
+
providesUnknownContext?: boolean;
|
|
146
|
+
/** It may read a library context, and so write to the stores one hands on. */
|
|
147
|
+
readsLibraryContext?: boolean;
|
|
148
|
+
file?: string;
|
|
149
|
+
libraryImports?: LibraryImports;
|
|
150
|
+
/** Names it imports from the barrel that aren't components; `"any"` if it may read any. */
|
|
151
|
+
libraryValues?: Set<string> | "any";
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
type LibraryImports = {
|
|
155
|
+
components: Set<string>;
|
|
156
|
+
barrel: boolean;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
declare const FUNCTION_DECLARATION = "function";
|
|
160
|
+
|
|
161
|
+
type FunctionNode = Extract<Node, {
|
|
162
|
+
type: "FunctionDeclaration" | "FunctionExpression" | "ArrowFunctionExpression";
|
|
163
|
+
}>;
|
|
164
|
+
|
|
165
|
+
type Helper = {
|
|
166
|
+
model: ComponentModel;
|
|
167
|
+
fn: FunctionNode;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
type ComponentModel = {
|
|
171
|
+
/** Path relative to the library's `srcDir`, e.g. `Button/Button.svelte`. */
|
|
172
|
+
readonly key: string;
|
|
173
|
+
readonly code: string;
|
|
174
|
+
readonly ast: AST.Root;
|
|
175
|
+
readonly scopes: Scopes;
|
|
176
|
+
readonly props: Map<string, Expression | null>;
|
|
177
|
+
/** Local name -> the name a parent passes it by (`class` for `className`). */
|
|
178
|
+
readonly propNames: Map<string, string>;
|
|
179
|
+
/** `<svelte:options customElement>`: any renderer can set its props. */
|
|
180
|
+
readonly customElement: boolean;
|
|
181
|
+
/** Top-level `let`/`const`, functions, and `$: x = …` declarations. */
|
|
182
|
+
readonly declarations: Map<string, Expression | null | typeof FUNCTION_DECLARATION>;
|
|
183
|
+
readonly functions: Map<string, FunctionNode>;
|
|
184
|
+
/** The `$: x = …` assignments that define a declaration above. */
|
|
185
|
+
readonly reactiveDeclarations: WeakSet<Node>;
|
|
186
|
+
/** Top-level names written outside their declaration (handlers, `bind:`). */
|
|
187
|
+
readonly unknownNames: Set<string>;
|
|
188
|
+
readonly unknownReasons: Map<string, string>;
|
|
189
|
+
/** Names written only by `name = …` under `if`s in `$:` (see `withGuardedWrites`). */
|
|
190
|
+
readonly guardedWrites: Map<string, GuardedWrite[]>;
|
|
191
|
+
/** Local binding -> library module key, for relative `.svelte` imports. */
|
|
192
|
+
readonly componentImports: Map<string, string>;
|
|
193
|
+
readonly otherImports: Set<string>;
|
|
194
|
+
readonly packageImports: Map<string, string>;
|
|
195
|
+
/** Library objects with component members (`import * as L`, `Object.assign`). */
|
|
196
|
+
readonly memberImports: Map<string, Export>;
|
|
197
|
+
/** Imported `export const NAME = "…"` strings, for context keys. */
|
|
198
|
+
readonly importedStrings: Map<string, string>;
|
|
199
|
+
/** Imported functions of library `.js` modules, read when first called. */
|
|
200
|
+
readonly importedHelpers: Map<string, () => Helper | undefined>;
|
|
201
|
+
/** Local name -> `svelte/store` export. */
|
|
202
|
+
readonly storeImports: Map<string, string>;
|
|
203
|
+
readonly providedContexts: Set<string>;
|
|
204
|
+
providesUnknownContext: boolean;
|
|
205
|
+
/** Per `setContext` call: an object literal's properties, or `null`. */
|
|
206
|
+
readonly contextObjects: Map<string, Array<ContextObject | null>>;
|
|
207
|
+
/** Context properties it may write or hand on (`"*"`: all); see `readContextUse`. */
|
|
208
|
+
readonly contextLeaks: Map<string, Set<string>>;
|
|
209
|
+
readsUnknownContext: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Decides whether a literal a name holds stays known (see `Shape`).
|
|
212
|
+
* `$$props.x` adds `"$$props.x"`, any other `$$props` use `"*"`, both `full`.
|
|
213
|
+
*/
|
|
214
|
+
readonly escapes: Map<string, Escape>;
|
|
215
|
+
/** `rest` in `let { a, ...rest } = $props()`, unless reassigned. */
|
|
216
|
+
restPropsName?: string;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
type Escape = {
|
|
220
|
+
full: boolean;
|
|
221
|
+
readonly paths: string[][];
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
type Guard = {
|
|
225
|
+
readonly test: Expression;
|
|
226
|
+
readonly holds: boolean;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
type GuardedWrite = {
|
|
230
|
+
readonly guards: readonly Guard[];
|
|
231
|
+
readonly value: Expression;
|
|
232
|
+
readonly line: number;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
type ContextObject = {
|
|
236
|
+
readonly properties: Map<string, MirroredStore | null>;
|
|
237
|
+
readonly unlessProvided: readonly string[];
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
type MirroredStore = {
|
|
241
|
+
readonly initial: Expression | null;
|
|
242
|
+
readonly writes: readonly Expression[];
|
|
243
|
+
readonly readOnly: boolean;
|
|
244
|
+
/** The object's other properties that hold the same store. */
|
|
245
|
+
readonly aliases: readonly string[];
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/** Cached by path and mtime, so a library edited under `--watch` reloads. */
|
|
249
|
+
export declare function loadComponentModel(src: string, key: string): ComponentModel;
|
|
250
|
+
|
|
251
|
+
type Node = AST.SvelteNode;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* svelte-ast without its HTML entity table: the indexer reads class names, which
|
|
255
|
+
* never hold a named character reference. TypeScript stays in, so a library
|
|
256
|
+
* release that adds `<script lang="ts">` still parses.
|
|
257
|
+
*/
|
|
258
|
+
export declare const parse: (source: string, options?: import("svelte-ast/core").ParseOptions) => import("svelte-ast/core").AST.Root, parseModule: (source: string, options?: import("svelte-ast/core").ParseModuleOptions) => import("svelte-ast/core").Program;
|
|
259
|
+
|
|
260
|
+
type Export =
|
|
261
|
+
/** A component: its module key (`button/button.svelte`). */
|
|
262
|
+
{
|
|
263
|
+
kind: "component";
|
|
264
|
+
key: string;
|
|
265
|
+
}
|
|
266
|
+
/** A namespace, or a component with members (`Object.assign(Root, { Item })`) keyed `self`. */
|
|
267
|
+
| {
|
|
268
|
+
kind: "members";
|
|
269
|
+
self?: string;
|
|
270
|
+
member: (name: string) => Export;
|
|
271
|
+
}
|
|
272
|
+
/** Something that holds none of the library's components. */
|
|
273
|
+
| {
|
|
274
|
+
kind: "value";
|
|
275
|
+
}
|
|
276
|
+
/** Anything, a component or something that holds one included. */
|
|
277
|
+
| {
|
|
278
|
+
kind: "unknown";
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
type ContextResolver = (key: string) => Value;
|
|
282
|
+
|
|
283
|
+
type Scope = {
|
|
284
|
+
readonly model: ComponentModel;
|
|
285
|
+
readonly usage: ComponentUsage;
|
|
286
|
+
readonly context: ContextResolver;
|
|
287
|
+
readonly memo: Map<string, Value>;
|
|
288
|
+
/** Names being evaluated, so a cycle reads as unknown instead of looping. */
|
|
289
|
+
readonly pending: Set<string>;
|
|
290
|
+
/** Enclosing `{#each}` items; replaced, never mutated. */
|
|
291
|
+
locals: ReadonlyMap<Binding, Value>;
|
|
292
|
+
readonly imported: ReadonlyMap<string, Value>;
|
|
293
|
+
readonly svelteMajor: number | undefined;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
type CallSite = {
|
|
297
|
+
/** Library module key, relative to its `srcDir`: `Button/Button.svelte`. */
|
|
298
|
+
component: string;
|
|
299
|
+
/** Every prop and slot is unknown: props are spread, or it's used as a value. */
|
|
300
|
+
open: boolean;
|
|
301
|
+
props: Map<string, Value>;
|
|
302
|
+
/** Slots this site fills (a snippet fills its name's); `null` when that can't be told. */
|
|
303
|
+
slots: Set<string> | null;
|
|
304
|
+
/** Has content outside any snippet or `slot="…"`: Svelte 5's `children`. */
|
|
305
|
+
children?: boolean;
|
|
306
|
+
/** `bind:this` members read off the instance; `null` if used otherwise. */
|
|
307
|
+
instance?: ReadonlySet<string> | null;
|
|
308
|
+
/** Events it listens to with `on:`; unset if that can't be told. */
|
|
309
|
+
events?: ReadonlySet<string>;
|
|
310
|
+
/** Only set for app files, for the report. */
|
|
311
|
+
location?: {
|
|
312
|
+
file: string;
|
|
313
|
+
line: number;
|
|
314
|
+
};
|
|
315
|
+
reason?: string;
|
|
316
|
+
/** Per unknown prop; a function is only called if no earlier site gave one. */
|
|
317
|
+
why?: Map<string, string | (() => string | undefined)>;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
type ComponentUsage = {
|
|
321
|
+
open: boolean;
|
|
322
|
+
props: Map<string, Value>;
|
|
323
|
+
/** Props some site leaves out: their default applies, or they're absent. */
|
|
324
|
+
omitted: Set<string>;
|
|
325
|
+
/** `$$slots[name]` across sites; Svelte only sets filled slots' keys. */
|
|
326
|
+
slots: Map<string, Value>;
|
|
327
|
+
slotsUnknown: boolean;
|
|
328
|
+
siteCount: number;
|
|
329
|
+
appSites: CallSite[];
|
|
330
|
+
openReason?: string;
|
|
331
|
+
/** Why each unknown prop is unknown, from the first site that made it so. */
|
|
332
|
+
unknownBecause: Map<string, string>;
|
|
333
|
+
/** Events some site listens to with `on:`. */
|
|
334
|
+
events: Set<string>;
|
|
335
|
+
/** A site may listen to any event. */
|
|
336
|
+
eventsUnknown: boolean;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
declare const OBJECT: unique symbol;
|
|
340
|
+
|
|
341
|
+
declare const EMPTY_ARRAY: unique symbol;
|
|
342
|
+
|
|
343
|
+
declare const UNKNOWN: unique symbol;
|
|
344
|
+
|
|
345
|
+
type Shape = {
|
|
346
|
+
readonly kind: "object";
|
|
347
|
+
readonly props: ReadonlyMap<string, Value>;
|
|
348
|
+
} | {
|
|
349
|
+
readonly kind: "array";
|
|
350
|
+
readonly elements: readonly Value[];
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
type Store = {
|
|
354
|
+
readonly kind: "store";
|
|
355
|
+
readonly value: Value;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
type Primitive = string | number | boolean | null | undefined | typeof OBJECT | typeof EMPTY_ARRAY | Shape | Store;
|
|
359
|
+
|
|
360
|
+
type Value = ReadonlySet<Primitive> | typeof UNKNOWN;
|
|
361
|
+
|
|
362
|
+
declare class Library extends LibraryPaths {
|
|
363
|
+
readonly root: string;
|
|
364
|
+
/** Export name -> module key in `srcDir` (`Button` -> `Button/Button.svelte`). */
|
|
365
|
+
readonly components: ReadonlyMap<string, string>;
|
|
366
|
+
constructor(spec: LibrarySpec, root: string, components: ReadonlyMap<string, string>);
|
|
367
|
+
get src(): string;
|
|
368
|
+
private exports?;
|
|
369
|
+
exportOf(name: string): Export;
|
|
370
|
+
private svelte?;
|
|
371
|
+
/** Resolved from the library's root: it decides whether content is passed as `children` (Svelte 5). */
|
|
372
|
+
get svelteMajor(): number | undefined;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Cached by the barrel's mtime, so a linked checkout edited between watch rebuilds is reread. */
|
|
376
|
+
export declare function libraryAt(spec: LibrarySpec, root: string): Library;
|
|
377
|
+
|
|
378
|
+
type ClassTokens = {
|
|
379
|
+
/** Text that may name a class contains it (`"x--"`). */
|
|
380
|
+
marker: string;
|
|
381
|
+
text(text: string): string[];
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
type LibraryClassTokens = ClassTokens & {
|
|
385
|
+
script(code: string, into: Set<string>): void;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
type LibrarySpec = {
|
|
389
|
+
/** The package apps import: `"my-library"`. */
|
|
390
|
+
name: string;
|
|
391
|
+
/** The directory of its modules in the package: `"src"`. */
|
|
392
|
+
srcDir: string;
|
|
393
|
+
/** Its barrel, in `srcDir`: `"index.js"`. */
|
|
394
|
+
barrel: string;
|
|
395
|
+
/** Packages whose exports are components (an icon set): passing one as a prop passes an object. */
|
|
396
|
+
componentPackages: readonly string[];
|
|
397
|
+
/** Its context key prefix (`"my-library:"`): an app module holding one may use its contexts. */
|
|
398
|
+
contextKeyPrefix: string;
|
|
399
|
+
/** Names the library in messages: `"My Library"`. */
|
|
400
|
+
label: string;
|
|
401
|
+
/** Names the tool in messages, and starts each warning and error: `"my-plugin"`. */
|
|
402
|
+
tool: string;
|
|
403
|
+
/**
|
|
404
|
+
* Reads class names, for pruning the library's styles: `text` a string
|
|
405
|
+
* containing `marker`, `script` a whole script module. Omit to read none,
|
|
406
|
+
* or, with `styles`, every run of word characters and hyphens.
|
|
407
|
+
*/
|
|
408
|
+
classTokens?: LibraryClassTokens;
|
|
409
|
+
/**
|
|
410
|
+
* The library's stylesheets. A production build drops the rules in the
|
|
411
|
+
* CSS it emits that need a class these stylesheets define and that
|
|
412
|
+
* nothing can render: no live component, none of the library's script
|
|
413
|
+
* modules, nothing in `content`. Omit to leave CSS as it is.
|
|
414
|
+
*/
|
|
415
|
+
styles?: {
|
|
416
|
+
/**
|
|
417
|
+
* Files in installed packages, each `"<package>/<path>"`, where `*`
|
|
418
|
+
* matches within a path segment: `"my-library/css/*.css"`.
|
|
419
|
+
*/
|
|
420
|
+
stylesheets: readonly string[];
|
|
421
|
+
/** Classes to keep whatever renders: ones the app's page sets (`"my-body"`). */
|
|
422
|
+
keep?: readonly string[];
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* `true` for a library whose classes are Tailwind's: its tailwind-variants
|
|
426
|
+
* tables are rewritten, and with Tailwind installed, every build (the dev
|
|
427
|
+
* server's included) writes what of it can render to
|
|
428
|
+
* `node_modules/.svelte-prune/<name>`, for Tailwind to scan. @default false
|
|
429
|
+
*/
|
|
430
|
+
tailwind?: boolean;
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
type LibraryImport = {
|
|
434
|
+
id: string;
|
|
435
|
+
importer: string;
|
|
436
|
+
specifier?: string;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
declare function patternsOf(spec: LibrarySpec): {
|
|
440
|
+
/** A computed `import()`'s arguments that name the package. */
|
|
441
|
+
argument: RegExp;
|
|
442
|
+
directComponentPath: RegExp;
|
|
443
|
+
contextKey: RegExp;
|
|
444
|
+
/** A specifier of one of its modules that's neither a component nor a stylesheet. */
|
|
445
|
+
valueSubpath: RegExp;
|
|
446
|
+
/** An import of one of its modules that isn't a component. */
|
|
447
|
+
scriptSpecifier: RegExp;
|
|
448
|
+
barrelImport: RegExp;
|
|
449
|
+
barrelSpecifier: RegExp;
|
|
450
|
+
directComponentSpecifier: RegExp;
|
|
451
|
+
/** Imports that are components: passing one as a prop passes an object. */
|
|
452
|
+
componentSource: RegExp;
|
|
453
|
+
/** An import or `require` of it in a file the lexer can't read. */
|
|
454
|
+
importText: RegExp;
|
|
455
|
+
dynamicImport: RegExp;
|
|
456
|
+
directComponentName: RegExp;
|
|
457
|
+
segment: RegExp;
|
|
458
|
+
srcSegment: RegExp;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
declare class LibraryPaths {
|
|
462
|
+
readonly spec: LibrarySpec;
|
|
463
|
+
readonly patterns: ReturnType<typeof patternsOf>;
|
|
464
|
+
constructor(spec: LibrarySpec);
|
|
465
|
+
get name(): string;
|
|
466
|
+
get logPrefix(): string;
|
|
467
|
+
/** `pkg/src/` */
|
|
468
|
+
get srcPrefix(): string;
|
|
469
|
+
get barrelKey(): string;
|
|
470
|
+
/** `…/pkg/src/Button/Button.svelte` -> `Button/Button.svelte`. */
|
|
471
|
+
moduleKey(id: string): string | undefined;
|
|
472
|
+
/** `moduleKey` of a component or the barrel, the modules whose imports the analysis reads. */
|
|
473
|
+
importKey(id: string): string | undefined;
|
|
474
|
+
/** Other imports resolving into the package (bundler aliases) are invisible to the analysis. */
|
|
475
|
+
isSpecifier(specifier: string): boolean;
|
|
476
|
+
isComponentFile(id: string): boolean;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
type AppUsage = {
|
|
480
|
+
/** Every module's library call sites, ready for `analyzeUsage`. */
|
|
481
|
+
modules: ModuleUsage[];
|
|
482
|
+
/** Each analyzed file as first read: see `readLibraryImport`. */
|
|
483
|
+
read: ReadonlyMap<string, ModuleUsage>;
|
|
484
|
+
/**
|
|
485
|
+
* Props read from call sites alone: sound only if nothing unanalyzed
|
|
486
|
+
* renders them, which the build plugins check against the module graph.
|
|
487
|
+
*/
|
|
488
|
+
closed: Set<string>;
|
|
489
|
+
/** With merged usage; `undefined` unless closed and modeled. */
|
|
490
|
+
scopeFor(file: string): Scope | undefined;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Evaluates app components with the props their call sites pass, until no
|
|
495
|
+
* usage grows, so props flow through wrappers to library call sites. One
|
|
496
|
+
* never imported (a route), used by a script, or imported dynamically or
|
|
497
|
+
* through an alias renders with any props.
|
|
498
|
+
*/
|
|
499
|
+
export declare function collectAppUsage(files: Iterable<{
|
|
500
|
+
file: string;
|
|
501
|
+
code: string;
|
|
502
|
+
}>, library: Library,
|
|
503
|
+
/** Aliased `.svelte` imports the bundler resolved; see `AppComponents`. */
|
|
504
|
+
resolved?: ReadonlyMap<string, string>): AppUsage;
|
|
505
|
+
|
|
506
|
+
type Run = readonly [number, number, number];
|
|
507
|
+
|
|
508
|
+
type MappedText = {
|
|
509
|
+
text: string;
|
|
510
|
+
runs: Run[];
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
type SourceMap = {
|
|
514
|
+
version: 3;
|
|
515
|
+
sources: string[];
|
|
516
|
+
sourcesContent: string[];
|
|
517
|
+
names: string[];
|
|
518
|
+
mappings: string;
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
type Specialization = {
|
|
522
|
+
code: string;
|
|
523
|
+
mapped: MappedText;
|
|
524
|
+
/** Edits applied (nested edits inside a removed range aren't counted). */
|
|
525
|
+
edits: number;
|
|
526
|
+
dropped: number;
|
|
527
|
+
/** `.svelte` imports nothing renders anymore. Lazy: it parses again. */
|
|
528
|
+
unrendered: () => string[];
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
type SpecializeOptions = {
|
|
532
|
+
/**
|
|
533
|
+
* Replaces an `{#if}` that renders nothing between whitespace (removing it
|
|
534
|
+
* would merge the two). Not empty: Svelte 3/4 warn; not text: Svelte 5
|
|
535
|
+
* rejects text in elements like `<colgroup>`.
|
|
536
|
+
*/
|
|
537
|
+
emptyBlock?: string;
|
|
538
|
+
/** Remove top-level declarations nothing reads after the edits. */
|
|
539
|
+
dropUnused?: boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Replace an `{#if}` whose only live branch is known with that branch's
|
|
542
|
+
* content. Only Svelte 5 renders it identically: block boundaries decide
|
|
543
|
+
* how Svelte 3/4 trim whitespace.
|
|
544
|
+
*/
|
|
545
|
+
unwrap?: boolean;
|
|
546
|
+
/** Debugging: apply only the top-level edits this accepts (by index). */
|
|
547
|
+
editFilter?: (index: number, edit: {
|
|
548
|
+
start: number;
|
|
549
|
+
end: number;
|
|
550
|
+
}) => boolean;
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
export declare function specializeComponent(scope: Scope, options?: SpecializeOptions): Specialization;
|
|
554
|
+
|
|
555
|
+
type PrunedStyles = {
|
|
556
|
+
css: string;
|
|
557
|
+
/** Rules removed whole, `@keyframes` included. */
|
|
558
|
+
rules: number;
|
|
559
|
+
/** Selectors removed from rules that stay. */
|
|
560
|
+
selectors: number;
|
|
561
|
+
/** Custom property declarations removed. */
|
|
562
|
+
declarations: number;
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
/** Removes the rules of `css` that need a class nothing can render. */
|
|
566
|
+
export type StylePruner = (css: string) => PrunedStyles;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* A `safelist` entry: a class (`"x--grid"` or `".x--grid"`), which keeps
|
|
570
|
+
* every selector it appears in, or a RegExp tested against each selector.
|
|
571
|
+
*/
|
|
572
|
+
export type SafelistEntry = string | RegExp;
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* The pruner for `spec`'s stylesheets: a class goes when they define it,
|
|
576
|
+
* `isPruned` says nothing renders it, and neither `content` nor `keep`
|
|
577
|
+
* names it. A selector `safelist` matches stays whole.
|
|
578
|
+
*/
|
|
579
|
+
export declare function libraryStylePruner(input: {
|
|
580
|
+
spec: LibrarySpec;
|
|
581
|
+
projectRoot: string;
|
|
582
|
+
isPruned: (cls: string) => boolean;
|
|
583
|
+
/** Files whose class names stay: the app's, as `content` reads them. */
|
|
584
|
+
files: Iterable<{
|
|
585
|
+
code: string;
|
|
586
|
+
}>;
|
|
587
|
+
safelist?: readonly SafelistEntry[];
|
|
588
|
+
}): StylePruner | undefined;
|
|
589
|
+
|
|
590
|
+
type RewrittenTables = {
|
|
591
|
+
/** Rewritten modules by key, with the source they were rewritten from. */
|
|
592
|
+
modules: Map<string, {
|
|
593
|
+
mapped: MappedText;
|
|
594
|
+
source: string;
|
|
595
|
+
}>;
|
|
596
|
+
pruned: number;
|
|
597
|
+
emptied: number;
|
|
598
|
+
keys: number;
|
|
599
|
+
compounds: number;
|
|
600
|
+
/** Tables a live component calls that keep every class, and why. */
|
|
601
|
+
kept: Map<string, string>;
|
|
602
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I,fe,J,Ve,Z,Ie,Be,Fe,Ue,he}from"./index-n6hffmks.js";export{Fe as analyzeFiles,J as collectAppUsage,Be as createUsageCollector,Ue as formatPropAwareReport,Ve as libraryAt,Ie as libraryStylePruner,fe as loadComponentModel,I as parse,Z as specializeComponent,he as specializeFiles};
|