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/internal.d.ts ADDED
@@ -0,0 +1,451 @@
1
+ export { type LexedImport, lexComponent, lexImportsExports, lexStrings, } from "svelte-ast/lexer";
2
+
3
+ export { type AST, walk } from "svelte-ast/walk";
4
+
5
+ import type { Plugin } from "vite";
6
+
7
+ /**
8
+ * Adds the components `source` imports or re-exports from `spec` to `into`.
9
+ * Returns `true` when it may use ones it doesn't name: a namespace import,
10
+ * `export *`, or a dynamic import of the barrel or a computed path.
11
+ */
12
+ export declare function collectLibraryImports(spec: LibrarySpec, source: string, into: Set<string>): boolean;
13
+
14
+ type ClassTokens = {
15
+ /** Text that may name a class contains it (`"x--"`). */
16
+ marker: string;
17
+ text(text: string): string[];
18
+ };
19
+
20
+ type LibraryClassTokens = ClassTokens & {
21
+ script(code: string, into: Set<string>): void;
22
+ };
23
+
24
+ /** A Svelte component library svelte-prune reads and rewrites. */
25
+ export type LibrarySpec = {
26
+ /** The package apps import: `"my-library"`. */
27
+ name: string;
28
+ /** The directory of its modules in the package: `"src"`. */
29
+ srcDir: string;
30
+ /** Its barrel, in `srcDir`: `"index.js"`. */
31
+ barrel: string;
32
+ /** Packages whose exports are components (an icon set): passing one as a prop passes an object. */
33
+ componentPackages: readonly string[];
34
+ /** Its context key prefix (`"my-library:"`): an app module holding one may use its contexts. */
35
+ contextKeyPrefix: string;
36
+ /** Names the library in messages: `"My Library"`. */
37
+ label: string;
38
+ /** Names the tool in messages, and starts each warning and error: `"my-plugin"`. */
39
+ tool: string;
40
+ /**
41
+ * Reads class names, for pruning the library's styles: `text` a string
42
+ * containing `marker`, `script` a whole script module. Omit to read none,
43
+ * or, with `styles`, every run of word characters and hyphens.
44
+ */
45
+ classTokens?: LibraryClassTokens;
46
+ /**
47
+ * The library's stylesheets. A production build drops the rules in the
48
+ * CSS it emits that need a class these stylesheets define and that
49
+ * nothing can render: no live component, none of the library's script
50
+ * modules, nothing in `content`. Omit to leave CSS as it is.
51
+ */
52
+ styles?: {
53
+ /**
54
+ * Files in installed packages, each `"<package>/<path>"`, where `*`
55
+ * matches within a path segment: `"my-library/css/*.css"`.
56
+ */
57
+ stylesheets: readonly string[];
58
+ /** Classes to keep whatever renders: ones the app's page sets (`"my-body"`). */
59
+ keep?: readonly string[];
60
+ };
61
+ /**
62
+ * `true` for a library whose classes are Tailwind's: its tailwind-variants
63
+ * tables are rewritten, and with Tailwind installed, every build (the dev
64
+ * server's included) writes what of it can render to
65
+ * `node_modules/.svelte-prune/<name>`, for Tailwind to scan. @default false
66
+ */
67
+ tailwind?: boolean;
68
+ };
69
+
70
+ /** An edge of the bundler's module graph into library module `id`; `specifier` is what `importer` wrote, when the bundler says. */
71
+ export type LibraryImport = {
72
+ id: string;
73
+ importer: string;
74
+ specifier?: string;
75
+ };
76
+
77
+ declare function patternsOf(spec: LibrarySpec): {
78
+ /** A computed `import()`'s arguments that name the package. */
79
+ argument: RegExp;
80
+ directComponentPath: RegExp;
81
+ contextKey: RegExp;
82
+ /** A specifier of one of its modules that's neither a component nor a stylesheet. */
83
+ valueSubpath: RegExp;
84
+ /** An import of one of its modules that isn't a component. */
85
+ scriptSpecifier: RegExp;
86
+ barrelImport: RegExp;
87
+ barrelSpecifier: RegExp;
88
+ directComponentSpecifier: RegExp;
89
+ /** Imports that are components: passing one as a prop passes an object. */
90
+ componentSource: RegExp;
91
+ /** An import or `require` of it in a file the lexer can't read. */
92
+ importText: RegExp;
93
+ dynamicImport: RegExp;
94
+ directComponentName: RegExp;
95
+ segment: RegExp;
96
+ srcSegment: RegExp;
97
+ };
98
+
99
+ declare class LibraryPaths {
100
+ readonly spec: LibrarySpec;
101
+ readonly patterns: ReturnType<typeof patternsOf>;
102
+ constructor(spec: LibrarySpec);
103
+ get name(): string;
104
+ get logPrefix(): string;
105
+ /** `pkg/src/` */
106
+ get srcPrefix(): string;
107
+ get barrelKey(): string;
108
+ /** `…/pkg/src/Button/Button.svelte` -> `Button/Button.svelte`. */
109
+ moduleKey(id: string): string | undefined;
110
+ /** `moduleKey` of a component or the barrel, the modules whose imports the analysis reads. */
111
+ importKey(id: string): string | undefined;
112
+ /** Other imports resolving into the package (bundler aliases) are invisible to the analysis. */
113
+ isSpecifier(specifier: string): boolean;
114
+ isComponentFile(id: string): boolean;
115
+ }
116
+
117
+ export declare const libraryPaths: (spec: LibrarySpec) => LibraryPaths;
118
+
119
+ /**
120
+ * Optimizers by id: loader options must be plain data under Rspack, and
121
+ * the loader may load as its own copy of this module, so the map lives on
122
+ * `globalThis`.
123
+ */
124
+ export declare function optimizerRegistry(): Map<string, ComponentOptimizer>;
125
+
126
+ type LoaderContext = {
127
+ resourcePath: string;
128
+ resourceQuery: string;
129
+ getOptions(): {
130
+ id: string;
131
+ };
132
+ addDependency(file: string): void;
133
+ callback(error: null, code: string, map?: unknown): void;
134
+ };
135
+
136
+ /** The pre-loader `SveltePrunePlugin` adds on `.svelte` files and the library's script modules: serves the ones it rewrote. */
137
+ export function sveltePruneLoader(this: LoaderContext, source: string, map?: unknown): void;
138
+ export { sveltePruneLoader as loader };
139
+
140
+ export type SveltePruneOptions = {
141
+ /**
142
+ * Globs (relative to the project root) of every file that renders the
143
+ * library's components; a module outside them that imports one fails the
144
+ * build. Components imported from script, Markdown, MDX or Astro files
145
+ * keep every prop value. `node_modules` is skipped unless a pattern names it.
146
+ * @default ["src/**\/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"]
147
+ */
148
+ content?: string[];
149
+ /**
150
+ * Replace an `{#if}` whose only live branch is known with that branch.
151
+ * Svelte 5 only: Svelte 3/4 render whitespace differently without the block.
152
+ * @default true when the installed Svelte is 5 or later
153
+ */
154
+ unwrap?: boolean;
155
+ /** Skip the per-build summary. @default false */
156
+ silent?: boolean;
157
+ /**
158
+ * Print what each build rewrote: edits, child components no longer rendered
159
+ * or bundled, and each call site's prop values. Independent of `silent`.
160
+ * @default false
161
+ */
162
+ report?: boolean;
163
+ /**
164
+ * Selectors of the library's stylesheets (`styles` in the `LibrarySpec`)
165
+ * to keep whatever renders, for classes the app builds from data at
166
+ * runtime: a class (`"x--tag--red"`, with or without its `.`) keeps every
167
+ * selector it's in, a RegExp every selector it matches (`/^\.x--tag--/`).
168
+ */
169
+ safelist?: Array<string | RegExp>;
170
+ };
171
+
172
+ type ImportResolver = (source: string, importer: string) => Promise<string | undefined>;
173
+
174
+ export type PluginNames = {
175
+ plugin: string;
176
+ failure: Failure;
177
+ };
178
+
179
+ declare function createComponentOptimizer(spec: LibrarySpec, options: SveltePruneOptions | undefined, names: PluginNames): {
180
+ prepare(root: string, resolve?: ImportResolver): Promise<{
181
+ warning?: string;
182
+ info?: string;
183
+ report?: string[];
184
+ }>;
185
+ readonly analyzed: ReadonlySet<string>;
186
+ /**
187
+ * Prunes the CSS assets `assets` holds (name to source) in place, and
188
+ * says what it removed; `undefined` when there's nothing to prune with.
189
+ */
190
+ pruneStyles(assets: Map<string, string>): string | undefined;
191
+ /** Whether `id` may be served rewritten, now or after `content` changes. */
192
+ rewritable(id: string): boolean;
193
+ load(id: string): RewrittenSource | undefined;
194
+ /** Records module `id` if it renders the library without having been analyzed. */
195
+ check(id: string, code: string): void;
196
+ /**
197
+ * A rewritten script module (its tailwind-variants tables) may only be
198
+ * imported by the library: the analysis reads the app's imports of the barrel.
199
+ */
200
+ checkScriptImporters(id: string, importers: Array<string | undefined>): void;
201
+ isClosed(id: string): boolean;
202
+ /**
203
+ * An `undefined` importer has no file (an entry, a `require.context`);
204
+ * `dynamic` means some `import()` of `id`.
205
+ */
206
+ checkImporters(id: string, importers: Array<string | undefined>, dynamic: boolean): void;
207
+ /**
208
+ * Catches graph edges into the library that `check`'s text scan misses,
209
+ * e.g. through an alias (`import { Button } from "@lib"`).
210
+ */
211
+ checkLibraryImport(edge: LibraryImport): void;
212
+ error(): string | undefined;
213
+ };
214
+
215
+ type ComponentOptimizer = ReturnType<typeof createComponentOptimizer>;
216
+
217
+ type Failure = {
218
+ feature: string;
219
+ fallback: string;
220
+ };
221
+
222
+ type RewrittenSource = {
223
+ code: string;
224
+ map: SourceMap;
225
+ };
226
+
227
+ type SourceMap = {
228
+ version: 3;
229
+ sources: string[];
230
+ sourcesContent: string[];
231
+ names: string[];
232
+ mappings: string;
233
+ };
234
+
235
+ /** Writes ASCII bytes: appending a string per segment builds slow ropes. */
236
+ export declare class MappingsBuilder {
237
+ private buffer;
238
+ private length;
239
+ private line;
240
+ private column;
241
+ private genColumn;
242
+ private lineHasSegments;
243
+ private prevGenColumn;
244
+ private prevLine;
245
+ private prevColumn;
246
+ copy(text: string): void;
247
+ replace(content: string, original: string, start: number, end: number): void;
248
+ skip(original: string, start: number, end: number): void;
249
+ private addSegment;
250
+ private reserve;
251
+ toString(): string;
252
+ }
253
+
254
+ type ModuleGraph = {
255
+ getModuleIds(): IterableIterator<string>;
256
+ getModuleInfo(id: string): {
257
+ code?: string | null;
258
+ importers: readonly string[];
259
+ dynamicImporters: readonly string[];
260
+ } | null;
261
+ resolve(source: string, importer: string): Promise<{
262
+ id: string;
263
+ } | null | undefined>;
264
+ };
265
+
266
+ /**
267
+ * The graph doesn't say which specifier made an edge, so importers are lexed
268
+ * for aliases resolving into the library; those edges carry their `specifier`.
269
+ */
270
+ export declare function libraryImports(spec: LibrarySpec, graph: ModuleGraph): Promise<LibraryImport[]>;
271
+
272
+ export declare function listJsAndSvelteFiles(root: string): Promise<string[]>;
273
+
274
+ export declare function requirePackageDir(name: string, from?: string): string;
275
+
276
+ export declare function isLinkedCheckout(root: string): boolean;
277
+
278
+ /** Cache key for a package's contents: real path and version, plus `srcDir` mtimes when linked. */
279
+ export declare function packageSignature(root: string, srcDir: string): Promise<string>;
280
+
281
+ /** Where a name a package's barrel exports is defined. */
282
+ export type PackageExport = {
283
+ /** Direct import path, e.g. `some-library/src/Button/Button.svelte`. */
284
+ path: string;
285
+ name: string;
286
+ };
287
+
288
+ /** Whether `name` can be written unquoted in an import or export specifier. */
289
+ export declare function isIdentifierName(name: string): boolean;
290
+
291
+ /** Barrel exports of package `name`, followed through `index.js` re-export chains to their definitions. */
292
+ export declare function readPackageExports(root: string, { name: packageName, srcDir, barrel: barrelFile, }: {
293
+ name: string;
294
+ srcDir: string;
295
+ barrel: string;
296
+ }): Map<string, PackageExport>;
297
+
298
+ export declare const RE_EXT_SVELTE: RegExp;
299
+
300
+ /** `.css` and the preprocessor files a bundler compiles to CSS. */
301
+ export declare const RE_EXT_STYLESHEET: RegExp;
302
+
303
+ export declare function isSvelteFile(id: string): id is `${string}.svelte`;
304
+
305
+ /** `App.svelte?svelte&type=style&lang.css` -> `App.svelte`. */
306
+ export declare function stripQuery(id: string): string;
307
+
308
+ export declare function errorMessage(error: unknown): string;
309
+
310
+ /**
311
+ * Vite, Rollup and Rolldown plugin that rewrites each component of
312
+ * `library` the app renders for the props it passes: values that never
313
+ * change become literals, and branches that can't run go, along with the
314
+ * components only they render. The app's own components are rewritten
315
+ * too when every call site is in `content`.
316
+ *
317
+ * Runs on production builds only, before Svelte compiles. Rewritten
318
+ * components come with source maps back to their original source. With
319
+ * `styles` in `library`, the CSS a build emits loses the rules of the
320
+ * library's stylesheets that nothing can match. With
321
+ * Tailwind installed, every build (the dev server's included) writes what
322
+ * of the library can render to `node_modules/.svelte-prune/<name>`, for Tailwind
323
+ * to scan instead of the package.
324
+ */
325
+ export declare function sveltePrune(library: LibrarySpec, options?: SveltePruneOptions,
326
+ /** How it names itself in messages; `id` is its name in the bundler. */
327
+ names?: PluginNames & {
328
+ id: string;
329
+ }): Plugin;
330
+
331
+ type AsyncHook = {
332
+ tapPromise(name: string, callback: () => Promise<void>): void;
333
+ };
334
+
335
+ type WebpackCompilation = {
336
+ moduleGraph: {
337
+ getIncomingConnections(module: WebpackModule): Iterable<WebpackConnection>;
338
+ };
339
+ hooks: {
340
+ finishModules: {
341
+ tap(name: string, callback: (modules: Iterable<WebpackModule>) => void): void;
342
+ };
343
+ processAssets: {
344
+ tap(options: {
345
+ name: string;
346
+ stage: number;
347
+ }, callback: (assets: Record<string, unknown>) => void): void;
348
+ };
349
+ };
350
+ getAsset(name: string): {
351
+ source: {
352
+ source(): string | Uint8Array;
353
+ };
354
+ } | undefined;
355
+ updateAsset(name: string, source: unknown): void;
356
+ warnings: {
357
+ push(error: Error): void;
358
+ };
359
+ errors: {
360
+ push(error: Error): void;
361
+ };
362
+ };
363
+
364
+ type Resolver = {
365
+ resolve(context: object, path: string, request: string, resolveContext: object, callback: (error: Error | null, result?: string | false) => void): void;
366
+ };
367
+
368
+ export type WebpackCompiler = {
369
+ options: {
370
+ mode?: string;
371
+ module: {
372
+ rules: unknown[];
373
+ };
374
+ };
375
+ context: string;
376
+ webpack: {
377
+ WebpackError: new (message: string) => Error;
378
+ Compilation: {
379
+ PROCESS_ASSETS_STAGE_OPTIMIZE: number;
380
+ };
381
+ sources: {
382
+ RawSource: new (source: string) => unknown;
383
+ };
384
+ };
385
+ hooks: {
386
+ beforeRun: AsyncHook;
387
+ watchRun: AsyncHook;
388
+ /** webpack 5.40+ and Rspack. */
389
+ shutdown?: {
390
+ tap(name: string, callback: () => void): void;
391
+ };
392
+ thisCompilation: {
393
+ tap(name: string, callback: (compilation: WebpackCompilation) => void): void;
394
+ };
395
+ };
396
+ getInfrastructureLogger(name: string): {
397
+ info(message: string): void;
398
+ warn(message: string): void;
399
+ };
400
+ resolverFactory?: {
401
+ get(type: "normal"): Resolver;
402
+ };
403
+ };
404
+
405
+ /**
406
+ * `svelte-prune` for webpack and Rspack: rewrites each component of `library`
407
+ * the app renders for the props it passes.
408
+ *
409
+ * Runs on production builds only. It adds a loader before `svelte-loader`
410
+ * on `.svelte` files (and on the library's script modules, for its
411
+ * tailwind-variants tables), and fails the build if a module outside
412
+ * `content` imports one of the library's components.
413
+ */
414
+ export declare class SveltePrunePlugin {
415
+ private readonly spec;
416
+ private readonly options;
417
+ /** `plugin` also names webpack's hooks; `loader` is the built loader's path. */
418
+ private readonly names;
419
+ constructor(library: LibrarySpec, options?: SveltePruneOptions, names?: Partial<SveltePrunePlugin["names"]>);
420
+ apply(compiler: WebpackCompiler): void;
421
+ }
422
+
423
+ export type WebpackModule = {
424
+ resource?: unknown;
425
+ /** On `NormalModule`: the loader output. */
426
+ originalSource?: () => {
427
+ source(): string | Buffer;
428
+ } | null | undefined;
429
+ };
430
+
431
+ export type WebpackConnection = {
432
+ originModule?: WebpackModule | null;
433
+ /** `request` is the specifier the import was written with. */
434
+ dependency?: {
435
+ type?: string;
436
+ request?: unknown;
437
+ } | null;
438
+ };
439
+
440
+ /** An unset `mode` defaults to `"production"`. */
441
+ export declare function isProduction(compiler: {
442
+ options: {
443
+ mode?: string;
444
+ };
445
+ }): boolean;
446
+
447
+ /** The loader output of `module`, if it has one as text. */
448
+ export declare function moduleSource(module: WebpackModule): string | undefined;
449
+
450
+ /** The edges into library module `id` from modules with a file. */
451
+ export declare function importEdges(id: string, connections: Iterable<WebpackConnection>): LibraryImport[];
package/internal.js ADDED
@@ -0,0 +1 @@
1
+ import{D,Ne}from"./index-xt8m9vw2.js";import{we,De}from"./index-34y0pc8q.js";import{Ee,ke,Ae,Ce}from"./index-6g116bmb.js";import{Te}from"./index-zq01wexv.js";import{f,$e,me,Oe}from"./index-wkcyw7a9.js";import{_}from"./index-4960rqxx.js";import{p,Ge,ce,F,O,o,pe,u,E,N,He,k}from"./index-4992cggh.js";export{Oe as MappingsBuilder,F as RE_EXT_STYLESHEET,ce as RE_EXT_SVELTE,Ce as SveltePrunePlugin,Te as collectLibraryImports,pe as errorMessage,Ae as importEdges,$e as isIdentifierName,He as isLinkedCheckout,Ee as isProduction,O as isSvelteFile,_ as lexComponent,p as lexImportsExports,Ge as lexStrings,we as libraryImports,u as libraryPaths,E as listJsAndSvelteFiles,Ne as loader,ke as moduleSource,D as optimizerRegistry,k as packageSignature,me as readPackageExports,N as requirePackageDir,o as stripQuery,De as sveltePrune,f as walk};
package/loader.js ADDED
@@ -0,0 +1 @@
1
+ import{D,Ne}from"./index-xt8m9vw2.js";export{Ne as default,D as optimizerRegistry};
package/package.json CHANGED
@@ -1,8 +1,58 @@
1
1
  {
2
2
  "name": "svelte-prune",
3
- "version": "0.0.0",
4
- "description": "Placeholder package reserving the \"svelte-prune\" name.",
3
+ "version": "0.10.1",
5
4
  "license": "MIT",
5
+ "description": "Ship only the Svelte library code your app renders.",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
7
- "main": "index.ts"
7
+ "type": "module",
8
+ "main": "./index.js",
9
+ "types": "./index.d.ts",
10
+ "sideEffects": false,
11
+ "engines": {
12
+ "node": ">=22"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/metonym/svelte-prune.git"
17
+ },
18
+ "homepage": "https://github.com/metonym/svelte-prune",
19
+ "bugs": "https://github.com/metonym/svelte-prune/issues",
20
+ "keywords": [
21
+ "svelte",
22
+ "specialize",
23
+ "dead-code-elimination",
24
+ "tree-shaking",
25
+ "partial-evaluation",
26
+ "vite",
27
+ "webpack",
28
+ "rspack",
29
+ "zero-dependency"
30
+ ],
31
+ "exports": {
32
+ ".": {
33
+ "types": "./index.d.ts",
34
+ "import": "./index.js",
35
+ "default": "./index.js"
36
+ },
37
+ "./vite": {
38
+ "types": "./vite.d.ts",
39
+ "import": "./vite.js",
40
+ "default": "./vite.js"
41
+ },
42
+ "./webpack": {
43
+ "types": "./webpack.d.ts",
44
+ "import": "./webpack.js",
45
+ "default": "./webpack.js"
46
+ },
47
+ "./internal": {
48
+ "types": "./internal.d.ts",
49
+ "import": "./internal.js",
50
+ "default": "./internal.js"
51
+ },
52
+ "./internal/analysis": {
53
+ "types": "./internal-analysis.d.ts",
54
+ "import": "./internal-analysis.js",
55
+ "default": "./internal-analysis.js"
56
+ }
57
+ }
8
58
  }
