@sanity/tsdown-config 0.14.2 → 0.16.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 +51 -0
- package/dist/index.d.mts +23 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +8 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -132,6 +132,20 @@ export default defineConfig({
|
|
|
132
132
|
})
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
## outDir
|
|
136
|
+
|
|
137
|
+
tsdown's [`outDir` option](https://tsdown.dev/options/output#outdir) is passed through as-is.
|
|
138
|
+
When left undefined, tsdown writes to `dist` (the same default as `@sanity/pkg-utils`):
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
142
|
+
|
|
143
|
+
export default defineConfig({
|
|
144
|
+
tsconfig: 'tsconfig.dist.json',
|
|
145
|
+
outDir: 'lib',
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
135
149
|
## Isolated declarations
|
|
136
150
|
|
|
137
151
|
If you're using the [`@sanity/tsconfig/isolated-declarations`](https://github.com/sanity-io/pkg-utils/tree/main/packages/%40sanity/tsconfig#isolated-declarations-tsconfigjson)
|
|
@@ -178,6 +192,43 @@ export default defineConfig({
|
|
|
178
192
|
})
|
|
179
193
|
```
|
|
180
194
|
|
|
195
|
+
## sourcemap
|
|
196
|
+
|
|
197
|
+
tsdown's [`sourcemap` option](https://tsdown.dev/options/output#sourcemap) is forwarded with a
|
|
198
|
+
`true` default (the same as `@sanity/pkg-utils`). tsdown itself defaults to `false` and does not
|
|
199
|
+
read `sourceMap` from the tsconfig:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
203
|
+
|
|
204
|
+
export default defineConfig({
|
|
205
|
+
tsconfig: 'tsconfig.dist.json',
|
|
206
|
+
sourcemap: false,
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## deps
|
|
211
|
+
|
|
212
|
+
tsdown's [`deps` option](https://tsdown.dev/options/dependencies) is forwarded. When `platform` is
|
|
213
|
+
`'neutral'` (the default), `neverBundle` always includes `/^node:/` so node built-ins stay
|
|
214
|
+
external, and userland `neverBundle` entries are appended rather than replacing that default
|
|
215
|
+
(tsdown's `mergeConfig` would replace the array):
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
import {defineConfig} from '@sanity/tsdown-config'
|
|
219
|
+
|
|
220
|
+
export default defineConfig({
|
|
221
|
+
tsconfig: 'tsconfig.dist.json',
|
|
222
|
+
// Resulting neverBundle: [/^node:/, /^my-package(\/|$)/]
|
|
223
|
+
deps: {neverBundle: [/^my-package(\/|$)/]},
|
|
224
|
+
})
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`'neutral'` also restores `inputOptions.resolve.mainFields: ['module', 'main']` for inlined
|
|
228
|
+
dependencies that ship no `exports` map. Prefer it over `'node'` for packages that also run in
|
|
229
|
+
the browser - `'node'` makes CommonJS-interop emit a module-scope
|
|
230
|
+
`createRequire(import.meta.url)` for inlined CJS deps, which crashes browser-bundled consumers.
|
|
231
|
+
|
|
181
232
|
## target
|
|
182
233
|
|
|
183
234
|
tsdown's [`target` option](https://tsdown.dev/options/target) is also passed through as-is. It
|
package/dist/index.d.mts
CHANGED
|
@@ -48,9 +48,18 @@ type ReactCompilerOptions = Partial<PluginOptions>;
|
|
|
48
48
|
/**
|
|
49
49
|
* @public
|
|
50
50
|
*/
|
|
51
|
-
interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format" | "dts" | "define" | "target"> {
|
|
51
|
+
interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format" | "dts" | "define" | "target" | "outDir"> {
|
|
52
52
|
/**
|
|
53
53
|
* @defaultValue 'neutral'
|
|
54
|
+
*
|
|
55
|
+
* When left at `'neutral'` (the default), two resolution tweaks compensate for rolldown's
|
|
56
|
+
* strict neutral defaults: `deps.neverBundle` includes `/^node:/` (node built-ins stay external
|
|
57
|
+
* so neutral does not warn about them as unresolvable; only node runtimes execute those code
|
|
58
|
+
* paths), and `inputOptions.resolve.mainFields` falls back to `['module', 'main']` for inlined
|
|
59
|
+
* dependencies that ship no `exports` map (e.g. `rxjs-etc/operators`). Prefer `'neutral'` over
|
|
60
|
+
* `'node'` for packages that also run in the browser - `'node'` makes CommonJS-interop emit a
|
|
61
|
+
* module-scope `createRequire(import.meta.url)` for inlined CJS deps, which crashes
|
|
62
|
+
* browser-bundled consumers.
|
|
54
63
|
*/
|
|
55
64
|
platform?: UserConfig["platform"];
|
|
56
65
|
/**
|
|
@@ -68,6 +77,19 @@ interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format
|
|
|
68
77
|
* `{enabled: 'local-only'}` otherwise.
|
|
69
78
|
*/
|
|
70
79
|
exports?: UserConfig["exports"];
|
|
80
|
+
/**
|
|
81
|
+
* Whether to generate source map files. The same default as the `sourcemap` option in
|
|
82
|
+
* `@sanity/pkg-utils` - tsdown itself defaults to `false` and does not read `sourceMap` from
|
|
83
|
+
* the tsconfig.
|
|
84
|
+
* @defaultValue true
|
|
85
|
+
*/
|
|
86
|
+
sourcemap?: UserConfig["sourcemap"];
|
|
87
|
+
/**
|
|
88
|
+
* tsdown's `deps` option. When `platform` is `'neutral'` (the default), `neverBundle` always
|
|
89
|
+
* includes `/^node:/` and userland `neverBundle` entries are appended (tsdown's `mergeConfig`
|
|
90
|
+
* would replace the array). Other `deps` fields pass through as-is.
|
|
91
|
+
*/
|
|
92
|
+
deps?: UserConfig["deps"];
|
|
71
93
|
/**
|
|
72
94
|
* Runs `babel-plugin-react-compiler` on the source files before they are bundled, so published
|
|
73
95
|
* components are memoized automatically. Pass `true` to use the defaults, or an options object
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;KAmBY,+BAA+B;;;;;UAM1B;;EAEf;;;;;EAKA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;;;;;;;;;KAUU,uBAAuB,QAAQ;;;;UAK1B,uBAAuB,KACtC
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;KAmBY,+BAA+B;;;;;UAM1B;;EAEf;;;;;EAKA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA;;;;;;;;;KAUU,uBAAuB,QAAQ;;;;UAK1B,uBAAuB,KACtC;;;;;;;;;;;;;EAeA,WAAW;;;;;;;;;;;;;;;EAeX,UAAU;;;;;;;EAOV,YAAY;;;;;;EAMZ,OAAO;;;;;;;;;;EAUP,0BAA0B;;;;;;;;EAQ1B,6BAA6B;;;;;;;;;;;EAW7B,2BAA2B;;;;;iBAMP,aAAa,UAAS,iBAAsB,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -4,9 +4,10 @@ import { defineConfig as defineConfig$1, mergeConfig } from "tsdown";
|
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
async function defineConfig(options = {}) {
|
|
7
|
-
let { entry, tsconfig, dts, define, target } = options, platform = options.platform ?? "neutral", reactCompiler = options.reactCompiler ?? !1, styledComponents = options.styledComponents ?? !1, report = { gzip: !1 }, format = options.format ?? "esm", inputOptions = {
|
|
7
|
+
let { entry, tsconfig, dts, define, target, outDir } = options, platform = options.platform ?? "neutral", sourcemap = options.sourcemap ?? !0, reactCompiler = options.reactCompiler ?? !1, styledComponents = options.styledComponents ?? !1, report = { gzip: !1 }, format = options.format ?? "esm", inputOptions = {
|
|
8
8
|
preserveEntrySignatures: "strict",
|
|
9
9
|
experimental: { attachDebugInfo: "none" },
|
|
10
|
+
...platform === "neutral" && { resolve: { mainFields: ["module", "main"] } },
|
|
10
11
|
...styledComponents !== !1 && { transform: { plugins: { styledComponents: {
|
|
11
12
|
fileName: !1,
|
|
12
13
|
transpileTemplateLiterals: !1,
|
|
@@ -14,6 +15,9 @@ async function defineConfig(options = {}) {
|
|
|
14
15
|
cssProp: !1,
|
|
15
16
|
...typeof styledComponents == "object" ? styledComponents : {}
|
|
16
17
|
} } } }
|
|
18
|
+
}, userNeverBundle = options.deps?.neverBundle, nodeBuiltinExternal = platform === "neutral" ? /^node:/ : void 0, neverBundle = userNeverBundle == null ? nodeBuiltinExternal && [nodeBuiltinExternal] : nodeBuiltinExternal == null ? userNeverBundle : typeof userNeverBundle == "function" ? (id, importer, isResolved) => nodeBuiltinExternal.test(id) || userNeverBundle(id, importer, isResolved) : [nodeBuiltinExternal, ...Array.isArray(userNeverBundle) ? userNeverBundle : [userNeverBundle]], deps = options.deps === void 0 && neverBundle === void 0 ? void 0 : {
|
|
19
|
+
...options.deps,
|
|
20
|
+
...neverBundle === void 0 ? {} : { neverBundle }
|
|
17
21
|
}, plugins = [];
|
|
18
22
|
if (reactCompiler !== !1) {
|
|
19
23
|
let [{ default: pluginBabel }, { reactCompilerPreset }] = await Promise.all([import("@rolldown/plugin-babel"), import("@vitejs/plugin-react")]);
|
|
@@ -32,15 +36,18 @@ async function defineConfig(options = {}) {
|
|
|
32
36
|
} }, { exports: options.exports });
|
|
33
37
|
return defineConfig$1({
|
|
34
38
|
define,
|
|
39
|
+
deps,
|
|
35
40
|
dts,
|
|
36
41
|
entry,
|
|
37
42
|
exports,
|
|
38
43
|
format,
|
|
39
44
|
inputOptions,
|
|
45
|
+
outDir,
|
|
40
46
|
platform,
|
|
41
47
|
plugins,
|
|
42
48
|
publint: !0,
|
|
43
49
|
report,
|
|
50
|
+
sourcemap,
|
|
44
51
|
target,
|
|
45
52
|
tsconfig,
|
|
46
53
|
minify: {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["defineTsdownConfig"],"sources":["../src/index.ts"],"sourcesContent":["import type {Options as VanillaExtractPluginOptions} from '@sanity/vanilla-extract-tsdown-plugin'\nimport type {PluginOptions as ReactCompilerPluginOptions} from 'babel-plugin-react-compiler'\nimport {detect} from 'package-manager-detector/detect'\nimport {\n defineConfig as defineTsdownConfig,\n mergeConfig,\n type Rolldown,\n type UserConfig,\n} from 'tsdown'\n\n/**\n * Options for the `vanillaExtract` option — the same options as\n * `@sanity/vanilla-extract-tsdown-plugin` (`identifiers`, `fileName`, `minify`, `target`, and\n * `inject`, all modeled after the `css` options of `@tsdown/css`), with one different default:\n * `inject` defaults to `{nodeCompat: true}` (instead of the plugin's `false`), wiring up the\n * conditional CSS export pattern that Sanity libraries ship with. Set `inject: true` for a plain\n * relative CSS import, or `inject: false` to only extract the CSS.\n * @public\n */\nexport type PackageVanillaExtractOptions = VanillaExtractPluginOptions\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 * Options for the React Compiler, the same options as `babel-plugin-react-compiler`.\n * The typings resolve in userland once `babel-plugin-react-compiler` (an optional peer\n * dependency, required to use `reactCompiler`) is installed, and always match the installed\n * version of the compiler.\n * @public\n */\nexport type ReactCompilerOptions = Partial<ReactCompilerPluginOptions>\n\n/**\n * @public\n */\nexport interface PackageOptions extends Pick<\n UserConfig,\n 'tsconfig' | 'entry' | 'format' | 'dts' | 'define' | 'target'\n> {\n /**\n * @defaultValue 'neutral'\n */\n platform?: UserConfig['platform']\n /**\n * tsdown's `exports` option, with defaults suited for publishing Sanity libraries:\n * `enabled: 'local-only'` generates the `exports` map during local builds and skips it in CI\n * (where the committed `package.json` is already up to date). When pnpm is detected,\n * `devExports: true` also keeps the local `exports` map pointing at source files while\n * `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 * @defaultValue `{enabled: 'local-only', devExports: true}` for pnpm projects;\n * `{enabled: 'local-only'}` otherwise.\n */\n exports?: UserConfig['exports']\n /**\n * Runs `babel-plugin-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 object\n * to configure the compiler (e.g. `{target: '18'}`).\n * This is the same feature as the `babel: {reactCompiler: true}` and `reactCompilerOptions`\n * options in `@sanity/pkg-utils`. Unlike `styledComponents` there's no oxc native port of the\n * React Compiler yet, so `babel-plugin-react-compiler` needs to be installed.\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,\n * `lightningcss`-optimized file. Pass `true` to use the defaults, or an object to customize.\n *\n * By default (`inject: {nodeCompat: true}`) the plugin also injects the self-referential\n * `import \"<pkg>/bundle.css\"`, emits a `bundle.css.js` shim, and writes the conditional\n * `\"./bundle.css\"` export to `package.json` - see {@link PackageVanillaExtractOptions}.\n * This is the same feature as `rollup.vanillaExtract` in `@sanity/pkg-utils`.\n * @alpha\n */\n vanillaExtract?: boolean | PackageVanillaExtractOptions\n}\n\n/**\n * @public\n */\nexport async function defineConfig(options: PackageOptions = {}): Promise<UserConfig> {\n // `tsconfig`, `entry`, `dts`, `define` and `target` are passed through to tsdown as-is. When\n // left undefined, tsdown keeps its default behavior (`tsconfig` is auto-detected from the\n // project, `dts` from `package.json`, `define` replaces nothing, and `target` applies no\n // syntax downleveling).\n const {entry, tsconfig, dts, define, target} = options\n const platform = options.platform ?? 'neutral'\n const reactCompiler = options.reactCompiler ?? false\n const styledComponents = options.styledComponents ?? false\n const report = {gzip: false} as const satisfies UserConfig['report']\n const publint = true\n const format = options.format ?? 'esm'\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 ...(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 } as const satisfies UserConfig['inputOptions']\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 // Follows the official tsdown recipe for the React Compiler:\n // https://tsdown.dev/recipes/react-support#enabling-react-compiler\n // The plugins are lazy loaded so they're only paid for when the React Compiler is enabled.\n // `babel-plugin-react-compiler` itself is resolved by Babel from the consumer package during\n // the build, which is why it can be an optional peer dependency. Once rolldown ships its rust\n // port of the React Compiler this can be swapped out for an oxc transform, like `styledComponents`.\n const [{default: pluginBabel}, {reactCompilerPreset}] = await Promise.all([\n import('@rolldown/plugin-babel'),\n import('@vitejs/plugin-react'),\n ])\n plugins.push(\n await pluginBabel({\n presets: [reactCompilerPreset(typeof reactCompiler === 'object' ? reactCompiler : {})],\n }),\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\n // `lightningcss`-optimized file. Its `inject` option is general purpose (and, like\n // `css.inject` in `@tsdown/css`, disabled by default), so this config supplies the default\n // most Sanity libraries want: `{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} = await import('@sanity/vanilla-extract-tsdown-plugin')\n plugins.push(\n vanillaExtractPlugin({\n inject: {nodeCompat: true},\n ...(options.vanillaExtract === true ? {} : options.vanillaExtract),\n }),\n )\n }\n\n const packageManager = await detect({cwd: process.cwd()})\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 const {exports} = mergeConfig(\n {\n exports: {\n enabled: 'local-only',\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: options.exports},\n )\n\n return defineTsdownConfig({\n define,\n dts,\n entry,\n exports,\n format,\n inputOptions,\n platform,\n plugins,\n publint,\n report,\n target,\n tsconfig,\n minify: {compress: true, codegen: false, mangle: false},\n })\n}\n"],"mappings":";;;;;AAqHA,eAAsB,aAAa,UAA0B,CAAC,GAAwB;CAKpF,IAAM,EAAC,OAAO,UAAU,KAAK,QAAQ,WAAU,SACzC,WAAW,QAAQ,YAAY,WAC/B,gBAAgB,QAAQ,iBAAiB,IACzC,mBAAmB,QAAQ,oBAAoB,IAC/C,SAAS,EAAC,MAAM,GAAK,GAErB,SAAS,QAAQ,UAAU,OAC3B,eAAe;EAEnB,yBAAyB;EACzB,cAAc,EAAC,iBAAiB,OAAM;EACtC,GAAI,qBAAqB,MAAS,EAChC,WAAW,EACT,SAAS,EACP,kBAAkB;GAIhB,UAAU;GAIV,2BAA2B;GAG3B,MAAM;GAGN,SAAS;GACT,GAAI,OAAO,oBAAqB,WAAW,mBAAmB,CAAC;EACjE,EACF,EACF,EACF;CACF,GAKM,UAA6B,CAAC;CACpC,IAAI,kBAAkB,IAAO;EAO3B,IAAM,CAAC,EAAC,SAAS,eAAc,EAAC,yBAAwB,MAAM,QAAQ,IAAI,CACxE,OAAO,2BACP,OAAO,uBACT,CAAC;EACD,QAAQ,KACN,MAAM,YAAY,EAChB,SAAS,CAAC,oBAAoB,OAAO,iBAAkB,WAAW,gBAAgB,CAAC,CAAC,CAAC,EACvF,CAAC,CACH;CACF;CACA,IAAI,QAAQ,gBAAgB;EAS1B,IAAM,EAAC,yBAAwB,MAAM,OAAO;EAC5C,QAAQ,KACN,qBAAqB;GACnB,QAAQ,EAAC,YAAY,GAAI;GACzB,GAAI,QAAQ,mBAAmB,KAAO,CAAC,IAAI,QAAQ;EACrD,CAAC,CACH;CACF;CAMA,IAAM,EAAC,YAAW,YAChB,EACE,SAAS;EACP,SAAS;EAGT,IAAI,MAVmB,OAAO,EAAC,KAAK,QAAQ,IAAI,EAAC,CAAC,EAAA,EAU9B,SAAS,UAAU,EAAC,YAAY,GAAI;CAC1D,EACF,GACA,EAAC,SAAS,QAAQ,QAAO,CAC3B;CAEA,OAAOA,eAAmB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ;GAAC,UAAU;GAAM,SAAS;GAAO,QAAQ;EAAK;CACxD,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["defineTsdownConfig"],"sources":["../src/index.ts"],"sourcesContent":["import type {Options as VanillaExtractPluginOptions} from '@sanity/vanilla-extract-tsdown-plugin'\nimport type {PluginOptions as ReactCompilerPluginOptions} from 'babel-plugin-react-compiler'\nimport {detect} from 'package-manager-detector/detect'\nimport {\n defineConfig as defineTsdownConfig,\n mergeConfig,\n type Rolldown,\n type UserConfig,\n} from 'tsdown'\n\n/**\n * Options for the `vanillaExtract` option — the same options as\n * `@sanity/vanilla-extract-tsdown-plugin` (`identifiers`, `fileName`, `minify`, `target`, and\n * `inject`, all modeled after the `css` options of `@tsdown/css`), with one different default:\n * `inject` defaults to `{nodeCompat: true}` (instead of the plugin's `false`), wiring up the\n * conditional CSS export pattern that Sanity libraries ship with. Set `inject: true` for a plain\n * relative CSS import, or `inject: false` to only extract the CSS.\n * @public\n */\nexport type PackageVanillaExtractOptions = VanillaExtractPluginOptions\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 * Options for the React Compiler, the same options as `babel-plugin-react-compiler`.\n * The typings resolve in userland once `babel-plugin-react-compiler` (an optional peer\n * dependency, required to use `reactCompiler`) is installed, and always match the installed\n * version of the compiler.\n * @public\n */\nexport type ReactCompilerOptions = Partial<ReactCompilerPluginOptions>\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 * tsdown's `exports` option, with defaults suited for publishing Sanity libraries:\n * `enabled: 'local-only'` generates the `exports` map during local builds and skips it in CI\n * (where the committed `package.json` is already up to date). When pnpm is detected,\n * `devExports: true` also keeps the local `exports` map pointing at source files while\n * `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 * @defaultValue `{enabled: 'local-only', devExports: true}` for pnpm projects;\n * `{enabled: 'local-only'}` 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 * Runs `babel-plugin-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 object\n * to configure the compiler (e.g. `{target: '18'}`).\n * This is the same feature as the `babel: {reactCompiler: true}` and `reactCompilerOptions`\n * options in `@sanity/pkg-utils`. Unlike `styledComponents` there's no oxc native port of the\n * React Compiler yet, so `babel-plugin-react-compiler` needs to be installed.\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,\n * `lightningcss`-optimized file. Pass `true` to use the defaults, or an object to customize.\n *\n * By default (`inject: {nodeCompat: true}`) the plugin also injects the self-referential\n * `import \"<pkg>/bundle.css\"`, emits a `bundle.css.js` shim, and writes the conditional\n * `\"./bundle.css\"` export to `package.json` - see {@link PackageVanillaExtractOptions}.\n * This is the same feature as `rollup.vanillaExtract` in `@sanity/pkg-utils`.\n * @alpha\n */\n vanillaExtract?: boolean | PackageVanillaExtractOptions\n}\n\n/**\n * @public\n */\nexport async function defineConfig(options: PackageOptions = {}): Promise<UserConfig> {\n // `tsconfig`, `entry`, `dts`, `define`, `target` and `outDir` are passed through to tsdown\n // as-is. When left undefined, tsdown keeps its default behavior (`tsconfig` is auto-detected\n // from the project, `dts` from `package.json`, `define` replaces nothing, `target` applies no\n // syntax downleveling, and `outDir` defaults to `'dist'`).\n const {entry, tsconfig, dts, define, target, outDir} = options\n const platform = options.platform ?? 'neutral'\n const sourcemap = options.sourcemap ?? true\n const reactCompiler = options.reactCompiler ?? false\n const styledComponents = options.styledComponents ?? false\n const report = {gzip: false} as const satisfies UserConfig['report']\n const publint = true\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\n ? userNeverBundle\n : typeof userNeverBundle === 'function'\n ? (id, importer, isResolved) =>\n nodeBuiltinExternal.test(id) || userNeverBundle(id, importer, isResolved)\n : [\n nodeBuiltinExternal,\n ...(Array.isArray(userNeverBundle) ? userNeverBundle : [userNeverBundle]),\n ]\n const deps: UserConfig['deps'] =\n options.deps === undefined && neverBundle === undefined\n ? undefined\n : {\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 // Follows the official tsdown recipe for the React Compiler:\n // https://tsdown.dev/recipes/react-support#enabling-react-compiler\n // The plugins are lazy loaded so they're only paid for when the React Compiler is enabled.\n // `babel-plugin-react-compiler` itself is resolved by Babel from the consumer package during\n // the build, which is why it can be an optional peer dependency. Once rolldown ships its rust\n // port of the React Compiler this can be swapped out for an oxc transform, like `styledComponents`.\n const [{default: pluginBabel}, {reactCompilerPreset}] = await Promise.all([\n import('@rolldown/plugin-babel'),\n import('@vitejs/plugin-react'),\n ])\n plugins.push(\n await pluginBabel({\n presets: [reactCompilerPreset(typeof reactCompiler === 'object' ? reactCompiler : {})],\n }),\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\n // `lightningcss`-optimized file. Its `inject` option is general purpose (and, like\n // `css.inject` in `@tsdown/css`, disabled by default), so this config supplies the default\n // most Sanity libraries want: `{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} = await import('@sanity/vanilla-extract-tsdown-plugin')\n plugins.push(\n vanillaExtractPlugin({\n inject: {nodeCompat: true},\n ...(options.vanillaExtract === true ? {} : options.vanillaExtract),\n }),\n )\n }\n\n const packageManager = await detect({cwd: process.cwd()})\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 const {exports} = mergeConfig(\n {\n exports: {\n enabled: 'local-only',\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: options.exports},\n )\n\n return defineTsdownConfig({\n define,\n deps,\n dts,\n entry,\n exports,\n format,\n inputOptions,\n outDir,\n platform,\n plugins,\n publint,\n report,\n sourcemap,\n target,\n tsconfig,\n minify: {compress: true, codegen: false, mangle: false},\n })\n}\n"],"mappings":";;;;;AA2IA,eAAsB,aAAa,UAA0B,CAAC,GAAwB;CAKpF,IAAM,EAAC,OAAO,UAAU,KAAK,QAAQ,QAAQ,WAAU,SACjD,WAAW,QAAQ,YAAY,WAC/B,YAAY,QAAQ,aAAa,IACjC,gBAAgB,QAAQ,iBAAiB,IACzC,mBAAmB,QAAQ,oBAAoB,IAC/C,SAAS,EAAC,MAAM,GAAK,GAErB,SAAS,QAAQ,UAAU,OAG3B,eAAe;EAEnB,yBAAyB;EACzB,cAAc,EAAC,iBAAiB,OAAM;EACtC,GAAI,aAAa,aAAa,EAC5B,SAAS,EAAC,YAAY,CAAC,UAAU,MAAM,EAAC,EAC1C;EACA,GAAI,qBAAqB,MAAS,EAChC,WAAW,EACT,SAAS,EACP,kBAAkB;GAIhB,UAAU;GAIV,2BAA2B;GAG3B,MAAM;GAGN,SAAS;GACT,GAAI,OAAO,oBAAqB,WAAW,mBAAmB,CAAC;EACjE,EACF,EACF,EACF;CACF,GAKM,kBAAkB,QAAQ,MAAM,aAChC,sBAAsB,aAAa,YAAY,WAAW,KAAA,GAC1D,cACJ,mBAAmB,OACf,uBAAuB,CAAC,mBAAmB,IAC3C,uBAAuB,OACrB,kBACA,OAAO,mBAAoB,cACxB,IAAI,UAAU,eACb,oBAAoB,KAAK,EAAE,KAAK,gBAAgB,IAAI,UAAU,UAAU,IAC1E,CACE,qBACA,GAAI,MAAM,QAAQ,eAAe,IAAI,kBAAkB,CAAC,eAAe,CACzE,GACJ,OACJ,QAAQ,SAAS,KAAA,KAAa,gBAAgB,KAAA,IAC1C,KAAA,IACA;EACE,GAAG,QAAQ;EACX,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAC,YAAW;CACnD,GAKA,UAA6B,CAAC;CACpC,IAAI,kBAAkB,IAAO;EAO3B,IAAM,CAAC,EAAC,SAAS,eAAc,EAAC,yBAAwB,MAAM,QAAQ,IAAI,CACxE,OAAO,2BACP,OAAO,uBACT,CAAC;EACD,QAAQ,KACN,MAAM,YAAY,EAChB,SAAS,CAAC,oBAAoB,OAAO,iBAAkB,WAAW,gBAAgB,CAAC,CAAC,CAAC,EACvF,CAAC,CACH;CACF;CACA,IAAI,QAAQ,gBAAgB;EAS1B,IAAM,EAAC,yBAAwB,MAAM,OAAO;EAC5C,QAAQ,KACN,qBAAqB;GACnB,QAAQ,EAAC,YAAY,GAAI;GACzB,GAAI,QAAQ,mBAAmB,KAAO,CAAC,IAAI,QAAQ;EACrD,CAAC,CACH;CACF;CAMA,IAAM,EAAC,YAAW,YAChB,EACE,SAAS;EACP,SAAS;EAGT,IAAI,MAVmB,OAAO,EAAC,KAAK,QAAQ,IAAI,EAAC,CAAC,EAAA,EAU9B,SAAS,UAAU,EAAC,YAAY,GAAI;CAC1D,EACF,GACA,EAAC,SAAS,QAAQ,QAAO,CAC3B;CAEA,OAAOA,eAAmB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ;GAAC,UAAU;GAAM,SAAS;GAAO,QAAQ;EAAK;CACxD,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/tsdown-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Shared configuration for tsdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -40,16 +40,16 @@
|
|
|
40
40
|
"@vitejs/plugin-react": "^6.0.3",
|
|
41
41
|
"package-manager-detector": "^1.7.0",
|
|
42
42
|
"publint": "^0.3.21",
|
|
43
|
-
"@sanity/vanilla-extract-tsdown-plugin": "^0.1.
|
|
43
|
+
"@sanity/vanilla-extract-tsdown-plugin": "^0.1.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/babel__core": "^7.20.5",
|
|
47
47
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
48
48
|
"tinyexec": "^1.2.4",
|
|
49
|
-
"tsdown": "^0.22.
|
|
49
|
+
"tsdown": "^0.22.8",
|
|
50
50
|
"typescript": "7.0.2",
|
|
51
51
|
"vitest": "^4.1.10",
|
|
52
|
-
"@sanity/pkg-utils": "^11.0.
|
|
52
|
+
"@sanity/pkg-utils": "^11.0.4",
|
|
53
53
|
"@sanity/tsconfig": "^2.2.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|