@sanity/pkg-utils 6.13.4 → 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 (39) hide show
  1. package/dist/_chunks-cjs/build.cjs +6 -41
  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 +22 -59
  6. package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
  7. package/dist/_chunks-cjs/index.cjs +20 -86
  8. package/dist/_chunks-cjs/index.cjs.map +1 -1
  9. package/dist/_chunks-cjs/logger.cjs +2 -2
  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 -1
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +4 -23
  17. package/dist/index.d.ts +4 -23
  18. package/dist/index.js +49 -201
  19. package/dist/index.js.map +1 -1
  20. package/package.json +3 -3
  21. package/src/node/build.ts +1 -2
  22. package/src/node/check.ts +1 -2
  23. package/src/node/core/config/types.ts +3 -4
  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/resolveBuildContext.ts +0 -1
  29. package/src/node/resolveBuildTasks.ts +4 -62
  30. package/src/node/resolveWatchTasks.ts +1 -23
  31. package/src/node/tasks/dts/createApiExtractorConfig.ts +12 -32
  32. package/src/node/tasks/dts/getExtractMessagesConfig.ts +5 -1
  33. package/src/node/tasks/dts/getTargetPaths.ts +0 -2
  34. package/src/node/tasks/index.ts +1 -2
  35. package/src/node/tasks/rollup/index.ts +0 -1
  36. package/src/node/tasks/rollup/resolveRollupConfig.ts +5 -10
  37. package/src/node/tasks/types.ts +1 -12
  38. package/src/node/watch.ts +1 -2
  39. package/src/node/tasks/rollup/rollupLegacyTask.ts +0 -145
package/dist/index.d.cts CHANGED
@@ -65,13 +65,12 @@ export declare interface BuildFile {
65
65
  }
66
66
 
67
67
  /** @internal */
68
- export declare type BuildTask = DtsTask | RollupTask | RollupLegacyTask
68
+ export declare type BuildTask = DtsTask | RollupTask
69
69
 
70
70
  /** @internal */
71
71
  export declare interface BuildTaskHandlers {
72
72
  'build:dts': TaskHandler<DtsTask, DtsResult>
73
73
  'build:js': TaskHandler<RollupTask>
74
- 'build:legacy': TaskHandler<RollupLegacyTask>
75
74
  }
76
75
 
77
76
  /** @internal */
@@ -169,7 +168,6 @@ export declare function loadPkgWithReporting(options: {
169
168
  cwd: string
170
169
  logger: Logger
171
170
  strict: boolean
172
- legacyExports: boolean
173
171
  }): Promise<PackageJSON>
174
172
 
175
173
  /** @internal */
