@sanity/pkg-utils 12.1.3 → 12.3.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 +27 -3
- package/dist/{buildAction-HQvn8xA1.js → buildAction-ntNgCJfA.js} +2 -2
- package/dist/{buildAction-HQvn8xA1.js.map → buildAction-ntNgCJfA.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +27 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/{resolveTsdownConfig-I9zyPE-E.js → resolveTsdownConfig-DunhV2W-.js} +3 -2
- package/dist/{resolveTsdownConfig-I9zyPE-E.js.map → resolveTsdownConfig-DunhV2W-.js.map} +1 -1
- package/dist/{watchAction-BiD7pJr4.js → watchAction-BcwDTNcj.js} +3 -3
- package/dist/{watchAction-BiD7pJr4.js.map → watchAction-BcwDTNcj.js.map} +1 -1
- package/dist/{writeBundleCssExports-BK5XC19e.js → writeBundleCssExports-DlqASssv.js} +2 -2
- package/dist/{writeBundleCssExports-BK5XC19e.js.map → writeBundleCssExports-DlqASssv.js.map} +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -84,6 +84,26 @@ export default defineConfig({
|
|
|
84
84
|
An array of entry points to bundle. This is useful if you want to bundle something that should not
|
|
85
85
|
be exported by the package, e.g. CLI scripts or Node.js workers.
|
|
86
86
|
|
|
87
|
+
#### `bundleAnalyzer`
|
|
88
|
+
|
|
89
|
+
- Type: `boolean | PackageBundleAnalyzerOptions`
|
|
90
|
+
- Default: `false`
|
|
91
|
+
|
|
92
|
+
Enables Rolldown's experimental
|
|
93
|
+
[`bundleAnalyzerPlugin`](https://rolldown.rs/builtin-plugins/bundle-analyzer) to emit a report of
|
|
94
|
+
what the package itself bundles. Pass `true` for the defaults (`format: 'md'`, an LLM-friendly
|
|
95
|
+
`analyze-data.md` in `dist`), or an options object to customize. Analysis adds work to the build,
|
|
96
|
+
so this stays off by default — typical usage is an env-gated opt-in:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
export default defineConfig({
|
|
100
|
+
bundleAnalyzer: process.env.ENABLE_BUNDLE_ANALYZER === 'true',
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The report is **not** a publishable artifact. Exclude it from `package.json` `files` (e.g.
|
|
105
|
+
`"!dist/analyze-data.md"`) so an accidental analyze build cannot ship it.
|
|
106
|
+
|
|
87
107
|
#### `clean`
|
|
88
108
|
|
|
89
109
|
- Type: `boolean | string[]`
|
|
@@ -168,9 +188,13 @@ pkg-utils sets up. Most Rollup plugins are also compatible.
|
|
|
168
188
|
- Type: `boolean | ReactCompilerOptions`
|
|
169
189
|
- Default: `false`
|
|
170
190
|
|
|
171
|
-
Runs
|
|
172
|
-
|
|
173
|
-
|
|
191
|
+
Runs the React Compiler on the source files before they are bundled, so published components
|
|
192
|
+
are memoized automatically. Pass `true` for the defaults, or an options object
|
|
193
|
+
(e.g. `{target: '18'}`).
|
|
194
|
+
|
|
195
|
+
`transform` picks the compiler implementation: `'babel'` (default, install
|
|
196
|
+
`babel-plugin-react-compiler`) or the experimental `'oxc'` (install `oxc-transform-react`) —
|
|
197
|
+
[details and caveats](https://github.com/sanity-io/pkg-utils/tree/main/packages/@sanity/tsdown-config#transforms-transform).
|
|
174
198
|
|
|
175
199
|
#### `runtime`
|
|
176
200
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as createLogger, r as isRecord, t as handleError } from "./handleError-83GwKIFM.js";
|
|
2
2
|
import { a as loadPkgWithReporting, o as loadConfig, t as resolveBuildContext } from "./resolveBuildContext-vVTRkIDl.js";
|
|
3
3
|
import { t as createSpinner } from "./spinner-DAHe7SuT.js";
|
|
4
|
-
import { r as resolveTsdownBuilds, t as resolveTsdownConfig } from "./resolveTsdownConfig-
|
|
4
|
+
import { r as resolveTsdownBuilds, t as resolveTsdownConfig } from "./resolveTsdownConfig-DunhV2W-.js";
|
|
5
5
|
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { up } from "empathic/package";
|
|
@@ -147,4 +147,4 @@ async function buildAction(options) {
|
|
|
147
147
|
}
|
|
148
148
|
export { buildAction };
|
|
149
149
|
|
|
150
|
-
//# sourceMappingURL=buildAction-
|
|
150
|
+
//# sourceMappingURL=buildAction-ntNgCJfA.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildAction-HQvn8xA1.js","names":["build","findPkgPath","tsdownBuild","build"],"sources":["../src/node/build.ts","../src/cli/buildAction.ts"],"sourcesContent":["import {existsSync, readFileSync, rmSync, writeFileSync} from 'node:fs'\nimport path from 'node:path'\nimport {up as findPkgPath} from 'empathic/package'\nimport {build as tsdownBuild, type TsdownBundle} from 'tsdown'\nimport {loadConfig} from './core/config/loadConfig.ts'\nimport {isRecord} from './core/isRecord.ts'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting.ts'\nimport {createLogger, type Logger} from './logger.ts'\nimport {resolveBuildContext} from './resolveBuildContext.ts'\nimport {createSpinner} from './spinner.ts'\nimport {\n resolveTsdownBuilds,\n type TsdownBuild as TsdownBuildDef,\n} from './tasks/tsdown/resolveTsdownBuilds.ts'\nimport {resolveTsdownConfig} from './tasks/tsdown/resolveTsdownConfig.ts'\n\nconst RE_TS_SOURCE = /\\.[cm]?tsx?$/\n\n/**\n * Build the distribution files of a npm package.\n *\n * @example\n * ```ts\n * import {build} from '@sanity/pkg-utils'\n *\n * build({\n * cwd: process.cwd(),\n * tsconfig: 'tsconfig.dist.json,\n * }).then(() => {\n * console.log('successfully built')\n * }).catch((err) => {\n * console.log(`build error: ${err.message}`)\n * })\n * ```\n *\n * @public\n */\nexport async function build(options: {\n cwd: string\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n const {\n cwd,\n emitDeclarationOnly,\n strict = false,\n tsconfig: tsconfigOption,\n // `--no-clean` skips cleaning for this run; `true` (the CLI default — `--clean` still\n // parses as a no-op for v11 compatibility) defers to the `clean` config option\n clean = true,\n quiet = false,\n } = options\n const logger = createLogger(quiet)\n\n const pkgPath = findPkgPath({cwd})\n if (!pkgPath) {\n throw new Error('no package.json found', {cause: {cwd}})\n }\n const config = await loadConfig({cwd, pkgPath})\n\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({pkgPath, logger, strict, strictOptions})\n\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n const ctx = await resolveBuildContext({\n config,\n cwd,\n emitDeclarationOnly,\n logger,\n pkg,\n strict,\n tsconfig,\n })\n\n warnAboutTsdownConfigFiles(cwd, logger)\n\n const builds = resolveTsdownBuilds(ctx)\n\n let first = true\n for (const buildDef of builds) {\n // A types-only run skips builds without TypeScript sources entirely\n if (\n ctx.emitDeclarationOnly &&\n !buildDef.entries.some((entry) => RE_TS_SOURCE.test(entry.source))\n ) {\n continue\n }\n\n const taskName = buildTaskName(buildDef)\n const spinner = createSpinner(taskName, quiet)\n\n try {\n const inlineConfig = await resolveTsdownConfig(ctx, buildDef, {clean: first && clean})\n first = false\n\n const bundles = await tsdownBuild(inlineConfig)\n\n if (ctx.emitDeclarationOnly) {\n // `dts.emitDtsOnly` suppresses the JS chunks of the ES pass, but the CJS pass emits\n // its JS regardless (only its extra dts pass runs the dts plugin) — a types-only\n // build removes everything that is not a declaration file\n removeNonDeclarationOutputs(bundles)\n }\n\n if (buildDef.canonical) {\n restoreAuthoredTypes(ctx)\n }\n\n spinner.complete()\n ctx.logger.log()\n\n printBuildOutputs(ctx, bundles, buildDef)\n ctx.logger.log()\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(escapeRegExp(cwd), 'g')\n\n ctx.logger.error((err.stack || err.message).replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n process.exit(1)\n }\n }\n}\n\nfunction buildTaskName(buildDef: TsdownBuildDef): string {\n const formats = Array.from(new Set(buildDef.entries.flatMap((entry) => entry.formats)))\n return `build ${buildDef.key} (${formats.join(', ') || 'types'})`\n}\n\nconst RE_DTS_OUTPUT = /\\.d\\.[mc]?ts(\\.map)?$/\n\n/** Removes every emitted file that is not a declaration file (or its sourcemap). */\nfunction removeNonDeclarationOutputs(bundles: TsdownBundle[]): void {\n for (const bundle of bundles) {\n for (const chunk of bundle.chunks) {\n if (RE_DTS_OUTPUT.test(chunk.fileName)) continue\n rmSync(path.join(chunk.outDir, chunk.fileName), {force: true})\n rmSync(path.join(chunk.outDir, `${chunk.fileName}.map`), {force: true})\n }\n }\n}\n\n/**\n * Prints `<pkg>: <source> → <output>` for every entry chunk (JS and `.d.ts`) that tsdown\n * emitted, mirroring the per-file output of previous majors.\n */\nfunction printBuildOutputs(\n ctx: {\n cwd: string\n distPath: string\n emitDeclarationOnly: boolean\n logger: Logger\n pkg: {name: string}\n },\n bundles: TsdownBundle[],\n buildDef: TsdownBuildDef,\n): void {\n const {cwd, logger, pkg} = ctx\n const lines = new Set<string>()\n\n // Stylesheets are emitted as assets, which carry no `facadeModuleId` back to their source,\n // so the stylesheet build's lines come from its entry map instead.\n if (buildDef.css) {\n for (const entry of buildDef.entries) {\n const output = `./${path\n .relative(cwd, path.join(ctx.distPath, `${entry.alias}.css`))\n .replaceAll('\\\\', '/')}`\n lines.add(\n `${pkg.name}: ./${path.relative(cwd, path.resolve(cwd, entry.source)).replaceAll('\\\\', '/')} \\u2192 ${output}`,\n )\n }\n }\n\n for (const bundle of bundles) {\n for (const chunk of bundle.chunks) {\n if (chunk.type !== 'chunk' || !chunk.isEntry || !chunk.facadeModuleId) continue\n if (ctx.emitDeclarationOnly && !RE_DTS_OUTPUT.test(chunk.fileName)) continue\n const source = `./${path\n .relative(cwd, chunk.facadeModuleId)\n .replaceAll('\\\\', '/')\n // the dts chunks facade the fake `.d.ts` module ids of rolldown-plugin-dts; print the\n // actual `.ts` source instead\n .replace(/\\.d\\.([mc]?)ts$/, '.$1ts')}`\n const output = `./${path\n .relative(cwd, path.join(chunk.outDir, chunk.fileName))\n .replaceAll('\\\\', '/')}`\n lines.add(`${pkg.name}: ${source} \\u2192 ${output}`)\n }\n }\n\n for (const line of Array.from(lines).toSorted()) {\n logger.log(line)\n }\n}\n\n/**\n * tsdown's exports generation rewrites the top-level `types` field alongside `main`/`module`\n * when the `legacy` fields are maintained, preferring the CJS declarations (`.d.cts`) for\n * dual-format packages. The hand-written value is authoritative here (the Sanity convention\n * points `types` at the ESM `.d.ts`), so it is restored after the canonical build.\n */\nfunction restoreAuthoredTypes(ctx: {cwd: string; pkg: {types?: string | undefined}}): void {\n const authoredTypes = ctx.pkg.types\n if (!authoredTypes) return\n\n const pkgPath = path.resolve(ctx.cwd, 'package.json')\n let text: string\n try {\n text = readFileSync(pkgPath, 'utf8')\n } catch {\n return\n }\n const json: unknown = JSON.parse(text)\n if (!isRecord(json) || json['types'] === authoredTypes) return\n json['types'] = authoredTypes\n\n const indent = /^([ \\t]+)\\S/m.exec(text)?.[1] ?? 2\n let output = JSON.stringify(json, null, indent)\n if (text.endsWith('\\n')) output += '\\n'\n writeFileSync(pkgPath, output, 'utf8')\n}\n\n/**\n * pkg-utils owns its own experience: `tsdown.config.*` files are never loaded in pkg-utils\n * mode (`package.config.ts` is the sole config source), so their presence is worth a warning.\n */\nfunction warnAboutTsdownConfigFiles(cwd: string, logger: Logger): void {\n const candidates = [\n 'tsdown.config.ts',\n 'tsdown.config.mts',\n 'tsdown.config.cts',\n 'tsdown.config.js',\n 'tsdown.config.mjs',\n 'tsdown.config.cjs',\n 'tsdown.config.json',\n ]\n const found = candidates.find((candidate) => existsSync(path.resolve(cwd, candidate)))\n if (found) {\n logger.warn(\n `found \\`${found}\\`, which @sanity/pkg-utils does not load — \\`package.config.ts\\` is the only config source of \\`pkg build\\`. Either migrate the package fully to tsdown (and drop @sanity/pkg-utils), or move the configuration into \\`package.config.ts\\`.`,\n )\n }\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n","import {build} from '../node/build.ts'\nimport {handleError} from './handleError.ts'\n\nexport async function buildAction(options: {\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n try {\n await build({\n cwd: process.cwd(),\n emitDeclarationOnly: options.emitDeclarationOnly,\n strict: options.strict,\n tsconfig: options.tsconfig,\n clean: options.clean,\n quiet: options.quiet,\n })\n } catch (err) {\n handleError(err)\n }\n}\n"],"mappings":";;;;;;;;AAgBA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;AAqBrB,eAAsBA,QAAM,SAOV;CAChB,IAAM,EACJ,KACA,qBACA,SAAS,IACT,UAAU,gBAGV,QAAQ,IACR,QAAQ,OACN,SACE,SAAS,aAAa,KAAK,GAE3B,UAAUC,GAAY,EAAC,IAAG,CAAC;CACjC,IAAI,CAAC,SACH,MAAU,MAAM,yBAAyB,EAAC,OAAO,EAAC,IAAG,EAAC,CAAC;CAEzD,IAAM,SAAS,MAAM,WAAW;EAAC;EAAK;CAAO,CAAC,GAExC,EAAC,uBAAsB,MAAM,OAAO,oCAAc,CAAA,MAAA,MAAA,EAAA,CAAA,GAClD,gBAAgB,mBAAmB,QAAQ,iBAAiB,CAAC,CAAC,GAC9D,MAAM,MAAM,qBAAqB;EAAC;EAAS;EAAQ;EAAQ;CAAa,CAAC,GAEzE,WAAW,kBAAkB,QAAQ,YAAY,iBAEjD,MAAM,MAAM,oBAAoB;EACpC;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,2BAA2B,KAAK,MAAM;CAEtC,IAAM,SAAS,oBAAoB,GAAG,GAElC,QAAQ;CACZ,KAAK,IAAM,YAAY,QAAQ;EAE7B,IACE,IAAI,uBACJ,CAAC,SAAS,QAAQ,MAAM,UAAU,aAAa,KAAK,MAAM,MAAM,C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,UAAa,eAAe;CACxD,KAAK,QAAW;CAEhB,IAAM,SAAS,eAAe,KAAK,IAAI,CAAC,GAAG,MAAM,GAC7C,SAAS,KAAK,UAAU,MAAM,MAAM,MAAM;CAE9C,AADI,KAAK,SAAS,IAAI,MAAG,UAAU,OACnC,cAAc,SAAS,QAAQ,MAAM;AACvC;;;;;AAMA,SAAS,2BAA2B,KAAa,QAAsB;CAUrE,IAAM,QAAQ;EARZ;EACA;EACA;EACA;EACA;EACA;EACA;CAEqB,CAAC,CAAC,MAAM,cAAc,WAAW,KAAK,QAAQ,KAAK,SAAS,CAAC,CAAC;CACrF,AAAI,SACF,OAAO,KACL,WAAW,MAAM,6OACnB;AAEJ;AAEA,SAAS,aAAa,OAAuB;CAC3C,OAAO,MAAM,QAAQ,uBAAuB,MAAM;AACpD;AC5PA,eAAsB,YAAY,SAMhB;CAChB,IAAI;EACF,MAAMC,QAAM;GACV,KAAK,QAAQ,IAAI;GACjB,qBAAqB,QAAQ;GAC7B,QAAQ,QAAQ;GAChB,UAAU,QAAQ;GAClB,OAAO,QAAQ;GACf,OAAO,QAAQ;EACjB,CAAC;CACH,SAAS,KAAK;EACZ,YAAY,GAAG;CACjB;AACF"}
|
|
1
|
+
{"version":3,"file":"buildAction-ntNgCJfA.js","names":["build","findPkgPath","tsdownBuild","build"],"sources":["../src/node/build.ts","../src/cli/buildAction.ts"],"sourcesContent":["import {existsSync, readFileSync, rmSync, writeFileSync} from 'node:fs'\nimport path from 'node:path'\nimport {up as findPkgPath} from 'empathic/package'\nimport {build as tsdownBuild, type TsdownBundle} from 'tsdown'\nimport {loadConfig} from './core/config/loadConfig.ts'\nimport {isRecord} from './core/isRecord.ts'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting.ts'\nimport {createLogger, type Logger} from './logger.ts'\nimport {resolveBuildContext} from './resolveBuildContext.ts'\nimport {createSpinner} from './spinner.ts'\nimport {\n resolveTsdownBuilds,\n type TsdownBuild as TsdownBuildDef,\n} from './tasks/tsdown/resolveTsdownBuilds.ts'\nimport {resolveTsdownConfig} from './tasks/tsdown/resolveTsdownConfig.ts'\n\nconst RE_TS_SOURCE = /\\.[cm]?tsx?$/\n\n/**\n * Build the distribution files of a npm package.\n *\n * @example\n * ```ts\n * import {build} from '@sanity/pkg-utils'\n *\n * build({\n * cwd: process.cwd(),\n * tsconfig: 'tsconfig.dist.json,\n * }).then(() => {\n * console.log('successfully built')\n * }).catch((err) => {\n * console.log(`build error: ${err.message}`)\n * })\n * ```\n *\n * @public\n */\nexport async function build(options: {\n cwd: string\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n const {\n cwd,\n emitDeclarationOnly,\n strict = false,\n tsconfig: tsconfigOption,\n // `--no-clean` skips cleaning for this run; `true` (the CLI default — `--clean` still\n // parses as a no-op for v11 compatibility) defers to the `clean` config option\n clean = true,\n quiet = false,\n } = options\n const logger = createLogger(quiet)\n\n const pkgPath = findPkgPath({cwd})\n if (!pkgPath) {\n throw new Error('no package.json found', {cause: {cwd}})\n }\n const config = await loadConfig({cwd, pkgPath})\n\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({pkgPath, logger, strict, strictOptions})\n\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n const ctx = await resolveBuildContext({\n config,\n cwd,\n emitDeclarationOnly,\n logger,\n pkg,\n strict,\n tsconfig,\n })\n\n warnAboutTsdownConfigFiles(cwd, logger)\n\n const builds = resolveTsdownBuilds(ctx)\n\n let first = true\n for (const buildDef of builds) {\n // A types-only run skips builds without TypeScript sources entirely\n if (\n ctx.emitDeclarationOnly &&\n !buildDef.entries.some((entry) => RE_TS_SOURCE.test(entry.source))\n ) {\n continue\n }\n\n const taskName = buildTaskName(buildDef)\n const spinner = createSpinner(taskName, quiet)\n\n try {\n const inlineConfig = await resolveTsdownConfig(ctx, buildDef, {clean: first && clean})\n first = false\n\n const bundles = await tsdownBuild(inlineConfig)\n\n if (ctx.emitDeclarationOnly) {\n // `dts.emitDtsOnly` suppresses the JS chunks of the ES pass, but the CJS pass emits\n // its JS regardless (only its extra dts pass runs the dts plugin) — a types-only\n // build removes everything that is not a declaration file\n removeNonDeclarationOutputs(bundles)\n }\n\n if (buildDef.canonical) {\n restoreAuthoredTypes(ctx)\n }\n\n spinner.complete()\n ctx.logger.log()\n\n printBuildOutputs(ctx, bundles, buildDef)\n ctx.logger.log()\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(escapeRegExp(cwd), 'g')\n\n ctx.logger.error((err.stack || err.message).replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n process.exit(1)\n }\n }\n}\n\nfunction buildTaskName(buildDef: TsdownBuildDef): string {\n const formats = Array.from(new Set(buildDef.entries.flatMap((entry) => entry.formats)))\n return `build ${buildDef.key} (${formats.join(', ') || 'types'})`\n}\n\nconst RE_DTS_OUTPUT = /\\.d\\.[mc]?ts(\\.map)?$/\n\n/** Removes every emitted file that is not a declaration file (or its sourcemap). */\nfunction removeNonDeclarationOutputs(bundles: TsdownBundle[]): void {\n for (const bundle of bundles) {\n for (const chunk of bundle.chunks) {\n if (RE_DTS_OUTPUT.test(chunk.fileName)) continue\n rmSync(path.join(chunk.outDir, chunk.fileName), {force: true})\n rmSync(path.join(chunk.outDir, `${chunk.fileName}.map`), {force: true})\n }\n }\n}\n\n/**\n * Prints `<pkg>: <source> → <output>` for every entry chunk (JS and `.d.ts`) that tsdown\n * emitted, mirroring the per-file output of previous majors.\n */\nfunction printBuildOutputs(\n ctx: {\n cwd: string\n distPath: string\n emitDeclarationOnly: boolean\n logger: Logger\n pkg: {name: string}\n },\n bundles: TsdownBundle[],\n buildDef: TsdownBuildDef,\n): void {\n const {cwd, logger, pkg} = ctx\n const lines = new Set<string>()\n\n // Stylesheets are emitted as assets, which carry no `facadeModuleId` back to their source,\n // so the stylesheet build's lines come from its entry map instead.\n if (buildDef.css) {\n for (const entry of buildDef.entries) {\n const output = `./${path\n .relative(cwd, path.join(ctx.distPath, `${entry.alias}.css`))\n .replaceAll('\\\\', '/')}`\n lines.add(\n `${pkg.name}: ./${path.relative(cwd, path.resolve(cwd, entry.source)).replaceAll('\\\\', '/')} \\u2192 ${output}`,\n )\n }\n }\n\n for (const bundle of bundles) {\n for (const chunk of bundle.chunks) {\n if (chunk.type !== 'chunk' || !chunk.isEntry || !chunk.facadeModuleId) continue\n if (ctx.emitDeclarationOnly && !RE_DTS_OUTPUT.test(chunk.fileName)) continue\n const source = `./${path\n .relative(cwd, chunk.facadeModuleId)\n .replaceAll('\\\\', '/')\n // the dts chunks facade the fake `.d.ts` module ids of rolldown-plugin-dts; print the\n // actual `.ts` source instead\n .replace(/\\.d\\.([mc]?)ts$/, '.$1ts')}`\n const output = `./${path\n .relative(cwd, path.join(chunk.outDir, chunk.fileName))\n .replaceAll('\\\\', '/')}`\n lines.add(`${pkg.name}: ${source} \\u2192 ${output}`)\n }\n }\n\n for (const line of Array.from(lines).toSorted()) {\n logger.log(line)\n }\n}\n\n/**\n * tsdown's exports generation rewrites the top-level `types` field alongside `main`/`module`\n * when the `legacy` fields are maintained, preferring the CJS declarations (`.d.cts`) for\n * dual-format packages. The hand-written value is authoritative here (the Sanity convention\n * points `types` at the ESM `.d.ts`), so it is restored after the canonical build.\n */\nfunction restoreAuthoredTypes(ctx: {cwd: string; pkg: {types?: string | undefined}}): void {\n const authoredTypes = ctx.pkg.types\n if (!authoredTypes) return\n\n const pkgPath = path.resolve(ctx.cwd, 'package.json')\n let text: string\n try {\n text = readFileSync(pkgPath, 'utf8')\n } catch {\n return\n }\n const json: unknown = JSON.parse(text)\n if (!isRecord(json) || json['types'] === authoredTypes) return\n json['types'] = authoredTypes\n\n const indent = /^([ \\t]+)\\S/m.exec(text)?.[1] ?? 2\n let output = JSON.stringify(json, null, indent)\n if (text.endsWith('\\n')) output += '\\n'\n writeFileSync(pkgPath, output, 'utf8')\n}\n\n/**\n * pkg-utils owns its own experience: `tsdown.config.*` files are never loaded in pkg-utils\n * mode (`package.config.ts` is the sole config source), so their presence is worth a warning.\n */\nfunction warnAboutTsdownConfigFiles(cwd: string, logger: Logger): void {\n const candidates = [\n 'tsdown.config.ts',\n 'tsdown.config.mts',\n 'tsdown.config.cts',\n 'tsdown.config.js',\n 'tsdown.config.mjs',\n 'tsdown.config.cjs',\n 'tsdown.config.json',\n ]\n const found = candidates.find((candidate) => existsSync(path.resolve(cwd, candidate)))\n if (found) {\n logger.warn(\n `found \\`${found}\\`, which @sanity/pkg-utils does not load — \\`package.config.ts\\` is the only config source of \\`pkg build\\`. Either migrate the package fully to tsdown (and drop @sanity/pkg-utils), or move the configuration into \\`package.config.ts\\`.`,\n )\n }\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n","import {build} from '../node/build.ts'\nimport {handleError} from './handleError.ts'\n\nexport async function buildAction(options: {\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n try {\n await build({\n cwd: process.cwd(),\n emitDeclarationOnly: options.emitDeclarationOnly,\n strict: options.strict,\n tsconfig: options.tsconfig,\n clean: options.clean,\n quiet: options.quiet,\n })\n } catch (err) {\n handleError(err)\n }\n}\n"],"mappings":";;;;;;;;AAgBA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;AAqBrB,eAAsBA,QAAM,SAOV;CAChB,IAAM,EACJ,KACA,qBACA,SAAS,IACT,UAAU,gBAGV,QAAQ,IACR,QAAQ,OACN,SACE,SAAS,aAAa,KAAK,GAE3B,UAAUC,GAAY,EAAC,IAAG,CAAC;CACjC,IAAI,CAAC,SACH,MAAU,MAAM,yBAAyB,EAAC,OAAO,EAAC,IAAG,EAAC,CAAC;CAEzD,IAAM,SAAS,MAAM,WAAW;EAAC;EAAK;CAAO,CAAC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/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { cac } from "cac";
|
|
2
|
-
var version = "12.
|
|
2
|
+
var version = "12.3.0";
|
|
3
3
|
const cli = cac();
|
|
4
4
|
cli.command("", "Check").alias("check").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").action(async (options) => {
|
|
5
5
|
let { checkAction } = await import("./checkAction-DWSqzrZd.js");
|
|
6
6
|
return checkAction(options);
|
|
7
7
|
}), cli.command("build", "Build package").option("--emitDeclarationOnly", "Emit d.ts only").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").option("--check", "Run the check command after build (same as running `pkg build && pkg check`)").option("--no-clean", "Skip cleaning the `dist` folder before the build").option("--quiet", "Suppress all output except errors, warnings, and checks").action(async (options) => {
|
|
8
|
-
let { check = !1, ...buildOptions } = options, { buildAction } = await import("./buildAction-
|
|
8
|
+
let { check = !1, ...buildOptions } = options, { buildAction } = await import("./buildAction-ntNgCJfA.js");
|
|
9
9
|
if (await buildAction(buildOptions), check) {
|
|
10
10
|
let { checkAction } = await import("./checkAction-DWSqzrZd.js");
|
|
11
11
|
await checkAction({
|
|
@@ -17,7 +17,7 @@ cli.command("", "Check").alias("check").option("--strict", "Strict mode").option
|
|
|
17
17
|
let { initAction } = await import("./initAction-CmOO8eod.js");
|
|
18
18
|
return initAction({ path: p });
|
|
19
19
|
}), cli.command("watch", "Watch package").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").action(async (options) => {
|
|
20
|
-
let { watchAction } = await import("./watchAction-
|
|
20
|
+
let { watchAction } = await import("./watchAction-BcwDTNcj.js");
|
|
21
21
|
return watchAction(options);
|
|
22
22
|
}), cli.help(), cli.version(version), cli.parse();
|
|
23
23
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PkgExport, PkgExports, PkgExports as PkgExports$1 } from "@sanity/parse-package-json";
|
|
2
|
-
import { PackageCssOptions, PackageTsdocCustomTag, PackageTsdocCustomTag as PackageTsdocCustomTag$1, PackageTsdocOptions, PackageTsdocOptions as PackageTsdocOptions$1, PackageTsdocRuleLevel, PackageTsdocRuleLevel as PackageTsdocRuleLevel$1, PackageVanillaExtractOptions, PackageVanillaExtractOptions as PackageVanillaExtractOptions$1, ReactCompilerOptions, ReactCompilerOptions as ReactCompilerOptions$1, StyledComponentsOptions, StyledComponentsOptions as StyledComponentsOptions$1 } from "@sanity/tsdown-config";
|
|
2
|
+
import { PackageBundleAnalyzerOptions, PackageBundleAnalyzerOptions as PackageBundleAnalyzerOptions$1, PackageCssOptions, PackageTsdocCustomTag, PackageTsdocCustomTag as PackageTsdocCustomTag$1, PackageTsdocOptions, PackageTsdocOptions as PackageTsdocOptions$1, PackageTsdocRuleLevel, PackageTsdocRuleLevel as PackageTsdocRuleLevel$1, PackageVanillaExtractOptions, PackageVanillaExtractOptions as PackageVanillaExtractOptions$1, ReactCompilerBabelOptions, ReactCompilerConfigOptions, ReactCompilerOptions, ReactCompilerOptions as ReactCompilerOptions$1, ReactCompilerOxcOptions, StyledComponentsOptions, StyledComponentsOptions as StyledComponentsOptions$1 } from "@sanity/tsdown-config";
|
|
3
3
|
import { UserConfig } from "tsdown";
|
|
4
4
|
type ToggleType = "error" | "warn" | "off";
|
|
5
5
|
/**
|
|
@@ -156,6 +156,25 @@ type PkgTsdocOptions = PackageTsdocOptions$1;
|
|
|
156
156
|
/** @public */
|
|
157
157
|
interface PkgConfigOptions {
|
|
158
158
|
bundles?: PkgBundle[];
|
|
159
|
+
/**
|
|
160
|
+
* Enables Rolldown's experimental
|
|
161
|
+
* [`bundleAnalyzerPlugin`](https://rolldown.rs/builtin-plugins/bundle-analyzer) to emit a
|
|
162
|
+
* report of what the package itself bundles. Pass `true` for the defaults (`format: 'md'`,
|
|
163
|
+
* an LLM-friendly `analyze-data.md` in `dist`), or an options object to customize.
|
|
164
|
+
*
|
|
165
|
+
* Analysis adds work to the build, so this stays off by default — typical usage is an
|
|
166
|
+
* env-gated opt-in:
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* bundleAnalyzer: process.env.ENABLE_BUNDLE_ANALYZER === 'true'
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* The report is **not** a publishable artifact. Exclude it from `package.json` `files`
|
|
173
|
+
* (e.g. `"!dist/analyze-data.md"`) so an accidental analyze build cannot ship it.
|
|
174
|
+
* @defaultValue false
|
|
175
|
+
* @alpha This option wraps Rolldown's experimental analyzer, whose API may change.
|
|
176
|
+
*/
|
|
177
|
+
bundleAnalyzer?: boolean | PackageBundleAnalyzerOptions$1;
|
|
159
178
|
/**
|
|
160
179
|
* tsdown's `clean` option, passed through as-is. Cleaning is on by default: `true` (the
|
|
161
180
|
* default) cleans the `dist` folder before the build, `false` skips cleaning, and a
|
|
@@ -236,16 +255,17 @@ interface PkgConfigOptions {
|
|
|
236
255
|
minify?: boolean;
|
|
237
256
|
/**
|
|
238
257
|
* Extra rolldown plugins, appended after the plugins pkg-utils sets up (React Compiler,
|
|
239
|
-
* vanilla-extract). Most Rollup plugins are also compatible.
|
|
258
|
+
* vanilla-extract, bundle analyzer). Most Rollup plugins are also compatible.
|
|
240
259
|
* @see https://tsdown.dev/advanced/plugins
|
|
241
260
|
* @alpha
|
|
242
261
|
*/
|
|
243
262
|
plugins?: UserConfig["plugins"];
|
|
244
263
|
/**
|
|
245
|
-
* Runs
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* `babel-plugin-react-compiler`
|
|
264
|
+
* Runs the React Compiler on the source files before they are bundled, so published
|
|
265
|
+
* components are memoized automatically. Pass `true` to use the defaults, or an options
|
|
266
|
+
* object (e.g. `{target: '18'}`). `transform` picks the implementation: `'babel'`
|
|
267
|
+
* (default, requires `babel-plugin-react-compiler`) or the experimental `'oxc'` (requires
|
|
268
|
+
* `oxc-transform-react`, the Rust port).
|
|
249
269
|
*/
|
|
250
270
|
reactCompiler?: boolean | ReactCompilerOptions$1;
|
|
251
271
|
/**
|
|
@@ -362,5 +382,5 @@ interface PkgTemplateStringOption<T = string> {
|
|
|
362
382
|
type PkgTemplateOption<T = string> = PkgTemplateStringOption<T>;
|
|
363
383
|
/** @public */
|
|
364
384
|
declare function defineTemplateOption<T>(option: PkgTemplateOption<T>): PkgTemplateOption<T>;
|
|
365
|
-
export { DEFAULT_BROWSERSLIST_QUERY, type PackageTsdocCustomTag, type PackageTsdocOptions, type PackageTsdocRuleLevel, type PackageVanillaExtractOptions, type PkgBundle, type PkgConfigOptions, type PkgConfigProperty, type PkgConfigPropertyResolver, type PkgExport, type PkgExports, type PkgFormat, type PkgRuleLevel, type PkgRuntime, type PkgTsdocOptions, type ReactCompilerOptions, type StyledComponentsOptions, type TSDocCustomTag, defineConfig, defineTemplateOption, loadConfig };
|
|
385
|
+
export { DEFAULT_BROWSERSLIST_QUERY, type PackageBundleAnalyzerOptions, type PackageTsdocCustomTag, type PackageTsdocOptions, type PackageTsdocRuleLevel, type PackageVanillaExtractOptions, type PkgBundle, type PkgConfigOptions, type PkgConfigProperty, type PkgConfigPropertyResolver, type PkgExport, type PkgExports, type PkgFormat, type PkgRuleLevel, type PkgRuntime, type PkgTsdocOptions, type ReactCompilerBabelOptions, type ReactCompilerConfigOptions, type ReactCompilerOptions, type ReactCompilerOxcOptions, type StyledComponentsOptions, type TSDocCustomTag, defineConfig, defineTemplateOption, loadConfig };
|
|
366
386
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/node/strict.ts","../src/node/core/config/types.ts","../src/node/core/config/defineConfig.ts","../src/node/core/config/loadConfig.ts","../src/node/core/defaults.ts","../src/node/core/template/types.ts","../src/node/core/template/define.ts"],"mappings":";;;KAKK;;;;UAwCY;;;;;EAKf,sBAAsB;;;;;EAKtB,uBAAuB;;;;;;;;;EASvB,wBAAwB;;;;;EAKxB,wBAAwB;;;;;EAKxB,wBAAwB;;;;;EAKxB,cAAc;;;;;EAKd,sBAAsB;;;;;EAKtB,4BAA4B;;;;;EAK5B,kBAAkB;;;;;EAKlB,wBAAwB;;;;;EAKxB,yBAAyB;;;;;EAKzB,0BAA0B;;;;;EAK1B,6BAA6B;;;;;EAK7B,oBAAoB;;;;;EAKpB,8BAA8B;;;;;EAK9B,mBAAmB;;;;;EAKnB,sBAAsB;;;;;EAKtB,wBAAwB;;;;;EAKxB,2BAA2B;;;;;EAK3B,uBAAuB;;;;;EAKvB,sBAAsB;;;;;EAKtB,8BAA8B;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/node/strict.ts","../src/node/core/config/types.ts","../src/node/core/config/defineConfig.ts","../src/node/core/config/loadConfig.ts","../src/node/core/defaults.ts","../src/node/core/template/types.ts","../src/node/core/template/define.ts"],"mappings":";;;KAKK;;;;UAwCY;;;;;EAKf,sBAAsB;;;;;EAKtB,uBAAuB;;;;;;;;;EASvB,wBAAwB;;;;;EAKxB,wBAAwB;;;;;EAKxB,wBAAwB;;;;;EAKxB,cAAc;;;;;EAKd,sBAAsB;;;;;EAKtB,4BAA4B;;;;;EAK5B,kBAAkB;;;;;EAKlB,wBAAwB;;;;;EAKxB,yBAAyB;;;;;EAKzB,0BAA0B;;;;;EAK1B,6BAA6B;;;;;EAK7B,oBAAoB;;;;;EAKpB,8BAA8B;;;;;EAK9B,mBAAmB;;;;;EAKnB,sBAAsB;;;;;EAKtB,wBAAwB;;;;;EAKxB,2BAA2B;;;;;EAK3B,uBAAuB;;;;;EAKvB,sBAAsB;;;;;EAKtB,8BAA8B;;;KCjIpB;;KAGA;;KAGA,0BAA0B,MAAM,MAAM,MAAM;;KAG5C,kBAAkB,KAAK,0BAA0B,KAAK;;UAGjD;EACf;EACA;EACA;EACA,UAAU;;;;;;KAOA,eAAe;;;;;KAMf,iBAAiB;;;;;;;KAQjB,kBAAkB;;UAGb;EACf,UAAU;;;;;;;;;;;;;;;;;;;EAmBV,2BAA2B;;;;;;;;;EAS3B,QAAQ;;;;;;;;;;;;;;;;;;;;EAoBR,MAAM;;EAEN,SAAS;;;;;;;;EAQT,OAAO;;;;EAIP;;;;;;;EAOA,cAAc,QAAQ,YAAY;EAClC,UAAU,kBAAkB;;;;;;;;;;;EAW5B,WAAW;;;;;;;;EAQX;;;;;;;;EAQA;;;;;;;EAOA,UAAU;;;;;;;;EAQV,0BAA0B;;;;EAI1B,UAAU;EACV;;;;EAIA;;;;EAIA,gBAAgB,QAAQ;;;;;;;EAOxB,6BAA6B;EAC7B;;;;;;;EAOA,kBAAkB;;;;;;;;;;EAUlB,2BAA2B;;;;;;;EAa3B;;;;;;;;EAQA;;;;;EAKA;;;;;EAKA;;;;;EAKA;;;;;EAKA;;;;;EAKA;;;;;;;;EAQA;;;;;EAKA;;;iBCrRc,mBAAmB,UAAU,kBAAkB,eAAe,IAAI;;iBCK5D,WAAW;EAC/B;EACA;IACE,QAAQ;;cCRC;;UCMI,wBAAwB;EACvC;EACA;EACA;EACA,UAAU,MAAM,SAAS,wBAAwB;EACjD,SAAS,cAAc;EACvB,YAAY;;;KAIF,kBAAkB,cAAc,wBAAwB;;iBChBpD,qBAAqB,GAAG,QAAQ,kBAAkB,KAAK,kBAAkB"}
|
|
@@ -385,6 +385,7 @@ async function resolveTsdownConfig(ctx, build, options) {
|
|
|
385
385
|
reactCompiler: config?.reactCompiler,
|
|
386
386
|
styledComponents: config?.styledComponents,
|
|
387
387
|
vanillaExtract: config?.vanillaExtract,
|
|
388
|
+
bundleAnalyzer: config?.bundleAnalyzer,
|
|
388
389
|
tsdoc: !options.watch && tsdocOption
|
|
389
390
|
}), extMap = pkgExtMap[pkg.type === "module" ? "module" : "commonjs"], outExtensions = ({ format: outputFormat }) => ({ js: outputFormat === "cjs" ? extMap.commonjs : extMap.esm });
|
|
390
391
|
return {
|
|
@@ -421,7 +422,7 @@ function createWatchCssExportsHook(ctx, css) {
|
|
|
421
422
|
return (hooks) => {
|
|
422
423
|
hooks.hook("build:done", async ({ chunks }) => {
|
|
423
424
|
if (mergedCssName === void 0 || !chunks.some((chunk) => chunk.type === "asset" && chunk.fileName === mergedCssName)) return;
|
|
424
|
-
let { writeBundleCssExports } = await import("./writeBundleCssExports-
|
|
425
|
+
let { writeBundleCssExports } = await import("./writeBundleCssExports-DlqASssv.js").then((n) => n.n);
|
|
425
426
|
await writeBundleCssExports({
|
|
426
427
|
cwd: ctx.cwd,
|
|
427
428
|
distPath: ctx.distPath,
|
|
@@ -433,4 +434,4 @@ function createWatchCssExportsHook(ctx, css) {
|
|
|
433
434
|
}
|
|
434
435
|
export { createConditionalCssExport as n, resolveTsdownBuilds as r, resolveTsdownConfig as t };
|
|
435
436
|
|
|
436
|
-
//# sourceMappingURL=resolveTsdownConfig-
|
|
437
|
+
//# sourceMappingURL=resolveTsdownConfig-DunhV2W-.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveTsdownConfig-I9zyPE-E.js","names":[],"sources":["../src/node/tasks/tsdown/resolveTsdownBuilds.ts","../src/node/core/pkg/cssShimFileName.ts","../src/node/core/pkg/cssExport.ts","../src/node/tasks/tsdown/composeExports.ts","../src/node/tasks/tsdown/resolveTsdownConfig.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgFormat, PkgRuntime} from '../../core/config/types.ts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {fileEnding} from '../../core/pkg/pkgExt.ts'\n\n/**\n * One entry of a tsdown build.\n * @internal\n */\nexport interface TsdownBuildEntry {\n /**\n * The entry alias handed to tsdown: the output path relative to `dist` without the\n * extension (e.g. `index`, `index.browser`, `sub/feature`), so the emitted filenames match\n * the hand-written `exports` targets exactly.\n */\n alias: string\n source: string\n /** The hand-written export subpath this entry backs (`undefined` for `bundles`). */\n exportPath?: string\n /** The formats the hand-written exports declare for this entry. */\n formats: PkgFormat[]\n}\n\n/**\n * One tsdown `build()` call of the waterfall. Builds run serially — variants and bundles\n * first, the canonical build last, so its exports generation and publint see every emitted\n * file on disk.\n * @internal\n */\nexport interface TsdownBuild {\n /** Stable identifier, e.g. `neutral`, `browser`, `node`, `bundles`, `css`. */\n key: string\n runtime: PkgRuntime\n /** The canonical build owns `dist` conventions: exports generation runs here. */\n canonical: boolean\n entries: TsdownBuildEntry[]\n /**\n * The stylesheet build: its entries are `.css` files rather than JS, so it emits CSS assets\n * (one per entry) and no JS at all. It runs on its own because a `.css` entry has nothing to\n * declare types for, and because its per-entry CSS output needs `css.splitting`.\n */\n css?: boolean\n}\n\n/** The build key of the stylesheet build. */\nconst CSS_BUILD_KEY = 'css'\n\n/**\n * Collapses the hand-written `exports` map (+ `bundles`) into the per-platform tsdown build\n * waterfall: one canonical build for the package's default runtime, plus a variant build per\n * `browser`/`node` exports condition, plus builds for `bundles` (which must not participate\n * in exports generation).\n * @internal\n */\nexport function resolveTsdownBuilds(ctx: BuildContext): TsdownBuild[] {\n const {config, cwd, distPath, logger} = ctx\n\n const entryAlias = (output: string): string => {\n const alias = path\n .relative(distPath, path.resolve(cwd, output))\n .replaceAll('\\\\', '/')\n .replace(fileEnding, '')\n if (alias.startsWith('..')) {\n throw new Error(`output file is outside the \\`dist\\` folder: ${output}`)\n }\n return alias\n }\n\n interface EntryDraft {\n alias: string\n source: string\n exportPath?: string | undefined\n formats: Set<PkgFormat>\n }\n\n const draftsByBuild = new Map<string, Map<string, EntryDraft>>()\n const runtimeByBuild = new Map<string, PkgRuntime>()\n\n const addEntry = (\n buildKey: string,\n runtime: PkgRuntime,\n entry: {\n source: string\n exportPath?: string | undefined\n import?: string | undefined\n require?: string | undefined\n },\n ) => {\n runtimeByBuild.set(buildKey, runtime)\n const {source, exportPath} = entry\n const aliases = new Set<string>()\n const formats = new Set<PkgFormat>()\n if (entry.import) {\n aliases.add(entryAlias(entry.import))\n formats.add('esm')\n }\n if (entry.require) {\n aliases.add(entryAlias(entry.require))\n formats.add('commonjs')\n }\n if (aliases.size === 0) return\n if (aliases.size > 1) {\n throw new Error(\n `the \\`import\\` and \\`require\\` targets of ${\n exportPath ? `exports[\"${exportPath}\"]` : `the bundle for ${source}`\n } must share a basename (e.g. \\`./dist/index.js\\` + \\`./dist/index.cjs\\`), ` +\n `got: ${entry.import} and ${entry.require}`,\n )\n }\n const [alias] = aliases\n let drafts = draftsByBuild.get(buildKey)\n if (!drafts) {\n drafts = new Map()\n draftsByBuild.set(buildKey, drafts)\n }\n const existing = drafts.get(alias!)\n if (existing) {\n if (existing.source !== source) {\n throw new Error(\n `conflicting sources for the output alias \"${alias}\": ${existing.source} and ${source}`,\n )\n }\n for (const format of formats) existing.formats.add(format)\n return\n }\n drafts.set(alias!, {alias: alias!, source, exportPath, formats})\n }\n\n const exports = Object.entries(ctx.exports || {})\n const packageType = ctx.pkg.type === 'module' ? 'module' : 'commonjs'\n const resolveRuntimeTargets = (condition: {\n import?: string\n require?: string\n default?: string\n }) => ({\n import: condition.import ?? (packageType === 'module' ? condition.default : undefined),\n require: condition.require ?? (packageType === 'commonjs' ? condition.default : undefined),\n })\n\n let hasRuntimeConditions = false\n\n for (const [exportPath, exp] of exports) {\n addEntry('canonical', ctx.runtime, {\n source: exp.source,\n exportPath,\n import: exp.import,\n require: exp.require,\n })\n\n const browserTargets = exp.browser && resolveRuntimeTargets(exp.browser)\n if (exp.browser && browserTargets && (browserTargets.import || browserTargets.require)) {\n hasRuntimeConditions = true\n addEntry('browser', 'browser', {\n source: exp.browser.source || exp.source,\n exportPath,\n ...browserTargets,\n })\n }\n\n const nodeTargets = exp.node && resolveRuntimeTargets(exp.node)\n if (exp.node && nodeTargets && (nodeTargets.import || nodeTargets.require)) {\n hasRuntimeConditions = true\n addEntry('node', 'node', {\n source: exp.node.source || exp.source,\n exportPath,\n ...nodeTargets,\n })\n }\n }\n\n // `bundles` are extra entrypoints that are deliberately not in the exports map (CLI workers\n // and similar), so they build separately from the canonical build — exports generation\n // derives subpaths from every entry of its build, and bundles must never become export\n // subpaths of their own.\n for (const bundle of config?.bundles || []) {\n const runtime = bundle.runtime || ctx.runtime\n addEntry(runtime === ctx.runtime ? 'bundles' : `bundles:${runtime}`, runtime, {\n source: bundle.source,\n import: bundle.import,\n require: bundle.require,\n })\n }\n\n if (hasRuntimeConditions) {\n logger.warn(\n [\n 'The `exports[].browser.source` / `exports[].node.source` pattern is not recommended: every',\n 'runtime condition adds a full extra build (complexity and build time). Consider instead:',\n ' 1. separate npm packages per platform/runtime, selected through export conditions that',\n ' pick the right package per environment,',\n ' 2. when possible, a single neutral build using JS that works in both runtimes without',\n ' special-casing (e.g. `new URL` over `require(\"url\")`, WebCrypto over',\n ' `require(\"crypto\")`), or',\n ' 3. using `tsdown` + `@sanity/tsdown-config` directly, exporting an array from',\n ' `tsdown.config.ts` with one config per `platform` — the fully supported path for',\n ' this level of customization.',\n ].join('\\n'),\n )\n }\n\n const builds: TsdownBuild[] = []\n\n // `.css` export subpaths that declare a `source` build in their own pass: their entries are\n // stylesheets, so the emitted file name follows the export subpath (`./ui/styles.css` ->\n // `dist/ui/styles.css`) instead of an `import`/`require` target, and `dts` has nothing to do.\n const cssEntries: TsdownBuildEntry[] = ctx.cssExports.map((cssExport) => ({\n alias: cssEntryAlias(cssExport._path),\n source: cssExport.source,\n exportPath: cssExport._path,\n formats: ['esm'],\n }))\n if (cssEntries.length) {\n builds.push({\n key: CSS_BUILD_KEY,\n runtime: ctx.runtime,\n canonical: false,\n entries: cssEntries,\n css: true,\n })\n }\n\n const toBuild = (key: string, runtime: PkgRuntime, canonical: boolean): TsdownBuild | null => {\n const drafts = draftsByBuild.get(key)\n if (!drafts || drafts.size === 0) return null\n return {\n key,\n runtime,\n canonical,\n entries: Array.from(drafts.values(), (draft) => ({\n alias: draft.alias,\n source: draft.source,\n ...(draft.exportPath === undefined ? {} : {exportPath: draft.exportPath}),\n formats: Array.from(draft.formats),\n })),\n }\n }\n\n // Variants and bundles run first; the canonical build runs last so its exports generation\n // and publint see the other builds' files on disk. Each build's runtime was recorded when\n // its entries were added, so nothing is re-derived from the build key (a bundle with\n // `runtime: '*'` in a `runtime: 'node'` package must build for `'*'`/neutral).\n for (const key of draftsByBuild.keys()) {\n if (key === 'canonical') continue\n const build = toBuild(key, runtimeByBuild.get(key) ?? ctx.runtime, false)\n if (build) builds.push(build)\n }\n\n const canonical = toBuild('canonical', ctx.runtime, true)\n if (canonical) builds.push(canonical)\n\n return builds\n}\n\n/**\n * The tsdown entry alias of a `.css` export subpath: the subpath without its leading `./` and\n * `.css` ending, so `@tsdown/css` (with `splitting`) emits the stylesheet at exactly the path\n * the subpath promises — `\"./ui/styles.css\"` -> alias `ui/styles` -> `dist/ui/styles.css`.\n */\nfunction cssEntryAlias(exportPath: string): string {\n return exportPath.replace(/^\\.\\//, '').replace(/\\.css$/, '')\n}\n","/**\n * The no-op JS shim file name for a CSS file under vanilla-extract compat mode.\n *\n * `bundle.css` → `bundle-css.js` — deliberately not `${cssFileName}.js` (`bundle.css.js`),\n * which vanilla-extract's `cssFileFilter` (`/\\.css\\.(js|cjs|mjs|jsx|ts|tsx)$/`) would treat as\n * a stylesheet module. Kept in sync with `cssShimFileName` in\n * `@sanity/vanilla-extract-rolldown-plugin`.\n *\n * @internal\n */\nexport function cssShimFileName(cssFileName: string): string {\n return `${cssFileName.replace(/\\.css$/, '-css')}.js`\n}\n\n/**\n * The `.d.ts` companion for {@link cssShimFileName}. `bundle.css` → `bundle-css.d.ts`.\n *\n * @internal\n */\nexport function cssShimDtsFileName(cssFileName: string): string {\n return `${cssFileName.replace(/\\.css$/, '-css')}.d.ts`\n}\n","import path from 'node:path'\nimport {cssShimDtsFileName, cssShimFileName} from './cssShimFileName.ts'\n\n/**\n * Build the conditional CSS export object that `exports.nodeCompat` expects, e.g.\n * ```json\n * {\n * \"types\": \"./dist/bundle-css.d.ts\",\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 * The shim is named `bundle-css.js` (not `bundle.css.js`) so it does not match\n * vanilla-extract's `cssFileFilter`. An explicit `types` condition (rather than relying on\n * TypeScript's extension-substitution fallback, which only works when the shim shares the CSS\n * file's basename, and which TypeScript is deprecating anyway - microsoft/TypeScript#50762)\n * points resolvers straight at the shim's declaration file.\n *\n * Kept in sync with `createConditionalCssExport` in `@sanity/vanilla-extract-tsdown-plugin`,\n * which writes the same entry through tsdown's `exports.customExports` during full builds.\n *\n * @internal\n */\nexport function createConditionalCssExport(\n cssName: string,\n distRel: string,\n): Record<string, string> {\n const cssFile = `./${path.posix.join(distRel, cssName)}`\n const shimFile = `./${path.posix.join(distRel, cssShimFileName(cssName))}`\n const shimDtsFile = `./${path.posix.join(distRel, cssShimDtsFileName(cssName))}`\n return {types: shimDtsFile, browser: cssFile, style: cssFile, node: shimFile, default: shimFile}\n}\n","import path from 'node:path'\nimport type {PkgExport} from '../../core/config/types.ts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {isRecord} from '../../core/isRecord.ts'\nimport {createConditionalCssExport} from '../../core/pkg/cssExport.ts'\nimport type {TsdownBuild} from './resolveTsdownBuilds.ts'\n\ntype ExportsMap = Record<string, unknown>\ninterface ComposeContext {\n isPublish: boolean\n}\n\n/**\n * The pkg-utils opinion layer over tsdown's generated `exports` map, composed into\n * `exports.customExports` of the canonical build (the same composition hook\n * `@sanity/vanilla-extract-tsdown-plugin` uses for its conditional CSS export).\n *\n * tsdown generates subpaths from the entry aliases with `source`/`import`/`require` conditions\n * (`devExports: 'source'`) and a `source`-less `publishConfig.exports` — already the Sanity\n * convention. This composer reconciles the generated map with the hand-written one, which\n * remains the input:\n *\n * - generated keys are remapped to the hand-written subpaths (entry aliases are derived from\n * the output paths, which don't have to match the subpath names),\n * - the hand-written `types`, `browser`, `node`, `development` and `monorepo` conditions are\n * re-inserted (tsdown's generator cannot express them; the `browser`/`node` files are built\n * by the variant builds of the waterfall) — with `source`-like conditions stripped from the\n * publish variant,\n * - all hand-written conditions (`react-server`, `worker`, … included) retain their authored\n * order in each map independently, because earlier matching conditions take precedence,\n * - generated conditions for conditional entries are materialized in both `exports` and\n * `publishConfig.exports`, so they can be reordered directly in `package.json` and keep that\n * position on later builds (plain-string entries stay compact),\n * - a trailing `default` condition is kept on dual-format entries and nested runtime variants\n * (tsdown emits bare `import`/`require` pairs; the Sanity convention always ends with\n * `default`),\n * - hand-written subpaths that aren't build entries (`.css`/`.json` exports, `svelte`\n * entries) are carried over untouched, and\n * - the hand-written subpath and condition key order of each map is preserved.\n * @internal\n */\nexport function createExportsComposer(\n ctx: BuildContext,\n build: TsdownBuild,\n): (exportsMap: ExportsMap, context: ComposeContext) => ExportsMap {\n const {pkg} = ctx\n const type = pkg.type === 'module' ? 'module' : 'commonjs'\n\n // POSIX separators: on Windows `path.relative` yields backslashes, which must never leak\n // into generated `package.json` export targets.\n const distRel = (path.relative(ctx.cwd, ctx.distPath) || 'dist').split(path.sep).join('/')\n const cssExportPaths = new Set(ctx.cssExports.map((cssExport) => cssExport._path))\n const cssSources: Record<string, string> = {}\n for (const cssExport of ctx.cssExports) {\n cssSources[cssExport._path] = cssExport.source\n }\n\n // alias -> hand-written subpath, e.g. `index` -> `.`, `sub/feature` -> `./feature`\n const aliasToExportPath = new Map<string, string>()\n for (const entry of build.entries) {\n if (entry.exportPath !== undefined) {\n aliasToExportPath.set(entry.alias, entry.exportPath)\n }\n }\n\n return (exportsMap, context) => {\n const {isPublish} = context\n\n // 1. Remap the generated keys (`.` for the `index` alias, `./<alias>` otherwise) back to\n // the hand-written subpaths.\n const remapped: ExportsMap = {}\n for (const [key, value] of Object.entries(exportsMap)) {\n const alias = key === '.' ? 'index' : key.startsWith('./') ? key.slice(2) : key\n const exportPath = aliasToExportPath.get(alias) ?? key\n remapped[exportPath] = value\n }\n\n // 2. Reconcile each generated entry with its hand-written counterpart.\n const result: ExportsMap = {}\n const handwritten = ctx.exports || {}\n const sourceRaw: ExportsMap = pkg.exports || {}\n const publishRaw: ExportsMap | undefined = pkg.publishConfig?.exports\n const authoredRaw = isPublish && publishRaw ? publishRaw : sourceRaw\n\n const reconcile = (exportPath: string, value: unknown): unknown => {\n const exp = handwritten[exportPath]\n if (!exp) return value\n const raw = authoredRaw[exportPath]\n const source = sourceRaw[exportPath]\n // A configured exports map is itself authoritative. Otherwise use the raw package entry\n // for the map being generated. Fall back to `exports` when a new publish map/entry is\n // being generated, so inferred conditions don't masquerade as ordering choices.\n const authored =\n ctx.config?.exports === undefined\n ? isRecord(raw)\n ? raw\n : isRecord(source)\n ? source\n : exp\n : exp\n return reconcileEntry(exp, value, {authored, isPublish, type})\n }\n\n // 3. Follow the hand-written key order of the map being generated. Source-only passthrough\n // subpaths missing from an existing publish map are appended, followed by generated extras.\n const authoredPaths = Object.keys(authoredRaw)\n for (const exportPath of Object.keys(sourceRaw)) {\n if (!Object.prototype.hasOwnProperty.call(authoredRaw, exportPath)) {\n authoredPaths.push(exportPath)\n }\n }\n for (const exportPath of authoredPaths) {\n if (exportPath in remapped) {\n result[exportPath] = reconcile(exportPath, remapped[exportPath])\n } else if (cssExportPaths.has(exportPath)) {\n // A `.css` subpath with a `source` is built by the stylesheet build, which does not\n // participate in exports generation (its entries are stylesheets, not JS). Its\n // conditions are materialized here instead, from the export subpath: `./ui/styles.css`\n // is built to `<dist>/ui/styles.css` with the shim next to it.\n result[exportPath] = reconcileCssEntry(exportPath, {\n distRel,\n source: cssSources[exportPath],\n isPublish,\n })\n } else {\n // Hand-written subpaths that aren't build entries (plain `.css`/`.json` exports,\n // `svelte` entries) pass through untouched.\n result[exportPath] = Object.prototype.hasOwnProperty.call(authoredRaw, exportPath)\n ? authoredRaw[exportPath]\n : sourceRaw[exportPath]\n }\n }\n for (const [exportPath, value] of Object.entries(remapped)) {\n if (exportPath in result) continue\n result[exportPath] = reconcile(exportPath, value)\n }\n\n return result\n }\n}\n\n/**\n * The conditional CSS export of a `.css` subpath built by the stylesheet build. `source`\n * resolves at development time, so it is kept in `exports` and stripped from the publish\n * variant — the same split the build entries get.\n */\nfunction reconcileCssEntry(\n exportPath: string,\n options: {distRel: string; source: string | undefined; isPublish: boolean},\n): Record<string, string> {\n const {distRel, source, isPublish} = options\n const cssName = exportPath.replace(/^\\.\\//, '')\n const conditions = createConditionalCssExport(cssName, distRel)\n return isPublish || source === undefined ? conditions : {source, ...conditions}\n}\n\n/**\n * Rebuilds a generated subpath entry in its authored condition order, re-inserting the\n * hand-written conditions tsdown's generator cannot express.\n */\nfunction reconcileEntry(\n exp: PkgExport,\n generated: unknown,\n options: {authored: object; isPublish: boolean; type: 'commonjs' | 'module'},\n): unknown {\n const {authored, isPublish, type} = options\n const authoredRecord = isRecord(authored) ? authored : {}\n\n // tsdown's publish variant of a single-format entry is a plain string\n const gen: Record<string, unknown> | undefined =\n typeof generated === 'string'\n ? {default: generated}\n : isRecord(generated)\n ? generated\n : undefined\n if (!gen) return generated\n\n const browserOrder = isRecord(authoredRecord['browser']) ? authoredRecord['browser'] : exp.browser\n const browser =\n exp.browser && (exp.browser.import || exp.browser.require || exp.browser.default)\n ? pickConditions(exp.browser, {\n authored: browserOrder ?? exp.browser,\n isPublish,\n type,\n })\n : undefined\n const nodeOrder = isRecord(authoredRecord['node']) ? authoredRecord['node'] : exp.node\n const node =\n exp.node && (exp.node.import || exp.node.require || exp.node.default)\n ? pickConditions(exp.node, {\n authored: nodeOrder ?? exp.node,\n isPublish,\n type,\n })\n : undefined\n const custom = pickCustomConditions(exp)\n\n // Preserve tsdown's compact single-format publish shape unless hand-written conditions need\n // to be re-inserted. There is no condition ordering to preserve in a plain string entry.\n if (typeof generated === 'string' && !exp.types && !browser && !node && custom.length === 0) {\n return generated\n }\n\n const next: Record<string, unknown> = {}\n\n // `source`-like conditions resolve at development time and are stripped from the publish\n // variant (tsdown already does this for `source`; `development`/`monorepo` follow)\n if (!isPublish) {\n if (typeof gen['source'] === 'string') next['source'] = gen['source']\n else if (exp.source) next['source'] = exp.source\n if (exp.development) next['development'] = exp.development\n if (exp.monorepo) next['monorepo'] = exp.monorepo\n }\n\n if (exp.types) next['types'] = exp.types\n if (browser) next['browser'] = browser\n if (node) next['node'] = node\n\n // Hand-written custom conditions (`react-server`, `worker`, …) aren't built, but they are\n // the author's: carry their targets over, then restore every condition's authored position.\n for (const [condition, target] of custom) {\n const authoredTarget = authoredRecord[condition]\n next[condition] =\n isRecord(target) && isRecord(authoredTarget)\n ? preserveConditionOrder(target, authoredTarget)\n : target\n }\n\n if (typeof gen['import'] === 'string' && typeof gen['require'] === 'string') {\n next['import'] = gen['import']\n next['require'] = gen['require']\n // tsdown emits bare `import`/`require` pairs; the Sanity convention ends with `default`\n next['default'] = type === 'module' ? gen['import'] : gen['require']\n } else {\n // Single-format entries keep the generated shape (`{source, default}` in development)\n for (const [condition, target] of Object.entries(gen)) {\n if (condition in next || condition === 'source') continue\n next[condition] = target\n }\n }\n\n return preserveConditionOrder(next, authored)\n}\n\n/**\n * The hand-written `browser`/`node` condition object, minus `source` for the publish map.\n * A nested runtime condition must have its own fallback: once a resolver matches `node` or\n * `browser`, an unmatched module-format condition otherwise backtracks to the outer entry.\n */\nfunction pickConditions(\n conditions: {source?: string; import?: string; require?: string; default?: string},\n options: {\n authored?: object\n isPublish: boolean\n type: 'commonjs' | 'module'\n },\n): Record<string, string> {\n const {authored = conditions, isPublish, type} = options\n const next: Record<string, string> = {}\n if (!isPublish && conditions.source) next['source'] = conditions.source\n if (conditions.import) next['import'] = conditions.import\n if (conditions.require) next['require'] = conditions.require\n const fallback =\n conditions.default ?? (type === 'module' ? conditions.import : conditions.require)\n if (fallback) next['default'] = fallback\n return preserveConditionOrder(next, authored)\n}\n\n/**\n * Reorders reconciled conditions to match their hand-written order. Conditions generated by\n * tsdown but absent from the hand-written entry are inserted before its `default` fallback.\n */\nfunction preserveConditionOrder<T>(\n conditions: Record<string, T>,\n authored: object,\n): Record<string, T> {\n const entries: [string, T][] = []\n const added = new Set<string>()\n const conditionEntries = Object.entries(conditions)\n const entriesByCondition = new Map(conditionEntries.map((entry) => [entry[0], entry]))\n const authoredOrder = Object.keys(authored).filter((condition) => !condition.startsWith('_'))\n const authoredConditions = new Set(authoredOrder)\n\n const addGeneratedConditions = () => {\n for (const entry of conditionEntries) {\n if (!authoredConditions.has(entry[0]) && !added.has(entry[0])) {\n entries.push(entry)\n added.add(entry[0])\n }\n }\n }\n\n for (const condition of authoredOrder) {\n // A generated condition has no authored position. Keep the explicit `default` as the final\n // fallback by placing generated conditions immediately before it.\n if (condition === 'default') addGeneratedConditions()\n const entry = entriesByCondition.get(condition)\n if (!entry) continue\n entries.push(entry)\n added.add(condition)\n }\n\n addGeneratedConditions()\n\n return Object.fromEntries(entries)\n}\n\n/** The conditions the pipeline owns (or re-inserts itself) on a build entry. */\nconst managedConditions = new Set([\n 'source',\n 'development',\n 'monorepo',\n 'types',\n 'browser',\n 'node',\n 'import',\n 'require',\n 'default',\n])\n\n/**\n * Hand-written conditions the pipeline knows nothing about (`react-server`, `worker`,\n * `edge-light`, …), in authored order. `parseExports` spreads the raw entry, so they survive\n * on the parsed `PkgExport` beyond its typed fields.\n */\nfunction pickCustomConditions(exp: PkgExport): [string, unknown][] {\n return Object.entries(exp).filter(\n ([condition, target]) =>\n !managedConditions.has(condition) && !condition.startsWith('_') && target !== undefined,\n )\n}\n","import path from 'node:path'\nimport {defineConfig} from '@sanity/tsdown-config'\nimport {mergeConfig, type InlineConfig, type UserConfig} from 'tsdown'\nimport type {PkgConfigOptions} from '../../core/config/types.ts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {pkgExtMap} from '../../core/pkg/pkgExt.ts'\nimport {createExportsComposer} from './composeExports.ts'\nimport type {TsdownBuild} from './resolveTsdownBuilds.ts'\n\nconst RE_TS_SOURCE = /\\.[cm]?tsx?$/\n\n/**\n * Composes the tsdown config for one build of the waterfall: `@sanity/tsdown-config`'s\n * `defineConfig()` provides the shared Sanity base, and the pkg-utils opinions (browserslist\n * targets, `PKG_*` defines, exports reconciliation, dts selection) layer over it with\n * tsdown's `mergeConfig`.\n *\n * pkg-utils owns its own experience: the returned config carries `config: false`, so tsdown\n * never loads `tsdown.config.*` files — `package.config.ts` is the sole config source — and\n * `logLevel: 'warn'` keeps tsdown's info chatter out of pkg-utils' own output.\n * @internal\n */\nexport async function resolveTsdownConfig(\n ctx: BuildContext,\n build: TsdownBuild,\n options: {\n /**\n * Whether this build may clean: only the first build of the waterfall cleans (so later\n * builds can't wipe earlier output), and `--no-clean` turns it off for the whole run.\n */\n clean: boolean\n watch?: boolean\n },\n): Promise<InlineConfig> {\n const {config, cwd, distPath, pkg} = ctx\n\n const reactCompiler = config?.reactCompiler\n if (typeof reactCompiler === 'object' && reactCompiler.reactServer === true) {\n throw new Error(\n [\n 'package.config.ts: `reactCompiler.reactServer` is not supported by `pkg build` — the',\n 'dual React Server Components build needs one tsdown run driving multiple configs.',\n 'Use `tsdown` + `@sanity/tsdown-config` directly instead: export the config from',\n '`tsdown.config.ts` and build with `tsdown`.',\n ].join('\\n'),\n )\n }\n\n const entry: Record<string, string> = {}\n for (const buildEntry of build.entries) {\n entry[buildEntry.alias] = buildEntry.source\n }\n\n // tsdown's `format` applies to the whole build (and its exports generation composes the\n // dual `import`/`require` map from both formats' chunks of one build), so the entries'\n // formats union: every entry is emitted in every format of the build. Mixed per-entry\n // coverage gets a heads-up — the extra files are emitted, and local exports generation\n // will declare them.\n const formats = new Set(build.entries.flatMap((buildEntry) => buildEntry.formats))\n if (formats.size > 1) {\n const partial = build.entries.filter((buildEntry) => buildEntry.formats.length < formats.size)\n if (partial.length) {\n const names = partial\n .map((buildEntry) =>\n buildEntry.exportPath ? `exports[\"${buildEntry.exportPath}\"]` : buildEntry.source,\n )\n .join(', ')\n ctx.logger.warn(\n `${names} declare${partial.length === 1 ? 's' : ''} fewer formats than the rest of the package. tsdown emits every format of a build for every entry, so the missing format is built anyway (and local exports generation will declare it). Declare both \\`import\\` and \\`require\\` targets for every subpath — or for none — to keep the exports map unambiguous.`,\n )\n }\n }\n const format = [\n ...(formats.has('esm') ? ['esm' as const] : []),\n ...(formats.has('commonjs') ? ['cjs' as const] : []),\n ]\n\n const platform =\n build.runtime === 'node' ? 'node' : build.runtime === 'browser' ? 'browser' : 'neutral'\n\n // The `@tsdown/css` pipeline turns on when it's configured, and automatically for a package\n // that declares a `.css` export subpath with a `source`. The stylesheet build needs\n // `splitting` so each entry emits its own file at the path its subpath promises; the JS\n // builds keep `@tsdown/css`'s merged default, so CSS imported from JS lands in a single\n // `style.css` with one export and one injected import - the `bundle.css` shape of\n // `vanillaExtract`.\n const css: PkgConfigOptions['css'] | undefined =\n config?.css || ctx.cssExports.length\n ? {...config?.css, ...(build.css ? {splitting: true} : {})}\n : undefined\n\n // Build-time constants: `PKG_VERSION` reads the environment override first, like v11.\n // pkg-utils' own build skips it so the replacement logic in this very file survives its own\n // bundling. (`PKG_FORMAT`, `PKG_RUNTIME` and `PKG_FILE_PATH` were removed in v12 — see\n // MIGRATE.md for the `package.json#imports` / `import.meta.url` replacements.)\n const define: Record<string, string> = {}\n if (pkg.name !== '@sanity/pkg-utils') {\n define['process.env.PKG_VERSION'] = JSON.stringify(process.env['PKG_VERSION'] || pkg.version)\n }\n for (const [key, value] of Object.entries(config?.define || {})) {\n define[key] = JSON.stringify(value)\n }\n\n // Types are generated with tsdown (rolldown-plugin-dts). `@typescript/native-preview` in\n // devDependencies auto-enables tsgo, like v11; an explicit `dts.tsgo` wins. Only the object\n // form spreads: when the `legacyChecks` migration errors are skipped\n // (`NODE_ENV=production` / `legacyChecks: false`), a leftover v11 string like\n // `dts: 'rolldown'` must degrade to the default behavior (which is what it meant) instead\n // of spreading into numeric character keys.\n const hasTsSources =\n !build.css && build.entries.some((buildEntry) => RE_TS_SOURCE.test(buildEntry.source))\n const dtsPassthrough = typeof config?.dts === 'object' ? config.dts : undefined\n const dts =\n hasTsSources && config?.dts !== false\n ? {\n ...(typeof pkg.devDependencies === 'object' &&\n '@typescript/native-preview' in pkg.devDependencies\n ? {tsgo: true}\n : {}),\n // Always create dts from scratch, don't reuse contexts from previous builds\n newContext: true,\n ...dtsPassthrough,\n ...(ctx.emitDeclarationOnly ? {emitDtsOnly: true} : {}),\n }\n : false\n\n // Exports generation runs on the canonical build only, with `devExports: 'source'` — the\n // hand-written Sanity convention (`source` conditions in `exports`, a `source`-less\n // `publishConfig.exports`) — and the pkg-utils composer reconciling the generated map with\n // the hand-written one. `@sanity/tsdown-config`'s always-on exports default applies: the map\n // is rewritten on every build (CI included), so environments that set `CI=true` without\n // meaning \"skip package.json\" (Cursor Cloud, …) still keep exports in sync. A types-only\n // build never rewrites `package.json`, and neither do watch builds (a rewrite would\n // re-trigger the `package.json` watcher).\n const exports: UserConfig['exports'] =\n build.canonical && !ctx.emitDeclarationOnly && !options.watch && !build.css\n ? {\n devExports: 'source',\n customExports: createExportsComposer(ctx, build),\n // Keep the hand-written legacy fields (`main`/`module`) in sync instead of deleting\n // them; packages without them don't gain them\n ...(pkg.main || pkg.module ? {legacy: true} : {}),\n }\n : false\n\n // `@sanity/tsdown-config` defaults `tsdoc` to `false`; pkg-utils keeps the historical\n // default of enabled (`true`), and forwards an options object (with `bundledPackages` for\n // API Extractor's type resolution of inlined deps) when the user customized rules/tags.\n const tsdocOption =\n config?.tsdoc === false\n ? false\n : {\n ...(typeof config?.tsdoc === 'object' ? config.tsdoc : {}),\n bundledPackages: ctx.bundledPackages,\n }\n\n const base = await defineConfig({\n cwd,\n tsconfig: ctx.ts.configPath,\n platform,\n format,\n entry,\n // POSIX separators: on Windows `path.relative` yields backslashes, which would leak into\n // generated `package.json` export targets (e.g. the conditional vanilla-extract export)\n outDir: path.relative(cwd, distPath).replaceAll('\\\\', '/') || '.',\n target: ctx.target[build.runtime],\n define,\n sourcemap: config?.sourcemap,\n // tsdown owns cleaning: the first build of the waterfall carries the effective `clean`\n // (the config passthrough, or tsdown's default `true`), every later build gets `false`.\n // A types-only build never cleans, so it can't delete JS output.\n clean: options.clean && !ctx.emitDeclarationOnly ? config?.clean : false,\n dts,\n deps: ctx.deps,\n exports,\n css,\n reactCompiler: config?.reactCompiler,\n styledComponents: config?.styledComponents,\n vanillaExtract: config?.vanillaExtract,\n // Types-only builds still emit `.d.ts` files that deserve the check; watch mode skips it\n // so a failing TSDoc rule doesn't tear down the watcher on every save.\n tsdoc: options.watch ? false : tsdocOption,\n })\n\n // The hand-written exports define the emitted extensions (`.js`/`.mjs`/`.cjs` per\n // `package.json#type`, enforced by `validateExports`), so the extensions are pinned\n // explicitly instead of relying on tsdown's defaults (whose `fixedExtension` kicks in for\n // `platform: 'node'` and would emit `.mjs` for `type: module` packages).\n const extMap = pkgExtMap[pkg.type === 'module' ? 'module' : 'commonjs']\n const outExtensions: UserConfig['outExtensions'] = ({format: outputFormat}) => ({\n js: outputFormat === 'cjs' ? extMap.commonjs : extMap.esm,\n })\n\n const merged = mergeConfig(base, {\n outExtensions,\n // publint runs during `pkg check` (via its node API), not inside the build\n publint: false,\n // the per-file size report logs through tsdown's info channel; pkg-utils prints its own\n report: false,\n ...(config?.minify === true ? {minify: true} : {}),\n ...(config?.plugins === undefined ? {} : {plugins: config.plugins}),\n ...(options.watch && css ? {hooks: createWatchCssExportsHook(ctx, css)} : {}),\n })\n\n return {\n ...merged,\n config: false,\n logLevel: 'warn',\n ...(options.watch ? {watch: true} : {}),\n }\n}\n\n/**\n * Declares the conditional export of every CSS file a watch rebuild emitted.\n *\n * A full build leaves this to `cssNodeCompatPlugin`, which composes into tsdown's\n * `exports.customExports`. Watch mode turns tsdown's `exports` feature off (a `package.json`\n * write per rebuild would loop the watcher), so `pkg watch` maintains the exports itself. Most\n * of them are known before the build and are written once per context in `watch.ts`, but the\n * merged `style.css` of CSS imported from JS only exists when something actually imports CSS —\n * declaring it from the config alone would point the export at files nobody produced.\n *\n * `build:done` is the only place that knows: in watch mode `build()` resolves before the first\n * rebuild runs, so the returned bundle's chunks are still empty. The write is idempotent, so\n * the `package.json` watcher settles after one extra rebuild rather than looping.\n * @internal\n */\nfunction createWatchCssExportsHook(\n ctx: BuildContext,\n css: NonNullable<PkgConfigOptions['css']>,\n): NonNullable<UserConfig['hooks']> {\n // Only the merged mode has a CSS file name to declare up front. With `splitting` the names\n // follow the chunk names and the export is the host's to wire up, so a full build declares\n // nothing either.\n const mergedCssName = css.splitting ? undefined : css.fileName || 'style.css'\n\n return (hooks) => {\n hooks.hook('build:done', async ({chunks}) => {\n if (mergedCssName === undefined) return\n const emitted = chunks.some(\n (chunk) => chunk.type === 'asset' && chunk.fileName === mergedCssName,\n )\n if (!emitted) return\n\n const {writeBundleCssExports} = await import('../../core/pkg/writeBundleCssExports.ts')\n await writeBundleCssExports({\n cwd: ctx.cwd,\n distPath: ctx.distPath,\n cssNames: [mergedCssName],\n logger: ctx.logger,\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsDA,SAAgB,oBAAoB,KAAkC;CACpE,IAAM,EAAC,QAAQ,KAAK,UAAU,WAAU,KAElC,cAAc,WAA2B;EAC7C,IAAM,QAAQ,KACX,SAAS,UAAU,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,CAC7C,WAAW,MAAM,GAAG,CAAC,CACrB,QAAQ,YAAY,EAAE;EACzB,IAAI,MAAM,WAAW,IAAI,GACvB,MAAU,MAAM,+CAA+C,QAAQ;EAEzE,OAAO;CACT,GASM,gCAAgB,IAAI,IAAqC,GACzD,iCAAiB,IAAI,IAAwB,GAE7C,YACJ,UACA,SACA,UAMG;EACH,eAAe,IAAI,UAAU,OAAO;EACpC,IAAM,EAAC,QAAQ,eAAc,OACvB,0BAAU,IAAI,IAAY,GAC1B,0BAAU,IAAI,IAAe;EASnC,IARI,MAAM,WACR,QAAQ,IAAI,WAAW,MAAM,MAAM,CAAC,GACpC,QAAQ,IAAI,KAAK,IAEf,MAAM,YACR,QAAQ,IAAI,WAAW,MAAM,OAAO,CAAC,GACrC,QAAQ,IAAI,UAAU,IAEpB,QAAQ,SAAS,GAAG;EACxB,IAAI,QAAQ,OAAO,GACj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I,kBAAkB,KAAA,KAIlB,CAHY,OAAO,MACpB,UAAU,MAAM,SAAS,WAAW,MAAM,aAAa,aAE/C,GAAG;GAEd,IAAM,EAAC,0BAAyB,MAAM,OAAO,sCAA0C,CAAA,MAAA,MAAA,EAAA,CAAA;GACvF,MAAM,sBAAsB;IAC1B,KAAK,IAAI;IACT,UAAU,IAAI;IACd,UAAU,CAAC,aAAa;IACxB,QAAQ,IAAI;GACd,CAAC;EACH,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"resolveTsdownConfig-DunhV2W-.js","names":[],"sources":["../src/node/tasks/tsdown/resolveTsdownBuilds.ts","../src/node/core/pkg/cssShimFileName.ts","../src/node/core/pkg/cssExport.ts","../src/node/tasks/tsdown/composeExports.ts","../src/node/tasks/tsdown/resolveTsdownConfig.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgFormat, PkgRuntime} from '../../core/config/types.ts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {fileEnding} from '../../core/pkg/pkgExt.ts'\n\n/**\n * One entry of a tsdown build.\n * @internal\n */\nexport interface TsdownBuildEntry {\n /**\n * The entry alias handed to tsdown: the output path relative to `dist` without the\n * extension (e.g. `index`, `index.browser`, `sub/feature`), so the emitted filenames match\n * the hand-written `exports` targets exactly.\n */\n alias: string\n source: string\n /** The hand-written export subpath this entry backs (`undefined` for `bundles`). */\n exportPath?: string\n /** The formats the hand-written exports declare for this entry. */\n formats: PkgFormat[]\n}\n\n/**\n * One tsdown `build()` call of the waterfall. Builds run serially — variants and bundles\n * first, the canonical build last, so its exports generation and publint see every emitted\n * file on disk.\n * @internal\n */\nexport interface TsdownBuild {\n /** Stable identifier, e.g. `neutral`, `browser`, `node`, `bundles`, `css`. */\n key: string\n runtime: PkgRuntime\n /** The canonical build owns `dist` conventions: exports generation runs here. */\n canonical: boolean\n entries: TsdownBuildEntry[]\n /**\n * The stylesheet build: its entries are `.css` files rather than JS, so it emits CSS assets\n * (one per entry) and no JS at all. It runs on its own because a `.css` entry has nothing to\n * declare types for, and because its per-entry CSS output needs `css.splitting`.\n */\n css?: boolean\n}\n\n/** The build key of the stylesheet build. */\nconst CSS_BUILD_KEY = 'css'\n\n/**\n * Collapses the hand-written `exports` map (+ `bundles`) into the per-platform tsdown build\n * waterfall: one canonical build for the package's default runtime, plus a variant build per\n * `browser`/`node` exports condition, plus builds for `bundles` (which must not participate\n * in exports generation).\n * @internal\n */\nexport function resolveTsdownBuilds(ctx: BuildContext): TsdownBuild[] {\n const {config, cwd, distPath, logger} = ctx\n\n const entryAlias = (output: string): string => {\n const alias = path\n .relative(distPath, path.resolve(cwd, output))\n .replaceAll('\\\\', '/')\n .replace(fileEnding, '')\n if (alias.startsWith('..')) {\n throw new Error(`output file is outside the \\`dist\\` folder: ${output}`)\n }\n return alias\n }\n\n interface EntryDraft {\n alias: string\n source: string\n exportPath?: string | undefined\n formats: Set<PkgFormat>\n }\n\n const draftsByBuild = new Map<string, Map<string, EntryDraft>>()\n const runtimeByBuild = new Map<string, PkgRuntime>()\n\n const addEntry = (\n buildKey: string,\n runtime: PkgRuntime,\n entry: {\n source: string\n exportPath?: string | undefined\n import?: string | undefined\n require?: string | undefined\n },\n ) => {\n runtimeByBuild.set(buildKey, runtime)\n const {source, exportPath} = entry\n const aliases = new Set<string>()\n const formats = new Set<PkgFormat>()\n if (entry.import) {\n aliases.add(entryAlias(entry.import))\n formats.add('esm')\n }\n if (entry.require) {\n aliases.add(entryAlias(entry.require))\n formats.add('commonjs')\n }\n if (aliases.size === 0) return\n if (aliases.size > 1) {\n throw new Error(\n `the \\`import\\` and \\`require\\` targets of ${\n exportPath ? `exports[\"${exportPath}\"]` : `the bundle for ${source}`\n } must share a basename (e.g. \\`./dist/index.js\\` + \\`./dist/index.cjs\\`), ` +\n `got: ${entry.import} and ${entry.require}`,\n )\n }\n const [alias] = aliases\n let drafts = draftsByBuild.get(buildKey)\n if (!drafts) {\n drafts = new Map()\n draftsByBuild.set(buildKey, drafts)\n }\n const existing = drafts.get(alias!)\n if (existing) {\n if (existing.source !== source) {\n throw new Error(\n `conflicting sources for the output alias \"${alias}\": ${existing.source} and ${source}`,\n )\n }\n for (const format of formats) existing.formats.add(format)\n return\n }\n drafts.set(alias!, {alias: alias!, source, exportPath, formats})\n }\n\n const exports = Object.entries(ctx.exports || {})\n const packageType = ctx.pkg.type === 'module' ? 'module' : 'commonjs'\n const resolveRuntimeTargets = (condition: {\n import?: string\n require?: string\n default?: string\n }) => ({\n import: condition.import ?? (packageType === 'module' ? condition.default : undefined),\n require: condition.require ?? (packageType === 'commonjs' ? condition.default : undefined),\n })\n\n let hasRuntimeConditions = false\n\n for (const [exportPath, exp] of exports) {\n addEntry('canonical', ctx.runtime, {\n source: exp.source,\n exportPath,\n import: exp.import,\n require: exp.require,\n })\n\n const browserTargets = exp.browser && resolveRuntimeTargets(exp.browser)\n if (exp.browser && browserTargets && (browserTargets.import || browserTargets.require)) {\n hasRuntimeConditions = true\n addEntry('browser', 'browser', {\n source: exp.browser.source || exp.source,\n exportPath,\n ...browserTargets,\n })\n }\n\n const nodeTargets = exp.node && resolveRuntimeTargets(exp.node)\n if (exp.node && nodeTargets && (nodeTargets.import || nodeTargets.require)) {\n hasRuntimeConditions = true\n addEntry('node', 'node', {\n source: exp.node.source || exp.source,\n exportPath,\n ...nodeTargets,\n })\n }\n }\n\n // `bundles` are extra entrypoints that are deliberately not in the exports map (CLI workers\n // and similar), so they build separately from the canonical build — exports generation\n // derives subpaths from every entry of its build, and bundles must never become export\n // subpaths of their own.\n for (const bundle of config?.bundles || []) {\n const runtime = bundle.runtime || ctx.runtime\n addEntry(runtime === ctx.runtime ? 'bundles' : `bundles:${runtime}`, runtime, {\n source: bundle.source,\n import: bundle.import,\n require: bundle.require,\n })\n }\n\n if (hasRuntimeConditions) {\n logger.warn(\n [\n 'The `exports[].browser.source` / `exports[].node.source` pattern is not recommended: every',\n 'runtime condition adds a full extra build (complexity and build time). Consider instead:',\n ' 1. separate npm packages per platform/runtime, selected through export conditions that',\n ' pick the right package per environment,',\n ' 2. when possible, a single neutral build using JS that works in both runtimes without',\n ' special-casing (e.g. `new URL` over `require(\"url\")`, WebCrypto over',\n ' `require(\"crypto\")`), or',\n ' 3. using `tsdown` + `@sanity/tsdown-config` directly, exporting an array from',\n ' `tsdown.config.ts` with one config per `platform` — the fully supported path for',\n ' this level of customization.',\n ].join('\\n'),\n )\n }\n\n const builds: TsdownBuild[] = []\n\n // `.css` export subpaths that declare a `source` build in their own pass: their entries are\n // stylesheets, so the emitted file name follows the export subpath (`./ui/styles.css` ->\n // `dist/ui/styles.css`) instead of an `import`/`require` target, and `dts` has nothing to do.\n const cssEntries: TsdownBuildEntry[] = ctx.cssExports.map((cssExport) => ({\n alias: cssEntryAlias(cssExport._path),\n source: cssExport.source,\n exportPath: cssExport._path,\n formats: ['esm'],\n }))\n if (cssEntries.length) {\n builds.push({\n key: CSS_BUILD_KEY,\n runtime: ctx.runtime,\n canonical: false,\n entries: cssEntries,\n css: true,\n })\n }\n\n const toBuild = (key: string, runtime: PkgRuntime, canonical: boolean): TsdownBuild | null => {\n const drafts = draftsByBuild.get(key)\n if (!drafts || drafts.size === 0) return null\n return {\n key,\n runtime,\n canonical,\n entries: Array.from(drafts.values(), (draft) => ({\n alias: draft.alias,\n source: draft.source,\n ...(draft.exportPath === undefined ? {} : {exportPath: draft.exportPath}),\n formats: Array.from(draft.formats),\n })),\n }\n }\n\n // Variants and bundles run first; the canonical build runs last so its exports generation\n // and publint see the other builds' files on disk. Each build's runtime was recorded when\n // its entries were added, so nothing is re-derived from the build key (a bundle with\n // `runtime: '*'` in a `runtime: 'node'` package must build for `'*'`/neutral).\n for (const key of draftsByBuild.keys()) {\n if (key === 'canonical') continue\n const build = toBuild(key, runtimeByBuild.get(key) ?? ctx.runtime, false)\n if (build) builds.push(build)\n }\n\n const canonical = toBuild('canonical', ctx.runtime, true)\n if (canonical) builds.push(canonical)\n\n return builds\n}\n\n/**\n * The tsdown entry alias of a `.css` export subpath: the subpath without its leading `./` and\n * `.css` ending, so `@tsdown/css` (with `splitting`) emits the stylesheet at exactly the path\n * the subpath promises — `\"./ui/styles.css\"` -> alias `ui/styles` -> `dist/ui/styles.css`.\n */\nfunction cssEntryAlias(exportPath: string): string {\n return exportPath.replace(/^\\.\\//, '').replace(/\\.css$/, '')\n}\n","/**\n * The no-op JS shim file name for a CSS file under vanilla-extract compat mode.\n *\n * `bundle.css` → `bundle-css.js` — deliberately not `${cssFileName}.js` (`bundle.css.js`),\n * which vanilla-extract's `cssFileFilter` (`/\\.css\\.(js|cjs|mjs|jsx|ts|tsx)$/`) would treat as\n * a stylesheet module. Kept in sync with `cssShimFileName` in\n * `@sanity/vanilla-extract-rolldown-plugin`.\n *\n * @internal\n */\nexport function cssShimFileName(cssFileName: string): string {\n return `${cssFileName.replace(/\\.css$/, '-css')}.js`\n}\n\n/**\n * The `.d.ts` companion for {@link cssShimFileName}. `bundle.css` → `bundle-css.d.ts`.\n *\n * @internal\n */\nexport function cssShimDtsFileName(cssFileName: string): string {\n return `${cssFileName.replace(/\\.css$/, '-css')}.d.ts`\n}\n","import path from 'node:path'\nimport {cssShimDtsFileName, cssShimFileName} from './cssShimFileName.ts'\n\n/**\n * Build the conditional CSS export object that `exports.nodeCompat` expects, e.g.\n * ```json\n * {\n * \"types\": \"./dist/bundle-css.d.ts\",\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 * The shim is named `bundle-css.js` (not `bundle.css.js`) so it does not match\n * vanilla-extract's `cssFileFilter`. An explicit `types` condition (rather than relying on\n * TypeScript's extension-substitution fallback, which only works when the shim shares the CSS\n * file's basename, and which TypeScript is deprecating anyway - microsoft/TypeScript#50762)\n * points resolvers straight at the shim's declaration file.\n *\n * Kept in sync with `createConditionalCssExport` in `@sanity/vanilla-extract-tsdown-plugin`,\n * which writes the same entry through tsdown's `exports.customExports` during full builds.\n *\n * @internal\n */\nexport function createConditionalCssExport(\n cssName: string,\n distRel: string,\n): Record<string, string> {\n const cssFile = `./${path.posix.join(distRel, cssName)}`\n const shimFile = `./${path.posix.join(distRel, cssShimFileName(cssName))}`\n const shimDtsFile = `./${path.posix.join(distRel, cssShimDtsFileName(cssName))}`\n return {types: shimDtsFile, browser: cssFile, style: cssFile, node: shimFile, default: shimFile}\n}\n","import path from 'node:path'\nimport type {PkgExport} from '../../core/config/types.ts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {isRecord} from '../../core/isRecord.ts'\nimport {createConditionalCssExport} from '../../core/pkg/cssExport.ts'\nimport type {TsdownBuild} from './resolveTsdownBuilds.ts'\n\ntype ExportsMap = Record<string, unknown>\ninterface ComposeContext {\n isPublish: boolean\n}\n\n/**\n * The pkg-utils opinion layer over tsdown's generated `exports` map, composed into\n * `exports.customExports` of the canonical build (the same composition hook\n * `@sanity/vanilla-extract-tsdown-plugin` uses for its conditional CSS export).\n *\n * tsdown generates subpaths from the entry aliases with `source`/`import`/`require` conditions\n * (`devExports: 'source'`) and a `source`-less `publishConfig.exports` — already the Sanity\n * convention. This composer reconciles the generated map with the hand-written one, which\n * remains the input:\n *\n * - generated keys are remapped to the hand-written subpaths (entry aliases are derived from\n * the output paths, which don't have to match the subpath names),\n * - the hand-written `types`, `browser`, `node`, `development` and `monorepo` conditions are\n * re-inserted (tsdown's generator cannot express them; the `browser`/`node` files are built\n * by the variant builds of the waterfall) — with `source`-like conditions stripped from the\n * publish variant,\n * - all hand-written conditions (`react-server`, `worker`, … included) retain their authored\n * order in each map independently, because earlier matching conditions take precedence,\n * - generated conditions for conditional entries are materialized in both `exports` and\n * `publishConfig.exports`, so they can be reordered directly in `package.json` and keep that\n * position on later builds (plain-string entries stay compact),\n * - a trailing `default` condition is kept on dual-format entries and nested runtime variants\n * (tsdown emits bare `import`/`require` pairs; the Sanity convention always ends with\n * `default`),\n * - hand-written subpaths that aren't build entries (`.css`/`.json` exports, `svelte`\n * entries) are carried over untouched, and\n * - the hand-written subpath and condition key order of each map is preserved.\n * @internal\n */\nexport function createExportsComposer(\n ctx: BuildContext,\n build: TsdownBuild,\n): (exportsMap: ExportsMap, context: ComposeContext) => ExportsMap {\n const {pkg} = ctx\n const type = pkg.type === 'module' ? 'module' : 'commonjs'\n\n // POSIX separators: on Windows `path.relative` yields backslashes, which must never leak\n // into generated `package.json` export targets.\n const distRel = (path.relative(ctx.cwd, ctx.distPath) || 'dist').split(path.sep).join('/')\n const cssExportPaths = new Set(ctx.cssExports.map((cssExport) => cssExport._path))\n const cssSources: Record<string, string> = {}\n for (const cssExport of ctx.cssExports) {\n cssSources[cssExport._path] = cssExport.source\n }\n\n // alias -> hand-written subpath, e.g. `index` -> `.`, `sub/feature` -> `./feature`\n const aliasToExportPath = new Map<string, string>()\n for (const entry of build.entries) {\n if (entry.exportPath !== undefined) {\n aliasToExportPath.set(entry.alias, entry.exportPath)\n }\n }\n\n return (exportsMap, context) => {\n const {isPublish} = context\n\n // 1. Remap the generated keys (`.` for the `index` alias, `./<alias>` otherwise) back to\n // the hand-written subpaths.\n const remapped: ExportsMap = {}\n for (const [key, value] of Object.entries(exportsMap)) {\n const alias = key === '.' ? 'index' : key.startsWith('./') ? key.slice(2) : key\n const exportPath = aliasToExportPath.get(alias) ?? key\n remapped[exportPath] = value\n }\n\n // 2. Reconcile each generated entry with its hand-written counterpart.\n const result: ExportsMap = {}\n const handwritten = ctx.exports || {}\n const sourceRaw: ExportsMap = pkg.exports || {}\n const publishRaw: ExportsMap | undefined = pkg.publishConfig?.exports\n const authoredRaw = isPublish && publishRaw ? publishRaw : sourceRaw\n\n const reconcile = (exportPath: string, value: unknown): unknown => {\n const exp = handwritten[exportPath]\n if (!exp) return value\n const raw = authoredRaw[exportPath]\n const source = sourceRaw[exportPath]\n // A configured exports map is itself authoritative. Otherwise use the raw package entry\n // for the map being generated. Fall back to `exports` when a new publish map/entry is\n // being generated, so inferred conditions don't masquerade as ordering choices.\n const authored =\n ctx.config?.exports === undefined\n ? isRecord(raw)\n ? raw\n : isRecord(source)\n ? source\n : exp\n : exp\n return reconcileEntry(exp, value, {authored, isPublish, type})\n }\n\n // 3. Follow the hand-written key order of the map being generated. Source-only passthrough\n // subpaths missing from an existing publish map are appended, followed by generated extras.\n const authoredPaths = Object.keys(authoredRaw)\n for (const exportPath of Object.keys(sourceRaw)) {\n if (!Object.prototype.hasOwnProperty.call(authoredRaw, exportPath)) {\n authoredPaths.push(exportPath)\n }\n }\n for (const exportPath of authoredPaths) {\n if (exportPath in remapped) {\n result[exportPath] = reconcile(exportPath, remapped[exportPath])\n } else if (cssExportPaths.has(exportPath)) {\n // A `.css` subpath with a `source` is built by the stylesheet build, which does not\n // participate in exports generation (its entries are stylesheets, not JS). Its\n // conditions are materialized here instead, from the export subpath: `./ui/styles.css`\n // is built to `<dist>/ui/styles.css` with the shim next to it.\n result[exportPath] = reconcileCssEntry(exportPath, {\n distRel,\n source: cssSources[exportPath],\n isPublish,\n })\n } else {\n // Hand-written subpaths that aren't build entries (plain `.css`/`.json` exports,\n // `svelte` entries) pass through untouched.\n result[exportPath] = Object.prototype.hasOwnProperty.call(authoredRaw, exportPath)\n ? authoredRaw[exportPath]\n : sourceRaw[exportPath]\n }\n }\n for (const [exportPath, value] of Object.entries(remapped)) {\n if (exportPath in result) continue\n result[exportPath] = reconcile(exportPath, value)\n }\n\n return result\n }\n}\n\n/**\n * The conditional CSS export of a `.css` subpath built by the stylesheet build. `source`\n * resolves at development time, so it is kept in `exports` and stripped from the publish\n * variant — the same split the build entries get.\n */\nfunction reconcileCssEntry(\n exportPath: string,\n options: {distRel: string; source: string | undefined; isPublish: boolean},\n): Record<string, string> {\n const {distRel, source, isPublish} = options\n const cssName = exportPath.replace(/^\\.\\//, '')\n const conditions = createConditionalCssExport(cssName, distRel)\n return isPublish || source === undefined ? conditions : {source, ...conditions}\n}\n\n/**\n * Rebuilds a generated subpath entry in its authored condition order, re-inserting the\n * hand-written conditions tsdown's generator cannot express.\n */\nfunction reconcileEntry(\n exp: PkgExport,\n generated: unknown,\n options: {authored: object; isPublish: boolean; type: 'commonjs' | 'module'},\n): unknown {\n const {authored, isPublish, type} = options\n const authoredRecord = isRecord(authored) ? authored : {}\n\n // tsdown's publish variant of a single-format entry is a plain string\n const gen: Record<string, unknown> | undefined =\n typeof generated === 'string'\n ? {default: generated}\n : isRecord(generated)\n ? generated\n : undefined\n if (!gen) return generated\n\n const browserOrder = isRecord(authoredRecord['browser']) ? authoredRecord['browser'] : exp.browser\n const browser =\n exp.browser && (exp.browser.import || exp.browser.require || exp.browser.default)\n ? pickConditions(exp.browser, {\n authored: browserOrder ?? exp.browser,\n isPublish,\n type,\n })\n : undefined\n const nodeOrder = isRecord(authoredRecord['node']) ? authoredRecord['node'] : exp.node\n const node =\n exp.node && (exp.node.import || exp.node.require || exp.node.default)\n ? pickConditions(exp.node, {\n authored: nodeOrder ?? exp.node,\n isPublish,\n type,\n })\n : undefined\n const custom = pickCustomConditions(exp)\n\n // Preserve tsdown's compact single-format publish shape unless hand-written conditions need\n // to be re-inserted. There is no condition ordering to preserve in a plain string entry.\n if (typeof generated === 'string' && !exp.types && !browser && !node && custom.length === 0) {\n return generated\n }\n\n const next: Record<string, unknown> = {}\n\n // `source`-like conditions resolve at development time and are stripped from the publish\n // variant (tsdown already does this for `source`; `development`/`monorepo` follow)\n if (!isPublish) {\n if (typeof gen['source'] === 'string') next['source'] = gen['source']\n else if (exp.source) next['source'] = exp.source\n if (exp.development) next['development'] = exp.development\n if (exp.monorepo) next['monorepo'] = exp.monorepo\n }\n\n if (exp.types) next['types'] = exp.types\n if (browser) next['browser'] = browser\n if (node) next['node'] = node\n\n // Hand-written custom conditions (`react-server`, `worker`, …) aren't built, but they are\n // the author's: carry their targets over, then restore every condition's authored position.\n for (const [condition, target] of custom) {\n const authoredTarget = authoredRecord[condition]\n next[condition] =\n isRecord(target) && isRecord(authoredTarget)\n ? preserveConditionOrder(target, authoredTarget)\n : target\n }\n\n if (typeof gen['import'] === 'string' && typeof gen['require'] === 'string') {\n next['import'] = gen['import']\n next['require'] = gen['require']\n // tsdown emits bare `import`/`require` pairs; the Sanity convention ends with `default`\n next['default'] = type === 'module' ? gen['import'] : gen['require']\n } else {\n // Single-format entries keep the generated shape (`{source, default}` in development)\n for (const [condition, target] of Object.entries(gen)) {\n if (condition in next || condition === 'source') continue\n next[condition] = target\n }\n }\n\n return preserveConditionOrder(next, authored)\n}\n\n/**\n * The hand-written `browser`/`node` condition object, minus `source` for the publish map.\n * A nested runtime condition must have its own fallback: once a resolver matches `node` or\n * `browser`, an unmatched module-format condition otherwise backtracks to the outer entry.\n */\nfunction pickConditions(\n conditions: {source?: string; import?: string; require?: string; default?: string},\n options: {\n authored?: object\n isPublish: boolean\n type: 'commonjs' | 'module'\n },\n): Record<string, string> {\n const {authored = conditions, isPublish, type} = options\n const next: Record<string, string> = {}\n if (!isPublish && conditions.source) next['source'] = conditions.source\n if (conditions.import) next['import'] = conditions.import\n if (conditions.require) next['require'] = conditions.require\n const fallback =\n conditions.default ?? (type === 'module' ? conditions.import : conditions.require)\n if (fallback) next['default'] = fallback\n return preserveConditionOrder(next, authored)\n}\n\n/**\n * Reorders reconciled conditions to match their hand-written order. Conditions generated by\n * tsdown but absent from the hand-written entry are inserted before its `default` fallback.\n */\nfunction preserveConditionOrder<T>(\n conditions: Record<string, T>,\n authored: object,\n): Record<string, T> {\n const entries: [string, T][] = []\n const added = new Set<string>()\n const conditionEntries = Object.entries(conditions)\n const entriesByCondition = new Map(conditionEntries.map((entry) => [entry[0], entry]))\n const authoredOrder = Object.keys(authored).filter((condition) => !condition.startsWith('_'))\n const authoredConditions = new Set(authoredOrder)\n\n const addGeneratedConditions = () => {\n for (const entry of conditionEntries) {\n if (!authoredConditions.has(entry[0]) && !added.has(entry[0])) {\n entries.push(entry)\n added.add(entry[0])\n }\n }\n }\n\n for (const condition of authoredOrder) {\n // A generated condition has no authored position. Keep the explicit `default` as the final\n // fallback by placing generated conditions immediately before it.\n if (condition === 'default') addGeneratedConditions()\n const entry = entriesByCondition.get(condition)\n if (!entry) continue\n entries.push(entry)\n added.add(condition)\n }\n\n addGeneratedConditions()\n\n return Object.fromEntries(entries)\n}\n\n/** The conditions the pipeline owns (or re-inserts itself) on a build entry. */\nconst managedConditions = new Set([\n 'source',\n 'development',\n 'monorepo',\n 'types',\n 'browser',\n 'node',\n 'import',\n 'require',\n 'default',\n])\n\n/**\n * Hand-written conditions the pipeline knows nothing about (`react-server`, `worker`,\n * `edge-light`, …), in authored order. `parseExports` spreads the raw entry, so they survive\n * on the parsed `PkgExport` beyond its typed fields.\n */\nfunction pickCustomConditions(exp: PkgExport): [string, unknown][] {\n return Object.entries(exp).filter(\n ([condition, target]) =>\n !managedConditions.has(condition) && !condition.startsWith('_') && target !== undefined,\n )\n}\n","import path from 'node:path'\nimport {defineConfig} from '@sanity/tsdown-config'\nimport {mergeConfig, type InlineConfig, type UserConfig} from 'tsdown'\nimport type {PkgConfigOptions} from '../../core/config/types.ts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {pkgExtMap} from '../../core/pkg/pkgExt.ts'\nimport {createExportsComposer} from './composeExports.ts'\nimport type {TsdownBuild} from './resolveTsdownBuilds.ts'\n\nconst RE_TS_SOURCE = /\\.[cm]?tsx?$/\n\n/**\n * Composes the tsdown config for one build of the waterfall: `@sanity/tsdown-config`'s\n * `defineConfig()` provides the shared Sanity base, and the pkg-utils opinions (browserslist\n * targets, `PKG_*` defines, exports reconciliation, dts selection) layer over it with\n * tsdown's `mergeConfig`.\n *\n * pkg-utils owns its own experience: the returned config carries `config: false`, so tsdown\n * never loads `tsdown.config.*` files — `package.config.ts` is the sole config source — and\n * `logLevel: 'warn'` keeps tsdown's info chatter out of pkg-utils' own output.\n * @internal\n */\nexport async function resolveTsdownConfig(\n ctx: BuildContext,\n build: TsdownBuild,\n options: {\n /**\n * Whether this build may clean: only the first build of the waterfall cleans (so later\n * builds can't wipe earlier output), and `--no-clean` turns it off for the whole run.\n */\n clean: boolean\n watch?: boolean\n },\n): Promise<InlineConfig> {\n const {config, cwd, distPath, pkg} = ctx\n\n const reactCompiler = config?.reactCompiler\n if (typeof reactCompiler === 'object' && reactCompiler.reactServer === true) {\n throw new Error(\n [\n 'package.config.ts: `reactCompiler.reactServer` is not supported by `pkg build` — the',\n 'dual React Server Components build needs one tsdown run driving multiple configs.',\n 'Use `tsdown` + `@sanity/tsdown-config` directly instead: export the config from',\n '`tsdown.config.ts` and build with `tsdown`.',\n ].join('\\n'),\n )\n }\n\n const entry: Record<string, string> = {}\n for (const buildEntry of build.entries) {\n entry[buildEntry.alias] = buildEntry.source\n }\n\n // tsdown's `format` applies to the whole build (and its exports generation composes the\n // dual `import`/`require` map from both formats' chunks of one build), so the entries'\n // formats union: every entry is emitted in every format of the build. Mixed per-entry\n // coverage gets a heads-up — the extra files are emitted, and local exports generation\n // will declare them.\n const formats = new Set(build.entries.flatMap((buildEntry) => buildEntry.formats))\n if (formats.size > 1) {\n const partial = build.entries.filter((buildEntry) => buildEntry.formats.length < formats.size)\n if (partial.length) {\n const names = partial\n .map((buildEntry) =>\n buildEntry.exportPath ? `exports[\"${buildEntry.exportPath}\"]` : buildEntry.source,\n )\n .join(', ')\n ctx.logger.warn(\n `${names} declare${partial.length === 1 ? 's' : ''} fewer formats than the rest of the package. tsdown emits every format of a build for every entry, so the missing format is built anyway (and local exports generation will declare it). Declare both \\`import\\` and \\`require\\` targets for every subpath — or for none — to keep the exports map unambiguous.`,\n )\n }\n }\n const format = [\n ...(formats.has('esm') ? ['esm' as const] : []),\n ...(formats.has('commonjs') ? ['cjs' as const] : []),\n ]\n\n const platform =\n build.runtime === 'node' ? 'node' : build.runtime === 'browser' ? 'browser' : 'neutral'\n\n // The `@tsdown/css` pipeline turns on when it's configured, and automatically for a package\n // that declares a `.css` export subpath with a `source`. The stylesheet build needs\n // `splitting` so each entry emits its own file at the path its subpath promises; the JS\n // builds keep `@tsdown/css`'s merged default, so CSS imported from JS lands in a single\n // `style.css` with one export and one injected import - the `bundle.css` shape of\n // `vanillaExtract`.\n const css: PkgConfigOptions['css'] | undefined =\n config?.css || ctx.cssExports.length\n ? {...config?.css, ...(build.css ? {splitting: true} : {})}\n : undefined\n\n // Build-time constants: `PKG_VERSION` reads the environment override first, like v11.\n // pkg-utils' own build skips it so the replacement logic in this very file survives its own\n // bundling. (`PKG_FORMAT`, `PKG_RUNTIME` and `PKG_FILE_PATH` were removed in v12 — see\n // MIGRATE.md for the `package.json#imports` / `import.meta.url` replacements.)\n const define: Record<string, string> = {}\n if (pkg.name !== '@sanity/pkg-utils') {\n define['process.env.PKG_VERSION'] = JSON.stringify(process.env['PKG_VERSION'] || pkg.version)\n }\n for (const [key, value] of Object.entries(config?.define || {})) {\n define[key] = JSON.stringify(value)\n }\n\n // Types are generated with tsdown (rolldown-plugin-dts). `@typescript/native-preview` in\n // devDependencies auto-enables tsgo, like v11; an explicit `dts.tsgo` wins. Only the object\n // form spreads: when the `legacyChecks` migration errors are skipped\n // (`NODE_ENV=production` / `legacyChecks: false`), a leftover v11 string like\n // `dts: 'rolldown'` must degrade to the default behavior (which is what it meant) instead\n // of spreading into numeric character keys.\n const hasTsSources =\n !build.css && build.entries.some((buildEntry) => RE_TS_SOURCE.test(buildEntry.source))\n const dtsPassthrough = typeof config?.dts === 'object' ? config.dts : undefined\n const dts =\n hasTsSources && config?.dts !== false\n ? {\n ...(typeof pkg.devDependencies === 'object' &&\n '@typescript/native-preview' in pkg.devDependencies\n ? {tsgo: true}\n : {}),\n // Always create dts from scratch, don't reuse contexts from previous builds\n newContext: true,\n ...dtsPassthrough,\n ...(ctx.emitDeclarationOnly ? {emitDtsOnly: true} : {}),\n }\n : false\n\n // Exports generation runs on the canonical build only, with `devExports: 'source'` — the\n // hand-written Sanity convention (`source` conditions in `exports`, a `source`-less\n // `publishConfig.exports`) — and the pkg-utils composer reconciling the generated map with\n // the hand-written one. `@sanity/tsdown-config`'s always-on exports default applies: the map\n // is rewritten on every build (CI included), so environments that set `CI=true` without\n // meaning \"skip package.json\" (Cursor Cloud, …) still keep exports in sync. A types-only\n // build never rewrites `package.json`, and neither do watch builds (a rewrite would\n // re-trigger the `package.json` watcher).\n const exports: UserConfig['exports'] =\n build.canonical && !ctx.emitDeclarationOnly && !options.watch && !build.css\n ? {\n devExports: 'source',\n customExports: createExportsComposer(ctx, build),\n // Keep the hand-written legacy fields (`main`/`module`) in sync instead of deleting\n // them; packages without them don't gain them\n ...(pkg.main || pkg.module ? {legacy: true} : {}),\n }\n : false\n\n // `@sanity/tsdown-config` defaults `tsdoc` to `false`; pkg-utils keeps the historical\n // default of enabled (`true`), and forwards an options object (with `bundledPackages` for\n // API Extractor's type resolution of inlined deps) when the user customized rules/tags.\n const tsdocOption =\n config?.tsdoc === false\n ? false\n : {\n ...(typeof config?.tsdoc === 'object' ? config.tsdoc : {}),\n bundledPackages: ctx.bundledPackages,\n }\n\n const base = await defineConfig({\n cwd,\n tsconfig: ctx.ts.configPath,\n platform,\n format,\n entry,\n // POSIX separators: on Windows `path.relative` yields backslashes, which would leak into\n // generated `package.json` export targets (e.g. the conditional vanilla-extract export)\n outDir: path.relative(cwd, distPath).replaceAll('\\\\', '/') || '.',\n target: ctx.target[build.runtime],\n define,\n sourcemap: config?.sourcemap,\n // tsdown owns cleaning: the first build of the waterfall carries the effective `clean`\n // (the config passthrough, or tsdown's default `true`), every later build gets `false`.\n // A types-only build never cleans, so it can't delete JS output.\n clean: options.clean && !ctx.emitDeclarationOnly ? config?.clean : false,\n dts,\n deps: ctx.deps,\n exports,\n css,\n reactCompiler: config?.reactCompiler,\n styledComponents: config?.styledComponents,\n vanillaExtract: config?.vanillaExtract,\n bundleAnalyzer: config?.bundleAnalyzer,\n // Types-only builds still emit `.d.ts` files that deserve the check; watch mode skips it\n // so a failing TSDoc rule doesn't tear down the watcher on every save.\n tsdoc: options.watch ? false : tsdocOption,\n })\n\n // The hand-written exports define the emitted extensions (`.js`/`.mjs`/`.cjs` per\n // `package.json#type`, enforced by `validateExports`), so the extensions are pinned\n // explicitly instead of relying on tsdown's defaults (whose `fixedExtension` kicks in for\n // `platform: 'node'` and would emit `.mjs` for `type: module` packages).\n const extMap = pkgExtMap[pkg.type === 'module' ? 'module' : 'commonjs']\n const outExtensions: UserConfig['outExtensions'] = ({format: outputFormat}) => ({\n js: outputFormat === 'cjs' ? extMap.commonjs : extMap.esm,\n })\n\n const merged = mergeConfig(base, {\n outExtensions,\n // publint runs during `pkg check` (via its node API), not inside the build\n publint: false,\n // the per-file size report logs through tsdown's info channel; pkg-utils prints its own\n report: false,\n ...(config?.minify === true ? {minify: true} : {}),\n ...(config?.plugins === undefined ? {} : {plugins: config.plugins}),\n ...(options.watch && css ? {hooks: createWatchCssExportsHook(ctx, css)} : {}),\n })\n\n return {\n ...merged,\n config: false,\n logLevel: 'warn',\n ...(options.watch ? {watch: true} : {}),\n }\n}\n\n/**\n * Declares the conditional export of every CSS file a watch rebuild emitted.\n *\n * A full build leaves this to `cssNodeCompatPlugin`, which composes into tsdown's\n * `exports.customExports`. Watch mode turns tsdown's `exports` feature off (a `package.json`\n * write per rebuild would loop the watcher), so `pkg watch` maintains the exports itself. Most\n * of them are known before the build and are written once per context in `watch.ts`, but the\n * merged `style.css` of CSS imported from JS only exists when something actually imports CSS —\n * declaring it from the config alone would point the export at files nobody produced.\n *\n * `build:done` is the only place that knows: in watch mode `build()` resolves before the first\n * rebuild runs, so the returned bundle's chunks are still empty. The write is idempotent, so\n * the `package.json` watcher settles after one extra rebuild rather than looping.\n * @internal\n */\nfunction createWatchCssExportsHook(\n ctx: BuildContext,\n css: NonNullable<PkgConfigOptions['css']>,\n): NonNullable<UserConfig['hooks']> {\n // Only the merged mode has a CSS file name to declare up front. With `splitting` the names\n // follow the chunk names and the export is the host's to wire up, so a full build declares\n // nothing either.\n const mergedCssName = css.splitting ? undefined : css.fileName || 'style.css'\n\n return (hooks) => {\n hooks.hook('build:done', async ({chunks}) => {\n if (mergedCssName === undefined) return\n const emitted = chunks.some(\n (chunk) => chunk.type === 'asset' && chunk.fileName === mergedCssName,\n )\n if (!emitted) return\n\n const {writeBundleCssExports} = await import('../../core/pkg/writeBundleCssExports.ts')\n await writeBundleCssExports({\n cwd: ctx.cwd,\n distPath: ctx.distPath,\n cssNames: [mergedCssName],\n logger: ctx.logger,\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsDA,SAAgB,oBAAoB,KAAkC;CACpE,IAAM,EAAC,QAAQ,KAAK,UAAU,WAAU,KAElC,cAAc,WAA2B;EAC7C,IAAM,QAAQ,KACX,SAAS,UAAU,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC,CAC7C,WAAW,MAAM,GAAG,CAAC,CACrB,QAAQ,YAAY,EAAE;EACzB,IAAI,MAAM,WAAW,IAAI,GACvB,MAAU,MAAM,+CAA+C,QAAQ;EAEzE,OAAO;CACT,GASM,gCAAgB,IAAI,IAAqC,GACzD,iCAAiB,IAAI,IAAwB,GAE7C,YACJ,UACA,SACA,UAMG;EACH,eAAe,IAAI,UAAU,OAAO;EACpC,IAAM,EAAC,QAAQ,eAAc,OACvB,0BAAU,IAAI,IAAY,GAC1B,0BAAU,IAAI,IAAe;EASnC,IARI,MAAM,WACR,QAAQ,IAAI,WAAW,MAAM,MAAM,CAAC,GACpC,QAAQ,IAAI,KAAK,IAEf,MAAM,YACR,QAAQ,IAAI,WAAW,MAAM,OAAO,CAAC,GACrC,QAAQ,IAAI,UAAU,IAEpB,QAAQ,SAAS,GAAG;EACxB,IAAI,QAAQ,OAAO,GACjB,MAAU,MACR,6CACE,aAAa,YAAY,WAAW,MAAM,kBAAkB,SAC7D,iFACS,MAAM,OAAO,OAAO,MAAM,SACtC;EAEF,IAAM,CAAC,SAAS,SACZ,SAAS,cAAc,IAAI,QAAQ;EACvC,AAAK,WACH,yBAAS,IAAI,IAAI,GACjB,cAAc,IAAI,UAAU,MAAM;EAEpC,IAAM,WAAW,OAAO,IAAI,KAAM;EAClC,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AC,aAAa;IACxB,QAAQ,IAAI;GACd,CAAC;EACH,CAAC;CACH;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as createLogger, r as isRecord, t as handleError } from "./handleError-83GwKIFM.js";
|
|
2
2
|
import { a as loadPkgWithReporting, o as loadConfig, t as resolveBuildContext } from "./resolveBuildContext-vVTRkIDl.js";
|
|
3
|
-
import { r as resolveTsdownBuilds, t as resolveTsdownConfig } from "./resolveTsdownConfig-
|
|
4
|
-
import { t as writeBundleCssExports } from "./writeBundleCssExports-
|
|
3
|
+
import { r as resolveTsdownBuilds, t as resolveTsdownConfig } from "./resolveTsdownConfig-DunhV2W-.js";
|
|
4
|
+
import { t as writeBundleCssExports } from "./writeBundleCssExports-DlqASssv.js";
|
|
5
5
|
import { up } from "empathic/package";
|
|
6
6
|
import { build } from "tsdown";
|
|
7
7
|
import { switchMap } from "rxjs";
|
|
@@ -114,4 +114,4 @@ async function watchAction(options) {
|
|
|
114
114
|
}
|
|
115
115
|
export { watchAction };
|
|
116
116
|
|
|
117
|
-
//# sourceMappingURL=watchAction-
|
|
117
|
+
//# sourceMappingURL=watchAction-BcwDTNcj.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watchAction-BiD7pJr4.js","names":["findPkgPath","tsdownBuild"],"sources":["../src/node/core/pkg/cssExportOptions.ts","../src/node/watch.ts","../src/cli/watchAction.ts"],"sourcesContent":["import {isRecord} from '../isRecord.ts'\n\n/**\n * Whether a CSS pipeline's options wire up the conditional CSS export pattern — the no-op JS\n * shim, its declaration file, and the `\"./<fileName>\"` export whose `node`/`default` conditions\n * point at the shim.\n *\n * `pkg watch` needs this to decide which exports to maintain itself, because watch mode turns\n * tsdown's `exports` feature off. Full builds never ask: the plugins own the answer there.\n *\n * Only `exports` decides. `@sanity/tsdown-config` composes the plugin options as\n * `{inject: true, exports: {nodeCompat: true}, ...userOptions}`, so `exports` is always set by\n * the time `resolveCssExportOptions` sees them — a user-supplied `inject` never clears the\n * default. That makes the plugin's compatibility fallback for the deprecated\n * `inject: {nodeCompat: true}` spelling unreachable from here, and reading `inject` would get\n * `{inject: {nodeCompat: false}}` wrong: it still leaves the `exports` default in place, so the\n * conditional export is written.\n *\n * Kept in sync with `resolveCssExportOptions` in `@sanity/vanilla-extract-rolldown-plugin` —\n * the same reason `cssShimFileName` has a copy here. Importing the canonical one would make\n * `@sanity/vanilla-extract-tsdown-plugin` a static dependency of this module graph, pulling the\n * whole vanilla-extract toolchain into every `pkg build`.\n *\n * @internal\n */\nexport function usesCssExportNodeCompat(options: {exports?: unknown}): boolean {\n if (options.exports === undefined) {\n // `@sanity/tsdown-config`'s `exports: {nodeCompat: true}` default applies\n return true\n }\n return isRecord(options.exports) && options.exports['nodeCompat'] === true\n}\n","import {up as findPkgPath} from 'empathic/package'\nimport type {Subscription} from 'rxjs'\nimport {switchMap} from 'rxjs'\nimport {build as tsdownBuild, type TsdownBundle} from 'tsdown'\nimport {loadConfig} from './core/config/loadConfig.ts'\nimport {usesCssExportNodeCompat} from './core/pkg/cssExportOptions.ts'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting.ts'\nimport {writeBundleCssExports} from './core/pkg/writeBundleCssExports.ts'\nimport {createLogger} from './logger.ts'\nimport {resolveBuildContext} from './resolveBuildContext.ts'\nimport {resolveTsdownBuilds} from './tasks/tsdown/resolveTsdownBuilds.ts'\nimport {resolveTsdownConfig} from './tasks/tsdown/resolveTsdownConfig.ts'\n\nconst asyncDispose: typeof Symbol.asyncDispose =\n Symbol.asyncDispose || Symbol.for('Symbol.asyncDispose')\n\n/** @public */\nexport async function watch(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n signal?: AbortSignal\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption, signal} = options\n\n const logger = createLogger()\n\n const {watchConfigFiles} = await import('./watchConfigFiles.ts')\n const configFiles$ = await watchConfigFiles({cwd, logger})\n\n // Every rebuild of the waterfall holds tsdown watchers (one per platform build); they are\n // disposed when the config files change (the waterfall restarts) or the signal aborts.\n // RxJS does not await async subscriber callbacks, so a monotonically increasing run id\n // guards the rebuilds: only the latest run may publish into `bundles`, and a run that turns\n // stale mid-flight (a newer config-file event, or the abort signal) disposes the watchers\n // it created instead of leaking them.\n let bundles: TsdownBundle[] = []\n let runId = 0\n const disposeBundles = async () => {\n const disposing = bundles\n bundles = []\n for (const bundle of disposing) {\n await bundle[asyncDispose]()\n }\n }\n\n const ctx$ = configFiles$.pipe(\n switchMap(async () => {\n const pkgPath = findPkgPath({cwd})\n if (!pkgPath) {\n throw new Error('missing package.json', {cause: {cwd}})\n }\n\n const config = await loadConfig({cwd, pkgPath})\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({pkgPath, logger, strict, strictOptions})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n }),\n )\n\n const ctxSubscription: Subscription = ctx$.subscribe(async (ctx) => {\n const id = ++runId\n const runBundles: TsdownBundle[] = []\n try {\n await disposeBundles()\n\n // Full builds write the conditional `./<css>` export through tsdown's\n // `exports.customExports` composition, but watch mode disables tsdown's `exports` feature\n // (a package.json write per rebuild would loop the watcher). Keep the export in sync here\n // instead, once per context, like v11 — the write is idempotent, so it won't loop.\n const cssNames: string[] = []\n const cssSources: Record<string, string> = {}\n\n const vanillaExtract = ctx.config?.vanillaExtract\n if (vanillaExtract) {\n const veOptions = vanillaExtract === true ? {} : vanillaExtract\n if (usesCssExportNodeCompat(veOptions)) {\n cssNames.push(veOptions.fileName || 'bundle.css')\n }\n }\n\n // The `@tsdown/css` pipeline's own exports: the `.css` export subpaths built by the\n // stylesheet build. Their file names follow their subpath and a declared entry always\n // emits, so they are known up front. The merged `style.css` of CSS imported from JS is\n // not — it only exists once something actually imports CSS — so `resolveTsdownConfig`\n // declares that one from a `build:done` hook instead, matching what\n // `cssNodeCompatPlugin` declares in a full build.\n const cssConfig = ctx.config?.css\n const cssNodeCompat =\n (Boolean(cssConfig) || ctx.cssExports.length > 0) &&\n usesCssExportNodeCompat(cssConfig ?? {})\n if (cssNodeCompat) {\n for (const cssExport of ctx.cssExports) {\n cssNames.push(cssExport._path.replace(/^\\.\\//, ''))\n cssSources[cssExport._path] = cssExport.source\n }\n }\n\n await writeBundleCssExports({\n cwd,\n distPath: ctx.distPath,\n cssNames,\n sources: cssSources,\n logger,\n })\n\n const builds = resolveTsdownBuilds(ctx)\n\n let first = true\n for (const buildDef of builds) {\n if (id !== runId) break\n\n const inlineConfig = await resolveTsdownConfig(ctx, buildDef, {\n clean: first,\n watch: true,\n })\n first = false\n\n runBundles.push(...(await tsdownBuild(inlineConfig)))\n }\n\n if (id !== runId) {\n // A newer run (or the abort signal) took over while this rebuild was in flight —\n // dispose everything this run created instead of publishing it\n for (const bundle of runBundles) {\n await bundle[asyncDispose]()\n }\n return\n }\n\n bundles = runBundles\n\n logger.success(`${ctx.pkg.name}: watching for file changes\\u2026`)\n logger.log()\n } catch (err) {\n ctx.logger.error(err)\n ctx.logger.log()\n\n process.exit(1)\n }\n })\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n runId++\n ctxSubscription.unsubscribe()\n void disposeBundles()\n },\n {once: true},\n )\n }\n}\n","import {watch} from '../node/watch.ts'\nimport {handleError} from './handleError.ts'\n\nexport async function watchAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {\n try {\n await watch({\n cwd: process.cwd(),\n strict: options.strict,\n tsconfig: options.tsconfig,\n })\n } catch (err) {\n handleError(err)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,wBAAwB,SAAuC;CAK7E,OAJI,QAAQ,YAAY,KAAA,KAIjB,SAAS,QAAQ,OAAO,KAAK,QAAQ,QAAQ,eAAkB;AACxE;AClBA,MAAM,eACJ,OAAO,gBAAgB,OAAO,I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","../src/cli/watchAction.ts"],"sourcesContent":["import {isRecord} from '../isRecord.ts'\n\n/**\n * Whether a CSS pipeline's options wire up the conditional CSS export pattern — the no-op JS\n * shim, its declaration file, and the `\"./<fileName>\"` export whose `node`/`default` conditions\n * point at the shim.\n *\n * `pkg watch` needs this to decide which exports to maintain itself, because watch mode turns\n * tsdown's `exports` feature off. Full builds never ask: the plugins own the answer there.\n *\n * Only `exports` decides. `@sanity/tsdown-config` composes the plugin options as\n * `{inject: true, exports: {nodeCompat: true}, ...userOptions}`, so `exports` is always set by\n * the time `resolveCssExportOptions` sees them — a user-supplied `inject` never clears the\n * default. That makes the plugin's compatibility fallback for the deprecated\n * `inject: {nodeCompat: true}` spelling unreachable from here, and reading `inject` would get\n * `{inject: {nodeCompat: false}}` wrong: it still leaves the `exports` default in place, so the\n * conditional export is written.\n *\n * Kept in sync with `resolveCssExportOptions` in `@sanity/vanilla-extract-rolldown-plugin` —\n * the same reason `cssShimFileName` has a copy here. Importing the canonical one would make\n * `@sanity/vanilla-extract-tsdown-plugin` a static dependency of this module graph, pulling the\n * whole vanilla-extract toolchain into every `pkg build`.\n *\n * @internal\n */\nexport function usesCssExportNodeCompat(options: {exports?: unknown}): boolean {\n if (options.exports === undefined) {\n // `@sanity/tsdown-config`'s `exports: {nodeCompat: true}` default applies\n return true\n }\n return isRecord(options.exports) && options.exports['nodeCompat'] === true\n}\n","import {up as findPkgPath} from 'empathic/package'\nimport type {Subscription} from 'rxjs'\nimport {switchMap} from 'rxjs'\nimport {build as tsdownBuild, type TsdownBundle} from 'tsdown'\nimport {loadConfig} from './core/config/loadConfig.ts'\nimport {usesCssExportNodeCompat} from './core/pkg/cssExportOptions.ts'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting.ts'\nimport {writeBundleCssExports} from './core/pkg/writeBundleCssExports.ts'\nimport {createLogger} from './logger.ts'\nimport {resolveBuildContext} from './resolveBuildContext.ts'\nimport {resolveTsdownBuilds} from './tasks/tsdown/resolveTsdownBuilds.ts'\nimport {resolveTsdownConfig} from './tasks/tsdown/resolveTsdownConfig.ts'\n\nconst asyncDispose: typeof Symbol.asyncDispose =\n Symbol.asyncDispose || Symbol.for('Symbol.asyncDispose')\n\n/** @public */\nexport async function watch(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n signal?: AbortSignal\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption, signal} = options\n\n const logger = createLogger()\n\n const {watchConfigFiles} = await import('./watchConfigFiles.ts')\n const configFiles$ = await watchConfigFiles({cwd, logger})\n\n // Every rebuild of the waterfall holds tsdown watchers (one per platform build); they are\n // disposed when the config files change (the waterfall restarts) or the signal aborts.\n // RxJS does not await async subscriber callbacks, so a monotonically increasing run id\n // guards the rebuilds: only the latest run may publish into `bundles`, and a run that turns\n // stale mid-flight (a newer config-file event, or the abort signal) disposes the watchers\n // it created instead of leaking them.\n let bundles: TsdownBundle[] = []\n let runId = 0\n const disposeBundles = async () => {\n const disposing = bundles\n bundles = []\n for (const bundle of disposing) {\n await bundle[asyncDispose]()\n }\n }\n\n const ctx$ = configFiles$.pipe(\n switchMap(async () => {\n const pkgPath = findPkgPath({cwd})\n if (!pkgPath) {\n throw new Error('missing package.json', {cause: {cwd}})\n }\n\n const config = await loadConfig({cwd, pkgPath})\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({pkgPath, logger, strict, strictOptions})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n }),\n )\n\n const ctxSubscription: Subscription = ctx$.subscribe(async (ctx) => {\n const id = ++runId\n const runBundles: TsdownBundle[] = []\n try {\n await disposeBundles()\n\n // Full builds write the conditional `./<css>` export through tsdown's\n // `exports.customExports` composition, but watch mode disables tsdown's `exports` feature\n // (a package.json write per rebuild would loop the watcher). Keep the export in sync here\n // instead, once per context, like v11 — the write is idempotent, so it won't loop.\n const cssNames: string[] = []\n const cssSources: Record<string, string> = {}\n\n const vanillaExtract = ctx.config?.vanillaExtract\n if (vanillaExtract) {\n const veOptions = vanillaExtract === true ? {} : vanillaExtract\n if (usesCssExportNodeCompat(veOptions)) {\n cssNames.push(veOptions.fileName || 'bundle.css')\n }\n }\n\n // The `@tsdown/css` pipeline's own exports: the `.css` export subpaths built by the\n // stylesheet build. Their file names follow their subpath and a declared entry always\n // emits, so they are known up front. The merged `style.css` of CSS imported from JS is\n // not — it only exists once something actually imports CSS — so `resolveTsdownConfig`\n // declares that one from a `build:done` hook instead, matching what\n // `cssNodeCompatPlugin` declares in a full build.\n const cssConfig = ctx.config?.css\n const cssNodeCompat =\n (Boolean(cssConfig) || ctx.cssExports.length > 0) &&\n usesCssExportNodeCompat(cssConfig ?? {})\n if (cssNodeCompat) {\n for (const cssExport of ctx.cssExports) {\n cssNames.push(cssExport._path.replace(/^\\.\\//, ''))\n cssSources[cssExport._path] = cssExport.source\n }\n }\n\n await writeBundleCssExports({\n cwd,\n distPath: ctx.distPath,\n cssNames,\n sources: cssSources,\n logger,\n })\n\n const builds = resolveTsdownBuilds(ctx)\n\n let first = true\n for (const buildDef of builds) {\n if (id !== runId) break\n\n const inlineConfig = await resolveTsdownConfig(ctx, buildDef, {\n clean: first,\n watch: true,\n })\n first = false\n\n runBundles.push(...(await tsdownBuild(inlineConfig)))\n }\n\n if (id !== runId) {\n // A newer run (or the abort signal) took over while this rebuild was in flight —\n // dispose everything this run created instead of publishing it\n for (const bundle of runBundles) {\n await bundle[asyncDispose]()\n }\n return\n }\n\n bundles = runBundles\n\n logger.success(`${ctx.pkg.name}: watching for file changes\\u2026`)\n logger.log()\n } catch (err) {\n ctx.logger.error(err)\n ctx.logger.log()\n\n process.exit(1)\n }\n })\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n runId++\n ctxSubscription.unsubscribe()\n void disposeBundles()\n },\n {once: true},\n )\n }\n}\n","import {watch} from '../node/watch.ts'\nimport {handleError} from './handleError.ts'\n\nexport async function watchAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {\n try {\n await watch({\n cwd: process.cwd(),\n strict: options.strict,\n tsconfig: options.tsconfig,\n })\n } catch (err) {\n handleError(err)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,wBAAwB,SAAuC;CAK7E,OAJI,QAAQ,YAAY,KAAA,KAIjB,SAAS,QAAQ,OAAO,KAAK,QAAQ,QAAQ,eAAkB;AACxE;AClBA,MAAM,eACJ,OAAO,gBAAgB,OAAO,IAAI,qBAAqB;;AAGzD,eAAsB,MAAM,SAKV;CAChB,IAAM,EAAC,KAAK,SAAS,IAAO,UAAU,gBAAgB,WAAU,SAE1D,SAAS,aAAa,GAEtB,EAAC,qBAAoB,MAAM,OAAO,mCAClC,eAAe,MAAM,iBAAiB;EAAC;EAAK;CAAM,CAAC,GAQrD,UAA0B,CAAC,GAC3B,QAAQ,GACN,iBAAiB,YAAY;EACjC,IAAM,YAAY;EAClB,UAAU,CAAC;EACX,KAAK,IAAM,UAAU,WACnB,MAAM,OAAO,aAAa,CAAC;CAE/B,GAmBM,kBAjBO,aAAa,KACxB,UAAU,YAAY;EACpB,IAAM,UAAUA,GAAY,EAAC,IAAG,CAAC;EACjC,IAAI,CAAC,SACH,MAAU,MAAM,wBAAwB,EAAC,OAAO,EAAC,IAAG,EAAC,CAAC;EAGxD,IAAM,SAAS,MAAM,WAAW;GAAC;GAAK;EAAO,CAAC,GACxC,EAAC,uBAAsB,MAAM,OAAO,oCAAc,CAAA,MAAA,MAAA,EAAA,CAAA,GAClD,gBAAgB,mBAAmB,QAAQ,iBAAiB,CAAC,CAAC,GAC9D,MAAM,MAAM,qBAAqB;GAAC;GAAS;GAAQ;GAAQ;EAAa,CAAC,GACzE,WAAW,kBAAkB,QAAQ,YAAY;EAEvD,OAAO,oBAAoB;GAAC;GAAQ;GAAK;GAAQ;GAAK;GAAQ;EAAQ,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AAFA,SACA,gBAAgB,YAAY,GAC5B,eAAoB;CACtB,GACA,EAAC,MAAM,GAAI,CACb;AAEJ;ACzJA,eAAsB,YAAY,SAA+D;CAC/F,IAAI;EACF,MAAM,MAAM;GACV,KAAK,QAAQ,IAAI;GACjB,QAAQ,QAAQ;GAChB,UAAU,QAAQ;EACpB,CAAC;CACH,SAAS,KAAK;EACZ,YAAY,GAAG;CACjB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as isRecord } from "./handleError-83GwKIFM.js";
|
|
2
|
-
import { n as createConditionalCssExport } from "./resolveTsdownConfig-
|
|
2
|
+
import { n as createConditionalCssExport } from "./resolveTsdownConfig-DunhV2W-.js";
|
|
3
3
|
import { t as __exportAll } from "./initAction-CmOO8eod.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { readFile, writeFile } from "node:fs/promises";
|
|
@@ -61,4 +61,4 @@ async function writeBundleCssExports(options) {
|
|
|
61
61
|
}
|
|
62
62
|
export { writeBundleCssExports_exports as n, writeBundleCssExports as t };
|
|
63
63
|
|
|
64
|
-
//# sourceMappingURL=writeBundleCssExports-
|
|
64
|
+
//# sourceMappingURL=writeBundleCssExports-DlqASssv.js.map
|
package/dist/{writeBundleCssExports-BK5XC19e.js.map → writeBundleCssExports-DlqASssv.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeBundleCssExports-
|
|
1
|
+
{"version":3,"file":"writeBundleCssExports-DlqASssv.js","names":[],"sources":["../src/node/core/pkg/writeBundleCssExports.ts"],"sourcesContent":["import {readFile, writeFile} from 'node:fs/promises'\nimport path from 'node:path'\nimport type {Logger} from '../../logger.ts'\nimport {isRecord} from '../isRecord.ts'\nimport {createConditionalCssExport} from './cssExport.ts'\n\nfunction hasMatchingExport(value: unknown, expected: Record<string, string>): boolean {\n if (typeof value !== 'object' || value === null) return false\n const actual = Object.fromEntries(Object.entries(value))\n const keys = Object.keys(expected)\n return (\n keys.length === Object.keys(actual).length && keys.every((key) => actual[key] === expected[key])\n )\n}\n\n/**\n * Insert (or replace) the `\"./<cssName>\"` export in an `exports`-shaped map, preserving the existing\n * order and placing it before `./package.json` when present.\n */\nfunction 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\nfunction detectIndent(source: string): string | number {\n const match = source.match(/\\n([ \\t]+)\\S/)\n if (!match) return 2\n const indent = match[1]!\n return indent.includes('\\t') ? '\\t' : indent.length\n}\n\n/**\n * Write the conditional `\"./<cssName>\"` export of every CSS file to `package.json` (used by\n * `exports.nodeCompat`), so userland does not have to maintain it by hand. The write is\n * idempotent: if every export already matches, the file is left untouched.\n *\n * Full builds write these entries through tsdown's `exports.customExports` (the\n * `@sanity/vanilla-extract-tsdown-plugin` composition, and the `@sanity/tsdown-config` one for\n * `@tsdown/css` output), but watch mode disables tsdown's `exports` feature (a `package.json`\n * write per rebuild would loop the watcher) — `pkg watch` calls this once per context instead,\n * like v11 did.\n *\n * When `publishConfig.exports` is present, the same conditional CSS exports are mirrored into it.\n * A conditional CSS export has no `source`/`development`/`monorepo` conditions to strip, so the\n * entries are identical in both places — except for a hand-written `source`, which stays in\n * `exports` only. Keeping them in sync prevents the `publishConfig.exports` validation from\n * failing with a \"missing export path\" error for the auto-added `./<cssName>` exports.\n *\n * @internal\n */\nexport async function writeBundleCssExports(options: {\n cwd: string\n distPath: string\n cssNames: string[]\n /** Hand-written `source` conditions to preserve in `exports`, keyed by export subpath. */\n sources?: Record<string, string>\n logger: Logger\n}): Promise<void> {\n const {cwd, distPath, cssNames, sources = {}, logger} = options\n if (cssNames.length === 0) return\n\n const pkgPath = path.resolve(cwd, 'package.json')\n const source = await readFile(pkgPath, 'utf8')\n // oxlint-disable-next-line no-unsafe-type-assertion\n const pkg = JSON.parse(source) as {\n exports?: Record<string, unknown>\n publishConfig?: {exports?: Record<string, unknown>}\n }\n\n // Normalize to POSIX separators - `path.relative` uses `\\\\` on Windows, but `exports` paths in\n // package.json must always use `/`.\n const distRel = (path.relative(cwd, distPath) || 'dist').split(path.sep).join('/')\n\n // Only mirror into `publishConfig.exports` when it already exists; never create it here.\n const publishConfig = pkg.publishConfig\n const publishConfigExports = isRecord(publishConfig?.exports) ? publishConfig.exports : undefined\n\n const written: string[] = []\n let exports = pkg.exports ?? {}\n let publishExports = publishConfigExports\n\n for (const cssName of cssNames) {\n const exportKey = `./${cssName}`\n const publishExport = createConditionalCssExport(cssName, distRel)\n // A hand-written `source` resolves at development time only, so it stays out of the\n // publish map — the same split `composeExports` applies to build entries.\n const sourceCondition = sources[exportKey]\n const localExport =\n sourceCondition === undefined ? publishExport : {source: sourceCondition, ...publishExport}\n\n const exportsMatch = hasMatchingExport(exports[exportKey], localExport)\n const publishExportsMatch =\n !publishExports || hasMatchingExport(publishExports[exportKey], publishExport)\n if (exportsMatch && publishExportsMatch) continue\n\n exports = insertCssExport(exports, exportKey, localExport)\n if (publishExports) {\n publishExports = insertCssExport(publishExports, exportKey, publishExport)\n }\n written.push(exportKey)\n }\n\n if (written.length === 0) return\n\n pkg.exports = exports\n if (publishConfig && publishExports) {\n publishConfig.exports = publishExports\n }\n\n await writeFile(pkgPath, `${JSON.stringify(pkg, null, detectIndent(source))}\\n`)\n const maps = publishConfigExports ? ['exports', 'publishConfig.exports'] : ['exports']\n const keys = maps\n .flatMap((map) => written.map((key) => `\\`${map}[\"${key}\"]\\``))\n .join(', ')\n .replace(/, ([^,]*)$/, written.length * maps.length > 1 ? ' and $1' : '$1')\n logger.log(`Updated package.json: added ${keys} for the conditional CSS export pattern`)\n}\n"],"mappings":";;;;;;AAMA,SAAS,kBAAkB,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AM,YAAY,KAAK,WACjB,gBAAgB,2BAA2B,SAAS,OAAO,GAG3D,kBAAkB,QAAQ,YAC1B,cACJ,oBAAoB,KAAA,IAAY,gBAAgB;GAAC,QAAQ;GAAiB,GAAG;EAAa,GAEtF,eAAe,kBAAkB,QAAQ,YAAY,WAAW,GAChE,sBACJ,CAAC,kBAAkB,kBAAkB,eAAe,YAAY,aAAa;EAC3E,gBAAgB,wBAEpB,UAAU,gBAAgB,SAAS,WAAW,WAAW,GACzD,AACE,mBAAiB,gBAAgB,gBAAgB,WAAW,aAAa,GAE3E,QAAQ,KAAK,SAAS;CACxB;CAEA,IAAI,QAAQ,WAAW,GAAG;CAO1B,AALA,IAAI,UAAU,SACV,iBAAiB,mBACnB,cAAc,UAAU,iBAG1B,MAAM,UAAU,SAAS,GAAG,KAAK,UAAU,KAAK,MAAM,aAAa,MAAM,CAAC,EAAE,GAAG;CAC/E,IAAM,OAAO,uBAAuB,CAAC,WAAW,uBAAuB,IAAI,CAAC,SAAS,GAC/E,OAAO,KACV,SAAS,QAAQ,QAAQ,KAAK,QAAQ,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,CAC9D,KAAK,IAAI,CAAC,CACV,QAAQ,cAAc,QAAQ,SAAS,KAAK,SAAS,IAAI,YAAY,IAAI;CAC5E,OAAO,IAAI,+BAA+B,KAAK,wCAAwC;AACzF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"tsx": "^4.23.12",
|
|
68
68
|
"zod": "^4.4.3",
|
|
69
69
|
"zod-validation-error": "^5.0.0",
|
|
70
|
-
"@sanity/
|
|
71
|
-
"@sanity/
|
|
70
|
+
"@sanity/parse-package-json": "^2.3.2",
|
|
71
|
+
"@sanity/tsdown-config": "^0.26.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/find-config": "^1.0.4",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"@types/treeify": "^1.0.3",
|
|
79
79
|
"babel-plugin-react-compiler": "1.0.0",
|
|
80
80
|
"nanoexec": "^1.1.0",
|
|
81
|
+
"oxc-transform-react": "0.145.0",
|
|
81
82
|
"parse-github-url": "^1.0.4",
|
|
82
83
|
"rimraf": "^6.1.3",
|
|
83
84
|
"typescript": "7.0.2",
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
"peerDependencies": {
|
|
88
89
|
"@tsdown/css": "*",
|
|
89
90
|
"babel-plugin-react-compiler": "*",
|
|
91
|
+
"oxc-transform-react": "*",
|
|
90
92
|
"typescript": "6.x || 7.x"
|
|
91
93
|
},
|
|
92
94
|
"peerDependenciesMeta": {
|
|
@@ -95,6 +97,9 @@
|
|
|
95
97
|
},
|
|
96
98
|
"babel-plugin-react-compiler": {
|
|
97
99
|
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"oxc-transform-react": {
|
|
102
|
+
"optional": true
|
|
98
103
|
}
|
|
99
104
|
},
|
|
100
105
|
"engines": {
|