@sanity/pkg-utils 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -621,27 +621,17 @@ const _LOG_LEVELS = {
621
621
  warn: "warning"
622
622
  };
623
623
 
624
- async function _extractTypes(options) {
624
+ function _getExtractMessagesConfig(options) {
625
625
  const {
626
- distPath,
627
- exportPath,
628
- files,
629
- filePath,
630
- projectPath,
631
- rules,
632
- sourceTypesPath,
633
- tsconfigPath
626
+ rules
634
627
  } = options;
635
- const tsdocConfigFile = await _createTSDocConfig({
636
- customTags: []
637
- });
638
628
 
639
629
  function _ruleToLogLevel(key, defaultLevel) {
640
630
  const r = rules == null ? void 0 : rules[key];
641
631
  return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
642
632
  }
643
633
 
644
- const messagesConfig = {
634
+ return {
645
635
  compilerMessageReporting: {
646
636
  default: {
647
637
  logLevel: "warning"
@@ -692,12 +682,31 @@ async function _extractTypes(options) {
692
682
  }
693
683
  }
694
684
  };
685
+ }
686
+
687
+ async function _extractTypes(options) {
688
+ const {
689
+ customTags,
690
+ distPath,
691
+ exportPath,
692
+ files,
693
+ filePath,
694
+ projectPath,
695
+ rules,
696
+ sourceTypesPath,
697
+ tsconfigPath
698
+ } = options;
699
+ const tsdocConfigFile = await _createTSDocConfig({
700
+ customTags: customTags || []
701
+ });
695
702
  const extractorConfig = ExtractorConfig.prepare({
696
703
  configObject: _createApiExtractorConfig({
697
704
  distPath,
698
705
  exportPath,
699
706
  filePath,
700
- messages: messagesConfig,
707
+ messages: _getExtractMessagesConfig({
708
+ rules
709
+ }),
701
710
  projectFolder: projectPath,
702
711
  mainEntryPointFilePath: sourceTypesPath,
703
712
  tsconfigPath
@@ -737,7 +746,7 @@ async function _extractTypes(options) {
737
746
  const rimraf = promisify(rimrafCallback);
738
747
 
739
748
  async function _doExtract(ctx, task) {
740
- var _a;
749
+ var _a, _b;
741
750
 
742
751
  const {
743
752
  config,
@@ -777,12 +786,13 @@ async function _doExtract(ctx, task) {
777
786
  const sourceTypesPath = path.resolve(tmpPath, path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
778
787
  const targetPath = path.resolve(cwd, entry.targetPath);
779
788
  const result = await _extractTypes({
789
+ customTags: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.customTags,
780
790
  cwd,
781
791
  exportPath,
782
792
  files,
783
793
  filePath: path.relative(outDir, targetPath),
784
794
  projectPath: cwd,
785
- rules: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.rules,
795
+ rules: (_b = config == null ? void 0 : config.extract) == null ? void 0 : _b.rules,
786
796
  sourceTypesPath,
787
797
  tsconfigPath: path.resolve(cwd, ts.configPath || "tsconfig.json"),
788
798
  distPath: outDir
@@ -869,7 +879,7 @@ const _dtsWatchTask = {
869
879
  };
870
880
 
871
881
  function _resolveRollupConfig(ctx, buildTask) {
872
- var _ref2, _ref4, _ref5, _ref6, _ref7, _ref8;
882
+ var _ref2, _ref5, _ref6, _ref7, _ref8, _ref9;
873
883
 
874
884
  var _a, _b;
875
885
 
@@ -908,6 +918,10 @@ function _resolveRollupConfig(ctx, buildTask) {
908
918
 
909
919
  const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
910
920
 
921
+ const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref4 => {
922
+ let [key, val] = _ref4;
923
+ return [key, JSON.stringify(val)];
924
+ }));
911
925
  return {
912
926
  inputOptions: {
913
927
  context: cwd,
@@ -948,7 +962,7 @@ function _resolveRollupConfig(ctx, buildTask) {
948
962
 
949
963
  plugins: [replace({
950
964
  preventAssignment: true,
951
- values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
965
+ values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? _objectSpread({}, replacements) : _objectSpread({
952
966
  "process.env.PKG_FILE_PATH": arg => {
953
967
  const sourcePath = "./" + path.relative(cwd, arg);
954
968
  const entry = entries.find(e => e.source === sourcePath);
@@ -962,7 +976,7 @@ function _resolveRollupConfig(ctx, buildTask) {
962
976
  "process.env.PKG_FORMAT": JSON.stringify(format),
963
977
  "process.env.PKG_RUNTIME": JSON.stringify(runtime),
964
978
  "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
965
- })
979
+ }, replacements))
966
980
  }), alias({
967
981
  entries: _objectSpread({}, pathAliases)
968
982
  }), nodeResolve({
@@ -973,10 +987,10 @@ function _resolveRollupConfig(ctx, buildTask) {
973
987
  esmExternals: false,
974
988
  extensions: [".js"]
975
989
  }), json(), esbuild({
976
- jsx: (_ref4 = config == null ? void 0 : config.jsx) !== null && _ref4 !== void 0 ? _ref4 : "automatic",
977
- jsxFactory: (_ref5 = config == null ? void 0 : config.jsxFactory) !== null && _ref5 !== void 0 ? _ref5 : "createElement",
978
- jsxFragment: (_ref6 = config == null ? void 0 : config.jsxFragment) !== null && _ref6 !== void 0 ? _ref6 : "Fragment",
979
- jsxImportSource: (_ref7 = config == null ? void 0 : config.jsxImportSource) !== null && _ref7 !== void 0 ? _ref7 : "react",
990
+ jsx: (_ref5 = config == null ? void 0 : config.jsx) !== null && _ref5 !== void 0 ? _ref5 : "automatic",
991
+ jsxFactory: (_ref6 = config == null ? void 0 : config.jsxFactory) !== null && _ref6 !== void 0 ? _ref6 : "createElement",
992
+ jsxFragment: (_ref7 = config == null ? void 0 : config.jsxFragment) !== null && _ref7 !== void 0 ? _ref7 : "Fragment",
993
+ jsxImportSource: (_ref8 = config == null ? void 0 : config.jsxImportSource) !== null && _ref8 !== void 0 ? _ref8 : "react",
980
994
  target,
981
995
  tsconfig: ctx.ts.configPath || "tsconfig.json"
982
996
  }), getBabelOutputPlugin({
@@ -1009,7 +1023,7 @@ function _resolveRollupConfig(ctx, buildTask) {
1009
1023
  entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
1010
1024
  format,
1011
1025
  exports: "auto",
1012
- sourcemap: (_ref8 = config == null ? void 0 : config.sourcemap) !== null && _ref8 !== void 0 ? _ref8 : true
1026
+ sourcemap: (_ref9 = config == null ? void 0 : config.sourcemap) !== null && _ref9 !== void 0 ? _ref9 : true
1013
1027
  }
1014
1028
  };
1015
1029
  }
@@ -1298,7 +1312,7 @@ function _createLogger() {
1298
1312
  }
1299
1313
 
1300
1314
  async function _resolveBuildContext(options) {
1301
- var _ref9;
1315
+ var _ref10;
1302
1316
 
1303
1317
  const {
1304
1318
  config,
@@ -1391,7 +1405,7 @@ async function _resolveBuildContext(options) {
1391
1405
  files: [],
1392
1406
  logger,
1393
1407
  pkg,
1394
- runtime: (_ref9 = config == null ? void 0 : config.runtime) !== null && _ref9 !== void 0 ? _ref9 : "*",
1408
+ runtime: (_ref10 = config == null ? void 0 : config.runtime) !== null && _ref10 !== void 0 ? _ref10 : "*",
1395
1409
  target,
1396
1410
  ts: {
1397
1411
  config: tsconfig,
@@ -1511,11 +1525,11 @@ function _printPackageTree(ctx) {
1511
1525
  return "".concat(file, " ").concat(chalk.gray(info.size));
1512
1526
  }
1513
1527
 
1514
- tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref10 => {
1515
- let [, entry] = _ref10;
1528
+ tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref11 => {
1529
+ let [, entry] = _ref11;
1516
1530
  return entry._exported;
1517
- }).map(_ref11 => {
1518
- let [exportPath, entry] = _ref11;
1531
+ }).map(_ref12 => {
1532
+ let [exportPath, entry] = _ref12;
1519
1533
  const exp = {
1520
1534
  source: entry.source,
1521
1535
  types: void 0,
@@ -1713,8 +1727,8 @@ function _resolveWatchTasks(ctx) {
1713
1727
  target
1714
1728
  } = ctx;
1715
1729
  const tasks = [];
1716
- const exports = Object.entries(ctx.exports || {}).map(_ref12 => {
1717
- let [_path, exp] = _ref12;
1730
+ const exports = Object.entries(ctx.exports || {}).map(_ref13 => {
1731
+ let [_path, exp] = _ref13;
1718
1732
  return _objectSpread({
1719
1733
  _path
1720
1734
  }, exp);
@@ -1927,5 +1941,5 @@ async function watch(options) {
1927
1941
  });
1928
1942
  }
1929
1943
 
1930
- export { _DEFAULTS, _MODULE_EXT, _buildTaskHandlers, _dtsTask, _dtsWatchTask, _isRecord, _loadConfig, _loadPkg, _loadPkgWithReporting, _loadTSConfig, _parseExports, _resolveBuildTasks, _resolveConfigProperty, _rollupTask, _rollupWatchTask, _watchTaskHandlers, build, check, defineConfig, watch };
1944
+ export { _DEFAULTS, _MODULE_EXT, _buildTaskHandlers, _dtsTask, _dtsWatchTask, _getExtractMessagesConfig, _isRecord, _loadConfig, _loadPkg, _loadPkgWithReporting, _loadTSConfig, _parseExports, _resolveBuildTasks, _resolveConfigProperty, _rollupTask, _rollupWatchTask, _watchTaskHandlers, build, check, defineConfig, watch };
1931
1945
  //# sourceMappingURL=index.esm.js.map