@sanity/pkg-utils 7.2.9-canary.0 → 7.2.10-canary.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/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import browserslist from "browserslist";
12
12
  import config$1 from "@sanity/browserslist-config";
13
13
  import ts from "typescript";
14
14
  import { errorMap } from "zod-validation-error";
15
- import { Observable, switchMap } from "rxjs";
15
+ import { Observable, from, switchMap } from "rxjs";
16
16
  import { ExtractorConfig, Extractor } from "@microsoft/api-extractor";
17
17
  import { mkdirp } from "mkdirp";
18
18
  import * as prettier from "prettier";
@@ -21,16 +21,18 @@ import { TSDocConfigFile } from "@microsoft/tsdoc-config";
21
21
  import { parse } from "jsonc-parser";
22
22
  import { parse as parse$1, print } from "recast";
23
23
  import typeScriptParser from "recast/parsers/typescript.js";
24
- import { rollup, watch as watch$1 } from "rollup";
24
+ import { rolldown } from "rolldown";
25
25
  import { optimizeLodashImports } from "@optimize-lodash/rollup-plugin";
26
26
  import alias from "@rollup/plugin-alias";
27
- import { babel, getBabelOutputPlugin } from "@rollup/plugin-babel";
27
+ import { getBabelOutputPlugin, babel } from "@rollup/plugin-babel";
28
28
  import commonjs from "@rollup/plugin-commonjs";
29
29
  import json from "@rollup/plugin-json";
30
30
  import { nodeResolve } from "@rollup/plugin-node-resolve";
31
- import replace from "@rollup/plugin-replace";
32
31
  import terser from "@rollup/plugin-terser";
32
+ import { dts } from "rolldown-plugin-dts";
33
33
  import esbuild from "rollup-plugin-esbuild";
34
+ import { rollup, watch as watch$1 } from "rollup";
35
+ import replace from "@rollup/plugin-replace";
34
36
  import esbuild$1 from "esbuild";
35
37
  import treeify from "treeify";
36
38
  import prettyBytes from "pretty-bytes";
@@ -555,7 +557,8 @@ async function resolveBuildContext(options) {
555
557
  ts: {
556
558
  config: tsconfig,
557
559
  configPath: tsconfigPath
558
- }
560
+ },
561
+ dts: config2?.dts === "rolldown" ? "rolldown" : "api-extractor"
559
562
  };
560
563
  }
561
564
  function transformPackageName(packageName) {
@@ -573,95 +576,102 @@ function resolveBuildTasks(ctx) {
573
576
  ), dtsTask2 = {
574
577
  type: "build:dts",
575
578
  entries: []
576
- }, rollupTasks = {};
579
+ }, rolldownDtsTask2 = {}, rollupTasks = {};
577
580
  function addRollupTaskEntry(format2, runtime, entry) {
578
581
  const buildId = `${format2}:${runtime}`;
579
- rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
582
+ ctx.dts === "rolldown" && (rolldownDtsTask2[buildId] ? rolldownDtsTask2[buildId].entries.push(entry) : rolldownDtsTask2[buildId] = {
583
+ type: "rolldown:dts",
584
+ buildId,
585
+ entries: [entry],
586
+ runtime,
587
+ format: format2,
588
+ target: target[runtime]
589
+ }), ctx.emitDeclarationOnly || (rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
580
590
  type: "build:js",
581
591
  buildId,
582
592
  entries: [entry],
583
593
  runtime,
584
594
  format: format2,
585
595
  target: target[runtime]
586
- };
587
- }
588
- for (const exp of exports) {
589
- const importId = path.join(pkg.name, exp._path);
590
- exp.source?.endsWith(".ts") && dtsTask2.entries.push({
591
- importId,
592
- exportPath: exp._path,
593
- sourcePath: exp.source,
594
- targetPaths: getTargetPaths(pkg.type, exp)
595
- }), exp.browser?.source?.endsWith(".ts") && dtsTask2.entries.push({
596
- importId,
597
- exportPath: exp._path,
598
- sourcePath: exp.browser.source,
599
- targetPaths: getTargetPaths(pkg.type, exp.browser)
600
- }), exp.node?.source?.endsWith(".ts") && dtsTask2.entries.push({
601
- importId,
602
- exportPath: exp._path,
603
- sourcePath: exp.node.source,
604
- targetPaths: getTargetPaths(pkg.type, exp.node)
605
596
  });
606
597
  }
