@xylabs/ts-scripts-yarn3 5.1.3 → 5.1.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 +12 -135
- package/dist/actions/fix.mjs.map +1 -1
- package/dist/actions/index.mjs +5 -7
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/lint-clean.mjs +12 -135
- package/dist/actions/lint-clean.mjs.map +1 -1
- package/dist/actions/lint.mjs +5 -7
- package/dist/actions/lint.mjs.map +1 -1
- package/dist/bin/xy-ts.mjs +8 -38
- package/dist/bin/xy-ts.mjs.map +1 -1
- package/dist/bin/xy.mjs +8 -38
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +5 -7
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +8 -38
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +8 -38
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +8 -38
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +4 -4
- package/src/actions/lint.ts +3 -4
package/dist/actions/fix.mjs
CHANGED
|
@@ -2,67 +2,8 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/actions/lint.ts
|
|
5
|
-
import chalk4 from "chalk";
|
|
6
|
-
import { ESLint } from "eslint";
|
|
7
|
-
|
|
8
|
-
// src/lib/checkResult.ts
|
|
9
5
|
import chalk from "chalk";
|
|
10
|
-
|
|
11
|
-
if (result) {
|
|
12
|
-
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
13
|
-
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
14
|
-
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
15
|
-
if (exitOnFail) {
|
|
16
|
-
process.exit(result);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}, "checkResult");
|
|
20
|
-
|
|
21
|
-
// src/lib/processEx.ts
|
|
22
|
-
import chalk2 from "chalk";
|
|
23
|
-
|
|
24
|
-
// src/lib/withError.ts
|
|
25
|
-
var withError = /* @__PURE__ */ __name((ex, closure, predicate = (ex2) => !!ex2.name && !!ex2.message) => {
|
|
26
|
-
return predicate(ex) ? closure(ex) : void 0;
|
|
27
|
-
}, "withError");
|
|
28
|
-
|
|
29
|
-
// src/lib/withErrnoException.ts
|
|
30
|
-
var withErrnoException = /* @__PURE__ */ __name((ex, closure) => {
|
|
31
|
-
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
32
|
-
}, "withErrnoException");
|
|
33
|
-
|
|
34
|
-
// src/lib/processEx.ts
|
|
35
|
-
var processEx = /* @__PURE__ */ __name((ex) => {
|
|
36
|
-
const error = typeof ex === "string" ? new Error(ex) : ex;
|
|
37
|
-
const exitCode = withErrnoException(error, (error2) => {
|
|
38
|
-
if (error2.code === "ENOENT") {
|
|
39
|
-
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
40
|
-
} else {
|
|
41
|
-
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
42
|
-
}
|
|
43
|
-
return error2.errno ?? -1;
|
|
44
|
-
}) ?? withError(error, (error2) => {
|
|
45
|
-
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
46
|
-
return -1;
|
|
47
|
-
}) ?? (() => {
|
|
48
|
-
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
49
|
-
return -1;
|
|
50
|
-
})();
|
|
51
|
-
process.exit(process.exitCode ?? exitCode);
|
|
52
|
-
}, "processEx");
|
|
53
|
-
|
|
54
|
-
// src/lib/safeExit.ts
|
|
55
|
-
var safeExit = /* @__PURE__ */ __name((func, exitOnFail = true) => {
|
|
56
|
-
try {
|
|
57
|
-
const result = func();
|
|
58
|
-
if (result && exitOnFail) {
|
|
59
|
-
process.exit(result);
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
} catch (ex) {
|
|
63
|
-
return processEx(ex);
|
|
64
|
-
}
|
|
65
|
-
}, "safeExit");
|
|
6
|
+
import { ESLint } from "eslint";
|
|
66
7
|
|
|
67
8
|
// src/lib/yarn/workspace/yarnWorkspaces.ts
|
|
68
9
|
import { spawnSync } from "node:child_process";
|
|
@@ -84,40 +25,6 @@ var yarnWorkspaces = /* @__PURE__ */ __name(() => {
|
|
|
84
25
|
});
|
|
85
26
|
}, "yarnWorkspaces");
|
|
86
27
|
|
|
87
|
-
// src/lib/runSteps.ts
|
|
88
|
-
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
89
|
-
import { existsSync } from "node:fs";
|
|
90
|
-
import chalk3 from "chalk";
|
|
91
|
-
var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages) => {
|
|
92
|
-
return safeExit(() => {
|
|
93
|
-
const pkgName = process.env.npm_package_name;
|
|
94
|
-
console.log(chalk3.green(`${name} [${pkgName}]`));
|
|
95
|
-
let totalStatus = 0;
|
|
96
|
-
for (const [i, [command, args, config]] of steps.entries()) {
|
|
97
|
-
if (messages?.[i]) {
|
|
98
|
-
console.log(chalk3.gray(messages?.[i]));
|
|
99
|
-
}
|
|
100
|
-
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
101
|
-
if (command === "node" && !existsSync(argList[0])) {
|
|
102
|
-
throw new Error(`File not found [${argList[0]}]`);
|
|
103
|
-
}
|
|
104
|
-
const status = spawnSync2(command, Array.isArray(args) ? args : args.split(" "), {
|
|
105
|
-
...config,
|
|
106
|
-
encoding: "utf8",
|
|
107
|
-
env: {
|
|
108
|
-
FORCE_COLOR: "3",
|
|
109
|
-
...process.env
|
|
110
|
-
},
|
|
111
|
-
shell: true,
|
|
112
|
-
stdio: "inherit"
|
|
113
|
-
}).status ?? 0;
|
|
114
|
-
checkResult(name, status, "error", exitOnFail);
|
|
115
|
-
totalStatus += status ?? 0;
|
|
116
|
-
}
|
|
117
|
-
return totalStatus;
|
|
118
|
-
}, !!exitOnFail);
|
|
119
|
-
}, "runSteps");
|
|
120
|
-
|
|
121
28
|
// src/actions/lint.ts
|
|
122
29
|
var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
123
30
|
const colors = [
|
|
@@ -132,9 +39,9 @@ var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
|
132
39
|
];
|
|
133
40
|
for (const lintResult of lintResults) {
|
|
134
41
|
if (lintResult.messages.length > 0) {
|
|
135
|
-
console.log(
|
|
42
|
+
console.log(chalk.gray(`${lintResult.filePath}`));
|
|
136
43
|
for (const message of lintResult.messages) {
|
|
137
|
-
console.log(
|
|
44
|
+
console.log(chalk.gray(` ${message.line}:${message.column}`), chalk[colors[message.severity]](` ${severity[message.severity]}`), chalk.white(` ${message.message}`), chalk.gray(` ${message.ruleId}`));
|
|
138
45
|
}
|
|
139
46
|
}
|
|
140
47
|
}
|
|
@@ -142,7 +49,7 @@ var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
|
142
49
|
var lintPackage = /* @__PURE__ */ __name(async ({ pkg, fix: fix2 }) => {
|
|
143
50
|
const workspace = yarnWorkspaces().find((workspace2) => workspace2.name === pkg);
|
|
144
51
|
if (!workspace) {
|
|
145
|
-
console.error(
|
|
52
|
+
console.error(chalk.red(`Unable to locate package [${chalk.magenta(pkg)}]`));
|
|
146
53
|
process.exit(1);
|
|
147
54
|
}
|
|
148
55
|
const engine = new ESLint({
|
|
@@ -153,53 +60,23 @@ var lintPackage = /* @__PURE__ */ __name(async ({ pkg, fix: fix2 }) => {
|
|
|
153
60
|
dumpMessages(lintResults);
|
|
154
61
|
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
155
62
|
}, "lintPackage");
|
|
63
|
+
var lintAll = /* @__PURE__ */ __name(async ({ fix: fix2 }) => {
|
|
64
|
+
const workspace = yarnWorkspaces();
|
|
65
|
+
return (await Promise.all(workspace.map((ws) => lintPackage({
|
|
66
|
+
pkg: ws.name,
|
|
67
|
+
fix: fix2
|
|
68
|
+
})))).reduce((prev, curr) => prev + curr, 0);
|
|
69
|
+
}, "lintAll");
|
|
156
70
|
var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental, fix: fix2 } = {}) => {
|
|
157
71
|
return pkg ? await lintPackage({
|
|
158
72
|
pkg,
|
|
159
73
|
fix: fix2
|
|
160
|
-
}) :
|
|
74
|
+
}) : lintAll({
|
|
161
75
|
verbose,
|
|
162
76
|
incremental,
|
|
163
77
|
fix: fix2
|
|
164
78
|
});
|
|
165
79
|
}, "lint");
|
|
166
|
-
var lintAllPackages = /* @__PURE__ */ __name(({ fix: fix2, verbose = true, incremental } = {}) => {
|
|
167
|
-
console.log(chalk4.gray("Linting [All-Packages]"));
|
|
168
|
-
const start = Date.now();
|
|
169
|
-
const verboseOptions = verbose ? [
|
|
170
|
-
"--verbose"
|
|
171
|
-
] : [
|
|
172
|
-
"--no-verbose"
|
|
173
|
-
];
|
|
174
|
-
const fixOptions = fix2 ? [
|
|
175
|
-
"--fix"
|
|
176
|
-
] : [
|
|
177
|
-
""
|
|
178
|
-
];
|
|
179
|
-
const incrementalOptions = incremental ? [
|
|
180
|
-
"--since",
|
|
181
|
-
"-Apt"
|
|
182
|
-
] : [
|
|
183
|
-
"--parallel",
|
|
184
|
-
"-Apt"
|
|
185
|
-
];
|
|
186
|
-
const result = runSteps("Lint [All-Packages]", [
|
|
187
|
-
[
|
|
188
|
-
"yarn",
|
|
189
|
-
[
|
|
190
|
-
"workspaces",
|
|
191
|
-
"foreach",
|
|
192
|
-
...verboseOptions,
|
|
193
|
-
...incrementalOptions,
|
|
194
|
-
"run",
|
|
195
|
-
"package-lint",
|
|
196
|
-
...fixOptions
|
|
197
|
-
]
|
|
198
|
-
]
|
|
199
|
-
]);
|
|
200
|
-
console.log(`${chalk4.gray("Linted in")} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`);
|
|
201
|
-
return result;
|
|
202
|
-
}, "lintAllPackages");
|
|
203
80
|
|
|
204
81
|
// src/actions/fix.ts
|
|
205
82
|
var fix = /* @__PURE__ */ __name(async () => {
|
package/dist/actions/fix.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/lint.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/fix.ts"],"sourcesContent":["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 for (const ws of workspace) {\n await lintPackage({ pkg: ws.name, fix })\n }\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('Linting [All-Packages]'))\n const start = Date.now()\n const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n const fixOptions = fix ? ['--fix'] : ['']\n const incrementalOptions = incremental ? ['--since', '-Apt'] : ['--parallel', '-Apt']\n\n const result = runSteps('Lint [All-Packages]', [\n ['yarn', ['workspaces',\n 'foreach',\n ...verboseOptions,\n ...incrementalOptions,\n 'run',\n 'package-lint',\n ...fixOptions,\n ]],\n ])\n console.log(`${chalk.gray('Linted in')} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`)\n return result\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 { 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 { spawnSync, SpawnSyncOptionsWithBufferEncoding } 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 { lint } from './lint.ts'\n\nexport const fix = async () => {\n return await lint({ fix: true })\n}\n"],"mappings":";;;;AAAA,OAAOA,YAAW;AAClB,SAASC,cAAc;;;ACDvB,OAAOC,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,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAW,CAAC,CAACA,IAAGG,QAAQ,CAAC,CAACH,IAAGI,YAAQ;AAElD,SAAOF,UAAUF,EAAAA,IAAWC,QAAQD,EAAAA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AChB,CAAC,MAAC;AAChB,SAAOH,MACH,MAAMI,YAAY;IAAEJ;IAAKG,KAAAA;EAAI,CAAA,IAC7BE,gBAAgB;IACdJ;IAASC;IAAaC,KAAAA;EACxB,CAAA;AACN,GARoB;AAUb,IAAME,kBAAkB,wBAAC,EAC9BF,KAAAA,MAAKF,UAAU,MAAMC,YAAW,IAClB,CAAC,MAAC;AAChBI,UAAQC,IAAIC,OAAMC,KAAK,wBAAA,CAAA;AACvB,QAAMC,QAAQC,KAAKC,IAAG;AACtB,QAAMC,iBAAiBZ,UAAU;IAAC;MAAe;IAAC;;AAClD,QAAMa,aAAaX,OAAM;IAAC;MAAW;IAAC;;AACtC,QAAMY,qBAAqBb,cAAc;IAAC;IAAW;MAAU;IAAC;IAAc;;AAE9E,QAAMc,SAASC,SAAS,uBAAuB;IAC7C;MAAC;MAAQ;QAAC;QACR;WACGJ;WACAE;QACH;QACA;WACGD;;;GAEN;AACDR,UAAQC,IAAI,GAAGC,OAAMC,KAAK,WAAA,CAAA,KAAiBD,OAAMU,UAAUP,KAAKC,IAAG,IAAKF,SAAS,KAAMS,QAAQ,CAAA,CAAA,CAAA,KAAQX,OAAMC,KAAK,SAAA,CAAA,EAAY;AAC9H,SAAOO;AACT,GArB+B;;;AQnExB,IAAMI,MAAM,mCAAA;AACjB,SAAO,MAAMC,KAAK;IAAED,KAAK;EAAK,CAAA;AAChC,GAFmB;","names":["chalk","ESLint","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","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","fixOptions","incrementalOptions","result","runSteps","magenta","toFixed","fix","lint"]}
|
|
1
|
+
{"version":3,"sources":["../../src/actions/lint.ts","../../src/lib/yarn/workspace/yarnWorkspaces.ts","../../src/actions/fix.ts"],"sourcesContent":["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 : lintAll({\n verbose, incremental, fix,\n })\n}\n\nexport const lintAllPackages = ({\n fix, verbose = true, incremental,\n}: LintParams = {}) => {\n console.log(chalk.gray('Linting [All-Packages]'))\n const start = Date.now()\n const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n const fixOptions = fix ? ['--fix'] : ['']\n const incrementalOptions = incremental ? ['--since', '-Apt'] : ['--parallel', '-Apt']\n\n const result = runSteps('Lint [All-Packages]', [\n ['yarn', ['workspaces',\n 'foreach',\n ...verboseOptions,\n ...incrementalOptions,\n 'run',\n 'package-lint',\n ...fixOptions,\n ]],\n ])\n console.log(`${chalk.gray('Linted in')} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`)\n return result\n}\n","import { spawnSync } from 'node:child_process'\n\nimport { 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 { lint } from './lint.ts'\n\nexport const fix = async () => {\n return await lint({ fix: true })\n}\n"],"mappings":";;;;AAAA,OAAOA,WAAW;AAClB,SAASC,cAAc;;;ACDvB,SAASC,iBAAiB;AAInB,IAAMC,iBAAiB,6BAAA;AAC5B,QAAMC,SAASC,UAA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AAI,CAAA;AAE7C,QAAMlB,cAAc,MAAM4B,OAAOG,UAAUZ,UAAUa,QAAQ;AAE7DjC,eAAaC,WAAAA;AAEb,SAAOA,YAAYiC,OAAO,CAACC,MAAM/B,eAAe+B,OAAO/B,WAAWgC,YAAY,CAAA;AAChF,GAd2B;AAgBpB,IAAMC,UAAU,8BAAO,EAAElB,KAAAA,KAAG,MAAc;AAC/C,QAAMC,YAAYC,eAAAA;AAClB,UAAQ,MAAMiB,QAAQC,IAAInB,UAAUoB,IAAIC,CAAAA,OACtCxB,YAAY;IAAEC,KAAKuB,GAAGlB;IAAMJ,KAAAA;EAAI,CAAA,CAAA,CAAA,GAAMe,OAAO,CAACC,MAAMO,SAASP,OAAOO,MAAM,CAAA;AAC9E,GAJuB;AAMhB,IAAMC,OAAO,8BAAO,EACzBzB,KAAK0B,SAASC,aAAa1B,KAAAA,KAAG,IAChB,CAAC,MAAC;AAChB,SAAOD,MACH,MAAMD,YAAY;IAAEC;IAAKC,KAAAA;EAAI,CAAA,IAC7BkB,QAAQ;IACNO;IAASC;IAAa1B,KAAAA;EACxB,CAAA;AACN,GARoB;;;AExDb,IAAM2B,MAAM,mCAAA;AACjB,SAAO,MAAMC,KAAK;IAAED,KAAK;EAAK,CAAA;AAChC,GAFmB;","names":["chalk","ESLint","spawnSync","yarnWorkspaces","result","spawnSync","encoding","shell","error","stdout","toString","split","slice","map","item","JSON","parse","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","lintAll","Promise","all","map","ws","curr","lint","verbose","incremental","fix","lint"]}
|
package/dist/actions/index.mjs
CHANGED
|
@@ -952,18 +952,16 @@ var lintPackage = /* @__PURE__ */ __name(async ({ pkg, fix: fix2 }) => {
|
|
|
952
952
|
}, "lintPackage");
|
|
953
953
|
var lintAll = /* @__PURE__ */ __name(async ({ fix: fix2 }) => {
|
|
954
954
|
const workspace = yarnWorkspaces();
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
});
|
|
960
|
-
}
|
|
955
|
+
return (await Promise.all(workspace.map((ws) => lintPackage({
|
|
956
|
+
pkg: ws.name,
|
|
957
|
+
fix: fix2
|
|
958
|
+
})))).reduce((prev, curr) => prev + curr, 0);
|
|
961
959
|
}, "lintAll");
|
|
962
960
|
var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental, fix: fix2 } = {}) => {
|
|
963
961
|
return pkg ? await lintPackage({
|
|
964
962
|
pkg,
|
|
965
963
|
fix: fix2
|
|
966
|
-
}) :
|
|
964
|
+
}) : lintAll({
|
|
967
965
|
verbose,
|
|
968
966
|
incremental,
|
|
969
967
|
fix: fix2
|