@sanity/pkg-utils 1.13.0 → 1.15.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 (46) hide show
  1. package/dist/_chunks/{_resolveBuildContext-ef196a3e.js → _resolveBuildContext-0e601cff.js} +3 -1
  2. package/dist/_chunks/_resolveBuildContext-0e601cff.js.map +1 -0
  3. package/dist/_chunks/{build-36a16057.js → build-3762711f.js} +7 -4
  4. package/dist/_chunks/build-3762711f.js.map +1 -0
  5. package/dist/_chunks/{buildAction-d4c2a5d2.js → buildAction-b4e23900.js} +5 -4
  6. package/dist/_chunks/buildAction-b4e23900.js.map +1 -0
  7. package/dist/_chunks/{check-7d728336.js → check-e60e8979.js} +6 -4
  8. package/dist/_chunks/check-e60e8979.js.map +1 -0
  9. package/dist/_chunks/{checkAction-2342707c.js → checkAction-6de69604.js} +3 -3
  10. package/dist/_chunks/{checkAction-2342707c.js.map → checkAction-6de69604.js.map} +1 -1
  11. package/dist/_chunks/{index-340fbb6a.js → index-00a76fd5.js} +101 -76
  12. package/dist/_chunks/index-00a76fd5.js.map +1 -0
  13. package/dist/_chunks/{watch-41c2ea71.js → watch-69b1e41c.js} +7 -4
  14. package/dist/_chunks/watch-69b1e41c.js.map +1 -0
  15. package/dist/_chunks/{watchAction-fea46c01.js → watchAction-72377ec8.js} +5 -4
  16. package/dist/_chunks/watchAction-72377ec8.js.map +1 -0
  17. package/dist/cli.js +6 -6
  18. package/dist/cli.js.map +1 -1
  19. package/dist/index.d.ts +48 -4
  20. package/dist/index.esm.js +121 -87
  21. package/dist/index.esm.js.map +1 -1
  22. package/dist/index.js +6 -5
  23. package/dist/index.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/cli/buildAction.ts +2 -1
  26. package/src/cli/index.ts +2 -0
  27. package/src/cli/watchAction.ts +2 -1
  28. package/src/node/_core/config/types.ts +12 -1
  29. package/src/node/_core/contexts/buildContext.ts +1 -0
  30. package/src/node/_resolveBuildContext.ts +3 -1
  31. package/src/node/_tasks/dts/_buildTypes.ts +5 -2
  32. package/src/node/_tasks/dts/_doExtract.ts +3 -2
  33. package/src/node/_tasks/dts/_extractTypes.ts +16 -85
  34. package/src/node/_tasks/dts/_getExtractMessagesConfig.ts +87 -0
  35. package/src/node/_tasks/dts/index.ts +1 -0
  36. package/src/node/_tasks/rollup/_resolveRollupConfig.ts +91 -77
  37. package/src/node/build.ts +27 -5
  38. package/src/node/check.ts +3 -2
  39. package/src/node/watch.ts +8 -3
  40. package/dist/_chunks/_resolveBuildContext-ef196a3e.js.map +0 -1
  41. package/dist/_chunks/build-36a16057.js.map +0 -1
  42. package/dist/_chunks/buildAction-d4c2a5d2.js.map +0 -1
  43. package/dist/_chunks/check-7d728336.js.map +0 -1
  44. package/dist/_chunks/index-340fbb6a.js.map +0 -1
  45. package/dist/_chunks/watch-41c2ea71.js.map +0 -1
  46. package/dist/_chunks/watchAction-fea46c01.js.map +0 -1