607
- for (const bundle of bundles)
608
- if (bundle.source?.endsWith(".ts")) {
609
- const exportPath = (bundle.import || bundle.require).replace(/\.[mc]?js$/, ""), importId = path.join(pkg.name, exportPath);
610
- dtsTask2.entries.push({
611
- importId,
612
- exportPath,
613
- sourcePath: bundle.source,
614
- targetPaths: getTargetPaths(pkg.type, bundle)
615
- });
616
- }
617
- if (dtsTask2.entries.length && tasks.push(dtsTask2), !ctx.emitDeclarationOnly) {
618
- for (const exp of exports) {
619
- const output = exp.require;
620
- output && addRollupTaskEntry("commonjs", ctx.runtime, {
621
- path: exp._path,
622
- source: exp.source,
623
- output
624
- });
625
- }
626
- for (const exp of exports) {
627
- const output = exp.import;
628
- output && addRollupTaskEntry("esm", ctx.runtime, {
629
- path: exp._path,
630
- source: exp.source,
631
- output
632
- });
633
- }
634
- for (const exp of exports) {
635
- const output = exp.browser?.require;
636
- output && addRollupTaskEntry("commonjs", "browser", {
637
- path: exp._path,
638
- source: exp.browser?.source || exp.source,
639
- output
640
- });
641
- }
598
+ if (ctx.dts === "api-extractor") {
642
599
  for (const exp of exports) {
643
- const output = exp.browser?.import;
644
- output && addRollupTaskEntry("esm", "browser", {
645
- path: exp._path,
646
- source: exp.browser?.source || exp.source,
647
- output
648
- });
649
- }
650
- for (const bundle of bundles) {
651
- const idx = bundles.indexOf(bundle);
652
- bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
653
- path: `__$$bundle_cjs_${idx}$$__`,
654
- source: bundle.source,
655
- output: bundle.require
656
- }), bundle.import && addRollupTaskEntry("esm", bundle.runtime || ctx.runtime, {
657
- path: `__$$bundle_esm_${idx}$$__`,
658
- source: bundle.source,
659
- output: bundle.import
600
+ const importId = path.join(pkg.name, exp._path);
601
+ exp.source?.endsWith(".ts") && dtsTask2.entries.push({
602
+ importId,
603
+ exportPath: exp._path,
604
+ sourcePath: exp.source,
605
+ targetPaths: getTargetPaths(pkg.type, exp)
606
+ }), exp.browser?.source?.endsWith(".ts") && dtsTask2.entries.push({
607
+ importId,
608
+ exportPath: exp._path,
609
+ sourcePath: exp.browser.source,
610
+ targetPaths: getTargetPaths(pkg.type, exp.browser)
611
+ }), exp.node?.source?.endsWith(".ts") && dtsTask2.entries.push({
612
+ importId,
613
+ exportPath: exp._path,
614
+ sourcePath: exp.node.source,
615
+ targetPaths: getTargetPaths(pkg.type, exp.node)
660
616
  });
661
617
  }
662
- tasks.push(...Object.values(rollupTasks));
618
+ for (const bundle of bundles)
619
+ if (bundle.source?.endsWith(".ts")) {
620
+ const exportPath = (bundle.import || bundle.require).replace(/\.[mc]?js$/, ""), importId = path.join(pkg.name, exportPath);
621
+ dtsTask2.entries.push({
622
+ importId,
623
+ exportPath,
624
+ sourcePath: bundle.source,
625
+ targetPaths: getTargetPaths(pkg.type, bundle)
626
+ });
627
+ }
628
+ dtsTask2.entries.length && tasks.push(dtsTask2);
629
+ }
630
+ for (const exp of exports) {
631
+ const output = exp.require;
632
+ output && addRollupTaskEntry("commonjs", ctx.runtime, {
633
+ path: exp._path,
634
+ source: exp.source,
635
+ output
636
+ });
637
+ }
638
+ for (const exp of exports) {
639
+ const output = exp.import;
640
+ output && addRollupTaskEntry("esm", ctx.runtime, {
641
+ path: exp._path,
642
+ source: exp.source,
643
+ output
644
+ });
663
645
  }
664
- return tasks;
646
+ for (const exp of exports) {
647
+ const output = exp.browser?.require;
648
+ output && addRollupTaskEntry("commonjs", "browser", {
649
+ path: exp._path,
650
+ source: exp.browser?.source || exp.source,
651
+ output
652
+ });
653
+ }
654
+ for (const exp of exports) {
655
+ const output = exp.browser?.import;
656
+ output && addRollupTaskEntry("esm", "browser", {
657
+ path: exp._path,
658
+ source: exp.browser?.source || exp.source,
659
+ output
660
+ });
661
+ }
662
+ for (const bundle of bundles) {
663
+ const idx = bundles.indexOf(bundle);
664
+ bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
665
+ path: `__$$bundle_cjs_${idx}$$__`,
666
+ source: bundle.source,
667
+ output: bundle.require
668
+ }), bundle.import && addRollupTaskEntry("esm", bundle.runtime || ctx.runtime, {
669
+ path: `__$$bundle_esm_${idx}$$__`,
670
+ source: bundle.source,
671
+ output: bundle.import
672
+ });
673
+ }
674
+ return tasks.push(...Object.values(rolldownDtsTask2)), tasks.push(...Object.values(rollupTasks)), tasks;
665
675
  }
