@strapi/upgrade 0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78 → 0.0.0-experimental.f86f67937111a56cae88a8a8c0d84fb2d9c39dd3

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 (280) hide show
  1. package/LICENSE +19 -4
  2. package/README.md +1 -1
  3. package/dist/cli.js +13 -1451
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli.mjs +14 -0
  6. package/dist/cli.mjs.map +1 -0
  7. package/dist/index.js +9 -1428
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +4 -1420
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/modules/codemod-repository/constants.d.ts.map +1 -1
  12. package/dist/modules/error/utils.d.ts +8 -0
  13. package/dist/modules/error/utils.d.ts.map +1 -1
  14. package/dist/modules/file-scanner/scanner.d.ts.map +1 -1
  15. package/dist/modules/format/formats.d.ts +2 -1
  16. package/dist/modules/format/formats.d.ts.map +1 -1
  17. package/dist/modules/npm/package.d.ts +7 -3
  18. package/dist/modules/npm/package.d.ts.map +1 -1
  19. package/dist/modules/project/constants.d.ts +6 -5
  20. package/dist/modules/project/constants.d.ts.map +1 -1
  21. package/dist/modules/project/project.d.ts +16 -2
  22. package/dist/modules/project/project.d.ts.map +1 -1
  23. package/dist/modules/project/types.d.ts +3 -0
  24. package/dist/modules/project/types.d.ts.map +1 -1
  25. package/dist/modules/runner/json/transform.d.ts.map +1 -1
  26. package/dist/modules/upgrader/types.d.ts +6 -0
  27. package/dist/modules/upgrader/types.d.ts.map +1 -1
  28. package/dist/modules/upgrader/upgrader.d.ts +4 -0
  29. package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
  30. package/dist/modules/version/range.d.ts.map +1 -1
  31. package/dist/modules/version/types.d.ts +2 -1
  32. package/dist/modules/version/types.d.ts.map +1 -1
  33. package/dist/package.json.js +6 -0
  34. package/dist/package.json.js.map +1 -0
  35. package/dist/package.json.mjs +4 -0
  36. package/dist/package.json.mjs.map +1 -0
  37. package/dist/src/cli/commands/codemods.js +121 -0
  38. package/dist/src/cli/commands/codemods.js.map +1 -0
  39. package/dist/src/cli/commands/codemods.mjs +117 -0
  40. package/dist/src/cli/commands/codemods.mjs.map +1 -0
  41. package/dist/src/cli/commands/upgrade.js +99 -0
  42. package/dist/src/cli/commands/upgrade.js.map +1 -0
  43. package/dist/src/cli/commands/upgrade.mjs +96 -0
  44. package/dist/src/cli/commands/upgrade.mjs.map +1 -0
  45. package/dist/src/cli/errors.js +18 -0
  46. package/dist/src/cli/errors.js.map +1 -0
  47. package/dist/src/cli/errors.mjs +16 -0
  48. package/dist/src/cli/errors.mjs.map +1 -0
  49. package/dist/src/cli/options.js +25 -0
  50. package/dist/src/cli/options.js.map +1 -0
  51. package/dist/src/cli/options.mjs +18 -0
  52. package/dist/src/cli/options.mjs.map +1 -0
  53. package/dist/src/modules/codemod/codemod.js +44 -0
  54. package/dist/src/modules/codemod/codemod.js.map +1 -0
  55. package/dist/src/modules/codemod/codemod.mjs +41 -0
  56. package/dist/src/modules/codemod/codemod.mjs.map +1 -0
  57. package/dist/src/modules/codemod/constants.js +17 -0
  58. package/dist/src/modules/codemod/constants.js.map +1 -0
  59. package/dist/src/modules/codemod/constants.mjs +11 -0
  60. package/dist/src/modules/codemod/constants.mjs.map +1 -0
  61. package/dist/src/modules/codemod/index.js +10 -0
  62. package/dist/src/modules/codemod/index.js.map +1 -0
  63. package/dist/src/modules/codemod/index.mjs +4 -0
  64. package/dist/src/modules/codemod/index.mjs.map +1 -0
  65. package/dist/src/modules/codemod-repository/constants.js +9 -0
  66. package/dist/src/modules/codemod-repository/constants.js.map +1 -0
  67. package/dist/src/modules/codemod-repository/constants.mjs +7 -0
  68. package/dist/src/modules/codemod-repository/constants.mjs.map +1 -0
  69. package/dist/src/modules/codemod-repository/index.js +10 -0
  70. package/dist/src/modules/codemod-repository/index.js.map +1 -0
  71. package/dist/src/modules/codemod-repository/index.mjs +4 -0
  72. package/dist/src/modules/codemod-repository/index.mjs.map +1 -0
  73. package/dist/src/modules/codemod-repository/repository.js +126 -0
  74. package/dist/src/modules/codemod-repository/repository.js.map +1 -0
  75. package/dist/src/modules/codemod-repository/repository.mjs +122 -0
  76. package/dist/src/modules/codemod-repository/repository.mjs.map +1 -0
  77. package/dist/src/modules/codemod-runner/codemod-runner.js +112 -0
  78. package/dist/src/modules/codemod-runner/codemod-runner.js.map +1 -0
  79. package/dist/src/modules/codemod-runner/codemod-runner.mjs +109 -0
  80. package/dist/src/modules/codemod-runner/codemod-runner.mjs.map +1 -0
  81. package/dist/src/modules/error/index.js +11 -0
  82. package/dist/src/modules/error/index.js.map +1 -0
  83. package/dist/src/modules/error/index.mjs +2 -0
  84. package/dist/src/modules/error/index.mjs.map +1 -0
  85. package/dist/src/modules/error/utils.js +33 -0
  86. package/dist/src/modules/error/utils.js.map +1 -0
  87. package/dist/src/modules/error/utils.mjs +28 -0
  88. package/dist/src/modules/error/utils.mjs.map +1 -0
  89. package/dist/src/modules/file-scanner/index.js +8 -0
  90. package/dist/src/modules/file-scanner/index.js.map +1 -0
  91. package/dist/src/modules/file-scanner/index.mjs +2 -0
  92. package/dist/src/modules/file-scanner/index.mjs.map +1 -0
  93. package/dist/src/modules/file-scanner/scanner.js +23 -0
  94. package/dist/src/modules/file-scanner/scanner.js.map +1 -0
  95. package/dist/src/modules/file-scanner/scanner.mjs +20 -0
  96. package/dist/src/modules/file-scanner/scanner.mjs.map +1 -0
  97. package/dist/src/modules/format/formats.js +107 -0
  98. package/dist/src/modules/format/formats.js.map +1 -0
  99. package/dist/src/modules/format/formats.mjs +94 -0
  100. package/dist/src/modules/format/formats.mjs.map +1 -0
  101. package/dist/src/modules/format/index.js +19 -0
  102. package/dist/src/modules/format/index.js.map +1 -0
  103. package/dist/src/modules/format/index.mjs +2 -0
  104. package/dist/src/modules/format/index.mjs.map +1 -0
  105. package/dist/src/modules/index.js +32 -0
  106. package/dist/src/modules/index.js.map +1 -0
  107. package/dist/src/modules/index.mjs +27 -0
  108. package/dist/src/modules/index.mjs.map +1 -0
  109. package/dist/src/modules/json/file.js +16 -0
  110. package/dist/src/modules/json/file.js.map +1 -0
  111. package/dist/src/modules/json/file.mjs +13 -0
  112. package/dist/src/modules/json/file.mjs.map +1 -0
  113. package/dist/src/modules/json/transform-api.js +38 -0
  114. package/dist/src/modules/json/transform-api.js.map +1 -0
  115. package/dist/src/modules/json/transform-api.mjs +35 -0
  116. package/dist/src/modules/json/transform-api.mjs.map +1 -0
  117. package/dist/src/modules/logger/index.js +8 -0
  118. package/dist/src/modules/logger/index.js.map +1 -0
  119. package/dist/src/modules/logger/index.mjs +2 -0
  120. package/dist/src/modules/logger/index.mjs.map +1 -0
  121. package/dist/src/modules/logger/logger.js +76 -0
  122. package/dist/src/modules/logger/logger.js.map +1 -0
  123. package/dist/src/modules/logger/logger.mjs +73 -0
  124. package/dist/src/modules/logger/logger.mjs.map +1 -0
  125. package/dist/src/modules/npm/constants.js +6 -0
  126. package/dist/src/modules/npm/constants.js.map +1 -0
  127. package/dist/src/modules/npm/constants.mjs +4 -0
  128. package/dist/src/modules/npm/constants.mjs.map +1 -0
  129. package/dist/src/modules/npm/package.js +107 -0
  130. package/dist/src/modules/npm/package.js.map +1 -0
  131. package/dist/src/modules/npm/package.mjs +104 -0
  132. package/dist/src/modules/npm/package.mjs.map +1 -0
  133. package/dist/src/modules/project/constants.js +45 -0
  134. package/dist/src/modules/project/constants.js.map +1 -0
  135. package/dist/src/modules/project/constants.mjs +35 -0
  136. package/dist/src/modules/project/constants.mjs.map +1 -0
  137. package/dist/src/modules/project/index.js +15 -0
  138. package/dist/src/modules/project/index.js.map +1 -0
  139. package/dist/src/modules/project/index.mjs +5 -0
  140. package/dist/src/modules/project/index.mjs.map +1 -0
  141. package/dist/src/modules/project/project.js +205 -0
  142. package/dist/src/modules/project/project.js.map +1 -0
  143. package/dist/src/modules/project/project.mjs +200 -0
  144. package/dist/src/modules/project/project.mjs.map +1 -0
  145. package/dist/src/modules/project/utils.js +26 -0
  146. package/dist/src/modules/project/utils.js.map +1 -0
  147. package/dist/src/modules/project/utils.mjs +21 -0
  148. package/dist/src/modules/project/utils.mjs.map +1 -0
  149. package/dist/src/modules/report/index.js +9 -0
  150. package/dist/src/modules/report/index.js.map +1 -0
  151. package/dist/src/modules/report/index.mjs +2 -0
  152. package/dist/src/modules/report/index.mjs.map +1 -0
  153. package/dist/src/modules/report/report.js +13 -0
  154. package/dist/src/modules/report/report.js.map +1 -0
  155. package/dist/src/modules/report/report.mjs +10 -0
  156. package/dist/src/modules/report/report.mjs.map +1 -0
  157. package/dist/src/modules/requirement/index.js +8 -0
  158. package/dist/src/modules/requirement/index.js.map +1 -0
  159. package/dist/src/modules/requirement/index.mjs +2 -0
  160. package/dist/src/modules/requirement/index.mjs.map +1 -0
  161. package/dist/src/modules/requirement/requirement.js +55 -0
  162. package/dist/src/modules/requirement/requirement.js.map +1 -0
  163. package/dist/src/modules/requirement/requirement.mjs +52 -0
  164. package/dist/src/modules/requirement/requirement.mjs.map +1 -0
  165. package/dist/src/modules/runner/code/code.js +20 -0
  166. package/dist/src/modules/runner/code/code.js.map +1 -0
  167. package/dist/src/modules/runner/code/code.mjs +17 -0
  168. package/dist/src/modules/runner/code/code.mjs.map +1 -0
  169. package/dist/src/modules/runner/code/index.js +8 -0
  170. package/dist/src/modules/runner/code/index.js.map +1 -0
  171. package/dist/src/modules/runner/code/index.mjs +2 -0
  172. package/dist/src/modules/runner/code/index.mjs.map +1 -0
  173. package/dist/src/modules/runner/index.js +10 -0
  174. package/dist/src/modules/runner/index.js.map +1 -0
  175. package/dist/src/modules/runner/index.mjs +5 -0
  176. package/dist/src/modules/runner/index.mjs.map +1 -0
  177. package/dist/src/modules/runner/json/index.js +8 -0
  178. package/dist/src/modules/runner/json/index.js.map +1 -0
  179. package/dist/src/modules/runner/json/index.mjs +2 -0
  180. package/dist/src/modules/runner/json/index.mjs.map +1 -0
  181. package/dist/src/modules/runner/json/json.js +20 -0
  182. package/dist/src/modules/runner/json/json.js.map +1 -0
  183. package/dist/src/modules/runner/json/json.mjs +17 -0
  184. package/dist/src/modules/runner/json/json.mjs.map +1 -0
  185. package/dist/src/modules/runner/json/transform.js +85 -0
  186. package/dist/src/modules/runner/json/transform.js.map +1 -0
  187. package/dist/src/modules/runner/json/transform.mjs +83 -0
  188. package/dist/src/modules/runner/json/transform.mjs.map +1 -0
  189. package/dist/src/modules/runner/runner.js +22 -0
  190. package/dist/src/modules/runner/runner.js.map +1 -0
  191. package/dist/src/modules/runner/runner.mjs +20 -0
  192. package/dist/src/modules/runner/runner.mjs.map +1 -0
  193. package/dist/src/modules/timer/constants.js +6 -0
  194. package/dist/src/modules/timer/constants.js.map +1 -0
  195. package/dist/src/modules/timer/constants.mjs +4 -0
  196. package/dist/src/modules/timer/constants.mjs.map +1 -0
  197. package/dist/src/modules/timer/index.js +10 -0
  198. package/dist/src/modules/timer/index.js.map +1 -0
  199. package/dist/src/modules/timer/index.mjs +4 -0
  200. package/dist/src/modules/timer/index.mjs.map +1 -0
  201. package/dist/src/modules/timer/timer.js +33 -0
  202. package/dist/src/modules/timer/timer.js.map +1 -0
  203. package/dist/src/modules/timer/timer.mjs +30 -0
  204. package/dist/src/modules/timer/timer.mjs.map +1 -0
  205. package/dist/src/modules/upgrader/constants.js +6 -0
  206. package/dist/src/modules/upgrader/constants.js.map +1 -0
  207. package/dist/src/modules/upgrader/constants.mjs +4 -0
  208. package/dist/src/modules/upgrader/constants.mjs.map +1 -0
  209. package/dist/src/modules/upgrader/index.js +10 -0
  210. package/dist/src/modules/upgrader/index.js.map +1 -0
  211. package/dist/src/modules/upgrader/index.mjs +4 -0
  212. package/dist/src/modules/upgrader/index.mjs.map +1 -0
  213. package/dist/src/modules/upgrader/upgrader.js +265 -0
  214. package/dist/src/modules/upgrader/upgrader.js.map +1 -0
  215. package/dist/src/modules/upgrader/upgrader.mjs +262 -0
  216. package/dist/src/modules/upgrader/upgrader.mjs.map +1 -0
  217. package/dist/src/modules/version/index.js +20 -0
  218. package/dist/src/modules/version/index.js.map +1 -0
  219. package/dist/src/modules/version/index.mjs +5 -0
  220. package/dist/src/modules/version/index.mjs.map +1 -0
  221. package/dist/src/modules/version/range.js +81 -0
  222. package/dist/src/modules/version/range.js.map +1 -0
  223. package/dist/src/modules/version/range.mjs +75 -0
  224. package/dist/src/modules/version/range.mjs.map +1 -0
  225. package/dist/src/modules/version/semver.js +26 -0
  226. package/dist/src/modules/version/semver.js.map +1 -0
  227. package/dist/src/modules/version/semver.mjs +20 -0
  228. package/dist/src/modules/version/semver.mjs.map +1 -0
  229. package/dist/src/modules/version/types.js +14 -0
  230. package/dist/src/modules/version/types.js.map +1 -0
  231. package/dist/src/modules/version/types.mjs +12 -0
  232. package/dist/src/modules/version/types.mjs.map +1 -0
  233. package/dist/src/tasks/codemods/list-codemods.js +40 -0
  234. package/dist/src/tasks/codemods/list-codemods.js.map +1 -0
  235. package/dist/src/tasks/codemods/list-codemods.mjs +38 -0
  236. package/dist/src/tasks/codemods/list-codemods.mjs.map +1 -0
  237. package/dist/src/tasks/codemods/run-codemods.js +36 -0
  238. package/dist/src/tasks/codemods/run-codemods.js.map +1 -0
  239. package/dist/src/tasks/codemods/run-codemods.mjs +34 -0
  240. package/dist/src/tasks/codemods/run-codemods.mjs.map +1 -0
  241. package/dist/src/tasks/codemods/utils.js +54 -0
  242. package/dist/src/tasks/codemods/utils.js.map +1 -0
  243. package/dist/src/tasks/codemods/utils.mjs +50 -0
  244. package/dist/src/tasks/codemods/utils.mjs.map +1 -0
  245. package/dist/src/tasks/index.js +14 -0
  246. package/dist/src/tasks/index.js.map +1 -0
  247. package/dist/src/tasks/index.mjs +6 -0
  248. package/dist/src/tasks/index.mjs.map +1 -0
  249. package/dist/src/tasks/upgrade/prompts/latest.js +48 -0
  250. package/dist/src/tasks/upgrade/prompts/latest.js.map +1 -0
  251. package/dist/src/tasks/upgrade/prompts/latest.mjs +46 -0
  252. package/dist/src/tasks/upgrade/prompts/latest.mjs.map +1 -0
  253. package/dist/src/tasks/upgrade/requirements/common.js +40 -0
  254. package/dist/src/tasks/upgrade/requirements/common.js.map +1 -0
  255. package/dist/src/tasks/upgrade/requirements/common.mjs +35 -0
  256. package/dist/src/tasks/upgrade/requirements/common.mjs.map +1 -0
  257. package/dist/src/tasks/upgrade/requirements/major.js +28 -0
  258. package/dist/src/tasks/upgrade/requirements/major.js.map +1 -0
  259. package/dist/src/tasks/upgrade/requirements/major.mjs +25 -0
  260. package/dist/src/tasks/upgrade/requirements/major.mjs.map +1 -0
  261. package/dist/src/tasks/upgrade/upgrade.js +69 -0
  262. package/dist/src/tasks/upgrade/upgrade.js.map +1 -0
  263. package/dist/src/tasks/upgrade/upgrade.mjs +67 -0
  264. package/dist/src/tasks/upgrade/upgrade.mjs.map +1 -0
  265. package/dist/tasks/codemods/utils.d.ts.map +1 -1
  266. package/dist/tasks/upgrade/prompts/index.d.ts +2 -0
  267. package/dist/tasks/upgrade/prompts/index.d.ts.map +1 -0
  268. package/dist/tasks/upgrade/prompts/latest.d.ts +9 -0
  269. package/dist/tasks/upgrade/prompts/latest.d.ts.map +1 -0
  270. package/dist/tasks/upgrade/requirements/major.d.ts.map +1 -1
  271. package/dist/tasks/upgrade/upgrade.d.ts.map +1 -1
  272. package/package.json +16 -14
  273. package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
  274. package/resources/codemods/5.0.0/dependency-upgrade-react-and-react-dom.json.ts +67 -0
  275. package/resources/codemods/5.0.0/dependency-upgrade-styled-components.json.ts +49 -0
  276. package/resources/codemods/5.0.0/deprecate-helper-plugin.code.ts +192 -0
  277. package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +0 -1
  278. package/resources/codemods/5.1.0/dependency-better-sqlite3.json.ts +48 -0
  279. package/resources/utils/change-import.ts +118 -0
  280. package/resources/utils/replace-jsx.ts +49 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.mjs","sources":["../../../../src/modules/npm/package.ts"],"sourcesContent":["import assert from 'node:assert';\nimport semver from 'semver';\nimport execa from 'execa';\nimport { packageManager } from '@strapi/utils';\n\nimport { ProxyAgent } from 'undici';\nimport * as constants from './constants';\nimport { isLiteralSemVer } from '../version';\n\nimport type { Package as PackageInterface, NPMPackage, NPMPackageVersion } from './types';\nimport type { Version } from '../version';\nimport { Logger } from '../logger';\n\nconst proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;\nconst agent = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;\n\nexport class Package implements PackageInterface {\n name: string;\n\n cwd: string;\n\n private logger: Logger;\n\n private npmPackage: NPMPackage | null;\n\n constructor(name: string, cwd: string, logger: Logger) {\n this.name = name;\n this.cwd = cwd;\n this.logger = logger;\n this.npmPackage = null;\n }\n\n get isLoaded() {\n return this.npmPackage !== null;\n }\n\n private assertPackageIsLoaded(npmPackage: NPMPackage | null): asserts npmPackage is NPMPackage {\n assert(this.isLoaded, 'The package is not loaded yet');\n }\n\n getVersionsDict() {\n this.assertPackageIsLoaded(this.npmPackage);\n\n return this.npmPackage.versions;\n }\n\n getVersionsAsList() {\n this.assertPackageIsLoaded(this.npmPackage);\n\n return Object.values(this.npmPackage.versions);\n }\n\n findVersionsInRange(range: Version.Range) {\n const versions = this.getVersionsAsList();\n\n return (\n versions\n // Only select versions matching the upgrade range\n .filter((v) => range.test(v.version))\n // Only select supported version format (x.x.x)\n .filter((v) => isLiteralSemVer(v.version))\n // Sort in ascending order\n .sort((v1, v2) => semver.compare(v1.version, v2.version))\n );\n }\n\n private async getRegistryFromPackageManager(): Promise<string | undefined> {\n try {\n const packageManagerName = await packageManager.getPreferred(this.cwd);\n if (!packageManagerName) return undefined;\n\n const registryCommands = {\n yarn: ['config', 'get', 'npmRegistryServer'],\n npm: ['config', 'get', 'registry'],\n } as const;\n\n const command = registryCommands[packageManagerName as keyof typeof registryCommands];\n if (!command) {\n this.logger.warn(`Unsupported package manager: ${packageManagerName}`);\n return undefined;\n }\n\n const { stdout } = await execa(packageManagerName, command, { timeout: 10_000 });\n return stdout.trim() || undefined;\n } catch (error) {\n this.logger.warn('Failed to determine registry URL from package manager');\n return undefined;\n }\n }\n\n private async determineRegistryUrl(): Promise<string> {\n if (process.env.NPM_REGISTRY_URL) {\n this.logger.debug(`Using NPM_REGISTRY_URL: ${process.env.NPM_REGISTRY_URL}`);\n return process.env.NPM_REGISTRY_URL.replace(/\\/$/, '');\n }\n\n const packageManagerRegistry = await this.getRegistryFromPackageManager();\n if (packageManagerRegistry) {\n this.logger.debug(`Using package manager registry: ${packageManagerRegistry}`);\n return packageManagerRegistry.replace(/\\/$/, '');\n }\n\n this.logger.debug(`Using default registry: ${constants.NPM_REGISTRY_URL}`);\n return constants.NPM_REGISTRY_URL.replace(/\\/$/, '');\n }\n\n findVersion(version: Version.SemVer): NPMPackageVersion | undefined {\n const versions = this.getVersionsAsList();\n\n return versions.find((npmVersion) => semver.eq(npmVersion.version, version));\n }\n\n async refresh() {\n const packageURL = `${await this.determineRegistryUrl()}/${this.name}`;\n\n const response = await fetch(packageURL, {\n // @ts-expect-error Node.js fetch supports dispatcher (undici extension)\n dispatcher: agent,\n });\n\n // TODO: Use a validation library to make sure the response structure is correct\n assert(response.ok, `Request failed for ${packageURL}`);\n\n this.npmPackage = (await response.json()) as NPMPackage;\n\n return this;\n }\n\n versionExists(version: Version.SemVer) {\n return this.findVersion(version) !== undefined;\n }\n}\n\nexport const npmPackageFactory = (name: string, cwd: string, logger: Logger) =>\n new Package(name, cwd, logger);\n"],"names":["proxyUrl","process","env","HTTP_PROXY","HTTPS_PROXY","agent","ProxyAgent","undefined","Package","isLoaded","npmPackage","assertPackageIsLoaded","assert","getVersionsDict","versions","getVersionsAsList","Object","values","findVersionsInRange","range","filter","v","test","version","isLiteralSemVer","sort","v1","v2","semver","compare","getRegistryFromPackageManager","packageManagerName","packageManager","getPreferred","cwd","registryCommands","yarn","npm","command","logger","warn","stdout","execa","timeout","trim","error","determineRegistryUrl","NPM_REGISTRY_URL","debug","replace","packageManagerRegistry","constants","findVersion","find","npmVersion","eq","refresh","packageURL","name","response","fetch","dispatcher","ok","json","versionExists","npmPackageFactory"],"mappings":";;;;;;;;AAaA,MAAMA,QAAAA,GAAWC,QAAQC,GAAG,CAACC,UAAU,IAAIF,OAAAA,CAAQC,GAAG,CAACE,WAAW;AAClE,MAAMC,KAAQL,GAAAA,QAAAA,GAAW,IAAIM,UAAAA,CAAWN,QAAYO,CAAAA,GAAAA,SAAAA;AAE7C,MAAMC,OAAAA,CAAAA;AAgBX,IAAA,IAAIC,QAAW,GAAA;QACb,OAAO,IAAI,CAACC,UAAU,KAAK,IAAA;AAC7B;AAEQC,IAAAA,qBAAAA,CAAsBD,UAA6B,EAAoC;QAC7FE,MAAO,CAAA,IAAI,CAACH,QAAQ,EAAE,+BAAA,CAAA;AACxB;IAEAI,eAAkB,GAAA;AAChB,QAAA,IAAI,CAACF,qBAAqB,CAAC,IAAI,CAACD,UAAU,CAAA;AAE1C,QAAA,OAAO,IAAI,CAACA,UAAU,CAACI,QAAQ;AACjC;IAEAC,iBAAoB,GAAA;AAClB,QAAA,IAAI,CAACJ,qBAAqB,CAAC,IAAI,CAACD,UAAU,CAAA;AAE1C,QAAA,OAAOM,OAAOC,MAAM,CAAC,IAAI,CAACP,UAAU,CAACI,QAAQ,CAAA;AAC/C;AAEAI,IAAAA,mBAAAA,CAAoBC,KAAoB,EAAE;QACxC,MAAML,QAAAA,GAAW,IAAI,CAACC,iBAAiB,EAAA;AAEvC,QAAA,OACED,QACE;SACCM,MAAM,CAAC,CAACC,CAAMF,GAAAA,KAAAA,CAAMG,IAAI,CAACD,CAAAA,CAAEE,OAAO,CAAA,CACnC;AACCH,SAAAA,MAAM,CAAC,CAACC,CAAAA,GAAMG,gBAAgBH,CAAEE,CAAAA,OAAO,EACxC;SACCE,IAAI,CAAC,CAACC,EAAAA,EAAIC,EAAOC,GAAAA,MAAAA,CAAOC,OAAO,CAAC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B,EAAE;AACrC,QAAA,OAAO,IAAI,CAAC6B,WAAW,CAAC7B,OAAahB,CAAAA,KAAAA,SAAAA;AACvC;AAzGA,IAAA,WAAA,CAAYmD,IAAY,EAAExB,GAAW,EAAEK,MAAc,CAAE;QACrD,IAAI,CAACmB,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACxB,GAAG,GAAGA,GAAAA;QACX,IAAI,CAACK,MAAM,GAAGA,MAAAA;QACd,IAAI,CAAC7B,UAAU,GAAG,IAAA;AACpB;AAqGF;AAEO,MAAMuD,iBAAoB,GAAA,CAACP,IAAcxB,EAAAA,GAAAA,EAAaK,SAC3D,IAAI/B,OAAAA,CAAQkD,IAAMxB,EAAAA,GAAAA,EAAKK,MAAQ;;;;"}
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ const PROJECT_PACKAGE_JSON = 'package.json';
4
+ const PROJECT_APP_ALLOWED_ROOT_PATHS = [
5
+ 'src',
6
+ 'config',
7
+ 'public'
8
+ ];
9
+ const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = [
10
+ 'admin',
11
+ 'server'
12
+ ];
13
+ const PROJECT_PLUGIN_ROOT_FILES = [
14
+ 'strapi-admin.js',
15
+ 'strapi-server.js'
16
+ ];
17
+ const PROJECT_CODE_EXTENSIONS = [
18
+ // Source files
19
+ 'js',
20
+ 'mjs',
21
+ 'ts',
22
+ // React files
23
+ 'jsx',
24
+ 'tsx'
25
+ ];
26
+ const PROJECT_JSON_EXTENSIONS = [
27
+ 'json'
28
+ ];
29
+ const PROJECT_ALLOWED_EXTENSIONS = [
30
+ ...PROJECT_CODE_EXTENSIONS,
31
+ ...PROJECT_JSON_EXTENSIONS
32
+ ];
33
+ const SCOPED_STRAPI_PACKAGE_PREFIX = '@strapi/';
34
+ const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
35
+
36
+ exports.PROJECT_ALLOWED_EXTENSIONS = PROJECT_ALLOWED_EXTENSIONS;
37
+ exports.PROJECT_APP_ALLOWED_ROOT_PATHS = PROJECT_APP_ALLOWED_ROOT_PATHS;
38
+ exports.PROJECT_CODE_EXTENSIONS = PROJECT_CODE_EXTENSIONS;
39
+ exports.PROJECT_JSON_EXTENSIONS = PROJECT_JSON_EXTENSIONS;
40
+ exports.PROJECT_PACKAGE_JSON = PROJECT_PACKAGE_JSON;
41
+ exports.PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = PROJECT_PLUGIN_ALLOWED_ROOT_PATHS;
42
+ exports.PROJECT_PLUGIN_ROOT_FILES = PROJECT_PLUGIN_ROOT_FILES;
43
+ exports.SCOPED_STRAPI_PACKAGE_PREFIX = SCOPED_STRAPI_PACKAGE_PREFIX;
44
+ exports.STRAPI_DEPENDENCY_NAME = STRAPI_DEPENDENCY_NAME;
45
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../../../src/modules/project/constants.ts"],"sourcesContent":["export const PROJECT_PACKAGE_JSON = 'package.json';\n\nexport const PROJECT_APP_ALLOWED_ROOT_PATHS = ['src', 'config', 'public'];\n\nexport const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ['admin', 'server'];\n\nexport const PROJECT_PLUGIN_ROOT_FILES = ['strapi-admin.js', 'strapi-server.js'];\n\nexport const PROJECT_CODE_EXTENSIONS = [\n // Source files\n 'js',\n 'mjs',\n 'ts',\n // React files\n 'jsx',\n 'tsx',\n];\n\nexport const PROJECT_JSON_EXTENSIONS = ['json'];\n\nexport const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];\n\nexport const SCOPED_STRAPI_PACKAGE_PREFIX = '@strapi/';\n\nexport const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;\n"],"names":["PROJECT_PACKAGE_JSON","PROJECT_APP_ALLOWED_ROOT_PATHS","PROJECT_PLUGIN_ALLOWED_ROOT_PATHS","PROJECT_PLUGIN_ROOT_FILES","PROJECT_CODE_EXTENSIONS","PROJECT_JSON_EXTENSIONS","PROJECT_ALLOWED_EXTENSIONS","SCOPED_STRAPI_PACKAGE_PREFIX","STRAPI_DEPENDENCY_NAME"],"mappings":";;AAAO,MAAMA,uBAAuB;MAEvBC,8BAAiC,GAAA;AAAC,IAAA,KAAA;AAAO,IAAA,QAAA;AAAU,IAAA;;MAEnDC,iCAAoC,GAAA;AAAC,IAAA,OAAA;AAAS,IAAA;;MAE9CC,yBAA4B,GAAA;AAAC,IAAA,iBAAA;AAAmB,IAAA;;MAEhDC,uBAA0B,GAAA;;AAErC,IAAA,IAAA;AACA,IAAA,KAAA;AACA,IAAA,IAAA;;AAEA,IAAA,KAAA;AACA,IAAA;;MAGWC,uBAA0B,GAAA;AAAC,IAAA;;MAE3BC,0BAA6B,GAAA;AAAIF,IAAAA,GAAAA,uBAAAA;AAA4BC,IAAAA,GAAAA;;AAEnE,MAAME,+BAA+B;MAE/BC,sBAAyB,GAAA,CAAA,EAAGD,4BAA6B,CAAA,MAAM;;;;;;;;;;;;"}
@@ -0,0 +1,35 @@
1
+ const PROJECT_PACKAGE_JSON = 'package.json';
2
+ const PROJECT_APP_ALLOWED_ROOT_PATHS = [
3
+ 'src',
4
+ 'config',
5
+ 'public'
6
+ ];
7
+ const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = [
8
+ 'admin',
9
+ 'server'
10
+ ];
11
+ const PROJECT_PLUGIN_ROOT_FILES = [
12
+ 'strapi-admin.js',
13
+ 'strapi-server.js'
14
+ ];
15
+ const PROJECT_CODE_EXTENSIONS = [
16
+ // Source files
17
+ 'js',
18
+ 'mjs',
19
+ 'ts',
20
+ // React files
21
+ 'jsx',
22
+ 'tsx'
23
+ ];
24
+ const PROJECT_JSON_EXTENSIONS = [
25
+ 'json'
26
+ ];
27
+ const PROJECT_ALLOWED_EXTENSIONS = [
28
+ ...PROJECT_CODE_EXTENSIONS,
29
+ ...PROJECT_JSON_EXTENSIONS
30
+ ];
31
+ const SCOPED_STRAPI_PACKAGE_PREFIX = '@strapi/';
32
+ const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
33
+
34
+ export { PROJECT_ALLOWED_EXTENSIONS, PROJECT_APP_ALLOWED_ROOT_PATHS, PROJECT_CODE_EXTENSIONS, PROJECT_JSON_EXTENSIONS, PROJECT_PACKAGE_JSON, PROJECT_PLUGIN_ALLOWED_ROOT_PATHS, PROJECT_PLUGIN_ROOT_FILES, SCOPED_STRAPI_PACKAGE_PREFIX, STRAPI_DEPENDENCY_NAME };
35
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sources":["../../../../src/modules/project/constants.ts"],"sourcesContent":["export const PROJECT_PACKAGE_JSON = 'package.json';\n\nexport const PROJECT_APP_ALLOWED_ROOT_PATHS = ['src', 'config', 'public'];\n\nexport const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ['admin', 'server'];\n\nexport const PROJECT_PLUGIN_ROOT_FILES = ['strapi-admin.js', 'strapi-server.js'];\n\nexport const PROJECT_CODE_EXTENSIONS = [\n // Source files\n 'js',\n 'mjs',\n 'ts',\n // React files\n 'jsx',\n 'tsx',\n];\n\nexport const PROJECT_JSON_EXTENSIONS = ['json'];\n\nexport const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];\n\nexport const SCOPED_STRAPI_PACKAGE_PREFIX = '@strapi/';\n\nexport const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;\n"],"names":["PROJECT_PACKAGE_JSON","PROJECT_APP_ALLOWED_ROOT_PATHS","PROJECT_PLUGIN_ALLOWED_ROOT_PATHS","PROJECT_PLUGIN_ROOT_FILES","PROJECT_CODE_EXTENSIONS","PROJECT_JSON_EXTENSIONS","PROJECT_ALLOWED_EXTENSIONS","SCOPED_STRAPI_PACKAGE_PREFIX","STRAPI_DEPENDENCY_NAME"],"mappings":"AAAO,MAAMA,uBAAuB;MAEvBC,8BAAiC,GAAA;AAAC,IAAA,KAAA;AAAO,IAAA,QAAA;AAAU,IAAA;;MAEnDC,iCAAoC,GAAA;AAAC,IAAA,OAAA;AAAS,IAAA;;MAE9CC,yBAA4B,GAAA;AAAC,IAAA,iBAAA;AAAmB,IAAA;;MAEhDC,uBAA0B,GAAA;;AAErC,IAAA,IAAA;AACA,IAAA,KAAA;AACA,IAAA,IAAA;;AAEA,IAAA,KAAA;AACA,IAAA;;MAGWC,uBAA0B,GAAA;AAAC,IAAA;;MAE3BC,0BAA6B,GAAA;AAAIF,IAAAA,GAAAA,uBAAAA;AAA4BC,IAAAA,GAAAA;;AAEnE,MAAME,+BAA+B;MAE/BC,sBAAyB,GAAA,CAAA,EAAGD,4BAA6B,CAAA,MAAM;;;;"}
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var project = require('./project.js');
4
+ var constants = require('./constants.js');
5
+ var utils = require('./utils.js');
6
+
7
+
8
+
9
+ exports.projectFactory = project.projectFactory;
10
+ exports.constants = constants;
11
+ exports.assertAppProject = utils.assertAppProject;
12
+ exports.assertPluginProject = utils.assertPluginProject;
13
+ exports.isApplicationProject = utils.isApplicationProject;
14
+ exports.isPluginProject = utils.isPluginProject;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -0,0 +1,5 @@
1
+ export { projectFactory } from './project.mjs';
2
+ import * as constants from './constants.mjs';
3
+ export { constants };
4
+ export { assertAppProject, assertPluginProject, isApplicationProject, isPluginProject } from './utils.mjs';
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,205 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var assert = require('node:assert');
5
+ var fse = require('fs-extra');
6
+ var semver$1 = require('semver');
7
+ var semver = require('../version/semver.js');
8
+ var scanner = require('../file-scanner/scanner.js');
9
+ var code = require('../runner/code/code.js');
10
+ var json = require('../runner/json/json.js');
11
+ var constants = require('./constants.js');
12
+
13
+ class Project {
14
+ getFilesByExtensions(extensions) {
15
+ return this.files.filter((filePath)=>{
16
+ const fileExtension = path.extname(filePath);
17
+ return extensions.includes(fileExtension);
18
+ });
19
+ }
20
+ refresh() {
21
+ this.refreshPackageJSON();
22
+ this.refreshProjectFiles();
23
+ return this;
24
+ }
25
+ async runCodemods(codemods, options) {
26
+ const runners = this.createProjectCodemodsRunners(options.dry);
27
+ const reports = [];
28
+ for (const codemod of codemods){
29
+ for (const runner of runners){
30
+ if (runner.valid(codemod)) {
31
+ const report = await runner.run(codemod);
32
+ reports.push({
33
+ codemod,
34
+ report
35
+ });
36
+ }
37
+ }
38
+ }
39
+ return reports;
40
+ }
41
+ createProjectCodemodsRunners(dry = false) {
42
+ const jsonExtensions = constants.PROJECT_JSON_EXTENSIONS.map((ext)=>`.${ext}`);
43
+ const codeExtensions = constants.PROJECT_CODE_EXTENSIONS.map((ext)=>`.${ext}`);
44
+ const jsonFiles = this.getFilesByExtensions(jsonExtensions);
45
+ const codeFiles = this.getFilesByExtensions(codeExtensions);
46
+ const codeRunner = code.codeRunnerFactory(codeFiles, {
47
+ dry,
48
+ parser: 'ts',
49
+ runInBand: true,
50
+ babel: true,
51
+ extensions: constants.PROJECT_CODE_EXTENSIONS.join(','),
52
+ // Don't output any log coming from the runner
53
+ print: false,
54
+ silent: true,
55
+ verbose: 0
56
+ });
57
+ const jsonRunner = json.jsonRunnerFactory(jsonFiles, {
58
+ dry,
59
+ cwd: this.cwd
60
+ });
61
+ return [
62
+ codeRunner,
63
+ jsonRunner
64
+ ];
65
+ }
66
+ refreshPackageJSON() {
67
+ const packageJSONPath = path.join(this.cwd, constants.PROJECT_PACKAGE_JSON);
68
+ try {
69
+ fse.accessSync(packageJSONPath);
70
+ } catch {
71
+ throw new Error(`Could not find a ${constants.PROJECT_PACKAGE_JSON} file in ${this.cwd}`);
72
+ }
73
+ const packageJSONBuffer = fse.readFileSync(packageJSONPath);
74
+ this.packageJSONPath = packageJSONPath;
75
+ this.packageJSON = JSON.parse(packageJSONBuffer.toString());
76
+ }
77
+ refreshProjectFiles() {
78
+ const scanner$1 = scanner.fileScannerFactory(this.cwd);
79
+ this.files = scanner$1.scan(this.paths);
80
+ }
81
+ constructor(cwd, config){
82
+ if (!fse.pathExistsSync(cwd)) {
83
+ throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
84
+ }
85
+ this.cwd = cwd;
86
+ this.paths = config.paths;
87
+ this.refresh();
88
+ }
89
+ }
90
+ class AppProject extends Project {
91
+ /**
92
+ * Returns an array of allowed file paths for a Strapi application
93
+ *
94
+ * The resulting paths include app default files and the root package.json file.
95
+ */ static get paths() {
96
+ const allowedRootPaths = formatGlobCollectionPattern(constants.PROJECT_APP_ALLOWED_ROOT_PATHS);
97
+ const allowedExtensions = formatGlobCollectionPattern(constants.PROJECT_ALLOWED_EXTENSIONS);
98
+ return [
99
+ // App default files
100
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
101
+ `!./**/node_modules/**/*`,
102
+ `!./**/dist/**/*`,
103
+ // Root package.json file
104
+ constants.PROJECT_PACKAGE_JSON
105
+ ];
106
+ }
107
+ refresh() {
108
+ super.refresh();
109
+ this.refreshStrapiVersion();
110
+ return this;
111
+ }
112
+ refreshStrapiVersion() {
113
+ this.strapiVersion = // First try to get the strapi version from the package.json dependencies
114
+ this.findStrapiVersionFromProjectPackageJSON() ?? // If the version found is not a valid SemVer, get the Strapi version from the installed package
115
+ this.findLocallyInstalledStrapiVersion();
116
+ }
117
+ findStrapiVersionFromProjectPackageJSON() {
118
+ const projectName = this.packageJSON.name;
119
+ const version = this.packageJSON.dependencies?.[constants.STRAPI_DEPENDENCY_NAME];
120
+ if (version === undefined) {
121
+ throw new Error(`No version of ${constants.STRAPI_DEPENDENCY_NAME} was found in ${projectName}. Are you in a valid Strapi project?`);
122
+ }
123
+ const isValidSemVer = semver.isLiteralSemVer(version) && semver$1.valid(version) === version;
124
+ // We return undefined only if a strapi/strapi version is found, but it's not semver compliant
125
+ return isValidSemVer ? semver.semVerFactory(version) : undefined;
126
+ }
127
+ findLocallyInstalledStrapiVersion() {
128
+ const packageSearchText = `${constants.STRAPI_DEPENDENCY_NAME}/package.json`;
129
+ let strapiPackageJSONPath;
130
+ let strapiPackageJSON;
131
+ try {
132
+ strapiPackageJSONPath = require.resolve(packageSearchText, {
133
+ paths: [
134
+ this.cwd
135
+ ]
136
+ });
137
+ strapiPackageJSON = require(strapiPackageJSONPath);
138
+ assert(typeof strapiPackageJSON === 'object');
139
+ } catch {
140
+ throw new Error(`Cannot resolve module "${constants.STRAPI_DEPENDENCY_NAME}" from paths [${this.cwd}]`);
141
+ }
142
+ const strapiVersion = strapiPackageJSON.version;
143
+ if (!semver.isValidSemVer(strapiVersion)) {
144
+ throw new Error(`Invalid ${constants.STRAPI_DEPENDENCY_NAME} version found in ${strapiPackageJSONPath} (${strapiVersion})`);
145
+ }
146
+ return semver.semVerFactory(strapiVersion);
147
+ }
148
+ constructor(cwd){
149
+ super(cwd, {
150
+ paths: AppProject.paths
151
+ }), this.type = 'application';
152
+ this.refreshStrapiVersion();
153
+ }
154
+ }
155
+ const formatGlobCollectionPattern = (collection)=>{
156
+ assert(collection.length > 0, 'Invalid pattern provided, the given collection needs at least 1 element');
157
+ return collection.length === 1 ? collection[0] : `{${collection}}`;
158
+ };
159
+ class PluginProject extends Project {
160
+ /**
161
+ * Returns an array of allowed file paths for a Strapi plugin
162
+ *
163
+ * The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
164
+ */ static get paths() {
165
+ const allowedRootPaths = formatGlobCollectionPattern(constants.PROJECT_PLUGIN_ALLOWED_ROOT_PATHS);
166
+ const allowedExtensions = formatGlobCollectionPattern(constants.PROJECT_ALLOWED_EXTENSIONS);
167
+ return [
168
+ // Plugin default files
169
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
170
+ `!./**/node_modules/**/*`,
171
+ `!./**/dist/**/*`,
172
+ // Root package.json file
173
+ constants.PROJECT_PACKAGE_JSON,
174
+ // Plugin root files
175
+ ...constants.PROJECT_PLUGIN_ROOT_FILES
176
+ ];
177
+ }
178
+ constructor(cwd){
179
+ super(cwd, {
180
+ paths: PluginProject.paths
181
+ }), this.type = 'plugin';
182
+ }
183
+ }
184
+ const isPlugin = (cwd)=>{
185
+ const packageJSONPath = path.join(cwd, constants.PROJECT_PACKAGE_JSON);
186
+ try {
187
+ fse.accessSync(packageJSONPath);
188
+ } catch {
189
+ throw new Error(`Could not find a ${constants.PROJECT_PACKAGE_JSON} file in ${cwd}`);
190
+ }
191
+ const packageJSONBuffer = fse.readFileSync(packageJSONPath);
192
+ const packageJSON = JSON.parse(packageJSONBuffer.toString());
193
+ return packageJSON?.strapi?.kind === 'plugin';
194
+ };
195
+ // TODO: make this async so we can use async file methods
196
+ const projectFactory = (cwd)=>{
197
+ fse.accessSync(cwd);
198
+ return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
199
+ };
200
+
201
+ exports.AppProject = AppProject;
202
+ exports.PluginProject = PluginProject;
203
+ exports.Project = Project;
204
+ exports.projectFactory = projectFactory;
205
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sources":["../../../../src/modules/project/project.ts"],"sourcesContent":["import path from 'node:path';\nimport assert from 'node:assert';\nimport fse from 'fs-extra';\nimport semver from 'semver';\n\nimport { semVerFactory, isLiteralSemVer, isValidSemVer } from '../version';\nimport { fileScannerFactory } from '../file-scanner';\nimport { codeRunnerFactory } from '../runner/code';\nimport { jsonRunnerFactory } from '../runner/json';\nimport * as constants from './constants';\n\nimport type { Version } from '../version';\nimport type { Codemod } from '../codemod';\nimport type { Report } from '../report';\nimport type {\n FileExtension,\n MinimalPackageJSON,\n ProjectConfig,\n ProjectType,\n RunCodemodsOptions,\n} from './types';\n\nexport class Project {\n public cwd: string;\n\n // The following properties are assigned during the .refresh() call in the constructor.\n\n public files!: string[];\n\n public packageJSONPath!: string;\n\n public packageJSON!: MinimalPackageJSON;\n\n public readonly paths: string[];\n\n constructor(cwd: string, config: ProjectConfig) {\n if (!fse.pathExistsSync(cwd)) {\n throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);\n }\n\n this.cwd = cwd;\n this.paths = config.paths;\n\n this.refresh();\n }\n\n getFilesByExtensions(extensions: FileExtension[]) {\n return this.files.filter((filePath) => {\n const fileExtension = path.extname(filePath) as FileExtension;\n\n return extensions.includes(fileExtension);\n });\n }\n\n refresh() {\n this.refreshPackageJSON();\n this.refreshProjectFiles();\n\n return this;\n }\n\n async runCodemods(codemods: Codemod.List, options: RunCodemodsOptions) {\n const runners = this.createProjectCodemodsRunners(options.dry);\n const reports: Report.CodemodReport[] = [];\n\n for (const codemod of codemods) {\n for (const runner of runners) {\n if (runner.valid(codemod)) {\n const report = await runner.run(codemod);\n reports.push({ codemod, report });\n }\n }\n }\n\n return reports;\n }\n\n private createProjectCodemodsRunners(dry: boolean = false) {\n const jsonExtensions = constants.PROJECT_JSON_EXTENSIONS.map<FileExtension>((ext) => `.${ext}`);\n const codeExtensions = constants.PROJECT_CODE_EXTENSIONS.map<FileExtension>((ext) => `.${ext}`);\n\n const jsonFiles = this.getFilesByExtensions(jsonExtensions);\n const codeFiles = this.getFilesByExtensions(codeExtensions);\n\n const codeRunner = codeRunnerFactory(codeFiles, {\n dry,\n parser: 'ts',\n runInBand: true,\n babel: true,\n extensions: constants.PROJECT_CODE_EXTENSIONS.join(','),\n // Don't output any log coming from the runner\n print: false,\n silent: true,\n verbose: 0,\n });\n\n const jsonRunner = jsonRunnerFactory(jsonFiles, { dry, cwd: this.cwd });\n\n return [codeRunner, jsonRunner] as const;\n }\n\n private refreshPackageJSON(): void {\n const packageJSONPath = path.join(this.cwd, constants.PROJECT_PACKAGE_JSON);\n\n try {\n fse.accessSync(packageJSONPath);\n } catch {\n throw new Error(`Could not find a ${constants.PROJECT_PACKAGE_JSON} file in ${this.cwd}`);\n }\n\n const packageJSONBuffer = fse.readFileSync(packageJSONPath);\n\n this.packageJSONPath = packageJSONPath;\n this.packageJSON = JSON.parse(packageJSONBuffer.toString());\n }\n\n private refreshProjectFiles(): void {\n const scanner = fileScannerFactory(this.cwd);\n\n this.files = scanner.scan(this.paths);\n }\n}\n\nexport class AppProject extends Project {\n public strapiVersion!: Version.SemVer;\n\n readonly type = 'application' as const satisfies ProjectType;\n\n /**\n * Returns an array of allowed file paths for a Strapi application\n *\n * The resulting paths include app default files and the root package.json file.\n */\n private static get paths() {\n const allowedRootPaths = formatGlobCollectionPattern(constants.PROJECT_APP_ALLOWED_ROOT_PATHS);\n const allowedExtensions = formatGlobCollectionPattern(constants.PROJECT_ALLOWED_EXTENSIONS);\n\n return [\n // App default files\n `./${allowedRootPaths}/**/*.${allowedExtensions}`,\n `!./**/node_modules/**/*`,\n `!./**/dist/**/*`,\n // Root package.json file\n constants.PROJECT_PACKAGE_JSON,\n ];\n }\n\n constructor(cwd: string) {\n super(cwd, { paths: AppProject.paths });\n this.refreshStrapiVersion();\n }\n\n refresh() {\n super.refresh();\n this.refreshStrapiVersion();\n return this;\n }\n\n private refreshStrapiVersion(): void {\n this.strapiVersion =\n // First try to get the strapi version from the package.json dependencies\n this.findStrapiVersionFromProjectPackageJSON() ??\n // If the version found is not a valid SemVer, get the Strapi version from the installed package\n this.findLocallyInstalledStrapiVersion();\n }\n\n private findStrapiVersionFromProjectPackageJSON(): Version.SemVer | undefined {\n const projectName = this.packageJSON.name;\n const version = this.packageJSON.dependencies?.[constants.STRAPI_DEPENDENCY_NAME];\n\n if (version === undefined) {\n throw new Error(\n `No version of ${constants.STRAPI_DEPENDENCY_NAME} was found in ${projectName}. Are you in a valid Strapi project?`\n );\n }\n\n const isValidSemVer = isLiteralSemVer(version) && semver.valid(version) === version;\n\n // We return undefined only if a strapi/strapi version is found, but it's not semver compliant\n return isValidSemVer ? semVerFactory(version) : undefined;\n }\n\n private findLocallyInstalledStrapiVersion(): Version.SemVer {\n const packageSearchText = `${constants.STRAPI_DEPENDENCY_NAME}/package.json`;\n\n let strapiPackageJSONPath: string;\n let strapiPackageJSON: MinimalPackageJSON;\n\n try {\n strapiPackageJSONPath = require.resolve(packageSearchText, { paths: [this.cwd] });\n strapiPackageJSON = require(strapiPackageJSONPath);\n\n assert(typeof strapiPackageJSON === 'object');\n } catch {\n throw new Error(\n `Cannot resolve module \"${constants.STRAPI_DEPENDENCY_NAME}\" from paths [${this.cwd}]`\n );\n }\n\n const strapiVersion = strapiPackageJSON.version;\n\n if (!isValidSemVer(strapiVersion)) {\n throw new Error(\n `Invalid ${constants.STRAPI_DEPENDENCY_NAME} version found in ${strapiPackageJSONPath} (${strapiVersion})`\n );\n }\n\n return semVerFactory(strapiVersion);\n }\n}\n\nconst formatGlobCollectionPattern = (collection: string[]): string => {\n assert(\n collection.length > 0,\n 'Invalid pattern provided, the given collection needs at least 1 element'\n );\n\n return collection.length === 1 ? collection[0] : `{${collection}}`;\n};\n\nexport class PluginProject extends Project {\n readonly type = 'plugin' as const satisfies ProjectType;\n\n /**\n * Returns an array of allowed file paths for a Strapi plugin\n *\n * The resulting paths include plugin default files, the root package.json file, and plugin-specific files.\n */\n private static get paths() {\n const allowedRootPaths = formatGlobCollectionPattern(\n constants.PROJECT_PLUGIN_ALLOWED_ROOT_PATHS\n );\n const allowedExtensions = formatGlobCollectionPattern(constants.PROJECT_ALLOWED_EXTENSIONS);\n\n return [\n // Plugin default files\n `./${allowedRootPaths}/**/*.${allowedExtensions}`,\n `!./**/node_modules/**/*`,\n `!./**/dist/**/*`,\n // Root package.json file\n constants.PROJECT_PACKAGE_JSON,\n // Plugin root files\n ...constants.PROJECT_PLUGIN_ROOT_FILES,\n ];\n }\n\n constructor(cwd: string) {\n super(cwd, { paths: PluginProject.paths });\n }\n}\n\nconst isPlugin = (cwd: string) => {\n const packageJSONPath = path.join(cwd, constants.PROJECT_PACKAGE_JSON);\n\n try {\n fse.accessSync(packageJSONPath);\n } catch {\n throw new Error(`Could not find a ${constants.PROJECT_PACKAGE_JSON} file in ${cwd}`);\n }\n\n const packageJSONBuffer = fse.readFileSync(packageJSONPath);\n\n const packageJSON = JSON.parse(packageJSONBuffer.toString());\n\n return packageJSON?.strapi?.kind === 'plugin';\n};\n\n// TODO: make this async so we can use async file methods\nexport const projectFactory = (cwd: string) => {\n fse.accessSync(cwd);\n\n return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);\n};\n"],"names":["Project","getFilesByExtensions","extensions","files","filter","filePath","fileExtension","path","extname","includes","refresh","refreshPackageJSON","refreshProjectFiles","runCodemods","codemods","options","runners","createProjectCodemodsRunners","dry","reports","codemod","runner","valid","report","run","push","jsonExtensions","constants","map","ext","codeExtensions","jsonFiles","codeFiles","codeRunner","codeRunnerFactory","parser","runInBand","babel","join","print","silent","verbose","jsonRunner","jsonRunnerFactory","cwd","packageJSONPath","fse","accessSync","Error","packageJSONBuffer","readFileSync","packageJSON","JSON","parse","toString","scanner","fileScannerFactory","scan","paths","config","pathExistsSync","AppProject","allowedRootPaths","formatGlobCollectionPattern","allowedExtensions","refreshStrapiVersion","strapiVersion","findStrapiVersionFromProjectPackageJSON","findLocallyInstalledStrapiVersion","projectName","name","version","dependencies","undefined","isValidSemVer","isLiteralSemVer","semver","semVerFactory","packageSearchText","strapiPackageJSONPath","strapiPackageJSON","require","resolve","assert","type","collection","length","PluginProject","isPlugin","strapi","kind","projectFactory"],"mappings":";;;;;;;;;;;;AAsBO,MAAMA,OAAAA,CAAAA;AAwBXC,IAAAA,oBAAAA,CAAqBC,UAA2B,EAAE;AAChD,QAAA,OAAO,IAAI,CAACC,KAAK,CAACC,MAAM,CAAC,CAACC,QAAAA,GAAAA;YACxB,MAAMC,aAAAA,GAAg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AIC,UAAU,CAACF,eAAAA,CAAAA;AACjB,KAAA,CAAE,OAAM;QACN,MAAM,IAAIG,KAAM,CAAA,CAAC,iBAAiB,EAAErB,8BAA8B,CAAC,SAAS,EAAEiB,GAAK,CAAA,CAAA,CAAA;AACrF;IAEA,MAAMK,iBAAAA,GAAoBH,GAAII,CAAAA,YAAY,CAACL,eAAAA,CAAAA;AAE3C,IAAA,MAAMM,WAAcC,GAAAA,IAAAA,CAAKC,KAAK,CAACJ,kBAAkBK,QAAQ,EAAA,CAAA;IAEzD,OAAOH,WAAAA,EAAasC,QAAQC,IAAS,KAAA,QAAA;AACvC,CAAA;AAEA;AACO,MAAMC,iBAAiB,CAAC/C,GAAAA,GAAAA;AAC7BE,IAAAA,GAAAA,CAAIC,UAAU,CAACH,GAAAA,CAAAA;AAEf,IAAA,OAAO4C,SAAS5C,GAAO,CAAA,GAAA,IAAI2C,aAAc3C,CAAAA,GAAAA,CAAAA,GAAO,IAAIiB,UAAWjB,CAAAA,GAAAA,CAAAA;AACjE;;;;;;;"}
@@ -0,0 +1,200 @@
1
+ import path from 'node:path';
2
+ import assert from 'node:assert';
3
+ import fse from 'fs-extra';
4
+ import semver from 'semver';
5
+ import { isLiteralSemVer, semVerFactory, isValidSemVer } from '../version/semver.mjs';
6
+ import { fileScannerFactory } from '../file-scanner/scanner.mjs';
7
+ import { codeRunnerFactory } from '../runner/code/code.mjs';
8
+ import { jsonRunnerFactory } from '../runner/json/json.mjs';
9
+ import { PROJECT_PACKAGE_JSON, STRAPI_DEPENDENCY_NAME, PROJECT_PLUGIN_ALLOWED_ROOT_PATHS, PROJECT_ALLOWED_EXTENSIONS, PROJECT_PLUGIN_ROOT_FILES, PROJECT_JSON_EXTENSIONS, PROJECT_CODE_EXTENSIONS, PROJECT_APP_ALLOWED_ROOT_PATHS } from './constants.mjs';
10
+
11
+ class Project {
12
+ getFilesByExtensions(extensions) {
13
+ return this.files.filter((filePath)=>{
14
+ const fileExtension = path.extname(filePath);
15
+ return extensions.includes(fileExtension);
16
+ });
17
+ }
18
+ refresh() {
19
+ this.refreshPackageJSON();
20
+ this.refreshProjectFiles();
21
+ return this;
22
+ }
23
+ async runCodemods(codemods, options) {
24
+ const runners = this.createProjectCodemodsRunners(options.dry);
25
+ const reports = [];
26
+ for (const codemod of codemods){
27
+ for (const runner of runners){
28
+ if (runner.valid(codemod)) {
29
+ const report = await runner.run(codemod);
30
+ reports.push({
31
+ codemod,
32
+ report
33
+ });
34
+ }
35
+ }
36
+ }
37
+ return reports;
38
+ }
39
+ createProjectCodemodsRunners(dry = false) {
40
+ const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext)=>`.${ext}`);
41
+ const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext)=>`.${ext}`);
42
+ const jsonFiles = this.getFilesByExtensions(jsonExtensions);
43
+ const codeFiles = this.getFilesByExtensions(codeExtensions);
44
+ const codeRunner = codeRunnerFactory(codeFiles, {
45
+ dry,
46
+ parser: 'ts',
47
+ runInBand: true,
48
+ babel: true,
49
+ extensions: PROJECT_CODE_EXTENSIONS.join(','),
50
+ // Don't output any log coming from the runner
51
+ print: false,
52
+ silent: true,
53
+ verbose: 0
54
+ });
55
+ const jsonRunner = jsonRunnerFactory(jsonFiles, {
56
+ dry,
57
+ cwd: this.cwd
58
+ });
59
+ return [
60
+ codeRunner,
61
+ jsonRunner
62
+ ];
63
+ }
64
+ refreshPackageJSON() {
65
+ const packageJSONPath = path.join(this.cwd, PROJECT_PACKAGE_JSON);
66
+ try {
67
+ fse.accessSync(packageJSONPath);
68
+ } catch {
69
+ throw new Error(`Could not find a ${PROJECT_PACKAGE_JSON} file in ${this.cwd}`);
70
+ }
71
+ const packageJSONBuffer = fse.readFileSync(packageJSONPath);
72
+ this.packageJSONPath = packageJSONPath;
73
+ this.packageJSON = JSON.parse(packageJSONBuffer.toString());
74
+ }
75
+ refreshProjectFiles() {
76
+ const scanner = fileScannerFactory(this.cwd);
77
+ this.files = scanner.scan(this.paths);
78
+ }
79
+ constructor(cwd, config){
80
+ if (!fse.pathExistsSync(cwd)) {
81
+ throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
82
+ }
83
+ this.cwd = cwd;
84
+ this.paths = config.paths;
85
+ this.refresh();
86
+ }
87
+ }
88
+ class AppProject extends Project {
89
+ /**
90
+ * Returns an array of allowed file paths for a Strapi application
91
+ *
92
+ * The resulting paths include app default files and the root package.json file.
93
+ */ static get paths() {
94
+ const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
95
+ const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
96
+ return [
97
+ // App default files
98
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
99
+ `!./**/node_modules/**/*`,
100
+ `!./**/dist/**/*`,
101
+ // Root package.json file
102
+ PROJECT_PACKAGE_JSON
103
+ ];
104
+ }
105
+ refresh() {
106
+ super.refresh();
107
+ this.refreshStrapiVersion();
108
+ return this;
109
+ }
110
+ refreshStrapiVersion() {
111
+ this.strapiVersion = // First try to get the strapi version from the package.json dependencies
112
+ this.findStrapiVersionFromProjectPackageJSON() ?? // If the version found is not a valid SemVer, get the Strapi version from the installed package
113
+ this.findLocallyInstalledStrapiVersion();
114
+ }
115
+ findStrapiVersionFromProjectPackageJSON() {
116
+ const projectName = this.packageJSON.name;
117
+ const version = this.packageJSON.dependencies?.[STRAPI_DEPENDENCY_NAME];
118
+ if (version === undefined) {
119
+ throw new Error(`No version of ${STRAPI_DEPENDENCY_NAME} was found in ${projectName}. Are you in a valid Strapi project?`);
120
+ }
121
+ const isValidSemVer = isLiteralSemVer(version) && semver.valid(version) === version;
122
+ // We return undefined only if a strapi/strapi version is found, but it's not semver compliant
123
+ return isValidSemVer ? semVerFactory(version) : undefined;
124
+ }
125
+ findLocallyInstalledStrapiVersion() {
126
+ const packageSearchText = `${STRAPI_DEPENDENCY_NAME}/package.json`;
127
+ let strapiPackageJSONPath;
128
+ let strapiPackageJSON;
129
+ try {
130
+ strapiPackageJSONPath = require.resolve(packageSearchText, {
131
+ paths: [
132
+ this.cwd
133
+ ]
134
+ });
135
+ strapiPackageJSON = require(strapiPackageJSONPath);
136
+ assert(typeof strapiPackageJSON === 'object');
137
+ } catch {
138
+ throw new Error(`Cannot resolve module "${STRAPI_DEPENDENCY_NAME}" from paths [${this.cwd}]`);
139
+ }
140
+ const strapiVersion = strapiPackageJSON.version;
141
+ if (!isValidSemVer(strapiVersion)) {
142
+ throw new Error(`Invalid ${STRAPI_DEPENDENCY_NAME} version found in ${strapiPackageJSONPath} (${strapiVersion})`);
143
+ }
144
+ return semVerFactory(strapiVersion);
145
+ }
146
+ constructor(cwd){
147
+ super(cwd, {
148
+ paths: AppProject.paths
149
+ }), this.type = 'application';
150
+ this.refreshStrapiVersion();
151
+ }
152
+ }
153
+ const formatGlobCollectionPattern = (collection)=>{
154
+ assert(collection.length > 0, 'Invalid pattern provided, the given collection needs at least 1 element');
155
+ return collection.length === 1 ? collection[0] : `{${collection}}`;
156
+ };
157
+ class PluginProject extends Project {
158
+ /**
159
+ * Returns an array of allowed file paths for a Strapi plugin
160
+ *
161
+ * The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
162
+ */ static get paths() {
163
+ const allowedRootPaths = formatGlobCollectionPattern(PROJECT_PLUGIN_ALLOWED_ROOT_PATHS);
164
+ const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
165
+ return [
166
+ // Plugin default files
167
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
168
+ `!./**/node_modules/**/*`,
169
+ `!./**/dist/**/*`,
170
+ // Root package.json file
171
+ PROJECT_PACKAGE_JSON,
172
+ // Plugin root files
173
+ ...PROJECT_PLUGIN_ROOT_FILES
174
+ ];
175
+ }
176
+ constructor(cwd){
177
+ super(cwd, {
178
+ paths: PluginProject.paths
179
+ }), this.type = 'plugin';
180
+ }
181
+ }
182
+ const isPlugin = (cwd)=>{
183
+ const packageJSONPath = path.join(cwd, PROJECT_PACKAGE_JSON);
184
+ try {
185
+ fse.accessSync(packageJSONPath);
186
+ } catch {
187
+ throw new Error(`Could not find a ${PROJECT_PACKAGE_JSON} file in ${cwd}`);
188
+ }
189
+ const packageJSONBuffer = fse.readFileSync(packageJSONPath);
190
+ const packageJSON = JSON.parse(packageJSONBuffer.toString());
191
+ return packageJSON?.strapi?.kind === 'plugin';
192
+ };
193
+ // TODO: make this async so we can use async file methods
194
+ const projectFactory = (cwd)=>{
195
+ fse.accessSync(cwd);
196
+ return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
197
+ };
198
+
199
+ export { AppProject, PluginProject, Project, projectFactory };
200
+ //# sourceMappingURL=project.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.mjs","sources":["../../../../src/modules/project/project.ts"],"sourcesContent":["import path from 'node:path';\nimport assert from 'node:assert';\nimport fse from 'fs-extra';\nimport semver from 'semver';\n\nimport { semVerFactory, isLiteralSemVer, isValidSemVer } from '../version';\nimport { fileScannerFactory } from '../file-scanner';\nimport { codeRunnerFactory } from '../runner/code';\nimport { jsonRunnerFactory } from '../runner/json';\nimport * as constants from './constants';\n\nimport type { Version } from '../version';\nimport type { Codemod } from '../codemod';\nimport type { Report } from '../report';\nimport type {\n FileExtension,\n MinimalPackageJSON,\n ProjectConfig,\n ProjectType,\n RunCodemodsOptions,\n} from './types';\n\nexport class Project {\n public cwd: string;\n\n // The following properties are assigned during the .refresh() call in the constructor.\n\n public files!: string[];\n\n public packageJSONPath!: string;\n\n public packageJSON!: MinimalPackageJSON;\n\n public readonly paths: string[];\n\n constructor(cwd: string, config: ProjectConfig) {\n if (!fse.pathExistsSync(cwd)) {\n throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);\n }\n\n this.cwd = cwd;\n this.paths = config.paths;\n\n this.refresh();\n }\n\n getFilesByExtensions(extensions: FileExtension[]) {\n return this.files.filter((filePath) => {\n const fileExtension = path.extname(filePath) as FileExtension;\n\n return extensions.includes(fileExtension);\n });\n }\n\n refresh() {\n this.refreshPackageJSON();\n this.refreshProjectFiles();\n\n return this;\n }\n\n async runCodemods(codemods: Codemod.List, options: RunCodemodsOptions) {\n const runners = this.createProjectCodemodsRunners(options.dry);\n const reports: Report.CodemodReport[] = [];\n\n for (const codemod of codemods) {\n for (const runner of runners) {\n if (runner.valid(codemod)) {\n const report = await runner.run(codemod);\n reports.push({ codemod, report });\n }\n }\n }\n\n return reports;\n }\n\n private createProjectCodemodsRunners(dry: boolean = false) {\n const jsonExtensions = constants.PROJECT_JSON_EXTENSIONS.map<FileExtension>((ext) => `.${ext}`);\n const codeExtensions = constants.PROJECT_CODE_EXTENSIONS.map<FileExtension>((ext) => `.${ext}`);\n\n const jsonFiles = this.getFilesByExtensions(jsonExtensions);\n const codeFiles = this.getFilesByExtensions(codeExtensions);\n\n const codeRunner = codeRunnerFactory(codeFiles, {\n dry,\n parser: 'ts',\n runInBand: true,\n babel: true,\n extensions: constants.PROJECT_CODE_EXTENSIONS.join(','),\n // Don't output any log coming from the runner\n print: false,\n silent: true,\n verbose: 0,\n });\n\n const jsonRunner = jsonRunnerFactory(jsonFiles, { dry, cwd: this.cwd });\n\n return [codeRunner, jsonRunner] as const;\n }\n\n private refreshPackageJSON(): void {\n const packageJSONPath = path.join(this.cwd, constants.PROJECT_PACKAGE_JSON);\n\n try {\n fse.accessSync(packageJSONPath);\n } catch {\n throw new Error(`Could not find a ${constants.PROJECT_PACKAGE_JSON} file in ${this.cwd}`);\n }\n\n const packageJSONBuffer = fse.readFileSync(packageJSONPath);\n\n this.packageJSONPath = packageJSONPath;\n this.packageJSON = JSON.parse(packageJSONBuffer.toString());\n }\n\n private refreshProjectFiles(): void {\n const scanner = fileScannerFactory(this.cwd);\n\n this.files = scanner.scan(this.paths);\n }\n}\n\nexport class AppProject extends Project {\n public strapiVersion!: Version.SemVer;\n\n readonly type = 'application' as const satisfies ProjectType;\n\n /**\n * Returns an array of allowed file paths for a Strapi application\n *\n * The resulting paths include app default files and the root package.json file.\n */\n private static get paths() {\n const allowedRootPaths = formatGlobCollectionPattern(constants.PROJECT_APP_ALLOWED_ROOT_PATHS);\n const allowedExtensions = formatGlobCollectionPattern(constants.PROJECT_ALLOWED_EXTENSIONS);\n\n return [\n // App default files\n `./${allowedRootPaths}/**/*.${allowedExtensions}`,\n `!./**/node_modules/**/*`,\n `!./**/dist/**/*`,\n // Root package.json file\n constants.PROJECT_PACKAGE_JSON,\n ];\n }\n\n constructor(cwd: string) {\n super(cwd, { paths: AppProject.paths });\n this.refreshStrapiVersion();\n }\n\n refresh() {\n super.refresh();\n this.refreshStrapiVersion();\n return this;\n }\n\n private refreshStrapiVersion(): void {\n this.strapiVersion =\n // First try to get the strapi version from the package.json dependencies\n this.findStrapiVersionFromProjectPackageJSON() ??\n // If the version found is not a valid SemVer, get the Strapi version from the installed package\n this.findLocallyInstalledStrapiVersion();\n }\n\n private findStrapiVersionFromProjectPackageJSON(): Version.SemVer | undefined {\n const projectName = this.packageJSON.name;\n const version = this.packageJSON.dependencies?.[constants.STRAPI_DEPENDENCY_NAME];\n\n if (version === undefined) {\n throw new Error(\n `No version of ${constants.STRAPI_DEPENDENCY_NAME} was found in ${projectName}. Are you in a valid Strapi project?`\n );\n }\n\n const isValidSemVer = isLiteralSemVer(version) && semver.valid(version) === version;\n\n // We return undefined only if a strapi/strapi version is found, but it's not semver compliant\n return isValidSemVer ? semVerFactory(version) : undefined;\n }\n\n private findLocallyInstalledStrapiVersion(): Version.SemVer {\n const packageSearchText = `${constants.STRAPI_DEPENDENCY_NAME}/package.json`;\n\n let strapiPackageJSONPath: string;\n let strapiPackageJSON: MinimalPackageJSON;\n\n try {\n strapiPackageJSONPath = require.resolve(packageSearchText, { paths: [this.cwd] });\n strapiPackageJSON = require(strapiPackageJSONPath);\n\n assert(typeof strapiPackageJSON === 'object');\n } catch {\n throw new Error(\n `Cannot resolve module \"${constants.STRAPI_DEPENDENCY_NAME}\" from paths [${this.cwd}]`\n );\n }\n\n const strapiVersion = strapiPackageJSON.version;\n\n if (!isValidSemVer(strapiVersion)) {\n throw new Error(\n `Invalid ${constants.STRAPI_DEPENDENCY_NAME} version found in ${strapiPackageJSONPath} (${strapiVersion})`\n );\n }\n\n return semVerFactory(strapiVersion);\n }\n}\n\nconst formatGlobCollectionPattern = (collection: string[]): string => {\n assert(\n collection.length > 0,\n 'Invalid pattern provided, the given collection needs at least 1 element'\n );\n\n return collection.length === 1 ? collection[0] : `{${collection}}`;\n};\n\nexport class PluginProject extends Project {\n readonly type = 'plugin' as const satisfies ProjectType;\n\n /**\n * Returns an array of allowed file paths for a Strapi plugin\n *\n * The resulting paths include plugin default files, the root package.json file, and plugin-specific files.\n */\n private static get paths() {\n const allowedRootPaths = formatGlobCollectionPattern(\n constants.PROJECT_PLUGIN_ALLOWED_ROOT_PATHS\n );\n const allowedExtensions = formatGlobCollectionPattern(constants.PROJECT_ALLOWED_EXTENSIONS);\n\n return [\n // Plugin default files\n `./${allowedRootPaths}/**/*.${allowedExtensions}`,\n `!./**/node_modules/**/*`,\n `!./**/dist/**/*`,\n // Root package.json file\n constants.PROJECT_PACKAGE_JSON,\n // Plugin root files\n ...constants.PROJECT_PLUGIN_ROOT_FILES,\n ];\n }\n\n constructor(cwd: string) {\n super(cwd, { paths: PluginProject.paths });\n }\n}\n\nconst isPlugin = (cwd: string) => {\n const packageJSONPath = path.join(cwd, constants.PROJECT_PACKAGE_JSON);\n\n try {\n fse.accessSync(packageJSONPath);\n } catch {\n throw new Error(`Could not find a ${constants.PROJECT_PACKAGE_JSON} file in ${cwd}`);\n }\n\n const packageJSONBuffer = fse.readFileSync(packageJSONPath);\n\n const packageJSON = JSON.parse(packageJSONBuffer.toString());\n\n return packageJSON?.strapi?.kind === 'plugin';\n};\n\n// TODO: make this async so we can use async file methods\nexport const projectFactory = (cwd: string) => {\n fse.accessSync(cwd);\n\n return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);\n};\n"],"names":["Project","getFilesByExtensions","extensions","files","filter","filePath","fileExtension","path","extname","includes","refresh","refreshPackageJSON","refreshProjectFiles","runCodemods","codemods","options","runners","createProjectCodemodsRunners","dry","reports","codemod","runner","valid","report","run","push","jsonExtensions","constants","map","ext","codeExtensions","jsonFiles","codeFiles","codeRunner","codeRunnerFactory","parser","runInBand","babel","join","print","silent","verbose","jsonRunner","jsonRunnerFactory","cwd","packageJSONPath","fse","accessSync","Error","packageJSONBuffer","readFileSync","packageJSON","JSON","parse","toString","scanner","fileScannerFactory","scan","paths","config","pathExistsSync","AppProject","allowedRootPaths","formatGlobCollectionPattern","allowedExtensions","refreshStrapiVersion","strapiVersion","findStrapiVersionFromProjectPackageJSON","findLocallyInstalledStrapiVersion","projectName","name","version","dependencies","undefined","isValidSemVer","isLiteralSemVer","semver","semVerFactory","packageSearchText","strapiPackageJSONPath","strapiPackageJSON","require","resolve","assert","type","collection","length","PluginProject","isPlugin","strapi","kind","projectFactory"],"mappings":";;;;;;;;;;AAsBO,MAAMA,OAAAA,CAAAA;AAwBXC,IAAAA,oBAAAA,CAAqBC,UAA2B,EAAE;AAChD,QAAA,OAAO,IAAI,CAACC,KAAK,CAACC,MAAM,CAAC,CAACC,QAAAA,GAAAA;YACxB,MAAMC,aAAAA,GAAgBC,IAAKC,CAAAA,OAAO,CAACH,QAAAA,CAAAA;YAEnC,OAAOH,UAAAA,CAAWO,QAAQ,CAACH,aAAAA,CAAAA;AAC7B,SAAA,CAAA;AACF;IAEAI,OAAU,GAAA;AACR,QAAA,IAAI,CAACC,kBAAkB,EAAA;AACvB,QAAA,IAAI,CAACC,mBAAmB,EAAA;AAExB,QAAA,OAAO,IAAI;AACb;AAEA,IAAA,MAAMC,WAAYC,CAAAA,QAAsB,EAAEC,OAA2B,EAAE;AACrE,QAAA,MAAMC,UAAU,IAAI,CAACC,4BAA4B,CAACF,QAAQG,GAAG,CAAA;AAC7D,QAAA,MAAMC,UAAkC,EAAE;QAE1C,KAAK,MAAMC,WAAWN,QAAU,CAAA;YAC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