@shopify/cli-kit 3.36.1 → 3.37.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 (155) hide show
  1. package/dist/index.d.ts +0 -7
  2. package/dist/index.js +0 -7
  3. package/dist/index.js.map +1 -1
  4. package/dist/private/node/analytics.js +5 -4
  5. package/dist/private/node/analytics.js.map +1 -1
  6. package/dist/private/node/api/graphql.js +2 -2
  7. package/dist/private/node/api/graphql.js.map +1 -1
  8. package/dist/private/node/api/headers.d.ts +1 -1
  9. package/dist/private/node/api/headers.js +1 -1
  10. package/dist/private/node/api/headers.js.map +1 -1
  11. package/dist/private/node/conf-store.d.ts +21 -0
  12. package/dist/private/node/conf-store.js +41 -0
  13. package/dist/private/node/conf-store.js.map +1 -0
  14. package/dist/{secure-store.d.ts → private/node/secure-store.d.ts} +3 -3
  15. package/dist/{secure-store.js → private/node/secure-store.js} +7 -7
  16. package/dist/private/node/secure-store.js.map +1 -0
  17. package/dist/private/node/session/authorize.d.ts +0 -2
  18. package/dist/private/node/session/authorize.js +2 -3
  19. package/dist/private/node/session/authorize.js.map +1 -1
  20. package/dist/private/node/session/device-authorization.js +2 -2
  21. package/dist/private/node/session/device-authorization.js.map +1 -1
  22. package/dist/private/node/session/exchange.d.ts +1 -1
  23. package/dist/private/node/session/exchange.js +1 -2
  24. package/dist/private/node/session/exchange.js.map +1 -1
  25. package/dist/private/node/session/identity.js +2 -2
  26. package/dist/private/node/session/identity.js.map +1 -1
  27. package/dist/private/node/session/post-auth.d.ts +2 -2
  28. package/dist/private/node/session/post-auth.js +2 -2
  29. package/dist/private/node/session/post-auth.js.map +1 -1
  30. package/dist/private/node/session/redirect-listener.js +5 -5
  31. package/dist/private/node/session/redirect-listener.js.map +1 -1
  32. package/dist/private/node/session/schema.d.ts +46 -46
  33. package/dist/private/node/session/schema.js +12 -12
  34. package/dist/private/node/session/schema.js.map +1 -1
  35. package/dist/private/node/session/scopes.js +2 -2
  36. package/dist/private/node/session/scopes.js.map +1 -1
  37. package/dist/private/node/session/store.js +5 -6
  38. package/dist/private/node/session/store.js.map +1 -1
  39. package/dist/private/node/session.js +3 -4
  40. package/dist/private/node/session.js.map +1 -1
  41. package/dist/{testing → private/node/testing}/ui.d.ts +0 -0
  42. package/dist/{testing → private/node/testing}/ui.js +1 -1
  43. package/dist/private/node/testing/ui.js.map +1 -0
  44. package/dist/private/node/ui/components/AutocompletePrompt.test.js +1 -1
  45. package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
  46. package/dist/private/node/ui/components/ConcurrentOutput.test.js +1 -1
  47. package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
  48. package/dist/private/node/ui/components/FatalError.d.ts +1 -1
  49. package/dist/private/node/ui/components/FatalError.js +2 -2
  50. package/dist/private/node/ui/components/FatalError.js.map +1 -1
  51. package/dist/private/node/ui/components/FatalError.test.js +4 -4
  52. package/dist/private/node/ui/components/FatalError.test.js.map +1 -1
  53. package/dist/private/node/ui/components/SelectInput.test.js +1 -1
  54. package/dist/private/node/ui/components/SelectInput.test.js.map +1 -1
  55. package/dist/private/node/ui/components/SelectPrompt.test.js +1 -1
  56. package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
  57. package/dist/private/node/ui/components/Tasks.test.js +1 -1
  58. package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
  59. package/dist/private/node/ui/components/TextInput.test.js +1 -1
  60. package/dist/private/node/ui/components/TextInput.test.js.map +1 -1
  61. package/dist/private/node/ui/components/TextPrompt.test.js +1 -1
  62. package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
  63. package/dist/public/common/version.d.ts +1 -1
  64. package/dist/public/common/version.js +1 -1
  65. package/dist/public/common/version.js.map +1 -1
  66. package/dist/public/node/analytics.js +6 -6
  67. package/dist/public/node/analytics.js.map +1 -1
  68. package/dist/public/node/api/admin.js +3 -3
  69. package/dist/public/node/api/admin.js.map +1 -1
  70. package/dist/public/node/base-command.js +6 -5
  71. package/dist/public/node/base-command.js.map +1 -1
  72. package/dist/public/node/conf.d.ts +2 -0
  73. package/dist/public/node/conf.js +3 -0
  74. package/dist/public/node/conf.js.map +1 -0
  75. package/dist/public/node/environment/fqdn.d.ts +5 -5
  76. package/dist/public/node/environment/fqdn.js +5 -5
  77. package/dist/public/node/environment/fqdn.js.map +1 -1
  78. package/dist/public/node/environment/spin.js +2 -2
  79. package/dist/public/node/environment/spin.js.map +1 -1
  80. package/dist/public/node/error-handler.d.ts +2 -2
  81. package/dist/public/node/error-handler.js +7 -7
  82. package/dist/public/node/error-handler.js.map +1 -1
  83. package/dist/public/node/error.d.ts +84 -4
  84. package/dist/public/node/error.js +165 -4
  85. package/dist/public/node/error.js.map +1 -1
  86. package/dist/public/node/fs.js +4 -0
  87. package/dist/public/node/fs.js.map +1 -1
  88. package/dist/public/node/git.d.ts +2 -2
  89. package/dist/public/node/git.js +11 -10
  90. package/dist/public/node/git.js.map +1 -1
  91. package/dist/{metadata.d.ts → public/node/metadata.d.ts} +13 -13
  92. package/dist/{metadata.js → public/node/metadata.js} +13 -8
  93. package/dist/public/node/metadata.js.map +1 -0
  94. package/dist/{monorail.d.ts → public/node/monorail.d.ts} +11 -3
  95. package/dist/{monorail.js → public/node/monorail.js} +11 -3
  96. package/dist/public/node/monorail.js.map +1 -0
  97. package/dist/public/node/node-package-manager.d.ts +2 -2
  98. package/dist/public/node/node-package-manager.js +7 -2
  99. package/dist/public/node/node-package-manager.js.map +1 -1
  100. package/dist/public/node/path.d.ts +12 -2
  101. package/dist/public/node/path.js +17 -4
  102. package/dist/public/node/path.js.map +1 -1
  103. package/dist/public/node/plugins/tunnel.d.ts +2 -2
  104. package/dist/public/node/plugins/tunnel.js +1 -1
  105. package/dist/public/node/plugins/tunnel.js.map +1 -1
  106. package/dist/{plugins.d.ts → public/node/plugins.d.ts} +17 -11
  107. package/dist/{plugins.js → public/node/plugins.js} +15 -9
  108. package/dist/public/node/plugins.js.map +1 -0
  109. package/dist/public/node/result.js +3 -4
  110. package/dist/public/node/result.js.map +1 -1
  111. package/dist/public/node/ruby.d.ts +1 -0
  112. package/dist/public/node/ruby.js +24 -31
  113. package/dist/public/node/ruby.js.map +1 -1
  114. package/dist/public/node/schema.d.ts +1 -0
  115. package/dist/public/node/schema.js +2 -0
  116. package/dist/public/node/schema.js.map +1 -0
  117. package/dist/public/node/session.js +4 -4
  118. package/dist/public/node/session.js.map +1 -1
  119. package/dist/public/node/system.js +4 -3
  120. package/dist/public/node/system.js.map +1 -1
  121. package/dist/public/node/tcp.js +2 -2
  122. package/dist/public/node/tcp.js.map +1 -1
  123. package/dist/public/node/testing/output.d.ts +16 -0
  124. package/dist/{testing → public/node/testing}/output.js +6 -2
  125. package/dist/public/node/testing/output.js.map +1 -0
  126. package/dist/public/node/ui.d.ts +1 -1
  127. package/dist/public/node/ui.js.map +1 -1
  128. package/dist/public/node/vscode.js +2 -2
  129. package/dist/public/node/vscode.js.map +1 -1
  130. package/dist/tsconfig.tsbuildinfo +1 -1
  131. package/dist/ui.js +5 -5
  132. package/dist/ui.js.map +1 -1
  133. package/package.json +1 -1
  134. package/dist/error.d.ts +0 -68
  135. package/dist/error.js +0 -143
  136. package/dist/error.js.map +0 -1
  137. package/dist/git.d.ts +0 -36
  138. package/dist/git.js +0 -133
  139. package/dist/git.js.map +0 -1
  140. package/dist/metadata.js.map +0 -1
  141. package/dist/monorail.js.map +0 -1
  142. package/dist/plugins.js.map +0 -1
  143. package/dist/schema.d.ts +0 -1
  144. package/dist/schema.js +0 -2
  145. package/dist/schema.js.map +0 -1
  146. package/dist/secure-store.js.map +0 -1
  147. package/dist/store.d.ts +0 -53
  148. package/dist/store.js +0 -133
  149. package/dist/store.js.map +0 -1
  150. package/dist/testing/output.d.ts +0 -10
  151. package/dist/testing/output.js.map +0 -1
  152. package/dist/testing/store.d.ts +0 -7
  153. package/dist/testing/store.js +0 -26
  154. package/dist/testing/store.js.map +0 -1
  155. package/dist/testing/ui.js.map +0 -1
