@gadgetinc/ggt 0.4.10 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -93
- package/lib/__generated__/graphql.js +66 -1
- package/lib/__generated__/graphql.js.map +1 -1
- package/lib/commands/deploy.js +328 -230
- package/lib/commands/deploy.js.map +1 -1
- package/lib/commands/dev.js +445 -0
- package/lib/commands/dev.js.map +1 -0
- package/lib/commands/list.js +27 -19
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/login.js +15 -11
- package/lib/commands/login.js.map +1 -1
- package/lib/commands/logout.js +5 -5
- package/lib/commands/logout.js.map +1 -1
- package/lib/commands/open.js +200 -0
- package/lib/commands/open.js.map +1 -0
- package/lib/commands/pull.js +128 -0
- package/lib/commands/pull.js.map +1 -0
- package/lib/commands/push.js +126 -0
- package/lib/commands/push.js.map +1 -0
- package/lib/commands/root.js +46 -28
- package/lib/commands/root.js.map +1 -1
- package/lib/commands/status.js +61 -0
- package/lib/commands/status.js.map +1 -0
- package/lib/commands/version.js +6 -6
- package/lib/commands/version.js.map +1 -1
- package/lib/commands/whoami.js +6 -6
- package/lib/commands/whoami.js.map +1 -1
- package/lib/ggt.js +33 -8
- package/lib/ggt.js.map +1 -1
- package/lib/main.js +5 -0
- package/lib/main.js.map +1 -0
- package/lib/services/app/api/api.js +191 -0
- package/lib/services/app/api/api.js.map +1 -0
- package/lib/services/app/api/operation.js +12 -0
- package/lib/services/app/api/operation.js.map +1 -0
- package/lib/services/app/app.js +44 -10
- package/lib/services/app/app.js.map +1 -1
- package/lib/services/app/{edit/client.js → client.js} +29 -19
- package/lib/services/app/client.js.map +1 -0
- package/lib/services/app/edit/edit.js +67 -31
- package/lib/services/app/edit/edit.js.map +1 -1
- package/lib/services/app/edit/operation.js +4 -3
- package/lib/services/app/edit/operation.js.map +1 -1
- package/lib/services/app/{edit/error.js → error.js} +6 -6
- package/lib/services/app/error.js.map +1 -0
- package/lib/services/command/arg.js +4 -4
- package/lib/services/command/arg.js.map +1 -1
- package/lib/services/command/command.js +9 -7
- package/lib/services/command/command.js.map +1 -1
- package/lib/services/command/context.js +82 -20
- package/lib/services/command/context.js.map +1 -1
- package/lib/services/config/config.js +4 -7
- package/lib/services/config/config.js.map +1 -1
- package/lib/services/config/env.js +1 -1
- package/lib/services/config/env.js.map +1 -1
- package/lib/services/filesync/changes.js +76 -37
- package/lib/services/filesync/changes.js.map +1 -1
- package/lib/services/filesync/conflicts.js +10 -9
- package/lib/services/filesync/conflicts.js.map +1 -1
- package/lib/services/filesync/directory.js +16 -1
- package/lib/services/filesync/directory.js.map +1 -1
- package/lib/services/filesync/error.js +96 -27
- package/lib/services/filesync/error.js.map +1 -1
- package/lib/services/filesync/filesync.js +448 -490
- package/lib/services/filesync/filesync.js.map +1 -1
- package/lib/services/filesync/hashes.js +8 -5
- package/lib/services/filesync/hashes.js.map +1 -1
- package/lib/services/filesync/strategy.js +59 -0
- package/lib/services/filesync/strategy.js.map +1 -0
- package/lib/services/filesync/sync-json.js +475 -0
- package/lib/services/filesync/sync-json.js.map +1 -0
- package/lib/services/http/auth.js +30 -1
- package/lib/services/http/auth.js.map +1 -1
- package/lib/services/http/http.js +5 -0
- package/lib/services/http/http.js.map +1 -1
- package/lib/services/output/confirm.js +149 -0
- package/lib/services/output/confirm.js.map +1 -0
- package/lib/services/output/footer.js +22 -0
- package/lib/services/output/footer.js.map +1 -0
- package/lib/services/output/log/format/pretty.js +2 -1
- package/lib/services/output/log/format/pretty.js.map +1 -1
- package/lib/services/output/log/logger.js +13 -5
- package/lib/services/output/log/logger.js.map +1 -1
- package/lib/services/output/log/structured.js +2 -2
- package/lib/services/output/log/structured.js.map +1 -1
- package/lib/services/output/output.js +197 -0
- package/lib/services/output/output.js.map +1 -0
- package/lib/services/output/print.js +31 -0
- package/lib/services/output/print.js.map +1 -0
- package/lib/services/output/problems.js +84 -0
- package/lib/services/output/problems.js.map +1 -0
- package/lib/services/output/prompt.js +173 -40
- package/lib/services/output/prompt.js.map +1 -1
- package/lib/services/output/report.js +63 -19
- package/lib/services/output/report.js.map +1 -1
- package/lib/services/output/select.js +198 -0
- package/lib/services/output/select.js.map +1 -0
- package/lib/services/output/spinner.js +141 -0
- package/lib/services/output/spinner.js.map +1 -0
- package/lib/services/output/sprint.js +38 -15
- package/lib/services/output/sprint.js.map +1 -1
- package/lib/services/output/symbols.js +23 -0
- package/lib/services/output/symbols.js.map +1 -0
- package/lib/services/output/table.js +98 -0
- package/lib/services/output/table.js.map +1 -0
- package/lib/services/output/timestamp.js +12 -0
- package/lib/services/output/timestamp.js.map +1 -0
- package/lib/services/output/update.js +29 -9
- package/lib/services/output/update.js.map +1 -1
- package/lib/services/user/session.js +4 -0
- package/lib/services/user/session.js.map +1 -1
- package/lib/services/user/user.js +15 -10
- package/lib/services/user/user.js.map +1 -1
- package/lib/services/util/assert.js +11 -0
- package/lib/services/util/assert.js.map +1 -0
- package/lib/services/util/boolean.js +2 -2
- package/lib/services/util/boolean.js.map +1 -1
- package/lib/services/util/function.js +45 -7
- package/lib/services/util/function.js.map +1 -1
- package/lib/services/util/is.js +23 -2
- package/lib/services/util/is.js.map +1 -1
- package/lib/services/util/json.js +16 -13
- package/lib/services/util/json.js.map +1 -1
- package/lib/services/util/object.js +2 -2
- package/lib/services/util/object.js.map +1 -1
- package/lib/services/util/promise.js +5 -2
- package/lib/services/util/promise.js.map +1 -1
- package/lib/services/util/types.js.map +1 -1
- package/npm-shrinkwrap.json +3415 -2973
- package/package.json +47 -40
- package/bin/dev.cmd +0 -3
- package/bin/dev.js +0 -14
- package/bin/run.cmd +0 -3
- package/bin/run.js +0 -5
- package/lib/commands/sync.js +0 -284
- package/lib/commands/sync.js.map +0 -1
- package/lib/services/app/edit/client.js.map +0 -1
- package/lib/services/app/edit/error.js.map +0 -1
- package/lib/services/output/log/printer.js +0 -120
- package/lib/services/output/log/printer.js.map +0 -1
- package/lib/services/output/stream.js +0 -54
- package/lib/services/output/stream.js.map +0 -1
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import boxen from "boxen";
|
|
2
|
-
import CliTable3 from "cli-table3";
|
|
3
|
-
import { dedent } from "ts-dedent";
|
|
4
|
-
import { config } from "../../config/config.js";
|
|
5
|
-
import { sprint, sprintln, sprintln2, sprintlns } from "../sprint.js";
|
|
6
|
-
import { stdout } from "../stream.js";
|
|
7
|
-
import { formatters } from "./format/format.js";
|
|
8
|
-
import { Level } from "./level.js";
|
|
9
|
-
export const createPrinter = ({ name })=>{
|
|
10
|
-
const createPrint = (sprinter)=>{
|
|
11
|
-
return (template, ...values)=>{
|
|
12
|
-
let msg = sprinter(template, ...values);
|
|
13
|
-
if (config.logLevel < Level.PRINT || config.logFormat === "json") {
|
|
14
|
-
msg = formatters[config.logFormat](Level.PRINT, name, msg, {});
|
|
15
|
-
}
|
|
16
|
-
stdout.write(msg);
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
print: createPrint(sprint),
|
|
21
|
-
println: createPrint(sprintln),
|
|
22
|
-
println2: createPrint(sprintln2),
|
|
23
|
-
printlns: createPrint(sprintlns),
|
|
24
|
-
printTable ({ message, headers, rows, footer, borders: borderType = "none", spaceY = 0, colAligns = [], colWidths = [], boxen: boxenOptions }) {
|
|
25
|
-
if (config.logFormat === "json") {
|
|
26
|
-
stdout.write(formatters.json(Level.PRINT, name, message || boxenOptions?.title || "table", {
|
|
27
|
-
headers,
|
|
28
|
-
rows,
|
|
29
|
-
footer
|
|
30
|
-
}));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const table = new CliTable3({
|
|
34
|
-
chars: borders[borderType],
|
|
35
|
-
colAligns,
|
|
36
|
-
colWidths,
|
|
37
|
-
head: headers,
|
|
38
|
-
style: {
|
|
39
|
-
head: [],
|
|
40
|
-
border: []
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
table.push(...rows);
|
|
44
|
-
const padding = "\n".repeat(spaceY + 1);
|
|
45
|
-
let output = "";
|
|
46
|
-
if (message) {
|
|
47
|
-
output += message + padding;
|
|
48
|
-
}
|
|
49
|
-
if (borderType === "none") {
|
|
50
|
-
// remove the left padding
|
|
51
|
-
output += dedent(table.toString()).slice(1);
|
|
52
|
-
} else {
|
|
53
|
-
output += table.toString();
|
|
54
|
-
}
|
|
55
|
-
if (footer) {
|
|
56
|
-
output += padding + footer;
|
|
57
|
-
}
|
|
58
|
-
if (boxenOptions) {
|
|
59
|
-
output = boxen(output, boxenOptions);
|
|
60
|
-
}
|
|
61
|
-
this.println2(output);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
// prettier-ignore
|
|
66
|
-
const borders = {
|
|
67
|
-
none: {
|
|
68
|
-
"top-left": "",
|
|
69
|
-
top: "",
|
|
70
|
-
"top-mid": "",
|
|
71
|
-
"top-right": "",
|
|
72
|
-
"left-mid": "",
|
|
73
|
-
mid: "",
|
|
74
|
-
"mid-mid": "",
|
|
75
|
-
"right-mid": "",
|
|
76
|
-
left: "",
|
|
77
|
-
middle: "",
|
|
78
|
-
right: "",
|
|
79
|
-
"bottom-left": "",
|
|
80
|
-
bottom: "",
|
|
81
|
-
"bottom-mid": "",
|
|
82
|
-
"bottom-right": ""
|
|
83
|
-
},
|
|
84
|
-
thin: {
|
|
85
|
-
"top-left": "┌",
|
|
86
|
-
top: "─",
|
|
87
|
-
"top-mid": "┬",
|
|
88
|
-
"top-right": "┐",
|
|
89
|
-
"left-mid": "├",
|
|
90
|
-
mid: "─",
|
|
91
|
-
"mid-mid": "┼",
|
|
92
|
-
"right-mid": "┤",
|
|
93
|
-
left: "│",
|
|
94
|
-
middle: "│",
|
|
95
|
-
right: "│",
|
|
96
|
-
"bottom-left": "└",
|
|
97
|
-
bottom: "─",
|
|
98
|
-
"bottom-mid": "┴",
|
|
99
|
-
"bottom-right": "┘"
|
|
100
|
-
},
|
|
101
|
-
thick: {
|
|
102
|
-
"top-left": "╔",
|
|
103
|
-
top: "═",
|
|
104
|
-
"top-mid": "╤",
|
|
105
|
-
"top-right": "╗",
|
|
106
|
-
left: "║",
|
|
107
|
-
middle: "│",
|
|
108
|
-
right: "║",
|
|
109
|
-
"left-mid": "╟",
|
|
110
|
-
mid: "─",
|
|
111
|
-
"mid-mid": "┼",
|
|
112
|
-
"right-mid": "╢",
|
|
113
|
-
"bottom-left": "╚",
|
|
114
|
-
bottom: "═",
|
|
115
|
-
"bottom-mid": "╧",
|
|
116
|
-
"bottom-right": "╝"
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
//# sourceMappingURL=printer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/services/output/log/printer.ts"],"sourcesContent":["import type { Options as BoxenOptions } from \"boxen\";\nimport boxen from \"boxen\";\nimport CliTable3 from \"cli-table3\";\nimport { dedent } from \"ts-dedent\";\nimport { config } from \"../../config/config.js\";\nimport { sprint, sprintln, sprintln2, sprintlns, type Sprint } from \"../sprint.js\";\nimport { stdout } from \"../stream.js\";\nimport { formatters } from \"./format/format.js\";\nimport { Level } from \"./level.js\";\n\ntype Print = (template: TemplateStringsArray | string, ...values: unknown[]) => void;\n\nexport type Printer = {\n /**\n * Prints a message to stdout.\n *\n * @example\n * logger.print(\"Hello, world!\");\n * // Hello, world!\n */\n print: Print;\n\n /**\n * Prints a message to stdout followed by a newline.\n *\n * @example\n * logger.println(\"Hello, world!\");\n * // Hello, world!\\n\n */\n println: Print;\n\n /**\n * Prints a message to stdout followed by two newlines.\n *\n * @example\n * logger.println2(\"Hello, world!\");\n * // Hello, world!\\n\n * // \\n\n */\n println2: Print;\n\n /**\n * Prints a message to stdout surrounded by newlines.\n *\n * @example\n * logger.printlns(\"Hello, world!\");\n * // \\n\n * // Hello, world!\\n\n */\n printlns: Print;\n\n /**\n * Prints a table to stdout.\n */\n printTable: (options: PrintTableOptions) => void;\n};\n\nexport type PrintTableOptions = {\n /**\n * The message to print above the table.\n */\n message?: string;\n\n /**\n * The headers of the table.\n */\n headers?: string[];\n\n /**\n * The rows of the table.\n */\n rows: string[][];\n\n /**\n * The message to print below the table.\n */\n footer?: string;\n\n /**\n * The type of borders to use.\n *\n * @default \"none\"\n */\n borders?: \"none\" | \"thin\" | \"thick\";\n\n /**\n * The amount of empty lines to print between the message, table,\n * and footer.\n *\n * @default 0\n */\n spaceY?: number;\n\n /**\n * The alignment of the content in each column.\n *\n * @default [] (left-aligned)\n */\n colAligns?: (\"left\" | \"center\" | \"right\")[];\n\n /**\n * The width of each column.\n *\n * @default [] (auto-sized)\n */\n colWidths?: number[];\n\n /**\n * The options to pass to `boxen`.\n *\n * @default undefined (no box)\n */\n boxen?: BoxenOptions;\n};\n\nexport const createPrinter = ({ name }: { name: string }): Printer => {\n const createPrint = (sprinter: Sprint): Print => {\n return (template, ...values) => {\n let msg = sprinter(template, ...values);\n if (config.logLevel < Level.PRINT || config.logFormat === \"json\") {\n msg = formatters[config.logFormat](Level.PRINT, name, msg, {});\n }\n stdout.write(msg);\n };\n };\n\n return {\n print: createPrint(sprint),\n println: createPrint(sprintln),\n println2: createPrint(sprintln2),\n printlns: createPrint(sprintlns),\n printTable({\n message,\n headers,\n rows,\n footer,\n borders: borderType = \"none\",\n spaceY = 0,\n colAligns = [],\n colWidths = [],\n boxen: boxenOptions,\n }) {\n if (config.logFormat === \"json\") {\n stdout.write(formatters.json(Level.PRINT, name, message || boxenOptions?.title || \"table\", { headers, rows, footer }));\n return;\n }\n\n const table = new CliTable3({\n chars: borders[borderType],\n colAligns,\n colWidths,\n head: headers,\n style: { head: [], border: [] },\n });\n\n table.push(...rows);\n\n const padding = \"\\n\".repeat(spaceY + 1);\n\n let output = \"\";\n if (message) {\n output += message + padding;\n }\n\n if (borderType === \"none\") {\n // remove the left padding\n output += dedent(table.toString()).slice(1);\n } else {\n output += table.toString();\n }\n\n if (footer) {\n output += padding + footer;\n }\n\n if (boxenOptions) {\n output = boxen(output, boxenOptions);\n }\n\n this.println2(output);\n },\n };\n};\n\n// prettier-ignore\nconst borders = {\n none: {\n \"top-left\": \"\", top: \"\", \"top-mid\": \"\", \"top-right\": \"\",\n \"left-mid\": \"\", mid: \"\", \"mid-mid\": \"\", \"right-mid\": \"\",\n left: \"\", middle: \"\", right: \"\",\n \"bottom-left\": \"\", bottom: \"\", \"bottom-mid\": \"\", \"bottom-right\": \"\",\n },\n thin: {\n \"top-left\": \"┌\", top: \"─\", \"top-mid\": \"┬\", \"top-right\": \"┐\",\n \"left-mid\": \"├\", mid: \"─\", \"mid-mid\": \"┼\", \"right-mid\": \"┤\",\n left: \"│\", middle: \"│\", right: \"│\",\n \"bottom-left\": \"└\", bottom: \"─\", \"bottom-mid\": \"┴\", \"bottom-right\": \"┘\",\n },\n thick: {\n \"top-left\": \"╔\", top: \"═\", \"top-mid\": \"╤\", \"top-right\": \"╗\",\n left: \"║\", middle: \"│\", right: \"║\",\n \"left-mid\": \"╟\", mid: \"─\", \"mid-mid\": \"┼\", \"right-mid\": \"╢\",\n \"bottom-left\": \"╚\", bottom: \"═\", \"bottom-mid\": \"╧\", \"bottom-right\": \"╝\",\n },\n};\n"],"names":["boxen","CliTable3","dedent","config","sprint","sprintln","sprintln2","sprintlns","stdout","formatters","Level","createPrinter","name","createPrint","sprinter","template","values","msg","logLevel","PRINT","logFormat","write","print","println","println2","printlns","printTable","message","headers","rows","footer","borders","borderType","spaceY","colAligns","colWidths","boxenOptions","json","title","table","chars","head","style","border","push","padding","repeat","output","toString","slice","none","top","mid","left","middle","right","bottom","thin","thick"],"mappings":"AACA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,eAAe,aAAa;AACnC,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,SAAS,QAAqB,eAAe;AACnF,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,KAA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AMS,QAAQ,IAAIC,KAAK,CAAC;YAC3C,OAAO;gBACLF,UAAUR,MAAMS,QAAQ;YAC1B;YAEA,IAAIlB,QAAQ;gBACViB,UAAUF,UAAUf;YACtB;YAEA,IAAIM,cAAc;gBAChBW,SAAS/C,MAAM+C,QAAQX;YACzB;YAEA,IAAI,CAACZ,QAAQ,CAACuB;QAChB;IACF;AACF,EAAE;AAEF,kBAAkB;AAClB,MAAMhB,UAAU;IACdmB,MAAM;QACD,YAAY;QAAOC,KAAK;QAAO,WAAW;QAAO,aAAa;QAC9D,YAAY;QAAOC,KAAK;QAAO,WAAW;QAAO,aAAa;QACxDC,MAAM;QAAsBC,QAAQ;QAAaC,OAAO;QACjE,eAAe;QAAIC,QAAQ;QAAI,cAAc;QAAI,gBAAgB;IACnE;IACAC,MAAM;QACD,YAAY;QAAQN,KAAK;QAAQ,WAAW;QAAQ,aAAa;QACjE,YAAY;QAAQC,KAAK;QAAQ,WAAW;QAAQ,aAAa;QAC3DC,MAAM;QAAwBC,QAAQ;QAAcC,OAAO;QACpE,eAAe;QAAKC,QAAQ;QAAK,cAAc;QAAK,gBAAgB;IACtE;IACAE,OAAO;QACF,YAAY;QAAQP,KAAK;QAAQ,WAAW;QAAQ,aAAa;QAC3DE,MAAM;QAAwBC,QAAQ;QAAcC,OAAO;QACjE,YAAY;QAAQH,KAAK;QAAQ,WAAW;QAAQ,aAAa;QACpE,eAAe;QAAKI,QAAQ;QAAK,cAAc;QAAK,gBAAgB;IACtE;AACF"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { env } from "../config/env.js";
|
|
4
|
-
import { isObject } from "../util/is.js";
|
|
5
|
-
/**
|
|
6
|
-
* A wrapper around process.stdout and process.stderr that allows us to mock out the streams for testing.
|
|
7
|
-
*
|
|
8
|
-
* @see https://github.com/oclif/core/blob/16139fe8a7f991b4b446a1599ab63f15d9809b8e/src/cli-ux/stream.ts
|
|
9
|
-
*/ export class Stream {
|
|
10
|
-
get isTTY() {
|
|
11
|
-
return process[this.channel].isTTY;
|
|
12
|
-
}
|
|
13
|
-
getWindowSize() {
|
|
14
|
-
return process[this.channel].getWindowSize();
|
|
15
|
-
}
|
|
16
|
-
write(data) {
|
|
17
|
-
if (env.testLike) {
|
|
18
|
-
// use console.log/error in tests since vitest doesn't display
|
|
19
|
-
// process.stdout/stderr correctly; also, remove trailing newline
|
|
20
|
-
// since console.log/error adds one.
|
|
21
|
-
data = data.replace(/\n$/, "");
|
|
22
|
-
if (this.channel === "stdout") {
|
|
23
|
-
console.log(data);
|
|
24
|
-
} else {
|
|
25
|
-
console.error(data);
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
} else {
|
|
29
|
-
return process[this.channel].write(data);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
on(event, listener) {
|
|
33
|
-
process[this.channel].on(event, listener);
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
once(event, listener) {
|
|
37
|
-
process[this.channel].once(event, listener);
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
constructor(channel){
|
|
41
|
-
_define_property(this, "channel", void 0);
|
|
42
|
-
this.channel = channel;
|
|
43
|
-
process[this.channel].on("error", (err)=>{
|
|
44
|
-
if (isObject(err) && "code" in err && err.code === "EPIPE") {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
throw err;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export const stdout = new Stream("stdout");
|
|
52
|
-
export const stderr = new Stream("stderr");
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=stream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/output/stream.ts"],"sourcesContent":["import process from \"node:process\";\nimport { env } from \"../config/env.js\";\nimport { isObject } from \"../util/is.js\";\n\n/**\n * A wrapper around process.stdout and process.stderr that allows us to mock out the streams for testing.\n *\n * @see https://github.com/oclif/core/blob/16139fe8a7f991b4b446a1599ab63f15d9809b8e/src/cli-ux/stream.ts\n */\nexport class Stream {\n public constructor(public channel: \"stdout\" | \"stderr\") {\n process[this.channel].on(\"error\", (err: unknown) => {\n if (isObject(err) && \"code\" in err && err.code === \"EPIPE\") {\n return;\n }\n throw err;\n });\n }\n\n public get isTTY(): boolean {\n return process[this.channel].isTTY;\n }\n\n public getWindowSize(): number[] {\n return process[this.channel].getWindowSize();\n }\n\n public write(data: string): boolean {\n if (env.testLike) {\n // use console.log/error in tests since vitest doesn't display\n // process.stdout/stderr correctly; also, remove trailing newline\n // since console.log/error adds one.\n data = data.replace(/\\n$/, \"\");\n if (this.channel === \"stdout\") {\n console.log(data);\n } else {\n console.error(data);\n }\n return true;\n } else {\n return process[this.channel].write(data);\n }\n }\n\n public on(event: string, listener: (...args: unknown[]) => void): this {\n process[this.channel].on(event, listener);\n return this;\n }\n\n public once(event: string, listener: (...args: unknown[]) => void): this {\n process[this.channel].once(event, listener);\n return this;\n }\n}\n\nexport const stdout = new Stream(\"stdout\");\nexport const stderr = new Stream(\"stderr\");\n"],"names":["process","env","isObject","Stream","isTTY","channel","getWindowSize","write","data","testLike","replace","console","log","error","on","event","listener","once","err","code","stdout","stderr"],"mappings":";AAAA,OAAOA,aAAa,eAAe;AACnC,SAASC,GAAG,QAAQ,mBAAmB;AACvC,SAASC,QAAQ,QAAQ,gBAAgB;AAEzC;;;;CAIC,GACD,OAAO,MAAMC;IAUX,IAAWC,QAAiB;QAC1B,OAAOJ,OAAO,CAAC,IAAI,CAACK,OAAO,CAAC,CAACD,KAAK;IACpC;IAEOE,gBAA0B;QAC/B,OAAON,OAAO,CAAC,IAAI,CAACK,OAAO,CAAC,CAACC,aAAa;IAC5C;IAEOC,MAAMC,IAAY,EAAW;QAClC,IAAIP,IAAIQ,QAAQ,EAAE;YAChB,8DAA8D;YAC9D,iEAAiE;YACjE,oCAAoC;YAC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