@teambit/cli 0.0.0-00805bd6ead01ffad26e598a8de15824e876ee5a

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 (100) hide show
  1. package/.npmignore +18 -0
  2. package/cli-output-style-guide.md +132 -0
  3. package/cli.composition.tsx +7 -0
  4. package/cli.docs.mdx +12 -0
  5. package/dist/cli-output-style-guide.md +132 -0
  6. package/dist/cli-parser.d.ts +38 -0
  7. package/dist/cli-parser.js +388 -0
  8. package/dist/cli-parser.js.map +1 -0
  9. package/dist/cli-parser.spec.d.ts +1 -0
  10. package/dist/cli-parser.spec.js +113 -0
  11. package/dist/cli-parser.spec.js.map +1 -0
  12. package/dist/cli.aspect.d.ts +4 -0
  13. package/dist/cli.aspect.js +22 -0
  14. package/dist/cli.aspect.js.map +1 -0
  15. package/dist/cli.cmd.d.ts +34 -0
  16. package/dist/cli.cmd.js +163 -0
  17. package/dist/cli.cmd.js.map +1 -0
  18. package/dist/cli.composition.d.ts +2 -0
  19. package/dist/cli.composition.js +29 -0
  20. package/dist/cli.composition.js.map +1 -0
  21. package/dist/cli.docs.mdx +12 -0
  22. package/dist/cli.main.runtime.d.ts +86 -0
  23. package/dist/cli.main.runtime.js +270 -0
  24. package/dist/cli.main.runtime.js.map +1 -0
  25. package/dist/command-groups.d.ts +31 -0
  26. package/dist/command-groups.js +44 -0
  27. package/dist/command-groups.js.map +1 -0
  28. package/dist/command-helper.d.ts +25 -0
  29. package/dist/command-helper.js +59 -0
  30. package/dist/command-helper.js.map +1 -0
  31. package/dist/command-runner.d.ts +38 -0
  32. package/dist/command-runner.js +227 -0
  33. package/dist/command-runner.js.map +1 -0
  34. package/dist/command.d.ts +145 -0
  35. package/dist/command.js +3 -0
  36. package/dist/command.js.map +1 -0
  37. package/dist/completion.cmd.d.ts +9 -0
  38. package/dist/completion.cmd.js +22 -0
  39. package/dist/completion.cmd.js.map +1 -0
  40. package/dist/default-error-handler.d.ts +12 -0
  41. package/dist/default-error-handler.js +80 -0
  42. package/dist/default-error-handler.js.map +1 -0
  43. package/dist/details.cmd.d.ts +12 -0
  44. package/dist/details.cmd.js +78 -0
  45. package/dist/details.cmd.js.map +1 -0
  46. package/dist/esm.mjs +17 -0
  47. package/dist/exceptions/already-exists.d.ts +4 -0
  48. package/dist/exceptions/already-exists.js +21 -0
  49. package/dist/exceptions/already-exists.js.map +1 -0
  50. package/dist/exceptions/command-not-found.d.ts +7 -0
  51. package/dist/exceptions/command-not-found.js +44 -0
  52. package/dist/exceptions/command-not-found.js.map +1 -0
  53. package/dist/exceptions/index.d.ts +2 -0
  54. package/dist/exceptions/index.js +33 -0
  55. package/dist/exceptions/index.js.map +1 -0
  56. package/dist/exceptions/yargs-exit-workaround.d.ts +6 -0
  57. package/dist/exceptions/yargs-exit-workaround.js +23 -0
  58. package/dist/exceptions/yargs-exit-workaround.js.map +1 -0
  59. package/dist/generate-doc-md.d.ts +39 -0
  60. package/dist/generate-doc-md.js +266 -0
  61. package/dist/generate-doc-md.js.map +1 -0
  62. package/dist/get-command-id.d.ts +1 -0
  63. package/dist/get-command-id.js +11 -0
  64. package/dist/get-command-id.js.map +1 -0
  65. package/dist/global-flags.d.ts +7 -0
  66. package/dist/global-flags.js +24 -0
  67. package/dist/global-flags.js.map +1 -0
  68. package/dist/handle-errors.d.ts +3 -0
  69. package/dist/handle-errors.js +78 -0
  70. package/dist/handle-errors.js.map +1 -0
  71. package/dist/help.cmd.d.ts +16 -0
  72. package/dist/help.cmd.js +37 -0
  73. package/dist/help.cmd.js.map +1 -0
  74. package/dist/help.d.ts +3 -0
  75. package/dist/help.js +88 -0
  76. package/dist/help.js.map +1 -0
  77. package/dist/index.d.ts +14 -0
  78. package/dist/index.js +245 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/output-formatter.d.ts +40 -0
  81. package/dist/output-formatter.js +115 -0
  82. package/dist/output-formatter.js.map +1 -0
  83. package/dist/pager.d.ts +35 -0
  84. package/dist/pager.js +178 -0
  85. package/dist/pager.js.map +1 -0
  86. package/dist/preview-1787076242549.js +7 -0
  87. package/dist/version.cmd.d.ts +13 -0
  88. package/dist/version.cmd.js +39 -0
  89. package/dist/version.cmd.js.map +1 -0
  90. package/dist/yargs-adapter.d.ts +22 -0
  91. package/dist/yargs-adapter.js +133 -0
  92. package/dist/yargs-adapter.js.map +1 -0
  93. package/esm.mjs +17 -0
  94. package/exceptions/already-exists.ts +7 -0
  95. package/exceptions/command-not-found.ts +22 -0
  96. package/exceptions/index.ts +2 -0
  97. package/exceptions/yargs-exit-workaround.ts +10 -0
  98. package/package.json +74 -0
  99. package/types/asset.d.ts +41 -0
  100. package/types/style.d.ts +46 -0
