@shopify/cli-kit 3.51.1 → 3.52.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.
@@ -45,7 +45,7 @@ module ShopifyCLI
45
45
  # on disk.
46
46
  def reject_duplicated_checksums!
47
47
  checksums_mutex.synchronize do
48
- checksum_by_key.reject! { |key, _| checksum_by_key.key?("#{key}.liquid") }
48
+ checksum_by_key.reject! { |key, _| key.start_with?("assets/") && checksum_by_key.key?("#{key}.liquid") }
49
49
  end
50
50
  end
51
51
 
@@ -46,7 +46,7 @@ export function buildHeaders(token) {
46
46
  ...(firstPartyDev() && { 'X-Shopify-Cli-Employee': '1' }),
47
47
  };
48
48
  if (token) {
49
- const authString = token.startsWith('shpat') ? token : `Bearer ${token}`;
49
+ const authString = token.match(/^shp(at|ua)/) ? token : `Bearer ${token}`;
50
50
  // eslint-disable-next-line dot-notation
51
51
  headers['authorization'] = authString;
52
52
  headers['X-Shopify-Access-Token'] = authString;
@@ -1 +1 @@
1
- {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../../src/private/node/api/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mCAAmC,CAAA;AACjE,OAAO,EAAC,aAAa,EAAC,MAAM,uCAAuC,CAAA;AACnE,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAA;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IAErD,YAAmB,OAAe,EAAE,UAAkB;QACpD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;CACF;AACD,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;IAIxD,8DAA8D;IAC9D,YAAmB,OAAe,EAAE,UAAkB,EAAE,MAAc;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AC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAA;QACxE,wCAAwC;QACxC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,CAAA;QACrC,OAAO,CAAC,wBAAwB,CAAC,GAAG,UAAU,CAAA;KAC/C;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC;QACrB,kBAAkB,EAAE,MAAM,gCAAgC,EAAE;QAC5D,SAAS,EAAE,IAAI;KAChB,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,gCAAgC;IAC7C,OAAO,CAAC,MAAM,kBAAkB,EAAE,CAAC,KAAK,WAAW,CAAC,IAAI,CAAA;AAC1D,CAAC","sourcesContent":["import {CLI_KIT_VERSION} from '../../../public/common/version.js'\nimport {firstPartyDev} from '../../../public/node/context/local.js'\nimport {Environment, serviceEnvironment} from '../context/service.js'\nimport {ExtendableError} from '../../../public/node/error.js'\nimport https from 'https'\n\nexport class RequestClientError extends ExtendableError {\n statusCode: number\n public constructor(message: string, statusCode: number) {\n super(message)\n this.statusCode = statusCode\n }\n}\nexport class GraphQLClientError extends RequestClientError {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n errors?: any[]\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public constructor(message: string, statusCode: number, errors?: any[]) {\n super(message, statusCode)\n this.errors = errors\n }\n}\n\n/**\n * Removes the sensitive data from the headers and outputs them as a string.\n * @param headers - HTTP headers.\n * @returns A sanitized version of the headers as a string.\n */\nexport function sanitizedHeadersOutput(headers: {[key: string]: string}): string {\n const sanitized: {[key: string]: string} = {}\n const keywords = ['token', 'authorization', 'subject_token']\n Object.keys(headers).forEach((header) => {\n if (keywords.find((keyword) => header.toLocaleLowerCase().includes(keyword)) === undefined) {\n sanitized[header] = headers[header]!\n }\n })\n return Object.keys(sanitized)\n .map((header) => {\n return ` - ${header}: ${sanitized[header]}`\n })\n .join('\\n')\n}\n\nexport function buildHeaders(token?: string): {[key: string]: string} {\n const userAgent = `Shopify CLI; v=${CLI_KIT_VERSION}`\n\n const headers: {[header: string]: string} = {\n 'User-Agent': userAgent,\n 'Keep-Alive': 'timeout=30',\n // 'Sec-CH-UA': secCHUA, This header requires the Git sha.\n 'Sec-CH-UA-PLATFORM': process.platform,\n 'Content-Type': 'application/json',\n ...(firstPartyDev() && {'X-Shopify-Cli-Employee': '1'}),\n }\n if (token) {\n const authString = token.startsWith('shpat') ? token : `Bearer ${token}`\n // eslint-disable-next-line dot-notation\n headers['authorization'] = authString\n headers['X-Shopify-Access-Token'] = authString\n }\n\n return headers\n}\n\n/**\n * This utility function returns the https.Agent to use for a given service. The agent\n * includes the right configuration based on the service's environment. For example,\n * if the service is running in a Spin environment, the attribute \"rejectUnauthorized\" is\n * set to false\n */\nexport async function httpsAgent(): Promise<https.Agent> {\n return new https.Agent({\n rejectUnauthorized: await shouldRejectUnauthorizedRequests(),\n keepAlive: true,\n })\n}\n\n/**\n * Spin stores the CA certificate in the keychain and it should be used when sending HTTP\n * requests to Spin instances. However, Node doesn't read certificates from the Keychain\n * by default, which leads to Shopifolks running into issues that they workaround by setting the\n * NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable, which applies to all the HTTP\n * requests sent from the CLI (context: https://github.com/nodejs/node/issues/39657)\n * This utility function allows controlling the behavior in a per-service level by returning\n * the value of for the \"rejectUnauthorized\" attribute that's used in the https agent.\n *\n * @returns A promise that resolves with a boolean indicating whether\n * unauthorized requests should be rejected or not.\n */\nasync function shouldRejectUnauthorizedRequests(): Promise<boolean> {\n return (await serviceEnvironment()) !== Environment.Spin\n}\n"]}
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../../src/private/node/api/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mCAAmC,CAA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AA;IAC7C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,SAAS,GAAG,kBAAkB,eAAe,EAAE,CAAA;IAErD,MAAM,OAAO,GAA+B;QAC1C,YAAY,EAAE,SAAS;QACvB,YAAY,EAAE,YAAY;QAC1B,0DAA0D;QAC1D,oBAAoB,EAAE,OAAO,CAAC,QAAQ;QACtC,cAAc,EAAE,kBAAkB;QAClC,GAAG,CAAC,aAAa,EAAE,IAAI,EAAC,wBAAwB,EAAE,GAAG,EAAC,CAAC;KACxD,CAAA;IACD,IAAI,KAAK,EAAE;QACT,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,EAAE,CAAA;QACzE,wCAAwC;QACxC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,CAAA;QACrC,OAAO,CAAC,wBAAwB,CAAC,GAAG,UAAU,CAAA;KAC/C;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC;QACrB,kBAAkB,EAAE,MAAM,gCAAgC,EAAE;QAC5D,SAAS,EAAE,IAAI;KAChB,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,gCAAgC;IAC7C,OAAO,CAAC,MAAM,kBAAkB,EAAE,CAAC,KAAK,WAAW,CAAC,IAAI,CAAA;AAC1D,CAAC","sourcesContent":["import {CLI_KIT_VERSION} from '../../../public/common/version.js'\nimport {firstPartyDev} from '../../../public/node/context/local.js'\nimport {Environment, serviceEnvironment} from '../context/service.js'\nimport {ExtendableError} from '../../../public/node/error.js'\nimport https from 'https'\n\nexport class RequestClientError extends ExtendableError {\n statusCode: number\n public constructor(message: string, statusCode: number) {\n super(message)\n this.statusCode = statusCode\n }\n}\nexport class GraphQLClientError extends RequestClientError {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n errors?: any[]\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public constructor(message: string, statusCode: number, errors?: any[]) {\n super(message, statusCode)\n this.errors = errors\n }\n}\n\n/**\n * Removes the sensitive data from the headers and outputs them as a string.\n * @param headers - HTTP headers.\n * @returns A sanitized version of the headers as a string.\n */\nexport function sanitizedHeadersOutput(headers: {[key: string]: string}): string {\n const sanitized: {[key: string]: string} = {}\n const keywords = ['token', 'authorization', 'subject_token']\n Object.keys(headers).forEach((header) => {\n if (keywords.find((keyword) => header.toLocaleLowerCase().includes(keyword)) === undefined) {\n sanitized[header] = headers[header]!\n }\n })\n return Object.keys(sanitized)\n .map((header) => {\n return ` - ${header}: ${sanitized[header]}`\n })\n .join('\\n')\n}\n\nexport function buildHeaders(token?: string): {[key: string]: string} {\n const userAgent = `Shopify CLI; v=${CLI_KIT_VERSION}`\n\n const headers: {[header: string]: string} = {\n 'User-Agent': userAgent,\n 'Keep-Alive': 'timeout=30',\n // 'Sec-CH-UA': secCHUA, This header requires the Git sha.\n 'Sec-CH-UA-PLATFORM': process.platform,\n 'Content-Type': 'application/json',\n ...(firstPartyDev() && {'X-Shopify-Cli-Employee': '1'}),\n }\n if (token) {\n const authString = token.match(/^shp(at|ua)/) ? token : `Bearer ${token}`\n // eslint-disable-next-line dot-notation\n headers['authorization'] = authString\n headers['X-Shopify-Access-Token'] = authString\n }\n\n return headers\n}\n\n/**\n * This utility function returns the https.Agent to use for a given service. The agent\n * includes the right configuration based on the service's environment. For example,\n * if the service is running in a Spin environment, the attribute \"rejectUnauthorized\" is\n * set to false\n */\nexport async function httpsAgent(): Promise<https.Agent> {\n return new https.Agent({\n rejectUnauthorized: await shouldRejectUnauthorizedRequests(),\n keepAlive: true,\n })\n}\n\n/**\n * Spin stores the CA certificate in the keychain and it should be used when sending HTTP\n * requests to Spin instances. However, Node doesn't read certificates from the Keychain\n * by default, which leads to Shopifolks running into issues that they workaround by setting the\n * NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable, which applies to all the HTTP\n * requests sent from the CLI (context: https://github.com/nodejs/node/issues/39657)\n * This utility function allows controlling the behavior in a per-service level by returning\n * the value of for the \"rejectUnauthorized\" attribute that's used in the https agent.\n *\n * @returns A promise that resolves with a boolean indicating whether\n * unauthorized requests should be rejected or not.\n */\nasync function shouldRejectUnauthorizedRequests(): Promise<boolean> {\n return (await serviceEnvironment()) !== Environment.Spin\n}\n"]}
@@ -9,7 +9,7 @@ interface RenderOnceOptions {
9
9
  renderOptions?: RenderOptions;
10
10
  }
11
11
  export declare function renderOnce(element: JSX.Element, { logLevel, logger, renderOptions }: RenderOnceOptions): string | undefined;
12
- export declare function render(element: JSX.Element, options?: RenderOptions): Promise<void>;
12
+ export declare function render(element: JSX.Element, options?: RenderOptions): Promise<unknown>;
13
13
  export declare class Stdout extends EventEmitter {
14
14
  columns: number;
15
15
  rows: number;
@@ -13,9 +13,11 @@ export function renderOnce(element, { logLevel = 'info', logger = consoleLog, re
13
13
  unmount();
14
14
  return output;
15
15
  }
16
- export function render(element, options) {
16
+ export async function render(element, options) {
17
17
  const { waitUntilExit } = inkRender(element, options);
18
- return waitUntilExit();
18
+ await waitUntilExit();
19
+ // We need to wait for other pending tasks -- unmounting of the ink component -- to complete
20
+ return new Promise((resolve) => setImmediate(resolve));
19
21
  }
20
22
  export class Stdout extends EventEmitter {
21
23
  constructor(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/private/node/ui.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAoB,sBAAsB,EAAC,MAAM,6BAA6B,CAAA;AAC5G,OAAO,EAAC,UAAU,EAAC,MAAM,oCAAoC,CAAA;AAC7D,OAAO,EAAC,QAAQ,EAAC,MAAM,gCAAgC,CAAA;AAEvD,OAAO,EAA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;CAUF;AAED,MAAM,YAAY,GAAG,CAAC,OAAqB,EAAE,aAA6B,EAAY,EAAE;IACtF,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAA;IAC1D,8DAA8D;IAC9D,MAAM,MAAM,GAAI,aAAa,EAAE,MAAc,IAAI,IAAI,MAAM,CAAC,EAAC,OAAO,EAAC,CAAC,CAAA;IAEtE,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE;QAClC,MAAM;QACN,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAA;IAEF,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE;QAC1B,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAA;AACH,CAAC,CAAA;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,GAAQ,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;IAC/F,IAAI,KAAK,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE;QAC7B,gEAAgE;QAChE,IAAI,EAAE,CAAA;KACP;AACH,CAAC","sourcesContent":["import {collectLog, consoleLog, Logger, LogLevel, outputWhereAppropriate} from '../../public/node/output.js'\nimport {isUnitTest} from '../../public/node/context/local.js'\nimport {treeKill} from '../../public/node/tree-kill.js'\nimport {ReactElement} from 'react'\nimport {Key, render as inkRender, RenderOptions} from 'ink'\nimport {EventEmitter} from 'events'\n\ninterface RenderOnceOptions {\n logLevel?: LogLevel\n logger?: Logger\n renderOptions?: RenderOptions\n}\n\nexport function renderOnce(\n element: JSX.Element,\n {logLevel = 'info', logger = consoleLog, renderOptions}: RenderOnceOptions,\n) {\n const {output, unmount} = renderString(element, renderOptions)\n\n if (output) {\n if (isUnitTest()) collectLog(logLevel, output)\n outputWhereAppropriate(logLevel, logger, output, {skipUIEvent: true})\n }\n\n unmount()\n\n return output\n}\n\nexport function render(element: JSX.Element, options?: RenderOptions) {\n const {waitUntilExit} = inkRender(element, options)\n return waitUntilExit()\n}\n\ninterface Instance {\n output: string | undefined\n unmount: () => void\n}\n\nexport class Stdout extends EventEmitter {\n columns: number\n rows: number\n readonly frames: string[] = []\n private _lastFrame?: string\n\n constructor(options: {columns?: number; rows?: number}) {\n super()\n this.columns = options.columns ?? 80\n this.rows = options.rows ?? 80\n }\n\n write = (frame: string) => {\n this.frames.push(frame)\n this._lastFrame = frame\n }\n\n lastFrame = () => {\n return this._lastFrame\n }\n}\n\nconst renderString = (element: ReactElement, renderOptions?: RenderOptions): Instance => {\n const columns = isUnitTest() ? 80 : process.stdout.columns\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const stdout = (renderOptions?.stdout as any) ?? new Stdout({columns})\n\n const instance = inkRender(element, {\n stdout,\n debug: true,\n exitOnCtrlC: false,\n patchConsole: false,\n })\n\n return {\n output: stdout.lastFrame(),\n unmount: instance.unmount,\n }\n}\n\nexport function handleCtrlC(input: string, key: Key, exit = () => treeKill(process.pid, 'SIGINT')) {\n if (input === 'c' && key.ctrl) {\n // Exceptions thrown in hooks aren't caught by our errorHandler.\n exit()\n }\n}\n"]}
1
+ {"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/private/node/ui.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,UAAU,EAAoB,sBAAsB,EAAC,MAAM,6BAA6B,CAAA;AAC5G,OAAO,EAAC,UAAU,EAAC,MAAM,oCAAoC,CAAA;AAC7D,OAAO,EAAC,QAAQ,EAAC,MAAM,gCAAgC,CAAA;AAEvD,OAAO,EAAM,MAAM,IAAI,SAAS,EAAgB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAA;AAQnC,MAAM,UAAU,UAAU,CACxB,OAAoB,EACpB,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,YAAY,GAAG,CAAC,OAAqB,EAAE,aAA6B,EAAY,EAAE;IACtF,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAA;IAC1D,8DAA8D;IAC9D,MAAM,MAAM,GAAI,aAAa,EAAE,MAAc,IAAI,IAAI,MAAM,CAAC,EAAC,OAAO,EAAC,CAAC,CAAA;IAEtE,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE;QAClC,MAAM;QACN,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAA;IAEF,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE;QAC1B,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAA;AACH,CAAC,CAAA;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,GAAQ,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;IAC/F,IAAI,KAAK,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE;QAC7B,gEAAgE;QAChE,IAAI,EAAE,CAAA;KACP;AACH,CAAC","sourcesContent":["import {collectLog, consoleLog, Logger, LogLevel, outputWhereAppropriate} from '../../public/node/output.js'\nimport {isUnitTest} from '../../public/node/context/local.js'\nimport {treeKill} from '../../public/node/tree-kill.js'\nimport {ReactElement} from 'react'\nimport {Key, render as inkRender, RenderOptions} from 'ink'\nimport {EventEmitter} from 'events'\n\ninterface RenderOnceOptions {\n logLevel?: LogLevel\n logger?: Logger\n renderOptions?: RenderOptions\n}\n\nexport function renderOnce(\n element: JSX.Element,\n {logLevel = 'info', logger = consoleLog, renderOptions}: RenderOnceOptions,\n) {\n const {output, unmount} = renderString(element, renderOptions)\n\n if (output) {\n if (isUnitTest()) collectLog(logLevel, output)\n outputWhereAppropriate(logLevel, logger, output, {skipUIEvent: true})\n }\n\n unmount()\n\n return output\n}\n\nexport async function render(element: JSX.Element, options?: RenderOptions) {\n const {waitUntilExit} = inkRender(element, options)\n await waitUntilExit()\n // We need to wait for other pending tasks -- unmounting of the ink component -- to complete\n return new Promise((resolve) => setImmediate(resolve))\n}\n\ninterface Instance {\n output: string | undefined\n unmount: () => void\n}\n\nexport class Stdout extends EventEmitter {\n columns: number\n rows: number\n readonly frames: string[] = []\n private _lastFrame?: string\n\n constructor(options: {columns?: number; rows?: number}) {\n super()\n this.columns = options.columns ?? 80\n this.rows = options.rows ?? 80\n }\n\n write = (frame: string) => {\n this.frames.push(frame)\n this._lastFrame = frame\n }\n\n lastFrame = () => {\n return this._lastFrame\n }\n}\n\nconst renderString = (element: ReactElement, renderOptions?: RenderOptions): Instance => {\n const columns = isUnitTest() ? 80 : process.stdout.columns\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const stdout = (renderOptions?.stdout as any) ?? new Stdout({columns})\n\n const instance = inkRender(element, {\n stdout,\n debug: true,\n exitOnCtrlC: false,\n patchConsole: false,\n })\n\n return {\n output: stdout.lastFrame(),\n unmount: instance.unmount,\n }\n}\n\nexport function handleCtrlC(input: string, key: Key, exit = () => treeKill(process.pid, 'SIGINT')) {\n if (input === 'c' && key.ctrl) {\n // Exceptions thrown in hooks aren't caught by our errorHandler.\n exit()\n }\n}\n"]}
@@ -1 +1 @@
1
- export declare const CLI_KIT_VERSION = "3.51.1";
1
+ export declare const CLI_KIT_VERSION = "3.52.0";
@@ -1,2 +1,2 @@
1
- export const CLI_KIT_VERSION = '3.51.1';
1
+ export const CLI_KIT_VERSION = '3.52.0';
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,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.51.1'\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.52.0'\n"]}
@@ -9,6 +9,21 @@ import { AdminSession } from '../session.js';
9
9
  * @returns The response of the query of generic type <T>.
10
10
  */
11
11
  export declare function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T>;
12
+ /**
13
+ * GraphQL query to retrieve all supported API versions.
14
+ *
15
+ * @param session - Shopify admin session including token and Store FQDN.
16
+ * @returns - An array of supported API versions.
17
+ */
18
+ export declare function supportedApiVersions(session: AdminSession): Promise<string[]>;
19
+ /**
20
+ * Returns the Admin API URL for the given store and version.
21
+ *
22
+ * @param store - Store FQDN.
23
+ * @param version - API version.
24
+ * @returns - Admin API URL.
25
+ */
26
+ export declare function adminUrl(store: string, version: string | undefined): string;
12
27
  /**
13
28
  * Executes a REST request against the Admin API.
14
29
  *
@@ -14,7 +14,7 @@ import { ClientError, gql } from 'graphql-request';
14
14
  */
15
15
  export async function adminRequest(query, session, variables) {
16
16
  const api = 'Admin';
17
- const version = await fetchApiVersion(session);
17
+ const version = await fetchLatestSupportedApiVersion(session);
18
18
  const url = adminUrl(session.storeFqdn, version);
19
19
  return graphqlRequest({ query, api, url, token: session.token, variables });
20
20
  }
@@ -24,7 +24,30 @@ export async function adminRequest(query, session, variables) {
24
24
  * @param session - Shopify admin session including token and Store FQDN.
25
25
  * @returns - The latest supported API version.
26
26
  */
27
- async function fetchApiVersion(session) {
27
+ async function fetchLatestSupportedApiVersion(session) {
28
+ const apiVersions = await supportedApiVersions(session);
29
+ return apiVersions.reverse()[0];
30
+ }
31
+ /**
32
+ * GraphQL query to retrieve all supported API versions.
33
+ *
34
+ * @param session - Shopify admin session including token and Store FQDN.
35
+ * @returns - An array of supported API versions.
36
+ */
37
+ export async function supportedApiVersions(session) {
38
+ const apiVersions = await fetchApiVersions(session);
39
+ return apiVersions
40
+ .filter((item) => item.supported)
41
+ .map((item) => item.handle)
42
+ .sort();
43
+ }
44
+ /**
45
+ * GraphQL query to retrieve all API versions.
46
+ *
47
+ * @param session - Shopify admin session including token and Store FQDN.
48
+ * @returns - An array of supported and unsupported API versions.
49
+ */
50
+ async function fetchApiVersions(session) {
28
51
  const url = adminUrl(session.storeFqdn, 'unstable');
29
52
  const query = apiVersionQuery();
30
53
  try {
@@ -36,11 +59,7 @@ async function fetchApiVersion(session) {
36
59
  variables: {},
37
60
  responseOptions: { handleErrors: false },
38
61
  });
39
- return data.publicApiVersions
40
- .filter((item) => item.supported)
41
- .map((item) => item.handle)
42
- .sort()
43
- .reverse()[0];
62
+ return data.publicApiVersions;
44
63
  }
45
64
  catch (error) {
46
65
  if (error instanceof ClientError && error.response.status === 403) {
@@ -57,7 +76,7 @@ async function fetchApiVersion(session) {
57
76
  * @param version - API version.
58
77
  * @returns - Admin API URL.
59
78
  */
60
- function adminUrl(store, version) {
79
+ export function adminUrl(store, version) {
61
80
  const realVersion = version || 'unstable';
62
81
  return `https://${store}/admin/api/${realVersion}/graphql.json`;
63
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"admin.js","sourceRoot":"","sources":["../../../../src/public/node/api/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAmB,MAAM,cAAc,CAAA;AAE7D,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,gCAAgC,CAAA;AACzE,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,aAAa,CAAA;AAChD,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAC,MAAM,mCAAmC,CAAA;AACrG,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,WAAW,EAAE,GAAG,EAAC,MAAM,iBAAiB,CAAA;AAEhD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,KA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from '../session.js'\nimport {outputContent, outputToken} from '../../../public/node/output.js'\nimport {BugError, AbortError} from '../error.js'\nimport {restRequestBody, restRequestHeaders, restRequestUrl} from '../../../private/node/api/rest.js'\nimport {fetch} from '../http.js'\nimport {ClientError, gql} from 'graphql-request'\n\n/**\n * Executes a GraphQL query against the Admin API.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {\n const api = 'Admin'\n const version = await fetchApiVersion(session)\n const url = adminUrl(session.storeFqdn, version)\n return graphqlRequest({query, api, url, token: session.token, variables})\n}\n\n/**\n * GraphQL query to retrieve the latest supported API version.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - The latest supported API version.\n */\nasync function fetchApiVersion(session: AdminSession): Promise<string> {\n const url = adminUrl(session.storeFqdn, 'unstable')\n const query = apiVersionQuery()\n try {\n const data: ApiVersionResponse = await graphqlRequest({\n query,\n api: 'Admin',\n url,\n token: session.token,\n variables: {},\n responseOptions: {handleErrors: false},\n })\n\n return data.publicApiVersions\n .filter((item) => item.supported)\n .map((item) => item.handle)\n .sort()\n .reverse()[0]!\n } catch (error) {\n if (error instanceof ClientError && error.response.status === 403) {\n const storeName = session.storeFqdn.replace('.myshopify.com', '')\n throw new AbortError(\n outputContent`Looks like you don't have access this dev store: (${outputToken.link(\n storeName,\n `https://${session.storeFqdn}`,\n )})`,\n outputContent`If you're not the owner, create a dev store staff account for yourself`,\n )\n }\n throw new BugError(`Unknown error connecting to your store`)\n }\n}\n\n/**\n * Returns the Admin API URL for the given store and version.\n *\n * @param store - Store FQDN.\n * @param version - API version.\n * @returns - Admin API URL.\n */\nfunction adminUrl(store: string, version: string | undefined): string {\n const realVersion = version || 'unstable'\n return `https://${store}/admin/api/${realVersion}/graphql.json`\n}\n\ninterface ApiVersionResponse {\n publicApiVersions: {handle: string; supported: boolean}[]\n}\n\n/**\n * GraphQL query string to retrieve the latest supported API version.\n *\n * @returns - A query string.\n */\nfunction apiVersionQuery(): string {\n return gql`\n query {\n publicApiVersions {\n handle\n supported\n }\n }\n `\n}\n\n/**\n * Executes a REST request against the Admin API.\n *\n * @param method - Request's HTTP method.\n * @param path - Path of the REST resource.\n * @param session - Shopify Admin session including token and Store FQDN.\n * @param requestBody - Request body of including REST resource specific parameters.\n * @param searchParams - Search params, appended to the URL.\n * @param apiVersion - Admin API version.\n * @returns - The {@link RestResponse}.\n */\nexport async function restRequest<T>(\n method: string,\n path: string,\n session: AdminSession,\n requestBody?: T,\n searchParams: {[name: string]: string} = {},\n apiVersion = 'unstable',\n): Promise<RestResponse> {\n const url = restRequestUrl(session, apiVersion, path, searchParams)\n const body = restRequestBody<T>(requestBody)\n\n const headers = restRequestHeaders(session)\n const response = await fetch(url, {\n headers,\n method,\n body,\n })\n\n const json = await response.json().catch(() => ({}))\n\n return {\n json,\n status: response.status,\n headers: response.headers.raw(),\n }\n}\n\n/**\n * Respose of a REST request.\n */\nexport interface RestResponse {\n /**\n * REST JSON respose.\n */\n // Using `any` to avoid introducing extra DTO layers.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n json: any\n\n /**\n * HTTP response status.\n */\n status: number\n\n /**\n * HTTP response headers.\n */\n headers: {[key: string]: string[]}\n}\n"]}
1
+ {"version":3,"file":"admin.js","sourceRoot":"","sources":["../../../../src/public/node/api/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAmB,MAAM,cAAc,CAAA;AAE7D,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,gCAAgC,CAAA;AACzE,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,aAAa,CAAA;AAChD,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAC,MAAM,mCAAmC,CAAA;AACrG,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;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AAkB,CAAC,OAAO,CAAC,CAAA;IAC3C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,OAAO;QACP,MAAM;QACN,IAAI;KACL,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEpD,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {graphqlRequest, GraphQLVariables} from './graphql.js'\nimport {AdminSession} from '../session.js'\nimport {outputContent, outputToken} from '../../../public/node/output.js'\nimport {BugError, AbortError} from '../error.js'\nimport {restRequestBody, restRequestHeaders, restRequestUrl} from '../../../private/node/api/rest.js'\nimport {fetch} from '../http.js'\nimport {ClientError, gql} from 'graphql-request'\n\n/**\n * Executes a GraphQL query against the Admin API.\n *\n * @param query - GraphQL query to execute.\n * @param session - Shopify admin session including token and Store FQDN.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T> {\n const api = 'Admin'\n const version = await fetchLatestSupportedApiVersion(session)\n const url = adminUrl(session.storeFqdn, version)\n return graphqlRequest({query, api, url, token: session.token, variables})\n}\n\n/**\n * GraphQL query to retrieve the latest supported API version.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - The latest supported API version.\n */\nasync function fetchLatestSupportedApiVersion(session: AdminSession): Promise<string> {\n const apiVersions = await supportedApiVersions(session)\n return apiVersions.reverse()[0]!\n}\n\n/**\n * GraphQL query to retrieve all supported API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported API versions.\n */\nexport async function supportedApiVersions(session: AdminSession): Promise<string[]> {\n const apiVersions = await fetchApiVersions(session)\n return apiVersions\n .filter((item) => item.supported)\n .map((item) => item.handle)\n .sort()\n}\n\n/**\n * GraphQL query to retrieve all API versions.\n *\n * @param session - Shopify admin session including token and Store FQDN.\n * @returns - An array of supported and unsupported API versions.\n */\nasync function fetchApiVersions(session: AdminSession): Promise<ApiVersion[]> {\n const url = adminUrl(session.storeFqdn, 'unstable')\n const query = apiVersionQuery()\n try {\n const data: ApiVersionResponse = await graphqlRequest({\n query,\n api: 'Admin',\n url,\n token: session.token,\n variables: {},\n responseOptions: {handleErrors: false},\n })\n\n return data.publicApiVersions\n } catch (error) {\n if (error instanceof ClientError && error.response.status === 403) {\n const storeName = session.storeFqdn.replace('.myshopify.com', '')\n throw new AbortError(\n outputContent`Looks like you don't have access this dev store: (${outputToken.link(\n storeName,\n `https://${session.storeFqdn}`,\n )})`,\n outputContent`If you're not the owner, create a dev store staff account for yourself`,\n )\n }\n throw new BugError(`Unknown error connecting to your store`)\n }\n}\n\n/**\n * Returns the Admin API URL for the given store and version.\n *\n * @param store - Store FQDN.\n * @param version - API version.\n * @returns - Admin API URL.\n */\nexport function adminUrl(store: string, version: string | undefined): string {\n const realVersion = version || 'unstable'\n return `https://${store}/admin/api/${realVersion}/graphql.json`\n}\n\ninterface ApiVersion {\n handle: string\n supported: boolean\n}\n\ninterface ApiVersionResponse {\n publicApiVersions: ApiVersion[]\n}\n\n/**\n * GraphQL query string to retrieve the latest supported API version.\n *\n * @returns - A query string.\n */\nfunction apiVersionQuery(): string {\n return gql`\n query {\n publicApiVersions {\n handle\n supported\n }\n }\n `\n}\n\n/**\n * Executes a REST request against the Admin API.\n *\n * @param method - Request's HTTP method.\n * @param path - Path of the REST resource.\n * @param session - Shopify Admin session including token and Store FQDN.\n * @param requestBody - Request body of including REST resource specific parameters.\n * @param searchParams - Search params, appended to the URL.\n * @param apiVersion - Admin API version.\n * @returns - The {@link RestResponse}.\n */\nexport async function restRequest<T>(\n method: string,\n path: string,\n session: AdminSession,\n requestBody?: T,\n searchParams: {[name: string]: string} = {},\n apiVersion = 'unstable',\n): Promise<RestResponse> {\n const url = restRequestUrl(session, apiVersion, path, searchParams)\n const body = restRequestBody<T>(requestBody)\n\n const headers = restRequestHeaders(session)\n const response = await fetch(url, {\n headers,\n method,\n body,\n })\n\n const json = await response.json().catch(() => ({}))\n\n return {\n json,\n status: response.status,\n headers: response.headers.raw(),\n }\n}\n\n/**\n * Respose of a REST request.\n */\nexport interface RestResponse {\n /**\n * REST JSON respose.\n */\n // Using `any` to avoid introducing extra DTO layers.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n json: any\n\n /**\n * HTTP response status.\n */\n status: number\n\n /**\n * HTTP response headers.\n */\n headers: {[key: string]: string[]}\n}\n"]}
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  import { FatalError as Fatal } from './error.js';
2
3
  import { Logger, LogLevel } from './output.js';
3
4
  import { ConcurrentOutputProps } from '../../private/node/ui/components/ConcurrentOutput.js';
@@ -16,6 +17,10 @@ import { InfoTableSection } from '../../private/node/ui/components/Prompts/InfoT
16
17
  import { InfoMessageProps } from '../../private/node/ui/components/Prompts/InfoMessage.js';
17
18
  import { Key as InkKey, RenderOptions } from 'ink';
18
19
  type PartialBy<T, TKey extends keyof T> = Omit<T, TKey> & Partial<Pick<T, TKey>>;
20
+ interface UIDebugOptions {
21
+ /** If true, don't check if the current terminal is interactive or not */
22
+ skipTTYCheck: boolean;
23
+ }
19
24
  export interface RenderConcurrentOptions extends PartialBy<ConcurrentOutputProps, 'abortSignal'> {
20
25
  renderOptions?: RenderOptions;
21
26
  }
@@ -30,7 +35,7 @@ export interface RenderConcurrentOptions extends PartialBy<ConcurrentOutputProps
30
35
  * 00:00:00 │ frontend │ third frontend message
31
36
  *
32
37
  */
33
- export declare function renderConcurrent({ renderOptions, ...props }: RenderConcurrentOptions): Promise<void>;
38
+ export declare function renderConcurrent({ renderOptions, ...props }: RenderConcurrentOptions): Promise<unknown>;
34
39
  export type AlertCustomSection = CustomSection;
35
40
  export type RenderAlertOptions = Omit<AlertOptions, 'type'>;
36
41
  /**
@@ -223,7 +228,7 @@ export interface RenderSelectPromptOptions<T> extends Omit<SelectPromptProps<T>,
223
228
  * Press ↑↓ arrows to select, enter to confirm.
224
229
  *
225
230
  */
226
- export declare function renderSelectPrompt<T>({ renderOptions, isConfirmationPrompt, ...props }: RenderSelectPromptOptions<T>): Promise<T>;
231
+ export declare function renderSelectPrompt<T>({ renderOptions, isConfirmationPrompt, ...props }: RenderSelectPromptOptions<T>, uiDebugOptions?: UIDebugOptions): Promise<T>;
227
232
  export interface RenderConfirmationPromptOptions extends Pick<SelectPromptProps<boolean>, 'message' | 'infoTable' | 'infoMessage' | 'gitDiff' | 'abortSignal'> {
228
233
  confirmationMessage?: string;
229
234
  cancellationMessage?: string;
@@ -291,7 +296,7 @@ export interface RenderAutocompleteOptions<T> extends PartialBy<Omit<Autocomplet
291
296
  * Press ↑↓ arrows to select, enter to confirm.
292
297
  *
293
298
  */
294
- export declare function renderAutocompletePrompt<T>({ renderOptions, ...props }: RenderAutocompleteOptions<T>): Promise<T>;
299
+ export declare function renderAutocompletePrompt<T>({ renderOptions, ...props }: RenderAutocompleteOptions<T>, uiDebugOptions?: UIDebugOptions): Promise<T>;
295
300
  interface RenderTableOptions<T extends ScalarDict> extends TableProps<T> {
296
301
  renderOptions?: RenderOptions;
297
302
  }
@@ -326,7 +331,7 @@ export interface RenderTextPromptOptions extends Omit<TextPromptProps, 'onSubmit
326
331
  * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
327
332
  *
328
333
  */
329
- export declare function renderTextPrompt({ renderOptions, ...props }: RenderTextPromptOptions): Promise<string>;
334
+ export declare function renderTextPrompt({ renderOptions, ...props }: RenderTextPromptOptions, uiDebugOptions?: UIDebugOptions): Promise<string>;
330
335
  export interface RenderDangerousConfirmationPromptOptions extends Omit<DangerousConfirmationPromptProps, 'onSubmit'> {
331
336
  renderOptions?: RenderOptions;
332
337
  }
@@ -353,7 +358,7 @@ export interface RenderDangerousConfirmationPromptOptions extends Omit<Dangerous
353
358
  * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
354
359
  *
355
360
  */
356
- export declare function renderDangerousConfirmationPrompt({ renderOptions, ...props }: RenderDangerousConfirmationPromptOptions): Promise<boolean>;
361
+ export declare function renderDangerousConfirmationPrompt({ renderOptions, ...props }: RenderDangerousConfirmationPromptOptions, uiDebugOptions?: UIDebugOptions): Promise<boolean>;
357
362
  interface RenderTextOptions {
358
363
  text: string;
359
364
  logLevel?: LogLevel;
@@ -367,7 +372,9 @@ interface RenderTextOptions {
367
372
  */
368
373
  export declare function renderText({ text, logLevel, logger }: RenderTextOptions): string;
369
374
  /** Waits for any key to be pressed except Ctrl+C which will terminate the process. */
370
- export declare const keypress: () => Promise<unknown>;
375
+ export declare const keypress: (stdin?: NodeJS.ReadStream & {
376
+ fd: 0;
377
+ }, uiDebugOptions?: UIDebugOptions) => Promise<unknown>;
371
378
  export type Key = InkKey;
372
379
  export type InfoMessage = InfoMessageProps['message'];
373
380
  export { Task, TokenItem, InlineToken, LinkToken, TableColumn, InfoTableSection, ListToken, render, handleCtrlC };
@@ -18,6 +18,9 @@ import { TextPrompt } from '../../private/node/ui/components/TextPrompt.js';
18
18
  import { AutocompletePrompt } from '../../private/node/ui/components/AutocompletePrompt.js';
19
19
  import { recordUIEvent, resetRecordedSleep } from '../../private/node/demo-recorder.js';
20
20
  import React from 'react';
21
+ const defaultUIDebugOptions = {
22
+ skipTTYCheck: false,
23
+ };
21
24
  /**
22
25
  * Renders output from concurrent processes to the terminal with {@link ConcurrentOutput}.
23
26
  * @example
@@ -231,21 +234,26 @@ export function renderFatalError(error, { renderOptions } = {}) {
231
234
  * Press ↑↓ arrows to select, enter to confirm.
232
235
  *
233
236
  */
234
- export async function renderSelectPrompt({ renderOptions, isConfirmationPrompt, ...props }) {
235
- throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin });
237
+ // eslint-disable-next-line max-params
238
+ export async function renderSelectPrompt({ renderOptions, isConfirmationPrompt, ...props }, uiDebugOptions = defaultUIDebugOptions) {
239
+ throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin }, uiDebugOptions);
236
240
  if (!isConfirmationPrompt) {
237
241
  recordUIEvent({ type: 'selectPrompt', properties: { renderOptions, ...props } });
238
242
  }
239
- return runWithTimer('cmd_all_timing_prompts_ms')(() => {
240
- // eslint-disable-next-line max-params
241
- return new Promise((resolve, reject) => {
242
- render(React.createElement(SelectPrompt, { ...props, onSubmit: (value) => resolve(value) }), {
243
+ return runWithTimer('cmd_all_timing_prompts_ms')(async () => {
244
+ let selectedValue;
245
+ try {
246
+ await render(React.createElement(SelectPrompt, { ...props, onSubmit: (value) => {
247
+ selectedValue = value;
248
+ } }), {
243
249
  ...renderOptions,
244
250
  exitOnCtrlC: false,
245
- })
246
- .catch(reject)
247
- .finally(resetRecordedSleep);
248
- });
251
+ });
252
+ return selectedValue;
253
+ }
254
+ finally {
255
+ resetRecordedSleep();
256
+ }
249
257
  });
250
258
  }
251
259
  /**
@@ -332,8 +340,9 @@ export async function renderConfirmationPrompt({ message, infoTable, gitDiff, co
332
340
  * Press ↑↓ arrows to select, enter to confirm.
333
341
  *
334
342
  */
335
- export async function renderAutocompletePrompt({ renderOptions, ...props }) {
336
- throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin });
343
+ // eslint-disable-next-line max-params
344
+ export async function renderAutocompletePrompt({ renderOptions, ...props }, uiDebugOptions = defaultUIDebugOptions) {
345
+ throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin }, uiDebugOptions);
337
346
  // eslint-disable-next-line prefer-rest-params
338
347
  recordUIEvent({ type: 'autocompletePrompt', properties: arguments[0] });
339
348
  const newProps = {
@@ -347,16 +356,20 @@ export async function renderAutocompletePrompt({ renderOptions, ...props }) {
347
356
  },
348
357
  ...props,
349
358
  };
350
- return runWithTimer('cmd_all_timing_prompts_ms')(() => {
351
- // eslint-disable-next-line max-params
352
- return new Promise((resolve, reject) => {
353
- render(React.createElement(AutocompletePrompt, { ...newProps, onSubmit: (value) => resolve(value) }), {
359
+ return runWithTimer('cmd_all_timing_prompts_ms')(async () => {
360
+ let selectedValue;
361
+ try {
362
+ await render(React.createElement(AutocompletePrompt, { ...newProps, onSubmit: (value) => {
363
+ selectedValue = value;
364
+ } }), {
354
365
  ...renderOptions,
355
366
  exitOnCtrlC: false,
356
- })
357
- .catch(reject)
358
- .finally(resetRecordedSleep);
359
- });
367
+ });
368
+ return selectedValue;
369
+ }
370
+ finally {
371
+ resetRecordedSleep();
372
+ }
360
373
  });
361
374
  }
362
375
  /**
@@ -409,20 +422,25 @@ export async function renderTasks(tasks, { renderOptions } = {}) {
409
422
  * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
410
423
  *
411
424
  */
412
- export async function renderTextPrompt({ renderOptions, ...props }) {
413
- throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin });
425
+ // eslint-disable-next-line max-params
426
+ export async function renderTextPrompt({ renderOptions, ...props }, uiDebugOptions = defaultUIDebugOptions) {
427
+ throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin }, uiDebugOptions);
414
428
  // eslint-disable-next-line prefer-rest-params
415
429
  recordUIEvent({ type: 'textPrompt', properties: arguments[0] });
416
- return runWithTimer('cmd_all_timing_prompts_ms')(() => {
417
- // eslint-disable-next-line max-params
418
- return new Promise((resolve, reject) => {
419
- render(React.createElement(TextPrompt, { ...props, onSubmit: (value) => resolve(value) }), {
430
+ return runWithTimer('cmd_all_timing_prompts_ms')(async () => {
431
+ let enteredText = '';
432
+ try {
433
+ await render(React.createElement(TextPrompt, { ...props, onSubmit: (value) => {
434
+ enteredText = value;
435
+ } }), {
420
436
  ...renderOptions,
421
437
  exitOnCtrlC: false,
422
- })
423
- .catch(reject)
424
- .finally(resetRecordedSleep);
425
- });
438
+ });
439
+ return enteredText;
440
+ }
441
+ finally {
442
+ resetRecordedSleep();
443
+ }
426
444
  });
427
445
  }
428
446
  /**
@@ -448,20 +466,25 @@ export async function renderTextPrompt({ renderOptions, ...props }) {
448
466
  * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
449
467
  *
450
468
  */
451
- export async function renderDangerousConfirmationPrompt({ renderOptions, ...props }) {
452
- throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin });
469
+ // eslint-disable-next-line max-params
470
+ export async function renderDangerousConfirmationPrompt({ renderOptions, ...props }, uiDebugOptions = defaultUIDebugOptions) {
471
+ throwInNonTTY({ message: props.message, stdin: renderOptions?.stdin }, uiDebugOptions);
453
472
  // eslint-disable-next-line prefer-rest-params
454
473
  recordUIEvent({ type: 'dangerousConfirmationPrompt', properties: arguments[0] });
455
- return runWithTimer('cmd_all_timing_prompts_ms')(() => {
456
- // eslint-disable-next-line max-params
457
- return new Promise((resolve, reject) => {
458
- render(React.createElement(DangerousConfirmationPrompt, { ...props, onSubmit: (value) => resolve(value) }), {
474
+ return runWithTimer('cmd_all_timing_prompts_ms')(async () => {
475
+ let confirmed;
476
+ try {
477
+ await render(React.createElement(DangerousConfirmationPrompt, { ...props, onSubmit: (value) => {
478
+ confirmed = value;
479
+ } }), {
459
480
  ...renderOptions,
460
481
  exitOnCtrlC: false,
461
- })
462
- .catch(reject)
463
- .finally(resetRecordedSleep);
464
- });
482
+ });
483
+ return confirmed;
484
+ }
485
+ finally {
486
+ resetRecordedSleep();
487
+ }
465
488
  });
466
489
  }
467
490
  /** Renders a text string to the console.
@@ -480,29 +503,33 @@ export function renderText({ text, logLevel = 'info', logger = consoleLog }) {
480
503
  return textWithLineReturn;
481
504
  }
482
505
  /** Waits for any key to be pressed except Ctrl+C which will terminate the process. */
483
- export const keypress = async () => {
484
- throwInNonTTY({ message: 'Press any key' });
506
+ // eslint-disable-next-line max-params
507
+ export const keypress = async (stdin = process.stdin, uiDebugOptions = defaultUIDebugOptions) => {
508
+ throwInNonTTY({ message: 'Press any key' }, uiDebugOptions);
485
509
  return runWithTimer('cmd_all_timing_prompts_ms')(() => {
486
510
  // eslint-disable-next-line max-params
487
511
  return new Promise((resolve, reject) => {
488
512
  const handler = (buffer) => {
489
- process.stdin.setRawMode(false);
490
- process.stdin.pause();
513
+ stdin.setRawMode(false);
491
514
  const bytes = Array.from(buffer);
492
515
  if (bytes.length && bytes[0] === 3) {
493
516
  outputDebug('Canceled keypress, User pressed CTRL+C');
494
517
  reject(new AbortSilentError());
495
518
  }
519
+ stdin.unref();
496
520
  process.nextTick(resolve);
497
521
  };
498
- process.stdin.resume();
499
- process.stdin.setRawMode(true);
500
- process.stdin.once('data', handler);
522
+ stdin.setRawMode(true);
523
+ stdin.once('data', handler);
524
+ // We want to indicate that we're still using stdin, so that the process
525
+ // doesn't exit early.
526
+ stdin.ref();
501
527
  });
502
528
  });
503
529
  };
504
- function throwInNonTTY({ message, stdin = undefined }) {
505
- if (stdin || terminalSupportsRawMode())
530
+ // eslint-disable-next-line max-params
531
+ function throwInNonTTY({ message, stdin = undefined }, uiDebugOptions) {
532
+ if (uiDebugOptions.skipTTYCheck || stdin || terminalSupportsRawMode())
506
533
  return;
507
534
  const promptText = tokenItemToString(message);
508
535
  const errorMessage = `Failed to prompt: