skuba 4.4.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (330) hide show
  1. package/config/tsconfig.json +1 -0
  2. package/jest/moduleNameMapper.js +50 -78
  3. package/jest/moduleNameMapper.test.ts +4 -14
  4. package/jest/transform.js +10 -1
  5. package/jest/tsConfig.js +26 -0
  6. package/lib/api/buildkite/annotate.js +46 -33
  7. package/lib/api/buildkite/annotate.js.map +7 -1
  8. package/lib/api/buildkite/index.js +31 -7
  9. package/lib/api/buildkite/index.js.map +7 -1
  10. package/lib/api/buildkite/md.js +31 -8
  11. package/lib/api/buildkite/md.js.map +7 -1
  12. package/lib/api/git/commit.js +45 -17
  13. package/lib/api/git/commit.js.map +7 -1
  14. package/lib/api/git/commitAllChanges.js +57 -27
  15. package/lib/api/git/commitAllChanges.js.map +7 -1
  16. package/lib/api/git/currentBranch.js +50 -28
  17. package/lib/api/git/currentBranch.js.map +7 -1
  18. package/lib/api/git/getChangedFiles.js +49 -27
  19. package/lib/api/git/getChangedFiles.js.map +7 -1
  20. package/lib/api/git/index.js +54 -22
  21. package/lib/api/git/index.js.map +7 -1
  22. package/lib/api/git/log.js +63 -42
  23. package/lib/api/git/log.js.map +7 -1
  24. package/lib/api/git/pull.js +62 -31
  25. package/lib/api/git/pull.js.map +7 -1
  26. package/lib/api/git/push.js +63 -31
  27. package/lib/api/git/push.js.map +7 -1
  28. package/lib/api/git/remote.js +59 -56
  29. package/lib/api/git/remote.js.map +7 -1
  30. package/lib/api/git/reset.js +55 -27
  31. package/lib/api/git/reset.js.map +7 -1
  32. package/lib/api/git/statusMatrix.js +46 -13
  33. package/lib/api/git/statusMatrix.js.map +7 -1
  34. package/lib/api/github/checkRun.js +70 -79
  35. package/lib/api/github/checkRun.js.map +7 -1
  36. package/lib/api/github/environment.js +40 -33
  37. package/lib/api/github/environment.js.map +7 -1
  38. package/lib/api/github/index.js +47 -17
  39. package/lib/api/github/index.js.map +7 -1
  40. package/lib/api/github/issueComment.js +73 -81
  41. package/lib/api/github/issueComment.js.map +7 -1
  42. package/lib/api/github/pullRequest.js +60 -61
  43. package/lib/api/github/pullRequest.js.map +7 -1
  44. package/lib/api/github/push.js +138 -133
  45. package/lib/api/github/push.js.map +7 -1
  46. package/lib/api/jest/index.d.ts +2 -1
  47. package/lib/api/jest/index.js +35 -14
  48. package/lib/api/jest/index.js.map +7 -1
  49. package/lib/api/net/compose.js +45 -17
  50. package/lib/api/net/compose.js.map +7 -1
  51. package/lib/api/net/index.js +28 -5
  52. package/lib/api/net/index.js.map +7 -1
  53. package/lib/api/net/socket.js +58 -36
  54. package/lib/api/net/socket.js.map +7 -1
  55. package/lib/api/net/waitFor.js +38 -18
  56. package/lib/api/net/waitFor.js.map +7 -1
  57. package/lib/cli/adapter/eslint.js +95 -72
  58. package/lib/cli/adapter/eslint.js.map +7 -1
  59. package/lib/cli/adapter/prettier.js +135 -123
  60. package/lib/cli/adapter/prettier.js.map +7 -1
  61. package/lib/cli/build/args.d.ts +7 -0
  62. package/lib/cli/build/args.js +69 -0
  63. package/lib/cli/build/args.js.map +7 -0
  64. package/lib/cli/build/esbuild.d.ts +5 -0
  65. package/lib/cli/build/esbuild.js +128 -0
  66. package/lib/cli/build/esbuild.js.map +7 -0
  67. package/lib/cli/build/index.d.ts +1 -1
  68. package/lib/cli/build/index.js +68 -5
  69. package/lib/cli/build/index.js.map +7 -1
  70. package/lib/cli/build/tsc.d.ts +1 -1
  71. package/lib/cli/build/tsc.js +34 -23
  72. package/lib/cli/build/tsc.js.map +7 -1
  73. package/lib/cli/buildPackage.js +53 -23
  74. package/lib/cli/buildPackage.js.map +7 -1
  75. package/lib/cli/configure/addEmptyExports.d.ts +5 -0
  76. package/lib/cli/configure/addEmptyExports.js +67 -0
  77. package/lib/cli/configure/addEmptyExports.js.map +7 -0
  78. package/lib/cli/configure/analyseConfiguration.js +61 -31
  79. package/lib/cli/configure/analyseConfiguration.js.map +7 -1
  80. package/lib/cli/configure/analyseDependencies.js +122 -113
  81. package/lib/cli/configure/analyseDependencies.js.map +7 -1
  82. package/lib/cli/configure/analysis/diff.js +37 -11
  83. package/lib/cli/configure/analysis/diff.js.map +7 -1
  84. package/lib/cli/configure/analysis/files.js +49 -22
  85. package/lib/cli/configure/analysis/files.js.map +7 -1
  86. package/lib/cli/configure/analysis/git.js +46 -16
  87. package/lib/cli/configure/analysis/git.js.map +7 -1
  88. package/lib/cli/configure/analysis/package.js +99 -52
  89. package/lib/cli/configure/analysis/package.js.map +7 -1
  90. package/lib/cli/configure/analysis/project.js +90 -54
  91. package/lib/cli/configure/analysis/project.js.map +7 -1
  92. package/lib/cli/configure/dependencies/index.js +40 -13
  93. package/lib/cli/configure/dependencies/index.js.map +7 -1
  94. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js +57 -32
  95. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js.map +7 -1
  96. package/lib/cli/configure/dependencies/seekKoala.js +53 -31
  97. package/lib/cli/configure/dependencies/seekKoala.js.map +7 -1
  98. package/lib/cli/configure/dependencies/skuba.js +49 -27
  99. package/lib/cli/configure/dependencies/skuba.js.map +7 -1
  100. package/lib/cli/configure/dependencies/skubaDeps.js +49 -28
  101. package/lib/cli/configure/dependencies/skubaDeps.js.map +7 -1
  102. package/lib/cli/configure/dependencies/skubaDive.js +65 -38
  103. package/lib/cli/configure/dependencies/skubaDive.js.map +7 -1
  104. package/lib/cli/configure/ensureTemplateCompletion.js +69 -41
  105. package/lib/cli/configure/ensureTemplateCompletion.js.map +7 -1
  106. package/lib/cli/configure/getEntryPoint.js +62 -32
  107. package/lib/cli/configure/getEntryPoint.js.map +7 -1
  108. package/lib/cli/configure/getProjectType.js +50 -28
  109. package/lib/cli/configure/getProjectType.js.map +7 -1
  110. package/lib/cli/configure/index.js +134 -109
  111. package/lib/cli/configure/index.js.map +7 -1
  112. package/lib/cli/configure/modules/eslint.js +57 -26
  113. package/lib/cli/configure/modules/eslint.js.map +7 -1
  114. package/lib/cli/configure/modules/ignore.js +37 -14
  115. package/lib/cli/configure/modules/ignore.js.map +7 -1
  116. package/lib/cli/configure/modules/index.js +53 -28
  117. package/lib/cli/configure/modules/index.js.map +7 -1
  118. package/lib/cli/configure/modules/jest.js +82 -47
  119. package/lib/cli/configure/modules/jest.js.map +7 -1
  120. package/lib/cli/configure/modules/nodemon.js +29 -6
  121. package/lib/cli/configure/modules/nodemon.js.map +7 -1
  122. package/lib/cli/configure/modules/package.js +113 -92
  123. package/lib/cli/configure/modules/package.js.map +7 -1
  124. package/lib/cli/configure/modules/prettier.js +48 -19
  125. package/lib/cli/configure/modules/prettier.js.map +7 -1
  126. package/lib/cli/configure/modules/renovate.js +52 -39
  127. package/lib/cli/configure/modules/renovate.js.map +7 -1
  128. package/lib/cli/configure/modules/serverless.js +33 -15
  129. package/lib/cli/configure/modules/serverless.js.map +7 -1
  130. package/lib/cli/configure/modules/skubaDive.js +63 -37
  131. package/lib/cli/configure/modules/skubaDive.js.map +7 -1
  132. package/lib/cli/configure/modules/tsconfig.js +84 -63
  133. package/lib/cli/configure/modules/tsconfig.js.map +7 -1
  134. package/lib/cli/configure/modules/tslint.js +29 -6
  135. package/lib/cli/configure/modules/tslint.js.map +7 -1
  136. package/lib/cli/configure/processing/deleteFiles.js +30 -8
  137. package/lib/cli/configure/processing/deleteFiles.js.map +7 -1
  138. package/lib/cli/configure/processing/ignoreFile.js +65 -59
  139. package/lib/cli/configure/processing/ignoreFile.js.map +7 -1
  140. package/lib/cli/configure/processing/javascript.js +35 -15
  141. package/lib/cli/configure/processing/javascript.js.map +7 -1
  142. package/lib/cli/configure/processing/json.js +51 -20
  143. package/lib/cli/configure/processing/json.js.map +7 -1
  144. package/lib/cli/configure/processing/loadFiles.js +30 -8
  145. package/lib/cli/configure/processing/loadFiles.js.map +7 -1
  146. package/lib/cli/configure/processing/module.js +37 -14
  147. package/lib/cli/configure/processing/module.js.map +7 -1
  148. package/lib/cli/configure/processing/package.js +73 -43
  149. package/lib/cli/configure/processing/package.js.map +7 -1
  150. package/lib/cli/configure/processing/prettier.js +37 -11
  151. package/lib/cli/configure/processing/prettier.js.map +7 -1
  152. package/lib/cli/configure/processing/record.js +54 -31
  153. package/lib/cli/configure/processing/record.js.map +7 -1
  154. package/lib/cli/configure/processing/typescript.js +176 -158
  155. package/lib/cli/configure/processing/typescript.js.map +7 -1
  156. package/lib/cli/configure/refreshIgnoreFiles.js +64 -40
  157. package/lib/cli/configure/refreshIgnoreFiles.js.map +7 -1
  158. package/lib/cli/configure/types.js +16 -2
  159. package/lib/cli/configure/types.js.map +7 -1
  160. package/lib/cli/format.js +58 -31
  161. package/lib/cli/format.js.map +7 -1
  162. package/lib/cli/help.js +31 -8
  163. package/lib/cli/help.js.map +7 -1
  164. package/lib/cli/init/getConfig.d.ts +1 -1
  165. package/lib/cli/init/getConfig.js +238 -207
  166. package/lib/cli/init/getConfig.js.map +7 -1
  167. package/lib/cli/init/git.js +70 -63
  168. package/lib/cli/init/git.js.map +7 -1
  169. package/lib/cli/init/index.js +133 -100
  170. package/lib/cli/init/index.js.map +7 -1
  171. package/lib/cli/init/prompts.js +84 -54
  172. package/lib/cli/init/prompts.js.map +7 -1
  173. package/lib/cli/init/types.js +52 -52
  174. package/lib/cli/init/types.js.map +7 -1
  175. package/lib/cli/init/validation.js +34 -12
  176. package/lib/cli/init/validation.js.map +7 -1
  177. package/lib/cli/init/writePackageJson.js +51 -22
  178. package/lib/cli/init/writePackageJson.js.map +7 -1
  179. package/lib/cli/lint/annotate/buildkite/eslint.js +34 -28
  180. package/lib/cli/lint/annotate/buildkite/eslint.js.map +7 -1
  181. package/lib/cli/lint/annotate/buildkite/index.js +50 -44
  182. package/lib/cli/lint/annotate/buildkite/index.js.map +7 -1
  183. package/lib/cli/lint/annotate/buildkite/prettier.js +41 -35
  184. package/lib/cli/lint/annotate/buildkite/prettier.js.map +7 -1
  185. package/lib/cli/lint/annotate/buildkite/tsc.js +39 -39
  186. package/lib/cli/lint/annotate/buildkite/tsc.js.map +7 -1
  187. package/lib/cli/lint/annotate/github/eslint.js +40 -16
  188. package/lib/cli/lint/annotate/github/eslint.js.map +7 -1
  189. package/lib/cli/lint/annotate/github/index.js +55 -51
  190. package/lib/cli/lint/annotate/github/index.js.map +7 -1
  191. package/lib/cli/lint/annotate/github/prettier.js +36 -13
  192. package/lib/cli/lint/annotate/github/prettier.js.map +7 -1
  193. package/lib/cli/lint/annotate/github/tsc.js +52 -52
  194. package/lib/cli/lint/annotate/github/tsc.js.map +7 -1
  195. package/lib/cli/lint/annotate/index.d.ts +1 -1
  196. package/lib/cli/lint/annotate/index.js +33 -10
  197. package/lib/cli/lint/annotate/index.js.map +7 -1
  198. package/lib/cli/lint/autofix.js +122 -117
  199. package/lib/cli/lint/autofix.js.map +7 -1
  200. package/lib/cli/lint/eslint.js +48 -18
  201. package/lib/cli/lint/eslint.js.map +7 -1
  202. package/lib/cli/lint/external.js +102 -81
  203. package/lib/cli/lint/external.js.map +7 -1
  204. package/lib/cli/lint/index.js +42 -18
  205. package/lib/cli/lint/index.js.map +7 -1
  206. package/lib/cli/lint/internal.js +54 -21
  207. package/lib/cli/lint/internal.js.map +7 -1
  208. package/lib/cli/lint/prettier.js +48 -18
  209. package/lib/cli/lint/prettier.js.map +7 -1
  210. package/lib/cli/lint/tsc.js +56 -32
  211. package/lib/cli/lint/tsc.js.map +7 -1
  212. package/lib/cli/lint/types.js +16 -2
  213. package/lib/cli/lint/types.js.map +7 -1
  214. package/lib/cli/node.js +65 -58
  215. package/lib/cli/node.js.map +7 -1
  216. package/lib/cli/release.js +29 -6
  217. package/lib/cli/release.js.map +7 -1
  218. package/lib/cli/start.js +61 -24
  219. package/lib/cli/start.js.map +7 -1
  220. package/lib/cli/test/index.js +35 -11
  221. package/lib/cli/test/index.js.map +7 -1
  222. package/lib/cli/test/reporters/github/annotations.js +89 -92
  223. package/lib/cli/test/reporters/github/annotations.js.map +7 -1
  224. package/lib/cli/test/reporters/github/index.js +68 -68
  225. package/lib/cli/test/reporters/github/index.js.map +7 -1
  226. package/lib/cli/version.js +31 -8
  227. package/lib/cli/version.js.map +7 -1
  228. package/lib/enquirer.d.js +2 -0
  229. package/lib/enquirer.d.js.map +7 -0
  230. package/lib/index.d.ts +6 -0
  231. package/lib/index.js +45 -41
  232. package/lib/index.js.map +7 -1
  233. package/lib/skuba.js +45 -38
  234. package/lib/skuba.js.map +7 -1
  235. package/lib/utils/args.js +97 -96
  236. package/lib/utils/args.js.map +7 -1
  237. package/lib/utils/command.js +64 -33
  238. package/lib/utils/command.js.map +7 -1
  239. package/lib/utils/copy.js +88 -51
  240. package/lib/utils/copy.js.map +7 -1
  241. package/lib/utils/dir.js +79 -67
  242. package/lib/utils/dir.js.map +7 -1
  243. package/lib/utils/env.js +27 -7
  244. package/lib/utils/env.js.map +7 -1
  245. package/lib/utils/error.js +58 -56
  246. package/lib/utils/error.js.map +7 -1
  247. package/lib/utils/exec.js +139 -110
  248. package/lib/utils/exec.js.map +7 -1
  249. package/lib/utils/help.js +31 -8
  250. package/lib/utils/help.js.map +7 -1
  251. package/lib/utils/logging.js +52 -24
  252. package/lib/utils/logging.js.map +7 -1
  253. package/lib/utils/logo.js +65 -27
  254. package/lib/utils/logo.js.map +7 -1
  255. package/lib/utils/manifest.d.ts +1 -0
  256. package/lib/utils/manifest.js +65 -51
  257. package/lib/utils/manifest.js.map +7 -1
  258. package/lib/utils/port.js +38 -17
  259. package/lib/utils/port.js.map +7 -1
  260. package/lib/utils/template.js +106 -87
  261. package/lib/utils/template.js.map +7 -1
  262. package/lib/utils/validation.js +43 -18
  263. package/lib/utils/validation.js.map +7 -1
  264. package/lib/utils/version.js +72 -82
  265. package/lib/utils/version.js.map +7 -1
  266. package/lib/utils/wait.js +52 -25
  267. package/lib/utils/wait.js.map +7 -1
  268. package/lib/utils/worker.js +59 -44
  269. package/lib/utils/worker.js.map +7 -1
  270. package/lib/wrapper/function-arguments.d.js +2 -0
  271. package/lib/wrapper/function-arguments.d.js.map +7 -0
  272. package/lib/wrapper/functionHandler.js +56 -29
  273. package/lib/wrapper/functionHandler.js.map +7 -1
  274. package/lib/wrapper/http.js +66 -56
  275. package/lib/wrapper/http.js.map +7 -1
  276. package/lib/wrapper/index.js +9 -21
  277. package/lib/wrapper/index.js.map +7 -1
  278. package/lib/wrapper/main.js +39 -20
  279. package/lib/wrapper/main.js.map +7 -1
  280. package/lib/wrapper/requestListener.js +50 -35
  281. package/lib/wrapper/requestListener.js.map +7 -1
  282. package/package.json +85 -79
  283. package/template/base/jest.config.ts +0 -6
  284. package/template/base/jest.setup.ts +2 -0
  285. package/template/base/tsconfig.json +2 -2
  286. package/template/express-rest-api/.buildkite/pipeline.yml +1 -1
  287. package/template/express-rest-api/.nvmrc +1 -1
  288. package/template/express-rest-api/Dockerfile +1 -1
  289. package/template/express-rest-api/Dockerfile.dev-deps +1 -1
  290. package/template/express-rest-api/package.json +14 -14
  291. package/template/greeter/.buildkite/pipeline.yml +1 -1
  292. package/template/greeter/.nvmrc +1 -1
  293. package/template/greeter/Dockerfile +1 -1
  294. package/template/greeter/package.json +11 -11
  295. package/template/greeter/src/app.test.ts +3 -1
  296. package/template/koa-rest-api/.buildkite/pipeline.yml +1 -1
  297. package/template/koa-rest-api/.nvmrc +1 -1
  298. package/template/koa-rest-api/Dockerfile +1 -1
  299. package/template/koa-rest-api/Dockerfile.dev-deps +1 -1
  300. package/template/koa-rest-api/package.json +20 -21
  301. package/template/koa-rest-api/src/api/jobs/postJob.test.ts +3 -7
  302. package/template/koa-rest-api/src/api/jobs/postJob.ts +2 -2
  303. package/template/koa-rest-api/src/framework/validation.test.ts +17 -15
  304. package/template/koa-rest-api/src/framework/validation.ts +66 -12
  305. package/template/koa-rest-api/src/testing/types.ts +5 -10
  306. package/template/koa-rest-api/src/types/jobs.ts +5 -10
  307. package/template/lambda-sqs-worker/.buildkite/pipeline.yml +4 -4
  308. package/template/lambda-sqs-worker/Dockerfile +1 -1
  309. package/template/lambda-sqs-worker/package.json +16 -20
  310. package/template/lambda-sqs-worker/src/app.ts +2 -2
  311. package/template/lambda-sqs-worker/src/framework/validation.test.ts +37 -17
  312. package/template/lambda-sqs-worker/src/framework/validation.ts +10 -2
  313. package/template/lambda-sqs-worker/src/services/jobScorer.ts +2 -2
  314. package/template/lambda-sqs-worker/src/testing/types.ts +5 -10
  315. package/template/lambda-sqs-worker/src/types/jobScorer.ts +9 -16
  316. package/template/lambda-sqs-worker/src/types/pipelineEvents.ts +13 -20
  317. package/template/lambda-sqs-worker/tsconfig.json +13 -0
  318. package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +4 -4
  319. package/template/lambda-sqs-worker-cdk/Dockerfile +1 -1
  320. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +6 -0
  321. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +3 -3
  322. package/template/lambda-sqs-worker-cdk/infra/index.ts +2 -2
  323. package/template/lambda-sqs-worker-cdk/package.json +14 -14
  324. package/template/lambda-sqs-worker-cdk/shared/context-types.ts +16 -25
  325. package/template/lambda-sqs-worker-cdk/tsconfig.json +13 -0
  326. package/template/oss-npm-package/.nvmrc +1 -1
  327. package/template/oss-npm-package/_package.json +1 -1
  328. package/template/private-npm-package/.nvmrc +1 -1
  329. package/template/private-npm-package/_package.json +1 -1
  330. package/jest/resolver.js +0 -24
