@sanity/pkg-utils 2.1.0 → 2.1.1

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 (25) hide show
  1. package/dist/_chunks/{build-2a47293b.cjs → build-68e9229a.cjs} +7 -11
  2. package/dist/_chunks/{build-2a47293b.cjs.map → build-68e9229a.cjs.map} +1 -1
  3. package/dist/_chunks/{buildAction-404437e8.cjs → buildAction-9ce9614a.cjs} +2 -2
  4. package/dist/_chunks/{buildAction-404437e8.cjs.map → buildAction-9ce9614a.cjs.map} +1 -1
  5. package/dist/_chunks/{check-3bf5eb0d.cjs → check-745260bc.cjs} +2 -2
  6. package/dist/_chunks/{check-3bf5eb0d.cjs.map → check-745260bc.cjs.map} +1 -1
  7. package/dist/_chunks/{checkAction-fcfe53a1.cjs → checkAction-1aa1fff7.cjs} +2 -2
  8. package/dist/_chunks/{checkAction-fcfe53a1.cjs.map → checkAction-1aa1fff7.cjs.map} +1 -1
  9. package/dist/_chunks/{index-58e287aa.cjs → index-a01cf661.cjs} +52 -41
  10. package/dist/_chunks/index-a01cf661.cjs.map +1 -0
  11. package/dist/_chunks/{resolveBuildContext-86a1602c.cjs → resolveBuildContext-702e3fb6.cjs} +14 -18
  12. package/dist/_chunks/{resolveBuildContext-86a1602c.cjs.map → resolveBuildContext-702e3fb6.cjs.map} +1 -1
  13. package/dist/_chunks/{watch-86ed07a5.cjs → watch-533fe913.cjs} +7 -11
  14. package/dist/_chunks/{watch-86ed07a5.cjs.map → watch-533fe913.cjs.map} +1 -1
  15. package/dist/_chunks/{watchAction-b72906aa.cjs → watchAction-d2c08880.cjs} +2 -2
  16. package/dist/_chunks/{watchAction-b72906aa.cjs.map → watchAction-d2c08880.cjs.map} +1 -1
  17. package/dist/cli.cjs +4 -4
  18. package/dist/index.cjs +5 -5
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.js +71 -57
  21. package/dist/index.js.map +1 -1
  22. package/package.json +4 -4
  23. package/src/node/core/config/types.ts +5 -0
  24. package/src/node/tasks/rollup/resolveRollupConfig.ts +1 -1
  25. package/dist/_chunks/index-58e287aa.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"watchAction-b72906aa.cjs","sources":["../../src/cli/watchAction.ts"],"sourcesContent":["import {watch} from '../node/watch'\nimport {handleError} from './handleError'\n\nexport async function watchAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {\n try {\n await watch({\n cwd: process.cwd(),\n strict: options.strict,\n tsconfig: options.tsconfig,\n })\n } catch (err) {\n handleError(err)\n }\n}\n"],"names":["watchAction","options","watch","cwd","process","strict","tsconfig","err","handleError"],"mappings":";;;;AAGA,eAAsBA,YAAYC,OAA+D,EAAA;EAC3F,IAAA;IACF,MAAMC,WAAM,CAAA;MACVC,GAAA,EAAKC,QAAQD,GAAI,EAAA;MACjBE,QAAQJ,OAAQ,CAAAI,MAAA;MAChBC,UAAUL,OAAQ,CAAAK;IAAA,CACnB,CAAA;WACMC,GAAP,EAAA;IACAC,WAAA,CAAAA,WAAA,CAAYD,GAAG,CAAA;EACjB;AACF;"}
