@valbuild/cli 0.63.1 ā 0.64.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/package.json +4 -4
- package/src/cli.ts +4 -4
- package/src/files.ts +3 -3
- package/src/logger.ts +2 -2
- package/src/validate.ts +21 -21
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/cli",
|
3
3
|
"private": false,
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.64.0",
|
5
5
|
"description": "Val CLI tools",
|
6
6
|
"bin": {
|
7
7
|
"val": "./bin.js"
|
@@ -18,9 +18,9 @@
|
|
18
18
|
"typecheck": "tsc --noEmit"
|
19
19
|
},
|
20
20
|
"dependencies": {
|
21
|
-
"@valbuild/core": "~0.
|
22
|
-
"@valbuild/server": "~0.
|
23
|
-
"@valbuild/eslint-plugin": "~0.
|
21
|
+
"@valbuild/core": "~0.64.0",
|
22
|
+
"@valbuild/server": "~0.64.0",
|
23
|
+
"@valbuild/eslint-plugin": "~0.64.0",
|
24
24
|
"eslint": "^8.31.0",
|
25
25
|
"@inquirer/confirm": "^2.0.15",
|
26
26
|
"@inquirer/prompts": "^3.0.2",
|
package/src/cli.ts
CHANGED
@@ -61,7 +61,7 @@ async function main(): Promise<void> {
|
|
61
61
|
},
|
62
62
|
},
|
63
63
|
hardRejection: false,
|
64
|
-
}
|
64
|
+
},
|
65
65
|
);
|
66
66
|
|
67
67
|
if (input.length === 0) {
|
@@ -77,7 +77,7 @@ async function main(): Promise<void> {
|
|
77
77
|
case "files":
|
78
78
|
if (flags.fix || flags.noEslint) {
|
79
79
|
return error(
|
80
|
-
`Command "files" does not support --fix or --noEslint flags
|
80
|
+
`Command "files" does not support --fix or --noEslint flags`,
|
81
81
|
);
|
82
82
|
}
|
83
83
|
return files({
|
@@ -106,8 +106,8 @@ void main().catch((err) => {
|
|
106
106
|
err instanceof Error
|
107
107
|
? err.message + "\n" + err.stack
|
108
108
|
: typeof err === "object"
|
109
|
-
|
110
|
-
|
109
|
+
? JSON.stringify(err, null, 2)
|
110
|
+
: err,
|
111
111
|
);
|
112
112
|
process.exitCode = 1;
|
113
113
|
});
|
package/src/files.ts
CHANGED
@@ -30,7 +30,7 @@ export async function files({
|
|
30
30
|
async function printOrGetFileRefs(file: string) {
|
31
31
|
const moduleId = `/${file}`.replace(
|
32
32
|
/(\.val\.(ts|js))$/,
|
33
|
-
""
|
33
|
+
"",
|
34
34
|
) as ModuleFilePath; // TODO: check if this always works? (Windows?)
|
35
35
|
const valModule = await service.get(moduleId, "" as ModulePath, {
|
36
36
|
validate: true,
|
@@ -48,7 +48,7 @@ export async function files({
|
|
48
48
|
if (isFileRef(value)) {
|
49
49
|
const absoluteFilePathUsedByVal = path.join(
|
50
50
|
projectRoot,
|
51
|
-
...value[FILE_REF_PROP].split("/")
|
51
|
+
...value[FILE_REF_PROP].split("/"),
|
52
52
|
);
|
53
53
|
if (printFilesUsedByVal) {
|
54
54
|
console.log(absoluteFilePathUsedByVal);
|
@@ -86,7 +86,7 @@ export async function files({
|
|
86
86
|
}
|
87
87
|
|
88
88
|
function isFileRef(
|
89
|
-
value: unknown
|
89
|
+
value: unknown,
|
90
90
|
): value is { [FILE_REF_PROP]: string; [VAL_EXTENSION]: "file" } {
|
91
91
|
if (!value) return false;
|
92
92
|
if (typeof value !== "object") return false;
|
package/src/logger.ts
CHANGED
@@ -6,7 +6,7 @@ export function error(message: string) {
|
|
6
6
|
|
7
7
|
export function info(
|
8
8
|
message: string,
|
9
|
-
opts: { isCodeSnippet?: true; isGood?: true } = {}
|
9
|
+
opts: { isCodeSnippet?: true; isGood?: true } = {},
|
10
10
|
) {
|
11
11
|
if (opts.isCodeSnippet) {
|
12
12
|
console.log(chalk.cyanBright("$ > ") + chalk.cyan(message));
|
@@ -29,6 +29,6 @@ export function debugPrint(str: string) {
|
|
29
29
|
|
30
30
|
export function printDebuggingHelp() {
|
31
31
|
info(
|
32
|
-
`If you're having trouble, please follow the debugging steps\nš: https://val.build/docs/troubleshooting
|
32
|
+
`If you're having trouble, please follow the debugging steps\nš: https://val.build/docs/troubleshooting`,
|
33
33
|
);
|
34
34
|
}
|
package/src/validate.ts
CHANGED
@@ -44,7 +44,7 @@ export async function validate({
|
|
44
44
|
...acc,
|
45
45
|
[result.filePath.replaceAll(`${projectRoot}/`, "")]: result,
|
46
46
|
}),
|
47
|
-
{} as Record<string, ESLint.LintResult
|
47
|
+
{} as Record<string, ESLint.LintResult>,
|
48
48
|
);
|
49
49
|
eslintResults.forEach((result) => {
|
50
50
|
result.messages.forEach(async (m) => {
|
@@ -53,7 +53,7 @@ export async function validate({
|
|
53
53
|
logEslintMessage(
|
54
54
|
await fs.readFile(result.filePath, "utf-8"),
|
55
55
|
result.filePath,
|
56
|
-
m
|
56
|
+
m,
|
57
57
|
);
|
58
58
|
}
|
59
59
|
});
|
@@ -62,7 +62,7 @@ export async function validate({
|
|
62
62
|
errors === 0 ? picocolors.green("ā") : picocolors.red("ā"),
|
63
63
|
"ESlint complete",
|
64
64
|
lintFiles.length,
|
65
|
-
"files"
|
65
|
+
"files",
|
66
66
|
);
|
67
67
|
}
|
68
68
|
console.log("Validating...", valFiles.length, "files");
|
@@ -77,7 +77,7 @@ export async function validate({
|
|
77
77
|
});
|
78
78
|
const fileContent = await fs.readFile(
|
79
79
|
path.join(projectRoot, file),
|
80
|
-
"utf-8"
|
80
|
+
"utf-8",
|
81
81
|
);
|
82
82
|
const eslintResult = eslintResultsByFile?.[file];
|
83
83
|
eslintResult?.messages.forEach((m) => {
|
@@ -88,19 +88,19 @@ export async function validate({
|
|
88
88
|
console.log(
|
89
89
|
picocolors.green("ā"),
|
90
90
|
moduleFilePath,
|
91
|
-
"is valid (" + (Date.now() - start) + "ms)"
|
91
|
+
"is valid (" + (Date.now() - start) + "ms)",
|
92
92
|
);
|
93
93
|
return 0;
|
94
94
|
} else {
|
95
95
|
let errors =
|
96
96
|
eslintResultsByFile?.[file]?.messages.reduce(
|
97
97
|
(prev, m) => (m.severity >= 2 ? prev + 1 : prev),
|
98
|
-
0
|
98
|
+
0,
|
99
99
|
) || 0;
|
100
100
|
if (valModule.errors) {
|
101
101
|
if (valModule.errors.validation) {
|
102
102
|
for (const [sourcePath, validationErrors] of Object.entries(
|
103
|
-
valModule.errors.validation
|
103
|
+
valModule.errors.validation,
|
104
104
|
)) {
|
105
105
|
for (const v of validationErrors) {
|
106
106
|
if (v.fixes && v.fixes.length > 0) {
|
@@ -108,14 +108,14 @@ export async function validate({
|
|
108
108
|
{ projectRoot },
|
109
109
|
!!fix,
|
110
110
|
sourcePath as SourcePath,
|
111
|
-
v
|
111
|
+
v,
|
112
112
|
);
|
113
113
|
if (fix && fixPatch?.patch && fixPatch?.patch.length > 0) {
|
114
114
|
await service.patch(moduleFilePath, fixPatch.patch);
|
115
115
|
console.log(
|
116
116
|
picocolors.yellow("ā "),
|
117
117
|
"Applied fix for",
|
118
|
-
sourcePath
|
118
|
+
sourcePath,
|
119
119
|
);
|
120
120
|
}
|
121
121
|
fixPatch?.remainingErrors?.forEach((e) => {
|
@@ -124,7 +124,7 @@ export async function validate({
|
|
124
124
|
v.fixes ? picocolors.yellow("ā ") : picocolors.red("ā"),
|
125
125
|
`Found ${v.fixes ? "fixable " : ""}error in`,
|
126
126
|
`${sourcePath}:`,
|
127
|
-
e.message
|
127
|
+
e.message,
|
128
128
|
);
|
129
129
|
});
|
130
130
|
} else {
|
@@ -133,7 +133,7 @@ export async function validate({
|
|
133
133
|
picocolors.red("ā"),
|
134
134
|
"Found error in",
|
135
135
|
`${sourcePath}:`,
|
136
|
-
v.message
|
136
|
+
v.message,
|
137
137
|
);
|
138
138
|
}
|
139
139
|
}
|
@@ -145,14 +145,14 @@ export async function validate({
|
|
145
145
|
picocolors.red("ā"),
|
146
146
|
moduleFilePath,
|
147
147
|
"is invalid:",
|
148
|
-
fatalError.message
|
148
|
+
fatalError.message,
|
149
149
|
);
|
150
150
|
}
|
151
151
|
} else {
|
152
152
|
console.log(
|
153
153
|
picocolors.green("ā"),
|
154
154
|
moduleFilePath,
|
155
|
-
"is valid (" + (Date.now() - start) + "ms)"
|
155
|
+
"is valid (" + (Date.now() - start) + "ms)",
|
156
156
|
);
|
157
157
|
}
|
158
158
|
return errors;
|
@@ -166,7 +166,7 @@ export async function validate({
|
|
166
166
|
picocolors.red("ā"),
|
167
167
|
"Found",
|
168
168
|
errors,
|
169
|
-
"validation error" + (errors > 1 ? "s" : "")
|
169
|
+
"validation error" + (errors > 1 ? "s" : ""),
|
170
170
|
);
|
171
171
|
process.exit(1);
|
172
172
|
} else {
|
@@ -180,7 +180,7 @@ export async function validate({
|
|
180
180
|
function logEslintMessage(
|
181
181
|
fileContent: string,
|
182
182
|
filePath: string,
|
183
|
-
eslintMessage: ESLint.LintResult["messages"][number]
|
183
|
+
eslintMessage: ESLint.LintResult["messages"][number],
|
184
184
|
) {
|
185
185
|
const lines = fileContent.split("\n");
|
186
186
|
const line = lines[eslintMessage.line - 1];
|
@@ -191,12 +191,12 @@ function logEslintMessage(
|
|
191
191
|
isError ? picocolors.red("ā") : picocolors.yellow("ā "),
|
192
192
|
isError ? "Found eslint error:" : "Found eslint warning:",
|
193
193
|
`${filePath}:${eslintMessage.line}:${eslintMessage.column}\n`,
|
194
|
-
eslintMessage.message
|
194
|
+
eslintMessage.message,
|
195
195
|
);
|
196
196
|
lineBefore &&
|
197
197
|
console.log(
|
198
198
|
picocolors.gray(" " + (eslintMessage.line - 1) + " |"),
|
199
|
-
lineBefore
|
199
|
+
lineBefore,
|
200
200
|
);
|
201
201
|
line && console.log(picocolors.gray(" " + eslintMessage.line + " |"), line);
|
202
202
|
// adds ^ below the relevant line:
|
@@ -209,18 +209,18 @@ function logEslintMessage(
|
|
209
209
|
line &&
|
210
210
|
console.log(
|
211
211
|
picocolors.gray(
|
212
|
-
" " + " ".repeat(eslintMessage.line.toString().length) + " |"
|
212
|
+
" " + " ".repeat(eslintMessage.line.toString().length) + " |",
|
213
213
|
),
|
214
214
|
" ".repeat(eslintMessage.column - 1) +
|
215
215
|
(eslintMessage.endColumn
|
216
216
|
? (isError ? picocolors.red("^") : picocolors.yellow("^")).repeat(
|
217
|
-
amountOfColumns
|
217
|
+
amountOfColumns,
|
218
218
|
)
|
219
|
-
: "")
|
219
|
+
: ""),
|
220
220
|
);
|
221
221
|
lineAfter &&
|
222
222
|
console.log(
|
223
223
|
picocolors.gray(" " + (eslintMessage.line + 1) + " |"),
|
224
|
-
lineAfter
|
224
|
+
lineAfter,
|
225
225
|
);
|
226
226
|
}
|