@@ -1,62 +1,72 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.serveRequestListener = exports.createRequestListenerFromFunction = void 0;
7
- const http_1 = __importDefault(require("http"));
8
- const serialize_error_1 = require("serialize-error");
9
- const logging_1 = require("../utils/logging");
10
- /**
11
- * Create an HTTP request listener based on the supplied function.
12
- *
13
- * - The request body is JSON parsed and passed into the function as parameters.
14
- * - The function's return value is JSON stringified into the response body.
15
- */
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var http_exports = {};
26
+ __export(http_exports, {
27
+ createRequestListenerFromFunction: () => createRequestListenerFromFunction,
28
+ serveRequestListener: () => serveRequestListener
29
+ });
30
+ module.exports = __toCommonJS(http_exports);
31
+ var import_http = __toESM(require("http"));
32
+ var import_serialize_error = require("serialize-error");
33
+ var import_logging = require("../utils/logging");
16
34
  const createRequestListenerFromFunction = (fn) => async (req, res) => {
17
- const writeJsonResponse = (statusCode, jsonResponse) => {
18
- res.writeHead(statusCode, { 'Content-Type': 'application/json' });
19
- return new Promise((resolve, reject) => jsonResponse === undefined
20
- ? res.end(resolve)
21
- : res.write(JSON.stringify(jsonResponse, null, 2), 'utf8', (err) => err ? reject(err) : res.end(resolve)));
22
- };
23
- try {
24
- const requestBody = await new Promise((resolve, reject) => {
25
- const data = [];
26
- req
27
- .on('data', (chunk) => data.push(chunk))
28
- .on('end', () => resolve(Buffer.concat(data).toString()))
29
- .on('error', (err) => reject(err));
30
- });
31
- // Treat an empty body as no arguments
32
- const jsonRequest = requestBody ? JSON.parse(requestBody) : [];
33
- // Pass a non-array request body as the first parameter
34
- const args = Array.isArray(jsonRequest)
35
- ? jsonRequest
36
- : [jsonRequest];
37
- const response = await fn(...args);
38
- await writeJsonResponse(200, response);
39
- }
40
- catch (err) {
41
- await writeJsonResponse(500, (0, serialize_error_1.serializeError)(err));
42
- }
35
+ const writeJsonResponse = (statusCode, jsonResponse) => {
36
+ res.writeHead(statusCode, { "Content-Type": "application/json" });
37
+ return new Promise(
38
+ (resolve, reject) => jsonResponse === void 0 ? res.end(resolve) : res.write(
39
+ JSON.stringify(jsonResponse, null, 2),
40
+ "utf8",
41
+ (err) => err ? reject(err) : res.end(resolve)
42
+ )
43
+ );
44
+ };
45
+ try {
46
+ const requestBody = await new Promise((resolve, reject) => {
47
+ const data = [];
48
+ req.on("data", (chunk) => data.push(chunk)).on("end", () => resolve(Buffer.concat(data).toString())).on("error", (err) => reject(err));
49
+ });
50
+ const jsonRequest = requestBody ? JSON.parse(requestBody) : [];
51
+ const args = Array.isArray(jsonRequest) ? jsonRequest : [jsonRequest];
52
+ const response = await fn(...args);
53
+ await writeJsonResponse(200, response);
54
+ } catch (err) {
55
+ await writeJsonResponse(500, (0, import_serialize_error.serializeError)(err));
56
+ }
43
57
  };
