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.
- package/config/tsconfig.json +1 -0
- package/jest/moduleNameMapper.js +50 -78
- package/jest/moduleNameMapper.test.ts +4 -14
- package/jest/transform.js +10 -1
- package/jest/tsConfig.js +26 -0
- package/lib/api/buildkite/annotate.js +46 -33
- package/lib/api/buildkite/annotate.js.map +7 -1
- package/lib/api/buildkite/index.js +31 -7
- package/lib/api/buildkite/index.js.map +7 -1
- package/lib/api/buildkite/md.js +31 -8
- package/lib/api/buildkite/md.js.map +7 -1
- package/lib/api/git/commit.js +45 -17
- package/lib/api/git/commit.js.map +7 -1
- package/lib/api/git/commitAllChanges.js +57 -27
- package/lib/api/git/commitAllChanges.js.map +7 -1
- package/lib/api/git/currentBranch.js +50 -28
- package/lib/api/git/currentBranch.js.map +7 -1
- package/lib/api/git/getChangedFiles.js +49 -27
- package/lib/api/git/getChangedFiles.js.map +7 -1
- package/lib/api/git/index.js +54 -22
- package/lib/api/git/index.js.map +7 -1
- package/lib/api/git/log.js +63 -42
- package/lib/api/git/log.js.map +7 -1
- package/lib/api/git/pull.js +62 -31
- package/lib/api/git/pull.js.map +7 -1
- package/lib/api/git/push.js +63 -31
- package/lib/api/git/push.js.map +7 -1
- package/lib/api/git/remote.js +59 -56
- package/lib/api/git/remote.js.map +7 -1
- package/lib/api/git/reset.js +55 -27
- package/lib/api/git/reset.js.map +7 -1
- package/lib/api/git/statusMatrix.js +46 -13
- package/lib/api/git/statusMatrix.js.map +7 -1
- package/lib/api/github/checkRun.js +70 -79
- package/lib/api/github/checkRun.js.map +7 -1
- package/lib/api/github/environment.js +40 -33
- package/lib/api/github/environment.js.map +7 -1
- package/lib/api/github/index.js +47 -17
- package/lib/api/github/index.js.map +7 -1
- package/lib/api/github/issueComment.js +73 -81
- package/lib/api/github/issueComment.js.map +7 -1
- package/lib/api/github/pullRequest.js +60 -61
- package/lib/api/github/pullRequest.js.map +7 -1
- package/lib/api/github/push.js +138 -133
- package/lib/api/github/push.js.map +7 -1
- package/lib/api/jest/index.d.ts +2 -1
- package/lib/api/jest/index.js +35 -14
- package/lib/api/jest/index.js.map +7 -1
- package/lib/api/net/compose.js +45 -17
- package/lib/api/net/compose.js.map +7 -1
- package/lib/api/net/index.js +28 -5
- package/lib/api/net/index.js.map +7 -1
- package/lib/api/net/socket.js +58 -36
- package/lib/api/net/socket.js.map +7 -1
- package/lib/api/net/waitFor.js +38 -18
- package/lib/api/net/waitFor.js.map +7 -1
- package/lib/cli/adapter/eslint.js +95 -72
- package/lib/cli/adapter/eslint.js.map +7 -1
- package/lib/cli/adapter/prettier.js +126 -124
- package/lib/cli/adapter/prettier.js.map +7 -1
- package/lib/cli/build/args.d.ts +7 -0
- package/lib/cli/build/args.js +69 -0
- package/lib/cli/build/args.js.map +7 -0
- package/lib/cli/build/esbuild.d.ts +5 -0
- package/lib/cli/build/esbuild.js +128 -0
- package/lib/cli/build/esbuild.js.map +7 -0
- package/lib/cli/build/index.d.ts +1 -1
- package/lib/cli/build/index.js +68 -5
- package/lib/cli/build/index.js.map +7 -1
- package/lib/cli/build/tsc.d.ts +1 -1
- package/lib/cli/build/tsc.js +34 -23
- package/lib/cli/build/tsc.js.map +7 -1
- package/lib/cli/buildPackage.js +53 -23
- package/lib/cli/buildPackage.js.map +7 -1
- package/lib/cli/configure/addEmptyExports.d.ts +5 -0
- package/lib/cli/configure/addEmptyExports.js +67 -0
- package/lib/cli/configure/addEmptyExports.js.map +7 -0
- package/lib/cli/configure/analyseConfiguration.js +61 -31
- package/lib/cli/configure/analyseConfiguration.js.map +7 -1
- package/lib/cli/configure/analyseDependencies.js +122 -113
- package/lib/cli/configure/analyseDependencies.js.map +7 -1
- package/lib/cli/configure/analysis/diff.js +37 -11
- package/lib/cli/configure/analysis/diff.js.map +7 -1
- package/lib/cli/configure/analysis/files.js +49 -22
- package/lib/cli/configure/analysis/files.js.map +7 -1
- package/lib/cli/configure/analysis/git.js +46 -16
- package/lib/cli/configure/analysis/git.js.map +7 -1
- package/lib/cli/configure/analysis/package.js +99 -52
- package/lib/cli/configure/analysis/package.js.map +7 -1
- package/lib/cli/configure/analysis/project.js +90 -54
- package/lib/cli/configure/analysis/project.js.map +7 -1
- package/lib/cli/configure/dependencies/index.js +40 -13
- package/lib/cli/configure/dependencies/index.js.map +7 -1
- package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js +57 -32
- package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js.map +7 -1
- package/lib/cli/configure/dependencies/seekKoala.js +53 -31
- package/lib/cli/configure/dependencies/seekKoala.js.map +7 -1
- package/lib/cli/configure/dependencies/skuba.js +49 -27
- package/lib/cli/configure/dependencies/skuba.js.map +7 -1
- package/lib/cli/configure/dependencies/skubaDeps.js +49 -28
- package/lib/cli/configure/dependencies/skubaDeps.js.map +7 -1
- package/lib/cli/configure/dependencies/skubaDive.js +65 -38
- package/lib/cli/configure/dependencies/skubaDive.js.map +7 -1
- package/lib/cli/configure/ensureTemplateCompletion.js +69 -41
- package/lib/cli/configure/ensureTemplateCompletion.js.map +7 -1
- package/lib/cli/configure/getEntryPoint.js +62 -32
- package/lib/cli/configure/getEntryPoint.js.map +7 -1
- package/lib/cli/configure/getProjectType.js +50 -28
- package/lib/cli/configure/getProjectType.js.map +7 -1
- package/lib/cli/configure/index.js +134 -109
- package/lib/cli/configure/index.js.map +7 -1
- package/lib/cli/configure/modules/eslint.js +57 -26
- package/lib/cli/configure/modules/eslint.js.map +7 -1
- package/lib/cli/configure/modules/ignore.js +37 -14
- package/lib/cli/configure/modules/ignore.js.map +7 -1
- package/lib/cli/configure/modules/index.js +53 -28
- package/lib/cli/configure/modules/index.js.map +7 -1
- package/lib/cli/configure/modules/jest.js +84 -47
- package/lib/cli/configure/modules/jest.js.map +7 -1
- package/lib/cli/configure/modules/nodemon.js +29 -6
- package/lib/cli/configure/modules/nodemon.js.map +7 -1
- package/lib/cli/configure/modules/package.js +113 -92
- package/lib/cli/configure/modules/package.js.map +7 -1
- package/lib/cli/configure/modules/prettier.js +48 -19
- package/lib/cli/configure/modules/prettier.js.map +7 -1
- package/lib/cli/configure/modules/renovate.js +52 -39
- package/lib/cli/configure/modules/renovate.js.map +7 -1
- package/lib/cli/configure/modules/serverless.js +33 -15
- package/lib/cli/configure/modules/serverless.js.map +7 -1
- package/lib/cli/configure/modules/skubaDive.js +63 -37
- package/lib/cli/configure/modules/skubaDive.js.map +7 -1
- package/lib/cli/configure/modules/tsconfig.js +79 -63
- package/lib/cli/configure/modules/tsconfig.js.map +7 -1
- package/lib/cli/configure/modules/tslint.js +29 -6
- package/lib/cli/configure/modules/tslint.js.map +7 -1
- package/lib/cli/configure/processing/deleteFiles.js +30 -8
- package/lib/cli/configure/processing/deleteFiles.js.map +7 -1
- package/lib/cli/configure/processing/ignoreFile.js +65 -59
- package/lib/cli/configure/processing/ignoreFile.js.map +7 -1
- package/lib/cli/configure/processing/javascript.js +35 -15
- package/lib/cli/configure/processing/javascript.js.map +7 -1
- package/lib/cli/configure/processing/json.js +51 -20
- package/lib/cli/configure/processing/json.js.map +7 -1
- package/lib/cli/configure/processing/loadFiles.js +30 -8
- package/lib/cli/configure/processing/loadFiles.js.map +7 -1
- package/lib/cli/configure/processing/module.js +37 -14
- package/lib/cli/configure/processing/module.js.map +7 -1
- package/lib/cli/configure/processing/package.js +73 -43
- package/lib/cli/configure/processing/package.js.map +7 -1
- package/lib/cli/configure/processing/prettier.js +37 -11
- package/lib/cli/configure/processing/prettier.js.map +7 -1
- package/lib/cli/configure/processing/record.js +54 -31
- package/lib/cli/configure/processing/record.js.map +7 -1
- package/lib/cli/configure/processing/typescript.js +176 -158
- package/lib/cli/configure/processing/typescript.js.map +7 -1
- package/lib/cli/configure/refreshIgnoreFiles.js +64 -40
- package/lib/cli/configure/refreshIgnoreFiles.js.map +7 -1
- package/lib/cli/configure/types.js +16 -2
- package/lib/cli/configure/types.js.map +7 -1
- package/lib/cli/format.js +58 -31
- package/lib/cli/format.js.map +7 -1
- package/lib/cli/help.js +31 -8
- package/lib/cli/help.js.map +7 -1
- package/lib/cli/init/getConfig.js +238 -207
- package/lib/cli/init/getConfig.js.map +7 -1
- package/lib/cli/init/git.js +70 -63
- package/lib/cli/init/git.js.map +7 -1
- package/lib/cli/init/index.js +133 -100
- package/lib/cli/init/index.js.map +7 -1
- package/lib/cli/init/prompts.js +84 -54
- package/lib/cli/init/prompts.js.map +7 -1
- package/lib/cli/init/types.js +52 -52
- package/lib/cli/init/types.js.map +7 -1
- package/lib/cli/init/validation.js +34 -12
- package/lib/cli/init/validation.js.map +7 -1
- package/lib/cli/init/writePackageJson.js +51 -22
- package/lib/cli/init/writePackageJson.js.map +7 -1
- package/lib/cli/lint/annotate/buildkite/eslint.js +34 -28
- package/lib/cli/lint/annotate/buildkite/eslint.js.map +7 -1
- package/lib/cli/lint/annotate/buildkite/index.js +50 -44
- package/lib/cli/lint/annotate/buildkite/index.js.map +7 -1
- package/lib/cli/lint/annotate/buildkite/prettier.js +41 -35
- package/lib/cli/lint/annotate/buildkite/prettier.js.map +7 -1
- package/lib/cli/lint/annotate/buildkite/tsc.js +39 -39
- package/lib/cli/lint/annotate/buildkite/tsc.js.map +7 -1
- package/lib/cli/lint/annotate/github/eslint.js +40 -16
- package/lib/cli/lint/annotate/github/eslint.js.map +7 -1
- package/lib/cli/lint/annotate/github/index.js +55 -51
- package/lib/cli/lint/annotate/github/index.js.map +7 -1
- package/lib/cli/lint/annotate/github/prettier.js +36 -13
- package/lib/cli/lint/annotate/github/prettier.js.map +7 -1
- package/lib/cli/lint/annotate/github/tsc.js +52 -52
- package/lib/cli/lint/annotate/github/tsc.js.map +7 -1
- package/lib/cli/lint/annotate/index.js +33 -10
- package/lib/cli/lint/annotate/index.js.map +7 -1
- package/lib/cli/lint/autofix.js +122 -117
- package/lib/cli/lint/autofix.js.map +7 -1
- package/lib/cli/lint/eslint.js +48 -18
- package/lib/cli/lint/eslint.js.map +7 -1
- package/lib/cli/lint/external.js +102 -81
- package/lib/cli/lint/external.js.map +7 -1
- package/lib/cli/lint/index.js +42 -18
- package/lib/cli/lint/index.js.map +7 -1
- package/lib/cli/lint/internal.js +54 -21
- package/lib/cli/lint/internal.js.map +7 -1
- package/lib/cli/lint/prettier.js +48 -18
- package/lib/cli/lint/prettier.js.map +7 -1
- package/lib/cli/lint/tsc.js +56 -32
- package/lib/cli/lint/tsc.js.map +7 -1
- package/lib/cli/lint/types.js +16 -2
- package/lib/cli/lint/types.js.map +7 -1
- package/lib/cli/node.js +65 -58
- package/lib/cli/node.js.map +7 -1
- package/lib/cli/release.js +29 -6
- package/lib/cli/release.js.map +7 -1
- package/lib/cli/start.js +61 -24
- package/lib/cli/start.js.map +7 -1
- package/lib/cli/test/index.js +35 -11
- package/lib/cli/test/index.js.map +7 -1
- package/lib/cli/test/reporters/github/annotations.js +89 -92
- package/lib/cli/test/reporters/github/annotations.js.map +7 -1
- package/lib/cli/test/reporters/github/index.js +68 -68
- package/lib/cli/test/reporters/github/index.js.map +7 -1
- package/lib/cli/version.js +31 -8
- package/lib/cli/version.js.map +7 -1
- package/lib/enquirer.d.js +2 -0
- package/lib/enquirer.d.js.map +7 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +45 -41
- package/lib/index.js.map +7 -1
- package/lib/skuba.js +45 -38
- package/lib/skuba.js.map +7 -1
- package/lib/utils/args.js +97 -96
- package/lib/utils/args.js.map +7 -1
- package/lib/utils/command.js +64 -33
- package/lib/utils/command.js.map +7 -1
- package/lib/utils/copy.js +88 -51
- package/lib/utils/copy.js.map +7 -1
- package/lib/utils/dir.js +79 -67
- package/lib/utils/dir.js.map +7 -1
- package/lib/utils/env.js +27 -7
- package/lib/utils/env.js.map +7 -1
- package/lib/utils/error.js +58 -56
- package/lib/utils/error.js.map +7 -1
- package/lib/utils/exec.js +139 -110
- package/lib/utils/exec.js.map +7 -1
- package/lib/utils/help.js +31 -8
- package/lib/utils/help.js.map +7 -1
- package/lib/utils/logging.js +52 -24
- package/lib/utils/logging.js.map +7 -1
- package/lib/utils/logo.js +65 -27
- package/lib/utils/logo.js.map +7 -1
- package/lib/utils/manifest.d.ts +1 -0
- package/lib/utils/manifest.js +65 -51
- package/lib/utils/manifest.js.map +7 -1
- package/lib/utils/port.js +38 -17
- package/lib/utils/port.js.map +7 -1
- package/lib/utils/template.js +106 -87
- package/lib/utils/template.js.map +7 -1
- package/lib/utils/validation.js +43 -18
- package/lib/utils/validation.js.map +7 -1
- package/lib/utils/version.js +73 -40
- package/lib/utils/version.js.map +7 -1
- package/lib/utils/wait.js +52 -25
- package/lib/utils/wait.js.map +7 -1
- package/lib/utils/worker.js +59 -44
- package/lib/utils/worker.js.map +7 -1
- package/lib/wrapper/function-arguments.d.js +2 -0
- package/lib/wrapper/function-arguments.d.js.map +7 -0
- package/lib/wrapper/functionHandler.js +56 -29
- package/lib/wrapper/functionHandler.js.map +7 -1
- package/lib/wrapper/http.js +66 -56
- package/lib/wrapper/http.js.map +7 -1
- package/lib/wrapper/index.js +9 -21
- package/lib/wrapper/index.js.map +7 -1
- package/lib/wrapper/main.js +39 -20
- package/lib/wrapper/main.js.map +7 -1
- package/lib/wrapper/requestListener.js +50 -35
- package/lib/wrapper/requestListener.js.map +7 -1
- package/package.json +21 -14
- package/template/base/jest.config.ts +0 -6
- package/template/base/jest.setup.ts +2 -0
- package/template/express-rest-api/.buildkite/pipeline.yml +1 -1
- package/template/express-rest-api/package.json +1 -1
- package/template/greeter/.buildkite/pipeline.yml +1 -1
- package/template/greeter/package.json +1 -1
- package/template/greeter/src/app.test.ts +3 -1
- package/template/koa-rest-api/.buildkite/pipeline.yml +1 -1
- package/template/koa-rest-api/package.json +6 -9
- package/template/koa-rest-api/src/api/jobs/postJob.test.ts +3 -7
- package/template/koa-rest-api/src/api/jobs/postJob.ts +2 -2
- package/template/koa-rest-api/src/framework/validation.test.ts +17 -15
- package/template/koa-rest-api/src/framework/validation.ts +50 -9
- package/template/koa-rest-api/src/storage/jobs.ts +2 -2
- package/template/koa-rest-api/src/testing/types.ts +5 -10
- package/template/koa-rest-api/src/types/jobs.ts +5 -10
- package/template/lambda-sqs-worker/.buildkite/pipeline.yml +3 -3
- package/template/lambda-sqs-worker/README.md +1 -1
- package/template/lambda-sqs-worker/package.json +4 -4
- package/template/lambda-sqs-worker/serverless.yml +17 -2
- package/template/lambda-sqs-worker/src/app.test.ts +19 -17
- package/template/lambda-sqs-worker/src/app.ts +8 -8
- package/template/lambda-sqs-worker/src/config.ts +3 -0
- package/template/lambda-sqs-worker/src/framework/handler.test.ts +7 -7
- package/template/lambda-sqs-worker/src/framework/handler.ts +31 -8
- package/template/lambda-sqs-worker/src/framework/metrics.ts +10 -6
- package/template/lambda-sqs-worker/src/framework/validation.test.ts +37 -17
- package/template/lambda-sqs-worker/src/framework/validation.ts +4 -2
- package/template/lambda-sqs-worker/src/services/jobScorer.ts +2 -2
- package/template/lambda-sqs-worker/src/testing/types.ts +5 -10
- package/template/lambda-sqs-worker/src/types/jobScorer.ts +9 -16
- package/template/lambda-sqs-worker/src/types/pipelineEvents.ts +13 -20
- package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +3 -3
- package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +6 -0
- package/template/lambda-sqs-worker-cdk/infra/appStack.ts +3 -3
- package/template/lambda-sqs-worker-cdk/infra/index.ts +2 -2
- package/template/lambda-sqs-worker-cdk/package.json +2 -2
- package/template/lambda-sqs-worker-cdk/shared/context-types.ts +16 -25
- package/template/oss-npm-package/_package.json +1 -1
- package/template/private-npm-package/_package.json +1 -1
- package/jest/resolver.js +0 -24
package/lib/utils/version.js
CHANGED
|
@@ -1,52 +1,85 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
29
|
-
|
|
58
|
+
const { version } = await (0, import_manifest.getSkubaManifest)();
|
|
59
|
+
return version;
|
|
30
60
|
};
|
|
31
|
-
exports.getSkubaVersion = getSkubaVersion;
|
|
32
61
|
const getSkubaVersionInfo = async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
68
|
+
isStale: false,
|
|
69
|
+
local,
|
|
70
|
+
latest
|
|
49
71
|
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
isStale: latest !== local,
|
|
75
|
+
local,
|
|
76
|
+
latest
|
|
77
|
+
};
|
|
50
78
|
};
|
|
51
|
-
|
|
52
|
-
|
|
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
|
package/lib/utils/version.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
package/lib/utils/wait.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
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
|
+
}
|
package/lib/utils/worker.js
CHANGED
|
@@ -1,48 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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
|
package/lib/utils/worker.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
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
|
+
}
|
|
@@ -1,32 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
{
|
|
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
|
+
}
|
package/lib/wrapper/http.js
CHANGED
|
@@ -1,62 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|