@shopify/cli-kit 3.0.23 → 3.0.26

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 (287) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/assets/auth-error.html +2 -4
  3. package/assets/empty-url.html +2 -4
  4. package/assets/missing-code.html +2 -4
  5. package/assets/missing-state.html +2 -4
  6. package/assets/style.css +5 -8
  7. package/assets/success.html +1 -1
  8. package/dist/abort.d.ts +1 -0
  9. package/dist/abort.js +2 -0
  10. package/dist/abort.js.map +1 -0
  11. package/dist/analytics.d.ts +11 -0
  12. package/dist/analytics.js +96 -0
  13. package/dist/analytics.js.map +1 -0
  14. package/dist/api/admin.d.ts +3 -0
  15. package/dist/api/admin.js +80 -0
  16. package/dist/api/admin.js.map +1 -0
  17. package/dist/api/common.d.ts +11 -0
  18. package/dist/api/common.js +40 -0
  19. package/dist/api/common.js.map +1 -0
  20. package/dist/api/graphql/all_app_extension_registrations.d.ts +14 -0
  21. package/dist/api/graphql/all_app_extension_registrations.js +14 -0
  22. package/dist/api/graphql/all_app_extension_registrations.js.map +1 -0
  23. package/dist/api/graphql/all_orgs.d.ts +12 -0
  24. package/dist/api/graphql/all_orgs.js +14 -0
  25. package/dist/api/graphql/all_orgs.js.map +1 -0
  26. package/dist/api/graphql/all_stores_by_org.d.ts +18 -0
  27. package/dist/api/graphql/all_stores_by_org.js +21 -0
  28. package/dist/api/graphql/all_stores_by_org.js.map +1 -0
  29. package/dist/api/graphql/convert_dev_to_test_store.d.ts +16 -0
  30. package/dist/api/graphql/convert_dev_to_test_store.js +13 -0
  31. package/dist/api/graphql/convert_dev_to_test_store.js.map +1 -0
  32. package/dist/api/graphql/create_app.d.ts +28 -0
  33. package/dist/api/graphql/create_app.js +32 -0
  34. package/dist/api/graphql/create_app.js.map +1 -0
  35. package/dist/api/graphql/create_deployment.d.ts +33 -0
  36. package/dist/api/graphql/create_deployment.js +25 -0
  37. package/dist/api/graphql/create_deployment.js.map +1 -0
  38. package/dist/api/graphql/extension_create.d.ts +30 -0
  39. package/dist/api/graphql/extension_create.js +26 -0
  40. package/dist/api/graphql/extension_create.js.map +1 -0
  41. package/dist/api/graphql/extension_specifications.d.ts +18 -0
  42. package/dist/api/graphql/extension_specifications.js +18 -0
  43. package/dist/api/graphql/extension_specifications.js.map +1 -0
  44. package/dist/api/graphql/find_app.d.ts +13 -0
  45. package/dist/api/graphql/find_app.js +16 -0
  46. package/dist/api/graphql/find_app.js.map +1 -0
  47. package/dist/api/graphql/find_org.d.ts +23 -0
  48. package/dist/api/graphql/find_org.js +26 -0
  49. package/dist/api/graphql/find_org.js.map +1 -0
  50. package/dist/api/graphql/find_org_basic.d.ts +11 -0
  51. package/dist/api/graphql/find_org_basic.js +14 -0
  52. package/dist/api/graphql/find_org_basic.js.map +1 -0
  53. package/dist/api/graphql/functions/app_function_set.d.ts +43 -0
  54. package/dist/api/graphql/functions/app_function_set.js +52 -0
  55. package/dist/api/graphql/functions/app_function_set.js.map +1 -0
  56. package/dist/api/graphql/functions/compile_module.d.ts +15 -0
  57. package/dist/api/graphql/functions/compile_module.js +13 -0
  58. package/dist/api/graphql/functions/compile_module.js.map +1 -0
  59. package/dist/api/graphql/functions/function_service_proxy.d.ts +4 -0
  60. package/dist/api/graphql/functions/function_service_proxy.js +7 -0
  61. package/dist/api/graphql/functions/function_service_proxy.js.map +1 -0
  62. package/dist/api/graphql/functions/get_app_functions.d.ts +1 -0
  63. package/dist/api/graphql/functions/get_app_functions.js +10 -0
  64. package/dist/api/graphql/functions/get_app_functions.js.map +1 -0
  65. package/dist/api/graphql/functions/module_compilation_status.d.ts +15 -0
  66. package/dist/api/graphql/functions/module_compilation_status.js +13 -0
  67. package/dist/api/graphql/functions/module_compilation_status.js.map +1 -0
  68. package/dist/api/graphql/functions/module_upload_url_generate.d.ts +18 -0
  69. package/dist/api/graphql/functions/module_upload_url_generate.js +17 -0
  70. package/dist/api/graphql/functions/module_upload_url_generate.js.map +1 -0
  71. package/dist/api/graphql/generate_signed_upload_url.d.ts +15 -0
  72. package/dist/api/graphql/generate_signed_upload_url.js +15 -0
  73. package/dist/api/graphql/generate_signed_upload_url.js.map +1 -0
  74. package/dist/api/graphql/get_variant_id.d.ts +17 -0
  75. package/dist/api/graphql/get_variant_id.js +20 -0
  76. package/dist/api/graphql/get_variant_id.js.map +1 -0
  77. package/dist/api/graphql/index.d.ts +21 -0
  78. package/dist/api/graphql/index.js +22 -0
  79. package/dist/api/graphql/index.js.map +1 -0
  80. package/dist/api/graphql/update_draft.d.ts +33 -0
  81. package/dist/api/graphql/update_draft.js +24 -0
  82. package/dist/api/graphql/update_draft.js.map +1 -0
  83. package/dist/api/graphql/update_urls.d.ts +14 -0
  84. package/dist/api/graphql/update_urls.js +12 -0
  85. package/dist/api/graphql/update_urls.js.map +1 -0
  86. package/dist/api/identity.d.ts +1 -0
  87. package/dist/api/identity.js +29 -0
  88. package/dist/api/identity.js.map +1 -0
  89. package/dist/api/partners.d.ts +25 -0
  90. package/dist/api/partners.js +100 -0
  91. package/dist/api/partners.js.map +1 -0
  92. package/dist/api.d.ts +5 -0
  93. package/dist/api.js +6 -0
  94. package/dist/api.js.map +1 -0
  95. package/dist/checksum.d.ts +15 -0
  96. package/dist/checksum.js +27 -0
  97. package/dist/checksum.js.map +1 -0
  98. package/dist/cli.d.ts +7 -0
  99. package/dist/cli.js +13 -0
  100. package/dist/cli.js.map +1 -0
  101. package/dist/colors.d.ts +1 -0
  102. package/dist/colors.js +8 -0
  103. package/dist/colors.js.map +1 -0
  104. package/dist/constants.d.ts +43 -0
  105. package/dist/constants.js +63 -0
  106. package/dist/constants.js.map +1 -0
  107. package/dist/dependency.d.ts +128 -0
  108. package/dist/dependency.js +302 -0
  109. package/dist/dependency.js.map +1 -0
  110. package/dist/dot-env.d.ts +28 -0
  111. package/dist/dot-env.js +31 -0
  112. package/dist/dot-env.js.map +1 -0
  113. package/dist/environment/fqdn.d.ts +23 -0
  114. package/dist/environment/fqdn.js +61 -0
  115. package/dist/environment/fqdn.js.map +1 -0
  116. package/dist/environment/local.d.ts +48 -0
  117. package/dist/environment/local.js +82 -0
  118. package/dist/environment/local.js.map +1 -0
  119. package/dist/environment/service.d.ts +17 -0
  120. package/dist/environment/service.js +41 -0
  121. package/dist/environment/service.js.map +1 -0
  122. package/dist/environment/spin.d.ts +47 -0
  123. package/dist/environment/spin.js +83 -0
  124. package/dist/environment/spin.js.map +1 -0
  125. package/dist/environment/utilities.d.ts +6 -0
  126. package/dist/environment/utilities.js +12 -0
  127. package/dist/environment/utilities.js.map +1 -0
  128. package/dist/environment.d.ts +5 -0
  129. package/dist/environment.js +6 -0
  130. package/dist/environment.js.map +1 -0
  131. package/dist/error.d.ts +44 -0
  132. package/dist/error.js +91 -0
  133. package/dist/error.js.map +1 -0
  134. package/dist/file.d.ts +67 -0
  135. package/dist/file.js +165 -0
  136. package/dist/file.js.map +1 -0
  137. package/dist/git.d.ts +15 -0
  138. package/dist/git.js +48 -0
  139. package/dist/git.js.map +1 -0
  140. package/dist/github.d.ts +33 -0
  141. package/dist/github.js +56 -0
  142. package/dist/github.js.map +1 -0
  143. package/dist/haiku.d.ts +1 -0
  144. package/dist/haiku.js +8 -0
  145. package/dist/haiku.js.map +1 -0
  146. package/dist/http/fetch.d.ts +16 -0
  147. package/dist/http/fetch.js +18 -0
  148. package/dist/http/fetch.js.map +1 -0
  149. package/dist/http/formdata.d.ts +3 -0
  150. package/dist/http/formdata.js +6 -0
  151. package/dist/http/formdata.js.map +1 -0
  152. package/dist/http.d.ts +2 -0
  153. package/dist/http.js +3 -0
  154. package/dist/http.js.map +1 -0
  155. package/dist/id.d.ts +6 -0
  156. package/dist/id.js +18 -0
  157. package/dist/id.js.map +1 -0
  158. package/dist/index.d.ts +37 -2115
  159. package/dist/index.js +38 -46
  160. package/dist/index.js.map +1 -1
  161. package/dist/network/api.d.ts +2 -0
  162. package/dist/network/api.js +2 -0
  163. package/dist/network/api.js.map +1 -0
  164. package/dist/network/service.d.ts +16 -0
  165. package/dist/network/service.js +12 -0
  166. package/dist/network/service.js.map +1 -0
  167. package/dist/node/archiver.d.ts +6 -0
  168. package/dist/node/archiver.js +24 -0
  169. package/dist/node/archiver.js.map +1 -0
  170. package/dist/node/cli.d.ts +18 -0
  171. package/dist/node/cli.js +91 -0
  172. package/dist/node/cli.js.map +1 -0
  173. package/dist/npm.d.ts +27 -0
  174. package/dist/npm.js +20 -0
  175. package/dist/npm.js.map +1 -0
  176. package/dist/os.d.ts +10 -0
  177. package/dist/os.js +70 -0
  178. package/dist/os.js.map +1 -0
  179. package/dist/output.d.ts +142 -0
  180. package/dist/output.js +505 -0
  181. package/dist/output.js.map +1 -0
  182. package/dist/path.d.ts +22 -0
  183. package/dist/path.js +43 -0
  184. package/dist/path.js.map +1 -0
  185. package/dist/plugins.d.ts +9 -0
  186. package/dist/plugins.js +12 -0
  187. package/dist/plugins.js.map +1 -0
  188. package/dist/port.d.ts +5 -0
  189. package/dist/port.js +13 -0
  190. package/dist/port.js.map +1 -0
  191. package/dist/ruby.d.ts +21 -0
  192. package/dist/ruby.js +192 -0
  193. package/dist/ruby.js.map +1 -0
  194. package/dist/schema.d.ts +1 -0
  195. package/dist/schema.js +2 -0
  196. package/dist/schema.js.map +1 -0
  197. package/dist/secure-store.d.ts +19 -0
  198. package/dist/secure-store.js +63 -0
  199. package/dist/secure-store.js.map +1 -0
  200. package/dist/semver.d.ts +3 -0
  201. package/dist/semver.js +6 -0
  202. package/dist/semver.js.map +1 -0
  203. package/dist/session/authorize.d.ts +7 -0
  204. package/dist/session/authorize.js +40 -0
  205. package/dist/session/authorize.js.map +1 -0
  206. package/dist/session/exchange.d.ts +42 -0
  207. package/dist/session/exchange.js +144 -0
  208. package/dist/session/exchange.js.map +1 -0
  209. package/dist/session/identity.d.ts +3 -0
  210. package/dist/session/identity.js +58 -0
  211. package/dist/session/identity.js.map +1 -0
  212. package/dist/session/post-auth.d.ts +13 -0
  213. package/dist/session/post-auth.js +56 -0
  214. package/dist/session/post-auth.js.map +1 -0
  215. package/dist/session/redirect-listener.d.ts +34 -0
  216. package/dist/session/redirect-listener.js +97 -0
  217. package/dist/session/redirect-listener.js.map +1 -0
  218. package/dist/session/schema.d.ts +174 -0
  219. package/dist/session/schema.js +59 -0
  220. package/dist/session/schema.js.map +1 -0
  221. package/dist/session/scopes.d.ts +16 -0
  222. package/dist/session/scopes.js +53 -0
  223. package/dist/session/scopes.js.map +1 -0
  224. package/dist/session/store.d.ts +24 -0
  225. package/dist/session/store.js +88 -0
  226. package/dist/session/store.js.map +1 -0
  227. package/dist/session/token.d.ts +40 -0
  228. package/dist/session/token.js +22 -0
  229. package/dist/session/token.js.map +1 -0
  230. package/dist/session/validate.d.ts +17 -0
  231. package/dist/session/validate.js +75 -0
  232. package/dist/session/validate.js.map +1 -0
  233. package/dist/session.d.ts +88 -0
  234. package/dist/session.js +251 -0
  235. package/dist/session.js.map +1 -0
  236. package/dist/store/schema.d.ts +3 -0
  237. package/dist/store/schema.js +27 -0
  238. package/dist/store/schema.js.map +1 -0
  239. package/dist/store.d.ts +32 -0
  240. package/dist/store.js +102 -0
  241. package/dist/store.js.map +1 -0
  242. package/dist/string.d.ts +22 -0
  243. package/dist/string.js +38 -0
  244. package/dist/string.js.map +1 -0
  245. package/dist/system.d.ts +53 -0
  246. package/dist/system.js +109 -0
  247. package/dist/system.js.map +1 -0
  248. package/dist/template.d.ts +11 -0
  249. package/dist/template.js +50 -0
  250. package/dist/template.js.map +1 -0
  251. package/dist/testing/output.d.ts +9 -0
  252. package/dist/testing/output.js +15 -0
  253. package/dist/testing/output.js.map +1 -0
  254. package/dist/testing/store.d.ts +7 -0
  255. package/dist/testing/store.js +26 -0
  256. package/dist/testing/store.js.map +1 -0
  257. package/dist/toml.d.ts +3 -0
  258. package/dist/toml.js +8 -0
  259. package/dist/toml.js.map +1 -0
  260. package/dist/tsconfig.tsbuildinfo +1 -0
  261. package/dist/ui/autocomplete.d.ts +7 -0
  262. package/dist/ui/autocomplete.js +43 -0
  263. package/dist/ui/autocomplete.js.map +1 -0
  264. package/dist/ui/input.d.ts +7 -0
  265. package/dist/ui/input.js +48 -0
  266. package/dist/ui/input.js.map +1 -0
  267. package/dist/ui/select.d.ts +6 -0
  268. package/dist/ui/select.js +30 -0
  269. package/dist/ui/select.js.map +1 -0
  270. package/dist/ui.d.ts +36 -0
  271. package/dist/ui.js +124 -0
  272. package/dist/ui.js.map +1 -0
  273. package/dist/version.d.ts +19 -0
  274. package/dist/version.js +34 -0
  275. package/dist/version.js.map +1 -0
  276. package/dist/vscode.d.ts +8 -0
  277. package/dist/vscode.js +36 -0
  278. package/dist/vscode.js.map +1 -0
  279. package/dist/yaml.d.ts +2 -0
  280. package/dist/yaml.js +8 -0
  281. package/dist/yaml.js.map +1 -0
  282. package/package.json +32 -21
  283. package/dist/index-160b2bd2.js +0 -175294
  284. package/dist/index-160b2bd2.js.map +0 -1
  285. package/dist/index.d.ts.map +0 -1
  286. package/dist/multipart-parser-7ce1f707.js +0 -477
  287. package/dist/multipart-parser-7ce1f707.js.map +0 -1