44
- exports.createRequestListenerFromFunction = createRequestListenerFromFunction;
45
- /**
46
- * Create a HTTP server based on the supplied `http.RequestListener`.
47
- *
48
- * This function resolves when the server is closed.
49
- */
50
58
  const serveRequestListener = (requestListener, port) => {
51
- const server = http_1.default.createServer(requestListener);
52
- return new Promise((resolve, reject) => server
53
- .listen(port)
54
- .on('close', resolve)
55
- .on('error', reject)
56
- .on('listening', () => {
57
- const address = server.address();
58
- logging_1.log.ok('listening on port', logging_1.log.bold(address.port));
59
- }));
59
+ const server = import_http.default.createServer(requestListener);
60
+ return new Promise(
61
+ (resolve, reject) => server.listen(port).on("close", resolve).on("error", reject).on("listening", () => {
62
+ const address = server.address();
63
+ import_logging.log.ok("listening on port", import_logging.log.bold(address.port));
64
+ })
65
+ );
60
66
  };
61
- exports.serveRequestListener = serveRequestListener;
62
- //# sourceMappingURL=http.js.map
67
+ // Annotate the CommonJS export names for ESM import in node:
68
+ 0 && (module.exports = {
69
+ createRequestListenerFromFunction,
70
+ serveRequestListener
71
+ });
72
+ //# sourceMappingURL=http.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/wrapper/http.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAGxB,qDAAiD;AAEjD,8CAAuC;AAEvC;;;;;GAKG;AACI,MAAM,iCAAiC,GAC5C,CACE,EAAsD,EAChC,EAAE,CAC1B,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IACjB,MAAM,iBAAiB,GAAG,CAAC,UAAkB,EAAE,YAAqB,EAAE,EAAE;QACtE,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAElE,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAC3C,YAAY,KAAK,SAAS;YACxB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;YAClB,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAC/D,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CACrC,CACN,CAAC;IACJ,CAAC,CAAC;IAEF,IAAI;QACF,MAAM,WAAW,GAAG,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAChE,MAAM,IAAI,GAAa,EAAE,CAAC;YAE1B,GAAG;iBACA,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC/C,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;iBACxD,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;QAEH,sCAAsC;QACtC,MAAM,WAAW,GAAY,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAExE,uDAAuD;QACvD,MAAM,IAAI,GAAc,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;YAChD,CAAC,CAAC,WAAW;YACb,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QAElB,MAAM,QAAQ,GAAY,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAE5C,MAAM,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;KACxC;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,iBAAiB,CAAC,GAAG,EAAE,IAAA,gCAAc,EAAC,GAAG,CAAC,CAAC,CAAC;KACnD;AACH,CAAC,CAAC;AAzCS,QAAA,iCAAiC,qCAyC1C;AAEJ;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,CAClC,eAAqC,EACrC,IAAa,EACb,EAAE;IACF,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAElD,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAC3C,MAAM;SACH,MAAM,CAAC,IAAI,CAAC;SACZ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;SACpB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;SACnB,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;QACpB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAiB,CAAC;QAEhD,aAAG,CAAC,EAAE,CAAC,mBAAmB,EAAE,aAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,oBAAoB,wBAiB/B"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapper/http.ts"],
4
+ "sourcesContent": ["import http from 'http';\nimport type { AddressInfo } from 'net';\n\nimport { serializeError } from 'serialize-error';\n\nimport { log } from '../utils/logging';\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 (\n fn: (...args: unknown[]) => unknown | Promise<unknown>,\n ): http.RequestListener =>\n async (req, res) => {\n const writeJsonResponse = (statusCode: number, jsonResponse: unknown) => {\n res.writeHead(statusCode, { 'Content-Type': 'application/json' });\n\n return new Promise<void>((resolve, reject) =>\n jsonResponse === undefined\n ? res.end(resolve)\n : res.write(JSON.stringify(jsonResponse, null, 2), 'utf8', (err) =>\n err ? reject(err) : res.end(resolve),\n ),\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 await writeJsonResponse(200, response);\n } catch (err) {\n await writeJsonResponse(500, serializeError(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\n return 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};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAGjB,6BAA+B;AAE/B,qBAAoB;AAQb,MAAM,oCACX,CACE,OAEF,OAAO,KAAK,QAAQ;AAClB,QAAM,oBAAoB,CAAC,YAAoB,iBAA0B;AACvE,QAAI,UAAU,YAAY,EAAE,gBAAgB,mBAAmB,CAAC;AAEhE,WAAO,IAAI;AAAA,MAAc,CAAC,SAAS,WACjC,iBAAiB,SACb,IAAI,IAAI,OAAO,IACf,IAAI;AAAA,QAAM,KAAK,UAAU,cAAc,MAAM,CAAC;AAAA,QAAG;AAAA,QAAQ,CAAC,QACxD,MAAM,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO;AAAA,MACrC;AAAA,IACN;AAAA,EACF;AAEA,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,UAAM,kBAAkB,KAAK,QAAQ;AAAA,EACvC,SAAS,KAAP;AACA,UAAM,kBAAkB,SAAK,uCAAe,GAAG,CAAC;AAAA,EAClD;AACF;AAOK,MAAM,uBAAuB,CAClC,iBACA,SACG;AACH,QAAM,SAAS,YAAAA,QAAK,aAAa,eAAe;AAEhD,SAAO,IAAI;AAAA,IAAc,CAAC,SAAS,WACjC,OACG,OAAO,IAAI,EACX,GAAG,SAAS,OAAO,EACnB,GAAG,SAAS,MAAM,EAClB,GAAG,aAAa,MAAM;AACrB,YAAM,UAAU,OAAO,QAAQ;AAE/B,yBAAI,GAAG,qBAAqB,mBAAI,KAAK,QAAQ,IAAI,CAAC;AAAA,IACpD,CAAC;AAAA,EACL;AACF;",
6
+ "names": ["http"]
7
+ }
@@ -1,28 +1,16 @@
1
1
  "use strict";
