skuba 4.4.0 → 5.0.0-beta.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 (321) 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 +126 -124
  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 +84 -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 +79 -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.js +238 -207
  165. package/lib/cli/init/getConfig.js.map +7 -1
  166. package/lib/cli/init/git.js +70 -63
  167. package/lib/cli/init/git.js.map +7 -1
  168. package/lib/cli/init/index.js +133 -100
  169. package/lib/cli/init/index.js.map +7 -1
  170. package/lib/cli/init/prompts.js +84 -54
  171. package/lib/cli/init/prompts.js.map +7 -1
  172. package/lib/cli/init/types.js +52 -52
  173. package/lib/cli/init/types.js.map +7 -1
  174. package/lib/cli/init/validation.js +34 -12
  175. package/lib/cli/init/validation.js.map +7 -1
  176. package/lib/cli/init/writePackageJson.js +51 -22
  177. package/lib/cli/init/writePackageJson.js.map +7 -1
  178. package/lib/cli/lint/annotate/buildkite/eslint.js +34 -28
  179. package/lib/cli/lint/annotate/buildkite/eslint.js.map +7 -1
  180. package/lib/cli/lint/annotate/buildkite/index.js +50 -44
  181. package/lib/cli/lint/annotate/buildkite/index.js.map +7 -1
  182. package/lib/cli/lint/annotate/buildkite/prettier.js +41 -35
  183. package/lib/cli/lint/annotate/buildkite/prettier.js.map +7 -1
  184. package/lib/cli/lint/annotate/buildkite/tsc.js +39 -39
  185. package/lib/cli/lint/annotate/buildkite/tsc.js.map +7 -1
  186. package/lib/cli/lint/annotate/github/eslint.js +40 -16
  187. package/lib/cli/lint/annotate/github/eslint.js.map +7 -1
  188. package/lib/cli/lint/annotate/github/index.js +55 -51
  189. package/lib/cli/lint/annotate/github/index.js.map +7 -1
  190. package/lib/cli/lint/annotate/github/prettier.js +36 -13
  191. package/lib/cli/lint/annotate/github/prettier.js.map +7 -1
  192. package/lib/cli/lint/annotate/github/tsc.js +52 -52
  193. package/lib/cli/lint/annotate/github/tsc.js.map +7 -1
  194. package/lib/cli/lint/annotate/index.js +33 -10
  195. package/lib/cli/lint/annotate/index.js.map +7 -1
  196. package/lib/cli/lint/autofix.js +122 -117
  197. package/lib/cli/lint/autofix.js.map +7 -1
  198. package/lib/cli/lint/eslint.js +48 -18
  199. package/lib/cli/lint/eslint.js.map +7 -1
  200. package/lib/cli/lint/external.js +102 -81
  201. package/lib/cli/lint/external.js.map +7 -1
  202. package/lib/cli/lint/index.js +42 -18
  203. package/lib/cli/lint/index.js.map +7 -1
  204. package/lib/cli/lint/internal.js +54 -21
  205. package/lib/cli/lint/internal.js.map +7 -1
  206. package/lib/cli/lint/prettier.js +48 -18
  207. package/lib/cli/lint/prettier.js.map +7 -1
  208. package/lib/cli/lint/tsc.js +56 -32
  209. package/lib/cli/lint/tsc.js.map +7 -1
  210. package/lib/cli/lint/types.js +16 -2
  211. package/lib/cli/lint/types.js.map +7 -1
  212. package/lib/cli/node.js +65 -58
  213. package/lib/cli/node.js.map +7 -1
  214. package/lib/cli/release.js +29 -6
  215. package/lib/cli/release.js.map +7 -1
  216. package/lib/cli/start.js +61 -24
  217. package/lib/cli/start.js.map +7 -1
  218. package/lib/cli/test/index.js +35 -11
  219. package/lib/cli/test/index.js.map +7 -1
  220. package/lib/cli/test/reporters/github/annotations.js +89 -92
  221. package/lib/cli/test/reporters/github/annotations.js.map +7 -1
  222. package/lib/cli/test/reporters/github/index.js +68 -68
  223. package/lib/cli/test/reporters/github/index.js.map +7 -1
  224. package/lib/cli/version.js +31 -8
  225. package/lib/cli/version.js.map +7 -1
  226. package/lib/enquirer.d.js +2 -0
  227. package/lib/enquirer.d.js.map +7 -0
  228. package/lib/index.d.ts +6 -0
  229. package/lib/index.js +45 -41
  230. package/lib/index.js.map +7 -1
  231. package/lib/skuba.js +45 -38
  232. package/lib/skuba.js.map +7 -1
  233. package/lib/utils/args.js +97 -96
  234. package/lib/utils/args.js.map +7 -1
  235. package/lib/utils/command.js +64 -33
  236. package/lib/utils/command.js.map +7 -1
  237. package/lib/utils/copy.js +88 -51
  238. package/lib/utils/copy.js.map +7 -1
  239. package/lib/utils/dir.js +79 -67
  240. package/lib/utils/dir.js.map +7 -1
  241. package/lib/utils/env.js +27 -7
  242. package/lib/utils/env.js.map +7 -1
  243. package/lib/utils/error.js +58 -56
  244. package/lib/utils/error.js.map +7 -1
  245. package/lib/utils/exec.js +139 -110
  246. package/lib/utils/exec.js.map +7 -1
  247. package/lib/utils/help.js +31 -8
  248. package/lib/utils/help.js.map +7 -1
  249. package/lib/utils/logging.js +52 -24
  250. package/lib/utils/logging.js.map +7 -1
  251. package/lib/utils/logo.js +65 -27
  252. package/lib/utils/logo.js.map +7 -1
  253. package/lib/utils/manifest.d.ts +1 -0
  254. package/lib/utils/manifest.js +65 -51
  255. package/lib/utils/manifest.js.map +7 -1
  256. package/lib/utils/port.js +38 -17
  257. package/lib/utils/port.js.map +7 -1
  258. package/lib/utils/template.js +106 -87
  259. package/lib/utils/template.js.map +7 -1
  260. package/lib/utils/validation.js +43 -18
  261. package/lib/utils/validation.js.map +7 -1
  262. package/lib/utils/version.js +73 -40
  263. package/lib/utils/version.js.map +7 -1
  264. package/lib/utils/wait.js +52 -25
  265. package/lib/utils/wait.js.map +7 -1
  266. package/lib/utils/worker.js +59 -44
  267. package/lib/utils/worker.js.map +7 -1
  268. package/lib/wrapper/function-arguments.d.js +2 -0
  269. package/lib/wrapper/function-arguments.d.js.map +7 -0
  270. package/lib/wrapper/functionHandler.js +56 -29
  271. package/lib/wrapper/functionHandler.js.map +7 -1
  272. package/lib/wrapper/http.js +66 -56
  273. package/lib/wrapper/http.js.map +7 -1
  274. package/lib/wrapper/index.js +9 -21
  275. package/lib/wrapper/index.js.map +7 -1
  276. package/lib/wrapper/main.js +39 -20
  277. package/lib/wrapper/main.js.map +7 -1
  278. package/lib/wrapper/requestListener.js +50 -35
  279. package/lib/wrapper/requestListener.js.map +7 -1
  280. package/package.json +21 -14
  281. package/template/base/jest.config.ts +0 -6
  282. package/template/base/jest.setup.ts +2 -0
  283. package/template/express-rest-api/.buildkite/pipeline.yml +1 -1
  284. package/template/express-rest-api/package.json +1 -1
  285. package/template/greeter/.buildkite/pipeline.yml +1 -1
  286. package/template/greeter/package.json +1 -1
  287. package/template/greeter/src/app.test.ts +3 -1
  288. package/template/koa-rest-api/.buildkite/pipeline.yml +1 -1
  289. package/template/koa-rest-api/package.json +6 -9
  290. package/template/koa-rest-api/src/api/jobs/postJob.test.ts +3 -7
  291. package/template/koa-rest-api/src/api/jobs/postJob.ts +2 -2
  292. package/template/koa-rest-api/src/framework/validation.test.ts +17 -15
  293. package/template/koa-rest-api/src/framework/validation.ts +50 -9
  294. package/template/koa-rest-api/src/storage/jobs.ts +2 -2
  295. package/template/koa-rest-api/src/testing/types.ts +5 -10
  296. package/template/koa-rest-api/src/types/jobs.ts +5 -10
  297. package/template/lambda-sqs-worker/.buildkite/pipeline.yml +3 -3
  298. package/template/lambda-sqs-worker/README.md +1 -1
  299. package/template/lambda-sqs-worker/package.json +4 -4
  300. package/template/lambda-sqs-worker/serverless.yml +17 -2
  301. package/template/lambda-sqs-worker/src/app.test.ts +19 -17
  302. package/template/lambda-sqs-worker/src/app.ts +8 -8
  303. package/template/lambda-sqs-worker/src/config.ts +3 -0
  304. package/template/lambda-sqs-worker/src/framework/handler.test.ts +7 -7
  305. package/template/lambda-sqs-worker/src/framework/handler.ts +31 -8
  306. package/template/lambda-sqs-worker/src/framework/metrics.ts +10 -6
  307. package/template/lambda-sqs-worker/src/framework/validation.test.ts +37 -17
  308. package/template/lambda-sqs-worker/src/framework/validation.ts +4 -2
  309. package/template/lambda-sqs-worker/src/services/jobScorer.ts +2 -2
  310. package/template/lambda-sqs-worker/src/testing/types.ts +5 -10
  311. package/template/lambda-sqs-worker/src/types/jobScorer.ts +9 -16
  312. package/template/lambda-sqs-worker/src/types/pipelineEvents.ts +13 -20
  313. package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +3 -3
  314. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +6 -0
  315. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +3 -3
  316. package/template/lambda-sqs-worker-cdk/infra/index.ts +2 -2
  317. package/template/lambda-sqs-worker-cdk/package.json +2 -2
  318. package/template/lambda-sqs-worker-cdk/shared/context-types.ts +16 -25
  319. package/template/oss-npm-package/_package.json +1 -1
  320. package/template/private-npm-package/_package.json +1 -1
  321. package/jest/resolver.js +0 -24
