@webiny/cli-core 6.6.0-alpha.0 → 6.6.0-alpha.2
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/features/UpgradeCommand/UpgradeCommandHandler.js +4 -1
- package/features/UpgradeCommand/UpgradeCommandHandler.js.map +1 -1
- package/package.json +16 -13
- package/services/UiService/UiService.d.ts +18 -0
- package/services/UiService/UiService.js +18 -2
- package/services/UiService/UiService.js.map +1 -1
|
@@ -8,7 +8,7 @@ class UpgradeCommandHandlerImpl {
|
|
|
8
8
|
this.ui = ui;
|
|
9
9
|
}
|
|
10
10
|
async handle(params) {
|
|
11
|
-
const { version, skipChecks, debug, logLevel, showLogs, showStackTrace, installVersion, force } = params;
|
|
11
|
+
const { version, skipChecks, debug, logLevel, showLogs, showStackTrace, installVersion, force, registry, packageManager, skipDependencyGuard } = params;
|
|
12
12
|
if (!skipChecks) {
|
|
13
13
|
let gitStatus = "";
|
|
14
14
|
try {
|
|
@@ -36,6 +36,9 @@ class UpgradeCommandHandlerImpl {
|
|
|
36
36
|
logLevel ? `--logLevel=${logLevel}` : "--logLevel=debug",
|
|
37
37
|
installVersion ? `--installVersion=${installVersion}` : "",
|
|
38
38
|
force ? "--force" : "",
|
|
39
|
+
registry ? `--registry=${registry}` : "",
|
|
40
|
+
packageManager ? `--packageManager=${packageManager}` : "",
|
|
41
|
+
skipDependencyGuard ? "--skipDependencyGuard" : "",
|
|
39
42
|
"--json"
|
|
40
43
|
].filter(Boolean);
|
|
41
44
|
const npx = execa("npx", command, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/UpgradeCommand/UpgradeCommandHandler.js","sources":["../../../src/features/UpgradeCommand/UpgradeCommandHandler.ts"],"sourcesContent":["import { UpgradeCommandHandler as UpgradeCommandHandlerAbstraction } from \"./abstraction.js\";\nimport chalk from \"chalk\";\nimport { execa, execaSync } from \"execa\";\nimport { UiService } from \"~/abstractions/index.js\";\n\nconst GITHUB_REPOSITORY_URL = \"https://github.com/webiny/webiny-upgrades-v6\";\n\ntype LogType = \"debug\" | \"success\" | \"warning\" | \"warn\" | \"error\" | \"fatal\" | \"done\" | \"info\";\n\ninterface IUpgradeLine {\n type: LogType;\n message: string;\n data?: {\n stack?: string;\n [key: string]: any;\n };\n}\n\nexport class UpgradeCommandHandlerImpl implements UpgradeCommandHandlerAbstraction.Interface {\n public constructor(private ui: UiService.Interface) {}\n\n public async handle(params: UpgradeCommandHandlerAbstraction.Params): Promise<void> {\n const {\n version,\n skipChecks,\n debug,\n logLevel,\n showLogs,\n showStackTrace,\n installVersion,\n force\n } = params;\n\n if (!skipChecks) {\n /**\n * Before doing any upgrading, there must not be any active changes in the current branch.\n */\n let gitStatus = \"\";\n try {\n const { stdout } = execaSync(\"git\", [\"status\", \"--porcelain\"]);\n gitStatus = stdout.trim();\n } catch {}\n\n if (gitStatus) {\n this.ui.error(\n chalk.red(\"This git repository has untracked files or uncommitted changes:\") +\n \"\\n\\n\" +\n gitStatus\n .split(\"\\n\")\n .map(line => {\n const matched = line.match(/ .*/g);\n if (!matched || !matched[0]) {\n return \"\";\n }\n return matched[0].trim();\n })\n .join(\"\\n\") +\n \"\\n\\n\" +\n chalk.red(\n \"Remove untracked files, stash or commit any changes, and try again.\"\n )\n );\n process.exit(1);\n }\n }\n\n const command = [\n GITHUB_REPOSITORY_URL,\n version || undefined,\n debug ? \"--debug\" : \"\",\n showLogs ? `--showLogs=${showLogs}` : \"\",\n showStackTrace ? `--showStackTrace=${showStackTrace}` : \"\",\n logLevel ? `--logLevel=${logLevel}` : \"--logLevel=debug\",\n installVersion ? `--installVersion=${installVersion}` : \"\",\n force ? \"--force\" : \"\",\n \"--json\"\n ].filter(Boolean);\n\n const npx = execa(\"npx\", command, {\n env: {\n FORCE_COLOR: \"1\"\n },\n stdin: process.stdin\n });\n\n npx.stdout!.on(\"data\", data => {\n const lines = data.toString().replace(/\\n$/, \"\").split(\"\\n\") as string[];\n for (const line of lines) {\n if (!line || !line.trim()) {\n continue;\n }\n this.output(line);\n }\n });\n\n npx.stderr!.on(\"data\", data => {\n this.ui.error(data.toString());\n });\n\n try {\n await npx;\n } catch (ex) {\n this.ui.error(`Upgrade process failed: ${ex.message}`);\n }\n }\n\n private output(line: string): void {\n try {\n const json = JSON.parse(line) as IUpgradeLine;\n switch (json.type) {\n case \"debug\":\n this.ui.debug(json.message);\n if (!json.data?.stack) {\n return;\n }\n this.ui.debug(json.data?.stack);\n return;\n case \"info\":\n this.ui.info(json.message);\n return;\n case \"success\":\n case \"done\":\n this.ui.success(json.message);\n return;\n case \"warning\":\n case \"warn\":\n this.ui.warning(json.message);\n return;\n case \"error\":\n case \"fatal\":\n this.ui.error(json.message);\n if (!json.data?.stack) {\n return;\n }\n this.ui.debug(json.data?.stack);\n return;\n default:\n console.log(json);\n }\n } catch {\n console.log(line);\n }\n }\n}\n\nexport const UpgradeCommandHandler = UpgradeCommandHandlerAbstraction.createImplementation({\n implementation: UpgradeCommandHandlerImpl,\n dependencies: [UiService]\n});\n"],"names":["GITHUB_REPOSITORY_URL","UpgradeCommandHandlerImpl","ui","params","version","skipChecks","debug","logLevel","showLogs","showStackTrace","installVersion","force","gitStatus","stdout","execaSync","chalk","line","matched","process","command","undefined","Boolean","npx","execa","data","lines","ex","json","JSON","console","UpgradeCommandHandler","UpgradeCommandHandlerAbstraction","UiService"],"mappings":";;;;AAKA,MAAMA,wBAAwB;AAavB,MAAMC;IACT,YAA2BC,EAAuB,CAAE;aAAzBA,EAAE,GAAFA;IAA0B;IAErD,MAAa,OAAOC,MAA+C,EAAiB;QAChF,MAAM,EACFC,OAAO,EACPC,UAAU,EACVC,KAAK,EACLC,QAAQ,EACRC,QAAQ,EACRC,cAAc,EACdC,cAAc,EACdC,KAAK,
|
|
1
|
+
{"version":3,"file":"features/UpgradeCommand/UpgradeCommandHandler.js","sources":["../../../src/features/UpgradeCommand/UpgradeCommandHandler.ts"],"sourcesContent":["import { UpgradeCommandHandler as UpgradeCommandHandlerAbstraction } from \"./abstraction.js\";\nimport chalk from \"chalk\";\nimport { execa, execaSync } from \"execa\";\nimport { UiService } from \"~/abstractions/index.js\";\n\nconst GITHUB_REPOSITORY_URL = \"https://github.com/webiny/webiny-upgrades-v6\";\n\ntype LogType = \"debug\" | \"success\" | \"warning\" | \"warn\" | \"error\" | \"fatal\" | \"done\" | \"info\";\n\ninterface IUpgradeLine {\n type: LogType;\n message: string;\n data?: {\n stack?: string;\n [key: string]: any;\n };\n}\n\nexport class UpgradeCommandHandlerImpl implements UpgradeCommandHandlerAbstraction.Interface {\n public constructor(private ui: UiService.Interface) {}\n\n public async handle(params: UpgradeCommandHandlerAbstraction.Params): Promise<void> {\n const {\n version,\n skipChecks,\n debug,\n logLevel,\n showLogs,\n showStackTrace,\n installVersion,\n force,\n registry,\n packageManager,\n skipDependencyGuard\n } = params;\n\n if (!skipChecks) {\n /**\n * Before doing any upgrading, there must not be any active changes in the current branch.\n */\n let gitStatus = \"\";\n try {\n const { stdout } = execaSync(\"git\", [\"status\", \"--porcelain\"]);\n gitStatus = stdout.trim();\n } catch {}\n\n if (gitStatus) {\n this.ui.error(\n chalk.red(\"This git repository has untracked files or uncommitted changes:\") +\n \"\\n\\n\" +\n gitStatus\n .split(\"\\n\")\n .map(line => {\n const matched = line.match(/ .*/g);\n if (!matched || !matched[0]) {\n return \"\";\n }\n return matched[0].trim();\n })\n .join(\"\\n\") +\n \"\\n\\n\" +\n chalk.red(\n \"Remove untracked files, stash or commit any changes, and try again.\"\n )\n );\n process.exit(1);\n }\n }\n\n const command = [\n GITHUB_REPOSITORY_URL,\n version || undefined,\n debug ? \"--debug\" : \"\",\n showLogs ? `--showLogs=${showLogs}` : \"\",\n showStackTrace ? `--showStackTrace=${showStackTrace}` : \"\",\n logLevel ? `--logLevel=${logLevel}` : \"--logLevel=debug\",\n installVersion ? `--installVersion=${installVersion}` : \"\",\n force ? \"--force\" : \"\",\n registry ? `--registry=${registry}` : \"\",\n packageManager ? `--packageManager=${packageManager}` : \"\",\n skipDependencyGuard ? \"--skipDependencyGuard\" : \"\",\n \"--json\"\n ].filter(Boolean);\n\n const npx = execa(\"npx\", command, {\n env: {\n FORCE_COLOR: \"1\"\n },\n stdin: process.stdin\n });\n\n npx.stdout!.on(\"data\", data => {\n const lines = data.toString().replace(/\\n$/, \"\").split(\"\\n\") as string[];\n for (const line of lines) {\n if (!line || !line.trim()) {\n continue;\n }\n this.output(line);\n }\n });\n\n npx.stderr!.on(\"data\", data => {\n this.ui.error(data.toString());\n });\n\n try {\n await npx;\n } catch (ex) {\n this.ui.error(`Upgrade process failed: ${ex.message}`);\n }\n }\n\n private output(line: string): void {\n try {\n const json = JSON.parse(line) as IUpgradeLine;\n switch (json.type) {\n case \"debug\":\n this.ui.debug(json.message);\n if (!json.data?.stack) {\n return;\n }\n this.ui.debug(json.data?.stack);\n return;\n case \"info\":\n this.ui.info(json.message);\n return;\n case \"success\":\n case \"done\":\n this.ui.success(json.message);\n return;\n case \"warning\":\n case \"warn\":\n this.ui.warning(json.message);\n return;\n case \"error\":\n case \"fatal\":\n this.ui.error(json.message);\n if (!json.data?.stack) {\n return;\n }\n this.ui.debug(json.data?.stack);\n return;\n default:\n console.log(json);\n }\n } catch {\n console.log(line);\n }\n }\n}\n\nexport const UpgradeCommandHandler = UpgradeCommandHandlerAbstraction.createImplementation({\n implementation: UpgradeCommandHandlerImpl,\n dependencies: [UiService]\n});\n"],"names":["GITHUB_REPOSITORY_URL","UpgradeCommandHandlerImpl","ui","params","version","skipChecks","debug","logLevel","showLogs","showStackTrace","installVersion","force","registry","packageManager","skipDependencyGuard","gitStatus","stdout","execaSync","chalk","line","matched","process","command","undefined","Boolean","npx","execa","data","lines","ex","json","JSON","console","UpgradeCommandHandler","UpgradeCommandHandlerAbstraction","UiService"],"mappings":";;;;AAKA,MAAMA,wBAAwB;AAavB,MAAMC;IACT,YAA2BC,EAAuB,CAAE;aAAzBA,EAAE,GAAFA;IAA0B;IAErD,MAAa,OAAOC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zB;gBACJ;oBACIE,QAAQ,GAAG,CAACF;YACpB;QACJ,EAAE,OAAM;YACJE,QAAQ,GAAG,CAACb;QAChB;IACJ;AACJ;AAEO,MAAMc,8CAAwBC,sBAAAA,oBAAqD,CAAC;IACvF,gBAAgBjC;IAChB,cAAc;QAACkC;KAAU;AAC7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/cli-core",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -13,34 +13,37 @@
|
|
|
13
13
|
"description": "A command line interface (CLI) for managing Webiny projects.",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/di": "1.0
|
|
17
|
-
"@webiny/feature": "6.6.0-alpha.
|
|
18
|
-
"@webiny/project": "6.6.0-alpha.
|
|
19
|
-
"@webiny/stdlib": "0.0.
|
|
20
|
-
"@webiny/telemetry": "6.6.0-alpha.
|
|
16
|
+
"@webiny/di": "1.1.0",
|
|
17
|
+
"@webiny/feature": "6.6.0-alpha.2",
|
|
18
|
+
"@webiny/project": "6.6.0-alpha.2",
|
|
19
|
+
"@webiny/stdlib": "0.0.17",
|
|
20
|
+
"@webiny/telemetry": "6.6.0-alpha.2",
|
|
21
21
|
"chalk": "6.0.0",
|
|
22
22
|
"ci-info": "4.4.0",
|
|
23
|
-
"execa": "10.0.
|
|
23
|
+
"execa": "10.0.1",
|
|
24
24
|
"fast-glob": "3.3.3",
|
|
25
25
|
"find-up": "8.0.0",
|
|
26
|
-
"humanize-duration": "3.34.
|
|
27
|
-
"inquirer": "14.0
|
|
26
|
+
"humanize-duration": "3.34.1",
|
|
27
|
+
"inquirer": "14.1.0",
|
|
28
28
|
"load-json-file": "7.0.1",
|
|
29
|
-
"open": "11.0.
|
|
29
|
+
"open": "11.0.1",
|
|
30
30
|
"ora": "9.4.1",
|
|
31
31
|
"pino": "10.3.1",
|
|
32
32
|
"pino-pretty": "13.1.3",
|
|
33
33
|
"semver": "7.8.5",
|
|
34
34
|
"type-fest": "5.8.0",
|
|
35
|
+
"wrap-ansi": "9.0.2",
|
|
35
36
|
"write-json-file": "7.0.0",
|
|
36
37
|
"yargs": "18.1.0",
|
|
37
38
|
"zod": "4.4.3"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/lodash": "4.17.
|
|
41
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
41
|
+
"@types/lodash": "4.17.25",
|
|
42
|
+
"@webiny/build-tools": "6.6.0-alpha.2",
|
|
42
43
|
"rimraf": "6.1.3",
|
|
43
|
-
"
|
|
44
|
+
"strip-ansi": "7.2.0",
|
|
45
|
+
"typescript": "7.0.2",
|
|
46
|
+
"vitest": "4.1.11"
|
|
44
47
|
},
|
|
45
48
|
"publishConfig": {
|
|
46
49
|
"access": "public"
|
|
@@ -13,5 +13,23 @@ export declare class DefaultUiService implements UiService.Interface {
|
|
|
13
13
|
error(text: string, ...args: any[]): void;
|
|
14
14
|
debug(text: string, ...args: any[]): void;
|
|
15
15
|
private typedColorizedText;
|
|
16
|
+
/**
|
|
17
|
+
* Prefixes every line of `message` with the gutter, wrapping the text to the terminal width
|
|
18
|
+
* first.
|
|
19
|
+
*
|
|
20
|
+
* The wrap has to happen here rather than being left to the terminal. Writing the whole message
|
|
21
|
+
* as one long line means the terminal wraps it at column 0, with no knowledge of the gutter -
|
|
22
|
+
* so continuation lines start underneath the pipe instead of underneath the text, and a wrapped
|
|
23
|
+
* sentence reads as though it belongs to a different paragraph.
|
|
24
|
+
*/
|
|
25
|
+
private applyGutter;
|
|
26
|
+
/**
|
|
27
|
+
* Width available for the text itself, or `null` when there is nothing to wrap to.
|
|
28
|
+
*
|
|
29
|
+
* `columns` is undefined whenever stdout is not a TTY - piped to a file, or read by another
|
|
30
|
+
* process. Wrapping to a guessed width there would bake line breaks into output that something
|
|
31
|
+
* else is going to reflow anyway, so the message is left as a single line.
|
|
32
|
+
*/
|
|
33
|
+
private getTextWidth;
|
|
16
34
|
}
|
|
17
35
|
export declare const uiService: import("@webiny/di").Implementation<typeof DefaultUiService>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createImplementation } from "@webiny/di";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import util from "util";
|
|
4
|
+
import wrap_ansi from "wrap-ansi";
|
|
4
5
|
import { IsCi, StdioService, UiService } from "../../abstractions/index.js";
|
|
5
6
|
const NEW_LINE = "\n";
|
|
6
7
|
const PIPE_SYMBOL = "┃";
|
|
8
|
+
const GUTTER_WIDTH = 2;
|
|
9
|
+
const MIN_TEXT_WIDTH = 20;
|
|
7
10
|
const LOG_COLORS = {
|
|
8
11
|
info: chalk.blueBright,
|
|
9
12
|
error: chalk.red,
|
|
@@ -49,9 +52,22 @@ class DefaultUiService {
|
|
|
49
52
|
const prefix = `${type}: `;
|
|
50
53
|
return this.text(prefix + util.format(text, ...args));
|
|
51
54
|
}
|
|
52
|
-
const
|
|
55
|
+
const gutter = `${LOG_COLORS[type](PIPE_SYMBOL)} `;
|
|
53
56
|
const textWithColorizedPlaceholders = text.replace(/%[a-zA-Z]/g, (match)=>LOG_COLORS[type](match));
|
|
54
|
-
|
|
57
|
+
const message = util.format(textWithColorizedPlaceholders, ...args);
|
|
58
|
+
return this.text(this.applyGutter(message, gutter));
|
|
59
|
+
}
|
|
60
|
+
applyGutter(message, gutter) {
|
|
61
|
+
const textWidth = this.getTextWidth();
|
|
62
|
+
const wrapped = textWidth ? wrap_ansi(message, textWidth, {
|
|
63
|
+
hard: true
|
|
64
|
+
}) : message;
|
|
65
|
+
return wrapped.split(NEW_LINE).map((line)=>gutter + line).join(NEW_LINE);
|
|
66
|
+
}
|
|
67
|
+
getTextWidth() {
|
|
68
|
+
const columns = this.stdio.getStdout().columns;
|
|
69
|
+
if (!columns) return null;
|
|
70
|
+
return Math.max(columns - GUTTER_WIDTH, MIN_TEXT_WIDTH);
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
const uiService = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services/UiService/UiService.js","sources":["../../../src/services/UiService/UiService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport chalk from \"chalk\";\nimport util from \"util\";\nimport { UiService, StdioService, IsCi } from \"~/abstractions/index.js\";\n\nconst NEW_LINE = \"\\n\";\nconst PIPE_SYMBOL = \"┃\";\n\nconst LOG_COLORS = {\n info: chalk.blueBright,\n error: chalk.red,\n warning: chalk.yellow,\n success: chalk.green,\n debug: chalk.gray\n} as const;\n\nexport class DefaultUiService implements UiService.Interface {\n constructor(\n private readonly stdio: StdioService.Interface,\n private readonly isCi: IsCi.Interface\n ) {}\n\n raw(text: string) {\n this.stdio.getStdout().write(text);\n }\n\n text(text: string) {\n this.stdio.getStdout().write(text);\n this.stdio.getStdout().write(NEW_LINE);\n }\n\n textBold(text: string) {\n this.text(chalk.bold(text));\n }\n\n emptyLine() {\n this.stdio.getStdout().write(chalk.gray(\"∙\") + NEW_LINE);\n }\n\n // The following methods are used to print texts with a specific type prefix.\n success(text: string, ...args: any[]) {\n this.typedColorizedText(\"success\", text, ...args);\n }\n\n info(text: string, ...args: any[]) {\n this.typedColorizedText(\"info\", text, ...args);\n }\n\n warning(text: string, ...args: any[]) {\n this.typedColorizedText(\"warning\", text, ...args);\n }\n\n error(text: string, ...args: any[]) {\n this.typedColorizedText(\"error\", text, ...args);\n }\n\n debug(text: string, ...args: any[]) {\n this.typedColorizedText(\"debug\", text, ...args);\n }\n\n private typedColorizedText(type: keyof typeof LOG_COLORS, text: string, ...args: any[]) {\n // Use plain text format in CI environments.\n if (this.isCi.execute()) {\n const prefix = `${type}: `;\n return this.text(prefix + util.format(text, ...args));\n }\n\n const
|
|
1
|
+
{"version":3,"file":"services/UiService/UiService.js","sources":["../../../src/services/UiService/UiService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport chalk from \"chalk\";\nimport util from \"util\";\nimport wrapAnsi from \"wrap-ansi\";\nimport { UiService, StdioService, IsCi } from \"~/abstractions/index.js\";\n\nconst NEW_LINE = \"\\n\";\nconst PIPE_SYMBOL = \"┃\";\n\n// Visible width of the `┃ ` gutter that prefixes every line of a typed message. Hardcoded rather\n// than measured because the pipe is a single-column glyph and the colour codes around it occupy no\n// columns at all.\nconst GUTTER_WIDTH = 2;\n\n// A floor for very narrow terminals, so the wrap width can never go to zero or negative.\nconst MIN_TEXT_WIDTH = 20;\n\nconst LOG_COLORS = {\n info: chalk.blueBright,\n error: chalk.red,\n warning: chalk.yellow,\n success: chalk.green,\n debug: chalk.gray\n} as const;\n\nexport class DefaultUiService implements UiService.Interface {\n constructor(\n private readonly stdio: StdioService.Interface,\n private readonly isCi: IsCi.Interface\n ) {}\n\n raw(text: string) {\n this.stdio.getStdout().write(text);\n }\n\n text(text: string) {\n this.stdio.getStdout().write(text);\n this.stdio.getStdout().write(NEW_LINE);\n }\n\n textBold(text: string) {\n this.text(chalk.bold(text));\n }\n\n emptyLine() {\n this.stdio.getStdout().write(chalk.gray(\"∙\") + NEW_LINE);\n }\n\n // The following methods are used to print texts with a specific type prefix.\n success(text: string, ...args: any[]) {\n this.typedColorizedText(\"success\", text, ...args);\n }\n\n info(text: string, ...args: any[]) {\n this.typedColorizedText(\"info\", text, ...args);\n }\n\n warning(text: string, ...args: any[]) {\n this.typedColorizedText(\"warning\", text, ...args);\n }\n\n error(text: string, ...args: any[]) {\n this.typedColorizedText(\"error\", text, ...args);\n }\n\n debug(text: string, ...args: any[]) {\n this.typedColorizedText(\"debug\", text, ...args);\n }\n\n private typedColorizedText(type: keyof typeof LOG_COLORS, text: string, ...args: any[]) {\n // Use plain text format in CI environments.\n if (this.isCi.execute()) {\n const prefix = `${type}: `;\n return this.text(prefix + util.format(text, ...args));\n }\n\n const gutter = `${LOG_COLORS[type](PIPE_SYMBOL)} `;\n\n // Replace all placeholders (match with `/%[a-zA-Z]/g` regex) with colorized values.\n const textWithColorizedPlaceholders = text.replace(/%[a-zA-Z]/g, match => {\n return LOG_COLORS[type](match);\n });\n\n const message = util.format(textWithColorizedPlaceholders, ...args);\n\n return this.text(this.applyGutter(message, gutter));\n }\n\n /**\n * Prefixes every line of `message` with the gutter, wrapping the text to the terminal width\n * first.\n *\n * The wrap has to happen here rather than being left to the terminal. Writing the whole message\n * as one long line means the terminal wraps it at column 0, with no knowledge of the gutter -\n * so continuation lines start underneath the pipe instead of underneath the text, and a wrapped\n * sentence reads as though it belongs to a different paragraph.\n */\n private applyGutter(message: string, gutter: string) {\n const textWidth = this.getTextWidth();\n\n // `hard` also breaks words longer than a whole line - a long file path, or a URL. Letting\n // those overflow would hand them straight back to the terminal's own wrapping, which is\n // the column-0 behaviour this method exists to avoid.\n const wrapped = textWidth ? wrapAnsi(message, textWidth, { hard: true }) : message;\n\n return wrapped\n .split(NEW_LINE)\n .map(line => gutter + line)\n .join(NEW_LINE);\n }\n\n /**\n * Width available for the text itself, or `null` when there is nothing to wrap to.\n *\n * `columns` is undefined whenever stdout is not a TTY - piped to a file, or read by another\n * process. Wrapping to a guessed width there would bake line breaks into output that something\n * else is going to reflow anyway, so the message is left as a single line.\n */\n private getTextWidth() {\n const columns = this.stdio.getStdout().columns;\n if (!columns) {\n return null;\n }\n\n return Math.max(columns - GUTTER_WIDTH, MIN_TEXT_WIDTH);\n }\n}\n\nexport const uiService = createImplementation({\n abstraction: UiService,\n implementation: DefaultUiService,\n dependencies: [StdioService, IsCi]\n});\n"],"names":["NEW_LINE","PIPE_SYMBOL","GUTTER_WIDTH","MIN_TEXT_WIDTH","LOG_COLORS","chalk","DefaultUiService","stdio","isCi","text","args","type","prefix","util","gutter","textWithColorizedPlaceholders","match","message","textWidth","wrapped","wrapAnsi","line","columns","Math","uiService","createImplementation","UiService","StdioService","IsCi"],"mappings":";;;;;AAMA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