@xylabs/ts-scripts-yarn3 5.0.39 → 5.1.1
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/index.mjs +113 -15
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/lint-clean.mjs +31 -6
- package/dist/actions/lint-clean.mjs.map +1 -1
- package/dist/actions/lint.mjs +32 -6
- package/dist/actions/lint.mjs.map +1 -1
- package/dist/actions/package/index.mjs +72 -0
- package/dist/actions/package/index.mjs.map +1 -1
- package/dist/actions/package/lint.mjs +77 -0
- package/dist/actions/package/lint.mjs.map +1 -0
- package/dist/bin/package/lint.mjs +88 -0
- package/dist/bin/package/lint.mjs.map +1 -0
- package/dist/bin/xy-ts.mjs +31 -6
- package/dist/bin/xy-ts.mjs.map +1 -1
- package/dist/bin/xy.mjs +31 -6
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.mjs +123 -25
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +31 -6
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +31 -6
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +31 -6
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +6 -4
- package/src/actions/lint.ts +24 -2
- package/src/actions/package/index.ts +1 -0
- package/src/actions/package/lint.ts +71 -0
- package/src/bin/package/lint.ts +16 -0
|
@@ -153,20 +153,45 @@ var lintPackage = /* @__PURE__ */ __name(async ({ pkg }) => {
|
|
|
153
153
|
dumpMessages(lintResults);
|
|
154
154
|
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
155
155
|
}, "lintPackage");
|
|
156
|
-
var lint = /* @__PURE__ */ __name(async ({ pkg } = {}) => {
|
|
156
|
+
var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental } = {}) => {
|
|
157
157
|
return pkg ? await lintPackage({
|
|
158
158
|
pkg
|
|
159
|
-
}) :
|
|
159
|
+
}) : lintAllPackages({
|
|
160
|
+
verbose,
|
|
161
|
+
incremental
|
|
162
|
+
});
|
|
163
|
+
}, "lint");
|
|
164
|
+
var lintAllPackages = /* @__PURE__ */ __name(({ verbose = true, incremental } = {}) => {
|
|
165
|
+
console.log(chalk4.gray("Linting [All-Packages]"));
|
|
166
|
+
const start = Date.now();
|
|
167
|
+
const verboseOptions = verbose ? [
|
|
168
|
+
"--verbose"
|
|
169
|
+
] : [
|
|
170
|
+
"--no-verbose"
|
|
171
|
+
];
|
|
172
|
+
const incrementalOptions = incremental ? [
|
|
173
|
+
"--since",
|
|
174
|
+
"-Apt"
|
|
175
|
+
] : [
|
|
176
|
+
"--parallel",
|
|
177
|
+
"-Apt"
|
|
178
|
+
];
|
|
179
|
+
const result = runSteps("Lint [All-Packages]", [
|
|
160
180
|
[
|
|
161
181
|
"yarn",
|
|
162
182
|
[
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
|
|
183
|
+
"workspaces",
|
|
184
|
+
"foreach",
|
|
185
|
+
...verboseOptions,
|
|
186
|
+
...incrementalOptions,
|
|
187
|
+
"run",
|
|
188
|
+
"package-lint"
|
|
166
189
|
]
|
|
167
190
|
]
|
|
168
191
|
]);
|
|
169
|
-
}
|
|
192
|
+
console.log(`${chalk4.gray("Linted in")} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`);
|
|
193
|
+
return result;
|
|
194
|
+
}, "lintAllPackages");
|
|
170
195
|
|
|
171
196
|
// src/actions/lint-clean.ts
|
|
172
197
|
var lintClean = /* @__PURE__ */ __name(async () => {
|
|
@@ -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 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 }: 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 })\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 () => {\n const engine = new ESLint({ cache: true })\n\n const lintResults = await engine.lintFiles('./**/*.*')\n\n dumpMessages(lintResults)\n\n return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0)\n}\n\nexport const lint = async ({ pkg }: LintParams = {}) => {\n return pkg ? await lintPackage({ pkg }) : runSteps('Lint-Caching [All]', [['yarn', ['eslint', '.', '--cache']]])\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,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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O,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","workspace","yarnWorkspaces","find","name","error","red","magenta","process","exit","engine","ESLint","cache","lintFiles","location","reduce","prev","errorCount","lint","pkg","lintPackage","runSteps","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 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 }: 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 })\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 () => {\n const engine = new ESLint({ cache: true })\n\n const lintResults = await engine.lintFiles('./**/*.*')\n\n dumpMessages(lintResults)\n\n return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0)\n}\n\nexport const lint = async ({\n pkg, verbose, incremental,\n}: LintParams = {}) => {\n return pkg ? await lintPackage({ pkg }) : lintAllPackages({ verbose, incremental })\n}\n\nexport const lintAllPackages = ({ verbose = true, incremental }: LintParams = {}) => {\n console.log(chalk.gray('Linting [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('Lint [All-Packages]', [\n ['yarn', ['workspaces',\n 'foreach',\n ...verboseOptions,\n ...incrementalOptions,\n 'run',\n 'package-lint',\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,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,mBAA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C,iBAAiBX,UAAU;IAAC;MAAe;IAAC;;AAClD,QAAMY,qBAAqBX,cAAc;IAAC;IAAW;MAAU;IAAC;IAAc;;AAE9E,QAAMY,SAASC,SAAS,uBAAuB;IAC7C;MAAC;MAAQ;QAAC;QACR;WACGH;WACAC;QACH;QACA;;;GAEH;AACDR,UAAQC,IAAI,GAAGC,OAAMC,KAAK,WAAA,CAAA,KAAiBD,OAAMS,UAAUN,KAAKC,IAAG,IAAKF,SAAS,KAAMQ,QAAQ,CAAA,CAAA,CAAA,KAAQV,OAAMC,KAAK,SAAA,CAAA,EAAY;AAC9H,SAAOM;AACT,GAjB+B;;;AR9DxB,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","workspace","yarnWorkspaces","find","name","error","red","magenta","process","exit","engine","ESLint","cache","lintFiles","location","reduce","prev","errorCount","lint","pkg","verbose","incremental","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
|
@@ -160,23 +160,49 @@ var lintAll = /* @__PURE__ */ __name(async () => {
|
|
|
160
160
|
dumpMessages(lintResults);
|
|
161
161
|
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
162
162
|
}, "lintAll");
|
|
163
|
-
var lint = /* @__PURE__ */ __name(async ({ pkg } = {}) => {
|
|
163
|
+
var lint = /* @__PURE__ */ __name(async ({ pkg, verbose, incremental } = {}) => {
|
|
164
164
|
return pkg ? await lintPackage({
|
|
165
165
|
pkg
|
|
166
|
-
}) :
|
|
166
|
+
}) : lintAllPackages({
|
|
167
|
+
verbose,
|
|
168
|
+
incremental
|
|
169
|
+
});
|
|
170
|
+
}, "lint");
|
|
171
|
+
var lintAllPackages = /* @__PURE__ */ __name(({ verbose = true, incremental } = {}) => {
|
|
172
|
+
console.log(chalk4.gray("Linting [All-Packages]"));
|
|
173
|
+
const start = Date.now();
|
|
174
|
+
const verboseOptions = verbose ? [
|
|
175
|
+
"--verbose"
|
|
176
|
+
] : [
|
|
177
|
+
"--no-verbose"
|
|
178
|
+
];
|
|
179
|
+
const incrementalOptions = incremental ? [
|
|
180
|
+
"--since",
|
|
181
|
+
"-Apt"
|
|
182
|
+
] : [
|
|
183
|
+
"--parallel",
|
|
184
|
+
"-Apt"
|
|
185
|
+
];
|
|
186
|
+
const result = runSteps("Lint [All-Packages]", [
|
|
167
187
|
[
|
|
168
188
|
"yarn",
|
|
169
189
|
[
|
|
170
|
-
"
|
|
171
|
-
"
|
|
172
|
-
|
|
190
|
+
"workspaces",
|
|
191
|
+
"foreach",
|
|
192
|
+
...verboseOptions,
|
|
193
|
+
...incrementalOptions,
|
|
194
|
+
"run",
|
|
195
|
+
"package-lint"
|
|
173
196
|
]
|
|
174
197
|
]
|
|
175
198
|
]);
|
|
176
|
-
}
|
|
199
|
+
console.log(`${chalk4.gray("Linted in")} [${chalk4.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk4.gray("seconds")}`);
|
|
200
|
+
return result;
|
|
201
|
+
}, "lintAllPackages");
|
|
177
202
|
export {
|
|
178
203
|
lint,
|
|
179
204
|
lintAll,
|
|
205
|
+
lintAllPackages,
|
|
180
206
|
lintPackage
|
|
181
207
|
};
|
|
182
208
|
//# sourceMappingURL=lint.mjs.map
|
|
@@ -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 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 }: 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 })\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 () => {\n const engine = new ESLint({ cache: true })\n\n const lintResults = await engine.lintFiles('./**/*.*')\n\n dumpMessages(lintResults)\n\n return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0)\n}\n\nexport const lint = async ({ pkg }: LintParams = {}) => {\n return pkg ? await lintPackage({ pkg }) : runSteps('Lint-Caching [All]', [['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 { 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,IAA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c,MAAM2B,OAAOG,UAAU,UAAA;AAE3C/B,eAAaC,WAAAA;AAEb,SAAOA,YAAYgC,OAAO,CAACC,MAAM9B,eAAe8B,OAAO9B,WAAW+B,YAAY,CAAA;AAChF,GARuB;AAUhB,IAAME,OAAO,8BAAO,EAAEnB,IAAG,IAAiB,CAAC,MAAC;AACjD,SAAOA,MAAM,MAAMD,YAAY;IAAEC;EAAI,CAAA,IAAKoB,SAAS,sBAAsB;IAAC;MAAC;MAAQ;QAAC;QAAU;QAAK;;;GAAY;AACjH,GAFoB;","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","workspace","yarnWorkspaces","find","name","error","red","magenta","process","exit","engine","ESLint","cache","lintFiles","location","reduce","prev","errorCount","lintAll","lint","runSteps"]}
|
|
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 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 }: 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 })\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 () => {\n const engine = new ESLint({ cache: true })\n\n const lintResults = await engine.lintFiles('./**/*.*')\n\n dumpMessages(lintResults)\n\n return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0)\n}\n\nexport const lint = async ({\n pkg, verbose, incremental,\n}: LintParams = {}) => {\n return pkg ? await lintPackage({ pkg }) : lintAllPackages({ verbose, incremental })\n}\n\nexport const lintAllPackages = ({ verbose = true, incremental }: LintParams = {}) => {\n console.log(chalk.gray('Linting [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('Lint [All-Packages]', [\n ['yarn', ['workspaces',\n 'foreach',\n ...verboseOptions,\n ...incrementalOptions,\n 'run',\n 'package-lint',\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;;;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;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;EACxB,CAAA,KACGC,UAAUV,OAAO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qBAAqBN,cAAc;IAAC;IAAW;MAAU;IAAC;IAAc;;AAE9E,QAAMO,SAASC,SAAS,uBAAuB;IAC7C;MAAC;MAAQ;QAAC;QACR;WACGH;WACAC;QACH;QACA;;;GAEH;AACDtC,UAAQC,IAAI,GAAGC,OAAMC,KAAK,WAAA,CAAA,KAAiBD,OAAMgB,UAAUiB,KAAKC,IAAG,IAAKF,SAAS,KAAMO,QAAQ,CAAA,CAAA,CAAA,KAAQvC,OAAMC,KAAK,SAAA,CAAA,EAAY;AAC9H,SAAOoC;AACT,GAjB+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","workspace","yarnWorkspaces","find","name","error","red","magenta","process","exit","engine","ESLint","cache","lintFiles","location","reduce","prev","errorCount","lintAll","lint","verbose","incremental","lintAllPackages","start","Date","now","verboseOptions","incrementalOptions","result","runSteps","toFixed"]}
|
|
@@ -800,6 +800,77 @@ var runTypeDoc = /* @__PURE__ */ __name(async (app) => {
|
|
|
800
800
|
return ExitCodes.Ok;
|
|
801
801
|
}, "runTypeDoc");
|
|
802
802
|
|
|
803
|
+
// src/actions/package/lint.ts
|
|
804
|
+
import { readdirSync } from "node:fs";
|
|
805
|
+
import path5 from "node:path";
|
|
806
|
+
import { cwd as cwd4 } from "node:process";
|
|
807
|
+
import { pathToFileURL } from "node:url";
|
|
808
|
+
import chalk12 from "chalk";
|
|
809
|
+
import { ESLint } from "eslint";
|
|
810
|
+
import { findUp } from "find-up";
|
|
811
|
+
var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
812
|
+
const colors = [
|
|
813
|
+
"white",
|
|
814
|
+
"yellow",
|
|
815
|
+
"red"
|
|
816
|
+
];
|
|
817
|
+
const severity = [
|
|
818
|
+
"none",
|
|
819
|
+
"warning",
|
|
820
|
+
"error"
|
|
821
|
+
];
|
|
822
|
+
for (const lintResult of lintResults) {
|
|
823
|
+
if (lintResult.messages.length > 0) {
|
|
824
|
+
console.log(chalk12.gray(`
|
|
825
|
+
${lintResult.filePath}`));
|
|
826
|
+
for (const message of lintResult.messages) {
|
|
827
|
+
console.log(chalk12.gray(` ${message.line}:${message.column}`), chalk12[colors[message.severity]](` ${severity[message.severity]}`), chalk12.white(` ${message.message}`), chalk12.gray(` ${message.ruleId}`));
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}, "dumpMessages");
|
|
832
|
+
async function getRootESLintConfig() {
|
|
833
|
+
const configPath = await findUp("eslint.config.mjs");
|
|
834
|
+
if (!configPath) {
|
|
835
|
+
throw new Error("eslint.config.mjs not found in the monorepo");
|
|
836
|
+
}
|
|
837
|
+
return pathToFileURL(configPath);
|
|
838
|
+
}
|
|
839
|
+
__name(getRootESLintConfig, "getRootESLintConfig");
|
|
840
|
+
var packageLint = /* @__PURE__ */ __name(async () => {
|
|
841
|
+
const configPath = await getRootESLintConfig();
|
|
842
|
+
const { default: eslintConfig } = await import(configPath.href);
|
|
843
|
+
const ignoreFolders = /* @__PURE__ */ new Set([
|
|
844
|
+
"node_modules",
|
|
845
|
+
"dist",
|
|
846
|
+
"packages"
|
|
847
|
+
]);
|
|
848
|
+
function getFiles(dir, ignorePatterns2) {
|
|
849
|
+
return readdirSync(dir, {
|
|
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");
|
|
860
|
+
const engine = new ESLint({
|
|
861
|
+
baseConfig: [
|
|
862
|
+
...eslintConfig
|
|
863
|
+
]
|
|
864
|
+
});
|
|
865
|
+
const ignorePatterns = [
|
|
866
|
+
...eslintConfig.find((cfg) => cfg.ignores)?.ignores ?? [],
|
|
867
|
+
...ignoreFolders
|
|
868
|
+
];
|
|
869
|
+
const lintResults = await engine.lintFiles(getFiles(cwd4(), ignorePatterns));
|
|
870
|
+
dumpMessages(lintResults);
|
|
871
|
+
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
872
|
+
}, "packageLint");
|
|
873
|
+
|
|
803
874
|
// src/actions/package/recompile.ts
|
|
804
875
|
var packageRecompile = /* @__PURE__ */ __name(async () => {
|
|
805
876
|
return await packageClean() || await packageCompile();
|
|
@@ -814,6 +885,7 @@ export {
|
|
|
814
885
|
packageCopyAssets,
|
|
815
886
|
packageDeps,
|
|
816
887
|
packageGenDocs,
|
|
888
|
+
packageLint,
|
|
817
889
|
packagePublint,
|
|
818
890
|
packageRecompile
|
|
819
891
|
};
|