@@ -1,52 +1,85 @@
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.getSkubaVersionInfo = exports.getSkubaVersion = exports.latestNpmVersion = void 0;
7
- const package_json_1 = __importDefault(require("package-json"));
8
- const manifest_1 = require("./manifest");
9
- const wait_1 = require("./wait");
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 version_exports = {};
26
+ __export(version_exports, {
27
+ getSkubaVersion: () => getSkubaVersion,
28
+ getSkubaVersionInfo: () => getSkubaVersionInfo,
29
+ latestNpmVersion: () => latestNpmVersion
30
+ });
31
+ module.exports = __toCommonJS(version_exports);
32
+ var import_libnpmsearch = __toESM(require("libnpmsearch"));
33
+ var import_validate_npm_package_name = __toESM(require("validate-npm-package-name"));
34
+ var import_manifest = require("./manifest");
35
+ var import_wait = require("./wait");
10
36
  const latestNpmVersion = async (packageName) => {
11
- const { version } = await (0, package_json_1.default)(packageName);
12
- if (typeof version !== 'string') {
13
- throw new Error(`No version found for package "${packageName}"`);
14
- }
15
- return version;
37
+ const { validForNewPackages } = (0, import_validate_npm_package_name.default)(packageName);
38
+ if (!validForNewPackages) {
39
+ throw new Error(`Package "${packageName}" does not have a valid name`);
40
+ }
41
+ const [result] = await (0, import_libnpmsearch.default)(packageName, { limit: 1, timeout: 5e3 });
42
+ if (result?.name !== packageName) {
43
+ throw new Error(
44
+ `Package "${packageName}" does not exist on the npm registry`
45
+ );
46
+ }
47
+ return result.version;
16
48
  };
