@adonisjs/core 6.1.5-2 → 6.1.5-3

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 (304) hide show
  1. package/build/commands/build.d.ts +3 -0
  2. package/build/commands/build.d.ts.map +1 -0
  3. package/build/commands/build.js +22 -2
  4. package/build/commands/commands.json +1 -1
  5. package/build/commands/configure.d.ts +1 -0
  6. package/build/commands/configure.d.ts.map +1 -0
  7. package/build/commands/configure.js +2 -1
  8. package/build/commands/eject.d.ts +1 -0
  9. package/build/commands/eject.d.ts.map +1 -0
  10. package/build/commands/eject.js +2 -1
  11. package/build/commands/generate_key.d.ts +1 -0
  12. package/build/commands/generate_key.d.ts.map +1 -0
  13. package/build/commands/generate_key.js +2 -1
  14. package/build/commands/inspect_rcfile.d.ts +7 -0
  15. package/build/commands/inspect_rcfile.d.ts.map +1 -0
  16. package/build/commands/inspect_rcfile.js +10 -0
  17. package/build/commands/list/routes.d.ts +1 -0
  18. package/build/commands/list/routes.d.ts.map +1 -0
  19. package/build/commands/list/routes.js +2 -1
  20. package/build/commands/make/_base.d.ts +23 -1
  21. package/build/commands/make/_base.d.ts.map +1 -0
  22. package/build/commands/make/_base.js +11 -2
  23. package/build/commands/make/command.d.ts +1 -0
  24. package/build/commands/make/command.d.ts.map +1 -0
  25. package/build/commands/make/command.js +2 -1
  26. package/build/commands/make/controller.d.ts +1 -0
  27. package/build/commands/make/controller.d.ts.map +1 -0
  28. package/build/commands/make/controller.js +2 -1
  29. package/build/commands/make/event.d.ts +1 -0
  30. package/build/commands/make/event.d.ts.map +1 -0
  31. package/build/commands/make/event.js +2 -1
  32. package/build/commands/make/listener.d.ts +1 -0
  33. package/build/commands/make/listener.d.ts.map +1 -0
  34. package/build/commands/make/listener.js +2 -1
  35. package/build/commands/make/middleware.d.ts +1 -0
  36. package/build/commands/make/middleware.d.ts.map +1 -0
  37. package/build/commands/make/middleware.js +2 -1
  38. package/build/commands/make/prldfile.d.ts +9 -0
  39. package/build/commands/make/prldfile.d.ts.map +1 -0
  40. package/build/commands/make/prldfile.js +28 -0
  41. package/build/commands/make/provider.d.ts +1 -0
  42. package/build/commands/make/provider.d.ts.map +1 -0
  43. package/build/commands/make/provider.js +5 -2
  44. package/build/commands/make/service.d.ts +9 -0
  45. package/build/commands/make/service.d.ts.map +1 -0
  46. package/build/commands/make/service.js +26 -0
  47. package/build/commands/make/test.d.ts +1 -0
  48. package/build/commands/make/test.d.ts.map +1 -0
  49. package/build/commands/make/test.js +2 -1
  50. package/build/commands/serve.d.ts +3 -0
  51. package/build/commands/serve.d.ts.map +1 -0
  52. package/build/commands/serve.js +21 -1
  53. package/build/commands/test.d.ts +21 -0
  54. package/build/commands/test.d.ts.map +1 -0
  55. package/build/commands/test.js +156 -0
  56. package/build/factories/app.d.ts +1 -0
  57. package/build/factories/app.d.ts.map +1 -0
  58. package/build/factories/bodyparser.d.ts +1 -0
  59. package/build/factories/bodyparser.d.ts.map +1 -0
  60. package/build/factories/core/ace.d.ts +1 -0
  61. package/build/factories/core/ace.d.ts.map +1 -0
  62. package/build/factories/core/ignitor.d.ts +1 -0
  63. package/build/factories/core/ignitor.d.ts.map +1 -0
  64. package/build/factories/core/main.d.ts +1 -0
  65. package/build/factories/core/main.d.ts.map +1 -0
  66. package/build/factories/core/test_utils.d.ts +1 -0
  67. package/build/factories/core/test_utils.d.ts.map +1 -0
  68. package/build/factories/encryption.d.ts +1 -0
  69. package/build/factories/encryption.d.ts.map +1 -0
  70. package/build/factories/events.d.ts +1 -0
  71. package/build/factories/events.d.ts.map +1 -0
  72. package/build/factories/hash.d.ts +1 -0
  73. package/build/factories/hash.d.ts.map +1 -0
  74. package/build/factories/http.d.ts +1 -0
  75. package/build/factories/http.d.ts.map +1 -0
  76. package/build/factories/logger.d.ts +1 -0
  77. package/build/factories/logger.d.ts.map +1 -0
  78. package/build/factories/stubs.d.ts +1 -0
  79. package/build/factories/stubs.d.ts.map +1 -0
  80. package/build/index.d.ts +1 -0
  81. package/build/index.d.ts.map +1 -0
  82. package/build/legacy/validator.d.ts +1 -0
  83. package/build/legacy/validator.d.ts.map +1 -0
  84. package/build/modules/ace/commands.d.ts +1 -0
  85. package/build/modules/ace/commands.d.ts.map +1 -0
  86. package/build/modules/ace/commands.js +4 -2
  87. package/build/modules/ace/create_kernel.d.ts +1 -0
  88. package/build/modules/ace/create_kernel.d.ts.map +1 -0
  89. package/build/modules/ace/kernel.d.ts +1 -0
  90. package/build/modules/ace/kernel.d.ts.map +1 -0
  91. package/build/modules/ace/main.d.ts +1 -0
  92. package/build/modules/ace/main.d.ts.map +1 -0
  93. package/build/modules/ace/shell.d.ts +1 -0
  94. package/build/modules/ace/shell.d.ts.map +1 -0
  95. package/build/modules/app.d.ts +1 -0
  96. package/build/modules/app.d.ts.map +1 -0
  97. package/build/modules/bodyparser/bodyparser_middleware.d.ts +1 -0
  98. package/build/modules/bodyparser/bodyparser_middleware.d.ts.map +1 -0
  99. package/build/modules/bodyparser/main.d.ts +1 -0
  100. package/build/modules/bodyparser/main.d.ts.map +1 -0
  101. package/build/modules/config.d.ts +1 -0
  102. package/build/modules/config.d.ts.map +1 -0
  103. package/build/modules/container.d.ts +1 -0
  104. package/build/modules/container.d.ts.map +1 -0
  105. package/build/modules/encryption.d.ts +1 -0
  106. package/build/modules/encryption.d.ts.map +1 -0
  107. package/build/modules/env.d.ts +1 -0
  108. package/build/modules/env.d.ts.map +1 -0
  109. package/build/modules/events.d.ts +1 -0
  110. package/build/modules/events.d.ts.map +1 -0
  111. package/build/modules/hash/define_config.d.ts +1 -0
  112. package/build/modules/hash/define_config.d.ts.map +1 -0
  113. package/build/modules/hash/drivers_collection.d.ts +4 -4
  114. package/build/modules/hash/drivers_collection.d.ts.map +1 -0
  115. package/build/modules/hash/drivers_collection.js +2 -8
  116. package/build/modules/hash/main.d.ts +2 -0
  117. package/build/modules/hash/main.d.ts.map +1 -0
  118. package/build/modules/hash/main.js +1 -0
  119. package/build/modules/http.d.ts +1 -0
  120. package/build/modules/http.d.ts.map +1 -0
  121. package/build/modules/logger.d.ts +1 -0
  122. package/build/modules/logger.d.ts.map +1 -0
  123. package/build/providers/app_provider.d.ts +1 -0
  124. package/build/providers/app_provider.d.ts.map +1 -0
  125. package/build/providers/app_provider.js +5 -7
  126. package/build/providers/hash_provider.d.ts +1 -0
  127. package/build/providers/hash_provider.d.ts.map +1 -0
  128. package/build/providers/hash_provider.js +7 -6
  129. package/build/providers/http_provider.d.ts +1 -0
  130. package/build/providers/http_provider.d.ts.map +1 -0
  131. package/build/services/ace.d.ts +1 -0
  132. package/build/services/ace.d.ts.map +1 -0
  133. package/build/services/app.d.ts +1 -0
  134. package/build/services/app.d.ts.map +1 -0
  135. package/build/services/config.d.ts +1 -0
  136. package/build/services/config.d.ts.map +1 -0
  137. package/build/services/emitter.d.ts +1 -0
  138. package/build/services/emitter.d.ts.map +1 -0
  139. package/build/services/emitter.js +1 -2
  140. package/build/services/encryption.d.ts +1 -0
  141. package/build/services/encryption.d.ts.map +1 -0
  142. package/build/services/encryption.js +1 -2
  143. package/build/services/hash.d.ts +1 -0
  144. package/build/services/hash.d.ts.map +1 -0
  145. package/build/services/hash.js +1 -2
  146. package/build/services/logger.d.ts +1 -0
  147. package/build/services/logger.d.ts.map +1 -0
  148. package/build/services/logger.js +1 -2
  149. package/build/services/router.d.ts +1 -0
  150. package/build/services/router.d.ts.map +1 -0
  151. package/build/services/router.js +1 -2
  152. package/build/services/server.d.ts +1 -0
  153. package/build/services/server.d.ts.map +1 -0
  154. package/build/services/server.js +1 -2
  155. package/build/services/test_utils.d.ts +1 -0
  156. package/build/services/test_utils.d.ts.map +1 -0
  157. package/build/src/cli_formatters/routes_list.d.ts +1 -0
  158. package/build/src/cli_formatters/routes_list.d.ts.map +1 -0
  159. package/build/src/debug.d.ts +1 -0
  160. package/build/src/debug.d.ts.map +1 -0
  161. package/build/src/helpers/is.d.ts +1 -0
  162. package/build/src/helpers/is.d.ts.map +1 -0
  163. package/build/src/helpers/main.d.ts +1 -0
  164. package/build/src/helpers/main.d.ts.map +1 -0
  165. package/build/src/helpers/parse_binding_reference.d.ts +1 -0
  166. package/build/src/helpers/parse_binding_reference.d.ts.map +1 -0
  167. package/build/src/helpers/string.d.ts +3 -0
  168. package/build/src/helpers/string.d.ts.map +1 -0
  169. package/build/src/helpers/string.js +4 -0
  170. package/build/src/helpers/types.d.ts +1 -0
  171. package/build/src/helpers/types.d.ts.map +1 -0
  172. package/build/src/ignitor/ace.d.ts +1 -0
  173. package/build/src/ignitor/ace.d.ts.map +1 -0
  174. package/build/src/ignitor/http.d.ts +1 -0
  175. package/build/src/ignitor/http.d.ts.map +1 -0
  176. package/build/src/ignitor/main.d.ts +1 -0
  177. package/build/src/ignitor/main.d.ts.map +1 -0
  178. package/build/src/ignitor/test.d.ts +1 -0
  179. package/build/src/ignitor/test.d.ts.map +1 -0
  180. package/build/src/internal_helpers.d.ts +1 -0
  181. package/build/src/internal_helpers.d.ts.map +1 -0
  182. package/build/src/test_utils/http.d.ts +1 -0
  183. package/build/src/test_utils/http.d.ts.map +1 -0
  184. package/build/src/test_utils/main.d.ts +2 -1
  185. package/build/src/test_utils/main.d.ts.map +1 -0
  186. package/build/src/types.d.ts +3 -2
  187. package/build/src/types.d.ts.map +1 -0
  188. package/build/stubs/index.d.ts +1 -0
  189. package/build/stubs/index.d.ts.map +1 -0
  190. package/build/stubs/make/preload_file/main.stub +4 -0
  191. package/build/stubs/make/service/main.stub +4 -0
  192. package/build/toolkit/commands/index_commands.d.ts +1 -0
  193. package/build/toolkit/commands/index_commands.d.ts.map +1 -0
  194. package/build/toolkit/commands/index_commands.js +2 -1
  195. package/build/toolkit/main.d.ts +1 -0
  196. package/build/toolkit/main.d.ts.map +1 -0
  197. package/build/types/ace.d.ts +1 -0
  198. package/build/types/ace.d.ts.map +1 -0
  199. package/build/types/app.d.ts +1 -0
  200. package/build/types/app.d.ts.map +1 -0
  201. package/build/types/bodyparser.d.ts +1 -0
  202. package/build/types/bodyparser.d.ts.map +1 -0
  203. package/build/types/container.d.ts +1 -0
  204. package/build/types/container.d.ts.map +1 -0
  205. package/build/types/encryption.d.ts +1 -0
  206. package/build/types/encryption.d.ts.map +1 -0
  207. package/build/types/events.d.ts +1 -0
  208. package/build/types/events.d.ts.map +1 -0
  209. package/build/types/hash.d.ts +1 -0
  210. package/build/types/hash.d.ts.map +1 -0
  211. package/build/types/http.d.ts +1 -0
  212. package/build/types/http.d.ts.map +1 -0
  213. package/build/types/logger.d.ts +1 -0
  214. package/build/types/logger.d.ts.map +1 -0
  215. package/commands/build.ts +122 -0
  216. package/commands/configure.ts +179 -0
  217. package/commands/eject.ts +39 -0
  218. package/commands/generate_key.ts +53 -0
  219. package/commands/inspect_rcfile.ts +23 -0
  220. package/commands/list/routes.ts +121 -0
  221. package/commands/make/_base.ts +55 -0
  222. package/commands/make/command.ts +33 -0
  223. package/commands/make/controller.ts +77 -0
  224. package/commands/make/event.ts +33 -0
  225. package/commands/make/listener.ts +63 -0
  226. package/commands/make/middleware.ts +34 -0
  227. package/commands/make/prldfile.ts +40 -0
  228. package/commands/make/provider.ts +40 -0
  229. package/commands/make/service.ts +33 -0
  230. package/commands/make/test.ts +115 -0
  231. package/commands/serve.ts +146 -0
  232. package/commands/test.ts +189 -0
  233. package/factories/app.ts +10 -0
  234. package/factories/bodyparser.ts +10 -0
  235. package/factories/core/ace.ts +38 -0
  236. package/factories/core/ignitor.ts +132 -0
  237. package/factories/core/main.ts +13 -0
  238. package/factories/core/test_utils.ts +34 -0
  239. package/factories/encryption.ts +10 -0
  240. package/factories/events.ts +10 -0
  241. package/factories/hash.ts +10 -0
  242. package/factories/http.ts +10 -0
  243. package/factories/logger.ts +10 -0
  244. package/factories/stubs.ts +53 -0
  245. package/index.ts +39 -0
  246. package/legacy/validator.ts +10 -0
  247. package/modules/ace/commands.ts +152 -0
  248. package/modules/ace/create_kernel.ts +73 -0
  249. package/modules/ace/kernel.ts +28 -0
  250. package/modules/ace/main.ts +22 -0
  251. package/modules/ace/shell.ts +49 -0
  252. package/modules/app.ts +10 -0
  253. package/modules/bodyparser/bodyparser_middleware.ts +16 -0
  254. package/modules/bodyparser/main.ts +10 -0
  255. package/modules/config.ts +10 -0
  256. package/modules/container.ts +10 -0
  257. package/modules/encryption.ts +10 -0
  258. package/modules/env.ts +10 -0
  259. package/modules/events.ts +10 -0
  260. package/modules/hash/define_config.ts +64 -0
  261. package/modules/hash/drivers_collection.ts +61 -0
  262. package/modules/hash/main.ts +12 -0
  263. package/modules/http.ts +10 -0
  264. package/modules/logger.ts +10 -0
  265. package/package.json +39 -30
  266. package/providers/app_provider.ts +125 -0
  267. package/providers/hash_provider.ts +58 -0
  268. package/providers/http_provider.ts +66 -0
  269. package/services/ace.ts +26 -0
  270. package/services/app.ts +26 -0
  271. package/services/config.ts +22 -0
  272. package/services/emitter.ts +23 -0
  273. package/services/encryption.ts +23 -0
  274. package/services/hash.ts +23 -0
  275. package/services/logger.ts +23 -0
  276. package/services/router.ts +23 -0
  277. package/services/server.ts +23 -0
  278. package/services/test_utils.ts +26 -0
  279. package/src/cli_formatters/routes_list.ts +480 -0
  280. package/src/debug.ts +12 -0
  281. package/src/helpers/is.ts +11 -0
  282. package/src/helpers/main.ts +13 -0
  283. package/src/helpers/parse_binding_reference.ts +93 -0
  284. package/src/helpers/string.ts +89 -0
  285. package/src/helpers/types.ts +46 -0
  286. package/src/ignitor/ace.ts +90 -0
  287. package/src/ignitor/http.ts +167 -0
  288. package/src/ignitor/main.ts +118 -0
  289. package/src/ignitor/test.ts +51 -0
  290. package/src/internal_helpers.ts +59 -0
  291. package/src/test_utils/http.ts +79 -0
  292. package/src/test_utils/main.ts +69 -0
  293. package/src/types.ts +136 -0
  294. package/types/ace.ts +15 -0
  295. package/types/app.ts +10 -0
  296. package/types/bodyparser.ts +10 -0
  297. package/types/container.ts +10 -0
  298. package/types/encryption.ts +10 -0
  299. package/types/events.ts +10 -0
  300. package/types/hash.ts +10 -0
  301. package/types/http.ts +10 -0
  302. package/types/logger.ts +10 -0
  303. package/build/src/helpers/string_builder.d.ts +0 -23
  304. package/build/src/helpers/string_builder.js +0 -86
