@xylabs/ts-scripts-yarn3 6.0.3 → 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 +93 -119
- 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/relint.mjs +61 -45
- package/dist/actions/relint.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 +28 -22
- package/dist/index.mjs +109 -133
- 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/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/dist/actions/lint.mjs
CHANGED
|
@@ -3,7 +3,6 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/actions/lint.ts
|
|
5
5
|
import chalk4 from "chalk";
|
|
6
|
-
import { ESLint } from "eslint";
|
|
7
6
|
|
|
8
7
|
// src/lib/checkResult.ts
|
|
9
8
|
import chalk from "chalk";
|
|
@@ -64,28 +63,8 @@ var safeExit = /* @__PURE__ */ __name((func, exitOnFail = true) => {
|
|
|
64
63
|
}
|
|
65
64
|
}, "safeExit");
|
|
66
65
|
|
|
67
|
-
// src/lib/yarn/workspace/yarnWorkspaces.ts
|
|
68
|
-
import { spawnSync } from "node:child_process";
|
|
69
|
-
var yarnWorkspaces = /* @__PURE__ */ __name(() => {
|
|
70
|
-
const result = spawnSync("yarn", [
|
|
71
|
-
"workspaces",
|
|
72
|
-
"list",
|
|
73
|
-
"--json",
|
|
74
|
-
"--recursive"
|
|
75
|
-
], {
|
|
76
|
-
encoding: "utf8",
|
|
77
|
-
shell: true
|
|
78
|
-
});
|
|
79
|
-
if (result.error) {
|
|
80
|
-
throw result.error;
|
|
81
|
-
}
|
|
82
|
-
return result.stdout.toString().split("\n").slice(0, -1).map((item) => {
|
|
83
|
-
return JSON.parse(item);
|
|
84
|
-
});
|
|
85
|
-
}, "yarnWorkspaces");
|
|
86
|
-
|
|
87
66
|
// src/lib/runSteps.ts
|
|
88
|
-
import { spawnSync
|
|
67
|
+
import { spawnSync } from "node:child_process";
|
|
89
68
|
import { existsSync } from "node:fs";
|
|
90
69
|
import chalk3 from "chalk";
|
|
91
70
|
var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages) => {
|
|
@@ -101,7 +80,7 @@ var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages)
|
|
|
101
80
|
if (command === "node" && !existsSync(argList[0])) {
|
|
102
81
|
throw new Error(`File not found [${argList[0]}]`);
|
|
103
82
|
}
|
|
104
|
-
const status =
|
|
83
|
+
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
105
84
|
...config,
|
|
106
85
|
encoding: "utf8",
|
|
107
86
|
env: {
|
|
@@ -119,49 +98,31 @@ var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages)
|
|
|
119
98
|
}, "runSteps");
|
|
120
99
|
|
|
121
100
|
// src/actions/lint.ts
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"
|
|
127
|
-
]
|
|
128
|
-
|
|
129
|
-
"none",
|
|
130
|
-
"warning",
|
|
131
|
-
"error"
|
|
101
|
+
var lintPackage = /* @__PURE__ */ __name(({ pkg, fix, verbose }) => {
|
|
102
|
+
console.log(chalk4.gray(`${fix ? "Fix" : "Lint"} [All-Packages]`));
|
|
103
|
+
const start = Date.now();
|
|
104
|
+
const verboseOptions = verbose ? [
|
|
105
|
+
"--verbose"
|
|
106
|
+
] : [
|
|
107
|
+
"--no-verbose"
|
|
132
108
|
];
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
const engine = new ESLint({
|
|
149
|
-
cache: true,
|
|
150
|
-
fix
|
|
151
|
-
});
|
|
152
|
-
const lintResults = await engine.lintFiles(workspace.location);
|
|
153
|
-
dumpMessages(lintResults);
|
|
154
|
-
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
109
|
+
const result = runSteps(`${fix ? "Fix" : "Lint"} [All-Packages]`, [
|
|
110
|
+
[
|
|
111
|
+
"yarn",
|
|
112
|
+
[
|
|
113
|
+
"workspace",
|
|
114
|
+
pkg,
|
|
115
|
+
...verboseOptions,
|
|
116
|
+
"run",
|
|
117
|
+
fix ? "package-fix" : "package-lint"
|
|
118
|
+
]
|
|
119
|
+
]
|
|
120
|
+
]);
|
|
121
|
+
console.log(chalk4.gray(`${fix ? "Fixed in" : "Linted in"} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`));
|
|
122
|
+
return result;
|
|
155
123
|
}, "lintPackage");
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
return (await Promise.all(workspace.map((ws) => lintPackage({
|
|
159
|
-
pkg: ws.name,
|
|
160
|
-
fix
|
|
161
|
-
})))).reduce((prev, curr) => prev + curr, 0);
|
|
162
|
-
}, "lintAll");
|
|
163
|
-
var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental, fix } = {}) => {
|
|
164
|
-
return pkg ? await lintPackage({
|
|
124
|
+
var lint = /* @__PURE__ */ __name(({ pkg, verbose, incremental, fix } = {}) => {
|
|
125
|
+
return pkg ? lintPackage({
|
|
165
126
|
pkg,
|
|
166
127
|
fix
|
|
167
128
|
}) : lintAllPackages({
|
|
@@ -203,7 +164,6 @@ var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental
|
|
|
203
164
|
}, "lintAllPackages");
|
|
204
165
|
export {
|
|
205
166
|
lint,
|
|
206
|
-
lintAll,
|
|
207
167
|
lintAllPackages,
|
|
208
168
|
lintPackage
|
|
209
169
|
};
|
|
@@ -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"],"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 : 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","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"],"mappings":";;;;AAAA,OAAOA,YAAW;AAClB,SAASC,cAAc;;;ACDvB,OAAOC,WAAW;AAEX,IAAMC,cAAc,wBAACC,MAAcC,QAAgBC,QAA0B,SAASC,aAAa,UAAK;AAC7G,MAAIF,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;WACAC;QACH;QACAhC,MAAM,gBAAgB;;;GAEzB;AACDZ,UAAQC,IAAIC,OAAMC,KAAK,GAAGS,MAAM,aAAa,WAAA,KAAgBV,OAAMiB,UAAUsB,KAAKC,IAAG,IAAKF,SAAS,KAAMO,QAAQ,CAAA,CAAA,CAAA,KAAQ7C,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAChJ,SAAO0C;AACT,GAnB+B;","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","lintAll","Promise","all","map","ws","curr","lint","verbose","incremental","lintAllPackages","start","Date","now","verboseOptions","incrementalOptions","result","runSteps","toFixed"]}
|
|
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/runSteps.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { runSteps } 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\nexport const lintPackage = ({\n pkg, fix, verbose,\n}: LintParams & Required<Pick<LintParams, 'pkg'>>) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [All-Packages]`))\n const start = Date.now()\n const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [All-Packages]`, [\n ['yarn', ['workspace',\n pkg,\n ...verboseOptions,\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\nexport const lint = ({\n pkg, verbose, incremental, fix,\n}: LintParams = {}) => {\n return pkg\n ? 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","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"],"mappings":";;;;AAAA,OAAOA,YAAW;;;ACAlB,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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AQ,MAAA,oBAA0B;IACjE;MAAC;MAAQ;QAAC;QACRD;WACGU;QACH;QACAT,MAAM,gBAAgB;;;GAEzB;AACDE,UAAQC,IAAIC,OAAMC,KAAK,GAAGL,MAAM,aAAa,WAAA,KAAgBI,OAAMQ,UAAUL,KAAKC,IAAG,IAAKF,SAAS,KAAMO,QAAQ,CAAA,CAAA,CAAA,KAAQT,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAChJ,SAAOK;AACT,GAjB2B;AAmBpB,IAAMI,OAAO,wBAAC,EACnBf,KAAKE,SAASc,aAAaf,IAAG,IAChB,CAAC,MAAC;AAChB,SAAOD,MACHD,YAAY;IAAEC;IAAKC;EAAI,CAAA,IACvBgB,gBAAgB;IACdf;IAASc;IAAaf;EACxB,CAAA;AACN,GARoB;AAUb,IAAMgB,kBAAkB,wBAAC,EAC9BhB,KAAKC,UAAU,MAAMc,YAAW,IAClB,CAAC,MAAC;AAChBb,UAAQC,IAAIC,OAAMC,KAAK,GAAGL,MAAM,QAAQ,MAAA,iBAAuB,CAAA;AAC/D,QAAMM,QAAQC,KAAKC,IAAG;AACtB,QAAMC,iBAAiBR,UAAU;IAAC;MAAe;IAAC;;AAClD,QAAMgB,qBAAqBF,cAAc;IAAC;IAAW;MAAS;IAAC;IAAc;;AAE7E,QAAML,SAASC,SAAS,GAAGX,MAAM,QAAQ,MAAA,oBAA0B;IACjE;MAAC;MAAQ;QAAC;QACR;WACGS;WACAQ;QACH;QACAjB,MAAM,gBAAgB;;;GAEzB;AACDE,UAAQC,IAAIC,OAAMC,KAAK,GAAGL,MAAM,aAAa,WAAA,KAAgBI,OAAMQ,UAAUL,KAAKC,IAAG,IAAKF,SAAS,KAAMO,QAAQ,CAAA,CAAA,CAAA,KAAQT,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAChJ,SAAOK;AACT,GAnB+B;","names":["chalk","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","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","lintPackage","pkg","fix","verbose","console","log","chalk","gray","start","Date","now","verboseOptions","result","runSteps","magenta","toFixed","lint","incremental","lintAllPackages","incrementalOptions"]}
|
package/dist/actions/relint.mjs
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/actions/relint.ts
|
|
5
|
-
import
|
|
5
|
+
import chalk4 from "chalk";
|
|
6
6
|
|
|
7
7
|
// src/lib/checkResult.ts
|
|
8
8
|
import chalk from "chalk";
|
|
@@ -63,28 +63,8 @@ var safeExit = /* @__PURE__ */ __name((func, exitOnFail = true) => {
|
|
|
63
63
|
}
|
|
64
64
|
}, "safeExit");
|
|
65
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
66
|
// src/lib/runSteps.ts
|
|
87
|
-
import { spawnSync
|
|
67
|
+
import { spawnSync } from "node:child_process";
|
|
88
68
|
import { existsSync } from "node:fs";
|
|
89
69
|
import chalk3 from "chalk";
|
|
90
70
|
var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages) => {
|
|
@@ -100,7 +80,7 @@ var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages)
|
|
|
100
80
|
if (command === "node" && !existsSync(argList[0])) {
|
|
101
81
|
throw new Error(`File not found [${argList[0]}]`);
|
|
102
82
|
}
|
|
103
|
-
const status =
|
|
83
|
+
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
104
84
|
...config,
|
|
105
85
|
encoding: "utf8",
|
|
106
86
|
env: {
|
|
@@ -118,35 +98,71 @@ var runSteps = /* @__PURE__ */ __name((name, steps, exitOnFail = true, messages)
|
|
|
118
98
|
}, "runSteps");
|
|
119
99
|
|
|
120
100
|
// src/actions/relint.ts
|
|
121
|
-
var
|
|
122
|
-
console.log("Relint -
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
return 0;
|
|
132
|
-
} catch (ex) {
|
|
133
|
-
const error = ex;
|
|
134
|
-
console.error(`Relint - Cleaning [.eslintcache] Failed [${name}, ${error.message}]`);
|
|
135
|
-
return 1;
|
|
136
|
-
}
|
|
137
|
-
}).reduce((prev, result2) => prev || result2, 0);
|
|
138
|
-
return result || runSteps("Relint", [
|
|
101
|
+
var relintPackage = /* @__PURE__ */ __name(({ pkg, verbose }) => {
|
|
102
|
+
console.log(chalk4.gray(`${"Relint"} [All-Packages]`));
|
|
103
|
+
const start = Date.now();
|
|
104
|
+
const verboseOptions = verbose ? [
|
|
105
|
+
"--verbose"
|
|
106
|
+
] : [
|
|
107
|
+
"--no-verbose"
|
|
108
|
+
];
|
|
109
|
+
const result = runSteps("Relint [All-Packages]", [
|
|
139
110
|
[
|
|
140
111
|
"yarn",
|
|
141
112
|
[
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
|
|
113
|
+
"workspace",
|
|
114
|
+
pkg,
|
|
115
|
+
...verboseOptions,
|
|
116
|
+
"run",
|
|
117
|
+
"package-relint"
|
|
145
118
|
]
|
|
146
119
|
]
|
|
147
120
|
]);
|
|
121
|
+
console.log(chalk4.gray(`${"Relinted in"} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`));
|
|
122
|
+
return result;
|
|
123
|
+
}, "relintPackage");
|
|
124
|
+
var relint = /* @__PURE__ */ __name(({ pkg, verbose, incremental } = {}) => {
|
|
125
|
+
return pkg ? relintPackage({
|
|
126
|
+
pkg
|
|
127
|
+
}) : relintAllPackages({
|
|
128
|
+
verbose,
|
|
129
|
+
incremental
|
|
130
|
+
});
|
|
148
131
|
}, "relint");
|
|
132
|
+
var relintAllPackages = /* @__PURE__ */ __name(({ verbose = true, incremental } = {}) => {
|
|
133
|
+
console.log(chalk4.gray(`${"Relint"} [All-Packages]`));
|
|
134
|
+
const start = Date.now();
|
|
135
|
+
const verboseOptions = verbose ? [
|
|
136
|
+
"--verbose"
|
|
137
|
+
] : [
|
|
138
|
+
"--no-verbose"
|
|
139
|
+
];
|
|
140
|
+
const incrementalOptions = incremental ? [
|
|
141
|
+
"--since",
|
|
142
|
+
"-Ap"
|
|
143
|
+
] : [
|
|
144
|
+
"--parallel",
|
|
145
|
+
"-Ap"
|
|
146
|
+
];
|
|
147
|
+
const result = runSteps(`${"Relint"} [All-Packages]`, [
|
|
148
|
+
[
|
|
149
|
+
"yarn",
|
|
150
|
+
[
|
|
151
|
+
"workspaces",
|
|
152
|
+
"foreach",
|
|
153
|
+
...verboseOptions,
|
|
154
|
+
...incrementalOptions,
|
|
155
|
+
"run",
|
|
156
|
+
"package-relint"
|
|
157
|
+
]
|
|
158
|
+
]
|
|
159
|
+
]);
|
|
160
|
+
console.log(chalk4.gray(`Relinted in [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`));
|
|
161
|
+
return result;
|
|
162
|
+
}, "relintAllPackages");
|
|
149
163
|
export {
|
|
150
|
-
relint
|
|
164
|
+
relint,
|
|
165
|
+
relintAllPackages,
|
|
166
|
+
relintPackage
|
|
151
167
|
};
|
|
152
168
|
//# sourceMappingURL=relint.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/relint.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"],"sourcesContent":["import { rmSync } from 'node:fs'\n\nimport { runSteps, yarnWorkspaces } from '../lib/index.ts'\n\nexport const relint = () => {\n console.log('Relint - Cleaning [.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(`Relint - Cleaning [.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 || runSteps('Relint', [['yarn', ['eslint', '.', '--cache']]])\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"],"mappings":";;;;AAAA,SAASA,cAAc;;;ACAvB,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,O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IAAAA,IAAQA,OAAOA,KAAKO,MAAM,GAAA,GAAM;QACjE,GAAGN;QACHW,UAAU;QACVrB,KAAK;UAAEsB,aAAa;UAAK,GAAGvB,QAAQC;QAAI;QACxCuB,OAAO;QACPC,OAAO;MACT,CAAA,EAAGL,UAAU;AACfM,kBAAYhC,MAAM0B,QAAQ,SAASxB,UAAAA;AACnCW,qBAAea,UAAU;IAC3B;AACA,WAAOb;EACT,GAAG,CAAC,CAACX,UAAAA;AACP,GA1BwB;;;APTjB,IAAM+B,SAAS,6BAAA;AACpBC,UAAQC,IAAI,kCAAA;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,4CAA4CN,IAAAA,KAASM,MAAMC,OAAO,GAAG;AACnF,aAAO;IACT;EACF,CAAA,EAECC,OAAO,CAACC,MAAMZ,YAAWY,QAAQZ,SAAQ,CAAA;AAC5C,SAAOA,UAAUa,SAAS,UAAU;IAAC;MAAC;MAAQ;QAAC;QAAU;QAAK;;;GAAY;AAC5E,GAlBsB;","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","relint","console","log","workspaces","yarnWorkspaces","result","map","location","name","dist","rmSync","force","recursive","ex","error","message","reduce","prev","runSteps"]}
|
|
1
|
+
{"version":3,"sources":["../../src/actions/relint.ts","../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts"],"sourcesContent":["import chalk from 'chalk'\nimport type { ESLint } from 'eslint'\n\nimport { runSteps, yarnWorkspaces } from '../lib/index.ts'\n\nexport interface RelintParams {\n incremental?: boolean\n pkg?: string\n verbose?: boolean\n}\n\nexport interface RelintPackageParams {\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 relintPackage = ({ pkg, verbose }: RelintParams & Required<Pick<RelintParams, 'pkg'>>) => {\n console.log(chalk.gray(`${'Relint'} [All-Packages]`))\n const start = Date.now()\n const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n\n const result = runSteps('Relint [All-Packages]', [\n ['yarn', ['workspace',\n pkg,\n ...verboseOptions,\n 'run',\n 'package-relint',\n ]],\n ])\n console.log(chalk.gray(`${'Relinted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n\nexport const relint = ({\n pkg, verbose, incremental,\n}: RelintParams = {}) => {\n return pkg\n ? relintPackage({ pkg })\n : relintAllPackages({ verbose, incremental })\n}\n\nexport const relintAllPackages = ({ verbose = true, incremental }: RelintParams = {}) => {\n console.log(chalk.gray(`${'Relint'} [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(`${'Relint'} [All-Packages]`, [\n ['yarn', ['workspaces',\n 'foreach',\n ...verboseOptions,\n ...incrementalOptions,\n 'run',\n 'package-relint',\n ]],\n ])\n console.log(chalk.gray(`Relinted 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 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"],"mappings":";;;;AAAA,OAAOA,YAAW;;;ACAlB,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,IAAWK;AACjD,GAPyB;;;ACElB,IAAMC,qBAAqB,wBAChCC,IAAaC,YAAAA;AAEb,SAAOC,UAAaF,IAAIC,SAAS,CAACD,QAAiBA,IAA6BG,UAAUC,MAAAA;AAC5F,GAJkC;;;AFG3B,IAAMC,YAAY,wBAACC,OAAAA;AACxB,QAAMC,QAAQ,OAAOD,OAAO,WAAW,IAAIE,MAAMF,EAAAA,IAAMA;AACvD,QAAMG,WACFC,mBAAmBH,OAAO,CAACA,WAAAA;AAC3B,QAAIA,OAAMI,SAAS,UAAU;AAC3BC,cAAQL,MAAMM,OAAMC,IAAI,IAAIP,OAAMQ,IAAI,cAAc,CAAA;IACtD,OAAO;AACLH,cAAQL,MAAMM,OAAMC,IAAI,UAAUP,OAAMI,IAAI,EAAE,CAAA;IAChD;AACA,WAAOJ,OAAMS,SAAS;E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AAC;MAAe;IAAC;;AAClD,QAAMgB,qBAAqBF,cAAc;IAAC;IAAW;MAAS;IAAC;IAAc;;AAE7E,QAAML,SAASC,SAAS,GAAG,QAAA,oBAA4B;IACrD;MAAC;MAAQ;QAAC;QACR;WACGF;WACAQ;QACH;QACA;;;GAEH;AACDf,UAAQC,IAAIC,OAAMC,KAAK,gBAAgBD,OAAMQ,UAAUL,KAAKC,IAAG,IAAKF,SAAS,KAAMO,QAAQ,CAAA,CAAA,CAAA,KAAQT,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAC1H,SAAOK;AACT,GAjBiC;","names":["chalk","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","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","relintPackage","pkg","verbose","console","log","chalk","gray","start","Date","now","verboseOptions","result","runSteps","magenta","toFixed","relint","incremental","relintAllPackages","incrementalOptions"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
|
|
5
|
+
// src/bin/package/relint.ts
|
|
6
|
+
import chalk2 from "chalk";
|
|
7
|
+
|
|
8
|
+
// src/actions/package/lint.ts
|
|
9
|
+
import { readdirSync } from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { cwd } from "node:process";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
import { ESLint } from "eslint";
|
|
15
|
+
import { findUp } from "find-up";
|
|
16
|
+
import picomatch from "picomatch";
|
|
17
|
+
var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
18
|
+
const colors = [
|
|
19
|
+
"white",
|
|
20
|
+
"yellow",
|
|
21
|
+
"red"
|
|
22
|
+
];
|
|
23
|
+
const severity = [
|
|
24
|
+
"none",
|
|
25
|
+
"warning",
|
|
26
|
+
"error"
|
|
27
|
+
];
|
|
28
|
+
for (const lintResult of lintResults) {
|
|
29
|
+
if (lintResult.messages.length > 0) {
|
|
30
|
+
console.log(chalk.gray(`
|
|
31
|
+
${lintResult.filePath}`));
|
|
32
|
+
for (const message of lintResult.messages) {
|
|
33
|
+
console.log(chalk.gray(` ${message.line}:${message.column}`), chalk[colors[message.severity]](` ${severity[message.severity]}`), chalk.white(` ${message.message}`), chalk.gray(` ${message.ruleId}`));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, "dumpMessages");
|
|
38
|
+
async function getRootESLintConfig() {
|
|
39
|
+
const configPath = await findUp("eslint.config.mjs");
|
|
40
|
+
if (!configPath) {
|
|
41
|
+
throw new Error("eslint.config.mjs not found in the monorepo");
|
|
42
|
+
}
|
|
43
|
+
return pathToFileURL(configPath);
|
|
44
|
+
}
|
|
45
|
+
__name(getRootESLintConfig, "getRootESLintConfig");
|
|
46
|
+
function getFiles(dir, ignoreFolders) {
|
|
47
|
+
const currentDirectory = cwd();
|
|
48
|
+
const subDirectory = dir.split(currentDirectory)[1];
|
|
49
|
+
if (ignoreFolders.includes(subDirectory)) return [];
|
|
50
|
+
return readdirSync(dir, {
|
|
51
|
+
withFileTypes: true
|
|
52
|
+
}).flatMap((dirent) => {
|
|
53
|
+
const res = path.resolve(dir, dirent.name);
|
|
54
|
+
const relativePath = subDirectory ? `${subDirectory}/${dirent.name}` : dirent.name;
|
|
55
|
+
const ignoreMatchers = ignoreFolders.map((pattern) => picomatch(pattern));
|
|
56
|
+
if (ignoreMatchers.some((isMatch) => isMatch(relativePath))) return [];
|
|
57
|
+
return dirent.isDirectory() ? getFiles(res, ignoreFolders) : [
|
|
58
|
+
res
|
|
59
|
+
];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
__name(getFiles, "getFiles");
|
|
63
|
+
var packageLint = /* @__PURE__ */ __name(async (fix = false, verbose = false, cache = true) => {
|
|
64
|
+
const pkg = process.env.INIT_CWD;
|
|
65
|
+
const configPath = await getRootESLintConfig();
|
|
66
|
+
const { default: eslintConfig } = await import(configPath.href);
|
|
67
|
+
const ignoreFolders = [
|
|
68
|
+
"node_modules",
|
|
69
|
+
"dist",
|
|
70
|
+
"packages",
|
|
71
|
+
".git",
|
|
72
|
+
"build",
|
|
73
|
+
".yarn",
|
|
74
|
+
".vscode",
|
|
75
|
+
".github"
|
|
76
|
+
];
|
|
77
|
+
const engine = new ESLint({
|
|
78
|
+
baseConfig: [
|
|
79
|
+
...eslintConfig
|
|
80
|
+
],
|
|
81
|
+
fix,
|
|
82
|
+
warnIgnored: false,
|
|
83
|
+
cache
|
|
84
|
+
});
|
|
85
|
+
const files = getFiles(cwd(), ignoreFolders);
|
|
86
|
+
if (verbose) {
|
|
87
|
+
console.log(chalk.green(`Linting ${pkg} [files = ${files.length}]`));
|
|
88
|
+
}
|
|
89
|
+
const lintResults = await engine.lintFiles(files);
|
|
90
|
+
dumpMessages(lintResults);
|
|
91
|
+
if (fix) {
|
|
92
|
+
await ESLint.outputFixes(lintResults);
|
|
93
|
+
}
|
|
94
|
+
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
95
|
+
}, "packageLint");
|
|
96
|
+
|
|
97
|
+
// src/bin/package/relint.ts
|
|
98
|
+
packageLint(false, false, true).then((value) => {
|
|
99
|
+
if (value) {
|
|
100
|
+
process.exit(value);
|
|
101
|
+
}
|
|
102
|
+
}).catch((reason) => {
|
|
103
|
+
console.error(chalk2.red(reason));
|
|
104
|
+
process.exit(-1);
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=relint.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/package/relint.ts","../../../src/actions/package/lint.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport chalk from 'chalk'\n\nimport { packageLint } from '../../actions/index.ts'\n\npackageLint(false, false, true)\n .then((value) => {\n if (value) {\n process.exit(value)\n }\n })\n .catch((reason) => {\n console.error(chalk.red(reason))\n process.exit(-1)\n })\n","import { readdirSync } from 'node:fs'\nimport path from 'node:path'\nimport { cwd } from 'node:process'\nimport { pathToFileURL } from 'node:url'\n\nimport chalk from 'chalk'\nimport { ESLint } from 'eslint'\nimport { findUp } from 'find-up'\nimport picomatch from 'picomatch'\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(`\\n${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\nasync function getRootESLintConfig() {\n // Locate the root eslint.config.mjs\n const configPath = await findUp('eslint.config.mjs')\n\n if (!configPath) {\n throw new Error('eslint.config.mjs not found in the monorepo')\n }\n\n return pathToFileURL(configPath)\n}\n\nfunction getFiles(dir: string, ignoreFolders: string[]): string[] {\n const currentDirectory = cwd()\n const subDirectory = dir.split(currentDirectory)[1]\n if (ignoreFolders.includes(subDirectory)) return []\n return readdirSync(dir, { withFileTypes: true })\n .flatMap((dirent) => {\n const res = path.resolve(dir, dirent.name)\n const relativePath = subDirectory ? `${subDirectory}/${dirent.name}` : dirent.name\n\n const ignoreMatchers = ignoreFolders.map(pattern => picomatch(pattern))\n\n // Exclude ignored paths\n if (ignoreMatchers.some(isMatch => isMatch(relativePath))) return []\n\n return dirent.isDirectory()\n ? getFiles(res, ignoreFolders)\n : [res]\n })\n}\n\nexport const packageLint = async (fix = false, verbose = false, cache = true) => {\n const pkg = process.env.INIT_CWD\n const configPath = await getRootESLintConfig()\n const { default: eslintConfig } = await import(configPath.href)\n\n // List of folders to ignore\n const ignoreFolders = ['node_modules', 'dist', 'packages', '.git', 'build', '.yarn', '.vscode', '.github']\n\n const engine = new ESLint({\n baseConfig: [...eslintConfig], fix, warnIgnored: false, cache,\n })\n\n const files = getFiles(cwd(), ignoreFolders)\n if (verbose) {\n console.log(chalk.green(`Linting ${pkg} [files = ${files.length}]`))\n }\n const lintResults = await engine.lintFiles(files)\n\n dumpMessages(lintResults)\n\n if (fix) {\n await ESLint.outputFixes(lintResults)\n }\n\n return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0)\n}\n"],"mappings":";;;;;AAEA,OAAOA,YAAW;;;ACFlB,SAASC,mBAAmB;AAC5B,OAAOC,UAAU;AACjB,SAASC,WAAW;AACpB,SAASC,qBAAqB;AAE9B,OAAOC,WAAW;AAClB,SAASC,cAAc;AACvB,SAASC,cAAc;AACvB,OAAOC,eAAe;AAEtB,IAAMC,eAAe,wBAACC,gBAAAA;AACpB,QAAMC,SAAyC;IAAC;IAAS;IAAU;;AACnE,QAAMC,WAAqB;IAAC;IAAQ;IAAW;;AAE/C,aAAWC,cAAcH,aAAa;AACpC,QAAIG,WAAWC,SAASC,SAAS,GAAG;AAClCC,cAAQC,IAAIC,MAAMC,KAAK;EAAKN,WAAWO,QAAQ,EAAE,CAAA;AACjD,iBAAWC,WAAWR,WAAWC,UAAU;AACzCE,gBAAQC,IACNC,MAAMC,KAAK,IAAKE,QAAQC,IAAI,IAAID,QAAQE,MAAM,EAAE,GAChDL,MAAMP,OAAOU,QAAQT,QAAQ,CAAC,EAA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AQ;IAAS;IAAS;IAAW;;AAEhG,QAAMiC,SAAS,IAAIC,OAAO;IACxBC,YAAY;SAAIJ;;IAAeR;IAAKa,aAAa;IAAOX;EAC1D,CAAA;AAEA,QAAMY,QAAQvC,SAASI,IAAAA,GAAOF,aAAAA;AAC9B,MAAIwB,SAAS;AACXzC,YAAQC,IAAIC,MAAMqD,MAAM,WAAWZ,GAAAA,aAAgBW,MAAMvD,MAAM,GAAG,CAAA;EACpE;AACA,QAAML,cAAc,MAAMwD,OAAOM,UAAUF,KAAAA;AAE3C7D,eAAaC,WAAAA;AAEb,MAAI8C,KAAK;AACP,UAAMW,OAAOM,YAAY/D,WAAAA;EAC3B;AAEA,SAAOA,YAAYgE,OAAO,CAACC,MAAM9D,eAAe8D,OAAO9D,WAAW+D,YAAY,CAAA;AAChF,GAzB2B;;;ADtD3BC,YAAY,OAAO,OAAO,IAAA,EACvBC,KAAK,CAACC,UAAAA;AACL,MAAIA,OAAO;AACTC,YAAQC,KAAKF,KAAAA;EACf;AACF,CAAA,EACCG,MAAM,CAACC,WAAAA;AACNC,UAAQC,MAAMC,OAAMC,IAAIJ,MAAAA,CAAAA;AACxBH,UAAQC,KAAK,EAAC;AAChB,CAAA;","names":["chalk","readdirSync","path","cwd","pathToFileURL","chalk","ESLint","findUp","picomatch","dumpMessages","lintResults","colors","severity","lintResult","messages","length","console","log","chalk","gray","filePath","message","line","column","white","ruleId","getRootESLintConfig","configPath","findUp","Error","pathToFileURL","getFiles","dir","ignoreFolders","currentDirectory","cwd","subDirectory","split","includes","readdirSync","withFileTypes","flatMap","dirent","res","path","resolve","name","relativePath","ignoreMatchers","map","pattern","picomatch","some","isMatch","isDirectory","packageLint","fix","verbose","cache","pkg","process","env","INIT_CWD","default","eslintConfig","href","engine","ESLint","baseConfig","warnIgnored","files","green","lintFiles","outputFixes","reduce","prev","errorCount","packageLint","then","value","process","exit","catch","reason","console","error","chalk","red"]}
|