@xylabs/ts-scripts-yarn3 5.1.6 → 5.1.8
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 +4 -10
- package/dist/actions/fix.mjs.map +1 -1
- package/dist/actions/index.mjs +30 -31
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/lint-clean.mjs +4 -10
- package/dist/actions/lint-clean.mjs.map +1 -1
- package/dist/actions/lint.mjs +4 -10
- package/dist/actions/lint.mjs.map +1 -1
- package/dist/actions/package/index.mjs +26 -21
- package/dist/actions/package/index.mjs.map +1 -1
- package/dist/actions/package/lint.mjs +26 -21
- package/dist/actions/package/lint.mjs.map +1 -1
- package/dist/bin/package/fix.mjs +26 -21
- package/dist/bin/package/fix.mjs.map +1 -1
- package/dist/bin/package/lint.mjs +26 -21
- package/dist/bin/package/lint.mjs.map +1 -1
- package/dist/bin/xy-ts.mjs +4 -10
- package/dist/bin/xy-ts.mjs.map +1 -1
- package/dist/bin/xy.mjs +4 -10
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +30 -31
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +4 -10
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +4 -10
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +4 -10
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +6 -4
- package/src/actions/lint.ts +3 -5
- package/src/actions/package/lint.ts +26 -20
|
@@ -165,18 +165,13 @@ var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental, fix } = {}
|
|
|
165
165
|
});
|
|
166
166
|
}, "lint");
|
|
167
167
|
var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental } = {}) => {
|
|
168
|
-
console.log(chalk4.gray("
|
|
168
|
+
console.log(chalk4.gray(`${fix ? "Fix" : "Lint"} [All-Packages]`));
|
|
169
169
|
const start = Date.now();
|
|
170
170
|
const verboseOptions = verbose ? [
|
|
171
171
|
"--verbose"
|
|
172
172
|
] : [
|
|
173
173
|
"--no-verbose"
|
|
174
174
|
];
|
|
175
|
-
const fixOptions = fix ? [
|
|
176
|
-
"--fix"
|
|
177
|
-
] : [
|
|
178
|
-
""
|
|
179
|
-
];
|
|
180
175
|
const incrementalOptions = incremental ? [
|
|
181
176
|
"--since",
|
|
182
177
|
"-Apt"
|
|
@@ -184,7 +179,7 @@ var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental
|
|
|
184
179
|
"--parallel",
|
|
185
180
|
"-Apt"
|
|
186
181
|
];
|
|
187
|
-
const result = runSteps("Lint
|
|
182
|
+
const result = runSteps(`${fix ? "Fix" : "Lint"} [All-Packages]`, [
|
|
188
183
|
[
|
|
189
184
|
"yarn",
|
|
190
185
|
[
|
|
@@ -193,12 +188,11 @@ var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental
|
|
|
193
188
|
...verboseOptions,
|
|
194
189
|
...incrementalOptions,
|
|
195
190
|
"run",
|
|
196
|
-
fix ? "package-fix" : "package-lint"
|
|
197
|
-
...fixOptions
|
|
191
|
+
fix ? "package-fix" : "package-lint"
|
|
198
192
|
]
|
|
199
193
|
]
|
|
200
194
|
]);
|
|
201
|
-
console.log(
|
|
195
|
+
console.log(chalk4.gray(`${fix ? "Fixed in" : "Linted in"} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`));
|
|
202
196
|
return result;
|
|
203
197
|
}, "lintAllPackages");
|
|
204
198
|
|
|
@@ -1 +1 @@
|
|
|
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 { 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 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('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 fix ? 'package-fix' : '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"],"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,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,IA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B;","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","fixOptions","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
|
+
{"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 { 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 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', '-Apt'] : ['--parallel', '-Apt']\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,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,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AAC,MAAC;AAChBI,UAAQC,IAAIC,OAAMC,KAAK,GAAGN,MAAM,QAAQ,MAAA,iBAAuB,CAAA;AAC/D,QAAMO,QAAQC,KAAKC,IAAG;AACtB,QAAMC,iBAAiBZ,UAAU;IAAC;MAAe;IAAC;;AAClD,QAAMa,qBAAqBZ,cAAc;IAAC;IAAW;MAAU;IAAC;IAAc;;AAE9E,QAAMa,SAASC,SAAS,GAAGb,MAAM,QAAQ,MAAA,oBAA0B;IACjE;MAAC;MAAQ;QAAC;QACR;WACGU;WACAC;QACH;QACAX,MAAM,gBAAgB;;;GAEzB;AACDG,UAAQC,IAAIC,OAAMC,KAAK,GAAGN,MAAM,aAAa,WAAA,KAAgBK,OAAMS,UAAUN,KAAKC,IAAG,IAAKF,SAAS,KAAMQ,QAAQ,CAAA,CAAA,CAAA,KAAQV,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAChJ,SAAOM;AACT,GAnB+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"]}
|
package/dist/actions/lint.mjs
CHANGED
|
@@ -171,18 +171,13 @@ var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental, fix } = {}
|
|
|
171
171
|
});
|
|
172
172
|
}, "lint");
|
|
173
173
|
var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental } = {}) => {
|
|
174
|
-
console.log(chalk4.gray("
|
|
174
|
+
console.log(chalk4.gray(`${fix ? "Fix" : "Lint"} [All-Packages]`));
|
|
175
175
|
const start = Date.now();
|
|
176
176
|
const verboseOptions = verbose ? [
|
|
177
177
|
"--verbose"
|
|
178
178
|
] : [
|
|
179
179
|
"--no-verbose"
|
|
180
180
|
];
|
|
181
|
-
const fixOptions = fix ? [
|
|
182
|
-
"--fix"
|
|
183
|
-
] : [
|
|
184
|
-
""
|
|
185
|
-
];
|
|
186
181
|
const incrementalOptions = incremental ? [
|
|
187
182
|
"--since",
|
|
188
183
|
"-Apt"
|
|
@@ -190,7 +185,7 @@ var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental
|
|
|
190
185
|
"--parallel",
|
|
191
186
|
"-Apt"
|
|
192
187
|
];
|
|
193
|
-
const result = runSteps("Lint
|
|
188
|
+
const result = runSteps(`${fix ? "Fix" : "Lint"} [All-Packages]`, [
|
|
194
189
|
[
|
|
195
190
|
"yarn",
|
|
196
191
|
[
|
|
@@ -199,12 +194,11 @@ var lintAllPackages = /* @__PURE__ */ __name(({ fix, verbose = true, incremental
|
|
|
199
194
|
...verboseOptions,
|
|
200
195
|
...incrementalOptions,
|
|
201
196
|
"run",
|
|
202
|
-
fix ? "package-fix" : "package-lint"
|
|
203
|
-
...fixOptions
|
|
197
|
+
fix ? "package-fix" : "package-lint"
|
|
204
198
|
]
|
|
205
199
|
]
|
|
206
200
|
]);
|
|
207
|
-
console.log(
|
|
201
|
+
console.log(chalk4.gray(`${fix ? "Fixed in" : "Linted in"} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`));
|
|
208
202
|
return result;
|
|
209
203
|
}, "lintAllPackages");
|
|
210
204
|
export {
|
|
@@ -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('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 fix ? 'package-fix' : '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"],"mappings":";;;;AAAA,OAAOA,YAAW;AAClB,SAASC,cAAc;;;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W;MAAU;IAAC;IAAc;;AAE9E,QAAMQ,SAASC,SAAS,uBAAuB;IAC7C;MAAC;MAAQ;QAAC;QACR;WACGJ;WACAE;QACH;QACAjC,MAAM,gBAAgB;WACnBgC;;;GAEN;AACD5C,UAAQC,IAAI,GAAGC,OAAMC,KAAK,WAAA,CAAA,KAAiBD,OAAMiB,UAAUsB,KAAKC,IAAG,IAAKF,SAAS,KAAMQ,QAAQ,CAAA,CAAA,CAAA,KAAQ9C,OAAMC,KAAK,SAAA,CAAA,EAAY;AAC9H,SAAO2C;AACT,GArB+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","fixOptions","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/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', '-Apt'] : ['--parallel', '-Apt']\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 { 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"],"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,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;AAC3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IACdF;IAASC;IAAa1B;EACxB,CAAA;AACN,GARoB;AAUb,IAAM2B,kBAAkB,wBAAC,EAC9B3B,KAAKyB,UAAU,MAAMC,YAAW,IAClB,CAAC,MAAC;AAChBtC,UAAQC,IAAIC,OAAMC,KAAK,GAAGS,MAAM,QAAQ,MAAA,iBAAuB,CAAA;AAC/D,QAAM4B,QAAQC,KAAKC,IAAG;AACtB,QAAMC,iBAAiBN,UAAU;IAAC;MAAe;IAAC;;AAClD,QAAMO,qBAAqBN,cAAc;IAAC;IAAW;MAAU;IAAC;IAAc;;AAE9E,QAAMO,SAASC,SAAS,GAAGlC,MAAM,QAAQ,MAAA,oBAA0B;IACjE;MAAC;MAAQ;QAAC;QACR;WACG+B;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"]}
|
|
@@ -808,6 +808,7 @@ import { pathToFileURL } from "node:url";
|
|
|
808
808
|
import chalk12 from "chalk";
|
|
809
809
|
import { ESLint } from "eslint";
|
|
810
810
|
import { findUp } from "find-up";
|
|
811
|
+
import picomatch from "picomatch";
|
|
811
812
|
var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
812
813
|
const colors = [
|
|
813
814
|
"white",
|
|
@@ -837,37 +838,41 @@ async function getRootESLintConfig() {
|
|
|
837
838
|
return pathToFileURL(configPath);
|
|
838
839
|
}
|
|
839
840
|
__name(getRootESLintConfig, "getRootESLintConfig");
|
|
841
|
+
function getFiles(dir, ignoreFolders) {
|
|
842
|
+
const currentDirectory = cwd4();
|
|
843
|
+
return readdirSync(dir, {
|
|
844
|
+
withFileTypes: true
|
|
845
|
+
}).flatMap((dirent) => {
|
|
846
|
+
const res = path5.resolve(dir, dirent.name);
|
|
847
|
+
const subDirectory = dir.split(currentDirectory)[1];
|
|
848
|
+
const relativePath = subDirectory ? `${subDirectory}/${dirent.name}` : dirent.name;
|
|
849
|
+
const ignoreMatchers = ignoreFolders.map((pattern) => picomatch(pattern));
|
|
850
|
+
if (ignoreMatchers.some((isMatch) => isMatch(relativePath))) return [];
|
|
851
|
+
return dirent.isDirectory() ? getFiles(res, ignoreFolders) : [
|
|
852
|
+
res
|
|
853
|
+
];
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
__name(getFiles, "getFiles");
|
|
840
857
|
var packageLint = /* @__PURE__ */ __name(async (fix = false) => {
|
|
841
858
|
const configPath = await getRootESLintConfig();
|
|
842
859
|
const { default: eslintConfig } = await import(configPath.href);
|
|
843
|
-
const ignoreFolders =
|
|
860
|
+
const ignoreFolders = [
|
|
844
861
|
"node_modules",
|
|
845
862
|
"dist",
|
|
846
|
-
"packages"
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
withFileTypes: true
|
|
851
|
-
}).flatMap((dirent) => {
|
|
852
|
-
const res = path5.resolve(dir, dirent.name);
|
|
853
|
-
if (ignorePatterns2.some((pattern) => dir.includes(pattern))) return [];
|
|
854
|
-
return dirent.isDirectory() ? getFiles(res, ignorePatterns2) : res.endsWith(".ts") || res.endsWith(".tsx") || res.endsWith(".js") || res.endsWith(".jsx") ? [
|
|
855
|
-
res
|
|
856
|
-
] : [];
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
__name(getFiles, "getFiles");
|
|
863
|
+
"packages",
|
|
864
|
+
".git",
|
|
865
|
+
"build"
|
|
866
|
+
];
|
|
860
867
|
const engine = new ESLint({
|
|
861
868
|
baseConfig: [
|
|
862
869
|
...eslintConfig
|
|
863
870
|
],
|
|
864
|
-
fix
|
|
871
|
+
fix,
|
|
872
|
+
warnIgnored: false
|
|
865
873
|
});
|
|
866
|
-
const
|
|
867
|
-
|
|
868
|
-
...ignoreFolders
|
|
869
|
-
];
|
|
870
|
-
const lintResults = await engine.lintFiles(getFiles(cwd4(), ignorePatterns));
|
|
874
|
+
const files = getFiles(cwd4(), ignoreFolders);
|
|
875
|
+
const lintResults = await engine.lintFiles(files);
|
|
871
876
|
dumpMessages(lintResults);
|
|
872
877
|
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
873
878
|
}, "packageLint");
|