2
- /**
3
- * Wrapper around an entry point provided to `skuba node` or `skuba start`.
4
- *
5
- * Beyond simply loading the entry point, it supports the following features:
6
- *
7
- * - If you set the entry point to an exported function like `src/app#handler`,
8
- * it will spin up a local HTTP server that calls into the function.
9
- *
10
- * - If you `export =` or `export default` an Express or Koa application,
11
- * it will spin up a local HTTP server based on the request listener.
12
- */
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const error_1 = require("../utils/error");
15
- const logging_1 = require("../utils/logging");
16
- const main_1 = require("./main");
17
- const ENTRY_POINT_VAR = '__SKUBA_ENTRY_POINT';
18
- const PORT_VAR = '__SKUBA_PORT';
2
+ var import_error = require("../utils/error");
3
+ var import_logging = require("../utils/logging");
4
+ var import_main = require("./main");
5
+ const ENTRY_POINT_VAR = "__SKUBA_ENTRY_POINT";
6
+ const PORT_VAR = "__SKUBA_PORT";
19
7
  const rawEntryPoint = process.env[ENTRY_POINT_VAR];
20
8
  if (!rawEntryPoint) {
21
- throw new Error(`Missing environment variable: ${logging_1.log.bold(ENTRY_POINT_VAR)}`);
9
+ throw new Error(`Missing environment variable: ${import_logging.log.bold(ENTRY_POINT_VAR)}`);
22
10
  }
