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/cli/lint/autofix.js
CHANGED
|
@@ -1,127 +1,132 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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 });
|
|
24
11
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
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;
|
|
27
19
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
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 autofix_exports = {};
|
|
26
|
+
__export(autofix_exports, {
|
|
27
|
+
autofix: () => autofix
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(autofix_exports);
|
|
30
|
+
var import_util = require("util");
|
|
31
|
+
var import_simple_git = __toESM(require("simple-git"));
|
|
32
|
+
var Git = __toESM(require("../../api/git"));
|
|
33
|
+
var GitHub = __toESM(require("../../api/github"));
|
|
34
|
+
var import_eslint = require("../../cli/adapter/eslint");
|
|
35
|
+
var import_prettier = require("../../cli/adapter/prettier");
|
|
36
|
+
var import_env = require("../../utils/env");
|
|
37
|
+
var import_logging = require("../../utils/logging");
|
|
38
|
+
var import_wait = require("../../utils/wait");
|
|
39
|
+
const AUTOFIX_COMMIT_MESSAGE = "Run `skuba format`";
|
|
40
|
+
const shouldPush = async ({
|
|
41
|
+
currentBranch,
|
|
42
|
+
dir
|
|
43
|
+
}) => {
|
|
44
|
+
if (!(0, import_env.isCiEnv)()) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const isDefaultBuildkiteBranch = currentBranch && [process.env.BUILDKITE_PIPELINE_DEFAULT_BRANCH, "master", "main"].includes(
|
|
48
|
+
currentBranch
|
|
49
|
+
);
|
|
50
|
+
const isProtectedGitHubBranch = process.env.GITHUB_REF_PROTECTED === "true";
|
|
51
|
+
if (isDefaultBuildkiteBranch || isProtectedGitHubBranch) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
let headCommitMessage;
|
|
55
|
+
try {
|
|
56
|
+
headCommitMessage = await Git.getHeadCommitMessage({ dir });
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
if (headCommitMessage === AUTOFIX_COMMIT_MESSAGE) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
67
63
|
};
|
|
68
64
|
const autofix = async (params) => {
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
if (!params.eslint && !params.prettier) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const dir = process.cwd();
|
|
69
|
+
let currentBranch;
|
|
70
|
+
try {
|
|
71
|
+
currentBranch = await Git.currentBranch({ dir });
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
if (!await shouldPush({ currentBranch, dir })) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
import_logging.log.newline();
|
|
79
|
+
import_logging.log.warn(
|
|
80
|
+
`Trying to autofix with ${params.eslint ? "ESLint and " : ""}Prettier...`
|
|
81
|
+
);
|
|
82
|
+
const logger = (0, import_logging.createLogger)(params.debug);
|
|
83
|
+
if (params.eslint) {
|
|
84
|
+
await (0, import_eslint.runESLint)("format", logger);
|
|
71
85
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
await (0, import_prettier.runPrettier)("format", logger);
|
|
87
|
+
if (process.env.GITHUB_ACTIONS) {
|
|
88
|
+
const ref2 = await Git.commitAllChanges({
|
|
89
|
+
dir,
|
|
90
|
+
message: AUTOFIX_COMMIT_MESSAGE
|
|
91
|
+
});
|
|
92
|
+
if (!ref2) {
|
|
93
|
+
return import_logging.log.warn("No autofixes detected.");
|
|
94
|
+
}
|
|
95
|
+
await (0, import_wait.throwOnTimeout)((0, import_simple_git.default)().push(), { s: 30 });
|
|
96
|
+
import_logging.log.warn(`Pushed fix commit ${ref2}.`);
|
|
97
|
+
return;
|
|
76
98
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
if (!currentBranch) {
|
|
100
|
+
import_logging.log.warn("Could not determine the current branch.");
|
|
101
|
+
import_logging.log.warn(
|
|
102
|
+
"Please propagate BUILDKITE_BRANCH, GITHUB_HEAD_REF, GITHUB_REF_NAME, or the .git directory to your container."
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
80
105
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (process.env.GITHUB_ACTIONS) {
|
|
92
|
-
// GitHub runners have Git installed locally
|
|
93
|
-
const ref = await Git.commitAllChanges({
|
|
94
|
-
dir,
|
|
95
|
-
message: AUTOFIX_COMMIT_MESSAGE,
|
|
96
|
-
});
|
|
97
|
-
if (!ref) {
|
|
98
|
-
return logging_1.log.warn('No autofixes detected.');
|
|
99
|
-
}
|
|
100
|
-
await (0, wait_1.throwOnTimeout)((0, simple_git_1.default)().push(), { s: 30 });
|
|
101
|
-
logging_1.log.warn(`Pushed fix commit ${ref}.`);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
// Other CI Environments, use GitHub API
|
|
105
|
-
if (!currentBranch) {
|
|
106
|
-
logging_1.log.warn('Could not determine the current branch.');
|
|
107
|
-
logging_1.log.warn('Please propagate BUILDKITE_BRANCH, GITHUB_HEAD_REF, GITHUB_REF_NAME, or the .git directory to your container.');
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const ref = await (0, wait_1.throwOnTimeout)(GitHub.uploadAllFileChanges({
|
|
111
|
-
dir,
|
|
112
|
-
branch: currentBranch,
|
|
113
|
-
messageHeadline: AUTOFIX_COMMIT_MESSAGE,
|
|
114
|
-
}), { s: 30 });
|
|
115
|
-
if (!ref) {
|
|
116
|
-
return logging_1.log.warn('No autofixes detected.');
|
|
117
|
-
}
|
|
118
|
-
logging_1.log.warn(`Pushed fix commit ${ref}.`);
|
|
119
|
-
}
|
|
120
|
-
catch (err) {
|
|
121
|
-
logging_1.log.warn(logging_1.log.bold('Failed to push fix commit.'));
|
|
122
|
-
logging_1.log.warn(logging_1.log.bold('Does your CI environment have write access to your Git repository?'));
|
|
123
|
-
logging_1.log.subtle((0, util_1.inspect)(err));
|
|
106
|
+
const ref = await (0, import_wait.throwOnTimeout)(
|
|
107
|
+
GitHub.uploadAllFileChanges({
|
|
108
|
+
dir,
|
|
109
|
+
branch: currentBranch,
|
|
110
|
+
messageHeadline: AUTOFIX_COMMIT_MESSAGE
|
|
111
|
+
}),
|
|
112
|
+
{ s: 30 }
|
|
113
|
+
);
|
|
114
|
+
if (!ref) {
|
|
115
|
+
return import_logging.log.warn("No autofixes detected.");
|
|
124
116
|
}
|
|
117
|
+
import_logging.log.warn(`Pushed fix commit ${ref}.`);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
import_logging.log.warn(import_logging.log.bold("Failed to push fix commit."));
|
|
120
|
+
import_logging.log.warn(
|
|
121
|
+
import_logging.log.bold(
|
|
122
|
+
"Does your CI environment have write access to your Git repository?"
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
import_logging.log.subtle((0, import_util.inspect)(err));
|
|
126
|
+
}
|
|
125
127
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
autofix
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=autofix.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/cli/lint/autofix.ts"],
|
|
4
|
+
"sourcesContent": ["import { inspect } from 'util';\n\nimport simpleGit from 'simple-git';\n\nimport * as Git from '../../api/git';\nimport * as GitHub from '../../api/github';\nimport { runESLint } from '../../cli/adapter/eslint';\nimport { runPrettier } from '../../cli/adapter/prettier';\nimport { isCiEnv } from '../../utils/env';\nimport { createLogger, log } from '../../utils/logging';\nimport { throwOnTimeout } from '../../utils/wait';\n\nimport type { Input } from './types';\n\nconst AUTOFIX_COMMIT_MESSAGE = 'Run `skuba format`';\n\nconst shouldPush = async ({\n currentBranch,\n dir,\n}: {\n currentBranch?: string;\n dir: string;\n}) => {\n if (!isCiEnv()) {\n // We're not running in a CI environment so we don't need to push autofixes.\n // Ideally we'd drive this off of repository write permissions, but that is\n // non-trivial to infer without attempting an actual write.\n return false;\n }\n\n const isDefaultBuildkiteBranch =\n currentBranch &&\n [process.env.BUILDKITE_PIPELINE_DEFAULT_BRANCH, 'master', 'main'].includes(\n currentBranch,\n );\n\n const isProtectedGitHubBranch = process.env.GITHUB_REF_PROTECTED === 'true';\n\n if (isDefaultBuildkiteBranch || isProtectedGitHubBranch) {\n // The current branch is a protected branch.\n // We respect GitHub Flow; avoid pushing directly to the default branch.\n return false;\n }\n\n let headCommitMessage;\n try {\n headCommitMessage = await Git.getHeadCommitMessage({ dir });\n } catch {}\n\n if (headCommitMessage === AUTOFIX_COMMIT_MESSAGE) {\n // Short circuit when the head commit appears to be one of our autofixes.\n // Repeating the same operation is unlikely to correct outstanding issues.\n return false;\n }\n\n // Allow the push attempt to go ahead if our guards have been cleared.\n return true;\n};\n\ninterface AutofixParameters {\n debug: Input['debug'];\n\n eslint: boolean;\n prettier: boolean;\n}\n\nexport const autofix = async (params: AutofixParameters): Promise<void> => {\n if (!params.eslint && !params.prettier) {\n return;\n }\n\n const dir = process.cwd();\n\n let currentBranch;\n try {\n currentBranch = await Git.currentBranch({ dir });\n } catch {}\n\n if (!(await shouldPush({ currentBranch, dir }))) {\n return;\n }\n\n try {\n log.newline();\n log.warn(\n `Trying to autofix with ${params.eslint ? 'ESLint and ' : ''}Prettier...`,\n );\n\n const logger = createLogger(params.debug);\n\n if (params.eslint) {\n await runESLint('format', logger);\n }\n // Unconditionally re-run Prettier; reaching here means we have pre-existing\n // format violations or may have created new ones through ESLint fixes.\n await runPrettier('format', logger);\n\n if (process.env.GITHUB_ACTIONS) {\n // GitHub runners have Git installed locally\n const ref = await Git.commitAllChanges({\n dir,\n message: AUTOFIX_COMMIT_MESSAGE,\n });\n\n if (!ref) {\n return log.warn('No autofixes detected.');\n }\n\n await throwOnTimeout(simpleGit().push(), { s: 30 });\n log.warn(`Pushed fix commit ${ref}.`);\n return;\n }\n\n // Other CI Environments, use GitHub API\n if (!currentBranch) {\n log.warn('Could not determine the current branch.');\n log.warn(\n 'Please propagate BUILDKITE_BRANCH, GITHUB_HEAD_REF, GITHUB_REF_NAME, or the .git directory to your container.',\n );\n return;\n }\n\n const ref = await throwOnTimeout(\n GitHub.uploadAllFileChanges({\n dir,\n branch: currentBranch,\n messageHeadline: AUTOFIX_COMMIT_MESSAGE,\n }),\n { s: 30 },\n );\n\n if (!ref) {\n return log.warn('No autofixes detected.');\n }\n\n log.warn(`Pushed fix commit ${ref}.`);\n } catch (err) {\n log.warn(log.bold('Failed to push fix commit.'));\n log.warn(\n log.bold(\n 'Does your CI environment have write access to your Git repository?',\n ),\n );\n log.subtle(inspect(err));\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwB;AAExB,wBAAsB;AAEtB,UAAqB;AACrB,aAAwB;AACxB,oBAA0B;AAC1B,sBAA4B;AAC5B,iBAAwB;AACxB,qBAAkC;AAClC,kBAA+B;AAI/B,MAAM,yBAAyB;AAE/B,MAAM,aAAa,OAAO;AAAA,EACxB;AAAA,EACA;AACF,MAGM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D,yBAAI,KAAK,qBAAqBD,OAAM;AACpC;AAAA,IACF;AAGA,QAAI,CAAC,eAAe;AAClB,yBAAI,KAAK,yCAAyC;AAClD,yBAAI;AAAA,QACF;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,MAAM,UAAM;AAAA,MAChB,OAAO,qBAAqB;AAAA,QAC1B;AAAA,QACA,QAAQ;AAAA,QACR,iBAAiB;AAAA,MACnB,CAAC;AAAA,MACD,EAAE,GAAG,GAAG;AAAA,IACV;AAEA,QAAI,CAAC,KAAK;AACR,aAAO,mBAAI,KAAK,wBAAwB;AAAA,IAC1C;AAEA,uBAAI,KAAK,qBAAqB,MAAM;AAAA,EACtC,SAAS,KAAP;AACA,uBAAI,KAAK,mBAAI,KAAK,4BAA4B,CAAC;AAC/C,uBAAI;AAAA,MACF,mBAAI;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,uBAAI,WAAO,qBAAQ,GAAG,CAAC;AAAA,EACzB;AACF;",
|
|
6
|
+
"names": ["ref", "simpleGit"]
|
|
7
|
+
}
|
package/lib/cli/lint/eslint.js
CHANGED
|
@@ -1,21 +1,51 @@
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 eslint_exports = {};
|
|
26
|
+
__export(eslint_exports, {
|
|
27
|
+
runESLintInCurrentThread: () => runESLintInCurrentThread,
|
|
28
|
+
runESLintInWorkerThread: () => runESLintInWorkerThread
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(eslint_exports);
|
|
31
|
+
var import_path = __toESM(require("path"));
|
|
32
|
+
var import_worker_threads = require("worker_threads");
|
|
33
|
+
var import_chalk = __toESM(require("chalk"));
|
|
34
|
+
var import_logging = require("../../utils/logging");
|
|
35
|
+
var import_worker = require("../../utils/worker");
|
|
36
|
+
var import_eslint = require("../adapter/eslint");
|
|
37
|
+
const LOG_PREFIX = import_chalk.default.magenta("ESLint \u2502");
|
|
38
|
+
const runESLintInCurrentThread = ({ debug }) => (0, import_eslint.runESLint)("lint", (0, import_logging.createLogger)(debug, LOG_PREFIX));
|
|
39
|
+
const runESLintInWorkerThread = (input) => (0, import_worker.execWorkerThread)(
|
|
40
|
+
import_path.default.posix.join(__dirname, "eslint.js"),
|
|
41
|
+
input
|
|
42
|
+
);
|
|
43
|
+
if (!import_worker_threads.isMainThread) {
|
|
44
|
+
(0, import_worker.postWorkerOutput)(runESLintInCurrentThread, (0, import_logging.createLogger)(false, LOG_PREFIX));
|
|
20
45
|
}
|
|
21
|
-
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
runESLintInCurrentThread,
|
|
49
|
+
runESLintInWorkerThread
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=eslint.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/cli/lint/eslint.ts"],
|
|
4
|
+
"sourcesContent": ["import path from 'path';\nimport { isMainThread } from 'worker_threads';\n\nimport chalk from 'chalk';\n\nimport { createLogger } from '../../utils/logging';\nimport { execWorkerThread, postWorkerOutput } from '../../utils/worker';\nimport type { ESLintOutput } from '../adapter/eslint';\nimport { runESLint } from '../adapter/eslint';\n\nimport type { Input } from './types';\n\nconst LOG_PREFIX = chalk.magenta('ESLint \u2502');\n\nexport const runESLintInCurrentThread = ({ debug }: Input) =>\n runESLint('lint', createLogger(debug, LOG_PREFIX));\n\nexport const runESLintInWorkerThread = (input: Input) =>\n execWorkerThread<Input, ESLintOutput>(\n path.posix.join(__dirname, 'eslint.js'),\n input,\n );\n\nif (!isMainThread) {\n postWorkerOutput(runESLintInCurrentThread, createLogger(false, LOG_PREFIX));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,4BAA6B;AAE7B,mBAAkB;AAElB,qBAA6B;AAC7B,oBAAmD;AAEnD,oBAA0B;AAI1B,MAAM,aAAa,aAAAA,QAAM,QAAQ,iBAAY;AAEtC,MAAM,2BAA2B,CAAC,EAAE,MAAM,UAC/C,yBAAU,YAAQ,6BAAa,OAAO,UAAU,CAAC;AAE5C,MAAM,0BAA0B,CAAC,cACtC;AAAA,EACE,YAAAC,QAAK,MAAM,KAAK,WAAW,WAAW;AAAA,EACtC;AACF;AAEF,IAAI,CAAC,oCAAc;AACjB,sCAAiB,8BAA0B,6BAAa,OAAO,UAAU,CAAC;AAC5E;",
|
|
6
|
+
"names": ["chalk", "path"]
|
|
7
|
+
}
|
package/lib/cli/lint/external.js
CHANGED
|
@@ -1,95 +1,116 @@
|
|
|
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 external_exports = {};
|
|
26
|
+
__export(external_exports, {
|
|
27
|
+
StreamInterceptor: () => StreamInterceptor,
|
|
28
|
+
externalLint: () => externalLint
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(external_exports);
|
|
31
|
+
var import_stream = __toESM(require("stream"));
|
|
32
|
+
var import_util = require("util");
|
|
33
|
+
var import_logging = require("../../utils/logging");
|
|
34
|
+
var import_wait = require("../../utils/wait");
|
|
35
|
+
var import_annotate = require("./annotate");
|
|
36
|
+
var import_autofix = require("./autofix");
|
|
37
|
+
var import_eslint = require("./eslint");
|
|
38
|
+
var import_prettier = require("./prettier");
|
|
39
|
+
var import_tsc = require("./tsc");
|
|
16
40
|
const tscPrefixRegex = /^(.*?tsc\s+│.*?\s)/gm;
|
|
17
|
-
class StreamInterceptor extends
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
class StreamInterceptor extends import_stream.default.Transform {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.chunks = [];
|
|
45
|
+
}
|
|
46
|
+
output() {
|
|
47
|
+
return Buffer.concat(this.chunks).toString().replace(tscPrefixRegex, "");
|
|
48
|
+
}
|
|
49
|
+
_transform(chunk, _encoding, callback) {
|
|
50
|
+
this.chunks.push(chunk);
|
|
51
|
+
callback(null, chunk);
|
|
52
|
+
}
|
|
29
53
|
}
|
|
30
|
-
exports.StreamInterceptor = StreamInterceptor;
|
|
31
54
|
const lintConcurrently = async ({ tscOutputStream, ...input }) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
const [eslint, prettier, tscOk] = await Promise.all([
|
|
56
|
+
(0, import_eslint.runESLintInWorkerThread)(input),
|
|
57
|
+
(0, import_prettier.runPrettierInWorkerThread)(input),
|
|
58
|
+
(0, import_tsc.runTscInNewProcess)({ ...input, tscOutputStream })
|
|
59
|
+
]);
|
|
60
|
+
return { eslint, prettier, tscOk };
|
|
38
61
|
};
|
|
39
|
-
/**
|
|
40
|
-
* Run linting tools `--serial`ly for resource-constrained environments.
|
|
41
|
-
*
|
|
42
|
-
* Note that we still run ESLint and Prettier in worker threads as a
|
|
43
|
-
* counterintuitive optimisation. Memory can be more readily freed on worker
|
|
44
|
-
* thread exit, which isn't as easy with a monolithic main thread.
|
|
45
|
-
*/
|
|
46
62
|
const lintSerially = async ({ tscOutputStream, ...input }) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
const eslint = await (0, import_eslint.runESLintInWorkerThread)(input);
|
|
64
|
+
const prettier = await (0, import_prettier.runPrettierInWorkerThread)(input);
|
|
65
|
+
const tscOk = await (0, import_tsc.runTscInNewProcess)({ ...input, tscOutputStream });
|
|
66
|
+
return { eslint, prettier, tscOk };
|
|
51
67
|
};
|
|
52
68
|
const lintSeriallyWithoutWorkerThreads = async (input) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
const eslint = await (0, import_eslint.runESLintInCurrentThread)(input);
|
|
70
|
+
const prettier = await (0, import_prettier.runPrettierInCurrentThread)(input);
|
|
71
|
+
const tscOk = await (0, import_tsc.runTscInNewProcess)(input);
|
|
72
|
+
return { eslint, prettier, tscOk };
|
|
57
73
|
};
|
|
58
74
|
const selectLintFunction = (input) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return isSerial ? lintSerially : lintConcurrently;
|
|
75
|
+
if (!input.workerThreads) {
|
|
76
|
+
return lintSeriallyWithoutWorkerThreads;
|
|
77
|
+
}
|
|
78
|
+
const isSerial = input.debug || input.serial;
|
|
79
|
+
return isSerial ? lintSerially : lintConcurrently;
|
|
65
80
|
};
|
|
66
81
|
const externalLint = async (input) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
const lint = selectLintFunction(input);
|
|
83
|
+
const tscOutputStream = new StreamInterceptor();
|
|
84
|
+
tscOutputStream.pipe(input.tscOutputStream ?? process.stdout);
|
|
85
|
+
const { eslint, prettier, tscOk } = await lint({ ...input, tscOutputStream });
|
|
86
|
+
try {
|
|
87
|
+
await (0, import_wait.throwOnTimeout)(
|
|
88
|
+
(0, import_annotate.createAnnotations)(eslint, prettier, tscOk, tscOutputStream),
|
|
89
|
+
{ s: 30 }
|
|
90
|
+
);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
import_logging.log.warn("Failed to annotate lint results.");
|
|
93
|
+
import_logging.log.subtle((0, import_util.inspect)(err));
|
|
94
|
+
}
|
|
95
|
+
if (!eslint.ok || !prettier.ok || !tscOk) {
|
|
96
|
+
const tools = [
|
|
97
|
+
...eslint.ok ? [] : ["ESLint"],
|
|
98
|
+
...prettier.ok ? [] : ["Prettier"],
|
|
99
|
+
...tscOk ? [] : ["tsc"]
|
|
100
|
+
];
|
|
101
|
+
import_logging.log.newline();
|
|
102
|
+
import_logging.log.err(`${tools.join(", ")} found issues that require triage.`);
|
|
103
|
+
process.exitCode = 1;
|
|
104
|
+
}
|
|
105
|
+
await (0, import_autofix.autofix)({
|
|
106
|
+
debug: input.debug,
|
|
107
|
+
eslint: eslint.fixable,
|
|
108
|
+
prettier: !prettier.ok
|
|
109
|
+
});
|
|
93
110
|
};
|
|
94
|
-
|
|
95
|
-
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
StreamInterceptor,
|
|
114
|
+
externalLint
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=external.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/cli/lint/external.ts"],
|
|
4
|
+
"sourcesContent": ["import stream from 'stream';\nimport { inspect } from 'util';\n\nimport { log } from '../../utils/logging';\nimport { throwOnTimeout } from '../../utils/wait';\n\nimport { createAnnotations } from './annotate';\nimport { autofix } from './autofix';\nimport { runESLintInCurrentThread, runESLintInWorkerThread } from './eslint';\nimport {\n runPrettierInCurrentThread,\n runPrettierInWorkerThread,\n} from './prettier';\nimport { runTscInNewProcess } from './tsc';\nimport type { Input } from './types';\n\nconst tscPrefixRegex = /^(.*?tsc\\s+\u2502.*?\\s)/gm;\n\nexport class StreamInterceptor extends stream.Transform {\n private chunks: Uint8Array[] = [];\n\n public output() {\n return Buffer.concat(this.chunks).toString().replace(tscPrefixRegex, '');\n }\n\n _transform(\n chunk: Uint8Array,\n _encoding: BufferEncoding,\n callback: stream.TransformCallback,\n ) {\n this.chunks.push(chunk);\n\n callback(null, chunk);\n }\n}\n\nconst lintConcurrently = async ({ tscOutputStream, ...input }: Input) => {\n const [eslint, prettier, tscOk] = await Promise.all([\n runESLintInWorkerThread(input),\n runPrettierInWorkerThread(input),\n runTscInNewProcess({ ...input, tscOutputStream }),\n ]);\n\n return { eslint, prettier, tscOk };\n};\n\n/**\n * Run linting tools `--serial`ly for resource-constrained environments.\n *\n * Note that we still run ESLint and Prettier in worker threads as a\n * counterintuitive optimisation. Memory can be more readily freed on worker\n * thread exit, which isn't as easy with a monolithic main thread.\n */\nconst lintSerially = async ({ tscOutputStream, ...input }: Input) => {\n const eslint = await runESLintInWorkerThread(input);\n const prettier = await runPrettierInWorkerThread(input);\n const tscOk = await runTscInNewProcess({ ...input, tscOutputStream });\n\n return { eslint, prettier, tscOk };\n};\n\nconst lintSeriallyWithoutWorkerThreads = async (input: Input) => {\n const eslint = await runESLintInCurrentThread(input);\n const prettier = await runPrettierInCurrentThread(input);\n const tscOk = await runTscInNewProcess(input);\n\n return { eslint, prettier, tscOk };\n};\n\nconst selectLintFunction = (input: Input) => {\n if (!input.workerThreads) {\n return lintSeriallyWithoutWorkerThreads;\n }\n\n // `--debug` implies `--serial`.\n const isSerial = input.debug || input.serial;\n\n return isSerial ? lintSerially : lintConcurrently;\n};\n\nexport const externalLint = async (input: Input) => {\n const lint = selectLintFunction(input);\n\n const tscOutputStream = new StreamInterceptor();\n tscOutputStream.pipe(input.tscOutputStream ?? process.stdout);\n\n const { eslint, prettier, tscOk } = await lint({ ...input, tscOutputStream });\n\n try {\n await throwOnTimeout(\n createAnnotations(eslint, prettier, tscOk, tscOutputStream),\n { s: 30 },\n );\n } catch (err) {\n log.warn('Failed to annotate lint results.');\n log.subtle(inspect(err));\n }\n\n if (!eslint.ok || !prettier.ok || !tscOk) {\n const tools = [\n ...(eslint.ok ? [] : ['ESLint']),\n ...(prettier.ok ? [] : ['Prettier']),\n ...(tscOk ? [] : ['tsc']),\n ];\n\n log.newline();\n log.err(`${tools.join(', ')} found issues that require triage.`);\n\n process.exitCode = 1;\n }\n\n await autofix({\n debug: input.debug,\n eslint: eslint.fixable,\n prettier: !prettier.ok,\n });\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,kBAAwB;AAExB,qBAAoB;AACpB,kBAA+B;AAE/B,sBAAkC;AAClC,qBAAwB;AACxB,oBAAkE;AAClE,sBAGO;AACP,iBAAmC;AAGnC,MAAM,iBAAiB;AAEhB,MAAM,0BAA0B,cAAAA,QAAO,UAAU;AAAA,EAAjD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