17
- exports.latestNpmVersion = latestNpmVersion;
18
49
  const latestSkubaVersion = async () => {
19
- try {
20
- const result = await (0, wait_1.withTimeout)((0, exports.latestNpmVersion)('skuba'), { s: 2 });
21
- return result.ok ? result.value : null;
22
- }
23
- catch {
24
- return null;
25
- }
50
+ try {
51
+ const result = await (0, import_wait.withTimeout)(latestNpmVersion("skuba"), { s: 2 });
52
+ return result.ok ? result.value : null;
53
+ } catch {
54
+ return null;
55
+ }
26
56
  };
27
57
  const getSkubaVersion = async () => {
28
- const { version } = await (0, manifest_1.getSkubaManifest)();
29
- return version;
58
+ const { version } = await (0, import_manifest.getSkubaManifest)();
59
+ return version;
30
60
  };
31
- exports.getSkubaVersion = getSkubaVersion;
32
61
  const getSkubaVersionInfo = async () => {
33
- const [local, latest] = await Promise.all([
34
- (0, exports.getSkubaVersion)(),
35
- latestSkubaVersion(),
36
- ]);
37
- if (latest === null) {
38
- // Assume we're up to date if we can't reach the npm registry
39
- return {
40
- isStale: false,
41
- local,
42
- latest,
43
- };
44
- }
62
+ const [local, latest] = await Promise.all([
63
+ getSkubaVersion(),
64
+ latestSkubaVersion()
65
+ ]);
66
+ if (latest === null) {
45
67
  return {
46
- isStale: latest !== local,
47
- local,
48
- latest,
68
+ isStale: false,
69
+ local,
70
+ latest
49
71
  };
72
+ }
73
+ return {
74
+ isStale: latest !== local,
75
+ local,
76
+ latest
77
+ };
50
78
  };