23
11
  const rawPort = process.env[PORT_VAR];
24
12
  if (!rawPort) {
25
- throw new Error(`Missing environment variable: ${logging_1.log.bold(PORT_VAR)}`);
13
+ throw new Error(`Missing environment variable: ${import_logging.log.bold(PORT_VAR)}`);
26
14
  }
27
- (0, main_1.main)(rawEntryPoint, rawPort).catch(error_1.handleCliError);
28
- //# sourceMappingURL=index.js.map
15
+ (0, import_main.main)(rawEntryPoint, rawPort).catch(import_error.handleCliError);
16
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wrapper/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAEH,0CAAgD;AAChD,8CAAuC;AAEvC,iCAA8B;AAE9B,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC;AAEhC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACnD,IAAI,CAAC,aAAa,EAAE;IAClB,MAAM,IAAI,KAAK,CAAC,iCAAiC,aAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;CAC/E;AAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACtC,IAAI,CAAC,OAAO,EAAE;IACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,aAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;CACxE;AAED,IAAA,WAAI,EAAC,aAAa,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,sBAAc,CAAC,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapper/index.ts"],
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';\nimport { log } from '../utils/logging';\n\nimport { main } from './main';\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;AAClC,IAAI,CAAC,eAAe;AAClB,QAAM,IAAI,MAAM,iCAAiC,mBAAI,KAAK,eAAe,GAAG;AAC9E;AAEA,MAAM,UAAU,QAAQ,IAAI;AAC5B,IAAI,CAAC,SAAS;AACZ,QAAM,IAAI,MAAM,iCAAiC,mBAAI,KAAK,QAAQ,GAAG;AACvE;AAAA,IAEA,kBAAK,eAAe,OAAO,EAAE,MAAM,2BAAc;",
6
+ "names": []
7
+ }
@@ -1,24 +1,43 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.main = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const functionHandler_1 = require("./functionHandler");
9
- const requestListener_1 = require("./requestListener");
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
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var main_exports = {};
26
+ __export(main_exports, {
27
+ main: () => main
28
+ });
29
+ module.exports = __toCommonJS(main_exports);
30
+ var import_path = __toESM(require("path"));
31
+ var import_functionHandler = require("./functionHandler");
32
+ var import_requestListener = require("./requestListener");
10
33
  const main = async (rawEntryPoint, rawPort) => {
11
- const availablePort = Number(rawPort) || undefined;
12
- // Support exported function targeting, e.g. `src/module.ts#callMeMaybe`
13
- const [modulePath, functionName] = path_1.default
14
- .join(process.cwd(), rawEntryPoint)
15
- .split('#', 2);
16
- // Load entry point as module
17
- // eslint-disable-next-line @typescript-eslint/no-var-requires
18
- const entryPoint = require(modulePath);
19
- return functionName
20
- ? (0, functionHandler_1.runFunctionHandler)({ availablePort, entryPoint, functionName })
21
- : (0, requestListener_1.runRequestListener)({ availablePort, entryPoint });
34
+ const availablePort = Number(rawPort) || void 0;
35
+ const [modulePath, functionName] = import_path.default.join(process.cwd(), rawEntryPoint).split("#", 2);
36
+ const entryPoint = require(modulePath);
37
+ return functionName ? (0, import_functionHandler.runFunctionHandler)({ availablePort, entryPoint, functionName }) : (0, import_requestListener.runRequestListener)({ availablePort, entryPoint });
22
38
  };
