@sanity/tsdown-config 0.28.8 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -17
- package/dist/{cssLoweringTargets-Dn_sJGip.mjs → cssLoweringTargets-CBJMQRZ_.mjs} +13 -4
- package/dist/cssLoweringTargets-CBJMQRZ_.mjs.map +1 -0
- package/dist/index.d.mts +144 -17
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +19 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -5
- package/dist/cssLoweringTargets-Dn_sJGip.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -169,7 +169,7 @@ export default defineConfig({
|
|
|
169
169
|
## vanilla-extract
|
|
170
170
|
|
|
171
171
|
The same `vanillaExtract` feature as `@sanity/pkg-utils` is available. It extracts the CSS from
|
|
172
|
-
`.css.ts` files into a separate file (`dist/bundle.css` by default),
|
|
172
|
+
`.css.ts` files into a separate file (`dist/bundle.css` by default), lowered with
|
|
173
173
|
`lightningcss` for the
|
|
174
174
|
[`@sanity/browserslist-config`](https://github.com/sanity-io/browserslist-config#readme)
|
|
175
175
|
browsers by default. Under the hood it uses
|
|
@@ -222,22 +222,100 @@ without importing it automatically (for packages whose consumers import the subp
|
|
|
222
222
|
> and still works, with a warning: `nodeCompat` configures how the CSS file is published, not how
|
|
223
223
|
> the import is injected, so it moved to `exports`.
|
|
224
224
|
|
|
225
|
-
|
|
225
|
+
The default `identifiers: 'short'` names each style after a hash of the package name and the
|
|
226
|
+
file path, plus a counter of the styles before it in the file. A release that reorders a file's
|
|
227
|
+
styles therefore reuses its class names for different rules, and pages that load the CSS of two
|
|
228
|
+
releases (e.g. an app bundling a design system next to a CDN-served Studio bundling another
|
|
229
|
+
release of it) style one release's markup with the other's rules. Opt in to `'safe'` to keep
|
|
230
|
+
releases apart: it is `'short'` with the package version also hashed in, so every release gets
|
|
231
|
+
its own class names, and the same release always builds the same ones:
|
|
226
232
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
```ts
|
|
234
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
235
|
+
|
|
236
|
+
export default defineConfig({
|
|
237
|
+
tsconfig: 'tsconfig.dist.json',
|
|
238
|
+
vanillaExtract: {identifiers: 'safe'},
|
|
239
|
+
})
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
`minify` is not enabled. Set `minify: true` to minify the extracted CSS; otherwise it stays
|
|
243
|
+
readable, matching the bare plugin and `css.minify` in `@tsdown/css`.
|
|
244
|
+
|
|
245
|
+
The CSS syntax lowering `target` still diverges from the bare plugins (which match `@tsdown/css`
|
|
246
|
+
exactly). It defaults to tsdown's top-level `target`, and when the effective target is undefined
|
|
247
|
+
or names no browsers (e.g. `'node20'`, also what tsdown derives from `engines.node` - it speaks
|
|
248
|
+
to the JS runtime, not the browsers the extracted CSS runs in), the lowering targets are resolved
|
|
249
|
+
from `@sanity/browserslist-config` and passed through `lightningcss.targets`. The bare plugins
|
|
250
|
+
(like `@tsdown/css`) would skip lowering in that case. `target: false` disables lowering
|
|
251
|
+
entirely, and a user-provided `lightningcss.targets` wins over the fallback.
|
|
236
252
|
|
|
237
253
|
`vanillaExtract` can be combined with the [`css` option](#css) below when a package also uses
|
|
238
254
|
CSS modules (or other `@tsdown/css` features) — the two pipelines write to different files by
|
|
239
255
|
default (`bundle.css` vs `style.css`) and do not interfere with each other.
|
|
240
256
|
|
|
257
|
+
## panda
|
|
258
|
+
|
|
259
|
+
`panda: true` enables
|
|
260
|
+
[`@sanity/pandacss-tsdown-plugin`](https://github.com/sanity-io/pkg-utils/tree/main/packages/@sanity/pandacss-tsdown-plugin#readme)
|
|
261
|
+
for a package styled with [Panda CSS](https://panda-css.com): the build generates Panda's files,
|
|
262
|
+
rewrites the style calls it can resolve statically into class names, and extracts the CSS into a
|
|
263
|
+
separate stylesheet. It is the library-build counterpart of `@pandacss/vite`, which applications
|
|
264
|
+
keep using in their Vite config.
|
|
265
|
+
|
|
266
|
+
Install the plugin — an optional peer dependency of this config:
|
|
267
|
+
|
|
268
|
+
```sh
|
|
269
|
+
pnpm add --save-dev @sanity/pandacss-tsdown-plugin
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
274
|
+
|
|
275
|
+
export default defineConfig({
|
|
276
|
+
tsconfig: 'tsconfig.dist.json',
|
|
277
|
+
panda: true,
|
|
278
|
+
})
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
The Sanity defaults on top of the plugin's own:
|
|
282
|
+
|
|
283
|
+
- `inject: true` — the entry chunks that use Panda styles get an `import "<pkg>/bundle.css"`
|
|
284
|
+
(a `require()` in CJS output), so consumers' bundlers load the stylesheet.
|
|
285
|
+
- `exports: {nodeCompat: true}` — `./bundle.css` is published as a conditional export: the
|
|
286
|
+
`browser` and `style` conditions select the stylesheet, `node` and `default` a no-op JS shim,
|
|
287
|
+
so the import also loads in Node.js. The export is written to `package.json` through this
|
|
288
|
+
config's [`exports`](#exports) generation.
|
|
289
|
+
- The CSS syntax is transformed for the configured browsers — `panda.target`, then the top-level
|
|
290
|
+
`target`, and when neither names browsers (e.g. `node20`) the
|
|
291
|
+
[`@sanity/browserslist-config`](https://github.com/sanity-io/browserslist-config#readme)
|
|
292
|
+
browsers. Browserslist queries like `'defaults'` work too; `lightningcss.targets` wins over
|
|
293
|
+
everything and `target: false` disables the transform.
|
|
294
|
+
- `minify` stays off; `transform` stays on (unlike in `@pandacss/vite`).
|
|
295
|
+
|
|
296
|
+
Pass an object to customize, with the same options as the plugin:
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
300
|
+
|
|
301
|
+
export default defineConfig({
|
|
302
|
+
tsconfig: 'tsconfig.dist.json',
|
|
303
|
+
panda: {minify: true, fileName: 'styles.css'},
|
|
304
|
+
})
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Setup reminders, in the package being built:
|
|
308
|
+
|
|
309
|
+
- `"prepare": "panda codegen"` (from `@pandacss/dev`, recommended but not required) so the
|
|
310
|
+
generated files exist for the editor and the type checker before a build — the plugin
|
|
311
|
+
regenerates them when it builds.
|
|
312
|
+
- An `imports` map for the generated directory, e.g. `"#styled-system/*": "./styled-system/*/index.js"`,
|
|
313
|
+
matching `importMap` in `panda.config.ts`.
|
|
314
|
+
- `"sideEffects": ["*.css"]`, so consumers' tree-shaking keeps the injected stylesheet import.
|
|
315
|
+
|
|
316
|
+
See the plugin README for the full behavior (sources, codegen, the limits of the transform,
|
|
317
|
+
watch mode) and the options reference.
|
|
318
|
+
|
|
241
319
|
## css
|
|
242
320
|
|
|
243
321
|
tsdown's experimental [`css` option](https://tsdown.dev/options/css) enables the `@tsdown/css`
|
|
@@ -260,8 +338,7 @@ export default defineConfig({
|
|
|
260
338
|
})
|
|
261
339
|
```
|
|
262
340
|
|
|
263
|
-
The options are `@tsdown/css`'s, plus an `exports` option this config implements on top
|
|
264
|
-
same two Sanity-flavored defaults as `vanillaExtract`:
|
|
341
|
+
The options are `@tsdown/css`'s, plus an `exports` option this config implements on top:
|
|
265
342
|
|
|
266
343
|
- `exports` defaults to `{nodeCompat: true}`, wiring up the same conditional CSS export pattern:
|
|
267
344
|
the self-referential `import "<pkg>/style.css"`, a no-op `style-css.js` shim with its
|
|
@@ -269,8 +346,8 @@ same two Sanity-flavored defaults as `vanillaExtract`:
|
|
|
269
346
|
`@tsdown/css` has no equivalent — its own `inject` emits a relative `import "./style.css"`,
|
|
270
347
|
which throws in runtimes that cannot load `.css` files. Set `exports: true` for a plain
|
|
271
348
|
(browser-only) CSS export, or `exports: false` to fall back to the relative injection.
|
|
272
|
-
- `minify`
|
|
273
|
-
`@sanity/browserslist-config` — exactly as described for `vanillaExtract` above.
|
|
349
|
+
- `minify` is not enabled unless you set `minify: true`. Browserless CSS syntax lowering targets
|
|
350
|
+
fall back to `@sanity/browserslist-config` — exactly as described for `vanillaExtract` above.
|
|
274
351
|
|
|
275
352
|
Both `css` and `vanillaExtract` can be enabled in the same config. Use that when a package
|
|
276
353
|
authors styles with vanilla-extract _and_ CSS modules (`.module.css`):
|
|
@@ -511,8 +588,9 @@ the browser - `'node'` makes CommonJS-interop emit a module-scope
|
|
|
511
588
|
|
|
512
589
|
tsdown's [`target` option](https://tsdown.dev/options/target) is also passed through as-is. It
|
|
513
590
|
downlevels JS syntax for the given runtimes (esbuild-style target strings), and doubles as the
|
|
514
|
-
default CSS syntax lowering target when `vanillaExtract` is enabled
|
|
515
|
-
`node20` don't affect the CSS - it falls back to
|
|
591
|
+
default CSS syntax lowering target when `vanillaExtract`, `panda` or `css` is enabled
|
|
592
|
+
(browserless targets like `node20` don't affect the CSS - it falls back to
|
|
593
|
+
`@sanity/browserslist-config`):
|
|
516
594
|
|
|
517
595
|
```ts
|
|
518
596
|
import {defineConfig} from '@sanity/tsdown-config'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { esbuildTargetToLightningCSS } from "@sanity/vanilla-extract-tsdown-plugin";
|
|
2
2
|
/**
|
|
3
3
|
* Resolves the CSS syntax lowering targets for a CSS pipeline
|
|
4
|
-
* (`vanillaExtract`/`css`), applying the Sanity-flavored fallback on top of the
|
|
5
|
-
* `@tsdown/css` behavior
|
|
4
|
+
* (`vanillaExtract`/`panda`/`css`), applying the Sanity-flavored fallback on top of the
|
|
5
|
+
* `@tsdown/css` behavior the pipelines otherwise follow.
|
|
6
6
|
*
|
|
7
7
|
* `@tsdown/css` skips syntax lowering when it has no browser targets. Extracted CSS always runs
|
|
8
8
|
* in browsers though, so when the effective target (the pipeline's own `target`, falling back to
|
|
@@ -11,8 +11,10 @@ import { esbuildTargetToLightningCSS } from "@sanity/vanilla-extract-tsdown-plug
|
|
|
11
11
|
* are resolved from `@sanity/browserslist-config` and passed through `lightningcss.targets`
|
|
12
12
|
* instead.
|
|
13
13
|
*
|
|
14
|
+
* A target that isn't esbuild-style but is a browserslist query (`'defaults'`, `'> 0.5%'`,
|
|
15
|
+
* `'last 2 versions'`) is resolved with browserslist rather than overridden by that fallback.
|
|
14
16
|
* `target: false` stays the explicit off switch, and a user-provided `lightningcss.targets`
|
|
15
|
-
* wins over
|
|
17
|
+
* wins over everything.
|
|
16
18
|
*
|
|
17
19
|
* @internal
|
|
18
20
|
*/
|
|
@@ -24,6 +26,13 @@ async function resolveCssLoweringTargets(options) {
|
|
|
24
26
|
import("@sanity/browserslist-config"),
|
|
25
27
|
import("lightningcss")
|
|
26
28
|
]);
|
|
29
|
+
if (cssTarget !== void 0) try {
|
|
30
|
+
let targets = browserslistToTargets(browserslist(cssTarget));
|
|
31
|
+
if (Object.keys(targets).some((name) => name !== "node")) return {
|
|
32
|
+
...lightningcss,
|
|
33
|
+
targets
|
|
34
|
+
};
|
|
35
|
+
} catch {}
|
|
27
36
|
return {
|
|
28
37
|
...lightningcss,
|
|
29
38
|
targets: browserslistToTargets(browserslist(browserslistConfig))
|
|
@@ -31,4 +40,4 @@ async function resolveCssLoweringTargets(options) {
|
|
|
31
40
|
}
|
|
32
41
|
export { resolveCssLoweringTargets };
|
|
33
42
|
|
|
34
|
-
//# sourceMappingURL=cssLoweringTargets-
|
|
43
|
+
//# sourceMappingURL=cssLoweringTargets-CBJMQRZ_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssLoweringTargets-CBJMQRZ_.mjs","names":[],"sources":["../src/cssLoweringTargets.ts"],"sourcesContent":["import {esbuildTargetToLightningCSS} from '@sanity/vanilla-extract-tsdown-plugin'\nimport type {Targets} from 'lightningcss'\n\n/** The `lightningcss` options both CSS pipelines accept, narrowed to what this helper touches. */\ninterface LightningCSSOptionsWithTargets {\n targets?: Targets | undefined\n}\n\n/**\n * Resolves the CSS syntax lowering targets for a CSS pipeline\n * (`vanillaExtract`/`panda`/`css`), applying the Sanity-flavored fallback on top of the\n * `@tsdown/css` behavior the pipelines otherwise follow.\n *\n * `@tsdown/css` skips syntax lowering when it has no browser targets. Extracted CSS always runs\n * in browsers though, so when the effective target (the pipeline's own `target`, falling back to\n * the top-level `target`) is undefined or names no browsers - e.g. `'node20'`, which is also\n * what tsdown derives from `engines.node` and speaks to the JS runtime - the lowering targets\n * are resolved from `@sanity/browserslist-config` and passed through `lightningcss.targets`\n * instead.\n *\n * A target that isn't esbuild-style but is a browserslist query (`'defaults'`, `'> 0.5%'`,\n * `'last 2 versions'`) is resolved with browserslist rather than overridden by that fallback.\n * `target: false` stays the explicit off switch, and a user-provided `lightningcss.targets`\n * wins over everything.\n *\n * @internal\n */\nexport async function resolveCssLoweringTargets(options: {\n /** The pipeline's own `target` option. */\n cssTarget: string | string[] | false | undefined\n /** tsdown's top-level `target`, the fallback for `cssTarget`. */\n target: string | string[] | false | undefined\n /** The pipeline's own `lightningcss` options. */\n lightningcss: LightningCSSOptionsWithTargets | undefined\n}): Promise<LightningCSSOptionsWithTargets | undefined> {\n const {target, lightningcss} = options\n const cssTarget = options.cssTarget ?? target\n\n if (\n cssTarget === false ||\n lightningcss?.targets ||\n (cssTarget !== undefined && esbuildTargetToLightningCSS(cssTarget))\n ) {\n return lightningcss\n }\n\n // Lazy loaded: `browserslistToTargets` is a pure helper, but `lightningcss` is a native\n // package that only needs to load when the fallback applies\n const [{default: browserslist}, {default: browserslistConfig}, {browserslistToTargets}] =\n await Promise.all([\n import('browserslist'),\n import('@sanity/browserslist-config'),\n import('lightningcss'),\n ])\n\n if (cssTarget !== undefined) {\n // A target that isn't esbuild-style may be browserslist queries (`'defaults'`,\n // `'> 0.5%'`): the browsers they name are what the CSS is lowered for, not the fallback.\n // browserslist throws for queries it doesn't know (`'node20'`, `'es2022'`), and\n // `'node 20'` resolves to no browser (`browserslistToTargets` keeps `node` as a target).\n try {\n const targets = browserslistToTargets(browserslist(cssTarget))\n if (Object.keys(targets).some((name) => name !== 'node')) return {...lightningcss, targets}\n } catch {\n // Not browserslist queries either: the fallback below applies\n }\n }\n return {\n ...lightningcss,\n targets: browserslistToTargets(browserslist(browserslistConfig)),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,eAAsB,0BAA0B,SAOQ;CACtD,IAAM,EAAC,QAAQ,iBAAgB,SACzB,YAAY,QAAQ,aAAa;CAEvC,IACE,cAAc,MACd,cAAc,WACb,cAAc,KAAA,KAAa,4BAA4B,SAAS,GAEjE,OAAO;CAKT,IAAM,CAAC,EAAC,SAAS,gBAAe,EAAC,SAAS,sBAAqB,EAAC,2BAC9D,MAAM,QAAQ,IAAI;EAChB,OAAO;EACP,OAAO;EACP,OAAO;CACT,CAAC;CAEH,IAAI,cAAc,KAAA,GAKhB,IAAI;EACF,IAAM,UAAU,sBAAsB,aAAa,SAAS,CAAC;EAC7D,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,SAAS,SAAS,MAAM,GAAG,OAAO;GAAC,GAAG;GAAc;EAAO;CAC5F,QAAQ,CAER;CAEF,OAAO;EACL,GAAG;EACH,SAAS,sBAAsB,aAAa,kBAAkB,CAAC;CACjE;AACF"}
|
package/dist/index.d.mts
CHANGED
|
@@ -2,45 +2,147 @@ import { n as PackageTsdocOptions, r as PackageTsdocRuleLevel, t as PackageTsdoc
|
|
|
2
2
|
import { UserConfig } from "tsdown";
|
|
3
3
|
import { CssExportsOptions, CssExportsOptions as CssExportsOptions$1, Options } from "@sanity/vanilla-extract-tsdown-plugin";
|
|
4
4
|
import { PluginOptions } from "babel-plugin-react-compiler";
|
|
5
|
+
import { CustomAtRules, TransformOptions } from "lightningcss";
|
|
5
6
|
import { ReactCompilerOptions as ReactCompilerOptions$1 } from "oxc-transform-react";
|
|
6
7
|
/**
|
|
7
8
|
* Options for the `vanillaExtract` option — the same options as
|
|
8
9
|
* `@sanity/vanilla-extract-tsdown-plugin` (`identifiers`, `fileName`, `minify`, `target`,
|
|
9
10
|
* `lightningcss`, `inject`, and `exports`, all modeled after the `css` options of
|
|
10
|
-
* `@tsdown/css`), with
|
|
11
|
+
* `@tsdown/css`), with two Sanity-flavored defaults on top:
|
|
11
12
|
*
|
|
12
13
|
* - `inject` and `exports` default to `true` and `{nodeCompat: true}` (instead of the plugin's
|
|
13
14
|
* `false` for both), wiring up the conditional CSS export pattern that Sanity libraries ship
|
|
14
15
|
* with. Set `exports: true` for a plain (browser-only) CSS export, `exports: false` for a
|
|
15
16
|
* relative CSS import, or `inject: false` to only extract the CSS.
|
|
16
|
-
* - `minify` defaults to `true` (instead of the plugin's `false`, which matches `css.minify`
|
|
17
|
-
* in `@tsdown/css`): published Sanity libraries ship minified CSS. Set `minify: false` for
|
|
18
|
-
* readable output.
|
|
19
17
|
* - When the effective CSS syntax lowering target (`target`, falling back to the top-level
|
|
20
18
|
* `target`) is undefined or names no browsers (e.g. `'node20'`, resolved from
|
|
21
19
|
* `engines.node`), the lowering targets are resolved from `@sanity/browserslist-config` and
|
|
22
20
|
* passed through `lightningcss.targets` — where the plugin (like `@tsdown/css`) would skip
|
|
23
21
|
* lowering. `target: false` stays the explicit off switch, and a user-provided
|
|
24
22
|
* `lightningcss.targets` wins over the fallback.
|
|
23
|
+
*
|
|
24
|
+
* `minify` is not set, so it stays the plugin's default (`false`, matching `css.minify` in
|
|
25
|
+
* `@tsdown/css`). Set `minify: true` to minify the extracted CSS.
|
|
25
26
|
* @public
|
|
26
27
|
*/
|
|
27
28
|
export type PackageVanillaExtractOptions = Options;
|
|
29
|
+
/**
|
|
30
|
+
* Options for the `panda` option — the same options as `@sanity/pandacss-tsdown-plugin`
|
|
31
|
+
* (`cwd`, `configPath`, `outdir` and `transform` from `@pandacss/vite`, `codegen` and
|
|
32
|
+
* `polyfill`, plus `fileName`, `minify`, `target`, `lightningcss`, `inject`, and `exports`,
|
|
33
|
+
* modeled after the `css` options of `@tsdown/css`), with the same Sanity-flavored defaults as
|
|
34
|
+
* {@link PackageVanillaExtractOptions | `vanillaExtract`} on top:
|
|
35
|
+
*
|
|
36
|
+
* - `inject` and `exports` default to `true` and `{nodeCompat: true}` (instead of the plugin's
|
|
37
|
+
* `false` for both), wiring up the conditional CSS export pattern that Sanity libraries ship
|
|
38
|
+
* with. Set `exports: true` for a plain (browser-only) CSS export, `exports: false` for a
|
|
39
|
+
* relative CSS import, or `inject: false` to only extract the CSS.
|
|
40
|
+
* - When the effective CSS syntax lowering target (`target`, falling back to the top-level
|
|
41
|
+
* `target`) is undefined or names no browsers (e.g. `'node20'`, resolved from
|
|
42
|
+
* `engines.node`), the lowering targets are resolved from `@sanity/browserslist-config` and
|
|
43
|
+
* passed through `lightningcss.targets` — where the plugin (like `@tsdown/css`) would skip
|
|
44
|
+
* lowering. `target: false` stays the explicit off switch, and a user-provided
|
|
45
|
+
* `lightningcss.targets` wins over the fallback.
|
|
46
|
+
*
|
|
47
|
+
* `minify` is not set, so it stays the plugin's default (`false`, matching `css.minify` in
|
|
48
|
+
* `@tsdown/css`). Set `minify: true` to minify the extracted CSS.
|
|
49
|
+
*
|
|
50
|
+
* The options are declared here rather than imported from the plugin: the plugin is an
|
|
51
|
+
* optional peer, and a declaration file importing types from a package that isn't installed
|
|
52
|
+
* fails every consumer's `skipLibCheck: false` type check (TS2307) — including the consumers
|
|
53
|
+
* that never enable `panda`. `test/panda-options.test.ts` type-checks that the two
|
|
54
|
+
* declarations stay identical.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export interface PackagePandaOptions {
|
|
58
|
+
/**
|
|
59
|
+
* The project root the Panda config is discovered from (`panda.config.ts` upward), and the
|
|
60
|
+
* directory its `include`/`exclude` globs are relative to — like `cwd` in `@pandacss/vite`.
|
|
61
|
+
* @defaultValue tsdown's resolved `cwd`
|
|
62
|
+
*/
|
|
63
|
+
cwd?: string;
|
|
64
|
+
/**
|
|
65
|
+
* An explicit Panda config file, relative to `cwd`, instead of discovering it upward — like
|
|
66
|
+
* `configPath` in `@pandacss/vite`.
|
|
67
|
+
*/
|
|
68
|
+
configPath?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Run Panda's codegen when a build starts (and after the config reloads in watch mode),
|
|
71
|
+
* writing only the `styled-system` artifacts whose content changed. Set to `false` when
|
|
72
|
+
* codegen is managed elsewhere.
|
|
73
|
+
* @defaultValue true
|
|
74
|
+
*/
|
|
75
|
+
codegen?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Where the codegen artifacts are written, relative to `cwd` — like `outdir` in
|
|
78
|
+
* `@pandacss/vite`.
|
|
79
|
+
* @defaultValue the `outdir` of the Panda config
|
|
80
|
+
*/
|
|
81
|
+
outdir?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Rewrite the `css()`, `cva()`, pattern and recipe calls of the Panda sources into static
|
|
84
|
+
* class names, so the published JavaScript carries no Panda runtime. On by default — unlike
|
|
85
|
+
* `transform` in `@pandacss/vite`, which defaults to `false` there because applications keep
|
|
86
|
+
* the runtime around. `false` only extracts the CSS.
|
|
87
|
+
* @defaultValue true
|
|
88
|
+
*/
|
|
89
|
+
transform?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Emit the extracted CSS without cascade layers (Panda's `@layer` polyfill).
|
|
92
|
+
* @defaultValue the `polyfill` option of the Panda config
|
|
93
|
+
*/
|
|
94
|
+
polyfill?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Name of the emitted CSS file, like `css.fileName` in `@tsdown/css`.
|
|
97
|
+
* @defaultValue "bundle.css"
|
|
98
|
+
*/
|
|
99
|
+
fileName?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Minify the extracted CSS with `lightningcss`, like `css.minify` in `@tsdown/css`.
|
|
102
|
+
* @defaultValue false
|
|
103
|
+
*/
|
|
104
|
+
minify?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* The target environment for CSS syntax lowering: esbuild-style target strings like
|
|
107
|
+
* `'chrome90'`, or `false` to disable lowering. Falls back to the top-level `target`, then
|
|
108
|
+
* to `@sanity/browserslist-config` (see above).
|
|
109
|
+
*/
|
|
110
|
+
target?: string | string[] | false;
|
|
111
|
+
/**
|
|
112
|
+
* Options passed through to `lightningcss`'s `transform()`, like `css.lightningcss` in
|
|
113
|
+
* `@tsdown/css`. `targets` wins over `target`; `unusedSymbols` extends the
|
|
114
|
+
* `--made-with-panda` entry the plugin always removes.
|
|
115
|
+
*/
|
|
116
|
+
lightningcss?: Omit<TransformOptions<CustomAtRules>, "filename" | "code">;
|
|
117
|
+
/**
|
|
118
|
+
* Inject the CSS import into every entry chunk that reaches Panda styles, like `css.inject`
|
|
119
|
+
* in `@tsdown/css`.
|
|
120
|
+
* @defaultValue true
|
|
121
|
+
*/
|
|
122
|
+
inject?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Publish the CSS file as the `"./<fileName>"` export subpath: `true` for a plain export,
|
|
125
|
+
* `{nodeCompat: true}` for the conditional export with the Node-compatible shim, `false` for
|
|
126
|
+
* a relative CSS import instead.
|
|
127
|
+
* @defaultValue `{nodeCompat: true}`
|
|
128
|
+
*/
|
|
129
|
+
exports?: boolean | CssExportsOptions$1;
|
|
130
|
+
}
|
|
28
131
|
/**
|
|
29
132
|
* Options for the `css` option — tsdown's experimental
|
|
30
133
|
* [`css` options](https://tsdown.dev/options/css) from `@tsdown/css` (`splitting`, `fileName`,
|
|
31
134
|
* `target`, `minify`, `lightningcss`, `postcss`, `modules`, `preprocessorOptions`,
|
|
32
|
-
* `transformer`, `inject`), plus an `exports` option this config implements on top
|
|
33
|
-
*
|
|
135
|
+
* `transformer`, `inject`), plus an `exports` option this config implements on top. `exports`
|
|
136
|
+
* defaults to `{nodeCompat: true}`, wiring up the conditional CSS export pattern: the
|
|
137
|
+
* self-referential `import "<pkg>/style.css"`, a no-op `style-css.js` shim with a
|
|
138
|
+
* `style-css.d.ts` declaration, and the conditional `"./style.css"` export written to
|
|
139
|
+
* `package.json`. `@tsdown/css` has no equivalent — its `inject` emits a relative
|
|
140
|
+
* `import "./style.css"`, which throws in runtimes that cannot load `.css` files. Set
|
|
141
|
+
* `exports: true` for a plain (browser-only) CSS export, or `exports: false` to fall back to
|
|
142
|
+
* `@tsdown/css`'s relative injection.
|
|
34
143
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* `style-css.d.ts` declaration, and the conditional `"./style.css"` export written to
|
|
38
|
-
* `package.json`. `@tsdown/css` has no equivalent — its `inject` emits a relative
|
|
39
|
-
* `import "./style.css"`, which throws in runtimes that cannot load `.css` files. Set
|
|
40
|
-
* `exports: true` for a plain (browser-only) CSS export, or `exports: false` to fall back to
|
|
41
|
-
* `@tsdown/css`'s relative injection.
|
|
42
|
-
* - `minify` defaults to `true` (instead of `@tsdown/css`'s `false`): published Sanity
|
|
43
|
-
* libraries ship minified CSS. Set `minify: false` for readable output.
|
|
144
|
+
* `minify` is not set, so it stays `@tsdown/css`'s default (`false`). Set `minify: true` to
|
|
145
|
+
* minify the emitted CSS.
|
|
44
146
|
*
|
|
45
147
|
* The CSS syntax lowering target resolves exactly like
|
|
46
148
|
* {@link PackageVanillaExtractOptions | `vanillaExtract`}'s: browserless targets fall back to
|
|
@@ -279,7 +381,7 @@ export interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" |
|
|
|
279
381
|
* added `exports` option — requires
|
|
280
382
|
* [`@tsdown/css`](https://www.npmjs.com/package/@tsdown/css) to be installed in the project.
|
|
281
383
|
*
|
|
282
|
-
* By default (`exports: {nodeCompat: true}
|
|
384
|
+
* By default (`exports: {nodeCompat: true}`) the emitted CSS gets the same
|
|
283
385
|
* conditional CSS export treatment as {@link PackageOptions.vanillaExtract}: the
|
|
284
386
|
* self-referential `import "<pkg>/style.css"`, a no-op `style-css.js` shim with its
|
|
285
387
|
* `style-css.d.ts` declaration, and the conditional `"./style.css"` export written to
|
|
@@ -342,7 +444,8 @@ export interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" |
|
|
|
342
444
|
styledComponents?: boolean | StyledComponentsOptions;
|
|
343
445
|
/**
|
|
344
446
|
* Enables `@sanity/vanilla-extract-tsdown-plugin` to extract CSS into a separate file,
|
|
345
|
-
*
|
|
447
|
+
* lowered with `lightningcss`. CSS is left unminified unless `minify: true` is set. The
|
|
448
|
+
* lowering targets come from the effective
|
|
346
449
|
* `target` (`vanillaExtract.target`, falling back to the top-level `target`) when it names
|
|
347
450
|
* browsers; when it's undefined or browserless (e.g. `'node20'`), they're resolved from
|
|
348
451
|
* `@sanity/browserslist-config` instead — see {@link PackageVanillaExtractOptions}. Pass
|
|
@@ -359,6 +462,30 @@ export interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" |
|
|
|
359
462
|
* @alpha
|
|
360
463
|
*/
|
|
361
464
|
vanillaExtract?: boolean | PackageVanillaExtractOptions;
|
|
465
|
+
/**
|
|
466
|
+
* Enables `@sanity/pandacss-tsdown-plugin`, the library-build companion of `@pandacss/vite`
|
|
467
|
+
* for [Panda CSS](https://panda-css.com) packages: it loads `panda.config.ts`, rewrites the
|
|
468
|
+
* `css()`/`cva()`/pattern/recipe calls of the sources the config covers into static class
|
|
469
|
+
* names (so the published JavaScript carries no Panda runtime), and extracts the generated
|
|
470
|
+
* stylesheet into a separate file, lowered with `lightningcss`. CSS is left unminified unless
|
|
471
|
+
* `minify: true` is set, and the lowering targets resolve exactly like
|
|
472
|
+
* {@link PackageOptions.vanillaExtract | `vanillaExtract`}'s — see
|
|
473
|
+
* {@link PackagePandaOptions}. Pass `true` to use the defaults, or an object to customize.
|
|
474
|
+
*
|
|
475
|
+
* Install `@sanity/pandacss-tsdown-plugin`; like `@pandacss/vite`, it brings the Panda
|
|
476
|
+
* compiler and transformer it runs as regular dependencies, while the package keeps its own
|
|
477
|
+
* `@pandacss/dev` for `panda.config.ts` and the `panda` CLI. The plugin runs Panda's codegen
|
|
478
|
+
* when the build starts (writing only the artifacts whose content changed), so the
|
|
479
|
+
* `styled-system` directory matches the config the CSS is extracted with; keep the usual
|
|
480
|
+
* `"prepare": "panda codegen"` script so it also exists for the type checker before a build.
|
|
481
|
+
*
|
|
482
|
+
* By default (`inject: true` with `exports: {nodeCompat: true}`) the plugin also injects the
|
|
483
|
+
* self-referential `import "<pkg>/bundle.css"`, emits a `bundle-css.js` shim, and writes the
|
|
484
|
+
* conditional `"./bundle.css"` export to `package.json`, like
|
|
485
|
+
* {@link PackageOptions.vanillaExtract | `vanillaExtract`} does.
|
|
486
|
+
* @alpha
|
|
487
|
+
*/
|
|
488
|
+
panda?: boolean | PackagePandaOptions;
|
|
362
489
|
/**
|
|
363
490
|
* Runs `@microsoft/api-extractor` after the build (via tsdown's `build:done` hook) to check
|
|
364
491
|
* that TSDoc tags are valid and release tags are correct. Useful for packages consumed by
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["VanillaExtractPluginOptions","CssExportsOptions","BabelReactCompilerPluginOptions","OxcReactCompilerOptions"],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["VanillaExtractPluginOptions","LightningCssTransformOptions","CssExportsOptions","BabelReactCompilerPluginOptions","OxcReactCompilerOptions"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;YAsDY,+BAA+BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8B1B;;;;;;EAMf;;;;;EAKA;;;;;;;EAOA;;;;;;EAMA;;;;;;;;EAQA;;;;;EAKA;;;;;EAKA;;;;;EAKA;;;;;;EAMA;;;;;;EAMA,eAAe,KAAKC,iBAA6B;;;;;;EAMjD;;;;;;;EAOA,oBAAoBC;;;;;;;;;;;;;;;;;;;;;;;YAwBV,oBAAoB,YAAY;;;;;;;;;;;;;;;EAe1C,oBAAoBA;;;;;;;;;;;;;;;;;;iBAmBL;;;;;;;EAOf;;;;;;EAMA;;;;;;iBAOe;;EAEf;;;;;EAKA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;;;;;;;iBAQe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6Bf;;;;;;;;iBAgBe,kCACP,QAAQC,gBAAkC;;;;;EAKlD;;;;;;;;iBASe,gCACPC,wBAAyB;;;;;;;EAOjC;;;;;;;;YASU,uBAAuB,4BAA4B;;;;iBAK9C,uBAAuB,KACtC;;;;;;;;;;;;;EAeA,WAAW;;;;;;;;;;;EAWX,MAAM;;;;;;;;;;;;;;;;;;;EAmBN,QAAQ;;;;;;;;;;;;;;;;;;;;;EAqBR,UAAU;;;;;;;EAOV,YAAY;;;;;;EAMZ,OAAO;;;;;;;;;;;;;;;;;;;EAmBP,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BN,2BAA2B;;;;;;;;;;;;;EAa3B,0BAA0B;;;;;;;;EAQ1B,6BAA6B;;;;;;;;;;;;;;;;;;;;EAoB7B,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;EAwB3B,kBAAkB;;;;;;;;EAQlB,kBAAkB;;;;;;;;;;;;;;;;;;;;;EAqBlB,mBAAmB;;;;;;;wBAQL,aACd,SAAS;EAAkB,eAAe;IAAwB;;IACjE,QAAQ;;;;;wBAKK,aACd,SAAS;EAAkB,eAAe;IAAwB;;IACjE,QAAQ;;;;;;;wBAOK,aACd,SAAS;EAAkB,eAAe;IACzC,QAAQ,aAAa;;;;wBAIR,aAAa,UAAU,iBAAiB,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -42,7 +42,7 @@ async function resolvePackageConfig(options, variant) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
if (options.vanillaExtract) {
|
|
45
|
-
let [{ vanillaExtractPlugin }, { resolveCssLoweringTargets }] = await Promise.all([import("@sanity/vanilla-extract-tsdown-plugin"), import("./cssLoweringTargets-
|
|
45
|
+
let [{ vanillaExtractPlugin }, { resolveCssLoweringTargets }] = await Promise.all([import("@sanity/vanilla-extract-tsdown-plugin"), import("./cssLoweringTargets-CBJMQRZ_.mjs")]), vanillaExtract = options.vanillaExtract === !0 ? {} : options.vanillaExtract, lightningcss = await resolveCssLoweringTargets({
|
|
46
46
|
cssTarget: vanillaExtract.target,
|
|
47
47
|
target,
|
|
48
48
|
lightningcss: vanillaExtract.lightningcss
|
|
@@ -50,20 +50,34 @@ async function resolvePackageConfig(options, variant) {
|
|
|
50
50
|
plugins.push(vanillaExtractPlugin({
|
|
51
51
|
inject: !0,
|
|
52
52
|
exports: { nodeCompat: !0 },
|
|
53
|
-
minify: !0,
|
|
54
53
|
...vanillaExtract,
|
|
55
54
|
lightningcss
|
|
56
55
|
}));
|
|
57
56
|
}
|
|
57
|
+
if (options.panda) {
|
|
58
|
+
let panda = options.panda === !0 ? {} : options.panda, pandaFileName = panda.fileName ?? "bundle.css";
|
|
59
|
+
if (options.vanillaExtract && ((options.vanillaExtract === !0 ? {} : options.vanillaExtract).fileName ?? "bundle.css") === pandaFileName) throw Error(`\`panda\` and \`vanillaExtract\` both extract their CSS into "${pandaFileName}", so one would overwrite the other's stylesheet and \`./${pandaFileName}\` export. Give one of them a distinct file name, e.g. \`panda: {fileName: 'panda.css'}\`.`);
|
|
60
|
+
if (options.css && (options.css.fileName ?? "style.css") === pandaFileName) throw Error(`\`panda\` and \`css\` both write their CSS to "${pandaFileName}", so one would overwrite the other's stylesheet and \`./${pandaFileName}\` export. Give one of them a distinct file name, e.g. \`panda: {fileName: 'panda.css'}\`.`);
|
|
61
|
+
let [{ pandacssPlugin }, { resolveCssLoweringTargets }] = await Promise.all([import("@sanity/pandacss-tsdown-plugin"), import("./cssLoweringTargets-CBJMQRZ_.mjs")]), lightningcss = await resolveCssLoweringTargets({
|
|
62
|
+
cssTarget: panda.target,
|
|
63
|
+
target,
|
|
64
|
+
lightningcss: panda.lightningcss
|
|
65
|
+
});
|
|
66
|
+
plugins.push(pandacssPlugin({
|
|
67
|
+
inject: !0,
|
|
68
|
+
exports: { nodeCompat: !0 },
|
|
69
|
+
...panda,
|
|
70
|
+
lightningcss
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
58
73
|
let css;
|
|
59
74
|
if (options.css) {
|
|
60
|
-
let { exports: cssExports, ...cssOptions } = options.css, { resolveCssLoweringTargets } = await import("./cssLoweringTargets-
|
|
75
|
+
let { exports: cssExports, ...cssOptions } = options.css, { resolveCssLoweringTargets } = await import("./cssLoweringTargets-CBJMQRZ_.mjs"), lightningcss = await resolveCssLoweringTargets({
|
|
61
76
|
cssTarget: cssOptions.target,
|
|
62
77
|
target,
|
|
63
78
|
lightningcss: cssOptions.lightningcss
|
|
64
79
|
});
|
|
65
80
|
css = {
|
|
66
|
-
minify: !0,
|
|
67
81
|
...cssOptions,
|
|
68
82
|
lightningcss
|
|
69
83
|
};
|
|
@@ -259,7 +273,7 @@ const RE_JS_FILE = /\.(m?js|cjs)$/, RUNTIME_CONDITIONS = /* @__PURE__ */ new Set
|
|
|
259
273
|
* chunks — reconstructed in the exact `./<outDir relative to the package root>/<fileName>`
|
|
260
274
|
* form tsdown writes into the exports map, so entries that share a leaf name (`index.js` vs
|
|
261
275
|
* `features/index.js`) can never shadow each other, and non-entry exports (`./package.json`,
|
|
262
|
-
* the conditional `./bundle.css` export of `vanillaExtract`, `devExports` source paths like
|
|
276
|
+
* the conditional `./bundle.css` export of `vanillaExtract`/`panda`, `devExports` source paths like
|
|
263
277
|
* `./src/index.ts`) pass through untouched. The `react-server` files themselves never enter
|
|
264
278
|
* the map — the `react-server` variant builds with `exports: false` — so they don't become
|
|
265
279
|
* export subpaths of their own.
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["defineTsdownConfig","\"default\"","\"types\""],"sources":["../src/index.ts"],"sourcesContent":["import path from 'node:path'\nimport type {\n CssExportsOptions,\n Options as VanillaExtractPluginOptions,\n} from '@sanity/vanilla-extract-tsdown-plugin'\nimport type {PluginOptions as BabelReactCompilerPluginOptions} from 'babel-plugin-react-compiler'\nimport type {ReactCompilerOptions as OxcReactCompilerOptions} from 'oxc-transform-react'\nimport {detect} from 'package-manager-detector/detect'\nimport {\n defineConfig as defineTsdownConfig,\n mergeConfig,\n type PackageJsonWithPath,\n type Rolldown,\n type RolldownChunk,\n type UserConfig,\n} from 'tsdown'\nimport type {PackageTsdocOptions} from './tsdoc/types.ts'\n\nexport type {\n PackageTsdocCustomTag,\n PackageTsdocOptions,\n PackageTsdocRuleLevel,\n} from './tsdoc/types.ts'\n\n// Only types are re-exported from the plugin packages: a value re-export would make\n// `@sanity/vanilla-extract-tsdown-plugin` a static import of this entry, pulling the whole\n// vanilla-extract toolchain (the rolldown plugin, `@sanity/vanilla-extract-integration`,\n// `@vanilla-extract/css`, and the native `lightningcss` binary) into every consumer's module\n// graph — including packages with no CSS at all. Everything that needs those helpers loads\n// them through the `await import(...)` calls below.\nexport type {CssExportsOptions} from '@sanity/vanilla-extract-tsdown-plugin'\n\n/**\n * Options for the `vanillaExtract` option — the same options as\n * `@sanity/vanilla-extract-tsdown-plugin` (`identifiers`, `fileName`, `minify`, `target`,\n * `lightningcss`, `inject`, and `exports`, all modeled after the `css` options of\n * `@tsdown/css`), with three Sanity-flavored defaults on top:\n *\n * - `inject` and `exports` default to `true` and `{nodeCompat: true}` (instead of the plugin's\n * `false` for both), wiring up the conditional CSS export pattern that Sanity libraries ship\n * with. Set `exports: true` for a plain (browser-only) CSS export, `exports: false` for a\n * relative CSS import, or `inject: false` to only extract the CSS.\n * - `minify` defaults to `true` (instead of the plugin's `false`, which matches `css.minify`\n * in `@tsdown/css`): published Sanity libraries ship minified CSS. Set `minify: false` for\n * readable output.\n * - When the effective CSS syntax lowering target (`target`, falling back to the top-level\n * `target`) is undefined or names no browsers (e.g. `'node20'`, resolved from\n * `engines.node`), the lowering targets are resolved from `@sanity/browserslist-config` and\n * passed through `lightningcss.targets` — where the plugin (like `@tsdown/css`) would skip\n * lowering. `target: false` stays the explicit off switch, and a user-provided\n * `lightningcss.targets` wins over the fallback.\n * @public\n */\nexport type PackageVanillaExtractOptions = VanillaExtractPluginOptions\n\n/**\n * Options for the `css` option — tsdown's experimental\n * [`css` options](https://tsdown.dev/options/css) from `@tsdown/css` (`splitting`, `fileName`,\n * `target`, `minify`, `lightningcss`, `postcss`, `modules`, `preprocessorOptions`,\n * `transformer`, `inject`), plus an `exports` option this config implements on top, with two\n * Sanity-flavored defaults:\n *\n * - `exports` defaults to `{nodeCompat: true}`, wiring up the conditional CSS export pattern:\n * the self-referential `import \"<pkg>/style.css\"`, a no-op `style-css.js` shim with a\n * `style-css.d.ts` declaration, and the conditional `\"./style.css\"` export written to\n * `package.json`. `@tsdown/css` has no equivalent — its `inject` emits a relative\n * `import \"./style.css\"`, which throws in runtimes that cannot load `.css` files. Set\n * `exports: true` for a plain (browser-only) CSS export, or `exports: false` to fall back to\n * `@tsdown/css`'s relative injection.\n * - `minify` defaults to `true` (instead of `@tsdown/css`'s `false`): published Sanity\n * libraries ship minified CSS. Set `minify: false` for readable output.\n *\n * The CSS syntax lowering target resolves exactly like\n * {@link PackageVanillaExtractOptions | `vanillaExtract`}'s: browserless targets fall back to\n * `@sanity/browserslist-config` through `lightningcss.targets`.\n * @public\n */\nexport type PackageCssOptions = NonNullable<UserConfig['css']> & {\n /**\n * Publish each emitted CSS file as an export subpath of the package, so consumers can\n * `import \"<pkg-name>/style.css\"` — which is also the specifier `inject` then uses, instead\n * of `@tsdown/css`'s relative path.\n *\n * - `true` declares a plain `\"./style.css\": \"./dist/style.css\"` export. Enough for packages\n * that only ever run in browsers or bundlers.\n * - `{nodeCompat: true}` declares a conditional export instead, whose `browser`/`style`\n * conditions point at the stylesheet while `node`/`default` point at a no-op JS shim\n * emitted next to it, with a declaration file for the export's `types` condition. That\n * keeps the subpath resolvable in runtimes that cannot load `.css` files.\n *\n * @defaultValue `{nodeCompat: true}`\n */\n exports?: boolean | CssExportsOptions\n}\n\n/**\n * Options for the `bundleAnalyzer` option — the same options as Rolldown's experimental\n * [`bundleAnalyzerPlugin`](https://rolldown.rs/builtin-plugins/bundle-analyzer)\n * (`fileName`, `format`).\n *\n * When enabled with `true`, defaults to `{format: 'md'}` (an LLM-friendly markdown report)\n * rather than the plugin's own `'json'` default — that's the report Sanity library builds\n * want. Pass `{format: 'json'}` for the structured data file visualizers consume.\n *\n * The report is emitted into `outDir` (`analyze-data.md` by default) and is **not** a\n * publishable artifact. Exclude it from `package.json` `files` (e.g.\n * `\"!dist/analyze-data.md\"` / `\"!lib/analyze-data.md\"`) so an accidental analyze build\n * cannot ship it.\n * @public\n * @alpha This option wraps Rolldown's experimental analyzer, whose API may change.\n */\nexport interface PackageBundleAnalyzerOptions {\n /**\n * The filename used for the emitted analysis asset. The file is written into the same\n * output directory as the rest of the bundle.\n * @defaultValue `'analyze-data.md'` when `format` is `'md'`, `'analyze-data.json'` when\n * `format` is `'json'`\n */\n fileName?: string\n /**\n * `'md'` produces an LLM-friendly markdown report (Quick Summary, largest modules, entry\n * points, dependency chains); `'json'` produces structured data for visualizers.\n * @defaultValue `'md'`\n */\n format?: 'json' | 'md'\n}\n\n/**\n * Options for the `styled-components` transform, the same options as `babel-plugin-styled-components`.\n * @public\n */\nexport interface StyledComponentsOptions {\n /** @defaultValue true */\n displayName?: boolean\n /**\n * @defaultValue []\n * @example [\"\\@xstyled/styled-components\", \"\\@xstyled/styled-components/*\"]\n */\n topLevelImportPaths?: string[]\n /** @defaultValue true */\n ssr?: boolean\n /** @defaultValue false */\n fileName?: boolean\n /** @defaultValue [\"index\"] */\n meaninglessFileNames?: string[]\n /** @defaultValue true */\n minify?: boolean\n /** @defaultValue false */\n transpileTemplateLiterals?: boolean\n namespace?: string\n /** @defaultValue true */\n pure?: boolean\n}\n\n/**\n * The options of this config that both React Compiler implementations share — never\n * forwarded to the compiler itself.\n * @public\n */\nexport interface ReactCompilerConfigOptions {\n /**\n * Also emit an uncompiled build of every entry (`<name>.react-server.js` next to `<name>.js`),\n * wired to the `react-server` export condition in `package.json`:\n *\n * ```json\n * \".\": {\n * \"types\": \"./dist/index.d.ts\",\n * \"react-server\": \"./dist/index.react-server.js\",\n * \"default\": \"./dist/index.js\"\n * }\n * ```\n *\n * React Server Components refuse to load React Compiler output (`react/compiler-runtime`\n * throws in the `react-server` environment), so a library that ships compiled code\n * publishes two entrypoints: the compiled one (the `default` condition) and an uncompiled\n * one (the `react-server` condition) — see\n * https://github.com/facebook/react/issues/31702.\n *\n * Both builds come from the same source, and the only difference is that React Compiler\n * auto-memoization is applied to the non-`react-server` output; nothing is stripped from\n * either output. Pair it with deleting manual `useMemo`/`useCallback` calls from the\n * source: server components stop paying for memoization that can never pay off (they\n * render exactly once), and client components get the compiler's finer-grained\n * memoization instead.\n * @defaultValue false\n * @alpha This option is experimental and not covered by semver: it can change behavior or\n * be removed entirely in a minor version.\n */\n reactServer?: boolean\n}\n\n// `interface … extends` on purpose, not intersection aliases: an uninstalled peer's type\n// import degrades to `any` (skipLibCheck), and in an intersection that `any` would swallow\n// the whole `ReactCompilerOptions` union, making every config match the `reactServer: true`\n// overload of `defineConfig` (the bug sanity-io/ui had to stub around). Unresolvable\n// heritage clauses are dropped instead, leaving each interface's own members (`transform`,\n// `reactServer`), so the union keeps discriminating. See `test/optional-peer-types.test.ts`.\n\n/**\n * The `transform: 'babel'` shape: `babel-plugin-react-compiler` (an optional peer dependency)\n * runs the compiler, with its own `PluginOptions` — typed once the package is installed.\n * Install it together with `@rolldown/plugin-babel` and `@babel/core`.\n * @public\n */\nexport interface ReactCompilerBabelOptions\n extends Partial<BabelReactCompilerPluginOptions>, ReactCompilerConfigOptions {\n /**\n * The reference implementation — for what the Rust port lacks: custom `jsxImportSource`,\n * `logger`, function-valued `sources`.\n */\n transform: 'babel'\n}\n\n/**\n * The default `reactCompiler` shape: `oxc-transform-react` (an optional peer dependency) runs\n * the compiler, with its own `ReactCompilerOptions` — the serializable subset of the babel\n * plugin's (no `logger`, no function-valued `sources`), typed once the package is installed.\n * @public\n */\nexport interface ReactCompilerOxcOptions\n extends OxcReactCompilerOptions, ReactCompilerConfigOptions {\n /**\n * `oxc-transform-react`, the Rust port. Its one native pass also strips TypeScript and\n * lowers JSX (automatic runtime, `react` import source) — opt into `'babel'` for a\n * custom `jsxImportSource`.\n * @defaultValue 'oxc'\n */\n transform?: 'oxc'\n}\n\n/**\n * Options for the React Compiler: the compiler's own options, plus `transform` (which\n * implementation runs) and `reactServer` (the dual React Server Components build) — both\n * handled by this config, never forwarded to the compiler.\n * @public\n */\nexport type ReactCompilerOptions = ReactCompilerBabelOptions | ReactCompilerOxcOptions\n\n/**\n * @public\n */\nexport interface PackageOptions extends Pick<\n UserConfig,\n 'tsconfig' | 'entry' | 'format' | 'dts' | 'define' | 'target' | 'outDir'\n> {\n /**\n * @defaultValue 'neutral'\n *\n * When left at `'neutral'` (the default), two resolution tweaks compensate for rolldown's\n * strict neutral defaults: `deps.neverBundle` includes `/^node:/` (node built-ins stay external\n * so neutral does not warn about them as unresolvable; only node runtimes execute those code\n * paths), and `inputOptions.resolve.mainFields` falls back to `['module', 'main']` for inlined\n * dependencies that ship no `exports` map (e.g. `rxjs-etc/operators`). Prefer `'neutral'` over\n * `'node'` for packages that also run in the browser - `'node'` makes CommonJS-interop emit a\n * module-scope `createRequire(import.meta.url)` for inlined CJS deps, which crashes\n * browser-bundled consumers.\n */\n platform?: UserConfig['platform']\n /**\n * The working directory of the build — forwarded to tsdown's own `cwd` option, and also used\n * for the package-manager detection that decides the pnpm-gated `devExports` default of the\n * {@link PackageOptions.exports | `exports`} option (instead of `process.cwd()`).\n *\n * Config files can leave it unset; set it when driving builds programmatically for a package\n * in another directory, e.g. from a monorepo script or a tool composing this config (like\n * `@sanity/pkg-utils`).\n * @defaultValue `process.cwd()`\n */\n cwd?: UserConfig['cwd']\n /**\n * Clean directories before each build. Prefer an array of folders over a separate `\"clean\"`\n * script in `package.json` (e.g. `rimraf dist coverage`) — tsdown removes them as part of\n * `tsdown` / `pnpm build`, so packages don't need `rimraf`, a `clean` script, or\n * `prebuild`/`run-s clean build` wiring.\n *\n * - `true` (tsdown's default when left undefined) cleans `outDir` (`'dist'` by default)\n * - `false` skips cleaning\n * - a `string[]` replaces that default with the listed paths/globs — include `outDir` (e.g.\n * `'dist'`) when you still want it cleaned alongside other folders\n *\n * @defaultValue true\n * @example\n * ```ts\n * // Instead of `\"clean\": \"rimraf dist coverage\"` in package.json:\n * clean: ['dist', 'coverage']\n * ```\n */\n clean?: UserConfig['clean']\n /**\n * tsdown's `exports` option, with defaults suited for publishing Sanity libraries:\n * `enabled: true` generates the `exports` map on every build, whether `CI` is set or not\n * (GitHub Actions, Cursor Cloud, local shells, …). Relying on `'local-only'`/`'ci-only'`\n * surprised too many environments that set `CI=true` without meaning \"don't rewrite\n * package.json\". When pnpm is detected, `devExports: true` also keeps the local `exports`\n * map pointing at source files while `publishConfig.exports` receives the built files.\n *\n * Userland values apply with tsdown's `mergeConfig` semantics: an object deep-merges over\n * these defaults (so individual fields can be overridden), while any other value - `false`\n * to disable exports generation, or a bare CI condition (`'ci-only'`/`'local-only'`) -\n * replaces them entirely.\n *\n * The package-manager detection behind the `devExports` default reads from\n * {@link PackageOptions.cwd | `cwd`} and only runs when the default can still apply — it is\n * skipped when the value replaces the defaults (`false`, `true`, a bare CI condition) or\n * sets `devExports` explicitly.\n * @defaultValue `{enabled: true, devExports: true}` for pnpm projects;\n * `{enabled: true}` otherwise.\n */\n exports?: UserConfig['exports']\n /**\n * Whether to generate source map files. The same default as the `sourcemap` option in\n * `@sanity/pkg-utils` - tsdown itself defaults to `false` and does not read `sourceMap` from\n * the tsconfig.\n * @defaultValue true\n */\n sourcemap?: UserConfig['sourcemap']\n /**\n * tsdown's `deps` option. When `platform` is `'neutral'` (the default), `neverBundle` always\n * includes `/^node:/` and userland `neverBundle` entries are appended (tsdown's `mergeConfig`\n * would replace the array). Other `deps` fields pass through as-is.\n */\n deps?: UserConfig['deps']\n /**\n * tsdown's experimental [`css` option](https://tsdown.dev/options/css) (CSS modules,\n * preprocessors, Lightning CSS / PostCSS, inject, etc), with Sanity-flavored defaults and an\n * added `exports` option — requires\n * [`@tsdown/css`](https://www.npmjs.com/package/@tsdown/css) to be installed in the project.\n *\n * By default (`exports: {nodeCompat: true}`, `minify: true`) the emitted CSS gets the same\n * conditional CSS export treatment as {@link PackageOptions.vanillaExtract}: the\n * self-referential `import \"<pkg>/style.css\"`, a no-op `style-css.js` shim with its\n * `style-css.d.ts` declaration, and the conditional `\"./style.css\"` export written to\n * `package.json` — see {@link PackageCssOptions}.\n *\n * Safe to combine with {@link PackageOptions.vanillaExtract}: vanilla-extract extracts into\n * `bundle.css` by default, while `@tsdown/css` merges other CSS (including `.module.css`)\n * into `style.css`, so the two pipelines do not collide.\n * @see https://tsdown.dev/reference/api/Interface.InlineConfig#css\n * @alpha\n */\n css?: PackageCssOptions\n /**\n * Enables Rolldown's experimental\n * [`bundleAnalyzerPlugin`](https://rolldown.rs/builtin-plugins/bundle-analyzer)\n * (`rolldown/experimental`) to emit a report of what the package itself bundles — chunks,\n * modules, dependency chains — next to the build output. Pass `true` to use the defaults,\n * or an object to customize.\n *\n * Unlike the plugin's own defaults (`format: 'json'`), `true` selects `format: 'md'`: an\n * LLM-friendly markdown report (`analyze-data.md` in `outDir`). Pass `{format: 'json'}`\n * for the structured data file visualizers consume. Analysis adds work to the build, so\n * this stays off by default — typical usage is an env-gated opt-in:\n *\n * ```ts\n * bundleAnalyzer: process.env.ENABLE_BUNDLE_ANALYZER === 'true'\n * ```\n *\n * The report is **not** a publishable artifact. Exclude it from `package.json` `files`\n * (e.g. `\"!dist/analyze-data.md\"` / `\"!lib/analyze-data.md\"`) so an accidental analyze\n * build cannot ship it.\n *\n * With {@link ReactCompilerOptions.reactServer | `reactCompiler.reactServer`}, only the\n * compiled (`default`) variant is analyzed — the `react-server` variant skips it so the\n * two builds don't overwrite one report.\n * @defaultValue false\n * @alpha This option wraps Rolldown's experimental analyzer, whose API may change.\n */\n bundleAnalyzer?: boolean | PackageBundleAnalyzerOptions\n /**\n * Runs the React Compiler on the source files before they are bundled, so published\n * components are memoized automatically. Pass `true` to use the defaults, or an options\n * object (e.g. `{target: '18'}`). This is the same feature as the\n * `reactCompiler` option in `@sanity/pkg-utils`.\n *\n * `transform` picks the implementation — `'oxc'` (default, requires `oxc-transform-react`)\n * or `'babel'` (requires `babel-plugin-react-compiler`, `@rolldown/plugin-babel` and\n * `@babel/core`), see {@link ReactCompilerBabelOptions} — and `reactServer` adds the\n * uncompiled `react-server` build, see {@link ReactCompilerConfigOptions.reactServer}.\n * @defaultValue false\n */\n reactCompiler?: boolean | ReactCompilerOptions\n /**\n * Applies the `styled-components` transform (`displayName`, `componentId`, CSS minification, etc)\n * with the same defaults as the `babel: {styledComponents: true}` option in `@sanity/pkg-utils`.\n * Unlike `@sanity/pkg-utils` it doesn't use `babel-plugin-styled-components`, but oxc's native port of it,\n * so there's no need to install babel dependencies.\n * @defaultValue false\n */\n styledComponents?: boolean | StyledComponentsOptions\n /**\n * Enables `@sanity/vanilla-extract-tsdown-plugin` to extract CSS into a separate file,\n * minified and lowered with `lightningcss`. The lowering targets come from the effective\n * `target` (`vanillaExtract.target`, falling back to the top-level `target`) when it names\n * browsers; when it's undefined or browserless (e.g. `'node20'`), they're resolved from\n * `@sanity/browserslist-config` instead — see {@link PackageVanillaExtractOptions}. Pass\n * `true` to use the defaults, or an object to customize.\n *\n * By default (`inject: true` with `exports: {nodeCompat: true}`) the plugin also injects the\n * self-referential `import \"<pkg>/bundle.css\"`, emits a `bundle-css.js` shim, and writes the\n * conditional `\"./bundle.css\"` export to `package.json` - see\n * {@link PackageVanillaExtractOptions}. This is the same feature as `rollup.vanillaExtract`\n * in `@sanity/pkg-utils`.\n *\n * Combines with {@link PackageOptions.css}: enable both when a package uses vanilla-extract\n * alongside CSS modules (or other `@tsdown/css` features).\n * @alpha\n */\n vanillaExtract?: boolean | PackageVanillaExtractOptions\n /**\n * Runs `@microsoft/api-extractor` after the build (via tsdown's `build:done` hook) to check\n * that TSDoc tags are valid and release tags are correct. Useful for packages consumed by\n * TSDoc-based tooling. Off by default — set `tsdoc: true` to enable, or pass an options\n * object to customize rules and custom tags.\n * @defaultValue false\n */\n tsdoc?: boolean | PackageTsdocOptions\n /**\n * tsdown's `suppressWarnings` option: strings (matched with `includes`), regular expressions\n * (matched with `test`), or a predicate that drop build warnings before they're printed — and\n * before `failOnWarn` turns them into errors.\n *\n * Userland values are **added to** the built-in suppression instead of replacing it (which\n * `mergeConfig` would do, since it replaces functions): per-package suppressions can't\n * accidentally undo the declaration-only circular-dependency filter that this config pairs\n * with its `checks.circularDependency` default. This config always suppresses\n * `CIRCULAR_DEPENDENCY` warnings whose entire cycle consists of declaration files\n * (`.d.ts`/`.d.mts`/`.d.cts`) — those come from the declaration bundling pass, where every\n * import is type-only and erased at runtime, so the cycles are harmless and unavoidable for\n * mutually referencing public types (e.g. the schema definition types in `@sanity/types`).\n * Cycles involving a runtime module still warn.\n *\n * To drop the built-in suppression instead of adding to it, merge over the returned config —\n * `mergeConfig(await defineConfig(), {suppressWarnings: () => false})` restores every\n * warning, including the declaration-only cycles.\n * @defaultValue undefined — only the built-in declaration-only cycle suppression applies\n */\n suppressWarnings?: UserConfig['suppressWarnings']\n}\n\n/**\n * With `reactCompiler.reactServer` the config resolves to two tsdown configs: the compiled\n * `default` variant and the uncompiled `react-server` variant.\n * @public\n */\nexport function defineConfig(\n options: PackageOptions & {reactCompiler: ReactCompilerOptions & {reactServer: true}},\n): Promise<UserConfig[]>\n/**\n * Without `reactCompiler.reactServer` the config resolves to a single tsdown config.\n * @public\n */\nexport function defineConfig(\n options: PackageOptions & {reactCompiler: ReactCompilerOptions & {reactServer?: false}},\n): Promise<UserConfig>\n/**\n * When TypeScript can't tell whether `reactCompiler.reactServer` is set (a widened `boolean`,\n * e.g. through a `ReactCompilerOptions`-typed variable), the config resolves to either shape —\n * check `Array.isArray` on the result.\n * @public\n */\nexport function defineConfig(\n options: PackageOptions & {reactCompiler: ReactCompilerOptions},\n): Promise<UserConfig | UserConfig[]>\n/**\n * @public\n */\nexport function defineConfig(options?: PackageOptions): Promise<UserConfig>\n/**\n * @public\n */\nexport async function defineConfig(\n options: PackageOptions = {},\n): Promise<UserConfig | UserConfig[]> {\n const reactCompiler = options.reactCompiler ?? false\n // `reactCompiler.reactServer` opts into the dual React Server Components build: the same\n // config twice, where the only difference is that React Compiler auto-memoization is applied\n // to the non-`react-server` variant. Both variants build in one `tsdown` run — tsdown builds\n // the configs in parallel, cleans the shared `outDir` once before either variant emits, and\n // runs `exports` generation and `publint` per `package.json` only after every build for that\n // package has finished (so the `react-server` files exist by the time they're validated).\n if (typeof reactCompiler === 'object' && reactCompiler.reactServer === true) {\n return Promise.all([\n resolvePackageConfig(options, 'default'),\n resolvePackageConfig(options, 'react-server'),\n ])\n }\n return resolvePackageConfig(options, 'standalone')\n}\n\n/**\n * The build variants {@link defineConfig} produces: the classic single build\n * (`'standalone'`), or — with `reactCompiler.reactServer` — the compiled `'default'` variant\n * and the uncompiled `'react-server'` variant of the dual React Server Components build.\n */\ntype PackageConfigVariant = 'standalone' | 'default' | 'react-server'\n\nasync function resolvePackageConfig(\n options: PackageOptions,\n variant: PackageConfigVariant,\n): Promise<UserConfig> {\n // `tsconfig`, `entry`, `dts`, `define`, `target`, `outDir`, `clean`, `css` and `cwd` are\n // passed through to tsdown as-is. When left undefined, tsdown keeps its default behavior\n // (`tsconfig` is auto-detected from the project, `dts` from `package.json`, `define`\n // replaces nothing, `target` applies no syntax downleveling, `outDir` defaults to `'dist'`,\n // `clean` defaults to `true` — cleaning `outDir` before each build — `css` stays off\n // unless `@tsdown/css` is installed and the option is set, and `cwd` defaults to\n // `process.cwd()`).\n const {entry, tsconfig, define, target, outDir, cwd} = options\n const isReactServer = variant === 'react-server'\n // The `react-server` variant skips d.ts generation (the compiled variant's declarations\n // serve both entries — a `types` condition specified before `react-server` points every\n // resolution mode at them), never cleans (tsdown collects the clean paths of all configs\n // and cleans once, before either variant emits, so the compiled variant's `clean` already\n // covers the run), and skips `publint` (it runs once, from the compiled variant, after\n // both builds finish).\n const dts = isReactServer ? false : options.dts\n const clean = isReactServer ? false : options.clean\n const publint = !isReactServer\n const platform = options.platform ?? 'neutral'\n const sourcemap = options.sourcemap ?? true\n // The React Compiler is what the `react-server` variant exists to avoid: compiled output\n // loads `react/compiler-runtime`, which throws in the `react-server` environment.\n const reactCompiler = isReactServer ? false : (options.reactCompiler ?? false)\n const styledComponents = options.styledComponents ?? false\n // The `react-server` variant skips the analyzer so the two parallel builds don't race on\n // one `analyze-data.md` in the shared `outDir`. The compiled variant is the published\n // client bundle — that's the report worth reading.\n const bundleAnalyzer = isReactServer ? false : (options.bundleAnalyzer ?? false)\n // The `react-server` variant skips TSDoc checking (it emits no `.d.ts` files — the compiled\n // variant's declarations serve both entries), matching how it skips `publint`.\n const tsdoc = isReactServer ? false : (options.tsdoc ?? false)\n const report = {gzip: false} as const satisfies UserConfig['report']\n const format = options.format ?? 'esm'\n // When `platform` is `'neutral'`, restore the conventional `module`/`main` fallback that\n // rolldown's strict neutral defaults drop - needed for inlined deps without an `exports` map.\n const inputOptions = {\n // https://github.com/rolldown/rolldown/blob/main/packages/rolldown/src/options/docs/preserve-entry-signatures.md#strict\n preserveEntrySignatures: 'strict',\n experimental: {attachDebugInfo: 'none'},\n ...(platform === 'neutral' && {\n resolve: {mainFields: ['module', 'main']},\n }),\n ...(styledComponents !== false && {\n transform: {\n plugins: {\n styledComponents: {\n // The same defaults as `babel: {styledComponents: true}` in `@sanity/pkg-utils`:\n // `fileName` is unnecessary, as the way we use styled-components in Sanity is usually by wrapping\n // `@sanity/ui` primitives, not declaring new ones like \"const Button = styled.button``\"\n fileName: false,\n // Native template literals take less space than this transpilation, and unlike\n // `babel-plugin-styled-components`, oxc doesn't add a `@__PURE__` annotation to the\n // transpiled call expression either, so enabling it wouldn't improve tree-shaking\n transpileTemplateLiterals: false,\n // Helps dead code elimination and tree-shaking, although oxc only annotates plain call\n // expressions so far, not tagged template expressions (https://github.com/rollup/rollup/issues/4035)\n pure: true,\n // Disabled, as tsdown tends to be used for npm publishing, while other tooling,\n // like `sanity dev`, `next dev`, etc are used for testing\n cssProp: false,\n ...(typeof styledComponents === 'object' ? styledComponents : {}),\n },\n },\n },\n }),\n } satisfies UserConfig['inputOptions']\n\n // `neverBundle` is concatenated (not `mergeConfig`'d) so per-package externals add to the\n // `/^node:/` default for `platform: 'neutral'` instead of replacing it. Rolldown's\n // `ExternalOption` array form is `Array<string | RegExp>` only; a function override is composed.\n const userNeverBundle = options.deps?.neverBundle\n const nodeBuiltinExternal = platform === 'neutral' ? /^node:/ : undefined\n const neverBundle: NonNullable<UserConfig['deps']>['neverBundle'] =\n userNeverBundle == null\n ? nodeBuiltinExternal && [nodeBuiltinExternal]\n : nodeBuiltinExternal == null || userNeverBundle === true\n ? userNeverBundle\n : typeof userNeverBundle === 'function'\n ? (id, importer, isResolved) =>\n nodeBuiltinExternal.test(id) || userNeverBundle(id, importer, isResolved)\n : Array.isArray(userNeverBundle)\n ? [nodeBuiltinExternal, ...userNeverBundle]\n : [nodeBuiltinExternal, userNeverBundle]\n const deps: UserConfig['deps'] = {\n resolveDepSubpath: true,\n ...options.deps,\n ...(neverBundle === undefined ? {} : {neverBundle}),\n }\n\n // `outputOptions` is left to tsdown's defaults - notably chunk filenames keep tsdown's hashed\n // default (unless userland sets `hash`), which prevents chunk/entry filename collisions\n // (https://github.com/sanity-io/ui/issues/2262).\n const plugins: Rolldown.Plugin[] = []\n if (reactCompiler !== false) {\n // Lazy loaded so the toolchain is only paid for when enabled. The compiler package itself\n // (`oxc-transform-react` / `babel-plugin-react-compiler`, per `transform`) resolves from\n // the consumer package — everything babel-flavored is an optional peer dependency.\n const reactCompilerOptions: ReactCompilerOptions = reactCompiler === true ? {} : reactCompiler\n if (reactCompilerOptions.transform === 'babel') {\n // The opt-in reference implementation follows the official tsdown recipe for the React\n // Compiler: https://tsdown.dev/recipes/react-support#enabling-react-compiler\n // The compiler leaves TypeScript and JSX in place for rolldown's own transform.\n const [{default: pluginBabel}, {reactCompilerPreset}] = await Promise.all([\n import('@rolldown/plugin-babel').catch((cause: unknown) => {\n throw new Error(\n '`reactCompiler: {transform: \"babel\"}` needs `pnpm add -D @rolldown/plugin-babel @babel/core babel-plugin-react-compiler`.',\n {cause},\n )\n }),\n import('@vitejs/plugin-react'),\n ])\n const {\n reactServer: _reactServer,\n transform: _transform,\n ...compilerOptions\n } = reactCompilerOptions\n plugins.push(\n await pluginBabel({\n presets: [reactCompilerPreset(compilerOptions)],\n }),\n )\n } else {\n // The default: `@vitejs/plugin-react`'s `compiler` option — `oxc-transform-react`\n // compiles, strips TypeScript and lowers JSX in one native pass. Only the\n // `vite:react-compiler` plugin is cherry-picked — the rest of the array is Vite-only\n // (Fast Refresh wrapper, dev config). Outside Vite its defaults are what a library\n // build wants: production JSX, sourcemaps, no Fast Refresh. `transform`/`reactServer`\n // are this config's — drop before forwarding.\n const {\n reactServer: _reactServer,\n transform: _transform,\n ...compilerOptions\n } = reactCompilerOptions\n const {default: pluginReact} = await import('@vitejs/plugin-react')\n const compilerPlugin = pluginReact({\n compiler: compilerOptions,\n // Keep the one-pass transform away from rolldown-plugin-dts' generated `.d.ts` modules\n // (the default include matches them) — it would strip every type, collapsing the\n // bundled declarations to `export {}`. node_modules is restated because a userland\n // `exclude` replaces the plugin's default — with both separators, since plain rolldown\n // (unlike Vite) does not normalize Windows ids to POSIX.\n exclude: [/[\\\\/]node_modules[\\\\/]/, RE_DTS_FILE],\n }).find((plugin) => plugin.name === 'vite:react-compiler')\n if (!compilerPlugin) {\n throw new Error(\n '`@vitejs/plugin-react` returned no `vite:react-compiler` plugin — the installed version does not support the default `oxc` implementation of the `reactCompiler` option.',\n )\n }\n plugins.push(compilerPlugin)\n }\n }\n if (options.vanillaExtract) {\n // Lazy loaded, like `reactCompiler`, so the CSS toolchain is only paid for when the option is\n // enabled. The plugin compiles the `.css.ts` files and extracts the CSS into a single file.\n // Its `inject`/`exports` options are general purpose (and, like `css.inject` in\n // `@tsdown/css`, disabled by default), so this config supplies the default most Sanity\n // libraries want: `exports: {nodeCompat: true}` wires up the whole conditional CSS export\n // pattern - the self-referential CSS import, the no-op JS shim, and the conditional\n // `./<fileName>` export written through this config's `exports` option (which the plugin's\n // `tsdownConfig` hook composes into).\n const [{vanillaExtractPlugin}, {resolveCssLoweringTargets}] = await Promise.all([\n import('@sanity/vanilla-extract-tsdown-plugin'),\n import('./cssLoweringTargets.ts'),\n ])\n const vanillaExtract = options.vanillaExtract === true ? {} : options.vanillaExtract\n\n const lightningcss = await resolveCssLoweringTargets({\n cssTarget: vanillaExtract.target,\n target,\n lightningcss: vanillaExtract.lightningcss,\n })\n\n plugins.push(\n vanillaExtractPlugin({\n inject: true,\n exports: {nodeCompat: true},\n minify: true,\n ...vanillaExtract,\n lightningcss,\n }),\n )\n }\n\n // `@tsdown/css` compiles CSS but has no node-shim concept, so the `exports` option (and the\n // plugin implementing it) lives here. Its `exports` key is not a `@tsdown/css` option, so it\n // is stripped before the rest is handed to tsdown.\n let css: UserConfig['css']\n if (options.css) {\n const {exports: cssExports, ...cssOptions} = options.css\n const {resolveCssLoweringTargets} = await import('./cssLoweringTargets.ts')\n const lightningcss = await resolveCssLoweringTargets({\n cssTarget: cssOptions.target,\n target,\n lightningcss: cssOptions.lightningcss,\n })\n css = {minify: true, ...cssOptions, lightningcss}\n\n const {cssNodeCompatPlugin} = await import('./cssNodeCompatPlugin.ts')\n plugins.push(\n cssNodeCompatPlugin({\n fileName: css.fileName,\n splitting: css.splitting,\n // `@tsdown/css`'s own `inject` emits a relative import, which throws in runtimes that\n // cannot load `.css` files; the plugin below injects the self-referential specifier of\n // the conditional CSS export instead.\n inject: css.inject ?? true,\n exports: cssExports ?? {nodeCompat: true},\n }),\n )\n css = {...css, inject: false}\n }\n\n if (bundleAnalyzer !== false) {\n // Lazy loaded, like `reactCompiler` / `vanillaExtract`, so `rolldown/experimental` is\n // only paid for when the option is enabled. `true` selects markdown — Rolldown's own\n // default is JSON, which is worse for humans and coding agents.\n const {bundleAnalyzerPlugin} = await import('rolldown/experimental')\n plugins.push(\n bundleAnalyzerPlugin({\n format: 'md',\n ...(typeof bundleAnalyzer === 'object' ? bundleAnalyzer : {}),\n }),\n )\n }\n\n // The `react-server` variant does not participate in `exports` generation: its files are\n // wired in through the compiled variant's `react-server` conditions instead of becoming\n // export subpaths of their own.\n let exports: UserConfig['exports'] = false\n if (!isReactServer) {\n const userExports = options.exports\n // Package-manager detection exists solely to decide the pnpm-gated `devExports: true`\n // default, so it only runs when that default can still apply. `false`, `true`, and bare\n // CI-condition strings replace the defaults entirely (mergeConfig semantics), and an\n // explicit `devExports` value overrides it — those configs skip the filesystem probing\n // and behave identically across package managers. Programmatic hosts composing this\n // config (e.g. `@sanity/pkg-utils` passing `{devExports: 'source'}`) never trigger it.\n const devExportsDefaultApplies =\n userExports === undefined ||\n (typeof userExports === 'object' && userExports.devExports === undefined)\n const packageManager = devExportsDefaultApplies\n ? await detect({cwd: cwd ?? process.cwd()})\n : undefined\n // tsdown's `exports` feature is enabled with Sanity-flavored defaults, and userland values\n // apply with tsdown's own `mergeConfig` semantics: an object deep-merges over the defaults,\n // anything else (`false`, a CI condition) replaces them.\n ;({exports} = mergeConfig(\n {\n exports: {\n // Always on: `'local-only'`/`'ci-only'` surprise environments that set `CI=true`\n // (Cursor Cloud, etc.) without intending to skip package.json rewrites. Keep the\n // object shape so mergeConfig never swaps between a scalar `true` and `{devExports}`.\n enabled: true,\n // Only opt in by default when pnpm is detected: support for replacing package fields\n // from `publishConfig` is not reliable across package managers.\n ...(packageManager?.name === 'pnpm' && {devExports: true}),\n },\n },\n {exports: userExports},\n ))\n if (variant === 'default' && exports) {\n // The compiled variant owns `exports` generation for the dual build, so the\n // `react-server` conditions are composed into its `customExports`: every entry export\n // gains a `react-server` condition pointing at the `.react-server.` sibling that the\n // `react-server` variant emits.\n exports = withReactServerExports(exports)\n }\n }\n\n return defineTsdownConfig({\n // Rolldown defaults `circularDependency` to `false`; enable it so Sanity library builds\n // surface import cycles (bigger bundles / execution-order hazards) as warnings. The\n // declaration bundling pass gets the same check, where cycles are type-only and harmless,\n // so `suppressWarnings` filters those out below.\n // Override via `mergeConfig(..., {checks: {circularDependency: false}})`.\n // https://rolldown.rs/reference/InputOptions.checks#circulardependency\n checks: {circularDependency: true},\n // Drops the `CIRCULAR_DEPENDENCY` warnings of the declaration bundling pass (userland\n // patterns are OR'd in, never replacing the built-in filter).\n suppressWarnings: resolveSuppressWarnings(options.suppressWarnings),\n clean,\n css,\n cwd,\n define,\n deps,\n dts,\n entry,\n exports,\n format,\n // When `tsdoc` is enabled, run API Extractor against the entry `.d.ts` files after the\n // build. The function form of `hooks` registers via hookable so a later `mergeConfig` that\n // also uses the function form can compose — an object-form `hooks: {'build:done': …}`\n // override still replaces this (tsdown's `mergeConfig` replaces functions).\n ...(tsdoc !== false\n ? {\n hooks: createTsdocHooks({\n tsdoc: tsdoc === true ? {} : tsdoc,\n tsconfig,\n outDir,\n deps,\n }),\n }\n : {}),\n inputOptions,\n outDir,\n // The `react-server` variant writes its files next to the compiled ones, with `.react-server`\n // inserted before tsdown's default extension (`index.js` ↔ `index.react-server.js`). Hashed\n // chunk filenames get the suffix too, so the two variants' chunks never collide in the\n // shared `outDir`.\n outExtensions: isReactServer ? reactServerOutExtensions : undefined,\n platform,\n plugins,\n publint,\n report,\n sourcemap,\n target,\n tsconfig,\n // Compress the output (constant folding, dead code elimination) without mangling\n // identifiers or stripping whitespace: consumers' production builds minify `node_modules`\n // again anyway, so full minification here would only hurt debuggability, not final app\n // bundle sizes. `keepNames` preserves the function and class names the compress pass\n // would otherwise strip as unreferenced - e.g. the inner name in\n // `forwardRef(function Button(…) {…})`, which React DevTools reads via `Function.name`.\n // That name is the tree-shakeable alternative to a top-level `Button.displayName = '…'`\n // assignment (a side effect that pins unused components into consumer bundles, see\n // https://github.com/sanity-io/ui/pull/2435), and names stripped at publish time are\n // unrecoverable in userland.\n minify: {\n compress: {keepNames: {function: true, class: true}},\n codegen: false,\n mangle: false,\n },\n })\n}\n\n/**\n * Matches the declaration file extensions tsdown emits next to `es`/`cjs` chunks — the same\n * extensions `rolldown-plugin-dts` gives the modules of the declaration bundling pass.\n */\nconst RE_DTS_FILE = /\\.d\\.(ts|mts|cts)$/\n\n/** Strips the SGR color codes rolldown formats warning messages with. */\n// oxlint-disable-next-line eslint/no-control-regex -- matching the ESC of a CSI sequence\nconst RE_ANSI_COLOR = /\\u001B\\[\\d*(?:;\\d+)*m/g\n\n/** The `CircularDependency` diagnostic of rolldown, ahead of the cycle's ` -> `-joined modules. */\nconst CIRCULAR_DEPENDENCY_PREFIX = 'Circular dependency: '\n\n/**\n * Whether a warning is a `CIRCULAR_DEPENDENCY` warning whose entire cycle consists of\n * declaration files, e.g.\n * `Circular dependency: src/exports/index.d.ts -> src/exports/nodes.d.ts -> src/exports/index.d.ts.`\n *\n * Those come from the declaration bundling pass: every import between `.d.ts` modules is\n * type-only and erased at runtime, so the cycle has none of the consequences the check exists\n * to catch (execution-order hazards, bigger bundles), and it's unavoidable for mutually\n * referencing public types — see https://github.com/sanity-io/sanity/pull/13753, where 109 of\n * 136 cycle warnings were declaration-only. A cycle that includes even one runtime module is\n * left alone.\n */\nfunction isDtsCircularDependencyWarning(message: string): boolean {\n // The message arrives pre-formatted, with a color-coded `[CIRCULAR_DEPENDENCY] ` code prefix\n // and a trailing newline\n const plain = message.replace(RE_ANSI_COLOR, '').trim()\n const cycleStart = plain.indexOf(CIRCULAR_DEPENDENCY_PREFIX)\n if (cycleStart === -1) return false\n const modules = plain\n .slice(cycleStart + CIRCULAR_DEPENDENCY_PREFIX.length)\n // The trailing period of the diagnostic, never part of a `.d.ts` extension\n .replace(/\\.$/, '')\n .split(' -> ')\n return modules.length > 1 && modules.every((module) => RE_DTS_FILE.test(module))\n}\n\n/**\n * Composes the userland `suppressWarnings` value with {@link isDtsCircularDependencyWarning}:\n * the two are OR'd, so adding a per-package suppression never drops the declaration-only\n * cycle filter that pairs with this config's `checks.circularDependency` default.\n *\n * The string/`RegExp` matching mirrors tsdown's own — `includes` and `test`, against the\n * message exactly as tsdown would see it, so a pattern behaves the same whether it goes\n * through this option or straight into tsdown's `suppressWarnings`. `lastIndex` is reset for\n * `/g` and `/y` patterns, which carry it between `test` calls and would otherwise skip\n * messages (a no-op for other patterns, whose `lastIndex` `test` ignores).\n */\nfunction resolveSuppressWarnings(\n suppressWarnings: UserConfig['suppressWarnings'],\n): (message: string) => boolean {\n if (suppressWarnings === undefined) return isDtsCircularDependencyWarning\n const matchesUserPattern =\n typeof suppressWarnings === 'function'\n ? suppressWarnings\n : (message: string): boolean =>\n (Array.isArray(suppressWarnings) ? suppressWarnings : [suppressWarnings]).some(\n (pattern) => {\n if (typeof pattern === 'string') return message.includes(pattern)\n if (pattern.global || pattern.sticky) pattern.lastIndex = 0\n return pattern.test(message)\n },\n )\n return (message) => isDtsCircularDependencyWarning(message) || matchesUserPattern(message)\n}\n\n/**\n * Registers the `build:done` hook that runs `checkTsdoc` against every entry `.d.ts` file\n * the build emitted. The checker is loaded from `./tsdoc` only when the hook runs, so\n * importing `defineConfig` never pulls in API Extractor.\n */\nfunction createTsdocHooks(options: {\n tsdoc: PackageTsdocOptions\n tsconfig: UserConfig['tsconfig']\n outDir: UserConfig['outDir']\n deps: UserConfig['deps']\n}): NonNullable<UserConfig['hooks']> {\n const {tsdoc, outDir, deps} = options\n // `tsconfig: false` means \"don't use a tsconfig\"; fall back to the conventional name so\n // API Extractor still has a project root. A string path is forwarded as-is.\n const tsconfigPath = typeof options.tsconfig === 'string' ? options.tsconfig : 'tsconfig.json'\n const bundledPackages =\n tsdoc.bundledPackages ??\n (Array.isArray(deps?.alwaysBundle)\n ? deps.alwaysBundle.filter((entry): entry is string => typeof entry === 'string')\n : typeof deps?.alwaysBundle === 'string'\n ? [deps.alwaysBundle]\n : undefined)\n\n return (hooks) => {\n hooks.hook('build:done', async ({chunks, options: resolved}) => {\n const entryDtsFiles = entryDtsFilesFromChunks(chunks)\n if (entryDtsFiles.length === 0) return\n\n // Lazy-load the `/tsdoc` entry so `@microsoft/api-extractor` and friends stay out of\n // the root module graph until a build with `tsdoc` enabled actually finishes.\n const {checkTsdoc} = await import('./tsdoc/index.ts')\n await checkTsdoc({\n cwd: resolved.cwd,\n entryDtsFiles,\n tsconfig: tsconfigPath,\n outDir: outDir ?? resolved.outDir,\n bundledPackages,\n customTags: tsdoc.customTags,\n rules: tsdoc.rules,\n logger: {\n log: (...args) => {\n resolved.logger.info(...args.map(String))\n },\n warn: (...args) => {\n resolved.logger.warn(...args.map(String))\n },\n error: (...args) => {\n resolved.logger.error(...args.map(String))\n },\n },\n })\n })\n }\n}\n\n/** Absolute paths of entry declaration chunks emitted by the build. */\nfunction entryDtsFilesFromChunks(chunks: RolldownChunk[]): string[] {\n const files: string[] = []\n for (const chunk of chunks) {\n if (chunk.type !== 'chunk' || !chunk.isEntry || !RE_DTS_FILE.test(chunk.fileName)) continue\n files.push(path.resolve(chunk.outDir, chunk.fileName))\n }\n return files\n}\n\n/**\n * The `outExtensions` of the `react-server` variant: tsdown's default extension for the\n * format and package type (see `resolveJsOutputExtension` in tsdown), with `.react-server` inserted\n * so the variant's entries sit next to the compiled ones (`index.js` ↔ `index.react-server.js`,\n * `index.cjs` ↔ `index.react-server.cjs`, and `.mjs` accordingly for CommonJS packages).\n */\nconst reactServerOutExtensions: NonNullable<UserConfig['outExtensions']> = ({format, pkgType}) => ({\n js:\n format === 'cjs'\n ? pkgType === 'module'\n ? '.react-server.cjs'\n : '.react-server.js'\n : pkgType === 'module'\n ? '.react-server.js'\n : '.react-server.mjs',\n})\n\ntype ExportsOptions = Extract<NonNullable<UserConfig['exports']>, object>\ntype CustomExportsFunction = Extract<\n NonNullable<ExportsOptions['customExports']>,\n (...args: never[]) => unknown\n>\ntype ExportsMap = Parameters<CustomExportsFunction>[0]\n/**\n * Wires the `react-server` conditions into tsdown's `exports` feature by composing into\n * `exports.customExports` (the same composition `@sanity/vanilla-extract-tsdown-plugin` uses\n * for its conditional CSS export): a pre-existing `customExports` applies first — both its\n * function and record forms, mirroring how tsdown itself applies them — and the\n * `react-server` conditions are inserted into the result. The composed function runs for both\n * the local `exports` map and `publishConfig.exports`; with `devExports` the local map points\n * at source files, which the entry-file matching leaves untouched (source resolves for every\n * condition in development, which is correct — uncompiled source is exactly what the\n * `react-server` condition ships).\n */\nfunction withReactServerExports(\n exportsOption: Exclude<NonNullable<UserConfig['exports']>, false>,\n): ExportsOptions {\n // Normalize the `boolean | CIOption | object` forms of the `exports` option into the\n // object form, preserving the enabled-ness (`true` and bare CI conditions mean enabled)\n const exportsOptions: ExportsOptions =\n exportsOption === true\n ? {}\n : typeof exportsOption === 'string'\n ? {enabled: exportsOption}\n : exportsOption\n const previousCustomExports = exportsOptions.customExports\n exportsOptions.customExports = async (exportsMap, context) => {\n // Apply a pre-existing `customExports` first (both its function and record forms,\n // mirroring how tsdown itself applies them), then insert the `react-server` conditions\n const base =\n typeof previousCustomExports === 'function'\n ? await previousCustomExports(exportsMap, context)\n : previousCustomExports\n ? {...exportsMap, ...previousCustomExports}\n : exportsMap\n return addReactServerConditions(base, context)\n }\n return exportsOptions\n}\n\n/** Matches the JS output extensions tsdown emits for `es`/`cjs` chunks. */\nconst RE_JS_FILE = /\\.(m?js|cjs)$/\n\n/** The conditions tsdown generates that resolve at runtime, in contrast to `types` etc. */\nconst RUNTIME_CONDITIONS = new Set(['import', 'require', 'default'])\n\n/**\n * Inserts a `react-server` condition into every entry export of an `exports`-shaped map,\n * pointing at the `.react-server.` sibling emitted by the `react-server` variant — e.g.\n * `\"./dist/index.js\"` becomes\n * `{\"types\": \"./dist/index.d.ts\", \"react-server\": \"./dist/index.react-server.js\", \"default\": \"./dist/index.js\"}`.\n *\n * The `react-server` variant emits no `.d.ts` siblings, so TypeScript's adjacent-file lookup\n * cannot resolve types for `./dist/index.react-server.js` — a `types` condition pointing at\n * the compiled variant's declarations is specified before `react-server` instead (conditions\n * match in order, so it covers every resolution mode). It's only added when the declarations\n * actually exist among the compiled variant's chunks, and an already-present `types`\n * condition is left in place.\n *\n * Entries are recognized by comparing export targets against the compiled variant's entry\n * chunks — reconstructed in the exact `./<outDir relative to the package root>/<fileName>`\n * form tsdown writes into the exports map, so entries that share a leaf name (`index.js` vs\n * `features/index.js`) can never shadow each other, and non-entry exports (`./package.json`,\n * the conditional `./bundle.css` export of `vanillaExtract`, `devExports` source paths like\n * `./src/index.ts`) pass through untouched. The `react-server` files themselves never enter\n * the map — the `react-server` variant builds with `exports: false` — so they don't become\n * export subpaths of their own.\n */\nfunction addReactServerConditions(\n exportsMap: ExportsMap,\n context: Parameters<CustomExportsFunction>[1],\n): ExportsMap {\n // tsdown always resolves the package with its path here: its own exports generation reads\n // `packageJsonPath` unconditionally from the same object it passes to `customExports` -\n // only the declared context type is the plain `PackageJson` shape.\n const pkg: Partial<PackageJsonWithPath> = context.pkg\n const pkgRoot = path.dirname(pkg.packageJsonPath ?? 'package.json')\n // Export targets of the compiled variant's entry JS and declaration chunks; the\n // `react-server` variant's files sit next to the entries with `.react-server` inserted\n // before the extension\n const entryFiles = new Set<string>()\n const dtsFiles = new Set<string>()\n for (const [format, formatChunks] of Object.entries(context.chunks)) {\n // Only `es` and `cjs` chunks become package exports (mirroring tsdown's own generation)\n if (format !== 'es' && format !== 'cjs') continue\n for (const chunk of formatChunks) {\n if (chunk.type !== 'chunk') continue\n const target = exportTarget(pkgRoot, chunk.outDir, chunk.fileName)\n if (chunk.isEntry && RE_JS_FILE.test(chunk.fileName)) {\n entryFiles.add(target)\n } else if (RE_DTS_FILE.test(chunk.fileName)) {\n dtsFiles.add(target)\n }\n }\n }\n const isEntryFile = (value: unknown): value is string =>\n typeof value === 'string' && entryFiles.has(value)\n // The `types` file for an entry export target, when the compiled variant emitted it\n const dtsFor = (value: string): string | undefined => {\n const dtsFile = toDtsFile(value)\n return dtsFiles.has(dtsFile) ? dtsFile : undefined\n }\n\n const result: ExportsMap = {}\n for (const [key, value] of Object.entries(exportsMap as Record<string, unknown>)) {\n result[key] = withReactServerCondition(value, isEntryFile, dtsFor)\n }\n return result\n}\n\n/**\n * Mirrors tsdown's own `join` for exports targets:\n * `./<outDir relative to the package root>/<fileName>`, with POSIX separators.\n */\nfunction exportTarget(pkgRoot: string, outDir: string, fileName: string): string {\n const outDirRelative = path.relative(pkgRoot, outDir).replaceAll('\\\\', '/')\n return `${outDirRelative ? `./${outDirRelative}` : '.'}/${fileName.replaceAll('\\\\', '/')}`\n}\n\nfunction withReactServerCondition(\n value: unknown,\n isEntryFile: (value: unknown) => value is string,\n dtsFor: (value: string) => string | undefined,\n): unknown {\n // A bare-string entry export (e.g. the pure-ESM publish shape `\".\": \"./dist/index.js\"`)\n // becomes a conditional export, with `types` specified before `react-server` so type\n // resolution never reaches the declaration-less `.react-server.` file\n if (isEntryFile(value)) {\n const types = dtsFor(value)\n return {\n ...(types === undefined ? {} : {types}),\n 'react-server': toServerFile(value),\n 'default': value,\n }\n }\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return value\n const conditions = Object.entries(value)\n const matched = conditions.filter(\n (entry): entry is [string, string] => RUNTIME_CONDITIONS.has(entry[0]) && isEntryFile(entry[1]),\n )\n const [firstMatch] = matched\n if (!firstMatch) return value\n const hasTypes = conditions.some(([condition]) => condition === 'types')\n // A single runtime file maps to a plain path (with a `types` condition inserted ahead of\n // `react-server` below, unless one is already specified). A dual-format entry nests its\n // `import` and `require` files under the `react-server` condition, each with its own\n // format-matched `types` — a single top-level `types` file cannot serve both resolution\n // modes, which is also why tsdown's own dual-format output relies on adjacent-file lookup.\n const missingTypes = hasTypes ? undefined : dtsFor(firstMatch[1])\n const serverTarget =\n matched.length === 1\n ? toServerFile(firstMatch[1])\n : Object.fromEntries(\n matched.map(([condition, target]) => {\n const types = hasTypes ? undefined : dtsFor(target)\n return [\n condition,\n types === undefined ? toServerFile(target) : {types, default: toServerFile(target)},\n ]\n }),\n )\n // Conditions match in order, so `react-server` is inserted right before the first runtime\n // condition (`import`/`require`/`default`), keeping `types` and custom development\n // conditions (`devExports`) ahead of it\n const next: Record<string, unknown> = {}\n let inserted = false\n for (const [condition, target] of conditions) {\n if (!inserted && RUNTIME_CONDITIONS.has(condition)) {\n if (matched.length === 1 && missingTypes !== undefined) {\n next['types'] = missingTypes\n }\n next['react-server'] = serverTarget\n inserted = true\n }\n next[condition] = target\n }\n if (!inserted) {\n next['react-server'] = serverTarget\n }\n return next\n}\n\n/** `./dist/index.js` → `./dist/index.react-server.js` (and `.mjs`/`.cjs` accordingly). */\nfunction toServerFile(file: string): string {\n return file.replace(RE_JS_FILE, '.react-server.$1')\n}\n\n/** `./dist/index.js` → `./dist/index.d.ts` (`.mjs` → `.d.mts`, `.cjs` → `.d.cts`). */\nfunction toDtsFile(file: string): string {\n return file.replace(RE_JS_FILE, (extension) =>\n extension === '.mjs' ? '.d.mts' : extension === '.cjs' ? '.d.cts' : '.d.ts',\n )\n}\n"],"mappings":";;;;;;AAsdA,eAAsB,aACpB,UAA0B,CAAC,GACS;CACpC,IAAM,gBAAgB,QAAQ,iBAAiB;CAa/C,OANI,OAAO,iBAAkB,YAAY,cAAc,gBAAgB,KAC9D,QAAQ,IAAI,CACjB,qBAAqB,SAAS,SAAS,GACvC,qBAAqB,SAAS,cAAc,CAC9C,CAAC,IAEI,qBAAqB,SAAS,YAAY;AACnD;AASA,eAAe,qBACb,SACA,SACqB;CAQrB,IAAM,EAAC,OAAO,UAAU,QAAQ,QAAQ,QAAQ,QAAO,SACjD,gBAAgB,YAAY,gBAO5B,MAAM,kBAAwB,QAAQ,KACtC,QAAQ,kBAAwB,QAAQ,OACxC,UAAU,CAAC,eACX,WAAW,QAAQ,YAAY,WAC/B,YAAY,QAAQ,aAAa,IAGjC,gBAAgB,gBAAgB,KAAS,QAAQ,iBAAiB,IAClE,mBAAmB,QAAQ,oBAAoB,IAI/C,iBAAiB,gBAAgB,KAAS,QAAQ,kBAAkB,IAGpE,QAAQ,gBAAgB,KAAS,QAAQ,SAAS,IAClD,SAAS,EAAC,MAAM,GAAK,GACrB,SAAS,QAAQ,UAAU,OAG3B,eAAe;EAE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AW,KAAA,IAAY,OAAO,WAAW,EAAE,GAC1D,eACJ,QAAQ,WAAW,IACf,aAAa,WAAW,EAAE,IAC1B,OAAO,YACL,QAAQ,KAAK,CAAC,WAAW,YAAY;EACnC,IAAM,QAAQ,WAAW,KAAA,IAAY,OAAO,MAAM;EAClD,OAAO,CACL,WACA,UAAU,KAAA,IAAY,aAAa,MAAM,IAAI;GAAC;GAAO,SAAS,aAAa,MAAM;EAAC,CACpF;CACF,CAAC,CACH,GAIA,OAAgC,CAAC,GACnC,WAAW;CACf,KAAK,IAAM,CAAC,WAAW,WAAW,YAQhC,AAPI,CAAC,YAAY,mBAAmB,IAAI,SAAS,MAC3C,QAAQ,WAAW,KAAK,iBAAiB,KAAA,MAC3C,KAAKC,QAAW,eAElB,KAAK,kBAAkB,cACvB,WAAW,KAEb,KAAK,aAAa;CAKpB,OAHK,aACH,KAAK,kBAAkB,eAElB;AACT;;AAGA,SAAS,aAAa,MAAsB;CAC1C,OAAO,KAAK,QAAQ,YAAY,kBAAkB;AACpD;;AAGA,SAAS,UAAU,MAAsB;CACvC,OAAO,KAAK,QAAQ,aAAa,cAC/B,cAAc,SAAS,WAAW,cAAc,SAAS,WAAW,OACtE;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["defineTsdownConfig","\"default\"","\"types\""],"sources":["../src/index.ts"],"sourcesContent":["import path from 'node:path'\nimport type {\n CssExportsOptions,\n Options as VanillaExtractPluginOptions,\n} from '@sanity/vanilla-extract-tsdown-plugin'\nimport type {PluginOptions as BabelReactCompilerPluginOptions} from 'babel-plugin-react-compiler'\nimport type {CustomAtRules, TransformOptions as LightningCssTransformOptions} from 'lightningcss'\nimport type {ReactCompilerOptions as OxcReactCompilerOptions} from 'oxc-transform-react'\nimport {detect} from 'package-manager-detector/detect'\nimport {\n defineConfig as defineTsdownConfig,\n mergeConfig,\n type PackageJsonWithPath,\n type Rolldown,\n type RolldownChunk,\n type UserConfig,\n} from 'tsdown'\nimport type {PackageTsdocOptions} from './tsdoc/types.ts'\n\nexport type {\n PackageTsdocCustomTag,\n PackageTsdocOptions,\n PackageTsdocRuleLevel,\n} from './tsdoc/types.ts'\n\n// Only types are re-exported from the plugin packages: a value re-export would make\n// `@sanity/vanilla-extract-tsdown-plugin` a static import of this entry, pulling the whole\n// vanilla-extract toolchain (the rolldown plugin, `@sanity/vanilla-extract-integration`,\n// `@vanilla-extract/css`, and the native `lightningcss` binary) into every consumer's module\n// graph — including packages with no CSS at all. Everything that needs those helpers loads\n// them through the `await import(...)` calls below.\nexport type {CssExportsOptions} from '@sanity/vanilla-extract-tsdown-plugin'\n\n/**\n * Options for the `vanillaExtract` option — the same options as\n * `@sanity/vanilla-extract-tsdown-plugin` (`identifiers`, `fileName`, `minify`, `target`,\n * `lightningcss`, `inject`, and `exports`, all modeled after the `css` options of\n * `@tsdown/css`), with two Sanity-flavored defaults on top:\n *\n * - `inject` and `exports` default to `true` and `{nodeCompat: true}` (instead of the plugin's\n * `false` for both), wiring up the conditional CSS export pattern that Sanity libraries ship\n * with. Set `exports: true` for a plain (browser-only) CSS export, `exports: false` for a\n * relative CSS import, or `inject: false` to only extract the CSS.\n * - When the effective CSS syntax lowering target (`target`, falling back to the top-level\n * `target`) is undefined or names no browsers (e.g. `'node20'`, resolved from\n * `engines.node`), the lowering targets are resolved from `@sanity/browserslist-config` and\n * passed through `lightningcss.targets` — where the plugin (like `@tsdown/css`) would skip\n * lowering. `target: false` stays the explicit off switch, and a user-provided\n * `lightningcss.targets` wins over the fallback.\n *\n * `minify` is not set, so it stays the plugin's default (`false`, matching `css.minify` in\n * `@tsdown/css`). Set `minify: true` to minify the extracted CSS.\n * @public\n */\nexport type PackageVanillaExtractOptions = VanillaExtractPluginOptions\n\n/**\n * Options for the `panda` option — the same options as `@sanity/pandacss-tsdown-plugin`\n * (`cwd`, `configPath`, `outdir` and `transform` from `@pandacss/vite`, `codegen` and\n * `polyfill`, plus `fileName`, `minify`, `target`, `lightningcss`, `inject`, and `exports`,\n * modeled after the `css` options of `@tsdown/css`), with the same Sanity-flavored defaults as\n * {@link PackageVanillaExtractOptions | `vanillaExtract`} on top:\n *\n * - `inject` and `exports` default to `true` and `{nodeCompat: true}` (instead of the plugin's\n * `false` for both), wiring up the conditional CSS export pattern that Sanity libraries ship\n * with. Set `exports: true` for a plain (browser-only) CSS export, `exports: false` for a\n * relative CSS import, or `inject: false` to only extract the CSS.\n * - When the effective CSS syntax lowering target (`target`, falling back to the top-level\n * `target`) is undefined or names no browsers (e.g. `'node20'`, resolved from\n * `engines.node`), the lowering targets are resolved from `@sanity/browserslist-config` and\n * passed through `lightningcss.targets` — where the plugin (like `@tsdown/css`) would skip\n * lowering. `target: false` stays the explicit off switch, and a user-provided\n * `lightningcss.targets` wins over the fallback.\n *\n * `minify` is not set, so it stays the plugin's default (`false`, matching `css.minify` in\n * `@tsdown/css`). Set `minify: true` to minify the extracted CSS.\n *\n * The options are declared here rather than imported from the plugin: the plugin is an\n * optional peer, and a declaration file importing types from a package that isn't installed\n * fails every consumer's `skipLibCheck: false` type check (TS2307) — including the consumers\n * that never enable `panda`. `test/panda-options.test.ts` type-checks that the two\n * declarations stay identical.\n * @public\n */\nexport interface PackagePandaOptions {\n /**\n * The project root the Panda config is discovered from (`panda.config.ts` upward), and the\n * directory its `include`/`exclude` globs are relative to — like `cwd` in `@pandacss/vite`.\n * @defaultValue tsdown's resolved `cwd`\n */\n cwd?: string\n /**\n * An explicit Panda config file, relative to `cwd`, instead of discovering it upward — like\n * `configPath` in `@pandacss/vite`.\n */\n configPath?: string\n /**\n * Run Panda's codegen when a build starts (and after the config reloads in watch mode),\n * writing only the `styled-system` artifacts whose content changed. Set to `false` when\n * codegen is managed elsewhere.\n * @defaultValue true\n */\n codegen?: boolean\n /**\n * Where the codegen artifacts are written, relative to `cwd` — like `outdir` in\n * `@pandacss/vite`.\n * @defaultValue the `outdir` of the Panda config\n */\n outdir?: string\n /**\n * Rewrite the `css()`, `cva()`, pattern and recipe calls of the Panda sources into static\n * class names, so the published JavaScript carries no Panda runtime. On by default — unlike\n * `transform` in `@pandacss/vite`, which defaults to `false` there because applications keep\n * the runtime around. `false` only extracts the CSS.\n * @defaultValue true\n */\n transform?: boolean\n /**\n * Emit the extracted CSS without cascade layers (Panda's `@layer` polyfill).\n * @defaultValue the `polyfill` option of the Panda config\n */\n polyfill?: boolean\n /**\n * Name of the emitted CSS file, like `css.fileName` in `@tsdown/css`.\n * @defaultValue \"bundle.css\"\n */\n fileName?: string\n /**\n * Minify the extracted CSS with `lightningcss`, like `css.minify` in `@tsdown/css`.\n * @defaultValue false\n */\n minify?: boolean\n /**\n * The target environment for CSS syntax lowering: esbuild-style target strings like\n * `'chrome90'`, or `false` to disable lowering. Falls back to the top-level `target`, then\n * to `@sanity/browserslist-config` (see above).\n */\n target?: string | string[] | false\n /**\n * Options passed through to `lightningcss`'s `transform()`, like `css.lightningcss` in\n * `@tsdown/css`. `targets` wins over `target`; `unusedSymbols` extends the\n * `--made-with-panda` entry the plugin always removes.\n */\n lightningcss?: Omit<LightningCssTransformOptions<CustomAtRules>, 'filename' | 'code'>\n /**\n * Inject the CSS import into every entry chunk that reaches Panda styles, like `css.inject`\n * in `@tsdown/css`.\n * @defaultValue true\n */\n inject?: boolean\n /**\n * Publish the CSS file as the `\"./<fileName>\"` export subpath: `true` for a plain export,\n * `{nodeCompat: true}` for the conditional export with the Node-compatible shim, `false` for\n * a relative CSS import instead.\n * @defaultValue `{nodeCompat: true}`\n */\n exports?: boolean | CssExportsOptions\n}\n\n/**\n * Options for the `css` option — tsdown's experimental\n * [`css` options](https://tsdown.dev/options/css) from `@tsdown/css` (`splitting`, `fileName`,\n * `target`, `minify`, `lightningcss`, `postcss`, `modules`, `preprocessorOptions`,\n * `transformer`, `inject`), plus an `exports` option this config implements on top. `exports`\n * defaults to `{nodeCompat: true}`, wiring up the conditional CSS export pattern: the\n * self-referential `import \"<pkg>/style.css\"`, a no-op `style-css.js` shim with a\n * `style-css.d.ts` declaration, and the conditional `\"./style.css\"` export written to\n * `package.json`. `@tsdown/css` has no equivalent — its `inject` emits a relative\n * `import \"./style.css\"`, which throws in runtimes that cannot load `.css` files. Set\n * `exports: true` for a plain (browser-only) CSS export, or `exports: false` to fall back to\n * `@tsdown/css`'s relative injection.\n *\n * `minify` is not set, so it stays `@tsdown/css`'s default (`false`). Set `minify: true` to\n * minify the emitted CSS.\n *\n * The CSS syntax lowering target resolves exactly like\n * {@link PackageVanillaExtractOptions | `vanillaExtract`}'s: browserless targets fall back to\n * `@sanity/browserslist-config` through `lightningcss.targets`.\n * @public\n */\nexport type PackageCssOptions = NonNullable<UserConfig['css']> & {\n /**\n * Publish each emitted CSS file as an export subpath of the package, so consumers can\n * `import \"<pkg-name>/style.css\"` — which is also the specifier `inject` then uses, instead\n * of `@tsdown/css`'s relative path.\n *\n * - `true` declares a plain `\"./style.css\": \"./dist/style.css\"` export. Enough for packages\n * that only ever run in browsers or bundlers.\n * - `{nodeCompat: true}` declares a conditional export instead, whose `browser`/`style`\n * conditions point at the stylesheet while `node`/`default` point at a no-op JS shim\n * emitted next to it, with a declaration file for the export's `types` condition. That\n * keeps the subpath resolvable in runtimes that cannot load `.css` files.\n *\n * @defaultValue `{nodeCompat: true}`\n */\n exports?: boolean | CssExportsOptions\n}\n\n/**\n * Options for the `bundleAnalyzer` option — the same options as Rolldown's experimental\n * [`bundleAnalyzerPlugin`](https://rolldown.rs/builtin-plugins/bundle-analyzer)\n * (`fileName`, `format`).\n *\n * When enabled with `true`, defaults to `{format: 'md'}` (an LLM-friendly markdown report)\n * rather than the plugin's own `'json'` default — that's the report Sanity library builds\n * want. Pass `{format: 'json'}` for the structured data file visualizers consume.\n *\n * The report is emitted into `outDir` (`analyze-data.md` by default) and is **not** a\n * publishable artifact. Exclude it from `package.json` `files` (e.g.\n * `\"!dist/analyze-data.md\"` / `\"!lib/analyze-data.md\"`) so an accidental analyze build\n * cannot ship it.\n * @public\n * @alpha This option wraps Rolldown's experimental analyzer, whose API may change.\n */\nexport interface PackageBundleAnalyzerOptions {\n /**\n * The filename used for the emitted analysis asset. The file is written into the same\n * output directory as the rest of the bundle.\n * @defaultValue `'analyze-data.md'` when `format` is `'md'`, `'analyze-data.json'` when\n * `format` is `'json'`\n */\n fileName?: string\n /**\n * `'md'` produces an LLM-friendly markdown report (Quick Summary, largest modules, entry\n * points, dependency chains); `'json'` produces structured data for visualizers.\n * @defaultValue `'md'`\n */\n format?: 'json' | 'md'\n}\n\n/**\n * Options for the `styled-components` transform, the same options as `babel-plugin-styled-components`.\n * @public\n */\nexport interface StyledComponentsOptions {\n /** @defaultValue true */\n displayName?: boolean\n /**\n * @defaultValue []\n * @example [\"\\@xstyled/styled-components\", \"\\@xstyled/styled-components/*\"]\n */\n topLevelImportPaths?: string[]\n /** @defaultValue true */\n ssr?: boolean\n /** @defaultValue false */\n fileName?: boolean\n /** @defaultValue [\"index\"] */\n meaninglessFileNames?: string[]\n /** @defaultValue true */\n minify?: boolean\n /** @defaultValue false */\n transpileTemplateLiterals?: boolean\n namespace?: string\n /** @defaultValue true */\n pure?: boolean\n}\n\n/**\n * The options of this config that both React Compiler implementations share — never\n * forwarded to the compiler itself.\n * @public\n */\nexport interface ReactCompilerConfigOptions {\n /**\n * Also emit an uncompiled build of every entry (`<name>.react-server.js` next to `<name>.js`),\n * wired to the `react-server` export condition in `package.json`:\n *\n * ```json\n * \".\": {\n * \"types\": \"./dist/index.d.ts\",\n * \"react-server\": \"./dist/index.react-server.js\",\n * \"default\": \"./dist/index.js\"\n * }\n * ```\n *\n * React Server Components refuse to load React Compiler output (`react/compiler-runtime`\n * throws in the `react-server` environment), so a library that ships compiled code\n * publishes two entrypoints: the compiled one (the `default` condition) and an uncompiled\n * one (the `react-server` condition) — see\n * https://github.com/facebook/react/issues/31702.\n *\n * Both builds come from the same source, and the only difference is that React Compiler\n * auto-memoization is applied to the non-`react-server` output; nothing is stripped from\n * either output. Pair it with deleting manual `useMemo`/`useCallback` calls from the\n * source: server components stop paying for memoization that can never pay off (they\n * render exactly once), and client components get the compiler's finer-grained\n * memoization instead.\n * @defaultValue false\n * @alpha This option is experimental and not covered by semver: it can change behavior or\n * be removed entirely in a minor version.\n */\n reactServer?: boolean\n}\n\n// `interface … extends` on purpose, not intersection aliases: an uninstalled peer's type\n// import degrades to `any` (skipLibCheck), and in an intersection that `any` would swallow\n// the whole `ReactCompilerOptions` union, making every config match the `reactServer: true`\n// overload of `defineConfig` (the bug sanity-io/ui had to stub around). Unresolvable\n// heritage clauses are dropped instead, leaving each interface's own members (`transform`,\n// `reactServer`), so the union keeps discriminating. See `test/optional-peer-types.test.ts`.\n\n/**\n * The `transform: 'babel'` shape: `babel-plugin-react-compiler` (an optional peer dependency)\n * runs the compiler, with its own `PluginOptions` — typed once the package is installed.\n * Install it together with `@rolldown/plugin-babel` and `@babel/core`.\n * @public\n */\nexport interface ReactCompilerBabelOptions\n extends Partial<BabelReactCompilerPluginOptions>, ReactCompilerConfigOptions {\n /**\n * The reference implementation — for what the Rust port lacks: custom `jsxImportSource`,\n * `logger`, function-valued `sources`.\n */\n transform: 'babel'\n}\n\n/**\n * The default `reactCompiler` shape: `oxc-transform-react` (an optional peer dependency) runs\n * the compiler, with its own `ReactCompilerOptions` — the serializable subset of the babel\n * plugin's (no `logger`, no function-valued `sources`), typed once the package is installed.\n * @public\n */\nexport interface ReactCompilerOxcOptions\n extends OxcReactCompilerOptions, ReactCompilerConfigOptions {\n /**\n * `oxc-transform-react`, the Rust port. Its one native pass also strips TypeScript and\n * lowers JSX (automatic runtime, `react` import source) — opt into `'babel'` for a\n * custom `jsxImportSource`.\n * @defaultValue 'oxc'\n */\n transform?: 'oxc'\n}\n\n/**\n * Options for the React Compiler: the compiler's own options, plus `transform` (which\n * implementation runs) and `reactServer` (the dual React Server Components build) — both\n * handled by this config, never forwarded to the compiler.\n * @public\n */\nexport type ReactCompilerOptions = ReactCompilerBabelOptions | ReactCompilerOxcOptions\n\n/**\n * @public\n */\nexport interface PackageOptions extends Pick<\n UserConfig,\n 'tsconfig' | 'entry' | 'format' | 'dts' | 'define' | 'target' | 'outDir'\n> {\n /**\n * @defaultValue 'neutral'\n *\n * When left at `'neutral'` (the default), two resolution tweaks compensate for rolldown's\n * strict neutral defaults: `deps.neverBundle` includes `/^node:/` (node built-ins stay external\n * so neutral does not warn about them as unresolvable; only node runtimes execute those code\n * paths), and `inputOptions.resolve.mainFields` falls back to `['module', 'main']` for inlined\n * dependencies that ship no `exports` map (e.g. `rxjs-etc/operators`). Prefer `'neutral'` over\n * `'node'` for packages that also run in the browser - `'node'` makes CommonJS-interop emit a\n * module-scope `createRequire(import.meta.url)` for inlined CJS deps, which crashes\n * browser-bundled consumers.\n */\n platform?: UserConfig['platform']\n /**\n * The working directory of the build — forwarded to tsdown's own `cwd` option, and also used\n * for the package-manager detection that decides the pnpm-gated `devExports` default of the\n * {@link PackageOptions.exports | `exports`} option (instead of `process.cwd()`).\n *\n * Config files can leave it unset; set it when driving builds programmatically for a package\n * in another directory, e.g. from a monorepo script or a tool composing this config (like\n * `@sanity/pkg-utils`).\n * @defaultValue `process.cwd()`\n */\n cwd?: UserConfig['cwd']\n /**\n * Clean directories before each build. Prefer an array of folders over a separate `\"clean\"`\n * script in `package.json` (e.g. `rimraf dist coverage`) — tsdown removes them as part of\n * `tsdown` / `pnpm build`, so packages don't need `rimraf`, a `clean` script, or\n * `prebuild`/`run-s clean build` wiring.\n *\n * - `true` (tsdown's default when left undefined) cleans `outDir` (`'dist'` by default)\n * - `false` skips cleaning\n * - a `string[]` replaces that default with the listed paths/globs — include `outDir` (e.g.\n * `'dist'`) when you still want it cleaned alongside other folders\n *\n * @defaultValue true\n * @example\n * ```ts\n * // Instead of `\"clean\": \"rimraf dist coverage\"` in package.json:\n * clean: ['dist', 'coverage']\n * ```\n */\n clean?: UserConfig['clean']\n /**\n * tsdown's `exports` option, with defaults suited for publishing Sanity libraries:\n * `enabled: true` generates the `exports` map on every build, whether `CI` is set or not\n * (GitHub Actions, Cursor Cloud, local shells, …). Relying on `'local-only'`/`'ci-only'`\n * surprised too many environments that set `CI=true` without meaning \"don't rewrite\n * package.json\". When pnpm is detected, `devExports: true` also keeps the local `exports`\n * map pointing at source files while `publishConfig.exports` receives the built files.\n *\n * Userland values apply with tsdown's `mergeConfig` semantics: an object deep-merges over\n * these defaults (so individual fields can be overridden), while any other value - `false`\n * to disable exports generation, or a bare CI condition (`'ci-only'`/`'local-only'`) -\n * replaces them entirely.\n *\n * The package-manager detection behind the `devExports` default reads from\n * {@link PackageOptions.cwd | `cwd`} and only runs when the default can still apply — it is\n * skipped when the value replaces the defaults (`false`, `true`, a bare CI condition) or\n * sets `devExports` explicitly.\n * @defaultValue `{enabled: true, devExports: true}` for pnpm projects;\n * `{enabled: true}` otherwise.\n */\n exports?: UserConfig['exports']\n /**\n * Whether to generate source map files. The same default as the `sourcemap` option in\n * `@sanity/pkg-utils` - tsdown itself defaults to `false` and does not read `sourceMap` from\n * the tsconfig.\n * @defaultValue true\n */\n sourcemap?: UserConfig['sourcemap']\n /**\n * tsdown's `deps` option. When `platform` is `'neutral'` (the default), `neverBundle` always\n * includes `/^node:/` and userland `neverBundle` entries are appended (tsdown's `mergeConfig`\n * would replace the array). Other `deps` fields pass through as-is.\n */\n deps?: UserConfig['deps']\n /**\n * tsdown's experimental [`css` option](https://tsdown.dev/options/css) (CSS modules,\n * preprocessors, Lightning CSS / PostCSS, inject, etc), with Sanity-flavored defaults and an\n * added `exports` option — requires\n * [`@tsdown/css`](https://www.npmjs.com/package/@tsdown/css) to be installed in the project.\n *\n * By default (`exports: {nodeCompat: true}`) the emitted CSS gets the same\n * conditional CSS export treatment as {@link PackageOptions.vanillaExtract}: the\n * self-referential `import \"<pkg>/style.css\"`, a no-op `style-css.js` shim with its\n * `style-css.d.ts` declaration, and the conditional `\"./style.css\"` export written to\n * `package.json` — see {@link PackageCssOptions}.\n *\n * Safe to combine with {@link PackageOptions.vanillaExtract}: vanilla-extract extracts into\n * `bundle.css` by default, while `@tsdown/css` merges other CSS (including `.module.css`)\n * into `style.css`, so the two pipelines do not collide.\n * @see https://tsdown.dev/reference/api/Interface.InlineConfig#css\n * @alpha\n */\n css?: PackageCssOptions\n /**\n * Enables Rolldown's experimental\n * [`bundleAnalyzerPlugin`](https://rolldown.rs/builtin-plugins/bundle-analyzer)\n * (`rolldown/experimental`) to emit a report of what the package itself bundles — chunks,\n * modules, dependency chains — next to the build output. Pass `true` to use the defaults,\n * or an object to customize.\n *\n * Unlike the plugin's own defaults (`format: 'json'`), `true` selects `format: 'md'`: an\n * LLM-friendly markdown report (`analyze-data.md` in `outDir`). Pass `{format: 'json'}`\n * for the structured data file visualizers consume. Analysis adds work to the build, so\n * this stays off by default — typical usage is an env-gated opt-in:\n *\n * ```ts\n * bundleAnalyzer: process.env.ENABLE_BUNDLE_ANALYZER === 'true'\n * ```\n *\n * The report is **not** a publishable artifact. Exclude it from `package.json` `files`\n * (e.g. `\"!dist/analyze-data.md\"` / `\"!lib/analyze-data.md\"`) so an accidental analyze\n * build cannot ship it.\n *\n * With {@link ReactCompilerOptions.reactServer | `reactCompiler.reactServer`}, only the\n * compiled (`default`) variant is analyzed — the `react-server` variant skips it so the\n * two builds don't overwrite one report.\n * @defaultValue false\n * @alpha This option wraps Rolldown's experimental analyzer, whose API may change.\n */\n bundleAnalyzer?: boolean | PackageBundleAnalyzerOptions\n /**\n * Runs the React Compiler on the source files before they are bundled, so published\n * components are memoized automatically. Pass `true` to use the defaults, or an options\n * object (e.g. `{target: '18'}`). This is the same feature as the\n * `reactCompiler` option in `@sanity/pkg-utils`.\n *\n * `transform` picks the implementation — `'oxc'` (default, requires `oxc-transform-react`)\n * or `'babel'` (requires `babel-plugin-react-compiler`, `@rolldown/plugin-babel` and\n * `@babel/core`), see {@link ReactCompilerBabelOptions} — and `reactServer` adds the\n * uncompiled `react-server` build, see {@link ReactCompilerConfigOptions.reactServer}.\n * @defaultValue false\n */\n reactCompiler?: boolean | ReactCompilerOptions\n /**\n * Applies the `styled-components` transform (`displayName`, `componentId`, CSS minification, etc)\n * with the same defaults as the `babel: {styledComponents: true}` option in `@sanity/pkg-utils`.\n * Unlike `@sanity/pkg-utils` it doesn't use `babel-plugin-styled-components`, but oxc's native port of it,\n * so there's no need to install babel dependencies.\n * @defaultValue false\n */\n styledComponents?: boolean | StyledComponentsOptions\n /**\n * Enables `@sanity/vanilla-extract-tsdown-plugin` to extract CSS into a separate file,\n * lowered with `lightningcss`. CSS is left unminified unless `minify: true` is set. The\n * lowering targets come from the effective\n * `target` (`vanillaExtract.target`, falling back to the top-level `target`) when it names\n * browsers; when it's undefined or browserless (e.g. `'node20'`), they're resolved from\n * `@sanity/browserslist-config` instead — see {@link PackageVanillaExtractOptions}. Pass\n * `true` to use the defaults, or an object to customize.\n *\n * By default (`inject: true` with `exports: {nodeCompat: true}`) the plugin also injects the\n * self-referential `import \"<pkg>/bundle.css\"`, emits a `bundle-css.js` shim, and writes the\n * conditional `\"./bundle.css\"` export to `package.json` - see\n * {@link PackageVanillaExtractOptions}. This is the same feature as `rollup.vanillaExtract`\n * in `@sanity/pkg-utils`.\n *\n * Combines with {@link PackageOptions.css}: enable both when a package uses vanilla-extract\n * alongside CSS modules (or other `@tsdown/css` features).\n * @alpha\n */\n vanillaExtract?: boolean | PackageVanillaExtractOptions\n /**\n * Enables `@sanity/pandacss-tsdown-plugin`, the library-build companion of `@pandacss/vite`\n * for [Panda CSS](https://panda-css.com) packages: it loads `panda.config.ts`, rewrites the\n * `css()`/`cva()`/pattern/recipe calls of the sources the config covers into static class\n * names (so the published JavaScript carries no Panda runtime), and extracts the generated\n * stylesheet into a separate file, lowered with `lightningcss`. CSS is left unminified unless\n * `minify: true` is set, and the lowering targets resolve exactly like\n * {@link PackageOptions.vanillaExtract | `vanillaExtract`}'s — see\n * {@link PackagePandaOptions}. Pass `true` to use the defaults, or an object to customize.\n *\n * Install `@sanity/pandacss-tsdown-plugin`; like `@pandacss/vite`, it brings the Panda\n * compiler and transformer it runs as regular dependencies, while the package keeps its own\n * `@pandacss/dev` for `panda.config.ts` and the `panda` CLI. The plugin runs Panda's codegen\n * when the build starts (writing only the artifacts whose content changed), so the\n * `styled-system` directory matches the config the CSS is extracted with; keep the usual\n * `\"prepare\": \"panda codegen\"` script so it also exists for the type checker before a build.\n *\n * By default (`inject: true` with `exports: {nodeCompat: true}`) the plugin also injects the\n * self-referential `import \"<pkg>/bundle.css\"`, emits a `bundle-css.js` shim, and writes the\n * conditional `\"./bundle.css\"` export to `package.json`, like\n * {@link PackageOptions.vanillaExtract | `vanillaExtract`} does.\n * @alpha\n */\n panda?: boolean | PackagePandaOptions\n /**\n * Runs `@microsoft/api-extractor` after the build (via tsdown's `build:done` hook) to check\n * that TSDoc tags are valid and release tags are correct. Useful for packages consumed by\n * TSDoc-based tooling. Off by default — set `tsdoc: true` to enable, or pass an options\n * object to customize rules and custom tags.\n * @defaultValue false\n */\n tsdoc?: boolean | PackageTsdocOptions\n /**\n * tsdown's `suppressWarnings` option: strings (matched with `includes`), regular expressions\n * (matched with `test`), or a predicate that drop build warnings before they're printed — and\n * before `failOnWarn` turns them into errors.\n *\n * Userland values are **added to** the built-in suppression instead of replacing it (which\n * `mergeConfig` would do, since it replaces functions): per-package suppressions can't\n * accidentally undo the declaration-only circular-dependency filter that this config pairs\n * with its `checks.circularDependency` default. This config always suppresses\n * `CIRCULAR_DEPENDENCY` warnings whose entire cycle consists of declaration files\n * (`.d.ts`/`.d.mts`/`.d.cts`) — those come from the declaration bundling pass, where every\n * import is type-only and erased at runtime, so the cycles are harmless and unavoidable for\n * mutually referencing public types (e.g. the schema definition types in `@sanity/types`).\n * Cycles involving a runtime module still warn.\n *\n * To drop the built-in suppression instead of adding to it, merge over the returned config —\n * `mergeConfig(await defineConfig(), {suppressWarnings: () => false})` restores every\n * warning, including the declaration-only cycles.\n * @defaultValue undefined — only the built-in declaration-only cycle suppression applies\n */\n suppressWarnings?: UserConfig['suppressWarnings']\n}\n\n/**\n * With `reactCompiler.reactServer` the config resolves to two tsdown configs: the compiled\n * `default` variant and the uncompiled `react-server` variant.\n * @public\n */\nexport function defineConfig(\n options: PackageOptions & {reactCompiler: ReactCompilerOptions & {reactServer: true}},\n): Promise<UserConfig[]>\n/**\n * Without `reactCompiler.reactServer` the config resolves to a single tsdown config.\n * @public\n */\nexport function defineConfig(\n options: PackageOptions & {reactCompiler: ReactCompilerOptions & {reactServer?: false}},\n): Promise<UserConfig>\n/**\n * When TypeScript can't tell whether `reactCompiler.reactServer` is set (a widened `boolean`,\n * e.g. through a `ReactCompilerOptions`-typed variable), the config resolves to either shape —\n * check `Array.isArray` on the result.\n * @public\n */\nexport function defineConfig(\n options: PackageOptions & {reactCompiler: ReactCompilerOptions},\n): Promise<UserConfig | UserConfig[]>\n/**\n * @public\n */\nexport function defineConfig(options?: PackageOptions): Promise<UserConfig>\n/**\n * @public\n */\nexport async function defineConfig(\n options: PackageOptions = {},\n): Promise<UserConfig | UserConfig[]> {\n const reactCompiler = options.reactCompiler ?? false\n // `reactCompiler.reactServer` opts into the dual React Server Components build: the same\n // config twice, where the only difference is that React Compiler auto-memoization is applied\n // to the non-`react-server` variant. Both variants build in one `tsdown` run — tsdown builds\n // the configs in parallel, cleans the shared `outDir` once before either variant emits, and\n // runs `exports` generation and `publint` per `package.json` only after every build for that\n // package has finished (so the `react-server` files exist by the time they're validated).\n if (typeof reactCompiler === 'object' && reactCompiler.reactServer === true) {\n return Promise.all([\n resolvePackageConfig(options, 'default'),\n resolvePackageConfig(options, 'react-server'),\n ])\n }\n return resolvePackageConfig(options, 'standalone')\n}\n\n/**\n * The build variants {@link defineConfig} produces: the classic single build\n * (`'standalone'`), or — with `reactCompiler.reactServer` — the compiled `'default'` variant\n * and the uncompiled `'react-server'` variant of the dual React Server Components build.\n */\ntype PackageConfigVariant = 'standalone' | 'default' | 'react-server'\n\nasync function resolvePackageConfig(\n options: PackageOptions,\n variant: PackageConfigVariant,\n): Promise<UserConfig> {\n // `tsconfig`, `entry`, `dts`, `define`, `target`, `outDir`, `clean`, `css` and `cwd` are\n // passed through to tsdown as-is. When left undefined, tsdown keeps its default behavior\n // (`tsconfig` is auto-detected from the project, `dts` from `package.json`, `define`\n // replaces nothing, `target` applies no syntax downleveling, `outDir` defaults to `'dist'`,\n // `clean` defaults to `true` — cleaning `outDir` before each build — `css` stays off\n // unless `@tsdown/css` is installed and the option is set, and `cwd` defaults to\n // `process.cwd()`).\n const {entry, tsconfig, define, target, outDir, cwd} = options\n const isReactServer = variant === 'react-server'\n // The `react-server` variant skips d.ts generation (the compiled variant's declarations\n // serve both entries — a `types` condition specified before `react-server` points every\n // resolution mode at them), never cleans (tsdown collects the clean paths of all configs\n // and cleans once, before either variant emits, so the compiled variant's `clean` already\n // covers the run), and skips `publint` (it runs once, from the compiled variant, after\n // both builds finish).\n const dts = isReactServer ? false : options.dts\n const clean = isReactServer ? false : options.clean\n const publint = !isReactServer\n const platform = options.platform ?? 'neutral'\n const sourcemap = options.sourcemap ?? true\n // The React Compiler is what the `react-server` variant exists to avoid: compiled output\n // loads `react/compiler-runtime`, which throws in the `react-server` environment.\n const reactCompiler = isReactServer ? false : (options.reactCompiler ?? false)\n const styledComponents = options.styledComponents ?? false\n // The `react-server` variant skips the analyzer so the two parallel builds don't race on\n // one `analyze-data.md` in the shared `outDir`. The compiled variant is the published\n // client bundle — that's the report worth reading.\n const bundleAnalyzer = isReactServer ? false : (options.bundleAnalyzer ?? false)\n // The `react-server` variant skips TSDoc checking (it emits no `.d.ts` files — the compiled\n // variant's declarations serve both entries), matching how it skips `publint`.\n const tsdoc = isReactServer ? false : (options.tsdoc ?? false)\n const report = {gzip: false} as const satisfies UserConfig['report']\n const format = options.format ?? 'esm'\n // When `platform` is `'neutral'`, restore the conventional `module`/`main` fallback that\n // rolldown's strict neutral defaults drop - needed for inlined deps without an `exports` map.\n const inputOptions = {\n // https://github.com/rolldown/rolldown/blob/main/packages/rolldown/src/options/docs/preserve-entry-signatures.md#strict\n preserveEntrySignatures: 'strict',\n experimental: {attachDebugInfo: 'none'},\n ...(platform === 'neutral' && {\n resolve: {mainFields: ['module', 'main']},\n }),\n ...(styledComponents !== false && {\n transform: {\n plugins: {\n styledComponents: {\n // The same defaults as `babel: {styledComponents: true}` in `@sanity/pkg-utils`:\n // `fileName` is unnecessary, as the way we use styled-components in Sanity is usually by wrapping\n // `@sanity/ui` primitives, not declaring new ones like \"const Button = styled.button``\"\n fileName: false,\n // Native template literals take less space than this transpilation, and unlike\n // `babel-plugin-styled-components`, oxc doesn't add a `@__PURE__` annotation to the\n // transpiled call expression either, so enabling it wouldn't improve tree-shaking\n transpileTemplateLiterals: false,\n // Helps dead code elimination and tree-shaking, although oxc only annotates plain call\n // expressions so far, not tagged template expressions (https://github.com/rollup/rollup/issues/4035)\n pure: true,\n // Disabled, as tsdown tends to be used for npm publishing, while other tooling,\n // like `sanity dev`, `next dev`, etc are used for testing\n cssProp: false,\n ...(typeof styledComponents === 'object' ? styledComponents : {}),\n },\n },\n },\n }),\n } satisfies UserConfig['inputOptions']\n\n // `neverBundle` is concatenated (not `mergeConfig`'d) so per-package externals add to the\n // `/^node:/` default for `platform: 'neutral'` instead of replacing it. Rolldown's\n // `ExternalOption` array form is `Array<string | RegExp>` only; a function override is composed.\n const userNeverBundle = options.deps?.neverBundle\n const nodeBuiltinExternal = platform === 'neutral' ? /^node:/ : undefined\n const neverBundle: NonNullable<UserConfig['deps']>['neverBundle'] =\n userNeverBundle == null\n ? nodeBuiltinExternal && [nodeBuiltinExternal]\n : nodeBuiltinExternal == null || userNeverBundle === true\n ? userNeverBundle\n : typeof userNeverBundle === 'function'\n ? (id, importer, isResolved) =>\n nodeBuiltinExternal.test(id) || userNeverBundle(id, importer, isResolved)\n : Array.isArray(userNeverBundle)\n ? [nodeBuiltinExternal, ...userNeverBundle]\n : [nodeBuiltinExternal, userNeverBundle]\n const deps: UserConfig['deps'] = {\n resolveDepSubpath: true,\n ...options.deps,\n ...(neverBundle === undefined ? {} : {neverBundle}),\n }\n\n // `outputOptions` is left to tsdown's defaults - notably chunk filenames keep tsdown's hashed\n // default (unless userland sets `hash`), which prevents chunk/entry filename collisions\n // (https://github.com/sanity-io/ui/issues/2262).\n const plugins: Rolldown.Plugin[] = []\n if (reactCompiler !== false) {\n // Lazy loaded so the toolchain is only paid for when enabled. The compiler package itself\n // (`oxc-transform-react` / `babel-plugin-react-compiler`, per `transform`) resolves from\n // the consumer package — everything babel-flavored is an optional peer dependency.\n const reactCompilerOptions: ReactCompilerOptions = reactCompiler === true ? {} : reactCompiler\n if (reactCompilerOptions.transform === 'babel') {\n // The opt-in reference implementation follows the official tsdown recipe for the React\n // Compiler: https://tsdown.dev/recipes/react-support#enabling-react-compiler\n // The compiler leaves TypeScript and JSX in place for rolldown's own transform.\n const [{default: pluginBabel}, {reactCompilerPreset}] = await Promise.all([\n import('@rolldown/plugin-babel').catch((cause: unknown) => {\n throw new Error(\n '`reactCompiler: {transform: \"babel\"}` needs `pnpm add -D @rolldown/plugin-babel @babel/core babel-plugin-react-compiler`.',\n {cause},\n )\n }),\n import('@vitejs/plugin-react'),\n ])\n const {\n reactServer: _reactServer,\n transform: _transform,\n ...compilerOptions\n } = reactCompilerOptions\n plugins.push(\n await pluginBabel({\n presets: [reactCompilerPreset(compilerOptions)],\n }),\n )\n } else {\n // The default: `@vitejs/plugin-react`'s `compiler` option — `oxc-transform-react`\n // compiles, strips TypeScript and lowers JSX in one native pass. Only the\n // `vite:react-compiler` plugin is cherry-picked — the rest of the array is Vite-only\n // (Fast Refresh wrapper, dev config). Outside Vite its defaults are what a library\n // build wants: production JSX, sourcemaps, no Fast Refresh. `transform`/`reactServer`\n // are this config's — drop before forwarding.\n const {\n reactServer: _reactServer,\n transform: _transform,\n ...compilerOptions\n } = reactCompilerOptions\n const {default: pluginReact} = await import('@vitejs/plugin-react')\n const compilerPlugin = pluginReact({\n compiler: compilerOptions,\n // Keep the one-pass transform away from rolldown-plugin-dts' generated `.d.ts` modules\n // (the default include matches them) — it would strip every type, collapsing the\n // bundled declarations to `export {}`. node_modules is restated because a userland\n // `exclude` replaces the plugin's default — with both separators, since plain rolldown\n // (unlike Vite) does not normalize Windows ids to POSIX.\n exclude: [/[\\\\/]node_modules[\\\\/]/, RE_DTS_FILE],\n }).find((plugin) => plugin.name === 'vite:react-compiler')\n if (!compilerPlugin) {\n throw new Error(\n '`@vitejs/plugin-react` returned no `vite:react-compiler` plugin — the installed version does not support the default `oxc` implementation of the `reactCompiler` option.',\n )\n }\n plugins.push(compilerPlugin)\n }\n }\n if (options.vanillaExtract) {\n // Lazy loaded, like `reactCompiler`, so the CSS toolchain is only paid for when the option is\n // enabled. The plugin compiles the `.css.ts` files and extracts the CSS into a single file.\n // Its `inject`/`exports` options are general purpose (and, like `css.inject` in\n // `@tsdown/css`, disabled by default), so this config supplies the default most Sanity\n // libraries want: `exports: {nodeCompat: true}` wires up the whole conditional CSS export\n // pattern - the self-referential CSS import, the no-op JS shim, and the conditional\n // `./<fileName>` export written through this config's `exports` option (which the plugin's\n // `tsdownConfig` hook composes into).\n const [{vanillaExtractPlugin}, {resolveCssLoweringTargets}] = await Promise.all([\n import('@sanity/vanilla-extract-tsdown-plugin'),\n import('./cssLoweringTargets.ts'),\n ])\n const vanillaExtract = options.vanillaExtract === true ? {} : options.vanillaExtract\n\n const lightningcss = await resolveCssLoweringTargets({\n cssTarget: vanillaExtract.target,\n target,\n lightningcss: vanillaExtract.lightningcss,\n })\n\n plugins.push(\n vanillaExtractPlugin({\n inject: true,\n exports: {nodeCompat: true},\n ...vanillaExtract,\n lightningcss,\n }),\n )\n }\n if (options.panda) {\n const panda = options.panda === true ? {} : options.panda\n // Each CSS pipeline emits its own stylesheet and claims its export subpath; two pipelines\n // writing the same file would overwrite each other's CSS (neither merges the other's), so\n // a shared effective file name is a configuration error rather than a silent loss\n const pandaFileName = panda.fileName ?? 'bundle.css'\n if (options.vanillaExtract) {\n const vanillaExtract = options.vanillaExtract === true ? {} : options.vanillaExtract\n if ((vanillaExtract.fileName ?? 'bundle.css') === pandaFileName) {\n throw new Error(\n `\\`panda\\` and \\`vanillaExtract\\` both extract their CSS into \"${pandaFileName}\", so one would overwrite the other's stylesheet and \\`./${pandaFileName}\\` export. Give one of them a distinct file name, e.g. \\`panda: {fileName: 'panda.css'}\\`.`,\n )\n }\n }\n if (options.css && (options.css.fileName ?? 'style.css') === pandaFileName) {\n throw new Error(\n `\\`panda\\` and \\`css\\` both write their CSS to \"${pandaFileName}\", so one would overwrite the other's stylesheet and \\`./${pandaFileName}\\` export. Give one of them a distinct file name, e.g. \\`panda: {fileName: 'panda.css'}\\`.`,\n )\n }\n\n // Lazy loaded, like `vanillaExtract`, so Panda's toolchain (the `@pandacss/compiler` node\n // driver, `@pandacss/transformer` and the native `lightningcss` binary) is only paid for when the\n // option is enabled. The plugin's `inject`/`exports` options follow `css.inject` in\n // `@tsdown/css` (disabled by default), so this config supplies the same defaults as for\n // `vanillaExtract`: the conditional CSS export pattern, written through this config's\n // `exports` option (which the plugin's `tsdownConfig` hook composes into).\n const [{pandacssPlugin}, {resolveCssLoweringTargets}] = await Promise.all([\n import('@sanity/pandacss-tsdown-plugin'),\n import('./cssLoweringTargets.ts'),\n ])\n\n const lightningcss = await resolveCssLoweringTargets({\n cssTarget: panda.target,\n target,\n lightningcss: panda.lightningcss,\n })\n\n plugins.push(\n pandacssPlugin({\n inject: true,\n exports: {nodeCompat: true},\n ...panda,\n lightningcss,\n }),\n )\n }\n\n // `@tsdown/css` compiles CSS but has no node-shim concept, so the `exports` option (and the\n // plugin implementing it) lives here. Its `exports` key is not a `@tsdown/css` option, so it\n // is stripped before the rest is handed to tsdown.\n let css: UserConfig['css']\n if (options.css) {\n const {exports: cssExports, ...cssOptions} = options.css\n const {resolveCssLoweringTargets} = await import('./cssLoweringTargets.ts')\n const lightningcss = await resolveCssLoweringTargets({\n cssTarget: cssOptions.target,\n target,\n lightningcss: cssOptions.lightningcss,\n })\n css = {...cssOptions, lightningcss}\n\n const {cssNodeCompatPlugin} = await import('./cssNodeCompatPlugin.ts')\n plugins.push(\n cssNodeCompatPlugin({\n fileName: css.fileName,\n splitting: css.splitting,\n // `@tsdown/css`'s own `inject` emits a relative import, which throws in runtimes that\n // cannot load `.css` files; the plugin below injects the self-referential specifier of\n // the conditional CSS export instead.\n inject: css.inject ?? true,\n exports: cssExports ?? {nodeCompat: true},\n }),\n )\n css = {...css, inject: false}\n }\n\n if (bundleAnalyzer !== false) {\n // Lazy loaded, like `reactCompiler` / `vanillaExtract`, so `rolldown/experimental` is\n // only paid for when the option is enabled. `true` selects markdown — Rolldown's own\n // default is JSON, which is worse for humans and coding agents.\n const {bundleAnalyzerPlugin} = await import('rolldown/experimental')\n plugins.push(\n bundleAnalyzerPlugin({\n format: 'md',\n ...(typeof bundleAnalyzer === 'object' ? bundleAnalyzer : {}),\n }),\n )\n }\n\n // The `react-server` variant does not participate in `exports` generation: its files are\n // wired in through the compiled variant's `react-server` conditions instead of becoming\n // export subpaths of their own.\n let exports: UserConfig['exports'] = false\n if (!isReactServer) {\n const userExports = options.exports\n // Package-manager detection exists solely to decide the pnpm-gated `devExports: true`\n // default, so it only runs when that default can still apply. `false`, `true`, and bare\n // CI-condition strings replace the defaults entirely (mergeConfig semantics), and an\n // explicit `devExports` value overrides it — those configs skip the filesystem probing\n // and behave identically across package managers. Programmatic hosts composing this\n // config (e.g. `@sanity/pkg-utils` passing `{devExports: 'source'}`) never trigger it.\n const devExportsDefaultApplies =\n userExports === undefined ||\n (typeof userExports === 'object' && userExports.devExports === undefined)\n const packageManager = devExportsDefaultApplies\n ? await detect({cwd: cwd ?? process.cwd()})\n : undefined\n // tsdown's `exports` feature is enabled with Sanity-flavored defaults, and userland values\n // apply with tsdown's own `mergeConfig` semantics: an object deep-merges over the defaults,\n // anything else (`false`, a CI condition) replaces them.\n ;({exports} = mergeConfig(\n {\n exports: {\n // Always on: `'local-only'`/`'ci-only'` surprise environments that set `CI=true`\n // (Cursor Cloud, etc.) without intending to skip package.json rewrites. Keep the\n // object shape so mergeConfig never swaps between a scalar `true` and `{devExports}`.\n enabled: true,\n // Only opt in by default when pnpm is detected: support for replacing package fields\n // from `publishConfig` is not reliable across package managers.\n ...(packageManager?.name === 'pnpm' && {devExports: true}),\n },\n },\n {exports: userExports},\n ))\n if (variant === 'default' && exports) {\n // The compiled variant owns `exports` generation for the dual build, so the\n // `react-server` conditions are composed into its `customExports`: every entry export\n // gains a `react-server` condition pointing at the `.react-server.` sibling that the\n // `react-server` variant emits.\n exports = withReactServerExports(exports)\n }\n }\n\n return defineTsdownConfig({\n // Rolldown defaults `circularDependency` to `false`; enable it so Sanity library builds\n // surface import cycles (bigger bundles / execution-order hazards) as warnings. The\n // declaration bundling pass gets the same check, where cycles are type-only and harmless,\n // so `suppressWarnings` filters those out below.\n // Override via `mergeConfig(..., {checks: {circularDependency: false}})`.\n // https://rolldown.rs/reference/InputOptions.checks#circulardependency\n checks: {circularDependency: true},\n // Drops the `CIRCULAR_DEPENDENCY` warnings of the declaration bundling pass (userland\n // patterns are OR'd in, never replacing the built-in filter).\n suppressWarnings: resolveSuppressWarnings(options.suppressWarnings),\n clean,\n css,\n cwd,\n define,\n deps,\n dts,\n entry,\n exports,\n format,\n // When `tsdoc` is enabled, run API Extractor against the entry `.d.ts` files after the\n // build. The function form of `hooks` registers via hookable so a later `mergeConfig` that\n // also uses the function form can compose — an object-form `hooks: {'build:done': …}`\n // override still replaces this (tsdown's `mergeConfig` replaces functions).\n ...(tsdoc !== false\n ? {\n hooks: createTsdocHooks({\n tsdoc: tsdoc === true ? {} : tsdoc,\n tsconfig,\n outDir,\n deps,\n }),\n }\n : {}),\n inputOptions,\n outDir,\n // The `react-server` variant writes its files next to the compiled ones, with `.react-server`\n // inserted before tsdown's default extension (`index.js` ↔ `index.react-server.js`). Hashed\n // chunk filenames get the suffix too, so the two variants' chunks never collide in the\n // shared `outDir`.\n outExtensions: isReactServer ? reactServerOutExtensions : undefined,\n platform,\n plugins,\n publint,\n report,\n sourcemap,\n target,\n tsconfig,\n // Compress the output (constant folding, dead code elimination) without mangling\n // identifiers or stripping whitespace: consumers' production builds minify `node_modules`\n // again anyway, so full minification here would only hurt debuggability, not final app\n // bundle sizes. `keepNames` preserves the function and class names the compress pass\n // would otherwise strip as unreferenced - e.g. the inner name in\n // `forwardRef(function Button(…) {…})`, which React DevTools reads via `Function.name`.\n // That name is the tree-shakeable alternative to a top-level `Button.displayName = '…'`\n // assignment (a side effect that pins unused components into consumer bundles, see\n // https://github.com/sanity-io/ui/pull/2435), and names stripped at publish time are\n // unrecoverable in userland.\n minify: {\n compress: {keepNames: {function: true, class: true}},\n codegen: false,\n mangle: false,\n },\n })\n}\n\n/**\n * Matches the declaration file extensions tsdown emits next to `es`/`cjs` chunks — the same\n * extensions `rolldown-plugin-dts` gives the modules of the declaration bundling pass.\n */\nconst RE_DTS_FILE = /\\.d\\.(ts|mts|cts)$/\n\n/** Strips the SGR color codes rolldown formats warning messages with. */\n// oxlint-disable-next-line eslint/no-control-regex -- matching the ESC of a CSI sequence\nconst RE_ANSI_COLOR = /\\u001B\\[\\d*(?:;\\d+)*m/g\n\n/** The `CircularDependency` diagnostic of rolldown, ahead of the cycle's ` -> `-joined modules. */\nconst CIRCULAR_DEPENDENCY_PREFIX = 'Circular dependency: '\n\n/**\n * Whether a warning is a `CIRCULAR_DEPENDENCY` warning whose entire cycle consists of\n * declaration files, e.g.\n * `Circular dependency: src/exports/index.d.ts -> src/exports/nodes.d.ts -> src/exports/index.d.ts.`\n *\n * Those come from the declaration bundling pass: every import between `.d.ts` modules is\n * type-only and erased at runtime, so the cycle has none of the consequences the check exists\n * to catch (execution-order hazards, bigger bundles), and it's unavoidable for mutually\n * referencing public types — see https://github.com/sanity-io/sanity/pull/13753, where 109 of\n * 136 cycle warnings were declaration-only. A cycle that includes even one runtime module is\n * left alone.\n */\nfunction isDtsCircularDependencyWarning(message: string): boolean {\n // The message arrives pre-formatted, with a color-coded `[CIRCULAR_DEPENDENCY] ` code prefix\n // and a trailing newline\n const plain = message.replace(RE_ANSI_COLOR, '').trim()\n const cycleStart = plain.indexOf(CIRCULAR_DEPENDENCY_PREFIX)\n if (cycleStart === -1) return false\n const modules = plain\n .slice(cycleStart + CIRCULAR_DEPENDENCY_PREFIX.length)\n // The trailing period of the diagnostic, never part of a `.d.ts` extension\n .replace(/\\.$/, '')\n .split(' -> ')\n return modules.length > 1 && modules.every((module) => RE_DTS_FILE.test(module))\n}\n\n/**\n * Composes the userland `suppressWarnings` value with {@link isDtsCircularDependencyWarning}:\n * the two are OR'd, so adding a per-package suppression never drops the declaration-only\n * cycle filter that pairs with this config's `checks.circularDependency` default.\n *\n * The string/`RegExp` matching mirrors tsdown's own — `includes` and `test`, against the\n * message exactly as tsdown would see it, so a pattern behaves the same whether it goes\n * through this option or straight into tsdown's `suppressWarnings`. `lastIndex` is reset for\n * `/g` and `/y` patterns, which carry it between `test` calls and would otherwise skip\n * messages (a no-op for other patterns, whose `lastIndex` `test` ignores).\n */\nfunction resolveSuppressWarnings(\n suppressWarnings: UserConfig['suppressWarnings'],\n): (message: string) => boolean {\n if (suppressWarnings === undefined) return isDtsCircularDependencyWarning\n const matchesUserPattern =\n typeof suppressWarnings === 'function'\n ? suppressWarnings\n : (message: string): boolean =>\n (Array.isArray(suppressWarnings) ? suppressWarnings : [suppressWarnings]).some(\n (pattern) => {\n if (typeof pattern === 'string') return message.includes(pattern)\n if (pattern.global || pattern.sticky) pattern.lastIndex = 0\n return pattern.test(message)\n },\n )\n return (message) => isDtsCircularDependencyWarning(message) || matchesUserPattern(message)\n}\n\n/**\n * Registers the `build:done` hook that runs `checkTsdoc` against every entry `.d.ts` file\n * the build emitted. The checker is loaded from `./tsdoc` only when the hook runs, so\n * importing `defineConfig` never pulls in API Extractor.\n */\nfunction createTsdocHooks(options: {\n tsdoc: PackageTsdocOptions\n tsconfig: UserConfig['tsconfig']\n outDir: UserConfig['outDir']\n deps: UserConfig['deps']\n}): NonNullable<UserConfig['hooks']> {\n const {tsdoc, outDir, deps} = options\n // `tsconfig: false` means \"don't use a tsconfig\"; fall back to the conventional name so\n // API Extractor still has a project root. A string path is forwarded as-is.\n const tsconfigPath = typeof options.tsconfig === 'string' ? options.tsconfig : 'tsconfig.json'\n const bundledPackages =\n tsdoc.bundledPackages ??\n (Array.isArray(deps?.alwaysBundle)\n ? deps.alwaysBundle.filter((entry): entry is string => typeof entry === 'string')\n : typeof deps?.alwaysBundle === 'string'\n ? [deps.alwaysBundle]\n : undefined)\n\n return (hooks) => {\n hooks.hook('build:done', async ({chunks, options: resolved}) => {\n const entryDtsFiles = entryDtsFilesFromChunks(chunks)\n if (entryDtsFiles.length === 0) return\n\n // Lazy-load the `/tsdoc` entry so `@microsoft/api-extractor` and friends stay out of\n // the root module graph until a build with `tsdoc` enabled actually finishes.\n const {checkTsdoc} = await import('./tsdoc/index.ts')\n await checkTsdoc({\n cwd: resolved.cwd,\n entryDtsFiles,\n tsconfig: tsconfigPath,\n outDir: outDir ?? resolved.outDir,\n bundledPackages,\n customTags: tsdoc.customTags,\n rules: tsdoc.rules,\n logger: {\n log: (...args) => {\n resolved.logger.info(...args.map(String))\n },\n warn: (...args) => {\n resolved.logger.warn(...args.map(String))\n },\n error: (...args) => {\n resolved.logger.error(...args.map(String))\n },\n },\n })\n })\n }\n}\n\n/** Absolute paths of entry declaration chunks emitted by the build. */\nfunction entryDtsFilesFromChunks(chunks: RolldownChunk[]): string[] {\n const files: string[] = []\n for (const chunk of chunks) {\n if (chunk.type !== 'chunk' || !chunk.isEntry || !RE_DTS_FILE.test(chunk.fileName)) continue\n files.push(path.resolve(chunk.outDir, chunk.fileName))\n }\n return files\n}\n\n/**\n * The `outExtensions` of the `react-server` variant: tsdown's default extension for the\n * format and package type (see `resolveJsOutputExtension` in tsdown), with `.react-server` inserted\n * so the variant's entries sit next to the compiled ones (`index.js` ↔ `index.react-server.js`,\n * `index.cjs` ↔ `index.react-server.cjs`, and `.mjs` accordingly for CommonJS packages).\n */\nconst reactServerOutExtensions: NonNullable<UserConfig['outExtensions']> = ({format, pkgType}) => ({\n js:\n format === 'cjs'\n ? pkgType === 'module'\n ? '.react-server.cjs'\n : '.react-server.js'\n : pkgType === 'module'\n ? '.react-server.js'\n : '.react-server.mjs',\n})\n\ntype ExportsOptions = Extract<NonNullable<UserConfig['exports']>, object>\ntype CustomExportsFunction = Extract<\n NonNullable<ExportsOptions['customExports']>,\n (...args: never[]) => unknown\n>\ntype ExportsMap = Parameters<CustomExportsFunction>[0]\n/**\n * Wires the `react-server` conditions into tsdown's `exports` feature by composing into\n * `exports.customExports` (the same composition `@sanity/vanilla-extract-tsdown-plugin` uses\n * for its conditional CSS export): a pre-existing `customExports` applies first — both its\n * function and record forms, mirroring how tsdown itself applies them — and the\n * `react-server` conditions are inserted into the result. The composed function runs for both\n * the local `exports` map and `publishConfig.exports`; with `devExports` the local map points\n * at source files, which the entry-file matching leaves untouched (source resolves for every\n * condition in development, which is correct — uncompiled source is exactly what the\n * `react-server` condition ships).\n */\nfunction withReactServerExports(\n exportsOption: Exclude<NonNullable<UserConfig['exports']>, false>,\n): ExportsOptions {\n // Normalize the `boolean | CIOption | object` forms of the `exports` option into the\n // object form, preserving the enabled-ness (`true` and bare CI conditions mean enabled)\n const exportsOptions: ExportsOptions =\n exportsOption === true\n ? {}\n : typeof exportsOption === 'string'\n ? {enabled: exportsOption}\n : exportsOption\n const previousCustomExports = exportsOptions.customExports\n exportsOptions.customExports = async (exportsMap, context) => {\n // Apply a pre-existing `customExports` first (both its function and record forms,\n // mirroring how tsdown itself applies them), then insert the `react-server` conditions\n const base =\n typeof previousCustomExports === 'function'\n ? await previousCustomExports(exportsMap, context)\n : previousCustomExports\n ? {...exportsMap, ...previousCustomExports}\n : exportsMap\n return addReactServerConditions(base, context)\n }\n return exportsOptions\n}\n\n/** Matches the JS output extensions tsdown emits for `es`/`cjs` chunks. */\nconst RE_JS_FILE = /\\.(m?js|cjs)$/\n\n/** The conditions tsdown generates that resolve at runtime, in contrast to `types` etc. */\nconst RUNTIME_CONDITIONS = new Set(['import', 'require', 'default'])\n\n/**\n * Inserts a `react-server` condition into every entry export of an `exports`-shaped map,\n * pointing at the `.react-server.` sibling emitted by the `react-server` variant — e.g.\n * `\"./dist/index.js\"` becomes\n * `{\"types\": \"./dist/index.d.ts\", \"react-server\": \"./dist/index.react-server.js\", \"default\": \"./dist/index.js\"}`.\n *\n * The `react-server` variant emits no `.d.ts` siblings, so TypeScript's adjacent-file lookup\n * cannot resolve types for `./dist/index.react-server.js` — a `types` condition pointing at\n * the compiled variant's declarations is specified before `react-server` instead (conditions\n * match in order, so it covers every resolution mode). It's only added when the declarations\n * actually exist among the compiled variant's chunks, and an already-present `types`\n * condition is left in place.\n *\n * Entries are recognized by comparing export targets against the compiled variant's entry\n * chunks — reconstructed in the exact `./<outDir relative to the package root>/<fileName>`\n * form tsdown writes into the exports map, so entries that share a leaf name (`index.js` vs\n * `features/index.js`) can never shadow each other, and non-entry exports (`./package.json`,\n * the conditional `./bundle.css` export of `vanillaExtract`/`panda`, `devExports` source paths like\n * `./src/index.ts`) pass through untouched. The `react-server` files themselves never enter\n * the map — the `react-server` variant builds with `exports: false` — so they don't become\n * export subpaths of their own.\n */\nfunction addReactServerConditions(\n exportsMap: ExportsMap,\n context: Parameters<CustomExportsFunction>[1],\n): ExportsMap {\n // tsdown always resolves the package with its path here: its own exports generation reads\n // `packageJsonPath` unconditionally from the same object it passes to `customExports` -\n // only the declared context type is the plain `PackageJson` shape.\n const pkg: Partial<PackageJsonWithPath> = context.pkg\n const pkgRoot = path.dirname(pkg.packageJsonPath ?? 'package.json')\n // Export targets of the compiled variant's entry JS and declaration chunks; the\n // `react-server` variant's files sit next to the entries with `.react-server` inserted\n // before the extension\n const entryFiles = new Set<string>()\n const dtsFiles = new Set<string>()\n for (const [format, formatChunks] of Object.entries(context.chunks)) {\n // Only `es` and `cjs` chunks become package exports (mirroring tsdown's own generation)\n if (format !== 'es' && format !== 'cjs') continue\n for (const chunk of formatChunks) {\n if (chunk.type !== 'chunk') continue\n const target = exportTarget(pkgRoot, chunk.outDir, chunk.fileName)\n if (chunk.isEntry && RE_JS_FILE.test(chunk.fileName)) {\n entryFiles.add(target)\n } else if (RE_DTS_FILE.test(chunk.fileName)) {\n dtsFiles.add(target)\n }\n }\n }\n const isEntryFile = (value: unknown): value is string =>\n typeof value === 'string' && entryFiles.has(value)\n // The `types` file for an entry export target, when the compiled variant emitted it\n const dtsFor = (value: string): string | undefined => {\n const dtsFile = toDtsFile(value)\n return dtsFiles.has(dtsFile) ? dtsFile : undefined\n }\n\n const result: ExportsMap = {}\n for (const [key, value] of Object.entries(exportsMap as Record<string, unknown>)) {\n result[key] = withReactServerCondition(value, isEntryFile, dtsFor)\n }\n return result\n}\n\n/**\n * Mirrors tsdown's own `join` for exports targets:\n * `./<outDir relative to the package root>/<fileName>`, with POSIX separators.\n */\nfunction exportTarget(pkgRoot: string, outDir: string, fileName: string): string {\n const outDirRelative = path.relative(pkgRoot, outDir).replaceAll('\\\\', '/')\n return `${outDirRelative ? `./${outDirRelative}` : '.'}/${fileName.replaceAll('\\\\', '/')}`\n}\n\nfunction withReactServerCondition(\n value: unknown,\n isEntryFile: (value: unknown) => value is string,\n dtsFor: (value: string) => string | undefined,\n): unknown {\n // A bare-string entry export (e.g. the pure-ESM publish shape `\".\": \"./dist/index.js\"`)\n // becomes a conditional export, with `types` specified before `react-server` so type\n // resolution never reaches the declaration-less `.react-server.` file\n if (isEntryFile(value)) {\n const types = dtsFor(value)\n return {\n ...(types === undefined ? {} : {types}),\n 'react-server': toServerFile(value),\n 'default': value,\n }\n }\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return value\n const conditions = Object.entries(value)\n const matched = conditions.filter(\n (entry): entry is [string, string] => RUNTIME_CONDITIONS.has(entry[0]) && isEntryFile(entry[1]),\n )\n const [firstMatch] = matched\n if (!firstMatch) return value\n const hasTypes = conditions.some(([condition]) => condition === 'types')\n // A single runtime file maps to a plain path (with a `types` condition inserted ahead of\n // `react-server` below, unless one is already specified). A dual-format entry nests its\n // `import` and `require` files under the `react-server` condition, each with its own\n // format-matched `types` — a single top-level `types` file cannot serve both resolution\n // modes, which is also why tsdown's own dual-format output relies on adjacent-file lookup.\n const missingTypes = hasTypes ? undefined : dtsFor(firstMatch[1])\n const serverTarget =\n matched.length === 1\n ? toServerFile(firstMatch[1])\n : Object.fromEntries(\n matched.map(([condition, target]) => {\n const types = hasTypes ? undefined : dtsFor(target)\n return [\n condition,\n types === undefined ? toServerFile(target) : {types, default: toServerFile(target)},\n ]\n }),\n )\n // Conditions match in order, so `react-server` is inserted right before the first runtime\n // condition (`import`/`require`/`default`), keeping `types` and custom development\n // conditions (`devExports`) ahead of it\n const next: Record<string, unknown> = {}\n let inserted = false\n for (const [condition, target] of conditions) {\n if (!inserted && RUNTIME_CONDITIONS.has(condition)) {\n if (matched.length === 1 && missingTypes !== undefined) {\n next['types'] = missingTypes\n }\n next['react-server'] = serverTarget\n inserted = true\n }\n next[condition] = target\n }\n if (!inserted) {\n next['react-server'] = serverTarget\n }\n return next\n}\n\n/** `./dist/index.js` → `./dist/index.react-server.js` (and `.mjs`/`.cjs` accordingly). */\nfunction toServerFile(file: string): string {\n return file.replace(RE_JS_FILE, '.react-server.$1')\n}\n\n/** `./dist/index.js` → `./dist/index.d.ts` (`.mjs` → `.d.mts`, `.cjs` → `.d.cts`). */\nfunction toDtsFile(file: string): string {\n return file.replace(RE_JS_FILE, (extension) =>\n extension === '.mjs' ? '.d.mts' : extension === '.cjs' ? '.d.cts' : '.d.ts',\n )\n}\n"],"mappings":";;;;;;AAslBA,eAAsB,aACpB,UAA0B,CAAC,GACS;CACpC,IAAM,gBAAgB,QAAQ,iBAAiB;CAa/C,OANI,OAAO,iBAAkB,YAAY,cAAc,gBAAgB,KAC9D,QAAQ,IAAI,CACjB,qBAAqB,SAAS,SAAS,GACvC,qBAAqB,SAAS,cAAc,CAC9C,CAAC,IAEI,qBAAqB,SAAS,YAAY;AACnD;AASA,eAAe,qBACb,SACA,SACqB;CAQrB,IAAM,EAAC,OAAO,UAAU,QAAQ,Q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AU,KAAA,IAAY,aAAa,MAAM,IAAI;GAAC;GAAO,SAAS,aAAa,MAAM;EAAC,CACpF;CACF,CAAC,CACH,GAIA,OAAgC,CAAC,GACnC,WAAW;CACf,KAAK,IAAM,CAAC,WAAW,WAAW,YAQhC,AAPI,CAAC,YAAY,mBAAmB,IAAI,SAAS,MAC3C,QAAQ,WAAW,KAAK,iBAAiB,KAAA,MAC3C,KAAKC,QAAW,eAElB,KAAK,kBAAkB,cACvB,WAAW,KAEb,KAAK,aAAa;CAKpB,OAHK,aACH,KAAK,kBAAkB,eAElB;AACT;;AAGA,SAAS,aAAa,MAAsB;CAC1C,OAAO,KAAK,QAAQ,YAAY,kBAAkB;AACpD;;AAGA,SAAS,UAAU,MAAsB;CACvC,OAAO,KAAK,QAAQ,aAAa,cAC/B,cAAc,SAAS,WAAW,cAAc,SAAS,WAAW,OACtE;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/tsdown-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Shared configuration for tsdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@microsoft/api-extractor": "^7.59.4",
|
|
40
40
|
"@microsoft/tsdoc-config": "^0.18.3",
|
|
41
41
|
"@sanity/browserslist-config": "^1.0.5",
|
|
42
|
-
"@sanity/vanilla-extract-tsdown-plugin": "^0.
|
|
42
|
+
"@sanity/vanilla-extract-tsdown-plugin": "^0.5.1",
|
|
43
43
|
"@typescript/typescript6": "^6.0.2",
|
|
44
44
|
"@vitejs/plugin-react": "^6.1.2",
|
|
45
45
|
"browserslist": "^4.29.3",
|
|
@@ -47,17 +47,18 @@
|
|
|
47
47
|
"lightningcss": "^1.33.0",
|
|
48
48
|
"package-manager-detector": "^1.9.0",
|
|
49
49
|
"publint": "^0.3.25",
|
|
50
|
-
"rolldown": "~1.2.
|
|
50
|
+
"rolldown": "~1.2.14"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/core": "^7.29.7",
|
|
54
54
|
"@rolldown/plugin-babel": "^0.2.4",
|
|
55
|
-
"@sanity/
|
|
55
|
+
"@sanity/pandacss-tsdown-plugin": "^0.1.0",
|
|
56
|
+
"@sanity/pkg-utils": "^13.0.12",
|
|
56
57
|
"@sanity/tsconfig": "^2.2.1",
|
|
57
58
|
"@tsdown/css": "^0.23.1",
|
|
58
59
|
"@types/babel__core": "^7.20.5",
|
|
59
60
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
60
|
-
"oxc-transform-react": "^0.
|
|
61
|
+
"oxc-transform-react": "^0.154.0",
|
|
61
62
|
"tinyexec": "^1.3.1",
|
|
62
63
|
"tsdown": "^0.23.1",
|
|
63
64
|
"typescript": "7.0.2",
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
"peerDependencies": {
|
|
67
68
|
"@babel/core": "*",
|
|
68
69
|
"@rolldown/plugin-babel": "*",
|
|
70
|
+
"@sanity/pandacss-tsdown-plugin": "*",
|
|
69
71
|
"@tsdown/css": "*",
|
|
70
72
|
"babel-plugin-react-compiler": "*",
|
|
71
73
|
"oxc-transform-react": "*",
|
|
@@ -79,6 +81,9 @@
|
|
|
79
81
|
"@rolldown/plugin-babel": {
|
|
80
82
|
"optional": true
|
|
81
83
|
},
|
|
84
|
+
"@sanity/pandacss-tsdown-plugin": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
82
87
|
"@tsdown/css": {
|
|
83
88
|
"optional": true
|
|
84
89
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cssLoweringTargets-Dn_sJGip.mjs","names":[],"sources":["../src/cssLoweringTargets.ts"],"sourcesContent":["import {esbuildTargetToLightningCSS} from '@sanity/vanilla-extract-tsdown-plugin'\nimport type {Targets} from 'lightningcss'\n\n/** The `lightningcss` options both CSS pipelines accept, narrowed to what this helper touches. */\ninterface LightningCSSOptionsWithTargets {\n targets?: Targets | undefined\n}\n\n/**\n * Resolves the CSS syntax lowering targets for a CSS pipeline\n * (`vanillaExtract`/`css`), applying the Sanity-flavored fallback on top of the\n * `@tsdown/css` behavior both pipelines otherwise follow.\n *\n * `@tsdown/css` skips syntax lowering when it has no browser targets. Extracted CSS always runs\n * in browsers though, so when the effective target (the pipeline's own `target`, falling back to\n * the top-level `target`) is undefined or names no browsers - e.g. `'node20'`, which is also\n * what tsdown derives from `engines.node` and speaks to the JS runtime - the lowering targets\n * are resolved from `@sanity/browserslist-config` and passed through `lightningcss.targets`\n * instead.\n *\n * `target: false` stays the explicit off switch, and a user-provided `lightningcss.targets`\n * wins over the fallback.\n *\n * @internal\n */\nexport async function resolveCssLoweringTargets(options: {\n /** The pipeline's own `target` option. */\n cssTarget: string | string[] | false | undefined\n /** tsdown's top-level `target`, the fallback for `cssTarget`. */\n target: string | string[] | false | undefined\n /** The pipeline's own `lightningcss` options. */\n lightningcss: LightningCSSOptionsWithTargets | undefined\n}): Promise<LightningCSSOptionsWithTargets | undefined> {\n const {target, lightningcss} = options\n const cssTarget = options.cssTarget ?? target\n\n if (\n cssTarget === false ||\n lightningcss?.targets ||\n (cssTarget !== undefined && esbuildTargetToLightningCSS(cssTarget))\n ) {\n return lightningcss\n }\n\n // Lazy loaded: `browserslistToTargets` is a pure helper, but `lightningcss` is a native\n // package that only needs to load when the fallback applies\n const [{default: browserslist}, {default: browserslistConfig}, {browserslistToTargets}] =\n await Promise.all([\n import('browserslist'),\n import('@sanity/browserslist-config'),\n import('lightningcss'),\n ])\n return {\n ...lightningcss,\n targets: browserslistToTargets(browserslist(browserslistConfig)),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,eAAsB,0BAA0B,SAOQ;CACtD,IAAM,EAAC,QAAQ,iBAAgB,SACzB,YAAY,QAAQ,aAAa;CAEvC,IACE,cAAc,MACd,cAAc,WACb,cAAc,KAAA,KAAa,4BAA4B,SAAS,GAEjE,OAAO;CAKT,IAAM,CAAC,EAAC,SAAS,gBAAe,EAAC,SAAS,sBAAqB,EAAC,2BAC9D,MAAM,QAAQ,IAAI;EAChB,OAAO;EACP,OAAO;EACP,OAAO;CACT,CAAC;CACH,OAAO;EACL,GAAG;EACH,SAAS,sBAAsB,aAAa,kBAAkB,CAAC;CACjE;AACF"}
|