@strapi/strapi 5.12.1 → 5.12.2

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 (263) hide show
  1. package/dist/cli.js +89 -45
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs +90 -42
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/package.json.js +6 -0
  6. package/dist/package.json.js.map +1 -0
  7. package/dist/package.json.mjs +4 -0
  8. package/dist/package.json.mjs.map +1 -0
  9. package/dist/src/cli/commands/admin/create-user.js +124 -0
  10. package/dist/src/cli/commands/admin/create-user.js.map +1 -0
  11. package/dist/src/cli/commands/admin/create-user.mjs +121 -0
  12. package/dist/src/cli/commands/admin/create-user.mjs.map +1 -0
  13. package/dist/src/cli/commands/admin/reset-user-password.js +61 -0
  14. package/dist/src/cli/commands/admin/reset-user-password.js.map +1 -0
  15. package/dist/src/cli/commands/admin/reset-user-password.mjs +58 -0
  16. package/dist/src/cli/commands/admin/reset-user-password.mjs.map +1 -0
  17. package/dist/src/cli/commands/build.js +29 -0
  18. package/dist/src/cli/commands/build.js.map +1 -0
  19. package/dist/src/cli/commands/build.mjs +27 -0
  20. package/dist/src/cli/commands/build.mjs.map +1 -0
  21. package/dist/src/cli/commands/components/list.js +32 -0
  22. package/dist/src/cli/commands/components/list.js.map +1 -0
  23. package/dist/src/cli/commands/components/list.mjs +29 -0
  24. package/dist/src/cli/commands/components/list.mjs.map +1 -0
  25. package/dist/src/cli/commands/configuration/dump.js +53 -0
  26. package/dist/src/cli/commands/configuration/dump.js.map +1 -0
  27. package/dist/src/cli/commands/configuration/dump.mjs +50 -0
  28. package/dist/src/cli/commands/configuration/dump.mjs.map +1 -0
  29. package/dist/src/cli/commands/configuration/restore.js +173 -0
  30. package/dist/src/cli/commands/configuration/restore.js.map +1 -0
  31. package/dist/src/cli/commands/configuration/restore.mjs +170 -0
  32. package/dist/src/cli/commands/configuration/restore.mjs.map +1 -0
  33. package/dist/src/cli/commands/console.js +31 -0
  34. package/dist/src/cli/commands/console.js.map +1 -0
  35. package/dist/src/cli/commands/console.mjs +28 -0
  36. package/dist/src/cli/commands/console.mjs.map +1 -0
  37. package/dist/src/cli/commands/content-types/list.js +32 -0
  38. package/dist/src/cli/commands/content-types/list.js.map +1 -0
  39. package/dist/src/cli/commands/content-types/list.mjs +29 -0
  40. package/dist/src/cli/commands/content-types/list.mjs.map +1 -0
  41. package/dist/src/cli/commands/controllers/list.js +32 -0
  42. package/dist/src/cli/commands/controllers/list.js.map +1 -0
  43. package/dist/src/cli/commands/controllers/list.mjs +29 -0
  44. package/dist/src/cli/commands/controllers/list.mjs.map +1 -0
  45. package/dist/src/cli/commands/develop.js +32 -0
  46. package/dist/src/cli/commands/develop.js.map +1 -0
  47. package/dist/src/cli/commands/develop.mjs +30 -0
  48. package/dist/src/cli/commands/develop.mjs.map +1 -0
  49. package/dist/src/cli/commands/export/action.js +126 -0
  50. package/dist/src/cli/commands/export/action.js.map +1 -0
  51. package/dist/src/cli/commands/export/action.mjs +124 -0
  52. package/dist/src/cli/commands/export/action.mjs.map +1 -0
  53. package/dist/src/cli/commands/export/command.js +15 -0
  54. package/dist/src/cli/commands/export/command.js.map +1 -0
  55. package/dist/src/cli/commands/export/command.mjs +13 -0
  56. package/dist/src/cli/commands/export/command.mjs.map +1 -0
  57. package/dist/src/cli/commands/generate.js +18 -0
  58. package/dist/src/cli/commands/generate.js.map +1 -0
  59. package/dist/src/cli/commands/generate.mjs +16 -0
  60. package/dist/src/cli/commands/generate.mjs.map +1 -0
  61. package/dist/src/cli/commands/hooks/list.js +32 -0
  62. package/dist/src/cli/commands/hooks/list.js.map +1 -0
  63. package/dist/src/cli/commands/hooks/list.mjs +29 -0
  64. package/dist/src/cli/commands/hooks/list.mjs.map +1 -0
  65. package/dist/src/cli/commands/import/action.js +124 -0
  66. package/dist/src/cli/commands/import/action.js.map +1 -0
  67. package/dist/src/cli/commands/import/action.mjs +122 -0
  68. package/dist/src/cli/commands/import/action.mjs.map +1 -0
  69. package/dist/src/cli/commands/import/command.js +59 -0
  70. package/dist/src/cli/commands/import/command.js.map +1 -0
  71. package/dist/src/cli/commands/import/command.mjs +57 -0
  72. package/dist/src/cli/commands/import/command.mjs.map +1 -0
  73. package/dist/src/cli/commands/index.js +64 -0
  74. package/dist/src/cli/commands/index.js.map +1 -0
  75. package/dist/src/cli/commands/index.mjs +62 -0
  76. package/dist/src/cli/commands/index.mjs.map +1 -0
  77. package/dist/src/cli/commands/middlewares/list.js +32 -0
  78. package/dist/src/cli/commands/middlewares/list.js.map +1 -0
  79. package/dist/src/cli/commands/middlewares/list.mjs +29 -0
  80. package/dist/src/cli/commands/middlewares/list.mjs.map +1 -0
  81. package/dist/src/cli/commands/policies/list.js +32 -0
  82. package/dist/src/cli/commands/policies/list.js.map +1 -0
  83. package/dist/src/cli/commands/policies/list.mjs +29 -0
  84. package/dist/src/cli/commands/policies/list.mjs.map +1 -0
  85. package/dist/src/cli/commands/report.js +39 -0
  86. package/dist/src/cli/commands/report.js.map +1 -0
  87. package/dist/src/cli/commands/report.mjs +37 -0
  88. package/dist/src/cli/commands/report.mjs.map +1 -0
  89. package/dist/src/cli/commands/routes/list.js +40 -0
  90. package/dist/src/cli/commands/routes/list.js.map +1 -0
  91. package/dist/src/cli/commands/routes/list.mjs +37 -0
  92. package/dist/src/cli/commands/routes/list.mjs.map +1 -0
  93. package/dist/src/cli/commands/services/list.js +32 -0
  94. package/dist/src/cli/commands/services/list.js.map +1 -0
  95. package/dist/src/cli/commands/services/list.mjs +29 -0
  96. package/dist/src/cli/commands/services/list.mjs.map +1 -0
  97. package/dist/src/cli/commands/start.js +28 -0
  98. package/dist/src/cli/commands/start.js.map +1 -0
  99. package/dist/src/cli/commands/start.mjs +26 -0
  100. package/dist/src/cli/commands/start.mjs.map +1 -0
  101. package/dist/src/cli/commands/telemetry/disable.js +72 -0
  102. package/dist/src/cli/commands/telemetry/disable.js.map +1 -0
  103. package/dist/src/cli/commands/telemetry/disable.mjs +69 -0
  104. package/dist/src/cli/commands/telemetry/disable.mjs.map +1 -0
  105. package/dist/src/cli/commands/telemetry/enable.js +88 -0
  106. package/dist/src/cli/commands/telemetry/enable.js.map +1 -0
  107. package/dist/src/cli/commands/telemetry/enable.mjs +85 -0
  108. package/dist/src/cli/commands/telemetry/enable.mjs.map +1 -0
  109. package/dist/src/cli/commands/templates/generate.js +15 -0
  110. package/dist/src/cli/commands/templates/generate.js.map +1 -0
  111. package/dist/src/cli/commands/templates/generate.mjs +13 -0
  112. package/dist/src/cli/commands/templates/generate.mjs.map +1 -0
  113. package/dist/src/cli/commands/transfer/action.js +141 -0
  114. package/dist/src/cli/commands/transfer/action.js.map +1 -0
  115. package/dist/src/cli/commands/transfer/action.mjs +139 -0
  116. package/dist/src/cli/commands/transfer/action.mjs.map +1 -0
  117. package/dist/src/cli/commands/transfer/command.js +61 -0
  118. package/dist/src/cli/commands/transfer/command.js.map +1 -0
  119. package/dist/src/cli/commands/transfer/command.mjs +59 -0
  120. package/dist/src/cli/commands/transfer/command.mjs.map +1 -0
  121. package/dist/src/cli/commands/ts/generate-types.js +40 -0
  122. package/dist/src/cli/commands/ts/generate-types.js.map +1 -0
  123. package/dist/src/cli/commands/ts/generate-types.mjs +37 -0
  124. package/dist/src/cli/commands/ts/generate-types.mjs.map +1 -0
  125. package/dist/src/cli/commands/version.js +17 -0
  126. package/dist/src/cli/commands/version.js.map +1 -0
  127. package/dist/src/cli/commands/version.mjs +15 -0
  128. package/dist/src/cli/commands/version.mjs.map +1 -0
  129. package/dist/src/cli/utils/commander.js +125 -0
  130. package/dist/src/cli/utils/commander.js.map +1 -0
  131. package/dist/src/cli/utils/commander.mjs +116 -0
  132. package/dist/src/cli/utils/commander.mjs.map +1 -0
  133. package/dist/src/cli/utils/data-transfer.js +378 -0
  134. package/dist/src/cli/utils/data-transfer.js.map +1 -0
  135. package/dist/src/cli/utils/data-transfer.mjs +359 -0
  136. package/dist/src/cli/utils/data-transfer.mjs.map +1 -0
  137. package/dist/src/cli/utils/helpers.js +114 -0
  138. package/dist/src/cli/utils/helpers.js.map +1 -0
  139. package/dist/src/cli/utils/helpers.mjs +107 -0
  140. package/dist/src/cli/utils/helpers.mjs.map +1 -0
  141. package/dist/src/cli/utils/logger.js +125 -0
  142. package/dist/src/cli/utils/logger.js.map +1 -0
  143. package/dist/src/cli/utils/logger.mjs +104 -0
  144. package/dist/src/cli/utils/logger.mjs.map +1 -0
  145. package/dist/src/cli/utils/telemetry.js +27 -0
  146. package/dist/src/cli/utils/telemetry.js.map +1 -0
  147. package/dist/src/cli/utils/telemetry.mjs +25 -0
  148. package/dist/src/cli/utils/telemetry.mjs.map +1 -0
  149. package/dist/src/cli/utils/tsconfig.js +25 -0
  150. package/dist/src/cli/utils/tsconfig.js.map +1 -0
  151. package/dist/src/cli/utils/tsconfig.mjs +23 -0
  152. package/dist/src/cli/utils/tsconfig.mjs.map +1 -0
  153. package/dist/src/node/build.js +90 -0
  154. package/dist/src/node/build.js.map +1 -0
  155. package/dist/src/node/build.mjs +69 -0
  156. package/dist/src/node/build.mjs.map +1 -0
  157. package/dist/src/node/core/admin-customisations.js +27 -0
  158. package/dist/src/node/core/admin-customisations.js.map +1 -0
  159. package/dist/src/node/core/admin-customisations.mjs +25 -0
  160. package/dist/src/node/core/admin-customisations.mjs.map +1 -0
  161. package/dist/{chunks/aliases-BkD9BImE.js → src/node/core/aliases.js} +3 -42
  162. package/dist/src/node/core/aliases.js.map +1 -0
  163. package/dist/{chunks/aliases-CZgVGGH9.mjs → src/node/core/aliases.mjs} +4 -41
  164. package/dist/src/node/core/aliases.mjs.map +1 -0
  165. package/dist/src/node/core/config.js +18 -0
  166. package/dist/src/node/core/config.js.map +1 -0
  167. package/dist/src/node/core/config.mjs +16 -0
  168. package/dist/src/node/core/config.mjs.map +1 -0
  169. package/dist/src/node/core/dependencies.js +186 -0
  170. package/dist/src/node/core/dependencies.js.map +1 -0
  171. package/dist/src/node/core/dependencies.mjs +183 -0
  172. package/dist/src/node/core/dependencies.mjs.map +1 -0
  173. package/dist/src/node/core/env.js +32 -0
  174. package/dist/src/node/core/env.js.map +1 -0
  175. package/dist/src/node/core/env.mjs +29 -0
  176. package/dist/src/node/core/env.mjs.map +1 -0
  177. package/dist/src/node/core/errors.js +51 -0
  178. package/dist/src/node/core/errors.js.map +1 -0
  179. package/dist/src/node/core/errors.mjs +48 -0
  180. package/dist/src/node/core/errors.mjs.map +1 -0
  181. package/dist/src/node/core/files.js +68 -0
  182. package/dist/src/node/core/files.js.map +1 -0
  183. package/dist/src/node/core/files.mjs +63 -0
  184. package/dist/src/node/core/files.mjs.map +1 -0
  185. package/dist/src/node/core/managers.js +27 -0
  186. package/dist/src/node/core/managers.js.map +1 -0
  187. package/dist/src/node/core/managers.mjs +25 -0
  188. package/dist/src/node/core/managers.mjs.map +1 -0
  189. package/dist/src/node/core/monorepo.js +30 -0
  190. package/dist/src/node/core/monorepo.js.map +1 -0
  191. package/dist/src/node/core/monorepo.mjs +28 -0
  192. package/dist/src/node/core/monorepo.mjs.map +1 -0
  193. package/dist/src/node/core/plugins.js +140 -0
  194. package/dist/src/node/core/plugins.js.map +1 -0
  195. package/dist/src/node/core/plugins.mjs +137 -0
  196. package/dist/src/node/core/plugins.mjs.map +1 -0
  197. package/dist/src/node/core/timer.js +33 -0
  198. package/dist/src/node/core/timer.js.map +1 -0
  199. package/dist/src/node/core/timer.mjs +30 -0
  200. package/dist/src/node/core/timer.mjs.map +1 -0
  201. package/dist/src/node/create-build-context.js +111 -0
  202. package/dist/src/node/create-build-context.js.map +1 -0
  203. package/dist/src/node/create-build-context.mjs +109 -0
  204. package/dist/src/node/create-build-context.mjs.map +1 -0
  205. package/dist/src/node/develop.js +312 -0
  206. package/dist/src/node/develop.js.map +1 -0
  207. package/dist/src/node/develop.mjs +291 -0
  208. package/dist/src/node/develop.mjs.map +1 -0
  209. package/dist/src/node/staticFiles.js +81 -0
  210. package/dist/src/node/staticFiles.js.map +1 -0
  211. package/dist/src/node/staticFiles.mjs +78 -0
  212. package/dist/src/node/staticFiles.mjs.map +1 -0
  213. package/dist/src/node/vite/build.js +14 -0
  214. package/dist/src/node/vite/build.js.map +1 -0
  215. package/dist/src/node/vite/build.mjs +12 -0
  216. package/dist/src/node/vite/build.mjs.map +1 -0
  217. package/dist/{chunks/config-D3Y5s3ui.js → src/node/vite/config.js} +12 -50
  218. package/dist/src/node/vite/config.js.map +1 -0
  219. package/dist/{chunks/config-BFUn1raM.mjs → src/node/vite/config.mjs} +6 -44
  220. package/dist/src/node/vite/config.mjs.map +1 -0
  221. package/dist/src/node/vite/plugins.js +46 -0
  222. package/dist/src/node/vite/plugins.js.map +1 -0
  223. package/dist/src/node/vite/plugins.mjs +44 -0
  224. package/dist/src/node/vite/plugins.mjs.map +1 -0
  225. package/dist/{chunks/watch-gkyBsmAJ.js → src/node/vite/watch.js} +2 -45
  226. package/dist/src/node/vite/watch.js.map +1 -0
  227. package/dist/{chunks/watch-DUnlAAiK.mjs → src/node/vite/watch.mjs} +2 -45
  228. package/dist/src/node/vite/watch.mjs.map +1 -0
  229. package/dist/src/node/webpack/build.js +37 -0
  230. package/dist/src/node/webpack/build.js.map +1 -0
  231. package/dist/src/node/webpack/build.mjs +35 -0
  232. package/dist/src/node/webpack/build.mjs.map +1 -0
  233. package/dist/{chunks/config-Bcu3_xSp.js → src/node/webpack/config.js} +10 -8
  234. package/dist/src/node/webpack/config.js.map +1 -0
  235. package/dist/{chunks/config-DKpJU9io.mjs → src/node/webpack/config.mjs} +5 -3
  236. package/dist/src/node/webpack/config.mjs.map +1 -0
  237. package/dist/{chunks/watch-CNfkm7Fm.js → src/node/webpack/watch.js} +2 -51
  238. package/dist/src/node/webpack/watch.js.map +1 -0
  239. package/dist/{chunks/watch-BEC39t49.mjs → src/node/webpack/watch.mjs} +2 -51
  240. package/dist/src/node/webpack/watch.mjs.map +1 -0
  241. package/package.json +22 -22
  242. package/dist/chunks/aliases-BkD9BImE.js.map +0 -1
  243. package/dist/chunks/aliases-CZgVGGH9.mjs.map +0 -1
  244. package/dist/chunks/build-B6f5SABm.js +0 -87
  245. package/dist/chunks/build-B6f5SABm.js.map +0 -1
  246. package/dist/chunks/build-BQc6C2UF.mjs +0 -85
  247. package/dist/chunks/build-BQc6C2UF.mjs.map +0 -1
  248. package/dist/chunks/build-C4qN5x5L.js +0 -59
  249. package/dist/chunks/build-C4qN5x5L.js.map +0 -1
  250. package/dist/chunks/build-D6MP0Rwu.mjs +0 -57
  251. package/dist/chunks/build-D6MP0Rwu.mjs.map +0 -1
  252. package/dist/chunks/config-BFUn1raM.mjs.map +0 -1
  253. package/dist/chunks/config-Bcu3_xSp.js.map +0 -1
  254. package/dist/chunks/config-D3Y5s3ui.js.map +0 -1
  255. package/dist/chunks/config-DKpJU9io.mjs.map +0 -1
  256. package/dist/chunks/index-DGhshfMs.mjs +0 -3160
  257. package/dist/chunks/index-DGhshfMs.mjs.map +0 -1
  258. package/dist/chunks/index-DW2NjgW9.js +0 -3185
  259. package/dist/chunks/index-DW2NjgW9.js.map +0 -1
  260. package/dist/chunks/watch-BEC39t49.mjs.map +0 -1
  261. package/dist/chunks/watch-CNfkm7Fm.js.map +0 -1
  262. package/dist/chunks/watch-DUnlAAiK.mjs.map +0 -1
  263. package/dist/chunks/watch-gkyBsmAJ.js.map +0 -1