23
- exports.main = main;
24
- //# sourceMappingURL=main.js.map
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ main
42
+ });
43
+ //# sourceMappingURL=main.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/wrapper/main.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,uDAAuD;AACvD,uDAAuD;AAEhD,MAAM,IAAI,GAAG,KAAK,EAAE,aAAqB,EAAE,OAAe,EAAE,EAAE;IACnE,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC;IAEnD,wEAAwE;IACxE,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,cAAI;SACpC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC;SAClC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAEjB,6BAA6B;IAC7B,8DAA8D;IAC9D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAY,CAAC;IAElD,OAAO,YAAY;QACjB,CAAC,CAAC,IAAA,oCAAkB,EAAC,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;QACjE,CAAC,CAAC,IAAA,oCAAkB,EAAC,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAC;AACxD,CAAC,CAAC;AAfW,QAAA,IAAI,QAef"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapper/main.ts"],
4
+ "sourcesContent": ["import path from 'path';\n\nimport { runFunctionHandler } from './functionHandler';\nimport { runRequestListener } from './requestListener';\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-var-requires\n const entryPoint = require(modulePath) 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,UAAU;AAErC,SAAO,mBACH,2CAAmB,EAAE,eAAe,YAAY,aAAa,CAAC,QAC9D,2CAAmB,EAAE,eAAe,WAAW,CAAC;AACtD;",
6
+ "names": ["path"]
7
+ }
@@ -1,37 +1,52 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runRequestListener = void 0;
4
- const validation_1 = require("../utils/validation");
5
- const http_1 = require("./http");
6
- const isConfig = (data) => (0, validation_1.isFunction)(data) || (0, validation_1.isObject)(data);
7
- /**
8
- * Create an HTTP server that calls into an exported `http.RequestListener`.
9
- *
10
- * This supports Express and Koa applications out of the box.
11
- */
12
- const runRequestListener = async ({ availablePort, entryPoint, }) => {
13
- if (!isConfig(entryPoint)) {
14
- // Assume an executable script with weird exports
15
- return;
16
- }
17
- let config = entryPoint;
18
- if (typeof config === 'object' && isConfig(config.default)) {
19
- // Prefer `export default` over `export =`
20
- config = config.default;
21
- }
22
- if (Object.keys(config).length === 0) {
23
- // Assume an executable script with no exports
24
- return;
25
- }
26
- const requestListener = typeof config === 'function'
27
- ? config
28
- : config.requestListener ?? config.callback?.();
29
- if (typeof requestListener !== 'function') {
30
- // Assume an executable script with non-request listener exports
31
- return;
32
- }
33
- const port = (0, validation_1.isIpPort)(config.port) ? config.port : availablePort;
34
- return (0, http_1.serveRequestListener)(requestListener, port);
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 });
35
9
  };
