@teambit/cli 0.0.0-387ca83bd6d05e8441bf8d4e938b4a402307cc6b

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 (85) hide show
  1. package/cli.composition.tsx +7 -0
  2. package/cli.docs.mdx +12 -0
  3. package/dist/cli-parser.d.ts +38 -0
  4. package/dist/cli-parser.js +379 -0
  5. package/dist/cli-parser.js.map +1 -0
  6. package/dist/cli.aspect.d.ts +4 -0
  7. package/dist/cli.aspect.js +22 -0
  8. package/dist/cli.aspect.js.map +1 -0
  9. package/dist/cli.cmd.d.ts +32 -0
  10. package/dist/cli.cmd.js +151 -0
  11. package/dist/cli.cmd.js.map +1 -0
  12. package/dist/cli.composition.d.ts +1 -0
  13. package/dist/cli.composition.js +29 -0
  14. package/dist/cli.composition.js.map +1 -0
  15. package/dist/cli.docs.mdx +12 -0
  16. package/dist/cli.main.runtime.d.ts +86 -0
  17. package/dist/cli.main.runtime.js +304 -0
  18. package/dist/cli.main.runtime.js.map +1 -0
  19. package/dist/command-groups.d.ts +31 -0
  20. package/dist/command-groups.js +44 -0
  21. package/dist/command-groups.js.map +1 -0
  22. package/dist/command-helper.d.ts +25 -0
  23. package/dist/command-helper.js +59 -0
  24. package/dist/command-helper.js.map +1 -0
  25. package/dist/command-runner.d.ts +35 -0
  26. package/dist/command-runner.js +176 -0
  27. package/dist/command-runner.js.map +1 -0
  28. package/dist/command.d.ts +130 -0
  29. package/dist/command.js +3 -0
  30. package/dist/command.js.map +1 -0
  31. package/dist/completion.cmd.d.ts +9 -0
  32. package/dist/completion.cmd.js +22 -0
  33. package/dist/completion.cmd.js.map +1 -0
  34. package/dist/default-error-handler.d.ts +12 -0
  35. package/dist/default-error-handler.js +81 -0
  36. package/dist/default-error-handler.js.map +1 -0
  37. package/dist/esm.mjs +17 -0
  38. package/dist/exceptions/already-exists.d.ts +4 -0
  39. package/dist/exceptions/already-exists.js +21 -0
  40. package/dist/exceptions/already-exists.js.map +1 -0
  41. package/dist/exceptions/command-not-found.d.ts +7 -0
  42. package/dist/exceptions/command-not-found.js +44 -0
  43. package/dist/exceptions/command-not-found.js.map +1 -0
  44. package/dist/exceptions/index.d.ts +2 -0
  45. package/dist/exceptions/index.js +33 -0
  46. package/dist/exceptions/index.js.map +1 -0
  47. package/dist/exceptions/yargs-exit-workaround.d.ts +6 -0
  48. package/dist/exceptions/yargs-exit-workaround.js +23 -0
  49. package/dist/exceptions/yargs-exit-workaround.js.map +1 -0
  50. package/dist/generate-doc-md.d.ts +25 -0
  51. package/dist/generate-doc-md.js +151 -0
  52. package/dist/generate-doc-md.js.map +1 -0
  53. package/dist/get-command-id.d.ts +1 -0
  54. package/dist/get-command-id.js +11 -0
  55. package/dist/get-command-id.js.map +1 -0
  56. package/dist/global-flags.d.ts +7 -0
  57. package/dist/global-flags.js +24 -0
  58. package/dist/global-flags.js.map +1 -0
  59. package/dist/handle-errors.d.ts +3 -0
  60. package/dist/handle-errors.js +78 -0
  61. package/dist/handle-errors.js.map +1 -0
  62. package/dist/help.cmd.d.ts +15 -0
  63. package/dist/help.cmd.js +36 -0
  64. package/dist/help.cmd.js.map +1 -0
  65. package/dist/help.d.ts +3 -0
  66. package/dist/help.js +88 -0
  67. package/dist/help.js.map +1 -0
  68. package/dist/index.d.ts +12 -0
  69. package/dist/index.js +147 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/preview-1752165283597.js +7 -0
  72. package/dist/version.cmd.d.ts +13 -0
  73. package/dist/version.cmd.js +39 -0
  74. package/dist/version.cmd.js.map +1 -0
  75. package/dist/yargs-adapter.d.ts +22 -0
  76. package/dist/yargs-adapter.js +114 -0
  77. package/dist/yargs-adapter.js.map +1 -0
  78. package/esm.mjs +17 -0
  79. package/exceptions/already-exists.ts +7 -0
  80. package/exceptions/command-not-found.ts +22 -0
  81. package/exceptions/index.ts +2 -0
  82. package/exceptions/yargs-exit-workaround.ts +10 -0
  83. package/package.json +73 -0
  84. package/types/asset.d.ts +41 -0
  85. package/types/style.d.ts +42 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * These are the main group.