@@ -0,0 +1,183 @@
1
+ import os from 'node:os';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import semver from 'semver';
5
+ import resolveFrom from 'resolve-from';
6
+ import execa from 'execa';
7
+ import readPkgUp from 'read-pkg-up';
8
+ import { getPackageManager } from './managers.mjs';
9
+
10
+ /**
11
+ * From V5 this will be imported from the package.json of `@strapi/strapi`.
12
+ */ const PEER_DEPS = {
13
+ react: '^18.0.0',
14
+ 'react-dom': '^18.0.0',
15
+ 'react-router-dom': '^6.0.0',
16
+ 'styled-components': '^6.0.0'
17
+ };
18
+ /**
19
+ * Checks the user's project that it has declared and installed the required dependencies
20
+ * needed by the Strapi admin project. Whilst generally speaking most modules will be
21
+ * declared by the actual packages there are some packages where you only really want one of
22
+ * and thus they are declared as peer dependencies – react / styled-components / etc.
23
+ *
24
+ * If these deps are not installed or declared, then we prompt the user to correct this. In
25
+ * V4 this is not a hard requirement, but in V5 it will be. Might as well get people started now.
26
+ */ const checkRequiredDependencies = async ({ cwd, logger })=>{
27
+ /**
28
+ * This enables us to use experimental deps for libraries like
29
+ * react or styled-components. This is useful for testing against.
30
+ */ if (process.env.USE_EXPERIMENTAL_DEPENDENCIES === 'true') {
31
+ logger.warn('You are using experimental dependencies that may not be compatible with Strapi.');
32
+ return {
33
+ didInstall: false
34
+ };
35
+ }
36
+ const pkg = await readPkgUp({
37
+ cwd
38
+ });
39
+ if (!pkg) {
40
+ throw new Error(`Could not find package.json at path: ${cwd}`);
41
+ }
42
+ logger.debug('Loaded package.json:', os.EOL, pkg.packageJson);
43
+ /**
44
+ * Run through each of the peer deps and figure out if they need to be
45
+ * installed or they need their version checked against.
46
+ */ const { install, review } = Object.entries(PEER_DEPS).reduce((acc, [name, version])=>{
47
+ if (!pkg.packageJson.dependencies) {
48
+ throw new Error(`Could not find dependencies in package.json at path: ${cwd}`);
49
+ }
50
+ const declaredVersion = pkg.packageJson.dependencies[name];
51
+ if (!declaredVersion) {
52
+ acc.install.push({
53
+ name,
54
+ wantedVersion: version
55
+ });
56
+ } else {
57
+ acc.review.push({
58
+ name,
59
+ wantedVersion: version,
60
+ declaredVersion
61
+ });
62
+ }
63
+ return acc;
64
+ }, {
65
+ install: [],
66
+ review: []
67
+ });
68
+ if (install.length > 0) {
69
+ logger.info('The Strapi admin needs to install the following dependencies:', os.EOL, install.map(({ name, wantedVersion })=>` - ${name}@${wantedVersion}`).join(os.EOL));
70
+ await installDependencies(install, {
71
+ cwd,
72
+ logger
73
+ });
74
+ const [file, ...args] = process.argv;
75
+ /**
76
+ * Re-run the same command after installation e.g. strapi build because the yarn.lock might
77
+ * not be the same and could break installations. It's not the best solution, but it works.
78
+ */ await execa(file, args, {
79
+ cwd,
80
+ stdio: 'inherit'
81
+ });
82
+ return {
83
+ didInstall: true
84
+ };
85
+ }
86
+ if (review.length) {
87
+ const errors = [];
88
+ for (const dep of review){
89
+ // The version specified in package.json could be incorrect, eg `foo`
90
+ let minDeclaredVersion = null;
91
+ try {
92
+ minDeclaredVersion = semver.minVersion(dep.declaredVersion);
93
+ } catch (err) {
94
+ // Intentional fall-through (variable will be left as null, throwing below)
95
+ }
96
+ if (!minDeclaredVersion) {
97
+ errors.push(`The declared dependency, ${dep.name} has an invalid version in package.json: ${dep.declaredVersion}`);
98
+ } else if (!semver.satisfies(minDeclaredVersion, dep.wantedVersion)) {
99
+ /**
100
+ * The delcared version should be semver compatible with our required version
101
+ * of the dependency. If it's not, we should advise the user to change it.
102
+ */ logger.warn([
103
+ `Declared version of ${dep.name} (${minDeclaredVersion}) is not compatible with the version required by Strapi (${dep.wantedVersion}).`,
104
+ 'You may experience issues, we recommend you change this.'
105
+ ].join(os.EOL));
106
+ }
107
+ const installedVersion = await getModuleVersion(dep.name, cwd);
108
+ if (!installedVersion) {
109
+ /**
110
+ * TODO: when we know the packageManager we can advise the actual install command.
111
+ */ errors.push(`The declared dependency, ${dep.name} is not installed. You should install before re-running this command`);
112
+ } else if (!semver.satisfies(installedVersion, dep.wantedVersion)) {
113
+ logger.warn([
114
+ `Declared version of ${dep.name} (${installedVersion}) is not compatible with the version required by Strapi (${dep.wantedVersion}).`,
115
+ 'You may experience issues, we recommend you change this.'
116
+ ].join(os.EOL));
117
+ }
118
+ }
119
+ if (errors.length > 0 && process.env.NODE_ENV === 'development') {
120
+ throw new Error(`${os.EOL}- ${errors.join(`${os.EOL}- `)}`);
121
+ }
122
+ }
123
+ return {
124
+ didInstall: false
125
+ };
126
+ };
127
+ const getModule = async (name, cwd)=>{
128
+ const modulePackagePath = resolveFrom.silent(cwd, path.join(name, 'package.json'));
129
+ if (!modulePackagePath) {
130
+ return null;
131
+ }
132
+ const file = await fs.readFile(modulePackagePath, 'utf8').then((res)=>JSON.parse(res));
133
+ return file;
134
+ };
135
+ const getModuleVersion = async (name, cwd)=>{
136
+ const pkg = await getModule(name, cwd);
137
+ return pkg?.version || null;
138
+ };
139
+ const installDependencies = async (install, { cwd, logger })=>{
140
+ const packageManager = getPackageManager();
141
+ if (!packageManager) {
142
+ logger.error('Could not find a supported package manager, please install the dependencies manually.');
143
+ process.exit(1);
144
+ }
145
+ const execOptions = {
146
+ encoding: 'utf8',
147
+ cwd,
148
+ stdio: 'inherit'
149
+ };
150
+ const packages = install.map(({ name, wantedVersion })=>`${name}@${wantedVersion}`);
151
+ let result;
152
+ if (packageManager === 'npm') {
153
+ const npmArgs = [
154
+ 'install',
155
+ '--legacy-peer-deps',
156
+ '--save',
157
+ ...packages
158
+ ];
159
+ logger.info(`Running 'npm ${npmArgs.join(' ')}'`);
160
+ result = await execa('npm', npmArgs, execOptions);
161
+ } else if (packageManager === 'yarn') {
162
+ const yarnArgs = [
163
+ 'add',
164
+ ...packages
165
+ ];
166
+ logger.info(`Running 'yarn ${yarnArgs.join(' ')}'`);
167
+ result = await execa('yarn', yarnArgs, execOptions);
168
+ } else if (packageManager === 'pnpm') {
169
+ const pnpmArgs = [
170
+ 'add',
171
+ '--save-prod',
172
+ ...packages
173
+ ];
174
+ logger.info(`Running 'pnpm ${pnpmArgs.join(' ')}'`);
175
+ result = await execa('pnpm', pnpmArgs, execOptions);
176
+ }
177
+ if (result?.exitCode || result?.failed) {
178
+ throw new Error('Package installation failed');
179
+ }
180
+ };
181
+
182
+ export { checkRequiredDependencies, getModule };
183
+ //# sourceMappingURL=dependencies.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.mjs","sources":["../../../../src/node/core/dependencies.ts"],"sourcesContent":["import os from 'node:os';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport semver, { SemVer } from 'semver';\nimport resolveFrom from 'resolve-from';\nimport execa, { CommonOptions, ExecaReturnValue } from 'execa';\nimport readPkgUp, { PackageJson } from 'read-pkg-up';\nimport type { BuildOptions } from '../build';\nimport { getPackageManager } from './managers';\n\n/**\n * From V5 this will be imported from the package.json of `@strapi/strapi`.\n */\nconst PEER_DEPS = {\n react: '^18.0.0',\n 'react-dom': '^18.0.0',\n 'react-router-dom': '^6.0.0',\n 'styled-components': '^6.0.0',\n};\n\ninterface CheckRequiredDependenciesResult {\n didInstall: boolean;\n}\n\ninterface DepToInstall {\n name: string;\n wantedVersion: string;\n declaredVersion?: never;\n}\n\n/**\n * Checks the user's project that it has declared and installed the required dependencies\n * needed by the Strapi admin project. Whilst generally speaking most modules will be\n * declared by the actual packages there are some packages where you only really want one of\n * and thus they are declared as peer dependencies – react / styled-components / etc.\n *\n * If these deps are not installed or declared, then we prompt the user to correct this. In\n * V4 this is not a hard requirement, but in V5 it will be. Might as well get people started now.\n */\nconst checkRequiredDependencies = async ({\n cwd,\n logger,\n}: Pick<BuildOptions, 'cwd' | 'logger'>): Promise<CheckRequiredDependenciesResult> => {\n /**\n * This enables us to use experimental deps for libraries like\n * react or styled-components. This is useful for testing against.\n */\n if (process.env.USE_EXPERIMENTAL_DEPENDENCIES === 'true') {\n logger.warn('You are using experimental dependencies that may not be compatible with Strapi.');\n return { didInstall: false };\n }\n\n const pkg = await readPkgUp({ cwd });\n\n if (!pkg) {\n throw new Error(`Could not find package.json at path: ${cwd}`);\n }\n\n logger.debug('Loaded package.json:', os.EOL, pkg.packageJson);\n\n interface DepToReview {\n name: string;\n wantedVersion: string;\n declaredVersion: string;\n }\n\n /**\n * Run through each of the peer deps and figure out if they need to be\n * installed or they need their version checked against.\n */\n const { install, review } = Object.entries(PEER_DEPS).reduce<{\n install: DepToInstall[];\n review: DepToReview[];\n }>(\n (acc, [name, version]) => {\n if (!pkg.packageJson.dependencies) {\n throw new Error(`Could not find dependencies in package.json at path: ${cwd}`);\n }\n\n const declaredVersion = pkg.packageJson.dependencies[name];\n\n if (!declaredVersion) {\n acc.install.push({\n name,\n wantedVersion: version,\n });\n } else {\n acc.review.push({\n name,\n wantedVersion: version,\n declaredVersion,\n });\n }\n\n return acc;\n },\n {\n install: [],\n review: [],\n }\n );\n\n if (install.length > 0) {\n logger.info(\n 'The Strapi admin needs to install the following dependencies:',\n os.EOL,\n install.map(({ name, wantedVersion }) => ` - ${name}@${wantedVersion}`).join(os.EOL)\n );\n\n await installDependencies(install, {\n cwd,\n logger,\n });\n\n const [file, ...args] = process.argv;\n\n /**\n * Re-run the same command after installation e.g. strapi build because the yarn.lock might\n * not be the same and could break installations. It's not the best solution, but it works.\n */\n await execa(file, args, { cwd, stdio: 'inherit' });\n return { didInstall: true };\n }\n\n if (review.length) {\n const errors: string[] = [];\n\n for (const dep of review) {\n // The version specified in package.json could be incorrect, eg `foo`\n let minDeclaredVersion: SemVer | null = null;\n try {\n minDeclaredVersion = semver.minVersion(dep.declaredVersion);\n } catch (err) {\n // Intentional fall-through (variable will be left as null, throwing below)\n }\n\n if (!minDeclaredVersion) {\n errors.push(\n `The declared dependency, ${dep.name} has an invalid version in package.json: ${dep.declaredVersion}`\n );\n } else if (!semver.satisfies(minDeclaredVersion, dep.wantedVersion)) {\n /**\n * The delcared version should be semver compatible with our required version\n * of the dependency. If it's not, we should advise the user to change it.\n */\n logger.warn(\n [\n `Declared version of ${dep.name} (${minDeclaredVersion}) is not compatible with the version required by Strapi (${dep.wantedVersion}).`,\n 'You may experience issues, we recommend you change this.',\n ].join(os.EOL)\n );\n }\n\n const installedVersion = await getModuleVersion(dep.name, cwd);\n\n if (!installedVersion) {\n /**\n * TODO: when we know the packageManager we can advise the actual install command.\n */\n errors.push(\n `The declared dependency, ${dep.name} is not installed. You should install before re-running this command`\n );\n } else if (!semver.satisfies(installedVersion, dep.wantedVersion)) {\n logger.warn(\n [\n `Declared version of ${dep.name} (${installedVersion}) is not compatible with the version required by Strapi (${dep.wantedVersion}).`,\n 'You may experience issues, we recommend you change this.',\n ].join(os.EOL)\n );\n }\n }\n\n if (errors.length > 0 && process.env.NODE_ENV === 'development') {\n throw new Error(`${os.EOL}- ${errors.join(`${os.EOL}- `)}`);\n }\n }\n\n return { didInstall: false };\n};\n\nconst getModule = async (name: string, cwd: string): Promise<PackageJson | null> => {\n const modulePackagePath = resolveFrom.silent(cwd, path.join(name, 'package.json'));\n if (!modulePackagePath) {\n return null;\n }\n const file = await fs.readFile(modulePackagePath, 'utf8').then((res) => JSON.parse(res));\n\n return file;\n};\n\nconst getModuleVersion = async (name: string, cwd: string): Promise<string | null> => {\n const pkg = await getModule(name, cwd);\n\n return pkg?.version || null;\n};\n\nconst installDependencies = async (\n install: DepToInstall[],\n { cwd, logger }: Pick<BuildOptions, 'cwd' | 'logger'>\n) => {\n const packageManager = getPackageManager();\n\n if (!packageManager) {\n logger.error(\n 'Could not find a supported package manager, please install the dependencies manually.'\n );\n process.exit(1);\n }\n\n const execOptions: CommonOptions<'utf8'> = {\n encoding: 'utf8',\n cwd,\n stdio: 'inherit',\n };\n\n const packages = install.map(({ name, wantedVersion }) => `${name}@${wantedVersion}`);\n\n let result: ExecaReturnValue<string> | undefined;\n\n if (packageManager === 'npm') {\n const npmArgs = ['install', '--legacy-peer-deps', '--save', ...packages];\n logger.info(`Running 'npm ${npmArgs.join(' ')}'`);\n result = await execa('npm', npmArgs, execOptions);\n } else if (packageManager === 'yarn') {\n const yarnArgs = ['add', ...packages];\n logger.info(`Running 'yarn ${yarnArgs.join(' ')}'`);\n result = await execa('yarn', yarnArgs, execOptions);\n } else if (packageManager === 'pnpm') {\n const pnpmArgs = ['add', '--save-prod', ...packages];\n logger.info(`Running 'pnpm ${pnpmArgs.join(' ')}'`);\n result = await execa('pnpm', pnpmArgs, execOptions);\n }\n\n if (result?.exitCode || result?.failed) {\n throw new Error('Package installation failed');\n }\n};\n\nexport { checkRequiredDependencies, getModule };\nexport type { CheckRequiredDependenciesResult, PackageJson };\n"],"names":["PEER_DEPS","react","checkRequiredDependencies","cwd","logger","process","env","USE_EXPERIMENTAL_DEPENDENCIES","warn","didInstall","pkg","readPkgUp","Error","debug","os","EOL","packageJson","install","review","Object","entries","reduce","acc","name","version","dependencies","declaredVersion","push","wantedVersion","length","info","map","join","installDependencies","file","args","argv","execa","stdio","errors","dep","minDeclaredVersion","semver","minVersion","err","satisfies","installedVersion","getModuleVersion","NODE_ENV","getModule","modulePackagePath","resolveFrom","silent","path","fs","readFile","then","res","JSON","parse","packageManager","getPackageManager","error","exit","execOptions","encoding","packages","result","npmArgs","yarnArgs","pnpmArgs","exitCode","failed"],"mappings":";;;;;;;;;AAUA;;AAEC,IACD,MAAMA,SAAY,GAAA;IAChBC,KAAO,EAAA,SAAA;IACP,WAAa,EAAA,SAAA;IACb,kBAAoB,EAAA,QAAA;IACpB,mBAAqB,EAAA;AACvB,CAAA;AAYA;;;;;;;;AAQC,UACKC,yBAA4B,GAAA,OAAO,EACvCC,GAAG,EACHC,MAAM,EAC+B,GAAA;AACrC;;;AAGC,MACD,IAAIC,OAAQC,CAAAA,GAAG,CAACC,6BAA6B,KAAK,MAAQ,EAAA;AACxDH,QAAAA,MAAAA,CAAOI,IAAI,CAAC,iFAAA,CAAA;QACZ,OAAO;YAAEC,UAAY,EAAA;AAAM,SAAA;AAC7B;IAEA,MAAMC,GAAAA,GAAM,MAAMC,SAAU,CAAA;AAAER,QAAAA;AAAI,KAAA,CAAA;AAElC,IAAA,IAAI,CAACO,GAAK,EAAA;AACR,QAAA,MAAM,IAAIE,KAAM,CAAA,CAAC,qCAAqC,EAAET,IAAI,CAAC,CAAA;AAC/D;AAEAC,IAAAA,MAAAA,CAAOS,KAAK,CAAC,sBAAA,EAAwBC,GAAGC,GAAG,EAAEL,IAAIM,WAAW,CAAA;AAQ5D;;;AAGC,MACD,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGC,MAAAA,CAAOC,OAAO,CAACpB,WAAWqB,MAAM,CAI1D,CAACC,GAAK,EAAA,CAACC,MAAMC,OAAQ,CAAA,GAAA;AACnB,QAAA,IAAI,CAACd,GAAAA,CAAIM,WAA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;QAClDmC,MAAS,GAAA,MAAM9B,KAAM,CAAA,MAAA,EAAQgC,QAAUL,EAAAA,WAAAA,CAAAA;KAClC,MAAA,IAAIJ,mBAAmB,MAAQ,EAAA;AACpC,QAAA,MAAMU,QAAW,GAAA;AAAC,YAAA,KAAA;AAAO,YAAA,aAAA;AAAkBJ,YAAAA,GAAAA;AAAS,SAAA;QACpD9D,MAAO0B,CAAAA,IAAI,CAAC,CAAC,cAAc,EAAEwC,SAAStC,IAAI,CAAC,GAAK,CAAA,CAAA,CAAC,CAAC,CAAA;QAClDmC,MAAS,GAAA,MAAM9B,KAAM,CAAA,MAAA,EAAQiC,QAAUN,EAAAA,WAAAA,CAAAA;AACzC;IAEA,IAAIG,MAAAA,EAAQI,QAAYJ,IAAAA,MAAAA,EAAQK,MAAQ,EAAA;AACtC,QAAA,MAAM,IAAI5D,KAAM,CAAA,6BAAA,CAAA;AAClB;AACF,CAAA;;;;"}
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var dotenv = require('dotenv');
5
+ var files = require('./files.js');
6
+
7
+ /**
8
+ * @internal
9
+ *
10
+ * @description Load the .env file if it exists
11
+ */ const loadEnv = async (cwd)=>{
12
+ const pathToEnv = path.resolve(cwd, '.env');
13
+ if (await files.pathExists(pathToEnv)) {
14
+ dotenv.config({
15
+ path: pathToEnv
16
+ });
17
+ }
18
+ };
19
+ /**
20
+ * @internal
21
+ *
22
+ * @description Get all the environment variables that start with `STRAPI_ADMIN_`
23
+ */ const getStrapiAdminEnvVars = (defaultEnv)=>{
24
+ return Object.keys(process.env).filter((key)=>key.toUpperCase().startsWith('STRAPI_ADMIN_')).reduce((acc, key)=>{
25
+ acc[key] = process.env[key];
26
+ return acc;
27
+ }, defaultEnv);
28
+ };
29
+
30
+ exports.getStrapiAdminEnvVars = getStrapiAdminEnvVars;
31
+ exports.loadEnv = loadEnv;
32
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sources":["../../../../src/node/core/env.ts"],"sourcesContent":["import path from 'node:path';\nimport dotenv from 'dotenv';\nimport { pathExists } from './files';\n\n/**\n * This is the base of _any_ env set for a strapi project,\n * to build a strapi admin panel we require these env variables.\n */\ninterface DefaultEnv {\n ADMIN_PATH: string;\n STRAPI_ADMIN_BACKEND_URL: string;\n STRAPI_TELEMETRY_DISABLED: string;\n}\n\n/**\n * @internal\n *\n * @description Load the .env file if it exists\n */\nconst loadEnv = async (cwd: string) => {\n const pathToEnv = path.resolve(cwd, '.env');\n\n if (await pathExists(pathToEnv)) {\n dotenv.config({ path: pathToEnv });\n }\n};\n\n/**\n * @internal\n *\n * @description Get all the environment variables that start with `STRAPI_ADMIN_`\n */\nconst getStrapiAdminEnvVars = (defaultEnv: DefaultEnv): Record<string, string> => {\n return Object.keys(process.env)\n .filter((key) => key.toUpperCase().startsWith('STRAPI_ADMIN_'))\n .reduce(\n (acc, key) => {\n acc[key] = process.env[key] as string;\n\n return acc;\n },\n defaultEnv as unknown as Record<string, string>\n );\n};\n\nexport { getStrapiAdminEnvVars, loadEnv };\n"],"names":["loadEnv","cwd","pathToEnv","path","resolve","pathExists","dotenv","config","getStrapiAdminEnvVars","defaultEnv","Object","keys","process","env","filter","key","toUpperCase","startsWith","reduce","acc"],"mappings":";;;;;;AAcA;;;;IAKA,MAAMA,UAAU,OAAOC,GAAAA,GAAAA;AACrB,IAAA,MAAMC,SAAYC,GAAAA,IAAAA,CAAKC,OAAO,CAACH,GAAK,EAAA,MAAA,CAAA;IAEpC,IAAI,MAAMI,iBAAWH,SAAY,CAAA,EAAA;AAC/BI,QAAAA,MAAAA,CAAOC,MAAM,CAAC;YAAEJ,IAAMD,EAAAA;AAAU,SAAA,CAAA;AAClC;AACF;AAEA;;;;IAKA,MAAMM,wBAAwB,CAACC,UAAAA,GAAAA;AAC7B,IAAA,OAAOC,OAAOC,IAAI,CAACC,QAAQC,GAAG,CAAA,CAC3BC,MAAM,CAAC,CAACC,MAAQA,GAAIC,CAAAA,WAAW,GAAGC,UAAU,CAAC,kBAC7CC,MAAM,CACL,CAACC,GAAKJ,EAAAA,GAAAA,GAAAA;AACJI,QAAAA,GAAG,CAACJ,GAAI,CAAA,GAAGH,OAAQC,CAAAA,GAAG,CAACE,GAAI,CAAA;QAE3B,OAAOI,GAAAA;KAETV,EAAAA,UAAAA,CAAAA;AAEN;;;;;"}
@@ -0,0 +1,29 @@
1
+ import path from 'node:path';
2
+ import dotenv from 'dotenv';
3
+ import { pathExists } from './files.mjs';
4
+
5
+ /**
6
+ * @internal
7
+ *
8
+ * @description Load the .env file if it exists
9
+ */ const loadEnv = async (cwd)=>{
10
+ const pathToEnv = path.resolve(cwd, '.env');
11
+ if (await pathExists(pathToEnv)) {
12
+ dotenv.config({
13
+ path: pathToEnv
14
+ });
15
+ }
16
+ };
17
+ /**
18
+ * @internal
19
+ *
20
+ * @description Get all the environment variables that start with `STRAPI_ADMIN_`
21
+ */ const getStrapiAdminEnvVars = (defaultEnv)=>{
22
+ return Object.keys(process.env).filter((key)=>key.toUpperCase().startsWith('STRAPI_ADMIN_')).reduce((acc, key)=>{
23
+ acc[key] = process.env[key];
24
+ return acc;
25
+ }, defaultEnv);
26
+ };
27
+
28
+ export { getStrapiAdminEnvVars, loadEnv };
29
+ //# sourceMappingURL=env.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.mjs","sources":["../../../../src/node/core/env.ts"],"sourcesContent":["import path from 'node:path';\nimport dotenv from 'dotenv';\nimport { pathExists } from './files';\n\n/**\n * This is the base of _any_ env set for a strapi project,\n * to build a strapi admin panel we require these env variables.\n */\ninterface DefaultEnv {\n ADMIN_PATH: string;\n STRAPI_ADMIN_BACKEND_URL: string;\n STRAPI_TELEMETRY_DISABLED: string;\n}\n\n/**\n * @internal\n *\n * @description Load the .env file if it exists\n */\nconst loadEnv = async (cwd: string) => {\n const pathToEnv = path.resolve(cwd, '.env');\n\n if (await pathExists(pathToEnv)) {\n dotenv.config({ path: pathToEnv });\n }\n};\n\n/**\n * @internal\n *\n * @description Get all the environment variables that start with `STRAPI_ADMIN_`\n */\nconst getStrapiAdminEnvVars = (defaultEnv: DefaultEnv): Record<string, string> => {\n return Object.keys(process.env)\n .filter((key) => key.toUpperCase().startsWith('STRAPI_ADMIN_'))\n .reduce(\n (acc, key) => {\n acc[key] = process.env[key] as string;\n\n return acc;\n },\n defaultEnv as unknown as Record<string, string>\n );\n};\n\nexport { getStrapiAdminEnvVars, loadEnv };\n"],"names":["loadEnv","cwd","pathToEnv","path","resolve","pathExists","dotenv","config","getStrapiAdminEnvVars","defaultEnv","Object","keys","process","env","filter","key","toUpperCase","startsWith","reduce","acc"],"mappings":";;;;AAcA;;;;IAKA,MAAMA,UAAU,OAAOC,GAAAA,GAAAA;AACrB,IAAA,MAAMC,SAAYC,GAAAA,IAAAA,CAAKC,OAAO,CAACH,GAAK,EAAA,MAAA,CAAA;IAEpC,IAAI,MAAMI,WAAWH,SAAY,CAAA,EAAA;AAC/BI,QAAAA,MAAAA,CAAOC,MAAM,CAAC;YAAEJ,IAAMD,EAAAA;AAAU,SAAA,CAAA;AAClC;AACF;AAEA;;;;IAKA,MAAMM,wBAAwB,CAACC,UAAAA,GAAAA;AAC7B,IAAA,OAAOC,OAAOC,IAAI,CAACC,QAAQC,GAAG,CAAA,CAC3BC,MAAM,CAAC,CAACC,MAAQA,GAAIC,CAAAA,WAAW,GAAGC,UAAU,CAAC,kBAC7CC,MAAM,CACL,CAACC,GAAKJ,EAAAA,GAAAA,GAAAA;AACJI,QAAAA,GAAG,CAACJ,GAAI,CAAA,GAAGH,OAAQC,CAAAA,GAAG,CAACE,GAAI,CAAA;QAE3B,OAAOI,GAAAA;KAETV,EAAAA,UAAAA,CAAAA;AAEN;;;;"}
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ var boxen = require('boxen');
4
+ var chalk = require('chalk');
5
+ var os = require('node:os');
6
+ var utils = require('@strapi/utils');
7
+
8
+ const isError = (err)=>err instanceof Error;
9
+ /**
10
+ * @description Handle unexpected errors. No, but really, your CLI should anticipate error cases.
11
+ * If a user hits an error we don't expect, then we need to flag to them that this is not normal
12
+ * and they should use the `--debug` flag to get more information (assuming you've implemented this
13
+ * in your action).
14
+ */ const handleUnexpectedError = (err)=>{
15
+ console.error(chalk.red(`[ERROR] `, 'There seems to be an unexpected error, try again with --debug for more information', os.EOL));
16
+ if (isError(err) && err.stack) {
17
+ // eslint-disable-next-line no-console
18
+ console.log(chalk.red(boxen(err.stack, {
19
+ padding: 1,
20
+ align: 'left'
21
+ })));
22
+ }
23
+ if (err instanceof utils.errors.YupValidationError) {
24
+ const message = [];
25
+ const size = err.details.errors.length;
26
+ for (const error of err.details.errors){
27
+ // No need to repeat the error message as it's the same as the err.message
28
+ if (size === 1) {
29
+ message.push(` value: ${error.value}`);
30
+ continue;
31
+ }
32
+ message.push([
33
+ ` [${error.name}]`,
34
+ ` message: ${error.message}`,
35
+ ` value: ${error.value}`
36
+ ].join('\n'));
37
+ }
38
+ console.log(chalk.red(boxen([
39
+ 'Details:',
40
+ message.join('\n\n')
41
+ ].join('\n'), {
42
+ padding: 1,
43
+ align: 'left'
44
+ })));
45
+ }
46
+ process.exit(1);
47
+ };
48
+
49
+ exports.handleUnexpectedError = handleUnexpectedError;
50
+ exports.isError = isError;
51
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sources":["../../../../src/node/core/errors.ts"],"sourcesContent":["import boxen from 'boxen';\nimport chalk from 'chalk';\nimport os from 'node:os';\nimport { errors } from '@strapi/utils';\n\nconst isError = (err: unknown): err is Error => err instanceof Error;\n\n/**\n * @description Handle unexpected errors. No, but really, your CLI should anticipate error cases.\n * If a user hits an error we don't expect, then we need to flag to them that this is not normal\n * and they should use the `--debug` flag to get more information (assuming you've implemented this\n * in your action).\n */\nconst handleUnexpectedError = (err: unknown) => {\n console.error(\n chalk.red(\n `[ERROR] `,\n 'There seems to be an unexpected error, try again with --debug for more information',\n os.EOL\n )\n );\n\n if (isError(err) && err.stack) {\n // eslint-disable-next-line no-console\n console.log(\n chalk.red(\n boxen(err.stack, {\n padding: 1,\n align: 'left',\n })\n )\n );\n }\n\n if (err instanceof errors.YupValidationError) {\n const message = [];\n const size = err.details.errors.length;\n\n for (const error of err.details.errors) {\n // No need to repeat the error message as it's the same as the err.message\n if (size === 1) {\n message.push(` value: ${error.value}`);\n continue;\n }\n\n message.push(\n [` [${error.name}]`, ` message: ${error.message}`, ` value: ${error.value}`].join(\n '\\n'\n )\n );\n }\n\n console.log(\n chalk.red(\n boxen(['Details:', message.join('\\n\\n')].join('\\n'), {\n padding: 1,\n align: 'left',\n })\n )\n );\n }\n\n process.exit(1);\n};\n\nexport { handleUnexpectedError, isError };\n"],"names":["isError","err","Error","handleUnexpectedError","console","error","chalk","red","os","EOL","stack","log","boxen","padding","align","errors","YupValidationError","message","size","details","length","push","value","name","join","process","exit"],"mappings":";;;;;;;AAKMA,MAAAA,OAAAA,GAAU,CAACC,GAAAA,GAA+BA,GAAeC,YAAAA;AAE/D;;;;;IAMA,MAAMC,wBAAwB,CAACF,GAAAA,GAAAA;IAC7BG,OAAQC,CAAAA,KAAK,CACXC,KAAAA,CAAMC,GAAG,CACP,CAAC,QAAQ,CAAC,EACV,oFACAC,EAAAA,EAAAA,CAAGC,GAAG,CAAA,CAAA;AAIV,IAAA,IAAIT,OAAQC,CAAAA,GAAAA,CAAAA,IAAQA,GAAIS,CAAAA,KAAK,EAAE;;QAE7BN,OAAQO,CAAAA,GAAG,CACTL,KAAMC,CAAAA,GAAG,CACPK,KAAMX,CAAAA,GAAAA,CAAIS,KAAK,EAAE;YACfG,OAAS,EAAA,CAAA;YACTC,KAAO,EAAA;AACT,SAAA,CAAA,CAAA,CAAA;AAGN;IAEA,IAAIb,GAAAA,YAAec,YAAOC,CAAAA,kBAAkB,EAAE;AAC5C,QAAA,MAAMC,UAAU,EAAE;AAClB,QAAA,MAAMC,OAAOjB,GAAIkB,CAAAA,OAAO,CAACJ,MAAM,CAACK,MAAM;AAEtC,QAAA,KAAK,MAAMf,KAASJ,IAAAA,GAAAA,CAAIkB,OAAO,CAACJ,MAAM,CAAE;;AAEtC,YAAA,IAAIG,SAAS,CAAG,EAAA;gBACdD,OAAQI,CAAAA,IAAI,CAAC,CAAC,SAAS,EAAEhB,KAAMiB,CAAAA,KAAK,CAAC,CAAC,CAAA;AACtC,gBAAA;AACF;AAEAL,YAAAA,OAAAA,CAAQI,IAAI,CACV;AAAC,gBAAA,CAAC,GAAG,EAAEhB,KAAAA,CAAMkB,IAAI,CAAC,CAAC,CAAC;AAAE,gBAAA,CAAC,aAAa,EAAElB,KAAMY,CAAAA,OAAO,CAAC,CAAC;AAAE,gBAAA,CAAC,aAAa,EAAEZ,KAAMiB,CAAAA,KAAK,CAAC;AAAE,aAAA,CAACE,IAAI,CACxF,IAAA,CAAA,CAAA;AAGN;AAEApB,QAAAA,OAAAA,CAAQO,GAAG,CACTL,KAAMC,CAAAA,GAAG,CACPK,KAAM,CAAA;AAAC,YAAA,UAAA;AAAYK,YAAAA,OAAAA,CAAQO,IAAI,CAAC,MAAA;SAAQ,CAACA,IAAI,CAAC,IAAO,CAAA,EAAA;YACnDX,OAAS,EAAA,CAAA;YACTC,KAAO,EAAA;AACT,SAAA,CAAA,CAAA,CAAA;AAGN;AAEAW,IAAAA,OAAAA,CAAQC,IAAI,CAAC,CAAA,CAAA;AACf;;;;;"}
@@ -0,0 +1,48 @@
1
+ import boxen from 'boxen';
2
+ import chalk from 'chalk';
3
+ import os from 'node:os';
4
+ import { errors } from '@strapi/utils';
5
+
6
+ const isError = (err)=>err instanceof Error;
7
+ /**
8
+ * @description Handle unexpected errors. No, but really, your CLI should anticipate error cases.
9
+ * If a user hits an error we don't expect, then we need to flag to them that this is not normal
10
+ * and they should use the `--debug` flag to get more information (assuming you've implemented this
11
+ * in your action).
12
+ */ const handleUnexpectedError = (err)=>{
13
+ console.error(chalk.red(`[ERROR] `, 'There seems to be an unexpected error, try again with --debug for more information', os.EOL));
14
+ if (isError(err) && err.stack) {
15
+ // eslint-disable-next-line no-console
16
+ console.log(chalk.red(boxen(err.stack, {
17
+ padding: 1,
18
+ align: 'left'
19
+ })));
20
+ }
21
+ if (err instanceof errors.YupValidationError) {
22
+ const message = [];
23
+ const size = err.details.errors.length;
24
+ for (const error of err.details.errors){
25
+ // No need to repeat the error message as it's the same as the err.message
26
+ if (size === 1) {
27
+ message.push(` value: ${error.value}`);
28
+ continue;
29
+ }
30
+ message.push([
31
+ ` [${error.name}]`,
32
+ ` message: ${error.message}`,
33
+ ` value: ${error.value}`
34
+ ].join('\n'));
35
+ }
36
+ console.log(chalk.red(boxen([
37
+ 'Details:',
38
+ message.join('\n\n')
39
+ ].join('\n'), {
40
+ padding: 1,
41
+ align: 'left'
42
+ })));
43
+ }
44
+ process.exit(1);
45
+ };
46
+
47
+ export { handleUnexpectedError, isError };
48
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","sources":["../../../../src/node/core/errors.ts"],"sourcesContent":["import boxen from 'boxen';\nimport chalk from 'chalk';\nimport os from 'node:os';\nimport { errors } from '@strapi/utils';\n\nconst isError = (err: unknown): err is Error => err instanceof Error;\n\n/**\n * @description Handle unexpected errors. No, but really, your CLI should anticipate error cases.\n * If a user hits an error we don't expect, then we need to flag to them that this is not normal\n * and they should use the `--debug` flag to get more information (assuming you've implemented this\n * in your action).\n */\nconst handleUnexpectedError = (err: unknown) => {\n console.error(\n chalk.red(\n `[ERROR] `,\n 'There seems to be an unexpected error, try again with --debug for more information',\n os.EOL\n )\n );\n\n if (isError(err) && err.stack) {\n // eslint-disable-next-line no-console\n console.log(\n chalk.red(\n boxen(err.stack, {\n padding: 1,\n align: 'left',\n })\n )\n );\n }\n\n if (err instanceof errors.YupValidationError) {\n const message = [];\n const size = err.details.errors.length;\n\n for (const error of err.details.errors) {\n // No need to repeat the error message as it's the same as the err.message\n if (size === 1) {\n message.push(` value: ${error.value}`);\n continue;\n }\n\n message.push(\n [` [${error.name}]`, ` message: ${error.message}`, ` value: ${error.value}`].join(\n '\\n'\n )\n );\n }\n\n console.log(\n chalk.red(\n boxen(['Details:', message.join('\\n\\n')].join('\\n'), {\n padding: 1,\n align: 'left',\n })\n )\n );\n }\n\n process.exit(1);\n};\n\nexport { handleUnexpectedError, isError };\n"],"names":["isError","err","Error","handleUnexpectedError","console","error","chalk","red","os","EOL","stack","log","boxen","padding","align","errors","YupValidationError","message","size","details","length","push","value","name","join","process","exit"],"mappings":";;;;;AAKMA,MAAAA,OAAAA,GAAU,CAACC,GAAAA,GAA+BA,GAAeC,YAAAA;AAE/D;;;;;IAMA,MAAMC,wBAAwB,CAACF,GAAAA,GAAAA;IAC7BG,OAAQC,CAAAA,KAAK,CACXC,KAAAA,CAAMC,GAAG,CACP,CAAC,QAAQ,CAAC,EACV,oFACAC,EAAAA,EAAAA,CAAGC,GAAG,CAAA,CAAA;AAIV,IAAA,IAAIT,OAAQC,CAAAA,GAAAA,CAAAA,IAAQA,GAAIS,CAAAA,KAAK,EAAE;;QAE7BN,OAAQO,CAAAA,GAAG,CACTL,KAAMC,CAAAA,GAAG,CACPK,KAAMX,CAAAA,GAAAA,CAAIS,KAAK,EAAE;YACfG,OAAS,EAAA,CAAA;YACTC,KAAO,EAAA;AACT,SAAA,CAAA,CAAA,CAAA;AAGN;IAEA,IAAIb,GAAAA,YAAec,MAAOC,CAAAA,kBAAkB,EAAE;AAC5C,QAAA,MAAMC,UAAU,EAAE;AAClB,QAAA,MAAMC,OAAOjB,GAAIkB,CAAAA,OAAO,CAACJ,MAAM,CAACK,MAAM;AAEtC,QAAA,KAAK,MAAMf,KAASJ,IAAAA,GAAAA,CAAIkB,OAAO,CAACJ,MAAM,CAAE;;AAEtC,YAAA,IAAIG,SAAS,CAAG,EAAA;gBACdD,OAAQI,CAAAA,IAAI,CAAC,CAAC,SAAS,EAAEhB,KAAMiB,CAAAA,KAAK,CAAC,CAAC,CAAA;AACtC,gBAAA;AACF;AAEAL,YAAAA,OAAAA,CAAQI,IAAI,CACV;AAAC,gBAAA,CAAC,GAAG,EAAEhB,KAAAA,CAAMkB,IAAI,CAAC,CAAC,CAAC;AAAE,gBAAA,CAAC,aAAa,EAAElB,KAAMY,CAAAA,OAAO,CAAC,CAAC;AAAE,gBAAA,CAAC,aAAa,EAAEZ,KAAMiB,CAAAA,KAAK,CAAC;AAAE,aAAA,CAACE,IAAI,CACxF,IAAA,CAAA,CAAA;AAGN;AAEApB,QAAAA,OAAAA,CAAQO,GAAG,CACTL,KAAMC,CAAAA,GAAG,CACPK,KAAM,CAAA;AAAC,YAAA,UAAA;AAAYK,YAAAA,OAAAA,CAAQO,IAAI,CAAC,MAAA;SAAQ,CAACA,IAAI,CAAC,IAAO,CAAA,EAAA;YACnDX,OAAS,EAAA,CAAA;YACTC,KAAO,EAAA;AACT,SAAA,CAAA,CAAA,CAAA;AAGN;AAEAW,IAAAA,OAAAA,CAAQC,IAAI,CAAC,CAAA,CAAA;AACf;;;;"}
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var fs = require('node:fs/promises');
5
+ var node = require('esbuild-register/dist/node');
6
+
7
+ /**
8
+ * @internal
9
+ */ const pathExists = async (path)=>{
10
+ try {
11
+ await fs.access(path);
12
+ return true;
13
+ } catch (error) {
14
+ return false;
15
+ }
16
+ };
17
+ /**
18
+ * @internal
19
+ */ const loadFile = async (path)=>{
20
+ if (await pathExists(path)) {
21
+ const esbuildOptions = {
22
+ extensions: [
23
+ '.js',
24
+ '.mjs',
25
+ '.ts'
26
+ ]
27
+ };
28
+ const { unregister } = node.register(esbuildOptions);
29
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
30
+ const mod = require(path);
31
+ unregister();
32
+ /**
33
+ * handles esm or cjs exporting.
34
+ */ const file = mod?.default || mod || undefined;
35
+ return file;
36
+ }
37
+ return undefined;
38
+ };
39
+ /**
40
+ * @internal
41
+ *
42
+ * @description Converts a system path to a module path mainly for `Windows` systems.
43
+ * where the path separator is `\` instead of `/`, on linux systems the path separator
44
+ * is identical to the module path separator.
45
+ */ const convertSystemPathToModulePath = (sysPath)=>{
46
+ if (process.platform === 'win32') {
47
+ return sysPath.split(path.sep).join(path.posix.sep);
48
+ }
49
+ return sysPath;
50
+ };
51
+ /**
52
+ * @internal
53
+ *
54
+ * @description Converts a module path to a system path, again largely used for Windows systems.
55
+ * The original use case was plugins where the resolve path was in module format but we want to
56
+ * have it relative to the runtime directory.
57
+ */ const convertModulePathToSystemPath = (modulePath)=>{
58
+ if (process.platform === 'win32') {
59
+ return modulePath.split(path.posix.sep).join(path.sep);
60
+ }
61
+ return modulePath;
62
+ };
63
+
64
+ exports.convertModulePathToSystemPath = convertModulePathToSystemPath;
65
+ exports.convertSystemPathToModulePath = convertSystemPathToModulePath;
66
+ exports.loadFile = loadFile;
67
+ exports.pathExists = pathExists;
68
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sources":["../../../../src/node/core/files.ts"],"sourcesContent":["import path from 'node:path';\nimport { access } from 'node:fs/promises';\nimport { register } from 'esbuild-register/dist/node';\n\n/**\n * @internal\n */\nconst pathExists = async (path: string) => {\n try {\n await access(path);\n return true;\n } catch (error) {\n return false;\n }\n};\n\n/**\n * @internal\n */\nconst loadFile = async (path: string): Promise<undefined | any> => {\n if (await pathExists(path)) {\n const esbuildOptions: Parameters<typeof register>[0] = {\n extensions: ['.js', '.mjs', '.ts'],\n };\n\n const { unregister } = register(esbuildOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const mod = require(path);\n\n unregister();\n\n /**\n * handles esm or cjs exporting.\n */\n const file = mod?.default || mod || undefined;\n\n return file;\n }\n\n return undefined;\n};\n\n/**\n * @internal\n *\n * @description Converts a system path to a module path mainly for `Windows` systems.\n * where the path separator is `\\` instead of `/`, on linux systems the path separator\n * is identical to the module path separator.\n */\nconst convertSystemPathToModulePath = (sysPath: string) => {\n if (process.platform === 'win32') {\n return sysPath.split(path.sep).join(path.posix.sep);\n }\n\n return sysPath;\n};\n\n/**\n * @internal\n *\n * @description Converts a module path to a system path, again largely used for Windows systems.\n * The original use case was plugins where the resolve path was in module format but we want to\n * have it relative to the runtime directory.\n */\nconst convertModulePathToSystemPath = (modulePath: string) => {\n if (process.platform === 'win32') {\n return modulePath.split(path.posix.sep).join(path.sep);\n }\n\n return modulePath;\n};\n\nexport { pathExists, loadFile, convertSystemPathToModulePath, convertModulePathToSystemPath };\n"],"names":["pathExists","path","access","error","loadFile","esbuildOptions","extensions","unregister","register","mod","require","file","default","undefined","convertSystemPathToModulePath","sysPath","process","platform","split","sep","join","posix","convertModulePathToSystemPath","modulePath"],"mappings":";;;;;;AAIA;;IAGA,MAAMA,aAAa,OAAOC,IAAAA,GAAAA;IACxB,IAAI;AACF,QAAA,MAAMC,SAAOD,CAAAA,IAAAA,CAAAA;QACb,OAAO,IAAA;AACT,KAAA,CAAE,OAAOE,KAAO,EAAA;QACd,OAAO,KAAA;AACT;AACF;AAEA;;IAGA,MAAMC,WAAW,OAAOH,IAAAA,GAAAA;IACtB,IAAI,MAAMD,WAAWC,IAAO,CAAA,EAAA;AAC1B,QAAA,MAAMI,cAAiD,GAAA;YACrDC,UAAY,EAAA;AAAC,gBAAA,KAAA;AAAO,gBAAA,MAAA;AAAQ,gBAAA;AAAM;AACpC,SAAA;AAEA,QAAA,MAAM,EAAEC,UAAU,EAAE,GAAGC,aAASH,CAAAA,cAAAA,CAAAA;;AAGhC,QAAA,MAAMI,MAAMC,OAAQT,CAAAA,IAAAA,CAAAA;AAEpBM,QAAAA,UAAAA,EAAAA;AAEA;;AAEC,QACD,MAAMI,IAAAA,GAAOF,GAAKG,EAAAA,OAAAA,IAAWH,GAAOI,IAAAA,SAAAA;QAEpC,OAAOF,IAAAA;AACT;IAEA,OAAOE,SAAAA;AACT;AAEA;;;;;;IAOA,MAAMC,gCAAgC,CAACC,OAAAA,GAAAA;IACrC,IAAIC,OAAAA,CAAQC,QAAQ,KAAK,OAAS,EAAA;QAChC,OAAOF,OAAAA,CAAQG,KAAK,CAACjB,IAAKkB,CAAAA,GAAG,CAAEC,CAAAA,IAAI,CAACnB,IAAAA,CAAKoB,KAAK,CAACF,GAAG,CAAA;AACpD;IAEA,OAAOJ,OAAAA;AACT;AAEA;;;;;;IAOA,MAAMO,gCAAgC,CAACC,UAAAA,GAAAA;IACrC,IAAIP,OAAAA,CAAQC,QAAQ,KAAK,OAAS,EAAA;QAChC,OAAOM,UAAAA,CAAWL,KAAK,CAACjB,IAAKoB,CAAAA,KAAK,CAACF,GAAG,CAAEC,CAAAA,IAAI,CAACnB,IAAAA,CAAKkB,GAAG,CAAA;AACvD;IAEA,OAAOI,UAAAA;AACT;;;;;;;"}
@@ -0,0 +1,63 @@
1
+ import path from 'node:path';
2
+ import { access } from 'node:fs/promises';
3
+ import { register } from 'esbuild-register/dist/node';
4
+
5
+ /**
6
+ * @internal
7
+ */ const pathExists = async (path)=>{
8
+ try {
9
+ await access(path);
10
+ return true;
11
+ } catch (error) {
12
+ return false;
13
+ }
14
+ };
15
+ /**
16
+ * @internal
17
+ */ const loadFile = async (path)=>{
18
+ if (await pathExists(path)) {
19
+ const esbuildOptions = {
20
+ extensions: [
21
+ '.js',
22
+ '.mjs',
23
+ '.ts'
24
+ ]
25
+ };
26
+ const { unregister } = register(esbuildOptions);
27
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
28
+ const mod = require(path);
29
+ unregister();
30
+ /**
31
+ * handles esm or cjs exporting.
32
+ */ const file = mod?.default || mod || undefined;
33
+ return file;
34
+ }
35
+ return undefined;
36
+ };
37
+ /**
38
+ * @internal
39
+ *
40
+ * @description Converts a system path to a module path mainly for `Windows` systems.
41
+ * where the path separator is `\` instead of `/`, on linux systems the path separator
42
+ * is identical to the module path separator.
43
+ */ const convertSystemPathToModulePath = (sysPath)=>{
44
+ if (process.platform === 'win32') {
45
+ return sysPath.split(path.sep).join(path.posix.sep);
46
+ }
47
+ return sysPath;
48
+ };
49
+ /**
50
+ * @internal
51
+ *
52
+ * @description Converts a module path to a system path, again largely used for Windows systems.
53
+ * The original use case was plugins where the resolve path was in module format but we want to
54
+ * have it relative to the runtime directory.
55
+ */ const convertModulePathToSystemPath = (modulePath)=>{
56
+ if (process.platform === 'win32') {
57
+ return modulePath.split(path.posix.sep).join(path.sep);
58
+ }
59
+ return modulePath;
60
+ };
61
+
62
+ export { convertModulePathToSystemPath, convertSystemPathToModulePath, loadFile, pathExists };
63
+ //# sourceMappingURL=files.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.mjs","sources":["../../../../src/node/core/files.ts"],"sourcesContent":["import path from 'node:path';\nimport { access } from 'node:fs/promises';\nimport { register } from 'esbuild-register/dist/node';\n\n/**\n * @internal\n */\nconst pathExists = async (path: string) => {\n try {\n await access(path);\n return true;\n } catch (error) {\n return false;\n }\n};\n\n/**\n * @internal\n */\nconst loadFile = async (path: string): Promise<undefined | any> => {\n if (await pathExists(path)) {\n const esbuildOptions: Parameters<typeof register>[0] = {\n extensions: ['.js', '.mjs', '.ts'],\n };\n\n const { unregister } = register(esbuildOptions);\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const mod = require(path);\n\n unregister();\n\n /**\n * handles esm or cjs exporting.\n */\n const file = mod?.default || mod || undefined;\n\n return file;\n }\n\n return undefined;\n};\n\n/**\n * @internal\n *\n * @description Converts a system path to a module path mainly for `Windows` systems.\n * where the path separator is `\\` instead of `/`, on linux systems the path separator\n * is identical to the module path separator.\n */\nconst convertSystemPathToModulePath = (sysPath: string) => {\n if (process.platform === 'win32') {\n return sysPath.split(path.sep).join(path.posix.sep);\n }\n\n return sysPath;\n};\n\n/**\n * @internal\n *\n * @description Converts a module path to a system path, again largely used for Windows systems.\n * The original use case was plugins where the resolve path was in module format but we want to\n * have it relative to the runtime directory.\n */\nconst convertModulePathToSystemPath = (modulePath: string) => {\n if (process.platform === 'win32') {\n return modulePath.split(path.posix.sep).join(path.sep);\n }\n\n return modulePath;\n};\n\nexport { pathExists, loadFile, convertSystemPathToModulePath, convertModulePathToSystemPath };\n"],"names":["pathExists","path","access","error","loadFile","esbuildOptions","extensions","unregister","register","mod","require","file","default","undefined","convertSystemPathToModulePath","sysPath","process","platform","split","sep","join","posix","convertModulePathToSystemPath","modulePath"],"mappings":";;;;AAIA;;IAGA,MAAMA,aAAa,OAAOC,IAAAA,GAAAA;IACxB,IAAI;AACF,QAAA,MAAMC,MAAOD,CAAAA,IAAAA,CAAAA;QACb,OAAO,IAAA;AACT,KAAA,CAAE,OAAOE,KAAO,EAAA;QACd,OAAO,KAAA;AACT;AACF;AAEA;;IAGA,MAAMC,WAAW,OAAOH,IAAAA,GAAAA;IACtB,IAAI,MAAMD,WAAWC,IAAO,CAAA,EAAA;AAC1B,QAAA,MAAMI,cAAiD,GAAA;YACrDC,UAAY,EAAA;AAAC,gBAAA,KAAA;AAAO,gBAAA,MAAA;AAAQ,gBAAA;AAAM;AACpC,SAAA;AAEA,QAAA,MAAM,EAAEC,UAAU,EAAE,GAAGC,QAASH,CAAAA,cAAAA,CAAAA;;AAGhC,QAAA,MAAMI,MAAMC,OAAQT,CAAAA,IAAAA,CAAAA;AAEpBM,QAAAA,UAAAA,EAAAA;AAEA;;AAEC,QACD,MAAMI,IAAAA,GAAOF,GAAKG,EAAAA,OAAAA,IAAWH,GAAOI,IAAAA,SAAAA;QAEpC,OAAOF,IAAAA;AACT;IAEA,OAAOE,SAAAA;AACT;AAEA;;;;;;IAOA,MAAMC,gCAAgC,CAACC,OAAAA,GAAAA;IACrC,IAAIC,OAAAA,CAAQC,QAAQ,KAAK,OAAS,EAAA;QAChC,OAAOF,OAAAA,CAAQG,KAAK,CAACjB,IAAKkB,CAAAA,GAAG,CAAEC,CAAAA,IAAI,CAACnB,IAAAA,CAAKoB,KAAK,CAACF,GAAG,CAAA;AACpD;IAEA,OAAOJ,OAAAA;AACT;AAEA;;;;;;IAOA,MAAMO,gCAAgC,CAACC,UAAAA,GAAAA;IACrC,IAAIP,OAAAA,CAAQC,QAAQ,KAAK,OAAS,EAAA;QAChC,OAAOM,UAAAA,CAAWL,KAAK,CAACjB,IAAKoB,CAAAA,KAAK,CAACF,GAAG,CAAEC,CAAAA,IAAI,CAACnB,IAAAA,CAAKkB,GAAG,CAAA;AACvD;IAEA,OAAOI,UAAAA;AACT;;;;"}
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @description Supports the following managers:
5
+ * – npm
6
+ * – yarn
7
+ * – pnpm
8
+ */ const getPackageManager = ()=>{
9
+ // Yes, the env var is lowercase - it is set by the package managers themselves
10
+ const agent = process.env.npm_config_user_agent || '';
11
+ if (agent.includes('yarn')) {
12
+ return 'yarn';
13
+ }
14
+ if (agent.includes('pnpm')) {
15
+ return 'pnpm';
16
+ }
17
+ // Both yarn and pnpm does a `npm/?` thing, thus the slightly different match here
18
+ // Theoretically not needed since we check for yarn/pnpm above, but in case other
19
+ // package managers do the same thing, we'll (hopefully) catch them here.
20
+ if (/^npm\/\d/.test(agent)) {
21
+ return 'npm';
22
+ }
23
+ return undefined;
24
+ };
25
+
26
+ exports.getPackageManager = getPackageManager;
27
+ //# sourceMappingURL=managers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managers.js","sources":["../../../../src/node/core/managers.ts"],"sourcesContent":["/**\n * @description Supports the following managers:\n * – npm\n * – yarn\n * – pnpm\n */\nconst getPackageManager = () => {\n // Yes, the env var is lowercase - it is set by the package managers themselves\n const agent = process.env.npm_config_user_agent || '';\n\n if (agent.includes('yarn')) {\n return 'yarn';\n }\n\n if (agent.includes('pnpm')) {\n return 'pnpm';\n }\n\n // Both yarn and pnpm does a `npm/?` thing, thus the slightly different match here\n // Theoretically not needed since we check for yarn/pnpm above, but in case other\n // package managers do the same thing, we'll (hopefully) catch them here.\n if (/^npm\\/\\d/.test(agent)) {\n return 'npm';\n }\n\n return undefined;\n};\n\nexport { getPackageManager };\n"],"names":["getPackageManager","agent","process","env","npm_config_user_agent","includes","test","undefined"],"mappings":";;AAAA;;;;;AAKC,UACKA,iBAAoB,GAAA,IAAA;;AAExB,IAAA,MAAMC,KAAQC,GAAAA,OAAAA,CAAQC,GAAG,CAACC,qBAAqB,IAAI,EAAA;IAEnD,IAAIH,KAAAA,CAAMI,QAAQ,CAAC,MAAS,CAAA,EAAA;QAC1B,OAAO,MAAA;AACT;IAEA,IAAIJ,KAAAA,CAAMI,QAAQ,CAAC,MAAS,CAAA,EAAA;QAC1B,OAAO,MAAA;AACT;;;;IAKA,IAAI,UAAA,CAAWC,IAAI,CAACL,KAAQ,CAAA,EAAA;QAC1B,OAAO,KAAA;AACT;IAEA,OAAOM,SAAAA;AACT;;;;"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @description Supports the following managers:
3
+ * – npm
4
+ * – yarn
5
+ * – pnpm
6
+ */ const getPackageManager = ()=>{
7
+ // Yes, the env var is lowercase - it is set by the package managers themselves
8
+ const agent = process.env.npm_config_user_agent || '';
9
+ if (agent.includes('yarn')) {
10
+ return 'yarn';
11
+ }
12
+ if (agent.includes('pnpm')) {
13
+ return 'pnpm';
14
+ }
15
+ // Both yarn and pnpm does a `npm/?` thing, thus the slightly different match here
16
+ // Theoretically not needed since we check for yarn/pnpm above, but in case other
17
+ // package managers do the same thing, we'll (hopefully) catch them here.
18
+ if (/^npm\/\d/.test(agent)) {
19
+ return 'npm';
20
+ }
21
+ return undefined;
22
+ };
23
+
24
+ export { getPackageManager };
25
+ //# sourceMappingURL=managers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"managers.mjs","sources":["../../../../src/node/core/managers.ts"],"sourcesContent":["/**\n * @description Supports the following managers:\n * – npm\n * – yarn\n * – pnpm\n */\nconst getPackageManager = () => {\n // Yes, the env var is lowercase - it is set by the package managers themselves\n const agent = process.env.npm_config_user_agent || '';\n\n if (agent.includes('yarn')) {\n return 'yarn';\n }\n\n if (agent.includes('pnpm')) {\n return 'pnpm';\n }\n\n // Both yarn and pnpm does a `npm/?` thing, thus the slightly different match here\n // Theoretically not needed since we check for yarn/pnpm above, but in case other\n // package managers do the same thing, we'll (hopefully) catch them here.\n if (/^npm\\/\\d/.test(agent)) {\n return 'npm';\n }\n\n return undefined;\n};\n\nexport { getPackageManager };\n"],"names":["getPackageManager","agent","process","env","npm_config_user_agent","includes","test","undefined"],"mappings":"AAAA;;;;;AAKC,UACKA,iBAAoB,GAAA,IAAA;;AAExB,IAAA,MAAMC,KAAQC,GAAAA,OAAAA,CAAQC,GAAG,CAACC,qBAAqB,IAAI,EAAA;IAEnD,IAAIH,KAAAA,CAAMI,QAAQ,CAAC,MAAS,CAAA,EAAA;QAC1B,OAAO,MAAA;AACT;IAEA,IAAIJ,KAAAA,CAAMI,QAAQ,CAAC,MAAS,CAAA,EAAA;QAC1B,OAAO,MAAA;AACT;;;;IAKA,IAAI,UAAA,CAAWC,IAAI,CAACL,KAAQ,CAAA,EAAA;QAC1B,OAAO,KAAA;AACT;IAEA,OAAOM,SAAAA;AACT;;;;"}