51
- exports.getSkubaVersionInfo = getSkubaVersionInfo;
52
- //# sourceMappingURL=version.js.map
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ getSkubaVersion,
82
+ getSkubaVersionInfo,
83
+ latestNpmVersion
84
+ });
85
+ //# sourceMappingURL=version.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAuC;AAEvC,yCAA8C;AAC9C,iCAAqC;AAE9B,MAAM,gBAAgB,GAAG,KAAK,EACnC,WAAmB,EACF,EAAE;IACnB,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAA,sBAAW,EAAC,WAAW,CAAC,CAAC;IAEnD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,iCAAiC,WAAW,GAAG,CAAC,CAAC;KAClE;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,gBAAgB,oBAU3B;AAEF,MAAM,kBAAkB,GAAG,KAAK,IAA4B,EAAE;IAC5D,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,IAAA,kBAAW,EAAC,IAAA,wBAAgB,EAAC,OAAO,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAEtE,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;KACxC;IAAC,MAAM;QACN,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC;AAEK,MAAM,eAAe,GAAG,KAAK,IAAqB,EAAE;IACzD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAA,2BAAgB,GAAE,CAAC;IAE7C,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B;AAgBK,MAAM,mBAAmB,GAAG,KAAK,IAA+B,EAAE;IACvE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACxC,IAAA,uBAAe,GAAE;QACjB,kBAAkB,EAAE;KACrB,CAAC,CAAC;IAEH,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,6DAA6D;QAC7D,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK;YACL,MAAM;SACP,CAAC;KACH;IAED,OAAO;QACL,OAAO,EAAE,MAAM,KAAK,KAAK;QACzB,KAAK;QACL,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,mBAAmB,uBAoB9B"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/version.ts"],
4
+ "sourcesContent": ["import searchNpm from 'libnpmsearch';\nimport validatePackageName from 'validate-npm-package-name';\n\nimport { getSkubaManifest } from './manifest';\nimport { withTimeout } from './wait';\n\nexport const latestNpmVersion = async (\n packageName: string,\n): Promise<string> => {\n const { validForNewPackages } = validatePackageName(packageName);\n\n if (!validForNewPackages) {\n throw new Error(`Package \"${packageName}\" does not have a valid name`);\n }\n\n const [result] = await searchNpm(packageName, { limit: 1, timeout: 5_000 });\n\n if (result?.name !== packageName) {\n throw new Error(\n `Package \"${packageName}\" does not exist on the npm registry`,\n );\n }\n\n return result.version;\n};\n\nconst latestSkubaVersion = async (): Promise<string | null> => {\n try {\n const result = await withTimeout(latestNpmVersion('skuba'), { s: 2 });\n\n return result.ok ? result.value : null;\n } catch {\n return null;\n }\n};\n\nexport const getSkubaVersion = async (): Promise<string> => {\n const { version } = await getSkubaManifest();\n\n return version;\n};\n\ntype SkubaVersionInfo =\n | {\n isStale: true;\n\n local: string;\n latest: string;\n }\n | {\n isStale: false;\n\n local: string;\n latest: string | null;\n };\n\nexport const getSkubaVersionInfo = async (): Promise<SkubaVersionInfo> => {\n const [local, latest] = await Promise.all([\n getSkubaVersion(),\n latestSkubaVersion(),\n ]);\n\n if (latest === null) {\n // Assume we're up to date if we can't reach the npm registry\n return {\n isStale: false,\n local,\n latest,\n };\n }\n\n return {\n isStale: latest !== local,\n local,\n latest,\n };\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAsB;AACtB,uCAAgC;AAEhC,sBAAiC;AACjC,kBAA4B;AAErB,MAAM,mBAAmB,OAC9B,gBACoB;AACpB,QAAM,EAAE,oBAAoB,QAAI,iCAAAA,SAAoB,WAAW;AAE/D,MAAI,CAAC,qBAAqB;AACxB,UAAM,IAAI,MAAM,YAAY,yCAAyC;AAAA,EACvE;AAEA,QAAM,CAAC,MAAM,IAAI,UAAM,oBAAAC,SAAU,aAAa,EAAE,OAAO,GAAG,SAAS,IAAM,CAAC;AAE1E,MAAI,QAAQ,SAAS,aAAa;AAChC,UAAM,IAAI;AAAA,MACR,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO,OAAO;AAChB;AAEA,MAAM,qBAAqB,YAAoC;AAC7D,MAAI;AACF,UAAM,SAAS,UAAM,yBAAY,iBAAiB,OAAO,GAAG,EAAE,GAAG,EAAE,CAAC;AAEpE,WAAO,OAAO,KAAK,OAAO,QAAQ;AAAA,EACpC,QAAE;AACA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,kBAAkB,YAA6B;AAC1D,QAAM,EAAE,QAAQ,IAAI,UAAM,kCAAiB;AAE3C,SAAO;AACT;AAgBO,MAAM,sBAAsB,YAAuC;AACxE,QAAM,CAAC,OAAO,MAAM,IAAI,MAAM,QAAQ,IAAI;AAAA,IACxC,gBAAgB;AAAA,IAChB,mBAAmB;AAAA,EACrB,CAAC;AAED,MAAI,WAAW,MAAM;AAEnB,WAAO;AAAA,MACL,SAAS;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,SAAS,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AACF;",
6
+ "names": ["validatePackageName", "searchNpm"]
7
+ }
package/lib/utils/wait.js CHANGED
@@ -1,32 +1,59 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withTimeout = exports.throwOnTimeout = exports.sleep = void 0;
4
- const error_1 = require("./error");
5
- const logging_1 = require("./logging");
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");
27
+ var import_logging = require("./logging");
6
28
  const sleep = (ms) => {
7
- let timeout;
8
- return Object.assign(new Promise((resolve) => (timeout = setTimeout(resolve, ms))), { clear: () => clearTimeout(timeout) });
29
+ let timeout;
30
+ return Object.assign(
31
+ new Promise((resolve) => timeout = setTimeout(resolve, ms)),
32
+ { clear: () => clearTimeout(timeout) }
33
+ );
9
34
  };
