@xylabs/ts-scripts-yarn3 6.0.2 → 6.0.4
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/dist/actions/fix.mjs +28 -59
- package/dist/actions/fix.mjs.map +1 -1
- package/dist/actions/index.mjs +96 -121
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/lint.mjs +25 -65
- package/dist/actions/lint.mjs.map +1 -1
- package/dist/actions/package/index.mjs +3 -2
- package/dist/actions/package/index.mjs.map +1 -1
- package/dist/actions/package/lint.mjs +3 -2
- package/dist/actions/package/lint.mjs.map +1 -1
- package/dist/actions/relint.mjs +61 -45
- package/dist/actions/relint.mjs.map +1 -1
- package/dist/bin/package/fix.mjs +3 -2
- package/dist/bin/package/fix.mjs.map +1 -1
- package/dist/bin/package/lint.mjs +3 -2
- package/dist/bin/package/lint.mjs.map +1 -1
- package/dist/bin/package/relint.mjs +106 -0
- package/dist/bin/package/relint.mjs.map +1 -0
- package/dist/bin/xy.mjs +100 -94
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +29 -23
- package/dist/index.mjs +112 -135
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +100 -94
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +100 -94
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +97 -111
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +5 -4
- package/src/actions/fix.ts +3 -2
- package/src/actions/index.ts +0 -2
- package/src/actions/lint.ts +19 -42
- package/src/actions/package/lint.ts +2 -2
- package/src/actions/relint.ts +73 -18
- package/src/bin/package/relint.ts +16 -0
- package/src/xy/xyLintCommands.ts +6 -8
- package/dist/actions/lint-clean.mjs +0 -222
- package/dist/actions/lint-clean.mjs.map +0 -1
- package/dist/actions/lint-profile.mjs +0 -118
- package/dist/actions/lint-profile.mjs.map +0 -1
- package/src/actions/lint-clean.ts +0 -24
- package/src/actions/lint-profile.ts +0 -5
package/src/actions/relint.ts
CHANGED
|
@@ -1,23 +1,78 @@
|
|
|
1
|
-
import
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import type { ESLint } from 'eslint'
|
|
2
3
|
|
|
3
4
|
import { runSteps, yarnWorkspaces } from '../lib/index.ts'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
export interface RelintParams {
|
|
7
|
+
incremental?: boolean
|
|
8
|
+
pkg?: string
|
|
9
|
+
verbose?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RelintPackageParams {
|
|
13
|
+
pkg: string
|
|
14
|
+
verbose?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const dumpMessages = (lintResults: ESLint.LintResult[]) => {
|
|
18
|
+
const colors: ('white' | 'red' | 'yellow')[] = ['white', 'yellow', 'red']
|
|
19
|
+
const severity: string[] = ['none', 'warning', 'error']
|
|
20
|
+
|
|
21
|
+
for (const lintResult of lintResults) {
|
|
22
|
+
if (lintResult.messages.length > 0) {
|
|
23
|
+
console.log(chalk.gray(`${lintResult.filePath}`))
|
|
24
|
+
for (const message of lintResult.messages) {
|
|
25
|
+
console.log(
|
|
26
|
+
chalk.gray(`\t${message.line}:${message.column}`),
|
|
27
|
+
chalk[colors[message.severity]](`\t${severity[message.severity]}`),
|
|
28
|
+
chalk.white(`\t${message.message}`),
|
|
29
|
+
chalk.gray(`\t${message.ruleId}`),
|
|
30
|
+
)
|
|
18
31
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const relintPackage = ({ pkg, verbose }: RelintParams & Required<Pick<RelintParams, 'pkg'>>) => {
|
|
37
|
+
console.log(chalk.gray(`${'Relint'} [All-Packages]`))
|
|
38
|
+
const start = Date.now()
|
|
39
|
+
const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']
|
|
40
|
+
|
|
41
|
+
const result = runSteps('Relint [All-Packages]', [
|
|
42
|
+
['yarn', ['workspace',
|
|
43
|
+
pkg,
|
|
44
|
+
...verboseOptions,
|
|
45
|
+
'run',
|
|
46
|
+
'package-relint',
|
|
47
|
+
]],
|
|
48
|
+
])
|
|
49
|
+
console.log(chalk.gray(`${'Relinted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const relint = ({
|
|
54
|
+
pkg, verbose, incremental,
|
|
55
|
+
}: RelintParams = {}) => {
|
|
56
|
+
return pkg
|
|
57
|
+
? relintPackage({ pkg })
|
|
58
|
+
: relintAllPackages({ verbose, incremental })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const relintAllPackages = ({ verbose = true, incremental }: RelintParams = {}) => {
|
|
62
|
+
console.log(chalk.gray(`${'Relint'} [All-Packages]`))
|
|
63
|
+
const start = Date.now()
|
|
64
|
+
const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']
|
|
65
|
+
const incrementalOptions = incremental ? ['--since', '-Ap'] : ['--parallel', '-Ap']
|
|
66
|
+
|
|
67
|
+
const result = runSteps(`${'Relint'} [All-Packages]`, [
|
|
68
|
+
['yarn', ['workspaces',
|
|
69
|
+
'foreach',
|
|
70
|
+
...verboseOptions,
|
|
71
|
+
...incrementalOptions,
|
|
72
|
+
'run',
|
|
73
|
+
'package-relint',
|
|
74
|
+
]],
|
|
75
|
+
])
|
|
76
|
+
console.log(chalk.gray(`Relinted in [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))
|
|
77
|
+
return result
|
|
23
78
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
|
|
5
|
+
import { packageLint } from '../../actions/index.ts'
|
|
6
|
+
|
|
7
|
+
packageLint(false, false, true)
|
|
8
|
+
.then((value) => {
|
|
9
|
+
if (value) {
|
|
10
|
+
process.exit(value)
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
.catch((reason) => {
|
|
14
|
+
console.error(chalk.red(reason))
|
|
15
|
+
process.exit(-1)
|
|
16
|
+
})
|
package/src/xy/xyLintCommands.ts
CHANGED
|
@@ -2,7 +2,7 @@ import chalk from 'chalk'
|
|
|
2
2
|
import type { Argv } from 'yargs'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
cycle, fix, lint,
|
|
5
|
+
cycle, fix, lint, publint, relint, sonar,
|
|
6
6
|
} from '../actions/index.ts'
|
|
7
7
|
import { packagePositionalParam } from './param.ts'
|
|
8
8
|
|
|
@@ -27,15 +27,13 @@ export const xyLintCommands = (args: Argv) => {
|
|
|
27
27
|
(yargs) => {
|
|
28
28
|
return packagePositionalParam(yargs)
|
|
29
29
|
},
|
|
30
|
-
|
|
30
|
+
(argv) => {
|
|
31
31
|
if (argv.verbose) console.log('Lint')
|
|
32
32
|
const start = Date.now()
|
|
33
33
|
process.exitCode
|
|
34
34
|
= argv.fix
|
|
35
|
-
?
|
|
36
|
-
: argv.
|
|
37
|
-
? lintProfile()
|
|
38
|
-
: await lint({ pkg: argv.package as string })
|
|
35
|
+
? fix({ pkg: argv.package as string })
|
|
36
|
+
: lint({ pkg: argv.package as string })
|
|
39
37
|
console.log(chalk.blue(`Finished in ${Date.now() - start}ms`))
|
|
40
38
|
},
|
|
41
39
|
)
|
|
@@ -45,10 +43,10 @@ export const xyLintCommands = (args: Argv) => {
|
|
|
45
43
|
(yargs) => {
|
|
46
44
|
return packagePositionalParam(yargs)
|
|
47
45
|
},
|
|
48
|
-
|
|
46
|
+
(argv) => {
|
|
49
47
|
const start = Date.now()
|
|
50
48
|
if (argv.verbose) console.log('Fix')
|
|
51
|
-
process.exitCode =
|
|
49
|
+
process.exitCode = fix()
|
|
52
50
|
console.log(chalk.blue(`Finished in ${Date.now() - start}ms`))
|
|
53
51
|
},
|
|
54
52
|
)
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/actions/lint-clean.ts
|
|
5
|
-
import { rmSync } from "node:fs";
|
|
6
|
-
|
|
7
|
-
// src/lib/checkResult.ts
|
|
8
|
-
import chalk from "chalk";
|
|
9
|
-
var checkResult = /* @__PURE__ */ __name((name, result, level = "error", exitOnFail = false) => {
|
|
10
|
-
if (result) {
|
|
11
|
-
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
12
|
-
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
13
|
-
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
14
|
-
if (exitOnFail) {
|
|
15
|
-
process.exit(result);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}, "checkResult");
|
|
19
|
-
|
|
20
|
-
// src/lib/processEx.ts
|
|
21
|
-
import chalk2 from "chalk";
|
|
22
|
-
|
|
23
|
-
// src/lib/withError.ts
|
|
24
|
-
var withError = /* @__PURE__ */ __name((ex, closure, predicate = (ex2) => !!ex2.name && !!ex2.message) => {
|
|
25
|
-
return predicate(ex) ? closure(ex) : void 0;
|
|
26
|
-
}, "withError");
|
|
27
|
-
|
|
28
|
-
// src/lib/withErrnoException.ts
|
|
29
|
-
var withErrnoException = /* @__PURE__ */ __name((ex, closure) => {
|
|
30
|
-
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
31
|
-
}, "withErrnoException");
|
|
32
|
-
|
|
33
|
-
// src/lib/processEx.ts
|
|
34
|
-
var processEx = /* @__PURE__ */ __name((ex) => {
|
|
35
|
-
const error = typeof ex === "string" ? new Error(ex) : ex;
|
|
36
|
-
const exitCode = withErrnoException(error, (error2) => {
|
|
37
|
-
if (error2.code === "ENOENT") {
|
|
38
|
-
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
39
|
-
} else {
|
|
40
|
-
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
41
|
-
}
|
|
42
|
-
return error2.errno ?? -1;
|
|
43
|
-
}) ?? withError(error, (error2) => {
|
|
44
|
-
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
45
|
-
return -1;
|
|
46
|
-
}) ?? (() => {
|
|
47
|
-
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
48
|
-
return -1;
|
|
49
|
-
})();
|
|
50
|
-
process.exit(process.exitCode ?? exitCode);
|
|
51
|
-
}, "processEx");
|
|
52
|
-
|
|
53
|
-
// src/lib/safeExit.ts
|
|
54
|
-
var safeExit = /* @__PURE__ */ __name((func, exitOnFail = true) => {
|
|
55
|
-
try {
|
|
56
|
-
const result = func();
|
|
57
|
-
if (result && exitOnFail) {
|
|
58
|
-
process.exit(result);
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
} catch (ex) {
|
|
62
|
-
return processEx(ex);
|
|
63
|
-
}
|
|
64
|
-
}, "safeExit");
|
|
65
|
-
|
|
66
|
-
// src/lib/yarn/workspace/yarnWorkspaces.ts
|
|
67
|
-
import { spawnSync } from "node:child_process";
|
|
68
|
-
var yarnWorkspaces = /* @__PURE__ */ __name(() => {
|
|
69
|
-
const result = spawnSync("yarn", [
|
|
70
|
-
"workspaces",
|
|
71
|
-
"list",
|
|
72
|
-
"--json",
|
|
73
|
-
"--recursive"
|
|
74
|
-
], {
|
|
75
|
-
encoding: "utf8",
|
|
76
|
-
shell: true
|
|
77
|
-
});
|
|
78
|
-
if (result.error) {
|
|
79
|
-
throw result.error;
|
|
80
|
-
}
|
|
81
|
-
return result.stdout.toString().split("\n").slice(0, -1).map((item) => {
|
|
82
|
-
return JSON.parse(item);
|
|
83
|
-
});
|
|
84
|
-
}, "yarnWorkspaces");
|
|
85
|
-
|
|
86
|
-
// src/lib/runSteps.ts
|
|
87
|
-
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
88
|
-
import { existsSync } from "node:fs";
|
|
89
|
-
import chalk3 from "chalk";
|
|
90
|
-
var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages) => {
|
|
91
|
-
return safeExit(() => {
|
|
92
|
-
const pkgName = process.env.npm_package_name;
|
|
93
|
-
console.log(chalk3.green(`${name} [${pkgName}]`));
|
|
94
|
-
let totalStatus = 0;
|
|
95
|
-
for (const [i, [command, args, config]] of steps.entries()) {
|
|
96
|
-
if (messages?.[i]) {
|
|
97
|
-
console.log(chalk3.gray(messages?.[i]));
|
|
98
|
-
}
|
|
99
|
-
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
100
|
-
if (command === "node" && !existsSync(argList[0])) {
|
|
101
|
-
throw new Error(`File not found [${argList[0]}]`);
|
|
102
|
-
}
|
|
103
|
-
const status = spawnSync2(command, Array.isArray(args) ? args : args.split(" "), {
|
|
104
|
-
...config,
|
|
105
|
-
encoding: "utf8",
|
|
106
|
-
env: {
|
|
107
|
-
FORCE_COLOR: "3",
|
|
108
|
-
...process.env
|
|
109
|
-
},
|
|
110
|
-
shell: true,
|
|
111
|
-
stdio: "inherit"
|
|
112
|
-
}).status ?? 0;
|
|
113
|
-
checkResult(name, status, "error", exitOnFail);
|
|
114
|
-
totalStatus += status ?? 0;
|
|
115
|
-
}
|
|
116
|
-
return totalStatus;
|
|
117
|
-
}, !!exitOnFail);
|
|
118
|
-
}, "runSteps");
|
|
119
|
-
|
|
120
|
-
// src/actions/lint.ts
|
|
121
|
-
import chalk4 from "chalk";
|
|
122
|
-
import { ESLint } from "eslint";
|
|
123
|
-
var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
124
|
-
const colors = [
|
|
125
|
-
"white",
|
|
126
|
-
"yellow",
|
|
127
|
-
"red"
|
|
128
|
-
];
|
|
129
|
-
const severity = [
|
|
130
|
-
"none",
|
|
131
|
-
"warning",
|
|
132
|
-
"error"
|
|
133
|
-
];
|
|
134
|
-
for (const lintResult of lintResults) {
|
|
135
|
-
if (lintResult.messages.length > 0) {
|
|
136
|
-
console.log(chalk4.gray(`${lintResult.filePath}`));
|
|
137
|
-
for (const message of lintResult.messages) {
|
|
138
|
-
console.log(chalk4.gray(` ${message.line}:${message.column}`), chalk4[colors[message.severity]](` ${severity[message.severity]}`), chalk4.white(` ${message.message}`), chalk4.gray(` ${message.ruleId}`));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}, "dumpMessages");
|
|
143
|
-
var lintPackage = /* @__PURE__ */ __name(async ({ pkg, fix }) => {
|
|
144
|
-
const workspace = yarnWorkspaces().find((workspace2) => workspace2.name === pkg);
|
|
145
|
-
if (!workspace) {
|
|
146
|
-
console.error(chalk4.red(`Unable to locate package [${chalk4.magenta(pkg)}]`));
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
const engine = new ESLint({
|
|
150
|
-
cache: true,
|
|
151
|
-
fix
|
|
152
|
-
});
|
|
153
|
-
const lintResults = await engine.lintFiles(workspace.location);
|
|
154
|
-
dumpMessages(lintResults);
|
|
155
|
-
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
156
|
-
}, "lintPackage");
|
|
157
|
-
var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental, fix } = {}) => {
|
|
158
|
-
return pkg ? await lintPackage({
|
|
159
|
-
pkg,
|
|
160
|
-
fix
|
|
161
|
-
}) : lintAllPackages({
|
|
162
|
-
verbose,
|
|
163
|
-
incremental,
|
|
164
|
-
fix
|
|
165
|
-
});
|
|
166
|
-
}, "lint");
|
|
167
|
-
var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental } = {}) => {
|
|
168
|
-
console.log(chalk4.gray(`${fix ? "Fix" : "Lint"} [All-Packages]`));
|
|
169
|
-
const start = Date.now();
|
|
170
|
-
const verboseOptions = verbose ? [
|
|
171
|
-
"--verbose"
|
|
172
|
-
] : [
|
|
173
|
-
"--no-verbose"
|
|
174
|
-
];
|
|
175
|
-
const incrementalOptions = incremental ? [
|
|
176
|
-
"--since",
|
|
177
|
-
"-Ap"
|
|
178
|
-
] : [
|
|
179
|
-
"--parallel",
|
|
180
|
-
"-Ap"
|
|
181
|
-
];
|
|
182
|
-
const result = runSteps(`${fix ? "Fix" : "Lint"} [All-Packages]`, [
|
|
183
|
-
[
|
|
184
|
-
"yarn",
|
|
185
|
-
[
|
|
186
|
-
"workspaces",
|
|
187
|
-
"foreach",
|
|
188
|
-
...verboseOptions,
|
|
189
|
-
...incrementalOptions,
|
|
190
|
-
"run",
|
|
191
|
-
fix ? "package-fix" : "package-lint"
|
|
192
|
-
]
|
|
193
|
-
]
|
|
194
|
-
]);
|
|
195
|
-
console.log(chalk4.gray(`${fix ? "Fixed in" : "Linted in"} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`));
|
|
196
|
-
return result;
|
|
197
|
-
}, "lintAllPackages");
|
|
198
|
-
|
|
199
|
-
// src/actions/lint-clean.ts
|
|
200
|
-
var lintClean = /* @__PURE__ */ __name(async () => {
|
|
201
|
-
console.log("Lint Clean [.eslintcache]");
|
|
202
|
-
const workspaces = yarnWorkspaces();
|
|
203
|
-
const result = workspaces.map(({ location, name }) => {
|
|
204
|
-
const dist = `${location}/.eslintcache`;
|
|
205
|
-
try {
|
|
206
|
-
rmSync(dist, {
|
|
207
|
-
force: true,
|
|
208
|
-
recursive: true
|
|
209
|
-
});
|
|
210
|
-
return 0;
|
|
211
|
-
} catch (ex) {
|
|
212
|
-
const error = ex;
|
|
213
|
-
console.error(`Lint Clean [.eslintcache] Failed [${name}, ${error.message}]`);
|
|
214
|
-
return 1;
|
|
215
|
-
}
|
|
216
|
-
}).reduce((prev, result2) => prev || result2, 0);
|
|
217
|
-
return result || await lint();
|
|
218
|
-
}, "lintClean");
|
|
219
|
-
export {
|
|
220
|
-
lintClean
|
|
221
|
-
};
|
|
222
|
-
//# sourceMappingURL=lint-clean.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/lint-clean.ts","../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/yarn/workspace/yarnWorkspaces.ts","../../src/lib/runSteps.ts","../../src/actions/lint.ts"],"sourcesContent":["import { rmSync } from 'node:fs'\n\nimport { yarnWorkspaces } from '../lib/index.ts'\nimport { lint } from './lint.ts'\n\nexport const lintClean = async () => {\n console.log('Lint Clean [.eslintcache]')\n const workspaces = yarnWorkspaces()\n const result = workspaces\n .map(({ location, name }) => {\n const dist = `${location}/.eslintcache`\n try {\n rmSync(dist, { force: true, recursive: true })\n return 0\n } catch (ex) {\n const error = ex as Error\n console.error(`Lint Clean [.eslintcache] Failed [${name}, ${error.message}]`)\n return 1\n }\n })\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((prev, result) => prev || result, 0)\n return result || await lint()\n}\n","import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import { spawnSync } from 'node:child_process'\n\nimport type { Workspace } from './Workspace.ts'\n\nexport const yarnWorkspaces = (): Workspace[] => {\n const result = spawnSync('yarn', ['workspaces', 'list', '--json', '--recursive'], { encoding: 'utf8', shell: true })\n if (result.error) {\n throw result.error\n }\n return (\n result.stdout\n .toString()\n // NOTE: This probably doesn't work on Windows\n // TODO: Replace /r/n with /n first\n .split('\\n')\n .slice(0, -1)\n .map((item) => {\n return JSON.parse(item)\n })\n )\n}\n","import type { SpawnSyncOptionsWithBufferEncoding } from 'node:child_process'\nimport { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\n\nimport chalk from 'chalk'\n\nimport { checkResult } from './checkResult.ts'\nimport { safeExit } from './safeExit.ts'\n\nexport type ScriptStep =\n | [/* command */ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /* arg */ string | string[]]\n | [/* command */ string, /* arg */ string | string[], /* config */ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (const [i, [command, args, config]] of steps.entries()) {\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw new Error(`File not found [${argList[0]}]`)\n }\n const status\n = spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n","import chalk from 'chalk'\nimport { ESLint } from 'eslint'\n\nimport { runSteps, yarnWorkspaces } from '../lib/index.ts'\n\nexport interface LintParams {\n fix?: boolean\n incremental?: boolean\n pkg?: string\n verbose?: boolean\n}\n\nexport interface LintPackageParams {\n pkg: string\n verbose?: boolean\n}\n\nconst dumpMessages = (lintResults: ESLint.LintResult[]) => {\n const colors: ('white' | 'red' | 'yellow')[] = ['white', 'yellow', 'red']\n const severity: string[] = ['none', 'warning', 'error']\n\n for (const lintResult of lintResults) {\n if (lintResult.messages.length > 0) {\n console.log(chalk.gray(`${lintResult.filePath}`))\n for (const message of lintResult.messages) {\n console.log(\n chalk.gray(`\\t${message.line}:${message.column}`),\n chalk[colors[message.severity]](`\\t${severity[message.severity]}`),\n chalk.white(`\\t${message.message}`),\n chalk.gray(`\\t${message.ruleId}`),\n )\n }\n }\n }\n}\n\nexport const lintPackage = async ({ pkg, fix }: LintParams) => {\n const workspace = yarnWorkspaces().find(workspace => workspace.name === pkg)\n if (!workspace) {\n console.error(chalk.red(`Unable to locate package [${chalk.magenta(pkg)}]`))\n process.exit(1)\n }\n\n const engine = new ESLint({ cache: true, fix })\n\n const lintResults = await engine.lintFiles(workspace.location)\n\n dumpMessages(lintResults)\n\n return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0)\n}\n\nexport const lintAll = async ({ fix }: LintParams) => {\n const workspace = yarnWorkspaces()\n return (await Promise.all(workspace.map(ws =>\n lintPackage({ pkg: ws.name, fix })))).reduce((prev, curr) => prev + curr, 0)\n}\n\nexport const lint = async ({\n pkg, verbose, incremental, fix,\n}: LintParams = {}) => {\n return pkg\n ? await lintPackage({ pkg, fix })\n : lintAllPackages({\n verbose, incremental, fix,\n })\n}\n\nexport const lintAllPackages = ({\n fix, verbose = true, incremental,\n}: LintParams = {}) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [All-Packages]`))\n const start = Date.now()\n const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n const incrementalOptions = incremental ? ['--since', '-Ap'] : ['--parallel', '-Ap']\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [All-Packages]`, [\n ['yarn', ['workspaces',\n 'foreach',\n ...verboseOptions,\n ...incrementalOptions,\n 'run',\n fix ? 'package-fix' : 'package-lint',\n ]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n"],"mappings":";;;;AAAA,SAASA,cAAc;;;ACAvB,OAAOC,WAAW;AAEX,IAAMC,cAAc,wBAACC,MAAcC,QAAgBC,QAA0B,SAASC,aAAa,UAAK;AAC7G,MAAIF,QAAQ;AACV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+B;;;AR/DxB,IAAMI,YAAY,mCAAA;AACvBC,UAAQC,IAAI,2BAAA;AACZ,QAAMC,aAAaC,eAAAA;AACnB,QAAMC,SAASF,WACZG,IAAI,CAAC,EAAEC,UAAUC,KAAI,MAAE;AACtB,UAAMC,OAAO,GAAGF,QAAAA;AAChB,QAAI;AACFG,aAAOD,MAAM;QAAEE,OAAO;QAAMC,WAAW;MAAK,CAAA;AAC5C,aAAO;IACT,SAASC,IAAI;AACX,YAAMC,QAAQD;AACdZ,cAAQa,MAAM,qCAAqCN,IAAAA,KAASM,MAAMC,OAAO,GAAG;AAC5E,aAAO;IACT;EACF,CAAA,EAECC,OAAO,CAACC,MAAMZ,YAAWY,QAAQZ,SAAQ,CAAA;AAC5C,SAAOA,UAAU,MAAMa,KAAAA;AACzB,GAlByB;","names":["rmSync","chalk","checkResult","name","result","level","exitOnFail","exiting","chalkFunc","chalk","red","yellow","console","process","exit","chalk","withError","ex","closure","predicate","name","message","undefined","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","spawnSync","yarnWorkspaces","result","spawnSync","encoding","shell","error","stdout","toString","split","slice","map","item","JSON","parse","spawnSync","existsSync","chalk","runSteps","name","steps","exitOnFail","messages","safeExit","pkgName","process","env","npm_package_name","console","log","chalk","green","totalStatus","i","command","args","config","entries","gray","argList","Array","isArray","split","existsSync","Error","status","spawnSync","encoding","FORCE_COLOR","shell","stdio","checkResult","chalk","ESLint","dumpMessages","lintResults","colors","severity","lintResult","messages","length","console","log","chalk","gray","filePath","message","line","column","white","ruleId","lintPackage","pkg","fix","workspace","yarnWorkspaces","find","name","error","red","magenta","process","exit","engine","ESLint","cache","lintFiles","location","reduce","prev","errorCount","lint","pkg","verbose","incremental","fix","lintPackage","lintAllPackages","console","log","chalk","gray","start","Date","now","verboseOptions","incrementalOptions","result","runSteps","magenta","toFixed","lintClean","console","log","workspaces","yarnWorkspaces","result","map","location","name","dist","rmSync","force","recursive","ex","error","message","reduce","prev","lint"]}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/lib/checkResult.ts
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
var checkResult = /* @__PURE__ */ __name((name, result, level = "error", exitOnFail = false) => {
|
|
7
|
-
if (result) {
|
|
8
|
-
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
9
|
-
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
10
|
-
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
11
|
-
if (exitOnFail) {
|
|
12
|
-
process.exit(result);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}, "checkResult");
|
|
16
|
-
|
|
17
|
-
// src/lib/processEx.ts
|
|
18
|
-
import chalk2 from "chalk";
|
|
19
|
-
|
|
20
|
-
// src/lib/withError.ts
|
|
21
|
-
var withError = /* @__PURE__ */ __name((ex, closure, predicate = (ex2) => !!ex2.name && !!ex2.message) => {
|
|
22
|
-
return predicate(ex) ? closure(ex) : void 0;
|
|
23
|
-
}, "withError");
|
|
24
|
-
|
|
25
|
-
// src/lib/withErrnoException.ts
|
|
26
|
-
var withErrnoException = /* @__PURE__ */ __name((ex, closure) => {
|
|
27
|
-
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
28
|
-
}, "withErrnoException");
|
|
29
|
-
|
|
30
|
-
// src/lib/processEx.ts
|
|
31
|
-
var processEx = /* @__PURE__ */ __name((ex) => {
|
|
32
|
-
const error = typeof ex === "string" ? new Error(ex) : ex;
|
|
33
|
-
const exitCode = withErrnoException(error, (error2) => {
|
|
34
|
-
if (error2.code === "ENOENT") {
|
|
35
|
-
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
36
|
-
} else {
|
|
37
|
-
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
38
|
-
}
|
|
39
|
-
return error2.errno ?? -1;
|
|
40
|
-
}) ?? withError(error, (error2) => {
|
|
41
|
-
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
42
|
-
return -1;
|
|
43
|
-
}) ?? (() => {
|
|
44
|
-
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
45
|
-
return -1;
|
|
46
|
-
})();
|
|
47
|
-
process.exit(process.exitCode ?? exitCode);
|
|
48
|
-
}, "processEx");
|
|
49
|
-
|
|
50
|
-
// src/lib/safeExit.ts
|
|
51
|
-
var safeExit = /* @__PURE__ */ __name((func, exitOnFail = true) => {
|
|
52
|
-
try {
|
|
53
|
-
const result = func();
|
|
54
|
-
if (result && exitOnFail) {
|
|
55
|
-
process.exit(result);
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
} catch (ex) {
|
|
59
|
-
return processEx(ex);
|
|
60
|
-
}
|
|
61
|
-
}, "safeExit");
|
|
62
|
-
|
|
63
|
-
// src/lib/runSteps.ts
|
|
64
|
-
import { spawnSync } from "node:child_process";
|
|
65
|
-
import { existsSync } from "node:fs";
|
|
66
|
-
import chalk3 from "chalk";
|
|
67
|
-
var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages) => {
|
|
68
|
-
return safeExit(() => {
|
|
69
|
-
const pkgName = process.env.npm_package_name;
|
|
70
|
-
console.log(chalk3.green(`${name} [${pkgName}]`));
|
|
71
|
-
let totalStatus = 0;
|
|
72
|
-
for (const [i, [command, args, config]] of steps.entries()) {
|
|
73
|
-
if (messages?.[i]) {
|
|
74
|
-
console.log(chalk3.gray(messages?.[i]));
|
|
75
|
-
}
|
|
76
|
-
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
77
|
-
if (command === "node" && !existsSync(argList[0])) {
|
|
78
|
-
throw new Error(`File not found [${argList[0]}]`);
|
|
79
|
-
}
|
|
80
|
-
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
81
|
-
...config,
|
|
82
|
-
encoding: "utf8",
|
|
83
|
-
env: {
|
|
84
|
-
FORCE_COLOR: "3",
|
|
85
|
-
...process.env
|
|
86
|
-
},
|
|
87
|
-
shell: true,
|
|
88
|
-
stdio: "inherit"
|
|
89
|
-
}).status ?? 0;
|
|
90
|
-
checkResult(name, status, "error", exitOnFail);
|
|
91
|
-
totalStatus += status ?? 0;
|
|
92
|
-
}
|
|
93
|
-
return totalStatus;
|
|
94
|
-
}, !!exitOnFail);
|
|
95
|
-
}, "runSteps");
|
|
96
|
-
|
|
97
|
-
// src/actions/lint-profile.ts
|
|
98
|
-
var lintProfile = /* @__PURE__ */ __name(() => {
|
|
99
|
-
return runSteps("Lint Profile", [
|
|
100
|
-
[
|
|
101
|
-
"yarn",
|
|
102
|
-
[
|
|
103
|
-
"xy",
|
|
104
|
-
"lint"
|
|
105
|
-
],
|
|
106
|
-
{
|
|
107
|
-
env: {
|
|
108
|
-
...process.env,
|
|
109
|
-
TIMING: "1"
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
]);
|
|
114
|
-
}, "lintProfile");
|
|
115
|
-
export {
|
|
116
|
-
lintProfile
|
|
117
|
-
};
|
|
118
|
-
//# sourceMappingURL=lint-profile.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts","../../src/actions/lint-profile.ts"],"sourcesContent":["import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import type { SpawnSyncOptionsWithBufferEncoding } from 'node:child_process'\nimport { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\n\nimport chalk from 'chalk'\n\nimport { checkResult } from './checkResult.ts'\nimport { safeExit } from './safeExit.ts'\n\nexport type ScriptStep =\n | [/* command */ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /* arg */ string | string[]]\n | [/* command */ string, /* arg */ string | string[], /* config */ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (const [i, [command, args, config]] of steps.entries()) {\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw new Error(`File not found [${argList[0]}]`)\n }\n const status\n = spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n","import { runSteps } from '../lib/index.ts'\n\nexport const lintProfile = () => {\n return runSteps('Lint Profile', [['yarn', ['xy', 'lint'], { env: { ...process.env, TIMING: '1' } }]])\n}\n"],"mappings":";;;;AAAA,OAAOA,WAAW;AAEX,IAAMC,cAAc,wBAACC,MAAcC,QAAgBC,QAA0B,SAASC,aAAa,UAAK;AAC7G,MAAIF,QAAQ;AACV,UAAMG,UAAUD,aAAa,sBAAsB;AACnD,UAAME,YAAYH,UAAU,UAAUI,MAAMC,MAAMD,MAAME;AACxDC,YAAQP,KAAAA,EAAOG,UAAU,GAAGL,IAAAA,QAAYC,MAAAA,aAAmBG,OAAAA,EAAS,CAAA;AACpE,QAAID,YAAY;AACdO,cAAQC,KAAKV,MAAAA;IACf;EACF;AACF,GAT2B;;;ACF3B,OAAOW,YAAW;;;ACAX,IAAMC,YAAY,w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nFail","exiting","chalkFunc","chalk","red","yellow","console","process","exit","chalk","withError","ex","closure","predicate","name","message","undefined","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","spawnSync","existsSync","chalk","runSteps","name","steps","exitOnFail","messages","safeExit","pkgName","process","env","npm_package_name","console","log","chalk","green","totalStatus","i","command","args","config","entries","gray","argList","Array","isArray","split","existsSync","Error","status","spawnSync","encoding","FORCE_COLOR","shell","stdio","checkResult","lintProfile","runSteps","env","process","TIMING"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { rmSync } from 'node:fs'
|
|
2
|
-
|
|
3
|
-
import { yarnWorkspaces } from '../lib/index.ts'
|
|
4
|
-
import { lint } from './lint.ts'
|
|
5
|
-
|
|
6
|
-
export const lintClean = async () => {
|
|
7
|
-
console.log('Lint Clean [.eslintcache]')
|
|
8
|
-
const workspaces = yarnWorkspaces()
|
|
9
|
-
const result = workspaces
|
|
10
|
-
.map(({ location, name }) => {
|
|
11
|
-
const dist = `${location}/.eslintcache`
|
|
12
|
-
try {
|
|
13
|
-
rmSync(dist, { force: true, recursive: true })
|
|
14
|
-
return 0
|
|
15
|
-
} catch (ex) {
|
|
16
|
-
const error = ex as Error
|
|
17
|
-
console.error(`Lint Clean [.eslintcache] Failed [${name}, ${error.message}]`)
|
|
18
|
-
return 1
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
22
|
-
.reduce((prev, result) => prev || result, 0)
|
|
23
|
-
return result || await lint()
|
|
24
|
-
}
|