@@ -0,0 +1 @@
1
+ import{_e}from"./index-gdmk0qve.js";import{w}from"./index-4992cggh.js";import{mkdir as u,readdir as f,readFile as m,rm as d,writeFile as g}from"node:fs/promises";import s from"node:path";var y=/<script\b[^>]*\b(?:module|context=["']module["'])/;function h(t,e){return s.join(t,"node_modules",".svelte-prune",e.name)}var R=/\.d\.[cm]?ts$|\.map$/;async function l(t){return(await f(t,{recursive:!0,withFileTypes:!0})).filter((e)=>e.isFile()).map((e)=>s.relative(t,s.join(e.parentPath,e.name)).split(s.sep).join("/"))}async function v(t,e){let n=w(t.src)??t.src,o=!e||await _e(t)!==void 0,i=new Map;return await Promise.all((await l(n)).map(async(r)=>{if(R.test(r))return;let a=s.join(n,r),c=e?.sources.get(a)?.code;if(c!==void 0){i.set(r,c);return}let p=await m(a,"utf8");if(o||!r.endsWith(".svelte")||e?.liveComponents.has(r)||y.test(p))i.set(r,p)})),i}async function P(t,e){let n=[];try{n=await l(t)}catch{}await Promise.all(n.filter((i)=>!e.has(i)).map((i)=>d(s.join(t,i),{force:!0})));let o=new Set(n);await Promise.all([...e].map(async([i,r])=>{let a=s.join(t,i);if(o.has(i))try{if(await m(a,"utf8")===r)return}catch{}await u(s.dirname(a),{recursive:!0}),await g(a,r)}))}async function F(t,e,n){await P(h(e,t.spec),await v(t,n))}export{F as writeTailwindSources};
@@ -0,0 +1 @@
1
+ import{_e,Ye}from"./index-gdmk0qve.js";export{_e as scriptRendersComponents,Ye as specializeTables};
package/vite.d.ts ADDED
@@ -0,0 +1,119 @@
1
+ import type { Plugin } from "vite";
2
+
3
+ /**
4
+ * Vite, Rollup and Rolldown plugin that rewrites each component of
5
+ * `library` the app renders for the props it passes: values that never
6
+ * change become literals, and branches that can't run go, along with the
7
+ * components only they render. The app's own components are rewritten
8
+ * too when every call site is in `content`.
9
+ *
10
+ * Runs on production builds only, before Svelte compiles. Rewritten
11
+ * components come with source maps back to their original source. With
12
+ * `styles` in `library`, the CSS a build emits loses the rules of the
13
+ * library's stylesheets that nothing can match. With
14
+ * Tailwind installed, every build (the dev server's included) writes what
15
+ * of the library can render to `node_modules/.svelte-prune/<name>`, for Tailwind
16
+ * to scan instead of the package.
17
+ */
18
+ export declare function sveltePrune(library: LibrarySpec, options?: SveltePruneOptions,
19
+ /** How it names itself in messages; `id` is its name in the bundler. */
20
+ names?: PluginNames & {
21
+ id: string;
22
+ }): Plugin;
23
+
24
+ type ClassTokens = {
25
+ /** Text that may name a class contains it (`"x--"`). */
26
+ marker: string;
27
+ text(text: string): string[];
28
+ };
29
+
30
+ type LibraryClassTokens = ClassTokens & {
31
+ script(code: string, into: Set<string>): void;
32
+ };
33
+
34
+ type LibrarySpec = {
35
+ /** The package apps import: `"my-library"`. */
36
+ name: string;
37
+ /** The directory of its modules in the package: `"src"`. */
38
+ srcDir: string;
39
+ /** Its barrel, in `srcDir`: `"index.js"`. */
40
+ barrel: string;
41
+ /** Packages whose exports are components (an icon set): passing one as a prop passes an object. */
42
+ componentPackages: readonly string[];
43
+ /** Its context key prefix (`"my-library:"`): an app module holding one may use its contexts. */
44
+ contextKeyPrefix: string;
45
+ /** Names the library in messages: `"My Library"`. */
46
+ label: string;
47
+ /** Names the tool in messages, and starts each warning and error: `"my-plugin"`. */
48
+ tool: string;
49
+ /**
50
+ * Reads class names, for pruning the library's styles: `text` a string
51
+ * containing `marker`, `script` a whole script module. Omit to read none,
52
+ * or, with `styles`, every run of word characters and hyphens.
53
+ */
54
+ classTokens?: LibraryClassTokens;
55
+ /**
56
+ * The library's stylesheets. A production build drops the rules in the
57
+ * CSS it emits that need a class these stylesheets define and that
58
+ * nothing can render: no live component, none of the library's script
59
+ * modules, nothing in `content`. Omit to leave CSS as it is.
60
+ */
61
+ styles?: {
62
+ /**
63
+ * Files in installed packages, each `"<package>/<path>"`, where `*`
64
+ * matches within a path segment: `"my-library/css/*.css"`.
65
+ */
66
+ stylesheets: readonly string[];
67
+ /** Classes to keep whatever renders: ones the app's page sets (`"my-body"`). */
68
+ keep?: readonly string[];
69
+ };
70
+ /**
71
+ * `true` for a library whose classes are Tailwind's: its tailwind-variants
72
+ * tables are rewritten, and with Tailwind installed, every build (the dev
73
+ * server's included) writes what of it can render to
74
+ * `node_modules/.svelte-prune/<name>`, for Tailwind to scan. @default false
75
+ */
76
+ tailwind?: boolean;
77
+ };
78
+
79
+ type SveltePruneOptions = {
80
+ /**
81
+ * Globs (relative to the project root) of every file that renders the
82
+ * library's components; a module outside them that imports one fails the
83
+ * build. Components imported from script, Markdown, MDX or Astro files
84
+ * keep every prop value. `node_modules` is skipped unless a pattern names it.
85
+ * @default ["src/**\/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"]
86
+ */
87
+ content?: string[];
88
+ /**
89
+ * Replace an `{#if}` whose only live branch is known with that branch.
90
+ * Svelte 5 only: Svelte 3/4 render whitespace differently without the block.
91
+ * @default true when the installed Svelte is 5 or later
92
+ */
93
+ unwrap?: boolean;
94
+ /** Skip the per-build summary. @default false */
95
+ silent?: boolean;
96
+ /**
97
+ * Print what each build rewrote: edits, child components no longer rendered
98
+ * or bundled, and each call site's prop values. Independent of `silent`.
99
+ * @default false
100
+ */
101
+ report?: boolean;
102
+ /**
103
+ * Selectors of the library's stylesheets (`styles` in the `LibrarySpec`)
104
+ * to keep whatever renders, for classes the app builds from data at
105
+ * runtime: a class (`"x--tag--red"`, with or without its `.`) keeps every
106
+ * selector it's in, a RegExp every selector it matches (`/^\.x--tag--/`).
107
+ */
108
+ safelist?: Array<string | RegExp>;
109
+ };
110
+
111
+ type PluginNames = {
112
+ plugin: string;
113
+ failure: Failure;
114
+ };
115
+
116
+ type Failure = {
117
+ feature: string;
118
+ fallback: string;
119
+ };
package/vite.js ADDED
@@ -0,0 +1 @@
1
+ import{De}from"./index-34y0pc8q.js";export{De as sveltePrune};