@shopify/cli-kit 3.37.0 → 3.39.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.
Files changed (191) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/private/common/json.d.ts +2 -2
  5. package/dist/private/common/lodash.d.ts +4 -4
  6. package/dist/private/common/ts/overloaded-parameters.d.ts +5 -5
  7. package/dist/private/node/api/graphql.js +7 -7
  8. package/dist/private/node/api/graphql.js.map +1 -1
  9. package/dist/private/node/api/headers.d.ts +1 -1
  10. package/dist/private/node/api.d.ts +2 -0
  11. package/dist/{network → private/node}/api.js +0 -0
  12. package/dist/private/node/api.js.map +1 -0
  13. package/dist/private/node/conf-store.js +4 -4
  14. package/dist/private/node/conf-store.js.map +1 -1
  15. package/dist/private/node/constants.d.ts +2 -2
  16. package/dist/{content-tokens.d.ts → private/node/content-tokens.d.ts} +11 -11
  17. package/dist/{content-tokens.js → private/node/content-tokens.js} +3 -3
  18. package/dist/private/node/content-tokens.js.map +1 -0
  19. package/dist/private/node/environment/service.d.ts +1 -1
  20. package/dist/private/node/error-handler.d.ts +2 -0
  21. package/dist/private/node/error-handler.js +5 -0
  22. package/dist/private/node/error-handler.js.map +1 -0
  23. package/dist/private/node/secure-store.js +4 -4
  24. package/dist/private/node/secure-store.js.map +1 -1
  25. package/dist/private/node/session/authorize.js +3 -3
  26. package/dist/private/node/session/authorize.js.map +1 -1
  27. package/dist/private/node/session/device-authorization.js +6 -6
  28. package/dist/private/node/session/device-authorization.js.map +1 -1
  29. package/dist/private/node/session/exchange.d.ts +1 -1
  30. package/dist/private/node/session/exchange.js.map +1 -1
  31. package/dist/private/node/session/identity-token-validation.js +5 -5
  32. package/dist/private/node/session/identity-token-validation.js.map +1 -1
  33. package/dist/private/node/session/identity.d.ts +1 -1
  34. package/dist/private/node/session/identity.js.map +1 -1
  35. package/dist/private/node/session/redirect-listener.d.ts +1 -1
  36. package/dist/private/node/session/redirect-listener.js +7 -7
  37. package/dist/private/node/session/redirect-listener.js.map +1 -1
  38. package/dist/private/node/session/schema.d.ts +3 -3
  39. package/dist/private/node/session/scopes.d.ts +1 -1
  40. package/dist/private/node/session/scopes.js +1 -1
  41. package/dist/private/node/session/scopes.js.map +1 -1
  42. package/dist/private/node/session/store.js +4 -4
  43. package/dist/private/node/session/store.js.map +1 -1
  44. package/dist/private/node/session/validate.d.ts +1 -1
  45. package/dist/private/node/session/validate.js +2 -2
  46. package/dist/private/node/session/validate.js.map +1 -1
  47. package/dist/private/node/session.d.ts +4 -4
  48. package/dist/private/node/session.js +19 -19
  49. package/dist/private/node/session.js.map +1 -1
  50. package/dist/private/node/ui/alert.js +1 -1
  51. package/dist/private/node/ui/alert.js.map +1 -1
  52. package/dist/private/node/ui/components/Alert.test.js +1 -1
  53. package/dist/private/node/ui/components/Alert.test.js.map +1 -1
  54. package/dist/private/node/ui/components/AutocompletePrompt.d.ts +9 -2
  55. package/dist/private/node/ui/components/AutocompletePrompt.js +8 -4
  56. package/dist/private/node/ui/components/AutocompletePrompt.js.map +1 -1
  57. package/dist/private/node/ui/components/AutocompletePrompt.test.js +62 -8
  58. package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
  59. package/dist/private/node/ui/components/Banner.d.ts +1 -1
  60. package/dist/private/node/ui/components/ConcurrentOutput.d.ts +3 -3
  61. package/dist/private/node/ui/components/ConcurrentOutput.js.map +1 -1
  62. package/dist/private/node/ui/components/ConcurrentOutput.test.js +1 -1
  63. package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
  64. package/dist/private/node/ui/components/FatalError.test.js +1 -1
  65. package/dist/private/node/ui/components/FatalError.test.js.map +1 -1
  66. package/dist/private/node/ui/components/List.test.js +1 -1
  67. package/dist/private/node/ui/components/List.test.js.map +1 -1
  68. package/dist/private/node/ui/components/SelectInput.d.ts +3 -1
  69. package/dist/private/node/ui/components/SelectInput.js +8 -2
  70. package/dist/private/node/ui/components/SelectInput.js.map +1 -1
  71. package/dist/private/node/ui/components/SelectInput.test.js +26 -0
  72. package/dist/private/node/ui/components/SelectInput.test.js.map +1 -1
  73. package/dist/private/node/ui/components/SelectPrompt.test.js +1 -1
  74. package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
  75. package/dist/private/node/ui/components/Table/Row.d.ts +1 -1
  76. package/dist/private/node/ui/components/Table/ScalarDict.d.ts +1 -1
  77. package/dist/private/node/ui/components/Table/Table.d.ts +1 -1
  78. package/dist/private/node/ui/components/Tasks.d.ts +5 -1
  79. package/dist/private/node/ui/components/Tasks.js +31 -6
  80. package/dist/private/node/ui/components/Tasks.js.map +1 -1
  81. package/dist/private/node/ui/components/Tasks.test.js +260 -20
  82. package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
  83. package/dist/private/node/ui/components/TextPrompt.test.js +1 -1
  84. package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
  85. package/dist/private/node/ui/components/TokenizedText.d.ts +2 -2
  86. package/dist/private/node/ui/components/TokenizedText.test.js +1 -1
  87. package/dist/private/node/ui/components/TokenizedText.test.js.map +1 -1
  88. package/dist/private/node/ui.d.ts +2 -2
  89. package/dist/private/node/ui.js +1 -1
  90. package/dist/private/node/ui.js.map +1 -1
  91. package/dist/public/common/string.d.ts +1 -1
  92. package/dist/public/common/string.js +1 -1
  93. package/dist/public/common/string.js.map +1 -1
  94. package/dist/{private → public}/common/ts/deep-required.d.ts +2 -1
  95. package/dist/{private → public}/common/ts/deep-required.js +0 -0
  96. package/dist/public/common/ts/deep-required.js.map +1 -0
  97. package/dist/public/common/ts/pick-by-prefix.d.ts +2 -1
  98. package/dist/public/common/ts/pick-by-prefix.js.map +1 -1
  99. package/dist/public/common/version.d.ts +1 -1
  100. package/dist/public/common/version.js +1 -1
  101. package/dist/public/common/version.js.map +1 -1
  102. package/dist/public/node/analytics.js +5 -5
  103. package/dist/public/node/analytics.js.map +1 -1
  104. package/dist/public/node/api/admin.js +2 -2
  105. package/dist/public/node/api/admin.js.map +1 -1
  106. package/dist/public/node/api/http.d.ts +1 -0
  107. package/dist/public/node/api/http.js +1 -1
  108. package/dist/public/node/archiver.d.ts +20 -6
  109. package/dist/public/node/archiver.js +16 -15
  110. package/dist/public/node/archiver.js.map +1 -1
  111. package/dist/public/node/base-command.js +4 -4
  112. package/dist/public/node/base-command.js.map +1 -1
  113. package/dist/public/node/crypto.d.ts +1 -1
  114. package/dist/public/node/dot-env.js +4 -2
  115. package/dist/public/node/dot-env.js.map +1 -1
  116. package/dist/public/node/environment/local.d.ts +1 -1
  117. package/dist/public/node/environment/spin.d.ts +1 -1
  118. package/dist/public/node/environment/spin.js +2 -2
  119. package/dist/public/node/environment/spin.js.map +1 -1
  120. package/dist/public/node/error-handler.d.ts +1 -2
  121. package/dist/public/node/error-handler.js +15 -5
  122. package/dist/public/node/error-handler.js.map +1 -1
  123. package/dist/public/node/error.d.ts +5 -5
  124. package/dist/public/node/error.js +1 -1
  125. package/dist/public/node/error.js.map +1 -1
  126. package/dist/public/node/fs.d.ts +24 -4
  127. package/dist/public/node/fs.js +50 -21
  128. package/dist/public/node/fs.js.map +1 -1
  129. package/dist/public/node/git.d.ts +9 -1
  130. package/dist/public/node/git.js +39 -9
  131. package/dist/public/node/git.js.map +1 -1
  132. package/dist/public/node/github.js +2 -2
  133. package/dist/public/node/github.js.map +1 -1
  134. package/dist/public/node/hooks/postrun.js +2 -2
  135. package/dist/public/node/hooks/postrun.js.map +1 -1
  136. package/dist/public/node/hooks/prerun.js +2 -2
  137. package/dist/public/node/hooks/prerun.js.map +1 -1
  138. package/dist/public/node/http.d.ts +9 -1
  139. package/dist/public/node/http.js +37 -3
  140. package/dist/public/node/http.js.map +1 -1
  141. package/dist/public/node/liquid.js +2 -2
  142. package/dist/public/node/liquid.js.map +1 -1
  143. package/dist/public/node/metadata.d.ts +7 -7
  144. package/dist/public/node/monorail.d.ts +6 -6
  145. package/dist/public/node/monorail.js +4 -4
  146. package/dist/public/node/monorail.js.map +1 -1
  147. package/dist/public/node/node-package-manager.d.ts +5 -5
  148. package/dist/public/node/node-package-manager.js +9 -9
  149. package/dist/public/node/node-package-manager.js.map +1 -1
  150. package/dist/public/node/os.d.ts +2 -2
  151. package/dist/public/node/os.js +2 -2
  152. package/dist/public/node/os.js.map +1 -1
  153. package/dist/public/node/output.d.ts +188 -0
  154. package/dist/{output.js → public/node/output.js} +129 -50
  155. package/dist/public/node/output.js.map +1 -0
  156. package/dist/public/node/path.d.ts +1 -1
  157. package/dist/public/node/plugins/tunnel.d.ts +5 -5
  158. package/dist/public/node/plugins.d.ts +4 -4
  159. package/dist/public/node/result.d.ts +1 -1
  160. package/dist/public/node/ruby.d.ts +1 -1
  161. package/dist/public/node/ruby.js +7 -5
  162. package/dist/public/node/ruby.js.map +1 -1
  163. package/dist/public/node/session.d.ts +1 -1
  164. package/dist/public/node/session.js +9 -9
  165. package/dist/public/node/session.js.map +1 -1
  166. package/dist/public/node/system.d.ts +1 -1
  167. package/dist/public/node/system.js +2 -2
  168. package/dist/public/node/system.js.map +1 -1
  169. package/dist/public/node/tcp.js +4 -4
  170. package/dist/public/node/tcp.js.map +1 -1
  171. package/dist/public/node/testing/output.js +10 -9
  172. package/dist/public/node/testing/output.js.map +1 -1
  173. package/dist/public/node/ui.d.ts +11 -6
  174. package/dist/public/node/ui.js +5 -4
  175. package/dist/public/node/ui.js.map +1 -1
  176. package/dist/public/node/vscode.js +4 -4
  177. package/dist/public/node/vscode.js.map +1 -1
  178. package/dist/tsconfig.tsbuildinfo +1 -1
  179. package/dist/ui.d.ts +6 -20
  180. package/dist/ui.js +8 -28
  181. package/dist/ui.js.map +1 -1
  182. package/package.json +6 -7
  183. package/dist/content-tokens.js.map +0 -1
  184. package/dist/network/api.d.ts +0 -2
  185. package/dist/network/api.js.map +0 -1
  186. package/dist/output.d.ts +0 -129
  187. package/dist/output.js.map +0 -1
  188. package/dist/private/common/ts/deep-required.js.map +0 -1
  189. package/dist/private/node/simple-definitions.d.ts +0 -4
  190. package/dist/private/node/simple-definitions.js +0 -2
  191. package/dist/private/node/simple-definitions.js.map +0 -1
