@sanity/pkg-utils 6.13.3-canary.4 → 6.13.4

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
@@ -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()),
@@ -248,12 +238,7 @@ function getTargetPaths(_type, expOrBundle) {
248
238
  expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
249
239
  ), expOrBundle.node?.require && set.add(
250
240
  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);
241
+ ))), Array.from(set);
257
242
  }
258
243
  function isPkgExport$1(exp) {
259
244
  return exp?.browser || exp?.node || exp?.default;
@@ -624,8 +609,6 @@ async function resolveBuildContext(options) {
624
609
  exportEntry.browser?.require,
625
610
  exportEntry.node?.source && exportEntry.node.import,
626
611
  exportEntry.node?.source && exportEntry.node.require
627
- // @TODO implement this
628
- // exportEntry['react-compiler']?.source && exportEntry['react-compiler']?.default,
629
612
  ].filter(Boolean)).map((p) => path.resolve(cwd, p)), commonDistPath = findCommonDirPath(outputPaths);
630
613
  if (commonDistPath === cwd)
631
614
  throw new Error(
@@ -674,13 +657,7 @@ function resolveBuildTasks(ctx) {
674
657
  ), dtsTask2 = {
675
658
  type: "build:dts",
676
659
  entries: []
677
- }, rollupTasks = {}, rollupLegacyTasks = {}, rollupReactCompilerTask2 = {
678
- type: "build:react-compiler",
679
- runtime: "browser",
680
- format: "esm",
681
- entries: [],
682
- target: target.browser
683
- };
660
+ }, rollupTasks = {}, rollupLegacyTasks = {};
684
661
  function addRollupTaskEntry(format2, runtime, entry) {
685
662
  const buildId = `${format2}:${runtime}`;
686
663
  rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
@@ -704,9 +681,6 @@ function resolveBuildTasks(ctx) {
704
681
  target: target[runtime]
705
682
  };
706
683
  }
707
- function addRollupReactCompilerTaskEntry(entry) {
708
- rollupReactCompilerTask2.entries.push(entry);
709
- }
710
684
  for (const exp of exports) {
711
685
  const importId = path.join(pkg.name, exp._path);
712
686
  exp.source?.endsWith(".ts") && dtsTask2.entries.push({
@@ -769,15 +743,7 @@ function resolveBuildTasks(ctx) {
769
743
  output
770
744
  });
771
745
  }
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)
746
+ if (config2?.legacyExports)
781
747
  for (const exp of exports) {
782
748
  const runtime = exp.browser?.import ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import;
783
749
  if (!output) continue;
@@ -907,23 +873,27 @@ function createApiExtractorConfig(options) {
907
873
  mainEntryPointFilePath,
908
874
  tsconfig,
909
875
  tsconfigPath
910
- } = options;
911
- return {
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
+ }), {
912
891
  apiReport: {
913
892
  enabled: !1,
914
893
  reportFileName: "<unscopedPackageName>.api.md"
915
894
  },
916
895
  bundledPackages,
917
- // 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`),
918
- compiler: tsconfig.options.paths ? {
919
- overrideTsconfig: {
920
- extends: tsconfigPath,
921
- compilerOptions: {
922
- // An empty object replaces whatever is in the original tsconfig file
923
- paths: {}
924
- }
925
- }
926
- } : { tsconfigFilePath: tsconfigPath },
896
+ compiler: workaroundModulePreserve || workaroundPaths ? { overrideTsconfig } : { tsconfigFilePath: tsconfigPath },
927
897
  docModel: {
928
898
  enabled: !1,
929
899
  apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`)
@@ -1288,7 +1258,7 @@ function createConsoleSpy(options) {
1288
1258
  };
1289
1259
  }
1290
1260
  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(
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(
1292
1262
  Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
1293
1263
  ), entries = buildTask.entries.map((entry) => ({
1294
1264
  ...entry,
@@ -1323,7 +1293,7 @@ function resolveRollupConfig(ctx, buildTask) {
1323
1293
  }),
1324
1294
  commonjs(),
1325
1295
  json(),
1326
- (isReactCompiler || config2?.babel?.reactCompiler || config2?.babel?.styledComponents) && babel({
1296
+ (config2?.babel?.reactCompiler || config2?.babel?.styledComponents) && babel({
1327
1297
  babelrc: !1,
1328
1298
  presets: ["@babel/preset-typescript"],
1329
1299
  babelHelpers: "bundled",
@@ -1344,7 +1314,7 @@ function resolveRollupConfig(ctx, buildTask) {
1344
1314
  ...typeof config2.babel.styledComponents == "object" ? config2.babel.styledComponents : {}
1345
1315
  }
1346
1316
  ],
1347
- (isReactCompiler || config2?.babel?.reactCompiler) && [
1317
+ config2?.babel?.reactCompiler && [
1348
1318
  "babel-plugin-react-compiler",
1349
1319
  config2?.reactCompilerOptions || {}
1350
1320
  ]
@@ -1382,7 +1352,7 @@ function resolveRollupConfig(ctx, buildTask) {
1382
1352
  preserve_annotations: !0
1383
1353
  }
1384
1354
  })
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}`;
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}`;
1386
1356
  return {
1387
1357
  inputOptions: {
1388
1358
  context: cwd,
@@ -1453,65 +1423,6 @@ const rollupLegacyTask = {
1453
1423
  ...targetLines,
1454
1424
  ...entriesLines
1455
1425
  ].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
1426
  `);
1516
1427
  },
1517
1428
  exec: (ctx, task) => new Observable((observer) => {
@@ -1671,8 +1582,7 @@ const rollupWatchTask = {
1671
1582
  }, buildTaskHandlers = {
1672
1583
  "build:dts": dtsTask,
1673
1584
  "build:js": rollupTask,
1674
- "build:legacy": rollupLegacyTask,
1675
- "build:react-compiler": rollupReactCompilerTask
1585
+ "build:legacy": rollupLegacyTask
1676
1586
  }, watchTaskHandlers = {
1677
1587
  "watch:dts": dtsWatchTask,
1678
1588
  "watch:js": rollupWatchTask
@@ -2449,7 +2359,6 @@ export {
2449
2359
  resolveBuildTasks,
2450
2360
  resolveConfigProperty,
2451
2361
  rollupLegacyTask,
2452
- rollupReactCompilerTask,
2453
2362
  rollupTask,
2454
2363
  rollupWatchTask,
2455
2364
  strictOptions,