3
+ * It's possible to create new groups by calling `cliMain.registerGroup()`.
4
+ */
5
+ export declare const groups: {
6
+ 'workspace-setup': string;
7
+ collaborate: string;
8
+ 'info-analysis': string;
9
+ 'workspace-tools': string;
10
+ 'component-config': string;
11
+ 'component-development': string;
12
+ dependencies: string;
13
+ 'version-control': string;
14
+ testing: string;
15
+ 'run-serve': string;
16
+ system: string;
17
+ auth: string;
18
+ advanced: string;
19
+ ungrouped: string;
20
+ start: string;
21
+ development: string;
22
+ discover: string;
23
+ info: string;
24
+ general: string;
25
+ };
26
+ export type Group = keyof typeof groups;
27
+ type GroupDescription = string;
28
+ export type GroupsType = {
29
+ [groupName: string]: GroupDescription;
30
+ };
31
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.groups = void 0;
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
11
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
+ /**
13
+ * They might be needed for backward compatibility.
14
+ */
15
+ const oldGroups = {
16
+ start: 'Start a working area',
17
+ development: 'Develop components',
18
+ discover: 'Explore components',
19
+ info: 'View components',
20
+ general: 'Workspace commands'
21
+ };
22
+
23
+ /**
24
+ * These are the main group.
25
+ * It's possible to create new groups by calling `cliMain.registerGroup()`.
26
+ */
27
+ const groups = exports.groups = _objectSpread(_objectSpread({}, oldGroups), {}, {
28
+ 'workspace-setup': 'Workspace & Project Setup',
29
+ collaborate: 'Collaboration & Remote',
30
+ 'info-analysis': 'Information & Analysis',
31
+ 'workspace-tools': 'Workspace Tools',
32
+ 'component-config': 'Component Configuration',
33
+ 'component-development': 'Component Development',
34
+ dependencies: 'Dependencies & Packages',
35
+ 'version-control': 'Version Control',
36
+ testing: 'Testing & Quality',
37
+ 'run-serve': 'Run & Serve',
38
+ system: 'System & Utility',
39
+ auth: 'Authentication & Cloud',
40
+ advanced: 'Advanced/Debug',
41
+ ungrouped: 'Ungrouped'
42
+ });
43
+
44
+ //# sourceMappingURL=command-groups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["oldGroups","start","development","discover","info","general","groups","exports","_objectSpread","collaborate","dependencies","testing","system","auth","advanced","ungrouped"],"sources":["command-groups.ts"],"sourcesContent":["/**\n * They might be needed for backward compatibility.\n */\nconst oldGroups = {\n start: 'Start a working area',\n development: 'Develop components',\n discover: 'Explore components',\n info: 'View components',\n general: 'Workspace commands',\n};\n\n/**\n * These are the main group.\n * It's possible to create new groups by calling `cliMain.registerGroup()`.\n */\nexport const groups = {\n ...oldGroups,\n 'workspace-setup': 'Workspace & Project Setup',\n collaborate: 'Collaboration & Remote',\n 'info-analysis': 'Information & Analysis',\n 'workspace-tools': 'Workspace Tools',\n 'component-config': 'Component Configuration',\n 'component-development': 'Component Development',\n dependencies: 'Dependencies & Packages',\n 'version-control': 'Version Control',\n testing: 'Testing & Quality',\n 'run-serve': 'Run & Serve',\n system: 'System & Utility',\n auth: 'Authentication & Cloud',\n advanced: 'Advanced/Debug',\n ungrouped: 'Ungrouped',\n};\n\nexport type Group = keyof typeof groups;\n\ntype GroupDescription = string;\n\nexport type GroupsType = { [groupName: string]: GroupDescription };\n"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA,MAAMA,SAAS,GAAG;EAChBC,KAAK,EAAE,sBAAsB;EAC7BC,WAAW,EAAE,oBAAoB;EACjCC,QAAQ,EAAE,oBAAoB;EAC9BC,IAAI,EAAE,iBAAiB;EACvBC,OAAO,EAAE;AACX,CAAC;;AAED;AACA;AACA;AACA;AACO,MAAMC,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAAE,aAAA,CAAAA,aAAA,KACdR,SAAS;EACZ,iBAAiB,EAAE,2BAA2B;EAC9CS,WAAW,EAAE,wBAAwB;EACrC,eAAe,EAAE,wBAAwB;EACzC,iBAAiB,EAAE,iBAAiB;EACpC,kBAAkB,EAAE,yBAAyB;EAC7C,uBAAuB,EAAE,uBAAuB;EAChDC,YAAY,EAAE,yBAAyB;EACvC,iBAAiB,EAAE,iBAAiB;EACpCC,OAAO,EAAE,mBAAmB;EAC5B,WAAW,EAAE,aAAa;EAC1BC,MAAM,EAAE,kBAAkB;EAC1BC,IAAI,EAAE,wBAAwB;EAC9BC,QAAQ,EAAE,gBAAgB;EAC1BC,SAAS,EAAE;AAAW,EACvB","ignoreList":[]}
@@ -0,0 +1,25 @@
1
+ import { Command } from './command';
2
+ type ArgData = {
3
+ /**
4
+ * as it appears in the command name, e.g. "component-pattern..."
5
+ */
6
+ nameRaw: string;
7
+ /**
8
+ * to make it valid as a js variable name, e.g. "componentPattern"
9
+ */
10
+ nameCamelCase: string;
11
+ required: boolean;
12
+ description?: string;
13
+ isArray?: boolean;
14
+ };
15
+ export declare function getArgsData(cmd: Command): ArgData[];
16
+ type FlagData = {
17
+ name: string;
18
+ alias?: string;
19
+ description: string;
20
+ type: 'string' | 'boolean';
21
+ requiresArg: boolean;
22
+ };
23
+ export declare function getFlagsData(cmd: Command): FlagData[];
24
+ export declare function getCommandName(cmd: Command): string;
25
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getArgsData = getArgsData;
7
+ exports.getCommandName = getCommandName;
8
+ exports.getFlagsData = getFlagsData;
9
+ function _lodash() {
10
+ const data = require("lodash");
11
+ _lodash = function () {
12
+ return data;
13
+ };
14
+ return data;
15
+ }
16
+ function getArgsData(cmd) {
17
+ const commandSplit = cmd.name.split(' ');
18
+ commandSplit.shift(); // remove the first element, it's the command-name
19
+
20
+ return commandSplit.map(existArg => {
21
+ const trimmed = existArg.trim();
22
+ if (!trimmed.startsWith('<') && !trimmed.startsWith('[') || !trimmed.endsWith('>') && !trimmed.endsWith(']')) {
23
+ throw new Error(`expect arg "${trimmed}" of "${cmd.name}" to be wrapped with "[]" or "<>"`);
24
+ }
25
+ // remove the opening and closing brackets
26
+ const withoutBrackets = trimmed.slice(1, -1);
27
+ const foundInArguments = cmd.arguments?.find(arg => arg.name === withoutBrackets);
28
+ return {
29
+ nameRaw: withoutBrackets,
30
+ nameCamelCase: (0, _lodash().camelCase)(withoutBrackets),
31
+ // it also removes the "..." if exists
32
+ required: trimmed.startsWith('<'),
33
+ description: foundInArguments?.description,
34
+ isArray: withoutBrackets.endsWith('...')
35
+ };
36
+ });
37
+ }
38
+ function getFlagsData(cmd) {
39
+ const options = cmd.options;
40
+ if (!options) return [];
41
+ return options.map(opt => {
42
+ const [alias, flag, description] = opt;
43
+ const name = flag.split(' ')[0];
44
+ const type = flag.includes('<') || flag.includes('[') ? 'string' : 'boolean';
45
+ const requiresArg = flag.includes('<');
46
+ return {
47
+ name,
48
+ alias,
49
+ description,
50
+ type,
51
+ requiresArg
52
+ };
53
+ });
54
+ }
55
+ function getCommandName(cmd) {
56
+ return cmd.name.split(' ')[0];
57
+ }
58
+
59
+ //# sourceMappingURL=command-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_lodash","data","require","getArgsData","cmd","commandSplit","name","split","shift","map","existArg","trimmed","trim","startsWith","endsWith","Error","withoutBrackets","slice","foundInArguments","arguments","find","arg","nameRaw","nameCamelCase","camelCase","required","description","isArray","getFlagsData","options","opt","alias","flag","type","includes","requiresArg","getCommandName"],"sources":["command-helper.ts"],"sourcesContent":["import { Command } from './command';\nimport { camelCase } from 'lodash';\n\ntype ArgData = {\n /**\n * as it appears in the command name, e.g. \"component-pattern...\"\n */\n nameRaw: string;\n /**\n * to make it valid as a js variable name, e.g. \"componentPattern\"\n */\n nameCamelCase: string;\n required: boolean;\n description?: string;\n isArray?: boolean;\n}\n\nexport function getArgsData(cmd: Command): ArgData[] {\n const commandSplit = cmd.name.split(' ');\n commandSplit.shift(); // remove the first element, it's the command-name\n\n return commandSplit.map((existArg) => {\n const trimmed = existArg.trim();\n if ((!trimmed.startsWith('<') && !trimmed.startsWith('[')) || (!trimmed.endsWith('>') && !trimmed.endsWith(']'))) {\n throw new Error(`expect arg \"${trimmed}\" of \"${cmd.name}\" to be wrapped with \"[]\" or \"<>\"`);\n }\n // remove the opening and closing brackets\n const withoutBrackets = trimmed.slice(1, -1);\n const foundInArguments = cmd.arguments?.find((arg) => arg.name === withoutBrackets);\n\n return {\n nameRaw: withoutBrackets,\n nameCamelCase: camelCase(withoutBrackets), // it also removes the \"...\" if exists\n required: trimmed.startsWith('<'),\n description: foundInArguments?.description,\n isArray: withoutBrackets.endsWith('...'),\n }\n });\n}\n\ntype FlagData = {\n name: string;\n alias?: string;\n description: string;\n type: 'string' | 'boolean';\n requiresArg: boolean; // a value is required after the flag. e.g. 'message <message>'\n}\n\nexport function getFlagsData(cmd: Command): FlagData[] {\n const options = cmd.options;\n if (!options) return [];\n return options.map((opt) => {\n const [alias, flag, description] = opt;\n const name = flag.split(' ')[0];\n const type = flag.includes('<') || flag.includes('[') ? 'string' : 'boolean';\n const requiresArg = flag.includes('<');\n\n return {\n name,\n alias,\n description,\n type,\n requiresArg,\n }\n });\n}\n\nexport function getCommandName(cmd: Command): string {\n return cmd.name.split(' ')[0];\n}"],"mappings":";;;;;;;;AACA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAgBO,SAASE,WAAWA,CAACC,GAAY,EAAa;EACnD,MAAMC,YAAY,GAAGD,GAAG,CAACE,IAAI,CAACC,KAAK,CAAC,GAAG,CAAC;EACxCF,YAAY,CAACG,KAAK,CAAC,CAAC,CAAC,CAAC;;EAEtB,OAAOH,YAAY,CAACI,GAAG,CAAEC,QAAQ,IAAK;IACpC,MAAMC,OAAO,GAAGD,QAAQ,CAACE,IAAI,CAAC,CAAC;IAC/B,IAAK,CAACD,OAAO,CAACE,UAAU,CAAC,GAAG,CAAC,IAAI,CAACF,OAAO,CAACE,UAAU,CAAC,GAAG,CAAC,IAAM,CAACF,OAAO,CAACG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAACH,OAAO,CAACG,QAAQ,CAAC,GAAG,CAAE,EAAE;MAChH,MAAM,IAAIC,KAAK,CAAC,eAAeJ,OAAO,SAASP,GAAG,CAACE,IAAI,mCAAmC,CAAC;IAC7F;IACA;IACA,MAAMU,eAAe,GAAGL,OAAO,CAACM,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,MAAMC,gBAAgB,GAAGd,GAAG,CAACe,SAAS,EAAEC,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACf,IAAI,KAAKU,eAAe,CAAC;IAEnF,OAAO;MACLM,OAAO,EAAEN,eAAe;MACxBO,aAAa,EAAE,IAAAC,mBAAS,EAACR,eAAe,CAAC;MAAE;MAC3CS,QAAQ,EAAEd,OAAO,CAACE,UAAU,CAAC,GAAG,CAAC;MACjCa,WAAW,EAAER,gBAAgB,EAAEQ,WAAW;MAC1CC,OAAO,EAAEX,eAAe,CAACF,QAAQ,CAAC,KAAK;IACzC,CAAC;EACH,CAAC,CAAC;AACJ;AAUO,SAASc,YAAYA,CAACxB,GAAY,EAAc;EACrD,MAAMyB,OAAO,GAAGzB,GAAG,CAACyB,OAAO;EAC3B,IAAI,CAACA,OAAO,EAAE,OAAO,EAAE;EACvB,OAAOA,OAAO,CAACpB,GAAG,CAAEqB,GAAG,IAAK;IAC1B,MAAM,CAACC,KAAK,EAAEC,IAAI,EAAEN,WAAW,CAAC,GAAGI,GAAG;IACtC,MAAMxB,IAAI,GAAG0B,IAAI,CAACzB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM0B,IAAI,GAAGD,IAAI,CAACE,QAAQ,CAAC,GAAG,CAAC,IAAIF,IAAI,CAACE,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,GAAG,SAAS;IAC5E,MAAMC,WAAW,GAAGH,IAAI,CAACE,QAAQ,CAAC,GAAG,CAAC;IAEtC,OAAO;MACL5B,IAAI;MACJyB,KAAK;MACLL,WAAW;MACXO,IAAI;MACJE;IACF,CAAC;EACH,CAAC,CAAC;AACJ;AAEO,SAASC,cAAcA,CAAChC,GAAY,EAAU;EACnD,OAAOA,GAAG,CAACE,IAAI,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC/B","ignoreList":[]}
@@ -0,0 +1,35 @@
1
+ import { CLIArgs, Command, Flags } from './command';
2
+ import { OnCommandStartSlot } from './cli.main.runtime';
3
+ type CommandResult = {
4
+ data: any;
5
+ exitCode: number;
6
+ };
7
+ export declare class CommandRunner {
8
+ private command;
9
+ private args;
10
+ private flags;
11
+ private onCommandStartSlot;
12
+ private commandName;
13
+ constructor(command: Command, args: CLIArgs, flags: Flags, onCommandStartSlot: OnCommandStartSlot);
14
+ /**
15
+ * run command using one of the handler, "json"/"report"/"render". once done, exit the process.
16
+ */
17
+ runCommand(shouldReturnResult?: boolean): Promise<void | CommandResult>;
18
+ private bootstrapCommand;
19
+ private invokeOnCommandStart;
20
+ /**
21
+ * this works for both, Harmony commands and Legacy commands (the legacy-command-adapter
22
+ * implements json() method)
23
+ */
24
+ private runJsonHandler;
25
+ private runReportHandler;
26
+ private runWaitHandler;
27
+ /**
28
+ * the loader and logger.console write output to the console during the command execution.
29
+ * for internals commands, such as, _put, _fetch, the command.loader = false.
30
+ */
31
+ private determineConsoleWritingDuringCommand;
32
+ private writeAndExit;
33
+ }
34
+ export declare function parseCommandName(commandName: string): string;
35
+ export {};
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CommandRunner = void 0;
7
+ exports.parseCommandName = parseCommandName;
8
+ function _legacy() {
9
+ const data = require("@teambit/legacy.logger");
10
+ _legacy = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _legacy2() {
16
+ const data = require("@teambit/legacy.loader");
17
+ _legacy2 = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
22
+ function _handleErrors() {
23
+ const data = require("./handle-errors");
24
+ _handleErrors = function () {
25
+ return data;
26
+ };
27
+ return data;
28
+ }
29
+ function _legacy3() {
30
+ const data = require("@teambit/legacy.constants");
31
+ _legacy3 = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
36
+ function _globalFlags() {
37
+ const data = _interopRequireDefault(require("./global-flags"));
38
+ _globalFlags = function () {
39
+ return data;
40
+ };
41
+ return data;
42
+ }
43
+ function _legacy4() {
44
+ const data = require("@teambit/legacy.analytics");
45
+ _legacy4 = function () {
46
+ return data;
47
+ };
48
+ return data;
49
+ }
50
+ function _pMapSeries() {
51
+ const data = _interopRequireDefault(require("p-map-series"));
52
+ _pMapSeries = function () {
53
+ return data;
54
+ };
55
+ return data;
56
+ }
57
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
58
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
59
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
60
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
61
+ class CommandRunner {
62
+ constructor(command, args, flags, onCommandStartSlot) {
63
+ this.command = command;
64
+ this.args = args;
65
+ this.flags = flags;
66
+ this.onCommandStartSlot = onCommandStartSlot;
67
+ _defineProperty(this, "commandName", void 0);
68
+ this.commandName = parseCommandName(this.command.name);
69
+ }
70
+
71
+ /**
72
+ * run command using one of the handler, "json"/"report"/"render". once done, exit the process.
73
+ */
74
+ async runCommand(shouldReturnResult = false) {
75
+ try {
76
+ this.bootstrapCommand();
77
+ await this.invokeOnCommandStart();
78
+ this.determineConsoleWritingDuringCommand();
79
+ if (this.flags.json) {
80
+ return await this.runJsonHandler(shouldReturnResult);
81
+ }
82
+ if (this.command.report) {
83
+ return await this.runReportHandler(shouldReturnResult);
84
+ }
85
+ if (this.command.wait) {
86
+ return await this.runWaitHandler();
87
+ }
88
+ } catch (err) {
89
+ if (shouldReturnResult) throw err;
90
+ return (0, _handleErrors().handleErrorAndExit)(err, this.commandName);
91
+ }
92
+ throw new Error(`command "${this.commandName}" doesn't implement "render" nor "report" nor "wait" methods`);
93
+ }
94
+ bootstrapCommand() {
95
+ try {
96
+ _legacy4().Analytics.init(this.commandName, this.flags, this.args);
97
+ } catch (err) {
98
+ // ignoring the error, we don't want to fail the app if analytics failed.
99
+ _legacy().logger.error('failed to initialize analytics', err);
100
+ }
101
+ _legacy().logger.info(`[*] started a new command: "${this.commandName}" with the following data:`, {
102
+ args: this.args,
103
+ flags: this.flags
104
+ });
105
+ const token = this.flags[_legacy3().TOKEN_FLAG_NAME];
106
+ if (token) {
107
+ _globalFlags().default.token = token.toString();
108
+ }
109
+ }
110
+ async invokeOnCommandStart() {
111
+ const funcs = this.onCommandStartSlot.values();
112
+ await (0, _pMapSeries().default)(funcs, onCommandStart => onCommandStart(this.commandName, this.args, this.flags));
113
+ }
114
+
115
+ /**
116
+ * this works for both, Harmony commands and Legacy commands (the legacy-command-adapter
117
+ * implements json() method)
118
+ */
119
+ async runJsonHandler(shouldReturnResult = false) {
120
+ if (!this.flags.json) return undefined;
121
+ if (!this.command.json) throw new Error(`command "${this.commandName}" doesn't implement "json" method`);
122
+ const result = await this.command.json(this.args, this.flags);
123
+ const code = result.code || 0;
124
+ const data = result.data || result;
125
+ if (shouldReturnResult) return {
126
+ data,
127
+ exitCode: code
128
+ };
129
+ const isJsonStream = Boolean(this.flags.stream);
130
+ if (isJsonStream) data.end = true;
131
+ const jsonStr = isJsonStream ? `${JSON.stringify(data)}\n` : JSON.stringify(data, null, 2);
132
+ await this.writeAndExit(jsonStr, code);
133
+ }
134
+ async runReportHandler(shouldReturnResult = false) {
135
+ if (!this.command.report) throw new Error('runReportHandler expects command.report to be implemented');
136
+ const result = await this.command.report(this.args, this.flags);
137
+ _legacy2().loader.off();
138
+ const data = typeof result === 'string' ? result : result.data;
139
+ const exitCode = typeof result === 'string' ? 0 : result.code;
140
+ if (shouldReturnResult) return {
141
+ data,
142
+ exitCode
143
+ };
144
+ await this.writeAndExit(`${data}\n`, exitCode);
145
+ }
146
+ async runWaitHandler() {
147
+ if (!this.command.wait) throw new Error('runReportHandler expects command.wait to be implemented');
148
+ await this.command.wait(this.args, this.flags);
149
+ }
150
+
151
+ /**
152
+ * the loader and logger.console write output to the console during the command execution.
153
+ * for internals commands, such as, _put, _fetch, the command.loader = false.
154
+ */
155
+ determineConsoleWritingDuringCommand() {
156
+ if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions'] && !_legacy().shouldDisableLoader) {
157
+ _legacy2().loader.on();
158
+ _legacy2().loader.start(`running command "${this.commandName}"...`);
159
+ _legacy().logger.shouldWriteToConsole = true;
160
+ } else {
161
+ _legacy2().loader.off();
162
+ _legacy().logger.shouldWriteToConsole = false;
163
+ }
164
+ }
165
+ async writeAndExit(data, exitCode) {
166
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
167
+ return process.stdout.write(data, async () => _legacy().logger.exitAfterFlush(exitCode, this.commandName, data));
168
+ }
169
+ }
170
+ exports.CommandRunner = CommandRunner;
171
+ function parseCommandName(commandName) {
172
+ if (!commandName) return '';
173
+ return commandName.split(' ')[0];
174
+ }
175
+
176
+ //# sourceMappingURL=command-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_legacy","data","require","_legacy2","_handleErrors","_legacy3","_globalFlags","_interopRequireDefault","_legacy4","_pMapSeries","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","CommandRunner","constructor","command","args","flags","onCommandStartSlot","commandName","parseCommandName","name","runCommand","shouldReturnResult","bootstrapCommand","invokeOnCommandStart","determineConsoleWritingDuringCommand","json","runJsonHandler","report","runReportHandler","wait","runWaitHandler","err","handleErrorAndExit","Error","Analytics","init","logger","error","info","token","TOKEN_FLAG_NAME","globalFlags","toString","funcs","values","pMapSeries","onCommandStart","undefined","result","code","exitCode","isJsonStream","Boolean","stream","end","jsonStr","JSON","stringify","writeAndExit","loader","off","shouldDisableLoader","on","start","shouldWriteToConsole","process","stdout","write","exitAfterFlush","exports","split"],"sources":["command-runner.ts"],"sourcesContent":["import { logger, shouldDisableLoader } from '@teambit/legacy.logger';\nimport { CLIArgs, Command, Flags } from './command';\nimport { loader } from '@teambit/legacy.loader';\nimport { handleErrorAndExit } from './handle-errors';\nimport { TOKEN_FLAG_NAME } from '@teambit/legacy.constants';\nimport globalFlags from './global-flags';\nimport { Analytics } from '@teambit/legacy.analytics';\nimport { OnCommandStartSlot } from './cli.main.runtime';\nimport pMapSeries from 'p-map-series';\n\ntype CommandResult = { data: any; exitCode: number };\n\nexport class CommandRunner {\n private commandName: string;\n constructor(\n private command: Command,\n private args: CLIArgs,\n private flags: Flags,\n private onCommandStartSlot: OnCommandStartSlot\n ) {\n this.commandName = parseCommandName(this.command.name);\n }\n\n /**\n * run command using one of the handler, \"json\"/\"report\"/\"render\". once done, exit the process.\n */\n async runCommand(shouldReturnResult = false): Promise<void | CommandResult> {\n try {\n this.bootstrapCommand();\n await this.invokeOnCommandStart();\n this.determineConsoleWritingDuringCommand();\n if (this.flags.json) {\n return await this.runJsonHandler(shouldReturnResult);\n }\n if (this.command.report) {\n return await this.runReportHandler(shouldReturnResult);\n }\n if (this.command.wait) {\n return await this.runWaitHandler();\n }\n } catch (err: any) {\n if (shouldReturnResult) throw err;\n return handleErrorAndExit(err, this.commandName);\n }\n\n throw new Error(`command \"${this.commandName}\" doesn't implement \"render\" nor \"report\" nor \"wait\" methods`);\n }\n\n private bootstrapCommand() {\n try {\n Analytics.init(this.commandName, this.flags, this.args);\n } catch (err: any) {\n // ignoring the error, we don't want to fail the app if analytics failed.\n logger.error('failed to initialize analytics', err);\n }\n logger.info(`[*] started a new command: \"${this.commandName}\" with the following data:`, {\n args: this.args,\n flags: this.flags,\n });\n const token = this.flags[TOKEN_FLAG_NAME];\n if (token) {\n globalFlags.token = token.toString();\n }\n }\n\n private async invokeOnCommandStart() {\n const funcs = this.onCommandStartSlot.values();\n await pMapSeries(funcs, (onCommandStart) => onCommandStart(this.commandName, this.args, this.flags));\n }\n\n /**\n * this works for both, Harmony commands and Legacy commands (the legacy-command-adapter\n * implements json() method)\n */\n private async runJsonHandler(shouldReturnResult = false): Promise<CommandResult | undefined> {\n if (!this.flags.json) return undefined;\n if (!this.command.json) throw new Error(`command \"${this.commandName}\" doesn't implement \"json\" method`);\n const result = await this.command.json(this.args, this.flags);\n const code = result.code || 0;\n const data = result.data || result;\n if (shouldReturnResult) return { data, exitCode: code };\n const isJsonStream = Boolean(this.flags.stream);\n if (isJsonStream) data.end = true;\n const jsonStr = isJsonStream ? `${JSON.stringify(data)}\\n` : JSON.stringify(data, null, 2);\n await this.writeAndExit(jsonStr, code);\n }\n\n private async runReportHandler(shouldReturnResult = false): Promise<CommandResult | undefined> {\n if (!this.command.report) throw new Error('runReportHandler expects command.report to be implemented');\n const result = await this.command.report(this.args, this.flags);\n loader.off();\n const data = typeof result === 'string' ? result : result.data;\n const exitCode = typeof result === 'string' ? 0 : result.code;\n if (shouldReturnResult) return { data, exitCode };\n await this.writeAndExit(`${data}\\n`, exitCode);\n }\n\n private async runWaitHandler() {\n if (!this.command.wait) throw new Error('runReportHandler expects command.wait to be implemented');\n await this.command.wait(this.args, this.flags);\n }\n\n /**\n * the loader and logger.console write output to the console during the command execution.\n * for internals commands, such as, _put, _fetch, the command.loader = false.\n */\n private determineConsoleWritingDuringCommand() {\n if (this.command.loader && !this.flags.json && !this.flags['get-yargs-completions'] && !shouldDisableLoader) {\n loader.on();\n loader.start(`running command \"${this.commandName}\"...`);\n logger.shouldWriteToConsole = true;\n } else {\n loader.off();\n logger.shouldWriteToConsole = false;\n }\n }\n\n private async writeAndExit(data: string, exitCode: number) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return process.stdout.write(data, async () => logger.exitAfterFlush(exitCode, this.commandName, data));\n }\n}\n\nexport function parseCommandName(commandName: string): string {\n if (!commandName) return '';\n return commandName.split(' ')[0];\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,SAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IA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,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAClC","ignoreList":[]}
@@ -0,0 +1,130 @@
1
+ import { Group } from './command-groups';
2
+ type CommandOption = [string, string, string];
3
+ export type CommandOptions = Array<CommandOption>;
4
+ export interface Command {
5
+ /**
6
+ * Name of command with arguments:
7
+ * <> for mandatory arguments.
8
+ * [] for optional arguments.
9
+ * e.g. 'add <path>'
10
+ */
11
+ name: string;
12
+ /**
13
+ * command alias (for example: 't' for 'tag')
14
+ */
15
+ alias?: string;
16
+ /**
17
+ * The description of the command. Being used in the commands summery (`bit --help`) and the help (e.g. `bit create --help`).
18
+ * should be short and precise. not more than one line. (use extendedDescription for more info).
19
+ */
20
+ description: string;
21
+ /**
22
+ * The extended description of the command. Will be seen in only in the command help, just after the description.
23
+ */
24
+ extendedDescription?: string;
25
+ /**
26
+ * url to a doc page explaining the command. shown in the command help just after the extendedDescription.
27
+ * if a relative url is entered, the base url will be retrieved from `teambit.community/community` aspect.
28
+ */
29
+ helpUrl?: string;
30
+ /**
31
+ * allow grouping of commands to hint summery renderer
32
+ * Places in default automatic help
33
+ */
34
+ group?: Group | string;
35
+ /**
36
+ * should a command be exposed to the user (by bit help).
37
+ * e.g. experimental or plumbing commands should be hidden.
38
+ */
39
+ private?: boolean;
40
+ /**
41
+ * should turn on Loader.
42
+ * the default is false for internal-commands and true for others.
43
+ * @see cliMain.setDefaults()
44
+ */
45
+ loader?: boolean;
46
+ /**
47
+ * Array of command options where each element is a tuple.
48
+ * ['flag alias', 'flag name', 'flag description']
49
+ * for example:
50
+ * ['j', 'json', 'output json format']
51
+ */
52
+ options: CommandOptions;
53
+ /**
54
+ * arguments are defined in the "name" property, and that's where the source of truth is.
55
+ * this prop is optional and provides a way to describe the args. later, it'll support more fields, such as defaultValue.
56
+ * if this is set, it'll be shown in the command help under "Arguments" section.
57
+ */
58
+ arguments?: CommandArg[];
59
+ /**
60
+ * sub commands for example:
61
+ * bit capsule list to list active capsules.
62
+ */
63
+ commands?: Command[];
64
+ /**
65
+ * interact with a remote, e.g. "export" push to a remote
66
+ * for now, the only difference is that they get a "token" flag to authenticate anonymously.
67
+ */
68
+ remoteOp?: boolean;
69
+ /**
70
+ * if true, it indicates that it doesn't need the workspace to work and can be executed outside a
71
+ * workspace
72
+ */
73
+ skipWorkspace?: boolean;
74
+ /**
75
+ * optionally, give some examples how to use the command.
76
+ */
77
+ examples?: Example[];
78
+ /**
79
+ * whether to load aspects set in workspace.jsonc before running the command.
80
+ * default is true.
81
+ */
82
+ loadAspects?: boolean;
83
+ /**
84
+ * do not set this. it is being set once the command run.
85
+ * the values are those followed `--` in the command line. (e.g. `bit import -- --no-optional`)
86
+ */
87
+ _packageManagerArgs?: string[];
88
+ /**
89
+ * Command handler which prints the return value to the console and exits.
90
+ * If the command has both, `render` and `report`, this one will be called when process.isTTY is false.
91
+ * @param args - arguments object as defined in name.
92
+ * @param flags - command flags as described in options.
93
+ * @return - Report object. The Report.data is printed to the stdout as is.
94
+ */
95
+ report?(args: CLIArgs, flags: Flags): Promise<string | Report>;
96
+ /**
97
+ * Command handler which never exits the process
98
+ * @param args - arguments object as defined in name.
99
+ * @param flags - command flags as described in options.
100
+ */
101
+ wait?(args: CLIArgs, flags: Flags): Promise<void>;
102
+ /**
103
+ * Optional handler to provide a raw result of the command.
104
+ * Will be go called if '-j'/'--json' option is provided by user.
105
+ * @param args - arguments object as defined in name.
106
+ * @param flags - command flags as described in options.
107
+ * @return a GenericObject to be rendered to string (by json.stringify) in the console.
108
+ */
109
+ json?(args: CLIArgs, flags: Flags): Promise<GenericObject>;
110
+ }
111
+ export type Flags = {
112
+ [flagName: string]: string | boolean | undefined | any;
113
+ };
114
+ export type CLIArgs = Array<string[] | string>;
115
+ export type GenericObject = {
116
+ [k: string]: any;
117
+ };
118
+ export type Report = {
119
+ data: string;
120
+ code: number;
121
+ };
122
+ export type CommandArg = {
123
+ name: string;
124
+ description?: string;
125
+ };
126
+ export type Example = {
127
+ cmd: string;
128
+ description: string;
129
+ };
130
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["command.ts"],"sourcesContent":["import { Group } from './command-groups';\n\ntype CommandOption = [string, string, string];\nexport type CommandOptions = Array<CommandOption>;\n\nexport interface Command {\n /**\n * Name of command with arguments:\n * <> for mandatory arguments.\n * [] for optional arguments.\n * e.g. 'add <path>'\n */\n name: string;\n\n /**\n * command alias (for example: 't' for 'tag')\n */\n alias?: string;\n\n /**\n * The description of the command. Being used in the commands summery (`bit --help`) and the help (e.g. `bit create --help`).\n * should be short and precise. not more than one line. (use extendedDescription for more info).\n */\n description: string;\n\n /**\n * The extended description of the command. Will be seen in only in the command help, just after the description.\n */\n extendedDescription?: string;\n\n /**\n * url to a doc page explaining the command. shown in the command help just after the extendedDescription.\n * if a relative url is entered, the base url will be retrieved from `teambit.community/community` aspect.\n */\n helpUrl?: string;\n\n /**\n * allow grouping of commands to hint summery renderer\n * Places in default automatic help\n */\n group?: Group | string;\n\n /**\n * should a command be exposed to the user (by bit help).\n * e.g. experimental or plumbing commands should be hidden.\n */\n private?: boolean;\n\n /**\n * should turn on Loader.\n * the default is false for internal-commands and true for others.\n * @see cliMain.setDefaults()\n */\n loader?: boolean;\n\n /**\n * Array of command options where each element is a tuple.\n * ['flag alias', 'flag name', 'flag description']\n * for example:\n * ['j', 'json', 'output json format']\n */\n options: CommandOptions;\n\n /**\n * arguments are defined in the \"name\" property, and that's where the source of truth is.\n * this prop is optional and provides a way to describe the args. later, it'll support more fields, such as defaultValue.\n * if this is set, it'll be shown in the command help under \"Arguments\" section.\n */\n arguments?: CommandArg[];\n\n /**\n * sub commands for example:\n * bit capsule list to list active capsules.\n */\n commands?: Command[];\n\n /**\n * interact with a remote, e.g. \"export\" push to a remote\n * for now, the only difference is that they get a \"token\" flag to authenticate anonymously.\n */\n remoteOp?: boolean;\n\n /**\n * if true, it indicates that it doesn't need the workspace to work and can be executed outside a\n * workspace\n */\n skipWorkspace?: boolean;\n\n /**\n * optionally, give some examples how to use the command.\n */\n examples?: Example[];\n\n /**\n * whether to load aspects set in workspace.jsonc before running the command.\n * default is true.\n */\n loadAspects?: boolean;\n\n /**\n * do not set this. it is being set once the command run.\n * the values are those followed `--` in the command line. (e.g. `bit import -- --no-optional`)\n */\n _packageManagerArgs?: string[];\n\n /**\n * Command handler which prints the return value to the console and exits.\n * If the command has both, `render` and `report`, this one will be called when process.isTTY is false.\n * @param args - arguments object as defined in name.\n * @param flags - command flags as described in options.\n * @return - Report object. The Report.data is printed to the stdout as is.\n */\n report?(args: CLIArgs, flags: Flags): Promise<string | Report>;\n\n /**\n * Command handler which never exits the process\n * @param args - arguments object as defined in name.\n * @param flags - command flags as described in options.\n */\n wait?(args: CLIArgs, flags: Flags): Promise<void>;\n\n /**\n * Optional handler to provide a raw result of the command.\n * Will be go called if '-j'/'--json' option is provided by user.\n * @param args - arguments object as defined in name.\n * @param flags - command flags as described in options.\n * @return a GenericObject to be rendered to string (by json.stringify) in the console.\n */\n json?(args: CLIArgs, flags: Flags): Promise<GenericObject>;\n}\nexport type Flags = { [flagName: string]: string | boolean | undefined | any };\nexport type CLIArgs = Array<string[] | string>;\nexport type GenericObject = { [k: string]: any };\nexport type Report = { data: string; code: number };\nexport type CommandArg = { name: string; description?: string };\nexport type Example = { cmd: string; description: string };\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import { Command } from './command';
2
+ export declare class CompletionCmd implements Command {
3
+ name: string;
4
+ description: string;
5
+ alias: string;
6
+ group: string;
7
+ options: never[];
8
+ private: boolean;
9
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CompletionCmd = void 0;
7
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
9
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
+ class CompletionCmd {
11
+ constructor() {
12
+ _defineProperty(this, "name", 'completion');
13
+ _defineProperty(this, "description", 'enable bash/zsh-completion shortcuts for commands and options');
14
+ _defineProperty(this, "alias", '');
15
+ _defineProperty(this, "group", 'system');
16
+ _defineProperty(this, "options", []);
17
+ _defineProperty(this, "private", true);
18
+ }
19
+ }
20
+ exports.CompletionCmd = CompletionCmd;
21
+
22
+ //# sourceMappingURL=completion.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CompletionCmd","constructor","_defineProperty","exports"],"sources":["completion.cmd.ts"],"sourcesContent":["import { Command } from './command';\n\nexport class CompletionCmd implements Command {\n name = 'completion';\n description = 'enable bash/zsh-completion shortcuts for commands and options';\n alias = '';\n group = 'system';\n options = [];\n private = true;\n}\n"],"mappings":";;;;;;;;;AAEO,MAAMA,aAAa,CAAoB;EAAAC,YAAA;IAAAC,eAAA,eACrC,YAAY;IAAAA,eAAA,sBACL,+DAA+D;IAAAA,eAAA,gBACrE,EAAE;IAAAA,eAAA,gBACF,QAAQ;IAAAA,eAAA,kBACN,EAAE;IAAAA,eAAA,kBACF,IAAI;EAAA;AAChB;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * if err.userError is set, it inherits from AbstractError, which are user errors not Bit errors
3
+ * and should not be reported to Sentry.
4
+ * reason why we don't check (err instanceof AbstractError) is that it could be thrown from a fork,
5
+ * in which case, it loses its class and has only the fields.
6
+ */
7
+ export declare function sendToAnalyticsAndSentry(err: Error): void;
8
+ declare const _default: (err: Error) => {
9
+ message: string;
10
+ error: Error;
11
+ };
12
+ export default _default;