@sanity/pkg-utils 5.1.2 → 5.1.3

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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist/_chunks-cjs/build.cjs +36 -16
  3. package/dist/_chunks-cjs/build.cjs.map +1 -1
  4. package/dist/_chunks-cjs/check.cjs +4 -4
  5. package/dist/_chunks-cjs/check.cjs.map +1 -1
  6. package/dist/_chunks-cjs/consoleSpy.cjs +65 -40
  7. package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
  8. package/dist/_chunks-cjs/handleError.cjs +3 -3
  9. package/dist/_chunks-cjs/index.cjs +77 -40
  10. package/dist/_chunks-cjs/index.cjs.map +1 -1
  11. package/dist/_chunks-cjs/init.cjs +3 -3
  12. package/dist/_chunks-cjs/logger.cjs +3 -3
  13. package/dist/_chunks-cjs/watch.cjs +8 -8
  14. package/dist/_chunks-cjs/watch.cjs.map +1 -1
  15. package/dist/cli.cjs +3 -3
  16. package/dist/index.cjs +2 -2
  17. package/dist/index.d.cts +21 -10
  18. package/dist/index.d.ts +21 -10
  19. package/dist/index.js +164 -84
  20. package/dist/index.js.map +1 -1
  21. package/package.json +2 -2
  22. package/src/node/build.ts +1 -3
  23. package/src/node/check.ts +2 -3
  24. package/src/node/core/contexts/buildContext.ts +4 -5
  25. package/src/node/core/pkg/parseExports.ts +35 -13
  26. package/src/node/core/pkg/pkgExt.ts +6 -19
  27. package/src/node/core/pkg/validateExports.ts +6 -5
  28. package/src/node/resolveBuildContext.ts +11 -11
  29. package/src/node/resolveBuildTasks.ts +49 -7
  30. package/src/node/tasks/dts/buildTypes.ts +5 -1
  31. package/src/node/tasks/dts/getTargetPaths.ts +6 -2
  32. package/src/node/tasks/index.ts +3 -2
  33. package/src/node/tasks/rollup/index.ts +1 -0
  34. package/src/node/tasks/rollup/resolveRollupConfig.ts +22 -31
  35. package/src/node/tasks/rollup/rollupLegacyTask.ts +144 -0
  36. package/src/node/tasks/rollup/rollupTask.ts +2 -2
  37. package/src/node/tasks/types.ts +16 -5
  38. package/src/node/watch.ts +3 -4