1
+ {"version":3,"file":"watchAction-d2c08880.cjs","sources":["../../src/cli/watchAction.ts"],"sourcesContent":["import {watch} from '../node/watch'\nimport {handleError} from './handleError'\n\nexport async function watchAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {\n try {\n await watch({\n cwd: process.cwd(),\n strict: options.strict,\n tsconfig: options.tsconfig,\n })\n } catch (err) {\n handleError(err)\n }\n}\n"],"names":["watchAction","options","watch","cwd","process","strict","tsconfig","err","handleError"],"mappings":";;;;AAGA,eAAsBA,YAAYC,OAA+D,EAAA;EAC3F,IAAA;IACF,MAAMC,WAAM,CAAA;MACVC,GAAA,EAAKC,QAAQD,GAAI,EAAA;MACjBE,QAAQJ,OAAQ,CAAAI,MAAA;MAChBC,UAAUL,OAAQ,CAAAK;IAAA,CACnB,CAAA;WACMC,GAAP,EAAA;IACAC,WAAA,CAAAA,WAAA,CAAYD,GAAG,CAAA;EACjB;AACF;"}
package/dist/cli.cjs CHANGED
@@ -7,13 +7,13 @@ function _interopDefaultCompat(e) {
7
7
  };
8
8
  }
9
9
  var cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
10
- var version = "2.1.0";
10
+ var version = "2.1.1";
11
11
  const cli = cac__default.default();
12
12
  cli.command("", "Check").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").action(async options => {
13
13
  const {
14
14
  checkAction: statusAction
15
15
  } = await Promise.resolve().then(function () {
16
- return require('./_chunks/checkAction-fcfe53a1.cjs');
16
+ return require('./_chunks/checkAction-1aa1fff7.cjs');
17
17
  });
18
18
  return statusAction(options);
19
19
  });
@@ -21,7 +21,7 @@ cli.command("build", "Build package").option("--emitDeclarationOnly", "Emit d.ts
21
21
  const {
22
22
  buildAction
23
23
  } = await Promise.resolve().then(function () {
24
- return require('./_chunks/buildAction-404437e8.cjs');
24
+ return require('./_chunks/buildAction-9ce9614a.cjs');
25
25
  });
26
26
  return buildAction(options);
27
27
  });
@@ -29,7 +29,7 @@ cli.command("watch", "Watch package").option("--strict", "Strict mode").option("
29
29
  const {
30
30
  watchAction
31
31
  } = await Promise.resolve().then(function () {
32
- return require('./_chunks/watchAction-b72906aa.cjs');
32
+ return require('./_chunks/watchAction-d2c08880.cjs');
33
33
  });
34
34
  return watchAction(options);
35
35
  });
package/dist/index.cjs CHANGED
@@ -3,11 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', {
4
4
  value: true
5
5
  });
