@sanity/tsdown-config 0.23.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -15
- package/dist/cssLoweringTargets-Dn_sJGip.mjs +34 -0
- package/dist/cssLoweringTargets-Dn_sJGip.mjs.map +1 -0
- package/dist/cssNodeCompatPlugin-B_ndKoRv.mjs +115 -0
- package/dist/cssNodeCompatPlugin-B_ndKoRv.mjs.map +1 -0
- package/dist/index.d.mts +93 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +118 -16
- package/dist/index.mjs.map +1 -1
- package/dist/tsdoc.d.mts +47 -0
- package/dist/tsdoc.d.mts.map +1 -0
- package/dist/tsdoc.mjs +196 -0
- package/dist/tsdoc.mjs.map +1 -0
- package/dist/types-CrQ2my_P.d.mts +38 -0
- package/dist/types-CrQ2my_P.d.mts.map +1 -0
- package/package.json +16 -7
package/README.md
CHANGED
|
@@ -152,8 +152,8 @@ export default defineConfig({
|
|
|
152
152
|
})
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
By default (`inject: {nodeCompat: true}`) the conditional CSS export pattern
|
|
156
|
-
automatically:
|
|
155
|
+
By default (`inject: true` with `exports: {nodeCompat: true}`) the conditional CSS export pattern
|
|
156
|
+
is wired up automatically:
|
|
157
157
|
|
|
158
158
|
- injects the self-referential `import "<pkg>/bundle.css"` into the entry chunks that use
|
|
159
159
|
vanilla-extract styles,
|
|
@@ -174,9 +174,15 @@ consumers by adding it to `sideEffects` in `package.json`:
|
|
|
174
174
|
|
|
175
175
|
Pass an options object instead of `true` to customize - the options are modeled after the
|
|
176
176
|
[`css` options of `@tsdown/css`](https://tsdown.dev/options/css) (e.g. `fileName`, `minify`,
|
|
177
|
-
`target`, `lightningcss`).
|
|
178
|
-
|
|
179
|
-
export
|
|
177
|
+
`target`, `lightningcss`). `inject` and `exports` are independent: set `exports: true` for a
|
|
178
|
+
plain (browser-only) `"./bundle.css"` export without the shim, `exports: false` for a relative
|
|
179
|
+
`import "./bundle.css"` instead of the export pattern, or `inject: false` to publish the CSS
|
|
180
|
+
without importing it automatically (for packages whose consumers import the subpath themselves).
|
|
181
|
+
|
|
182
|
+
> [!NOTE]
|
|
183
|
+
> `inject: {nodeCompat: true}` is deprecated. It means `{inject: true, exports: {nodeCompat: true}}`
|
|
184
|
+
> and still works, with a warning: `nodeCompat` configures how the CSS file is published, not how
|
|
185
|
+
> the import is injected, so it moved to `exports`.
|
|
180
186
|
|
|
181
187
|
Two Sanity-flavored defaults diverge from the bare plugins (which match `@tsdown/css` exactly):
|
|
182
188
|
|
|
@@ -196,11 +202,10 @@ default (`bundle.css` vs `style.css`) and do not interfere with each other.
|
|
|
196
202
|
|
|
197
203
|
## css
|
|
198
204
|
|
|
199
|
-
tsdown's experimental [`css` option](https://tsdown.dev/options/css)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
`@tsdown/css` itself:
|
|
205
|
+
tsdown's experimental [`css` option](https://tsdown.dev/options/css) enables the `@tsdown/css`
|
|
206
|
+
pipeline for plain CSS, CSS modules, preprocessors, and Lightning CSS / PostCSS. Install
|
|
207
|
+
[`@tsdown/css`](https://www.npmjs.com/package/@tsdown/css) in the project first — it is an
|
|
208
|
+
optional peer dependency:
|
|
204
209
|
|
|
205
210
|
```sh
|
|
206
211
|
pnpm add --save-dev @tsdown/css
|
|
@@ -212,12 +217,23 @@ import {defineConfig} from '@sanity/tsdown-config'
|
|
|
212
217
|
export default defineConfig({
|
|
213
218
|
tsconfig: 'tsconfig.dist.json',
|
|
214
219
|
css: {
|
|
215
|
-
inject: true,
|
|
216
220
|
modules: {localsConvention: 'camelCase'},
|
|
217
221
|
},
|
|
218
222
|
})
|
|
219
223
|
```
|
|
220
224
|
|
|
225
|
+
The options are `@tsdown/css`'s, plus an `exports` option this config implements on top, with the
|
|
226
|
+
same two Sanity-flavored defaults as `vanillaExtract`:
|
|
227
|
+
|
|
228
|
+
- `exports` defaults to `{nodeCompat: true}`, wiring up the same conditional CSS export pattern:
|
|
229
|
+
the self-referential `import "<pkg>/style.css"`, a no-op `style-css.js` shim with its
|
|
230
|
+
`style-css.d.ts` declaration, and the conditional `"./style.css"` export in `package.json`.
|
|
231
|
+
`@tsdown/css` has no equivalent — its own `inject` emits a relative `import "./style.css"`,
|
|
232
|
+
which throws in runtimes that cannot load `.css` files. Set `exports: true` for a plain
|
|
233
|
+
(browser-only) CSS export, or `exports: false` to fall back to the relative injection.
|
|
234
|
+
- `minify` defaults to `true`, and browserless CSS syntax lowering targets fall back to
|
|
235
|
+
`@sanity/browserslist-config` — exactly as described for `vanillaExtract` above.
|
|
236
|
+
|
|
221
237
|
Both `css` and `vanillaExtract` can be enabled in the same config. Use that when a package
|
|
222
238
|
authors styles with vanilla-extract _and_ CSS modules (`.module.css`):
|
|
223
239
|
|
|
@@ -228,15 +244,14 @@ export default defineConfig({
|
|
|
228
244
|
tsconfig: 'tsconfig.dist.json',
|
|
229
245
|
vanillaExtract: true,
|
|
230
246
|
css: {
|
|
231
|
-
inject: true,
|
|
232
247
|
modules: {localsConvention: 'camelCase'},
|
|
233
248
|
},
|
|
234
249
|
})
|
|
235
250
|
```
|
|
236
251
|
|
|
237
|
-
vanilla-extract extracts into `dist/bundle.css`
|
|
238
|
-
`
|
|
239
|
-
|
|
252
|
+
vanilla-extract extracts into `dist/bundle.css`, while `@tsdown/css` merges other CSS — including
|
|
253
|
+
scoped CSS modules — into `dist/style.css`. Each pipeline publishes its own conditional export and
|
|
254
|
+
emits its own shim, so they never collide. See the
|
|
240
255
|
[`InlineConfig.css`](https://tsdown.dev/reference/api/Interface.InlineConfig#css) API reference
|
|
241
256
|
for the full option surface.
|
|
242
257
|
|
|
@@ -258,6 +273,44 @@ export default defineConfig({
|
|
|
258
273
|
})
|
|
259
274
|
```
|
|
260
275
|
|
|
276
|
+
## tsdoc
|
|
277
|
+
|
|
278
|
+
Runs [API Extractor](https://api-extractor.com/) after the build (via tsdown's `build:done` hook)
|
|
279
|
+
to check that TSDoc tags are valid and release tags are correct. Off by default — set
|
|
280
|
+
`tsdoc: true` to enable, or pass an options object to customize rules and custom tags:
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
284
|
+
|
|
285
|
+
export default defineConfig({
|
|
286
|
+
tsconfig: 'tsconfig.dist.json',
|
|
287
|
+
tsdoc: true,
|
|
288
|
+
})
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
export default defineConfig({
|
|
293
|
+
tsconfig: 'tsconfig.dist.json',
|
|
294
|
+
tsdoc: {
|
|
295
|
+
rules: {
|
|
296
|
+
// do not require internal members to be prefixed with `_`
|
|
297
|
+
'ae-internal-missing-underscore': 'off',
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
})
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The check runs against every entry `.d.ts` / `.d.mts` / `.d.cts` file the build emitted. API
|
|
304
|
+
Extractor is loaded only when that hook runs (or when you import the programmatic API), so
|
|
305
|
+
enabling `tsdoc` does not pull those dependencies into the root `@sanity/tsdown-config` entry.
|
|
306
|
+
|
|
307
|
+
It is also available as `checkTsdoc` from `@sanity/tsdown-config/tsdoc` for hosts that want to
|
|
308
|
+
run it outside the build:
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
import {checkTsdoc} from '@sanity/tsdown-config/tsdoc'
|
|
312
|
+
```
|
|
313
|
+
|
|
261
314
|
## outDir
|
|
262
315
|
|
|
263
316
|
tsdown's [`outDir` option](https://tsdown.dev/options/output#outdir) is passed through as-is.
|
|
@@ -484,6 +537,8 @@ const config = await defineConfig({
|
|
|
484
537
|
Rolldown's [`checks.circularDependency`](https://rolldown.rs/reference/InputOptions.checks#circulardependency)
|
|
485
538
|
warning is enabled by default (Rolldown itself defaults it to `false`). Circular imports inflate
|
|
486
539
|
bundle size and can cause execution-order issues, so library builds surface them as warnings.
|
|
540
|
+
Cycles that only exist between declaration files are filtered out - see
|
|
541
|
+
[`suppressWarnings`](#suppresswarnings).
|
|
487
542
|
|
|
488
543
|
To turn the warning off, merge over the returned config:
|
|
489
544
|
|
|
@@ -496,6 +551,47 @@ export default mergeConfig(await defineConfig({tsconfig: 'tsconfig.dist.json'}),
|
|
|
496
551
|
})
|
|
497
552
|
```
|
|
498
553
|
|
|
554
|
+
## suppressWarnings
|
|
555
|
+
|
|
556
|
+
The `checks.circularDependency` check above also applies to the declaration bundling pass, where
|
|
557
|
+
it reports cycles between the emitted `.d.ts` modules. Those imports are type-only and erased at
|
|
558
|
+
runtime, so the cycles carry none of the hazards the check exists to surface - and they're
|
|
559
|
+
unavoidable for mutually referencing public types, e.g. a `DocumentNode` whose `fields` are
|
|
560
|
+
`FieldNode`s that point back at their `parent` document. In
|
|
561
|
+
[sanity-io/sanity#13753](https://github.com/sanity-io/sanity/pull/13753) 109 of 136 cycle
|
|
562
|
+
warnings were declaration-only, drowning out the 27 real ones.
|
|
563
|
+
|
|
564
|
+
So `defineConfig` sets tsdown's `suppressWarnings` to drop `CIRCULAR_DEPENDENCY` warnings whose
|
|
565
|
+
**entire** cycle consists of declaration files (`.d.ts`/`.d.mts`/`.d.cts`). A cycle that includes
|
|
566
|
+
even one runtime module still warns.
|
|
567
|
+
|
|
568
|
+
Adding your own suppressions - strings (matched with `includes`), regular expressions (matched
|
|
569
|
+
with `test`), or a predicate - goes through the `suppressWarnings` option, which is OR'd with the
|
|
570
|
+
built-in one rather than replacing it:
|
|
571
|
+
|
|
572
|
+
```ts
|
|
573
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
574
|
+
|
|
575
|
+
export default defineConfig({
|
|
576
|
+
tsconfig: 'tsconfig.dist.json',
|
|
577
|
+
suppressWarnings: [/EMPTY_BUNDLE/, 'node_modules/some-dep'],
|
|
578
|
+
})
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
Suppression happens before `failOnWarn` turns warnings into errors, so a suppressed warning never
|
|
582
|
+
fails the build. To drop the built-in suppression instead of adding to it, merge over the returned
|
|
583
|
+
config - `mergeConfig` replaces functions:
|
|
584
|
+
|
|
585
|
+
```ts
|
|
586
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
587
|
+
import {mergeConfig} from 'tsdown'
|
|
588
|
+
|
|
589
|
+
export default mergeConfig(await defineConfig({tsconfig: 'tsconfig.dist.json'}), {
|
|
590
|
+
// Restores every warning, including the declaration-only cycles
|
|
591
|
+
suppressWarnings: () => false,
|
|
592
|
+
})
|
|
593
|
+
```
|
|
594
|
+
|
|
499
595
|
## Everything else: `mergeConfig`
|
|
500
596
|
|
|
501
597
|
`defineConfig` deliberately only exposes options you're likely to change. For anything else, merge
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { esbuildTargetToLightningCSS } from "@sanity/vanilla-extract-tsdown-plugin";
|
|
2
|
+
/**
|
|
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 both pipelines otherwise follow.
|
|
6
|
+
*
|
|
7
|
+
* `@tsdown/css` skips syntax lowering when it has no browser targets. Extracted CSS always runs
|
|
8
|
+
* in browsers though, so when the effective target (the pipeline's own `target`, falling back to
|
|
9
|
+
* the top-level `target`) is undefined or names no browsers - e.g. `'node20'`, which is also
|
|
10
|
+
* what tsdown derives from `engines.node` and speaks to the JS runtime - the lowering targets
|
|
11
|
+
* are resolved from `@sanity/browserslist-config` and passed through `lightningcss.targets`
|
|
12
|
+
* instead.
|
|
13
|
+
*
|
|
14
|
+
* `target: false` stays the explicit off switch, and a user-provided `lightningcss.targets`
|
|
15
|
+
* wins over the fallback.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
async function resolveCssLoweringTargets(options) {
|
|
20
|
+
let { target, lightningcss } = options, cssTarget = options.cssTarget ?? target;
|
|
21
|
+
if (cssTarget === !1 || lightningcss?.targets || cssTarget !== void 0 && esbuildTargetToLightningCSS(cssTarget)) return lightningcss;
|
|
22
|
+
let [{ default: browserslist }, { default: browserslistConfig }, { browserslistToTargets }] = await Promise.all([
|
|
23
|
+
import("browserslist"),
|
|
24
|
+
import("@sanity/browserslist-config"),
|
|
25
|
+
import("lightningcss")
|
|
26
|
+
]);
|
|
27
|
+
return {
|
|
28
|
+
...lightningcss,
|
|
29
|
+
targets: browserslistToTargets(browserslist(browserslistConfig))
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export { resolveCssLoweringTargets };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=cssLoweringTargets-Dn_sJGip.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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<T extends LightningCSSOptionsWithTargets>(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: T | undefined\n}): Promise<T | 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 // oxlint-disable-next-line no-unsafe-type-assertion -- widening the passthrough options object\n return {\n ...lightningcss,\n targets: browserslistToTargets(browserslist(browserslistConfig)),\n } as T\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,eAAsB,0BAAoE,SAO/D;CACzB,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,OAAO;EACL,GAAG;EACH,SAAS,sBAAsB,aAAa,kBAAkB,CAAC;CACjE;AACF"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createConditionalCssExport, createCssExport, cssShimDtsFileName, cssShimDtsSource, cssShimFileName, cssShimSource, insertCssExport, resolveCssExportOptions } from "@sanity/vanilla-extract-tsdown-plugin";
|
|
3
|
+
/**
|
|
4
|
+
* Matches the module ids `@tsdown/css` treats as stylesheets, so this plugin can tell which
|
|
5
|
+
* chunks pulled CSS in without reaching into `@tsdown/css`'s own bookkeeping.
|
|
6
|
+
*/
|
|
7
|
+
const RE_CSS_LANG = /\.(css|less|sass|scss|styl|stylus)(?:$|\?)/, RE_CSS_INLINE = /[?&]inline\b/, RE_DTS = /\.d\.[cm]?ts$/, RE_CSS_ASSET = /\.css$/;
|
|
8
|
+
/** `index.mjs` -> `index.css`, the naming `@tsdown/css` uses when `css.splitting` is on. */
|
|
9
|
+
function toCssFileName(jsFileName) {
|
|
10
|
+
return jsFileName.replace(/(?:\.module)?(\.[cm]?js)$/, ".css");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A tsdown plugin that gives `@tsdown/css` output the same conditional CSS export pattern
|
|
14
|
+
* `@sanity/vanilla-extract-tsdown-plugin` gives vanilla-extract output.
|
|
15
|
+
*
|
|
16
|
+
* `@tsdown/css` compiles CSS but has no node-shim concept: its only `inject` is a relative
|
|
17
|
+
* `import "./style.css"`, which throws in every runtime that cannot load `.css` files. For each
|
|
18
|
+
* CSS file `@tsdown/css` emits, this plugin instead:
|
|
19
|
+
*
|
|
20
|
+
* - emits a no-op JS shim (`style.css` -> `style-css.js`) and its `style-css.d.ts` declaration,
|
|
21
|
+
* - writes the `"./style.css"` export to `package.json` (and `publishConfig.exports`) through
|
|
22
|
+
* tsdown's `exports` feature, conditional with `nodeCompat` so `browser`/`style` resolve to
|
|
23
|
+
* the stylesheet while `node`/`default` resolve to the shim, and
|
|
24
|
+
* - prepends the self-referential `import "<pkg>/style.css"` to entry chunks that use the CSS,
|
|
25
|
+
* replacing `@tsdown/css`'s relative injection.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function cssNodeCompatPlugin(options = {}) {
|
|
30
|
+
let { inject, exports: exportsCss, nodeCompat } = resolveCssExportOptions(options), splitting = options.splitting ?? !1, mergedFileName = options.fileName ?? "style.css", cssModuleIds = /* @__PURE__ */ new Set(), packageName, cssFileNameFor = (chunkFileName) => splitting ? toCssFileName(chunkFileName) : mergedFileName;
|
|
31
|
+
return {
|
|
32
|
+
name: "sanity-css-node-compat",
|
|
33
|
+
options(inputOptions) {
|
|
34
|
+
if (inject) return {
|
|
35
|
+
...inputOptions,
|
|
36
|
+
experimental: {
|
|
37
|
+
...inputOptions.experimental,
|
|
38
|
+
nativeMagicString: !0
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
transform: {
|
|
43
|
+
filter: { id: RE_CSS_LANG },
|
|
44
|
+
handler(_code, id) {
|
|
45
|
+
RE_CSS_INLINE.test(id) || cssModuleIds.add(id);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
tsdownConfig(config) {
|
|
49
|
+
if (!exportsCss || splitting) return;
|
|
50
|
+
let exportsOption = config.exports;
|
|
51
|
+
if (!exportsOption) return;
|
|
52
|
+
let exportsOptions = exportsOption === !0 ? {} : typeof exportsOption == "string" ? { enabled: exportsOption } : exportsOption, configOutDir = config.outDir ?? "dist", cssExport = nodeCompat ? createConditionalCssExport(mergedFileName, configOutDir) : createCssExport(mergedFileName, configOutDir), previousCustomExports = exportsOptions.customExports;
|
|
53
|
+
exportsOptions.customExports = async (exportsMap, context) => {
|
|
54
|
+
let base = typeof previousCustomExports == "function" ? await previousCustomExports(exportsMap, context) : previousCustomExports ? {
|
|
55
|
+
...exportsMap,
|
|
56
|
+
...previousCustomExports
|
|
57
|
+
} : exportsMap;
|
|
58
|
+
return Object.values(context.chunks).some((chunks) => chunks.some((chunk) => chunk.type === "asset" && chunk.fileName === mergedFileName)) ? insertCssExport(base, `./${mergedFileName}`, cssExport) : base;
|
|
59
|
+
}, config.exports = exportsOptions;
|
|
60
|
+
},
|
|
61
|
+
tsdownConfigResolved(config) {
|
|
62
|
+
packageName = config.pkg?.name;
|
|
63
|
+
},
|
|
64
|
+
renderChunk(code, chunk, outputOptions, meta) {
|
|
65
|
+
if (!inject || cssModuleIds.size === 0 || !chunk.isEntry || chunk.name.endsWith(".d") || RE_DTS.test(chunk.fileName)) return;
|
|
66
|
+
let { format } = outputOptions;
|
|
67
|
+
if (format !== "es" && format !== "cjs" || !(splitting ? chunk.moduleIds.some((id) => cssModuleIds.has(id)) : chunkHasStyles(chunk, meta.chunks, cssModuleIds))) return;
|
|
68
|
+
let cssFileName = cssFileNameFor(chunk.fileName), specifier = JSON.stringify(exportsCss ? `${resolvePackageName()}/${cssFileName}` : relativeImportPath(chunk.fileName, cssFileName)), statement = format === "cjs" ? `require(${specifier});\n` : `import ${specifier};\n`, { magicString } = meta;
|
|
69
|
+
return magicString ? (magicString.prepend(statement), magicString) : (outputOptions.sourcemap && this.warn(`[sanity-css-node-compat] rolldown's native magic-string is unavailable, so the CSS import injected into "${chunk.fileName}" shifts its sourcemap by one line.`), { code: statement + code });
|
|
70
|
+
},
|
|
71
|
+
generateBundle: {
|
|
72
|
+
order: "post",
|
|
73
|
+
handler(_outputOptions, bundle) {
|
|
74
|
+
if (!nodeCompat) return;
|
|
75
|
+
let cssFileNames = Object.values(bundle).filter((asset) => asset.type === "asset" && RE_CSS_ASSET.test(asset.fileName)).map((asset) => asset.fileName);
|
|
76
|
+
for (let cssFileName of cssFileNames) {
|
|
77
|
+
let shimFileName = cssShimFileName(cssFileName);
|
|
78
|
+
bundle[shimFileName] || (this.emitFile({
|
|
79
|
+
type: "asset",
|
|
80
|
+
fileName: shimFileName,
|
|
81
|
+
source: cssShimSource(cssFileName)
|
|
82
|
+
}), this.emitFile({
|
|
83
|
+
type: "asset",
|
|
84
|
+
fileName: cssShimDtsFileName(cssFileName),
|
|
85
|
+
source: cssShimDtsSource(cssFileName)
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function resolvePackageName() {
|
|
92
|
+
if (!packageName) throw Error("[sanity-css-node-compat] Unable to resolve the package name from package.json, which is required by `css.exports` for the self-referential CSS import. Disable `css.exports` (or `css.inject`) to wire up the CSS import yourself.");
|
|
93
|
+
return packageName;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** The relative import path from a chunk to a CSS file, like the `css.inject` in `@tsdown/css`. */
|
|
97
|
+
function relativeImportPath(chunkFileName, cssFileName) {
|
|
98
|
+
let relativePath = path.posix.relative(path.posix.dirname(chunkFileName), cssFileName);
|
|
99
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
100
|
+
}
|
|
101
|
+
/** Whether a chunk (or any chunk it imports, transitively) contains stylesheet modules. */
|
|
102
|
+
function chunkHasStyles(chunk, chunks, cssModuleIds) {
|
|
103
|
+
let seen = /* @__PURE__ */ new Set(), queue = [chunk];
|
|
104
|
+
for (let current = queue.pop(); current; current = queue.pop()) if (!seen.has(current.fileName)) {
|
|
105
|
+
if (seen.add(current.fileName), current.moduleIds.some((id) => cssModuleIds.has(id))) return !0;
|
|
106
|
+
for (let imported of [...current.imports, ...current.dynamicImports]) {
|
|
107
|
+
let importedChunk = chunks[imported];
|
|
108
|
+
importedChunk && queue.push(importedChunk);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return !1;
|
|
112
|
+
}
|
|
113
|
+
export { cssNodeCompatPlugin };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=cssNodeCompatPlugin-B_ndKoRv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssNodeCompatPlugin-B_ndKoRv.mjs","names":[],"sources":["../src/cssNodeCompatPlugin.ts"],"sourcesContent":["import path from 'node:path'\nimport {\n createConditionalCssExport,\n createCssExport,\n cssShimDtsFileName,\n cssShimDtsSource,\n cssShimFileName,\n cssShimSource,\n insertCssExport,\n resolveCssExportOptions,\n type CssExportsOptions,\n} from '@sanity/vanilla-extract-tsdown-plugin'\nimport type {ResolvedConfig, TsdownPlugin, UserConfig} from 'tsdown'\n\n/**\n * Matches the module ids `@tsdown/css` treats as stylesheets, so this plugin can tell which\n * chunks pulled CSS in without reaching into `@tsdown/css`'s own bookkeeping.\n */\nconst RE_CSS_LANG = /\\.(css|less|sass|scss|styl|stylus)(?:$|\\?)/\n/** Matches `?inline` CSS imports, which `@tsdown/css` inlines into JS instead of extracting. */\nconst RE_CSS_INLINE = /[?&]inline\\b/\n/** Matches rendered `.d.ts`/`.d.mts`/`.d.cts` chunk file names. */\nconst RE_DTS = /\\.d\\.[cm]?ts$/\n/** Matches the emitted CSS assets whose shims and exports this plugin maintains. */\nconst RE_CSS_ASSET = /\\.css$/\n\n/** `index.mjs` -> `index.css`, the naming `@tsdown/css` uses when `css.splitting` is on. */\nfunction toCssFileName(jsFileName: string): string {\n return jsFileName.replace(/(?:\\.module)?(\\.[cm]?js)$/, '.css')\n}\n\n/**\n * The `@tsdown/css` options this plugin needs to mirror. Kept structural so the plugin does not\n * have to import `@tsdown/css` (an optional peer dependency) for its types.\n */\nexport interface CssNodeCompatPluginOptions {\n /** `css.fileName`, the merged CSS file name when `css.splitting` is off. */\n fileName?: string | undefined\n /** `css.splitting`, which switches CSS output from one merged file to one file per chunk. */\n splitting?: boolean | undefined\n /** Prepend an import of the CSS to entry chunks that use it. */\n inject?: boolean | undefined\n /** Publish the CSS files as export subpaths, optionally with the Node-safe shim. */\n exports?: boolean | CssExportsOptions | undefined\n}\n\n/**\n * A tsdown plugin that gives `@tsdown/css` output the same conditional CSS export pattern\n * `@sanity/vanilla-extract-tsdown-plugin` gives vanilla-extract output.\n *\n * `@tsdown/css` compiles CSS but has no node-shim concept: its only `inject` is a relative\n * `import \"./style.css\"`, which throws in every runtime that cannot load `.css` files. For each\n * CSS file `@tsdown/css` emits, this plugin instead:\n *\n * - emits a no-op JS shim (`style.css` -> `style-css.js`) and its `style-css.d.ts` declaration,\n * - writes the `\"./style.css\"` export to `package.json` (and `publishConfig.exports`) through\n * tsdown's `exports` feature, conditional with `nodeCompat` so `browser`/`style` resolve to\n * the stylesheet while `node`/`default` resolve to the shim, and\n * - prepends the self-referential `import \"<pkg>/style.css\"` to entry chunks that use the CSS,\n * replacing `@tsdown/css`'s relative injection.\n *\n * @internal\n */\nexport function cssNodeCompatPlugin(options: CssNodeCompatPluginOptions = {}): TsdownPlugin {\n const {inject, exports: exportsCss, nodeCompat} = resolveCssExportOptions(options)\n const splitting = options.splitting ?? false\n const mergedFileName = options.fileName ?? 'style.css'\n\n /**\n * The ids of the stylesheet modules in the build, mirroring `@tsdown/css`'s own `styles` map\n * so a chunk's CSS usage can be detected without depending on it. Hosts run one build per\n * output format with a shared plugin instance, so the set is append-only.\n */\n const cssModuleIds = new Set<string>()\n /** The package name, for the self-referential CSS import. */\n let packageName: string | undefined\n\n /** The CSS file an entry chunk's own styles are emitted to. */\n const cssFileNameFor = (chunkFileName: string): string =>\n splitting ? toCssFileName(chunkFileName) : mergedFileName\n\n return {\n name: 'sanity-css-node-compat',\n\n // Injection prepends the import through rolldown's native MagicString\n // (`meta.magicString`), which keeps sourcemaps intact.\n options(inputOptions) {\n if (!inject) return undefined\n return {\n ...inputOptions,\n experimental: {...inputOptions.experimental, nativeMagicString: true},\n }\n },\n\n // Record the stylesheet modules without transforming them: `@tsdown/css`'s own `transform`\n // hooks do the compiling, and returning `undefined` here leaves their result untouched.\n transform: {\n filter: {id: RE_CSS_LANG},\n handler(_code, id) {\n if (!RE_CSS_INLINE.test(id)) cssModuleIds.add(id)\n return undefined\n },\n },\n\n // With `exports`, write the `./<cssFileName>` exports to `package.json` (and, through\n // tsdown, to `publishConfig.exports`) by composing into `exports.customExports` before the\n // config is resolved. tsdown's `exports` feature is opt-in, so nothing is written when it\n // is not enabled. Only the merged mode has a statically known file name; with `splitting`\n // the file names follow the chunk names, so those exports are left to the host (which is\n // what `@sanity/pkg-utils` does for its `.css` export subpaths).\n tsdownConfig(config: UserConfig) {\n if (!exportsCss || splitting) return undefined\n const exportsOption = config.exports\n if (!exportsOption) return undefined\n\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: Extract<NonNullable<UserConfig['exports']>, object> = exportsOption ===\n true\n ? {}\n : typeof exportsOption === 'string'\n ? {enabled: exportsOption}\n : exportsOption\n\n const configOutDir = config.outDir ?? 'dist'\n const cssExport = nodeCompat\n ? createConditionalCssExport(mergedFileName, configOutDir)\n : createCssExport(mergedFileName, configOutDir)\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 CSS export\n const base =\n typeof previousCustomExports === 'function'\n ? await previousCustomExports(exportsMap, context)\n : previousCustomExports\n ? {...exportsMap, ...previousCustomExports}\n : exportsMap\n // Only declare the export when the build actually emitted the CSS file. A package can\n // enable the pipeline (or have it enabled for it) without any JS-imported CSS, and an\n // export pointing at a file nobody produced is worse than no export at all.\n const emitted = Object.values(context.chunks).some((chunks) =>\n chunks.some((chunk) => chunk.type === 'asset' && chunk.fileName === mergedFileName),\n )\n return emitted ? insertCssExport(base, `./${mergedFileName}`, cssExport) : base\n }\n config.exports = exportsOptions\n return undefined\n },\n\n tsdownConfigResolved(config: ResolvedConfig) {\n packageName = config.pkg?.name\n },\n\n // Inject the CSS import into entry chunks that use CSS: relative by default (like\n // `css.inject` in `@tsdown/css`), or the self-referential bare specifier when the CSS file\n // is published as an export subpath.\n renderChunk(code, chunk, outputOptions, meta) {\n if (!inject || cssModuleIds.size === 0) return undefined\n // The `.d` name / `.d.ts` file checks skip the chunks of tsdown's d.ts passes - they\n // never contain styles.\n if (!chunk.isEntry || chunk.name.endsWith('.d') || RE_DTS.test(chunk.fileName))\n return undefined\n const {format} = outputOptions\n if (format !== 'es' && format !== 'cjs') return undefined\n // In merged mode every stylesheet lands in the same file, so a chunk that reaches CSS\n // through an imported chunk still needs the import. With `splitting` each chunk's CSS\n // goes to its own file, so only the chunk's own modules count - the same condition\n // `@tsdown/css` uses for its relative injection.\n const hasStyles = splitting\n ? chunk.moduleIds.some((id) => cssModuleIds.has(id))\n : chunkHasStyles(chunk, meta.chunks, cssModuleIds)\n if (!hasStyles) return undefined\n\n const cssFileName = cssFileNameFor(chunk.fileName)\n const specifier = JSON.stringify(\n exportsCss\n ? `${resolvePackageName()}/${cssFileName}`\n : relativeImportPath(chunk.fileName, cssFileName),\n )\n const statement = format === 'cjs' ? `require(${specifier});\\n` : `import ${specifier};\\n`\n\n const {magicString} = meta\n if (magicString) {\n magicString.prepend(statement)\n return magicString\n }\n // Fallback when another `options` hook disabled `experimental.nativeMagicString`: the\n // import is still injected, but the chunk's sourcemap can't be adjusted for it.\n if (outputOptions.sourcemap) {\n this.warn(\n `[sanity-css-node-compat] rolldown's native magic-string is unavailable, so the CSS import injected into \"${chunk.fileName}\" shifts its sourcemap by one line.`,\n )\n }\n return {code: statement + code}\n },\n\n // Emit a no-op JS shim and its declaration file next to every CSS file `@tsdown/css`\n // emitted, for the `node`/`default` and `types` conditions of the export to point at.\n // `order: 'post'` is required: tsdown registers the `@tsdown/css` output plugins after the\n // user plugins, so the CSS assets only exist in the bundle once they have run.\n generateBundle: {\n order: 'post',\n handler(_outputOptions, bundle) {\n if (!nodeCompat) return\n const cssFileNames = Object.values(bundle)\n .filter((asset) => asset.type === 'asset' && RE_CSS_ASSET.test(asset.fileName))\n .map((asset) => asset.fileName)\n\n for (const cssFileName of cssFileNames) {\n const shimFileName = cssShimFileName(cssFileName)\n // Another plugin (`@sanity/vanilla-extract-rolldown-plugin` for `bundle.css`) may\n // already own this CSS file and have emitted its shims.\n if (bundle[shimFileName]) continue\n this.emitFile({\n type: 'asset',\n fileName: shimFileName,\n source: cssShimSource(cssFileName),\n })\n this.emitFile({\n type: 'asset',\n fileName: cssShimDtsFileName(cssFileName),\n source: cssShimDtsSource(cssFileName),\n })\n }\n },\n },\n }\n\n function resolvePackageName(): string {\n if (!packageName) {\n throw new Error(\n `[sanity-css-node-compat] Unable to resolve the package name from package.json, which is required by \\`css.exports\\` for the self-referential CSS import. Disable \\`css.exports\\` (or \\`css.inject\\`) to wire up the CSS import yourself.`,\n )\n }\n return packageName\n }\n}\n\n/** The relative import path from a chunk to a CSS file, like the `css.inject` in `@tsdown/css`. */\nfunction relativeImportPath(chunkFileName: string, cssFileName: string): string {\n const relativePath = path.posix.relative(path.posix.dirname(chunkFileName), cssFileName)\n return relativePath.startsWith('.') ? relativePath : `./${relativePath}`\n}\n\n/** Whether a chunk (or any chunk it imports, transitively) contains stylesheet modules. */\nfunction chunkHasStyles(\n chunk: {fileName: string; moduleIds: string[]; imports: string[]; dynamicImports: string[]},\n chunks: Record<\n string,\n {fileName: string; moduleIds: string[]; imports: string[]; dynamicImports: string[]}\n >,\n cssModuleIds: ReadonlySet<string>,\n): boolean {\n const seen = new Set<string>()\n const queue = [chunk]\n for (let current = queue.pop(); current; current = queue.pop()) {\n if (seen.has(current.fileName)) continue\n seen.add(current.fileName)\n if (current.moduleIds.some((id) => cssModuleIds.has(id))) return true\n for (const imported of [...current.imports, ...current.dynamicImports]) {\n const importedChunk = chunks[imported]\n if (importedChunk) queue.push(importedChunk)\n }\n }\n return false\n}\n"],"mappings":"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"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { n as PackageTsdocOptions, r as PackageTsdocRuleLevel, t as PackageTsdocCustomTag } from "./types-CrQ2my_P.mjs";
|
|
1
2
|
import { UserConfig } from "tsdown";
|
|
2
|
-
import { Options } from "@sanity/vanilla-extract-tsdown-plugin";
|
|
3
|
+
import { CssExportsOptions, CssExportsOptions as CssExportsOptions$1, Options } from "@sanity/vanilla-extract-tsdown-plugin";
|
|
3
4
|
import { PluginOptions } from "babel-plugin-react-compiler";
|
|
4
5
|
/**
|
|
5
6
|
* Options for the `vanillaExtract` option — the same options as
|
|
6
7
|
* `@sanity/vanilla-extract-tsdown-plugin` (`identifiers`, `fileName`, `minify`, `target`,
|
|
7
|
-
* `lightningcss`, and `
|
|
8
|
-
* three Sanity-flavored defaults on top:
|
|
8
|
+
* `lightningcss`, `inject`, and `exports`, all modeled after the `css` options of
|
|
9
|
+
* `@tsdown/css`), with three Sanity-flavored defaults on top:
|
|
9
10
|
*
|
|
10
|
-
* - `inject`
|
|
11
|
-
* conditional CSS export pattern that Sanity libraries ship
|
|
12
|
-
* plain
|
|
11
|
+
* - `inject` and `exports` default to `true` and `{nodeCompat: true}` (instead of the plugin's
|
|
12
|
+
* `false` for both), wiring up the conditional CSS export pattern that Sanity libraries ship
|
|
13
|
+
* with. Set `exports: true` for a plain (browser-only) CSS export, `exports: false` for a
|
|
14
|
+
* relative CSS import, or `inject: false` to only extract the CSS.
|
|
13
15
|
* - `minify` defaults to `true` (instead of the plugin's `false`, which matches `css.minify`
|
|
14
16
|
* in `@tsdown/css`): published Sanity libraries ship minified CSS. Set `minify: false` for
|
|
15
17
|
* readable output.
|
|
@@ -22,6 +24,45 @@ import { PluginOptions } from "babel-plugin-react-compiler";
|
|
|
22
24
|
* @public
|
|
23
25
|
*/
|
|
24
26
|
type PackageVanillaExtractOptions = Options;
|
|
27
|
+
/**
|
|
28
|
+
* Options for the `css` option — tsdown's experimental
|
|
29
|
+
* [`css` options](https://tsdown.dev/options/css) from `@tsdown/css` (`splitting`, `fileName`,
|
|
30
|
+
* `target`, `minify`, `lightningcss`, `postcss`, `modules`, `preprocessorOptions`,
|
|
31
|
+
* `transformer`, `inject`), plus an `exports` option this config implements on top, with two
|
|
32
|
+
* Sanity-flavored defaults:
|
|
33
|
+
*
|
|
34
|
+
* - `exports` defaults to `{nodeCompat: true}`, wiring up the conditional CSS export pattern:
|
|
35
|
+
* the self-referential `import "<pkg>/style.css"`, a no-op `style-css.js` shim with a
|
|
36
|
+
* `style-css.d.ts` declaration, and the conditional `"./style.css"` export written to
|
|
37
|
+
* `package.json`. `@tsdown/css` has no equivalent — its `inject` emits a relative
|
|
38
|
+
* `import "./style.css"`, which throws in runtimes that cannot load `.css` files. Set
|
|
39
|
+
* `exports: true` for a plain (browser-only) CSS export, or `exports: false` to fall back to
|
|
40
|
+
* `@tsdown/css`'s relative injection.
|
|
41
|
+
* - `minify` defaults to `true` (instead of `@tsdown/css`'s `false`): published Sanity
|
|
42
|
+
* libraries ship minified CSS. Set `minify: false` for readable output.
|
|
43
|
+
*
|
|
44
|
+
* The CSS syntax lowering target resolves exactly like
|
|
45
|
+
* {@link PackageVanillaExtractOptions | `vanillaExtract`}'s: browserless targets fall back to
|
|
46
|
+
* `@sanity/browserslist-config` through `lightningcss.targets`.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
type PackageCssOptions = NonNullable<UserConfig["css"]> & {
|
|
50
|
+
/**
|
|
51
|
+
* Publish each emitted CSS file as an export subpath of the package, so consumers can
|
|
52
|
+
* `import "<pkg-name>/style.css"` — which is also the specifier `inject` then uses, instead
|
|
53
|
+
* of `@tsdown/css`'s relative path.
|
|
54
|
+
*
|
|
55
|
+
* - `true` declares a plain `"./style.css": "./dist/style.css"` export. Enough for packages
|
|
56
|
+
* that only ever run in browsers or bundlers.
|
|
57
|
+
* - `{nodeCompat: true}` declares a conditional export instead, whose `browser`/`style`
|
|
58
|
+
* conditions point at the stylesheet while `node`/`default` point at a no-op JS shim
|
|
59
|
+
* emitted next to it, with a declaration file for the export's `types` condition. That
|
|
60
|
+
* keeps the subpath resolvable in runtimes that cannot load `.css` files.
|
|
61
|
+
*
|
|
62
|
+
* @defaultValue `{nodeCompat: true}`
|
|
63
|
+
*/
|
|
64
|
+
exports?: boolean | CssExportsOptions$1;
|
|
65
|
+
};
|
|
25
66
|
/**
|
|
26
67
|
* Options for the `styled-components` transform, the same options as `babel-plugin-styled-components`.
|
|
27
68
|
* @public
|
|
@@ -173,14 +214,23 @@ interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format
|
|
|
173
214
|
deps?: UserConfig["deps"];
|
|
174
215
|
/**
|
|
175
216
|
* tsdown's experimental [`css` option](https://tsdown.dev/options/css) (CSS modules,
|
|
176
|
-
* preprocessors, Lightning CSS / PostCSS, inject, etc)
|
|
217
|
+
* preprocessors, Lightning CSS / PostCSS, inject, etc), with Sanity-flavored defaults and an
|
|
218
|
+
* added `exports` option — requires
|
|
177
219
|
* [`@tsdown/css`](https://www.npmjs.com/package/@tsdown/css) to be installed in the project.
|
|
220
|
+
*
|
|
221
|
+
* By default (`exports: {nodeCompat: true}`, `minify: true`) the emitted CSS gets the same
|
|
222
|
+
* conditional CSS export treatment as {@link PackageOptions.vanillaExtract}: the
|
|
223
|
+
* self-referential `import "<pkg>/style.css"`, a no-op `style-css.js` shim with its
|
|
224
|
+
* `style-css.d.ts` declaration, and the conditional `"./style.css"` export written to
|
|
225
|
+
* `package.json` — see {@link PackageCssOptions}.
|
|
226
|
+
*
|
|
178
227
|
* Safe to combine with {@link PackageOptions.vanillaExtract}: vanilla-extract extracts into
|
|
179
228
|
* `bundle.css` by default, while `@tsdown/css` merges other CSS (including `.module.css`)
|
|
180
229
|
* into `style.css`, so the two pipelines do not collide.
|
|
181
230
|
* @see https://tsdown.dev/reference/api/Interface.InlineConfig#css
|
|
231
|
+
* @alpha
|
|
182
232
|
*/
|
|
183
|
-
css?:
|
|
233
|
+
css?: PackageCssOptions;
|
|
184
234
|
/**
|
|
185
235
|
* Runs `babel-plugin-react-compiler` on the source files before they are bundled, so published
|
|
186
236
|
* components are memoized automatically. Pass `true` to use the defaults, or an options object
|
|
@@ -212,16 +262,46 @@ interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format
|
|
|
212
262
|
* `@sanity/browserslist-config` instead — see {@link PackageVanillaExtractOptions}. Pass
|
|
213
263
|
* `true` to use the defaults, or an object to customize.
|
|
214
264
|
*
|
|
215
|
-
* By default (`inject: {nodeCompat: true}`) the plugin also injects the
|
|
216
|
-
* `import "<pkg>/bundle.css"`, emits a `bundle-css.js` shim, and writes the
|
|
217
|
-
* `"./bundle.css"` export to `package.json` - see
|
|
218
|
-
* This is the same feature as `rollup.vanillaExtract`
|
|
265
|
+
* By default (`inject: true` with `exports: {nodeCompat: true}`) the plugin also injects the
|
|
266
|
+
* self-referential `import "<pkg>/bundle.css"`, emits a `bundle-css.js` shim, and writes the
|
|
267
|
+
* conditional `"./bundle.css"` export to `package.json` - see
|
|
268
|
+
* {@link PackageVanillaExtractOptions}. This is the same feature as `rollup.vanillaExtract`
|
|
269
|
+
* in `@sanity/pkg-utils`.
|
|
219
270
|
*
|
|
220
271
|
* Combines with {@link PackageOptions.css}: enable both when a package uses vanilla-extract
|
|
221
272
|
* alongside CSS modules (or other `@tsdown/css` features).
|
|
222
273
|
* @alpha
|
|
223
274
|
*/
|
|
224
275
|
vanillaExtract?: boolean | PackageVanillaExtractOptions;
|
|
276
|
+
/**
|
|
277
|
+
* Runs `@microsoft/api-extractor` after the build (via tsdown's `build:done` hook) to check
|
|
278
|
+
* that TSDoc tags are valid and release tags are correct. Useful for packages consumed by
|
|
279
|
+
* TSDoc-based tooling. Off by default — set `tsdoc: true` to enable, or pass an options
|
|
280
|
+
* object to customize rules and custom tags.
|
|
281
|
+
* @defaultValue false
|
|
282
|
+
*/
|
|
283
|
+
tsdoc?: boolean | PackageTsdocOptions;
|
|
284
|
+
/**
|
|
285
|
+
* tsdown's `suppressWarnings` option: strings (matched with `includes`), regular expressions
|
|
286
|
+
* (matched with `test`), or a predicate that drop build warnings before they're printed — and
|
|
287
|
+
* before `failOnWarn` turns them into errors.
|
|
288
|
+
*
|
|
289
|
+
* Userland values are **added to** the built-in suppression instead of replacing it (which
|
|
290
|
+
* `mergeConfig` would do, since it replaces functions): per-package suppressions can't
|
|
291
|
+
* accidentally undo the declaration-only circular-dependency filter that this config pairs
|
|
292
|
+
* with its `checks.circularDependency` default. This config always suppresses
|
|
293
|
+
* `CIRCULAR_DEPENDENCY` warnings whose entire cycle consists of declaration files
|
|
294
|
+
* (`.d.ts`/`.d.mts`/`.d.cts`) — those come from the declaration bundling pass, where every
|
|
295
|
+
* import is type-only and erased at runtime, so the cycles are harmless and unavoidable for
|
|
296
|
+
* mutually referencing public types (e.g. the schema definition types in `@sanity/types`).
|
|
297
|
+
* Cycles involving a runtime module still warn.
|
|
298
|
+
*
|
|
299
|
+
* To drop the built-in suppression instead of adding to it, merge over the returned config —
|
|
300
|
+
* `mergeConfig(await defineConfig(), {suppressWarnings: () => false})` restores every
|
|
301
|
+
* warning, including the declaration-only cycles.
|
|
302
|
+
* @defaultValue undefined — only the built-in declaration-only cycle suppression applies
|
|
303
|
+
*/
|
|
304
|
+
suppressWarnings?: UserConfig["suppressWarnings"];
|
|
225
305
|
}
|
|
226
306
|
/**
|
|
227
307
|
* With `reactCompiler.reactServer` the config resolves to two tsdown configs: the compiled
|
|
@@ -255,5 +335,5 @@ declare function defineConfig(options: PackageOptions & {
|
|
|
255
335
|
* @public
|
|
256
336
|
*/
|
|
257
337
|
declare function defineConfig(options?: PackageOptions): Promise<UserConfig>;
|
|
258
|
-
export { PackageOptions, PackageVanillaExtractOptions, ReactCompilerOptions, StyledComponentsOptions, defineConfig };
|
|
338
|
+
export { type CssExportsOptions, PackageCssOptions, PackageOptions, type PackageTsdocCustomTag, type PackageTsdocOptions, type PackageTsdocRuleLevel, PackageVanillaExtractOptions, ReactCompilerOptions, StyledComponentsOptions, defineConfig };
|
|
259
339
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;KAoDY,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;KAwB/B,oBAAoB,YAAY;;;;;;;;;;;;;;;EAe1C,oBAAoB;;;;;;UAOL;;EAEf;;;;;EAKA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;;;;;;;;;;;;;KAcU,uBAAuB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BzC;;;;;UAMe,uBAAuB,KACtC;;;;;;;;;;;;;EAeA,WAAW;;;;;;;;;;;EAWX,MAAM;;;;;;;;;;;;;;;;;;;EAmBN,QAAQ;;;;;;;;;;;;;;;;;;;;;EAqBR,UAAU;;;;;;;EAOV,YAAY;;;;;;EAMZ,OAAO;;;;;;;;;;;;;;;;;;;EAmBP,MAAM;;;;;;;;;;;;;;;EAeN,0BAA0B;;;;;;;;EAQ1B,6BAA6B;;;;;;;;;;;;;;;;;;;EAmB7B,2BAA2B;;;;;;;;EAQ3B,kBAAkB;;;;;;;;;;;;;;;;;;;;;EAqBlB,mBAAmB;;;;;;;iBAQL,aACd,SAAS;EAAkB,eAAe;IAAwB;;IACjE,QAAQ;;;;;iBAKK,aACd,SAAS;EAAkB,eAAe;IAAwB;;IACjE,QAAQ;;;;;;;iBAOK,aACd,SAAS;EAAkB,eAAe;IACzC,QAAQ,aAAa;;;;iBAIR,aAAa,UAAU,iBAAiB,QAAQ"}
|