svelte-prune 0.0.0 → 0.10.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/webpack.d.ts ADDED
@@ -0,0 +1,195 @@
1
+ type AsyncHook = {
2
+ tapPromise(name: string, callback: () => Promise<void>): void;
3
+ };
4
+
5
+ type WebpackCompilation = {
6
+ moduleGraph: {
7
+ getIncomingConnections(module: WebpackModule): Iterable<WebpackConnection>;
8
+ };
9
+ hooks: {
10
+ finishModules: {
11
+ tap(name: string, callback: (modules: Iterable<WebpackModule>) => void): void;
12
+ };
13
+ processAssets: {
14
+ tap(options: {
15
+ name: string;
16
+ stage: number;
17
+ }, callback: (assets: Record<string, unknown>) => void): void;
18
+ };
19
+ };
20
+ getAsset(name: string): {
21
+ source: {
22
+ source(): string | Uint8Array;
23
+ };
24
+ } | undefined;
25
+ updateAsset(name: string, source: unknown): void;
26
+ warnings: {
27
+ push(error: Error): void;
28
+ };
29
+ errors: {
30
+ push(error: Error): void;
31
+ };
32
+ };
33
+
34
+ type Resolver = {
35
+ resolve(context: object, path: string, request: string, resolveContext: object, callback: (error: Error | null, result?: string | false) => void): void;
36
+ };
37
+
38
+ export type WebpackCompiler = {
39
+ options: {
40
+ mode?: string;
41
+ module: {
42
+ rules: unknown[];
43
+ };
44
+ };
45
+ context: string;
46
+ webpack: {
47
+ WebpackError: new (message: string) => Error;
48
+ Compilation: {
49
+ PROCESS_ASSETS_STAGE_OPTIMIZE: number;
50
+ };
51
+ sources: {
52
+ RawSource: new (source: string) => unknown;
53
+ };
54
+ };
55
+ hooks: {
56
+ beforeRun: AsyncHook;
57
+ watchRun: AsyncHook;
58
+ /** webpack 5.40+ and Rspack. */
59
+ shutdown?: {
60
+ tap(name: string, callback: () => void): void;
61
+ };
62
+ thisCompilation: {
63
+ tap(name: string, callback: (compilation: WebpackCompilation) => void): void;
64
+ };
65
+ };
66
+ getInfrastructureLogger(name: string): {
67
+ info(message: string): void;
68
+ warn(message: string): void;
69
+ };
70
+ resolverFactory?: {
71
+ get(type: "normal"): Resolver;
72
+ };
73
+ };
74
+
75
+ /**
76
+ * `svelte-prune` for webpack and Rspack: rewrites each component of `library`
77
+ * the app renders for the props it passes.
78
+ *
79
+ * Runs on production builds only. It adds a loader before `svelte-loader`
80
+ * on `.svelte` files (and on the library's script modules, for its
81
+ * tailwind-variants tables), and fails the build if a module outside
82
+ * `content` imports one of the library's components.
83
+ */
84
+ export declare class SveltePrunePlugin {
85
+ private readonly spec;
86
+ private readonly options;
87
+ /** `plugin` also names webpack's hooks; `loader` is the built loader's path. */
88
+ private readonly names;
89
+ constructor(library: LibrarySpec, options?: SveltePruneOptions, names?: Partial<SveltePrunePlugin["names"]>);
90
+ apply(compiler: WebpackCompiler): void;
91
+ }
92
+
93
+ type ClassTokens = {
94
+ /** Text that may name a class contains it (`"x--"`). */
95
+ marker: string;
96
+ text(text: string): string[];
97
+ };
98
+
99
+ type LibraryClassTokens = ClassTokens & {
100
+ script(code: string, into: Set<string>): void;
101
+ };
102
+
103
+ type LibrarySpec = {
104
+ /** The package apps import: `"my-library"`. */
105
+ name: string;
106
+ /** The directory of its modules in the package: `"src"`. */
107
+ srcDir: string;
108
+ /** Its barrel, in `srcDir`: `"index.js"`. */
109
+ barrel: string;
110
+ /** Packages whose exports are components (an icon set): passing one as a prop passes an object. */
111
+ componentPackages: readonly string[];
112
+ /** Its context key prefix (`"my-library:"`): an app module holding one may use its contexts. */
113
+ contextKeyPrefix: string;
114
+ /** Names the library in messages: `"My Library"`. */
115
+ label: string;
116
+ /** Names the tool in messages, and starts each warning and error: `"my-plugin"`. */
117
+ tool: string;
118
+ /**
119
+ * Reads class names, for pruning the library's styles: `text` a string
120
+ * containing `marker`, `script` a whole script module. Omit to read none,
121
+ * or, with `styles`, every run of word characters and hyphens.
122
+ */
123
+ classTokens?: LibraryClassTokens;
124
+ /**
125
+ * The library's stylesheets. A production build drops the rules in the
126
+ * CSS it emits that need a class these stylesheets define and that
127
+ * nothing can render: no live component, none of the library's script
128
+ * modules, nothing in `content`. Omit to leave CSS as it is.
129
+ */
130
+ styles?: {
131
+ /**
132
+ * Files in installed packages, each `"<package>/<path>"`, where `*`
133
+ * matches within a path segment: `"my-library/css/*.css"`.
134
+ */
135
+ stylesheets: readonly string[];
136
+ /** Classes to keep whatever renders: ones the app's page sets (`"my-body"`). */
137
+ keep?: readonly string[];
138
+ };
139
+ /**
140
+ * `true` for a library whose classes are Tailwind's: its tailwind-variants
141
+ * tables are rewritten, and with Tailwind installed, every build (the dev
142
+ * server's included) writes what of it can render to
143
+ * `node_modules/.svelte-prune/<name>`, for Tailwind to scan. @default false
144
+ */
145
+ tailwind?: boolean;
146
+ };
147
+
148
+ type SveltePruneOptions = {
149
+ /**
150
+ * Globs (relative to the project root) of every file that renders the
151
+ * library's components; a module outside them that imports one fails the
152
+ * build. Components imported from script, Markdown, MDX or Astro files
153
+ * keep every prop value. `node_modules` is skipped unless a pattern names it.
154
+ * @default ["src/**\/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"]
155
+ */
156
+ content?: string[];
157
+ /**
158
+ * Replace an `{#if}` whose only live branch is known with that branch.
159
+ * Svelte 5 only: Svelte 3/4 render whitespace differently without the block.
160
+ * @default true when the installed Svelte is 5 or later
161
+ */
162
+ unwrap?: boolean;
163
+ /** Skip the per-build summary. @default false */
164
+ silent?: boolean;
165
+ /**
166
+ * Print what each build rewrote: edits, child components no longer rendered
167
+ * or bundled, and each call site's prop values. Independent of `silent`.
168
+ * @default false
169
+ */
170
+ report?: boolean;
171
+ /**
172
+ * Selectors of the library's stylesheets (`styles` in the `LibrarySpec`)
173
+ * to keep whatever renders, for classes the app builds from data at
174
+ * runtime: a class (`"x--tag--red"`, with or without its `.`) keeps every
175
+ * selector it's in, a RegExp every selector it matches (`/^\.x--tag--/`).
176
+ */
177
+ safelist?: Array<string | RegExp>;
178
+ };
179
+
180
+ type WebpackModule = {
181
+ resource?: unknown;
182
+ /** On `NormalModule`: the loader output. */
183
+ originalSource?: () => {
184
+ source(): string | Buffer;
185
+ } | null | undefined;
186
+ };
187
+
188
+ type WebpackConnection = {
189
+ originModule?: WebpackModule | null;
190
+ /** `request` is the specifier the import was written with. */
191
+ dependency?: {
192
+ type?: string;
193
+ request?: unknown;
194
+ } | null;
195
+ };
package/webpack.js ADDED
@@ -0,0 +1 @@
1
+ import{Ce}from"./index-z8hj1913.js";import"./index-v520xws8.js";export{Ce as SveltePrunePlugin};
package/index.ts DELETED
@@ -1 +0,0 @@
1
- export {};