6
- var build = require('./_chunks/build-2a47293b.cjs');
7
- var check = require('./_chunks/check-3bf5eb0d.cjs');
8
- var resolveBuildContext = require('./_chunks/resolveBuildContext-86a1602c.cjs');
9
- var index = require('./_chunks/index-58e287aa.cjs');
10
- var watch = require('./_chunks/watch-86ed07a5.cjs');
6
+ var build = require('./_chunks/build-68e9229a.cjs');
7
+ var check = require('./_chunks/check-745260bc.cjs');
8
+ var resolveBuildContext = require('./_chunks/resolveBuildContext-702e3fb6.cjs');
9
+ var index = require('./_chunks/index-a01cf661.cjs');
10
+ var watch = require('./_chunks/watch-533fe913.cjs');
11
11
  function defineConfig(configOptions) {
12
12
  return configOptions;
13
13
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {ExtractorMessage} from '@microsoft/api-extractor'
2
2
  import {IExtractorMessagesConfig} from '@microsoft/api-extractor'
3
3
  import {Observable} from 'rxjs'
4
+ import {PluginItem} from '@babel/core'
4
5
  import {Plugin as RollupPlugin} from 'rollup'
5
6
  import {RollupWatcherEvent} from 'rollup'
6
7
  import ts from 'typescript'
@@ -234,6 +235,10 @@ export declare interface PkgBundle {
234
235
 
235
236
  /** @public */
236
237
  export declare interface PkgConfigOptions {
238
+ /** @alpha */
239
+ babel?: {
240
+ plugins?: PluginItem[] | null | undefined
241
+ }
237
242
  bundles?: PkgBundle[]
238
243
  /** @alpha */
239
244
  define?: Record<string, string | number | boolean | undefined | null>
package/dist/index.js CHANGED
@@ -1,11 +1,3 @@
1
- const _excluded = ["_path"];
2
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
3
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
8
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
1
  import path from 'path';
10
2
  import { register } from 'esbuild-register/dist/node';
11
3
  import pkgUp from 'pkg-up';
@@ -260,10 +252,11 @@ function parseExports(options) {
260
252
  }
261
253
  Object.assign(rootExport, exportEntry);
262
254
  } else {
263
- const extraExport = _objectSpread({
255
+ const extraExport = {
264
256
  _exported: true,
265
- _path: exportPath
266
- }, exportEntry);
257
+ _path: exportPath,
258
+ ...exportEntry
259
+ };
267
260
  extraExports.push(extraExport);
268
261
  }
269
262
  } else {
@@ -295,7 +288,9 @@ function getPkgExtMap(options) {
295
288
  const {
296
289
  legacyExports
297
290
  } = options;
298
- const ret = _objectSpread({}, DEFAULT_PKG_EXT_MAP);
291
+ const ret = {
292
+ ...DEFAULT_PKG_EXT_MAP
293
+ };
299
294
  if (legacyExports) {
300
295
  ret["commonjs"] = {
301
296
  commonjs: ".js",
@@ -484,12 +479,13 @@ async function resolveBuildContext(options) {
484
479
  strict
485
480
  }).reduce((acc, x) => {
486
481
  const {
487
- _path: exportPath
488
- } = x,
489
- exportEntry = _objectWithoutProperties(x, _excluded);
490
- return _objectSpread(_objectSpread({}, acc), {}, {
482
+ _path: exportPath,
483
+ ...exportEntry
484
+ } = x;
485
+ return {
486
+ ...acc,
491
487
  [exportPath]: exportEntry
492
- });
488
+ };
493
489
  }, {});
494
490
  const exports = resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
495
491
  const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
@@ -547,9 +543,10 @@ function resolveBuildTasks(ctx) {
547
543
  const tasks = [];
548
544
  const exports = Object.entries(ctx.exports || {}).map(_ref2 => {
549
545
  let [_path, exp] = _ref2;
550
- return _objectSpread({
551
- _path
552
- }, exp);
546
+ return {
547
+ _path,
548
+ ...exp
549
+ };
553
550
  });
554
551
  const dtsTask = {
555
552
  type: "build:dts",
@@ -747,13 +744,14 @@ async function buildTypes(options) {
747
744
  tsconfig,
748
745
  strict = false
749
746
  } = options;
750
- const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
747
+ const compilerOptions = {
748
+ ...tsconfig.options,
751
749
  declaration: true,
752
750
  declarationDir: outDir,
753
751
  emitDeclarationOnly: true,
754
752
  noEmit: false,
755
753
  outDir
756
- });
754
+ };
757
755
  const program = ts.createProgram(tsconfig.fileNames, compilerOptions);
758
756
  const emitResult = program.emit();
759
757
  const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
@@ -827,15 +825,18 @@ async function createTSDocConfig(opts) {
827
825
  syntaxKind: t.syntaxKind,
828
826
  allowMultiple: t.allowMultiple
829
827
  })));
830
- const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
828
+ const supportForTags = {
829
+ ...tsDocBaseConfig.supportForTags
830
+ };
831
831
  for (const customTag of customTags) {
832
832
  supportForTags["@".concat(customTag.name)] = true;
833
833
  }
