@sanity/pkg-utils 6.13.3 → 7.0.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.
Files changed (41) hide show
  1. package/dist/_chunks-cjs/build.cjs +6 -58
  2. package/dist/_chunks-cjs/build.cjs.map +1 -1
  3. package/dist/_chunks-cjs/check.cjs +3 -3
  4. package/dist/_chunks-cjs/check.cjs.map +1 -1
  5. package/dist/_chunks-cjs/consoleSpy.cjs +23 -67
  6. package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
  7. package/dist/_chunks-cjs/index.cjs +10 -133
  8. package/dist/_chunks-cjs/index.cjs.map +1 -1
  9. package/dist/_chunks-cjs/logger.cjs +2 -12
  10. package/dist/_chunks-cjs/logger.cjs.map +1 -1
  11. package/dist/_chunks-cjs/watch.cjs +5 -21
  12. package/dist/_chunks-cjs/watch.cjs.map +1 -1
  13. package/dist/cli.cjs +1 -1
  14. package/dist/index.cjs +0 -2
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +12 -48
  17. package/dist/index.d.ts +12 -48
  18. package/dist/index.js +40 -283
  19. package/dist/index.js.map +1 -1
  20. package/package.json +3 -4
  21. package/src/node/build.ts +1 -2
  22. package/src/node/check.ts +1 -2
  23. package/src/node/core/config/types.ts +11 -16
  24. package/src/node/core/pkg/loadPkgWithReporting.ts +2 -10
  25. package/src/node/core/pkg/parseExports.ts +7 -46
  26. package/src/node/core/pkg/pkgExt.ts +1 -4
  27. package/src/node/core/pkg/validateExports.ts +0 -1
  28. package/src/node/core/pkg/validatePkg.ts +7 -17
  29. package/src/node/resolveBuildContext.ts +0 -3
  30. package/src/node/resolveBuildTasks.ts +4 -108
  31. package/src/node/resolveWatchTasks.ts +1 -23
  32. package/src/node/tasks/dts/createApiExtractorConfig.ts +1 -0
  33. package/src/node/tasks/dts/getExtractMessagesConfig.ts +5 -1
  34. package/src/node/tasks/dts/getTargetPaths.ts +0 -13
  35. package/src/node/tasks/index.ts +1 -3
  36. package/src/node/tasks/rollup/index.ts +0 -2
  37. package/src/node/tasks/rollup/resolveRollupConfig.ts +7 -15
  38. package/src/node/tasks/types.ts +1 -22
  39. package/src/node/watch.ts +1 -2
  40. package/src/node/tasks/rollup/rollupLegacyTask.ts +0 -145
  41. package/src/node/tasks/rollup/rollupReactCompilerTask.ts +0 -140
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import rimraf from "rimraf";
3
3
  import { register } from "esbuild-register/dist/node";
4
4
  import pkgUp from "pkg-up";
5
5
  import findConfig from "find-config";
6
- import fs$1, { statSync, existsSync } from "node:fs";
6
+ import { statSync, existsSync } from "node:fs";
7
7
  import { z, ZodError } from "zod";
8
8
  import chalk from "chalk";
9
9
  import fs, { writeFile, readFile, readdir, lstat } from "node:fs/promises";
@@ -112,16 +112,6 @@ const pkgSchema = z.object({
112
112
  require: z.optional(z.string())
113
113
  })
114
114
  ),
