@sanity/tsdown-config 0.10.0 → 0.11.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 CHANGED
@@ -109,3 +109,34 @@ consumers by adding it to `sideEffects` in `package.json`:
109
109
  Pass an options object instead of `true` to customize (e.g. `minify`, `browserslist`,
110
110
  `extract.name`), or set `extract.compatMode: false` to wire up the import, shim, and export
111
111
  yourself.
112
+
113
+ ## dts
114
+
115
+ tsdown's [`dts` option](https://tsdown.dev/options/dts) is passed through as-is. By default tsdown
116
+ auto-detects it from `package.json` (it's enabled when a `types` field or a `types` condition in
117
+ `exports` is present). Pass an object to customize how the `.d.ts` files are generated, for example
118
+ to use [`tsgo`](https://github.com/microsoft/typescript-go) (the same feature as the `tsgo` option
119
+ in `@sanity/pkg-utils`, requires `@typescript/native-preview` to be installed):
120
+
121
+ ```ts
122
+ import {defineConfig} from '@sanity/tsdown-config'
123
+
124
+ export default defineConfig({
125
+ tsconfig: 'tsconfig.dist.json',
126
+ dts: {tsgo: true},
127
+ })
128
+ ```
129
+
130
+ ## define
131
+
132
+ tsdown's `define` option is also passed through as-is. It replaces global identifiers with constant
133
+ expressions at build time (the same feature as the `define` option in `@sanity/pkg-utils`):
134
+
135
+ ```ts
136
+ import {defineConfig} from '@sanity/tsdown-config'
137
+
138
+ export default defineConfig({
139
+ tsconfig: 'tsconfig.dist.json',
140
+ define: {'process.env.NODE_ENV': JSON.stringify('production')},
141
+ })
142
+ ```
package/dist/index.d.mts CHANGED
@@ -89,7 +89,7 @@ type ReactCompilerOptions = Partial<PluginOptions>;
89
89
  /**
90
90
  * @public
91
91
  */