834
- return TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
834
+ return TSDocConfigFile.loadFromObject({
835
+ ...tsDocBaseConfig,
835
836
  noStandardTags: false,
836
837
  tagDefinitions,
837
838
  supportForTags
838
- }));
839
+ });
839
840
  }
840
841
  async function extractModuleBlocksFromTypes(_ref3) {
841
842
  let {
@@ -975,9 +976,10 @@ async function extractTypes(options) {
975
976
  tsOutDir: tmpPath
976
977
  });
977
978
  const code = [typesBuf.toString(), ...moduleBlocks].join("\n\n");
978
- await fs.writeFile(typesPath, prettier.format(code, _objectSpread(_objectSpread({}, prettierConfig), {}, {
979
+ await fs.writeFile(typesPath, prettier.format(code, {
980
+ ...prettierConfig,
979
981
  filepath: typesPath
980
- })));
982
+ }));
981
983
  files.push({
982
984
  type: "types",
983
985
  path: typesPath
@@ -1189,7 +1191,7 @@ function createConsoleSpy(options) {
1189
1191
  }
1190
1192
  function resolveRollupConfig(ctx, buildTask) {
1191
1193
  var _ref4, _ref7, _ref8, _ref9, _ref10, _ref11;
1192
- var _a, _b, _c;
1194
+ var _a, _b, _c, _d;
1193
1195
  const {
1194
1196
  format,
1195
1197
  runtime,
@@ -1215,9 +1217,10 @@ function resolveRollupConfig(ctx, buildTask) {
1215
1217
  return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
1216
1218
  }));
1217
1219
  const entries = buildTask.entries.map(entry => {
1218
- return _objectSpread(_objectSpread({}, entry), {}, {
1220
+ return {
1221
+ ...entry,
1219
1222
  name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
1220
- });
1223
+ };
1221
1224
  }, {});
1222
1225
  const exportIds = _exports && Object.keys(_exports).map(exportPath => path.join(pkg.name, exportPath));
1223
1226
  const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
@@ -1227,22 +1230,29 @@ function resolveRollupConfig(ctx, buildTask) {
1227
1230
  }));
1228
1231
  const defaultPlugins = [replace({
1229
1232
  preventAssignment: true,
1230
- values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? _objectSpread({}, replacements) : _objectSpread({
1231
- "process.env.PKG_FILE_PATH": arg => {
1232
- const sourcePath = "./" + path.relative(cwd, arg);
1233
- const entry = entries.find(e => e.source === sourcePath);
1234
- if (!entry) {
1235
- console.error("could not find source entry: ".concat(sourcePath));
1236
- return "null";
1237
- }
1238
- return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
1239
- },
1240
- "process.env.PKG_FORMAT": JSON.stringify(format),
1241
- "process.env.PKG_RUNTIME": JSON.stringify(runtime),
1242
- "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
1243
- }, replacements))
1233
+ values: {
1234
+ ...(pkg.name === "@sanity/pkg-utils" ? {
1235
+ ...replacements
1236
+ } : {
1237
+ "process.env.PKG_FILE_PATH": arg => {
1238
+ const sourcePath = "./" + path.relative(cwd, arg);
1239
+ const entry = entries.find(e => e.source === sourcePath);
1240
+ if (!entry) {
1241
+ console.error("could not find source entry: ".concat(sourcePath));
1242
+ return "null";
1243
+ }
1244
+ return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
1245
+ },
1246
+ "process.env.PKG_FORMAT": JSON.stringify(format),
1247
+ "process.env.PKG_RUNTIME": JSON.stringify(runtime),
1248
+ "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version),
1249
+ ...replacements
1250
+ })
1251
+ }
1244
1252
  }), alias({
1245
- entries: _objectSpread({}, pathAliases)
1253
+ entries: {
1254
+ ...pathAliases
1255
+ }
1246
1256
  }), nodeResolve({
1247
1257
  browser: runtime === "browser",
1248
1258
  extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
@@ -1256,7 +1266,7 @@ function resolveRollupConfig(ctx, buildTask) {
1256
1266
  tsconfig: ctx.ts.configPath || "tsconfig.json"
1257
1267
  }), getBabelOutputPlugin({
1258
1268
  babelrc: false,
1259
- plugins: ["@babel/plugin-proposal-object-rest-spread"],
1269
+ plugins: (_b = config == null ? void 0 : config.babel) == null ? void 0 : _b.plugins,
1260
1270
  presets: [["@babel/preset-env", {
1261
1271
  targets: pkg.browserslist || DEFAULT_BROWSERSLIST_QUERY,
1262
1272
  modules: false
@@ -1276,8 +1286,8 @@ function resolveRollupConfig(ctx, buildTask) {
1276
1286
  }
1277
1287
  }
1278
1288
  })].filter(Boolean);
1279
- const userPlugins = (_b = config == null ? void 0 : config.rollup) == null ? void 0 : _b.plugins;
1280
- const plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty((_c = config == null ? void 0 : config.rollup) == null ? void 0 : _c.plugins, defaultPlugins);
1289
+ const userPlugins = (_c = config == null ? void 0 : config.rollup) == null ? void 0 : _c.plugins;
1290
+ const plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty((_d = config == null ? void 0 : config.rollup) == null ? void 0 : _d.plugins, defaultPlugins);
1281
1291
  return {
1282
1292
  inputOptions: {
1283
1293
  context: cwd,
@@ -1300,9 +1310,10 @@ function resolveRollupConfig(ctx, buildTask) {
1300
1310
  return false;
1301
1311
  },
1302
1312
  input: entries.reduce((acc, entry) => {
1303
- return _objectSpread(_objectSpread({}, acc), {}, {
1313
+ return {
1314
+ ...acc,
1304
1315
  [entry.name]: entry.source
1305
- });
1316
+ };
1306
1317
  }, {}),
1307
1318
  plugins,
1308
1319
  treeshake: {
@@ -1387,7 +1398,8 @@ async function execPromise(ctx, task) {
1387
1398
  inputOptions,
1388
1399
  outputOptions
1389
1400
  } = resolveRollupConfig(ctx, task);
1390
- const bundle = await rollup(_objectSpread(_objectSpread({}, inputOptions), {}, {
1401
+ const bundle = await rollup({
1402
+ ...inputOptions,
1391
1403
  onwarn(warning) {
1392
1404
  consoleSpy.messages.push({
1393
1405
  type: "warn",
@@ -1395,7 +1407,7 @@ async function execPromise(ctx, task) {
1395
1407
  args: [warning.message]
1396
1408
  });
1397
1409
  }
1398
- }));
1410
+ });
1399
1411
  const {
1400
1412
  output
1401
1413
  } = await bundle.generate(outputOptions);
@@ -1428,9 +1440,10 @@ const rollupWatchTask = {
1428
1440
  outputOptions
1429
1441
  } = resolveRollupConfig(ctx, task);
1430
1442
  return new Observable(observer => {
1431
- const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
1443
+ const watchOptions = {
1444
+ ...inputOptions,
1432
1445
  output: outputOptions
1433
- });
1446
+ };
1434
1447
  const watcher = watch$1(watchOptions);
1435
1448
  watcher.on("event", event => {
1436
1449
  observer.next(event);
@@ -1759,9 +1772,10 @@ function resolveWatchTasks(ctx) {
1759
1772
  const tasks = [];
1760
1773
  const exports = Object.entries(ctx.exports || {}).map(_ref17 => {
1761
1774
  let [_path, exp] = _ref17;
1762
- return _objectSpread({
1763
- _path
1764
- }, exp);
1775
+ return {
1776
+ _path,
1777
+ ...exp
1778
+ };
1765
1779
  });
1766
1780
  const dtsTask = {
1767
1781
  type: "watch:dts",