666
676
  function createSpinner(msg) {
667
677
  const startTime = Date.now();
@@ -753,7 +763,8 @@ function createApiExtractorConfig(options) {
753
763
  projectFolder,
754
764
  mainEntryPointFilePath,
755
765
  tsconfig,
756
- tsconfigPath
766
+ tsconfigPath,
767
+ dtsRollupEnabled
757
768
  } = options;
758
769
  return {
759
770
  apiReport: {
@@ -776,7 +787,7 @@ function createApiExtractorConfig(options) {
776
787
  apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`)
777
788
  },
778
789
  dtsRollup: {
779
- enabled: !0,
790
+ enabled: dtsRollupEnabled,
780
791
  untrimmedFilePath: path.resolve(distPath, filePath)
781
792
  // betaTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-beta.d.ts')),
782
793
  // publicTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-public.d.ts')),
@@ -832,7 +843,7 @@ const LOG_LEVELS = {
832
843
  warn: "warning"
833
844
  };
834
845
  function getExtractMessagesConfig(options) {
835
- const { rules } = options;
846
+ const { rules, disabled = !1 } = options;
836
847
  function ruleToLogLevel(key, defaultLevel) {
837
848
  const r = rules?.[key];
838
849
  return r ? LOG_LEVELS[r] : defaultLevel || "warning";
@@ -840,10 +851,15 @@ function getExtractMessagesConfig(options) {
840
851
  return {
841
852
  compilerMessageReporting: {
842
853
  default: {
843
- logLevel: "warning"
854
+ logLevel: disabled ? "none" : "warning"
844
855
  }
845
856
  },
846
- extractorMessageReporting: {
857
+ extractorMessageReporting: disabled ? {
858
+ default: {
859
+ logLevel: "none",
860
+ addToApiReportFile: !1
861
+ }
862
+ } : {
847
863
  default: {
848
864
  logLevel: "warning",
849
865
  addToApiReportFile: !1
@@ -873,13 +889,21 @@ function getExtractMessagesConfig(options) {
873
889
  addToApiReportFile: !1
874
890
  }
875
891
  },
876
- tsdocMessageReporting: {
892
+ tsdocMessageReporting: disabled ? {
893
+ default: {
894
+ logLevel: "none",
895
+ addToApiReportFile: !1
896
+ }
897
+ } : {
877
898
  default: {
878
899
  logLevel: "warning",
879
900
  addToApiReportFile: !1
880
901
  },
881
902
  "tsdoc-link-tag-unescaped-text": {
882
- logLevel: ruleToLogLevel("tsdoc-link-tag-unescaped-text", "warning"),
903
+ logLevel: ruleToLogLevel(
904
+ "tsdoc-link-tag-unescaped-text",
905
+ "warning"
906
+ ),
883
907
  addToApiReportFile: !1
884
908
  },
885
909
  "tsdoc-undefined-tag": {
@@ -906,7 +930,8 @@ async function extractTypes(options) {
906
930
  sourceTypesPath,
907
931
  tmpPath,
908
932
  tsconfig,
909
- tsconfigPath
933
+ tsconfigPath,
934
+ extractorDisabled
910
935
  } = options, tsdocConfigFile = await createTSDocConfig({
911
936
  customTags: customTags || []
912
937
  }), filePath = filePaths[0].replace(/\.d\.[mc]ts$/, ".d.ts"), shouldCleanUpDts = !filePaths.includes(filePath), extractorConfig = ExtractorConfig.prepare({
@@ -915,11 +940,12 @@ async function extractTypes(options) {
915
940
  distPath,
916
941
  exportPath,
917
942
  filePath,
918
- messages: getExtractMessagesConfig({ rules }),
943
+ messages: getExtractMessagesConfig({ rules, disabled: extractorDisabled }),
919
944
  projectFolder: projectPath,
920
945
  mainEntryPointFilePath: sourceTypesPath,
921
946
  tsconfig,
922
- tsconfigPath
947
+ tsconfigPath,
948
+ dtsRollupEnabled: !0
923
949
  }),
924
950
  configObjectFullPath: void 0,
925
951
  tsdocConfigFile,
@@ -979,7 +1005,8 @@ async function doExtract(ctx, task) {
979
1005
  sourceTypesPath,
980
1006
  tsconfig: ts2.config,
981
1007
  tmpPath,
982
- tsconfigPath: path.resolve(cwd, ts2.configPath || "tsconfig.json")
1008
+ tsconfigPath: path.resolve(cwd, ts2.configPath || "tsconfig.json"),
1009
+ extractorDisabled: config2?.extract?.enabled === !1
983
1010
  });
984
1011
  messages.push(...result.messages);
985
1012
  const errors = result.messages.filter((msg) => msg.logLevel === "error");
@@ -990,8 +1017,8 @@ async function doExtract(ctx, task) {
990
1017
  return await rimraf$1(tmpPath), { type: "dts", messages, results };
991
1018
  }
992
1019
  const dtsTask = {
993
- name: (_ctx, task) => [
994
- "Build type definitions...",
1020
+ name: (ctx, task) => [
1021
+ `Build type definitions with ${chalk.bold(ctx.dts)}...`,
995
1022
  " entries:",
996
1023
  ...task.entries.map((entry) => entry.targetPaths.map((targetPath) => [
997
1024
  ` - ${chalk.cyan(entry.importId)}: `,
@@ -1089,7 +1116,8 @@ const dtsTask = {
1089
1116
  sourceTypesPath,
1090
1117
  tsconfig: tsContext.config,
1091
1118
  tmpPath,
1092
- tsconfigPath: path.resolve(cwd, tsContext.configPath || "tsconfig.json")
1119
+ tsconfigPath: path.resolve(cwd, tsContext.configPath || "tsconfig.json"),
1120
+ extractorDisabled: config2?.extract?.enabled === !1
1093
1121
  });
1094
1122
  messages.push(...result.messages), results.push({ sourcePath: path.resolve(cwd, entry.sourcePath), filePaths: targetPaths });
1095
1123
  } catch (err) {
@@ -1137,6 +1165,174 @@ function createConsoleSpy(options) {
1137
1165
  }
1138
1166
  };
1139
1167
  }
1168
+ function resolveRolldownConfig(ctx, buildTask) {
1169
+ const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, outputExt = pkgExtMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
1170
+ Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
1171
+ ), entries = buildTask.entries.map((entry) => ({
1172
+ ...entry,
1173
+ name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
1174
+ }), {}), exportIds = _exports && Object.keys(_exports).map((exportPath) => path.join(pkg.name, exportPath)), sourcePaths = _exports && Object.values(_exports).map((e) => path.resolve(cwd, e.source)), replacements = Object.fromEntries(
1175
+ Object.entries(config2?.define || {}).map(([key, val]) => [key, JSON.stringify(val)])
1176
+ ), { optimizeLodash: enableOptimizeLodash = hasDependency$1(pkg, "lodash") } = config2?.rollup || {};
1177
+ [
1178
+ alias({
1179
+ entries: { ...pathAliases }
1180
+ }),
1181
+ nodeResolve({
1182
+ browser: runtime === "browser",
1183
+ extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
1184
+ preferBuiltins: !0
1185
+ }),
1186
+ commonjs(),
1187
+ json(),
1188
+ esbuild({
1189
+ target,
1190
+ tsconfig: ctx.ts.configPath || "tsconfig.json",
1191
+ treeShaking: !0,
1192
+ minifySyntax: config2?.minify !== !1,
1193
+ supported: {
1194
+ "template-literal": !0
1195
+ }
1196
+ }),
1197
+ Array.isArray(config2?.babel?.plugins) && getBabelOutputPlugin({
1198
+ babelrc: !1,
1199
+ plugins: config2.babel.plugins
1200
+ }),
1201
+ enableOptimizeLodash && optimizeLodashImports({
1202
+ useLodashEs: format2 === "esm" && hasDependency$1(pkg, "lodash-es") ? !0 : void 0,
1203
+ ...typeof config2?.rollup?.optimizeLodash == "boolean" ? {} : config2?.rollup?.optimizeLodash
1204
+ }),
1205
+ minify && terser({
1206
+ compress: { directives: !1, passes: 10 },
1207
+ ecma: 2020,
1208
+ output: {
1209
+ comments: (_node, comment) => {
1210
+ const text = comment.value;
1211
+ return comment.type === "comment2" ? /@preserve|@license|@cc_on/i.test(text) : !1;
1212
+ },
1213
+ preserve_annotations: !0
1214
+ }
1215
+ })
1216
+ ].filter(Boolean);
1217
+ const hashChunkFileNames = config2?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = `[name]${outputExt}`, inputOptions = {
1218
+ cwd,
1219
+ jsx: {
1220
+ mode: config2?.jsx === "automatic" ? "automatic" : config2?.jsx === "preserve" ? "preserve" : config2?.jsx === "transform" ? "classic" : "automatic",
1221
+ factory: config2?.jsxFactory,
1222
+ fragment: config2?.jsxFragment,
1223
+ importSource: config2?.jsxImportSource
1224
+ },
1225
+ define: pkg.name === "@sanity/pkg-utils" ? { ...replacements } : {
1226
+ "process.env.PKG_FORMAT": JSON.stringify(format2),
1227
+ "process.env.PKG_RUNTIME": JSON.stringify(runtime),
1228
+ "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version),
1229
+ ...replacements
1230
+ },
1231
+ external: (id, importer) => {
1232
+ if (exportIds?.includes(id))
1233
+ return !0;
1234
+ if (importer && (id.startsWith(".") || id.startsWith("/"))) {
1235
+ const idPath = path.resolve(path.dirname(importer), id);
1236
+ if (sourcePaths?.includes(idPath))
1237
+ return logger.warn(
1238
+ `detected self-referencing import \u2013 treating as external: ${path.relative(
1239
+ cwd,
1240
+ idPath
1241
+ )}`
1242
+ ), !0;
1243
+ }
1244
+ const idParts = id.split("/"), name = idParts[0].startsWith("@") ? `${idParts[0]}/${idParts[1]}` : idParts[0];
1245
+ return !!(name && external.includes(name));
1246
+ },
1247
+ input: entries.reduce(
1248
+ (acc, entry) => Object.assign(acc, { [entry.name]: entry.source }),
1249
+ {}
1250
+ ),
1251
+ plugins: [dts({ emitDtsOnly: !0, tsconfig: ctx.ts.configPath || "tsconfig.json" })],
1252
+ treeshake: !0
1253
+ }, outputOptions = {
1254
+ chunkFileNames,
1255
+ dir: outDir,
1256
+ entryFileNames,
1257
+ esModule: !0,
1258
+ format: buildTask.type === "rolldown:dts" ? "es" : format2,
1259
+ sourcemap: buildTask.type === "rolldown:dts" ? !1 : config2?.sourcemap ?? !0,
1260
+ hoistTransitiveImports: !1
1261
+ };
1262
+ return { inputOptions, outputOptions };
1263
+ }
1264
+ function hasDependency$1(pkg, packageName) {
1265
+ return pkg.dependencies ? packageName in pkg.dependencies : pkg.peerDependencies ? packageName in pkg.peerDependencies : !1;
1266
+ }
1267
+ const rolldownDtsTask = {
1268
+ name: (ctx, task) => {
1269
+ const bundleEntries = task.entries.filter((e) => e.path.includes("__$$bundle_")), entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk.yellow(t)}`)] : [], bundlesLines = bundleEntries.length ? [
1270
+ " bundles:",
1271
+ ...bundleEntries.map(
1272
+ (e) => [
1273
+ " - ",
1274
+ `${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
1275
+ ].join("")
1276
+ )
1277
+ ] : [], entriesLines = entries.length ? [
1278
+ " entries:",
1279
+ ...entries.map(
1280
+ (e) => [
1281
+ " - ",
1282
+ `${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
1283
+ `${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
1284
+ ].join("")
1285
+ )
1286
+ ] : [];
1287
+ return [
1288
+ `Build type definitions with ${chalk.bold("rolldown")}...`,
1289
+ ` format: ${chalk.yellow(task.format)}`,
1290
+ ...targetLines,
1291
+ ...bundlesLines,
1292
+ ...entriesLines
1293
+ ].join(`
1294
+ `);
1295
+ },
1296
+ exec: (ctx, task) => from(execPromise$1(ctx, task)),
1297
+ complete: () => {
1298
+ },
1299
+ error: (_ctx, _task, err) => {
1300
+ console.error(err);
1301
+ }
1302
+ };
1303
+ async function execPromise$1(ctx, task) {
1304
+ const { distPath, files, logger } = ctx, outDir = path.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
1305
+ onRestored: (messages) => {
1306
+ for (const msg of messages) {
1307
+ const text = String(msg.args[0]);
1308
+ msg.code !== "CIRCULAR_DEPENDENCY" && (text.startsWith("Dynamic import can only") || text.startsWith("Sourcemap is likely to be incorrect") || (msg.type === "log" && logger.info(...msg.args), msg.type === "warn" && logger.warn(...msg.args), msg.type === "error" && logger.error(...msg.args)));
1309
+ }
1310
+ }
1311
+ });
1312
+ try {
1313
+ const { inputOptions, outputOptions } = resolveRolldownConfig(ctx, task), bundle = await rolldown({
1314
+ ...inputOptions,
1315
+ onwarn(warning) {
1316
+ consoleSpy.messages.push({
1317
+ type: "warn",
1318
+ code: warning.code,
1319
+ args: [warning.message]
1320
+ });
1321
+ }
1322
+ }), { output } = await bundle.generate(outputOptions);
1323
+ for (const chunkOrAsset of output)
1324
+ chunkOrAsset.type === "asset" ? files.push({
1325
+ type: "asset",
1326
+ path: path.resolve(outDir, chunkOrAsset.fileName)
1327
+ }) : files.push({
1328
+ type: "chunk",
1329
+ path: path.resolve(outDir, chunkOrAsset.fileName)
1330
+ });
1331
+ await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
1332
+ } catch (err) {
1333
+ throw consoleSpy.restore(), err;
1334
+ }
1335
+ }
1140
1336
  function resolveRollupConfig(ctx, buildTask) {
1141
1337
  const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, outputExt = pkgExtMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
1142
1338
  Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
@@ -1398,7 +1594,8 @@ const rollupWatchTask = {
1398
1594
  }
1399
1595
  }, buildTaskHandlers = {
1400
1596
  "build:dts": dtsTask,
1401
- "build:js": rollupTask
1597
+ "build:js": rollupTask,
1598
+ "rolldown:dts": rolldownDtsTask
1402
1599
  }, watchTaskHandlers = {
1403
1600
  "watch:dts": dtsWatchTask,
1404
1601
  "watch:js": rollupWatchTask