@shopify/cli-kit 0.0.0-snapshot-20261009114709 → 0.0.0-snapshot-20261009150933

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.
@@ -1,16 +1,3 @@
1
- interface FatalErrorLike {
2
- type?: number;
3
- message?: unknown;
4
- formattedMessage?: unknown;
5
- tryMessage?: unknown;
6
- nextSteps?: unknown;
7
- customSections?: unknown;
8
- stack?: unknown;
9
- command?: unknown;
10
- args?: unknown;
11
- details?: unknown;
12
- code?: unknown;
13
- }
14
1
  /**
15
2
  * Writes the public JSON representation of a fatal error to stdout.
16
3
  *
@@ -19,5 +6,4 @@ interface FatalErrorLike {
19
6
  *
20
7
  * @param error - Fatal error to serialize.
21
8
  */
22
- export declare function renderFatalErrorAsJson(error: FatalErrorLike): void;
23
- export {};
9
+ export declare function renderFatalErrorAsJson(error: unknown): void;
@@ -1,101 +1,7 @@
1
- import { tokenItemToJsonString } from './ui/components/token-item.js';
2
1
  import { FatalErrorType } from '../../public/node/error.js';
3
2
  import { jsonErrorOutputSchema } from '../../public/node/error/schema.js';
4
- import { outputResult, unstyled } from '../../public/node/output.js';
5
- function externalCommand(error) {
6
- if (typeof error.command !== 'string' || !Array.isArray(error.args))
7
- return;
8
- if (!error.args.every((arg) => typeof arg === 'string'))
9
- return;
10
- return { command: error.command, args: error.args };
11
- }
12
- function jsonErrorType(error, external) {
13
- if (error.type === FatalErrorType.Abort) {
14
- return external ? 'external' : 'abort';
15
- }
16
- return 'bug';
17
- }
18
- function jsonTokenItem(token) {
19
- if (token === null || token === undefined)
20
- return;
21
- try {
22
- const message = tokenItemToJsonString(token);
23
- return typeof message === 'string' ? unstyled(message) : undefined;
24
- }
25
- catch (error) {
26
- if (error instanceof TypeError)
27
- return undefined;
28
- throw error;
29
- }
30
- }
31
- function jsonTokenItems(items) {
32
- if (!Array.isArray(items))
33
- return;
34
- const renderedItems = items.map(jsonTokenItem).filter((item) => item !== undefined);
35
- return renderedItems.length > 0 ? renderedItems : undefined;
36
- }
37
- function jsonTable(data) {
38
- if (!Array.isArray(data))
39
- return;
40
- return data
41
- .filter((row) => Array.isArray(row))
42
- .map((row) => row.map((cell) => jsonTokenItem(cell) ?? ''));
43
- }
44
- function jsonCustomSection(section) {
45
- if (typeof section !== 'object' || section === null || !('body' in section))
46
- return;
47
- const title = 'title' in section && typeof section.title === 'string' ? unstyled(section.title) : undefined;
48
- const sectionBody = section.body;
49
- const body = typeof sectionBody === 'object' && sectionBody !== null && 'tabularData' in sectionBody
50
- ? jsonTable(sectionBody.tabularData)
51
- : jsonTokenItem(sectionBody);
52
- if (body === undefined)
53
- return;
54
- return { ...(title ? { title } : {}), body };
55
- }
56
- function jsonCustomSections(sections) {
57
- if (!Array.isArray(sections))
58
- return;
59
- const renderedSections = sections
60
- .map(jsonCustomSection)
61
- .filter((section) => section !== undefined);
62
- return renderedSections.length > 0 ? renderedSections : undefined;
63
- }
64
- function jsonErrorDocument(error) {
65
- if (error.type === FatalErrorType.AbortSilent)
66
- return;
67
- const external = externalCommand(error);
68
- const type = jsonErrorType(error, external);
69
- const formattedMessage = jsonTokenItem(error.formattedMessage);
70
- const message = formattedMessage ?? (typeof error.message === 'string' ? unstyled(error.message) : 'Unknown error');
71
- const tryMessage = jsonTokenItem(error.tryMessage);
72
- const nextSteps = jsonTokenItems(error.nextSteps);
73
- const customSections = jsonCustomSections(error.customSections);
74
- const details = error.details;
75
- const commonFields = {
76
- message,
77
- ...(typeof error.code === 'string' && error.code.length > 0 ? { code: error.code } : {}),
78
- ...(tryMessage === undefined ? {} : { tryMessage }),
79
- ...(nextSteps === undefined ? {} : { nextSteps }),
80
- ...(customSections === undefined ? {} : { customSections }),
81
- ...(details === undefined ? {} : { details }),
82
- };
83
- let jsonError;
84
- if (type === 'bug') {
85
- jsonError = {
86
- type,
87
- ...commonFields,
88
- ...(typeof error.stack === 'string' ? { stack: unstyled(error.stack) } : {}),
89
- };
90
- }
91
- else if (type === 'external' && external) {
92
- jsonError = { type, ...commonFields, ...external };
93
- }
94
- else {
95
- jsonError = { type: 'abort', ...commonFields };
96
- }
97
- return { error: jsonError };
98
- }
3
+ import { errorToJson } from '../../public/node/error/serialization.js';
4
+ import { outputResult } from '../../public/node/output.js';
99
5
  /**
100
6
  * Writes the public JSON representation of a fatal error to stdout.
101
7
  *
@@ -107,9 +13,9 @@ function jsonErrorDocument(error) {
107
13
  export function renderFatalErrorAsJson(error) {
108
14
  let serializedDocument;
109
15
  try {
110
- const document = jsonErrorDocument(error);
111
- if (!document)
16
+ if (typeof error === 'object' && error !== null && 'type' in error && error.type === FatalErrorType.AbortSilent)
112
17
  return;
18
+ const document = { error: errorToJson(error) };
113
19
  serializedDocument = JSON.stringify(jsonErrorOutputSchema.validate(document));
114
20
  // Serialization must not replace the JSON contract with a text banner.
115
21
  // eslint-disable-next-line no-catch-all/no-catch-all
@@ -1 +1 @@
1
- {"version":3,"file":"json-error.js","sourceRoot":"","sources":["../../../src/private/node/json-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAiB,MAAM,+BAA+B,CAAA;AACnF,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAC,qBAAqB,EAAC,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,6BAA6B,CAAA;AA2BlE,SAAS,eAAe,CAAC,KAAqB;IAC5C,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,OAAM;IAC3E,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC;QAAE,OAAM;IAE/D,OAAO,EAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAC,CA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AO,EAAE,wCAAwC,EAAC,EAAC,CAAC,CAAA;IAChH,CAAC;IAED,qFAAqF;IACrF,YAAY,CAAC,kBAAkB,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import {tokenItemToJsonString, type TokenItem} from './ui/components/token-item.js'\nimport {FatalErrorType} from '../../public/node/error.js'\nimport {jsonErrorOutputSchema} from '../../public/node/error/schema.js'\nimport {outputResult, unstyled} from '../../public/node/output.js'\nimport type {\n JsonError,\n JsonErrorCustomSection,\n JsonErrorDocument,\n JsonErrorType,\n} from '../../public/node/error/types.js'\n\ninterface FatalErrorLike {\n type?: number\n message?: unknown\n formattedMessage?: unknown\n tryMessage?: unknown\n nextSteps?: unknown\n customSections?: unknown\n stack?: unknown\n command?: unknown\n args?: unknown\n details?: unknown\n code?: unknown\n}\n\ninterface ExternalCommand {\n command: string\n args: string[]\n}\n\nfunction externalCommand(error: FatalErrorLike): ExternalCommand | undefined {\n if (typeof error.command !== 'string' || !Array.isArray(error.args)) return\n if (!error.args.every((arg) => typeof arg === 'string')) return\n\n return {command: error.command, args: error.args}\n}\n\nfunction jsonErrorType(error: FatalErrorLike, external: ExternalCommand | undefined): JsonErrorType {\n if (error.type === FatalErrorType.Abort) {\n return external ? 'external' : 'abort'\n }\n return 'bug'\n}\n\nfunction jsonTokenItem(token: unknown): string | undefined {\n if (token === null || token === undefined) return\n\n try {\n const message = tokenItemToJsonString(token as TokenItem)\n return typeof message === 'string' ? unstyled(message) : undefined\n } catch (error) {\n if (error instanceof TypeError) return undefined\n throw error\n }\n}\n\nfunction jsonTokenItems(items: unknown): string[] | undefined {\n if (!Array.isArray(items)) return\n\n const renderedItems = items.map(jsonTokenItem).filter((item): item is string => item !== undefined)\n return renderedItems.length > 0 ? renderedItems : undefined\n}\n\nfunction jsonTable(data: unknown): string[][] | undefined {\n if (!Array.isArray(data)) return\n\n return data\n .filter((row): row is unknown[] => Array.isArray(row))\n .map((row) => row.map((cell) => jsonTokenItem(cell) ?? ''))\n}\n\nfunction jsonCustomSection(section: unknown): JsonErrorCustomSection | undefined {\n if (typeof section !== 'object' || section === null || !('body' in section)) return\n\n const title = 'title' in section && typeof section.title === 'string' ? unstyled(section.title) : undefined\n const sectionBody = section.body\n const body =\n typeof sectionBody === 'object' && sectionBody !== null && 'tabularData' in sectionBody\n ? jsonTable(sectionBody.tabularData)\n : jsonTokenItem(sectionBody)\n\n if (body === undefined) return\n return {...(title ? {title} : {}), body}\n}\n\nfunction jsonCustomSections(sections: unknown): JsonErrorCustomSection[] | undefined {\n if (!Array.isArray(sections)) return\n\n const renderedSections = sections\n .map(jsonCustomSection)\n .filter((section): section is JsonErrorCustomSection => section !== undefined)\n return renderedSections.length > 0 ? renderedSections : undefined\n}\n\nfunction jsonErrorDocument(error: FatalErrorLike): JsonErrorDocument | undefined {\n if (error.type === FatalErrorType.AbortSilent) return\n\n const external = externalCommand(error)\n const type = jsonErrorType(error, external)\n const formattedMessage = jsonTokenItem(error.formattedMessage)\n const message = formattedMessage ?? (typeof error.message === 'string' ? unstyled(error.message) : 'Unknown error')\n const tryMessage = jsonTokenItem(error.tryMessage)\n const nextSteps = jsonTokenItems(error.nextSteps)\n const customSections = jsonCustomSections(error.customSections)\n const details = error.details\n\n const commonFields = {\n message,\n ...(typeof error.code === 'string' && error.code.length > 0 ? {code: error.code} : {}),\n ...(tryMessage === undefined ? {} : {tryMessage}),\n ...(nextSteps === undefined ? {} : {nextSteps}),\n ...(customSections === undefined ? {} : {customSections}),\n ...(details === undefined ? {} : {details}),\n }\n\n let jsonError: JsonError\n if (type === 'bug') {\n jsonError = {\n type,\n ...commonFields,\n ...(typeof error.stack === 'string' ? {stack: unstyled(error.stack)} : {}),\n }\n } else if (type === 'external' && external) {\n jsonError = {type, ...commonFields, ...external}\n } else {\n jsonError = {type: 'abort', ...commonFields}\n }\n\n return {error: jsonError}\n}\n\n/**\n * Writes the public JSON representation of a fatal error to stdout.\n *\n * The allow-list mirrors the meaningful content of the regular fatal-error renderer.\n * Arbitrary error properties remain private and are never copied to stdout.\n *\n * @param error - Fatal error to serialize.\n */\nexport function renderFatalErrorAsJson(error: FatalErrorLike): void {\n let serializedDocument: string\n try {\n const document = jsonErrorDocument(error)\n if (!document) return\n serializedDocument = JSON.stringify(jsonErrorOutputSchema.validate(document))\n // Serialization must not replace the JSON contract with a text banner.\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n serializedDocument = JSON.stringify({error: {type: 'bug', message: 'Failed to serialize the error as JSON.'}})\n }\n\n // Keep write failures separate: retrying after a partial write could corrupt stdout.\n outputResult(serializedDocument)\n}\n"]}
1
+ {"version":3,"file":"json-error.js","sourceRoot":"","sources":["../../../src/private/node/json-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAC,qBAAqB,EAAC,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAC,WAAW,EAAC,MAAM,0CAA0C,CAAA;AACpE,OAAO,EAAC,YAAY,EAAC,MAAM,6BAA6B,CAAA;AAExD;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,IAAI,kBAA0B,CAAA;IAC9B,IAAI,CAAC;QACH,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,WAAW;YAC7G,OAAM;QACR,MAAM,QAAQ,GAAG,EAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAC,CAAA;QAC5C,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC7E,uEAAuE;QACvE,qDAAqD;IACvD,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,EAAC,KAAK,EAAE,EAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,wCAAwC,EAAC,EAAC,CAAC,CAAA;IAChH,CAAC;IAED,qFAAqF;IACrF,YAAY,CAAC,kBAAkB,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import {FatalErrorType} from '../../public/node/error.js'\nimport {jsonErrorOutputSchema} from '../../public/node/error/schema.js'\nimport {errorToJson} from '../../public/node/error/serialization.js'\nimport {outputResult} from '../../public/node/output.js'\n\n/**\n * Writes the public JSON representation of a fatal error to stdout.\n *\n * The allow-list mirrors the meaningful content of the regular fatal-error renderer.\n * Arbitrary error properties remain private and are never copied to stdout.\n *\n * @param error - Fatal error to serialize.\n */\nexport function renderFatalErrorAsJson(error: unknown): void {\n let serializedDocument: string\n try {\n if (typeof error === 'object' && error !== null && 'type' in error && error.type === FatalErrorType.AbortSilent)\n return\n const document = {error: errorToJson(error)}\n serializedDocument = JSON.stringify(jsonErrorOutputSchema.validate(document))\n // Serialization must not replace the JSON contract with a text banner.\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n serializedDocument = JSON.stringify({error: {type: 'bug', message: 'Failed to serialize the error as JSON.'}})\n }\n\n // Keep write failures separate: retrying after a partial write could corrupt stdout.\n outputResult(serializedDocument)\n}\n"]}
@@ -1 +1 @@
1
- export declare const CLI_KIT_VERSION = "0.0.0-snapshot-20261009114709";
1
+ export declare const CLI_KIT_VERSION = "0.0.0-snapshot-20261009150933";
@@ -1,2 +1,2 @@
1
- export const CLI_KIT_VERSION = '0.0.0-snapshot-20261009114709';
1
+ export const CLI_KIT_VERSION = '0.0.0-snapshot-20261009150933';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,+BAA+B,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '0.0.0-snapshot-20261009114709'\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,+BAA+B,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '0.0.0-snapshot-20261009150933'\n"]}
@@ -0,0 +1,8 @@
1
+ import type { JsonError } from './types.js';
2
+ /**
3
+ * Projects an error into the shared JSON error contract, retaining only allowlisted fields.
4
+ *
5
+ * @param source - Error to project.
6
+ * @returns The error classification, message, and available recovery information.
7
+ */
8
+ export declare function errorToJson(source: unknown): JsonError;
@@ -0,0 +1,103 @@
1
+ import { FatalErrorType } from './index.js';
2
+ import { tokenItemToJsonString } from '../../../private/node/ui/components/token-item.js';
3
+ import { unstyled } from '../output.js';
4
+ function externalCommand(error) {
5
+ if (typeof error.command !== 'string' || !Array.isArray(error.args))
6
+ return;
7
+ if (!error.args.every((arg) => typeof arg === 'string'))
8
+ return;
9
+ return { command: error.command, args: error.args };
10
+ }
11
+ function jsonErrorType(error, external) {
12
+ if (error.type === FatalErrorType.Abort) {
13
+ return external ? 'external' : 'abort';
14
+ }
15
+ return 'bug';
16
+ }
17
+ function jsonTokenItem(token) {
18
+ if (token === null || token === undefined)
19
+ return;
20
+ try {
21
+ const message = tokenItemToJsonString(token);
22
+ return typeof message === 'string' ? unstyled(message) : undefined;
23
+ }
24
+ catch (error) {
25
+ if (error instanceof TypeError)
26
+ return undefined;
27
+ throw error;
28
+ }
29
+ }
30
+ function jsonTokenItems(items) {
31
+ if (!Array.isArray(items))
32
+ return;
33
+ const renderedItems = items.map(jsonTokenItem).filter((item) => item !== undefined);
34
+ return renderedItems.length > 0 ? renderedItems : undefined;
35
+ }
36
+ function jsonTable(data) {
37
+ if (!Array.isArray(data))
38
+ return;
39
+ return data
40
+ .filter((row) => Array.isArray(row))
41
+ .map((row) => row.map((cell) => jsonTokenItem(cell) ?? ''));
42
+ }
43
+ function jsonCustomSection(section) {
44
+ if (typeof section !== 'object' || section === null || !('body' in section))
45
+ return;
46
+ const title = 'title' in section && typeof section.title === 'string' ? unstyled(section.title) : undefined;
47
+ const sectionBody = section.body;
48
+ const body = typeof sectionBody === 'object' && sectionBody !== null && 'tabularData' in sectionBody
49
+ ? jsonTable(sectionBody.tabularData)
50
+ : jsonTokenItem(sectionBody);
51
+ if (body === undefined)
52
+ return;
53
+ return { ...(title ? { title } : {}), body };
54
+ }
55
+ function jsonCustomSections(sections) {
56
+ if (!Array.isArray(sections))
57
+ return;
58
+ const renderedSections = sections
59
+ .map(jsonCustomSection)
60
+ .filter((section) => section !== undefined);
61
+ return renderedSections.length > 0 ? renderedSections : undefined;
62
+ }
63
+ /**
64
+ * Projects an error into the shared JSON error contract, retaining only allowlisted fields.
65
+ *
66
+ * @param source - Error to project.
67
+ * @returns The error classification, message, and available recovery information.
68
+ */
69
+ export function errorToJson(source) {
70
+ const error = typeof source === 'object' && source !== null ? source : { message: source };
71
+ const external = externalCommand(error);
72
+ const type = jsonErrorType(error, external);
73
+ const formattedMessage = jsonTokenItem(error.formattedMessage);
74
+ const message = formattedMessage ?? (typeof error.message === 'string' ? unstyled(error.message) : 'Unknown error');
75
+ const tryMessage = jsonTokenItem(error.tryMessage);
76
+ const nextSteps = jsonTokenItems(error.nextSteps);
77
+ const customSections = jsonCustomSections(error.customSections);
78
+ const details = error.details;
79
+ const commonFields = {
80
+ message,
81
+ ...(typeof error.code === 'string' && error.code.length > 0 ? { code: error.code } : {}),
82
+ ...(tryMessage === undefined ? {} : { tryMessage }),
83
+ ...(nextSteps === undefined ? {} : { nextSteps }),
84
+ ...(customSections === undefined ? {} : { customSections }),
85
+ ...(details === undefined ? {} : { details }),
86
+ };
87
+ let jsonError;
88
+ if (type === 'bug') {
89
+ jsonError = {
90
+ type,
91
+ ...commonFields,
92
+ ...(typeof error.stack === 'string' ? { stack: unstyled(error.stack) } : {}),
93
+ };
94
+ }
95
+ else if (type === 'external' && external) {
96
+ jsonError = { type, ...commonFields, ...external };
97
+ }
98
+ else {
99
+ jsonError = { type: 'abort', ...commonFields };
100
+ }
101
+ return jsonError;
102
+ }
103
+ //# sourceMappingURL=serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../../../src/public/node/error/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AACzC,OAAO,EAAC,qBAAqB,EAAiB,MAAM,mDAAmD,CAAA;AACvG,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAA;AAsBrC,SAAS,eAAe,CAAC,KAAqB;IAC5C,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,OAAM;IAC3E,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC;QAAE,OAAM;IAE/D,OAAO,EAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAC,CAAA;AACnD,CAAC;AAED,SAAS,aAAa,CAAC,KAAqB,EAAE,QAAqC;IACjF,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,KAAK,EAAE,CAAC;QACxC,OAAO,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAA;IACxC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAM;IAEjD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,qBAAqB,CAAC,KAAkB,CAAC,CAAA;QACzD,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,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AM,IAAI,IAAI,KAAK,UAAU,IAAI,QAAQ,EAAE,CAAC;QAC3C,SAAS,GAAG,EAAC,IAAI,EAAE,GAAG,YAAY,EAAE,GAAG,QAAQ,EAAC,CAAA;IAClD,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,EAAC,IAAI,EAAE,OAAO,EAAE,GAAG,YAAY,EAAC,CAAA;IAC9C,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import {FatalErrorType} from './index.js'\nimport {tokenItemToJsonString, type TokenItem} from '../../../private/node/ui/components/token-item.js'\nimport {unstyled} from '../output.js'\nimport type {JsonError, JsonErrorCustomSection, JsonErrorType} from './types.js'\n\ninterface FatalErrorLike {\n type?: number\n message?: unknown\n formattedMessage?: unknown\n tryMessage?: unknown\n nextSteps?: unknown\n customSections?: unknown\n stack?: unknown\n command?: unknown\n args?: unknown\n details?: unknown\n code?: unknown\n}\n\ninterface ExternalCommand {\n command: string\n args: string[]\n}\n\nfunction externalCommand(error: FatalErrorLike): ExternalCommand | undefined {\n if (typeof error.command !== 'string' || !Array.isArray(error.args)) return\n if (!error.args.every((arg) => typeof arg === 'string')) return\n\n return {command: error.command, args: error.args}\n}\n\nfunction jsonErrorType(error: FatalErrorLike, external: ExternalCommand | undefined): JsonErrorType {\n if (error.type === FatalErrorType.Abort) {\n return external ? 'external' : 'abort'\n }\n return 'bug'\n}\n\nfunction jsonTokenItem(token: unknown): string | undefined {\n if (token === null || token === undefined) return\n\n try {\n const message = tokenItemToJsonString(token as TokenItem)\n return typeof message === 'string' ? unstyled(message) : undefined\n } catch (error) {\n if (error instanceof TypeError) return undefined\n throw error\n }\n}\n\nfunction jsonTokenItems(items: unknown): string[] | undefined {\n if (!Array.isArray(items)) return\n\n const renderedItems = items.map(jsonTokenItem).filter((item): item is string => item !== undefined)\n return renderedItems.length > 0 ? renderedItems : undefined\n}\n\nfunction jsonTable(data: unknown): string[][] | undefined {\n if (!Array.isArray(data)) return\n\n return data\n .filter((row): row is unknown[] => Array.isArray(row))\n .map((row) => row.map((cell) => jsonTokenItem(cell) ?? ''))\n}\n\nfunction jsonCustomSection(section: unknown): JsonErrorCustomSection | undefined {\n if (typeof section !== 'object' || section === null || !('body' in section)) return\n\n const title = 'title' in section && typeof section.title === 'string' ? unstyled(section.title) : undefined\n const sectionBody = section.body\n const body =\n typeof sectionBody === 'object' && sectionBody !== null && 'tabularData' in sectionBody\n ? jsonTable(sectionBody.tabularData)\n : jsonTokenItem(sectionBody)\n\n if (body === undefined) return\n return {...(title ? {title} : {}), body}\n}\n\nfunction jsonCustomSections(sections: unknown): JsonErrorCustomSection[] | undefined {\n if (!Array.isArray(sections)) return\n\n const renderedSections = sections\n .map(jsonCustomSection)\n .filter((section): section is JsonErrorCustomSection => section !== undefined)\n return renderedSections.length > 0 ? renderedSections : undefined\n}\n\n/**\n * Projects an error into the shared JSON error contract, retaining only allowlisted fields.\n *\n * @param source - Error to project.\n * @returns The error classification, message, and available recovery information.\n */\nexport function errorToJson(source: unknown): JsonError {\n const error: FatalErrorLike = typeof source === 'object' && source !== null ? source : {message: source}\n\n const external = externalCommand(error)\n const type = jsonErrorType(error, external)\n const formattedMessage = jsonTokenItem(error.formattedMessage)\n const message = formattedMessage ?? (typeof error.message === 'string' ? unstyled(error.message) : 'Unknown error')\n const tryMessage = jsonTokenItem(error.tryMessage)\n const nextSteps = jsonTokenItems(error.nextSteps)\n const customSections = jsonCustomSections(error.customSections)\n const details = error.details\n\n const commonFields = {\n message,\n ...(typeof error.code === 'string' && error.code.length > 0 ? {code: error.code} : {}),\n ...(tryMessage === undefined ? {} : {tryMessage}),\n ...(nextSteps === undefined ? {} : {nextSteps}),\n ...(customSections === undefined ? {} : {customSections}),\n ...(details === undefined ? {} : {details}),\n }\n\n let jsonError: JsonError\n if (type === 'bug') {\n jsonError = {\n type,\n ...commonFields,\n ...(typeof error.stack === 'string' ? {stack: unstyled(error.stack)} : {}),\n }\n } else if (type === 'external' && external) {\n jsonError = {type, ...commonFields, ...external}\n } else {\n jsonError = {type: 'abort', ...commonFields}\n }\n\n return jsonError\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { Writable } from 'node:stream';
2
+ /**
3
+ * Keeps package-manager output off the result channel in JSON mode.
4
+ *
5
+ * @returns Streams for package-manager diagnostics, or the original terminal streams.
6
+ */
7
+ export declare function upgradeOutputStreams(): {
8
+ stdout: Writable;
9
+ stderr: Writable;
10
+ };
11
+ /**
12
+ * Runs a global upgrade with terminal input and format-appropriate diagnostics.
13
+ *
14
+ * @param command - The package-manager executable.
15
+ * @param args - The install arguments.
16
+ */
17
+ export declare function execUpgradeCommand(command: string, args: string[]): Promise<void>;
@@ -0,0 +1,51 @@
1
+ import { commandEventOutputMode } from '../command-events.js';
2
+ import { outputInfo } from '../output.js';
3
+ import { exec } from '../system.js';
4
+ import { Writable } from 'node:stream';
5
+ import { StringDecoder } from 'node:string_decoder';
6
+ /**
7
+ * Keeps package-manager output off the result channel in JSON mode.
8
+ *
9
+ * @returns Streams for package-manager diagnostics, or the original terminal streams.
10
+ */
11
+ export function upgradeOutputStreams() {
12
+ if (commandEventOutputMode() !== 'json')
13
+ return { stdout: process.stdout, stderr: process.stderr };
14
+ return { stdout: diagnosticStream(), stderr: diagnosticStream() };
15
+ }
16
+ function diagnosticStream() {
17
+ const decoder = new StringDecoder('utf8');
18
+ return new Writable({
19
+ write(chunk, _encoding, callback) {
20
+ const message = decoder.write(chunk);
21
+ if (message)
22
+ outputInfo(message);
23
+ callback();
24
+ },
25
+ final(callback) {
26
+ const message = decoder.end();
27
+ if (message)
28
+ outputInfo(message);
29
+ callback();
30
+ },
31
+ });
32
+ }
33
+ /**
34
+ * Runs a global upgrade with terminal input and format-appropriate diagnostics.
35
+ *
36
+ * @param command - The package-manager executable.
37
+ * @param args - The install arguments.
38
+ */
39
+ export async function execUpgradeCommand(command, args) {
40
+ const streams = upgradeOutputStreams();
41
+ try {
42
+ await exec(command, args, streams.stdout === process.stdout ? { stdio: 'inherit' } : { stdin: 'inherit', ...streams });
43
+ }
44
+ finally {
45
+ if (streams.stdout !== process.stdout)
46
+ streams.stdout.end();
47
+ if (streams.stderr !== process.stderr)
48
+ streams.stderr.end();
49
+ }
50
+ }
51
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../../../src/public/node/upgrade/output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AACvC,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAA;AACjC,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AACpC,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAA;AAEjD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IAClC,IAAI,sBAAsB,EAAE,KAAK,MAAM;QAAE,OAAO,EAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAC,CAAA;IAEhG,OAAO,EAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAC,CAAA;AACjE,CAAC;AAED,SAAS,gBAAgB;IACvB,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAA;IACzC,OAAO,IAAI,QAAQ,CAAC;QAClB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ;YAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACpC,IAAI,OAAO;gBAAE,UAAU,CAAC,OAAO,CAAC,CAAA;YAChC,QAAQ,EAAE,CAAA;QACZ,CAAC;QACD,KAAK,CAAC,QAAQ;YACZ,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;YAC7B,IAAI,OAAO;gBAAE,UAAU,CAAC,OAAO,CAAC,CAAA;YAChC,QAAQ,EAAE,CAAA;QACZ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAe,EAAE,IAAc;IACtE,MAAM,OAAO,GAAG,oBAAoB,EAAE,CAAA;IACtC,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAC,KAAK,EAAE,SAAS,EAAC,CAAC,CAAC,CAAC,EAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,EAAC,CAAC,CAAA;IACpH,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;QAC3D,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;IAC7D,CAAC;AACH,CAAC","sourcesContent":["import {commandEventOutputMode} from '../command-events.js'\nimport {outputInfo} from '../output.js'\nimport {exec} from '../system.js'\nimport {Writable} from 'node:stream'\nimport {StringDecoder} from 'node:string_decoder'\n\n/**\n * Keeps package-manager output off the result channel in JSON mode.\n *\n * @returns Streams for package-manager diagnostics, or the original terminal streams.\n */\nexport function upgradeOutputStreams(): {stdout: Writable; stderr: Writable} {\n if (commandEventOutputMode() !== 'json') return {stdout: process.stdout, stderr: process.stderr}\n\n return {stdout: diagnosticStream(), stderr: diagnosticStream()}\n}\n\nfunction diagnosticStream(): Writable {\n const decoder = new StringDecoder('utf8')\n return new Writable({\n write(chunk, _encoding, callback) {\n const message = decoder.write(chunk)\n if (message) outputInfo(message)\n callback()\n },\n final(callback) {\n const message = decoder.end()\n if (message) outputInfo(message)\n callback()\n },\n })\n}\n\n/**\n * Runs a global upgrade with terminal input and format-appropriate diagnostics.\n *\n * @param command - The package-manager executable.\n * @param args - The install arguments.\n */\nexport async function execUpgradeCommand(command: string, args: string[]): Promise<void> {\n const streams = upgradeOutputStreams()\n try {\n await exec(command, args, streams.stdout === process.stdout ? {stdio: 'inherit'} : {stdin: 'inherit', ...streams})\n } finally {\n if (streams.stdout !== process.stdout) streams.stdout.end()\n if (streams.stderr !== process.stderr) streams.stderr.end()\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { type UpgradeResult } from './types.js';
2
+ /**
3
+ * Presents the upgrade result without changing progress or package-manager output.
4
+ *
5
+ * @param result - The completed upgrade outcome.
6
+ * @param format - The output format selected by the caller.
7
+ */
8
+ export declare function presentUpgradeResult(result: UpgradeResult, format: 'json' | 'text'): void;
@@ -0,0 +1,21 @@
1
+ import { upgradeJsonOutputSchema } from './types.js';
2
+ import { outputResult } from '../output.js';
3
+ import { renderSuccess } from '../ui.js';
4
+ /**
5
+ * Presents the upgrade result without changing progress or package-manager output.
6
+ *
7
+ * @param result - The completed upgrade outcome.
8
+ * @param format - The output format selected by the caller.
9
+ */
10
+ export function presentUpgradeResult(result, format) {
11
+ if (format === 'json') {
12
+ outputResult(upgradeJsonOutputSchema.encode(result));
13
+ }
14
+ else if (result.status === 'success' && result.scope === 'global') {
15
+ renderSuccess({
16
+ headline: 'Shopify CLI upgraded.',
17
+ body: `You're now on version ${result.version}.`,
18
+ });
19
+ }
20
+ }
21
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../../src/public/node/upgrade/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAqB,MAAM,YAAY,CAAA;AACtE,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAA;AACzC,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAA;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAqB,EAAE,MAAuB;IACjF,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,YAAY,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;IACtD,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QACpE,aAAa,CAAC;YACZ,QAAQ,EAAE,uBAAuB;YACjC,IAAI,EAAE,yBAAyB,MAAM,CAAC,OAAO,GAAG;SACjD,CAAC,CAAA;IACJ,CAAC;AACH,CAAC","sourcesContent":["import {upgradeJsonOutputSchema, type UpgradeResult} from './types.js'\nimport {outputResult} from '../output.js'\nimport {renderSuccess} from '../ui.js'\n\n/**\n * Presents the upgrade result without changing progress or package-manager output.\n *\n * @param result - The completed upgrade outcome.\n * @param format - The output format selected by the caller.\n */\nexport function presentUpgradeResult(result: UpgradeResult, format: 'json' | 'text'): void {\n if (format === 'json') {\n outputResult(upgradeJsonOutputSchema.encode(result))\n } else if (result.status === 'success' && result.scope === 'global') {\n renderSuccess({\n headline: 'Shopify CLI upgraded.',\n body: `You're now on version ${result.version}.`,\n })\n }\n}\n"]}
@@ -0,0 +1,61 @@
1
+ import { type InferJsonOutputSchema } from '../json-output-schema.js';
2
+ import { zod } from '../schema.js';
3
+ export declare const upgradeJsonOutputSchema: import("../json-output-schema.js").JsonOutputSchema<zod.ZodUnion<[zod.ZodObject<{
4
+ status: zod.ZodLiteral<"success">;
5
+ changed: zod.ZodBoolean;
6
+ scope: zod.ZodLiteral<"global">;
7
+ previousVersion: zod.ZodString;
8
+ version: zod.ZodString;
9
+ packageManager: zod.ZodEnum<["npm", "pnpm", "yarn", "bun", "homebrew"]>;
10
+ }, "strict", zod.ZodTypeAny, {
11
+ status: "success";
12
+ version: string;
13
+ scope: "global";
14
+ changed: boolean;
15
+ previousVersion: string;
16
+ packageManager: "yarn" | "npm" | "pnpm" | "bun" | "homebrew";
17
+ }, {
18
+ status: "success";
19
+ version: string;
20
+ scope: "global";
21
+ changed: boolean;
22
+ previousVersion: string;
23
+ packageManager: "yarn" | "npm" | "pnpm" | "bun" | "homebrew";
24
+ }>, zod.ZodObject<{
25
+ status: zod.ZodLiteral<"success">;
26
+ changed: zod.ZodNull;
27
+ scope: zod.ZodLiteral<"local">;
28
+ directory: zod.ZodEffects<zod.ZodEffects<zod.ZodString, string, string>, string, string>;
29
+ previousVersion: zod.ZodString;
30
+ availableVersion: zod.ZodNullable<zod.ZodString>;
31
+ packages: zod.ZodArray<zod.ZodString, "many">;
32
+ }, "strict", zod.ZodTypeAny, {
33
+ status: "success";
34
+ directory: string;
35
+ scope: "local";
36
+ changed: null;
37
+ previousVersion: string;
38
+ availableVersion: string | null;
39
+ packages: string[];
40
+ }, {
41
+ status: "success";
42
+ directory: string;
43
+ scope: "local";
44
+ changed: null;
45
+ previousVersion: string;
46
+ availableVersion: string | null;
47
+ packages: string[];
48
+ }>, zod.ZodObject<{
49
+ status: zod.ZodLiteral<"skipped">;
50
+ reason: zod.ZodEnum<["development", "local-autoupgrade", "dependency-not-found"]>;
51
+ scope: zod.ZodEnum<["global", "local"]>;
52
+ }, "strict", zod.ZodTypeAny, {
53
+ status: "skipped";
54
+ scope: "local" | "global";
55
+ reason: "development" | "local-autoupgrade" | "dependency-not-found";
56
+ }, {
57
+ status: "skipped";
58
+ scope: "local" | "global";
59
+ reason: "development" | "local-autoupgrade" | "dependency-not-found";
60
+ }>]>>;
61
+ export type UpgradeResult = InferJsonOutputSchema<typeof upgradeJsonOutputSchema>;
@@ -0,0 +1,46 @@
1
+ import { defineJsonOutputSchema } from '../json-output-schema.js';
2
+ import { isAbsolutePath } from '../path.js';
3
+ import { zod } from '../schema.js';
4
+ // eslint-disable-next-line no-restricted-imports -- JSON filesystem paths use native platform separators.
5
+ import { resolve } from 'node:path';
6
+ export const upgradeJsonOutputSchema = defineJsonOutputSchema({
7
+ name: 'UpgradeResult',
8
+ schema: zod.union([
9
+ zod
10
+ .object({
11
+ status: zod.literal('success'),
12
+ changed: zod.boolean().describe('Whether the verified installed version differs from previousVersion.'),
13
+ scope: zod.literal('global'),
14
+ previousVersion: zod.string().min(1),
15
+ version: zod.string().min(1),
16
+ packageManager: zod.enum(['npm', 'pnpm', 'yarn', 'bun', 'homebrew']),
17
+ })
18
+ .strict(),
19
+ zod
20
+ .object({
21
+ status: zod.literal('success'),
22
+ changed: zod.null().describe('Null because local dependency changes and installed versions are not verified.'),
23
+ scope: zod.literal('local'),
24
+ directory: zod
25
+ .string()
26
+ .refine(isAbsolutePath, 'Must be an absolute filesystem path.')
27
+ .transform((directory) => resolve(directory)),
28
+ previousVersion: zod.string().min(1),
29
+ availableVersion: zod
30
+ .string()
31
+ .min(1)
32
+ .nullable()
33
+ .describe('The available registry version, or null when unknown.'),
34
+ packages: zod.array(zod.string().min(1)),
35
+ })
36
+ .strict(),
37
+ zod
38
+ .object({
39
+ status: zod.literal('skipped'),
40
+ reason: zod.enum(['development', 'local-autoupgrade', 'dependency-not-found']),
41
+ scope: zod.enum(['global', 'local']),
42
+ })
43
+ .strict(),
44
+ ]),
45
+ });
46
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/public/node/upgrade/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAA6B,MAAM,0BAA0B,CAAA;AAC3F,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AACzC,OAAO,EAAC,GAAG,EAAC,MAAM,cAAc,CAAA;AAChC,0GAA0G;AAC1G,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AAEjC,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;IAC5D,IAAI,EAAE,eAAe;IACrB,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC;QAChB,GAAG;aACA,MAAM,CAAC;YACN,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;YAC9B,OAAO,EAAE,GAAG,CAAC,OA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C,aAAa,EAAE,mBAAmB,EAAE,sBAAsB,CAAC,CAAC;YAC9E,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;SACrC,CAAC;aACD,MAAM,EAAE;KACZ,CAAC;CACH,CAAC,CAAA","sourcesContent":["import {defineJsonOutputSchema, type InferJsonOutputSchema} from '../json-output-schema.js'\nimport {isAbsolutePath} from '../path.js'\nimport {zod} from '../schema.js'\n// eslint-disable-next-line no-restricted-imports -- JSON filesystem paths use native platform separators.\nimport {resolve} from 'node:path'\n\nexport const upgradeJsonOutputSchema = defineJsonOutputSchema({\n name: 'UpgradeResult',\n schema: zod.union([\n zod\n .object({\n status: zod.literal('success'),\n changed: zod.boolean().describe('Whether the verified installed version differs from previousVersion.'),\n scope: zod.literal('global'),\n previousVersion: zod.string().min(1),\n version: zod.string().min(1),\n packageManager: zod.enum(['npm', 'pnpm', 'yarn', 'bun', 'homebrew']),\n })\n .strict(),\n zod\n .object({\n status: zod.literal('success'),\n changed: zod.null().describe('Null because local dependency changes and installed versions are not verified.'),\n scope: zod.literal('local'),\n directory: zod\n .string()\n .refine(isAbsolutePath, 'Must be an absolute filesystem path.')\n .transform((directory) => resolve(directory)),\n previousVersion: zod.string().min(1),\n availableVersion: zod\n .string()\n .min(1)\n .nullable()\n .describe('The available registry version, or null when unknown.'),\n packages: zod.array(zod.string().min(1)),\n })\n .strict(),\n zod\n .object({\n status: zod.literal('skipped'),\n reason: zod.enum(['development', 'local-autoupgrade', 'dependency-not-found']),\n scope: zod.enum(['global', 'local']),\n })\n .strict(),\n ]),\n})\n\nexport type UpgradeResult = InferJsonOutputSchema<typeof upgradeJsonOutputSchema>\n"]}
@@ -1,4 +1,5 @@
1
1
  import { getAutoUpgradeEnabled, setAutoUpgradeEnabled } from '../../private/node/conf-store.js';
2
+ import type { UpgradeResult } from './upgrade/types.js';
2
3
  export { getAutoUpgradeEnabled, setAutoUpgradeEnabled };
3
4
  /**
4
5
  * Utility function for generating an install command for the user to run
@@ -27,6 +28,13 @@ export interface RunCLIUpgradeOptions {
27
28
  * @throws AbortError if the package manager or command cannot be determined.
28
29
  */
29
30
  export declare function runCLIUpgrade(options?: RunCLIUpgradeOptions): Promise<void>;
31
+ /**
32
+ * Upgrades the CLI and returns the outcome independently of final presentation.
33
+ *
34
+ * @param options - Whether the upgrade was triggered automatically.
35
+ * @returns The verified global version, local dependency update, or skip reason.
36
+ */
37
+ export declare function upgradeCLI(options?: RunCLIUpgradeOptions): Promise<UpgradeResult>;
30
38
  /**
31
39
  * Returns the version to auto-upgrade to, or undefined if auto-upgrade should be skipped.
32
40
  * Auto-upgrade is enabled by default and can be disabled via `setAutoUpgradeEnabled(false)`.