01ac828f4e4bb0f53df6608199d76b092a1a8cd0dabc8c9490902a51ee601bc5ce0338cc3a700c97fd2da1b8ec5e35d56c9a88116457542eecc63be0acd74f 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { dealias, isAsyncFile, isAsyncNoFile, isSyncFile, isSyncNoFile, } from './options.js';
  2. export const makeCommand = (syncFile, asyncFile, syncNoFile, asyncNoFile, validate) => {
  3. return Object.assign((opt_ = [], entries, cb) => {
  4. if (Array.isArray(opt_)) {
  5. entries = opt_;
  6. opt_ = {};
  7. }
  8. if (typeof entries === 'function') {
  9. cb = entries;
  10. entries = undefined;
  11. }
  12. if (!entries) {
  13. entries = [];
  14. }
  15. else {
  16. entries = Array.from(entries);
  17. }
  18. const opt = dealias(opt_);
  19. validate?.(opt, entries);
  20. if (isSyncFile(opt)) {
  21. if (typeof cb === 'function') {
  22. throw new TypeError('callback not supported for sync tar functions');
  23. }
  24. return syncFile(opt, entries);
  25. }
  26. else if (isAsyncFile(opt)) {
  27. const p = asyncFile(opt, entries);
  28. // weirdness to make TS happy
  29. const c = cb ? cb : undefined;
  30. return c ? p.then(() => c(), c) : p;
  31. }
  32. else if (isSyncNoFile(opt)) {
  33. if (typeof cb === 'function') {
  34. throw new TypeError('callback not supported for sync tar functions');
  35. }
  36. return syncNoFile(opt, entries);
  37. }
  38. else if (isAsyncNoFile(opt)) {
  39. if (typeof cb === 'function') {
  40. throw new TypeError('callback only supported with file option');
  41. }
  42. return asyncNoFile(opt, entries);
  43. /* c8 ignore start */
  44. }
  45. else {
  46. throw new Error('impossible options??');
  47. }
  48. /* c8 ignore stop */
  49. }, {
  50. syncFile,
  51. asyncFile,
  52. syncNoFile,
  53. asyncNoFile,
  54. validate,
  55. });
  56. };
  57. //# sourceMappingURL=make-command.js.map