@shopify/cli-kit 3.0.25 → 3.1.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 (289) hide show
  1. package/CHANGELOG.md +34 -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 +13 -0
  12. package/dist/analytics.js +111 -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/find_store_by_domain.d.ts +21 -0
  54. package/dist/api/graphql/find_store_by_domain.js +24 -0
  55. package/dist/api/graphql/find_store_by_domain.js.map +1 -0
  56. package/dist/api/graphql/functions/app_function_set.d.ts +43 -0
  57. package/dist/api/graphql/functions/app_function_set.js +52 -0
  58. package/dist/api/graphql/functions/app_function_set.js.map +1 -0
  59. package/dist/api/graphql/functions/compile_module.d.ts +15 -0
  60. package/dist/api/graphql/functions/compile_module.js +13 -0
  61. package/dist/api/graphql/functions/compile_module.js.map +1 -0
  62. package/dist/api/graphql/functions/function_service_proxy.d.ts +4 -0
  63. package/dist/api/graphql/functions/function_service_proxy.js +7 -0
  64. package/dist/api/graphql/functions/function_service_proxy.js.map +1 -0
  65. package/dist/api/graphql/functions/get_app_functions.d.ts +1 -0
  66. package/dist/api/graphql/functions/get_app_functions.js +10 -0
  67. package/dist/api/graphql/functions/get_app_functions.js.map +1 -0
  68. package/dist/api/graphql/functions/module_compilation_status.d.ts +15 -0
  69. package/dist/api/graphql/functions/module_compilation_status.js +13 -0
  70. package/dist/api/graphql/functions/module_compilation_status.js.map +1 -0
  71. package/dist/api/graphql/functions/module_upload_url_generate.d.ts +18 -0
  72. package/dist/api/graphql/functions/module_upload_url_generate.js +17 -0
  73. package/dist/api/graphql/functions/module_upload_url_generate.js.map +1 -0
  74. package/dist/api/graphql/generate_signed_upload_url.d.ts +15 -0
  75. package/dist/api/graphql/generate_signed_upload_url.js +15 -0
  76. package/dist/api/graphql/generate_signed_upload_url.js.map +1 -0
  77. package/dist/api/graphql/get_variant_id.d.ts +17 -0
  78. package/dist/api/graphql/get_variant_id.js +20 -0
  79. package/dist/api/graphql/get_variant_id.js.map +1 -0
  80. package/dist/api/graphql/index.d.ts +22 -0
  81. package/dist/api/graphql/index.js +23 -0
  82. package/dist/api/graphql/index.js.map +1 -0
  83. package/dist/api/graphql/update_draft.d.ts +33 -0
  84. package/dist/api/graphql/update_draft.js +24 -0
  85. package/dist/api/graphql/update_draft.js.map +1 -0
  86. package/dist/api/graphql/update_urls.d.ts +14 -0
  87. package/dist/api/graphql/update_urls.js +12 -0
  88. package/dist/api/graphql/update_urls.js.map +1 -0
  89. package/dist/api/identity.d.ts +1 -0
  90. package/dist/api/identity.js +32 -0
  91. package/dist/api/identity.js.map +1 -0
  92. package/dist/api/partners.d.ts +25 -0
  93. package/dist/api/partners.js +100 -0
  94. package/dist/api/partners.js.map +1 -0
  95. package/dist/api.d.ts +5 -0
  96. package/dist/api.js +6 -0
  97. package/dist/api.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/constants.d.ts +43 -0
  102. package/dist/constants.js +63 -0
  103. package/dist/constants.js.map +1 -0
  104. package/dist/environment/fqdn.d.ts +23 -0
  105. package/dist/environment/fqdn.js +61 -0
  106. package/dist/environment/fqdn.js.map +1 -0
  107. package/dist/environment/local.d.ts +48 -0
  108. package/dist/environment/local.js +82 -0
  109. package/dist/environment/local.js.map +1 -0
  110. package/dist/environment/service.d.ts +17 -0
  111. package/dist/environment/service.js +41 -0
  112. package/dist/environment/service.js.map +1 -0
  113. package/dist/environment/spin.d.ts +47 -0
  114. package/dist/environment/spin.js +83 -0
  115. package/dist/environment/spin.js.map +1 -0
  116. package/dist/environment/utilities.d.ts +6 -0
  117. package/dist/environment/utilities.js +12 -0
  118. package/dist/environment/utilities.js.map +1 -0
  119. package/dist/environment.d.ts +5 -0
  120. package/dist/environment.js +6 -0
  121. package/dist/environment.js.map +1 -0
  122. package/dist/error.d.ts +44 -0
  123. package/dist/error.js +91 -0
  124. package/dist/error.js.map +1 -0
  125. package/dist/file.d.ts +67 -0
  126. package/dist/file.js +165 -0
  127. package/dist/file.js.map +1 -0
  128. package/dist/git.d.ts +15 -0
  129. package/dist/git.js +48 -0
  130. package/dist/git.js.map +1 -0
  131. package/dist/github.d.ts +33 -0
  132. package/dist/github.js +56 -0
  133. package/dist/github.js.map +1 -0
  134. package/dist/haiku.d.ts +1 -0
  135. package/dist/haiku.js +8 -0
  136. package/dist/haiku.js.map +1 -0
  137. package/dist/http/fetch.d.ts +16 -0
  138. package/dist/http/fetch.js +18 -0
  139. package/dist/http/fetch.js.map +1 -0
  140. package/dist/http/formdata.d.ts +3 -0
  141. package/dist/http/formdata.js +6 -0
  142. package/dist/http/formdata.js.map +1 -0
  143. package/dist/http.d.ts +2 -0
  144. package/dist/http.js +3 -0
  145. package/dist/http.js.map +1 -0
  146. package/dist/id.d.ts +6 -0
  147. package/dist/id.js +18 -0
  148. package/dist/id.js.map +1 -0
  149. package/dist/index.d.ts +33 -2179
  150. package/dist/index.js +34 -3264
  151. package/dist/index.js.map +1 -1
  152. package/dist/network/api.d.ts +2 -0
  153. package/dist/network/api.js +2 -0
  154. package/dist/network/api.js.map +1 -0
  155. package/dist/network/service.d.ts +16 -0
  156. package/dist/network/service.js +12 -0
  157. package/dist/network/service.js.map +1 -0
  158. package/dist/{archiver.d.ts → node/archiver.d.ts} +1 -4
  159. package/dist/node/archiver.js +22 -42
  160. package/dist/node/archiver.js.map +1 -1
  161. package/dist/node/checksum.d.ts +20 -0
  162. package/dist/node/checksum.js +32 -0
  163. package/dist/node/checksum.js.map +1 -0
  164. package/dist/node/cli.d.ts +18 -0
  165. package/dist/node/cli.js +96 -0
  166. package/dist/node/cli.js.map +1 -0
  167. package/dist/node/colors.d.ts +1 -0
  168. package/dist/node/colors.js +8 -0
  169. package/dist/node/colors.js.map +1 -0
  170. package/dist/node/dot-env.d.ts +33 -0
  171. package/dist/node/dot-env.js +36 -0
  172. package/dist/node/dot-env.js.map +1 -0
  173. package/dist/node/node-package-manager.d.ts +197 -0
  174. package/dist/node/node-package-manager.js +309 -0
  175. package/dist/node/node-package-manager.js.map +1 -0
  176. package/dist/node/ruby.d.ts +30 -0
  177. package/dist/node/ruby.js +197 -0
  178. package/dist/node/ruby.js.map +1 -0
  179. package/dist/npm.d.ts +27 -0
  180. package/dist/npm.js +20 -0
  181. package/dist/npm.js.map +1 -0
  182. package/dist/os.d.ts +10 -0
  183. package/dist/os.js +70 -0
  184. package/dist/os.js.map +1 -0
  185. package/dist/output.d.ts +149 -0
  186. package/dist/output.js +515 -0
  187. package/dist/output.js.map +1 -0
  188. package/dist/path.d.ts +22 -0
  189. package/dist/path.js +43 -0
  190. package/dist/path.js.map +1 -0
  191. package/dist/plugins.d.ts +9 -0
  192. package/dist/plugins.js +12 -0
  193. package/dist/plugins.js.map +1 -0
  194. package/dist/port.d.ts +5 -0
  195. package/dist/port.js +35 -0
  196. package/dist/port.js.map +1 -0
  197. package/dist/schema.d.ts +1 -0
  198. package/dist/schema.js +2 -0
  199. package/dist/schema.js.map +1 -0
  200. package/dist/secure-store.d.ts +19 -0
  201. package/dist/secure-store.js +63 -0
  202. package/dist/secure-store.js.map +1 -0
  203. package/dist/semver.d.ts +3 -0
  204. package/dist/semver.js +6 -0
  205. package/dist/semver.js.map +1 -0
  206. package/dist/session/authorize.d.ts +7 -0
  207. package/dist/session/authorize.js +40 -0
  208. package/dist/session/authorize.js.map +1 -0
  209. package/dist/session/exchange.d.ts +42 -0
  210. package/dist/session/exchange.js +144 -0
  211. package/dist/session/exchange.js.map +1 -0
  212. package/dist/session/identity.d.ts +3 -0
  213. package/dist/session/identity.js +58 -0
  214. package/dist/session/identity.js.map +1 -0
  215. package/dist/session/post-auth.d.ts +13 -0
  216. package/dist/session/post-auth.js +56 -0
  217. package/dist/session/post-auth.js.map +1 -0
  218. package/dist/session/redirect-listener.d.ts +34 -0
  219. package/dist/session/redirect-listener.js +97 -0
  220. package/dist/session/redirect-listener.js.map +1 -0
  221. package/dist/session/schema.d.ts +174 -0
  222. package/dist/session/schema.js +59 -0
  223. package/dist/session/schema.js.map +1 -0
  224. package/dist/session/scopes.d.ts +16 -0
  225. package/dist/session/scopes.js +53 -0
  226. package/dist/session/scopes.js.map +1 -0
  227. package/dist/session/store.d.ts +24 -0
  228. package/dist/session/store.js +88 -0
  229. package/dist/session/store.js.map +1 -0
  230. package/dist/session/token.d.ts +40 -0
  231. package/dist/session/token.js +22 -0
  232. package/dist/session/token.js.map +1 -0
  233. package/dist/session/validate.d.ts +17 -0
  234. package/dist/session/validate.js +75 -0
  235. package/dist/session/validate.js.map +1 -0
  236. package/dist/session.d.ts +88 -0
  237. package/dist/session.js +251 -0
  238. package/dist/session.js.map +1 -0
  239. package/dist/store/schema.d.ts +3 -0
  240. package/dist/store/schema.js +27 -0
  241. package/dist/store/schema.js.map +1 -0
  242. package/dist/store.d.ts +32 -0
  243. package/dist/store.js +102 -0
  244. package/dist/store.js.map +1 -0
  245. package/dist/string.d.ts +22 -0
  246. package/dist/string.js +38 -0
  247. package/dist/string.js.map +1 -0
  248. package/dist/system.d.ts +53 -0
  249. package/dist/system.js +109 -0
  250. package/dist/system.js.map +1 -0
  251. package/dist/template.d.ts +11 -0
  252. package/dist/template.js +50 -0
  253. package/dist/template.js.map +1 -0
  254. package/dist/testing/output.d.ts +9 -0
  255. package/dist/testing/output.js +15 -0
  256. package/dist/testing/output.js.map +1 -0
  257. package/dist/testing/store.d.ts +7 -0
  258. package/dist/testing/store.js +26 -0
  259. package/dist/testing/store.js.map +1 -0
  260. package/dist/toml.d.ts +3 -0
  261. package/dist/toml.js +8 -0
  262. package/dist/toml.js.map +1 -0
  263. package/dist/tsconfig.tsbuildinfo +1 -0
  264. package/dist/ui/autocomplete.d.ts +7 -0
  265. package/dist/ui/autocomplete.js +43 -0
  266. package/dist/ui/autocomplete.js.map +1 -0
  267. package/dist/ui/input.d.ts +7 -0
  268. package/dist/ui/input.js +48 -0
  269. package/dist/ui/input.js.map +1 -0
  270. package/dist/ui/select.d.ts +6 -0
  271. package/dist/ui/select.js +30 -0
  272. package/dist/ui/select.js.map +1 -0
  273. package/dist/ui.d.ts +36 -0
  274. package/dist/ui.js +124 -0
  275. package/dist/ui.js.map +1 -0
  276. package/dist/version.d.ts +19 -0
  277. package/dist/version.js +34 -0
  278. package/dist/version.js.map +1 -0
  279. package/dist/vscode.d.ts +8 -0
  280. package/dist/vscode.js +36 -0
  281. package/dist/vscode.js.map +1 -0
  282. package/dist/yaml.d.ts +2 -0
  283. package/dist/yaml.js +8 -0
  284. package/dist/yaml.js.map +1 -0
  285. package/package.json +19 -8
  286. package/dist/archiver.d.ts.map +0 -1
  287. package/dist/index.d.ts.map +0 -1
  288. package/dist/local-d0094ffe.js +0 -1344
  289. package/dist/local-d0094ffe.js.map +0 -1