@@ -4,17 +4,17 @@ import { fanoutHooks } from './plugins.js';
4
4
  import * as metadata from './metadata.js';
5
5
  import { AbortSilentError, CancelExecution, errorMapper, shouldReportError, handler, cleanSingleStackTracePath, } from './error.js';
6
6
  import { getEnvironmentData } from '../../private/node/analytics.js';
7
- import { debug, info } from '../../output.js';
7
+ import { outputDebug, outputInfo } from '../../public/node/output.js';
8
8
  import { bugsnagApiKey } from '../../private/node/constants.js';
9
9
  import { CLI_KIT_VERSION } from '../common/version.js';
10
+ import { Bugsnag } from '../../private/node/error-handler.js';
10
11
  import { settings } from '@oclif/core';
11
12
  import StackTracey from 'stacktracey';
12
- import Bugsnag from '@bugsnag/js';
13
13
  import { realpath } from 'fs/promises';
14
14
  export function errorHandler(error, config) {
15
15
  if (error instanceof CancelExecution) {
16
16
  if (error.message && error.message !== '') {
17
- info(`✨ ${error.message}`);
17
+ outputInfo(`✨ ${error.message}`);
18
18
  }
19
19
  }
20
20
  else if (error instanceof AbortSilentError) {
@@ -81,6 +81,8 @@ export async function sendErrorToBugsnag(error) {
81
81
  if (report) {
82
82
  initializeBugsnag();
83
83
  await new Promise((resolve, reject) => {
84
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
85
+ // @ts-ignore
84
86
  Bugsnag.notify(reportableError, undefined, (error, event) => {
85
87
  if (error) {
86
88
  reject(error);
@@ -117,7 +119,6 @@ export function cleanStackFrameFilePath({ currentFilePath, projectRoot, pluginLo
117
119
  */
118
120
  export async function registerCleanBugsnagErrorsFromWithinPlugins(config) {
119
121
  // Bugsnag have their own plug-ins that use this private field
120
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
122
  const bugsnagConfigProjectRoot = Bugsnag?._client?._config?.projectRoot ?? path.cwd();
122
123
  const projectRoot = path.normalizePath(bugsnagConfigProjectRoot);
123
124
  const pluginLocations = await Promise.all(config.plugins.map(async (plugin) => {
@@ -125,8 +126,12 @@ export async function registerCleanBugsnagErrorsFromWithinPlugins(config) {
125
126
  return { name: plugin.name, pluginPath: path.normalizePath(followSymlinks) };
126
127
  }));
127
128
  initializeBugsnag();
129
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
130
+ // @ts-ignore
128
131
  Bugsnag.addOnError(async (event) => {
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
133
  event.errors.forEach((error) => {
134
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
135
  error.stacktrace.forEach((stackFrame) => {
131
136
  stackFrame.file = cleanStackFrameFilePath({ currentFilePath: stackFrame.file, projectRoot, pluginLocations });
132
137
  });
@@ -136,10 +141,11 @@ export async function registerCleanBugsnagErrorsFromWithinPlugins(config) {
136
141
  // eslint-disable-next-line no-catch-all/no-catch-all
137
142
  }
138
143
  catch (metadataError) {
139
- debug(`There was an error adding metadata to the Bugsnag report; Ignoring and carrying on ${metadataError}`);
144
+ outputDebug(`There was an error adding metadata to the Bugsnag report; Ignoring and carrying on ${metadataError}`);
140
145
  }
141
146
  });
142
147
  }
148
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
143
149
  export async function addBugsnagMetadata(event, config) {
144
150
  const publicData = metadata.getAllPublicMetadata();
145
151
  const { commandStartOptions } = metadata.getAllSensitiveMetadata();
@@ -186,9 +192,13 @@ export async function addBugsnagMetadata(event, config) {
186
192
  });
187
193
  }
188
194
  function initializeBugsnag() {
195
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
196
+ // @ts-ignore
189
197
  if (Bugsnag.isStarted()) {
190
198
  return;
191
199
  }
200
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
201
+ // @ts-ignore
192
202
  Bugsnag.start({
193
203
  appType: 'node',
194
204
  apiKey: bugsnagApiKey,
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/public/node/error-hand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,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,aAAa;QACrB,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,eAAe;QAC3B,iBAAiB,EAAE,KAAK;QACxB,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {reportAnalyticsEvent} from './analytics.js'\nimport * as path from './path.js'\nimport {fanoutHooks} from './plugins.js'\nimport * as metadata from './metadata.js'\nimport {\n AbortSilentError,\n CancelExecution,\n errorMapper,\n shouldReportError,\n handler,\n cleanSingleStackTracePath,\n} from './error.js'\nimport {getEnvironmentData} from '../../private/node/analytics.js'\nimport {debug, info} from '../../output.js'\nimport {bugsnagApiKey} from '../../private/node/constants.js'\nimport {CLI_KIT_VERSION} from '../common/version.js'\nimport {settings, Interfaces} from '@oclif/core'\nimport StackTracey from 'stacktracey'\nimport Bugsnag, {Event} from '@bugsnag/js'\nimport {realpath} from 'fs/promises'\n\nexport function errorHandler(\n error: (CancelExecution | AbortSilentError) & {exitCode?: number | undefined},\n config?: Interfaces.Config,\n): void\nexport function errorHandler(error: Error & {exitCode?: number | undefined}, config?: Interfaces.Config): Promise<void>\nexport function errorHandler(error: Error & {exitCode?: number | undefined}, config?: Interfaces.Config): unknown {\n if (error instanceof CancelExecution) {\n if (error.message && error.message !== '') {\n info(`✨ ${error.message}`)\n }\n } else if (error instanceof AbortSilentError) {\n process.exit(1)\n } else {\n return errorMapper(error)\n .then((error) => {\n return handler(error)\n })\n .then((mappedError) => reportError(mappedError, config))\n .then(() => {\n process.exit(1)\n })\n }\n}\n\nconst reportError = async (error: unknown, config?: Interfaces.Config): Promise<void> => {\n if (config !== undefined) {\n // Log an analytics event when there's an error\n await reportAnalyticsEvent({config, errorMessage: error instanceof Error ? error.message : undefined})\n }\n await sendErrorToBugsnag(error)\n}\n\n/**\n * Sends an error to Bugsnag. This is configured automatically for uncaught errors from CLI commands, but can also be used to manually record an error.\n *\n * @returns the reported error (this may have been tweaked for better reporting), and a bool to indicate if the error was actually submitted or not\n */\nexport async function sendErrorToBugsnag(\n error: unknown,\n): Promise<{reported: false; error: unknown} | {error: Error; reported: true}> {\n if (settings.debug || !shouldReportError(error)) return {reported: false, error}\n\n let reportableError: Error\n let stacktrace: string | undefined\n let report = false\n\n if (error instanceof Error) {\n report = true\n reportableError = new Error(error.message)\n stacktrace = error.stack\n\n /**\n * Some errors that reach this point have an empty string. For example:\n * https://app.bugsnag.com/shopify/cli/errors/62cd5d31fd5040000814086c?filters[event.since]=30d&filters[error.status]=new&filters[release.seen_in]=3.1.0\n *\n * Because at this point we have neither the error message nor a stack trace reporting them\n * to Bugsnag is pointless and adds noise.\n */\n } else if (typeof error === 'string' && error.trim().length !== 0) {\n report = true\n reportableError = new Error(error)\n stacktrace = reportableError.stack\n } else {\n report = false\n reportableError = new Error('Unknown error')\n }\n\n const formattedStacktrace = new StackTracey(stacktrace ?? '')\n .clean()\n .items.map((item) => {\n const filePath = cleanSingleStackTracePath(item.file)\n return ` at ${item.callee} (${filePath}:${item.line}:${item.column})`\n })\n .join('\\n')\n reportableError.stack = `Error: ${reportableError.message}\\n${formattedStacktrace}`\n\n if (report) {\n initializeBugsnag()\n await new Promise((resolve, reject) => {\n Bugsnag.notify(reportableError, undefined, (error, event) => {\n if (error) {\n reject(error)\n } else {\n resolve(reportableError)\n }\n })\n })\n }\n return {error: reportableError, reported: report}\n}\n\n/**\n * If the given file path is within a node_modules folder, remove prefix up\n * to and including the node_modules folder.\n *\n * This gives us very consistent paths for errors generated by the CLI.\n */\nexport function cleanStackFrameFilePath({\n currentFilePath,\n projectRoot,\n pluginLocations,\n}: {\n currentFilePath: string\n projectRoot: string\n pluginLocations: {name: string; pluginPath: string}[]\n}): string {\n const fullLocation = path.isAbsolutePath(currentFilePath)\n ? currentFilePath\n : path.joinPath(projectRoot, currentFilePath)\n\n const matchingPluginPath = pluginLocations.filter(({pluginPath}) => fullLocation.indexOf(pluginPath) === 0)[0]\n\n if (matchingPluginPath !== undefined) {\n // the plugin name (e.g. @shopify/cli-kit), plus the relative path of the error line from within the plugin's code (e.g. dist/something.js )\n return path.joinPath(matchingPluginPath.name, path.relativePath(matchingPluginPath.pluginPath, fullLocation))\n }\n\n // strip prefix up to node_modules folder, so we can normalize error reporting\n return currentFilePath.replace(/.*node_modules\\//, '')\n}\n\n/**\n * Register a Bugsnag error listener to clean up stack traces for errors within plugin code.\n *\n */\nexport async function registerCleanBugsnagErrorsFromWithinPlugins(config: Interfaces.Config): Promise<void> {\n // Bugsnag have their own plug-ins that use this private field\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const bugsnagConfigProjectRoot: string = (Bugsnag as any)?._client?._config?.projectRoot ?? path.cwd()\n const projectRoot = path.normalizePath(bugsnagConfigProjectRoot)\n const pluginLocations = await Promise.all(\n config.plugins.map(async (plugin) => {\n const followSymlinks = await realpath(plugin.root)\n return {name: plugin.name, pluginPath: path.normalizePath(followSymlinks)}\n }),\n )\n initializeBugsnag()\n Bugsnag.addOnError(async (event) => {\n event.errors.forEach((error) => {\n error.stacktrace.forEach((stackFrame) => {\n stackFrame.file = cleanStackFrameFilePath({currentFilePath: stackFrame.file, projectRoot, pluginLocations})\n })\n })\n try {\n await addBugsnagMetadata(event, config)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (metadataError) {\n debug(`There was an error adding metadata to the Bugsnag report; Ignoring and carrying on ${metadataError}`)\n }\n })\n}\n\nexport async function addBugsnagMetadata(event: Event, config: Interfaces.Config): Promise<void> {\n const publicData = metadata.getAllPublicMetadata()\n const {commandStartOptions} = metadata.getAllSensitiveMetadata()\n const {startCommand} = commandStartOptions ?? {}\n\n const {'@shopify/app': appPublic, ...otherPluginsPublic} = await fanoutHooks(config, 'public_command_metadata', {})\n\n const environment = await getEnvironmentData(config)\n\n const allMetadata = {\n command: startCommand,\n ...appPublic,\n ...publicData,\n ...environment,\n pluginData: otherPluginsPublic,\n }\n\n const appData = {} as {[key: string]: unknown}\n const commandData = {} as {[key: string]: unknown}\n const environmentData = {} as {[key: string]: unknown}\n const miscData = {} as {[key: string]: unknown}\n const appKeys = ['api_key', 'partner_id', 'project_type']\n const commandKeys = ['command']\n const environmentKeys = ['cli_version', 'node_version', 'ruby_version', 'uname']\n\n Object.entries(allMetadata).forEach(([key, value]) => {\n if (key.startsWith('app_') || appKeys.includes(key)) {\n appData[key] = value\n } else if (key.startsWith('cmd_') || commandKeys.includes(key)) {\n commandData[key] = value\n } else if (key.startsWith('env_') || environmentKeys) {\n environmentData[key] = value\n } else {\n miscData[key] = value\n }\n })\n\n // app, command, environment, misc\n const bugsnagMetadata = {\n 'Shopify App': appData,\n Command: commandData,\n Environment: environmentData,\n Misc: miscData,\n }\n Object.entries(bugsnagMetadata).forEach(([section, values]) => {\n event.addMetadata(section, values)\n })\n}\n\nfunction initializeBugsnag() {\n if (Bugsnag.isStarted()) {\n return\n }\n Bugsnag.start({\n appType: 'node',\n apiKey: bugsnagApiKey,\n logger: null,\n appVersion: CLI_KIT_VERSION,\n autoTrackSessions: false,\n autoDetectErrors: false,\n })\n}\n"]}
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/public/node/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,yBAAyB,GAC1B,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAC,aAAa,EAAC,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAC,eAAe,EAAC,MAA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AG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC9D,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SACzB;aAAM,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,eAAe,EAAE;YACpD,eAAe,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SAC7B;aAAM;YACL,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;SACtB;IACH,CAAC,CAAC,CAAA;IAEF,kCAAkC;IAClC,MAAM,eAAe,GAAG;QACtB,aAAa,EAAE,OAAO;QACtB,OAAO,EAAE,WAAW;QACpB,WAAW,EAAE,eAAe;QAC5B,IAAI,EAAE,QAAQ;KACf,CAAA;IACD,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE;QAC5D,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,iBAAiB;IACxB,6DAA6D;IAC7D,aAAa;IACb,IAAI,OAAO,CAAC,SAAS,EAAE,EAAE;QACvB,OAAM;KACP;IACD,6DAA6D;IAC7D,aAAa;IACb,OAAO,CAAC,KAAK,CAAC;QACZ,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,aAAa;QACrB,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,eAAe;QAC3B,iBAAiB,EAAE,KAAK;QACxB,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {reportAnalyticsEvent} from './analytics.js'\nimport * as path from './path.js'\nimport {fanoutHooks} from './plugins.js'\nimport * as metadata from './metadata.js'\nimport {\n AbortSilentError,\n CancelExecution,\n errorMapper,\n shouldReportError,\n handler,\n cleanSingleStackTracePath,\n} from './error.js'\nimport {getEnvironmentData} from '../../private/node/analytics.js'\nimport {outputDebug, outputInfo} from '../../public/node/output.js'\nimport {bugsnagApiKey} from '../../private/node/constants.js'\nimport {CLI_KIT_VERSION} from '../common/version.js'\nimport {Bugsnag} from '../../private/node/error-handler.js'\nimport {settings, Interfaces} from '@oclif/core'\nimport StackTracey from 'stacktracey'\nimport {realpath} from 'fs/promises'\n\nexport function errorHandler(\n error: (CancelExecution | AbortSilentError) & {exitCode?: number | undefined},\n config?: Interfaces.Config,\n): void\nexport function errorHandler(error: Error & {exitCode?: number | undefined}, config?: Interfaces.Config): Promise<void>\nexport function errorHandler(error: Error & {exitCode?: number | undefined}, config?: Interfaces.Config): unknown {\n if (error instanceof CancelExecution) {\n if (error.message && error.message !== '') {\n outputInfo(`✨ ${error.message}`)\n }\n } else if (error instanceof AbortSilentError) {\n process.exit(1)\n } else {\n return errorMapper(error)\n .then((error) => {\n return handler(error)\n })\n .then((mappedError) => reportError(mappedError, config))\n .then(() => {\n process.exit(1)\n })\n }\n}\n\nconst reportError = async (error: unknown, config?: Interfaces.Config): Promise<void> => {\n if (config !== undefined) {\n // Log an analytics event when there's an error\n await reportAnalyticsEvent({config, errorMessage: error instanceof Error ? error.message : undefined})\n }\n await sendErrorToBugsnag(error)\n}\n\n/**\n * Sends an error to Bugsnag. This is configured automatically for uncaught errors from CLI commands, but can also be used to manually record an error.\n *\n * @returns the reported error (this may have been tweaked for better reporting), and a bool to indicate if the error was actually submitted or not\n */\nexport async function sendErrorToBugsnag(\n error: unknown,\n): Promise<{reported: false; error: unknown} | {error: Error; reported: true}> {\n if (settings.debug || !shouldReportError(error)) return {reported: false, error}\n\n let reportableError: Error\n let stacktrace: string | undefined\n let report = false\n\n if (error instanceof Error) {\n report = true\n reportableError = new Error(error.message)\n stacktrace = error.stack\n\n /**\n * Some errors that reach this point have an empty string. For example:\n * https://app.bugsnag.com/shopify/cli/errors/62cd5d31fd5040000814086c?filters[event.since]=30d&filters[error.status]=new&filters[release.seen_in]=3.1.0\n *\n * Because at this point we have neither the error message nor a stack trace reporting them\n * to Bugsnag is pointless and adds noise.\n */\n } else if (typeof error === 'string' && error.trim().length !== 0) {\n report = true\n reportableError = new Error(error)\n stacktrace = reportableError.stack\n } else {\n report = false\n reportableError = new Error('Unknown error')\n }\n\n const formattedStacktrace = new StackTracey(stacktrace ?? '')\n .clean()\n .items.map((item) => {\n const filePath = cleanSingleStackTracePath(item.file)\n return ` at ${item.callee} (${filePath}:${item.line}:${item.column})`\n })\n .join('\\n')\n reportableError.stack = `Error: ${reportableError.message}\\n${formattedStacktrace}`\n\n if (report) {\n initializeBugsnag()\n await new Promise((resolve, reject) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.notify(reportableError, undefined, (error, event) => {\n if (error) {\n reject(error)\n } else {\n resolve(reportableError)\n }\n })\n })\n }\n return {error: reportableError, reported: report}\n}\n\n/**\n * If the given file path is within a node_modules folder, remove prefix up\n * to and including the node_modules folder.\n *\n * This gives us very consistent paths for errors generated by the CLI.\n */\nexport function cleanStackFrameFilePath({\n currentFilePath,\n projectRoot,\n pluginLocations,\n}: {\n currentFilePath: string\n projectRoot: string\n pluginLocations: {name: string; pluginPath: string}[]\n}): string {\n const fullLocation = path.isAbsolutePath(currentFilePath)\n ? currentFilePath\n : path.joinPath(projectRoot, currentFilePath)\n\n const matchingPluginPath = pluginLocations.filter(({pluginPath}) => fullLocation.indexOf(pluginPath) === 0)[0]\n\n if (matchingPluginPath !== undefined) {\n // the plugin name (e.g. @shopify/cli-kit), plus the relative path of the error line from within the plugin's code (e.g. dist/something.js )\n return path.joinPath(matchingPluginPath.name, path.relativePath(matchingPluginPath.pluginPath, fullLocation))\n }\n\n // strip prefix up to node_modules folder, so we can normalize error reporting\n return currentFilePath.replace(/.*node_modules\\//, '')\n}\n\n/**\n * Register a Bugsnag error listener to clean up stack traces for errors within plugin code.\n *\n */\nexport async function registerCleanBugsnagErrorsFromWithinPlugins(config: Interfaces.Config): Promise<void> {\n // Bugsnag have their own plug-ins that use this private field\n\n const bugsnagConfigProjectRoot: string = Bugsnag?._client?._config?.projectRoot ?? path.cwd()\n const projectRoot = path.normalizePath(bugsnagConfigProjectRoot)\n const pluginLocations = await Promise.all(\n config.plugins.map(async (plugin) => {\n const followSymlinks = await realpath(plugin.root)\n return {name: plugin.name, pluginPath: path.normalizePath(followSymlinks)}\n }),\n )\n initializeBugsnag()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.addOnError(async (event) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n event.errors.forEach((error: any) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error.stacktrace.forEach((stackFrame: any) => {\n stackFrame.file = cleanStackFrameFilePath({currentFilePath: stackFrame.file, projectRoot, pluginLocations})\n })\n })\n try {\n await addBugsnagMetadata(event, config)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (metadataError) {\n outputDebug(`There was an error adding metadata to the Bugsnag report; Ignoring and carrying on ${metadataError}`)\n }\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\nexport async function addBugsnagMetadata(event: any, config: Interfaces.Config): Promise<void> {\n const publicData = metadata.getAllPublicMetadata()\n const {commandStartOptions} = metadata.getAllSensitiveMetadata()\n const {startCommand} = commandStartOptions ?? {}\n\n const {'@shopify/app': appPublic, ...otherPluginsPublic} = await fanoutHooks(config, 'public_command_metadata', {})\n\n const environment = await getEnvironmentData(config)\n\n const allMetadata = {\n command: startCommand,\n ...appPublic,\n ...publicData,\n ...environment,\n pluginData: otherPluginsPublic,\n }\n\n const appData = {} as {[key: string]: unknown}\n const commandData = {} as {[key: string]: unknown}\n const environmentData = {} as {[key: string]: unknown}\n const miscData = {} as {[key: string]: unknown}\n const appKeys = ['api_key', 'partner_id', 'project_type']\n const commandKeys = ['command']\n const environmentKeys = ['cli_version', 'node_version', 'ruby_version', 'uname']\n\n Object.entries(allMetadata).forEach(([key, value]) => {\n if (key.startsWith('app_') || appKeys.includes(key)) {\n appData[key] = value\n } else if (key.startsWith('cmd_') || commandKeys.includes(key)) {\n commandData[key] = value\n } else if (key.startsWith('env_') || environmentKeys) {\n environmentData[key] = value\n } else {\n miscData[key] = value\n }\n })\n\n // app, command, environment, misc\n const bugsnagMetadata = {\n 'Shopify App': appData,\n Command: commandData,\n Environment: environmentData,\n Misc: miscData,\n }\n Object.entries(bugsnagMetadata).forEach(([section, values]) => {\n event.addMetadata(section, values)\n })\n}\n\nfunction initializeBugsnag() {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (Bugsnag.isStarted()) {\n return\n }\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n Bugsnag.start({\n appType: 'node',\n apiKey: bugsnagApiKey,\n logger: null,\n appVersion: CLI_KIT_VERSION,\n autoTrackSessions: false,\n autoDetectErrors: false,\n })\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Message } from '../../output.js';
1
+ import { OutputMessage } from '../../public/node/output.js';
2
2
  import { TokenItem } from '../../private/node/ui/components/TokenizedText.js';
3
3
  export { ExtendableError } from 'ts-error';
4
4
  declare enum FatalErrorType {
@@ -26,7 +26,7 @@ export declare abstract class FatalError extends Error {
26
26
  * if you need to style the message inside the error Banner component.
27
27
  * @param nextSteps - Message to show as "next steps" with suggestions to solve the issue.
28
28
  */
29
- constructor(message: Message, type: FatalErrorType, tryMessage?: TokenItem | Message | null, nextSteps?: TokenItem[]);
29
+ constructor(message: OutputMessage, type: FatalErrorType, tryMessage?: TokenItem | OutputMessage | null, nextSteps?: TokenItem[]);
30
30
  }
31
31
  /**
32
32
  * An abort error is a fatal error that shouldn't be reported as a bug.
@@ -34,7 +34,7 @@ export declare abstract class FatalError extends Error {
34
34
  */
35
35
  export declare class AbortError extends FatalError {
36
36
  nextSteps?: TokenItem[];
37
- constructor(message: Message, tryMessage?: TokenItem | Message | null, nextSteps?: TokenItem[]);
37
+ constructor(message: OutputMessage, tryMessage?: TokenItem | OutputMessage | null, nextSteps?: TokenItem[]);
38
38
  }
39
39
  /**
40
40
  * An external error is similar to Abort but has extra command and args attributes.
@@ -43,7 +43,7 @@ export declare class AbortError extends FatalError {
43
43
  export declare class ExternalError extends FatalError {
44
44
  command: string;
45
45
  args: string[];
46
- constructor(message: Message, command: string, args: string[], tryMessage?: TokenItem | Message | null);
46
+ constructor(message: OutputMessage, command: string, args: string[], tryMessage?: TokenItem | OutputMessage | null);
47
47
  }
48
48
  export declare class AbortSilentError extends FatalError {
49
49
  constructor();
@@ -52,7 +52,7 @@ export declare class AbortSilentError extends FatalError {
52
52
  * A bug error is an error that represents a bug and therefore should be reported.
53
53
  */
54
54
  export declare class BugError extends FatalError {
55
- constructor(message: Message, tryMessage?: TokenItem | null);
55
+ constructor(message: OutputMessage, tryMessage?: TokenItem | null);
56
56
  }
57
57
  /**
58
58
  * A function that handles errors that blow up in the CLI.
@@ -1,5 +1,5 @@
1
1
  import { renderFatalError } from './ui.js';
2
- import { stringifyMessage, TokenizedString } from '../../output.js';
2
+ import { stringifyMessage, TokenizedString } from '../../public/node/output.js';
3
3
  import { normalizePath } from '../../public/node/path.js';
4
4
  import { Errors } from '@oclif/core';
5
5
  export { ExtendableError } from 'ts-error';
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/public/node/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAA;AACxC,OAAO,EAAU,gBAAgB,EAAE,eAAe,EAAC,MAAM,iBAAiB,CAAA;AAC1E,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAA;AAEvD,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAElC,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAA;AAExC,IAAK,cAIJ;AAJD,WAAK,cAAc;IACjB,qDAAK,CAAA;IACL,iEAAW,CAAA;IACX,iDAA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AO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;KACpC;SAAM;QACL,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;KAC9B;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,OAAO,CAAC,KAAc;IAC7B,IAAI;QACF,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC1D,qDAAqD;KACtD;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACnB,OAAO,IAAI,CAAA;KACZ;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG,EAAE;QACrC,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,QAAgB;IACxD,OAAO,aAAa,CAAC,QAAQ,CAAC;SAC3B,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;AAC9B,CAAC","sourcesContent":["import {renderFatalError} from './ui.js'\nimport {Message, stringifyMessage, TokenizedString} from '../../output.js'\nimport {normalizePath} from '../../public/node/path.js'\nimport {TokenItem} from '../../private/node/ui/components/TokenizedText.js'\nimport {Errors} from '@oclif/core'\n\nexport {ExtendableError} from 'ts-error'\n\nenum FatalErrorType {\n Abort,\n AbortSilent,\n Bug,\n}\n\nexport class CancelExecution extends Error {}\n\n/**\n * A fatal error represents an error shouldn't be rescued and that causes the execution to terminate.\n * There shouldn't be code that catches fatal errors.\n */\nexport abstract class FatalError extends Error {\n tryMessage: TokenItem | null\n type: FatalErrorType\n nextSteps?: TokenItem[]\n /**\n * Creates a new FatalError error.\n *\n * @param message - The error message.\n * @param type - The type of fatal error.\n * @param tryMessage - The message that recommends next steps to the user.\n * You can pass a string a {@link TokenizedString} or a {@link TokenItem}\n * if you need to style the message inside the error Banner component.\n * @param nextSteps - Message to show as \"next steps\" with suggestions to solve the issue.\n */\n constructor(\n message: Message,\n type: FatalErrorType,\n tryMessage: TokenItem | Message | null = null,\n nextSteps?: TokenItem[],\n ) {\n super(stringifyMessage(message))\n\n if (tryMessage) {\n if (tryMessage instanceof TokenizedString) {\n this.tryMessage = stringifyMessage(tryMessage)\n } else {\n this.tryMessage = tryMessage\n }\n } else {\n this.tryMessage = null\n }\n\n this.type = type\n this.nextSteps = nextSteps\n }\n}\n\n/**\n * An abort error is a fatal error that shouldn't be reported as a bug.\n * Those usually represent unexpected scenarios that we can't handle and that usually require some action from the developer.\n */\nexport class AbortError extends FatalError {\n nextSteps?: TokenItem[]\n constructor(message: Message, tryMessage: TokenItem | Message | null = null, nextSteps?: TokenItem[]) {\n super(message, FatalErrorType.Abort, tryMessage, nextSteps)\n }\n}\n\n/**\n * An external error is similar to Abort but has extra command and args attributes.\n * This is useful to represent errors coming from external commands, usually executed by execa.\n */\nexport class ExternalError extends FatalError {\n command: string\n args: string[]\n\n constructor(message: Message, command: string, args: string[], tryMessage: TokenItem | Message | null = null) {\n super(message, FatalErrorType.Abort, tryMessage)\n this.command = command\n this.args = args\n }\n}\n\nexport class AbortSilentError extends FatalError {\n constructor() {\n super('', FatalErrorType.AbortSilent)\n }\n}\n\n/**\n * A bug error is an error that represents a bug and therefore should be reported.\n */\nexport class BugError extends FatalError {\n constructor(message: Message, tryMessage: TokenItem | null = null) {\n super(message, FatalErrorType.Bug, tryMessage)\n }\n}\n\n/**\n * A function that handles errors that blow up in the CLI.\n *\n * @param error - Error to be handled.\n * @returns A promise that resolves with the error passed.\n */\nexport async function handler(error: unknown): Promise<unknown> {\n let fatal: FatalError\n if (isFatal(error)) {\n fatal = error\n } else if (typeof error === 'string') {\n fatal = new BugError(error)\n } else if (error instanceof Error) {\n fatal = new BugError(error.message)\n fatal.stack = error.stack\n } else {\n // errors can come in all shapes and sizes...\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const maybeError = error as any\n fatal = new BugError(maybeError?.message ?? 'Unknown error')\n if (maybeError?.stack) {\n fatal.stack = maybeError?.stack\n }\n }\n\n renderFatalError(fatal)\n return Promise.resolve(error)\n}\n\n/**\n * A function that maps an error to an Abort with the stack trace when coming from the CLI.\n *\n * @param error - Error to be mapped.\n * @returns A promise that resolves with the new error object.\n */\nexport function errorMapper(error: unknown): Promise<unknown> {\n if (error instanceof Errors.CLIError) {\n const mappedError = new AbortError(error.message)\n mappedError.stack = error.stack\n return Promise.resolve(mappedError)\n } else {\n return Promise.resolve(error)\n }\n}\n\n/**\n * A function that checks if an error is a fatal one.\n *\n * @param error - Error to be checked.\n * @returns A boolean indicating if the error is a fatal one.\n */\nfunction isFatal(error: unknown): error is FatalError {\n try {\n return Object.prototype.hasOwnProperty.call(error, 'type')\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * A function that checks if an error should be reported.\n *\n * @param error - Error to be checked.\n * @returns A boolean indicating if the error should be reported.\n */\nexport function shouldReportError(error: unknown): boolean {\n if (!isFatal(error)) {\n return true\n }\n if (error.type === FatalErrorType.Bug) {\n return true\n }\n return false\n}\n\n/**\n * Stack traces usually have file:// - we strip that and also remove the Windows drive designation.\n *\n * @param filePath - Path to be cleaned.\n * @returns The cleaned path.\n */\nexport function cleanSingleStackTracePath(filePath: string): string {\n return normalizePath(filePath)\n .replace('file:/', '/')\n .replace(/^\\/?[A-Z]:/, '')\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/public/node/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAA;AACxC,OAAO,EAAgB,gBAAgB,EAAE,eAAe,EAAC,MAAM,6BAA6B,CAAA;AAC5F,OAAO,EAAC,aAAa,EAAC,MAAM,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IACxC,IAAI,KAAK,YAAY,MAAM,CAAC,QAAQ,EAAE;QACpC,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACjD,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;QAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;KACpC;SAAM;QACL,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;KAC9B;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,OAAO,CAAC,KAAc;IAC7B,IAAI;QACF,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAC1D,qDAAqD;KACtD;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACnB,OAAO,IAAI,CAAA;KACZ;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,GAAG,EAAE;QACrC,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,QAAgB;IACxD,OAAO,aAAa,CAAC,QAAQ,CAAC;SAC3B,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;AAC9B,CAAC","sourcesContent":["import {renderFatalError} from './ui.js'\nimport {OutputMessage, stringifyMessage, TokenizedString} from '../../public/node/output.js'\nimport {normalizePath} from '../../public/node/path.js'\nimport {TokenItem} from '../../private/node/ui/components/TokenizedText.js'\nimport {Errors} from '@oclif/core'\n\nexport {ExtendableError} from 'ts-error'\n\nenum FatalErrorType {\n Abort,\n AbortSilent,\n Bug,\n}\n\nexport class CancelExecution extends Error {}\n\n/**\n * A fatal error represents an error shouldn't be rescued and that causes the execution to terminate.\n * There shouldn't be code that catches fatal errors.\n */\nexport abstract class FatalError extends Error {\n tryMessage: TokenItem | null\n type: FatalErrorType\n nextSteps?: TokenItem[]\n /**\n * Creates a new FatalError error.\n *\n * @param message - The error message.\n * @param type - The type of fatal error.\n * @param tryMessage - The message that recommends next steps to the user.\n * You can pass a string a {@link TokenizedString} or a {@link TokenItem}\n * if you need to style the message inside the error Banner component.\n * @param nextSteps - Message to show as \"next steps\" with suggestions to solve the issue.\n */\n constructor(\n message: OutputMessage,\n type: FatalErrorType,\n tryMessage: TokenItem | OutputMessage | null = null,\n nextSteps?: TokenItem[],\n ) {\n super(stringifyMessage(message))\n\n if (tryMessage) {\n if (tryMessage instanceof TokenizedString) {\n this.tryMessage = stringifyMessage(tryMessage)\n } else {\n this.tryMessage = tryMessage\n }\n } else {\n this.tryMessage = null\n }\n\n this.type = type\n this.nextSteps = nextSteps\n }\n}\n\n/**\n * An abort error is a fatal error that shouldn't be reported as a bug.\n * Those usually represent unexpected scenarios that we can't handle and that usually require some action from the developer.\n */\nexport class AbortError extends FatalError {\n nextSteps?: TokenItem[]\n constructor(message: OutputMessage, tryMessage: TokenItem | OutputMessage | null = null, nextSteps?: TokenItem[]) {\n super(message, FatalErrorType.Abort, tryMessage, nextSteps)\n }\n}\n\n/**\n * An external error is similar to Abort but has extra command and args attributes.\n * This is useful to represent errors coming from external commands, usually executed by execa.\n */\nexport class ExternalError extends FatalError {\n command: string\n args: string[]\n\n constructor(\n message: OutputMessage,\n command: string,\n args: string[],\n tryMessage: TokenItem | OutputMessage | null = null,\n ) {\n super(message, FatalErrorType.Abort, tryMessage)\n this.command = command\n this.args = args\n }\n}\n\nexport class AbortSilentError extends FatalError {\n constructor() {\n super('', FatalErrorType.AbortSilent)\n }\n}\n\n/**\n * A bug error is an error that represents a bug and therefore should be reported.\n */\nexport class BugError extends FatalError {\n constructor(message: OutputMessage, tryMessage: TokenItem | null = null) {\n super(message, FatalErrorType.Bug, tryMessage)\n }\n}\n\n/**\n * A function that handles errors that blow up in the CLI.\n *\n * @param error - Error to be handled.\n * @returns A promise that resolves with the error passed.\n */\nexport async function handler(error: unknown): Promise<unknown> {\n let fatal: FatalError\n if (isFatal(error)) {\n fatal = error\n } else if (typeof error === 'string') {\n fatal = new BugError(error)\n } else if (error instanceof Error) {\n fatal = new BugError(error.message)\n fatal.stack = error.stack\n } else {\n // errors can come in all shapes and sizes...\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const maybeError = error as any\n fatal = new BugError(maybeError?.message ?? 'Unknown error')\n if (maybeError?.stack) {\n fatal.stack = maybeError?.stack\n }\n }\n\n renderFatalError(fatal)\n return Promise.resolve(error)\n}\n\n/**\n * A function that maps an error to an Abort with the stack trace when coming from the CLI.\n *\n * @param error - Error to be mapped.\n * @returns A promise that resolves with the new error object.\n */\nexport function errorMapper(error: unknown): Promise<unknown> {\n if (error instanceof Errors.CLIError) {\n const mappedError = new AbortError(error.message)\n mappedError.stack = error.stack\n return Promise.resolve(mappedError)\n } else {\n return Promise.resolve(error)\n }\n}\n\n/**\n * A function that checks if an error is a fatal one.\n *\n * @param error - Error to be checked.\n * @returns A boolean indicating if the error is a fatal one.\n */\nfunction isFatal(error: unknown): error is FatalError {\n try {\n return Object.prototype.hasOwnProperty.call(error, 'type')\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * A function that checks if an error should be reported.\n *\n * @param error - Error to be checked.\n * @returns A boolean indicating if the error should be reported.\n */\nexport function shouldReportError(error: unknown): boolean {\n if (!isFatal(error)) {\n return true\n }\n if (error.type === FatalErrorType.Bug) {\n return true\n }\n return false\n}\n\n/**\n * Stack traces usually have file:// - we strip that and also remove the Windows drive designation.\n *\n * @param filePath - Path to be cleaned.\n * @returns The cleaned path.\n */\nexport function cleanSingleStackTracePath(filePath: string): string {\n return normalizePath(filePath)\n .replace('file:/', '/')\n .replace(/^\\/?[A-Z]:/, '')\n}\n"]}
@@ -1,9 +1,9 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
3
  import { RandomNameFamily } from '../common/string.js';
4
4
  import { OverloadParameters } from '../../private/common/ts/overloaded-parameters.js';
5
5
  import { findUp as internalFindUp } from 'find-up';
6
- import { ReadStream } from 'fs';
6
+ import { ReadStream, WriteStream } from 'fs';
7
7
  import type { Pattern, Options as GlobOptions } from 'fast-glob';
8
8
  /**
9
9
  * Strip the first `strip` parts of the path.
@@ -26,7 +26,7 @@ export declare function inTemporaryDirectory<T>(callback: (tmpDir: string) => T
26
26
  * @param path - Path to the file to read.
27
27
  * @returns A promise that resolves with the content of the file.
28
28
  */
29
- export declare type ReadOptions = undefined | {
29
+ export type ReadOptions = undefined | {
30
30
  flag?: string | undefined;
31
31
  } | {
32
32
  encoding: BufferEncoding | string;
@@ -113,6 +113,12 @@ export declare function mkdirSync(path: string): void;
113
113
  * @param path - Path to the file to be removed.
114
114
  */
115
115
  export declare function removeFile(path: string): Promise<void>;
116
+ /**
117
+ * Renames a file.
118
+ * @param from - Path to the file to be renamed.
119
+ * @param to - New path for the file.
120
+ */
121
+ export declare function renameFile(from: string, to: string): Promise<void>;
116
122
  /**
117
123
  * Synchronously removes a file at the given path.
118
124
  *
@@ -156,6 +162,12 @@ export declare function fileSize(path: string): Promise<number>;
156
162
  * @returns The size of the file in bytes.
157
163
  */
158
164
  export declare function fileSizeSync(path: string): number;
165
+ /**
166
+ * Unlink a file at the given path.
167
+ * @param path - Path to the file.
168
+ * @returns A promise that resolves when the file is unlinked.
169
+ */
170
+ export declare function unlinkFileSync(path: string): void;
159
171
  /**
160
172
  * Create a read stream for a file.
161
173
  *
@@ -163,6 +175,13 @@ export declare function fileSizeSync(path: string): number;
163
175
  * @returns A read stream for the file.
164
176
  */
165
177
  export declare function createFileReadStream(path: string): ReadStream;
178
+ /**
179
+ * Create a write stream for a file.
180
+ *
181
+ * @param path - Path to the file.
182
+ * @returns A write stream for the file.
183
+ */
184
+ export declare function createFileWriteStream(path: string): WriteStream;
166
185
  /**
167
186
  * Returns the Date object for the last modification of a file.
168
187
  *
@@ -208,6 +227,7 @@ export declare function fileHasExecutablePermissions(path: string): Promise<bool
208
227
  * @returns True if it exists.
209
228
  */
210
229
  export declare function fileExists(path: string): Promise<boolean>;
230
+ export declare function fileExistsSync(path: string): boolean;
211
231
  interface FileOptions {
212
232
  path: string;
213
233
  }
@@ -1,5 +1,5 @@
1
1
  import { joinPath, normalizePath } from './path.js';
2
- import { content as outputContent, token, debug } from '../../output.js';
2
+ import { outputContent, outputToken, outputDebug } from '../../public/node/output.js';
3
3
  import { getRandomName } from '../common/string.js';
4
4
  import { copy as fsCopy, ensureFile as fsEnsureFile, ensureFileSync as fsEnsureFileSync, remove as fsRemove, removeSync as fsRemoveSync, move as fsMove,
5
5
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -8,8 +8,8 @@ import { copy as fsCopy, ensureFile as fsEnsureFile, ensureFileSync as fsEnsureF
8
8
  import { temporaryDirectoryTask } from 'tempy';
9
9
  import { sep, join, extname } from 'pathe';
10
10
  import { findUp as internalFindUp } from 'find-up';
11
- import { mkdirSync as fsMkdirSync, readFileSync as fsReadFileSync, writeFileSync as fsWriteFileSync, appendFileSync as fsAppendFileSync, statSync as fsStatSync, createReadStream as fsCreateReadStream, constants as fsConstants, } from 'fs';
12
- import { mkdir as fsMkdir, writeFile as fsWriteFile, readFile as fsReadFile, realpath as fsRealPath, appendFile as fsAppendFile, mkdtemp as fsMkdtemp, stat as fsStat, lstat as fsLstat, chmod as fsChmod, access as fsAccess, } from 'fs/promises';
11
+ import { mkdirSync as fsMkdirSync, readFileSync as fsReadFileSync, writeFileSync as fsWriteFileSync, appendFileSync as fsAppendFileSync, statSync as fsStatSync, createReadStream as fsCreateReadStream, createWriteStream as fsCreateWriteStream, constants as fsConstants, existsSync as fsFileExistsSync, unlinkSync as fsUnlinkSync, } from 'fs';
12
+ import { mkdir as fsMkdir, writeFile as fsWriteFile, readFile as fsReadFile, realpath as fsRealPath, appendFile as fsAppendFile, mkdtemp as fsMkdtemp, stat as fsStat, lstat as fsLstat, chmod as fsChmod, access as fsAccess, rename as fsRename, } from 'fs/promises';
13
13
  const DEFAULT_PRETTIER_CONFIG = {
14
14
  arrowParens: 'always',
15
15
  singleQuote: true,
@@ -44,7 +44,7 @@ export async function inTemporaryDirectory(callback) {
44
44
  * @returns A promise that resolves with the content of the file.
45
45
  */
46
46
  export async function readFile(path, options = { encoding: 'utf8' }) {
47
- debug(outputContent `Reading the content of file at ${token.path(path)}...`);
47
+ outputDebug(outputContent `Reading the content of file at ${outputToken.path(path)}...`);
48
48
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
49
49
  // @ts-ignore
50
50
  return fsReadFile(path, options);
@@ -56,7 +56,7 @@ export async function readFile(path, options = { encoding: 'utf8' }) {
56
56
  * @returns The content of the file.
57
57
  */
58
58
  export function readFileSync(path) {
59
- debug(outputContent `Sync-reading the content of file at ${token.path(path)}...`);
59
+ outputDebug(outputContent `Sync-reading the content of file at ${outputToken.path(path)}...`);
60
60
  return fsReadFileSync(path);
61
61
  }
62
62
  /**
@@ -75,7 +75,7 @@ export async function fileRealPath(path) {
75
75
  * @param to - Destination path.
76
76
  */
77
77
  export async function copyFile(from, to) {
78
- debug(outputContent `Copying file from ${token.path(from)} to ${token.path(to)}...`);
78
+ outputDebug(outputContent `Copying file from ${outputToken.path(from)} to ${outputToken.path(to)}...`);
79
79
  await fsCopy(from, to);
80
80
  }
81
81
  /**
@@ -84,7 +84,7 @@ export async function copyFile(from, to) {
84
84
  * @param path - Path to the file to be created.
85
85
  */
86
86
  export async function touchFile(path) {
87
- debug(outputContent `Creating an empty file at ${token.path(path)}...`);
87
+ outputDebug(outputContent `Creating an empty file at ${outputToken.path(path)}...`);
88
88
  await fsEnsureFile(path);
89
89
  }
90
90
  /**
@@ -93,7 +93,7 @@ export async function touchFile(path) {
93
93
  * @param path - Path to the file to be created.
94
94
  */
95
95
  export function touchFileSync(path) {
96
- debug(outputContent `Creating an empty file at ${token.path(path)}...`);
96
+ outputDebug(outputContent `Creating an empty file at ${outputToken.path(path)}...`);
97
97
  fsEnsureFileSync(path);
98
98
  }
99
99
  /**
@@ -103,7 +103,7 @@ export function touchFileSync(path) {
103
103
  * @param content - Content to be appended.
104
104
  */
105
105
  export async function appendFile(path, content) {
106
- debug(outputContent `Appending the following content to ${token.path(path)}:
106
+ outputDebug(outputContent `Appending the following content to ${outputToken.path(path)}:
107
107
  ${content
108
108
  .split('\n')
109
109
  .map((line) => ` ${line}`)
@@ -127,7 +127,7 @@ export function appendFileSync(path, data) {
127
127
  * @param data - Content to be written.
128
128
  */
129
129
  export async function writeFile(path, data) {
130
- debug(outputContent `Writing some content to file at ${token.path(path)}...`);
130
+ outputDebug(outputContent `Writing some content to file at ${outputToken.path(path)}...`);
131
131
  await fsWriteFile(path, data, { encoding: 'utf8' });
132
132
  }
133
133
  /**
@@ -137,7 +137,7 @@ export async function writeFile(path, data) {
137
137
  * @param data - Content to be written.
138
138
  */
139
139
  export function writeFileSync(path, data) {
140
- debug(outputContent `File-writing some content to file at ${token.path(path)}...`);
140
+ outputDebug(outputContent `File-writing some content to file at ${outputToken.path(path)}...`);
141
141
  fsWriteFileSync(path, data);
142
142
  }
143
143
  /**
@@ -146,7 +146,7 @@ export function writeFileSync(path, data) {
146
146
  * @param path - Path to the directory to be created.
147
147
  */
148
148
  export async function mkdir(path) {
149
- debug(outputContent `Creating directory at ${token.path(path)}...`);
149
+ outputDebug(outputContent `Creating directory at ${outputToken.path(path)}...`);
150
150
  await fsMkdir(path, { recursive: true });
151
151
  }
152
152
  /**
@@ -155,7 +155,7 @@ export async function mkdir(path) {
155
155
  * @param path - Path to the directory to be created.
156
156
  */
157
157
  export function mkdirSync(path) {
158
- debug(outputContent `Sync-creating directory at ${token.path(path)}...`);
158
+ outputDebug(outputContent `Sync-creating directory at ${outputToken.path(path)}...`);
159
159
  fsMkdirSync(path, { recursive: true });
160
160
  }
161
161
  /**
@@ -164,16 +164,25 @@ export function mkdirSync(path) {
164
164
  * @param path - Path to the file to be removed.
165
165
  */
166
166
  export async function removeFile(path) {
167
- debug(outputContent `Removing file at ${token.path(path)}...`);
167
+ outputDebug(outputContent `Removing file at ${outputToken.path(path)}...`);
168
168
  await fsRemove(path);
169
169
  }
170
+ /**
171
+ * Renames a file.
172
+ * @param from - Path to the file to be renamed.
173
+ * @param to - New path for the file.
174
+ */
175
+ export async function renameFile(from, to) {
176
+ outputDebug(outputContent `Renaming file from ${outputToken.path(from)} to ${outputToken.path(to)}...`);
177
+ await fsRename(from, to);
178
+ }
170
179
  /**
171
180
  * Synchronously removes a file at the given path.
172
181
  *
173
182
  * @param path - Path to the file to be removed.
174
183
  */
175
184
  export function removeFileSync(path) {
176
- debug(outputContent `Sync-removing file at ${token.path(path)}...`);
185
+ outputDebug(outputContent `Sync-removing file at ${outputToken.path(path)}...`);
177
186
  fsRemoveSync(path);
178
187
  }
179
188
  /**
@@ -184,7 +193,7 @@ export function removeFileSync(path) {
184
193
  */
185
194
  export async function rmdir(path, options = {}) {
186
195
  const { default: del } = await import('del');
187
- debug(outputContent `Removing directory at ${token.path(path)}...`);
196
+ outputDebug(outputContent `Removing directory at ${outputToken.path(path)}...`);
188
197
  await del(path, { force: options.force });
189
198
  }
190
199
  /**
@@ -193,7 +202,7 @@ export async function rmdir(path, options = {}) {
193
202
  * @returns Path to the temporary directory.
194
203
  */
195
204
  export async function mkTmpDir() {
196
- debug(outputContent `Creating a temporary directory...`);
205
+ outputDebug(outputContent `Creating a temporary directory...`);
197
206
  const directory = await fsMkdtemp('tmp-');
198
207
  return directory;
199
208
  }
@@ -204,7 +213,7 @@ export async function mkTmpDir() {
204
213
  * @returns True if the path is a directory, false otherwise.
205
214
  */
206
215
  export async function isDirectory(path) {
207
- debug(outputContent `Checking if ${token.path(path)} is a directory...`);
216
+ outputDebug(outputContent `Checking if ${outputToken.path(path)} is a directory...`);
208
217
  return (await fsLstat(path)).isDirectory();
209
218
  }
210
219
  /**
@@ -214,7 +223,7 @@ export async function isDirectory(path) {
214
223
  * @returns The size of the file in bytes.
215
224
  */
216
225
  export async function fileSize(path) {
217
- debug(outputContent `Getting the size of file file at ${token.path(path)}...`);
226
+ outputDebug(outputContent `Getting the size of file file at ${outputToken.path(path)}...`);
218
227
  return (await fsStat(path)).size;
219
228
  }
220
229
  /**
@@ -224,9 +233,17 @@ export async function fileSize(path) {
224
233
  * @returns The size of the file in bytes.
225
234
  */
226
235
  export function fileSizeSync(path) {
227
- debug(outputContent `Sync-getting the size of file file at ${token.path(path)}...`);
236
+ outputDebug(outputContent `Sync-getting the size of file file at ${outputToken.path(path)}...`);
228
237
  return fsStatSync(path).size;
229
238
  }
239
+ /**
240
+ * Unlink a file at the given path.
241
+ * @param path - Path to the file.
242
+ * @returns A promise that resolves when the file is unlinked.
243
+ */
244
+ export function unlinkFileSync(path) {
245
+ return fsUnlinkSync(path);
246
+ }
230
247
  /**
231
248
  * Create a read stream for a file.
232
249
  *
@@ -236,6 +253,15 @@ export function fileSizeSync(path) {
236
253
  export function createFileReadStream(path) {
237
254
  return fsCreateReadStream(path);
238
255
  }
256
+ /**
257
+ * Create a write stream for a file.
258
+ *
259
+ * @param path - Path to the file.
260
+ * @returns A write stream for the file.
261
+ */
262
+ export function createFileWriteStream(path) {
263
+ return fsCreateWriteStream(path);
264
+ }
239
265
  /**
240
266
  * Returns the Date object for the last modification of a file.
241
267
  *
@@ -243,7 +269,7 @@ export function createFileReadStream(path) {
243
269
  * @returns A unix timestamp.
244
270
  */
245
271
  export async function fileLastUpdated(path) {
246
- debug(outputContent `Getting last updated timestamp for file at ${token.path(path)}...`);
272
+ outputDebug(outputContent `Getting last updated timestamp for file at ${outputToken.path(path)}...`);
247
273
  return (await fsStat(path)).ctime;
248
274
  }
249
275
  /**
@@ -312,6 +338,9 @@ export async function fileExists(path) {
312
338
  return false;
313
339
  }
314
340
  }
341
+ export function fileExistsSync(path) {
342
+ return fsFileExistsSync(path);
343
+ }
315
344
  /**
316
345
  * Format a string using prettier. Return the formatted content.
317
346
  *