36
- exports.runRequestListener = runRequestListener;
37
- //# sourceMappingURL=requestListener.js.map
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 requestListener_exports = {};
20
+ __export(requestListener_exports, {
21
+ runRequestListener: () => runRequestListener
22
+ });
23
+ module.exports = __toCommonJS(requestListener_exports);
24
+ var import_validation = require("../utils/validation");
25
+ var import_http = require("./http");
26
+ const isConfig = (data) => (0, import_validation.isFunction)(data) || (0, import_validation.isObject)(data);
27
+ const runRequestListener = async ({
28
+ availablePort,
29
+ entryPoint
30
+ }) => {
31
+ if (!isConfig(entryPoint)) {
32
+ return;
33
+ }
34
+ let config = entryPoint;
35
+ if (typeof config === "object" && isConfig(config.default)) {
36
+ config = config.default;
37
+ }
38
+ if (Object.keys(config).length === 0) {
39
+ return;
40
+ }
41
+ const requestListener = typeof config === "function" ? config : config.requestListener ?? config.callback?.();
42
+ if (typeof requestListener !== "function") {
43
+ return;
44
+ }
45
+ const port = (0, import_validation.isIpPort)(config.port) ? config.port : availablePort;
46
+ return (0, import_http.serveRequestListener)(requestListener, port);
47
+ };
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ runRequestListener
51
+ });
52
+ //# sourceMappingURL=requestListener.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"requestListener.js","sourceRoot":"","sources":["../../src/wrapper/requestListener.ts"],"names":[],"mappings":";;;AAEA,oDAAqE;AAErE,iCAA8C;AAiB9C,MAAM,QAAQ,GAAG,CAAC,IAAa,EAAyC,EAAE,CACxE,IAAA,uBAAU,EAAC,IAAI,CAAC,IAAI,IAAA,qBAAQ,EAAC,IAAI,CAAC,CAAC;AAOrC;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,aAAa,EACb,UAAU,GACL,EAAiB,EAAE;IACxB,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACzB,iDAAiD;QACjD,OAAO;KACR;IAED,IAAI,MAAM,GAAG,UAAU,CAAC;IAExB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;QAC1D,0CAA0C;QAC1C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;KACzB;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACpC,8CAA8C;QAC9C,OAAO;KACR;IAED,MAAM,eAAe,GACnB,OAAO,MAAM,KAAK,UAAU;QAC1B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;IAEpD,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE;QACzC,gEAAgE;QAChE,OAAO;KACR;IAED,MAAM,IAAI,GAAG,IAAA,qBAAQ,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC;IAEjE,OAAO,IAAA,2BAAoB,EAAC,eAAe,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC,CAAC;AAlCW,QAAA,kBAAkB,sBAkC7B"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapper/requestListener.ts"],
4
+ "sourcesContent": ["import type http from 'http';\n\nimport { isFunction, isIpPort, isObject } from '../utils/validation';\n\nimport { serveRequestListener } from './http';\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 default?: unknown;\n port?: unknown;\n}\n\nconst isConfig = (data: unknown): data is FunctionConfig | 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 = entryPoint;\n\n if (typeof config === 'object' && isConfig(config.default)) {\n // Prefer `export default` over `export =`\n config = 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 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 const port = isIpPort(config.port) ? config.port : availablePort;\n\n return serveRequestListener(requestListener, port);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAA+C;AAE/C,kBAAqC;AAiBrC,MAAM,WAAW,CAAC,aAChB,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,SAAS;AAEb,MAAI,OAAO,WAAW,YAAY,SAAS,OAAO,OAAO,GAAG;AAE1D,aAAS,OAAO;AAAA,EAClB;AAEA,MAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAEpC;AAAA,EACF;AAEA,QAAM,kBACJ,OAAO,WAAW,aACd,SACA,OAAO,mBAAmB,OAAO,WAAW;AAElD,MAAI,OAAO,oBAAoB,YAAY;AAEzC;AAAA,EACF;AAEA,QAAM,WAAO,4BAAS,OAAO,IAAI,IAAI,OAAO,OAAO;AAEnD,aAAO,kCAAqB,iBAAiB,IAAI;AACnD;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,16 +1,79 @@
1
1
  {
2
+ "name": "skuba",
3
+ "version": "5.0.0",
4
+ "private": false,
5
+ "description": "SEEK development toolkit for backend applications and packages",
6
+ "homepage": "https://github.com/seek-oss/skuba#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/seek-oss/skuba/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+ssh://git@github.com/seek-oss/skuba.git"
13
+ },
14
+ "license": "MIT",
15
+ "sideEffects": false,
16
+ "main": "lib/index.js",
17
+ "types": "./lib/index.d.ts",
2
18
  "bin": {
3
19
  "skuba": "lib/skuba.js"
4
20
  },
5
- "bugs": {
6
- "url": "https://github.com/seek-oss/skuba/issues"
21
+ "files": [
22
+ "config/**/*",
23
+ "jest/**/*",
24
+ "lib*/**/*.d.ts",
25
+ "lib*/**/*.js",
26
+ "lib*/**/*.js.map",
27
+ "template/**/*",
28
+ "jest-preset.js"
29
+ ],
30
+ "scripts": {
31
+ "build": "scripts/build.sh",
32
+ "deploy": "scripts/deploy.sh",
33
+ "format": "yarn skuba format",
34
+ "lint": "yarn skuba lint && yarn lint:md",
35
+ "lint:md": "remark --frail --quiet .",
36
+ "release": "yarn build && changeset publish",
37
+ "skuba": "yarn build && node lib/skuba",
38
+ "stage": "changeset version && yarn format",
39
+ "test": "yarn skuba test",
40
+ "test:ci": "yarn skuba test --config jest.config.int.ts --runInBand",
41
+ "test:int": "yarn skuba test --config jest.config.int.ts --runInBand",
42
+ "test:template": "scripts/test-template.sh",
43
+ "test:watch": "yarn skuba test --config jest.config.int.ts --runInBand --watch"
44
+ },
45
+ "remarkConfig": {
46
+ "plugins": [
47
+ "remark-preset-lint-recommended",
48
+ [
49
+ "remark-lint-list-item-indent",
50
+ false
51
+ ],
52
+ [
53
+ "remark-lint-no-shortcut-reference-link",
54
+ false
55
+ ],
56
+ [
57
+ "remark-lint-no-undefined-references",
58
+ {
59
+ "allow": [
60
+ " ",
61
+ "x"
62
+ ]
63
+ }
64
+ ]
65
+ ]
66
+ },
67
+ "resolutions": {
68
+ "**/@types/node": ">=14.18"
7
69
  },
8
70
  "dependencies": {
71
+ "@esbuild-plugins/tsconfig-paths": "^0.0.4",
9
72
  "@jest/types": "^29.0.0",
10
73
  "@octokit/graphql": "^5.0.0",
11
74
  "@octokit/graphql-schema": "^12.0.0",
12
75
  "@octokit/rest": "^19.0.0",
13
- "@octokit/types": "^7.0.0",
76
+ "@octokit/types": "^8.0.0",
14
77
  "@types/jest": "^29.0.0",
15
78
  "@types/node": ">=14.18",
16
79
  "chalk": "^4.1.0",
@@ -18,6 +81,7 @@
18
81
  "dotenv": "^16.0.0",
19
82
  "ejs": "^3.1.6",
20
83
  "enquirer": "^2.3.6",
84
+ "esbuild": "~0.15.7",
21
85
  "eslint": "^8.11.0",
22
86
  "eslint-config-skuba": "1.1.4",
23
87
  "execa": "^5.0.0",
@@ -30,8 +94,10 @@
30
94
  "isomorphic-git": "^1.11.1",
31
95
  "jest": "^29.0.1",
32
96
  "jest-watch-typeahead": "^2.1.1",
97
+ "libnpmsearch": "^6.0.0",
33
98
  "lodash.mergewith": "^4.6.2",
34
- "normalize-package-data": "^4.0.0",
99
+ "minimist": "^1.2.6",
100
+ "normalize-package-data": "^5.0.0",
35
101
  "npm-run-path": "^4.0.1",
36
102
  "npm-which": "^3.0.1",
37
103
  "picomatch": "^2.2.2",
@@ -44,23 +110,23 @@
44
110
  "sort-package-json": "^1.57.0",
45
111
  "strip-ansi": "^6.0.1",
46
112
  "ts-dedent": "^2.2.0",
47
- "ts-jest": "^29.0.0-next.0",
113
+ "ts-jest": "^29.0.3",
48
114
  "ts-node": "^10.7.0",
49
115
  "ts-node-dev": "^2.0.0",
50
116
  "tsconfig-paths": "^4.0.0",
51
117
  "tsconfig-seek": "1.0.2",
52
118
  "typescript": "~4.8.2",
53
- "validate-npm-package-name": "^4.0.0"
119
+ "validate-npm-package-name": "^5.0.0"
54
120
  },
55
- "description": "SEEK development toolkit for backend applications and packages",
56
121
  "devDependencies": {
57
- "@changesets/cli": "2.24.3",
122
+ "@changesets/cli": "2.25.2",
58
123
  "@changesets/get-github-info": "0.5.1",
59
- "@jest/reporters": "29.0.1",
124
+ "@jest/reporters": "29.3.0",
60
125
  "@types/ejs": "3.1.1",
61
- "@types/express": "4.17.13",
126
+ "@types/express": "4.17.14",
62
127
  "@types/fs-extra": "9.0.13",
63
128
  "@types/koa": "2.13.5",
129
+ "@types/libnpmsearch": "2.0.3",
64
130
  "@types/lodash.mergewith": "4.6.7",
65
131
  "@types/module-alias": "2.0.1",
66
132
  "@types/npm-which": "3.0.1",
@@ -68,32 +134,16 @@
68
134
  "@types/supertest": "2.0.12",
69
135
  "@types/validate-npm-package-name": "4.0.0",
70
136
  "enhanced-resolve": "5.10.0",
71
- "express": "4.18.1",
137
+ "express": "4.18.2",
72
138
  "jsonfile": "6.1.0",
73
139
  "koa": "2.13.4",
74
- "memfs": "3.4.7",
140
+ "memfs": "3.4.10",
75
141
  "remark-cli": "11.0.0",
76
142
  "remark-preset-lint-recommended": "6.1.2",
77
- "semver": "7.3.7",
78
- "supertest": "6.2.4",
79
- "type-fest": "2.18.0"
143
+ "semver": "7.3.8",
144
+ "supertest": "6.3.1",
145
+ "type-fest": "2.19.0"
80
146
  },
81
- "engines": {
82
- "node": ">=14.18"
83
- },
84
- "files": [
85
- "config/**/*",
86
- "jest/**/*",
87
- "lib*/**/*.d.ts",
88
- "lib*/**/*.js",
89
- "lib*/**/*.js.map",
90
- "template/**/*",
91
- "jest-preset.js"
92
- ],
93
- "homepage": "https://github.com/seek-oss/skuba#readme",
94
- "license": "MIT",
95
- "main": "lib/index.js",
96
- "name": "skuba",
97
147
  "peerDependencies": {
98
148
  "skuba-dive": "1 || 2"
99
149
  },
@@ -102,58 +152,14 @@
102
152
  "optional": true
103
153
  }
104
154
  },