@@ -0,0 +1,14 @@
1
+ import { CLIAspect, MainRuntime } from './cli.aspect';
2
+ import globalFlags from './global-flags';
3
+ import defaultErrorHandler from './default-error-handler';
4
+ export { CLIParser } from './cli-parser';
5
+ export type { CLIMain, CommandList, CommandsSlot } from './cli.main.runtime';
6
+ export { handleUnhandledRejection, handleErrorAndExit, setExitOnUnhandledRejection } from './handle-errors';
7
+ export { globalFlags };
8
+ export { defaultErrorHandler };
9
+ export type { Command, CLIArgs, Flags, GenericObject, CommandOptions, Report } from './command';
10
+ export { getArgsData, getCommandName, getFlagsData } from './command-helper';
11
+ export * from './exceptions';
12
+ export { successSymbol, warnSymbol, errorSymbol, bulletSymbol, formatItem, formatSection, formatTitle, formatHint, formatDetailsHint, formatSuccessSummary, formatWarningSummary, joinSections, renderSections, } from './output-formatter';
13
+ export type { OutputSection } from './output-formatter';
14
+ export { CLIAspect as default, MainRuntime, CLIAspect };
package/dist/index.js ADDED
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ CLIAspect: true,
8
+ MainRuntime: true,
9
+ globalFlags: true,
10
+ defaultErrorHandler: true,
11
+ CLIParser: true,
12
+ handleUnhandledRejection: true,
13
+ handleErrorAndExit: true,
14
+ setExitOnUnhandledRejection: true,
15
+ getArgsData: true,
16
+ getCommandName: true,
17
+ getFlagsData: true,
18
+ successSymbol: true,
19
+ warnSymbol: true,
20
+ errorSymbol: true,
21
+ bulletSymbol: true,
22
+ formatItem: true,
23
+ formatSection: true,
24
+ formatTitle: true,
25
+ formatHint: true,
26
+ formatDetailsHint: true,
27
+ formatSuccessSummary: true,
28
+ formatWarningSummary: true,
29
+ joinSections: true,
30
+ renderSections: true
31
+ };
32
+ Object.defineProperty(exports, "CLIAspect", {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _cli().CLIAspect;
36
+ }
37
+ });
38
+ Object.defineProperty(exports, "CLIParser", {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _cliParser().CLIParser;
42
+ }
43
+ });
44
+ Object.defineProperty(exports, "MainRuntime", {
45
+ enumerable: true,
46
+ get: function () {
47
+ return _cli().MainRuntime;
48
+ }
49
+ });
50
+ Object.defineProperty(exports, "bulletSymbol", {
51
+ enumerable: true,
52
+ get: function () {
53
+ return _outputFormatter().bulletSymbol;
54
+ }
55
+ });
56
+ Object.defineProperty(exports, "default", {
57
+ enumerable: true,
58
+ get: function () {
59
+ return _cli().CLIAspect;
60
+ }
61
+ });
62
+ Object.defineProperty(exports, "defaultErrorHandler", {
63
+ enumerable: true,
64
+ get: function () {
65
+ return _defaultErrorHandler().default;
66
+ }
67
+ });
68
+ Object.defineProperty(exports, "errorSymbol", {
69
+ enumerable: true,
70
+ get: function () {
71
+ return _outputFormatter().errorSymbol;
72
+ }
73
+ });
74
+ Object.defineProperty(exports, "formatDetailsHint", {
75
+ enumerable: true,
76
+ get: function () {
77
+ return _outputFormatter().formatDetailsHint;
78
+ }
79
+ });
80
+ Object.defineProperty(exports, "formatHint", {
81
+ enumerable: true,
82
+ get: function () {
83
+ return _outputFormatter().formatHint;
84
+ }
85
+ });
86
+ Object.defineProperty(exports, "formatItem", {
87
+ enumerable: true,
88
+ get: function () {
89
+ return _outputFormatter().formatItem;
90
+ }
91
+ });
92
+ Object.defineProperty(exports, "formatSection", {
93
+ enumerable: true,
94
+ get: function () {
95
+ return _outputFormatter().formatSection;
96
+ }
97
+ });
98
+ Object.defineProperty(exports, "formatSuccessSummary", {
99
+ enumerable: true,
100
+ get: function () {
101
+ return _outputFormatter().formatSuccessSummary;
102
+ }
103
+ });
104
+ Object.defineProperty(exports, "formatTitle", {
105
+ enumerable: true,
106
+ get: function () {
107
+ return _outputFormatter().formatTitle;
108
+ }
109
+ });
110
+ Object.defineProperty(exports, "formatWarningSummary", {
111
+ enumerable: true,
112
+ get: function () {
113
+ return _outputFormatter().formatWarningSummary;
114
+ }
115
+ });
116
+ Object.defineProperty(exports, "getArgsData", {
117
+ enumerable: true,
118
+ get: function () {
119
+ return _commandHelper().getArgsData;
120
+ }
121
+ });
122
+ Object.defineProperty(exports, "getCommandName", {
123
+ enumerable: true,
124
+ get: function () {
125
+ return _commandHelper().getCommandName;
126
+ }
127
+ });
128
+ Object.defineProperty(exports, "getFlagsData", {
129
+ enumerable: true,
130
+ get: function () {
131
+ return _commandHelper().getFlagsData;
132
+ }
133
+ });
134
+ Object.defineProperty(exports, "globalFlags", {
135
+ enumerable: true,
136
+ get: function () {
137
+ return _globalFlags().default;
138
+ }
139
+ });
140
+ Object.defineProperty(exports, "handleErrorAndExit", {
141
+ enumerable: true,
142
+ get: function () {
143
+ return _handleErrors().handleErrorAndExit;
144
+ }
145
+ });
146
+ Object.defineProperty(exports, "handleUnhandledRejection", {
147
+ enumerable: true,
148
+ get: function () {
149
+ return _handleErrors().handleUnhandledRejection;
150
+ }
151
+ });
152
+ Object.defineProperty(exports, "joinSections", {
153
+ enumerable: true,
154
+ get: function () {
155
+ return _outputFormatter().joinSections;
156
+ }
157
+ });
158
+ Object.defineProperty(exports, "renderSections", {
159
+ enumerable: true,
160
+ get: function () {
161
+ return _outputFormatter().renderSections;
162
+ }
163
+ });
164
+ Object.defineProperty(exports, "setExitOnUnhandledRejection", {
165
+ enumerable: true,
166
+ get: function () {
167
+ return _handleErrors().setExitOnUnhandledRejection;
168
+ }
169
+ });
170
+ Object.defineProperty(exports, "successSymbol", {
171
+ enumerable: true,
172
+ get: function () {
173
+ return _outputFormatter().successSymbol;
174
+ }
175
+ });
176
+ Object.defineProperty(exports, "warnSymbol", {
177
+ enumerable: true,
178
+ get: function () {
179
+ return _outputFormatter().warnSymbol;
180
+ }
181
+ });
182
+ function _cli() {
183
+ const data = require("./cli.aspect");
184
+ _cli = function () {
185
+ return data;
186
+ };
187
+ return data;
188
+ }
189
+ function _globalFlags() {
190
+ const data = _interopRequireDefault(require("./global-flags"));
191
+ _globalFlags = function () {
192
+ return data;
193
+ };
194
+ return data;
195
+ }
196
+ function _defaultErrorHandler() {
197
+ const data = _interopRequireDefault(require("./default-error-handler"));
198
+ _defaultErrorHandler = function () {
199
+ return data;
200
+ };
201
+ return data;
202
+ }
203
+ function _cliParser() {
204
+ const data = require("./cli-parser");
205
+ _cliParser = function () {
206
+ return data;
207
+ };
208
+ return data;
209
+ }
210
+ function _handleErrors() {
211
+ const data = require("./handle-errors");
212
+ _handleErrors = function () {
213
+ return data;
214
+ };
215
+ return data;
216
+ }
217
+ function _commandHelper() {
218
+ const data = require("./command-helper");
219
+ _commandHelper = function () {
220
+ return data;
221
+ };
222
+ return data;
223
+ }
224
+ var _exceptions = require("./exceptions");
225
+ Object.keys(_exceptions).forEach(function (key) {
226
+ if (key === "default" || key === "__esModule") return;
227
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
228
+ if (key in exports && exports[key] === _exceptions[key]) return;
229
+ Object.defineProperty(exports, key, {
230
+ enumerable: true,
231
+ get: function () {
232
+ return _exceptions[key];
233
+ }
234
+ });
235
+ });
236
+ function _outputFormatter() {
237
+ const data = require("./output-formatter");
238
+ _outputFormatter = function () {
239
+ return data;
240
+ };
241
+ return data;
242
+ }
243
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
244
+
245
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_cli","data","require","_globalFlags","_interopRequireDefault","_defaultErrorHandler","_cliParser","_handleErrors","_commandHelper","_exceptions","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_outputFormatter","e","__esModule","default"],"sources":["index.ts"],"sourcesContent":["import { CLIAspect, MainRuntime } from './cli.aspect';\nimport globalFlags from './global-flags';\nimport defaultErrorHandler from './default-error-handler';\nexport { CLIParser } from './cli-parser';\nexport type { CLIMain, CommandList, CommandsSlot } from './cli.main.runtime';\nexport { handleUnhandledRejection, handleErrorAndExit, setExitOnUnhandledRejection } from './handle-errors';\nexport { globalFlags };\nexport { defaultErrorHandler };\nexport type { Command, CLIArgs, Flags, GenericObject, CommandOptions, Report } from './command';\nexport { getArgsData, getCommandName, getFlagsData } from './command-helper';\nexport * from './exceptions';\n\nexport {\n successSymbol,\n warnSymbol,\n errorSymbol,\n bulletSymbol,\n formatItem,\n formatSection,\n formatTitle,\n formatHint,\n formatDetailsHint,\n formatSuccessSummary,\n formatWarningSummary,\n joinSections,\n renderSections,\n} from './output-formatter';\nexport type { OutputSection } from './output-formatter';\n\nexport { CLIAspect as default, MainRuntime, CLIAspect };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,aAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA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OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -0,0 +1,40 @@
1
+ export declare function successSymbol(): string;
2
+ /** Yellow warning symbol */
3
+ export declare const warnSymbol: string;
4
+ /** Red error symbol */
5
+ export declare const errorSymbol: string;
6
+ /** Neutral bullet for informational items (no success/failure connotation) */
7
+ export declare const bulletSymbol: string;
8
+ /** Format a single item with 3-space indent + symbol + text. Defaults to bullet symbol. */
9
+ export declare function formatItem(text: string, symbol?: string): string;
10
+ /**
11
+ * Format a section with bold white title (including item count), dim description, and items.
12
+ * Returns empty string if items array is empty.
13
+ */
14
+ export declare function formatSection(title: string, description: string, items: string[]): string;
15
+ /** Format a bold white section title */
16
+ export declare function formatTitle(text: string): string;
17
+ /** Format hint text in dim color */
18
+ export declare function formatHint(text: string): string;
19
+ /** Format a hint pointing the user to `bit details` for expanded output */
20
+ export declare function formatDetailsHint(subject?: string): string;
21
+ /** Format a success summary: green checkmark + green message */
22
+ export declare function formatSuccessSummary(msg: string): string;
23
+ /** Format a warning summary: warning symbol + yellow message */
24
+ export declare function formatWarningSummary(msg: string): string;
25
+ /** Filter out empty strings and join remaining sections with double newlines */
26
+ export declare function joinSections(sections: string[]): string;
27
+ export interface OutputSection {
28
+ /** The fully rendered section text */
29
+ content: string;
30
+ /** If set, this section starts collapsed. Use --expand to show full content. */
31
+ collapsible?: {
32
+ /** Summary line shown when collapsed */
33
+ summary: string;
34
+ };
35
+ }
36
+ /**
37
+ * Render sections to a string, collapsing sections that are marked collapsible.
38
+ * When expand is true, all sections are shown expanded.
39
+ */
40
+ export declare function renderSections(sections: OutputSection[], expand?: boolean): string;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.errorSymbol = exports.bulletSymbol = void 0;
7
+ exports.formatDetailsHint = formatDetailsHint;
8
+ exports.formatHint = formatHint;
9
+ exports.formatItem = formatItem;
10
+ exports.formatSection = formatSection;
11
+ exports.formatSuccessSummary = formatSuccessSummary;
12
+ exports.formatTitle = formatTitle;
13
+ exports.formatWarningSummary = formatWarningSummary;
14
+ exports.joinSections = joinSections;
15
+ exports.renderSections = renderSections;
16
+ exports.successSymbol = successSymbol;
17
+ exports.warnSymbol = void 0;
18
+ function _chalk() {
19
+ const data = _interopRequireDefault(require("chalk"));
20
+ _chalk = function () {
21
+ return data;
22
+ };
23
+ return data;
24
+ }
25
+ function _os() {
26
+ const data = require("os");
27
+ _os = function () {
28
+ return data;
29
+ };
30
+ return data;
31
+ }
32
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
+ /** Cross-platform green checkmark (mirrors Logger.successSymbol without importing Logger to avoid coupling) */
34
+ const _successSymbol = (0, _os().platform)() === 'win32' ? _chalk().default.green('\u2713') : _chalk().default.green('\u2714');
35
+ function successSymbol() {
36
+ return _successSymbol;
37
+ }
38
+
39
+ /** Yellow warning symbol */
40
+ const warnSymbol = exports.warnSymbol = _chalk().default.yellow('\u26A0');
41
+
42
+ /** Red error symbol */
43
+ const errorSymbol = exports.errorSymbol = _chalk().default.red('\u2716');
44
+
45
+ /** Neutral bullet for informational items (no success/failure connotation) */
46
+ const bulletSymbol = exports.bulletSymbol = _chalk().default.dim('\u203A');
47
+
48
+ /** Format a single item with 3-space indent + symbol + text. Defaults to bullet symbol. */
49
+ function formatItem(text, symbol) {
50
+ const s = symbol ?? bulletSymbol;
51
+ return ` ${s} ${text}`;
52
+ }
53
+
54
+ /**
55
+ * Format a section with bold white title (including item count), dim description, and items.
56
+ * Returns empty string if items array is empty.
57
+ */
58
+ function formatSection(title, description, items) {
59
+ if (!items.length) return '';
60
+ const lines = [formatTitle(`${title} (${items.length})`)];
61
+ if (description) {
62
+ const indented = description.split('\n').map(l => ` ${l}`).join('\n');
63
+ lines.push(_chalk().default.dim(indented));
64
+ }
65
+ lines.push(...items);
66
+ return lines.join('\n');
67
+ }
68
+
69
+ /** Format a bold white section title */
70
+ function formatTitle(text) {
71
+ return _chalk().default.bold.white(text);
72
+ }
73
+
74
+ /** Format hint text in dim color */
75
+ function formatHint(text) {
76
+ return _chalk().default.dim(text);
77
+ }
78
+
79
+ /** Format a hint pointing the user to `bit details` for expanded output */
80
+ function formatDetailsHint(subject) {
81
+ const what = subject ? ` ${subject}` : '';
82
+ return formatHint(`(run "bit details" to see${what})`);
83
+ }
84
+
85
+ /** Format a success summary: green checkmark + green message */
86
+ function formatSuccessSummary(msg) {
87
+ return `${successSymbol()} ${_chalk().default.green(msg)}`;
88
+ }
89
+
90
+ /** Format a warning summary: warning symbol + yellow message */
91
+ function formatWarningSummary(msg) {
92
+ return `${warnSymbol} ${_chalk().default.yellow(msg)}`;
93
+ }
94
+
95
+ /** Filter out empty strings and join remaining sections with double newlines */
96
+ function joinSections(sections) {
97
+ return sections.filter(Boolean).join('\n\n');
98
+ }
99
+ /**
100
+ * Render sections to a string, collapsing sections that are marked collapsible.
101
+ * When expand is true, all sections are shown expanded.
102
+ */
103
+ function renderSections(sections, expand = false) {
104
+ const parts = [];
105
+ for (const section of sections) {
106
+ if (section.collapsible && !expand) {
107
+ parts.push(section.collapsible.summary);
108
+ } else if (section.content) {
109
+ parts.push(section.content);
110
+ }
111
+ }
112
+ return parts.filter(Boolean).join('\n\n');
113
+ }
114
+
115
+ //# sourceMappingURL=output-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_chalk","data","_interopRequireDefault","require","_os","e","__esModule","default","_successSymbol","platform","chalk","green","successSymbol","warnSymbol","exports","yellow","errorSymbol","red","bulletSymbol","dim","formatItem","text","symbol","s","formatSection","title","description","items","length","lines","formatTitle","indented","split","map","l","join","push","bold","white","formatHint","formatDetailsHint","subject","what","formatSuccessSummary","msg","formatWarningSummary","joinSections","sections","filter","Boolean","renderSections","expand","parts","section","collapsible","summary","content"],"sources":["output-formatter.ts"],"sourcesContent":["import chalk from 'chalk';\nimport { platform } from 'os';\n\n/** Cross-platform green checkmark (mirrors Logger.successSymbol without importing Logger to avoid coupling) */\nconst _successSymbol = platform() === 'win32' ? chalk.green('\\u2713') : chalk.green('\\u2714');\nexport function successSymbol(): string {\n return _successSymbol;\n}\n\n/** Yellow warning symbol */\nexport const warnSymbol = chalk.yellow('\\u26A0');\n\n/** Red error symbol */\nexport const errorSymbol = chalk.red('\\u2716');\n\n/** Neutral bullet for informational items (no success/failure connotation) */\nexport const bulletSymbol = chalk.dim('\\u203A');\n\n/** Format a single item with 3-space indent + symbol + text. Defaults to bullet symbol. */\nexport function formatItem(text: string, symbol?: string): string {\n const s = symbol ?? bulletSymbol;\n return ` ${s} ${text}`;\n}\n\n/**\n * Format a section with bold white title (including item count), dim description, and items.\n * Returns empty string if items array is empty.\n */\nexport function formatSection(title: string, description: string, items: string[]): string {\n if (!items.length) return '';\n const lines: string[] = [formatTitle(`${title} (${items.length})`)];\n if (description) {\n const indented = description\n .split('\\n')\n .map((l) => ` ${l}`)\n .join('\\n');\n lines.push(chalk.dim(indented));\n }\n lines.push(...items);\n return lines.join('\\n');\n}\n\n/** Format a bold white section title */\nexport function formatTitle(text: string): string {\n return chalk.bold.white(text);\n}\n\n/** Format hint text in dim color */\nexport function formatHint(text: string): string {\n return chalk.dim(text);\n}\n\n/** Format a hint pointing the user to `bit details` for expanded output */\nexport function formatDetailsHint(subject?: string): string {\n const what = subject ? ` ${subject}` : '';\n return formatHint(`(run \"bit details\" to see${what})`);\n}\n\n/** Format a success summary: green checkmark + green message */\nexport function formatSuccessSummary(msg: string): string {\n return `${successSymbol()} ${chalk.green(msg)}`;\n}\n\n/** Format a warning summary: warning symbol + yellow message */\nexport function formatWarningSummary(msg: string): string {\n return `${warnSymbol} ${chalk.yellow(msg)}`;\n}\n\n/** Filter out empty strings and join remaining sections with double newlines */\nexport function joinSections(sections: string[]): string {\n return sections.filter(Boolean).join('\\n\\n');\n}\n\nexport interface OutputSection {\n /** The fully rendered section text */\n content: string;\n /** If set, this section starts collapsed. Use --expand to show full content. */\n collapsible?: {\n /** Summary line shown when collapsed */\n summary: string;\n };\n}\n\n/**\n * Render sections to a string, collapsing sections that are marked collapsible.\n * When expand is true, all sections are shown expanded.\n */\nexport function renderSections(sections: OutputSection[], expand = false): string {\n const parts: string[] = [];\n for (const section of sections) {\n if (section.collapsible && !expand) {\n parts.push(section.collapsible.summary);\n } else if (section.content) {\n parts.push(section.content);\n }\n }\n return parts.filter(Boolean).join('\\n\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,IAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,GAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8B,SAAAC,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9B;AACA,MAAMG,cAAc,GAAG,IAAAC,cAAQ,EAAC,CAAC,KAAK,OAAO,GAAGC,gBAAK,CAACC,KAAK,CAAC,QAAQ,CAAC,GAAGD,gBAAK,CAACC,KAAK,CAAC,QAAQ,CAAC;AACtF,SAASC,aAAaA,CAAA,EAAW;EACtC,OAAOJ,cAAc;AACvB;;AAEA;AACO,MAAMK,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGH,gBAAK,CAACK,MAAM,CAAC,QAAQ,CAAC;;AAEhD;AACO,MAAMC,WAAW,GAAAF,OAAA,CAAAE,WAAA,GAAGN,gBAAK,CAACO,GAAG,CAAC,QAAQ,CAAC;;AAE9C;AACO,MAAMC,YAAY,GAAAJ,OAAA,CAAAI,YAAA,GAAGR,gBAAK,CAACS,GAAG,CAAC,QAAQ,CAAC;;AAE/C;AACO,SAASC,UAAUA,CAACC,IAAY,EAAEC,MAAe,EAAU;EAChE,MAAMC,CAA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A;AACO,SAASC,oBAAoBA,CAACD,GAAW,EAAU;EACxD,OAAO,GAAG/B,UAAU,IAAIH,gBAAK,CAACK,MAAM,CAAC6B,GAAG,CAAC,EAAE;AAC7C;;AAEA;AACO,SAASE,YAAYA,CAACC,QAAkB,EAAU;EACvD,OAAOA,QAAQ,CAACC,MAAM,CAACC,OAAO,CAAC,CAACd,IAAI,CAAC,MAAM,CAAC;AAC9C;AAYA;AACA;AACA;AACA;AACO,SAASe,cAAcA,CAACH,QAAyB,EAAEI,MAAM,GAAG,KAAK,EAAU;EAChF,MAAMC,KAAe,GAAG,EAAE;EAC1B,KAAK,MAAMC,OAAO,IAAIN,QAAQ,EAAE;IAC9B,IAAIM,OAAO,CAACC,WAAW,IAAI,CAACH,MAAM,EAAE;MAClCC,KAAK,CAAChB,IAAI,CAACiB,OAAO,CAACC,WAAW,CAACC,OAAO,CAAC;IACzC,CAAC,MAAM,IAAIF,OAAO,CAACG,OAAO,EAAE;MAC1BJ,KAAK,CAAChB,IAAI,CAACiB,OAAO,CAACG,OAAO,CAAC;IAC7B;EACF;EACA,OAAOJ,KAAK,CAACJ,MAAM,CAACC,OAAO,CAAC,CAACd,IAAI,CAAC,MAAM,CAAC;AAC3C","ignoreList":[]}
@@ -0,0 +1,35 @@
1
+ import type { Command, Flags } from './command';
2
+ /**
3
+ * detect whether the output is going to an interactive human terminal.
4
+ * anything non-interactive (piped output, CI, ai-agents, bit-cli-server) gets the full output
5
+ * with no pager.
6
+ */
7
+ export declare function isInteractiveTerminal(): boolean;
8
+ /**
9
+ * whether the output already fits within the current terminal, in which case there's no reason
10
+ * to page it (avoids the "press q to exit" annoyance for short output, without relying on the
11
+ * version-dependent `less -F` behavior which is broken by `-X` in modern less). accounts for line
12
+ * wrapping and ignores ansi color codes when measuring width. returns false when the terminal size
13
+ * is unknown.
14
+ */
15
+ export declare function fitsOnScreen(output: string): boolean;
16
+ /**
17
+ * decide whether a command's report output should be piped through a pager.
18
+ * mirrors git: on by default for interactive terminals, off for anything else. explicit flags
19
+ * (--pager / --no-pager) and the BIT_NO_PAGER env var override the automatic behavior. in the
20
+ * automatic case, output that already fits on the screen is printed directly (no pager).
21
+ */
22
+ export declare function shouldUsePager(command: Command, flags: Flags, output: string): boolean;
23
+ /**
24
+ * pipe the given output through a pager (`less` by default). resolves to `true` only after the
25
+ * pager process has exited cleanly — the caller must await this before exiting the process so the
26
+ * pager isn't cut off. resolves to `false` when paging is disabled, the pager couldn't launch, or
27
+ * it exited with an error, in which case the caller must write the data directly so nothing is lost.
28
+ *
29
+ * the pager binary is taken from BIT_PAGER, then PAGER, defaulting to `less`. an empty or `cat`
30
+ * pager means the user disabled paging via the env — honored unless `force` is set (the `--pager`
31
+ * flag), which falls back to a real pager so the flag is a true override. for `less` we set
32
+ * `LESS=FRX` (unless already set, matching git's default): keep ansi colors (-R), don't clear the
33
+ * screen on exit (-X), and quit if the output fits one screen (-F).
34
+ */
35
+ export declare function writeToPager(data: string, force?: boolean): Promise<boolean>;
package/dist/pager.js ADDED
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fitsOnScreen = fitsOnScreen;
7
+ exports.isInteractiveTerminal = isInteractiveTerminal;
8
+ exports.shouldUsePager = shouldUsePager;
9
+ exports.writeToPager = writeToPager;
10
+ function _child_process() {
11
+ const data = require("child_process");
12
+ _child_process = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _path() {
18
+ const data = require("path");
19
+ _path = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _legacy() {
25
+ const data = require("@teambit/legacy.logger");
26
+ _legacy = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _legacy2() {
32
+ const data = require("@teambit/legacy.utils");
33
+ _legacy2 = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ 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; }
39
+ 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; }
40
+ 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; }
41
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
42
+ 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); }
43
+ /**
44
+ * best-effort list of env vars set by ai-agent / automation runners. when any is present we
45
+ * never page, so agents always receive the full command output at once (never partial/paged
46
+ * data), even in the rare case they allocate a pseudo-tty.
47
+ */
48
+ const AI_AGENT_ENV_VARS = ['CLAUDECODE', 'CLAUDE_CODE', 'CURSOR_AGENT'];
49
+
50
+ /**
51
+ * an env var counts as "set" when it's present at all, even if its value is an empty string. the
52
+ * vars we gate on (CI, ai-agent markers, BIT_NO_PAGER) are opt-outs, so presence — not truthiness —
53
+ * is what disables paging; this also matches automation runners that inject empty-string values.
54
+ */
55
+ const isEnvSet = name => process.env[name] !== undefined;
56
+
57
+ /**
58
+ * detect whether the output is going to an interactive human terminal.
59
+ * anything non-interactive (piped output, CI, ai-agents, bit-cli-server) gets the full output
60
+ * with no pager.
61
+ */
62
+ function isInteractiveTerminal() {
63
+ if (!process.stdout.isTTY) return false;
64
+ // daemon contexts don't page: the bit-cli-server (output travels over IPC, no terminal) and the
65
+ // experimental `bit cli` REPL (a pager would fight its readline interface over the TTY).
66
+ if (_legacy().logger.isDaemon) return false;
67
+ if (isEnvSet('CI')) return false;
68
+ if (AI_AGENT_ENV_VARS.some(isEnvSet)) return false;
69
+ return true;
70
+ }
71
+
72
+ /**
73
+ * whether the output already fits within the current terminal, in which case there's no reason
74
+ * to page it (avoids the "press q to exit" annoyance for short output, without relying on the
75
+ * version-dependent `less -F` behavior which is broken by `-X` in modern less). accounts for line
76
+ * wrapping and ignores ansi color codes when measuring width. returns false when the terminal size
77
+ * is unknown.
78
+ */
79
+ function fitsOnScreen(output) {
80
+ const {
81
+ rows,
82
+ columns
83
+ } = process.stdout;
84
+ if (!rows || !columns) return false;
85
+ // split at most rows+1 lines — enough to prove overflow — so the array never scales with the
86
+ // full (potentially huge) output; the loop below also early-exits once one screen is exceeded.
87
+ const lines = output.replace(/\n$/, '').split('\n', rows + 1);
88
+ let usedRows = 0;
89
+ for (const line of lines) {
90
+ const width = ((0, _legacy2().removeChalkCharacters)(line) || '').length;
91
+ usedRows += width === 0 ? 1 : Math.ceil(width / columns);
92
+ if (usedRows > rows) return false; // stop early once we know it overflows one screen
93
+ }
94
+ return true;
95
+ }
96
+
97
+ /**
98
+ * decide whether a command's report output should be piped through a pager.
99
+ * mirrors git: on by default for interactive terminals, off for anything else. explicit flags
100
+ * (--pager / --no-pager) and the BIT_NO_PAGER env var override the automatic behavior. in the
101
+ * automatic case, output that already fits on the screen is printed directly (no pager).
102
+ */
103
+ function shouldUsePager(command, flags, output) {
104
+ if (!command.pager) return false; // command didn't opt-in to paging
105
+ if (flags.json) return false; // json is for machine consumption, never page it
106
+ // explicit CLI flags win over the BIT_NO_PAGER env var, so `--pager` can force paging for a
107
+ // single invocation even when the user exports BIT_NO_PAGER globally.
108
+ if (flags['no-pager']) return false;
109
+ if (flags.pager) return true; // explicit force-on, even when non-interactive / fits on screen
110
+ if (isEnvSet('BIT_NO_PAGER')) return false; // env opt-out (overridable by --pager above)
111
+ if (!isInteractiveTerminal()) return false;
112
+ return !fitsOnScreen(output); // only page when the output is longer than one screen
113
+ }
114
+
115
+ /**
116
+ * split a configured pager string (BIT_PAGER / PAGER) into [command, ...args], honoring single and
117
+ * double quotes so an executable path that contains spaces can be configured, e.g.
118
+ * `"/Applications/My Pager/less" -R`. we deliberately don't run the pager through a shell (avoids
119
+ * shell-injection and the ENOENT-swallows-output problem), so quoting is how a spaced path is
120
+ * expressed.
121
+ */
122
+ function parsePagerCommand(pager) {
123
+ const tokens = pager.match(/"[^"]*"|'[^']*'|\S+/g) || [];
124
+ return tokens.map(token => token.replace(/^["']|["']$/g, ''));
125
+ }
126
+
127
+ /**
128
+ * pipe the given output through a pager (`less` by default). resolves to `true` only after the
129
+ * pager process has exited cleanly — the caller must await this before exiting the process so the
130
+ * pager isn't cut off. resolves to `false` when paging is disabled, the pager couldn't launch, or
131
+ * it exited with an error, in which case the caller must write the data directly so nothing is lost.
132
+ *
133
+ * the pager binary is taken from BIT_PAGER, then PAGER, defaulting to `less`. an empty or `cat`
134
+ * pager means the user disabled paging via the env — honored unless `force` is set (the `--pager`
135
+ * flag), which falls back to a real pager so the flag is a true override. for `less` we set
136
+ * `LESS=FRX` (unless already set, matching git's default): keep ansi colors (-R), don't clear the
137
+ * screen on exit (-X), and quit if the output fits one screen (-F).
138
+ */
139
+ function writeToPager(data, force = false) {
140
+ return new Promise(resolve => {
141
+ // BIT_PAGER wins over PAGER; default to `less` only when neither is set. use `??` (not `||`)
142
+ // so an explicit empty string is preserved rather than treated as unset — that lets
143
+ // BIT_PAGER="" disable paging.
144
+ const configuredPager = process.env.BIT_PAGER ?? process.env.PAGER ?? 'less';
145
+ const tokens = parsePagerCommand(configuredPager);
146
+ // an empty / "cat" pager means the user disabled paging. honor that, unless `--pager` forces
147
+ // paging on, in which case fall back to a real pager so the flag is a true override.
148
+ const disabled = !tokens[0] || tokens[0] === 'cat';
149
+ if (disabled && !force) {
150
+ resolve(false);
151
+ return;
152
+ }
153
+ const [cmd, ...args] = disabled ? ['less'] : tokens;
154
+ const env = _objectSpread({}, process.env);
155
+ // LESS=FRX only makes sense for `less` itself; don't leak it into other pagers or wrapper scripts.
156
+ if (/^less(\.exe)?$/i.test((0, _path().basename)(cmd)) && !env.LESS) env.LESS = 'FRX';
157
+ try {
158
+ const child = (0, _child_process().spawn)(cmd, args, {
159
+ stdio: ['pipe', 'inherit', 'inherit'],
160
+ env
161
+ });
162
+ // pager missing (ENOENT) or otherwise failed to launch => fall back to a direct write.
163
+ child.on('error', () => resolve(false));
164
+ // resolve success only on a clean exit (code 0) or a signal (code null, e.g. the user killed
165
+ // it). a non-zero exit means the pager failed (bad args, couldn't render) without showing the
166
+ // output, so fall back to a direct write and never lose it.
167
+ child.on('close', code => resolve(code === 0 || code === null));
168
+ // ignore EPIPE that happens when the user quits the pager (e.g. "q") before all data is read.
169
+ child.stdin?.on('error', () => {});
170
+ child.stdin?.write(data);
171
+ child.stdin?.end();
172
+ } catch {
173
+ resolve(false);
174
+ }
175
+ });
176
+ }
177
+
178
+ //# sourceMappingURL=pager.js.map