svelte-prune 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +531 -2
- package/analysis-ah6ws3px.js +1 -0
- package/index-17bw6v3k.js +2 -0
- package/index-45rna84h.js +9 -0
- package/index-c4dndsx9.js +2 -0
- package/index-fhqjbrb9.js +3 -0
- package/index-jxng1156.js +5 -0
- package/index-k2z70ex7.js +22 -0
- package/index-pykm4v5k.js +2 -0
- package/index-v520xws8.js +2 -0
- package/index-z8hj1913.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 +56 -4
- package/tailwind-sources-8wvzbxes.js +1 -0
- package/variant-tables-zha5f3x0.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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Eric Liu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,532 @@
|
|
|
1
|
-
#
|
|
1
|
+
# svelte-prune
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Ship only the Svelte library code your app renders.**
|
|
4
|
+
|
|
5
|
+
A component library's `Button` handles every `kind`, `size` and state any app might ask for, and your bundle carries all of it. svelte-prune reads how your app uses the library before the build, then hands Svelte a copy of each component rewritten for the props it actually receives: branches that can't run, the components only they render, and the CSS only they use are cut from the build.
|
|
6
|
+
|
|
7
|
+
Zero dependencies. Production builds in Vite, Rollup, Rolldown, webpack and Rspack, for Svelte 3, 4 and 5 (runes included), with source maps back to the original components.
|
|
8
|
+
|
|
9
|
+
## Results
|
|
10
|
+
|
|
11
|
+
A realistic page per library, built with Vite with and without svelte-prune ([`examples/`](examples/README.md)), gzipped:
|
|
12
|
+
|
|
13
|
+
| Library | Style | JS smaller by | CSS smaller by |
|
|
14
|
+
| :---------------------------- | :------------------------- | :------------ | :------------- |
|
|
15
|
+
| flowbite-svelte | Tailwind variants | 37.8% | 60.9% |
|
|
16
|
+
| carbon-components-svelte | branches on props | 34.1% | 70.8% |
|
|
17
|
+
| svelte-5-ui-lib | Tailwind variants | 22.9% | 71.7% |
|
|
18
|
+
| @sveltestrap/sveltestrap | branches on props | 22.0% | 46.8% |
|
|
19
|
+
| svelte-ux | Tailwind | 7.4% | 35.5% |
|
|
20
|
+
| bits-ui | headless, state in classes | 2.2% | (no CSS) |
|
|
21
|
+
| @skeletonlabs/skeleton-svelte | headless, state machines | 0% | 0% |
|
|
22
|
+
|
|
23
|
+
CSS is Tailwind's output for the Tailwind libraries ([Tailwind](#tailwind)) and the library's own stylesheet for Carbon and sveltestrap ([Stylesheets](#stylesheets)). Libraries whose markup branches on their props gain the most, and so do those whose tailwind-variants tables hold every variant's classes. Headless libraries that keep their state in classes or hand their props to a state machine leave little to fold.
|
|
24
|
+
|
|
25
|
+
Every page renders and behaves identically in the browser, and 7,669 generated apps across these libraries render identically before and after ([Correctness](#correctness)).
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
bun i -d svelte-prune
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## What it removes
|
|
34
|
+
|
|
35
|
+
Each diff is the library component as svelte-prune rewrites it for the app in its first comment (Svelte 5 output; on Svelte 3 and 4 a live branch keeps its `{#if true}` wrapper).
|
|
36
|
+
|
|
37
|
+
**Branches that can't render, and the components only they render.** `Icon` is no longer bundled:
|
|
38
|
+
|
|
39
|
+
```diff
|
|
40
|
+
<!-- <Button kind="ghost">Save</Button> <Button kind="ghost" size="sm">Cancel</Button> -->
|
|
41
|
+
<script>
|
|
42
|
+
import Icon from "./Icon.svelte";
|
|
43
|
+
- export let kind = "primary";
|
|
44
|
+
export let size = "md";
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
-{#if kind === "danger"}
|
|
48
|
+
- <button class="btn danger {size}"><Icon name="warning" /><slot /></button>
|
|
49
|
+
-{:else if kind === "ghost"}
|
|
50
|
+
- <button class="btn ghost {size}"><slot /></button>
|
|
51
|
+
-{:else}
|
|
52
|
+
- <button class="btn primary {size}"><slot /></button>
|
|
53
|
+
-{/if}
|
|
54
|
+
+<button class="btn ghost {size}"><slot /></button>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Props that never change become literals.**
|
|
58
|
+
|
|
59
|
+
```diff
|
|
60
|
+
<!-- <Button size="sm">Save</Button> <Button size="sm">Cancel</Button> -->
|
|
61
|
+
<script>
|
|
62
|
+
- export let size = "md";
|
|
63
|
+
- export let disabled = false;
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
-<button class="btn btn-{size}" {disabled}><slot /></button>
|
|
67
|
+
+<button class="btn btn-{"sm"}" disabled={false}><slot /></button>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Defaults no call site overrides**, and the markup that only renders for other values:
|
|
71
|
+
|
|
72
|
+
```diff
|
|
73
|
+
<!-- <Field label="Name" /> -->
|
|
74
|
+
<script>
|
|
75
|
+
- export let label = "";
|
|
76
|
+
- export let helperText = "";
|
|
77
|
+
- export let invalid = false;
|
|
78
|
+
- export let id = "field";
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
-<label for={id}>{label}</label>
|
|
82
|
+
-<input {id} aria-invalid={invalid} />
|
|
83
|
+
-{#if helperText}<p class="helper">{helperText}</p>{/if}
|
|
84
|
+
+<label for={"field"}>{"Name"}</label>
|
|
85
|
+
+<input id={"field"} aria-invalid={false} />
|
|
86
|
+
+{#if false}<!---->{/if}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Events nobody listens to.** A forwarded `on:focus` and a `dispatch("change")` go; `on:click` has a listener and stays. `checked`, which no call site passes, becomes the component's own variable:
|
|
90
|
+
|
|
91
|
+
```diff
|
|
92
|
+
<!-- <Toggle on:click={log}>Dark mode</Toggle> -->
|
|
93
|
+
<script>
|
|
94
|
+
import { createEventDispatcher } from "svelte";
|
|
95
|
+
- export let checked = false;
|
|
96
|
+
+ let checked = false;
|
|
97
|
+
const dispatch = createEventDispatcher();
|
|
98
|
+
function toggle() {
|
|
99
|
+
checked = !checked;
|
|
100
|
+
- dispatch("change", checked);
|
|
101
|
+
}
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
-<button on:click on:focus on:click={toggle} aria-pressed={checked}><slot /></button>
|
|
105
|
+
+<button on:click on:click={toggle} aria-pressed={checked}><slot /></button>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**`$$restProps` spreads that carry nothing**, onto components:
|
|
109
|
+
|
|
110
|
+
```diff
|
|
111
|
+
<!-- <Link href="/docs" icon="arrow">Docs</Link> -->
|
|
112
|
+
-<a {href}><slot />{#if icon}<Icon name={icon} {...$$restProps} />{/if}</a>
|
|
113
|
+
+<a href={"/docs"}><slot /><Icon name={"arrow"} /></a>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Runes and snippets.** A snippet prop no call site passes is `undefined`:
|
|
117
|
+
|
|
118
|
+
```diff
|
|
119
|
+
<!-- <Card title="Usage">Body</Card> -->
|
|
120
|
+
<script>
|
|
121
|
+
let { title, variant = "outlined", header, children } = $props();
|
|
122
|
+
</script>
|
|
123
|
+
|
|
124
|
+
-<div class="card {variant}">
|
|
125
|
+
- {#if header}
|
|
126
|
+
- {@render header()}
|
|
127
|
+
- {:else if title}
|
|
128
|
+
- <h2>{title}</h2>
|
|
129
|
+
- {/if}
|
|
130
|
+
+<div class="card {"outlined"}">
|
|
131
|
+
+ <h2>{"Usage"}</h2>
|
|
132
|
+
{@render children?.()}
|
|
133
|
+
</div>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Through your own components.** A wrapper's props come from its call sites, so `<Confirm tone="danger">` reaches the `Button` inside it:
|
|
137
|
+
|
|
138
|
+
```diff
|
|
139
|
+
<!-- src/Confirm.svelte, rendered only as <Confirm tone="danger">Delete</Confirm> -->
|
|
140
|
+
-<Button kind={tone}><slot /></Button>
|
|
141
|
+
+<Button kind={"danger"}><slot /></Button>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```diff
|
|
145
|
+
<!-- the library's Button.svelte -->
|
|
146
|
+
-{#if kind === "danger"}
|
|
147
|
+
- <button class="danger"><slot /></button>
|
|
148
|
+
-{:else}
|
|
149
|
+
- <button class="primary"><slot /></button>
|
|
150
|
+
-{/if}
|
|
151
|
+
+<button class="danger"><slot /></button>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**tailwind-variants keys no live call selects**, with `tailwind: true` in the [`LibrarySpec`](#libraryspec). Tailwind, scanning what svelte-prune writes, leaves those classes out of your CSS too ([Tailwind](#tailwind)):
|
|
155
|
+
|
|
156
|
+
```diff
|
|
157
|
+
// <Badge color="green">Active</Badge> <Badge color="red">Failed</Badge>
|
|
158
|
+
export const badge = tv({
|
|
159
|
+
base: "rounded px-2",
|
|
160
|
+
variants: {
|
|
161
|
+
color: {
|
|
162
|
+
- gray: "bg-gray-100 text-gray-800",
|
|
163
|
+
red: "bg-red-100 text-red-800",
|
|
164
|
+
green: "bg-green-100 text-green-800",
|
|
165
|
+
},
|
|
166
|
+
- size: { sm: "text-xs", md: "text-sm", lg: "text-base" },
|
|
167
|
+
+ size: { md: "text-sm" },
|
|
168
|
+
},
|
|
169
|
+
defaultVariants: { color: "gray", size: "md" },
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Library stylesheet rules nothing renders**, with `styles` in the `LibrarySpec` ([Stylesheets](#stylesheets)):
|
|
174
|
+
|
|
175
|
+
```diff
|
|
176
|
+
/* <Button>Save</Button>, whose class is btn-{kind} */
|
|
177
|
+
.btn { padding: 4px; }
|
|
178
|
+
.btn-primary { background: blue; }
|
|
179
|
+
-.btn-danger { background: red; }
|
|
180
|
+
-.btn-ghost { background: none; }
|
|
181
|
+
-.btn-danger:hover { background: darkred; }
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Usage
|
|
185
|
+
|
|
186
|
+
### Vite, Rollup and Rolldown
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
// vite.config.ts
|
|
190
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
191
|
+
import { sveltePrune } from "svelte-prune/vite";
|
|
192
|
+
|
|
193
|
+
const library = {
|
|
194
|
+
name: "my-library", // the package your app imports
|
|
195
|
+
srcDir: "src", // where its .svelte files are, in the package
|
|
196
|
+
barrel: "index.js", // its entry, in srcDir
|
|
197
|
+
componentPackages: [], // packages whose exports are components (icon sets)
|
|
198
|
+
contextKeyPrefix: "my-library:", // what its context keys start with
|
|
199
|
+
label: "My Library", // names it in messages
|
|
200
|
+
tool: "svelte-prune", // starts every warning and error
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export default {
|
|
204
|
+
plugins: [sveltePrune(library), svelte()],
|
|
205
|
+
};
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### webpack and Rspack
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
// webpack.config.js
|
|
212
|
+
import { SveltePrunePlugin } from "svelte-prune/webpack";
|
|
213
|
+
|
|
214
|
+
export default {
|
|
215
|
+
plugins: [new SveltePrunePlugin(library)],
|
|
216
|
+
};
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
It adds a loader that runs before `svelte-loader` on `.svelte` files.
|
|
220
|
+
|
|
221
|
+
### Tailwind
|
|
222
|
+
|
|
223
|
+
Tailwind generates a utility for every class string it scans, and a library's setup has it scan the package (`@source "../node_modules/my-library/dist"`). For a library with `tailwind: true` in its [`LibrarySpec`](#libraryspec), and with Tailwind installed, every build writes what of the library can render to `node_modules/.svelte-prune/<name>`: every file but the components that can't render, as svelte-prune rewrote them (components and tailwind-variants tables). Scan that instead, with Tailwind v4's `@source`:
|
|
224
|
+
|
|
225
|
+
```css
|
|
226
|
+
@source "../node_modules/.svelte-prune/my-library";
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
or a Tailwind v3 `content` glob: `"./node_modules/.svelte-prune/my-library/**/*.{svelte,js}"`. The dev server and development builds write the library as it is, so their CSS has every class.
|
|
230
|
+
|
|
231
|
+
### Stylesheets
|
|
232
|
+
|
|
233
|
+
A library that ships its own CSS (Carbon's `css/white.css`, Bootstrap for sveltestrap) can name it in `styles`:
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
const library = {
|
|
237
|
+
// …
|
|
238
|
+
styles: { stylesheets: ["my-library/css/*.css"] },
|
|
239
|
+
};
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Every production build then removes, from the CSS it emits, the rules that need a class those stylesheets define and that nothing can render. A class stays when a live component can render it under the app's props (a template with a part it can't evaluate keeps every class it could build: `btn-{size}` keeps each `btn-` class), when one of the library's script modules names it, when a file in `content` names it, or when `styles.keep` or the `safelist` option names it. Classes the stylesheets don't define (the app's own, Svelte's scoping classes, other packages') never remove a rule. A selector inside `:not()` or `:has()` doesn't need its classes; an `:is()` list stays if any branch can match.
|
|
243
|
+
|
|
244
|
+
`classTokens` says how to read the library's class names. Without it, every run of word characters and hyphens is a class, which keeps more than a namespaced library needs: a `startsWith("x--")` in its code would keep every `x--` class. A library whose classes share a prefix should pass its own:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
classTokens: {
|
|
248
|
+
marker: "x--",
|
|
249
|
+
text: (text) => [...text.matchAll(/(?<![\w-])x--[\w-]+/g)].map(([t]) => `.${t}`),
|
|
250
|
+
script(code, into) {
|
|
251
|
+
for (const [t] of code.matchAll(/x--[\w-]+/g)) into.add(`.${t}`);
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Once those rules are gone, the custom properties (`--x`) and `@keyframes` the stylesheets define go too when nothing reads them: no `var()` or animation left in the emitted CSS, and no file in `content` or source of the library naming them (a script may read one, or build its name, as in `` `--tone-${t}` ``, which keeps every `--tone-` property). Only a class those tokens can read is ever removed. Classes the app builds from data at runtime are the one thing it can't see: list them, or a RegExp for their selectors, in `safelist`.
|
|
257
|
+
|
|
258
|
+
## API reference
|
|
259
|
+
|
|
260
|
+
svelte-prune has no CLI: it runs inside your bundler (`svelte-prune/vite`, `svelte-prune/webpack`), or from your own script with `specializeFiles` (`svelte-prune`). Each entry ships its own types:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import {
|
|
264
|
+
type LibrarySpec,
|
|
265
|
+
type SveltePruneOptions,
|
|
266
|
+
specializeFiles,
|
|
267
|
+
} from "svelte-prune";
|
|
268
|
+
import type { Failure, SpecializedComponents } from "svelte-prune";
|
|
269
|
+
import { sveltePrune } from "svelte-prune/vite";
|
|
270
|
+
import { SveltePrunePlugin, type WebpackCompiler } from "svelte-prune/webpack";
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### `sveltePrune(library, options?, names?)`
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
import { sveltePrune } from "svelte-prune/vite";
|
|
277
|
+
|
|
278
|
+
function sveltePrune(
|
|
279
|
+
library: LibrarySpec,
|
|
280
|
+
options?: SveltePruneOptions,
|
|
281
|
+
names?: PluginNames & { id: string },
|
|
282
|
+
): Plugin;
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
A Vite, Rollup and Rolldown plugin. Put it before the Svelte plugin.
|
|
286
|
+
|
|
287
|
+
- Rewrites on `vite build` only (`--watch` included), never on the dev server, which runs only to write the library as it is for [Tailwind](#tailwind) (`tailwind: true`). Rollup and Rolldown have no dev server: add it only to production configs there.
|
|
288
|
+
- `buildStart` reads `content`, resolving aliased `.svelte` imports (`$lib/Card.svelte`) with the bundler. A watch rebuild where nothing in `content` changed reuses the last analysis.
|
|
289
|
+
- `load` serves the rewritten components, with source maps; `transform` and `buildEnd` check the module graph and fail the build when a module the analysis didn't read imports the library (see [Errors](#warnings-and-errors)).
|
|
290
|
+
|
|
291
|
+
### `new SveltePrunePlugin(library, options?, names?)`
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
import { SveltePrunePlugin } from "svelte-prune/webpack";
|
|
295
|
+
|
|
296
|
+
class SveltePrunePlugin {
|
|
297
|
+
constructor(
|
|
298
|
+
library: LibrarySpec,
|
|
299
|
+
options?: SveltePruneOptions,
|
|
300
|
+
names?: Partial<PluginNames & { loader: string }>,
|
|
301
|
+
);
|
|
302
|
+
apply(compiler: WebpackCompiler): void;
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
A webpack 5 and Rspack plugin. It rewrites nothing unless `mode` is `"production"` (an unset `mode` counts); other modes only write the library as it is for [Tailwind](#tailwind) (`tailwind: true`). It adds a pre-loader on `.svelte` files and the library's script modules, so `svelte-loader` compiles the rewritten source wherever the plugin sits in `plugins`, analyzes `content` on `beforeRun` and `watchRun`, and checks the module graph on `finishModules`.
|
|
307
|
+
|
|
308
|
+
### `LibrarySpec`
|
|
309
|
+
|
|
310
|
+
Describes the library to rewrite. Every field but `classTokens`, `styles` and `tailwind` is required.
|
|
311
|
+
|
|
312
|
+
| Field | Type | |
|
|
313
|
+
| :------------------ | :------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
314
|
+
| `name` | `string` | The package apps import: `"my-library"`. |
|
|
315
|
+
| `srcDir` | `string` | The directory of its `.svelte` files in the package: `"src"`. |
|
|
316
|
+
| `barrel` | `string` | Its entry, relative to `srcDir`: `"index.js"`. |
|
|
317
|
+
| `componentPackages` | `readonly string[]` | Packages whose exports are components (an icon set), so passing one as a prop passes an object. |
|
|
318
|
+
| `contextKeyPrefix` | `string` | What its context keys start with (`"my-library:"`): an app module that holds such a string may set or read its contexts. |
|
|
319
|
+
| `label` | `string` | Names the library in messages: `"My Library"`. |
|
|
320
|
+
| `tool` | `string` | Starts every warning and error: `"svelte-prune"`. |
|
|
321
|
+
| `classTokens` | `{ marker, text, script }` | Optional. How to read the library's class names: `text` returns the classes (`.x--a`) in a string that contains `marker`, `script` adds those a whole script module names. Without it, a library with `styles` reads every run of word characters and hyphens. See [Stylesheets](#stylesheets). |
|
|
322
|
+
| `styles` | `{ stylesheets, keep? }` | Optional. `stylesheets`: the library's CSS, as `"<package>/<path>"` with `*` matching within a path segment. `keep`: classes always kept. With it, production builds prune those stylesheets' rules from the CSS they emit (see [Stylesheets](#stylesheets)). |
|
|
323
|
+
| `tailwind` | `boolean` | Optional, `false` by default. `true` for a library whose classes are Tailwind's: its tailwind-variants tables are rewritten, and with Tailwind installed, builds write what of it can render for [Tailwind](#tailwind) to scan, the dev server's and non-production webpack builds included. Without it, the analysis never loads that code, and the plugins skip those builds entirely. |
|
|
324
|
+
|
|
325
|
+
### `SveltePruneOptions`
|
|
326
|
+
|
|
327
|
+
| Option | Default | |
|
|
328
|
+
| :--------- | :--------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
329
|
+
| `content` | `["src/**/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"]` | Every file that renders the library's components, relative to the project root. They're analyzed before the build; a module outside them that imports one fails the build. `.svelte` files are read for the props they pass; a component imported from a script, Markdown, MDX or Astro file keeps every value. `node_modules` is skipped unless a pattern names it. |
|
|
330
|
+
| `unwrap` | `true` on Svelte 5 | Replace an `{#if}` whose only live branch is known with that branch, instead of `{#if true}`. Svelte 3 and 4 render whitespace differently without the block. |
|
|
331
|
+
| `silent` | `false` | Skip the per-build summary (`rewrote N My Library components for this app (M edits)`). |
|
|
332
|
+
| `report` | `false` | Print what each build rewrote: edits per component, the children it no longer renders, the components no longer bundled, and the values each call site passes (or why it keeps every value). Independent of `silent`. |
|
|
333
|
+
| `safelist` | `[]` | Selectors of the library's stylesheets to keep whatever renders, for classes the app builds from data at runtime: a class (`"x--tag--red"`, with or without its `.`) keeps every selector it's in, a RegExp every selector it matches (`/^\.x--tag--/`). Only with `styles`. |
|
|
334
|
+
|
|
335
|
+
### `names`
|
|
336
|
+
|
|
337
|
+
For a package that wraps svelte-prune and reports under its own name. `sveltePrune()` replaces its defaults whole, so pass `plugin`, `failure` and `id`; `SveltePrunePlugin` takes any of its fields.
|
|
338
|
+
|
|
339
|
+
| Field | Default | |
|
|
340
|
+
| :----------------- | :------------------------------------ | :----------------------------------------------------------------------------------------------------------------------- |
|
|
341
|
+
| `plugin` | `"svelte-prune"` | Names the plugin in errors, and webpack's hooks and logger. |
|
|
342
|
+
| `failure.feature` | `"svelte-prune"` | Names what a failed analysis turns off, in its warning and the `report` heading (after `tool`, unless they're the same). |
|
|
343
|
+
| `failure.fallback` | `"components were bundled unchanged"` | What happens instead, in that warning. |
|
|
344
|
+
| `id` | `"svelte-prune"` | `sveltePrune()` only: the plugin's name in the bundler. |
|
|
345
|
+
| `loader` | the bundled loader | webpack only: the path of the loader to add. |
|
|
346
|
+
|
|
347
|
+
### `specializeFiles(input)`
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
import { specializeFiles } from "svelte-prune";
|
|
351
|
+
|
|
352
|
+
function specializeFiles(input: {
|
|
353
|
+
library: LibrarySpec;
|
|
354
|
+
projectRoot: string;
|
|
355
|
+
files: Array<{ file: string; code: string }>;
|
|
356
|
+
failure: Failure;
|
|
357
|
+
options?: SpecializeOptions;
|
|
358
|
+
resolvedImports?: ReadonlyMap<string, string>;
|
|
359
|
+
safelist?: ReadonlyArray<string | RegExp>;
|
|
360
|
+
}): Promise<SpecializedComponents | { warning: string }>;
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
The analysis and rewrite the plugins run, for a set of files and without a bundler. Pass every file that renders the library: a component a missing file renders is rewritten without its call sites.
|
|
364
|
+
|
|
365
|
+
| Input | |
|
|
366
|
+
| :------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
367
|
+
| `library` | The `LibrarySpec`. |
|
|
368
|
+
| `projectRoot` | Where the library is resolved from (Yarn Plug'n'Play included), and what the report's paths are relative to. |
|
|
369
|
+
| `files` | Absolute paths and their source. |
|
|
370
|
+
| `failure` | `{ feature, fallback }` for the warning if the analysis throws. |
|
|
371
|
+
| `options.unwrap` | Default`false`. As in `SveltePruneOptions`; pass `true` on Svelte 5. |
|
|
372
|
+
| `options.dropUnused` | Default`true`. Remove top-level declarations nothing reads after the rewrite. |
|
|
373
|
+
| `options.emptyBlock` | Default`{#if false}<!---->{/if}`. What replaces an `{#if}` that renders nothing between whitespace. |
|
|
374
|
+
| `options.editFilter` | `(index, { start, end }) => boolean`. Debugging: apply only the top-level edits it accepts. |
|
|
375
|
+
| `resolvedImports` | Non-relative `.svelte` imports you resolved yourself (`$lib/Card.svelte`), keyed `` `${importer}\0${specifier}` ``, to the absolute path of a file in `files`. |
|
|
376
|
+
| `safelist` | As in `SveltePruneOptions`. |
|
|
377
|
+
|
|
378
|
+
It never throws: if the analysis fails, it resolves to `{ warning }` and nothing is rewritten. Otherwise to `SpecializedComponents`:
|
|
379
|
+
|
|
380
|
+
| Field | Type | |
|
|
381
|
+
| :------------ | :------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
382
|
+
| `sources` | `Map<string, { code: string; map: SourceMap }>` | Rewritten components and script modules by the real path of their source, each with a v3 source map. Serve these instead of the files on disk. |
|
|
383
|
+
| `edits` | `number` | Edits made to components, across `sources`. |
|
|
384
|
+
| `apps` | `number` | How many of `sources` are the app's own components. |
|
|
385
|
+
| `renderable` | `ReadonlySet<string>` | The library components that can render, by path in `srcDir`. |
|
|
386
|
+
| `tables` | `{ modules, pruned, emptied, keys, compounds }` | The tailwind-variants tables rewritten: how many of `sources` are their modules, tables pruned and emptied, and variant keys and compound variants removed. |
|
|
387
|
+
| `closed` | `Set<string>` | App components whose props came from their call sites in `files`. Nothing outside `files` may render them; the plugins check it. |
|
|
388
|
+
| `report` | `() => string[]` | The lines `report: true` prints. |
|
|
389
|
+
| `readImport` | `(importer, id) => boolean` | Whether the analysis read file `importer`'s import of library module `id` (both real paths). `false` means an import it can't see, such as one through a bundler alias. |
|
|
390
|
+
| `pruneStyles` | `(css) => { css, rules, selectors, declarations }` | With `styles`: removes from `css` the rules that need a class the library's stylesheets define and nothing can render, then the custom properties and `@keyframes` they define that nothing reads, and counts what it removed. |
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
const result = await specializeFiles({
|
|
394
|
+
library,
|
|
395
|
+
projectRoot: process.cwd(),
|
|
396
|
+
files: [{ file: "/app/src/App.svelte", code }],
|
|
397
|
+
failure: {
|
|
398
|
+
feature: "svelte-prune",
|
|
399
|
+
fallback: "components were bundled unchanged",
|
|
400
|
+
},
|
|
401
|
+
options: { unwrap: true },
|
|
402
|
+
});
|
|
403
|
+
if ("warning" in result) console.warn(result.warning);
|
|
404
|
+
else
|
|
405
|
+
for (const [file, { code, map }] of result.sources)
|
|
406
|
+
console.log(file, code, map);
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Warnings and errors
|
|
410
|
+
|
|
411
|
+
Every message starts with `` `${tool}:` ``.
|
|
412
|
+
|
|
413
|
+
- **Warning** (the build continues, nothing rewritten): `could not analyze this build (…)`, when the analysis throws, for example because the library isn't installed.
|
|
414
|
+
- **Errors** (the build fails), when components were rewritten without a call site:
|
|
415
|
+
- a file outside `content` imports the library: add it to `content`;
|
|
416
|
+
- an analyzed file imports the library through an alias the analysis can't read (`import { Button } from "@lib"`): import it from the package name;
|
|
417
|
+
- a virtual module (no file on disk) imports the library: import it from a file in `content`;
|
|
418
|
+
- a module outside `content` renders an app component whose props were read from its call sites: add it to `content`;
|
|
419
|
+
- a module outside the library imports one of its script modules whose tailwind-variants tables were rewritten (through an alias, for example): import them from the package name.
|
|
420
|
+
|
|
421
|
+
## What it reads
|
|
422
|
+
|
|
423
|
+
Each diff is rewritten for the call site in its first comment; the values come from what that call site passes.
|
|
424
|
+
|
|
425
|
+
**Names declared in markup.** A `{@const}`, an `{#each}` item, and destructuring in either are read where they're in scope, and so is a snippet's parameter, as what every `{@render}` of it passes:
|
|
426
|
+
|
|
427
|
+
```diff
|
|
428
|
+
<!-- <List size="md" {items} /> -->
|
|
429
|
+
{#snippet row(s, label)}
|
|
430
|
+
- {#if s === "sm"}<small>{label}</small>{:else}<b>{label}</b>{/if}
|
|
431
|
+
+ <b>{label}</b>
|
|
432
|
+
{/snippet}
|
|
433
|
+
{#each items as { label, tags: [first] = [] }}
|
|
434
|
+
- {@const compact = size === "sm"}
|
|
435
|
+
- {#if compact}<small>{first}</small>{/if}{@render row(size, label)}
|
|
436
|
+
+ {@const compact = false}
|
|
437
|
+
+ {@render row("md", label)}
|
|
438
|
+
{/each}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
A snippet handed to a component, or used as a component's content, keeps its parameters unknown: the component may call it with anything.
|
|
442
|
+
|
|
443
|
+
**Pure built-ins.** `Array.isArray`, `Math`'s rounding and min/max functions, and `includes`, `some` and `every` on arrays (`some` and `every` with a callback written inline that only reads) are evaluated, and a `&&`, `||` or `??` whose left side decides it folds without its right side:
|
|
444
|
+
|
|
445
|
+
```diff
|
|
446
|
+
<!-- <Header title="Hi" placement="left" /> -->
|
|
447
|
+
-{#if Array.isArray(title)}{#each title as t}<p>{t}</p>{/each}{:else}<p>{title}</p>{/if}
|
|
448
|
+
-{#if ["top", "bottom"].includes(placement)}<div class="vertical">…</div>{/if}
|
|
449
|
+
-{#if Array.isArray(data) && data.length > 0}<datalist>…</datalist>{/if}
|
|
450
|
+
+<p>{"Hi"}</p>
|
|
451
|
+
+{#if false}<!---->{/if}
|
|
452
|
+
+{#if false}<!---->{/if}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
`Array` or `Math` declared in the component isn't the built-in, and an object's own `includes` may do anything.
|
|
456
|
+
|
|
457
|
+
**Stores handed down in a context.** A `writable` a component sets only from its props, in `$:`, and hands down only in `setContext`, holds what those props can be in every component that reads it:
|
|
458
|
+
|
|
459
|
+
```svelte
|
|
460
|
+
<!-- Tabs.svelte -->
|
|
461
|
+
<script>
|
|
462
|
+
export let iconOnly = false;
|
|
463
|
+
const iconOnlyStore = writable(iconOnly);
|
|
464
|
+
$: iconOnlyStore.set(iconOnly);
|
|
465
|
+
setContext("tabs", { iconOnly: iconOnlyStore });
|
|
466
|
+
</script>
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
```diff
|
|
470
|
+
<!-- Tab.svelte, in <Tabs><Tab label="One" /></Tabs> -->
|
|
471
|
+
<script>
|
|
472
|
+
const { iconOnly } = getContext("tabs");
|
|
473
|
+
</script>
|
|
474
|
+
-{#if $iconOnly}<Tooltip text={label}><slot /></Tooltip>{:else}<span>{label}</span>{/if}
|
|
475
|
+
+<span>{label}</span>
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
`Tooltip` is no longer bundled. A store a reader may write, or that a provider above may receive, keeps every value.
|
|
479
|
+
|
|
480
|
+
**Only what the app uses.** A component your app imports but never names again (not in markup, scripts, comments or strings) adds no call site, so it's specialized only for where the library itself renders it:
|
|
481
|
+
|
|
482
|
+
```svelte
|
|
483
|
+
<script>
|
|
484
|
+
import { TextField, Field } from "my-library"; // Field: unused
|
|
485
|
+
</script>
|
|
486
|
+
<TextField label="Name" />
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
`TextField` renders `<Field placement="inset">`, so `Field` keeps only its `inset` branch.
|
|
490
|
+
|
|
491
|
+
## How it stays safe
|
|
492
|
+
|
|
493
|
+
**Unknown means open.** A component keeps every value of a prop the analysis can't read, and is rendered with any props wherever it can't see the call site:
|
|
494
|
+
|
|
495
|
+
- A prop passed as an expression it can't evaluate, spread from an object it can't read, or bound with `bind:` keeps every value.
|
|
496
|
+
- A component used as a value (`this={Button}`, passed as a prop), imported dynamically or through an alias, or rendered from a file outside `content` keeps every variant. The plugins check the bundler's module graph after the build and fail it when a module the analysis didn't read imports the library.
|
|
497
|
+
- A component whose props something other than a call site can set keeps every value: a custom element, or one bound with `bind:this` whose instance the app uses for more than calling what it exports (`$set`, an accessor, `$on`, handing it on).
|
|
498
|
+
- A prop nothing reads anymore stays declared where removing it would show: its default has effects (`uniqueId()`), something writes it, or a call site passes it to a component that reads `$$restProps` or `$$props`, where it would land.
|
|
499
|
+
- A prop becomes a plain `let` only when no call site passes or binds it.
|
|
500
|
+
- A bare `on:click` stays wherever a call site may listen to it: one with `on:click`, one whose own forwarded `on:click` has a listener, or one the analysis can't read. So does a `dispatch("click", …)`, and one goes only where its result is unused (`true` in the browser, `undefined` on the server), keeping whatever its arguments run.
|
|
501
|
+
- `$$restProps` is spread away only when no call site passes a key it would hold, and only onto components and into objects: on an element, a spread decides how Svelte renders its attributes.
|
|
502
|
+
- Content counts: snippets are props, and content outside them is `children` on Svelte 5 and a slot on Svelte 3 and 4.
|
|
503
|
+
- An export of the library it can't tell apart from a component (a function that may return one) keeps every component.
|
|
504
|
+
- A tailwind-variants table keeps every key when something other than a live component's call can read it: the app imports it, another table extends it, a script module reads it, a namespace or `import()` reaches it, or a component hands on what a call with slots returns. A variant whose value at some call the analysis can't evaluate (a spread, a function's parameter) keeps every key. A table nothing calls is emptied only when nothing else can read it, and a script module that mounts a component keeps every table whole.
|
|
505
|
+
|
|
506
|
+
- A stylesheet rule stays unless it needs a class the library's stylesheets define, its `classTokens` can read, and nothing can render: no live component under the app's props, no script module of the library, no file in `content`, nothing in `keep` or `safelist`. The examples check that no selector whose classes all appear on the rendered page goes missing.
|
|
507
|
+
|
|
508
|
+
The app's own components are rewritten too, when every file that renders them is in `content`: a wrapper's props come from its call sites, so `<Card tone="danger">` reaches the `Button` inside it.
|
|
509
|
+
|
|
510
|
+
## Correctness
|
|
511
|
+
|
|
512
|
+
On real libraries, each component with every prop value it compares against plus random mixes of them, SSR-rendered with the original and the rewritten library:
|
|
513
|
+
|
|
514
|
+
| Library | Components | Apps rendering identically | Apps rendering differently |
|
|
515
|
+
| :---------------------------- | :--------- | :------------------------- | :------------------------- |
|
|
516
|
+
| carbon-components-svelte | 262 | 2,330 | 0 |
|
|
517
|
+
| @sveltestrap/sveltestrap | 87 | 645 | 0 |
|
|
518
|
+
| svelte-ux | 101 | 999 | 0 |
|
|
519
|
+
| flowbite-svelte | 181 | 1,591 | 0 |
|
|
520
|
+
| svelte-5-ui-lib | 135 | 918 | 0 |
|
|
521
|
+
| bits-ui | 159 | 859 | 0 |
|
|
522
|
+
| @skeletonlabs/skeleton-svelte | 131 | 327 | 0 |
|
|
523
|
+
|
|
524
|
+
The [`examples/`](examples/README.md) behind [Results](#results) also compare each page's rendered HTML and its behavior in a browser, and fail when a selector whose classes all appear on the page goes missing from the CSS.
|
|
525
|
+
|
|
526
|
+
## Limitations
|
|
527
|
+
|
|
528
|
+
- **Production builds only.** The analysis runs for the whole app before the build, so dev serving and HMR are left alone.
|
|
529
|
+
- **tailwind-variants tables only in the library's `.js` modules**, made with `tv` imported from `tailwind-variants`. Tables defined in components, or with `createTV`, keep every class.
|
|
530
|
+
- **Every importer must be in `content`.** A module outside it that imports the library fails the build rather than ship components rewritten without its call sites.
|
|
531
|
+
- **Stylesheets can't see classes built from data.** A class the app or a package outside the library adds at runtime, from a value no file names, must be in `safelist`.
|
|
532
|
+
- **Values it can't evaluate stay open.** Props read from a whole `$props()` object, or state held in classes (`.svelte.js`), keep every value.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Ve,Be,Fe,fe,He}from"./index-k2z70ex7.js";export{Be as analyzeFiles,Ve as createUsageCollector,Fe as formatPropAwareReport,fe as specializeFiles,He as writeLibraryForTailwind};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c,B,o,b,pe,p,T,K,S}from"./index-jxng1156.js";import{createHash as _}from"node:crypto";import{existsSync as N,globSync as E,readFileSync as D}from"node:fs";import A from"node:path";function Te(n,l,w){if(!l.includes(n.name))return!1;let{patterns:h}=p(n),d=!1,v=(m,t)=>{let I=h.directComponentName.exec(m);if(I)w.add(I[1]);else if(m===n.name)for(let x of t())if(x==="*")d=!0;else w.add(x)};for(let m of c(l)){let t=m.source?.value;if(!t||m.typeOnly)continue;v(t,()=>m.kind==="export"?m.specifiers.flatMap((I)=>I.typeOnly?[]:[I.local]):m.specifiers.flatMap((I)=>I.typeOnly||I.kind==="default"?[]:[I.imported]))}for(let m of l.matchAll(h.dynamicImport))if(m[2].includes("${"))d=!0;else v(m[2],()=>["*"]);return d}var U=["src/**/*.{svelte,svx,md,mdx,astro,js,jsx,ts,tsx,mjs,mts,cjs,cts}"],W=/[\\/]/,j=/^\0/,V=/\.(svelte|[cm]?[jt]sx?)$/,q=/\b(?:from|import)\s*["']([^"'./][^"']*\.svelte)["']/g,F=(n,l)=>n.tailwind===!0&&K("tailwindcss",l)!==void 0;async function G(n,l,w){if(!F(n,l))return;let{writeLibraryForTailwind:h}=await import("./analysis-ah6ws3px.js");return h(n,l,void 0,w.failure)}var J=(n)=>n.split(W).includes("node_modules"),M=(n,l)=>n.startsWith("\x00")||!A.isAbsolute(l);function Q(n,l){let w=n.filter((d)=>d.includes("node_modules")),h=n.filter((d)=>!w.includes(d));return[...new Set([...h.length>0?E(h,{cwd:l,exclude:J}):[],...w.length>0?E(w,{cwd:l}):[]])]}function Y(n,l,w,h){if(!w.includes(n.name))return!1;if(!h&&!V.test(l))return n.patterns.importText.test(w);let d=new Set;return Te(n.spec,w,d)||d.size>0}async function Z(n,l,w){let h=new Map(l.map(({file:m})=>[b(m)??m,m])),d=new Map,v=[];for(let{file:m,code:t}of l){if(!t.includes(".svelte"))continue;for(let[,I]of t.matchAll(q)){if(n.isComponentFile(I))continue;v.push(w(I,m).then((x)=>{if(!x)return;let k=o(x),L=h.get(b(k)??k);if(L)d.set(pe(m,I),L)},()=>{}))}}return await Promise.all(v),d}var H={plugin:"svelte-prune",failure:{feature:"svelte-prune",fallback:"components were bundled unchanged"}};function O(n){return{root:n,sources:new Map,analyzed:new Set,missed:new Set,virtual:new Set,closed:new Set,escaped:new Map,unread:new Map,scriptImporters:new Map,readImport:()=>!0,realpaths:new Map,pruneStyles:void 0}}function X(n,l,w){let h=w.plugin,{label:d}=n,v=p(n),m=l?.content??U,t=O(process.cwd()),I,x,k=(e)=>{if(!t.realpaths.has(e))t.realpaths.set(e,b(e));return t.realpaths.get(e)},L=(e)=>k(e)??e,C=(e)=>t.analyzed.has(L(o(e))),P=(e)=>{let i=k(e);return i?A.relative(L(t.root),i):A.relative(t.root,e)};return{async prepare(e,i){t=O(e);let a=[],s=_("sha1");for(let g of Q(m,e)){let y=A.resolve(e,g),z;try{z=D(y,"utf8")}catch{continue}a.push({file:y,code:z}),s.update(`${y}\x00${z}\x00`),t.analyzed.add(L(y))}let u=i?await Z(v,a,i):void 0;for(let[g,y]of u??[])s.update(`${g}\x00${y}\x00`);let f=s.digest("hex");if(I?.hash!==f){let{specializeFiles:g}=await import("./analysis-ah6ws3px.js");I={hash:f,result:await g({library:n,projectRoot:e,files:a,resolvedImports:u,failure:w.failure,options:{unwrap:l?.unwrap??(K("svelte",e)??0)>=5},safelist:l?.safelist})}}let{result:r}=I;if(F(n,e)){let g=A.join(e,"node_modules",".svelte-prune",n.name),y;try{let z=T(n.name,e);y=`${g}\x00${await S(z,n.srcDir)}`}catch{}if(x?.result!==r||y===void 0||x.key!==y||!N(g)){x=void 0;let{writeLibraryForTailwind:z}=await import("./analysis-ah6ws3px.js"),R=await z(n,e,"warning"in r?void 0:r,w.failure);if(R)return{warning:R};if(y!==void 0)x={result:r,key:y}}}if("warning"in r)return{warning:r.warning};return t.pruneStyles=r.pruneStyles,t.sources=r.sources,t.readImport=r.readImport,t.closed=new Set([...r.closed].map(L)),{info:l?.silent?void 0:`rewrote ${r.sources.size-r.apps-r.tables.modules} ${d} components${r.apps>0?` and ${r.apps} of the app's own`:""}${r.tables.modules>0?` and ${r.tables.pruned+r.tables.emptied} tailwind-variants tables`:""} for this app (${r.edits} edits)`,report:l?.report?r.report():void 0}},get analyzed(){return t.analyzed},pruneStyles(e){let i=t.pruneStyles;if(!i)return;let a=0,s=0,u=0,f=0;for(let[y,z]of e){let R=i(z);a+=R.rules,s+=R.declarations,u+=z.length,f+=R.css.length,e.set(y,R.css)}if(a+s===0||l?.silent)return;let r=(y)=>`${(y/1000).toFixed(2)} kB`,g=s>0?` and ${s} custom properties`:"";return`removed ${a} unused ${d} CSS rules${g} (${r(u)} -> ${r(f)})`},rewritable(e){let i=o(e);if(i.endsWith(".js"))return v.moduleKey(i)!==void 0;return i.endsWith(".svelte")&&(v.isComponentFile(i)||C(i))},load(e){if(t.sources.size===0)return;let[i,a=""]=e.split("?");if(a.includes("svelte"))return;return t.sources.get(L(i))},check(e,i){if(t.sources.size===0)return;let a=o(e);if(v.isComponentFile(a)||B.test(a))return;if(C(a))return;let s=M(e,a);if(!Y(v,a,i,s))return;if(s)t.virtual.add(e.replace(j,""));else t.missed.add(P(a))},checkScriptImporters(e,i){let a=o(e);if(!a.endsWith(".js")||!t.sources.has(L(a)))return;for(let s of i){if(s!==void 0&&v.moduleKey(o(s)))continue;let u=P(a),f=t.scriptImporters.get(u)??new Set;f.add(s===void 0?"the bundler":A.isAbsolute(o(s))?P(o(s)):s),t.scriptImporters.set(u,f)}},isClosed(e){if(t.closed.size===0||e.includes("?"))return!1;return t.closed.has(L(e))},checkImporters(e,i,a){let s=new Set;for(let u of i)if(u===void 0)s.add("the bundler");else if(!C(u)){let f=o(u);s.add(A.isAbsolute(f)?P(f):u)}if(a)s.add("a dynamic import");if(s.size>0)t.escaped.set(P(e),[...s])},checkLibraryImport(e){if(t.sources.size===0)return;let{id:i,importer:a,specifier:s}=e,u=o(a);if(!v.importKey(i)||v.moduleKey(u))return;if(M(a,u)){t.virtual.add(a.replace(j,""));return}let f=L(u);if(!t.analyzed.has(f)){t.missed.add(P(u));return}let r=L(o(i)),g=s!==void 0&&!v.isSpecifier(s);if(!g&&t.readImport(f,r))return;let y=P(u),z=t.unread.get(y)??new Set;z.add(g?`\`${s}\``:v.importKey(r)===v.barrelKey?`\`${n.name}\``:`${d}'s ${A.basename(r,A.extname(r))}`),t.unread.set(y,z)},error(){let{escaped:e,missed:i,scriptImporters:a,unread:s,virtual:u}=t,f=[];for(let[r,g]of e)f.push(`${h} read the props of ${r} from its call sites in \`content\`, but ${g.join(", ")} also ${g.length===1?"renders":"render"} it. Add those files to \`content\`.`);if(i.size>0)f.push(`${h} rewrote ${d} components before seeing ${[...i].join(", ")}, which ${i.size===1?"imports":"import"} them. Add those files to \`content\` (now ${JSON.stringify(m)}); only a pattern that names \`node_modules\` reaches inside it.`);for(let[r,g]of s)f.push(`${h} can't read how ${r} imports ${[...g].join(", ")}, so it rewrote ${d} without that file's call sites. Import ${d} from \`${n.name}\` there, not through an alias, or remove ${h}.`);for(let[r,g]of a)f.push(`${h} rewrote the tailwind-variants tables in ${r} for the ${d} components that call them, but ${[...g].join(", ")} ${g.size===1?"imports":"import"} it directly. Import them from \`${n.name}\` instead, or remove ${h}.`);if(u.size>0)f.push(`${h} can't analyze ${[...u].join(", ")}, which ${u.size===1?`imports ${d} components but has`:`import ${d} components but have`} no file on disk. Import them from a file in \`content\` instead, or remove ${h}.`);return f.length>0?`${v.logPrefix} ${f.join(" ")}`:void 0}}}
|
|
2
|
+
export{Te,G,H,X};
|