105
- "private": false,
106
- "remarkConfig": {
107
- "plugins": [
108
- "remark-preset-lint-recommended",
109
- [
110
- "remark-lint-list-item-indent",
111
- false
112
- ],
113
- [
114
- "remark-lint-no-shortcut-reference-link",
115
- false
116
- ],
117
- [
118
- "remark-lint-no-undefined-references",
119
- {
120
- "allow": [
121
- " ",
122
- "x"
123
- ]
124
- }
125
- ]
126
- ]
127
- },
128
- "repository": {
129
- "type": "git",
130
- "url": "git+ssh://git@github.com/seek-oss/skuba.git"
131
- },
132
- "resolutions": {
133
- "**/@types/node": ">=14.18"
134
- },
135
- "scripts": {
136
- "build": "ts-node --transpile-only src/skuba build && scripts/postbuild.sh",
137
- "deploy": "scripts/deploy.sh",
138
- "format": "yarn skuba format",
139
- "lint": "yarn skuba lint && yarn lint:md",
140
- "lint:md": "remark --frail --quiet .",
141
- "release": "yarn build && changeset publish",
142
- "stage": "changeset version && yarn format",
143
- "skuba": "yarn build && node lib/skuba",
144
- "test": "yarn skuba test",
145
- "test:ci": "yarn skuba test --config jest.config.int.ts --runInBand",
146
- "test:int": "yarn skuba test --config jest.config.int.ts --runInBand",
147
- "test:template": "scripts/test-template.sh",
148
- "test:watch": "yarn skuba test --config jest.config.int.ts --runInBand --watch"
155
+ "engines": {
156
+ "node": ">=14.18"
149
157
  },
150
- "sideEffects": false,
151
158
  "skuba": {
159
+ "build": "esbuild",
152
160
  "entryPoint": "src/index.ts",
153
161
  "template": null,
154
162
  "type": "package",
155
163
  "version": "4.0.0"
156
- },
157
- "types": "./lib/index.d.ts",
158
- "version": "4.4.1"
164
+ }
159
165
  }
@@ -10,12 +10,6 @@ export default Jest.mergePreset({
10
10
  statements: 0,
11
11
  },
12
12
  },
13
- globals: {
14
- 'ts-jest': {
15
- // seek-oss/skuba#626
16
- isolatedModules: true,
17
- },
18
- },
19
13
  setupFiles: ['<rootDir>/jest.setup.ts'],
20
14
  testPathIgnorePatterns: ['/test\\.ts'],
21
15
  });
@@ -1 +1,3 @@
1
1
  process.env.ENVIRONMENT = 'test';
2
+
3
+ export {};