skuba 13.0.2 → 14.0.0-esmify-skuba-20251031135439

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 (516) hide show
  1. package/config/eslint.js +1 -1
  2. package/config/prettier.js +10 -2
  3. package/lib/cli/adapter/eslint.js +10 -46
  4. package/lib/cli/adapter/eslint.js.map +2 -2
  5. package/lib/cli/adapter/prettier.js +40 -72
  6. package/lib/cli/adapter/prettier.js.map +2 -2
  7. package/lib/cli/build/args.js +7 -43
  8. package/lib/cli/build/args.js.map +2 -2
  9. package/lib/cli/build/assets.js +27 -62
  10. package/lib/cli/build/assets.js.map +2 -2
  11. package/lib/cli/build/esbuild.js +20 -55
  12. package/lib/cli/build/esbuild.js.map +3 -3
  13. package/lib/cli/build/index.js +20 -56
  14. package/lib/cli/build/index.js.map +2 -2
  15. package/lib/cli/build/tsc.js +24 -66
  16. package/lib/cli/build/tsc.js.map +2 -2
  17. package/lib/cli/buildPackage/index.js +7 -33
  18. package/lib/cli/buildPackage/index.js.map +1 -1
  19. package/lib/cli/configure/analyseConfiguration.js +15 -51
  20. package/lib/cli/configure/analyseConfiguration.js.map +2 -2
  21. package/lib/cli/configure/analyseDependencies.js +24 -60
  22. package/lib/cli/configure/analyseDependencies.js.map +3 -3
  23. package/lib/cli/configure/analysis/diff.js +4 -40
  24. package/lib/cli/configure/analysis/diff.js.map +2 -2
  25. package/lib/cli/configure/analysis/files.js +7 -43
  26. package/lib/cli/configure/analysis/files.js.map +2 -2
  27. package/lib/cli/configure/analysis/git.js +11 -47
  28. package/lib/cli/configure/analysis/git.js.map +2 -2
  29. package/lib/cli/configure/analysis/package.js +10 -48
  30. package/lib/cli/configure/analysis/package.js.map +3 -3
  31. package/lib/cli/configure/analysis/project.js +18 -53
  32. package/lib/cli/configure/analysis/project.js.map +2 -2
  33. package/lib/cli/configure/dependencies/index.js +5 -39
  34. package/lib/cli/configure/dependencies/index.js.map +1 -1
  35. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js +3 -29
  36. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js.map +1 -1
  37. package/lib/cli/configure/dependencies/seekKoala.js +3 -29
  38. package/lib/cli/configure/dependencies/seekKoala.js.map +1 -1
  39. package/lib/cli/configure/dependencies/skuba.js +3 -29
  40. package/lib/cli/configure/dependencies/skuba.js.map +1 -1
  41. package/lib/cli/configure/dependencies/skubaDeps.js +1 -27
  42. package/lib/cli/configure/dependencies/skubaDeps.js.map +1 -1
  43. package/lib/cli/configure/dependencies/skubaDive.js +4 -32
  44. package/lib/cli/configure/dependencies/skubaDive.js.map +1 -1
  45. package/lib/cli/configure/ensureTemplateCompletion.js +31 -61
  46. package/lib/cli/configure/ensureTemplateCompletion.js.map +3 -3
  47. package/lib/cli/configure/getEntryPoint.js +13 -49
  48. package/lib/cli/configure/getEntryPoint.js.map +3 -3
  49. package/lib/cli/configure/getProjectType.js +13 -36
  50. package/lib/cli/configure/getProjectType.js.map +2 -2
  51. package/lib/cli/configure/index.js +49 -85
  52. package/lib/cli/configure/index.js.map +3 -3
  53. package/lib/cli/configure/modules/eslint.js +9 -35
  54. package/lib/cli/configure/modules/eslint.js.map +1 -1
  55. package/lib/cli/configure/modules/ignore.js +7 -33
  56. package/lib/cli/configure/modules/ignore.js.map +1 -1
  57. package/lib/cli/configure/modules/index.js +17 -45
  58. package/lib/cli/configure/modules/index.js.map +2 -2
  59. package/lib/cli/configure/modules/nodemon.js +2 -28
  60. package/lib/cli/configure/modules/nodemon.js.map +1 -1
  61. package/lib/cli/configure/modules/package.js +9 -35
  62. package/lib/cli/configure/modules/package.js.map +1 -1
  63. package/lib/cli/configure/modules/prettier.js +10 -36
  64. package/lib/cli/configure/modules/prettier.js.map +1 -1
  65. package/lib/cli/configure/modules/renovate.js +17 -43
  66. package/lib/cli/configure/modules/renovate.js.map +2 -2
  67. package/lib/cli/configure/modules/serverless.js +1 -27
  68. package/lib/cli/configure/modules/serverless.js.map +1 -1
  69. package/lib/cli/configure/modules/tslint.js +2 -28
  70. package/lib/cli/configure/modules/tslint.js.map +1 -1
  71. package/lib/cli/configure/processing/configFile.js +4 -44
  72. package/lib/cli/configure/processing/configFile.js.map +1 -1
  73. package/lib/cli/configure/processing/deleteFiles.js +1 -27
  74. package/lib/cli/configure/processing/deleteFiles.js.map +1 -1
  75. package/lib/cli/configure/processing/javascript.js +2 -30
  76. package/lib/cli/configure/processing/javascript.js.map +1 -1
  77. package/lib/cli/configure/processing/json.js +6 -34
  78. package/lib/cli/configure/processing/json.js.map +1 -1
  79. package/lib/cli/configure/processing/loadFiles.js +1 -27
  80. package/lib/cli/configure/processing/loadFiles.js.map +1 -1
  81. package/lib/cli/configure/processing/module.js +2 -28
  82. package/lib/cli/configure/processing/module.js.map +1 -1
  83. package/lib/cli/configure/processing/package.js +10 -52
  84. package/lib/cli/configure/processing/package.js.map +3 -3
  85. package/lib/cli/configure/processing/prettier.js +3 -39
  86. package/lib/cli/configure/processing/prettier.js.map +2 -2
  87. package/lib/cli/configure/processing/record.js +4 -44
  88. package/lib/cli/configure/processing/record.js.map +2 -2
  89. package/lib/cli/configure/processing/typescript.js +28 -70
  90. package/lib/cli/configure/processing/typescript.js.map +2 -2
  91. package/lib/cli/configure/types.js +0 -15
  92. package/lib/cli/configure/types.js.map +3 -3
  93. package/lib/cli/format/index.js +19 -55
  94. package/lib/cli/format/index.js.map +2 -2
  95. package/lib/cli/help/index.js +5 -31
  96. package/lib/cli/help/index.js.map +1 -1
  97. package/lib/cli/init/getConfig.js +75 -107
  98. package/lib/cli/init/getConfig.js.map +3 -3
  99. package/lib/cli/init/git.js +16 -54
  100. package/lib/cli/init/git.js.map +3 -3
  101. package/lib/cli/init/index.js +66 -99
  102. package/lib/cli/init/index.js.map +2 -2
  103. package/lib/cli/init/prompts.js +20 -56
  104. package/lib/cli/init/prompts.js.map +3 -3
  105. package/lib/cli/init/types.js +6 -42
  106. package/lib/cli/init/types.js.map +1 -1
  107. package/lib/cli/init/validation.js +5 -39
  108. package/lib/cli/init/validation.js.map +1 -1
  109. package/lib/cli/init/writePackageJson.js +7 -43
  110. package/lib/cli/init/writePackageJson.js.map +2 -2
  111. package/lib/cli/lint/annotate/buildkite/eslint.js +2 -38
  112. package/lib/cli/lint/annotate/buildkite/eslint.js.map +1 -1
  113. package/lib/cli/lint/annotate/buildkite/index.js +10 -46
  114. package/lib/cli/lint/annotate/buildkite/index.js.map +1 -1
  115. package/lib/cli/lint/annotate/buildkite/internal.js +2 -38
  116. package/lib/cli/lint/annotate/buildkite/internal.js.map +1 -1
  117. package/lib/cli/lint/annotate/buildkite/prettier.js +2 -38
  118. package/lib/cli/lint/annotate/buildkite/prettier.js.map +1 -1
  119. package/lib/cli/lint/annotate/buildkite/tsc.js +2 -38
  120. package/lib/cli/lint/annotate/buildkite/tsc.js.map +1 -1
  121. package/lib/cli/lint/annotate/github/eslint.js +1 -27
  122. package/lib/cli/lint/annotate/github/eslint.js.map +1 -1
  123. package/lib/cli/lint/annotate/github/index.js +10 -46
  124. package/lib/cli/lint/annotate/github/index.js.map +1 -1
  125. package/lib/cli/lint/annotate/github/internal.js +1 -27
  126. package/lib/cli/lint/annotate/github/internal.js.map +1 -1
  127. package/lib/cli/lint/annotate/github/prettier.js +1 -27
  128. package/lib/cli/lint/annotate/github/prettier.js.map +1 -1
  129. package/lib/cli/lint/annotate/github/tsc.js +3 -29
  130. package/lib/cli/lint/annotate/github/tsc.js.map +2 -2
  131. package/lib/cli/lint/annotate/index.js +5 -31
  132. package/lib/cli/lint/annotate/index.js.map +1 -1
  133. package/lib/cli/lint/autofix.js +38 -78
  134. package/lib/cli/lint/autofix.js.map +3 -3
  135. package/lib/cli/lint/eslint.js +14 -52
  136. package/lib/cli/lint/eslint.js.map +3 -3
  137. package/lib/cli/lint/external.js +18 -53
  138. package/lib/cli/lint/external.js.map +2 -2
  139. package/lib/cli/lint/index.js +24 -50
  140. package/lib/cli/lint/index.js.map +1 -1
  141. package/lib/cli/lint/internal.js +17 -53
  142. package/lib/cli/lint/internal.js.map +2 -2
  143. package/lib/cli/lint/internalLints/detectBadCodeowners.js +8 -36
  144. package/lib/cli/lint/internalLints/detectBadCodeowners.js.map +1 -1
  145. package/lib/cli/lint/internalLints/noSkubaTemplateJs.js +10 -46
  146. package/lib/cli/lint/internalLints/noSkubaTemplateJs.js.map +3 -3
  147. package/lib/cli/lint/internalLints/patchRenovateConfig.js +20 -56
  148. package/lib/cli/lint/internalLints/patchRenovateConfig.js.map +2 -2
  149. package/lib/cli/lint/internalLints/refreshConfigFiles.js +33 -68
  150. package/lib/cli/lint/internalLints/refreshConfigFiles.js.map +2 -2
  151. package/lib/cli/lint/internalLints/upgrade/index.js +21 -54
  152. package/lib/cli/lint/internalLints/upgrade/index.js.map +3 -3
  153. package/lib/cli/lint/internalLints/upgrade/patches/10.0.4/index.js +3 -29
  154. package/lib/cli/lint/internalLints/upgrade/patches/10.0.4/index.js.map +1 -1
  155. package/lib/cli/lint/internalLints/upgrade/patches/10.0.4/removeYarnIgnoreOptionalFlags.js +10 -46
  156. package/lib/cli/lint/internalLints/upgrade/patches/10.0.4/removeYarnIgnoreOptionalFlags.js.map +2 -2
  157. package/lib/cli/lint/internalLints/upgrade/patches/10.1.0/index.js +5 -31
  158. package/lib/cli/lint/internalLints/upgrade/patches/10.1.0/index.js.map +1 -1
  159. package/lib/cli/lint/internalLints/upgrade/patches/10.1.0/migrateNpmrcToPnpmWorkspace.js +36 -73
  160. package/lib/cli/lint/internalLints/upgrade/patches/10.1.0/migrateNpmrcToPnpmWorkspace.js.map +3 -3
  161. package/lib/cli/lint/internalLints/upgrade/patches/10.1.0/stopBundlingInCDKTests.js +11 -49
  162. package/lib/cli/lint/internalLints/upgrade/patches/10.1.0/stopBundlingInCDKTests.js.map +2 -2
  163. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js +3 -29
  164. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js.map +1 -1
  165. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js +24 -64
  166. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js.map +2 -2
  167. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/index.js +3 -29
  168. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/index.js.map +1 -1
  169. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/patchJestSnapshots.js +11 -49
  170. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/patchJestSnapshots.js.map +2 -2
  171. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/index.js +5 -31
  172. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/index.js.map +1 -1
  173. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchApiTokenFromEnvironment.js +11 -49
  174. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchApiTokenFromEnvironment.js.map +2 -2
  175. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchDockerfileSyntaxDirective.js +11 -49
  176. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchDockerfileSyntaxDirective.js.map +2 -2
  177. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/index.js +3 -29
  178. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/index.js.map +1 -1
  179. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/patchDockerfileCIVariable.js +11 -49
  180. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/patchDockerfileCIVariable.js.map +2 -2
  181. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/configureTsConfigForESM.js +32 -76
  182. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/configureTsConfigForESM.js.map +2 -2
  183. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/index.js +9 -35
  184. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/index.js.map +1 -1
  185. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/patchApiDockerfiles.js +10 -46
  186. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/patchApiDockerfiles.js.map +2 -2
  187. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/rewriteSrcImports.js +28 -88
  188. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/rewriteSrcImports.js.map +2 -2
  189. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/updateLambdaConfigs.js +19 -58
  190. package/lib/cli/lint/internalLints/upgrade/patches/12.4.1/updateLambdaConfigs.js.map +3 -3
  191. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/addEmptyExports.js +16 -52
  192. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/addEmptyExports.js.map +2 -2
  193. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/index.js +9 -35
  194. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/index.js.map +1 -1
  195. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/patchDockerfile.js +9 -45
  196. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/patchDockerfile.js.map +2 -2
  197. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/patchServerListener.js +11 -47
  198. package/lib/cli/lint/internalLints/upgrade/patches/7.3.1/patchServerListener.js.map +2 -2
  199. package/lib/cli/lint/internalLints/upgrade/patches/8.0.0/index.js +3 -29
  200. package/lib/cli/lint/internalLints/upgrade/patches/8.0.0/index.js.map +1 -1
  201. package/lib/cli/lint/internalLints/upgrade/patches/8.0.0/patchPnpmPackageManager.js +14 -50
  202. package/lib/cli/lint/internalLints/upgrade/patches/8.0.0/patchPnpmPackageManager.js.map +2 -2
  203. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/collapseDuplicateMergeKeys.js +10 -46
  204. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/collapseDuplicateMergeKeys.js.map +2 -2
  205. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/index.js +9 -40
  206. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/index.js.map +2 -2
  207. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/moveNpmrcMounts.js +10 -46
  208. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/moveNpmrcMounts.js.map +2 -2
  209. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/patchDockerCompose.js +10 -46
  210. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/patchDockerCompose.js.map +2 -2
  211. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/patchDockerImages.js +12 -48
  212. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/patchDockerImages.js.map +2 -2
  213. package/lib/cli/lint/internalLints/upgrade/patches/9.0.1/index.js +3 -29
  214. package/lib/cli/lint/internalLints/upgrade/patches/9.0.1/index.js.map +1 -1
  215. package/lib/cli/lint/internalLints/upgrade/patches/9.0.1/patchPnpmDockerImages.js +10 -46
  216. package/lib/cli/lint/internalLints/upgrade/patches/9.0.1/patchPnpmDockerImages.js.map +2 -2
  217. package/lib/cli/lint/internalLints/upgrade/patches/9.1.0/index.js +3 -29
  218. package/lib/cli/lint/internalLints/upgrade/patches/9.1.0/index.js.map +1 -1
  219. package/lib/cli/lint/internalLints/upgrade/patches/9.1.0/upgradeNode.js +7 -33
  220. package/lib/cli/lint/internalLints/upgrade/patches/9.1.0/upgradeNode.js.map +1 -1
  221. package/lib/cli/lint/prettier.js +13 -51
  222. package/lib/cli/lint/prettier.js.map +3 -3
  223. package/lib/cli/lint/tsc.js +3 -29
  224. package/lib/cli/lint/tsc.js.map +1 -1
  225. package/lib/cli/lint/types.js +0 -15
  226. package/lib/cli/lint/types.js.map +3 -3
  227. package/lib/cli/migrate/index.js +9 -35
  228. package/lib/cli/migrate/index.js.map +1 -1
  229. package/lib/cli/migrate/nodeVersion/checks.js +26 -68
  230. package/lib/cli/migrate/nodeVersion/checks.js.map +2 -2
  231. package/lib/cli/migrate/nodeVersion/index.js +24 -56
  232. package/lib/cli/migrate/nodeVersion/index.js.map +2 -2
  233. package/lib/cli/node/index.js +20 -60
  234. package/lib/cli/node/index.js.map +3 -3
  235. package/lib/cli/release/index.js +3 -29
  236. package/lib/cli/release/index.js.map +1 -1
  237. package/lib/cli/start/index.js +15 -51
  238. package/lib/cli/start/index.js.map +3 -3
  239. package/lib/cli/test/index.js +3 -45
  240. package/lib/cli/test/index.js.map +2 -2
  241. package/lib/cli/version/index.js +5 -31
  242. package/lib/cli/version/index.js.map +1 -1
  243. package/lib/config/prettier.d.ts +7 -0
  244. package/lib/index.js +4 -49
  245. package/lib/index.js.map +2 -2
  246. package/lib/skuba.js +26 -44
  247. package/lib/skuba.js.map +3 -3
  248. package/lib/{cli → src/cli}/configure/analyseDependencies.d.ts +1 -1
  249. package/lib/{cli → src/cli}/configure/analysis/package.d.ts +2 -3
  250. package/lib/{cli → src/cli}/configure/ensureTemplateCompletion.d.ts +1 -1
  251. package/lib/{cli → src/cli}/configure/getEntryPoint.d.ts +1 -1
  252. package/lib/{cli → src/cli}/configure/getProjectType.d.ts +1 -1
  253. package/lib/src/cli/configure/processing/package.d.ts +5 -0
  254. package/lib/{cli → src/cli}/configure/types.d.ts +15 -4
  255. package/lib/{cli → src/cli}/init/getConfig.d.ts +1 -1
  256. package/lib/{cli → src/cli}/init/prompts.d.ts +4 -4
  257. package/lib/{cli → src/cli}/lint/internalLints/upgrade/index.d.ts +1 -1
  258. package/lib/{index.d.ts → src/index.d.ts} +0 -1
  259. package/lib/src/utils/fs.d.ts +1 -0
  260. package/lib/{utils → src/utils}/manifest.d.ts +3 -2
  261. package/lib/src/utils/sleep.d.ts +5 -0
  262. package/lib/{utils → src/utils}/wait.d.ts +0 -4
  263. package/lib/{wrapper → src/wrapper}/http.d.ts +0 -6
  264. package/lib/src/wrapper/server.d.ts +7 -0
  265. package/lib/utils/args.js +8 -50
  266. package/lib/utils/args.js.map +2 -2
  267. package/lib/utils/command.js +6 -50
  268. package/lib/utils/command.js.map +3 -3
  269. package/lib/utils/copy.js +22 -64
  270. package/lib/utils/copy.js.map +2 -2
  271. package/lib/utils/dir.js +37 -84
  272. package/lib/utils/dir.js.map +3 -3
  273. package/lib/utils/env.js +1 -27
  274. package/lib/utils/env.js.map +1 -1
  275. package/lib/utils/error.js +11 -53
  276. package/lib/utils/error.js.map +1 -1
  277. package/lib/utils/exec.js +26 -70
  278. package/lib/utils/exec.js.map +3 -3
  279. package/lib/utils/fs.js +15 -0
  280. package/lib/utils/fs.js.map +7 -0
  281. package/lib/utils/help.js +5 -31
  282. package/lib/utils/help.js.map +1 -1
  283. package/lib/utils/logging.js +13 -55
  284. package/lib/utils/logging.js.map +2 -2
  285. package/lib/utils/logo.js +23 -59
  286. package/lib/utils/logo.js.map +2 -2
  287. package/lib/utils/manifest.js +12 -60
  288. package/lib/utils/manifest.js.map +3 -3
  289. package/lib/utils/npmrc.js +1 -27
  290. package/lib/utils/npmrc.js.map +1 -1
  291. package/lib/utils/packageManager.js +14 -56
  292. package/lib/utils/packageManager.js.map +2 -2
  293. package/lib/utils/port.js +4 -42
  294. package/lib/utils/port.js.map +2 -2
  295. package/lib/utils/sleep.js +9 -0
  296. package/lib/utils/sleep.js.map +7 -0
  297. package/lib/utils/template.js +21 -68
  298. package/lib/utils/template.js.map +3 -3
  299. package/lib/utils/validation.js +6 -42
  300. package/lib/utils/validation.js.map +1 -1
  301. package/lib/utils/version.js +11 -53
  302. package/lib/utils/version.js.map +2 -2
  303. package/lib/utils/wait.js +6 -42
  304. package/lib/utils/wait.js.map +2 -2
  305. package/lib/utils/worker.js +9 -37
  306. package/lib/utils/worker.js.map +1 -1
  307. package/lib/wrapper/functionHandler.js +17 -50
  308. package/lib/wrapper/functionHandler.js.map +2 -2
  309. package/lib/wrapper/http.js +7 -53
  310. package/lib/wrapper/http.js.map +3 -3
  311. package/lib/wrapper/index.js +6 -6
  312. package/lib/wrapper/index.js.map +1 -1
  313. package/lib/wrapper/main.js +7 -43
  314. package/lib/wrapper/main.js.map +3 -3
  315. package/lib/wrapper/requestListener.js +12 -47
  316. package/lib/wrapper/requestListener.js.map +3 -3
  317. package/lib/wrapper/server.js +9 -0
  318. package/lib/wrapper/server.js.map +7 -0
  319. package/package.json +19 -24
  320. package/template/base/_.prettierrc.js +1 -1
  321. package/template/base/_eslint.config.js +1 -1
  322. package/template/base/_pnpm-workspace.yaml +3 -2
  323. package/template/base/vitest.config.ts +25 -0
  324. package/template/express-rest-api/.gantry/dev.yml +2 -2
  325. package/template/express-rest-api/.gantry/prod.yml +2 -2
  326. package/template/express-rest-api/package.json +6 -5
  327. package/template/express-rest-api/skuba.template.js +1 -1
  328. package/template/express-rest-api/src/app.test.ts +1 -0
  329. package/template/greeter/package.json +4 -3
  330. package/template/greeter/skuba.template.js +1 -1
  331. package/template/greeter/src/app.test.ts +3 -1
  332. package/template/koa-rest-api/.gantry/dev.yml +2 -2
  333. package/template/koa-rest-api/.gantry/prod.yml +2 -2
  334. package/template/koa-rest-api/package.json +6 -5
  335. package/template/koa-rest-api/skuba.template.js +1 -1
  336. package/template/koa-rest-api/src/api/jobs/getJobs.test.ts +2 -0
  337. package/template/koa-rest-api/src/api/jobs/postJob.test.ts +2 -0
  338. package/template/koa-rest-api/src/app.test.ts +2 -0
  339. package/template/koa-rest-api/src/framework/server.test.ts +2 -2
  340. package/template/koa-rest-api/src/framework/validation.test.ts +2 -0
  341. package/template/koa-rest-api/src/testing/metrics.ts +2 -0
  342. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +15 -3
  343. package/template/lambda-sqs-worker-cdk/infra/appStack.test.ts +11 -9
  344. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +1 -1
  345. package/template/lambda-sqs-worker-cdk/package.json +6 -5
  346. package/template/lambda-sqs-worker-cdk/skuba.template.js +1 -1
  347. package/template/lambda-sqs-worker-cdk/src/app.test.ts +22 -13
  348. package/template/lambda-sqs-worker-cdk/src/framework/handler.test.ts +1 -0
  349. package/template/lambda-sqs-worker-cdk/src/framework/validation.test.ts +33 -31
  350. package/template/lambda-sqs-worker-cdk/src/services/jobScorer.test.ts +8 -2
  351. package/template/lambda-sqs-worker-cdk/src/services/pipelineEventSender.test.ts +3 -2
  352. package/template/lambda-sqs-worker-cdk/src/testing/services.ts +4 -3
  353. package/template/oss-npm-package/.github/workflows/release.yml +1 -1
  354. package/template/oss-npm-package/.github/workflows/validate.yml +1 -1
  355. package/template/oss-npm-package/_package.json +1 -0
  356. package/template/oss-npm-package/skuba.template.js +1 -1
  357. package/template/oss-npm-package/src/index.test.ts +2 -0
  358. package/template/private-npm-package/_package.json +1 -0
  359. package/template/private-npm-package/skuba.template.js +1 -1
  360. package/template/private-npm-package/src/index.test.ts +2 -0
  361. package/config/jest.js +0 -1
  362. package/config/prettier.d.ts +0 -4
  363. package/jest/moduleNameMapper.js +0 -64
  364. package/jest/transform.js +0 -62
  365. package/jest/tsConfig.js +0 -26
  366. package/jest-preset.js +0 -37
  367. package/lib/api/jest/index.d.ts +0 -15
  368. package/lib/api/jest/index.js +0 -59
  369. package/lib/api/jest/index.js.map +0 -7
  370. package/lib/cli/configure/modules/jest.d.ts +0 -2
  371. package/lib/cli/configure/modules/jest.js +0 -86
  372. package/lib/cli/configure/modules/jest.js.map +0 -7
  373. package/lib/cli/configure/processing/package.d.ts +0 -71
  374. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/upgradeESLint.d.ts +0 -2
  375. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/upgradeESLint.js +0 -144
  376. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/upgradeESLint.js.map +0 -7
  377. package/lib/cli/test/reporters/github/annotations.d.ts +0 -9
  378. package/lib/cli/test/reporters/github/annotations.js +0 -102
  379. package/lib/cli/test/reporters/github/annotations.js.map +0 -7
  380. package/lib/cli/test/reporters/github/index.d.ts +0 -5
  381. package/lib/cli/test/reporters/github/index.js +0 -74
  382. package/lib/cli/test/reporters/github/index.js.map +0 -7
  383. package/template/base/jest.config.ts +0 -19
  384. package/template/base/jest.setup.ts +0 -3
  385. /package/lib/{cli → src/cli}/adapter/eslint.d.ts +0 -0
  386. /package/lib/{cli → src/cli}/adapter/prettier.d.ts +0 -0
  387. /package/lib/{cli → src/cli}/build/args.d.ts +0 -0
  388. /package/lib/{cli → src/cli}/build/assets.d.ts +0 -0
  389. /package/lib/{cli → src/cli}/build/esbuild.d.ts +0 -0
  390. /package/lib/{cli → src/cli}/build/index.d.ts +0 -0
  391. /package/lib/{cli → src/cli}/build/tsc.d.ts +0 -0
  392. /package/lib/{cli → src/cli}/buildPackage/index.d.ts +0 -0
  393. /package/lib/{cli → src/cli}/configure/analyseConfiguration.d.ts +0 -0
  394. /package/lib/{cli → src/cli}/configure/analysis/diff.d.ts +0 -0
  395. /package/lib/{cli → src/cli}/configure/analysis/files.d.ts +0 -0
  396. /package/lib/{cli → src/cli}/configure/analysis/git.d.ts +0 -0
  397. /package/lib/{cli → src/cli}/configure/analysis/project.d.ts +0 -0
  398. /package/lib/{cli → src/cli}/configure/dependencies/index.d.ts +0 -0
  399. /package/lib/{cli → src/cli}/configure/dependencies/seekDatadogCustomMetrics.d.ts +0 -0
  400. /package/lib/{cli → src/cli}/configure/dependencies/seekKoala.d.ts +0 -0
  401. /package/lib/{cli → src/cli}/configure/dependencies/skuba.d.ts +0 -0
  402. /package/lib/{cli → src/cli}/configure/dependencies/skubaDeps.d.ts +0 -0
  403. /package/lib/{cli → src/cli}/configure/dependencies/skubaDive.d.ts +0 -0
  404. /package/lib/{cli → src/cli}/configure/index.d.ts +0 -0
  405. /package/lib/{cli → src/cli}/configure/modules/eslint.d.ts +0 -0
  406. /package/lib/{cli → src/cli}/configure/modules/ignore.d.ts +0 -0
  407. /package/lib/{cli → src/cli}/configure/modules/index.d.ts +0 -0
  408. /package/lib/{cli → src/cli}/configure/modules/nodemon.d.ts +0 -0
  409. /package/lib/{cli → src/cli}/configure/modules/package.d.ts +0 -0
  410. /package/lib/{cli → src/cli}/configure/modules/prettier.d.ts +0 -0
  411. /package/lib/{cli → src/cli}/configure/modules/renovate.d.ts +0 -0
  412. /package/lib/{cli → src/cli}/configure/modules/serverless.d.ts +0 -0
  413. /package/lib/{cli → src/cli}/configure/modules/tslint.d.ts +0 -0
  414. /package/lib/{cli → src/cli}/configure/processing/configFile.d.ts +0 -0
  415. /package/lib/{cli → src/cli}/configure/processing/deleteFiles.d.ts +0 -0
  416. /package/lib/{cli → src/cli}/configure/processing/javascript.d.ts +0 -0
  417. /package/lib/{cli → src/cli}/configure/processing/json.d.ts +0 -0
  418. /package/lib/{cli → src/cli}/configure/processing/loadFiles.d.ts +0 -0
  419. /package/lib/{cli → src/cli}/configure/processing/module.d.ts +0 -0
  420. /package/lib/{cli → src/cli}/configure/processing/prettier.d.ts +0 -0
  421. /package/lib/{cli → src/cli}/configure/processing/record.d.ts +0 -0
  422. /package/lib/{cli → src/cli}/configure/processing/typescript.d.ts +0 -0
  423. /package/lib/{cli → src/cli}/format/index.d.ts +0 -0
  424. /package/lib/{cli → src/cli}/help/index.d.ts +0 -0
  425. /package/lib/{cli → src/cli}/init/git.d.ts +0 -0
  426. /package/lib/{cli → src/cli}/init/index.d.ts +0 -0
  427. /package/lib/{cli → src/cli}/init/types.d.ts +0 -0
  428. /package/lib/{cli → src/cli}/init/validation.d.ts +0 -0
  429. /package/lib/{cli → src/cli}/init/writePackageJson.d.ts +0 -0
  430. /package/lib/{cli → src/cli}/lint/annotate/buildkite/eslint.d.ts +0 -0
  431. /package/lib/{cli → src/cli}/lint/annotate/buildkite/index.d.ts +0 -0
  432. /package/lib/{cli → src/cli}/lint/annotate/buildkite/internal.d.ts +0 -0
  433. /package/lib/{cli → src/cli}/lint/annotate/buildkite/prettier.d.ts +0 -0
  434. /package/lib/{cli → src/cli}/lint/annotate/buildkite/tsc.d.ts +0 -0
  435. /package/lib/{cli → src/cli}/lint/annotate/github/eslint.d.ts +0 -0
  436. /package/lib/{cli → src/cli}/lint/annotate/github/index.d.ts +0 -0
  437. /package/lib/{cli → src/cli}/lint/annotate/github/internal.d.ts +0 -0
  438. /package/lib/{cli → src/cli}/lint/annotate/github/prettier.d.ts +0 -0
  439. /package/lib/{cli → src/cli}/lint/annotate/github/tsc.d.ts +0 -0
  440. /package/lib/{cli → src/cli}/lint/annotate/index.d.ts +0 -0
  441. /package/lib/{cli → src/cli}/lint/autofix.d.ts +0 -0
  442. /package/lib/{cli → src/cli}/lint/eslint.d.ts +0 -0
  443. /package/lib/{cli → src/cli}/lint/external.d.ts +0 -0
  444. /package/lib/{cli → src/cli}/lint/index.d.ts +0 -0
  445. /package/lib/{cli → src/cli}/lint/internal.d.ts +0 -0
  446. /package/lib/{cli → src/cli}/lint/internalLints/detectBadCodeowners.d.ts +0 -0
  447. /package/lib/{cli → src/cli}/lint/internalLints/noSkubaTemplateJs.d.ts +0 -0
  448. /package/lib/{cli → src/cli}/lint/internalLints/patchRenovateConfig.d.ts +0 -0
  449. /package/lib/{cli → src/cli}/lint/internalLints/refreshConfigFiles.d.ts +0 -0
  450. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/10.0.4/index.d.ts +0 -0
  451. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/10.0.4/removeYarnIgnoreOptionalFlags.d.ts +0 -0
  452. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/10.1.0/index.d.ts +0 -0
  453. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/10.1.0/migrateNpmrcToPnpmWorkspace.d.ts +0 -0
  454. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/10.1.0/stopBundlingInCDKTests.d.ts +0 -0
  455. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.0.2/index.d.ts +0 -0
  456. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.d.ts +0 -0
  457. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.1.1/index.d.ts +0 -0
  458. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.1.1/patchJestSnapshots.d.ts +0 -0
  459. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.3.0/index.d.ts +0 -0
  460. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.3.0/patchApiTokenFromEnvironment.d.ts +0 -0
  461. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.3.0/patchDockerfileSyntaxDirective.d.ts +0 -0
  462. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.4.0/index.d.ts +0 -0
  463. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.4.0/patchDockerfileCIVariable.d.ts +0 -0
  464. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.4.1/configureTsConfigForESM.d.ts +0 -0
  465. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.4.1/index.d.ts +0 -0
  466. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.4.1/patchApiDockerfiles.d.ts +0 -0
  467. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.4.1/rewriteSrcImports.d.ts +0 -0
  468. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/12.4.1/updateLambdaConfigs.d.ts +0 -0
  469. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/7.3.1/addEmptyExports.d.ts +0 -0
  470. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/7.3.1/index.d.ts +0 -0
  471. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/7.3.1/patchDockerfile.d.ts +0 -0
  472. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/7.3.1/patchServerListener.d.ts +0 -0
  473. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/8.0.0/index.d.ts +0 -0
  474. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/8.0.0/patchPnpmPackageManager.d.ts +0 -0
  475. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/8.2.1/collapseDuplicateMergeKeys.d.ts +0 -0
  476. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/8.2.1/index.d.ts +0 -0
  477. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/8.2.1/moveNpmrcMounts.d.ts +0 -0
  478. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/8.2.1/patchDockerCompose.d.ts +0 -0
  479. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/8.2.1/patchDockerImages.d.ts +0 -0
  480. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/9.0.1/index.d.ts +0 -0
  481. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/9.0.1/patchPnpmDockerImages.d.ts +0 -0
  482. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/9.1.0/index.d.ts +0 -0
  483. /package/lib/{cli → src/cli}/lint/internalLints/upgrade/patches/9.1.0/upgradeNode.d.ts +0 -0
  484. /package/lib/{cli → src/cli}/lint/prettier.d.ts +0 -0
  485. /package/lib/{cli → src/cli}/lint/tsc.d.ts +0 -0
  486. /package/lib/{cli → src/cli}/lint/types.d.ts +0 -0
  487. /package/lib/{cli → src/cli}/migrate/index.d.ts +0 -0
  488. /package/lib/{cli → src/cli}/migrate/nodeVersion/checks.d.ts +0 -0
  489. /package/lib/{cli → src/cli}/migrate/nodeVersion/index.d.ts +0 -0
  490. /package/lib/{cli → src/cli}/node/index.d.ts +0 -0
  491. /package/lib/{cli → src/cli}/release/index.d.ts +0 -0
  492. /package/lib/{cli → src/cli}/start/index.d.ts +0 -0
  493. /package/lib/{cli → src/cli}/test/index.d.ts +0 -0
  494. /package/lib/{cli → src/cli}/version/index.d.ts +0 -0
  495. /package/lib/{skuba.d.ts → src/skuba.d.ts} +0 -0
  496. /package/lib/{utils → src/utils}/args.d.ts +0 -0
  497. /package/lib/{utils → src/utils}/command.d.ts +0 -0
  498. /package/lib/{utils → src/utils}/copy.d.ts +0 -0
  499. /package/lib/{utils → src/utils}/dir.d.ts +0 -0
  500. /package/lib/{utils → src/utils}/env.d.ts +0 -0
  501. /package/lib/{utils → src/utils}/error.d.ts +0 -0
  502. /package/lib/{utils → src/utils}/exec.d.ts +0 -0
  503. /package/lib/{utils → src/utils}/help.d.ts +0 -0
  504. /package/lib/{utils → src/utils}/logging.d.ts +0 -0
  505. /package/lib/{utils → src/utils}/logo.d.ts +0 -0
  506. /package/lib/{utils → src/utils}/npmrc.d.ts +0 -0
  507. /package/lib/{utils → src/utils}/packageManager.d.ts +0 -0
  508. /package/lib/{utils → src/utils}/port.d.ts +0 -0
  509. /package/lib/{utils → src/utils}/template.d.ts +0 -0
  510. /package/lib/{utils → src/utils}/validation.d.ts +0 -0
  511. /package/lib/{utils → src/utils}/version.d.ts +0 -0
  512. /package/lib/{utils → src/utils}/worker.d.ts +0 -0
  513. /package/lib/{wrapper → src/wrapper}/functionHandler.d.ts +0 -0
  514. /package/lib/{wrapper → src/wrapper}/index.d.ts +0 -0
  515. /package/lib/{wrapper → src/wrapper}/main.d.ts +0 -0
  516. /package/lib/{wrapper → src/wrapper}/requestListener.d.ts +0 -0