@@ -0,0 +1,309 @@
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
+ /** The name of the Yarn lock file */
10
+ export const yarnLockfile = 'yarn.lock';
11
+ /** The name of the pnpm lock file */
12
+ export const pnpmLockfile = 'pnpm-lock.yaml';
13
+ /** An array containing the lockfiles from all the package managers */
14
+ export const lockfiles = [yarnLockfile, pnpmLockfile];
15
+ /**
16
+ * A union that represents the package managers available.
17
+ */
18
+ export const packageManager = ['yarn', 'npm', 'pnpm'];
19
+ /**
20
+ * Returns an abort error that's thrown when a directory that's expected to have
21
+ * a package.json doesn't have it.
22
+ * @param directory {string} The path to the directory that should contain a package.json
23
+ * @returns {Abort} An abort error.
24
+ */
25
+ export const PackageJsonNotFoundError = (directory) => {
26
+ return new Abort(`The directory ${directory} doesn't have a package.json.`);
27
+ };
28
+ /**
29
+ * Returns a bug error that's thrown when the lookup of the package.json traversing the directory
30
+ * hierarchy up can't find a package.json
31
+ * @param directory {string} The directory from which the traverse has been done
32
+ * @returns {Abort} An abort error.
33
+ */
34
+ export const FindUpAndReadPackageJsonNotFoundError = (directory) => {
35
+ return new Bug(content `Couldn't find a a package.json traversing directories from ${token.path(directory)}`);
36
+ };
37
+ /**
38
+ * Returns the dependency manager used to run the create workflow.
39
+ * @param env {Object} The environment variables of the process in which the CLI runs.
40
+ * @returns The dependency manager
41
+ */
42
+ export function packageManagerUsedForCreating(env = process.env) {
43
+ if (env.npm_config_user_agent?.includes('yarn')) {
44
+ return 'yarn';
45
+ }
46
+ else if (env.npm_config_user_agent?.includes('pnpm')) {
47
+ return 'pnpm';
48
+ }
49
+ else {
50
+ return 'npm';
51
+ }
52
+ }
53
+ /**
54
+ * Returns the dependency manager used by an existing project.
55
+ * @param directory {string} The root directory of the project.
56
+ * @returns The dependency manager
57
+ */
58
+ export async function getPackageManager(directory) {
59
+ debug(content `Obtaining the dependency manager in directory ${token.path(directory)}...`);
60
+ const yarnLockPath = pathJoin(directory, yarnLockfile);
61
+ const pnpmLockPath = pathJoin(directory, pnpmLockfile);
62
+ if (await fileExists(yarnLockPath)) {
63
+ return 'yarn';
64
+ }
65
+ else if (await fileExists(pnpmLockPath)) {
66
+ return 'pnpm';
67
+ }
68
+ else {
69
+ return 'npm';
70
+ }
71
+ }
72
+ /**
73
+ * This function traverses down a directory tree to find directories containing a package.json
74
+ * and installs the dependencies if needed. To know if it's needed, it uses the "check" command
75
+ * provided by dependency managers.
76
+ * @param options {InstallNPMDependenciesRecursivelyOptions} Options to install dependencies recursively.
77
+ */
78
+ export async function installNPMDependenciesRecursively(options) {
79
+ const packageJsons = await glob(pathJoin(options.directory, '**/package.json'), {
80
+ ignore: [pathJoin(options.directory, 'node_modules/**/package.json')],
81
+ cwd: options.directory,
82
+ onlyFiles: true,
83
+ deep: options.deep,
84
+ });
85
+ const abortController = new AbortController();
86
+ try {
87
+ await Promise.all(packageJsons.map(async (packageJsonPath) => {
88
+ const directory = dirname(packageJsonPath);
89
+ await installNodeModules(directory, options.packageManager, undefined, undefined, abortController.signal);
90
+ }));
91
+ }
92
+ catch (error) {
93
+ abortController.abort();
94
+ throw error;
95
+ }
96
+ }
97
+ /**
98
+ * Installs the dependencies in the given directory.
99
+ * @param directory {string} The directory that contains the package.json
100
+ * @param packageManager {PackageManager} The package manager to use to install the dependencies.
101
+ * @param stdout {Writable} Standard output stream.
102
+ * @param stderr {Writable} Standard error stream.
103
+ * @param signal {AbortSignal} Abort signal.
104
+ * @returns stderr {Writable} Standard error stream.
105
+ */
106
+ export async function installNodeModules(directory, packageManager, stdout, stderr, signal) {
107
+ const options = { cwd: directory, stdin: undefined, stdout, stderr, signal };
108
+ await exec(packageManager, ['install'], options);
109
+ }
110
+ /**
111
+ * Returns the name of the package configured in its package.json
112
+ * @param packageJsonPath {string} Path to the package.json file
113
+ * @returns A promise that resolves with the name.
114
+ */
115
+ export async function getPackageName(packageJsonPath) {
116
+ const packageJsonContent = await readAndParsePackageJson(packageJsonPath);
117
+ return packageJsonContent.name;
118
+ }
119
+ /**
120
+ * Returns the list of production and dev dependencies of a package.json
121
+ * @param packageJsonPath {string} Path to the package.json file
122
+ * @returns A promise that resolves with the list of dependencies.
123
+ */
124
+ export async function getDependencies(packageJsonPath) {
125
+ const packageJsonContent = await readAndParsePackageJson(packageJsonPath);
126
+ const dependencies = packageJsonContent.dependencies ?? {};
127
+ const devDependencies = packageJsonContent.devDependencies ?? {};
128
+ return { ...dependencies, ...devDependencies };
129
+ }
130
+ /**
131
+ * Given an NPM dependency, it checks if there's a more recent version, and if there is, it returns its value.
132
+ * @param dependency {string} The dependency name (e.g. react)
133
+ * @param currentVersion {string} The current version.
134
+ * @returns {Promise<string>} A promise that resolves with a more recent version or undefined if there's no more recent version.
135
+ */
136
+ export async function checkForNewVersion(dependency, currentVersion) {
137
+ debug(content `Checking if there's a version of ${dependency} newer than ${currentVersion}`);
138
+ try {
139
+ const lastVersion = await latestNpmPackageVersion(dependency);
140
+ if (lastVersion && new Version(currentVersion).compare(lastVersion) < 0) {
141
+ return lastVersion;
142
+ }
143
+ else {
144
+ return undefined;
145
+ }
146
+ // eslint-disable-next-line no-catch-all/no-catch-all
147
+ }
148
+ catch (error) {
149
+ return undefined;
150
+ }
151
+ }
152
+ /**
153
+ * Reads and parses a package.json
154
+ * @param packageJsonPath {string} Path to the package.json
155
+ * @returns {Promise<PackageJson>} An promise that resolves with an in-memory representation
156
+ * of the package.json or rejects with an error if the file is not found or the content is
157
+ * not decodable.
158
+ */
159
+ export async function readAndParsePackageJson(packageJsonPath) {
160
+ if (!(await fileExists(packageJsonPath))) {
161
+ throw PackageJsonNotFoundError(dirname(packageJsonPath));
162
+ }
163
+ return JSON.parse(await readFile(packageJsonPath));
164
+ }
165
+ /**
166
+ * Adds dependencies to a Node project (i.e. a project that has a package.json)
167
+ * @param dependencies {string[]} List of dependencies to be added.
168
+ * @param options {AddNPMDependenciesIfNeededOptions} Options for adding dependencies.
169
+ */
170
+ export async function addNPMDependenciesIfNeeded(dependencies, options, force = false) {
171
+ debug(content `Adding the following dependencies if needed:
172
+ ${token.json(dependencies)}
173
+ With options:
174
+ ${token.json(options)}
175
+ `);
176
+ const packageJsonPath = pathJoin(options.directory, 'package.json');
177
+ if (!(await fileExists(packageJsonPath))) {
178
+ throw PackageJsonNotFoundError(options.directory);
179
+ }
180
+ const existingDependencies = Object.keys(await getDependencies(packageJsonPath));
181
+ let dependenciesToAdd = dependencies;
182
+ if (!force) {
183
+ dependenciesToAdd = dependencies.filter((dep) => {
184
+ return !existingDependencies.includes(dep.name);
185
+ });
186
+ }
187
+ if (dependenciesToAdd.length === 0) {
188
+ return;
189
+ }
190
+ let args;
191
+ const depedenciesWithVersion = dependenciesToAdd.map((dep) => {
192
+ return dep.version ? `${dep.name}@${dep.version}` : dep.name;
193
+ });
194
+ switch (options.packageManager) {
195
+ case 'npm':
196
+ args = argumentsToAddDependenciesWithNPM(depedenciesWithVersion, options.type);
197
+ break;
198
+ case 'yarn':
199
+ args = argumentsToAddDependenciesWithYarn(depedenciesWithVersion, options.type);
200
+ break;
201
+ case 'pnpm':
202
+ args = argumentsToAddDependenciesWithPNPM(depedenciesWithVersion, options.type);
203
+ break;
204
+ }
205
+ options.stdout?.write(`Executing...${args.join(' ')}`);
206
+ await exec(options.packageManager, args, {
207
+ cwd: options.directory,
208
+ stdout: options.stdout,
209
+ stderr: options.stderr,
210
+ signal: options.signal,
211
+ });
212
+ }
213
+ export async function addNPMDependenciesWithoutVersionIfNeeded(dependencies, options) {
214
+ await addNPMDependenciesIfNeeded(dependencies.map((dependency) => {
215
+ return { name: dependency, version: undefined };
216
+ }), options);
217
+ }
218
+ // eslint-disable-next-line no-warning-comments
219
+ // TODO: Switch it around so add-if-needed depends on this, rather than calling
220
+ // if-needed with force: true which is counterintuitive.
221
+ export async function addLatestNPMDependencies(dependencies, options) {
222
+ await addNPMDependenciesIfNeeded(dependencies.map((dependency) => {
223
+ return { name: dependency, version: 'latest' };
224
+ }), options, true);
225
+ }
226
+ /**
227
+ * Returns the arguments to add dependencies using NPM.
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 argumentsToAddDependenciesWithNPM(dependencies, type) {
233
+ let command = ['install'];
234
+ command = command.concat(dependencies);
235
+ switch (type) {
236
+ case 'dev':
237
+ command.push('--save-dev');
238
+ break;
239
+ case 'peer':
240
+ command.push('--save-peer');
241
+ break;
242
+ case 'prod':
243
+ command.push('--save-prod');
244
+ break;
245
+ }
246
+ return command;
247
+ }
248
+ /**
249
+ * Returns the arguments to add dependencies using Yarn.
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 argumentsToAddDependenciesWithYarn(dependencies, type) {
255
+ let command = ['add'];
256
+ command = command.concat(dependencies);
257
+ switch (type) {
258
+ case 'dev':
259
+ command.push('--dev');
260
+ break;
261
+ case 'peer':
262
+ command.push('--peer');
263
+ break;
264
+ case 'prod':
265
+ command.push('--prod');
266
+ break;
267
+ }
268
+ return command;
269
+ }
270
+ /**
271
+ * Returns the arguments to add dependencies using PNPM.
272
+ * @param dependencies {string[]} The list of dependencies to add
273
+ * @param type {DependencyType} The dependency type.
274
+ * @returns {string[]} An array with the arguments.
275
+ */
276
+ function argumentsToAddDependenciesWithPNPM(dependencies, type) {
277
+ let command = ['add'];
278
+ command = command.concat(dependencies);
279
+ switch (type) {
280
+ case 'dev':
281
+ command.push('--save-dev');
282
+ break;
283
+ case 'peer':
284
+ command.push('--save-peer');
285
+ break;
286
+ case 'prod':
287
+ command.push('--save-prod');
288
+ break;
289
+ }
290
+ return command;
291
+ }
292
+ /**
293
+ * Given a directory it traverses the directory up looking for a package.json and if found, it reads it
294
+ * decodes the JSON, and returns its content as a Javascript object.
295
+ * @param options {string} The directory from which traverse up.
296
+ * @returns {Promise<{path: string; content: unknown}>} If found, the promise resolves with the path to the
297
+ * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.
298
+ */
299
+ export async function findUpAndReadPackageJson(fromDirectory) {
300
+ const packageJsonPath = await findUp('package.json', { cwd: fromDirectory, type: 'file' });
301
+ if (packageJsonPath) {
302
+ const packageJson = JSON.parse(await readFile(packageJsonPath));
303
+ return { path: packageJsonPath, content: packageJson };
304
+ }
305
+ else {
306
+ throw FindUpAndReadPackageJsonNotFoundError(fromDirectory);
307
+ }
308
+ }
309
+ //# sourceMappingURL=node-package-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-package-manager.js","sourceRoot":"","sources":["../../src/node/node-package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAA;AACjC,OAAO,EAAC,MAAM,IAAI,UAAU,EAAE,IAAI,IAAI,QAAQ,EAAC,MAAM,YAAY,CAAA;AACjE,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,EAAC,MAAM,YAAY,CAAA;AAClE,OAAO,EAAC,KAAK,EAAE,GAAG,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,uBAAuB,EAAC,MAAM,eAAe,CAAA;AACrD,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAA;AACpC,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,cAAc,CAAA;AAClD,OAAO,EAAC,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAI7D,qCAAqC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAA;AAEvC,qCAAqC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAA;AAE5C,sEAAsE;AACtE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;AAUrD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAU,CAAA;AAG9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC5D,OAAO,IAAI,KAAK,CAAC,iBAAiB,SAAS,+BAA+B,CAAC,CAAA;AAC7E,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,SAAiB,EAAE,EAAE;IACzE,O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AM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAA;QAC/D,OAAO,EAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAC,CAAA;KACrD;SAAM;QACL,MAAM,qCAAqC,CAAC,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\n/** The name of the Yarn lock file */\nexport const yarnLockfile = 'yarn.lock'\n\n/** The name of the pnpm lock file */\nexport const pnpmLockfile = 'pnpm-lock.yaml'\n\n/** An array containing the lockfiles from all the package managers */\nexport const lockfiles = [yarnLockfile, pnpmLockfile]\n\n/**\n * A union type that represents the type of dependencies in the package.json\n * - dev: devDependencies\n * - prod: dependencies\n * - peer: peerDependencies\n */\nexport type DependencyType = 'dev' | 'prod' | 'peer'\n\n/**\n * A union that represents the package managers available.\n */\nexport const packageManager = ['yarn', 'npm', 'pnpm'] as const\nexport type PackageManager = typeof packageManager[number]\n\n/**\n * Returns an abort error that's thrown when a directory that's expected to have\n * a package.json doesn't have it.\n * @param directory {string} The path to the directory that should contain a package.json\n * @returns {Abort} An abort error.\n */\nexport const PackageJsonNotFoundError = (directory: string) => {\n return new Abort(`The directory ${directory} doesn't have a package.json.`)\n}\n\n/**\n * Returns a bug error that's thrown when the lookup of the package.json traversing the directory\n * hierarchy up can't find a package.json\n * @param directory {string} The directory from which the traverse has been done\n * @returns {Abort} An abort error.\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 packageManagerUsedForCreating(env = process.env): PackageManager {\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 getPackageManager(directory: string): Promise<PackageManager> {\n debug(content`Obtaining the dependency manager in directory ${token.path(directory)}...`)\n const yarnLockPath = pathJoin(directory, yarnLockfile)\n const pnpmLockPath = pathJoin(directory, pnpmLockfile)\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 packageManager: PackageManager\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 installNodeModules(directory, options.packageManager, 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 packageManager {PackageManager} The package 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 installNodeModules(\n directory: string,\n packageManager: PackageManager,\n stdout?: Writable,\n stderr?: Writable,\n signal?: AbortSignal,\n) {\n const options: ExecOptions = {cwd: directory, stdin: undefined, stdout, stderr, signal}\n await exec(packageManager, ['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 readAndParsePackageJson(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 readAndParsePackageJson(packageJsonPath)\n const dependencies: {[key: string]: string} = packageJsonContent.dependencies ?? {}\n const devDependencies: {[key: string]: string} = packageJsonContent.devDependencies ?? {}\n\n return {...dependencies, ...devDependencies}\n}\n\n/**\n * Given an NPM dependency, it checks if there's a more recent version, and if there is, it returns its value.\n * @param dependency {string} The dependency name (e.g. react)\n * @param currentVersion {string} The current version.\n * @returns {Promise<string>} A promise that resolves with a more recent version or undefined if there's no more recent version.\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\n/**\n * An interface that represents a package.json\n */\ninterface PackageJson {\n /**\n * The absolute path to the package.json\n */\n path: string\n\n /**\n * The name attribute of the package.json\n */\n name: string\n\n /**\n * The version attribute of the package.json\n */\n version?: string\n\n /**\n * The dependencies attribute of the package.json\n */\n dependencies?: {[key: string]: string}\n\n /**\n * The devDependencies attribute of the package.json\n */\n devDependencies?: {[key: string]: string}\n}\n\n/**\n * Reads and parses a package.json\n * @param packageJsonPath {string} Path to the package.json\n * @returns {Promise<PackageJson>} An promise that resolves with an in-memory representation\n * of the package.json or rejects with an error if the file is not found or the content is\n * not decodable.\n */\nexport async function readAndParsePackageJson(packageJsonPath: string): Promise<PackageJson> {\n if (!(await fileExists(packageJsonPath))) {\n throw PackageJsonNotFoundError(dirname(packageJsonPath))\n }\n return JSON.parse(await readFile(packageJsonPath))\n}\n\ninterface AddNPMDependenciesIfNeededOptions {\n /** How dependencies should be added */\n type: DependencyType\n\n /** The dependency manager to use to add dependencies */\n packageManager: PackageManager\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\n/**\n * An interface that represents a dependency name with its version\n */\nexport interface DependencyVersion {\n /**\n * The name of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below name would be \"react\"\n * {\n * \"react\": \"1.2.3\"\n * }\n */\n name: string\n\n /**\n * The version of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below version would be \"1.2.3\"\n * {\n * \"react\": \"1.2.3\"\n * }\n */\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.packageManager) {\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.packageManager, 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\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,30 @@
1
+ /// <reference types="node" />
2
+ import { AdminSession } from '../session.js';
3
+ import { Writable } from 'node:stream';
4
+ /**
5
+ * Execute CLI 2.0 commands.
6
+ * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.
7
+ * User must have a valid ruby+bundler environment to run any command.
8
+ *
9
+ * @param args {string[]} List of argumets to execute. (ex: ['theme', 'pull'])
10
+ * @param adminSession {AdminSession} Contains token and store to pass to CLI 2.0, which will be set as environment variables
11
+ */
12
+ export declare function execCLI2(args: string[], adminSession?: AdminSession): Promise<void>;
13
+ interface ExecThemeCheckCLIOptions {
14
+ /** A list of directories in which theme-check should run */
15
+ directories: string[];
16
+ /** Arguments to pass to the theme-check CLI */
17
+ args?: string[];
18
+ /** Writable to send standard output content through */
19
+ stdout: Writable;
20
+ /** Writable to send standard error content through */
21
+ stderr: Writable;
22
+ }
23
+ /**
24
+ * A function that installs (if needed) and runs the theme-check CLI.
25
+ * @param options {ExecThemeCheckCLIOptions} Options to customize the execution of theme-check.
26
+ * @returns {Promise<void>} A promise that resolves or rejects depending on the result of the underlying theme-check process.
27
+ */
28
+ export declare function execThemeCheckCLI({ directories, args, stdout, stderr, }: ExecThemeCheckCLIOptions): Promise<void[]>;
29
+ export declare function version(): Promise<string | undefined>;
30
+ export {};
@@ -0,0 +1,197 @@
1
+ import * as file from '../file.js';
2
+ import * as ui from '../ui.js';
3
+ import * as system from '../system.js';
4
+ import { Abort } from '../error.js';
5
+ import { glob, join } from '../path.js';
6
+ import constants from '../constants.js';
7
+ import { coerce } from '../semver.js';
8
+ import { content, token } from '../output.js';
9
+ // eslint-disable-next-line no-restricted-imports
10
+ import { spawn } from 'child_process';
11
+ import { Writable } from 'node:stream';
12
+ const RubyCLIVersion = '2.16.0';
13
+ const ThemeCheckVersion = '1.10.3';
14
+ const MinBundlerVersion = '2.3.8';
15
+ const MinRubyVersion = '2.3.0';
16
+ const MinRubyGemVersion = '2.5.0';
17
+ /**
18
+ * Execute CLI 2.0 commands.
19
+ * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.
20
+ * User must have a valid ruby+bundler environment to run any command.
21
+ *
22
+ * @param args {string[]} List of argumets to execute. (ex: ['theme', 'pull'])
23
+ * @param adminSession {AdminSession} Contains token and store to pass to CLI 2.0, which will be set as environment variables
24
+ */
25
+ export async function execCLI2(args, adminSession) {
26
+ await installCLIDependencies();
27
+ const env = {
28
+ ...process.env,
29
+ SHOPIFY_CLI_ADMIN_AUTH_TOKEN: adminSession?.token,
30
+ SHOPIFY_CLI_STORE: adminSession?.storeFqdn,
31
+ };
32
+ spawn('bundle', ['exec', 'shopify'].concat(args), {
33
+ stdio: 'inherit',
34
+ cwd: shopifyCLIDirectory(),
35
+ shell: true,
36
+ env,
37
+ });
38
+ }
39
+ /**
40
+ * A function that installs (if needed) and runs the theme-check CLI.
41
+ * @param options {ExecThemeCheckCLIOptions} Options to customize the execution of theme-check.
42
+ * @returns {Promise<void>} A promise that resolves or rejects depending on the result of the underlying theme-check process.
43
+ */
44
+ export async function execThemeCheckCLI({ directories, args, stdout, stderr, }) {
45
+ await installThemeCheckCLIDependencies(stdout);
46
+ const processes = directories.map(async (directory) => {
47
+ // Check that there are files aside from the extension TOML config file,
48
+ // otherwise theme-check will return a false failure.
49
+ const files = await glob(join(directory, '/**/*'));
50
+ const fileCount = files.filter((file) => !file.match(/\.toml$/)).length;
51
+ if (fileCount === 0)
52
+ return;
53
+ const customStderr = new Writable({
54
+ write(chunk, ...args) {
55
+ // For some reason, theme-check reports this initial status line to stderr
56
+ // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31
57
+ // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65
58
+ if (chunk.toString('ascii').match(/^Checking/)) {
59
+ stdout.write(chunk, ...args);
60
+ }
61
+ else {
62
+ stderr.write(chunk, ...args);
63
+ }
64
+ },
65
+ });
66
+ await system.exec('bundle', ['exec', 'theme-check'].concat([directory, ...(args || [])]), {
67
+ stdout,
68
+ stderr: customStderr,
69
+ cwd: themeCheckDirectory(),
70
+ });
71
+ });
72
+ return Promise.all(processes);
73
+ }
74
+ /**
75
+ * Validate Ruby Enviroment
76
+ * Install Theme Check CLI and its dependencies
77
+ * Shows a loading message if it's the first time installing dependencies
78
+ * or if we are installing a new version of Theme Check CLI
79
+ */
80
+ async function installThemeCheckCLIDependencies(stdout) {
81
+ const exists = await file.exists(themeCheckDirectory());
82
+ if (!exists)
83
+ stdout.write('Installing theme dependencies...');
84
+ const list = ui.newListr([
85
+ {
86
+ title: 'Installing theme dependencies',
87
+ task: async () => {
88
+ await validateRubyEnv();
89
+ await createThemeCheckCLIWorkingDirectory();
90
+ await createThemeCheckGemfile();
91
+ await bundleInstallThemeCheck();
92
+ },
93
+ },
94
+ ], { renderer: 'silent' });
95
+ await list.run();
96
+ if (!exists)
97
+ stdout.write('Installed theme dependencies!');
98
+ }
99
+ /**
100
+ * Validate Ruby Enviroment
101
+ * Install RubyCLI and its dependencies
102
+ * Shows a loading spinner if it's the first time installing dependencies
103
+ * or if we are installing a new version of RubyCLI
104
+ */
105
+ async function installCLIDependencies() {
106
+ const exists = await file.exists(shopifyCLIDirectory());
107
+ const renderer = exists ? 'silent' : 'default';
108
+ const list = ui.newListr([
109
+ {
110
+ title: 'Installing theme dependencies',
111
+ task: async () => {
112
+ await validateRubyEnv();
113
+ await createShopifyCLIWorkingDirectory();
114
+ await createShopifyCLIGemfile();
115
+ await bundleInstallShopifyCLI();
116
+ },
117
+ },
118
+ ], { renderer });
119
+ await list.run();
120
+ }
121
+ async function validateRubyEnv() {
122
+ await validateRuby();
123
+ await validateRubyGems();
124
+ await validateBundler();
125
+ }
126
+ async function validateRuby() {
127
+ let version;
128
+ try {
129
+ const stdout = await system.captureOutput('ruby', ['-v']);
130
+ version = coerce(stdout);
131
+ }
132
+ catch {
133
+ throw new Abort('Ruby environment not found', `Make sure you have Ruby installed on your system: ${content `${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value}`);
134
+ }
135
+ const isValid = version?.compare(MinRubyVersion);
136
+ if (isValid === -1 || isValid === undefined) {
137
+ throw new Abort(`Ruby version ${content `${token.yellow(version.raw)}`.value} is not supported`, `Make sure you have at least Ruby ${content `${token.yellow(MinRubyVersion)}`.value} installed on your system: ${content `${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value}`);
138
+ }
139
+ }
140
+ async function validateRubyGems() {
141
+ const stdout = await system.captureOutput('gem', ['-v']);
142
+ const version = coerce(stdout);
143
+ const isValid = version?.compare(MinRubyGemVersion);
144
+ if (isValid === -1 || isValid === undefined) {
145
+ throw new Abort(`RubyGems version ${content `${token.yellow(version.raw)}`.value} is not supported`, `To update to the latest version of RubyGems, run ${content `${token.genericShellCommand('gem update --system')}`.value}`);
146
+ }
147
+ }
148
+ async function validateBundler() {
149
+ let version;
150
+ try {
151
+ const stdout = await system.captureOutput('bundler', ['-v']);
152
+ version = coerce(stdout);
153
+ }
154
+ catch {
155
+ throw new Abort('Bundler not found', `To install the latest version of Bundler, run ${content `${token.genericShellCommand('gem install bundler')}`.value}`);
156
+ }
157
+ const isValid = version?.compare(MinBundlerVersion);
158
+ if (isValid === -1 || isValid === undefined) {
159
+ throw new Abort(`Bundler version ${content `${token.yellow(version.raw)}`.value} is not supported`, `To update to the latest version of Bundler, run ${content `${token.genericShellCommand('gem install bundler')}`.value}`);
160
+ }
161
+ }
162
+ function createShopifyCLIWorkingDirectory() {
163
+ return file.mkdir(shopifyCLIDirectory());
164
+ }
165
+ function createThemeCheckCLIWorkingDirectory() {
166
+ return file.mkdir(themeCheckDirectory());
167
+ }
168
+ async function createShopifyCLIGemfile() {
169
+ const gemPath = join(shopifyCLIDirectory(), 'Gemfile');
170
+ await file.write(gemPath, `source 'https://rubygems.org'\ngem 'shopify-cli', '${RubyCLIVersion}'`);
171
+ }
172
+ async function createThemeCheckGemfile() {
173
+ const gemPath = join(themeCheckDirectory(), 'Gemfile');
174
+ await file.write(gemPath, `source 'https://rubygems.org'\ngem 'theme-check', '${ThemeCheckVersion}'`);
175
+ }
176
+ async function bundleInstallShopifyCLI() {
177
+ await system.exec('bundle', ['config', 'set', '--local', 'path', shopifyCLIDirectory()], { cwd: shopifyCLIDirectory() });
178
+ await system.exec('bundle', ['install'], { cwd: shopifyCLIDirectory() });
179
+ }
180
+ async function bundleInstallThemeCheck() {
181
+ await system.exec('bundle', ['config', 'set', '--local', 'path', themeCheckDirectory()], { cwd: themeCheckDirectory() });
182
+ await system.exec('bundle', ['install'], { cwd: themeCheckDirectory() });
183
+ }
184
+ function shopifyCLIDirectory() {
185
+ return join(constants.paths.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion);
186
+ }
187
+ function themeCheckDirectory() {
188
+ return join(constants.paths.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion);
189
+ }
190
+ export async function version() {
191
+ const parseOutput = (version) => version.match(/ruby (\d+\.\d+\.\d+)/)?.[1];
192
+ return system
193
+ .captureOutput('ruby', ['-v'])
194
+ .then(parseOutput)
195
+ .catch(() => undefined);
196
+ }
197
+ //# sourceMappingURL=ruby.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ruby.js","sourceRoot":"","sources":["../../src/node/ruby.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAA;AAClC,OAAO,KAAK,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AACjC,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,YAAY,CAAA;AACrC,OAAO,SAAS,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,cAAc,CAAA;AAC3C,iDAAiD;AACjD,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAA;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,C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,EAAE,CAAC,SAAS,CAAC,CAAA;AAC3B,CAAC","sourcesContent":["import * as file from '../file.js'\nimport * as ui from '../ui.js'\nimport * as system from '../system.js'\nimport {Abort} from '../error.js'\nimport {glob, join} from '../path.js'\nimport constants from '../constants.js'\nimport {coerce} from '../semver.js'\nimport {AdminSession} from '../session.js'\nimport {content, token} from '../output.js'\n// eslint-disable-next-line no-restricted-imports\nimport {spawn} from 'child_process'\nimport {Writable} from 'node:stream'\n\nconst RubyCLIVersion = '2.16.0'\nconst ThemeCheckVersion = '1.10.3'\nconst MinBundlerVersion = '2.3.8'\nconst MinRubyVersion = '2.3.0'\nconst MinRubyGemVersion = '2.5.0'\n\n/**\n * Execute CLI 2.0 commands.\n * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.\n * User must have a valid ruby+bundler environment to run any command.\n *\n * @param args {string[]} List of argumets to execute. (ex: ['theme', 'pull'])\n * @param adminSession {AdminSession} Contains token and store to pass to CLI 2.0, which will be set as environment variables\n */\nexport async function execCLI2(args: string[], adminSession?: AdminSession) {\n await installCLIDependencies()\n const env = {\n ...process.env,\n SHOPIFY_CLI_ADMIN_AUTH_TOKEN: adminSession?.token,\n SHOPIFY_CLI_STORE: adminSession?.storeFqdn,\n }\n\n spawn('bundle', ['exec', 'shopify'].concat(args), {\n stdio: 'inherit',\n cwd: shopifyCLIDirectory(),\n shell: true,\n env,\n })\n}\n\ninterface ExecThemeCheckCLIOptions {\n /** A list of directories in which theme-check should run */\n directories: string[]\n /** Arguments to pass to the theme-check CLI */\n args?: string[]\n /** Writable to send standard output content through */\n stdout: Writable\n /** Writable to send standard error content through */\n stderr: Writable\n}\n\n/**\n * A function that installs (if needed) and runs the theme-check CLI.\n * @param options {ExecThemeCheckCLIOptions} Options to customize the execution of theme-check.\n * @returns {Promise<void>} A promise that resolves or rejects depending on the result of the underlying theme-check process.\n */\nexport async function execThemeCheckCLI({\n directories,\n args,\n stdout,\n stderr,\n}: ExecThemeCheckCLIOptions): Promise<void[]> {\n await installThemeCheckCLIDependencies(stdout)\n\n const processes = directories.map(async (directory): Promise<void> => {\n // Check that there are files aside from the extension TOML config file,\n // otherwise theme-check will return a false failure.\n const files = await glob(join(directory, '/**/*'))\n const fileCount = files.filter((file) => !file.match(/\\.toml$/)).length\n if (fileCount === 0) return\n\n const customStderr = new Writable({\n write(chunk, ...args) {\n // For some reason, theme-check reports this initial status line to stderr\n // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31\n // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65\n if (chunk.toString('ascii').match(/^Checking/)) {\n stdout.write(chunk, ...args)\n } else {\n stderr.write(chunk, ...args)\n }\n },\n })\n await system.exec('bundle', ['exec', 'theme-check'].concat([directory, ...(args || [])]), {\n stdout,\n stderr: customStderr,\n cwd: themeCheckDirectory(),\n })\n })\n return Promise.all(processes)\n}\n\n/**\n * Validate Ruby Enviroment\n * Install Theme Check CLI and its dependencies\n * Shows a loading message if it's the first time installing dependencies\n * or if we are installing a new version of Theme Check CLI\n */\nasync function installThemeCheckCLIDependencies(stdout: Writable) {\n const exists = await file.exists(themeCheckDirectory())\n\n if (!exists) stdout.write('Installing theme dependencies...')\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n await validateRubyEnv()\n await createThemeCheckCLIWorkingDirectory()\n await createThemeCheckGemfile()\n await bundleInstallThemeCheck()\n },\n },\n ],\n {renderer: 'silent'},\n )\n await list.run()\n if (!exists) stdout.write('Installed theme dependencies!')\n}\n\n/**\n * Validate Ruby Enviroment\n * Install RubyCLI and its dependencies\n * Shows a loading spinner if it's the first time installing dependencies\n * or if we are installing a new version of RubyCLI\n */\nasync function installCLIDependencies() {\n const exists = await file.exists(shopifyCLIDirectory())\n const renderer = exists ? 'silent' : 'default'\n\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n await validateRubyEnv()\n await createShopifyCLIWorkingDirectory()\n await createShopifyCLIGemfile()\n await bundleInstallShopifyCLI()\n },\n },\n ],\n {renderer},\n )\n await list.run()\n}\n\nasync function validateRubyEnv() {\n await validateRuby()\n await validateRubyGems()\n await validateBundler()\n}\n\nasync function validateRuby() {\n let version\n try {\n const stdout = await system.captureOutput('ruby', ['-v'])\n version = coerce(stdout)\n } catch {\n throw new Abort(\n 'Ruby environment not found',\n `Make sure you have Ruby installed on your system: ${\n content`${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinRubyVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Ruby version ${content`${token.yellow(version!.raw)}`.value} is not supported`,\n `Make sure you have at least Ruby ${content`${token.yellow(MinRubyVersion)}`.value} installed on your system: ${\n content`${token.link('', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n}\n\nasync function validateRubyGems() {\n const stdout = await system.captureOutput('gem', ['-v'])\n const version = coerce(stdout)\n\n const isValid = version?.compare(MinRubyGemVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `RubyGems version ${content`${token.yellow(version!.raw)}`.value} is not supported`,\n `To update to the latest version of RubyGems, run ${\n content`${token.genericShellCommand('gem update --system')}`.value\n }`,\n )\n }\n}\n\nasync function validateBundler() {\n let version\n try {\n const stdout = await system.captureOutput('bundler', ['-v'])\n version = coerce(stdout)\n } catch {\n throw new Abort(\n 'Bundler not found',\n `To install the latest version of Bundler, run ${\n content`${token.genericShellCommand('gem install bundler')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinBundlerVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Bundler version ${content`${token.yellow(version!.raw)}`.value} is not supported`,\n `To update to the latest version of Bundler, run ${\n content`${token.genericShellCommand('gem install bundler')}`.value\n }`,\n )\n }\n}\n\nfunction createShopifyCLIWorkingDirectory() {\n return file.mkdir(shopifyCLIDirectory())\n}\n\nfunction createThemeCheckCLIWorkingDirectory() {\n return file.mkdir(themeCheckDirectory())\n}\n\nasync function createShopifyCLIGemfile() {\n const gemPath = join(shopifyCLIDirectory(), 'Gemfile')\n await file.write(gemPath, `source 'https://rubygems.org'\\ngem 'shopify-cli', '${RubyCLIVersion}'`)\n}\n\nasync function createThemeCheckGemfile() {\n const gemPath = join(themeCheckDirectory(), 'Gemfile')\n await file.write(gemPath, `source 'https://rubygems.org'\\ngem 'theme-check', '${ThemeCheckVersion}'`)\n}\n\nasync function bundleInstallShopifyCLI() {\n await system.exec('bundle', ['config', 'set', '--local', 'path', shopifyCLIDirectory()], {cwd: shopifyCLIDirectory()})\n await system.exec('bundle', ['install'], {cwd: shopifyCLIDirectory()})\n}\n\nasync function bundleInstallThemeCheck() {\n await system.exec('bundle', ['config', 'set', '--local', 'path', themeCheckDirectory()], {cwd: themeCheckDirectory()})\n await system.exec('bundle', ['install'], {cwd: themeCheckDirectory()})\n}\n\nfunction shopifyCLIDirectory() {\n return join(constants.paths.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion)\n}\n\nfunction themeCheckDirectory() {\n return join(constants.paths.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion)\n}\n\nexport async function version(): Promise<string | undefined> {\n const parseOutput = (version: string) => version.match(/ruby (\\d+\\.\\d+\\.\\d+)/)?.[1]\n return system\n .captureOutput('ruby', ['-v'])\n .then(parseOutput)\n .catch(() => undefined)\n}\n"]}
package/dist/npm.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ interface JSON {
2
+ [key: string]: JSONValue;
3
+ }
4
+ declare type JSONValue = string | number | boolean | JSON | JSONValue[];
5
+ export interface PackageJSON extends JSON {
6
+ name: string;
7
+ author: string;
8
+ dependencies: {
9
+ [key: string]: string;
10
+ };
11
+ devDependencies: {
12
+ [key: string]: string;
13
+ };
14
+ resolutions: {
15
+ [key: string]: string;
16
+ };
17
+ overrides: {
18
+ [key: string]: string;
19
+ };
20
+ scripts: {
21
+ [key: string]: string;
22
+ };
23
+ }
24
+ export declare function readPackageJSON(directory: string): Promise<PackageJSON>;
25
+ export declare function writePackageJSON(directory: string, packageJSON: JSON): Promise<void>;
26
+ export declare function updateAppData(packageJSON: JSON, name: string): Promise<void>;
27
+ export {};