skuba 0.0.0-master-20231121000709 → 0.0.0-master-20240206001217
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/README.md +3 -3
- package/jest/transform.test.ts +3 -1
- package/lib/api/jest/index.d.ts +1 -1
- package/lib/api/jest/index.js.map +2 -2
- package/lib/cli/adapter/prettier.d.ts +1 -1
- package/lib/cli/adapter/prettier.js +11 -10
- package/lib/cli/adapter/prettier.js.map +2 -2
- package/lib/cli/build/index.js +0 -2
- package/lib/cli/build/index.js.map +2 -2
- package/lib/cli/buildPackage.js +0 -2
- package/lib/cli/buildPackage.js.map +2 -2
- package/lib/cli/configure/analyseConfiguration.d.ts +2 -0
- package/lib/cli/configure/analyseConfiguration.js.map +2 -2
- package/lib/cli/configure/getEntryPoint.js +1 -1
- package/lib/cli/configure/getEntryPoint.js.map +2 -2
- package/lib/cli/configure/getProjectType.js +1 -1
- package/lib/cli/configure/getProjectType.js.map +2 -2
- package/lib/cli/configure/index.js +11 -8
- package/lib/cli/configure/index.js.map +2 -2
- package/lib/cli/configure/modules/index.js +0 -2
- package/lib/cli/configure/modules/index.js.map +2 -2
- package/lib/cli/configure/modules/package.d.ts +1 -1
- package/lib/cli/configure/modules/package.js +2 -1
- package/lib/cli/configure/modules/package.js.map +2 -2
- package/lib/cli/configure/patchRenovateConfig.d.ts +2 -1
- package/lib/cli/configure/patchRenovateConfig.js +23 -10
- package/lib/cli/configure/patchRenovateConfig.js.map +2 -2
- package/lib/cli/configure/types.d.ts +2 -0
- package/lib/cli/configure/types.js.map +1 -1
- package/lib/cli/configure/upgrade/index.d.ts +15 -0
- package/lib/cli/configure/upgrade/index.js +130 -0
- package/lib/cli/configure/upgrade/index.js.map +7 -0
- package/lib/cli/configure/{addEmptyExports.d.ts → upgrade/patches/7.3.1/addEmptyExports.d.ts} +2 -2
- package/lib/cli/configure/{addEmptyExports.js → upgrade/patches/7.3.1/addEmptyExports.js} +15 -11
- package/lib/cli/configure/upgrade/patches/7.3.1/addEmptyExports.js.map +7 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/index.d.ts +2 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/index.js +55 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/index.js.map +7 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/moveNpmrcOutOfGitignoreManagedSection.d.ts +2 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/moveNpmrcOutOfGitignoreManagedSection.js +94 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/moveNpmrcOutOfGitignoreManagedSection.js.map +7 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/patchDockerfile.d.ts +2 -0
- package/lib/cli/configure/{patchDockerfile.js → upgrade/patches/7.3.1/patchDockerfile.js} +18 -12
- package/lib/cli/configure/upgrade/patches/7.3.1/patchDockerfile.js.map +7 -0
- package/lib/cli/configure/upgrade/patches/7.3.1/patchServerListener.d.ts +2 -0
- package/lib/cli/configure/{patchServerListener.js → upgrade/patches/7.3.1/patchServerListener.js} +18 -14
- package/lib/cli/configure/upgrade/patches/7.3.1/patchServerListener.js.map +7 -0
- package/lib/cli/format.js +7 -14
- package/lib/cli/format.js.map +2 -2
- package/lib/cli/init/getConfig.d.ts +4 -2
- package/lib/cli/init/getConfig.js +53 -26
- package/lib/cli/init/getConfig.js.map +2 -2
- package/lib/cli/init/git.d.ts +2 -1
- package/lib/cli/init/git.js +2 -9
- package/lib/cli/init/git.js.map +2 -2
- package/lib/cli/init/index.d.ts +1 -1
- package/lib/cli/init/index.js +19 -9
- package/lib/cli/init/index.js.map +2 -2
- package/lib/cli/init/prompts.d.ts +26 -3
- package/lib/cli/init/prompts.js +10 -2
- package/lib/cli/init/prompts.js.map +2 -2
- package/lib/cli/init/types.d.ts +21 -0
- package/lib/cli/init/types.js +5 -1
- package/lib/cli/init/types.js.map +2 -2
- package/lib/cli/init/writePackageJson.d.ts +6 -0
- package/lib/cli/init/writePackageJson.js.map +2 -2
- package/lib/cli/lint/annotate/buildkite/index.d.ts +2 -1
- package/lib/cli/lint/annotate/buildkite/index.js +5 -3
- package/lib/cli/lint/annotate/buildkite/index.js.map +2 -2
- package/lib/cli/lint/annotate/buildkite/internal.d.ts +2 -0
- package/lib/cli/lint/annotate/buildkite/internal.js +45 -0
- package/lib/cli/lint/annotate/buildkite/internal.js.map +7 -0
- package/lib/cli/lint/annotate/github/index.d.ts +2 -1
- package/lib/cli/lint/annotate/github/index.js +4 -2
- package/lib/cli/lint/annotate/github/index.js.map +2 -2
- package/lib/cli/lint/annotate/github/internal.d.ts +3 -0
- package/lib/cli/lint/annotate/github/internal.js +36 -0
- package/lib/cli/lint/annotate/github/internal.js.map +7 -0
- package/lib/cli/lint/annotate/index.d.ts +4 -3
- package/lib/cli/lint/annotate/index.js +9 -3
- package/lib/cli/lint/annotate/index.js.map +2 -2
- package/lib/cli/lint/autofix.d.ts +3 -1
- package/lib/cli/lint/autofix.js +36 -59
- package/lib/cli/lint/autofix.js.map +3 -3
- package/lib/cli/lint/external.d.ts +6 -1
- package/lib/cli/lint/external.js +6 -29
- package/lib/cli/lint/external.js.map +2 -2
- package/lib/cli/lint/index.d.ts +2 -1
- package/lib/cli/lint/index.js +46 -14
- package/lib/cli/lint/index.js.map +2 -2
- package/lib/cli/lint/internal.d.ts +12 -1
- package/lib/cli/lint/internal.js +55 -19
- package/lib/cli/lint/internal.js.map +3 -3
- package/lib/cli/lint/internalLints/deleteFiles.d.ts +3 -0
- package/lib/cli/lint/internalLints/deleteFiles.js +102 -0
- package/lib/cli/lint/internalLints/deleteFiles.js.map +7 -0
- package/lib/cli/lint/internalLints/noSkubaTemplateJs.d.ts +3 -0
- package/lib/cli/lint/internalLints/noSkubaTemplateJs.js +75 -0
- package/lib/cli/lint/internalLints/noSkubaTemplateJs.js.map +7 -0
- package/lib/cli/lint/internalLints/refreshConfigFiles.d.ts +11 -0
- package/lib/cli/lint/internalLints/refreshConfigFiles.js +147 -0
- package/lib/cli/lint/internalLints/refreshConfigFiles.js.map +7 -0
- package/lib/cli/test/index.js +0 -2
- package/lib/cli/test/index.js.map +2 -2
- package/lib/skuba.d.ts +1 -1
- package/lib/skuba.js.map +1 -1
- package/lib/utils/exec.d.ts +2 -1
- package/lib/utils/exec.js +1 -0
- package/lib/utils/exec.js.map +2 -2
- package/lib/utils/logging.d.ts +2 -0
- package/lib/utils/logging.js +1 -0
- package/lib/utils/logging.js.map +2 -2
- package/lib/utils/logo.js +6 -10
- package/lib/utils/logo.js.map +3 -3
- package/lib/utils/manifest.d.ts +1 -1
- package/lib/utils/manifest.js +1 -1
- package/lib/utils/manifest.js.map +2 -2
- package/lib/utils/npmrc.d.ts +1 -0
- package/lib/utils/npmrc.js +29 -0
- package/lib/utils/npmrc.js.map +7 -0
- package/lib/utils/packageManager.d.ts +24 -0
- package/lib/utils/packageManager.js +97 -0
- package/lib/utils/packageManager.js.map +7 -0
- package/lib/utils/template.d.ts +3 -0
- package/lib/utils/template.js +2 -0
- package/lib/utils/template.js.map +2 -2
- package/lib/utils/worker.d.ts +1 -0
- package/lib/wrapper/http.d.ts +1 -0
- package/package.json +39 -36
- package/template/base/_.dockerignore +0 -1
- package/template/base/_.eslintignore +1 -0
- package/template/base/_.gitignore +1 -1
- package/template/base/_.npmrc +8 -0
- package/template/express-rest-api/.buildkite/pipeline.yml +13 -10
- package/template/express-rest-api/.gantry/dev.yml +3 -0
- package/template/express-rest-api/Dockerfile +6 -12
- package/template/express-rest-api/Dockerfile.dev-deps +6 -5
- package/template/express-rest-api/README.md +6 -6
- package/template/express-rest-api/docker-compose.yml +0 -10
- package/template/express-rest-api/gantry.apply.yml +5 -0
- package/template/express-rest-api/gantry.build.yml +1 -2
- package/template/express-rest-api/package.json +2 -2
- package/template/express-rest-api/skuba.template.js +1 -0
- package/template/greeter/.buildkite/pipeline.yml +12 -9
- package/template/greeter/Dockerfile +6 -5
- package/template/greeter/README.md +6 -6
- package/template/greeter/docker-compose.yml +0 -10
- package/template/greeter/package.json +1 -1
- package/template/greeter/skuba.template.js +1 -0
- package/template/koa-rest-api/.buildkite/pipeline.yml +13 -10
- package/template/koa-rest-api/.gantry/dev.yml +3 -0
- package/template/koa-rest-api/.nvmrc +1 -1
- package/template/koa-rest-api/Dockerfile +6 -12
- package/template/koa-rest-api/Dockerfile.dev-deps +6 -5
- package/template/koa-rest-api/README.md +6 -6
- package/template/koa-rest-api/docker-compose.yml +0 -10
- package/template/koa-rest-api/gantry.apply.yml +5 -0
- package/template/koa-rest-api/gantry.build.yml +1 -2
- package/template/koa-rest-api/package.json +8 -6
- package/template/koa-rest-api/skuba.template.js +1 -0
- package/template/koa-rest-api/src/framework/validation.test.ts +48 -15
- package/template/koa-rest-api/src/framework/validation.ts +31 -8
- package/template/koa-rest-api/src/testing/types.ts +16 -4
- package/template/lambda-sqs-worker/.buildkite/pipeline.yml +21 -15
- package/template/lambda-sqs-worker/Dockerfile +6 -6
- package/template/lambda-sqs-worker/README.md +8 -8
- package/template/lambda-sqs-worker/_.npmrc +12 -0
- package/template/lambda-sqs-worker/docker-compose.yml +0 -15
- package/template/lambda-sqs-worker/package.json +3 -4
- package/template/lambda-sqs-worker/serverless.yml +4 -1
- package/template/lambda-sqs-worker/skuba.template.js +1 -0
- package/template/lambda-sqs-worker/src/hooks.ts +1 -2
- package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +42 -18
- package/template/lambda-sqs-worker-cdk/.nvmrc +1 -1
- package/template/lambda-sqs-worker-cdk/Dockerfile +9 -7
- package/template/lambda-sqs-worker-cdk/cdk.json +12 -6
- package/template/lambda-sqs-worker-cdk/docker-compose.yml +0 -15
- package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +1587 -225
- package/template/lambda-sqs-worker-cdk/infra/appStack.test.ts +23 -3
- package/template/lambda-sqs-worker-cdk/infra/appStack.ts +127 -14
- package/template/lambda-sqs-worker-cdk/package.json +5 -3
- package/template/lambda-sqs-worker-cdk/shared/context-types.ts +1 -0
- package/template/lambda-sqs-worker-cdk/skuba.template.js +1 -0
- package/template/lambda-sqs-worker-cdk/src/app.ts +14 -1
- package/template/lambda-sqs-worker-cdk/src/postHook.ts +154 -0
- package/template/lambda-sqs-worker-cdk/src/preHook.ts +95 -0
- package/template/oss-npm-package/.github/workflows/release.yml +10 -7
- package/template/oss-npm-package/.github/workflows/validate.yml +10 -7
- package/template/oss-npm-package/.releaserc +16 -0
- package/template/oss-npm-package/README.md +17 -17
- package/template/oss-npm-package/_package.json +3 -2
- package/template/oss-npm-package/skuba.template.js +1 -0
- package/template/private-npm-package/.releaserc +16 -0
- package/template/private-npm-package/README.md +16 -16
- package/template/private-npm-package/_package.json +3 -3
- package/template/private-npm-package/skuba.template.js +1 -0
- package/lib/cli/configure/addEmptyExports.js.map +0 -7
- package/lib/cli/configure/modules/tsconfig.d.ts +0 -2
- package/lib/cli/configure/modules/tsconfig.js +0 -87
- package/lib/cli/configure/modules/tsconfig.js.map +0 -7
- package/lib/cli/configure/patchDockerfile.d.ts +0 -1
- package/lib/cli/configure/patchDockerfile.js.map +0 -7
- package/lib/cli/configure/patchServerListener.d.ts +0 -3
- package/lib/cli/configure/patchServerListener.js.map +0 -7
- package/lib/cli/configure/refreshIgnoreFiles.d.ts +0 -3
- package/lib/cli/configure/refreshIgnoreFiles.js +0 -78
- package/lib/cli/configure/refreshIgnoreFiles.js.map +0 -7
package/lib/cli/lint/autofix.js
CHANGED
|
@@ -28,54 +28,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var autofix_exports = {};
|
|
30
30
|
__export(autofix_exports, {
|
|
31
|
-
|
|
31
|
+
AUTOFIX_IGNORE_FILES_BASE: () => AUTOFIX_IGNORE_FILES_BASE,
|
|
32
|
+
AUTOFIX_IGNORE_FILES_NPMRC: () => AUTOFIX_IGNORE_FILES_NPMRC,
|
|
32
33
|
autofix: () => autofix
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(autofix_exports);
|
|
35
|
-
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_util = require("util");
|
|
37
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
38
37
|
var import_simple_git = __toESM(require("simple-git"));
|
|
39
38
|
var Buildkite = __toESM(require("../../api/buildkite"));
|
|
40
39
|
var Git = __toESM(require("../../api/git"));
|
|
41
40
|
var GitHub = __toESM(require("../../api/github"));
|
|
42
41
|
var import_env = require("../../utils/env");
|
|
43
42
|
var import_logging = require("../../utils/logging");
|
|
43
|
+
var import_npmrc = require("../../utils/npmrc");
|
|
44
44
|
var import_wait = require("../../utils/wait");
|
|
45
45
|
var import_eslint = require("../adapter/eslint");
|
|
46
46
|
var import_prettier = require("../adapter/prettier");
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var import_patchServerListener = require("../configure/patchServerListener");
|
|
50
|
-
var import_refreshIgnoreFiles = require("../configure/refreshIgnoreFiles");
|
|
47
|
+
var import_project = require("../configure/analysis/project");
|
|
48
|
+
var import_internal = require("./internal");
|
|
51
49
|
const RENOVATE_DEFAULT_PREFIX = "renovate";
|
|
52
50
|
const AUTOFIX_COMMIT_MESSAGE = "Run `skuba format`";
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const AUTOFIX_IGNORE_FILES_BASE = [
|
|
52
|
+
{
|
|
53
|
+
path: "Dockerfile-incunabulum",
|
|
54
|
+
state: "added"
|
|
55
|
+
}
|
|
57
56
|
];
|
|
58
|
-
const
|
|
59
|
-
...AUTOFIX_DELETE_FILES,
|
|
60
|
-
...import_addEmptyExports.JEST_SETUP_FILES,
|
|
61
|
-
...import_refreshIgnoreFiles.REFRESHABLE_IGNORE_FILES,
|
|
62
|
-
...import_renovate.RENOVATE_CONFIG_FILENAMES,
|
|
63
|
-
import_patchServerListener.SERVER_LISTENER_FILENAME
|
|
64
|
-
]);
|
|
65
|
-
const AUTOFIX_IGNORE_FILES = [
|
|
57
|
+
const AUTOFIX_IGNORE_FILES_NPMRC = [
|
|
66
58
|
{
|
|
67
59
|
path: ".npmrc",
|
|
68
60
|
state: "added"
|
|
69
61
|
},
|
|
70
62
|
{
|
|
71
|
-
// This file may already exist in version control, but we shouldn't commit
|
|
72
|
-
// further changes as the CI environment may have appended an npm token.
|
|
73
63
|
path: ".npmrc",
|
|
74
64
|
state: "modified"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
path: "Dockerfile-incunabulum",
|
|
78
|
-
state: "added"
|
|
79
65
|
}
|
|
80
66
|
];
|
|
81
67
|
const shouldPush = async ({
|
|
@@ -115,30 +101,16 @@ const shouldPush = async ({
|
|
|
115
101
|
}
|
|
116
102
|
return true;
|
|
117
103
|
};
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(filename) => import_fs_extra.default.promises.rm(import_path.default.join(dir, filename), { force: true })
|
|
123
|
-
)
|
|
124
|
-
);
|
|
125
|
-
const changedFiles = await Git.getChangedFiles({
|
|
126
|
-
dir,
|
|
127
|
-
ignore: AUTOFIX_IGNORE_FILES
|
|
128
|
-
});
|
|
129
|
-
return changedFiles.some(
|
|
130
|
-
(changedFile) => AUTOFIX_CODEGEN_FILES.has(changedFile.path)
|
|
131
|
-
);
|
|
132
|
-
} catch (err) {
|
|
133
|
-
import_logging.log.warn(import_logging.log.bold("Failed to evaluate codegen changes."));
|
|
134
|
-
import_logging.log.subtle((0, import_util.inspect)(err));
|
|
135
|
-
return false;
|
|
104
|
+
const getIgnores = async (dir) => {
|
|
105
|
+
const contents = await (0, import_project.createDestinationFileReader)(dir)(".npmrc");
|
|
106
|
+
if ((0, import_npmrc.hasNpmrcSecret)(contents ?? "")) {
|
|
107
|
+
return [...AUTOFIX_IGNORE_FILES_BASE, ...AUTOFIX_IGNORE_FILES_NPMRC];
|
|
136
108
|
}
|
|
109
|
+
return AUTOFIX_IGNORE_FILES_BASE;
|
|
137
110
|
};
|
|
138
111
|
const autofix = async (params) => {
|
|
139
112
|
const dir = process.cwd();
|
|
140
|
-
|
|
141
|
-
if (!params.eslint && !params.prettier && !codegen) {
|
|
113
|
+
if (!params.eslint && !params.prettier && !params.internal) {
|
|
142
114
|
return;
|
|
143
115
|
}
|
|
144
116
|
let currentBranch;
|
|
@@ -151,23 +123,27 @@ const autofix = async (params) => {
|
|
|
151
123
|
}
|
|
152
124
|
try {
|
|
153
125
|
import_logging.log.newline();
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
await (0,
|
|
126
|
+
import_logging.log.warn(
|
|
127
|
+
`Attempting to autofix issues (${[
|
|
128
|
+
params.eslint ? "ESLint" : void 0,
|
|
129
|
+
params.internal ? "skuba" : void 0,
|
|
130
|
+
"Prettier"
|
|
131
|
+
// Prettier is always run
|
|
132
|
+
].filter((s) => s !== void 0).join(", ")})...`
|
|
133
|
+
);
|
|
134
|
+
const logger = (0, import_logging.createLogger)(params.debug);
|
|
135
|
+
if (params.internal) {
|
|
136
|
+
await (0, import_internal.internalLint)("format");
|
|
137
|
+
}
|
|
138
|
+
if (params.eslint) {
|
|
139
|
+
await (0, import_eslint.runESLint)("format", logger);
|
|
165
140
|
}
|
|
141
|
+
await (0, import_prettier.runPrettier)("format", logger);
|
|
166
142
|
if (process.env.GITHUB_ACTIONS) {
|
|
167
143
|
const ref2 = await Git.commitAllChanges({
|
|
168
144
|
dir,
|
|
169
145
|
message: AUTOFIX_COMMIT_MESSAGE,
|
|
170
|
-
ignore:
|
|
146
|
+
ignore: await getIgnores(dir)
|
|
171
147
|
});
|
|
172
148
|
if (!ref2) {
|
|
173
149
|
return import_logging.log.warn("No autofixes detected.");
|
|
@@ -188,7 +164,7 @@ const autofix = async (params) => {
|
|
|
188
164
|
branch: currentBranch,
|
|
189
165
|
dir,
|
|
190
166
|
messageHeadline: AUTOFIX_COMMIT_MESSAGE,
|
|
191
|
-
ignore:
|
|
167
|
+
ignore: await getIgnores(dir)
|
|
192
168
|
}),
|
|
193
169
|
{ s: 30 }
|
|
194
170
|
);
|
|
@@ -208,7 +184,8 @@ const autofix = async (params) => {
|
|
|
208
184
|
};
|
|
209
185
|
// Annotate the CommonJS export names for ESM import in node:
|
|
210
186
|
0 && (module.exports = {
|
|
211
|
-
|
|
187
|
+
AUTOFIX_IGNORE_FILES_BASE,
|
|
188
|
+
AUTOFIX_IGNORE_FILES_NPMRC,
|
|
212
189
|
autofix
|
|
213
190
|
});
|
|
214
191
|
//# sourceMappingURL=autofix.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/cli/lint/autofix.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { inspect } from 'util';\n\nimport simpleGit from 'simple-git';\n\nimport * as Buildkite from '../../api/buildkite';\nimport * as Git from '../../api/git';\nimport * as GitHub from '../../api/github';\nimport { isCiEnv } from '../../utils/env';\nimport { createLogger, log } from '../../utils/logging';\nimport { hasNpmrcSecret } from '../../utils/npmrc';\nimport { throwOnTimeout } from '../../utils/wait';\nimport { runESLint } from '../adapter/eslint';\nimport { runPrettier } from '../adapter/prettier';\nimport { createDestinationFileReader } from '../configure/analysis/project';\n\nimport { internalLint } from './internal';\nimport type { Input } from './types';\n\nconst RENOVATE_DEFAULT_PREFIX = 'renovate';\n\nconst AUTOFIX_COMMIT_MESSAGE = 'Run `skuba format`';\n\nexport const AUTOFIX_IGNORE_FILES_BASE: Git.ChangedFile[] = [\n {\n path: 'Dockerfile-incunabulum',\n state: 'added',\n },\n];\n\nexport const AUTOFIX_IGNORE_FILES_NPMRC: Git.ChangedFile[] = [\n {\n path: '.npmrc',\n state: 'added',\n },\n {\n path: '.npmrc',\n state: 'modified',\n },\n];\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 if (currentBranch?.startsWith(RENOVATE_DEFAULT_PREFIX)) {\n try {\n await GitHub.getPullRequestNumber();\n } catch (error) {\n const warning =\n 'An autofix is available, but it was not pushed because an open pull request for this Renovate branch could not be found. If a pull request has since been created, retry the lint step to push the fix.';\n log.warn(warning);\n try {\n await Buildkite.annotate(Buildkite.md.terminal(warning));\n } catch {}\n\n return false;\n }\n }\n\n let headCommitMessage;\n try {\n headCommitMessage = await Git.getHeadCommitMessage({ dir });\n } catch {}\n\n if (headCommitMessage?.startsWith(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\nconst getIgnores = async (dir: string): Promise<Git.ChangedFile[]> => {\n const contents = await createDestinationFileReader(dir)('.npmrc');\n\n // If an .npmrc has secrets, we need to ignore it\n if (hasNpmrcSecret(contents ?? '')) {\n return [...AUTOFIX_IGNORE_FILES_BASE, ...AUTOFIX_IGNORE_FILES_NPMRC];\n }\n\n return AUTOFIX_IGNORE_FILES_BASE;\n};\n\ninterface AutofixParameters {\n debug: Input['debug'];\n\n eslint: boolean;\n prettier: boolean;\n internal: boolean;\n}\n\nexport const autofix = async (params: AutofixParameters): Promise<void> => {\n const dir = process.cwd();\n\n if (!params.eslint && !params.prettier && !params.internal) {\n return;\n }\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\n log.warn(\n `Attempting to autofix issues (${[\n params.eslint ? 'ESLint' : undefined,\n params.internal ? 'skuba' : undefined,\n 'Prettier', // Prettier is always run\n ]\n .filter((s) => s !== undefined)\n .join(', ')})...`,\n );\n\n const logger = createLogger(params.debug);\n\n if (params.internal) {\n await internalLint('format');\n }\n\n if (params.eslint) {\n await runESLint('format', logger);\n }\n\n // Unconditionally re-run Prettier; reaching here means we have pre-existing\n // format violations or may have created new ones through ESLint/internal 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 ignore: await getIgnores(dir),\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 branch: currentBranch,\n dir,\n messageHeadline: AUTOFIX_COMMIT_MESSAGE,\n\n ignore: await getIgnores(dir),\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;AAAA;AAAA,kBAAwB;AAExB,wBAAsB;AAEtB,gBAA2B;AAC3B,UAAqB;AACrB,aAAwB;AACxB,iBAAwB;AACxB,qBAAkC;AAClC,mBAA+B;AAC/B,kBAA+B;AAC/B,oBAA0B;AAC1B,sBAA4B;AAC5B,qBAA4C;AAE5C,sBAA6B;AAG7B,MAAM,0BAA0B;AAEhC,MAAM,yBAAyB;AAExB,MAAM,4BAA+C;AAAA,EAC1D;AAAA,IACE,MAAM;AAAA,IACN,OAAO;AAAA,EACT;AACF;AAEO,MAAM,6BAAgD;AAAA,EAC3D;AAAA,IACE,MAAM;AAAA,IACN,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,OAAO;AAAA,EACT;AACF;AAEA,MAAM,aAAa,OAAO;AAAA,EACxB;AAAA,EACA;AACF,MAGM;AACJ,MAAI,KAAC,oBAAQ,GAAG;AAId,WAAO;AAAA,EACT;AAEA,QAAM,2BACJ,iBACA,CAAC,QAAQ,IAAI,mCAAmC,UAAU,MAAM,EAAE;AAAA,IAChE;AAAA,EACF;AAEF,QAAM,0BAA0B,QAAQ,IAAI,yBAAyB;AAErE,MAAI,4BAA4B,yBAAyB;AAGvD,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,WAAW,uBAAuB,GAAG;AACtD,QAAI;AACF,YAAM,OAAO,qBAAqB;AAAA,IACpC,SAAS,OAAO;AACd,YAAM,UACJ;AACF,yBAAI,KAAK,OAAO;AAChB,UAAI;AACF,cAAM,UAAU,SAAS,UAAU,GAAG,SAAS,OAAO,CAAC;AAAA,MACzD,QAAQ;AAAA,MAAC;AAET,aAAO;AAAA,IACT;AAAA,EACF;A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AAAA,QACA,SAAS;AAAA,QAET,QAAQ,MAAM,WAAW,GAAG;AAAA,MAC9B,CAAC;AAED,UAAI,CAACA,MAAK;AACR,eAAO,mBAAI,KAAK,wBAAwB;AAAA,MAC1C;AAEA,gBAAM,gCAAe,kBAAAC,SAAU,EAAE,KAAK,GAAG,EAAE,GAAG,GAAG,CAAC;AAClD,yBAAI,KAAK,qBAAqBD,IAAG,GAAG;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,QAAQ;AAAA,QACR;AAAA,QACA,iBAAiB;AAAA,QAEjB,QAAQ,MAAM,WAAW,GAAG;AAAA,MAC9B,CAAC;AAAA,MACD,EAAE,GAAG,GAAG;AAAA,IACV;AAEA,QAAI,CAAC,KAAK;AACR,aAAO,mBAAI,KAAK,wBAAwB;AAAA,IAC1C;AAEA,uBAAI,KAAK,qBAAqB,GAAG,GAAG;AAAA,EACtC,SAAS,KAAK;AACZ,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
7
|
}
|
|
@@ -7,4 +7,9 @@ export declare class StreamInterceptor extends stream.Transform {
|
|
|
7
7
|
output(): string;
|
|
8
8
|
_transform(chunk: Uint8Array, _encoding: BufferEncoding, callback: stream.TransformCallback): void;
|
|
9
9
|
}
|
|
10
|
-
export declare const externalLint: (input: Input) => Promise<
|
|
10
|
+
export declare const externalLint: (input: Input) => Promise<{
|
|
11
|
+
eslint: import("../adapter/eslint").ESLintOutput;
|
|
12
|
+
prettier: import("../adapter/prettier").PrettierOutput;
|
|
13
|
+
tscOk: boolean;
|
|
14
|
+
tscOutputStream: StreamInterceptor;
|
|
15
|
+
}>;
|
package/lib/cli/lint/external.js
CHANGED
|
@@ -33,11 +33,6 @@ __export(external_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(external_exports);
|
|
35
35
|
var import_stream = __toESM(require("stream"));
|
|
36
|
-
var import_util = require("util");
|
|
37
|
-
var import_logging = require("../../utils/logging");
|
|
38
|
-
var import_wait = require("../../utils/wait");
|
|
39
|
-
var import_annotate = require("./annotate");
|
|
40
|
-
var import_autofix = require("./autofix");
|
|
41
36
|
var import_eslint = require("./eslint");
|
|
42
37
|
var import_prettier = require("./prettier");
|
|
43
38
|
var import_tsc = require("./tsc");
|
|
@@ -84,30 +79,12 @@ const externalLint = async (input) => {
|
|
|
84
79
|
const tscOutputStream = new StreamInterceptor();
|
|
85
80
|
tscOutputStream.pipe(input.tscOutputStream ?? process.stdout);
|
|
86
81
|
const { eslint, prettier, tscOk } = await lint({ ...input, tscOutputStream });
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
import_logging.log.warn("Failed to annotate lint results.");
|
|
94
|
-
import_logging.log.subtle((0, import_util.inspect)(err));
|
|
95
|
-
}
|
|
96
|
-
if (!eslint.ok || !prettier.ok || !tscOk) {
|
|
97
|
-
const tools = [
|
|
98
|
-
...eslint.ok ? [] : ["ESLint"],
|
|
99
|
-
...prettier.ok ? [] : ["Prettier"],
|
|
100
|
-
...tscOk ? [] : ["tsc"]
|
|
101
|
-
];
|
|
102
|
-
import_logging.log.newline();
|
|
103
|
-
import_logging.log.err(`${tools.join(", ")} found issues that require triage.`);
|
|
104
|
-
process.exitCode = 1;
|
|
105
|
-
}
|
|
106
|
-
await (0, import_autofix.autofix)({
|
|
107
|
-
debug: input.debug,
|
|
108
|
-
eslint: eslint.fixable,
|
|
109
|
-
prettier: !prettier.ok
|
|
110
|
-
});
|
|
82
|
+
return {
|
|
83
|
+
eslint,
|
|
84
|
+
prettier,
|
|
85
|
+
tscOk,
|
|
86
|
+
tscOutputStream
|
|
87
|
+
};
|
|
111
88
|
};
|
|
112
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
113
90
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/cli/lint/external.ts"],
|
|
4
|
-
"sourcesContent": ["import stream from 'stream';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;
|
|
4
|
+
"sourcesContent": ["import stream from 'stream';\n\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 return {\n eslint,\n prettier,\n tscOk,\n tscOutputStream,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AAEnB,oBAAkE;AAClE,sBAGO;AACP,iBAAmC;AAGnC,MAAM,iBAAiB;AAEhB,MAAM,0BAA0B,cAAAA,QAAO,UAAU;AAAA,EAC9C,SAAuB,CAAC;AAAA,EAEzB,SAAS;AACd,WAAO,OAAO,OAAO,KAAK,MAAM,EAAE,SAAS,EAAE,QAAQ,gBAAgB,EAAE;AAAA,EACzE;AAAA,EAEA,WACE,OACA,WACA,UACA;AACA,SAAK,OAAO,KAAK,KAAK;AAEtB,aAAS,MAAM,KAAK;AAAA,EACtB;AACF;AAEA,MAAM,mBAAmB,OAAO,EAAE,iBAAiB,GAAG,MAAM,MAAa;AACvE,QAAM,CAAC,QAAQ,UAAU,KAAK,IAAI,MAAM,QAAQ,IAAI;AAAA,QAClD,uCAAwB,KAAK;AAAA,QAC7B,2CAA0B,KAAK;AAAA,QAC/B,+BAAmB,EAAE,GAAG,OAAO,gBAAgB,CAAC;AAAA,EAClD,CAAC;AAED,SAAO,EAAE,QAAQ,UAAU,MAAM;AACnC;AASA,MAAM,eAAe,OAAO,EAAE,iBAAiB,GAAG,MAAM,MAAa;AACnE,QAAM,SAAS,UAAM,uCAAwB,KAAK;AAClD,QAAM,WAAW,UAAM,2CAA0B,KAAK;AACtD,QAAM,QAAQ,UAAM,+BAAmB,EAAE,GAAG,OAAO,gBAAgB,CAAC;AAEpE,SAAO,EAAE,QAAQ,UAAU,MAAM;AACnC;AAEA,MAAM,mCAAmC,OAAO,UAAiB;AAC/D,QAAM,SAAS,UAAM,wCAAyB,KAAK;AACnD,QAAM,WAAW,UAAM,4CAA2B,KAAK;AACvD,QAAM,QAAQ,UAAM,+BAAmB,KAAK;AAE5C,SAAO,EAAE,QAAQ,UAAU,MAAM;AACnC;AAEA,MAAM,qBAAqB,CAAC,UAAiB;AAC3C,MAAI,CAAC,MAAM,eAAe;AACxB,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,MAAM,SAAS,MAAM;AAEtC,SAAO,WAAW,eAAe;AACnC;AAEO,MAAM,eAAe,OAAO,UAAiB;AAClD,QAAM,OAAO,mBAAmB,KAAK;AAErC,QAAM,kBAAkB,IAAI,kBAAkB;AAC9C,kBAAgB,KAAK,MAAM,mBAAmB,QAAQ,MAAM;AAE5D,QAAM,EAAE,QAAQ,UAAU,MAAM,IAAI,MAAM,KAAK,EAAE,GAAG,OAAO,gBAAgB,CAAC;AAE5E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["stream"]
|
|
7
7
|
}
|
package/lib/cli/lint/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { Writable } from 'stream';
|
|
2
|
-
export declare const lint: (args?: string[],
|
|
3
|
+
export declare const lint: (args?: string[], tscWriteable?: Writable | undefined, workerThreads?: boolean) => Promise<void>;
|
package/lib/cli/lint/index.js
CHANGED
|
@@ -21,28 +21,60 @@ __export(lint_exports, {
|
|
|
21
21
|
lint: () => lint
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(lint_exports);
|
|
24
|
+
var import_util = require("util");
|
|
24
25
|
var import_args = require("../../utils/args");
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
26
|
+
var import_logging = require("../../utils/logging");
|
|
27
|
+
var import_packageManager = require("../../utils/packageManager");
|
|
28
|
+
var import_wait = require("../../utils/wait");
|
|
29
|
+
var import_annotate = require("./annotate");
|
|
30
|
+
var import_autofix = require("./autofix");
|
|
29
31
|
var import_external = require("./external");
|
|
30
32
|
var import_internal = require("./internal");
|
|
31
|
-
const lint = async (args = process.argv.slice(2),
|
|
32
|
-
await Promise.all([
|
|
33
|
-
(0, import_addEmptyExports.tryAddEmptyExports)(),
|
|
34
|
-
(0, import_patchRenovateConfig.tryPatchRenovateConfig)(),
|
|
35
|
-
(0, import_patchServerListener.tryPatchServerListener)(),
|
|
36
|
-
(0, import_refreshIgnoreFiles.tryRefreshIgnoreFiles)()
|
|
37
|
-
]);
|
|
33
|
+
const lint = async (args = process.argv.slice(2), tscWriteable = void 0, workerThreads = true) => {
|
|
38
34
|
const opts = {
|
|
39
35
|
debug: (0, import_args.hasDebugFlag)(args),
|
|
40
36
|
serial: (0, import_args.hasSerialFlag)(args),
|
|
41
|
-
tscOutputStream,
|
|
37
|
+
tscOutputStream: tscWriteable,
|
|
42
38
|
workerThreads
|
|
43
39
|
};
|
|
44
|
-
await (0, import_external.externalLint)(opts);
|
|
45
|
-
await (0, import_internal.internalLint)();
|
|
40
|
+
const { eslint, prettier, tscOk, tscOutputStream } = await (0, import_external.externalLint)(opts);
|
|
41
|
+
const internal = await (0, import_internal.internalLint)("lint", opts);
|
|
42
|
+
try {
|
|
43
|
+
await (0, import_wait.throwOnTimeout)(
|
|
44
|
+
(0, import_annotate.createAnnotations)(internal, eslint, prettier, tscOk, tscOutputStream),
|
|
45
|
+
{ s: 30 }
|
|
46
|
+
);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
import_logging.log.warn("Failed to annotate lint results.");
|
|
49
|
+
import_logging.log.subtle((0, import_util.inspect)(err));
|
|
50
|
+
}
|
|
51
|
+
if (!internal.ok || !eslint.ok || !prettier.ok || !tscOk) {
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
const tools = [
|
|
54
|
+
...internal.ok ? [] : ["skuba"],
|
|
55
|
+
...eslint.ok ? [] : ["ESLint"],
|
|
56
|
+
...prettier.ok ? [] : ["Prettier"],
|
|
57
|
+
...tscOk ? [] : ["tsc"]
|
|
58
|
+
];
|
|
59
|
+
import_logging.log.err(`${tools.join(", ")} found issues that require triage.`);
|
|
60
|
+
if (internal.fixable || eslint.fixable || !prettier.ok) {
|
|
61
|
+
const packageManager = await (0, import_packageManager.detectPackageManager)();
|
|
62
|
+
import_logging.log.newline();
|
|
63
|
+
import_logging.log.warn(
|
|
64
|
+
`Try running ${import_logging.log.bold(
|
|
65
|
+
packageManager.exec,
|
|
66
|
+
"skuba",
|
|
67
|
+
"format"
|
|
68
|
+
)} to fix them.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
await (0, import_autofix.autofix)({
|
|
73
|
+
debug: opts.debug,
|
|
74
|
+
eslint: eslint.fixable,
|
|
75
|
+
prettier: !prettier.ok,
|
|
76
|
+
internal: internal.fixable
|
|
77
|
+
});
|
|
46
78
|
};
|
|
47
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
48
80
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/cli/lint/index.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Writable } from 'stream';\n\nimport { hasDebugFlag, hasSerialFlag } from '../../utils/args';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type { Writable } from 'stream';\nimport { inspect } from 'util';\n\nimport { hasDebugFlag, hasSerialFlag } from '../../utils/args';\nimport { log } from '../../utils/logging';\nimport { detectPackageManager } from '../../utils/packageManager';\nimport { throwOnTimeout } from '../../utils/wait';\n\nimport { createAnnotations } from './annotate';\nimport { autofix } from './autofix';\nimport { externalLint } from './external';\nimport { internalLint } from './internal';\nimport type { Input } from './types';\n\nexport const lint = async (\n args = process.argv.slice(2),\n tscWriteable: Writable | undefined = undefined,\n workerThreads = true,\n) => {\n const opts: Input = {\n debug: hasDebugFlag(args),\n serial: hasSerialFlag(args),\n tscOutputStream: tscWriteable,\n workerThreads,\n };\n\n const { eslint, prettier, tscOk, tscOutputStream } = await externalLint(opts);\n const internal = await internalLint('lint', opts);\n\n try {\n await throwOnTimeout(\n createAnnotations(internal, 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 (!internal.ok || !eslint.ok || !prettier.ok || !tscOk) {\n process.exitCode = 1;\n\n const tools = [\n ...(internal.ok ? [] : ['skuba']),\n ...(eslint.ok ? [] : ['ESLint']),\n ...(prettier.ok ? [] : ['Prettier']),\n ...(tscOk ? [] : ['tsc']),\n ];\n\n log.err(`${tools.join(', ')} found issues that require triage.`);\n\n if (internal.fixable || eslint.fixable || !prettier.ok) {\n const packageManager = await detectPackageManager();\n log.newline();\n log.warn(\n `Try running ${log.bold(\n packageManager.exec,\n 'skuba',\n 'format',\n )} to fix them.`,\n );\n }\n }\n\n await autofix({\n debug: opts.debug,\n eslint: eslint.fixable,\n prettier: !prettier.ok,\n internal: internal.fixable,\n });\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,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AAA,UACjB,eAAe;AAAA,UACf;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,YAAM,wBAAQ;AAAA,IACZ,OAAO,KAAK;AAAA,IACZ,QAAQ,OAAO;AAAA,IACf,UAAU,CAAC,SAAS;AAAA,IACpB,UAAU,SAAS;AAAA,EACrB,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Input } from './types';
|
|
2
|
+
export type InternalLintResult = {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
fixable: boolean;
|
|
5
|
+
annotations?: Array<{
|
|
6
|
+
start_line?: number;
|
|
7
|
+
end_line?: number;
|
|
8
|
+
path: string;
|
|
9
|
+
message: string;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
export declare const internalLint: (mode: 'format' | 'lint', input?: Input) => Promise<InternalLintResult>;
|
package/lib/cli/lint/internal.js
CHANGED
|
@@ -31,32 +31,68 @@ __export(internal_exports, {
|
|
|
31
31
|
internalLint: () => internalLint
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(internal_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_util = require("util");
|
|
35
35
|
var import_chalk = __toESM(require("chalk"));
|
|
36
|
-
var import_fs_extra = require("fs-extra");
|
|
37
36
|
var import_logging = require("../../utils/logging");
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
var import_upgrade = require("../configure/upgrade");
|
|
38
|
+
var import_deleteFiles = require("./internalLints/deleteFiles");
|
|
39
|
+
var import_noSkubaTemplateJs = require("./internalLints/noSkubaTemplateJs");
|
|
40
|
+
var import_refreshConfigFiles = require("./internalLints/refreshConfigFiles");
|
|
41
|
+
const lints = [
|
|
42
|
+
// Run upgradeSkuba before refreshConfigFiles for npmrc handling
|
|
43
|
+
[import_upgrade.upgradeSkuba],
|
|
44
|
+
[import_deleteFiles.deleteFilesLint, import_noSkubaTemplateJs.noSkubaTemplateJs, import_refreshConfigFiles.tryRefreshConfigFiles]
|
|
45
|
+
];
|
|
46
|
+
const lintSerially = async (mode, logger) => {
|
|
47
|
+
const results = [];
|
|
48
|
+
for (const lintGroup of lints) {
|
|
49
|
+
for (const lint of lintGroup) {
|
|
50
|
+
results.push(await lint(mode, logger));
|
|
51
|
+
}
|
|
43
52
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"yarn skuba configure"
|
|
52
|
-
)}. ${import_chalk.default.dim("no-skuba-template-js")}`
|
|
53
|
+
return results;
|
|
54
|
+
};
|
|
55
|
+
const lintConcurrently = async (mode, logger) => {
|
|
56
|
+
const results = [];
|
|
57
|
+
for (const lintGroup of lints) {
|
|
58
|
+
results.push(
|
|
59
|
+
...await Promise.all(lintGroup.map((lint) => lint(mode, logger)))
|
|
53
60
|
);
|
|
54
|
-
process.exitCode = 1;
|
|
55
61
|
}
|
|
62
|
+
return results;
|
|
63
|
+
};
|
|
64
|
+
const selectLintFunction = (input) => {
|
|
65
|
+
const isSerial = input?.debug || input?.serial;
|
|
66
|
+
return isSerial ? lintSerially : lintConcurrently;
|
|
56
67
|
};
|
|
57
|
-
const internalLint = async () => {
|
|
58
|
-
|
|
68
|
+
const internalLint = async (mode, input) => {
|
|
69
|
+
const start = process.hrtime.bigint();
|
|
70
|
+
const logger = (0, import_logging.createLogger)(
|
|
71
|
+
input?.debug ?? false,
|
|
72
|
+
...mode === "lint" ? [import_chalk.default.blueBright("skuba \u2502")] : []
|
|
73
|
+
);
|
|
74
|
+
try {
|
|
75
|
+
const lint = selectLintFunction(input);
|
|
76
|
+
const results = await lint(mode, logger);
|
|
77
|
+
const result = combineResults(results);
|
|
78
|
+
const end = process.hrtime.bigint();
|
|
79
|
+
logger.plain(`Processed skuba lints in ${logger.timing(start, end)}.`);
|
|
80
|
+
return result;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
logger.err(logger.bold("Failed to run skuba lints."));
|
|
83
|
+
logger.subtle((0, import_util.inspect)(err));
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
return { ok: false, fixable: false, annotations: [] };
|
|
86
|
+
}
|
|
59
87
|
};
|
|
88
|
+
const combineResults = (results) => results.reduce(
|
|
89
|
+
(cur, next) => ({
|
|
90
|
+
ok: cur.ok && next.ok,
|
|
91
|
+
fixable: cur.fixable || next.fixable,
|
|
92
|
+
annotations: [...cur.annotations ?? [], ...next.annotations ?? []]
|
|
93
|
+
}),
|
|
94
|
+
{ ok: true, fixable: false }
|
|
95
|
+
);
|
|
60
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
97
|
0 && (module.exports = {
|
|
62
98
|
internalLint
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/cli/lint/internal.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { inspect } from 'util';\n\nimport chalk from 'chalk';\n\nimport { type Logger, createLogger } from '../../utils/logging';\nimport { upgradeSkuba } from '../configure/upgrade';\n\nimport { deleteFilesLint } from './internalLints/deleteFiles';\nimport { noSkubaTemplateJs } from './internalLints/noSkubaTemplateJs';\nimport { tryRefreshConfigFiles } from './internalLints/refreshConfigFiles';\nimport type { Input } from './types';\n\nexport type InternalLintResult = {\n ok: boolean;\n fixable: boolean;\n annotations?: Array<{\n start_line?: number;\n end_line?: number;\n path: string;\n message: string;\n }>;\n};\n\nconst lints: Array<\n Array<\n (mode: 'format' | 'lint', logger: Logger) => Promise<InternalLintResult>\n >\n> = [\n // Run upgradeSkuba before refreshConfigFiles for npmrc handling\n [upgradeSkuba],\n [deleteFilesLint, noSkubaTemplateJs, tryRefreshConfigFiles],\n];\n\nconst lintSerially = async (mode: 'format' | 'lint', logger: Logger) => {\n const results: InternalLintResult[] = [];\n for (const lintGroup of lints) {\n for (const lint of lintGroup) {\n results.push(await lint(mode, logger));\n }\n }\n return results;\n};\n\nconst lintConcurrently = async (mode: 'format' | 'lint', logger: Logger) => {\n const results: InternalLintResult[] = [];\n\n for (const lintGroup of lints) {\n results.push(\n ...(await Promise.all(lintGroup.map((lint) => lint(mode, logger)))),\n );\n }\n\n return results;\n};\n\nconst selectLintFunction = (input?: Input) => {\n const isSerial = input?.debug || input?.serial;\n return isSerial ? lintSerially : lintConcurrently;\n};\n\nexport const internalLint = async (\n mode: 'format' | 'lint',\n input?: Input,\n): Promise<InternalLintResult> => {\n const start = process.hrtime.bigint();\n const logger = createLogger(\n input?.debug ?? false,\n ...(mode === 'lint' ? [chalk.blueBright('skuba \u2502')] : []),\n );\n\n try {\n const lint = selectLintFunction(input);\n const results = await lint(mode, logger);\n const result = combineResults(results);\n const end = process.hrtime.bigint();\n logger.plain(`Processed skuba lints in ${logger.timing(start, end)}.`);\n return result;\n } catch (err) {\n logger.err(logger.bold('Failed to run skuba lints.'));\n logger.subtle(inspect(err));\n\n process.exitCode = 1;\n\n return { ok: false, fixable: false, annotations: [] };\n }\n};\n\nconst combineResults = (results: InternalLintResult[]): InternalLintResult =>\n results.reduce(\n (cur, next) => ({\n ok: cur.ok && next.ok,\n fixable: cur.fixable || next.fixable,\n annotations: [...(cur.annotations ?? []), ...(next.annotations ?? [])],\n }),\n { ok: true, fixable: false },\n );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwB;AAExB,mBAAkB;AAElB,qBAA0C;AAC1C,qBAA6B;AAE7B,yBAAgC;AAChC,+BAAkC;AAClC,gCAAsC;AActC,MAAM,QAIF;AAAA;AAAA,EAEF,CAAC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