@sanity/tsdown-config 0.11.0 → 0.12.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/dist/_chunks-es/bundleCssShim.mjs.map +1 -0
- package/dist/_chunks-es/optimizeCss.mjs.map +1 -0
- package/dist/_chunks-es/vanillaExtract.mjs.map +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +26 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/bundleCssShim.mjs.map +0 -1
- package/dist/optimizeCss.mjs.map +0 -1
- package/dist/vanillaExtract.mjs.map +0 -1
- /package/dist/{bundleCssShim.mjs → _chunks-es/bundleCssShim.mjs} +0 -0
- /package/dist/{optimizeCss.mjs → _chunks-es/optimizeCss.mjs} +0 -0
- /package/dist/{vanillaExtract.mjs → _chunks-es/vanillaExtract.mjs} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleCssShim.mjs","names":[],"sources":["../../src/bundleCssShim.ts"],"sourcesContent":["import type {Rolldown} from 'tsdown'\n\n/**\n * Emits a no-op JavaScript shim (`export default \"\"`) alongside the extracted CSS. The conditional\n * `./<css>` export points its `node`/`default` conditions at this file so that the self-referential\n * `import \"<pkg>/<css>\"` resolves to a harmless module in runtimes that cannot import `.css` files,\n * instead of throwing `Error: Unknown file extension \".css\"`.\n *\n * A matching `.d.ts` declaration is emitted next to the shim as well. Both the `browser`/`style`\n * (`<css>`) and the `node`/`default` (`<css>.js`) conditions of the `./<css>` export resolve their\n * types to the same `<css>.d.ts` file, so type-aware tooling (e.g. dts export checkers that load a\n * `.d.ts` for every export target) does not crash on a missing declaration file.\n *\n * @param options.fileName - The shim file name, e.g. `bundle.css.js`.\n * @internal\n */\nexport function bundleCssShim(options: {fileName: string}): Rolldown.Plugin {\n const cssName = options.fileName.replace(/\\.js$/, '')\n\n return {\n name: 'sanity-tsdown-config:bundle-css-shim',\n generateBundle() {\n this.emitFile({\n type: 'asset',\n fileName: options.fileName,\n source: `// No-op shim for \\`${cssName}\\` in runtimes that cannot import \\`.css\\` files directly.\\nexport default \"\"\\n`,\n })\n this.emitFile({\n type: 'asset',\n fileName: `${cssName}.d.ts`,\n source: `// Type declarations for \\`${cssName}\\` and its no-op JS shim.\\ndeclare const _default: string\\nexport default _default\\n`,\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,SAA8C;CAC1E,IAAM,UAAU,QAAQ,SAAS,QAAQ,SAAS,EAAE;CAEpD,OAAO;EACL,MAAM;EACN,iBAAiB;GAMf,AALA,KAAK,SAAS;IACZ,MAAM;IACN,UAAU,QAAQ;IAClB,QAAQ,uBAAuB,QAAQ;GACzC,CAAC,GACD,KAAK,SAAS;IACZ,MAAM;IACN,UAAU,GAAG,QAAQ;IACrB,QAAQ,8BAA8B,QAAQ;GAChD,CAAC;EACH;CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimizeCss.mjs","names":[],"sources":["../../src/optimizeCss.ts"],"sourcesContent":["import {basename} from 'node:path'\nimport browserslist from 'browserslist'\nimport {browserslistToTargets, transform} from 'lightningcss'\nimport type {Rolldown} from 'tsdown'\n\n/**\n * Post-processes the CSS file extracted by `@vanilla-extract/rollup-plugin` with `lightningcss`,\n * applying browserslist targets and (unless disabled) minification. Ported from the equivalent\n * `@sanity/pkg-utils` Rollup plugin.\n * @internal\n */\nexport function optimizeCss(options: {\n extractFileName: string\n browserslist: string | string[]\n minify?: boolean\n}): Rolldown.Plugin {\n return {\n name: 'sanity-tsdown-config:optimize-css',\n\n async generateBundle(_outputOptions, bundle, _isWrite) {\n for (const [fileName, assetOrChunk] of Object.entries(bundle)) {\n // find the extracted CSS asset\n if (assetOrChunk.type === 'asset') {\n const asset = assetOrChunk\n if (\n asset.fileName === options.extractFileName ||\n asset.originalFileNames.includes(options.extractFileName)\n ) {\n const sourceMap = bundle[`${fileName}.map`]\n await transformCss(\n asset,\n sourceMap?.type === 'asset' ? sourceMap : undefined,\n options.browserslist,\n options.minify ?? true,\n )\n }\n }\n }\n },\n }\n}\n\nasync function transformCss(\n asset: Rolldown.OutputAsset,\n sourceMapAsset: Rolldown.OutputAsset | undefined,\n browserslistConfig: string | string[],\n minify: boolean,\n) {\n const css = asset.source.toString()\n const file = asset.fileName\n\n const targets = browserslistToTargets(browserslist(browserslistConfig))\n\n // process (and, unless disabled, minify) css using lightningcss\n const lightningCssResult = transform({\n filename: file,\n code: Buffer.from(css),\n minify,\n cssModules: false,\n targets,\n sourceMap: !!sourceMapAsset,\n inputSourceMap: sourceMapAsset ? sourceMapAsset.source.toString() : undefined,\n })\n\n if (lightningCssResult.warnings.length) {\n console.warn(lightningCssResult.warnings)\n }\n\n asset.source = new TextDecoder().decode(lightningCssResult.code)\n if (sourceMapAsset && lightningCssResult.map) {\n sourceMapAsset.source = new TextDecoder().decode(lightningCssResult.map)\n asset.source += `\\n/*# sourceMappingURL=${basename(sourceMapAsset.fileName)}*/\\n`\n }\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,YAAY,SAIR;CAClB,OAAO;EACL,MAAM;EAEN,MAAM,eAAe,gBAAgB,QAAQ,UAAU;GACrD,KAAK,IAAM,CAAC,UAAU,iBAAiB,OAAO,QAAQ,MAAM,GAE1D,IAAI,aAAa,SAAS,SAAS;IACjC,IAAM,QAAQ;IACd,IACE,MAAM,aAAa,QAAQ,mBAC3B,MAAM,kBAAkB,SAAS,QAAQ,eAAe,GACxD;KACA,IAAM,YAAY,OAAO,GAAG,SAAS;KACrC,MAAM,aACJ,OACA,WAAW,SAAS,UAAU,YAAY,KAAA,GAC1C,QAAQ,cACR,QAAQ,UAAU,EACpB;IACF;GACF;EAEJ;CACF;AACF;AAEA,eAAe,aACb,OACA,gBACA,oBACA,QACA;CACA,IAAM,MAAM,MAAM,OAAO,SAAS,GAC5B,OAAO,MAAM,UAEb,UAAU,sBAAsB,aAAa,kBAAkB,CAAC,GAGhE,qBAAqB,UAAU;EACnC,UAAU;EACV,MAAM,OAAO,KAAK,GAAG;EACrB;EACA,YAAY;EACZ;EACA,WAAW,CAAC,CAAC;EACb,gBAAgB,iBAAiB,eAAe,OAAO,SAAS,IAAI,KAAA;CACtE,CAAC;CAOD,AALI,mBAAmB,SAAS,UAC9B,QAAQ,KAAK,mBAAmB,QAAQ,GAG1C,MAAM,SAAS,IAAI,YAAY,CAAC,CAAC,OAAO,mBAAmB,IAAI,GAC3D,kBAAkB,mBAAmB,QACvC,eAAe,SAAS,IAAI,YAAY,CAAC,CAAC,OAAO,mBAAmB,GAAG,GACvE,MAAM,UAAU,0BAA0B,SAAS,eAAe,QAAQ,EAAE;AAEhF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanillaExtract.mjs","names":[],"sources":["../../src/vanillaExtract.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\nimport path from 'node:path'\nimport type {Options as VanillaExtractPluginOptions} from '@vanilla-extract/rollup-plugin'\nimport type {Rolldown} from 'tsdown'\n\n/** The default name of the extracted CSS file. */\nconst DEFAULT_VANILLA_EXTRACT_CSS_NAME = 'bundle.css'\n\n/**\n * Options for the `@vanilla-extract/rollup-plugin` integration, including the same extensions as\n * `@sanity/pkg-utils` (`minify`, `browserslist`, and `extract.compatMode`).\n * @public\n */\nexport interface PackageVanillaExtractOptions extends Omit<VanillaExtractPluginOptions, 'extract'> {\n /**\n * Minify the extracted CSS with `lightningcss`.\n * @defaultValue true\n */\n minify?: boolean\n /**\n * Browserslist query passed to `lightningcss` when optimizing the extracted CSS.\n * @defaultValue `@sanity/browserslist-config`\n */\n browserslist?: string | string[]\n /**\n * Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc).\n * @defaultValue \"short\"\n */\n identifiers?: VanillaExtractPluginOptions['identifiers']\n /**\n * Extract the CSS into a separate file. The CSS is always extracted, so this configures _how_.\n */\n extract?: {\n /**\n * Name of the emitted `.css` file (and, with `compatMode`, the `exports` subpath + shim base).\n * @defaultValue \"bundle.css\"\n */\n name?: string\n /**\n * Generate a `.css.map` sourcemap file.\n * @defaultValue true\n */\n sourcemap?: boolean\n /**\n * Compatibility mode automatically wires up the conditional CSS export pattern so userland does\n * not have to. When enabled, the config:\n *\n * - injects `import \"<pkg-name>/<name>\"` into the `index` entry chunk,\n * - emits a no-op `<name>.js` shim for runtimes that cannot import `.css` files, and\n * - writes the conditional `\"./<name>\"` export to `package.json`\n * (`browser`/`style` → the real CSS, `node`/`default` → the shim).\n *\n * The result is that `import \"<pkg>/<name>\"` resolves to the real CSS in bundlers/browsers and\n * to the no-op shim in Node and similar runtimes. Disable it to wire these up yourself.\n * @defaultValue true\n */\n compatMode?: boolean\n }\n}\n\n/** @internal */\nexport interface ResolvedVanillaExtract {\n enabled: boolean\n /** Normalized options (the object form, or `{}` when `vanillaExtract: true`). */\n options: PackageVanillaExtractOptions\n /**\n * Whether to automatically wire up the conditional CSS export pattern (intro import, JS shim, and\n * the `package.json` export). Only `true` when vanilla-extract is enabled.\n */\n compatMode: boolean\n}\n\n/**\n * Normalize the `vanillaExtract` option into a consistent shape and resolve whether compatibility\n * mode is active.\n * @internal\n */\nexport function resolveVanillaExtract(\n value: boolean | PackageVanillaExtractOptions | undefined,\n): ResolvedVanillaExtract {\n const enabled = Boolean(value)\n const options: PackageVanillaExtractOptions = value === true || !value ? {} : value\n const compatMode = enabled ? (options.extract?.compatMode ?? true) : false\n\n return {enabled, options, compatMode}\n}\n\n/**\n * Resolve the name of the emitted CSS file. Unlike `@sanity/pkg-utils`, tsdown produces a single\n * bundle that is shared across runtimes, so there are no runtime-suffixed defaults.\n * @internal\n */\nexport function resolveVanillaExtractCssName(options: PackageVanillaExtractOptions): string {\n return options.extract?.name ?? DEFAULT_VANILLA_EXTRACT_CSS_NAME\n}\n\n/**\n * Build the conditional CSS export object that vanilla-extract compat mode expects, e.g.\n * ```json\n * {\n * \"browser\": \"./dist/bundle.css\",\n * \"style\": \"./dist/bundle.css\",\n * \"node\": \"./dist/bundle.css.js\",\n * \"default\": \"./dist/bundle.css.js\"\n * }\n * ```\n * @internal\n */\nexport function createConditionalCssExport(\n cssName: string,\n outDir: string,\n): Record<string, string> {\n const cssFile = `./${outDir}/${cssName}`\n const shimFile = `./${outDir}/${cssName}.js`\n return {browser: cssFile, style: cssFile, node: shimFile, default: shimFile}\n}\n\n/**\n * Insert (or replace) the `\"./<cssName>\"` export in an `exports`-shaped map, preserving the\n * existing order and placing it before `./package.json` when present. Used with tsdown's\n * `exports.customExports` so both `exports` and `publishConfig.exports` receive the entry.\n * @internal\n */\nexport function insertCssExport(\n exports: Record<string, unknown>,\n exportKey: string,\n conditionalExport: Record<string, string>,\n): Record<string, unknown> {\n const nextExports: Record<string, unknown> = {}\n let inserted = false\n for (const [key, value] of Object.entries(exports)) {\n if (key === exportKey) continue\n if (key === './package.json' && !inserted) {\n nextExports[exportKey] = conditionalExport\n inserted = true\n }\n nextExports[key] = value\n }\n if (!inserted) {\n nextExports[exportKey] = conditionalExport\n }\n return nextExports\n}\n\nconst RE_DTS = /\\.d\\.[cm]?ts$/\n\n/**\n * Build an `intro` function that prepends `autoImport` to the `index` entry chunk only. The\n * `.d.ts` chunks generated by tsdown share the build, so they are explicitly excluded.\n * @internal\n */\nexport function composeIntro(autoImport: string): (chunk: Rolldown.RenderedChunk) => string {\n return (chunk) =>\n chunk.isEntry && chunk.name === 'index' && !RE_DTS.test(chunk.fileName) ? `${autoImport}\\n` : ''\n}\n\n/**\n * Resolve the package name from `package.json`, required by compat mode to inject the\n * self-referential CSS import.\n * @internal\n */\nexport function readPackageName(cwd: string): string {\n const pkgPath = path.resolve(cwd, 'package.json')\n // oxlint-disable-next-line no-unsafe-type-assertion\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as {name?: unknown}\n if (typeof pkg.name !== 'string' || !pkg.name) {\n throw new Error(\n `Unable to resolve the package name from ${pkgPath}, which is required by \\`vanillaExtract\\` compat mode to inject the self-referential CSS import.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ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/vanillaExtract.ts","../src/index.ts"],"mappings":";;;;;AAaA;;;UAAiB,4BAAA,SAAqC,IAAA,CAAK,OAAA;;;;;EAKzD,MAAA;;;;;EAKA,YAAA;;;;;EAKA,WAAA,GAAc,OAAA;EA4BZ;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/vanillaExtract.ts","../src/index.ts"],"mappings":";;;;;AAaA;;;UAAiB,4BAAA,SAAqC,IAAA,CAAK,OAAA;;;;;EAKzD,MAAA;;;;;EAKA,YAAA;;;;;EAKA,WAAA,GAAc,OAAA;EA4BZ;;ACzCJ;EDiBE,OAAA;;;;;IAKE,IAAA;ICXF;;;;IDgBE,SAAA;ICPF;;AAAA;AAUF;;;;AAA2C;AAK3C;;;;;IDMI,UAAA;EAAA;AAAA;AA3CJ;;;;AAAA,UCEiB,uBAAA;;EAEf,WAAA;EDJoD;;;;ECSpD,mBAAA;;EAEA,GAAA;;EAEA,QAAA;;EAEA,oBAAA;ED4BE;EC1BF,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;AAoC7B;;;;;;EApCE,cAAA,aAA2B,4BAAA;AAAA;;;;iBAoCP,YAAA,CAAa,OAAA,GAAS,cAAA,GAAsB,OAAA,CAAQ,UAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { defineConfig as defineConfig$1 } from "tsdown";
|
|
2
2
|
/**
|
|
3
|
+
* Emits shared (non-entry) chunks into subfolders per output flavor, following the same naming
|
|
4
|
+
* convention as `@sanity/pkg-utils` (`_chunks-es`, `_chunks-cjs` and `_chunks-dts`), instead of
|
|
5
|
+
* rolldown's default of placing chunks at the root of the output directory next to the entries.
|
|
6
|
+
* A chunk can otherwise be named like an entry (e.g. code shared between `index` and `theme`
|
|
7
|
+
* entries forms a chunk that rolldown also names `theme`): the JS output deduplicates such
|
|
8
|
+
* filename collisions in favor of the entry, but the d.ts output can resolve them the other way
|
|
9
|
+
* around, handing `theme.d.ts` to the chunk - which re-exports everything under minified aliases -
|
|
10
|
+
* so every named import from the `theme` entry fails to type-check with TS2460
|
|
11
|
+
* (https://github.com/sanity-io/ui/issues/2262).
|
|
12
|
+
*/
|
|
13
|
+
function resolveChunkFileNames(defaultOutputOptions, format) {
|
|
14
|
+
return (chunk) => {
|
|
15
|
+
let template = (typeof defaultOutputOptions.chunkFileNames == "function" ? defaultOutputOptions.chunkFileNames(chunk) : defaultOutputOptions.chunkFileNames) ?? "[name].js";
|
|
16
|
+
return `${chunk.name.endsWith(".d") ? "_chunks-dts" : `_chunks-${format}`}/${template}`;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
3
20
|
* @public
|
|
4
21
|
*/
|
|
5
22
|
async function defineConfig(options = {}) {
|
|
@@ -13,7 +30,10 @@ async function defineConfig(options = {}) {
|
|
|
13
30
|
cssProp: !1,
|
|
14
31
|
...typeof styledComponents == "object" ? styledComponents : {}
|
|
15
32
|
} } } }
|
|
16
|
-
},
|
|
33
|
+
}, resolveBaseOutputOptions = (defaultOptions, outputFormat) => ({
|
|
34
|
+
hoistTransitiveImports: !1,
|
|
35
|
+
chunkFileNames: resolveChunkFileNames(defaultOptions, outputFormat)
|
|
36
|
+
}), outputOptions = resolveBaseOutputOptions, treeshake, customExports, plugins = [];
|
|
17
37
|
if (reactCompiler !== !1) {
|
|
18
38
|
let [{ default: pluginBabel }, { reactCompilerPreset }] = await Promise.all([import("@rolldown/plugin-babel"), import("@vitejs/plugin-react")]);
|
|
19
39
|
plugins.push(await pluginBabel({ presets: [reactCompilerPreset(typeof reactCompiler == "object" ? reactCompiler : {})] }));
|
|
@@ -22,9 +42,9 @@ async function defineConfig(options = {}) {
|
|
|
22
42
|
let [{ vanillaExtractPlugin }, { default: browserslistConfig }, { optimizeCss }, { bundleCssShim }, { composeIntro, createConditionalCssExport, insertCssExport, readPackageName, resolveVanillaExtract, resolveVanillaExtractCssName }] = await Promise.all([
|
|
23
43
|
import("@vanilla-extract/rollup-plugin"),
|
|
24
44
|
import("@sanity/browserslist-config"),
|
|
25
|
-
import("./optimizeCss.mjs"),
|
|
26
|
-
import("./bundleCssShim.mjs"),
|
|
27
|
-
import("./vanillaExtract.mjs")
|
|
45
|
+
import("./_chunks-es/optimizeCss.mjs"),
|
|
46
|
+
import("./_chunks-es/bundleCssShim.mjs"),
|
|
47
|
+
import("./_chunks-es/vanillaExtract.mjs")
|
|
28
48
|
]), vanillaExtract = resolveVanillaExtract(options.vanillaExtract), cssName = resolveVanillaExtractCssName(vanillaExtract.options);
|
|
29
49
|
plugins.push(vanillaExtractPlugin({
|
|
30
50
|
identifiers: vanillaExtract.options.identifiers ?? "short",
|
|
@@ -45,8 +65,8 @@ async function defineConfig(options = {}) {
|
|
|
45
65
|
sideEffects: !1
|
|
46
66
|
}] };
|
|
47
67
|
let cssImportId = vanillaExtract.compatMode ? `${readPackageName(process.cwd())}/${cssName}` : void 0;
|
|
48
|
-
if (outputOptions = (
|
|
49
|
-
...
|
|
68
|
+
if (outputOptions = (defaultOptions, outputFormat, context) => ({
|
|
69
|
+
...resolveBaseOutputOptions(defaultOptions, outputFormat),
|
|
50
70
|
assetFileNames: "[name][extname]",
|
|
51
71
|
...cssImportId && !context.cjsDts && (outputFormat === "es" || outputFormat === "cjs") ? { intro: composeIntro(outputFormat === "cjs" ? `require(${JSON.stringify(cssImportId)})` : `import ${JSON.stringify(cssImportId)}`) } : {}
|
|
52
72
|
}), vanillaExtract.compatMode) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -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<\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,QAAQ,UAAU,OAC3B,eAAe;EACnB,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,GAEM,oBAAoB,EACxB,wBAAwB,GAC1B,GAEI,gBAA6C,mBAC7C,WACA,eAEE,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,KAKL,MAAM,YAAY,EACjB,SAAS,CAAC,oBAAoB,OAAO,iBAAkB,WAAW,gBAAgB,CAAC,CAAC,CAAC,EACvF,CAAC,CACH;CACF;CACA,IAAI,QAAQ,gBAAgB;EAK1B,IAAM,CACJ,EAAC,wBACD,EAAC,SAAS,sBACV,EAAC,eACD,EAAC,iBACD,EACE,cACA,4BACA,iBACA,iBACA,uBACA,kCAEA,MAAM,QAAQ,IAAI;GACpB,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;EACT,CAAC,GAGK,iBAAiB,sBAAsB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AC;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 {\n defineConfig as defineTsdownConfig,\n type NormalizedFormat,\n type Rolldown,\n type UserConfig,\n} 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 * Emits shared (non-entry) chunks into subfolders per output flavor, following the same naming\n * convention as `@sanity/pkg-utils` (`_chunks-es`, `_chunks-cjs` and `_chunks-dts`), instead of\n * rolldown's default of placing chunks at the root of the output directory next to the entries.\n * A chunk can otherwise be named like an entry (e.g. code shared between `index` and `theme`\n * entries forms a chunk that rolldown also names `theme`): the JS output deduplicates such\n * filename collisions in favor of the entry, but the d.ts output can resolve them the other way\n * around, handing `theme.d.ts` to the chunk - which re-exports everything under minified aliases -\n * so every named import from the `theme` entry fails to type-check with TS2460\n * (https://github.com/sanity-io/ui/issues/2262).\n */\nfunction resolveChunkFileNames(\n defaultOutputOptions: Rolldown.OutputOptions,\n format: NormalizedFormat,\n): Rolldown.OutputOptions['chunkFileNames'] {\n return (chunk) => {\n // tsdown's default is a `[name]` template string carrying the resolved output extension for\n // the current format and package type (e.g. `[name].mjs`), so reuse it for the file names\n const template =\n (typeof defaultOutputOptions.chunkFileNames === 'function'\n ? defaultOutputOptions.chunkFileNames(chunk)\n : defaultOutputOptions.chunkFileNames) ?? '[name].js'\n // `rolldown-plugin-dts` names d.ts chunks with a `.d` suffix and later rewrites the rendered\n // JS filename to the matching d.ts extension (e.g. `_chunks-dts/[name].mjs` renders\n // `_chunks-dts/theme.mjs`, which becomes `_chunks-dts/theme.d.mts`)\n const folder = chunk.name.endsWith('.d') ? '_chunks-dts' : `_chunks-${format}`\n return `${folder}/${template}`\n }\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 resolveBaseOutputOptions = (\n defaultOptions: Rolldown.OutputOptions,\n outputFormat: NormalizedFormat,\n ) =>\n ({\n hoistTransitiveImports: false,\n chunkFileNames: resolveChunkFileNames(defaultOptions, outputFormat),\n }) satisfies Rolldown.OutputOptions\n\n let outputOptions: UserConfig['outputOptions'] = resolveBaseOutputOptions\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 = (defaultOptions, outputFormat, context) => ({\n ...resolveBaseOutputOptions(defaultOptions, outputFormat),\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":";;;;;;;;;;;;AAoGA,SAAS,sBACP,sBACA,QAC0C;CAC1C,QAAQ,UAAU;EAG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;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.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Shared configuration for tsdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@sanity/browserslist-config": "^1.0.5",
|
|
41
41
|
"@vanilla-extract/rollup-plugin": "^1.5.3",
|
|
42
42
|
"@vitejs/plugin-react": "^6.0.3",
|
|
43
|
-
"browserslist": "^4.28.
|
|
43
|
+
"browserslist": "^4.28.5",
|
|
44
44
|
"lightningcss": "^1.32.0",
|
|
45
45
|
"publint": "^0.3.21"
|
|
46
46
|
},
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"tinyexec": "^1.2.4",
|
|
52
52
|
"tsdown": "^0.22.3",
|
|
53
53
|
"typescript": "6.0.3",
|
|
54
|
-
"vitest": "^4.1.
|
|
55
|
-
"@sanity/pkg-utils": "^10.9.
|
|
54
|
+
"vitest": "^4.1.10",
|
|
55
|
+
"@sanity/pkg-utils": "^10.9.2",
|
|
56
56
|
"@sanity/tsconfig": "^2.2.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"babel-plugin-react-compiler": "*",
|
|
60
|
-
"tsdown": "0.22.
|
|
60
|
+
"tsdown": "0.22.3",
|
|
61
61
|
"typescript": "5.8.x || 5.9.x || 6.0.x"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundleCssShim.mjs","names":[],"sources":["../src/bundleCssShim.ts"],"sourcesContent":["import type {Rolldown} from 'tsdown'\n\n/**\n * Emits a no-op JavaScript shim (`export default \"\"`) alongside the extracted CSS. The conditional\n * `./<css>` export points its `node`/`default` conditions at this file so that the self-referential\n * `import \"<pkg>/<css>\"` resolves to a harmless module in runtimes that cannot import `.css` files,\n * instead of throwing `Error: Unknown file extension \".css\"`.\n *\n * A matching `.d.ts` declaration is emitted next to the shim as well. Both the `browser`/`style`\n * (`<css>`) and the `node`/`default` (`<css>.js`) conditions of the `./<css>` export resolve their\n * types to the same `<css>.d.ts` file, so type-aware tooling (e.g. dts export checkers that load a\n * `.d.ts` for every export target) does not crash on a missing declaration file.\n *\n * @param options.fileName - The shim file name, e.g. `bundle.css.js`.\n * @internal\n */\nexport function bundleCssShim(options: {fileName: string}): Rolldown.Plugin {\n const cssName = options.fileName.replace(/\\.js$/, '')\n\n return {\n name: 'sanity-tsdown-config:bundle-css-shim',\n generateBundle() {\n this.emitFile({\n type: 'asset',\n fileName: options.fileName,\n source: `// No-op shim for \\`${cssName}\\` in runtimes that cannot import \\`.css\\` files directly.\\nexport default \"\"\\n`,\n })\n this.emitFile({\n type: 'asset',\n fileName: `${cssName}.d.ts`,\n source: `// Type declarations for \\`${cssName}\\` and its no-op JS shim.\\ndeclare const _default: string\\nexport default _default\\n`,\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,SAA8C;CAC1E,IAAM,UAAU,QAAQ,SAAS,QAAQ,SAAS,EAAE;CAEpD,OAAO;EACL,MAAM;EACN,iBAAiB;GAMf,AALA,KAAK,SAAS;IACZ,MAAM;IACN,UAAU,QAAQ;IAClB,QAAQ,uBAAuB,QAAQ;GACzC,CAAC,GACD,KAAK,SAAS;IACZ,MAAM;IACN,UAAU,GAAG,QAAQ;IACrB,QAAQ,8BAA8B,QAAQ;GAChD,CAAC;EACH;CACF;AACF"}
|
package/dist/optimizeCss.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"optimizeCss.mjs","names":[],"sources":["../src/optimizeCss.ts"],"sourcesContent":["import {basename} from 'node:path'\nimport browserslist from 'browserslist'\nimport {browserslistToTargets, transform} from 'lightningcss'\nimport type {Rolldown} from 'tsdown'\n\n/**\n * Post-processes the CSS file extracted by `@vanilla-extract/rollup-plugin` with `lightningcss`,\n * applying browserslist targets and (unless disabled) minification. Ported from the equivalent\n * `@sanity/pkg-utils` Rollup plugin.\n * @internal\n */\nexport function optimizeCss(options: {\n extractFileName: string\n browserslist: string | string[]\n minify?: boolean\n}): Rolldown.Plugin {\n return {\n name: 'sanity-tsdown-config:optimize-css',\n\n async generateBundle(_outputOptions, bundle, _isWrite) {\n for (const [fileName, assetOrChunk] of Object.entries(bundle)) {\n // find the extracted CSS asset\n if (assetOrChunk.type === 'asset') {\n const asset = assetOrChunk\n if (\n asset.fileName === options.extractFileName ||\n asset.originalFileNames.includes(options.extractFileName)\n ) {\n const sourceMap = bundle[`${fileName}.map`]\n await transformCss(\n asset,\n sourceMap?.type === 'asset' ? sourceMap : undefined,\n options.browserslist,\n options.minify ?? true,\n )\n }\n }\n }\n },\n }\n}\n\nasync function transformCss(\n asset: Rolldown.OutputAsset,\n sourceMapAsset: Rolldown.OutputAsset | undefined,\n browserslistConfig: string | string[],\n minify: boolean,\n) {\n const css = asset.source.toString()\n const file = asset.fileName\n\n const targets = browserslistToTargets(browserslist(browserslistConfig))\n\n // process (and, unless disabled, minify) css using lightningcss\n const lightningCssResult = transform({\n filename: file,\n code: Buffer.from(css),\n minify,\n cssModules: false,\n targets,\n sourceMap: !!sourceMapAsset,\n inputSourceMap: sourceMapAsset ? sourceMapAsset.source.toString() : undefined,\n })\n\n if (lightningCssResult.warnings.length) {\n console.warn(lightningCssResult.warnings)\n }\n\n asset.source = new TextDecoder().decode(lightningCssResult.code)\n if (sourceMapAsset && lightningCssResult.map) {\n sourceMapAsset.source = new TextDecoder().decode(lightningCssResult.map)\n asset.source += `\\n/*# sourceMappingURL=${basename(sourceMapAsset.fileName)}*/\\n`\n }\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,YAAY,SAIR;CAClB,OAAO;EACL,MAAM;EAEN,MAAM,eAAe,gBAAgB,QAAQ,UAAU;GACrD,KAAK,IAAM,CAAC,UAAU,iBAAiB,OAAO,QAAQ,MAAM,GAE1D,IAAI,aAAa,SAAS,SAAS;IACjC,IAAM,QAAQ;IACd,IACE,MAAM,aAAa,QAAQ,mBAC3B,MAAM,kBAAkB,SAAS,QAAQ,eAAe,GACxD;KACA,IAAM,YAAY,OAAO,GAAG,SAAS;KACrC,MAAM,aACJ,OACA,WAAW,SAAS,UAAU,YAAY,KAAA,GAC1C,QAAQ,cACR,QAAQ,UAAU,EACpB;IACF;GACF;EAEJ;CACF;AACF;AAEA,eAAe,aACb,OACA,gBACA,oBACA,QACA;CACA,IAAM,MAAM,MAAM,OAAO,SAAS,GAC5B,OAAO,MAAM,UAEb,UAAU,sBAAsB,aAAa,kBAAkB,CAAC,GAGhE,qBAAqB,UAAU;EACnC,UAAU;EACV,MAAM,OAAO,KAAK,GAAG;EACrB;EACA,YAAY;EACZ;EACA,WAAW,CAAC,CAAC;EACb,gBAAgB,iBAAiB,eAAe,OAAO,SAAS,IAAI,KAAA;CACtE,CAAC;CAOD,AALI,mBAAmB,SAAS,UAC9B,QAAQ,KAAK,mBAAmB,QAAQ,GAG1C,MAAM,SAAS,IAAI,YAAY,CAAC,CAAC,OAAO,mBAAmB,IAAI,GAC3D,kBAAkB,mBAAmB,QACvC,eAAe,SAAS,IAAI,YAAY,CAAC,CAAC,OAAO,mBAAmB,GAAG,GACvE,MAAM,UAAU,0BAA0B,SAAS,eAAe,QAAQ,EAAE;AAEhF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vanillaExtract.mjs","names":[],"sources":["../src/vanillaExtract.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\nimport path from 'node:path'\nimport type {Options as VanillaExtractPluginOptions} from '@vanilla-extract/rollup-plugin'\nimport type {Rolldown} from 'tsdown'\n\n/** The default name of the extracted CSS file. */\nconst DEFAULT_VANILLA_EXTRACT_CSS_NAME = 'bundle.css'\n\n/**\n * Options for the `@vanilla-extract/rollup-plugin` integration, including the same extensions as\n * `@sanity/pkg-utils` (`minify`, `browserslist`, and `extract.compatMode`).\n * @public\n */\nexport interface PackageVanillaExtractOptions extends Omit<VanillaExtractPluginOptions, 'extract'> {\n /**\n * Minify the extracted CSS with `lightningcss`.\n * @defaultValue true\n */\n minify?: boolean\n /**\n * Browserslist query passed to `lightningcss` when optimizing the extracted CSS.\n * @defaultValue `@sanity/browserslist-config`\n */\n browserslist?: string | string[]\n /**\n * Different formatting of identifiers (e.g. class names, keyframes, CSS Vars, etc).\n * @defaultValue \"short\"\n */\n identifiers?: VanillaExtractPluginOptions['identifiers']\n /**\n * Extract the CSS into a separate file. The CSS is always extracted, so this configures _how_.\n */\n extract?: {\n /**\n * Name of the emitted `.css` file (and, with `compatMode`, the `exports` subpath + shim base).\n * @defaultValue \"bundle.css\"\n */\n name?: string\n /**\n * Generate a `.css.map` sourcemap file.\n * @defaultValue true\n */\n sourcemap?: boolean\n /**\n * Compatibility mode automatically wires up the conditional CSS export pattern so userland does\n * not have to. When enabled, the config:\n *\n * - injects `import \"<pkg-name>/<name>\"` into the `index` entry chunk,\n * - emits a no-op `<name>.js` shim for runtimes that cannot import `.css` files, and\n * - writes the conditional `\"./<name>\"` export to `package.json`\n * (`browser`/`style` → the real CSS, `node`/`default` → the shim).\n *\n * The result is that `import \"<pkg>/<name>\"` resolves to the real CSS in bundlers/browsers and\n * to the no-op shim in Node and similar runtimes. Disable it to wire these up yourself.\n * @defaultValue true\n */\n compatMode?: boolean\n }\n}\n\n/** @internal */\nexport interface ResolvedVanillaExtract {\n enabled: boolean\n /** Normalized options (the object form, or `{}` when `vanillaExtract: true`). */\n options: PackageVanillaExtractOptions\n /**\n * Whether to automatically wire up the conditional CSS export pattern (intro import, JS shim, and\n * the `package.json` export). Only `true` when vanilla-extract is enabled.\n */\n compatMode: boolean\n}\n\n/**\n * Normalize the `vanillaExtract` option into a consistent shape and resolve whether compatibility\n * mode is active.\n * @internal\n */\nexport function resolveVanillaExtract(\n value: boolean | PackageVanillaExtractOptions | undefined,\n): ResolvedVanillaExtract {\n const enabled = Boolean(value)\n const options: PackageVanillaExtractOptions = value === true || !value ? {} : value\n const compatMode = enabled ? (options.extract?.compatMode ?? true) : false\n\n return {enabled, options, compatMode}\n}\n\n/**\n * Resolve the name of the emitted CSS file. Unlike `@sanity/pkg-utils`, tsdown produces a single\n * bundle that is shared across runtimes, so there are no runtime-suffixed defaults.\n * @internal\n */\nexport function resolveVanillaExtractCssName(options: PackageVanillaExtractOptions): string {\n return options.extract?.name ?? DEFAULT_VANILLA_EXTRACT_CSS_NAME\n}\n\n/**\n * Build the conditional CSS export object that vanilla-extract compat mode expects, e.g.\n * ```json\n * {\n * \"browser\": \"./dist/bundle.css\",\n * \"style\": \"./dist/bundle.css\",\n * \"node\": \"./dist/bundle.css.js\",\n * \"default\": \"./dist/bundle.css.js\"\n * }\n * ```\n * @internal\n */\nexport function createConditionalCssExport(\n cssName: string,\n outDir: string,\n): Record<string, string> {\n const cssFile = `./${outDir}/${cssName}`\n const shimFile = `./${outDir}/${cssName}.js`\n return {browser: cssFile, style: cssFile, node: shimFile, default: shimFile}\n}\n\n/**\n * Insert (or replace) the `\"./<cssName>\"` export in an `exports`-shaped map, preserving the\n * existing order and placing it before `./package.json` when present. Used with tsdown's\n * `exports.customExports` so both `exports` and `publishConfig.exports` receive the entry.\n * @internal\n */\nexport function insertCssExport(\n exports: Record<string, unknown>,\n exportKey: string,\n conditionalExport: Record<string, string>,\n): Record<string, unknown> {\n const nextExports: Record<string, unknown> = {}\n let inserted = false\n for (const [key, value] of Object.entries(exports)) {\n if (key === exportKey) continue\n if (key === './package.json' && !inserted) {\n nextExports[exportKey] = conditionalExport\n inserted = true\n }\n nextExports[key] = value\n }\n if (!inserted) {\n nextExports[exportKey] = conditionalExport\n }\n return nextExports\n}\n\nconst RE_DTS = /\\.d\\.[cm]?ts$/\n\n/**\n * Build an `intro` function that prepends `autoImport` to the `index` entry chunk only. The\n * `.d.ts` chunks generated by tsdown share the build, so they are explicitly excluded.\n * @internal\n */\nexport function composeIntro(autoImport: string): (chunk: Rolldown.RenderedChunk) => string {\n return (chunk) =>\n chunk.isEntry && chunk.name === 'index' && !RE_DTS.test(chunk.fileName) ? `${autoImport}\\n` : ''\n}\n\n/**\n * Resolve the package name from `package.json`, required by compat mode to inject the\n * self-referential CSS import.\n * @internal\n */\nexport function readPackageName(cwd: string): string {\n const pkgPath = path.resolve(cwd, 'package.json')\n // oxlint-disable-next-line no-unsafe-type-assertion\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as {name?: unknown}\n if (typeof pkg.name !== 'string' || !pkg.name) {\n throw new Error(\n `Unable to resolve the package name from ${pkgPath}, which is required by \\`vanillaExtract\\` compat mode to inject the self-referential CSS import. Set \\`vanillaExtract: {extract: {compatMode: false}}\\` to wire up the CSS export manually.`,\n )\n }\n return pkg.name\n}\n"],"mappings":";;;;;;;AA6EA,SAAgB,sBACd,OACwB;CACxB,IAAM,UAAU,EAAQ,OAClB,UAAwC,UAAU,MAAQ,CAAC,QAAQ,CAAC,IAAI;CAG9E,OAAO;EAAC;EAAS;EAAS,YAFP,UAAW,QAAQ,SAAS,cAAc,KAAQ;CAEjC;AACtC;;;;;;AAOA,SAAgB,6BAA6B,SAA+C;CAC1F,OAAO,QAAQ,SAAS,QAAQ;AAClC;;;;;;;;;;;;;AAcA,SAAgB,2BACd,SACA,QACwB;CACxB,IAAM,UAAU,KAAK,OAAO,GAAG,WACzB,WAAW,KAAK,OAAO,GAAG,QAAQ;CACxC,OAAO;EAAC,SAAS;EAAS,OAAO;EAAS,MAAM;EAAU,SAAS;CAAQ;AAC7E;;;;;;;AAQA,SAAgB,gBACd,SACA,WACA,mBACyB;CACzB,IAAM,cAAuC,CAAC,GAC1C,WAAW;CACf,KAAK,IAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAC3C,QAAQ,cACR,QAAQ,oBAAoB,CAAC,aAC/B,YAAY,aAAa,mBACzB,WAAW,KAEb,YAAY,OAAO;CAKrB,OAHK,aACH,YAAY,aAAa,oBAEpB;AACT;AAEA,MAAM,SAAS;;;;;;AAOf,SAAgB,aAAa,YAA+D;CAC1F,QAAQ,UACN,MAAM,WAAW,MAAM,SAAS,WAAW,CAAC,OAAO,KAAK,MAAM,QAAQ,IAAI,GAAG,WAAW,MAAM;AAClG;;;;;;AAOA,SAAgB,gBAAgB,KAAqB;CACnD,IAAM,UAAU,KAAK,QAAQ,KAAK,cAAc,GAE1C,MAAM,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC;CACpD,IAAI,OAAO,IAAI,QAAS,YAAY,CAAC,IAAI,MACvC,MAAU,MACR,2CAA2C,QAAQ,4LACrD;CAEF,OAAO,IAAI;AACb"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|