@@ -0,0 +1,128 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Abort, Bug } from './error.js';
4
+ import { AbortSignal } from 'abort-controller';
5
+ import type { Writable } from 'node:stream';
6
+ export declare const genericConfigurationFileNames: {
7
+ readonly yarn: {
8
+ readonly lockfile: "yarn.lock";
9
+ };
10
+ readonly pnpm: {
11
+ readonly lockfile: "pnpm-lock.yaml";
12
+ };
13
+ };
14
+ export declare const dependencyManager: readonly ["yarn", "npm", "pnpm"];
15
+ export declare type DependencyManager = typeof dependencyManager[number];
16
+ export declare const PackageJsonNotFoundError: (directory: string) => Abort;
17
+ export declare const FindUpAndReadPackageJsonNotFoundError: (directory: string) => Bug;
18
+ /**
19
+ * Returns the dependency manager used to run the create workflow.
20
+ * @param env {Object} The environment variables of the process in which the CLI runs.
21
+ * @returns The dependency manager
22
+ */
23
+ export declare function dependencyManagerUsedForCreating(env?: NodeJS.ProcessEnv): DependencyManager;
24
+ /**
25
+ * Returns the dependency manager used by an existing project.
26
+ * @param directory {string} The root directory of the project.
27
+ * @returns The dependency manager
28
+ */
29
+ export declare function getDependencyManager(directory: string): Promise<DependencyManager>;
30
+ interface InstallNPMDependenciesRecursivelyOptions {
31
+ /**
32
+ * The dependency manager to use to install the dependencies.
33
+ */
34
+ dependencyManager: DependencyManager;
35
+ /**
36
+ * The directory from where we'll find package.json's recursively
37
+ */
38
+ directory: string;
39
+ /**
40
+ * Specifies the maximum depth of the glob search.
41
+ */
42
+ deep?: number;
43
+ }
44
+ /**
45
+ * This function traverses down a directory tree to find directories containing a package.json
46
+ * and installs the dependencies if needed. To know if it's needed, it uses the "check" command
47
+ * provided by dependency managers.
48
+ * @param options {InstallNPMDependenciesRecursivelyOptions} Options to install dependencies recursively.
49
+ */
50
+ export declare function installNPMDependenciesRecursively(options: InstallNPMDependenciesRecursivelyOptions): Promise<void>;
51
+ /**
52
+ * Installs the dependencies in the given directory.
53
+ * @param directory {string} The directory that contains the package.json
54
+ * @param dependencyManager {DependencyManager} The dependency manager to use to install the dependencies.
55
+ * @param stdout {Writable} Standard output stream.
56
+ * @param stderr {Writable} Standard error stream.
57
+ * @param signal {AbortSignal} Abort signal.
58
+ * @returns stderr {Writable} Standard error stream.
59
+ */
60
+ export declare function install(directory: string, dependencyManager: DependencyManager, stdout?: Writable, stderr?: Writable, signal?: AbortSignal): Promise<void>;
61
+ /**
62
+ * Returns the name of the package configured in its package.json
63
+ * @param packageJsonPath {string} Path to the package.json file
64
+ * @returns A promise that resolves with the name.
65
+ */
66
+ export declare function getPackageName(packageJsonPath: string): Promise<string>;
67
+ /**
68
+ * Returns the list of production and dev dependencies of a package.json
69
+ * @param packageJsonPath {string} Path to the package.json file
70
+ * @returns A promise that resolves with the list of dependencies.
71
+ */
72
+ export declare function getDependencies(packageJsonPath: string): Promise<{
73
+ [key: string]: string;
74
+ }>;
75
+ export declare function checkForNewVersion(dependency: string, currentVersion: string): Promise<string | undefined>;
76
+ export declare function getOutputUpdateCLIReminder(dependencyManager: DependencyManager, version: string): string;
77
+ interface PackageJSONContents {
78
+ name: string;
79
+ version?: string;
80
+ dependencies?: {
81
+ [key: string]: string;
82
+ };
83
+ devDependencies?: {
84
+ [key: string]: string;
85
+ };
86
+ }
87
+ export declare function packageJSONContents(packageJsonPath: string): Promise<PackageJSONContents>;
88
+ export declare type DependencyType = 'dev' | 'prod' | 'peer';
89
+ interface AddNPMDependenciesIfNeededOptions {
90
+ /** How dependencies should be added */
91
+ type: DependencyType;
92
+ /** The dependency manager to use to add dependencies */
93
+ dependencyManager: DependencyManager;
94
+ /** The directory that contains the package.json where dependencies will be added */
95
+ directory: string;
96
+ /** Standard output coming from the underlying installation process */
97
+ stdout?: Writable;
98
+ /** Standard error coming from the underlying installation process */
99
+ stderr?: Writable;
100
+ /** Abort signal to stop the process */
101
+ signal?: AbortSignal;
102
+ }
103
+ export interface DependencyVersion {
104
+ name: string;
105
+ version: string | undefined;
106
+ }
107
+ /**
108
+ * Adds dependencies to a Node project (i.e. a project that has a package.json)
109
+ * @param dependencies {string[]} List of dependencies to be added.
110
+ * @param options {AddNPMDependenciesIfNeededOptions} Options for adding dependencies.
111
+ */
112
+ export declare function addNPMDependenciesIfNeeded(dependencies: DependencyVersion[], options: AddNPMDependenciesIfNeededOptions, force?: boolean): Promise<void>;
113
+ export declare function addNPMDependenciesWithoutVersionIfNeeded(dependencies: string[], options: AddNPMDependenciesIfNeededOptions): Promise<void>;
114
+ export declare function addLatestNPMDependencies(dependencies: string[], options: AddNPMDependenciesIfNeededOptions): Promise<void>;
115
+ export declare type ProjectType = 'node' | 'php' | 'ruby' | undefined;
116
+ export declare function getProjectType(directory: string): Promise<ProjectType>;
117
+ /**
118
+ * Given a directory it traverses the directory up looking for a package.json and if found, it reads it
119
+ * decodes the JSON, and returns its content as a Javascript object.
120
+ * @param options {string} The directory from which traverse up.
121
+ * @returns {Promise<{path: string; content: unknown}>} If found, the promise resolves with the path to the
122
+ * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.
123
+ */
124
+ export declare function findUpAndReadPackageJson(fromDirectory: string): Promise<{
125
+ path: string;
126
+ content: unknown;
127
+ }>;
128
+ export {};
@@ -0,0 +1,302 @@
1
+ import { exec } from './system.js';
2
+ import { exists as fileExists, read as readFile } from './file.js';
3
+ import { glob, dirname, join as pathJoin, findUp } from './path.js';
4
+ import { Abort, Bug } from './error.js';
5
+ import { latestNpmPackageVersion } from './version.js';
6
+ import { Version } from './semver.js';
7
+ import { content, token, debug } from './output.js';
8
+ import { AbortController } from 'abort-controller';
9
+ export const genericConfigurationFileNames = {
10
+ yarn: {
11
+ lockfile: 'yarn.lock',
12
+ },
13
+ pnpm: {
14
+ lockfile: 'pnpm-lock.yaml',
15
+ },
16
+ };
17
+ export const dependencyManager = ['yarn', 'npm', 'pnpm'];
18
+ export const PackageJsonNotFoundError = (directory) => {
19
+ return new Abort(`The directory ${directory} doesn't have a package.json.`);
20
+ };
21
+ export const FindUpAndReadPackageJsonNotFoundError = (directory) => {
22
+ return new Bug(content `Couldn't find a a package.json traversing directories from ${token.path(directory)}`);
23
+ };
24
+ /**
25
+ * Returns the dependency manager used to run the create workflow.
26
+ * @param env {Object} The environment variables of the process in which the CLI runs.
27
+ * @returns The dependency manager
28
+ */
29
+ export function dependencyManagerUsedForCreating(env = process.env) {
30
+ if (env.npm_config_user_agent?.includes('yarn')) {
31
+ return 'yarn';
32
+ }
33
+ else if (env.npm_config_user_agent?.includes('pnpm')) {
34
+ return 'pnpm';
35
+ }
36
+ else {
37
+ return 'npm';
38
+ }
39
+ }
40
+ /**
41
+ * Returns the dependency manager used by an existing project.
42
+ * @param directory {string} The root directory of the project.
43
+ * @returns The dependency manager
44
+ */
45
+ export async function getDependencyManager(directory) {
46
+ debug(content `Obtaining the dependency manager in directory ${token.path(directory)}...`);
47
+ const yarnLockPath = pathJoin(directory, genericConfigurationFileNames.yarn.lockfile);
48
+ const pnpmLockPath = pathJoin(directory, genericConfigurationFileNames.pnpm.lockfile);
49
+ if (await fileExists(yarnLockPath)) {
50
+ return 'yarn';
51
+ }
52
+ else if (await fileExists(pnpmLockPath)) {
53
+ return 'pnpm';
54
+ }
55
+ else {
56
+ return 'npm';
57
+ }
58
+ }
59
+ /**
60
+ * This function traverses down a directory tree to find directories containing a package.json
61
+ * and installs the dependencies if needed. To know if it's needed, it uses the "check" command
62
+ * provided by dependency managers.
63
+ * @param options {InstallNPMDependenciesRecursivelyOptions} Options to install dependencies recursively.
64
+ */
65
+ export async function installNPMDependenciesRecursively(options) {
66
+ const packageJsons = await glob(pathJoin(options.directory, '**/package.json'), {
67
+ ignore: [pathJoin(options.directory, 'node_modules/**/package.json')],
68
+ cwd: options.directory,
69
+ onlyFiles: true,
70
+ deep: options.deep,
71
+ });
72
+ const abortController = new AbortController();
73
+ try {
74
+ await Promise.all(packageJsons.map(async (packageJsonPath) => {
75
+ const directory = dirname(packageJsonPath);
76
+ await install(directory, options.dependencyManager, undefined, undefined, abortController.signal);
77
+ }));
78
+ }
79
+ catch (error) {
80
+ abortController.abort();
81
+ throw error;
82
+ }
83
+ }
84
+ /**
85
+ * Installs the dependencies in the given directory.
86
+ * @param directory {string} The directory that contains the package.json
87
+ * @param dependencyManager {DependencyManager} The dependency manager to use to install the dependencies.
88
+ * @param stdout {Writable} Standard output stream.
89
+ * @param stderr {Writable} Standard error stream.
90
+ * @param signal {AbortSignal} Abort signal.
91
+ * @returns stderr {Writable} Standard error stream.
92
+ */
93
+ export async function install(directory, dependencyManager, stdout, stderr, signal) {
94
+ const options = { cwd: directory, stdin: undefined, stdout, stderr, signal };
95
+ await exec(dependencyManager, ['install'], options);
96
+ }
97
+ /**
98
+ * Returns the name of the package configured in its package.json
99
+ * @param packageJsonPath {string} Path to the package.json file
100
+ * @returns A promise that resolves with the name.
101
+ */
102
+ export async function getPackageName(packageJsonPath) {
103
+ const packageJsonContent = await packageJSONContents(packageJsonPath);
104
+ return packageJsonContent.name;
105
+ }
106
+ /**
107
+ * Returns the list of production and dev dependencies of a package.json
108
+ * @param packageJsonPath {string} Path to the package.json file
109
+ * @returns A promise that resolves with the list of dependencies.
110
+ */
111
+ export async function getDependencies(packageJsonPath) {
112
+ const packageJsonContent = await packageJSONContents(packageJsonPath);
113
+ const dependencies = packageJsonContent.dependencies ?? {};
114
+ const devDependencies = packageJsonContent.devDependencies ?? {};
115
+ return { ...dependencies, ...devDependencies };
116
+ }
117
+ export async function checkForNewVersion(dependency, currentVersion) {
118
+ debug(content `Checking if there's a version of ${dependency} newer than ${currentVersion}`);
119
+ try {
120
+ const lastVersion = await latestNpmPackageVersion(dependency);
121
+ if (lastVersion && new Version(currentVersion).compare(lastVersion) < 0) {
122
+ return lastVersion;
123
+ }
124
+ else {
125
+ return undefined;
126
+ }
127
+ // eslint-disable-next-line no-catch-all/no-catch-all
128
+ }
129
+ catch (error) {
130
+ return undefined;
131
+ }
132
+ }
133
+ export function getOutputUpdateCLIReminder(dependencyManager, version) {
134
+ const updateCommand = token.packagejsonScript(dependencyManager, 'shopify', 'upgrade');
135
+ return content `💡 Version ${version} available! Run ${updateCommand}`.value;
136
+ }
137
+ export async function packageJSONContents(packageJsonPath) {
138
+ if (!(await fileExists(packageJsonPath))) {
139
+ throw PackageJsonNotFoundError(dirname(packageJsonPath));
140
+ }
141
+ return JSON.parse(await readFile(packageJsonPath));
142
+ }
143
+ /**
144
+ * Adds dependencies to a Node project (i.e. a project that has a package.json)
145
+ * @param dependencies {string[]} List of dependencies to be added.
146
+ * @param options {AddNPMDependenciesIfNeededOptions} Options for adding dependencies.
147
+ */
148
+ export async function addNPMDependenciesIfNeeded(dependencies, options, force = false) {
149
+ debug(content `Adding the following dependencies if needed:
150
+ ${token.json(dependencies)}
151
+ With options:
152
+ ${token.json(options)}
153
+ `);
154
+ const packageJsonPath = pathJoin(options.directory, 'package.json');
155
+ if (!(await fileExists(packageJsonPath))) {
156
+ throw PackageJsonNotFoundError(options.directory);
157
+ }
158
+ const existingDependencies = Object.keys(await getDependencies(packageJsonPath));
159
+ let dependenciesToAdd = dependencies;
160
+ if (!force) {
161
+ dependenciesToAdd = dependencies.filter((dep) => {
162
+ return !existingDependencies.includes(dep.name);
163
+ });
164
+ }
165
+ if (dependenciesToAdd.length === 0) {
166
+ return;
167
+ }
168
+ let args;
169
+ const depedenciesWithVersion = dependenciesToAdd.map((dep) => {
170
+ return dep.version ? `${dep.name}@${dep.version}` : dep.name;
171
+ });
172
+ switch (options.dependencyManager) {
173
+ case 'npm':
174
+ args = argumentsToAddDependenciesWithNPM(depedenciesWithVersion, options.type);
175
+ break;
176
+ case 'yarn':
177
+ args = argumentsToAddDependenciesWithYarn(depedenciesWithVersion, options.type);
178
+ break;
179
+ case 'pnpm':
180
+ args = argumentsToAddDependenciesWithPNPM(depedenciesWithVersion, options.type);
181
+ break;
182
+ }
183
+ options.stdout?.write(`Executing...${args.join(' ')}`);
184
+ await exec(options.dependencyManager, args, {
185
+ cwd: options.directory,
186
+ stdout: options.stdout,
187
+ stderr: options.stderr,
188
+ signal: options.signal,
189
+ });
190
+ }
191
+ export async function addNPMDependenciesWithoutVersionIfNeeded(dependencies, options) {
192
+ await addNPMDependenciesIfNeeded(dependencies.map((dependency) => {
193
+ return { name: dependency, version: undefined };
194
+ }), options);
195
+ }
196
+ // eslint-disable-next-line no-warning-comments
197
+ // TODO: Switch it around so add-if-needed depends on this, rather than calling
198
+ // if-needed with force: true which is counterintuitive.
199
+ export async function addLatestNPMDependencies(dependencies, options) {
200
+ await addNPMDependenciesIfNeeded(dependencies.map((dependency) => {
201
+ return { name: dependency, version: 'latest' };
202
+ }), options, true);
203
+ }
204
+ /**
205
+ * Returns the arguments to add dependencies using NPM.
206
+ * @param dependencies {string[]} The list of dependencies to add
207
+ * @param type {DependencyType} The dependency type.
208
+ * @returns {string[]} An array with the arguments.
209
+ */
210
+ function argumentsToAddDependenciesWithNPM(dependencies, type) {
211
+ let command = ['install'];
212
+ command = command.concat(dependencies);
213
+ switch (type) {
214
+ case 'dev':
215
+ command.push('--save-dev');
216
+ break;
217
+ case 'peer':
218
+ command.push('--save-peer');
219
+ break;
220
+ case 'prod':
221
+ command.push('--save-prod');
222
+ break;
223
+ }
224
+ return command;
225
+ }
226
+ /**
227
+ * Returns the arguments to add dependencies using Yarn.
228
+ * @param dependencies {string[]} The list of dependencies to add
229
+ * @param type {DependencyType} The dependency type.
230
+ * @returns {string[]} An array with the arguments.
231
+ */
232
+ function argumentsToAddDependenciesWithYarn(dependencies, type) {
233
+ let command = ['add'];
234
+ command = command.concat(dependencies);
235
+ switch (type) {
236
+ case 'dev':
237
+ command.push('--dev');
238
+ break;
239
+ case 'peer':
240
+ command.push('--peer');
241
+ break;
242
+ case 'prod':
243
+ command.push('--prod');
244
+ break;
245
+ }
246
+ return command;
247
+ }
248
+ /**
249
+ * Returns the arguments to add dependencies using PNPM.
250
+ * @param dependencies {string[]} The list of dependencies to add
251
+ * @param type {DependencyType} The dependency type.
252
+ * @returns {string[]} An array with the arguments.
253
+ */
254
+ function argumentsToAddDependenciesWithPNPM(dependencies, type) {
255
+ let command = ['add'];
256
+ command = command.concat(dependencies);
257
+ switch (type) {
258
+ case 'dev':
259
+ command.push('--save-dev');
260
+ break;
261
+ case 'peer':
262
+ command.push('--save-peer');
263
+ break;
264
+ case 'prod':
265
+ command.push('--save-prod');
266
+ break;
267
+ }
268
+ return command;
269
+ }
270
+ export async function getProjectType(directory) {
271
+ const nodeConfigFile = pathJoin(directory, 'package.json');
272
+ const rubyConfigFile = pathJoin(directory, 'Gemfile');
273
+ const phpConfigFile = pathJoin(directory, 'composer.json');
274
+ if (await fileExists(nodeConfigFile)) {
275
+ return 'node';
276
+ }
277
+ else if (await fileExists(rubyConfigFile)) {
278
+ return 'ruby';
279
+ }
280
+ else if (await fileExists(phpConfigFile)) {
281
+ return 'php';
282
+ }
283
+ return undefined;
284
+ }
285
+ /**
286
+ * Given a directory it traverses the directory up looking for a package.json and if found, it reads it
287
+ * decodes the JSON, and returns its content as a Javascript object.
288
+ * @param options {string} The directory from which traverse up.
289
+ * @returns {Promise<{path: string; content: unknown}>} If found, the promise resolves with the path to the
290
+ * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.
291
+ */
292
+ export async function findUpAndReadPackageJson(fromDirectory) {
293
+ const packageJsonPath = await findUp('package.json', { cwd: fromDirectory, type: 'file' });
294
+ if (packageJsonPath) {
295
+ const packageJson = JSON.parse(await readFile(packageJsonPath));
296
+ return { path: packageJsonPath, content: packageJson };
297
+ }
298
+ else {
299
+ throw FindUpAndReadPackageJsonNotFoundError(fromDirectory);
300
+ }
301
+ }
302
+ //# sourceMappingURL=dependency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency.js","sourceRoot":"","sources":["../src/dependency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,aAAa,CAAA;AAChC,OAAO,EAAC,MAAM,IAAI,UAAU,EAAE,IAAI,IAAI,QAAQ,EAAC,MAAM,WAAW,CAAA;AAChE,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,EAAC,MAAM,WAAW,CAAA;AACjE,OAAO,EAAC,KAAK,EAAE,GAAG,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAA;AACpD,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAA;AACnC,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AACjD,OAAO,EAAC,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAI7D,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,IAAI,EAAE;QACJ,QAAQ,EAAE,WAAW;KACtB;IACD,IAAI,EAAE;QACJ,QAAQ,EAAE,gBAAgB;KAC3B;CACO,CAAA;AAEV,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAM,E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aAAa,CAAC,CAAA;KAC3D;AACH,CAAC","sourcesContent":["import {exec} from './system.js'\nimport {exists as fileExists, read as readFile} from './file.js'\nimport {glob, dirname, join as pathJoin, findUp} from './path.js'\nimport {Abort, Bug} from './error.js'\nimport {latestNpmPackageVersion} from './version.js'\nimport {Version} from './semver.js'\nimport {content, token, debug} from './output.js'\nimport {AbortController, AbortSignal} from 'abort-controller'\nimport type {Writable} from 'node:stream'\nimport type {ExecOptions} from './system.js'\n\nexport const genericConfigurationFileNames = {\n yarn: {\n lockfile: 'yarn.lock',\n },\n pnpm: {\n lockfile: 'pnpm-lock.yaml',\n },\n} as const\n\nexport const dependencyManager = ['yarn', 'npm', 'pnpm'] as const\nexport type DependencyManager = typeof dependencyManager[number]\n\nexport const PackageJsonNotFoundError = (directory: string) => {\n return new Abort(`The directory ${directory} doesn't have a package.json.`)\n}\n\nexport const FindUpAndReadPackageJsonNotFoundError = (directory: string) => {\n return new Bug(content`Couldn't find a a package.json traversing directories from ${token.path(directory)}`)\n}\n\n/**\n * Returns the dependency manager used to run the create workflow.\n * @param env {Object} The environment variables of the process in which the CLI runs.\n * @returns The dependency manager\n */\nexport function dependencyManagerUsedForCreating(env = process.env): DependencyManager {\n if (env.npm_config_user_agent?.includes('yarn')) {\n return 'yarn'\n } else if (env.npm_config_user_agent?.includes('pnpm')) {\n return 'pnpm'\n } else {\n return 'npm'\n }\n}\n\n/**\n * Returns the dependency manager used by an existing project.\n * @param directory {string} The root directory of the project.\n * @returns The dependency manager\n */\nexport async function getDependencyManager(directory: string): Promise<DependencyManager> {\n debug(content`Obtaining the dependency manager in directory ${token.path(directory)}...`)\n const yarnLockPath = pathJoin(directory, genericConfigurationFileNames.yarn.lockfile)\n const pnpmLockPath = pathJoin(directory, genericConfigurationFileNames.pnpm.lockfile)\n if (await fileExists(yarnLockPath)) {\n return 'yarn'\n } else if (await fileExists(pnpmLockPath)) {\n return 'pnpm'\n } else {\n return 'npm'\n }\n}\n\ninterface InstallNPMDependenciesRecursivelyOptions {\n /**\n * The dependency manager to use to install the dependencies.\n */\n dependencyManager: DependencyManager\n /**\n * The directory from where we'll find package.json's recursively\n */\n directory: string\n\n /**\n * Specifies the maximum depth of the glob search.\n */\n deep?: number\n}\n\n/**\n * This function traverses down a directory tree to find directories containing a package.json\n * and installs the dependencies if needed. To know if it's needed, it uses the \"check\" command\n * provided by dependency managers.\n * @param options {InstallNPMDependenciesRecursivelyOptions} Options to install dependencies recursively.\n */\nexport async function installNPMDependenciesRecursively(options: InstallNPMDependenciesRecursivelyOptions) {\n const packageJsons = await glob(pathJoin(options.directory, '**/package.json'), {\n ignore: [pathJoin(options.directory, 'node_modules/**/package.json')],\n cwd: options.directory,\n onlyFiles: true,\n deep: options.deep,\n })\n const abortController = new AbortController()\n try {\n await Promise.all(\n packageJsons.map(async (packageJsonPath) => {\n const directory = dirname(packageJsonPath)\n await install(directory, options.dependencyManager, undefined, undefined, abortController.signal)\n }),\n )\n } catch (error) {\n abortController.abort()\n throw error\n }\n}\n\n/**\n * Installs the dependencies in the given directory.\n * @param directory {string} The directory that contains the package.json\n * @param dependencyManager {DependencyManager} The dependency manager to use to install the dependencies.\n * @param stdout {Writable} Standard output stream.\n * @param stderr {Writable} Standard error stream.\n * @param signal {AbortSignal} Abort signal.\n * @returns stderr {Writable} Standard error stream.\n */\nexport async function install(\n directory: string,\n dependencyManager: DependencyManager,\n stdout?: Writable,\n stderr?: Writable,\n signal?: AbortSignal,\n) {\n const options: ExecOptions = {cwd: directory, stdin: undefined, stdout, stderr, signal}\n await exec(dependencyManager, ['install'], options)\n}\n\n/**\n * Returns the name of the package configured in its package.json\n * @param packageJsonPath {string} Path to the package.json file\n * @returns A promise that resolves with the name.\n */\nexport async function getPackageName(packageJsonPath: string): Promise<string> {\n const packageJsonContent = await packageJSONContents(packageJsonPath)\n return packageJsonContent.name\n}\n\n/**\n * Returns the list of production and dev dependencies of a package.json\n * @param packageJsonPath {string} Path to the package.json file\n * @returns A promise that resolves with the list of dependencies.\n */\nexport async function getDependencies(packageJsonPath: string): Promise<{[key: string]: string}> {\n const packageJsonContent = await packageJSONContents(packageJsonPath)\n const dependencies: {[key: string]: string} = packageJsonContent.dependencies ?? {}\n const devDependencies: {[key: string]: string} = packageJsonContent.devDependencies ?? {}\n\n return {...dependencies, ...devDependencies}\n}\n\nexport async function checkForNewVersion(dependency: string, currentVersion: string): Promise<string | undefined> {\n debug(content`Checking if there's a version of ${dependency} newer than ${currentVersion}`)\n try {\n const lastVersion = await latestNpmPackageVersion(dependency)\n if (lastVersion && new Version(currentVersion).compare(lastVersion) < 0) {\n return lastVersion\n } else {\n return undefined\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return undefined\n }\n}\n\nexport function getOutputUpdateCLIReminder(dependencyManager: DependencyManager, version: string): string {\n const updateCommand = token.packagejsonScript(dependencyManager, 'shopify', 'upgrade')\n return content`💡 Version ${version} available! Run ${updateCommand}`.value\n}\n\ninterface PackageJSONContents {\n name: string\n version?: string\n dependencies?: {[key: string]: string}\n devDependencies?: {[key: string]: string}\n}\n\nexport async function packageJSONContents(packageJsonPath: string): Promise<PackageJSONContents> {\n if (!(await fileExists(packageJsonPath))) {\n throw PackageJsonNotFoundError(dirname(packageJsonPath))\n }\n return JSON.parse(await readFile(packageJsonPath))\n}\n\nexport type DependencyType = 'dev' | 'prod' | 'peer'\n\ninterface AddNPMDependenciesIfNeededOptions {\n /** How dependencies should be added */\n type: DependencyType\n\n /** The dependency manager to use to add dependencies */\n dependencyManager: DependencyManager\n\n /** The directory that contains the package.json where dependencies will be added */\n directory: string\n\n /** Standard output coming from the underlying installation process */\n stdout?: Writable\n\n /** Standard error coming from the underlying installation process */\n stderr?: Writable\n\n /** Abort signal to stop the process */\n signal?: AbortSignal\n}\n\nexport interface DependencyVersion {\n name: string\n version: string | undefined\n}\n\n/**\n * Adds dependencies to a Node project (i.e. a project that has a package.json)\n * @param dependencies {string[]} List of dependencies to be added.\n * @param options {AddNPMDependenciesIfNeededOptions} Options for adding dependencies.\n */\nexport async function addNPMDependenciesIfNeeded(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n force = false,\n) {\n debug(content`Adding the following dependencies if needed:\n${token.json(dependencies)}\nWith options:\n${token.json(options)}\n `)\n const packageJsonPath = pathJoin(options.directory, 'package.json')\n if (!(await fileExists(packageJsonPath))) {\n throw PackageJsonNotFoundError(options.directory)\n }\n const existingDependencies = Object.keys(await getDependencies(packageJsonPath))\n let dependenciesToAdd = dependencies\n if (!force) {\n dependenciesToAdd = dependencies.filter((dep) => {\n return !existingDependencies.includes(dep.name)\n })\n }\n if (dependenciesToAdd.length === 0) {\n return\n }\n let args: string[]\n const depedenciesWithVersion = dependenciesToAdd.map((dep) => {\n return dep.version ? `${dep.name}@${dep.version}` : dep.name\n })\n switch (options.dependencyManager) {\n case 'npm':\n args = argumentsToAddDependenciesWithNPM(depedenciesWithVersion, options.type)\n break\n case 'yarn':\n args = argumentsToAddDependenciesWithYarn(depedenciesWithVersion, options.type)\n break\n case 'pnpm':\n args = argumentsToAddDependenciesWithPNPM(depedenciesWithVersion, options.type)\n break\n }\n options.stdout?.write(`Executing...${args.join(' ')}`)\n await exec(options.dependencyManager, args, {\n cwd: options.directory,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n })\n}\n\nexport async function addNPMDependenciesWithoutVersionIfNeeded(\n dependencies: string[],\n options: AddNPMDependenciesIfNeededOptions,\n) {\n await addNPMDependenciesIfNeeded(\n dependencies.map((dependency) => {\n return {name: dependency, version: undefined}\n }),\n options,\n )\n}\n\n// eslint-disable-next-line no-warning-comments\n// TODO: Switch it around so add-if-needed depends on this, rather than calling\n// if-needed with force: true which is counterintuitive.\nexport async function addLatestNPMDependencies(dependencies: string[], options: AddNPMDependenciesIfNeededOptions) {\n await addNPMDependenciesIfNeeded(\n dependencies.map((dependency) => {\n return {name: dependency, version: 'latest'}\n }),\n options,\n true,\n )\n}\n\n/**\n * Returns the arguments to add dependencies using NPM.\n * @param dependencies {string[]} The list of dependencies to add\n * @param type {DependencyType} The dependency type.\n * @returns {string[]} An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithNPM(dependencies: string[], type: DependencyType): string[] {\n let command = ['install']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using Yarn.\n * @param dependencies {string[]} The list of dependencies to add\n * @param type {DependencyType} The dependency type.\n * @returns {string[]} An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithYarn(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--dev')\n break\n case 'peer':\n command.push('--peer')\n break\n case 'prod':\n command.push('--prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using PNPM.\n * @param dependencies {string[]} The list of dependencies to add\n * @param type {DependencyType} The dependency type.\n * @returns {string[]} An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithPNPM(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\nexport type ProjectType = 'node' | 'php' | 'ruby' | undefined\n\nexport async function getProjectType(directory: string): Promise<ProjectType> {\n const nodeConfigFile = pathJoin(directory, 'package.json')\n const rubyConfigFile = pathJoin(directory, 'Gemfile')\n const phpConfigFile = pathJoin(directory, 'composer.json')\n\n if (await fileExists(nodeConfigFile)) {\n return 'node'\n } else if (await fileExists(rubyConfigFile)) {\n return 'ruby'\n } else if (await fileExists(phpConfigFile)) {\n return 'php'\n }\n return undefined\n}\n\n/**\n * Given a directory it traverses the directory up looking for a package.json and if found, it reads it\n * decodes the JSON, and returns its content as a Javascript object.\n * @param options {string} The directory from which traverse up.\n * @returns {Promise<{path: string; content: unknown}>} If found, the promise resolves with the path to the\n * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.\n */\nexport async function findUpAndReadPackageJson(fromDirectory: string): Promise<{path: string; content: unknown}> {\n const packageJsonPath = await findUp('package.json', {cwd: fromDirectory, type: 'file'})\n if (packageJsonPath) {\n const packageJson = JSON.parse(await readFile(packageJsonPath))\n return {path: packageJsonPath, content: packageJson}\n } else {\n throw FindUpAndReadPackageJsonNotFoundError(fromDirectory)\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { Abort } from './error.js';
2
+ /**
3
+ * Error that's thrown when the .env is not found.
4
+ * @param path {string} Path to the .env file.
5
+ * @returns {Abort} An abort error.
6
+ */
7
+ export declare const DotEnvNotFoundError: (path: string) => Abort;
8
+ /**
9
+ * This interface represents a .env file.
10
+ */
11
+ export interface DotEnvFile {
12
+ /**
13
+ * Path to the .env file.
14
+ */
15
+ path: string;
16
+ /**
17
+ * Variables of the .env file.
18
+ */
19
+ variables: {
20
+ [name: string]: string;
21
+ };
22
+ }
23
+ export declare function read(path: string): Promise<DotEnvFile>;
24
+ /**
25
+ * Writes a .env file to disk.
26
+ * @param file {DotEnvFile} .env file to be written.
27
+ */
28
+ export declare function write(file: DotEnvFile): Promise<void>;
@@ -0,0 +1,31 @@
1
+ import { Abort } from './error.js';
2
+ import { exists, read as readFile, write as writeFile } from './file.js';
3
+ import { debug, content as outputContent, token } from './output.js';
4
+ import { parse, stringify } from 'envfile';
5
+ /**
6
+ * Error that's thrown when the .env is not found.
7
+ * @param path {string} Path to the .env file.
8
+ * @returns {Abort} An abort error.
9
+ */
10
+ export const DotEnvNotFoundError = (path) => {
11
+ return new Abort(`The environment file at ${path} does not exist.`);
12
+ };
13
+ export async function read(path) {
14
+ debug(outputContent `Reading the .env file at ${token.path(path)}`);
15
+ if (!(await exists(path))) {
16
+ throw DotEnvNotFoundError(path);
17
+ }
18
+ const content = await readFile(path);
19
+ return {
20
+ path,
21
+ variables: parse(content),
22
+ };
23
+ }
24
+ /**
25
+ * Writes a .env file to disk.
26
+ * @param file {DotEnvFile} .env file to be written.
27
+ */
28
+ export async function write(file) {
29
+ await writeFile(file.path, stringify(file.variables));
30
+ }
31
+ //# sourceMappingURL=dot-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dot-env.js","sourceRoot":"","sources":["../src/dot-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAChC,OAAO,EAAC,MAAM,EAAE,IAAI,IAAI,QAAQ,EAAE,KAAK,IAAI,SAAS,EAAC,MAAM,WAAW,CAAA;AACtE,OAAO,EAAC,KAAK,EAAE,OAAO,IAAI,aAAa,EAAE,KAAK,EAAC,MAAM,aAAa,CAAA;AAClE,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAE,EAAE;IAClD,OAAO,IAAI,KAAK,CAAC,2BAA2B,IAAI,kBAAkB,CAAC,CAAA;AACrE,CAAC,CAAA;AAgBD,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAY;IACrC,KAAK,CAAC,aAAa,CAAA,4BAA4B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAClE,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE;QACzB,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAA;KAChC;IACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC;KAC1B,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,IAAgB;IAC1C,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;AACvD,CAAC","sourcesContent":["import {Abort} from './error.js'\nimport {exists, read as readFile, write as writeFile} from './file.js'\nimport {debug, content as outputContent, token} from './output.js'\nimport {parse, stringify} from 'envfile'\n\n/**\n * Error that's thrown when the .env is not found.\n * @param path {string} Path to the .env file.\n * @returns {Abort} An abort error.\n */\nexport const DotEnvNotFoundError = (path: string) => {\n return new Abort(`The environment file at ${path} does not exist.`)\n}\n\n/**\n * This interface represents a .env file.\n */\nexport interface DotEnvFile {\n /**\n * Path to the .env file.\n */\n path: string\n /**\n * Variables of the .env file.\n */\n variables: {[name: string]: string}\n}\n\nexport async function read(path: string): Promise<DotEnvFile> {\n debug(outputContent`Reading the .env file at ${token.path(path)}`)\n if (!(await exists(path))) {\n throw DotEnvNotFoundError(path)\n }\n const content = await readFile(path)\n return {\n path,\n variables: parse(content),\n }\n}\n\n/**\n * Writes a .env file to disk.\n * @param file {DotEnvFile} .env file to be written.\n */\nexport async function write(file: DotEnvFile) {\n await writeFile(file.path, stringify(file.variables))\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import { Abort } from '../error.js';
2
+ export declare const CouldntObtainPartnersSpinFQDNError: Abort;
3
+ export declare const CouldntObtainIdentitySpinFQDNError: Abort;
4
+ export declare const CouldntObtainShopifySpinFQDNError: Abort;
5
+ export declare const NotProvidedStoreFQDNError: Abort;
6
+ /**
7
+ * It returns the Partners' API service we should interact with.
8
+ * @returns {string} Fully-qualified domain of the partners service we should interact with.
9
+ */
10
+ export declare function partners(): Promise<string>;
11
+ /**
12
+ * It returns the Identity service we should interact with.
13
+ * @returns {string} Fully-qualified domain of the Identity service we should interact with.
14
+ */
15
+ export declare function identity(): Promise<string>;
16
+ /**
17
+ * It returns the Shopify service we should interact with.
18
+ * Note the same fqdn is sued for the Admin and the Storefront Renderer APIs.
19
+ * @returns {string} Fully-qualified domain of the Shopify service we should interact with.
20
+ */
21
+ export declare function shopify(options?: {
22
+ storeFqdn?: string;
23
+ }): Promise<string>;
@@ -0,0 +1,61 @@
1
+ import { partners as partnersEnvironment, shopify as shopifyEnvironment, identity as identityEnvironment, } from './service.js';
2
+ import { fqdn as spinFqdn } from './spin.js';
3
+ import { Abort } from '../error.js';
4
+ export const CouldntObtainPartnersSpinFQDNError = new Abort("Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.");
5
+ export const CouldntObtainIdentitySpinFQDNError = new Abort("Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.");
6
+ export const CouldntObtainShopifySpinFQDNError = new Abort("Couldn't obtain the Spin FQDN for Shopify when the CLI is not running from a Spin environment.");
7
+ export const NotProvidedStoreFQDNError = new Abort("Couldn't obtain the Shopify FQDN because the store FQDN was not provided.");
8
+ /**
9
+ * It returns the Partners' API service we should interact with.
10
+ * @returns {string} Fully-qualified domain of the partners service we should interact with.
11
+ */
12
+ export async function partners() {
13
+ const environment = partnersEnvironment();
14
+ const productionFqdn = 'partners.shopify.com';
15
+ switch (environment) {
16
+ case 'local':
17
+ return 'partners.myshopify.io';
18
+ case 'spin':
19
+ return `partners.${await spinFqdn()}`;
20
+ default:
21
+ return productionFqdn;
22
+ }
23
+ }
24
+ /**
25
+ * It returns the Identity service we should interact with.
26
+ * @returns {string} Fully-qualified domain of the Identity service we should interact with.
27
+ */
28
+ export async function identity() {
29
+ const environment = identityEnvironment();
30
+ const productionFqdn = 'accounts.shopify.com';
31
+ switch (environment) {
32
+ case 'local':
33
+ return 'identity.myshopify.io';
34
+ case 'spin':
35
+ return `identity.${await spinFqdn()}`;
36
+ default:
37
+ return productionFqdn;
38
+ }
39
+ }
40
+ /**
41
+ * It returns the Shopify service we should interact with.
42
+ * Note the same fqdn is sued for the Admin and the Storefront Renderer APIs.
43
+ * @returns {string} Fully-qualified domain of the Shopify service we should interact with.
44
+ */
45
+ export async function shopify(options = {}) {
46
+ const environment = shopifyEnvironment();
47
+ switch (environment) {
48
+ case 'local':
49
+ return 'shopify.myshopify.io';
50
+ case 'spin':
51
+ return `identity.${await spinFqdn()}`;
52
+ default:
53
+ if (options.storeFqdn) {
54
+ return options.storeFqdn;
55
+ }
56
+ else {
57
+ throw NotProvidedStoreFQDNError;
58
+ }
59
+ }
60
+ }
61
+ //# sourceMappingURL=fqdn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../src/environment/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,mBAAmB,EAC/B,OAAO,IAAI,kBAAkB,EAC7B,QAAQ,IAAI,mBAAmB,GAChC,MAAM,cAAc,CAAA;AACrB,OAAO,EAAC,IAAI,IAAI,QAAQ,EAAC,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AAEjC,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,KAAK,CACzD,iGAAiG,CAClG,CAAA;AACD,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,KAAK,CACzD,iGAAiG,CAClG,CAAA;AACD,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,KAAK,CACxD,gGAAgG,CACjG,CAAA;AACD,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,KAAK,CAChD,2EAA2E,CAC5E,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ;IAC5B,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAA;IACzC,MAAM,cAAc,GAAG,sBAAsB,CAAA;IAC7C,QAAQ,WAAW,EAAE;QACnB,KAAK,OAAO;YACV,OAAO,uBAAuB,CAAA;QAChC,KAAK,MAAM;YACT,OAAO,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAA;QACvC;YACE,OAAO,cAAc,CAAA;KACxB;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ;IAC5B,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAA;IACzC,MAAM,cAAc,GAAG,sBAAsB,CAAA;IAC7C,QAAQ,WAAW,EAAE;QACnB,KAAK,OAAO;YACV,OAAO,uBAAuB,CAAA;QAChC,KAAK,MAAM;YACT,OAAO,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAA;QACvC;YACE,OAAO,cAAc,CAAA;KACxB;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,UAAgC,EAAE;IAC9D,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAA;IACxC,QAAQ,WAAW,EAAE;QACnB,KAAK,OAAO;YACV,OAAO,sBAAsB,CAAA;QAC/B,KAAK,MAAM;YACT,OAAO,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAA;QACvC;YACE,IAAI,OAAO,CAAC,SAAS,EAAE;gBACrB,OAAO,OAAO,CAAC,SAAS,CAAA;aACzB;iBAAM;gBACL,MAAM,yBAAyB,CAAA;aAChC;KACJ;AACH,CAAC","sourcesContent":["import {\n partners as partnersEnvironment,\n shopify as shopifyEnvironment,\n identity as identityEnvironment,\n} from './service.js'\nimport {fqdn as spinFqdn} from './spin.js'\nimport {Abort} from '../error.js'\n\nexport const CouldntObtainPartnersSpinFQDNError = new Abort(\n \"Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainIdentitySpinFQDNError = new Abort(\n \"Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainShopifySpinFQDNError = new Abort(\n \"Couldn't obtain the Spin FQDN for Shopify when the CLI is not running from a Spin environment.\",\n)\nexport const NotProvidedStoreFQDNError = new Abort(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n * @returns {string} Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partners(): Promise<string> {\n const environment = partnersEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return 'partners.myshopify.io'\n case 'spin':\n return `partners.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n * @returns {string} Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identity(): Promise<string> {\n const environment = identityEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return 'identity.myshopify.io'\n case 'spin':\n return `identity.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Shopify service we should interact with.\n * Note the same fqdn is sued for the Admin and the Storefront Renderer APIs.\n * @returns {string} Fully-qualified domain of the Shopify service we should interact with.\n */\nexport async function shopify(options: {storeFqdn?: string} = {}): Promise<string> {\n const environment = shopifyEnvironment()\n switch (environment) {\n case 'local':\n return 'shopify.myshopify.io'\n case 'spin':\n return `identity.${await spinFqdn()}`\n default:\n if (options.storeFqdn) {\n return options.storeFqdn\n } else {\n throw NotProvidedStoreFQDNError\n }\n }\n}\n"]}