10
- exports.sleep = sleep;
11
35
  const throwOnTimeout = async (promise, { s }) => {
12
- const result = await (0, exports.withTimeout)(promise, { s });
13
- if (!result.ok) {
14
- throw (0, error_1.createTerseError)(`Timed out after ${(0, logging_1.pluralise)(s, 'second')}`);
15
- }
16
- return result.value;
36
+ const result = await withTimeout(promise, { s });
37
+ if (!result.ok) {
38
+ throw (0, import_error.createTerseError)(`Timed out after ${(0, import_logging.pluralise)(s, "second")}`);
39
+ }
40
+ return result.value;
17
41
  };
18
- exports.throwOnTimeout = throwOnTimeout;
19
42
  const withTimeout = async (promise, { s }) => {
20
- const timeout = (0, exports.sleep)(s * 1000);
21
- try {
22
- return await Promise.race([
23
- Promise.resolve(promise).then((value) => ({ ok: true, value })),
24
- timeout.then(() => ({ ok: false })),
25
- ]);
26
- }
27
- finally {
28
- timeout.clear?.();
29
- }
43
+ const timeout = sleep(s * 1e3);
44
+ try {
45
+ return await Promise.race([
46
+ Promise.resolve(promise).then((value) => ({ ok: true, value })),
47
+ timeout.then(() => ({ ok: false }))
48
+ ]);
49
+ } finally {
50
+ timeout.clear?.();
51
+ }
30
52
  };