92
- interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format"> {
92
+ interface PackageOptions extends Pick<UserConfig, "tsconfig" | "entry" | "format" | "dts" | "define"> {
93
93
  /**
94
94
  * @defaultValue 'neutral'
95
95
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources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A,oBAAA;EDiCE;EC/BF,MAAA;;EAEA,yBAAA;EACA,SAAA;;EAEA,IAAA;AAAA;;;;;;;;KAUU,oBAAA,GAAuB,OAAA,CAAQ,aAAA;;AAVzC;AAUF;UAKiB,cAAA,SAAuB,IAAA,CACtC,UAAA;;;AANyC;EAYzC,QAAA,GAAW,UAAA;EAPI;;;;;;;;;EAiBf,aAAA,aAA0B,oBAAA;;;;;;;;EAQ1B,gBAAA,aAA6B,uBAAA;;;;AAWF;AAM7B;;;;;;EANE,cAAA,aAA2B,4BAAA;AAAA;;;;iBAMP,YAAA,CAAa,OAAA,GAAS,cAAA,GAAsB,OAAA,CAAQ,UAAA"}
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { defineConfig as defineConfig$1 } from "tsdown";
3
3
  * @public
4
4
  */
5
5
  async function defineConfig(options = {}) {
6
- let { entry } = options, tsconfig = options.tsconfig ?? "tsconfig.json", platform = options.platform ?? "neutral", reactCompiler = options.reactCompiler ?? !1, styledComponents = options.styledComponents ?? !1, report = { gzip: !1 }, format = options.format ?? "esm", inputOptions = {
6
+ let { entry, dts, define } = options, tsconfig = options.tsconfig ?? "tsconfig.json", platform = options.platform ?? "neutral", reactCompiler = options.reactCompiler ?? !1, styledComponents = options.styledComponents ?? !1, report = { gzip: !1 }, format = options.format ?? "esm", inputOptions = {
7
7
  preserveEntrySignatures: "strict",
8
8
  experimental: { attachDebugInfo: "none" },
9
9
  ...styledComponents !== !1 && { transform: { plugins: { styledComponents: {
@@ -56,6 +56,8 @@ async function defineConfig(options = {}) {
56
56
  }
57
57
  }
58
58
  return defineConfig$1({
59
+ define,
60
+ dts,
59
61
  entry,
60
62
  exports: {
61
63
  enabled: "local-only",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["defineTsdownConfig"],"sources":["../src/index.ts"],"sourcesContent":["import type {PluginOptions as ReactCompilerPluginOptions} from 'babel-plugin-react-compiler'\nimport {defineConfig as defineTsdownConfig, type Rolldown, type UserConfig} from 'tsdown'\nimport type {PackageVanillaExtractOptions} from './vanillaExtract.ts'\n\nexport type {PackageVanillaExtractOptions}\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<UserConfig, 'tsconfig' | 'entry' | 'format'> {\n /**\n * @defaultValue 'neutral'\n */\n platform?: UserConfig['platform']\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 `@vanilla-extract/rollup-plugin` to extract CSS into a separate file, with support for\n * minifying the extracted CSS. Pass `true` to use the defaults, or an object to customize.\n *\n * By default (`extract.compatMode: true`) the config 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 const {entry} = options\n const tsconfig = options.tsconfig ?? 'tsconfig.json'\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 hash = false\n const format = options.format ?? 'esm'\n const inputOptions = {\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 const baseOutputOptions = {\n hoistTransitiveImports: false,\n } as const satisfies UserConfig['outputOptions']\n\n let outputOptions: UserConfig['outputOptions'] = baseOutputOptions\n let treeshake: UserConfig['treeshake']\n let customExports: ((exportsMap: Record<string, unknown>) => Record<string, unknown>) | undefined\n\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 // The plugin types don't match when `@rolldown/plugin-babel` resolves its `rolldown` peer\n // dependency to a different version than the one bundled with `tsdown`, so cast it:\n // https://tsdown.dev/advanced/plugins#rollup-plugins\n // oxlint-disable-next-line no-unsafe-type-assertion\n (await pluginBabel({\n presets: [reactCompilerPreset(typeof reactCompiler === 'object' ? reactCompiler : {})],\n })) as unknown as Rolldown.Plugin,\n )\n }\n if (options.vanillaExtract) {\n // Everything vanilla-extract related is lazy loaded, like `reactCompiler`, so it's only paid\n // for when the option is enabled: `@vanilla-extract/rollup-plugin` compiles the `.css.ts`\n // files, and `optimizeCss` pulls in the CSS toolchain (`lightningcss`, `browserslist`) that\n // minifies the extracted CSS.\n const [\n {vanillaExtractPlugin},\n {default: browserslistConfig},\n {optimizeCss},\n {bundleCssShim},\n {\n composeIntro,\n createConditionalCssExport,\n insertCssExport,\n readPackageName,\n resolveVanillaExtract,\n resolveVanillaExtractCssName,\n },\n ] = await Promise.all([\n import('@vanilla-extract/rollup-plugin'),\n import('@sanity/browserslist-config'),\n import('./optimizeCss.ts'),\n import('./bundleCssShim.ts'),\n import('./vanillaExtract.ts'),\n ])\n\n // Resolve vanilla-extract options + the conditional CSS export \"compat mode\"\n const vanillaExtract = resolveVanillaExtract(options.vanillaExtract)\n const cssName = resolveVanillaExtractCssName(vanillaExtract.options)\n\n plugins.push(\n // Rolldown supports most Rollup plugins, but the plugin types are not identical, so the\n // official guidance is to cast: https://tsdown.dev/advanced/plugins#rollup-plugins\n // oxlint-disable-next-line no-unsafe-type-assertion\n vanillaExtractPlugin({\n identifiers: vanillaExtract.options.identifiers ?? 'short',\n cwd: vanillaExtract.options.cwd,\n esbuildOptions: vanillaExtract.options.esbuildOptions,\n unstable_injectFilescopes: vanillaExtract.options.unstable_injectFilescopes,\n extract: {\n name: cssName,\n sourcemap: vanillaExtract.options.extract?.sourcemap ?? true,\n },\n }) as unknown as Rolldown.Plugin,\n optimizeCss({\n extractFileName: cssName,\n browserslist: vanillaExtract.options.browserslist || browserslistConfig,\n minify: vanillaExtract.options.minify ?? true,\n }),\n )\n\n // The vanilla-extract plugin resolves each compiled `.css.ts` module's CSS to an external,\n // side-effect-only `<file>.vanilla.css` import and extracts the CSS into a single file. The\n // imports are redundant once the CSS is extracted, so let tree-shaking drop them up front:\n // the plugin's own `generateBundle` cleanup only strips imports at the start of a line, which\n // the minifier's statement merging can defeat (e.g. `a(), require(\"….vanilla.css\")` in CJS).\n // Modules not matching the rule keep the default tree-shaking behavior.\n treeshake = {moduleSideEffects: [{test: /\\.vanilla\\.css$/, external: true, sideEffects: false}]}\n\n // In compat mode, the self-referential `import \"<pkg>/<css>\"` needs the package name.\n const cssImportId = vanillaExtract.compatMode\n ? `${readPackageName(process.cwd())}/${cssName}`\n : undefined\n\n outputOptions = (_options, outputFormat, context) => ({\n ...baseOutputOptions,\n // Emit the extracted CSS (and its sourcemap) with a stable name at the root of the tsdown\n // default `outDir` ('dist', not configurable yet) instead of rolldown's default\n // `assets/[name]-[hash][extname]`, so it can back the conditional `./<css>` export.\n assetFileNames: '[name][extname]',\n // In compat mode, inject the self-referential CSS import into the `index` entry chunk so\n // userland does not need to set `outputOptions.intro` themselves. Use `require()` for\n // CommonJS output (a top-level `import` would be invalid in a `.cjs` bundle).\n ...(cssImportId && !context.cjsDts && (outputFormat === 'es' || outputFormat === 'cjs')\n ? {\n intro: composeIntro(\n outputFormat === 'cjs'\n ? `require(${JSON.stringify(cssImportId)})`\n : `import ${JSON.stringify(cssImportId)}`,\n ),\n }\n : {}),\n })\n\n if (vanillaExtract.compatMode) {\n // In compat mode, emit the no-op JS shim that the `node`/`default` conditions of the\n // `./<css>` export resolve to.\n plugins.push(bundleCssShim({fileName: `${cssName}.js`}))\n\n // Write the conditional `./<css>` export to `package.json` (and, through tsdown, mirror it\n // into `publishConfig.exports`) so userland does not have to maintain it.\n const conditionalCssExport = createConditionalCssExport(cssName, 'dist')\n customExports = (exportsMap) =>\n insertCssExport(exportsMap, `./${cssName}`, conditionalCssExport)\n }\n }\n\n const exports = {\n enabled: 'local-only',\n // @TODO use @sanity/parse-package-json to determine if devExports should be `true` or `source`\n devExports: true,\n ...(customExports && {customExports}),\n } as const satisfies UserConfig['exports']\n\n return defineTsdownConfig({\n entry,\n exports,\n format,\n hash,\n inputOptions,\n outputOptions,\n platform,\n plugins,\n publint,\n report,\n treeshake,\n tsconfig,\n minify: {compress: true, codegen: false, mangle: false},\n // `treeshake` stays `undefined` (tsdown's/rolldown's default, `moduleSideEffects: true`)\n // unless vanilla-extract needs its targeted rule above. Previously this set the equivalent of\n // `moduleSideEffects: 'no-external'` (with a `.css` exemption), which stripped intentional\n // side-effect-only imports of external packages (e.g. `import 'react-time-ago/locale/en'`)\n // from the output. The default preserves those imports while still honoring `package.json`\n // `sideEffects` fields for bundled modules.\n })\n}\n"],"mappings":";;;;AAoFA,eAAsB,aAAa,UAA0B,CAAC,GAAwB;CACpF,IAAM,EAAC,UAAS,SACV,WAAW,QAAQ,YAAY,iBAC/B,WAAW,QAAQ,YAAY,WAC/B,gBAAgB,QAAQ,iBAAiB,IACzC,mBAAmB,QAAQ,oBAAoB,IAC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Q,eAAe,QAAQ,UAAU;EAC3C,CAAC,CACH,GAQA,YAAY,EAAC,mBAAmB,CAAC;GAAC,MAAM;GAAmB,UAAU;GAAM,aAAa;EAAK,CAAC,EAAC;EAG/F,IAAM,cAAc,eAAe,aAC/B,GAAG,gBAAgB,QAAQ,IAAI,CAAC,EAAE,GAAG,YACrC,KAAA;EAsBJ,IApBA,iBAAiB,UAAU,cAAc,aAAa;GACpD,GAAG;GAIH,gBAAgB;GAIhB,GAAI,eAAe,CAAC,QAAQ,WAAW,iBAAiB,QAAQ,iBAAiB,SAC7E,EACE,OAAO,aACL,iBAAiB,QACb,WAAW,KAAK,UAAU,WAAW,EAAE,KACvC,UAAU,KAAK,UAAU,WAAW,GAC1C,EACF,IACA,CAAC;EACP,IAEI,eAAe,YAAY;GAG7B,QAAQ,KAAK,cAAc,EAAC,UAAU,GAAG,QAAQ,KAAI,CAAC,CAAC;GAIvD,IAAM,uBAAuB,2BAA2B,SAAS,MAAM;GACvE,iBAAiB,eACf,gBAAgB,YAAY,KAAK,WAAW,oBAAoB;EACpE;CACF;CASA,OAAOA,eAAmB;EACxB;EACA,SAAA;GARA,SAAS;GAET,YAAY;GACZ,GAAI,iBAAiB,EAAC,cAAa;EAK7B;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ;GAAC,UAAU;GAAM,SAAS;GAAO,QAAQ;EAAK;CAOxD,CAAC;AACH"}
1
+ {"version":3,"file":"index.mjs","names":["defineTsdownConfig"],"sources":["../src/index.ts"],"sourcesContent":["import type {PluginOptions as ReactCompilerPluginOptions} from 'babel-plugin-react-compiler'\nimport {defineConfig as defineTsdownConfig, type Rolldown, type UserConfig} from 'tsdown'\nimport type {PackageVanillaExtractOptions} from './vanillaExtract.ts'\n\nexport type {PackageVanillaExtractOptions}\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'\n> {\n /**\n * @defaultValue 'neutral'\n */\n platform?: UserConfig['platform']\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 `@vanilla-extract/rollup-plugin` to extract CSS into a separate file, with support for\n * minifying the extracted CSS. Pass `true` to use the defaults, or an object to customize.\n *\n * By default (`extract.compatMode: true`) the config 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 // `dts` and `define` are passed through to tsdown as-is. When left undefined, tsdown keeps its\n // default behavior (`dts` is auto-detected from `package.json`, `define` replaces nothing).\n const {entry, dts, define} = options\n const tsconfig = options.tsconfig ?? 'tsconfig.json'\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 hash = false\n const format = options.format ?? 'esm'\n const inputOptions = {\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 const baseOutputOptions = {\n hoistTransitiveImports: false,\n } as const satisfies UserConfig['outputOptions']\n\n let outputOptions: UserConfig['outputOptions'] = baseOutputOptions\n let treeshake: UserConfig['treeshake']\n let customExports: ((exportsMap: Record<string, unknown>) => Record<string, unknown>) | undefined\n\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 // The plugin types don't match when `@rolldown/plugin-babel` resolves its `rolldown` peer\n // dependency to a different version than the one bundled with `tsdown`, so cast it:\n // https://tsdown.dev/advanced/plugins#rollup-plugins\n // oxlint-disable-next-line no-unsafe-type-assertion\n (await pluginBabel({\n presets: [reactCompilerPreset(typeof reactCompiler === 'object' ? reactCompiler : {})],\n })) as unknown as Rolldown.Plugin,\n )\n }\n if (options.vanillaExtract) {\n // Everything vanilla-extract related is lazy loaded, like `reactCompiler`, so it's only paid\n // for when the option is enabled: `@vanilla-extract/rollup-plugin` compiles the `.css.ts`\n // files, and `optimizeCss` pulls in the CSS toolchain (`lightningcss`, `browserslist`) that\n // minifies the extracted CSS.\n const [\n {vanillaExtractPlugin},\n {default: browserslistConfig},\n {optimizeCss},\n {bundleCssShim},\n {\n composeIntro,\n createConditionalCssExport,\n insertCssExport,\n readPackageName,\n resolveVanillaExtract,\n resolveVanillaExtractCssName,\n },\n ] = await Promise.all([\n import('@vanilla-extract/rollup-plugin'),\n import('@sanity/browserslist-config'),\n import('./optimizeCss.ts'),\n import('./bundleCssShim.ts'),\n import('./vanillaExtract.ts'),\n ])\n\n // Resolve vanilla-extract options + the conditional CSS export \"compat mode\"\n const vanillaExtract = resolveVanillaExtract(options.vanillaExtract)\n const cssName = resolveVanillaExtractCssName(vanillaExtract.options)\n\n plugins.push(\n // Rolldown supports most Rollup plugins, but the plugin types are not identical, so the\n // official guidance is to cast: https://tsdown.dev/advanced/plugins#rollup-plugins\n // oxlint-disable-next-line no-unsafe-type-assertion\n vanillaExtractPlugin({\n identifiers: vanillaExtract.options.identifiers ?? 'short',\n cwd: vanillaExtract.options.cwd,\n esbuildOptions: vanillaExtract.options.esbuildOptions,\n unstable_injectFilescopes: vanillaExtract.options.unstable_injectFilescopes,\n extract: {\n name: cssName,\n sourcemap: vanillaExtract.options.extract?.sourcemap ?? true,\n },\n }) as unknown as Rolldown.Plugin,\n optimizeCss({\n extractFileName: cssName,\n browserslist: vanillaExtract.options.browserslist || browserslistConfig,\n minify: vanillaExtract.options.minify ?? true,\n }),\n )\n\n // The vanilla-extract plugin resolves each compiled `.css.ts` module's CSS to an external,\n // side-effect-only `<file>.vanilla.css` import and extracts the CSS into a single file. The\n // imports are redundant once the CSS is extracted, so let tree-shaking drop them up front:\n // the plugin's own `generateBundle` cleanup only strips imports at the start of a line, which\n // the minifier's statement merging can defeat (e.g. `a(), require(\"….vanilla.css\")` in CJS).\n // Modules not matching the rule keep the default tree-shaking behavior.\n treeshake = {moduleSideEffects: [{test: /\\.vanilla\\.css$/, external: true, sideEffects: false}]}\n\n // In compat mode, the self-referential `import \"<pkg>/<css>\"` needs the package name.\n const cssImportId = vanillaExtract.compatMode\n ? `${readPackageName(process.cwd())}/${cssName}`\n : undefined\n\n outputOptions = (_options, outputFormat, context) => ({\n ...baseOutputOptions,\n // Emit the extracted CSS (and its sourcemap) with a stable name at the root of the tsdown\n // default `outDir` ('dist', not configurable yet) instead of rolldown's default\n // `assets/[name]-[hash][extname]`, so it can back the conditional `./<css>` export.\n assetFileNames: '[name][extname]',\n // In compat mode, inject the self-referential CSS import into the `index` entry chunk so\n // userland does not need to set `outputOptions.intro` themselves. Use `require()` for\n // CommonJS output (a top-level `import` would be invalid in a `.cjs` bundle).\n ...(cssImportId && !context.cjsDts && (outputFormat === 'es' || outputFormat === 'cjs')\n ? {\n intro: composeIntro(\n outputFormat === 'cjs'\n ? `require(${JSON.stringify(cssImportId)})`\n : `import ${JSON.stringify(cssImportId)}`,\n ),\n }\n : {}),\n })\n\n if (vanillaExtract.compatMode) {\n // In compat mode, emit the no-op JS shim that the `node`/`default` conditions of the\n // `./<css>` export resolve to.\n plugins.push(bundleCssShim({fileName: `${cssName}.js`}))\n\n // Write the conditional `./<css>` export to `package.json` (and, through tsdown, mirror it\n // into `publishConfig.exports`) so userland does not have to maintain it.\n const conditionalCssExport = createConditionalCssExport(cssName, 'dist')\n customExports = (exportsMap) =>\n insertCssExport(exportsMap, `./${cssName}`, conditionalCssExport)\n }\n }\n\n const exports = {\n enabled: 'local-only',\n // @TODO use @sanity/parse-package-json to determine if devExports should be `true` or `source`\n devExports: true,\n ...(customExports && {customExports}),\n } as const satisfies UserConfig['exports']\n\n return defineTsdownConfig({\n define,\n dts,\n entry,\n exports,\n format,\n hash,\n inputOptions,\n outputOptions,\n platform,\n plugins,\n publint,\n report,\n treeshake,\n tsconfig,\n minify: {compress: true, codegen: false, mangle: false},\n // `treeshake` stays `undefined` (tsdown's/rolldown's default, `moduleSideEffects: true`)\n // unless vanilla-extract needs its targeted rule above. Previously this set the equivalent of\n // `moduleSideEffects: 'no-external'` (with a `.css` exemption), which stripped intentional\n // side-effect-only imports of external packages (e.g. `import 'react-time-ago/locale/en'`)\n // from the output. The default preserves those imports while still honoring `package.json`\n // `sideEffects` fields for bundled modules.\n })\n}\n"],"mappings":";;;;AAuFA,eAAsB,aAAa,UAA0B,CAAC,GAAwB;CAGpF,IAAM,EAAC,OAAO,KAAK,WAAU,SACvB,WAAW,QAAQ,YAAY,iBAC/B,WAAW,QAAQ,YAAY,WAC/B,gBAAgB,QAAQ,iBAAiB,IACzC,mBAAmB,QAAQ,oBAAoB,IAC/C,SAAS,EAAC,MAAM,GAAK,GAGrB,SAAS,QA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QA,YAAY,EAAC,mBAAmB,CAAC;GAAC,MAAM;GAAmB,UAAU;GAAM,aAAa;EAAK,CAAC,EAAC;EAG/F,IAAM,cAAc,eAAe,aAC/B,GAAG,gBAAgB,QAAQ,IAAI,CAAC,EAAE,GAAG,YACrC,KAAA;EAsBJ,IApBA,iBAAiB,UAAU,cAAc,aAAa;GACpD,GAAG;GAIH,gBAAgB;GAIhB,GAAI,eAAe,CAAC,QAAQ,WAAW,iBAAiB,QAAQ,iBAAiB,SAC7E,EACE,OAAO,aACL,iBAAiB,QACb,WAAW,KAAK,UAAU,WAAW,EAAE,KACvC,UAAU,KAAK,UAAU,WAAW,GAC1C,EACF,IACA,CAAC;EACP,IAEI,eAAe,YAAY;GAG7B,QAAQ,KAAK,cAAc,EAAC,UAAU,GAAG,QAAQ,KAAI,CAAC,CAAC;GAIvD,IAAM,uBAAuB,2BAA2B,SAAS,MAAM;GACvE,iBAAiB,eACf,gBAAgB,YAAY,KAAK,WAAW,oBAAoB;EACpE;CACF;CASA,OAAOA,eAAmB;EACxB;EACA;EACA;EACA,SAAA;GAVA,SAAS;GAET,YAAY;GACZ,GAAI,iBAAiB,EAAC,cAAa;EAO7B;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ;GAAC,UAAU;GAAM,SAAS;GAAO,QAAQ;EAAK;CAOxD,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/tsdown-config",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Shared configuration for tsdown",
5
5
  "keywords": [
6
6
  "sanity-io",