115
- "react-compiler": z.optional(
116
- // z.union([
117
- // @TODO add support for a string shortcut
118
- // z.string(),
119
- z.object({
120
- source: z.optional(z.string()),
121
- default: z.string()
122
- })
123
- // ]),
124
- ),
125
115
  node: z.optional(
126
116
  z.object({
127
117
  source: z.optional(z.string()),
@@ -175,13 +165,11 @@ function assertOrder(a, b, arr) {
175
165
  return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
176
166
  }
177
167
  async function loadPkgWithReporting(options) {
178
- const { cwd, logger, strict, legacyExports } = options;
168
+ const { cwd, logger, strict } = options;
179
169
  try {
180
170
  const pkg = await loadPkg({ cwd });
181
171
  let shouldError = !1;
182
- if (strict && (legacyExports && pkg.type === "commonjs" && (shouldError = !0, logger.error(
183
- 'the `type` field in `./package.json` shouldn\'t be "commonjs" when `legacyExports` is set to true)'
184
- )), !legacyExports && !pkg.type && (shouldError = !0, logger.error(
172
+ if (strict && (pkg.type || (shouldError = !0, logger.error(
185
173
  'the `type` field in `./package.json` must be either "module" or "commonjs")'
186
174
  ))), pkg.exports) {
187
175
  const _exports = Object.entries(pkg.exports);
@@ -234,7 +222,7 @@ async function loadPkgWithReporting(options) {
234
222
  function formatPath(segments) {
235
223
  return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
236
224
  }
237
- const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", defaultEnding = ".js", legacyEnding = `.esm${defaultEnding}`, mjsEnding = ".mjs", cjsEnding = ".cjs", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
225
+ const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", defaultEnding = ".js", mjsEnding = ".mjs", cjsEnding = ".cjs", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
238
226
  function getTargetPaths(_type, expOrBundle) {
239
227
  const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
240
228
  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$1(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
@@ -248,12 +236,7 @@ function getTargetPaths(_type, expOrBundle) {
248
236
  expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
249
237
  ), expOrBundle.node?.require && set.add(
250
238
  expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
251
- )), expOrBundle["react-compiler"]?.source || expOrBundle["react-compiler"]?.default && set.add(
252
- expOrBundle["react-compiler"].default.replace(
253
- fileEnding,
254
- type === "module" ? dtsEnding : mtsEnding
255
- )
256
- )), Array.from(set);
239
+ ))), Array.from(set);
257
240
  }
258
241
  function isPkgExport$1(exp) {
259
242
  return exp?.browser || exp?.node || exp?.default;
@@ -268,9 +251,7 @@ const pkgExtMap = {
268
251
  module: {
269
252
  commonjs: cjsEnding,
270
253
  esm: defaultEnding
271
- },
272
- // package.config.legacyExports: true
273
- legacy: legacyEnding
254
+ }
274
255
  };
275
256
  function validateExports(_exports, options) {
276
257
  const { pkg } = options, type = pkg.type || "commonjs", ext = pkgExtMap[type], errors = [];
@@ -283,7 +264,7 @@ function validateExports(_exports, options) {
283
264
  return errors;
284
265
  }
285
266
  function parseExports(options) {
286
- const { cwd, pkg, strict, strictOptions: strictOptions2, legacyExports, logger } = options, type = pkg.type || "commonjs", errors = [], report = (kind, message) => {
267
+ const { cwd, pkg, strict, strictOptions: strictOptions2, logger } = options, type = pkg.type || "commonjs", errors = [], report = (kind, message) => {
287
268
  kind === "warn" ? logger.warn(message) : errors.push(message);
288
269
  };
289
270
  if (!pkg.main && strict && strictOptions2.alwaysPackageJsonMain !== "off" && report(strictOptions2.alwaysPackageJsonMain, "package.json: `main` must be declared"), !Array.isArray(pkg.files) && strict && strictOptions2.alwaysPackageJsonFiles !== "off" && report(
@@ -298,27 +279,13 @@ function parseExports(options) {
298
279
  const extMap = pkgExtMap[type], importExport = pkg.main.replace(fileEnding, extMap.esm), requireExport = pkg.main.replace(fileEnding, extMap.commonjs), defaultExport = pkg.main.replace(fileEnding, defaultEnding), maybeBrowserCondition = [];
299
280
  if (pkg.browser) {
300
281
  const browserConditions = [];
301
- if (pkg.module && pkg.browser?.[pkg.module])
302
- browserConditions.push(
303
- ` "import": ${JSON.stringify(pkg.browser[pkg.module].replace(fileEnding, extMap.esm))}`
304
- );
305
- else if (pkg.browser?.[pkg.main])
306
- browserConditions.push(
307
- ` "import": ${JSON.stringify(pkg.browser?.[pkg.main].replace(fileEnding, extMap.esm))}`
308
- );
309
- else if (legacyExports) {
310
- const browserImport = pkg.main.replace(fileEnding, `.browser${extMap.esm}`);
311
- browserConditions.push(` "import": ${JSON.stringify(browserImport)}`);
312
- }
313
- if (pkg.browser?.[pkg.main])
314
- browserConditions.push(
315
- ` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`
316
- );
317
- else if (legacyExports) {
318
- const browserRequire = pkg.main.replace(fileEnding, `.browser${extMap.commonjs}`);
319
- browserConditions.push(` "require": ${JSON.stringify(browserRequire)}`);
320
- }
321
- browserConditions.length && maybeBrowserCondition.push(
282
+ pkg.module && pkg.browser?.[pkg.module] ? browserConditions.push(
283
+ ` "import": ${JSON.stringify(pkg.browser[pkg.module].replace(fileEnding, extMap.esm))}`
284
+ ) : pkg.browser?.[pkg.main] && browserConditions.push(
285
+ ` "import": ${JSON.stringify(pkg.browser?.[pkg.main].replace(fileEnding, extMap.esm))}`
286
+ ), pkg.browser?.[pkg.main] && browserConditions.push(
287
+ ` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`
288
+ ), browserConditions.length && maybeBrowserCondition.push(
322
289
  ' "browser": {',
323
290
  ` "source": ${JSON.stringify(pkg.browser?.[pkg.source] || pkg.source)},`,
324
291
  ...browserConditions,
@@ -333,9 +300,8 @@ function parseExports(options) {
333
300
  ` "source": ${JSON.stringify(pkg.source)},`,
334
301
  // If browser conditions are detected then add them to the suggestion
335
302
  ...maybeBrowserCondition.length > 0 ? maybeBrowserCondition : [],
336
- // If legacy exports are enabled we suggest the full list of exports, if not we can use the terse version
337
- (legacyExports || type === "commonjs") && ` "import": ${JSON.stringify(importExport)},`,
338
- (legacyExports || type === "module") && ` "require": ${JSON.stringify(requireExport)},`,
303
+ type === "commonjs" && ` "import": ${JSON.stringify(importExport)},`,
304
+ type === "module" && ` "require": ${JSON.stringify(requireExport)},`,
339
305
  ` "default": ${JSON.stringify(defaultExport)}`,
340
306
  " },",
341
307
  ' "./package.json": "./package.json"',
@@ -386,28 +352,13 @@ function parseExports(options) {
386
352
  };
387
353
  if (!exp.default) {
388
354
  const fallback = type === "module" ? exp.import : exp.require;
389
- fallback && (exp.default = fallback), legacyExports && (fallback ? errors.push(
390
- `package.json - \`exports["${exp._path}"].default\` should be set to "${fallback}" when "legacyExports" is true`
391
- ) : errors.push(
392
- `package.json - \`exports["${exp._path}"].default\` should be specified when "legacyExports" is true`
393
- ));
355
+ fallback && (exp.default = fallback);
394
356
  }
395
- if (!exp.require && type === "commonjs" && exp.default && (exp.require = exp.default), !exp.import && type === "module" && exp.default && (exp.import = exp.default), exportPath === ".")
396
- if (exportEntry.require && pkg.main && exportEntry.require !== pkg.main && errors.push(
397
- 'package.json: mismatch between "main" and "exports.require". These must be equal.'
398
- ), legacyExports) {
399
- const indexLegacyExport = (exportEntry.import || exportEntry.require || "").replace(
400
- /(\.esm)?\.[mc]?js$/,
401
- legacyEnding
402
- );
403
- indexLegacyExport !== pkg.module && errors.push(
404
- `package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`
405
- );
406
- } else
407
- exportEntry.import && pkg.module && exportEntry.import !== pkg.module && errors.push(
408
- 'package.json: mismatch between "module" and "exports.import" These must be equal.'
409
- );
410
- _exports.push(exp);
357
+ !exp.require && type === "commonjs" && exp.default && (exp.require = exp.default), !exp.import && type === "module" && exp.default && (exp.import = exp.default), exportPath === "." && (exportEntry.require && pkg.main && exportEntry.require !== pkg.main && errors.push(
358
+ 'package.json: mismatch between "main" and "exports.require". These must be equal.'
359
+ ), exportEntry.import && pkg.module && exportEntry.import !== pkg.module && errors.push(
360
+ 'package.json: mismatch between "module" and "exports.import" These must be equal.'
361
+ )), _exports.push(exp);
411
362
  } else isRecord(exportEntry) || errors.push("package.json: exports must be an object");
412
363
  if (errors.push(...validateExports(_exports, { pkg })), errors.length)
413
364
  throw new Error(`
@@ -603,7 +554,6 @@ async function resolveBuildContext(options) {
603
554
  cwd,
604
555
  pkg,
605
556
  strict,
606
- legacyExports: config2?.legacyExports ?? !1,
607
557
  strictOptions: strictOptions2,
608
558
  logger
609
559
  }).reduce((acc, x) => {
@@ -624,8 +574,6 @@ async function resolveBuildContext(options) {
624
574
  exportEntry.browser?.require,
625
575
  exportEntry.node?.source && exportEntry.node.import,
626
576
  exportEntry.node?.source && exportEntry.node.require
627
- // @TODO implement this
628
- // exportEntry['react-compiler']?.source && exportEntry['react-compiler']?.default,
629
577
  ].filter(Boolean)).map((p) => path.resolve(cwd, p)), commonDistPath = findCommonDirPath(outputPaths);
630
578
  if (commonDistPath === cwd)
631
579
  throw new Error(
@@ -669,18 +617,12 @@ function transformPackageName(packageName) {
669
617
  return `@types/${packageName}`;
670
618
  }
671
619
  function resolveBuildTasks(ctx) {
672
- const { config: config2, cwd, pkg, target } = ctx, bundles = config2?.bundles || [], tasks = [], exports = Object.entries(ctx.exports || {}).map(
620
+ const { config: config2, pkg, target } = ctx, bundles = config2?.bundles || [], tasks = [], exports = Object.entries(ctx.exports || {}).map(
673
621
  ([_path, exp]) => ({ _path, ...exp })
674
622
  ), dtsTask2 = {
675
623
  type: "build:dts",
676
624
  entries: []
677
- }, rollupTasks = {}, rollupLegacyTasks = {}, rollupReactCompilerTask2 = {
678
- type: "build:react-compiler",
679
- runtime: "browser",
680
- format: "esm",
681
- entries: [],
682
- target: target.browser
683
- };
625
+ }, rollupTasks = {};
684
626
  function addRollupTaskEntry(format2, runtime, entry) {
685
627
  const buildId = `${format2}:${runtime}`;
686
628
  rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
@@ -692,21 +634,6 @@ function resolveBuildTasks(ctx) {
692
634
  target: target[runtime]
693
635
  };
694
636
  }
695
- function addRollupLegacyTaskEntry(runtime, entry) {
696
- const buildId = `esm:${runtime}`;
697
- rollupLegacyTasks[buildId] ? rollupLegacyTasks[buildId].entries.push(entry) : rollupLegacyTasks[buildId] = {
698
- type: "build:legacy",
699
- buildId,
700
- entries: [entry],
701
- runtime,
702
- format: "esm",
703
- // @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
704
- target: target[runtime]
705
- };
706
- }
707
- function addRollupReactCompilerTaskEntry(entry) {
708
- rollupReactCompilerTask2.entries.push(entry);
709
- }
710
637
  for (const exp of exports) {
711
638
  const importId = path.join(pkg.name, exp._path);
712
639
  exp.source?.endsWith(".ts") && dtsTask2.entries.push({
@@ -769,25 +696,6 @@ function resolveBuildTasks(ctx) {
769
696
  output
770
697
  });
771
698
  }
772
- for (const exp of exports) {
773
- const output = exp["react-compiler"]?.default;
774
- output && addRollupReactCompilerTaskEntry({
775
- path: exp._path,
776
- source: exp["react-compiler"]?.source || exp.source,
777
- output
778
- });
779
- }
780
- if (rollupReactCompilerTask2.entries.length && tasks.push(rollupReactCompilerTask2), config2?.legacyExports)
781
- for (const exp of exports) {
782
- const runtime = exp.browser?.import ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import;
783
- if (!output) continue;
784
- const legacyOutput = output.replace(fileEnding, legacyEnding);
785
- addRollupLegacyTaskEntry(runtime, {
786
- path: exp._path,
787
- source: exp.browser?.source || exp.source,
788
- output: legacyOutput
789
- });
790
- }
791
699
  for (const bundle of bundles) {
792
700
  const idx = bundles.indexOf(bundle);
793
701
  bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
@@ -800,19 +708,7 @@ function resolveBuildTasks(ctx) {
800
708
  output: bundle.import
801
709
  });
802
710
  }
803
- if (tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks)), config2?.legacyExports) {
804
- for (const exp of exports)
805
- if (exp._exported && exp._path !== ".") {
806
- const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(fileEnding, legacyEnding).replace(/\.[^/.]+$/, "");
807
- relativeTargetPath && fs$1.writeFileSync(
808
- path.resolve(cwd, `${exp._path}.js`),
809
- ["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
810
- `
811
- `
812
- )
813
- );
814
- }
815
- }
711
+ tasks.push(...Object.values(rollupTasks));
816
712
  }
817
713
  return tasks;
818
714
  }
@@ -1002,7 +898,11 @@ function getExtractMessagesConfig(options) {
1002
898
  addToApiReportFile: !1
1003
899
  },
1004
900
  "ae-forgotten-export": {
1005
- logLevel: ruleToLogLevel("ae-forgotten-export", "none"),
901
+ /**
902
+ * This is hardcoded to `none` as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
903
+ * It's hardcoded to `none` since supported by API Extractor when using `module: 'Preserve'` doesn't support it well since `@microsoft/api-extractor` v7.49.0, which upgraded from TS 5.4 to 5.7 internally
904
+ */
905
+ logLevel: "none",
1006
906
  addToApiReportFile: !1
1007
907
  },
1008
908
  "ae-incompatible-release-tags": {
@@ -1288,7 +1188,7 @@ function createConsoleSpy(options) {
1288
1188
  };
1289
1189
  }
1290
1190
  function resolveRollupConfig(ctx, buildTask) {
1291
- const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, isLegacyExports = buildTask.type === "build:legacy", isReactCompiler = buildTask.type === "build:react-compiler", outputExt = isLegacyExports ? pkgExtMap.legacy : pkgExtMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
1191
+ 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(
1292
1192
  Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
1293
1193
  ), entries = buildTask.entries.map((entry) => ({
1294
1194
  ...entry,
@@ -1323,7 +1223,7 @@ function resolveRollupConfig(ctx, buildTask) {
1323
1223
  }),
1324
1224
  commonjs(),
1325
1225
  json(),
1326
- (isReactCompiler || config2?.babel?.reactCompiler || config2?.babel?.styledComponents) && babel({
1226
+ (config2?.babel?.reactCompiler || config2?.babel?.styledComponents) && babel({
1327
1227
  babelrc: !1,
1328
1228
  presets: ["@babel/preset-typescript"],
1329
1229
  babelHelpers: "bundled",
@@ -1344,7 +1244,7 @@ function resolveRollupConfig(ctx, buildTask) {
1344
1244
  ...typeof config2.babel.styledComponents == "object" ? config2.babel.styledComponents : {}
1345
1245
  }
1346
1246
  ],
1347
- (isReactCompiler || config2?.babel?.reactCompiler) && [
1247
+ config2?.babel?.reactCompiler && [
1348
1248
  "babel-plugin-react-compiler",
1349
1249
  config2?.reactCompilerOptions || {}
1350
1250
  ]
@@ -1382,7 +1282,7 @@ function resolveRollupConfig(ctx, buildTask) {
1382
1282
  preserve_annotations: !0
1383
1283
  }
1384
1284
  })
1385
- ].filter(Boolean), userPlugins = config2?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config2?.rollup?.plugins, defaultPlugins), hashChunkFileNames = config2?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${isReactCompiler ? "_compiled" : isLegacyExports ? "_legacy" : hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = isLegacyExports ? "[name].js" : `[name]${outputExt}`;
1285
+ ].filter(Boolean), userPlugins = config2?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config2?.rollup?.plugins, defaultPlugins), hashChunkFileNames = config2?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = `[name]${outputExt}`;
1386
1286
  return {
1387
1287
  inputOptions: {
1388
1288
  context: cwd,
@@ -1435,129 +1335,6 @@ function resolveRollupConfig(ctx, buildTask) {
1435
1335
  function hasDependency(pkg, packageName) {
1436
1336
  return pkg.dependencies ? packageName in pkg.dependencies : pkg.peerDependencies ? packageName in pkg.peerDependencies : !1;
1437
1337
  }
1438
- const rollupLegacyTask = {
1439
- name: (ctx, task) => {
1440
- 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 ? [
1441
- " entries:",
1442
- ...entries.map(
1443
- (e) => [
1444
- " - ",
1445
- `${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
1446
- `${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
1447
- ].join("")
1448
- )
1449
- ] : [];
1450
- return [
1451
- "Build legacy exports...",
1452
- ` format: ${chalk.yellow(task.format)}`,
1453
- ...targetLines,
1454
- ...entriesLines
1455
- ].join(`
1456
- `);
1457
- },
1458
- exec: (ctx, task) => new Observable((observer) => {
1459
- execPromise$2(ctx, task).then((result) => {
1460
- observer.next(result), observer.complete();
1461
- }).catch((err) => observer.error(err));
1462
- }),
1463
- complete: () => {
1464
- },
1465
- error: (_ctx, _task, err) => {
1466
- console.error(err);
1467
- }
1468
- };
1469
- async function execPromise$2(ctx, task) {
1470
- const { distPath, files, logger } = ctx, outDir = path.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
1471
- onRestored: (messages) => {
1472
- for (const msg of messages) {
1473
- const text = String(msg.args[0]);
1474
- 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)));
1475
- }
1476
- }
1477
- });
1478
- try {
1479
- const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup({
1480
- ...inputOptions,
1481
- onwarn(warning) {
1482
- consoleSpy.messages.push({
1483
- type: "warn",
1484
- code: warning.code,
1485
- args: [warning.message]
1486
- });
1487
- }
1488
- }), { output } = await bundle.generate(outputOptions);
1489
- for (const chunkOrAsset of output)
1490
- chunkOrAsset.type === "asset" ? files.push({
1491
- type: "asset",
1492
- path: path.resolve(outDir, chunkOrAsset.fileName)
1493
- }) : files.push({
1494
- type: "chunk",
1495
- path: path.resolve(outDir, chunkOrAsset.fileName)
1496
- });
1497
- await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
1498
- } catch (err) {
1499
- throw consoleSpy.restore(), err;
1500
- }
1501
- }
1502
- const rollupReactCompilerTask = {
1503
- name: (ctx, task) => {
1504
- 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 ? [
1505
- " entries:",
1506
- ...entries.map(
1507
- (e) => [
1508
- " - ",
1509
- `${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
1510
- `${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
1511
- ].join("")
1512
- )
1513
- ] : [];
1514
- return ["Build react compiler exports...", ...targetLines, ...entriesLines].join(`
1515
- `);
1516
- },
1517
- exec: (ctx, task) => new Observable((observer) => {
1518
- execPromise$1(ctx, task).then((result) => {
1519
- observer.next(result), observer.complete();
1520
- }).catch((err) => observer.error(err));
1521
- }),
1522
- complete: () => {
1523
- },
1524
- error: (_ctx, _task, err) => {
1525
- console.error(err);
1526
- }
1527
- };
1528
- async function execPromise$1(ctx, task) {
1529
- const { distPath, files, logger } = ctx, outDir = path.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
1530
- onRestored: (messages) => {
1531
- for (const msg of messages) {
1532
- const text = String(msg.args[0]);
1533
- 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)));
1534
- }
1535
- }
1536
- });
1537
- try {
1538
- const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup({
1539
- ...inputOptions,
1540
- onwarn(warning) {
1541
- consoleSpy.messages.push({
1542
- type: "warn",
1543
- code: warning.code,
1544
- args: [warning.message]
1545
- });
1546
- }
1547
- }), { output } = await bundle.generate(outputOptions);
1548
- for (const chunkOrAsset of output)
1549
- chunkOrAsset.type === "asset" ? files.push({
1550
- type: "asset",
1551
- path: path.resolve(outDir, chunkOrAsset.fileName)
1552
- }) : files.push({
1553
- type: "chunk",
1554
- path: path.resolve(outDir, chunkOrAsset.fileName)
1555
- });
1556
- await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
1557
- } catch (err) {
1558
- throw consoleSpy.restore(), err;
1559
- }
1560
- }
1561
1338
  const rollupTask = {
1562
1339
  name: (ctx, task) => {
1563
1340
  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 ? [
@@ -1670,9 +1447,7 @@ const rollupWatchTask = {
1670
1447
  }
1671
1448
  }, buildTaskHandlers = {
1672
1449
  "build:dts": dtsTask,
1673
- "build:js": rollupTask,
1674
- "build:legacy": rollupLegacyTask,
1675
- "build:react-compiler": rollupReactCompilerTask
1450
+ "build:js": rollupTask
1676
1451
  }, watchTaskHandlers = {
1677
1452
  "watch:dts": dtsWatchTask,
1678
1453
  "watch:js": rollupWatchTask
@@ -1684,7 +1459,7 @@ async function build(options) {
1684
1459
  strict = !1,
1685
1460
  tsconfig: tsconfigOption,
1686
1461
  clean = !1
1687
- } = options, logger = createLogger(), config2 = await loadConfig({ cwd }), legacyExports = config2?.legacyExports ?? !1, pkg = await loadPkgWithReporting({ cwd, logger, strict, legacyExports }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({
1462
+ } = options, logger = createLogger(), config2 = await loadConfig({ cwd }), pkg = await loadPkgWithReporting({ cwd, logger, strict }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({
1688
1463
  config: config2,
1689
1464
  cwd,
1690
1465
  emitDeclarationOnly,
@@ -1746,7 +1521,7 @@ function printPackageTree(ctx) {
1746
1521
  ), logger.log(treeify.asTree(tree, !0, !0));
1747
1522
  }
1748
1523
  async function check(options) {
1749
- const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger = createLogger(), config2 = await loadConfig({ cwd }), legacyExports = config2?.legacyExports ?? !1, pkg = await loadPkgWithReporting({ cwd, logger, strict, legacyExports }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({ config: config2, cwd, logger, pkg, strict, tsconfig });
1524
+ const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger = createLogger(), config2 = await loadConfig({ cwd }), pkg = await loadPkgWithReporting({ cwd, logger, strict }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({ config: config2, cwd, logger, pkg, strict, tsconfig });
1750
1525
  if (printPackageTree(ctx), strict) {
1751
1526
  const missingFiles = [];
1752
1527
  for (const [, exp] of Object.entries(ctx.exports || {}))
@@ -2276,7 +2051,7 @@ async function ensurePackagePath(packagePath) {
2276
2051
  throw new Error("the package directory is not empty");
2277
2052
  }
2278
2053
  function resolveWatchTasks(ctx) {
2279
- const { config: config2, cwd, pkg, target } = ctx, tasks = [], exports = Object.entries(ctx.exports || {}).map(
2054
+ const { pkg, target } = ctx, tasks = [], exports = Object.entries(ctx.exports || {}).map(
2280
2055
  ([_path, exp]) => ({ _path, ...exp })
2281
2056
  ), dtsTask2 = {
2282
2057
  type: "watch:dts",
@@ -2344,23 +2119,7 @@ function resolveWatchTasks(ctx) {
2344
2119
  output
2345
2120
  });
2346
2121
  }
2347
- if (dtsTask2.entries.length && tasks.push(dtsTask2), tasks.push(...Object.values(rollupTasks)), config2?.legacyExports) {
2348
- for (const exp of exports)
2349
- if (exp._exported && exp._path !== ".") {
2350
- const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(
2351
- /\.[^/.]+$/,
2352
- ""
2353
- );
2354
- relativeTargetPath && fs$1.writeFileSync(
2355
- path.resolve(cwd, `${exp._path}.js`),
2356
- ["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
2357
- `
2358
- `
2359
- )
2360
- );
2361
- }
2362
- }
2363
- return tasks;
2122
+ return dtsTask2.entries.length && tasks.push(dtsTask2), tasks.push(...Object.values(rollupTasks)), tasks;
2364
2123
  }
2365
2124
  function globFiles(patterns) {
2366
2125
  return globby(patterns.map((pattern) => pattern.split(path.sep).join(path.posix.sep)));
@@ -2404,7 +2163,7 @@ async function watch(options) {
2404
2163
  switchMap(async (configFiles) => {
2405
2164
  if (!configFiles.map((f) => path.relative(cwd, f)).find((f) => f === "package.json"))
2406
2165
  throw new Error("missing package.json");
2407
- const config2 = await loadConfig({ cwd }), legacyExports = config2?.legacyExports ?? !1, pkg = await loadPkgWithReporting({ cwd, logger, strict, legacyExports }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json";
2166
+ const config2 = await loadConfig({ cwd }), pkg = await loadPkgWithReporting({ cwd, logger, strict }), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json";
2408
2167
  return resolveBuildContext({ config: config2, cwd, logger, pkg, strict, tsconfig });
2409
2168
  })
2410
2169
  ).subscribe(async (ctx) => {
@@ -2448,8 +2207,6 @@ export {
2448
2207
  pkgExtMap,
2449
2208
  resolveBuildTasks,
2450
2209
  resolveConfigProperty,
2451
- rollupLegacyTask,
2452
- rollupReactCompilerTask,
2453
2210
  rollupTask,
2454
2211
  rollupWatchTask,
2455
2212
  strictOptions,