package/dist/ui.js CHANGED
@@ -1,8 +1,8 @@
1
- import { CancelExecution, Abort, AbortSilent } from './error.js';
1
+ import { CancelExecution, AbortError, AbortSilentError } from './public/node/error.js';
2
2
  import { removeFile, fileExists } from './public/node/fs.js';
3
3
  import { info, completed, content, token, logUpdate, stringifyMessage, debug } from './output.js';
4
4
  import colors from './public/node/colors.js';
5
- import { relativePath } from './public/node/path.js';
5
+ import { relativizePath } from './public/node/path.js';
6
6
  import { isTerminalInteractive } from './public/node/environment/local.js';
7
7
  import { run as executorUI } from './ui/executor.js';
8
8
  import { Listr as OriginalListr } from 'listr2';
@@ -36,7 +36,7 @@ export const task = async ({ title, task }) => {
36
36
  };
37
37
  export const prompt = async (questions) => {
38
38
  if (!isTerminalInteractive() && questions.length !== 0) {
39
- throw new Abort(content `
39
+ throw new AbortError(content `
40
40
  The CLI prompted in a non-interactive terminal with the following questions:
41
41
  ${token.json(questions)}
42
42
  `);
@@ -57,7 +57,7 @@ export async function nonEmptyDirectoryPrompt(directory) {
57
57
  { name: 'No, don’t delete the files', value: 'abort' },
58
58
  { name: 'Yes, delete the files', value: 'overwrite' },
59
59
  ];
60
- const relativeDirectory = relativePath(process.cwd(), directory);
60
+ const relativeDirectory = relativizePath(directory);
61
61
  const questions = {
62
62
  type: 'select',
63
63
  name: 'value',
@@ -99,7 +99,7 @@ export const keypress = async () => {
99
99
  const bytes = Array.from(buffer);
100
100
  if (bytes.length && bytes[0] === 3) {
101
101
  debug('Canceled keypress, User pressed CTRL+C');
102
- reject(new AbortSilent());
102
+ reject(new AbortSilentError());
103
103
  }
104
104
  process.nextTick(resolve);
105
105
  };
package/dist/ui.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,KAAK,EAAE,WAAW,EAAC,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAE,UAAU,EAAC,MAAM,qBA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B,4BAA4B;YACrK,OAAO,EAAE,OAAO;SACjB;KACF,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAA;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;IACjC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YACjC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC/B,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;YAErB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAEhC,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;gBAClC,KAAK,CAAC,wCAAwC,CAAC,CAAA;gBAC/C,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA;aAC1B;YACD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAC3B,CAAC,CAAA;QAED,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAA;QACtB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QAC9B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import {CancelExecution, Abort, AbortSilent} from './error.js'\nimport {removeFile, fileExists} from './public/node/fs.js'\nimport {info, completed, content, token, logUpdate, Message, Logger, stringifyMessage, debug} from './output.js'\nimport colors from './public/node/colors.js'\nimport {relativePath} from './public/node/path.js'\nimport {isTerminalInteractive} from './public/node/environment/local.js'\nimport {run as executorUI} from './ui/executor.js'\nimport {Listr as OriginalListr, ListrTask, ListrBaseClassOptions} from 'listr2'\nimport findProcess from 'find-process'\n\nexport function newListr(tasks: ListrTask[], options?: object | ListrBaseClassOptions) {\n const listr = new OriginalListr(tasks, options)\n return listr\n}\n\nexport type ListrTasks = ConstructorParameters<typeof OriginalListr>[0]\nexport type {ListrTaskWrapper, ListrDefaultRenderer, ListrTask} from 'listr2'\n\nexport interface PromptAnswer {\n name: string\n value: string\n}\nexport type FilterFunction = (answers: PromptAnswer[], input: string) => Promise<PromptAnswer[]>\n\ninterface BaseQuestion<TName extends string> {\n name: TName\n message: string\n preface?: string\n validate?: (value: string) => string | true\n default?: string\n result?: (value: string) => string | boolean\n choices?: QuestionChoiceType[]\n source?: (filter: FilterFunction) => FilterFunction\n}\n\ntype TextQuestion<TName extends string> = BaseQuestion<TName> & {\n type: 'input'\n // a default is required, otherwise we'd show a prompt like 'undefined'\n default: string\n}\n\ntype PasswordQuestion<TName extends string> = BaseQuestion<TName> & {\n type: 'password'\n}\n\ntype SelectableQuestion<TName extends string> = BaseQuestion<TName> & {\n type: 'select' | 'autocomplete'\n choices: QuestionChoiceType[]\n}\n\nexport type Question<TName extends string = string> =\n | TextQuestion<TName>\n | SelectableQuestion<TName>\n | PasswordQuestion<TName>\n\nexport interface QuestionChoiceType {\n name: string\n value: string\n group?: {name: string; order: number}\n}\n\nconst started = (content: Message, logger: Logger) => {\n const message = `${colors.yellow('❯')} ${stringifyMessage(content)}`\n info(message, logger)\n}\n\nconst failed = (content: Message, logger: Logger) => {\n const message = `${colors.red('✖')} ${stringifyMessage(content)}`\n info(message, logger)\n}\n\n/**\n * Performs a task with the title kept up to date and stdout available to the\n * task while it runs (there is no re-writing stdout while the task runs).\n */\nexport interface TaskOptions {\n title: string\n task: () => Promise<void | {successMessage: string}>\n}\nexport const task = async ({title, task}: TaskOptions) => {\n let success\n started(title, logUpdate)\n try {\n const result = await task()\n success = result?.successMessage || title\n } catch (err) {\n failed(title, logUpdate)\n logUpdate.done()\n throw err\n }\n completed(success, logUpdate)\n logUpdate.done()\n}\nexport const prompt = async <\n TName extends string & keyof TAnswers,\n TAnswers extends {[key in TName]: string} = {[key in TName]: string},\n>(\n questions: ReadonlyArray<Question<TName>>,\n): Promise<TAnswers> => {\n if (!isTerminalInteractive() && questions.length !== 0) {\n throw new Abort(content`\nThe CLI prompted in a non-interactive terminal with the following questions:\n${token.json(questions)}\n `)\n }\n\n const value = {} as TAnswers\n for (const question of questions) {\n if (question.preface) {\n info(question.preface)\n }\n\n // eslint-disable-next-line no-await-in-loop\n value[question.name] = (await executorUI(question)) as TAnswers[TName]\n }\n return value\n}\n\nexport async function nonEmptyDirectoryPrompt(directory: string) {\n if (await fileExists(directory)) {\n const options = [\n {name: 'No, don’t delete the files', value: 'abort'},\n {name: 'Yes, delete the files', value: 'overwrite'},\n ]\n\n const relativeDirectory = relativePath(process.cwd(), directory)\n\n const questions: Question<'value'> = {\n type: 'select',\n name: 'value',\n message: `${relativeDirectory} is not an empty directory. Do you want to delete the existing files and continue?`,\n choices: options,\n }\n\n const choice = await prompt([questions])\n\n if (choice.value === 'abort') {\n throw new CancelExecution()\n }\n\n await removeFile(directory)\n }\n}\n\nexport async function terminateBlockingPortProcessPrompt(port: number, stepDescription?: string): Promise<boolean> {\n const stepDescriptionContent = stepDescription ?? 'current step'\n\n const processInfo = await findProcess('port', port)\n const formattedProcessName =\n processInfo && processInfo.length > 0 && processInfo[0]?.name\n ? ` ${content`${token.italic(`(${processInfo[0].name})`)}`.value}`\n : ''\n\n const options = [\n {name: 'Yes, terminate process in order to log in now', value: 'finish'},\n {name: `No, cancel command and try later`, value: 'cancel'},\n ]\n\n const choice = await prompt([\n {\n type: 'select',\n name: 'value',\n message: `${stepDescriptionContent} requires a port ${port} that's unavailable because it's running another process${formattedProcessName}. Terminate that process? `,\n choices: options,\n },\n ])\n return choice.value === 'finish'\n}\n\nexport const keypress = async () => {\n return new Promise((resolve, reject) => {\n const handler = (buffer: Buffer) => {\n process.stdin.setRawMode(false)\n process.stdin.pause()\n\n const bytes = Array.from(buffer)\n\n if (bytes.length && bytes[0] === 3) {\n debug('Canceled keypress, User pressed CTRL+C')\n reject(new AbortSilent())\n }\n process.nextTick(resolve)\n }\n\n process.stdin.resume()\n process.stdin.setRawMode(true)\n process.stdin.once('data', handler)\n })\n}\n"]}
1
+ {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAC,MAAM,wBAAwB,CAAA;AACpF,OAAO,EAAC,UAAU,EAAE,UAAU,EAAC,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAmB,gBAAgB,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AAChH,OAAO,MAAM,MAAM,yBAAyB,CAAA;AAC5C,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAC,GAAG,IAAI,UAAU,EAAC,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAC,KAAK,IAAI,aAAa,EAAmC,MAAM,QAAQ,CAAA;AAC/E,OAAO,WAAW,MAAM,cAAc,CAAA;AAEtC,MAAM,UAAU,QAAQ,CAAC,KAAkB,EAAE,OAAwC;IACnF,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC/C,OAAO,KAAK,CAAA;AACd,CAAC;AAgDD,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAE,MAAc,EAAE,EAAE;IACnD,MAAM,OAAO,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAA;IACpE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,MAAc,EAAE,EAAE;IAClD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ent":["import {CancelExecution, AbortError, AbortSilentError} from './public/node/error.js'\nimport {removeFile, fileExists} from './public/node/fs.js'\nimport {info, completed, content, token, logUpdate, Message, Logger, stringifyMessage, debug} from './output.js'\nimport colors from './public/node/colors.js'\nimport {relativizePath} from './public/node/path.js'\nimport {isTerminalInteractive} from './public/node/environment/local.js'\nimport {run as executorUI} from './ui/executor.js'\nimport {Listr as OriginalListr, ListrTask, ListrBaseClassOptions} from 'listr2'\nimport findProcess from 'find-process'\n\nexport function newListr(tasks: ListrTask[], options?: object | ListrBaseClassOptions) {\n const listr = new OriginalListr(tasks, options)\n return listr\n}\n\nexport type ListrTasks = ConstructorParameters<typeof OriginalListr>[0]\nexport type {ListrTaskWrapper, ListrDefaultRenderer, ListrTask} from 'listr2'\n\nexport interface PromptAnswer {\n name: string\n value: string\n}\nexport type FilterFunction = (answers: PromptAnswer[], input: string) => Promise<PromptAnswer[]>\n\ninterface BaseQuestion<TName extends string> {\n name: TName\n message: string\n preface?: string\n validate?: (value: string) => string | true\n default?: string\n result?: (value: string) => string | boolean\n choices?: QuestionChoiceType[]\n source?: (filter: FilterFunction) => FilterFunction\n}\n\ntype TextQuestion<TName extends string> = BaseQuestion<TName> & {\n type: 'input'\n // a default is required, otherwise we'd show a prompt like 'undefined'\n default: string\n}\n\ntype PasswordQuestion<TName extends string> = BaseQuestion<TName> & {\n type: 'password'\n}\n\ntype SelectableQuestion<TName extends string> = BaseQuestion<TName> & {\n type: 'select' | 'autocomplete'\n choices: QuestionChoiceType[]\n}\n\nexport type Question<TName extends string = string> =\n | TextQuestion<TName>\n | SelectableQuestion<TName>\n | PasswordQuestion<TName>\n\nexport interface QuestionChoiceType {\n name: string\n value: string\n group?: {name: string; order: number}\n}\n\nconst started = (content: Message, logger: Logger) => {\n const message = `${colors.yellow('❯')} ${stringifyMessage(content)}`\n info(message, logger)\n}\n\nconst failed = (content: Message, logger: Logger) => {\n const message = `${colors.red('✖')} ${stringifyMessage(content)}`\n info(message, logger)\n}\n\n/**\n * Performs a task with the title kept up to date and stdout available to the\n * task while it runs (there is no re-writing stdout while the task runs).\n */\nexport interface TaskOptions {\n title: string\n task: () => Promise<void | {successMessage: string}>\n}\nexport const task = async ({title, task}: TaskOptions) => {\n let success\n started(title, logUpdate)\n try {\n const result = await task()\n success = result?.successMessage || title\n } catch (err) {\n failed(title, logUpdate)\n logUpdate.done()\n throw err\n }\n completed(success, logUpdate)\n logUpdate.done()\n}\nexport const prompt = async <\n TName extends string & keyof TAnswers,\n TAnswers extends {[key in TName]: string} = {[key in TName]: string},\n>(\n questions: ReadonlyArray<Question<TName>>,\n): Promise<TAnswers> => {\n if (!isTerminalInteractive() && questions.length !== 0) {\n throw new AbortError(content`\nThe CLI prompted in a non-interactive terminal with the following questions:\n${token.json(questions)}\n `)\n }\n\n const value = {} as TAnswers\n for (const question of questions) {\n if (question.preface) {\n info(question.preface)\n }\n\n // eslint-disable-next-line no-await-in-loop\n value[question.name] = (await executorUI(question)) as TAnswers[TName]\n }\n return value\n}\n\nexport async function nonEmptyDirectoryPrompt(directory: string) {\n if (await fileExists(directory)) {\n const options = [\n {name: 'No, don’t delete the files', value: 'abort'},\n {name: 'Yes, delete the files', value: 'overwrite'},\n ]\n\n const relativeDirectory = relativizePath(directory)\n\n const questions: Question<'value'> = {\n type: 'select',\n name: 'value',\n message: `${relativeDirectory} is not an empty directory. Do you want to delete the existing files and continue?`,\n choices: options,\n }\n\n const choice = await prompt([questions])\n\n if (choice.value === 'abort') {\n throw new CancelExecution()\n }\n\n await removeFile(directory)\n }\n}\n\nexport async function terminateBlockingPortProcessPrompt(port: number, stepDescription?: string): Promise<boolean> {\n const stepDescriptionContent = stepDescription ?? 'current step'\n\n const processInfo = await findProcess('port', port)\n const formattedProcessName =\n processInfo && processInfo.length > 0 && processInfo[0]?.name\n ? ` ${content`${token.italic(`(${processInfo[0].name})`)}`.value}`\n : ''\n\n const options = [\n {name: 'Yes, terminate process in order to log in now', value: 'finish'},\n {name: `No, cancel command and try later`, value: 'cancel'},\n ]\n\n const choice = await prompt([\n {\n type: 'select',\n name: 'value',\n message: `${stepDescriptionContent} requires a port ${port} that's unavailable because it's running another process${formattedProcessName}. Terminate that process? `,\n choices: options,\n },\n ])\n return choice.value === 'finish'\n}\n\nexport const keypress = async () => {\n return new Promise((resolve, reject) => {\n const handler = (buffer: Buffer) => {\n process.stdin.setRawMode(false)\n process.stdin.pause()\n\n const bytes = Array.from(buffer)\n\n if (bytes.length && bytes[0] === 3) {\n debug('Canceled keypress, User pressed CTRL+C')\n reject(new AbortSilentError())\n }\n process.nextTick(resolve)\n }\n\n process.stdin.resume()\n process.stdin.setRawMode(true)\n process.stdin.once('data', handler)\n })\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopify/cli-kit",
3
- "version": "3.36.1",
3
+ "version": "3.37.0",
4
4
  "private": false,
5
5
  "description": "A set of utilities, interfaces, and models that are common across all the platform features",
6
6
  "keywords": [
package/dist/error.d.ts DELETED
@@ -1,68 +0,0 @@
1
- import { Message } from './output.js';
2
- import { TokenItem } from './private/node/ui/components/TokenizedText.js';
3
- export { ExtendableError } from 'ts-error';
4
- declare enum FatalErrorType {
5
- Abort = 0,
6
- AbortSilent = 1,
7
- Bug = 2
8
- }
9
- export declare class CancelExecution extends Error {
10
- }
11
- /**
12
- * A fatal error represents an error shouldn't be rescued and that causes the execution to terminate.
13
- * There shouldn't be code that catches fatal errors.
14
- */
15
- export declare abstract class Fatal extends Error {
16
- tryMessage: TokenItem | null;
17
- type: FatalErrorType;
18
- nextSteps?: TokenItem[];
19
- /**
20
- *
21
- * @param message - The error message
22
- * @param type - The type of fatal error
23
- * @param tryMessage - The message that recommends next steps to the user.
24
- * You can pass a string a {@link TokenizedString} or a {@link TokenItem}
25
- * if you need to style the message inside the error Banner component.
26
- */
27
- constructor(message: Message, type: FatalErrorType, tryMessage?: TokenItem | Message | null, nextSteps?: TokenItem[]);
28
- }
29
- /**
30
- * An abort error is a fatal error that shouldn't be reported as a bug.
31
- * Those usually represent unexpected scenarios that we can't handle and that usually require some action from the developer
32
- */
33
- export declare class Abort extends Fatal {
34
- nextSteps?: TokenItem[];
35
- constructor(message: Message, tryMessage?: TokenItem | Message | null, nextSteps?: TokenItem[]);
36
- }
37
- /**
38
- * An external error is similar to Abort but has extra command and args attributes.
39
- * This is useful to represent errors coming from external commands, usually executed by execa.
40
- */
41
- export declare class ExternalError extends Fatal {
42
- command: string;
43
- args: string[];
44
- constructor(message: Message, command: string, args: string[], tryMessage?: TokenItem | Message | null);
45
- }
46
- export declare class AbortSilent extends Fatal {
47
- constructor();
48
- }
49
- /**
50
- * A bug error is an error that represents a bug and therefore should be reported.
51
- */
52
- export declare class Bug extends Fatal {
53
- constructor(message: Message, tryMessage?: TokenItem | null);
54
- }
55
- /**
56
- * A function that handles errors that blow up in the CLI.
57
- * @param error - Error to be handled.
58
- * @returns A promise that resolves with the error passed.
59
- */
60
- export declare function handler(error: unknown): Promise<unknown>;
61
- export declare function mapper(error: unknown): Promise<unknown>;
62
- export declare function isFatal(error: unknown): error is Fatal;
63
- export declare function shouldReport(error: unknown): boolean;
64
- /**
65
- * Stack traces usually have file:// - we strip that and also remove the Windows drive designation
66
- *
67
- */
68
- export declare function cleanSingleStackTracePath(filePath: string): string;
package/dist/error.js DELETED
@@ -1,143 +0,0 @@
1
- import { stringifyMessage, TokenizedString } from './output.js';
2
- import { normalizePath } from './public/node/path.js';
3
- import { renderFatalError } from './public/node/ui.js';
4
- import { Errors } from '@oclif/core';
5
- export { ExtendableError } from 'ts-error';
6
- var FatalErrorType;
7
- (function (FatalErrorType) {
8
- FatalErrorType[FatalErrorType["Abort"] = 0] = "Abort";
9
- FatalErrorType[FatalErrorType["AbortSilent"] = 1] = "AbortSilent";
10
- FatalErrorType[FatalErrorType["Bug"] = 2] = "Bug";
11
- })(FatalErrorType || (FatalErrorType = {}));
12
- export class CancelExecution extends Error {
13
- }
14
- /**
15
- * A fatal error represents an error shouldn't be rescued and that causes the execution to terminate.
16
- * There shouldn't be code that catches fatal errors.
17
- */
18
- export class Fatal extends Error {
19
- /**
20
- *
21
- * @param message - The error message
22
- * @param type - The type of fatal error
23
- * @param tryMessage - The message that recommends next steps to the user.
24
- * You can pass a string a {@link TokenizedString} or a {@link TokenItem}
25
- * if you need to style the message inside the error Banner component.
26
- */
27
- constructor(message, type, tryMessage = null, nextSteps) {
28
- super(stringifyMessage(message));
29
- if (tryMessage) {
30
- if (tryMessage instanceof TokenizedString) {
31
- this.tryMessage = stringifyMessage(tryMessage);
32
- }
33
- else {
34
- this.tryMessage = tryMessage;
35
- }
36
- }
37
- else {
38
- this.tryMessage = null;
39
- }
40
- this.type = type;
41
- this.nextSteps = nextSteps;
42
- }
43
- }
44
- /**
45
- * An abort error is a fatal error that shouldn't be reported as a bug.
46
- * Those usually represent unexpected scenarios that we can't handle and that usually require some action from the developer
47
- */
48
- export class Abort extends Fatal {
49
- constructor(message, tryMessage = null, nextSteps) {
50
- super(message, FatalErrorType.Abort, tryMessage, nextSteps);
51
- }
52
- }
53
- /**
54
- * An external error is similar to Abort but has extra command and args attributes.
55
- * This is useful to represent errors coming from external commands, usually executed by execa.
56
- */
57
- export class ExternalError extends Fatal {
58
- constructor(message, command, args, tryMessage = null) {
59
- super(message, FatalErrorType.Abort, tryMessage);
60
- this.command = command;
61
- this.args = args;
62
- }
63
- }
64
- export class AbortSilent extends Fatal {
65
- constructor() {
66
- super('', FatalErrorType.AbortSilent);
67
- }
68
- }
69
- /**
70
- * A bug error is an error that represents a bug and therefore should be reported.
71
- */
72
- export class Bug extends Fatal {
73
- constructor(message, tryMessage = null) {
74
- super(message, FatalErrorType.Bug, tryMessage);
75
- }
76
- }
77
- /**
78
- * A function that handles errors that blow up in the CLI.
79
- * @param error - Error to be handled.
80
- * @returns A promise that resolves with the error passed.
81
- */
82
- export async function handler(error) {
83
- let fatal;
84
- if (isFatal(error)) {
85
- fatal = error;
86
- }
87
- else if (typeof error === 'string') {
88
- fatal = new Bug(error);
89
- }
90
- else if (error instanceof Error) {
91
- fatal = new Bug(error.message);
92
- fatal.stack = error.stack;
93
- }
94
- else {
95
- // errors can come in all shapes and sizes...
96
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
- const maybeError = error;
98
- fatal = new Bug(maybeError?.message ?? 'Unknown error');
99
- if (maybeError?.stack) {
100
- fatal.stack = maybeError?.stack;
101
- }
102
- }
103
- renderFatalError(fatal);
104
- return Promise.resolve(error);
105
- }
106
- export function mapper(error) {
107
- if (error instanceof Errors.CLIError) {
108
- const mappedError = new Abort(error.message);
109
- mappedError.stack = error.stack;
110
- return Promise.resolve(mappedError);
111
- }
112
- else {
113
- return Promise.resolve(error);
114
- }
115
- }
116
- export function isFatal(error) {
117
- try {
118
- return Object.prototype.hasOwnProperty.call(error, 'type');
119
- // eslint-disable-next-line no-catch-all/no-catch-all
120
- }
121
- catch {
122
- return false;
123
- }
124
- }
125
- export function shouldReport(error) {
126
- if (!isFatal(error)) {
127
- return true;
128
- }
129
- if (error.type === FatalErrorType.Bug) {
130
- return true;
131
- }
132
- return false;
133
- }
134
- /**
135
- * Stack traces usually have file:// - we strip that and also remove the Windows drive designation
136
- *
137
- */
138
- export function cleanSingleStackTracePath(filePath) {
139
- return normalizePath(filePath)
140
- .replace('file:/', '/')
141
- .replace(/^\/?[A-Z]:/, '');
142
- }
143
- //# sourceMappingURL=error.js.map
package/dist/error.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,gBAAgB,EAAE,eAAe,EAAC,MAAM,aAAa,CAAA;AACtE,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAElC,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAA;AAExC,IAAK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K,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,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,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,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,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;;;GAGG;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 {Message, stringifyMessage, TokenizedString} from './output.js'\nimport {normalizePath} from './public/node/path.js'\nimport {renderFatalError} from './public/node/ui.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 Fatal extends Error {\n tryMessage: TokenItem | null\n type: FatalErrorType\n nextSteps?: TokenItem[]\n /**\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 */\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 Abort extends Fatal {\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 Fatal {\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 AbortSilent extends Fatal {\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 Bug extends Fatal {\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 * @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: Fatal\n if (isFatal(error)) {\n fatal = error\n } else if (typeof error === 'string') {\n fatal = new Bug(error)\n } else if (error instanceof Error) {\n fatal = new Bug(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 Bug(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\nexport function mapper(error: unknown): Promise<unknown> {\n if (error instanceof Errors.CLIError) {\n const mappedError = new Abort(error.message)\n mappedError.stack = error.stack\n return Promise.resolve(mappedError)\n } else {\n return Promise.resolve(error)\n }\n}\n\nexport function isFatal(error: unknown): error is Fatal {\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\nexport function shouldReport(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 */\nexport function cleanSingleStackTracePath(filePath: string): string {\n return normalizePath(filePath)\n .replace('file:/', '/')\n .replace(/^\\/?[A-Z]:/, '')\n}\n"]}
package/dist/git.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import { Abort } from './error.js';
2
- import { DefaultLogFields, ListLogLine } from 'simple-git';
3
- export declare const factory: import("simple-git").SimpleGitFactory;
4
- export declare const GitNotPresentError: () => Abort;
5
- export declare const OutsideGitDirectoryError: (directory: string) => Abort;
6
- export declare const NoCommitError: () => Abort;
7
- export declare const DetachedHeadError: () => Abort;
8
- export declare function initializeRepository(directory: string, initialBranch?: string): Promise<void>;
9
- export interface GitIgnoreTemplate {
10
- [section: string]: string[];
11
- }
12
- export declare function createGitIgnore(directory: string, template: GitIgnoreTemplate): void;
13
- export declare function downloadRepository({ repoUrl, destination, progressUpdater, shallow, latestTag, }: {
14
- repoUrl: string;
15
- destination: string;
16
- progressUpdater?: (statusString: string) => void;
17
- shallow?: boolean;
18
- latestTag?: boolean;
19
- }): Promise<void>;
20
- export declare function getLatestCommit(directory?: string): Promise<DefaultLogFields & ListLogLine>;
21
- export declare function addAll(directory?: string): Promise<void>;
22
- export declare function commit(message: string, options?: {
23
- directory?: string;
24
- author?: string;
25
- }): Promise<string>;
26
- export declare function getHeadSymbolicRef(directory?: string): Promise<string>;
27
- /**
28
- * If "git" is not present in the environment it throws
29
- * an abort error.
30
- */
31
- export declare function ensurePresentOrAbort(): Promise<void>;
32
- /**
33
- * If command run from outside a .git directory tree
34
- * it throws an abort error.
35
- */
36
- export declare function ensureInsideGitDirectory(directory?: string): Promise<void>;
package/dist/git.js DELETED
@@ -1,133 +0,0 @@
1
- import { Abort } from './error.js';
2
- import { hasGit, isTerminalInteractive } from './public/node/environment/local.js';
3
- import { content, token, debug } from './output.js';
4
- import { appendFileSync } from './public/node/fs.js';
5
- import git from 'simple-git';
6
- export const factory = git;
7
- export const GitNotPresentError = () => {
8
- // eslint-disable-next-line rulesdir/no-error-factory-functions
9
- return new Abort(`Git is necessary in the environment to continue`, content `Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`);
10
- };
11
- export const OutsideGitDirectoryError = (directory) => {
12
- // eslint-disable-next-line rulesdir/no-error-factory-functions
13
- return new Abort(`${token.path(directory)} is not a Git directory`);
14
- };
15
- export const NoCommitError = () => {
16
- // eslint-disable-next-line rulesdir/no-error-factory-functions
17
- return new Abort('Must have at least one commit to run command', content `Run ${token.genericShellCommand("git commit -m 'Initial commit'")} to create your first commit.`);
18
- };
19
- export const DetachedHeadError = () => {
20
- // eslint-disable-next-line rulesdir/no-error-factory-functions
21
- return new Abort("Git HEAD can't be detached to run command", content `Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link('documentation', 'https://git-scm.com/book/en/v2/Git-Internals-Git-References')} for more details`);
22
- };
23
- export async function initializeRepository(directory, initialBranch = 'main') {
24
- debug(content `Initializing git repository at ${token.path(directory)}...`);
25
- await ensurePresentOrAbort();
26
- // We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+
27
- const repo = git(directory);
28
- await repo.init();
29
- await repo.checkoutLocalBranch(initialBranch);
30
- }
31
- export function createGitIgnore(directory, template) {
32
- debug(content `Creating .gitignore at ${token.path(directory)}...`);
33
- const filePath = `${directory}/.gitignore`;
34
- let fileContent = '';
35
- for (const [section, lines] of Object.entries(template)) {
36
- fileContent += `# ${section}\n`;
37
- fileContent += `${lines.join('\n')}\n\n`;
38
- }
39
- appendFileSync(filePath, fileContent);
40
- }
41
- export async function downloadRepository({ repoUrl, destination, progressUpdater, shallow, latestTag, }) {
42
- debug(content `Git-cloning repository ${repoUrl} into ${token.path(destination)}...`);
43
- await ensurePresentOrAbort();
44
- const [repository, branch] = repoUrl.split('#');
45
- const options = { '--recurse-submodules': null };
46
- if (branch && latestTag) {
47
- throw new Abort("Error cloning the repository. Git can't clone the latest release with a 'branch'.");
48
- }
49
- if (branch) {
50
- options['--branch'] = branch;
51
- }
52
- if (shallow && latestTag) {
53
- throw new Abort("Error cloning the repository. Git can't clone the latest release with the 'shallow' property.");
54
- }
55
- if (shallow) {
56
- options['--depth'] = 1;
57
- }
58
- const progress = ({ stage, progress, processed, total }) => {
59
- const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`;
60
- if (progressUpdater)
61
- progressUpdater(updateString);
62
- };
63
- const simpleGitOptions = {
64
- progress,
65
- ...(!isTerminalInteractive() && { config: ['core.askpass=true'] }),
66
- };
67
- try {
68
- await git(simpleGitOptions).clone(repository, destination, options);
69
- if (latestTag) {
70
- const localGitRepository = git(destination);
71
- const latestTag = await getLocalLatestTag(localGitRepository, repoUrl);
72
- await localGitRepository.checkout(latestTag);
73
- }
74
- }
75
- catch (err) {
76
- if (err instanceof Error) {
77
- const abortError = new Abort(err.message);
78
- abortError.stack = err.stack;
79
- throw abortError;
80
- }
81
- throw err;
82
- }
83
- }
84
- async function getLocalLatestTag(repository, repoUrl) {
85
- const latest = (await repository.tags()).latest;
86
- if (!latest) {
87
- throw new Abort(`Couldn't obtain the most recent tag of the repository ${repoUrl}`);
88
- }
89
- return latest;
90
- }
91
- export async function getLatestCommit(directory) {
92
- const logs = await git({ baseDir: directory }).log({
93
- maxCount: 1,
94
- });
95
- if (!logs.latest)
96
- throw NoCommitError();
97
- return logs.latest;
98
- }
99
- export async function addAll(directory) {
100
- const simpleGit = git({ baseDir: directory });
101
- await simpleGit.raw('add', '--all');
102
- }
103
- export async function commit(message, options) {
104
- const simpleGit = git({ baseDir: options?.directory });
105
- const commitOptions = options?.author ? { '--author': options.author } : undefined;
106
- const result = await simpleGit.commit(message, commitOptions);
107
- return result.commit;
108
- }
109
- export async function getHeadSymbolicRef(directory) {
110
- const ref = await git({ baseDir: directory }).raw('symbolic-ref', '-q', 'HEAD');
111
- if (!ref)
112
- throw DetachedHeadError();
113
- return ref.trim();
114
- }
115
- /**
116
- * If "git" is not present in the environment it throws
117
- * an abort error.
118
- */
119
- export async function ensurePresentOrAbort() {
120
- if (!(await hasGit())) {
121
- throw GitNotPresentError();
122
- }
123
- }
124
- /**
125
- * If command run from outside a .git directory tree
126
- * it throws an abort error.
127
- */
128
- export async function ensureInsideGitDirectory(directory) {
129
- if (!(await git({ baseDir: directory }).checkIsRepo())) {
130
- throw OutsideGitDirectoryError(directory || process.cwd());
131
- }
132
- }
133
- //# sourceMappingURL=git.js.map
package/dist/git.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,MAAM,EAAE,qBAAqB,EAAC,MAAM,oCAAoC,CAAA;AAChF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAA;AAClD,OAAO,GAAoF,MAAM,YAAY,CAAA;AAE7G,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAA;AAE1B,MAAM,CAA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OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,EAAE;QACrB,MAAM,kBAAkB,EAAE,CAAA;KAC3B;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,SAAkB;IAC/D,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE;QACpD,MAAM,wBAAwB,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;KAC3D;AACH,CAAC","sourcesContent":["import {Abort} from './error.js'\nimport {hasGit, isTerminalInteractive} from './public/node/environment/local.js'\nimport {content, token, debug} from './output.js'\nimport {appendFileSync} from './public/node/fs.js'\nimport git, {TaskOptions, SimpleGitProgressEvent, DefaultLogFields, ListLogLine, SimpleGit} from 'simple-git'\n\nexport const factory = git\n\nexport const GitNotPresentError = () => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(\n `Git is necessary in the environment to continue`,\n content`Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`,\n )\n}\n\nexport const OutsideGitDirectoryError = (directory: string) => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(`${token.path(directory)} is not a Git directory`)\n}\n\nexport const NoCommitError = () => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(\n 'Must have at least one commit to run command',\n content`Run ${token.genericShellCommand(\"git commit -m 'Initial commit'\")} to create your first commit.`,\n )\n}\n\nexport const DetachedHeadError = () => {\n // eslint-disable-next-line rulesdir/no-error-factory-functions\n return new Abort(\n \"Git HEAD can't be detached to run command\",\n content`Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link(\n 'documentation',\n 'https://git-scm.com/book/en/v2/Git-Internals-Git-References',\n )} for more details`,\n )\n}\n\nexport async function initializeRepository(directory: string, initialBranch = 'main') {\n debug(content`Initializing git repository at ${token.path(directory)}...`)\n await ensurePresentOrAbort()\n // We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+\n const repo = git(directory)\n await repo.init()\n await repo.checkoutLocalBranch(initialBranch)\n}\n\nexport interface GitIgnoreTemplate {\n [section: string]: string[]\n}\nexport function createGitIgnore(directory: string, template: GitIgnoreTemplate): void {\n debug(content`Creating .gitignore at ${token.path(directory)}...`)\n const filePath = `${directory}/.gitignore`\n\n let fileContent = ''\n for (const [section, lines] of Object.entries(template)) {\n fileContent += `# ${section}\\n`\n fileContent += `${lines.join('\\n')}\\n\\n`\n }\n\n appendFileSync(filePath, fileContent)\n}\n\nexport async function downloadRepository({\n repoUrl,\n destination,\n progressUpdater,\n shallow,\n latestTag,\n}: {\n repoUrl: string\n destination: string\n progressUpdater?: (statusString: string) => void\n shallow?: boolean\n latestTag?: boolean\n}) {\n debug(content`Git-cloning repository ${repoUrl} into ${token.path(destination)}...`)\n await ensurePresentOrAbort()\n const [repository, branch] = repoUrl.split('#')\n const options: TaskOptions = {'--recurse-submodules': null}\n\n if (branch && latestTag) {\n throw new Abort(\"Error cloning the repository. Git can't clone the latest release with a 'branch'.\")\n }\n if (branch) {\n options['--branch'] = branch\n }\n\n if (shallow && latestTag) {\n throw new Abort(\"Error cloning the repository. Git can't clone the latest release with the 'shallow' property.\")\n }\n if (shallow) {\n options['--depth'] = 1\n }\n\n const progress = ({stage, progress, processed, total}: SimpleGitProgressEvent) => {\n const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`\n if (progressUpdater) progressUpdater(updateString)\n }\n\n const simpleGitOptions = {\n progress,\n ...(!isTerminalInteractive() && {config: ['core.askpass=true']}),\n }\n try {\n await git(simpleGitOptions).clone(repository!, destination, options)\n\n if (latestTag) {\n const localGitRepository = git(destination)\n const latestTag = await getLocalLatestTag(localGitRepository, repoUrl)\n await localGitRepository.checkout(latestTag)\n }\n } catch (err) {\n if (err instanceof Error) {\n const abortError = new Abort(err.message)\n abortError.stack = err.stack\n throw abortError\n }\n throw err\n }\n}\n\nasync function getLocalLatestTag(repository: SimpleGit, repoUrl: string) {\n const latest = (await repository.tags()).latest\n\n if (!latest) {\n throw new Abort(`Couldn't obtain the most recent tag of the repository ${repoUrl}`)\n }\n\n return latest\n}\n\nexport async function getLatestCommit(directory?: string): Promise<DefaultLogFields & ListLogLine> {\n const logs = await git({baseDir: directory}).log({\n maxCount: 1,\n })\n if (!logs.latest) throw NoCommitError()\n return logs.latest\n}\n\nexport async function addAll(directory?: string): Promise<void> {\n const simpleGit = git({baseDir: directory})\n await simpleGit.raw('add', '--all')\n}\n\nexport async function commit(message: string, options?: {directory?: string; author?: string}): Promise<string> {\n const simpleGit = git({baseDir: options?.directory})\n\n const commitOptions = options?.author ? {'--author': options.author} : undefined\n const result = await simpleGit.commit(message, commitOptions)\n\n return result.commit\n}\n\nexport async function getHeadSymbolicRef(directory?: string): Promise<string> {\n const ref = await git({baseDir: directory}).raw('symbolic-ref', '-q', 'HEAD')\n if (!ref) throw DetachedHeadError()\n return ref.trim()\n}\n\n/**\n * If \"git\" is not present in the environment it throws\n * an abort error.\n */\nexport async function ensurePresentOrAbort() {\n if (!(await hasGit())) {\n throw GitNotPresentError()\n }\n}\n\n/**\n * If command run from outside a .git directory tree\n * it throws an abort error.\n */\nexport async function ensureInsideGitDirectory(directory?: string) {\n if (!(await git({baseDir: directory}).checkIsRepo())) {\n throw OutsideGitDirectoryError(directory || process.cwd())\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAA;AAEjE,OAAO,EAAC,UAAU,EAAC,MAAM,oCAAoC,CAAA;AAY7D,SAAS,gCAAgC;IACvC,IAAI,UAAU,E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S,EAAC,CAAA;QAC3B,CAAC;QACD,SAAS,EAAE,KAAK,EAAE,OAAiC,EAAE,UAAiC,MAAM,EAAE,EAAE;YAC9F,OAAO,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACjD,CAAC;QACD,YAAY,EAAE,KAAK,EAAE,OAAoC,EAAE,UAAiC,MAAM,EAAE,EAAE;YACpG,OAAO,WAAW,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACpD,CAAC;KACF,CAAA;AACH,CAAC;AAOD,MAAM,QAAQ,GAAG,8BAA8B,EAU5C,CAAA;AAEH,MAAM,CAAC,MAAM,EAAC,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAC,GAAG,QAAQ,CAAA","sourcesContent":["import {AnyJson} from './private/common/json.js'\nimport {MonorailEventPublic} from './monorail.js'\nimport {sendErrorToBugsnag} from './public/node/error-handler.js'\nimport {PickByPrefix} from './public/common/ts/pick-by-prefix.js'\nimport {isUnitTest} from './public/node/environment/local.js'\n\ntype ProvideMetadata<T> = () => Partial<T> | Promise<Partial<T>>\n\ntype MetadataErrorHandling =\n // Mute & report errors in production, throw them whilst testing\n | 'auto'\n // Errors are not reported to the user and do not stop execution, but they are reported to Bugsnag\n | 'mute-and-report'\n // Errors are not caught and will bubble out as normal\n | 'bubble'\n\nfunction getMetadataErrorHandlingStrategy(): 'mute-and-report' | 'bubble' {\n if (isUnitTest()) {\n return 'bubble'\n }\n return 'mute-and-report'\n}\n\nexport interface RuntimeMetadataManager<TPublic extends AnyJson, TSensitive extends AnyJson> {\n /** Add some public metadata -- this should not contain any PII */\n addPublic: (getData: ProvideMetadata<TPublic>, onError?: MetadataErrorHandling) => Promise<void>\n /** Add some potentially sensitive metadata -- this may include PII, but unnecessary data should never be tracked (this is a good fit for command args for instance) */\n addSensitive: (getData: ProvideMetadata<TSensitive>, onError?: MetadataErrorHandling) => Promise<void>\n /** Get a snapshot of the tracked public data */\n getAllPublic: () => Partial<TPublic>\n /** Get a snapshot of the tracked sensitive data */\n getAllSensitive: () => Partial<TSensitive>\n}\n\nexport type PublicSchema<T> = T extends RuntimeMetadataManager<infer TPublic, infer _TSensitive> ? TPublic : never\nexport type SensitiveSchema<T> = T extends RuntimeMetadataManager<infer _TPublic, infer TSensitive> ? TSensitive : never\n\n/**\n * Creates a container for metadata collected at runtime.\n *\n * The container provides async-safe functions for extracting the gathered metadata, and for setting it.\n *\n */\nexport function createRuntimeMetadataContainer<\n TPublic extends AnyJson,\n TSensitive extends AnyJson = {[key: string]: never},\n>(): RuntimeMetadataManager<TPublic, TSensitive> {\n const raw: {sensitive: Partial<TSensitive>; public: Partial<TPublic>} = {\n sensitive: {},\n public: {},\n }\n const addPublic = (data: Partial<TPublic>) => {\n Object.assign(raw.public, data)\n }\n const addSensitive = (data: Partial<TSensitive>) => {\n Object.assign(raw.sensitive, data)\n }\n\n const addMetadata = async <T>(\n addFn: (data: Partial<T>) => void,\n getFn: ProvideMetadata<T>,\n onError: MetadataErrorHandling,\n ) => {\n const errorHandling = onError === 'auto' ? getMetadataErrorHandlingStrategy() : onError\n const getAndSet = async () => {\n const data = await getFn()\n addFn(data)\n }\n\n if (errorHandling === 'bubble') {\n await getAndSet()\n } else {\n try {\n await getAndSet()\n // eslint-disable-next-line no-catch-all/no-catch-all, @typescript-eslint/no-explicit-any\n } catch (error: any) {\n await sendErrorToBugsnag(error)\n }\n }\n }\n\n return {\n getAllPublic: () => {\n return {...raw.public}\n },\n getAllSensitive: () => {\n return {...raw.sensitive}\n },\n addPublic: async (getData: ProvideMetadata<TPublic>, onError: MetadataErrorHandling = 'auto') => {\n return addMetadata(addPublic, getData, onError)\n },\n addSensitive: async (getData: ProvideMetadata<TSensitive>, onError: MetadataErrorHandling = 'auto') => {\n return addMetadata(addSensitive, getData, onError)\n },\n }\n}\n\n// We want to track anything that ends up getting sent to monorail as `cmd_all_*` and\n// `cmd_app_*`\ntype CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_all_'> &\n PickByPrefix<MonorailEventPublic, 'cmd_app_'>\n\nconst coreData = createRuntimeMetadataContainer<\n CmdFieldsFromMonorail,\n {\n commandStartOptions: {\n startTime: number\n startCommand: string\n startTopic?: string\n startArgs: string[]\n }\n }\n>()\n\nexport const {getAllPublic, getAllSensitive, addPublic, addSensitive} = coreData\n\nexport type Public = PublicSchema<typeof coreData>\nexport type Sensitive = SensitiveSchema<typeof coreData>\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"monorail.js","sourceRoot":"","sources":["../src/monorail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,uBAAuB,CAAA;AAC3C,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AAIjD,MAAM,GAAG,GAAG,iDAAiD,CAAA;AAI7D,mFAAmF;AACnF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAA+B,CAAA;AA+GrE,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAmB,EACnB,UAA8B,EAC9B,aAAoC;IAEpC,IAAI;QACF,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;QACxC,MAAM,OAAO,GAAG,EAAC,GAAG,UAAU,EAAE,GAAG,aAAa,EAAC,CAAA;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAC,CAAC,CAAA;QAC3D,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;QAEzC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAA;QAElE,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YAC3B,KAAK,CAAC,OAAO,CAAA,yBAAyB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC5D,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,CAAA;SACpB;aAAM;YACL,KAAK,CAAC,qCAAqC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;YACjE,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,UAAU,EAAC,CAAA;SACrD;QACD,qDAAqD;KACtD;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,OAAO,GAAG,kCAAkC,CAAA;QAChD,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;SAC/C;QACD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAC,CAAA;KAChC;AACH,CAAC;AAED,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAE,EAAE;IAC3C,OAAO;QACL,cAAc,EAAE,iCAAiC;QACjD,qCAAqC,EAAE,WAAW,CAAC,QAAQ,EAAE;QAC7D,kCAAkC,EAAE,WAAW,CAAC,QAAQ,EAAE;KAC3D,CAAA;AACH,CAAC,CAAA","sourcesContent":["import {fetch} from './public/node/http.js'\nimport {debug, content, token} from './output.js'\nimport {JsonMap} from './private/common/json.js'\nimport {DeepRequired} from './private/common/ts/deep-required.js'\n\nconst url = 'https://monorail-edge.shopifysvc.com/v1/produce'\n\ntype Optional<T> = T | null\n\n// This is the topic name of the main event we log to Monorail, the command tracker\nexport const MONORAIL_COMMAND_TOPIC = 'app_cli3_command/1.2' as const\n\nexport interface Schemas {\n [MONORAIL_COMMAND_TOPIC]: {\n sensitive: {\n args: string\n error_message?: Optional<string>\n app_name?: Optional<string>\n metadata?: Optional<string>\n store_fqdn?: Optional<string>\n\n // Dev related commands\n cmd_dev_tunnel_custom?: Optional<string>\n\n // Environment\n env_plugin_installed_all?: Optional<string>\n }\n public: {\n partner_id?: Optional<number>\n command: string\n project_type?: Optional<string>\n time_start: number\n time_end: number\n total_time: number\n success: boolean\n api_key?: Optional<string>\n cli_version: string\n uname: string\n ruby_version: string\n node_version: string\n is_employee: boolean\n store_fqdn_hash?: Optional<string>\n\n // Any and all commands\n cmd_all_alias_used?: Optional<string>\n cmd_all_launcher?: Optional<string>\n cmd_all_path_override?: Optional<boolean>\n cmd_all_path_override_hash?: Optional<string>\n cmd_all_plugin?: Optional<string>\n cmd_all_topic?: Optional<string>\n cmd_all_verbose?: Optional<boolean>\n\n // Any extension related command\n cmd_extensions_binary_from_source?: Optional<boolean>\n\n // Scaffolding related commands\n cmd_scaffold_required_auth?: Optional<boolean>\n cmd_scaffold_template_custom?: Optional<boolean>\n cmd_scaffold_template_flavor?: Optional<string>\n cmd_scaffold_type?: Optional<string>\n cmd_scaffold_type_category?: Optional<string>\n cmd_scaffold_type_gated?: Optional<boolean>\n cmd_scaffold_type_owner?: Optional<string>\n cmd_scaffold_used_prompts_for_type?: Optional<boolean>\n\n // Used in several but not all commands\n cmd_app_dependency_installation_skipped?: Optional<boolean>\n cmd_app_reset_used?: Optional<boolean>\n\n // Dev related commands\n cmd_dev_tunnel_type?: Optional<string>\n cmd_dev_tunnel_custom_hash?: Optional<string>\n cmd_dev_urls_updated?: Optional<boolean>\n\n // App setup\n app_extensions_any?: Optional<boolean>\n app_extensions_breakdown?: Optional<string>\n app_extensions_count?: Optional<number>\n app_extensions_custom_layout?: Optional<boolean>\n app_extensions_function_any?: Optional<boolean>\n app_extensions_function_count?: Optional<number>\n app_extensions_function_custom_layout?: Optional<boolean>\n app_extensions_theme_any?: Optional<boolean>\n app_extensions_theme_count?: Optional<number>\n app_extensions_theme_custom_layout?: Optional<boolean>\n app_extensions_ui_any?: Optional<boolean>\n app_extensions_ui_count?: Optional<number>\n app_extensions_ui_custom_layout?: Optional<boolean>\n app_name_hash?: Optional<string>\n app_path_hash?: Optional<string>\n app_scopes?: Optional<string>\n app_web_backend_any?: Optional<boolean>\n app_web_backend_count?: Optional<number>\n app_web_custom_layout?: Optional<boolean>\n app_web_framework?: Optional<string>\n app_web_frontend_any?: Optional<boolean>\n app_web_frontend_count?: Optional<number>\n\n // Environment\n env_ci?: Optional<boolean>\n env_ci_platform?: Optional<string>\n env_device_id?: Optional<string>\n env_package_manager?: Optional<string>\n env_package_manager_workspaces?: Optional<boolean>\n env_plugin_installed_any_custom?: Optional<boolean>\n env_plugin_installed_shopify?: Optional<string>\n env_shell?: Optional<string>\n env_web_ide?: Optional<string>\n env_cloud?: Optional<string>\n }\n }\n [schemaId: string]: {sensitive: JsonMap; public: JsonMap}\n}\n\n// In reality, we're normally most interested in just this from Schemas, so export it for ease of use.\n// The monorail schema itself has lots of optional values as it must be backwards-compatible. For our schema we want mandatory values instead.\nexport type MonorailEventPublic = DeepRequired<Schemas[typeof MONORAIL_COMMAND_TOPIC]['public']>\nexport type MonorailEventSensitive = Schemas[typeof MONORAIL_COMMAND_TOPIC]['sensitive']\n\ntype MonorailResult = {type: 'ok'} | {type: 'error'; message: string}\n\nexport async function publishEvent<TSchemaId extends keyof Schemas, TPayload extends Schemas[TSchemaId]>(\n schemaId: TSchemaId,\n publicData: TPayload['public'],\n sensitiveData: TPayload['sensitive'],\n): Promise<MonorailResult> {\n try {\n const currentTime = new Date().getTime()\n const payload = {...publicData, ...sensitiveData}\n const body = JSON.stringify({schema_id: schemaId, payload})\n const headers = buildHeaders(currentTime)\n\n const response = await fetch(url, {method: 'POST', body, headers})\n\n if (response.status === 200) {\n debug(content`Analytics event sent: ${token.json(payload)}`)\n return {type: 'ok'}\n } else {\n debug(`Failed to report usage analytics: ${response.statusText}`)\n return {type: 'error', message: response.statusText}\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n let message = 'Failed to report usage analytics'\n if (error instanceof Error) {\n message = message.concat(`: ${error.message}`)\n }\n debug(message)\n return {type: 'error', message}\n }\n}\n\nconst buildHeaders = (currentTime: number) => {\n return {\n 'Content-Type': 'application/json; charset=utf-8',\n 'X-Monorail-Edge-Event-Created-At-Ms': currentTime.toString(),\n 'X-Monorail-Edge-Event-Sent-At-Ms': currentTime.toString(),\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,0BAA0B,EAAE,0BAA0B,EAAC,MAAM,0BAA0B,CAAA;AAC/F,OAAO,EAAC,GAAG,EAAS,MAAM,yBAAyB,CAAA;AAGnD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAyB,EACzB,KAAa,EACb,OAA4C,EAC5C,OAAgB;IAEhB,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACzD,8DAA8D;IAC9D,OAAO,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAC,MAAM,EAAE,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAQ,CAAA;AAClG,CAAC;AA4CD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAAc;IACzD,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAA;IAC9D,MAAM,KAAK,GAAG,0BAA0B,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;IACtF,IAAI,0BAA0B,CAAC,KAAK,CAAC;QAAE,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,+BAA+B,EAAC,CAAA;IACtG,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,CAAA;AACzB,CAAC;AAQD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAc,EACd,IAAY,EACZ,QAAgB;IAEhB,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAA;IACzE,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAC5C,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,cAAc,EAAE,KAAK,EAAE,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB,CACjG,CAAA;IACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,EAAC,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAC,CAAC,CAAA;IACxE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC,EAAC,QAAQ,EAAE,IAAI,EAAE,aAAa,EAAC,CAAC,CAAA;IAE1F,OAAO,UAAU,CAAC,CAAC,CAAC;SACjB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;SACvB,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAClB,KAAK,CAAC,IAAI,KAAK,SAAS;QACtB,CAAC,CAAC,EAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAC;QACrD,CAAC,CAAC,EAAC,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAC,CACtC,CAAA;AACL,CAAC","sourcesContent":["import {JsonMap} from './private/common/json.js'\nimport {PickByPrefix} from './public/common/ts/pick-by-prefix.js'\nimport {MonorailEventPublic, MonorailEventSensitive} from './monorail.js'\nimport {HookReturnPerTunnelPlugin} from './public/node/plugins/tunnel.js'\nimport {getArrayContainsDuplicates, getArrayRejectingUndefined} from './public/common/array.js'\nimport {err, Result} from './public/node/result.js'\nimport {Config, Interfaces} from '@oclif/core'\n\n/**\n * Convenience function to trigger a hook, and gather any successful responses. Failures are ignored.\n *\n * Responses are organised into a dictionary, keyed by plug-in name. Only plug-ins that have hooks registered for the given event, and the hooks were run successfully, are included.\n */\nexport async function fanoutHooks<TPluginMap extends HookReturnsPerPlugin, TEvent extends string & keyof TPluginMap>(\n config: Interfaces.Config,\n event: TEvent,\n options: TPluginMap[typeof event]['options'],\n timeout?: number,\n): Promise<Partial<TPluginMap[typeof event]['pluginReturns']>> {\n const res = await config.runHook(event, options, timeout)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return Object.fromEntries(res.successes.map(({result, plugin}) => [plugin.name, result])) as any\n}\n\ntype AppSpecificMonorailFields = PickByPrefix<MonorailEventPublic, 'app_', 'project_type' | 'api_key' | 'partner_id'> &\n PickByPrefix<MonorailEventPublic, 'cmd_extensions_'> &\n PickByPrefix<MonorailEventPublic, 'cmd_scaffold_'>\n\ntype AppSpecificSensitiveMonorailFields = PickByPrefix<MonorailEventSensitive, 'app_'>\n\nexport interface HookReturnsPerPlugin extends HookReturnPerTunnelPlugin {\n public_command_metadata: {\n options: {[key: string]: never}\n pluginReturns: {\n '@shopify/app': Partial<AppSpecificMonorailFields>\n [pluginName: string]: JsonMap\n }\n }\n sensitive_command_metadata: {\n options: {[key: string]: never}\n pluginReturns: {\n '@shopify/app': Partial<AppSpecificSensitiveMonorailFields>\n [pluginName: string]: JsonMap\n }\n }\n [hookName: string]: {\n options: {[key: string]: unknown}\n pluginReturns: {[key: string]: unknown}\n }\n}\n\nexport type PluginReturnsForHook<\n TEvent extends keyof TPluginMap,\n TPluginName extends keyof TPluginMap[TEvent]['pluginReturns'],\n TPluginMap extends HookReturnsPerPlugin = HookReturnsPerPlugin,\n> = TPluginMap[TEvent]['pluginReturns'][TPluginName]\n\nexport type FanoutHookFunction<\n TEvent extends keyof TPluginMap = string,\n TPluginName extends keyof TPluginMap[TEvent]['pluginReturns'] = string,\n TPluginMap extends HookReturnsPerPlugin = HookReturnsPerPlugin,\n> = (\n this: Interfaces.Hook.Context,\n options: TPluginMap[TEvent]['options'] & {config: Interfaces.Config},\n) => Promise<PluginReturnsForHook<TEvent, TPluginName, TPluginMap>>\n\n/**\n * Execute the 'tunnel_provider' hook, and return the list of available tunnel providers.\n * Fail if there are multiple plugins for the same provider\n *\n * @param config - oclif config used to execute hooks\n * @returns list of available tunnel plugins\n */\nexport async function getListOfTunnelPlugins(config: Config): Promise<{plugins: string[]; error?: string}> {\n const hooks = await fanoutHooks(config, 'tunnel_provider', {})\n const names = getArrayRejectingUndefined(Object.values(hooks).map((key) => key?.name))\n if (getArrayContainsDuplicates(names)) return {plugins: names, error: 'multiple-plugins-for-provider'}\n return {plugins: names}\n}\n\nexport interface TunnelPluginError {\n provider: string\n type: 'multiple-urls' | 'handled-error' | 'unknown' | 'no-provider'\n message?: string\n}\n\n/**\n * Execute the 'tunnel_start' hook for the given provider.\n * Fails if there aren't plugins for that provider or if there are more than one.\n *\n * @param config - oclif config used to execute hooks\n * @param port - port where the tunnel will be started\n * @param provider - selected provider, must be unique\n * @returns tunnel URL from the selected provider\n */\nexport async function runTunnelPlugin(\n config: Config,\n port: number,\n provider: string,\n): Promise<Result<string, TunnelPluginError>> {\n const hooks = await fanoutHooks(config, 'tunnel_start', {port, provider})\n const urlResults = Object.values(hooks).filter(\n (tunnelResponse) => !tunnelResponse?.isErr() || tunnelResponse.error.type !== 'invalid-provider',\n )\n if (urlResults.length > 1) return err({provider, type: 'multiple-urls'})\n if (urlResults.length === 0 || !urlResults[0]) return err({provider, type: 'no-provider'})\n\n return urlResults[0]\n .map((data) => data.url)\n .mapError((error) =>\n error.type === 'unknown'\n ? {provider, type: 'unknown', message: error.message}\n : {provider, type: 'handled-error'},\n )\n}\n"]}
package/dist/schema.d.ts DELETED
@@ -1 +0,0 @@
1
- export { z as define } from 'zod';
package/dist/schema.js DELETED
@@ -1,2 +0,0 @@
1
- export { z as define } from 'zod';
2
- //# sourceMappingURL=schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,IAAI,MAAM,EAAC,MAAM,KAAK,CAAA","sourcesContent":["export {z as define} from 'zod'\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"secure-store.js","sourceRoot":"","sources":["../src/secure-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,aAAa,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AAC3D,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAA;AAE7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,UAAkB;IAC5C,KAAK,CAAC,aAAa,CAAA,WAAW,UAAU,2BAA2B,CAAC,CAAA;IACpE,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QAC/E,OAAO,OAAO,CAAA;KACf;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,CAAC,KAAK,EAAE,sCAAsC,CAAC,CAAA;KACjE;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,UAAkB,EAAE,OAAe;IAC7D,KAAK,CAAC,aAAa,CAAA,YAAY,UAAU,0CAA0C,CAAC,CAAA;IACpF,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;KACjF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,CAAC,KAAK,EAAE,mCAAmC,CAAC,CAAA;KAC9D;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,UAAkB;IAC7C,KAAK,CAAC,aAAa,CAAA,YAAY,UAAU,2BAA2B,CAAC,CAAA;IACrE,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QACzF,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,CAAC,KAAK,EAAE,wCAAwC,CAAC,CAAA;KACnE;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,OAAe;IAClD,IAAI,UAAU,GAAG,OAAO,CAAA;IACxB,IAAI,KAAK,GAAuB,EAAE,CAAA;IAClC,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;QACjD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;KACpB;IACD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;IACnC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAA;IACnB,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {content as outputContent, debug} from './output.js'\nimport {Abort} from './error.js'\nimport {keychainConstants} from './private/node/constants.js'\n\n/**\n * Fetches secured content from the system's keychain.\n * @param identifier - Identifier to identify the content.\n * @returns A promise that resolves with the content or null if it doesn't exist.\n */\nexport async function fetch(identifier: string): Promise<string | null> {\n debug(outputContent`Reading ${identifier} from the secure store...`)\n try {\n const keytar = await import('keytar')\n const content = await keytar.getPassword(keychainConstants.service, identifier)\n return content\n } catch (error) {\n throw createAbort(error, 'Unable to read from the secure store')\n }\n}\n\n/**\n * Securely stores the content under the given key.\n * @param identifier - Identifier to identify the content.\n * @param content - The content to be stored.\n * @returns A promise that resolves when the storing completes.\n */\nexport async function store(identifier: string, content: string): Promise<void> {\n debug(outputContent`Updating ${identifier} in the secure store with new content...`)\n try {\n const keytar = await import('keytar')\n await keytar.default.setPassword(keychainConstants.service, identifier, content)\n } catch (error) {\n throw createAbort(error, 'Unable to update the secure store')\n }\n}\n\n/**\n * Removes the content with the given identifier.\n * @param identifier - Identifier to identify the content.\n * @returns A promise that resolves with true if the content was deleted.\n */\nexport async function remove(identifier: string): Promise<boolean> {\n debug(outputContent`Removing ${identifier} from the secure store...`)\n try {\n const keytar = await import('keytar')\n const result = await keytar.default.deletePassword(keychainConstants.service, identifier)\n return result\n } catch (error) {\n throw createAbort(error, 'Unable to remove from the secure store')\n }\n}\n\nfunction createAbort(error: unknown, message: string) {\n let newMessage = message\n let stack: string | undefined = ''\n if (error instanceof Error) {\n newMessage = message.concat(`: ${error.message}`)\n stack = error.stack\n }\n const abort = new Abort(newMessage)\n abort.stack = stack\n return abort\n}\n"]}