package/dist/index.esm.js CHANGED
@@ -504,7 +504,8 @@ const formatHost = {
504
504
  async function _buildTypes(options) {
505
505
  const {
506
506
  outDir,
507
- tsconfig
507
+ tsconfig,
508
+ strict = false
508
509
  } = options;
509
510
 
510
511
  const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
@@ -536,7 +537,10 @@ async function _buildTypes(options) {
536
537
 
537
538
  if (errors.length) {
538
539
  console.error(ts.formatDiagnostics(errors, formatHost));
539
- throw new Error("failed to compile");
540
+
541
+ if (strict) {
542
+ throw new Error("failed to compile TypeScript definitions");
543
+ }
540
544
  }
541
545
  }
542
546
  }
@@ -621,27 +625,17 @@ const _LOG_LEVELS = {
621
625
  warn: "warning"
622
626
  };
623
627
 
624
- async function _extractTypes(options) {
628
+ function _getExtractMessagesConfig(options) {
625
629
  const {
626
- distPath,
627
- exportPath,
628
- files,
629
- filePath,
630
- projectPath,
631
- rules,
632
- sourceTypesPath,
633
- tsconfigPath
630
+ rules
634
631
  } = options;
635
- const tsdocConfigFile = await _createTSDocConfig({
636
- customTags: []
637
- });
638
632
 
639
633
  function _ruleToLogLevel(key, defaultLevel) {
640
634
  const r = rules == null ? void 0 : rules[key];
641
635
  return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
642
636
  }
643
637
 
644
- const messagesConfig = {
638
+ return {
645
639
  compilerMessageReporting: {
646
640
  default: {
647
641
  logLevel: "warning"
@@ -692,12 +686,31 @@ async function _extractTypes(options) {
692
686
  }
693
687
  }
694
688
  };
689
+ }
690
+
691
+ async function _extractTypes(options) {
692
+ const {
693
+ customTags,
694
+ distPath,
695
+ exportPath,
696
+ files,
697
+ filePath,
698
+ projectPath,
699
+ rules,
700
+ sourceTypesPath,
701
+ tsconfigPath
702
+ } = options;
703
+ const tsdocConfigFile = await _createTSDocConfig({
704
+ customTags: customTags || []
705
+ });
695
706
  const extractorConfig = ExtractorConfig.prepare({
696
707
  configObject: _createApiExtractorConfig({
697
708
  distPath,
698
709
  exportPath,
699
710
  filePath,
700
- messages: messagesConfig,
711
+ messages: _getExtractMessagesConfig({
712
+ rules
713
+ }),
701
714
  projectFolder: projectPath,
702
715
  mainEntryPointFilePath: sourceTypesPath,
703
716
  tsconfigPath
@@ -737,12 +750,13 @@ async function _extractTypes(options) {
737
750
  const rimraf = promisify(rimrafCallback);
738
751
 
739
752
  async function _doExtract(ctx, task) {
740
- var _a;
753
+ var _a, _b;
741
754
 
742
755
  const {
743
756
  config,
744
757
  cwd,
745
758
  files,
759
+ strict,
746
760
  ts
747
761
  } = ctx;
748
762
 
@@ -767,6 +781,7 @@ async function _doExtract(ctx, task) {
767
781
  await _buildTypes({
768
782
  cwd,
769
783
  outDir: tmpPath,
784
+ strict,
770
785
  tsconfig: ts.config
771
786
  });
772
787
  const messages = [];
@@ -777,12 +792,13 @@ async function _doExtract(ctx, task) {
777
792
  const sourceTypesPath = path.resolve(tmpPath, path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
778
793
  const targetPath = path.resolve(cwd, entry.targetPath);
779
794
  const result = await _extractTypes({
795
+ customTags: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.customTags,
780
796
  cwd,
781
797
  exportPath,
782
798
  files,
783
799
  filePath: path.relative(outDir, targetPath),
784
800
  projectPath: cwd,
785
- rules: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.rules,
801
+ rules: (_b = config == null ? void 0 : config.extract) == null ? void 0 : _b.rules,
786
802
  sourceTypesPath,
787
803
  tsconfigPath: path.resolve(cwd, ts.configPath || "tsconfig.json"),
788
804
  distPath: outDir
@@ -869,9 +885,9 @@ const _dtsWatchTask = {
869
885
  };
870
886
 
871
887
  function _resolveRollupConfig(ctx, buildTask) {
872
- var _ref2, _ref4, _ref5, _ref6, _ref7, _ref8;
888
+ var _ref2, _ref5, _ref6, _ref7, _ref8, _ref9;
873
889
 
874
- var _a, _b;
890
+ var _a, _b, _c;
875
891
 
876
892
  const {
877
893
  format,
@@ -908,6 +924,66 @@ function _resolveRollupConfig(ctx, buildTask) {
908
924
 
909
925
  const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
910
926
 
927
+ const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref4 => {
928
+ let [key, val] = _ref4;
929
+ return [key, JSON.stringify(val)];
930
+ }));
931
+ const defaultPlugins = [replace({
932
+ preventAssignment: true,
933
+ values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? _objectSpread({}, replacements) : _objectSpread({
934
+ "process.env.PKG_FILE_PATH": arg => {
935
+ const sourcePath = "./" + path.relative(cwd, arg);
936
+ const entry = entries.find(e => e.source === sourcePath);
937
+
938
+ if (!entry) {
939
+ console.error("could not find source entry: ".concat(sourcePath));
940
+ return "null";
941
+ }
942
+
943
+ return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
944
+ },
945
+ "process.env.PKG_FORMAT": JSON.stringify(format),
946
+ "process.env.PKG_RUNTIME": JSON.stringify(runtime),
947
+ "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
948
+ }, replacements))
949
+ }), alias({
950
+ entries: _objectSpread({}, pathAliases)
951
+ }), nodeResolve({
952
+ browser: runtime === "browser",
953
+ extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
954
+ preferBuiltins: true
955
+ }), commonjs({
956
+ esmExternals: false,
957
+ extensions: [".js"]
958
+ }), json(), esbuild({
959
+ jsx: (_ref5 = config == null ? void 0 : config.jsx) !== null && _ref5 !== void 0 ? _ref5 : "automatic",
960
+ jsxFactory: (_ref6 = config == null ? void 0 : config.jsxFactory) !== null && _ref6 !== void 0 ? _ref6 : "createElement",
961
+ jsxFragment: (_ref7 = config == null ? void 0 : config.jsxFragment) !== null && _ref7 !== void 0 ? _ref7 : "Fragment",
962
+ jsxImportSource: (_ref8 = config == null ? void 0 : config.jsxImportSource) !== null && _ref8 !== void 0 ? _ref8 : "react",
963
+ target,
964
+ tsconfig: ctx.ts.configPath || "tsconfig.json"
965
+ }), getBabelOutputPlugin({
966
+ babelrc: false,
967
+ plugins: ["@babel/plugin-proposal-object-rest-spread"],
968
+ presets: [["@babel/preset-env", {
969
+ targets: pkg.browserslist || _DEFAULTS.browserslist
970
+ }]]
971
+ }), minify && terser({
972
+ output: {
973
+ comments: (_node, comment) => {
974
+ const text = comment.value;
975
+ const type = comment.type;
976
+
977
+ if (type == "comment2") {
978
+ return /@preserve|@license|@cc_on/i.test(text);
979
+ }
980
+
981
+ return false;
982
+ }
983
+ }
984
+ })].filter(Boolean);
985
+ const userPlugins = (_b = config == null ? void 0 : config.rollup) == null ? void 0 : _b.plugins;
986
+ const plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : _resolveConfigProperty((_c = config == null ? void 0 : config.rollup) == null ? void 0 : _c.plugins, defaultPlugins);
911
987
  return {
912
988
  inputOptions: {
913
989
  context: cwd,
@@ -946,59 +1022,7 @@ function _resolveRollupConfig(ctx, buildTask) {
946
1022
  }
947
1023
  },
948
1024
 
949
- plugins: [replace({
950
- preventAssignment: true,
951
- values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
952
- "process.env.PKG_FILE_PATH": arg => {
953
- const sourcePath = "./" + path.relative(cwd, arg);
954
- const entry = entries.find(e => e.source === sourcePath);
955
-
956
- if (!entry) {
957
- throw new Error("could not find source entry: ".concat(sourcePath));
958
- }
959
-
960
- return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
961
- },
962
- "process.env.PKG_FORMAT": JSON.stringify(format),
963
- "process.env.PKG_RUNTIME": JSON.stringify(runtime),
964
- "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
965
- })
966
- }), alias({
967
- entries: _objectSpread({}, pathAliases)
968
- }), nodeResolve({
969
- browser: runtime === "browser",
970
- extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
971
- preferBuiltins: true
972
- }), commonjs({
973
- esmExternals: false,
974
- extensions: [".js"]
975
- }), 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",
980
- target,
981
- tsconfig: ctx.ts.configPath || "tsconfig.json"
982
- }), getBabelOutputPlugin({
983
- babelrc: false,
984
- plugins: ["@babel/plugin-proposal-object-rest-spread"],
985
- presets: [["@babel/preset-env", {
986
- targets: pkg.browserslist || _DEFAULTS.browserslist
987
- }]]
988
- }), minify && terser({
989
- output: {
990
- comments: (_node, comment) => {
991
- const text = comment.value;
992
- const type = comment.type;
993
-
994
- if (type == "comment2") {
995
- return /@preserve|@license|@cc_on/i.test(text);
996
- }
997
-
998
- return false;
999
- }
1000
- }
1001
- }), ...(((_b = config == null ? void 0 : config.rollup) == null ? void 0 : _b.plugins) || [])].filter(Boolean),
1025
+ plugins,
1002
1026
  treeshake: {
1003
1027
  propertyReadSideEffects: false
1004
1028
  }
@@ -1009,7 +1033,7 @@ function _resolveRollupConfig(ctx, buildTask) {
1009
1033
  entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
1010
1034
  format,
1011
1035
  exports: "auto",
1012
- sourcemap: (_ref8 = config == null ? void 0 : config.sourcemap) !== null && _ref8 !== void 0 ? _ref8 : true
1036
+ sourcemap: (_ref9 = config == null ? void 0 : config.sourcemap) !== null && _ref9 !== void 0 ? _ref9 : true
1013
1037
  }
1014
1038
  };
1015
1039
  }
@@ -1298,12 +1322,13 @@ function _createLogger() {
1298
1322
  }
1299
1323
 
1300
1324
  async function _resolveBuildContext(options) {
1301
- var _ref9;
1325
+ var _ref10;
1302
1326
 
1303
1327
  const {
1304
1328
  config,
1305
1329
  cwd,
1306
1330
  pkg,
1331
+ strict,
1307
1332
  tsconfig: tsconfigPath
1308
1333
  } = options;
1309
1334
 
@@ -1391,7 +1416,8 @@ async function _resolveBuildContext(options) {
1391
1416
  files: [],
1392
1417
  logger,
1393
1418
  pkg,
1394
- runtime: (_ref9 = config == null ? void 0 : config.runtime) !== null && _ref9 !== void 0 ? _ref9 : "*",
1419
+ runtime: (_ref10 = config == null ? void 0 : config.runtime) !== null && _ref10 !== void 0 ? _ref10 : "*",
1420
+ strict,
1395
1421
  target,
1396
1422
  ts: {
1397
1423
  config: tsconfig,
@@ -1417,7 +1443,8 @@ function _spinner(msg) {
1417
1443
  async function build(options) {
1418
1444
  const {
1419
1445
  cwd,
1420
- tsconfig = "tsconfig.json"
1446
+ strict = false,
1447
+ tsconfig: tsconfigOption
1421
1448
  } = options;
1422
1449
  const pkg = await _loadPkgWithReporting({
1423
1450
  cwd
@@ -1425,10 +1452,12 @@ async function build(options) {
1425
1452
  const config = await _loadConfig({
1426
1453
  cwd
1427
1454
  });
1455
+ const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
1428
1456
  const ctx = await _resolveBuildContext({
1429
1457
  config,
1430
1458
  cwd,
1431
1459
  pkg,
1460
+ strict,
1432
1461
  tsconfig
1433
1462
  });
1434
1463
 
@@ -1511,11 +1540,11 @@ function _printPackageTree(ctx) {
1511
1540
  return "".concat(file, " ").concat(chalk.gray(info.size));
1512
1541
  }
1513
1542
 
1514
- tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref10 => {
1515
- let [, entry] = _ref10;
1543
+ tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref11 => {
1544
+ let [, entry] = _ref11;
1516
1545
  return entry._exported;
1517
- }).map(_ref11 => {
1518
- let [exportPath, entry] = _ref11;
1546
+ }).map(_ref12 => {
1547
+ let [exportPath, entry] = _ref12;
1519
1548
  const exp = {
1520
1549
  source: entry.source,
1521
1550
  types: void 0,
@@ -1573,8 +1602,8 @@ function _printPackageTree(ctx) {
1573
1602
  async function check(options) {
1574
1603
  const {
1575
1604
  cwd,
1576
- strict,
1577
- tsconfig = "tsconfig.json"
1605
+ strict = false,
1606
+ tsconfig: tsconfigOption
1578
1607
  } = options;
1579
1608
  const pkg = await _loadPkgWithReporting({
1580
1609
  cwd
@@ -1582,10 +1611,12 @@ async function check(options) {
1582
1611
  const config = await _loadConfig({
1583
1612
  cwd
1584
1613
  });
1614
+ const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
1585
1615
  const ctx = await _resolveBuildContext({
1586
1616
  config,
1587
1617
  cwd,
1588
1618
  pkg,
1619
+ strict,
1589
1620
  tsconfig
1590
1621
  });
1591
1622
  const {
@@ -1713,8 +1744,8 @@ function _resolveWatchTasks(ctx) {
1713
1744
  target
1714
1745
  } = ctx;
1715
1746
  const tasks = [];
1716
- const exports = Object.entries(ctx.exports || {}).map(_ref12 => {
1717
- let [_path, exp] = _ref12;
1747
+ const exports = Object.entries(ctx.exports || {}).map(_ref13 => {
1748
+ let [_path, exp] = _ref13;
1718
1749
  return _objectSpread({
1719
1750
  _path
1720
1751
  }, exp);
@@ -1876,7 +1907,8 @@ async function _watchConfigFiles(options) {
1876
1907
  async function watch(options) {
1877
1908
  const {
1878
1909
  cwd,
1879
- tsconfig = "tsconfig.json"
1910
+ strict = false,
1911
+ tsconfig: tsconfigOption
1880
1912
  } = options;
1881
1913
  const configFiles$ = await _watchConfigFiles({
1882
1914
  cwd
@@ -1896,10 +1928,12 @@ async function watch(options) {
1896
1928
  const config = await _loadConfig({
1897
1929
  cwd
1898
1930
  });
1931
+ const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
1899
1932
  return _resolveBuildContext({
1900
1933
  config,
1901
1934
  cwd,
1902
1935
  pkg,
1936
+ strict,
1903
1937
  tsconfig
1904
1938
  });
1905
1939
  }));
@@ -1927,5 +1961,5 @@ async function watch(options) {
1927
1961
  });
1928
1962
  }
1929
1963
 
1930
- export { _DEFAULTS, _MODULE_EXT, _buildTaskHandlers, _dtsTask, _dtsWatchTask, _isRecord, _loadConfig, _loadPkg, _loadPkgWithReporting, _loadTSConfig, _parseExports, _resolveBuildTasks, _resolveConfigProperty, _rollupTask, _rollupWatchTask, _watchTaskHandlers, build, check, defineConfig, watch };
1964
+ export { _DEFAULTS, _MODULE_EXT, _buildTaskHandlers, _dtsTask, _dtsWatchTask, _getExtractMessagesConfig, _isRecord, _loadConfig, _loadPkg, _loadPkgWithReporting, _loadTSConfig, _parseExports, _resolveBuildTasks, _resolveConfigProperty, _rollupTask, _rollupWatchTask, _watchTaskHandlers, build, check, defineConfig, watch };
1931
1965
  //# sourceMappingURL=index.esm.js.map