@@ -0,0 +1,46 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import is from '@sindresorhus/is'
11
+
12
+ /**
13
+ * @deprecated
14
+ * Use "is" helpers instead. The types helpers exists
15
+ * for backward compatibility
16
+ */
17
+ const types = {
18
+ lookup: is,
19
+ isNull: is.null_,
20
+ isBoolean: is.boolean,
21
+ isBuffer: is.buffer,
22
+ isNumber: is.number,
23
+ isString: is.string,
24
+ isArguments: is.arguments,
25
+ isObject: is.object,
26
+ isDate: is.date,
27
+ isArray: is.array,
28
+ isRegexp: is.regExp,
29
+ isError: is.error,
30
+ isFunction: is.function_,
31
+ isClass: is.class_,
32
+ isInteger: is.integer,
33
+ isFloat(value: number): value is number {
34
+ return value !== (value | 0)
35
+ },
36
+ isDecimal(value: string | number, options?: { decimalPlaces?: string }): boolean {
37
+ if (typeof value === 'number') {
38
+ value = value.toString()
39
+ }
40
+
41
+ const decimalPlaces = (options && options.decimalPlaces) || '1,'
42
+ return new RegExp(`^[-+]?([0-9]+)?(\\.[0-9]{${decimalPlaces}})$`).test(value)
43
+ },
44
+ }
45
+
46
+ export default types
@@ -0,0 +1,90 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { Ignitor } from './main.js'
11
+ import type { ApplicationService } from '../types.js'
12
+
13
+ /**
14
+ * The Ace process is used to start the application in the
15
+ * console environment.
16
+ */
17
+ export class AceProcess {
18
+ /**
19
+ * Ignitor reference
20
+ */
21
+ #ignitor: Ignitor
22
+
23
+ /**
24
+ * The callback that configures the tests runner. This callback
25
+ * runs at the time of starting the app.
26
+ */
27
+ #configureCallback: (app: ApplicationService) => Promise<void> | void = () => {}
28
+
29
+ constructor(ignitor: Ignitor) {
30
+ this.#ignitor = ignitor
31
+ }
32
+
33
+ /**
34
+ * Register a callback that runs after booting the AdonisJS app
35
+ * and just before the provider's ready hook
36
+ */
37
+ configure(callback: (app: ApplicationService) => Promise<void> | void): this {
38
+ this.#configureCallback = callback
39
+ return this
40
+ }
41
+
42
+ /**
43
+ * Handles the command line arguments and executes
44
+ * the matching ace commands
45
+ */
46
+ async handle(argv: string[]) {
47
+ const app = this.#ignitor.createApp('console')
48
+ await app.init()
49
+
50
+ const { createAceKernel } = await import('../../modules/ace/create_kernel.js')
51
+
52
+ const kernel = createAceKernel(app)
53
+ app.container.bindValue('ace', kernel)
54
+
55
+ /**
56
+ * Hook into kernel and start the app when the
57
+ * command needs the app.
58
+ *
59
+ * Since multiple commands can be executed in a single process,
60
+ * we add a check to only start the app only once.
61
+ */
62
+ kernel.loading(async (metaData) => {
63
+ if (metaData.options.startApp && !app.isReady) {
64
+ await app.boot()
65
+ await app.start(() => {})
66
+ }
67
+ })
68
+
69
+ await this.#configureCallback(app)
70
+
71
+ /**
72
+ * Handle command line args
73
+ */
74
+ await kernel.handle(argv)
75
+
76
+ /**
77
+ * Update the process exit code
78
+ */
79
+ process.exitCode = kernel.exitCode
80
+
81
+ /**
82
+ * Terminate the app when the command does not want to
83
+ * hold a long running process
84
+ */
85
+ const mainCommand = kernel.getMainCommand()
86
+ if (!mainCommand || !mainCommand.staysAlive) {
87
+ await app.terminate()
88
+ }
89
+ }
90
+ }
@@ -0,0 +1,167 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import type { Server as NodeHttpsServer } from 'node:https'
11
+ import { IncomingMessage, ServerResponse, Server as NodeHttpServer, createServer } from 'node:http'
12
+
13
+ import debug from '../debug.js'
14
+ import { Ignitor } from './main.js'
15
+ import type { ApplicationService, EmitterService, LoggerService } from '../types.js'
16
+
17
+ /**
18
+ * The HTTP server process is used to start the application in the
19
+ * web environment.
20
+ */
21
+ export class HttpServerProcess {
22
+ /**
23
+ * Ignitor reference
24
+ */
25
+ #ignitor: Ignitor
26
+
27
+ constructor(ignitor: Ignitor) {
28
+ this.#ignitor = ignitor
29
+ }
30
+
31
+ /**
32
+ * Calling this method closes the underlying HTTP server
33
+ */
34
+ #close(nodeHttpServer: NodeHttpsServer | NodeHttpServer): Promise<void> {
35
+ return new Promise((resolve) => {
36
+ debug('closing http server process')
37
+ nodeHttpServer.close(() => resolve())
38
+ })
39
+ }
40
+
41
+ /**
42
+ * Monitors the app and the server to close the HTTP server when
43
+ * either one of them goes down
44
+ */
45
+ #monitorAppAndServer(
46
+ nodeHttpServer: NodeHttpsServer | NodeHttpServer,
47
+ app: ApplicationService,
48
+ logger: LoggerService
49
+ ) {
50
+ /**
51
+ * Close the HTTP server when the application begins to
52
+ * terminate
53
+ */
54
+ app.terminating(async () => {
55
+ debug('terminating signal received')
56
+ await this.#close(nodeHttpServer)
57
+ })
58
+
59
+ /**
60
+ * Terminate the app when the HTTP server crashes
61
+ */
62
+ nodeHttpServer.once('error', (error: NodeJS.ErrnoException) => {
63
+ debug('http server crashed with error "%O"', error)
64
+ logger.fatal({ err: error }, error.message)
65
+ process.exitCode = 1
66
+ app.terminate()
67
+ })
68
+ }
69
+
70
+ /**
71
+ * Starts the http server a given host and port
72
+ */
73
+ #listen(
74
+ nodeHttpServer: NodeHttpsServer | NodeHttpServer
75
+ ): Promise<{ port: number; host: string }> {
76
+ return new Promise((resolve, reject) => {
77
+ const host = process.env.HOST || '0.0.0.0'
78
+ const port = Number(process.env.PORT || '3333')
79
+
80
+ nodeHttpServer.listen(port, host)
81
+ nodeHttpServer.once('listening', () => {
82
+ debug('listening to http server, host :%s, port: %s', host, port)
83
+ resolve({ port, host })
84
+ })
85
+
86
+ nodeHttpServer.once('error', (error: NodeJS.ErrnoException) => {
87
+ reject(error)
88
+ })
89
+ })
90
+ }
91
+
92
+ /**
93
+ * Notifies the app and the parent process that the
94
+ * HTTP server is ready
95
+ */
96
+ #notifyServerHasStarted(
97
+ app: ApplicationService,
98
+ logger: LoggerService,
99
+ emitter: EmitterService,
100
+ payload: { host: string; port: number }
101
+ ) {
102
+ /**
103
+ * Notify parent process
104
+ */
105
+ app.notify({ isAdonisJS: true, environment: 'web', ...payload })
106
+
107
+ /**
108
+ * Visual notification
109
+ */
110
+ logger.info('started HTTP server on %s:%s', payload.host, payload.port)
111
+
112
+ /**
113
+ * Notify app
114
+ */
115
+ emitter.emit('http:server_ready', payload)
116
+ }
117
+
118
+ /**
119
+ * Start the HTTP server by wiring up the application
120
+ */
121
+ async start(
122
+ serverCallback?: (
123
+ handler: (req: IncomingMessage, res: ServerResponse) => any
124
+ ) => NodeHttpsServer | NodeHttpServer
125
+ ) {
126
+ /**
127
+ * Method to create the HTTP server
128
+ */
129
+ const createHTTPServer = serverCallback || createServer
130
+ const app = this.#ignitor.createApp('web')
131
+
132
+ await app.init()
133
+ await app.boot()
134
+ await app.start(async () => {
135
+ /**
136
+ * Resolve and boot the AdonisJS HTTP server
137
+ */
138
+ const server = await app.container.make('server')
139
+ await server.boot()
140
+
141
+ /**
142
+ * Create Node.js HTTP server instance and share it with the
143
+ * AdonisJS HTTP server
144
+ */
145
+ const httpServer = createHTTPServer(server.handle.bind(server))
146
+ server.setNodeServer(httpServer)
147
+
148
+ const logger = await app.container.make('logger')
149
+ const emitter = await app.container.make('emitter')
150
+
151
+ /**
152
+ * Start the server by listening on a port of host
153
+ */
154
+ const payload = await this.#listen(httpServer)
155
+
156
+ /**
157
+ * Notify
158
+ */
159
+ this.#notifyServerHasStarted(app, logger, emitter, payload)
160
+
161
+ /**
162
+ * Monitor app and the server (after the server is listening)
163
+ */
164
+ this.#monitorAppAndServer(httpServer, app, logger)
165
+ })
166
+ }
167
+ }
@@ -0,0 +1,118 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import debug from '../debug.js'
11
+ import { AceProcess } from './ace.js'
12
+ import { TestRunnerProcess } from './test.js'
13
+ import { HttpServerProcess } from './http.js'
14
+ import { setApp } from '../../services/app.js'
15
+ import { Application } from '../../modules/app.js'
16
+ import type { AppEnvironments } from '../../types/app.js'
17
+ import type { ApplicationService, IgnitorOptions } from '../types.js'
18
+
19
+ /**
20
+ * Ignitor is used to instantiate an AdonisJS application in different
21
+ * known environments.
22
+ */
23
+ export class Ignitor {
24
+ /**
25
+ * Ignitor options
26
+ */
27
+ #options: IgnitorOptions
28
+
29
+ /**
30
+ * Application root URL
31
+ */
32
+ #appRoot: URL
33
+
34
+ /**
35
+ * Reference to the application instance created using
36
+ * the "createApp" method.
37
+ *
38
+ * We store the output of the last call made to "createApp" method
39
+ * and assume that in one process only one entrypoint will
40
+ * call this method.
41
+ */
42
+ #app?: ApplicationService
43
+
44
+ /**
45
+ * Reference to the created application
46
+ */
47
+ #tapCallbacks: Set<(app: ApplicationService) => void> = new Set()
48
+
49
+ constructor(appRoot: URL, options: IgnitorOptions) {
50
+ this.#appRoot = appRoot
51
+ this.#options = options
52
+ }
53
+
54
+ /**
55
+ * Runs all the tap callbacks
56
+ */
57
+ #runTapCallbacks(app: ApplicationService) {
58
+ this.#tapCallbacks.forEach((tapCallback) => tapCallback(app))
59
+ }
60
+
61
+ /**
62
+ * Get access to the application instance created
63
+ * by either the http server process or the ace
64
+ * process
65
+ */
66
+ getApp() {
67
+ return this.#app
68
+ }
69
+
70
+ /**
71
+ * Create an instance of AdonisJS application
72
+ */
73
+ createApp(environment: AppEnvironments) {
74
+ debug('creating application instance')
75
+ this.#app = new Application(this.#appRoot, { environment, importer: this.#options.importer })
76
+
77
+ setApp(this.#app)
78
+ this.#runTapCallbacks(this.#app)
79
+ return this.#app
80
+ }
81
+
82
+ /**
83
+ * Tap to access the application class instance.
84
+ */
85
+ tap(callback: (app: ApplicationService) => void): this {
86
+ this.#tapCallbacks.add(callback)
87
+ return this
88
+ }
89
+
90
+ /**
91
+ * Get instance of the HTTPServerProcess
92
+ */
93
+ httpServer() {
94
+ return new HttpServerProcess(this)
95
+ }
96
+
97
+ /**
98
+ * Get an instance of the AceProcess class
99
+ */
100
+ ace() {
101
+ return new AceProcess(this)
102
+ }
103
+
104
+ /**
105
+ * Get an instance of the TestRunnerProcess class
106
+ */
107
+ testRunner() {
108
+ return new TestRunnerProcess(this)
109
+ }
110
+
111
+ /**
112
+ * Terminates the app by calling the "app.terminate"
113
+ * method
114
+ */
115
+ async terminate() {
116
+ await this.#app?.terminate()
117
+ }
118
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { Ignitor } from './main.js'
11
+ import type { ApplicationService } from '../types.js'
12
+
13
+ /**
14
+ * The Test runner process is used to start the tests runner process
15
+ */
16
+ export class TestRunnerProcess {
17
+ /**
18
+ * Ignitor reference
19
+ */
20
+ #ignitor: Ignitor
21
+
22
+ /**
23
+ * The callback that configures the tests runner. This callback
24
+ * runs at the time of starting the app.
25
+ */
26
+ #configureCallback: (app: ApplicationService) => Promise<void> | void = () => {}
27
+
28
+ constructor(ignitor: Ignitor) {
29
+ this.#ignitor = ignitor
30
+ }
31
+
32
+ /**
33
+ * Register a callback that runs after booting the AdonisJS app
34
+ * and just before the provider's ready hook
35
+ */
36
+ configure(callback: (app: ApplicationService) => Promise<void> | void): this {
37
+ this.#configureCallback = callback
38
+ return this
39
+ }
40
+
41
+ /**
42
+ * Runs a callback after starting the app
43
+ */
44
+ async run(callback: (app: ApplicationService) => Promise<void> | void) {
45
+ const app = this.#ignitor.createApp('test')
46
+ await app.init()
47
+ await app.boot()
48
+ await app.start(this.#configureCallback)
49
+ await callback(app)
50
+ }
51
+ }
@@ -0,0 +1,59 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import fs from 'node:fs'
11
+ import { ApplicationService } from './types.js'
12
+
13
+ /**
14
+ * Imports assembler optionally
15
+ */
16
+ export async function importAssembler(
17
+ app: ApplicationService
18
+ ): Promise<typeof import('@adonisjs/assembler') | undefined> {
19
+ try {
20
+ return await app.import('@adonisjs/assembler')
21
+ } catch {}
22
+ }
23
+
24
+ /**
25
+ * Imports typescript optionally
26
+ */
27
+ export async function importTypeScript(
28
+ app: ApplicationService
29
+ ): Promise<typeof import('typescript') | undefined> {
30
+ try {
31
+ return await app.importDefault('typescript')
32
+ } catch {}
33
+ }
34
+
35
+ /**
36
+ * Detects the assets bundler in use. The rcFile.assetsBundler is
37
+ * used when exists.
38
+ */
39
+ export async function detectAssetsBundler(app: ApplicationService) {
40
+ if (app.rcFile.assetsBundler) {
41
+ return app.rcFile.assetsBundler
42
+ }
43
+
44
+ if (fs.existsSync(app.makePath('vite.config.js'))) {
45
+ return {
46
+ name: 'vite',
47
+ devServerCommand: 'vite',
48
+ buildCommand: 'vite build',
49
+ }
50
+ }
51
+
52
+ if (fs.existsSync(app.makePath('webpack.config.js'))) {
53
+ return {
54
+ name: 'encore',
55
+ devServerCommand: 'encore dev-server',
56
+ buildCommand: 'encore',
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,79 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import debug from '../debug.js'
11
+ import type { TestUtils } from './main.js'
12
+ import type { Server as NodeHttpsServer } from 'node:https'
13
+ import { IncomingMessage, ServerResponse, Server as NodeHttpServer, createServer } from 'node:http'
14
+
15
+ /**
16
+ * Http server utils are used to start the AdonisJS HTTP server
17
+ * during testing
18
+ */
19
+ export class HttpServerUtils {
20
+ #utils: TestUtils
21
+
22
+ constructor(utils: TestUtils) {
23
+ this.#utils = utils
24
+ }
25
+
26
+ /**
27
+ * Starts the http server a given host and port
28
+ */
29
+ #listen(
30
+ nodeHttpServer: NodeHttpsServer | NodeHttpServer
31
+ ): Promise<{ port: number; host: string }> {
32
+ return new Promise((resolve, reject) => {
33
+ const host = process.env.HOST || '0.0.0.0'
34
+ const port = Number(process.env.PORT || '3333')
35
+
36
+ nodeHttpServer.listen(port, host)
37
+ nodeHttpServer.once('listening', () => {
38
+ debug('listening to utils http server, host :%s, port: %s', host, port)
39
+ resolve({ port, host })
40
+ })
41
+
42
+ nodeHttpServer.once('error', (error: NodeJS.ErrnoException) => {
43
+ reject(error)
44
+ })
45
+ })
46
+ }
47
+
48
+ /**
49
+ * Testing hook to start the HTTP server to listen for new request.
50
+ * The return value is a function to close the HTTP server.
51
+ */
52
+ async start(
53
+ serverCallback?: (
54
+ handler: (req: IncomingMessage, res: ServerResponse) => any
55
+ ) => NodeHttpsServer | NodeHttpServer
56
+ ): Promise<() => Promise<void>> {
57
+ const createHTTPServer = serverCallback || createServer
58
+
59
+ const server = await this.#utils.app.container.make('server')
60
+ await server.boot()
61
+
62
+ const httpServer = createHTTPServer(server.handle.bind(server))
63
+ server.setNodeServer(httpServer)
64
+
65
+ await this.#listen(httpServer)
66
+
67
+ return () => {
68
+ return new Promise<void>((resolve, reject) => {
69
+ httpServer.close((error) => {
70
+ if (error) {
71
+ reject(error)
72
+ } else {
73
+ resolve()
74
+ }
75
+ })
76
+ })
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,69 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { Socket } from 'node:net'
11
+ import Macroable from '@poppinss/macroable'
12
+ import { IncomingMessage, ServerResponse } from 'node:http'
13
+
14
+ import { HttpServerUtils } from './http.js'
15
+ import { CookieClient } from '../../modules/http.js'
16
+ import type { ApplicationService } from '../types.js'
17
+
18
+ /**
19
+ * Test utils has a collection of helper methods to make testing
20
+ * experience great for AdonisJS applications
21
+ */
22
+ export class TestUtils extends Macroable {
23
+ #booted: boolean = false
24
+
25
+ /**
26
+ * Check if utils have been booted
27
+ */
28
+ get isBooted() {
29
+ return this.#booted
30
+ }
31
+
32
+ declare cookies: CookieClient
33
+
34
+ constructor(public app: ApplicationService) {
35
+ super()
36
+ }
37
+
38
+ /**
39
+ * Boot test utils. It requires the app to be booted
40
+ * and container to have all the bindings
41
+ */
42
+ async boot() {
43
+ if (!this.isBooted) {
44
+ this.#booted = true
45
+ this.cookies = new CookieClient(await this.app.container.make('encryption'))
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Returns an instance of the HTTP server testing
51
+ * utils
52
+ */
53
+ httpServer() {
54
+ return new HttpServerUtils(this)
55
+ }
56
+
57
+ /**
58
+ * Create an instance of HTTP context for testing
59
+ */
60
+ async createHttpContext(options: { req?: IncomingMessage; res?: ServerResponse } = {}) {
61
+ const req = options.req || new IncomingMessage(new Socket())
62
+ const res = options.res || new ServerResponse(req)
63
+ const server = await this.app.container.make('server')
64
+
65
+ const request = server.createRequest(req, res)
66
+ const response = server.createResponse(req, res)
67
+ return server.createHttpContext(request, response, this.app.container.createResolver())
68
+ }
69
+ }