@@ -270,7 +268,6 @@ export declare function parseExports(options: {
270
268
  pkg: PackageJSON
271
269
  strict: boolean
272
270
  strictOptions: InferredStrictOptions
273
- legacyExports: boolean
274
271
  logger: Logger
275
272
  }): (PkgExport & {
276
273
  _path: string
@@ -349,7 +346,7 @@ export declare interface PkgConfigOptions {
349
346
  /**
350
347
  * @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
351
348
  */
352
- 'ae-forgotten-export'?: PkgRuleLevel
349
+ 'ae-forgotten-export'?: never
353
350
  'ae-incompatible-release-tags'?: PkgRuleLevel
354
351
  'ae-internal-missing-underscore'?: PkgRuleLevel
355
352
  'ae-missing-release-tag'?: PkgRuleLevel
@@ -383,10 +380,9 @@ export declare interface PkgConfigOptions {
383
380
  */
384
381
  jsxImportSource?: string
385
382
  /**
386
- * Build package with support for legacy exports (writes root `<export>.js` files)
387
- * @deprecated - will be removed in the next major version
383
+ * @deprecated no longer supported
388
384
  */
389
- legacyExports?: boolean
385
+ legacyExports?: never
390
386
  minify?: boolean
391
387
  /** @alpha */
392
388
  rollup?: {
@@ -472,7 +468,6 @@ export declare interface PkgExtMap {
472
468
  commonjs: string
473
469
  esm: string
474
470
  }
475
- legacy: string
476
471
  }
477
472
 
478
473
  /** @internal */
@@ -485,7 +480,6 @@ export declare const pkgExtMap: {
485
480
  commonjs: '.cjs'
486
481
  esm: '.js'
487
482
  }
488
- legacy: '.esm.js'
489
483
  }
490
484
 
491
485
  /** @public */
@@ -627,19 +621,6 @@ export declare function resolveConfigProperty<T>(
627
621
  initialValue: T,
628
622
  ): T
629
623
 
630
- /** @internal */
631
- export declare interface RollupLegacyTask {
632
- type: 'build:legacy'
633
- buildId: string
634
- entries: RollupTaskEntry[]
635
- runtime: PkgRuntime
636
- format: 'esm'
637
- target: string[]
638
- }
639
-
640
- /** @internal */
641
- export declare const rollupLegacyTask: TaskHandler<RollupLegacyTask>
642
-
643
624
  export {RollupPlugin}
644
625
 
645
626
  /** @internal */
package/dist/index.d.ts CHANGED
@@ -65,13 +65,12 @@ export declare interface BuildFile {
65
65
  }
66
66
 
67
67
  /** @internal */
68
- export declare type BuildTask = DtsTask | RollupTask | RollupLegacyTask
68
+ export declare type BuildTask = DtsTask | RollupTask
69
69
 
70
70
  /** @internal */
71
71
  export declare interface BuildTaskHandlers {
72
72
  'build:dts': TaskHandler<DtsTask, DtsResult>
73
73
  'build:js': TaskHandler<RollupTask>
74
- 'build:legacy': TaskHandler<RollupLegacyTask>
75
74
  }
76
75
 
77
76
  /** @internal */
@@ -169,7 +168,6 @@ export declare function loadPkgWithReporting(options: {
169
168
  cwd: string
170
169
  logger: Logger
171
170
  strict: boolean
172
- legacyExports: boolean
173
171
  }): Promise<PackageJSON>
174
172
 
175
173
  /** @internal */
@@ -270,7 +268,6 @@ export declare function parseExports(options: {
270
268
  pkg: PackageJSON
271
269
  strict: boolean
272
270
  strictOptions: InferredStrictOptions
273
- legacyExports: boolean
274
271
  logger: Logger
275
272
  }): (PkgExport & {
276
273
  _path: string
@@ -349,7 +346,7 @@ export declare interface PkgConfigOptions {
349
346
  /**
350
347
  * @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
351
348
  */
352
- 'ae-forgotten-export'?: PkgRuleLevel
349
+ 'ae-forgotten-export'?: never
353
350
  'ae-incompatible-release-tags'?: PkgRuleLevel
354
351
  'ae-internal-missing-underscore'?: PkgRuleLevel
355
352
  'ae-missing-release-tag'?: PkgRuleLevel
@@ -383,10 +380,9 @@ export declare interface PkgConfigOptions {
383
380
  */
384
381
  jsxImportSource?: string
385
382
  /**
386
- * Build package with support for legacy exports (writes root `<export>.js` files)
387
- * @deprecated - will be removed in the next major version
383
+ * @deprecated no longer supported
388
384
  */
389
- legacyExports?: boolean
385
+ legacyExports?: never
390
386
  minify?: boolean
391
387
  /** @alpha */
392
388
  rollup?: {
@@ -472,7 +468,6 @@ export declare interface PkgExtMap {
472
468
  commonjs: string
473
469
  esm: string
474
470
  }
475
- legacy: string
476
471
  }
477
472
 
478
473
  /** @internal */
@@ -485,7 +480,6 @@ export declare const pkgExtMap: {
485
480
  commonjs: '.cjs'
486
481
  esm: '.js'
487
482
  }
488
- legacy: '.esm.js'
489
483
  }
490
484
 
491
485
  /** @public */
@@ -627,19 +621,6 @@ export declare function resolveConfigProperty<T>(
627
621
  initialValue: T,
628
622
  ): T
629
623
 
630
- /** @internal */
631
- export declare interface RollupLegacyTask {
632
- type: 'build:legacy'
633
- buildId: string
634
- entries: RollupTaskEntry[]
635
- runtime: PkgRuntime
636
- format: 'esm'
637
- target: string[]
638
- }
639
-
640
- /** @internal */
641
- export declare const rollupLegacyTask: TaskHandler<RollupLegacyTask>
642
-
643
624
  export {RollupPlugin}
644
625
 
645
626
  /** @internal */
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";
@@ -165,13 +165,11 @@ function assertOrder(a, b, arr) {
165
165
  return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
166
166
  }
167
167
  async function loadPkgWithReporting(options) {
168
- const { cwd, logger, strict, legacyExports } = options;
168
+ const { cwd, logger, strict } = options;
169
169
  try {
170
170
  const pkg = await loadPkg({ cwd });
171
171
  let shouldError = !1;
172
- if (strict && (legacyExports && pkg.type === "commonjs" && (shouldError = !0, logger.error(
173
- 'the `type` field in `./package.json` shouldn\'t be "commonjs" when `legacyExports` is set to true)'
174
- )), !legacyExports && !pkg.type && (shouldError = !0, logger.error(
172
+ if (strict && (pkg.type || (shouldError = !0, logger.error(
175
173
  'the `type` field in `./package.json` must be either "module" or "commonjs")'
176
174
  ))), pkg.exports) {
177
175
  const _exports = Object.entries(pkg.exports);
@@ -224,7 +222,7 @@ async function loadPkgWithReporting(options) {
224
222
  function formatPath(segments) {
225
223
  return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
226
224
  }
227
- 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";
228
226
  function getTargetPaths(_type, expOrBundle) {
229
227
  const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
230
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(
@@ -253,9 +251,7 @@ const pkgExtMap = {
253
251
  module: {
254
252
  commonjs: cjsEnding,
255
253
  esm: defaultEnding
256
- },
257
- // package.config.legacyExports: true
258
- legacy: legacyEnding
254
+ }
259
255
  };
260
256
  function validateExports(_exports, options) {
261
257
  const { pkg } = options, type = pkg.type || "commonjs", ext = pkgExtMap[type], errors = [];
@@ -268,7 +264,7 @@ function validateExports(_exports, options) {
268
264
  return errors;
269
265
  }
270
266
  function parseExports(options) {
271
- 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) => {
272
268
  kind === "warn" ? logger.warn(message) : errors.push(message);
273
269
  };
274
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(
@@ -283,27 +279,13 @@ function parseExports(options) {
283
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 = [];
284
280
  if (pkg.browser) {
285
281
  const browserConditions = [];
286
- if (pkg.module && pkg.browser?.[pkg.module])
287
- browserConditions.push(
288
- ` "import": ${JSON.stringify(pkg.browser[pkg.module].replace(fileEnding, extMap.esm))}`
289
- );
290
- else if (pkg.browser?.[pkg.main])
291
- browserConditions.push(
292
- ` "import": ${JSON.stringify(pkg.browser?.[pkg.main].replace(fileEnding, extMap.esm))}`
293
- );
294
- else if (legacyExports) {
295
- const browserImport = pkg.main.replace(fileEnding, `.browser${extMap.esm}`);
296
- browserConditions.push(` "import": ${JSON.stringify(browserImport)}`);
297
- }
298
- if (pkg.browser?.[pkg.main])
299
- browserConditions.push(
300
- ` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`
301
- );
302
- else if (legacyExports) {
303
- const browserRequire = pkg.main.replace(fileEnding, `.browser${extMap.commonjs}`);
304
- browserConditions.push(` "require": ${JSON.stringify(browserRequire)}`);
305
- }
306
- 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(
307
289
  ' "browser": {',
308
290
  ` "source": ${JSON.stringify(pkg.browser?.[pkg.source] || pkg.source)},`,
309
291
  ...browserConditions,
@@ -318,9 +300,8 @@ function parseExports(options) {
318
300
  ` "source": ${JSON.stringify(pkg.source)},`,
319
301
  // If browser conditions are detected then add them to the suggestion
320
302
  ...maybeBrowserCondition.length > 0 ? maybeBrowserCondition : [],
321
- // If legacy exports are enabled we suggest the full list of exports, if not we can use the terse version
322
- (legacyExports || type === "commonjs") && ` "import": ${JSON.stringify(importExport)},`,
323
- (legacyExports || type === "module") && ` "require": ${JSON.stringify(requireExport)},`,
303
+ type === "commonjs" && ` "import": ${JSON.stringify(importExport)},`,
304
+ type === "module" && ` "require": ${JSON.stringify(requireExport)},`,
324
305
  ` "default": ${JSON.stringify(defaultExport)}`,
325
306
  " },",
326
307
  ' "./package.json": "./package.json"',
@@ -371,28 +352,13 @@ function parseExports(options) {
371
352
  };
372
353
  if (!exp.default) {
373
354
  const fallback = type === "module" ? exp.import : exp.require;
374
- fallback && (exp.default = fallback), legacyExports && (fallback ? errors.push(
375
- `package.json - \`exports["${exp._path}"].default\` should be set to "${fallback}" when "legacyExports" is true`
376
- ) : errors.push(
377
- `package.json - \`exports["${exp._path}"].default\` should be specified when "legacyExports" is true`
378
- ));
355
+ fallback && (exp.default = fallback);
379
356
  }
380
- if (!exp.require && type === "commonjs" && exp.default && (exp.require = exp.default), !exp.import && type === "module" && exp.default && (exp.import = exp.default), exportPath === ".")
381
- if (exportEntry.require && pkg.main && exportEntry.require !== pkg.main && errors.push(
382
- 'package.json: mismatch between "main" and "exports.require". These must be equal.'
383
- ), legacyExports) {
384
- const indexLegacyExport = (exportEntry.import || exportEntry.require || "").replace(
385
- /(\.esm)?\.[mc]?js$/,
386
- legacyEnding
387
- );
388
- indexLegacyExport !== pkg.module && errors.push(
389
- `package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`
390
- );
391
- } else
392
- exportEntry.import && pkg.module && exportEntry.import !== pkg.module && errors.push(
393
- 'package.json: mismatch between "module" and "exports.import" These must be equal.'
394
- );
395
- _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);
396
362
  } else isRecord(exportEntry) || errors.push("package.json: exports must be an object");
397
363
  if (errors.push(...validateExports(_exports, { pkg })), errors.length)
398
364
  throw new Error(`
@@ -588,7 +554,6 @@ async function resolveBuildContext(options) {
588
554
  cwd,
589
555
  pkg,
590
556
  strict,
591
- legacyExports: config2?.legacyExports ?? !1,
592
557
  strictOptions: strictOptions2,
593
558
  logger
594
559
  }).reduce((acc, x) => {
@@ -652,12 +617,12 @@ function transformPackageName(packageName) {
652
617
  return `@types/${packageName}`;
653
618
  }
654
619
  function resolveBuildTasks(ctx) {
655
- 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(
656
621
  ([_path, exp]) => ({ _path, ...exp })
657
622
  ), dtsTask2 = {
658
623
  type: "build:dts",
659
624
  entries: []
660
- }, rollupTasks = {}, rollupLegacyTasks = {};
625
+ }, rollupTasks = {};
661
626
  function addRollupTaskEntry(format2, runtime, entry) {
662
627
  const buildId = `${format2}:${runtime}`;
663
628
  rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
@@ -669,18 +634,6 @@ function resolveBuildTasks(ctx) {
669
634
  target: target[runtime]
670
635
  };
671
636
  }
672
- function addRollupLegacyTaskEntry(runtime, entry) {
673
- const buildId = `esm:${runtime}`;
674
- rollupLegacyTasks[buildId] ? rollupLegacyTasks[buildId].entries.push(entry) : rollupLegacyTasks[buildId] = {
675
- type: "build:legacy",
676
- buildId,
677
- entries: [entry],
678
- runtime,
679
- format: "esm",
680
- // @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
681
- target: target[runtime]
682
- };
683
- }
684
637
  for (const exp of exports) {
685
638
  const importId = path.join(pkg.name, exp._path);
686
639
  exp.source?.endsWith(".ts") && dtsTask2.entries.push({
@@ -743,17 +696,6 @@ function resolveBuildTasks(ctx) {
743
696
  output
744
697
  });
745
698
  }
746
- if (config2?.legacyExports)
747
- for (const exp of exports) {
748
- const runtime = exp.browser?.import ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import;
749
- if (!output) continue;
750
- const legacyOutput = output.replace(fileEnding, legacyEnding);
751
- addRollupLegacyTaskEntry(runtime, {
752
- path: exp._path,
753
- source: exp.browser?.source || exp.source,
754
- output: legacyOutput
755
- });
756
- }
757
699
  for (const bundle of bundles) {
758
700
  const idx = bundles.indexOf(bundle);
759
701
  bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
@@ -766,19 +708,7 @@ function resolveBuildTasks(ctx) {
766
708
  output: bundle.import
767
709
  });
768
710
  }
769
- if (tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks)), config2?.legacyExports) {
770
- for (const exp of exports)
771
- if (exp._exported && exp._path !== ".") {
772
- const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(fileEnding, legacyEnding).replace(/\.[^/.]+$/, "");
773
- relativeTargetPath && fs$1.writeFileSync(
774
- path.resolve(cwd, `${exp._path}.js`),
775
- ["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
776
- `
777
- `
778
- )
779
- );
780
- }
781
- }
711
+ tasks.push(...Object.values(rollupTasks));
782
712
  }
783
713
  return tasks;
784
714
  }
@@ -873,27 +803,23 @@ function createApiExtractorConfig(options) {
873
803
  mainEntryPointFilePath,
874
804
  tsconfig,
875
805
  tsconfigPath
876
- } = options, workaroundModulePreserve = tsconfig.options.module === ts.ModuleKind.Preserve, workaroundPaths = !!tsconfig.options.paths, overrideTsconfig = {
877
- extends: tsconfigPath,
878
- compilerOptions: {}
879
- };
880
- return workaroundModulePreserve && Object.assign(overrideTsconfig.compilerOptions, {
881
- // Set the equivalent options to `module: 'Preserve'`
882
- // https://github.com/microsoft/TypeScript/pull/56785/files?file-filters%5B%5D=.js&file-filters%5B%5D=.json&file-filters%5B%5D=.symbols&file-filters%5B%5D=.ts&file-filters%5B%5D=.types&show-viewed-files=true#diff-31d3c12bafea26bc9e8c8a77920c41af0c593206442add70c45a06c063767445
883
- module: "ESNext",
884
- moduleResolution: "Bundler",
885
- esModuleInterop: !0,
886
- resolveJsonModule: !0
887
- }), workaroundPaths && Object.assign(overrideTsconfig.compilerOptions, {
888
- // An empty object replaces whatever is in the original tsconfig file
889
- paths: {}
890
- }), {
806
+ } = options;
807
+ return {
891
808
  apiReport: {
892
809
  enabled: !1,
893
810
  reportFileName: "<unscopedPackageName>.api.md"
894
811
  },
895
812
  bundledPackages,
896
- compiler: workaroundModulePreserve || workaroundPaths ? { overrideTsconfig } : { tsconfigFilePath: tsconfigPath },
813
+ // If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),
814
+ compiler: tsconfig.options.paths ? {
815
+ overrideTsconfig: {
816
+ extends: tsconfigPath,
817
+ compilerOptions: {
818
+ // An empty object replaces whatever is in the original tsconfig file
819
+ paths: {}
820
+ }
821
+ }
822
+ } : { tsconfigFilePath: tsconfigPath },
897
823
  docModel: {
898
824
  enabled: !1,
899
825
  apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`)
@@ -972,7 +898,11 @@ function getExtractMessagesConfig(options) {
972
898
  addToApiReportFile: !1
973
899
  },
974
900
  "ae-forgotten-export": {
975
- 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",
976
906
  addToApiReportFile: !1
977
907
  },
978
908
  "ae-incompatible-release-tags": {
@@ -1258,7 +1188,7 @@ function createConsoleSpy(options) {
1258
1188
  };
1259
1189
  }
1260
1190
  function resolveRollupConfig(ctx, buildTask) {
1261
- 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.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(
1262
1192
  Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
1263
1193
  ), entries = buildTask.entries.map((entry) => ({
1264
1194
  ...entry,
@@ -1352,7 +1282,7 @@ function resolveRollupConfig(ctx, buildTask) {
1352
1282
  preserve_annotations: !0
1353
1283
  }
1354
1284
  })
1355
- ].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}`;
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}`;
1356
1286
  return {
1357
1287
  inputOptions: {
1358
1288
  context: cwd,
@@ -1405,70 +1335,6 @@ function resolveRollupConfig(ctx, buildTask) {
1405
1335
  function hasDependency(pkg, packageName) {
1406
1336
  return pkg.dependencies ? packageName in pkg.dependencies : pkg.peerDependencies ? packageName in pkg.peerDependencies : !1;
1407
1337
  }
1408
- const rollupLegacyTask = {
1409
- name: (ctx, task) => {
1410
- 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 ? [
1411
- " entries:",
1412
- ...entries.map(
1413
- (e) => [
1414
- " - ",
1415
- `${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
1416
- `${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
1417
- ].join("")
1418
- )
1419
- ] : [];
1420
- return [
1421
- "Build legacy exports...",
1422
- ` format: ${chalk.yellow(task.format)}`,
1423
- ...targetLines,
1424
- ...entriesLines
1425
- ].join(`
1426
- `);
1427
- },
1428
- exec: (ctx, task) => new Observable((observer) => {
1429
- execPromise$1(ctx, task).then((result) => {
1430
- observer.next(result), observer.complete();
1431
- }).catch((err) => observer.error(err));
1432
- }),
1433
- complete: () => {
1434
- },
1435
- error: (_ctx, _task, err) => {
1436
- console.error(err);
1437
- }
1438
- };
1439
- async function execPromise$1(ctx, task) {
1440
- const { distPath, files, logger } = ctx, outDir = path.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
1441
- onRestored: (messages) => {
1442
- for (const msg of messages) {
1443
- const text = String(msg.args[0]);
1444
- 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)));
1445
- }
1446
- }
1447
- });
1448
- try {
1449
- const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup({
1450
- ...inputOptions,
1451
- onwarn(warning) {
1452
- consoleSpy.messages.push({
1453
- type: "warn",
1454
- code: warning.code,
1455
- args: [warning.message]
1456
- });
1457
- }
1458
- }), { output } = await bundle.generate(outputOptions);
1459
- for (const chunkOrAsset of output)
1460
- chunkOrAsset.type === "asset" ? files.push({
1461
- type: "asset",
1462
- path: path.resolve(outDir, chunkOrAsset.fileName)
1463
- }) : files.push({
1464
- type: "chunk",
1465
- path: path.resolve(outDir, chunkOrAsset.fileName)
1466
- });
1467
- await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
1468
- } catch (err) {
1469
- throw consoleSpy.restore(), err;
1470
- }
1471
- }
1472
1338
  const rollupTask = {
1473
1339
  name: (ctx, task) => {
1474
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 ? [
@@ -1581,8 +1447,7 @@ const rollupWatchTask = {
1581
1447
  }
1582
1448
  }, buildTaskHandlers = {
1583
1449
  "build:dts": dtsTask,
1584
- "build:js": rollupTask,
1585
- "build:legacy": rollupLegacyTask
1450
+ "build:js": rollupTask
1586
1451
  }, watchTaskHandlers = {
1587
1452
  "watch:dts": dtsWatchTask,
1588
1453
  "watch:js": rollupWatchTask
@@ -1594,7 +1459,7 @@ async function build(options) {
1594
1459
  strict = !1,
1595
1460
  tsconfig: tsconfigOption,
1596
1461
  clean = !1
1597
- } = 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({
1598
1463
  config: config2,
1599
1464
  cwd,
1600
1465
  emitDeclarationOnly,
@@ -1656,7 +1521,7 @@ function printPackageTree(ctx) {
1656
1521
  ), logger.log(treeify.asTree(tree, !0, !0));
1657
1522
  }
1658
1523
  async function check(options) {
1659
- 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 });
1660
1525
  if (printPackageTree(ctx), strict) {
1661
1526
  const missingFiles = [];
1662
1527
  for (const [, exp] of Object.entries(ctx.exports || {}))
@@ -2186,7 +2051,7 @@ async function ensurePackagePath(packagePath) {
2186
2051
  throw new Error("the package directory is not empty");
2187
2052
  }
2188
2053
  function resolveWatchTasks(ctx) {
2189
- 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(
2190
2055
  ([_path, exp]) => ({ _path, ...exp })
2191
2056
  ), dtsTask2 = {
2192
2057
  type: "watch:dts",
@@ -2254,23 +2119,7 @@ function resolveWatchTasks(ctx) {
2254
2119
  output
2255
2120
  });
2256
2121
  }
2257
- if (dtsTask2.entries.length && tasks.push(dtsTask2), tasks.push(...Object.values(rollupTasks)), config2?.legacyExports) {
2258
- for (const exp of exports)
2259
- if (exp._exported && exp._path !== ".") {
2260
- const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(
2261
- /\.[^/.]+$/,
2262
- ""
2263
- );
2264
- relativeTargetPath && fs$1.writeFileSync(
2265
- path.resolve(cwd, `${exp._path}.js`),
2266
- ["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
2267
- `
2268
- `
2269
- )
2270
- );
2271
- }
2272
- }
2273
- return tasks;
2122
+ return dtsTask2.entries.length && tasks.push(dtsTask2), tasks.push(...Object.values(rollupTasks)), tasks;
2274
2123
  }
2275
2124
  function globFiles(patterns) {
2276
2125
  return globby(patterns.map((pattern) => pattern.split(path.sep).join(path.posix.sep)));
@@ -2314,7 +2163,7 @@ async function watch(options) {
2314
2163
  switchMap(async (configFiles) => {
2315
2164
  if (!configFiles.map((f) => path.relative(cwd, f)).find((f) => f === "package.json"))
2316
2165
  throw new Error("missing package.json");
2317
- 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";
2318
2167
  return resolveBuildContext({ config: config2, cwd, logger, pkg, strict, tsconfig });
2319
2168
  })
2320
2169
  ).subscribe(async (ctx) => {
@@ -2358,7 +2207,6 @@ export {
2358
2207
  pkgExtMap,
2359
2208
  resolveBuildTasks,
2360
2209
  resolveConfigProperty,
2361
- rollupLegacyTask,
2362
2210
  rollupTask,
2363
2211
  rollupWatchTask,
2364
2212
  strictOptions,