package/lib/utils/wait.js CHANGED
@@ -1,45 +1,15 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var wait_exports = {};
20
- __export(wait_exports, {
21
- sleep: () => sleep,
22
- throwOnTimeout: () => throwOnTimeout,
23
- withTimeout: () => withTimeout
24
- });
25
- module.exports = __toCommonJS(wait_exports);
26
- var import_error = require("./error.js");
27
- var import_logging = require("./logging.js");
28
- const sleep = (ms) => {
29
- let timeout;
30
- return Object.assign(
31
- new Promise((resolve) => timeout = setTimeout(resolve, ms)),
32
- { clear: () => clearTimeout(timeout) }
33
- );
34
- };
35
- const throwOnTimeout = async (promise, { s }) => {
2
+ import { createTerseError } from "./error.js";
3
+ import { pluralise } from "./logging.js";
4
+ import { sleep } from "./sleep.js";
5
+ export const throwOnTimeout = async (promise, { s }) => {
36
6
  const result = await withTimeout(promise, { s });
37
7
  if (!result.ok) {
38
- throw (0, import_error.createTerseError)(`Timed out after ${(0, import_logging.pluralise)(s, "second")}`);
8
+ throw createTerseError(`Timed out after ${pluralise(s, "second")}`);
39
9
  }
40
10
  return result.value;
41
11
  };
42
- const withTimeout = async (promise, { s }) => {
12
+ export const withTimeout = async (promise, { s }) => {
43
13
  const timeout = sleep(s * 1e3);
44
14
  try {
45
15
  return await Promise.race([
@@ -50,10 +20,4 @@ const withTimeout = async (promise, { s }) => {
50
20
  timeout.clear?.();
51
21
  }
52
22
  };
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- sleep,
56
- throwOnTimeout,
57
- withTimeout
58
- });
59
23
  //# sourceMappingURL=wait.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/wait.ts"],
4
- "sourcesContent": ["import { createTerseError } from './error.js';\nimport { pluralise } from './logging.js';\n\ninterface Timeout extends PromiseLike<void> {\n clear?: () => void;\n}\n\nexport const sleep = (ms: number): Timeout => {\n let timeout: NodeJS.Timeout;\n\n return Object.assign(\n new Promise<void>((resolve) => (timeout = setTimeout(resolve, ms))),\n { clear: () => clearTimeout(timeout) },\n );\n};\n\nexport const throwOnTimeout = async <T>(\n promise: PromiseLike<T>,\n { s }: { s: number },\n): Promise<T> => {\n const result = await withTimeout(promise, { s });\n\n if (!result.ok) {\n throw createTerseError(`Timed out after ${pluralise(s, 'second')}`);\n }\n\n return result.value;\n};\n\ntype TimeoutResult<T> = { ok: true; value: T } | { ok: false };\n\nexport const withTimeout = async <T>(\n promise: T | PromiseLike<T>,\n { s }: { s: number },\n): Promise<TimeoutResult<T>> => {\n const timeout = sleep(s * 1_000);\n\n try {\n return await Promise.race<TimeoutResult<T>>([\n Promise.resolve(promise).then((value) => ({ ok: true, value })),\n timeout.then(() => ({ ok: false })),\n ]);\n } finally {\n timeout.clear?.();\n }\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,qBAA0B;AAMnB,MAAM,QAAQ,CAAC,OAAwB;AAC5C,MAAI;AAEJ,SAAO,OAAO;AAAA,IACZ,IAAI,QAAc,CAAC,YAAa,UAAU,WAAW,SAAS,EAAE,CAAE;AAAA,IAClE,EAAE,OAAO,MAAM,aAAa,OAAO,EAAE;AAAA,EACvC;AACF;AAEO,MAAM,iBAAiB,OAC5B,SACA,EAAE,EAAE,MACW;AACf,QAAM,SAAS,MAAM,YAAY,SAAS,EAAE,EAAE,CAAC;AAE/C,MAAI,CAAC,OAAO,IAAI;AACd,cAAM,+BAAiB,uBAAmB,0BAAU,GAAG,QAAQ,CAAC,EAAE;AAAA,EACpE;AAEA,SAAO,OAAO;AAChB;AAIO,MAAM,cAAc,OACzB,SACA,EAAE,EAAE,MAC0B;AAC9B,QAAM,UAAU,MAAM,IAAI,GAAK;AAE/B,MAAI;AACF,WAAO,MAAM,QAAQ,KAAuB;AAAA,MAC1C,QAAQ,QAAQ,OAAO,EAAE,KAAK,CAAC,WAAW,EAAE,IAAI,MAAM,MAAM,EAAE;AAAA,MAC9D,QAAQ,KAAK,OAAO,EAAE,IAAI,MAAM,EAAE;AAAA,IACpC,CAAC;AAAA,EACH,UAAE;AACA,YAAQ,QAAQ;AAAA,EAClB;AACF;",
4
+ "sourcesContent": ["import { createTerseError } from './error.js';\nimport { pluralise } from './logging.js';\nimport { sleep } from './sleep.js';\n\nexport const throwOnTimeout = async <T>(\n promise: PromiseLike<T>,\n { s }: { s: number },\n): Promise<T> => {\n const result = await withTimeout(promise, { s });\n\n if (!result.ok) {\n throw createTerseError(`Timed out after ${pluralise(s, 'second')}`);\n }\n\n return result.value;\n};\n\ntype TimeoutResult<T> = { ok: true; value: T } | { ok: false };\n\nexport const withTimeout = async <T>(\n promise: T | PromiseLike<T>,\n { s }: { s: number },\n): Promise<TimeoutResult<T>> => {\n const timeout = sleep(s * 1_000);\n\n try {\n return await Promise.race<TimeoutResult<T>>([\n Promise.resolve(promise).then((value) => ({ ok: true, value })),\n timeout.then(() => ({ ok: false })),\n ]);\n } finally {\n timeout.clear?.();\n }\n};\n"],
5
+ "mappings": ";AAAA,SAAS,wBAAwB;AACjC,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAEf,aAAM,iBAAiB,OAC5B,SACA,EAAE,EAAE,MACW;AACf,QAAM,SAAS,MAAM,YAAY,SAAS,EAAE,EAAE,CAAC;AAE/C,MAAI,CAAC,OAAO,IAAI;AACd,UAAM,iBAAiB,mBAAmB,UAAU,GAAG,QAAQ,CAAC,EAAE;AAAA,EACpE;AAEA,SAAO,OAAO;AAChB;AAIO,aAAM,cAAc,OACzB,SACA,EAAE,EAAE,MAC0B;AAC9B,QAAM,UAAU,MAAM,IAAI,GAAK;AAE/B,MAAI;AACF,WAAO,MAAM,QAAQ,KAAuB;AAAA,MAC1C,QAAQ,QAAQ,OAAO,EAAE,KAAK,CAAC,WAAW,EAAE,IAAI,MAAM,MAAM,EAAE;AAAA,MAC9D,QAAQ,KAAK,OAAO,EAAE,IAAI,MAAM,EAAE;AAAA,IACpC,CAAC;AAAA,EACH,UAAE;AACA,YAAQ,QAAQ;AAAA,EAClB;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,35 +1,12 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var worker_exports = {};
20
- __export(worker_exports, {
21
- execWorkerThread: () => execWorkerThread,
22
- postWorkerOutput: () => postWorkerOutput
23
- });
24
- module.exports = __toCommonJS(worker_exports);
25
- var import_util = require("util");
26
- var import_worker_threads = require("worker_threads");
27
- var import_logging = require("./logging.js");
28
- const execWorkerThread = async (filepath, input) => {
2
+ import { inspect } from "util";
3
+ import { Worker, parentPort, workerData } from "worker_threads";
4
+ import { log } from "./logging.js";
5
+ export const execWorkerThread = async (filepath, input) => {
29
6
  let output;
30
7
  let messageReceived = false;
31
8
  return new Promise(
32
- (resolve, reject) => new import_worker_threads.Worker(filepath, {
9
+ (resolve, reject) => new Worker(filepath, {
33
10
  workerData: input
34
11
  }).on("error", reject).on(
35
12
  "exit",
@@ -44,20 +21,15 @@ const execWorkerThread = async (filepath, input) => {
44
21
  }).on("messageerror", (err) => reject(err))
45
22
  );
46
23
  };
47
- const postWorkerOutput = (fn, logger = import_logging.log) => {
48
- const port = import_worker_threads.parentPort;
24
+ export const postWorkerOutput = (fn, logger = log) => {
25
+ const port = parentPort;
49
26
  if (!port) {
50
27
  logger.err("`postWorkerOutput` called outside of a worker thread context");
51
28
  process.exit(1);
52
29
  }
53
- fn(import_worker_threads.workerData).then((output) => port.postMessage(output)).catch((err) => {
54
- logger.err((0, import_util.inspect)(err));
30
+ fn(workerData).then((output) => port.postMessage(output)).catch((err) => {
31
+ logger.err(inspect(err));
55
32
  process.exit(1);
56
33
  });
57
34
  };
58
- // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {
60
- execWorkerThread,
61
- postWorkerOutput
62
- });
63
35
  //# sourceMappingURL=worker.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/worker.ts"],
4
4
  "sourcesContent": ["import { inspect } from 'util';\nimport { Worker, parentPort, workerData } from 'worker_threads';\n\nimport { log } from './logging.js';\n\n/**\n * Executes a script at `filepath` in a Node.js worker thread.\n */\nexport const execWorkerThread = async <Input, Output>(\n filepath: string,\n input: Input,\n) => {\n let output: Output;\n let messageReceived = false;\n\n return new Promise<Output>((resolve, reject) =>\n new Worker(filepath, {\n workerData: input,\n })\n .on('error', reject)\n .on('exit', (code) =>\n messageReceived\n ? resolve(output)\n : reject(\n new Error(\n code\n ? `Worker thread failed with exit code ${code}`\n : 'Worker thread exited without posting a message',\n ),\n ),\n )\n .on('message', (message: Output) => {\n // Defer promise resolution to `exit` so stdio can settle.\n output = message;\n messageReceived = true;\n })\n .on('messageerror', (err) => reject(err)),\n );\n};\n\n/**\n * Runs a function in a Node.js worker thread context, forwarding the result\n * to the parent thread.\n */\nexport const postWorkerOutput = <Input, Output>(\n fn: (input: Input) => Promise<Output>,\n logger = log,\n) => {\n const port = parentPort;\n\n if (!port) {\n logger.err('`postWorkerOutput` called outside of a worker thread context');\n\n process.exit(1);\n }\n\n fn(workerData as Input)\n .then((output) => port.postMessage(output))\n .catch((err) => {\n logger.err(inspect(err));\n\n process.exit(1);\n });\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwB;AACxB,4BAA+C;AAE/C,qBAAoB;AAKb,MAAM,mBAAmB,OAC9B,UACA,UACG;AACH,MAAI;AACJ,MAAI,kBAAkB;AAEtB,SAAO,IAAI;AAAA,IAAgB,CAAC,SAAS,WACnC,IAAI,6BAAO,UAAU;AAAA,MACnB,YAAY;AAAA,IACd,CAAC,EACE,GAAG,SAAS,MAAM,EAClB;AAAA,MAAG;AAAA,MAAQ,CAAC,SACX,kBACI,QAAQ,MAAM,IACd;AAAA,QACE,IAAI;AAAA,UACF,OACI,uCAAuC,IAAI,KAC3C;AAAA,QACN;AAAA,MACF;AAAA,IACN,EACC,GAAG,WAAW,CAAC,YAAoB;AAElC,eAAS;AACT,wBAAkB;AAAA,IACpB,CAAC,EACA,GAAG,gBAAgB,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC5C;AACF;AAMO,MAAM,mBAAmB,CAC9B,IACA,SAAS,uBACN;AACH,QAAM,OAAO;AAEb,MAAI,CAAC,MAAM;AACT,WAAO,IAAI,8DAA8D;AAEzE,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,KAAG,gCAAmB,EACnB,KAAK,CAAC,WAAW,KAAK,YAAY,MAAM,CAAC,EACzC,MAAM,CAAC,QAAQ;AACd,WAAO,QAAI,qBAAQ,GAAG,CAAC;AAEvB,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACL;",
5
+ "mappings": ";AAAA,SAAS,eAAe;AACxB,SAAS,QAAQ,YAAY,kBAAkB;AAE/C,SAAS,WAAW;AAKb,aAAM,mBAAmB,OAC9B,UACA,UACG;AACH,MAAI;AACJ,MAAI,kBAAkB;AAEtB,SAAO,IAAI;AAAA,IAAgB,CAAC,SAAS,WACnC,IAAI,OAAO,UAAU;AAAA,MACnB,YAAY;AAAA,IACd,CAAC,EACE,GAAG,SAAS,MAAM,EAClB;AAAA,MAAG;AAAA,MAAQ,CAAC,SACX,kBACI,QAAQ,MAAM,IACd;AAAA,QACE,IAAI;AAAA,UACF,OACI,uCAAuC,IAAI,KAC3C;AAAA,QACN;AAAA,MACF;AAAA,IACN,EACC,GAAG,WAAW,CAAC,YAAoB;AAElC,eAAS;AACT,wBAAkB;AAAA,IACpB,CAAC,EACA,GAAG,gBAAgB,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC5C;AACF;AAMO,aAAM,mBAAmB,CAC9B,IACA,SAAS,QACN;AACH,QAAM,OAAO;AAEb,MAAI,CAAC,MAAM;AACT,WAAO,IAAI,8DAA8D;AAEzE,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,KAAG,UAAmB,EACnB,KAAK,CAAC,WAAW,KAAK,YAAY,MAAM,CAAC,EACzC,MAAM,CAAC,QAAQ;AACd,WAAO,IAAI,QAAQ,GAAG,CAAC;AAEvB,YAAQ,KAAK,CAAC;AAAA,EAChB,CAAC;AACL;",
6
6
  "names": []
7
7
  }
@@ -1,63 +1,30 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var functionHandler_exports = {};
30
- __export(functionHandler_exports, {
31
- runFunctionHandler: () => runFunctionHandler
32
- });
33
- module.exports = __toCommonJS(functionHandler_exports);
34
- var import_function_arguments = __toESM(require("function-arguments"));
35
- var import_logging = require("../utils/logging.js");
36
- var import_validation = require("../utils/validation.js");
37
- var import_http = require("./http.js");
38
- const runFunctionHandler = async ({
2
+ import fnArgs from "function-arguments";
3
+ import { log } from "../utils/logging.js";
4
+ import { isFunction, isObject } from "../utils/validation.js";
5
+ import {
6
+ createRequestListenerFromFunction,
7
+ serveRequestListener
8
+ } from "./http.js";
9
+ export const runFunctionHandler = async ({
39
10
  availablePort,
40
11
  entryPoint,
41
12
  functionName
42
13
  }) => {
43
- if (!(0, import_validation.isObject)(entryPoint)) {
44
- import_logging.log.subtle(import_logging.log.bold(functionName), "is not exported");
14
+ if (!isObject(entryPoint)) {
15
+ log.subtle(log.bold(functionName), "is not exported");
45
16
  return;
46
17
  }
47
18
  const fn = entryPoint[functionName];
48
- if (!(0, import_validation.isFunction)(fn)) {
49
- import_logging.log.subtle(import_logging.log.bold(functionName), "is not a function");
19
+ if (!isFunction(fn)) {
20
+ log.subtle(log.bold(functionName), "is not a function");
50
21
  return;
51
22
  }
52
- import_logging.log.warn(
53
- import_logging.log.bold(functionName),
54
- `(${(0, import_function_arguments.default)(fn).map((arg) => arg || "?").join(", ")})`
23
+ log.warn(
24
+ log.bold(functionName),
25
+ `(${fnArgs(fn).map((arg) => arg || "?").join(", ")})`
55
26
  );
56
- const requestListener = (0, import_http.createRequestListenerFromFunction)(fn);
57
- return (0, import_http.serveRequestListener)(requestListener, availablePort);
27
+ const requestListener = createRequestListenerFromFunction(fn);
28
+ return serveRequestListener(requestListener, availablePort);
58
29
  };
59
- // Annotate the CommonJS export names for ESM import in node:
60
- 0 && (module.exports = {
61
- runFunctionHandler
62
- });
63
30
  //# sourceMappingURL=functionHandler.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapper/functionHandler.ts"],
4
4
  "sourcesContent": ["import fnArgs from 'function-arguments';\n\nimport { log } from '../utils/logging.js';\nimport { isFunction, isObject } from '../utils/validation.js';\n\nimport {\n createRequestListenerFromFunction,\n serveRequestListener,\n} from './http.js';\n\ninterface Args {\n availablePort?: number;\n entryPoint: unknown;\n functionName: string;\n}\n\n/**\n * Create an HTTP server that calls into an exported function.\n */\nexport const runFunctionHandler = async ({\n availablePort,\n entryPoint,\n functionName,\n}: Args): Promise<void> => {\n if (!isObject(entryPoint)) {\n log.subtle(log.bold(functionName), 'is not exported');\n return;\n }\n\n const fn = entryPoint[functionName];\n\n if (!isFunction(fn)) {\n log.subtle(log.bold(functionName), 'is not a function');\n return;\n }\n\n log.warn(\n log.bold(functionName),\n `(${fnArgs(fn)\n // Add a `?` placeholder for unnamed arguments.\n .map((arg) => arg || '?')\n .join(', ')})`,\n );\n\n const requestListener = createRequestListenerFromFunction(fn);\n\n return serveRequestListener(requestListener, availablePort);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAmB;AAEnB,qBAAoB;AACpB,wBAAqC;AAErC,kBAGO;AAWA,MAAM,qBAAqB,OAAO;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF,MAA2B;AACzB,MAAI,KAAC,4BAAS,UAAU,GAAG;AACzB,uBAAI,OAAO,mBAAI,KAAK,YAAY,GAAG,iBAAiB;AACpD;AAAA,EACF;AAEA,QAAM,KAAK,WAAW,YAAY;AAElC,MAAI,KAAC,8BAAW,EAAE,GAAG;AACnB,uBAAI,OAAO,mBAAI,KAAK,YAAY,GAAG,mBAAmB;AACtD;AAAA,EACF;AAEA,qBAAI;AAAA,IACF,mBAAI,KAAK,YAAY;AAAA,IACrB,QAAI,0BAAAA,SAAO,EAAE,EAEV,IAAI,CAAC,QAAQ,OAAO,GAAG,EACvB,KAAK,IAAI,CAAC;AAAA,EACf;AAEA,QAAM,sBAAkB,+CAAkC,EAAE;AAE5D,aAAO,kCAAqB,iBAAiB,aAAa;AAC5D;",
6
- "names": ["fnArgs"]
5
+ "mappings": ";AAAA,OAAO,YAAY;AAEnB,SAAS,WAAW;AACpB,SAAS,YAAY,gBAAgB;AAErC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAWA,aAAM,qBAAqB,OAAO;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AACF,MAA2B;AACzB,MAAI,CAAC,SAAS,UAAU,GAAG;AACzB,QAAI,OAAO,IAAI,KAAK,YAAY,GAAG,iBAAiB;AACpD;AAAA,EACF;AAEA,QAAM,KAAK,WAAW,YAAY;AAElC,MAAI,CAAC,WAAW,EAAE,GAAG;AACnB,QAAI,OAAO,IAAI,KAAK,YAAY,GAAG,mBAAmB;AACtD;AAAA,EACF;AAEA,MAAI;AAAA,IACF,IAAI,KAAK,YAAY;AAAA,IACrB,IAAI,OAAO,EAAE,EAEV,IAAI,CAAC,QAAQ,OAAO,GAAG,EACvB,KAAK,IAAI,CAAC;AAAA,EACf;AAEA,QAAM,kBAAkB,kCAAkC,EAAE;AAE5D,SAAO,qBAAqB,iBAAiB,aAAa;AAC5D;",
6
+ "names": []
7
7
  }
@@ -1,42 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var http_exports = {};
30
- __export(http_exports, {
31
- createRequestListenerFromFunction: () => createRequestListenerFromFunction,
32
- serveRequestListener: () => serveRequestListener,
33
- startServer: () => startServer
34
- });
35
- module.exports = __toCommonJS(http_exports);
36
- var import_http = __toESM(require("http"));
37
- var import_util = __toESM(require("util"));
38
- var import_logging = require("../utils/logging.js");
39
- const createRequestListenerFromFunction = (fn) => async (req, res) => {
2
+ import http from "http";
3
+ import util from "util";
4
+ import { startServer } from "./server.js";
5
+ export const createRequestListenerFromFunction = (fn) => async (req, res) => {
40
6
  const writeResponse = (response) => new Promise(
41
7
  (resolve, reject) => response === void 0 ? res.end(resolve) : res.write(
42
8
  response,
@@ -56,23 +22,11 @@ const createRequestListenerFromFunction = (fn) => async (req, res) => {
56
22
  await writeResponse(JSON.stringify(response, null, 2));
57
23
  } catch (err) {
58
24
  res.writeHead(500);
59
- await writeResponse(import_util.default.inspect(err));
25
+ await writeResponse(util.inspect(err));
60
26
  }
61
27
  };
62
- const serveRequestListener = (requestListener, port) => {
63
- const server = import_http.default.createServer(requestListener);
28
+ export const serveRequestListener = (requestListener, port) => {
29
+ const server = http.createServer(requestListener);
64
30
  return startServer(server, port);
65
31
  };
66
- const startServer = (server, port) => new Promise(
67
- (resolve, reject) => server.listen(port).on("close", resolve).on("error", reject).on("listening", () => {
68
- const address = server.address();
69
- import_logging.log.ok("listening on port", import_logging.log.bold(address.port));
70
- })
71
- );
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- createRequestListenerFromFunction,
75
- serveRequestListener,
76
- startServer
77
- });
78
32
  //# sourceMappingURL=http.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapper/http.ts"],
4
- "sourcesContent": ["import http from 'http';\nimport type { AddressInfo } from 'net';\nimport util from 'util';\n\nimport { log } from '../utils/logging.js';\n\n/**\n * Create an HTTP request listener based on the supplied function.\n *\n * - The request body is JSON parsed and passed into the function as parameters.\n * - The function's return value is JSON stringified into the response body.\n */\nexport const createRequestListenerFromFunction =\n (fn: (...args: unknown[]) => Promise<unknown>): http.RequestListener =>\n async (req, res) => {\n const writeResponse = (response: unknown) =>\n new Promise<void>((resolve, reject) =>\n response === undefined\n ? res.end(resolve)\n : res.write(response, 'utf8', (err) =>\n err ? reject(err) : res.end(resolve),\n ),\n );\n\n try {\n const requestBody = await new Promise<string>((resolve, reject) => {\n const data: Buffer[] = [];\n\n req\n .on('data', (chunk: Buffer) => data.push(chunk))\n .on('end', () => resolve(Buffer.concat(data).toString()))\n .on('error', (err) => reject(err));\n });\n\n // Treat an empty body as no arguments\n const jsonRequest: unknown = requestBody ? JSON.parse(requestBody) : [];\n\n // Pass a non-array request body as the first parameter\n const args: unknown[] = Array.isArray(jsonRequest)\n ? jsonRequest\n : [jsonRequest];\n\n const response: unknown = await fn(...args);\n\n res.writeHead(200, { 'Content-Type': 'application/json' });\n\n await writeResponse(JSON.stringify(response, null, 2));\n } catch (err) {\n res.writeHead(500);\n\n await writeResponse(util.inspect(err));\n }\n };\n\n/**\n * Create a HTTP server based on the supplied `http.RequestListener`.\n *\n * This function resolves when the server is closed.\n */\nexport const serveRequestListener = (\n requestListener: http.RequestListener,\n port?: number,\n) => {\n const server = http.createServer(requestListener);\n return startServer(server, port);\n};\n\n/**\n * Returns a HTTP server wrapped in a promise\n *\n * This function resolves when the server is closed.\n */\nexport const startServer = (server: http.Server, port?: number) =>\n new Promise<void>((resolve, reject) =>\n server\n .listen(port)\n .on('close', resolve)\n .on('error', reject)\n .on('listening', () => {\n const address = server.address() as AddressInfo;\n\n log.ok('listening on port', log.bold(address.port));\n }),\n );\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,kBAAiB;AAEjB,qBAAoB;AAQb,MAAM,oCACX,CAAC,OACD,OAAO,KAAK,QAAQ;AAClB,QAAM,gBAAgB,CAAC,aACrB,IAAI;AAAA,IAAc,CAAC,SAAS,WAC1B,aAAa,SACT,IAAI,IAAI,OAAO,IACf,IAAI;AAAA,MAAM;AAAA,MAAU;AAAA,MAAQ,CAAC,QAC3B,MAAM,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO;AAAA,IACrC;AAAA,EACN;AAEF,MAAI;AACF,UAAM,cAAc,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AACjE,YAAM,OAAiB,CAAC;AAExB,UACG,GAAG,QAAQ,CAAC,UAAkB,KAAK,KAAK,KAAK,CAAC,EAC9C,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,IAAI,EAAE,SAAS,CAAC,CAAC,EACvD,GAAG,SAAS,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,IACrC,CAAC;AAGD,UAAM,cAAuB,cAAc,KAAK,MAAM,WAAW,IAAI,CAAC;AAGtE,UAAM,OAAkB,MAAM,QAAQ,WAAW,IAC7C,cACA,CAAC,WAAW;AAEhB,UAAM,WAAoB,MAAM,GAAG,GAAG,IAAI;AAE1C,QAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;AAEzD,UAAM,cAAc,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA,EACvD,SAAS,KAAK;AACZ,QAAI,UAAU,GAAG;AAEjB,UAAM,cAAc,YAAAA,QAAK,QAAQ,GAAG,CAAC;AAAA,EACvC;AACF;AAOK,MAAM,uBAAuB,CAClC,iBACA,SACG;AACH,QAAM,SAAS,YAAAC,QAAK,aAAa,eAAe;AAChD,SAAO,YAAY,QAAQ,IAAI;AACjC;AAOO,MAAM,cAAc,CAAC,QAAqB,SAC/C,IAAI;AAAA,EAAc,CAAC,SAAS,WAC1B,OACG,OAAO,IAAI,EACX,GAAG,SAAS,OAAO,EACnB,GAAG,SAAS,MAAM,EAClB,GAAG,aAAa,MAAM;AACrB,UAAM,UAAU,OAAO,QAAQ;AAE/B,uBAAI,GAAG,qBAAqB,mBAAI,KAAK,QAAQ,IAAI,CAAC;AAAA,EACpD,CAAC;AACL;",
6
- "names": ["util", "http"]
4
+ "sourcesContent": ["import http from 'http';\nimport util from 'util';\n\nimport { startServer } from './server.js';\n\n/**\n * Create an HTTP request listener based on the supplied function.\n *\n * - The request body is JSON parsed and passed into the function as parameters.\n * - The function's return value is JSON stringified into the response body.\n */\nexport const createRequestListenerFromFunction =\n (fn: (...args: unknown[]) => Promise<unknown>): http.RequestListener =>\n async (req, res) => {\n const writeResponse = (response: unknown) =>\n new Promise<void>((resolve, reject) =>\n response === undefined\n ? res.end(resolve)\n : res.write(response, 'utf8', (err) =>\n err ? reject(err) : res.end(resolve),\n ),\n );\n\n try {\n const requestBody = await new Promise<string>((resolve, reject) => {\n const data: Buffer[] = [];\n\n req\n .on('data', (chunk: Buffer) => data.push(chunk))\n .on('end', () => resolve(Buffer.concat(data).toString()))\n .on('error', (err) => reject(err));\n });\n\n // Treat an empty body as no arguments\n const jsonRequest: unknown = requestBody ? JSON.parse(requestBody) : [];\n\n // Pass a non-array request body as the first parameter\n const args: unknown[] = Array.isArray(jsonRequest)\n ? jsonRequest\n : [jsonRequest];\n\n const response: unknown = await fn(...args);\n\n res.writeHead(200, { 'Content-Type': 'application/json' });\n\n await writeResponse(JSON.stringify(response, null, 2));\n } catch (err) {\n res.writeHead(500);\n\n await writeResponse(util.inspect(err));\n }\n };\n\n/**\n * Create a HTTP server based on the supplied `http.RequestListener`.\n *\n * This function resolves when the server is closed.\n */\nexport const serveRequestListener = (\n requestListener: http.RequestListener,\n port?: number,\n) => {\n const server = http.createServer(requestListener);\n return startServer(server, port);\n};\n"],
5
+ "mappings": ";AAAA,OAAO,UAAU;AACjB,OAAO,UAAU;AAEjB,SAAS,mBAAmB;AAQrB,aAAM,oCACX,CAAC,OACD,OAAO,KAAK,QAAQ;AAClB,QAAM,gBAAgB,CAAC,aACrB,IAAI;AAAA,IAAc,CAAC,SAAS,WAC1B,aAAa,SACT,IAAI,IAAI,OAAO,IACf,IAAI;AAAA,MAAM;AAAA,MAAU;AAAA,MAAQ,CAAC,QAC3B,MAAM,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO;AAAA,IACrC;AAAA,EACN;AAEF,MAAI;AACF,UAAM,cAAc,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AACjE,YAAM,OAAiB,CAAC;AAExB,UACG,GAAG,QAAQ,CAAC,UAAkB,KAAK,KAAK,KAAK,CAAC,EAC9C,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,IAAI,EAAE,SAAS,CAAC,CAAC,EACvD,GAAG,SAAS,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,IACrC,CAAC;AAGD,UAAM,cAAuB,cAAc,KAAK,MAAM,WAAW,IAAI,CAAC;AAGtE,UAAM,OAAkB,MAAM,QAAQ,WAAW,IAC7C,cACA,CAAC,WAAW;AAEhB,UAAM,WAAoB,MAAM,GAAG,GAAG,IAAI;AAE1C,QAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;AAEzD,UAAM,cAAc,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA,EACvD,SAAS,KAAK;AACZ,QAAI,UAAU,GAAG;AAEjB,UAAM,cAAc,KAAK,QAAQ,GAAG,CAAC;AAAA,EACvC;AACF;AAOK,aAAM,uBAAuB,CAClC,iBACA,SACG;AACH,QAAM,SAAS,KAAK,aAAa,eAAe;AAChD,SAAO,YAAY,QAAQ,IAAI;AACjC;",
6
+ "names": []
7
7
  }
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
- var import_error = require("../utils/error.js");
3
- var import_logging = require("../utils/logging.js");
4
- var import_main = require("./main.js");
2
+ import { handleCliError } from "../utils/error.js";
3
+ import { log } from "../utils/logging.js";
4
+ import { main } from "./main.js";
5
5
  const ENTRY_POINT_VAR = "__SKUBA_ENTRY_POINT";
6
6
  const PORT_VAR = "__SKUBA_PORT";
7
7
  const rawEntryPoint = process.env[ENTRY_POINT_VAR];
8
8
  if (!rawEntryPoint) {
9
- throw new Error(`Missing environment variable: ${import_logging.log.bold(ENTRY_POINT_VAR)}`);
9
+ throw new Error(`Missing environment variable: ${log.bold(ENTRY_POINT_VAR)}`);
10
10
  }
11
11
  const rawPort = process.env[PORT_VAR];
12
12
  if (!rawPort) {
13
- throw new Error(`Missing environment variable: ${import_logging.log.bold(PORT_VAR)}`);
13
+ throw new Error(`Missing environment variable: ${log.bold(PORT_VAR)}`);
14
14
  }
15
- (0, import_main.main)(rawEntryPoint, rawPort).catch(import_error.handleCliError);
15
+ main(rawEntryPoint, rawPort).catch(handleCliError);
16
16
  //# sourceMappingURL=index.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapper/index.ts"],
4
4
  "sourcesContent": ["/**\n * Wrapper around an entry point provided to `skuba node` or `skuba start`.\n *\n * Beyond simply loading the entry point, it supports the following features:\n *\n * - If you set the entry point to an exported function like `src/app#handler`,\n * it will spin up a local HTTP server that calls into the function.\n *\n * - If you `export =` or `export default` an Express or Koa application,\n * it will spin up a local HTTP server based on the request listener.\n */\n\nimport { handleCliError } from '../utils/error.js';\nimport { log } from '../utils/logging.js';\n\nimport { main } from './main.js';\n\nconst ENTRY_POINT_VAR = '__SKUBA_ENTRY_POINT';\nconst PORT_VAR = '__SKUBA_PORT';\n\nconst rawEntryPoint = process.env[ENTRY_POINT_VAR];\nif (!rawEntryPoint) {\n throw new Error(`Missing environment variable: ${log.bold(ENTRY_POINT_VAR)}`);\n}\n\nconst rawPort = process.env[PORT_VAR];\nif (!rawPort) {\n throw new Error(`Missing environment variable: ${log.bold(PORT_VAR)}`);\n}\n\nmain(rawEntryPoint, rawPort).catch(handleCliError);\n"],
5
- "mappings": ";AAYA,mBAA+B;AAC/B,qBAAoB;AAEpB,kBAAqB;AAErB,MAAM,kBAAkB;AACxB,MAAM,WAAW;AAEjB,MAAM,gBAAgB,QAAQ,IAAI,eAAe;AACjD,IAAI,CAAC,eAAe;AAClB,QAAM,IAAI,MAAM,iCAAiC,mBAAI,KAAK,eAAe,CAAC,EAAE;AAC9E;AAEA,MAAM,UAAU,QAAQ,IAAI,QAAQ;AACpC,IAAI,CAAC,SAAS;AACZ,QAAM,IAAI,MAAM,iCAAiC,mBAAI,KAAK,QAAQ,CAAC,EAAE;AACvE;AAAA,IAEA,kBAAK,eAAe,OAAO,EAAE,MAAM,2BAAc;",
5
+ "mappings": ";AAYA,SAAS,sBAAsB;AAC/B,SAAS,WAAW;AAEpB,SAAS,YAAY;AAErB,MAAM,kBAAkB;AACxB,MAAM,WAAW;AAEjB,MAAM,gBAAgB,QAAQ,IAAI,eAAe;AACjD,IAAI,CAAC,eAAe;AAClB,QAAM,IAAI,MAAM,iCAAiC,IAAI,KAAK,eAAe,CAAC,EAAE;AAC9E;AAEA,MAAM,UAAU,QAAQ,IAAI,QAAQ;AACpC,IAAI,CAAC,SAAS;AACZ,QAAM,IAAI,MAAM,iCAAiC,IAAI,KAAK,QAAQ,CAAC,EAAE;AACvE;AAEA,KAAK,eAAe,OAAO,EAAE,MAAM,cAAc;",
6
6
  "names": []
7
7
  }
@@ -1,47 +1,11 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var main_exports = {};
30
- __export(main_exports, {
31
- main: () => main
32
- });
33
- module.exports = __toCommonJS(main_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_functionHandler = require("./functionHandler.js");
36
- var import_requestListener = require("./requestListener.js");
37
- const main = async (rawEntryPoint, rawPort) => {
2
+ import path from "path";
3
+ import { runFunctionHandler } from "./functionHandler.js";
4
+ import { runRequestListener } from "./requestListener.js";
5
+ export const main = async (rawEntryPoint, rawPort) => {
38
6
  const availablePort = Number(rawPort) || void 0;
39
- const [modulePath, functionName] = import_path.default.join(process.cwd(), rawEntryPoint).split("#", 2);
40
- const entryPoint = require(modulePath);
41
- return functionName ? (0, import_functionHandler.runFunctionHandler)({ availablePort, entryPoint, functionName }) : (0, import_requestListener.runRequestListener)({ availablePort, entryPoint });
7
+ const [modulePath, functionName] = path.join(process.cwd(), rawEntryPoint).split("#", 2);
8
+ const entryPoint = await import(modulePath);
9
+ return functionName ? runFunctionHandler({ availablePort, entryPoint, functionName }) : runRequestListener({ availablePort, entryPoint });
42
10
  };
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- main
46
- });
47
11
  //# sourceMappingURL=main.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapper/main.ts"],
4
- "sourcesContent": ["import path from 'path';\n\nimport { runFunctionHandler } from './functionHandler.js';\nimport { runRequestListener } from './requestListener.js';\n\nexport const main = async (rawEntryPoint: string, rawPort: string) => {\n const availablePort = Number(rawPort) || undefined;\n\n // Support exported function targeting, e.g. `src/module.ts#callMeMaybe`\n const [modulePath, functionName] = path\n .join(process.cwd(), rawEntryPoint)\n .split('#', 2);\n\n // Load entry point as module\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const entryPoint = require(modulePath as string) as unknown;\n\n return functionName\n ? runFunctionHandler({ availablePort, entryPoint, functionName })\n : runRequestListener({ availablePort, entryPoint });\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,6BAAmC;AACnC,6BAAmC;AAE5B,MAAM,OAAO,OAAO,eAAuB,YAAoB;AACpE,QAAM,gBAAgB,OAAO,OAAO,KAAK;AAGzC,QAAM,CAAC,YAAY,YAAY,IAAI,YAAAA,QAChC,KAAK,QAAQ,IAAI,GAAG,aAAa,EACjC,MAAM,KAAK,CAAC;AAIf,QAAM,aAAa,QAAQ,UAAoB;AAE/C,SAAO,mBACH,2CAAmB,EAAE,eAAe,YAAY,aAAa,CAAC,QAC9D,2CAAmB,EAAE,eAAe,WAAW,CAAC;AACtD;",
6
- "names": ["path"]
4
+ "sourcesContent": ["import path from 'path';\n\nimport { runFunctionHandler } from './functionHandler.js';\nimport { runRequestListener } from './requestListener.js';\n\nexport const main = async (rawEntryPoint: string, rawPort: string) => {\n const availablePort = Number(rawPort) || undefined;\n\n // Support exported function targeting, e.g. `src/module.ts#callMeMaybe`\n const [modulePath, functionName] = path\n .join(process.cwd(), rawEntryPoint)\n .split('#', 2);\n\n // Load entry point as module\n\n const entryPoint = (await import(modulePath as string)) as unknown;\n\n return functionName\n ? runFunctionHandler({ availablePort, entryPoint, functionName })\n : runRequestListener({ availablePort, entryPoint });\n};\n"],
5
+ "mappings": ";AAAA,OAAO,UAAU;AAEjB,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAE5B,aAAM,OAAO,OAAO,eAAuB,YAAoB;AACpE,QAAM,gBAAgB,OAAO,OAAO,KAAK;AAGzC,QAAM,CAAC,YAAY,YAAY,IAAI,KAChC,KAAK,QAAQ,IAAI,GAAG,aAAa,EACjC,MAAM,KAAK,CAAC;AAIf,QAAM,aAAc,MAAM,OAAO;AAEjC,SAAO,eACH,mBAAmB,EAAE,eAAe,YAAY,aAAa,CAAC,IAC9D,mBAAmB,EAAE,eAAe,WAAW,CAAC;AACtD;",
6
+ "names": []
7
7
  }
@@ -1,41 +1,10 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var requestListener_exports = {};
30
- __export(requestListener_exports, {
31
- runRequestListener: () => runRequestListener
32
- });
33
- module.exports = __toCommonJS(requestListener_exports);
34
- var import_http = __toESM(require("http"));
35
- var import_validation = require("../utils/validation.js");
36
- var import_http2 = require("./http.js");
37
- const isConfig = (data) => (0, import_validation.isFunction)(data) || (0, import_validation.isObject)(data);
38
- const runRequestListener = async ({
2
+ import http from "http";
3
+ import { isFunction, isIpPort, isObject } from "../utils/validation.js";
4
+ import { serveRequestListener } from "./http.js";
5
+ import { startServer } from "./server.js";
6
+ const isConfig = (data) => isFunction(data) || isObject(data);
7
+ export const runRequestListener = async ({
39
8
  availablePort,
40
9
  entryPoint
41
10
  }) => {
@@ -49,21 +18,17 @@ const runRequestListener = async ({
49
18
  if (Object.keys(config).length === 0) {
50
19
  return;
51
20
  }
52
- const port = (0, import_validation.isIpPort)(config.port) ? config.port : availablePort;
53
- if (typeof config !== "function" && config instanceof import_http.default.Server) {
54
- return (0, import_http2.startServer)(config, port);
21
+ const port = isIpPort(config.port) ? config.port : availablePort;
22
+ if (typeof config !== "function" && config instanceof http.Server) {
23
+ return startServer(config, port);
55
24
  }
56
- if (typeof config !== "function" && config.server && config.server instanceof import_http.default.Server) {
57
- return (0, import_http2.startServer)(config.server, port);
25
+ if (typeof config !== "function" && config.server && config.server instanceof http.Server) {
26
+ return startServer(config.server, port);
58
27
  }
59
28
  const requestListener = typeof config === "function" ? config : config.requestListener ?? config.callback?.();
60
29
  if (typeof requestListener !== "function") {
61
30
  return;
62
31
  }
63
- return (0, import_http2.serveRequestListener)(requestListener, port);
32
+ return serveRequestListener(requestListener, port);
64
33
  };
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- runRequestListener
68
- });
69
34
  //# sourceMappingURL=requestListener.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/wrapper/requestListener.ts"],
4
- "sourcesContent": ["import http from 'http';\n\nimport { isFunction, isIpPort, isObject } from '../utils/validation.js';\n\nimport { serveRequestListener, startServer } from './http.js';\n\n// Express compatibility\ninterface FunctionConfig extends http.RequestListener {\n port?: number;\n}\n\ninterface ObjectConfig {\n // Koa compatibility\n callback?: () => http.RequestListener;\n\n requestListener?: http.RequestListener;\n\n // Fastify compatibility\n server?: http.Server;\n\n default?: Promise<unknown>;\n port?: unknown;\n}\n\nconst isConfig = (\n data: unknown,\n): data is Promise<FunctionConfig> | Promise<ObjectConfig> =>\n isFunction(data) || isObject(data);\n\ninterface Args {\n availablePort?: number;\n entryPoint: unknown;\n}\n\n/**\n * Create an HTTP server that calls into an exported `http.RequestListener`.\n *\n * This supports Express and Koa applications out of the box.\n */\nexport const runRequestListener = async ({\n availablePort,\n entryPoint,\n}: Args): Promise<void> => {\n if (!isConfig(entryPoint)) {\n // Assume an executable script with weird exports\n return;\n }\n\n let config: FunctionConfig | ObjectConfig = await entryPoint;\n\n if (typeof config === 'object' && isConfig(config.default)) {\n // Prefer `export default` over `export =`\n config = await config.default;\n }\n\n if (Object.keys(config).length === 0) {\n // Assume an executable script with no exports\n return;\n }\n\n const port = isIpPort(config.port) ? config.port : availablePort;\n\n // http.Server support\n if (typeof config !== 'function' && config instanceof http.Server) {\n return startServer(config, port);\n }\n\n // Fastify workaround\n if (\n typeof config !== 'function' &&\n config.server &&\n config.server instanceof http.Server\n ) {\n return startServer(config.server, port);\n }\n\n const requestListener =\n typeof config === 'function'\n ? config\n : (config.requestListener ?? config.callback?.());\n\n if (typeof requestListener !== 'function') {\n // Assume an executable script with non-request listener exports\n return;\n }\n\n return serveRequestListener(requestListener, port);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,wBAA+C;AAE/C,IAAAA,eAAkD;AAoBlD,MAAM,WAAW,CACf,aAEA,8BAAW,IAAI,SAAK,4BAAS,IAAI;AAY5B,MAAM,qBAAqB,OAAO;AAAA,EACvC;AAAA,EACA;AACF,MAA2B;AACzB,MAAI,CAAC,SAAS,UAAU,GAAG;AAEzB;AAAA,EACF;AAEA,MAAI,SAAwC,MAAM;AAElD,MAAI,OAAO,WAAW,YAAY,SAAS,OAAO,OAAO,GAAG;AAE1D,aAAS,MAAM,OAAO;AAAA,EACxB;AAEA,MAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAEpC;AAAA,EACF;AAEA,QAAM,WAAO,4BAAS,OAAO,IAAI,IAAI,OAAO,OAAO;AAGnD,MAAI,OAAO,WAAW,cAAc,kBAAkB,YAAAC,QAAK,QAAQ;AACjE,eAAO,0BAAY,QAAQ,IAAI;AAAA,EACjC;AAGA,MACE,OAAO,WAAW,cAClB,OAAO,UACP,OAAO,kBAAkB,YAAAA,QAAK,QAC9B;AACA,eAAO,0BAAY,OAAO,QAAQ,IAAI;AAAA,EACxC;AAEA,QAAM,kBACJ,OAAO,WAAW,aACd,SACC,OAAO,mBAAmB,OAAO,WAAW;AAEnD,MAAI,OAAO,oBAAoB,YAAY;AAEzC;AAAA,EACF;AAEA,aAAO,mCAAqB,iBAAiB,IAAI;AACnD;",
6
- "names": ["import_http", "http"]
4
+ "sourcesContent": ["import http from 'http';\n\nimport { isFunction, isIpPort, isObject } from '../utils/validation.js';\n\nimport { serveRequestListener } from './http.js';\nimport { startServer } from './server.js';\n\n// Express compatibility\ninterface FunctionConfig extends http.RequestListener {\n port?: number;\n}\n\ninterface ObjectConfig {\n // Koa compatibility\n callback?: () => http.RequestListener;\n\n requestListener?: http.RequestListener;\n\n // Fastify compatibility\n server?: http.Server;\n\n default?: Promise<unknown>;\n port?: unknown;\n}\n\nconst isConfig = (\n data: unknown,\n): data is Promise<FunctionConfig> | Promise<ObjectConfig> =>\n isFunction(data) || isObject(data);\n\ninterface Args {\n availablePort?: number;\n entryPoint: unknown;\n}\n\n/**\n * Create an HTTP server that calls into an exported `http.RequestListener`.\n *\n * This supports Express and Koa applications out of the box.\n */\nexport const runRequestListener = async ({\n availablePort,\n entryPoint,\n}: Args): Promise<void> => {\n if (!isConfig(entryPoint)) {\n // Assume an executable script with weird exports\n return;\n }\n\n let config: FunctionConfig | ObjectConfig = await entryPoint;\n\n if (typeof config === 'object' && isConfig(config.default)) {\n // Prefer `export default` over `export =`\n config = await config.default;\n }\n\n if (Object.keys(config).length === 0) {\n // Assume an executable script with no exports\n return;\n }\n\n const port = isIpPort(config.port) ? config.port : availablePort;\n\n // http.Server support\n if (typeof config !== 'function' && config instanceof http.Server) {\n return startServer(config, port);\n }\n\n // Fastify workaround\n if (\n typeof config !== 'function' &&\n config.server &&\n config.server instanceof http.Server\n ) {\n return startServer(config.server, port);\n }\n\n const requestListener =\n typeof config === 'function'\n ? config\n : (config.requestListener ?? config.callback?.());\n\n if (typeof requestListener !== 'function') {\n // Assume an executable script with non-request listener exports\n return;\n }\n\n return serveRequestListener(requestListener, port);\n};\n"],
5
+ "mappings": ";AAAA,OAAO,UAAU;AAEjB,SAAS,YAAY,UAAU,gBAAgB;AAE/C,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAoB5B,MAAM,WAAW,CACf,SAEA,WAAW,IAAI,KAAK,SAAS,IAAI;AAY5B,aAAM,qBAAqB,OAAO;AAAA,EACvC;AAAA,EACA;AACF,MAA2B;AACzB,MAAI,CAAC,SAAS,UAAU,GAAG;AAEzB;AAAA,EACF;AAEA,MAAI,SAAwC,MAAM;AAElD,MAAI,OAAO,WAAW,YAAY,SAAS,OAAO,OAAO,GAAG;AAE1D,aAAS,MAAM,OAAO;AAAA,EACxB;AAEA,MAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAEpC;AAAA,EACF;AAEA,QAAM,OAAO,SAAS,OAAO,IAAI,IAAI,OAAO,OAAO;AAGnD,MAAI,OAAO,WAAW,cAAc,kBAAkB,KAAK,QAAQ;AACjE,WAAO,YAAY,QAAQ,IAAI;AAAA,EACjC;AAGA,MACE,OAAO,WAAW,cAClB,OAAO,UACP,OAAO,kBAAkB,KAAK,QAC9B;AACA,WAAO,YAAY,OAAO,QAAQ,IAAI;AAAA,EACxC;AAEA,QAAM,kBACJ,OAAO,WAAW,aACd,SACC,OAAO,mBAAmB,OAAO,WAAW;AAEnD,MAAI,OAAO,oBAAoB,YAAY;AAEzC;AAAA,EACF;AAEA,SAAO,qBAAqB,iBAAiB,IAAI;AACnD;",
6
+ "names": []
7
7
  }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ import { log } from "../utils/logging.js";
3
+ export const startServer = (server, port) => new Promise(
4
+ (resolve, reject) => server.listen(port).on("close", resolve).on("error", reject).on("listening", () => {
5
+ const address = server.address();
6
+ log.ok("listening on port", log.bold(address.port));
7
+ })
8
+ );
9
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapper/server.ts"],
4
+ "sourcesContent": ["import type http from 'http';\nimport type { AddressInfo } from 'net';\n\nimport { log } from '../utils/logging.js';\n/**\n * Returns a HTTP server wrapped in a promise\n *\n * This function resolves when the server is closed.\n */\nexport const startServer = (server: http.Server, port?: number) =>\n new Promise<void>((resolve, reject) =>\n server\n .listen(port)\n .on('close', resolve)\n .on('error', reject)\n .on('listening', () => {\n const address = server.address() as AddressInfo;\n\n log.ok('listening on port', log.bold(address.port));\n }),\n );\n"],
5
+ "mappings": ";AAGA,SAAS,WAAW;AAMb,aAAM,cAAc,CAAC,QAAqB,SAC/C,IAAI;AAAA,EAAc,CAAC,SAAS,WAC1B,OACG,OAAO,IAAI,EACX,GAAG,SAAS,OAAO,EACnB,GAAG,SAAS,MAAM,EAClB,GAAG,aAAa,MAAM;AACrB,UAAM,UAAU,OAAO,QAAQ;AAE/B,QAAI,GAAG,qBAAqB,IAAI,KAAK,QAAQ,IAAI,CAAC;AAAA,EACpD,CAAC;AACL;",
6
+ "names": []
7
+ }