package/dist/index.js CHANGED
@@ -208,8 +208,41 @@ async function loadPkgWithReporting(options2) {
208
208
  function formatPath(segments) {
209
209
  return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
210
210
  }
211
+ const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", legacyEnding = ".esm.js", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
212
+ function getTargetPaths(_type, expOrBundle) {
213
+ const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
214
+ return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
215
+ expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
216
+ ), expOrBundle.browser?.require && set.add(
217
+ expOrBundle.browser.require.replace(
218
+ fileEnding,
219
+ type === "commonjs" ? dtsEnding : ctsEnding
220
+ )
221
+ )), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
222
+ expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
223
+ ), expOrBundle.node?.require && set.add(
224
+ expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
225
+ ))), Array.from(set);
226
+ }
227
+ function isPkgExport(exp) {
228
+ return exp?.browser || exp?.node || exp?.default;
229
+ }
230
+ const pkgExtMap = {
231
+ // pkg.type: "commonjs"
232
+ commonjs: {
233
+ commonjs: ".js",
234
+ esm: ".mjs"
235
+ },
236
+ // pkg.type: "module"
237
+ module: {
238
+ commonjs: ".cjs",
239
+ esm: ".js"
240
+ },
241
+ // package.config.legacyExports: true
242
+ legacy: legacyEnding
243
+ };
211
244
  function validateExports(_exports, options2) {
212
- const { extMap, pkg } = options2, ext = extMap[pkg.type || "commonjs"], errors = [];
245
+ const { pkg } = options2, ext = pkgExtMap[pkg.type || "commonjs"], errors = [];
213
246
  for (const exp of _exports)
214
247
  exp.require && !exp.require.endsWith(ext.commonjs) && errors.push(
215
248
  `package.json with \`type: "${pkg.type}"\` - \`exports["${exp._path}"].require\` must end with "${ext.commonjs}"`
@@ -219,7 +252,7 @@ function validateExports(_exports, options2) {
219
252
  return errors;
220
253
  }
221
254
  function parseExports(options2) {
222
- const { extMap, pkg, strict } = options2, rootExport = {
255
+ const { pkg, strict, legacyExports } = options2, rootExport = {
223
256
  _exported: !0,
224
257
  _path: ".",
225
258
  source: pkg.source || "",
@@ -232,24 +265,31 @@ function parseExports(options2) {
232
265
  import: pkg.module,
233
266
  default: pkg.module || pkg.main || ""
234
267
  }, extraExports = [], errors = [];
235
- if (strict && !pkg.types && pkg.source?.endsWith(".ts") && pkg.exports && errors.push(
236
- "package.json: `types` must be declared for the npm listing to show as a TypeScript module."
237
- ), strict && "typings" in pkg && errors.push("package.json: `typings` should be `types`"), pkg.exports) {
238
- strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
268
+ if (strict && "typings" in pkg && errors.push("package.json: `typings` should be `types`"), pkg.exports) {
269
+ strict && !pkg.types && pkg.source?.endsWith(".ts") && errors.push(
270
+ "package.json: `types` must be declared for the npm listing to show as a TypeScript module."
271
+ ), strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
239
272
  for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
240
273
  if (exportPath.endsWith(".json"))
241
274
  exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"] must be "./package.json".');
242
275
  else if (!(isRecord(exportEntry) && "svelte" in exportEntry))
243
276
  if (isRecord(exportEntry))
244
- if (exportPath === ".")
245
- exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require && errors.push(
277
+ if (exportPath === ".") {
278
+ if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require && errors.push(
246
279
  'package.json: mismatch between "main" and "exports.require". These must be equal.'
247
- ), exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import && errors.push(
248
- 'package.json: mismatch between "module" and "exports.import" These must be equal.'
249
- ), exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source && errors.push(
280
+ ), legacyExports) {
281
+ const indexLegacyExport = (exportEntry.browser?.import || exportEntry.import || exportEntry.browser?.require || exportEntry.require || "").replace(/(\.esm)?\.[mc]?js$/, legacyEnding);
282
+ indexLegacyExport !== rootExport.import && errors.push(
283
+ `package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`
284
+ );
285
+ } else
286
+ exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import && errors.push(
287
+ 'package.json: mismatch between "module" and "exports.import" These must be equal.'
288
+ );
289
+ exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source && errors.push(
250
290
  'package.json: mismatch between "source" and "exports.source". These must be equal.'
251
291
  ), Object.assign(rootExport, exportEntry);
252
- else {
292
+ } else {
253
293
  const extraExport = {
254
294
  _exported: !0,
255
295
  _path: exportPath,
@@ -261,31 +301,12 @@ function parseExports(options2) {
261
301
  errors.push("package.json: exports must be an object");
262
302
  }
263
303
  const _exports = [rootExport, ...extraExports];
264
- if (errors.push(...validateExports(_exports, { extMap, pkg })), errors.length)
304
+ if (errors.push(...validateExports(_exports, { pkg })), errors.length)
265
305
  throw new Error(`
266
306
  - ` + errors.join(`
267
307
  - `));
268
308
  return _exports;
269
309
  }
270
- const DEFAULT_PKG_EXT_MAP = {
271
- // pkg.type: "commonjs"
272
- commonjs: {
273
- commonjs: ".js",
274
- esm: ".mjs"
275
- },
276
- // pkg.type: "module"
277
- module: {
278
- commonjs: ".cjs",
279
- esm: ".js"
280
- }
281
- };
282
- function getPkgExtMap(options2) {
283
- const { legacyExports } = options2, ret = { ...DEFAULT_PKG_EXT_MAP };
284
- return legacyExports && (ret.commonjs = {
285
- commonjs: ".js",
286
- esm: ".esm.js"
287
- }), ret;
288
- }
289
310
  const promptsTypes = {
290
311
  string: "text"
291
312
  };
@@ -421,7 +442,6 @@ async function resolveBuildContext(options2) {
421
442
  config: config2,
422
443
  cwd,
423
444
  emitDeclarationOnly = !1,
424
- extMap,
425
445
  logger,
426
446
  pkg,
427
447
  strict,
@@ -444,7 +464,11 @@ async function resolveBuildContext(options2) {
444
464
  "*": webTarget.concat(nodeTarget),
445
465
  browser: webTarget,
446
466
  node: nodeTarget
447
- }, parsedExports = parseExports({ extMap, pkg, strict }).reduce((acc, x) => {
467
+ }, parsedExports = parseExports({
468
+ pkg,
469
+ strict,
470
+ legacyExports: config2?.legacyExports ?? !1
471
+ }).reduce((acc, x) => {
448
472
  const { _path: exportPath, ...exportEntry } = x;
449
473
  return { ...acc, [exportPath]: exportEntry };
450
474
  }, {}), exports = resolveConfigProperty(config2?.exports, parsedExports), parsedExternal = [
@@ -477,7 +501,6 @@ async function resolveBuildContext(options2) {
477
501
  emitDeclarationOnly,
478
502
  exports,
479
503
  external,
480
- extMap,
481
504
  files: [],
482
505
  logger,
483
506
  pkg,
@@ -490,32 +513,13 @@ async function resolveBuildContext(options2) {
490
513
  }
491
514
  };
492
515
  }
493
- const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
494
- function getTargetPaths(_type, expOrBundle) {
495
- const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
496
- return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
497
- expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
498
- ), expOrBundle.browser?.require && set.add(
499
- expOrBundle.browser.require.replace(
500
- fileEnding,
501
- type === "commonjs" ? dtsEnding : ctsEnding
502
- )
503
- )), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
504
- expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
505
- ), expOrBundle.node?.require && set.add(
506
- expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
507
- ))), Array.from(set);
508
- }
509
- function isPkgExport(exp) {
510
- return exp?.browser || exp?.node || exp?.default;
511
- }
512
516
  function resolveBuildTasks(ctx) {
513
517
  const { config: config2, cwd, pkg, target } = ctx, bundles = config2?.bundles || [], tasks = [], exports = Object.entries(ctx.exports || {}).map(
514
518
  ([_path, exp]) => ({ _path, ...exp })
515
519
  ), dtsTask2 = {
516
520
  type: "build:dts",
517
521
  entries: []
518
- }, rollupTasks = {};
522
+ }, rollupTasks = {}, rollupLegacyTasks = {};
519
523
  function addRollupTaskEntry(format2, runtime, entry) {
520
524
  const buildId = `${format2}:${runtime}`;
521
525
  rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
@@ -527,6 +531,18 @@ function resolveBuildTasks(ctx) {
527
531
  target: target[runtime]
528
532
  };
529
533
  }
534
+ function addRollupLegacyTaskEntry(runtime, entry) {
535
+ const buildId = `esm:${runtime}`;
536
+ rollupLegacyTasks[buildId] ? rollupLegacyTasks[buildId].entries.push(entry) : rollupLegacyTasks[buildId] = {
537
+ type: "build:legacy",
538
+ buildId,
539
+ entries: [entry],
540
+ runtime,
541
+ format: "esm",
542
+ // @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
543
+ target: target[runtime]
544
+ };
545
+ }
530
546
  for (const exp of exports) {
531
547
  const importId = path$1.join(pkg.name, exp._path);
532
548
  exp.source?.endsWith(".ts") && dtsTask2.entries.push({
@@ -589,6 +605,18 @@ function resolveBuildTasks(ctx) {
589
605
  output
590
606
  });
591
607
  }
608
+ if (config2?.legacyExports)
609
+ for (const exp of exports) {
610
+ const runtime = exp.browser?.import || exp.browser?.require ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import || exp.browser?.require || exp.require;
611
+ if (!output)
612
+ continue;
613
+ const legacyOutput = output.replace(fileEnding, legacyEnding);
614
+ addRollupLegacyTaskEntry(runtime, {
615
+ path: exp._path,
616
+ source: exp.browser?.source || exp.source,
617
+ output: legacyOutput
618
+ });
619
+ }
592
620
  for (const bundle of bundles) {
593
621
  const idx = bundles.indexOf(bundle);
594
622
  bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
@@ -601,13 +629,10 @@ function resolveBuildTasks(ctx) {
601
629
  output: bundle.import
602
630
  });
603
631
  }
604
- if (tasks.push(...Object.values(rollupTasks)), config2?.legacyExports) {
632
+ if (tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks)), config2?.legacyExports) {
605
633
  for (const exp of exports)
606
634
  if (exp._exported && exp._path !== ".") {
607
- const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(
608
- /\.[^/.]+$/,
609
- ""
610
- );
635
+ const relativeTargetPath = (exp.browser?.import || exp.import || exp.browser?.require || exp.require || "").replace(fileEnding, legacyEnding).replace(/\.[^/.]+$/, "");
611
636
  relativeTargetPath && fs$1.writeFileSync(
612
637
  path$1.resolve(cwd, `${exp._path}.js`),
613
638
  ["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
@@ -698,7 +723,7 @@ async function buildTypes(options2) {
698
723
  } : {}
699
724
  }, program = ts.createProgram(tsconfig.fileNames, compilerOptions), emitResult = program.emit(), allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
700
725
  for (const diagnostic of allDiagnostics)
701
- printDiagnostic({ cwd, logger, diagnostic });
726
+ diagnostic.code !== 2307 && printDiagnostic({ cwd, logger, diagnostic });
702
727
  if (emitResult.emitSkipped && allDiagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error).length && strict)
703
728
  throw new Error("failed to compile TypeScript definitions");
704
729
  }
@@ -20370,7 +20395,7 @@ function createConsoleSpy(options2) {
20370
20395
  };
20371
20396
  }
20372
20397
  function resolveRollupConfig(ctx, buildTask) {
20373
- const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, extMap, external, distPath, logger, pkg, ts: ts2 } = ctx, outputExt = extMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path$1.relative(cwd, distPath), pathAliases = Object.fromEntries(
20398
+ const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, isLegacyExports = buildTask.type === "build:legacy", outputExt = isLegacyExports ? pkgExtMap.legacy : pkgExtMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path$1.relative(cwd, distPath), pathAliases = Object.fromEntries(
20374
20399
  Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path$1.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
20375
20400
  ), entries = buildTask.entries.map((entry) => ({
20376
20401
  ...entry,
@@ -20399,12 +20424,9 @@ function resolveRollupConfig(ctx, buildTask) {
20399
20424
  entries: { ...pathAliases }
20400
20425
  }),
20401
20426
  nodeResolve({
20402
- // mainFields: ['module', 'jsnext', 'main'],
20403
20427
  browser: runtime === "browser",
20404
- // exportConditions: [runtime === 'node' ? 'node' : 'browser'],
20405
20428
  extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
20406
20429
  preferBuiltins: !0
20407
- // runtime === 'node',
20408
20430
  }),
20409
20431
  commonjs(),
20410
20432
  json(),
@@ -20423,7 +20445,7 @@ function resolveRollupConfig(ctx, buildTask) {
20423
20445
  }),
20424
20446
  Array.isArray(config2?.babel?.plugins) && getBabelOutputPlugin({
20425
20447
  babelrc: !1,
20426
- plugins: config2?.babel?.plugins
20448
+ plugins: config2.babel.plugins
20427
20449
  }),
20428
20450
  minify && terser({
20429
20451
  compress: { directives: !1 },
@@ -20434,7 +20456,7 @@ function resolveRollupConfig(ctx, buildTask) {
20434
20456
  }
20435
20457
  }
20436
20458
  })
20437
- ].filter(Boolean), userPlugins = config2?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config2?.rollup?.plugins, defaultPlugins);
20459
+ ].filter(Boolean), userPlugins = config2?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config2?.rollup?.plugins, defaultPlugins), hashChunkFileNames = config2?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${isLegacyExports ? "_legacy" : hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = isLegacyExports ? "[name].js" : `[name]${outputExt}`;
20438
20460
  return {
20439
20461
  inputOptions: {
20440
20462
  context: cwd,
@@ -20469,25 +20491,83 @@ function resolveRollupConfig(ctx, buildTask) {
20469
20491
  experimentalLogSideEffects: config2?.rollup?.experimentalLogSideEffects
20470
20492
  },
20471
20493
  outputOptions: {
20472
- chunkFileNames: () => {
20473
- const parts = outputExt.split("."), prefix = config2?.rollup?.hashChunkFileNames ? "[name]-[hash]" : "[name]", folder = config2?.rollup?.hashChunkFileNames ? "_chunks" : "_chunks-[format]";
20474
- return parts.length === 3 ? `${folder}/${prefix}.${parts[2]}` : `${folder}/${prefix}${outputExt}`;
20475
- },
20494
+ chunkFileNames,
20476
20495
  compact: minify,
20477
20496
  dir: outDir,
20478
- entryFileNames: () => {
20479
- const parts = outputExt.split(".");
20480
- return parts.length === 3 ? `[name].${parts[2]}` : `[name]${outputExt}`;
20481
- },
20497
+ entryFileNames,
20482
20498
  esModule: !0,
20483
20499
  format: format2,
20484
- interop: "compat",
20500
+ interop: "auto",
20485
20501
  sourcemap: config2?.sourcemap ?? !0,
20486
20502
  hoistTransitiveImports: !1,
20487
20503
  ...config2?.rollup?.output
20488
20504
  }
20489
20505
  };
20490
20506
  }
20507
+ const rollupLegacyTask = {
20508
+ name: (ctx, task) => {
20509
+ const entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk.yellow(t)}`)] : [], entriesLines = entries.length ? [
20510
+ " entries:",
20511
+ ...entries.map(
20512
+ (e) => [
20513
+ " - ",
20514
+ `${chalk.cyan(path$1.join(ctx.pkg.name, e.path))}: `,
20515
+ `${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
20516
+ ].join("")
20517
+ )
20518
+ ] : [];
20519
+ return [
20520
+ "Build legacy exports...",
20521
+ ` format: ${chalk.yellow(task.format)}`,
20522
+ ...targetLines,
20523
+ ...entriesLines
20524
+ ].join(`
20525
+ `);
20526
+ },
20527
+ exec: (ctx, task) => new Observable((observer) => {
20528
+ execPromise$1(ctx, task).then((result) => {
20529
+ observer.next(result), observer.complete();
20530
+ }).catch((err) => observer.error(err));
20531
+ }),
20532
+ complete: () => {
20533
+ },
20534
+ error: (_ctx, _task, err) => {
20535
+ console.error(err);
20536
+ }
20537
+ };
20538
+ async function execPromise$1(ctx, task) {
20539
+ const { distPath, files, logger } = ctx, outDir = path$1.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
20540
+ onRestored: (messages) => {
20541
+ for (const msg of messages) {
20542
+ const text = String(msg.args[0]);
20543
+ 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)));
20544
+ }
20545
+ }
20546
+ });
20547
+ try {
20548
+ const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup({
20549
+ ...inputOptions,
20550
+ onwarn(warning) {
20551
+ consoleSpy.messages.push({
20552
+ type: "warn",
20553
+ code: warning.code,
20554
+ args: [warning.message]
20555
+ });
20556
+ }
20557
+ }), { output } = await bundle.generate(outputOptions);
20558
+ for (const chunkOrAsset of output)
20559
+ chunkOrAsset.type === "asset" ? files.push({
20560
+ type: "asset",
20561
+ path: path$1.resolve(outDir, chunkOrAsset.fileName)
20562
+ }) : files.push({
20563
+ type: "chunk",
20564
+ path: path$1.resolve(outDir, chunkOrAsset.fileName)
20565
+ });
20566
+ await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
20567
+ } catch (err) {
20568
+ throw consoleSpy.restore(), err;
20569
+ }
20570
+ }
20491
20571
  const rollupTask = {
20492
20572
  name: (ctx, task) => {
20493
20573
  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 ? [
@@ -20600,17 +20680,17 @@ const rollupWatchTask = {
20600
20680
  }
20601
20681
  }, buildTaskHandlers = {
20602
20682
  "build:dts": dtsTask,
20603
- "build:js": rollupTask
20683
+ "build:js": rollupTask,
20684
+ "build:legacy": rollupLegacyTask
20604
20685
  }, watchTaskHandlers = {
20605
20686
  "watch:dts": dtsWatchTask,
20606
20687
  "watch:js": rollupWatchTask
20607
20688
  };
20608
20689
  async function build(options2) {
20609
- const { cwd, emitDeclarationOnly, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap({ legacyExports: config2?.legacyExports ?? !1 }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({
20690
+ const { cwd, emitDeclarationOnly, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({
20610
20691
  config: config2,
20611
20692
  cwd,
20612
20693
  emitDeclarationOnly,
20613
- extMap,
20614
20694
  logger,
20615
20695
  pkg,
20616
20696
  strict,
@@ -20666,7 +20746,7 @@ function printPackageTree(ctx) {
20666
20746
  ), logger.log(treeify.asTree(tree, !0, !0));
20667
20747
  }
20668
20748
  async function check(options2) {
20669
- const { cwd, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap({ legacyExports: config2?.legacyExports ?? !1 }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({ config: config2, cwd, extMap, logger, pkg, strict, tsconfig });
20749
+ const { cwd, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({ config: config2, cwd, logger, pkg, strict, tsconfig });
20670
20750
  if (printPackageTree(ctx), strict) {
20671
20751
  const missingFiles = [];
20672
20752
  for (const [, exp] of Object.entries(ctx.exports || {}))
@@ -21358,8 +21438,8 @@ async function watch(options2) {
21358
21438
  switchMap(async (configFiles) => {
21359
21439
  if (!configFiles.map((f) => path$1.relative(cwd, f)).find((f) => f === "package.json"))
21360
21440
  throw new Error("missing package.json");
21361
- const pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap({ legacyExports: config2?.legacyExports ?? !1 }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json";
21362
- return resolveBuildContext({ config: config2, cwd, extMap, logger, pkg, strict, tsconfig });
21441
+ const pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json";
21442
+ return resolveBuildContext({ config: config2, cwd, logger, pkg, strict, tsconfig });
21363
21443
  })
21364
21444
  ).subscribe(async (ctx) => {
21365
21445
  const watchTasks = resolveWatchTasks(ctx);
@@ -21381,7 +21461,6 @@ async function watch(options2) {
21381
21461
  }
21382
21462
  export {
21383
21463
  DEFAULT_BROWSERSLIST_QUERY,
21384
- DEFAULT_PKG_EXT_MAP,
21385
21464
  build,
21386
21465
  buildTaskHandlers,
21387
21466
  check,
@@ -21392,7 +21471,6 @@ export {
21392
21471
  dtsTask,
21393
21472
  dtsWatchTask,
21394
21473
  getExtractMessagesConfig,
21395
- getPkgExtMap,
21396
21474
  init,
21397
21475
  isRecord,
21398
21476
  loadConfig,
@@ -21400,8 +21478,10 @@ export {
21400
21478
  loadPkgWithReporting,
21401
21479
  loadTSConfig,
21402
21480
  parseExports,
21481
+ pkgExtMap,
21403
21482
  resolveBuildTasks,
21404
21483
  resolveConfigProperty,
21484
+ rollupLegacyTask,
21405
21485
  rollupTask,
21406
21486
  rollupWatchTask,
21407
21487
  watch,