31
- exports.withTimeout = withTimeout;
32
- //# sourceMappingURL=wait.js.map
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ sleep,
56
+ throwOnTimeout,
57
+ withTimeout
58
+ });
59
+ //# sourceMappingURL=wait.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"wait.js","sourceRoot":"","sources":["../../src/utils/wait.ts"],"names":[],"mappings":";;;AAAA,mCAA2C;AAC3C,uCAAsC;AAM/B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAW,EAAE;IAC3C,IAAI,OAAuB,CAAC;IAE5B,OAAO,MAAM,CAAC,MAAM,CAClB,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EACnE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CACvC,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,KAAK,SAOhB;AAEK,MAAM,cAAc,GAAG,KAAK,EACjC,OAAuB,EACvB,EAAE,CAAC,EAAiB,EACR,EAAE;IACd,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAW,EAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAEjD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;QACd,MAAM,IAAA,wBAAgB,EAAC,mBAAmB,IAAA,mBAAS,EAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;KACrE;IAED,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC,CAAC;AAXW,QAAA,cAAc,kBAWzB;AAIK,MAAM,WAAW,GAAG,KAAK,EAC9B,OAA2B,EAC3B,EAAE,CAAC,EAAiB,EACO,EAAE;IAC7B,MAAM,OAAO,GAAG,IAAA,aAAK,EAAC,CAAC,GAAG,IAAK,CAAC,CAAC;IAEjC,IAAI;QACF,OAAO,MAAM,OAAO,CAAC,IAAI,CAAmB;YAC1C,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YAC/D,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;SACpC,CAAC,CAAC;KACJ;YAAS;QACR,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;KACnB;AACH,CAAC,CAAC;AAdW,QAAA,WAAW,eActB"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/wait.ts"],
4
+ "sourcesContent": ["import { createTerseError } from './error';\nimport { pluralise } from './logging';\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,GAAG;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;",
6
+ "names": []
7
+ }
@@ -1,48 +1,63 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.postWorkerOutput = exports.execWorkerThread = void 0;
4
- const util_1 = require("util");
5
- const worker_threads_1 = require("worker_threads");
6
- const logging_1 = require("./logging");
7
- /**
8
- * Executes a script at `filepath` in a Node.js worker thread.
9
- */
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");
10
28
  const execWorkerThread = async (filepath, input) => {
11
- let output;
12
- let messageReceived = false;
13
- return new Promise((resolve, reject) => new worker_threads_1.Worker(filepath, {
14
- workerData: input,
15
- })
16
- .on('error', reject)
17
- .on('exit', (code) => messageReceived
18
- ? resolve(output)
19
- : reject(new Error(code
20
- ? `Worker thread failed with exit code ${code}`
21
- : 'Worker thread exited without posting a message')))
22
- .on('message', (message) => {
23
- // Defer promise resolution to `exit` so stdio can settle.
24
- output = message;
25
- messageReceived = true;
26
- })
27
- .on('messageerror', (err) => reject(err)));
29
+ let output;
30
+ let messageReceived = false;
31
+ return new Promise(
32
+ (resolve, reject) => new import_worker_threads.Worker(filepath, {
33
+ workerData: input
34
+ }).on("error", reject).on(
35
+ "exit",
36
+ (code) => messageReceived ? resolve(output) : reject(
37
+ new Error(
38
+ code ? `Worker thread failed with exit code ${code}` : "Worker thread exited without posting a message"
39
+ )
40
+ )
41
+ ).on("message", (message) => {
42
+ output = message;
43
+ messageReceived = true;
44
+ }).on("messageerror", (err) => reject(err))
45
+ );
28
46
  };
29
- exports.execWorkerThread = execWorkerThread;
30
- /**
31
- * Runs a function in a Node.js worker thread context, forwarding the result
32
- * to the parent thread.
33
- */
34
- const postWorkerOutput = (fn, logger = logging_1.log) => {
35
- const port = worker_threads_1.parentPort;
36
- if (!port) {
37
- logger.err('`postWorkerOutput` called outside of a worker thread context');
38
- process.exit(1);
39
- }
40
- fn(worker_threads_1.workerData)
41
- .then((output) => port.postMessage(output))
42
- .catch((err) => {
43
- logger.err((0, util_1.inspect)(err));
44
- process.exit(1);
45
- });
47
+ const postWorkerOutput = (fn, logger = import_logging.log) => {
48
+ const port = import_worker_threads.parentPort;
49
+ if (!port) {
50
+ logger.err("`postWorkerOutput` called outside of a worker thread context");
51
+ process.exit(1);
52
+ }
53
+ fn(import_worker_threads.workerData).then((output) => port.postMessage(output)).catch((err) => {
54
+ logger.err((0, import_util.inspect)(err));
55
+ process.exit(1);
56
+ });
46
57
  };
47
- exports.postWorkerOutput = postWorkerOutput;
48
- //# sourceMappingURL=worker.js.map
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ execWorkerThread,
61
+ postWorkerOutput
62
+ });
63
+ //# sourceMappingURL=worker.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/utils/worker.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,mDAAgE;AAEhE,uCAAgC;AAEhC;;GAEG;AACI,MAAM,gBAAgB,GAAG,KAAK,EACnC,QAAgB,EAChB,KAAY,EACZ,EAAE;IACF,IAAI,MAAc,CAAC;IACnB,IAAI,eAAe,GAAG,KAAK,CAAC;IAE5B,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAC7C,IAAI,uBAAM,CAAC,QAAQ,EAAE;QACnB,UAAU,EAAE,KAAK;KAClB,CAAC;SACC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;SACnB,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CACnB,eAAe;QACb,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QACjB,CAAC,CAAC,MAAM,CACJ,IAAI,KAAK,CACP,IAAI;YACF,CAAC,CAAC,uCAAuC,IAAI,EAAE;YAC/C,CAAC,CAAC,gDAAgD,CACrD,CACF,CACN;SACA,EAAE,CAAC,SAAS,EAAE,CAAC,OAAe,EAAE,EAAE;QACjC,0DAA0D;QAC1D,MAAM,GAAG,OAAO,CAAC;QACjB,eAAe,GAAG,IAAI,CAAC;IACzB,CAAC,CAAC;SACD,EAAE,CAAC,cAAc,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAC5C,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,gBAAgB,oBA8B3B;AAEF;;;GAGG;AACI,MAAM,gBAAgB,GAAG,CAC9B,EAAqC,EACrC,MAAM,GAAG,aAAG,EACZ,EAAE;IACF,MAAM,IAAI,GAAG,2BAAU,CAAC;IAExB,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,CAAC,GAAG,CAAC,8DAA8D,CAAC,CAAC;QAE3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,EAAE,CAAC,2BAAmB,CAAC;SACpB,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;SAC1C,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,MAAM,CAAC,GAAG,CAAC,IAAA,cAAO,EAAC,GAAG,CAAC,CAAC,CAAC;QAEzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAnBW,QAAA,gBAAgB,oBAmB3B"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/worker.ts"],
4
+ "sourcesContent": ["import { inspect } from 'util';\nimport { Worker, parentPort, workerData } from 'worker_threads';\n\nimport { log } from './logging';\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,SACvC;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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=function-arguments.d.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,32 +1,59 @@
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.runFunctionHandler = void 0;
7
- const function_arguments_1 = __importDefault(require("function-arguments"));
8
- const logging_1 = require("../utils/logging");
9
- const validation_1 = require("../utils/validation");
10
- const http_1 = require("./http");
11
- /**
12
- * Create an HTTP server that calls into an exported function.
13
- */
14
- const runFunctionHandler = async ({ availablePort, entryPoint, functionName, }) => {
15
- if (!(0, validation_1.isObject)(entryPoint)) {
16
- logging_1.log.subtle(logging_1.log.bold(functionName), 'is not exported');
17
- return;
18
- }
19
- const fn = entryPoint[functionName];
20
- if (!(0, validation_1.isFunction)(fn)) {
21
- logging_1.log.subtle(logging_1.log.bold(functionName), 'is not a function');
22
- return;
23
- }
24
- logging_1.log.warn(logging_1.log.bold(functionName), `(${(0, function_arguments_1.default)(fn)
25
- // Add a `?` placeholder for unnamed arguments.
26
- .map((arg) => arg || '?')
27
- .join(', ')})`);
28
- const requestListener = (0, http_1.createRequestListenerFromFunction)(fn);
29
- return (0, http_1.serveRequestListener)(requestListener, availablePort);
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;
30
19
  };
31
- exports.runFunctionHandler = runFunctionHandler;
32
- //# sourceMappingURL=functionHandler.js.map
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 functionHandler_exports = {};
26
+ __export(functionHandler_exports, {
27
+ runFunctionHandler: () => runFunctionHandler
28
+ });
29
+ module.exports = __toCommonJS(functionHandler_exports);
30
+ var import_function_arguments = __toESM(require("function-arguments"));
31
+ var import_logging = require("../utils/logging");
32
+ var import_validation = require("../utils/validation");
33
+ var import_http = require("./http");
34
+ const runFunctionHandler = async ({
35
+ availablePort,
36
+ entryPoint,
37
+ functionName
38
+ }) => {
39
+ if (!(0, import_validation.isObject)(entryPoint)) {
40
+ import_logging.log.subtle(import_logging.log.bold(functionName), "is not exported");
41
+ return;
42
+ }
43
+ const fn = entryPoint[functionName];
44
+ if (!(0, import_validation.isFunction)(fn)) {
45
+ import_logging.log.subtle(import_logging.log.bold(functionName), "is not a function");
46
+ return;
47
+ }
48
+ import_logging.log.warn(
49
+ import_logging.log.bold(functionName),
50
+ `(${(0, import_function_arguments.default)(fn).map((arg) => arg || "?").join(", ")})`
51
+ );
52
+ const requestListener = (0, import_http.createRequestListenerFromFunction)(fn);
53
+ return (0, import_http.serveRequestListener)(requestListener, availablePort);
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ runFunctionHandler
58
+ });
59
+ //# sourceMappingURL=functionHandler.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"functionHandler.js","sourceRoot":"","sources":["../../src/wrapper/functionHandler.ts"],"names":[],"mappings":";;;;;;AAAA,4EAAwC;AAExC,8CAAuC;AACvC,oDAA2D;AAE3D,iCAGgB;AAQhB;;GAEG;AACI,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,aAAa,EACb,UAAU,EACV,YAAY,GACP,EAAiB,EAAE;IACxB,IAAI,CAAC,IAAA,qBAAQ,EAAC,UAAU,CAAC,EAAE;QACzB,aAAG,CAAC,MAAM,CAAC,aAAG,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC,CAAC;QACtD,OAAO;KACR;IAED,MAAM,EAAE,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAEpC,IAAI,CAAC,IAAA,uBAAU,EAAC,EAAE,CAAC,EAAE;QACnB,aAAG,CAAC,MAAM,CAAC,aAAG,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC,CAAC;QACxD,OAAO;KACR;IAED,aAAG,CAAC,IAAI,CACN,aAAG,CAAC,IAAI,CAAC,YAAY,CAAC,EACtB,IAAI,IAAA,4BAAM,EAAC,EAAE,CAAC;QACZ,+CAA+C;SAC9C,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC;SACxB,IAAI,CAAC,IAAI,CAAC,GAAG,CACjB,CAAC;IAEF,MAAM,eAAe,GAAG,IAAA,wCAAiC,EAAC,EAAE,CAAC,CAAC;IAE9D,OAAO,IAAA,2BAAoB,EAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AAC9D,CAAC,CAAC;AA5BW,QAAA,kBAAkB,sBA4B7B"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapper/functionHandler.ts"],
4
+ "sourcesContent": ["import fnArgs from 'function-arguments';\n\nimport { log } from '../utils/logging';\nimport { isFunction, isObject } from '../utils/validation';\n\nimport {\n createRequestListenerFromFunction,\n serveRequestListener,\n} from './http';\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;AAEtB,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;AAAA,EACd;AAEA,QAAM,sBAAkB,+CAAkC,EAAE;AAE5D,aAAO,kCAAqB,iBAAiB,aAAa;AAC5D;",
6
+ "names": ["fnArgs"]
7
+ }
@@ -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