@xylabs/ts-scripts-yarn3 6.1.16 → 6.2.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/fix.mjs +2 -19
- package/dist/actions/fix.mjs.map +1 -1
- package/dist/actions/index.mjs +67 -314
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/lint.mjs +2 -19
- package/dist/actions/lint.mjs.map +1 -1
- package/dist/actions/package/index.mjs +33 -206
- package/dist/actions/package/index.mjs.map +1 -1
- package/dist/bin/xy.mjs +45 -138
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +2 -17
- package/dist/index.mjs +78 -334
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +45 -138
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +45 -138
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyCommonCommands.mjs +15 -91
- package/dist/xy/xyCommonCommands.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +2 -19
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +7 -11
- package/dist/actions/deps.mjs +0 -170
- package/dist/actions/deps.mjs.map +0 -1
- package/dist/actions/package/deps.mjs +0 -180
- package/dist/actions/package/deps.mjs.map +0 -1
- package/dist/bin/package/deps.mjs +0 -185
- package/dist/bin/package/deps.mjs.map +0 -1
package/dist/actions/lint.mjs
CHANGED
|
@@ -125,31 +125,14 @@ var lint = /* @__PURE__ */ __name(({ pkg, verbose, incremental, fix } = {}) => {
|
|
|
125
125
|
fix
|
|
126
126
|
});
|
|
127
127
|
}, "lint");
|
|
128
|
-
var lintAllPackages = /* @__PURE__ */ __name(({ fix
|
|
128
|
+
var lintAllPackages = /* @__PURE__ */ __name(({ fix = false } = {}) => {
|
|
129
129
|
console.log(chalk4.gray(`${fix ? "Fix" : "Lint"} [All-Packages]`));
|
|
130
130
|
const start = Date.now();
|
|
131
|
-
const verboseOptions = verbose ? [
|
|
132
|
-
"--verbose"
|
|
133
|
-
] : [
|
|
134
|
-
"--no-verbose"
|
|
135
|
-
];
|
|
136
|
-
const incrementalOptions = incremental ? [
|
|
137
|
-
"--since",
|
|
138
|
-
"-Ap"
|
|
139
|
-
] : [
|
|
140
|
-
"--parallel",
|
|
141
|
-
"-Ap"
|
|
142
|
-
];
|
|
143
131
|
const result = runSteps(`${fix ? "Fix" : "Lint"} [All-Packages]`, [
|
|
144
132
|
[
|
|
145
133
|
"yarn",
|
|
146
134
|
[
|
|
147
|
-
"
|
|
148
|
-
"foreach",
|
|
149
|
-
...verboseOptions,
|
|
150
|
-
...incrementalOptions,
|
|
151
|
-
"run",
|
|
152
|
-
fix ? "package-fix" : "package-lint"
|
|
135
|
+
"eslint"
|
|
153
136
|
]
|
|
154
137
|
]
|
|
155
138
|
]);
|
|
@@ -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/runSteps.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { runSteps } from '../lib/index.ts'\n\nexport interface LintParams {\n fix?: boolean\n incremental?: boolean\n pkg?: string\n verbose?: boolean\n}\n\nexport interface LintPackageParams {\n pkg: string\n verbose?: boolean\n}\n\nexport const lintPackage = ({ pkg, fix }: LintParams & Required<Pick<LintParams, 'pkg'>>) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [${pkg}]`))\n const start = Date.now()\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [${pkg}]`, [\n ['yarn', ['workspace',\n pkg,\n 'run',\n fix ? 'package-fix' : 'package-lint',\n ]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n\nexport const lint = ({\n pkg, verbose, incremental, fix,\n}: LintParams = {}) => {\n return pkg\n ? lintPackage({ pkg, fix })\n : lintAllPackages({\n verbose, incremental, fix,\n })\n}\n\nexport const lintAllPackages = ({\n fix, verbose = true, incremental,\n}: LintParams = {}) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [All-Packages]`))\n const start = Date.now()\n const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n const incrementalOptions = incremental ? ['--since', '-Ap'] : ['--parallel', '-Ap']\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [All-Packages]`, [\n ['yarn', ['workspaces',\n 'foreach',\n ...verboseOptions,\n ...incrementalOptions,\n 'run',\n fix ? 'package-fix' : 'package-lint',\n ]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n","import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import type { SpawnSyncOptionsWithBufferEncoding } from 'node:child_process'\nimport { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\n\nimport chalk from 'chalk'\n\nimport { checkResult } from './checkResult.ts'\nimport { safeExit } from './safeExit.ts'\n\nexport type ScriptStep =\n | [/* command */ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /* arg */ string | string[]]\n | [/* command */ string, /* arg */ string | string[], /* config */ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (const [i, [command, args, config]] of steps.entries()) {\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw new Error(`File not found [${argList[0]}]`)\n }\n const status\n = spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n"],"mappings":";;;;AAAA,OAAOA,YAAW;;;ACAlB,OAAOC,WAAW;AAEX,IAAMC,cAAc,wBAACC,MAAcC,QAAgBC,QAA0B,SAASC,aAAa,UAAK;AAC7G,MAAIF,QAAQ;AACV,UAAMG,UAAUD,aAAa,sBAAsB;AACnD,UAAME,YAAYH,UAAU,UAAUI,MAAMC,MAAMD,MAAME;AACxDC,YAAQP,KAAAA,EAAOG,UAAU,GAAGL,IAAAA,QAAYC,MAAAA,aAAmBG,OAAAA,EAAS,CAAA;AACpE,QAAID,YAAY;AACdO,cAAQC,KAAKV,MAAAA;IACf;EACF;AACF,GAT2B;;;ACF3B,OAAOW,YAAW;;;ACAX,IAAMC,YAAY,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAW,CAAC,CAACA,IAAGG,QAAQ,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,c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MAAMC,YAAW,IAClB,CAAC,MAAC;AAChBb,UAAQC,IAAIC,OAAMC,KAAK,GAAGJ,MAAM,QAAQ,MAAA,iBAAuB,CAAA;AAC/D,QAAMK,QAAQC,KAAKC,IAAG;AACtB,QAAMS,iBAAiBH,UAAU;IAAC;MAAe;IAAC;;AAClD,QAAMI,qBAAqBH,cAAc;IAAC;IAAW;MAAS;IAAC;IAAc;;AAE7E,QAAMN,SAASC,SAAS,GAAGT,MAAM,QAAQ,MAAA,oBAA0B;IACjE;MAAC;MAAQ;QAAC;QACR;WACGgB;WACAC;QACH;QACAjB,MAAM,gBAAgB;;;GAEzB;AACDC,UAAQC,IAAIC,OAAMC,KAAK,GAAGJ,MAAM,aAAa,WAAA,KAAgBG,OAAMO,UAAUJ,KAAKC,IAAG,IAAKF,SAAS,KAAMM,QAAQ,CAAA,CAAA,CAAA,KAAQR,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAChJ,SAAOI;AACT,GAnB+B;","names":["chalk","chalk","checkResult","name","result","level","exitOnFail","exiting","chalkFunc","chalk","red","yellow","console","process","exit","chalk","withError","ex","closure","predicate","name","message","undefined","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","spawnSync","existsSync","chalk","runSteps","name","steps","exitOnFail","messages","safeExit","pkgName","process","env","npm_package_name","console","log","chalk","green","totalStatus","i","command","args","config","entries","gray","argList","Array","isArray","split","existsSync","Error","status","spawnSync","encoding","FORCE_COLOR","shell","stdio","checkResult","lintPackage","pkg","fix","console","log","chalk","gray","start","Date","now","result","runSteps","magenta","toFixed","lint","verbose","incremental","lintAllPackages","verboseOptions","incrementalOptions"]}
|
|
1
|
+
{"version":3,"sources":["../../src/actions/lint.ts","../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { runSteps } from '../lib/index.ts'\n\nexport interface LintParams {\n fix?: boolean\n incremental?: boolean\n pkg?: string\n verbose?: boolean\n}\n\nexport interface LintPackageParams {\n pkg: string\n verbose?: boolean\n}\n\nexport const lintPackage = ({ pkg, fix }: LintParams & Required<Pick<LintParams, 'pkg'>>) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [${pkg}]`))\n const start = Date.now()\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [${pkg}]`, [\n ['yarn', ['workspace',\n pkg,\n 'run',\n fix ? 'package-fix' : 'package-lint',\n ]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n\nexport const lint = ({\n pkg, verbose, incremental, fix,\n}: LintParams = {}) => {\n return pkg\n ? lintPackage({ pkg, fix })\n : lintAllPackages({\n verbose, incremental, fix,\n })\n}\n\nexport const lintAllPackages = ({ fix = false }: LintParams = {}) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [All-Packages]`))\n const start = Date.now()\n // const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n // const incrementalOptions = incremental ? ['--since', '-Ap'] : ['--parallel', '-Ap']\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [All-Packages]`, [\n ['yarn', ['eslint']],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n","import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import type { SpawnSyncOptionsWithBufferEncoding } from 'node:child_process'\nimport { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\n\nimport chalk from 'chalk'\n\nimport { checkResult } from './checkResult.ts'\nimport { safeExit } from './safeExit.ts'\n\nexport type ScriptStep =\n | [/* command */ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /* arg */ string | string[]]\n | [/* command */ string, /* arg */ string | string[], /* config */ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (const [i, [command, args, config]] of steps.entries()) {\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw new Error(`File not found [${argList[0]}]`)\n }\n const status\n = spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n"],"mappings":";;;;AAAA,OAAOA,YAAW;;;ACAlB,OAAOC,WAAW;AAEX,IAAMC,cAAc,wBAACC,MAAcC,QAAgBC,QAA0B,SAASC,aAAa,UAAK;AAC7G,MAAIF,QAAQ;AACV,UAAMG,UAAUD,aAAa,sBAAsB;AACnD,UAAME,YAAYH,UAAU,UAAUI,MAAMC,MAAMD,MAAME;AACxDC,YAAQP,KAAAA,EAAOG,UAAU,GAAGL,IAAAA,QAAYC,MAAAA,aAAmBG,OAAAA,EAAS,CAAA;AACpE,QAAID,YAAY;AACdO,cAAQC,KAAKV,MAAAA;IACf;EACF;AACF,GAT2B;;;ACF3B,OAAOW,YAAW;;;ACAX,IAAMC,YAAY,wBAEvBC,IACAC,SACAC,YAAY,CAACF,QAAW,CAAC,CAACA,IAAGG,QAAQ,CAAC,CAACH,IAAGI,YAAQ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ACAC,MAAM,gBAAgB;;;GAEzB;AACDC,UAAQC,IAAIC,OAAMC,KAAK,GAAGJ,MAAM,aAAa,WAAA,KAAgBG,OAAMO,UAAUJ,KAAKC,IAAG,IAAKF,SAAS,KAAMM,QAAQ,CAAA,CAAA,CAAA,KAAQR,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAChJ,SAAOI;AACT,GAb2B;AAepB,IAAMI,OAAO,wBAAC,EACnBb,KAAKc,SAASC,aAAad,IAAG,IAChB,CAAC,MAAC;AAChB,SAAOD,MACHD,YAAY;IAAEC;IAAKC;EAAI,CAAA,IACvBe,gBAAgB;IACdF;IAASC;IAAad;EACxB,CAAA;AACN,GARoB;AAUb,IAAMe,kBAAkB,wBAAC,EAAEf,MAAM,MAAK,IAAiB,CAAC,MAAC;AAC9DC,UAAQC,IAAIC,OAAMC,KAAK,GAAGJ,MAAM,QAAQ,MAAA,iBAAuB,CAAA;AAC/D,QAAMK,QAAQC,KAAKC,IAAG;AAItB,QAAMC,SAASC,SAAS,GAAGT,MAAM,QAAQ,MAAA,oBAA0B;IACjE;MAAC;MAAQ;QAAC;;;GACX;AACDC,UAAQC,IAAIC,OAAMC,KAAK,GAAGJ,MAAM,aAAa,WAAA,KAAgBG,OAAMO,UAAUJ,KAAKC,IAAG,IAAKF,SAAS,KAAMM,QAAQ,CAAA,CAAA,CAAA,KAAQR,OAAMC,KAAK,SAAA,CAAA,EAAY,CAAA;AAChJ,SAAOI;AACT,GAX+B;","names":["chalk","chalk","checkResult","name","result","level","exitOnFail","exiting","chalkFunc","chalk","red","yellow","console","process","exit","chalk","withError","ex","closure","predicate","name","message","undefined","withErrnoException","ex","closure","withError","errno","undefined","processEx","ex","error","Error","exitCode","withErrnoException","code","console","chalk","red","path","errno","withError","name","message","JSON","stringify","process","exit","safeExit","func","exitOnFail","result","process","exit","ex","processEx","spawnSync","existsSync","chalk","runSteps","name","steps","exitOnFail","messages","safeExit","pkgName","process","env","npm_package_name","console","log","chalk","green","totalStatus","i","command","args","config","entries","gray","argList","Array","isArray","split","existsSync","Error","status","spawnSync","encoding","FORCE_COLOR","shell","stdio","checkResult","lintPackage","pkg","fix","console","log","chalk","gray","start","Date","now","result","runSteps","magenta","toFixed","lint","verbose","incremental","lintAllPackages"]}
|
|
@@ -3,20 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/actions/package/clean-outputs.ts
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
// src/lib/checkResult.ts
|
|
9
|
-
import chalk from "chalk";
|
|
10
|
-
var checkResult = /* @__PURE__ */ __name((name, result, level = "error", exitOnFail = false) => {
|
|
11
|
-
if (result) {
|
|
12
|
-
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
13
|
-
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
14
|
-
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
15
|
-
if (exitOnFail) {
|
|
16
|
-
process.exit(result);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}, "checkResult");
|
|
6
|
+
import chalk2 from "chalk";
|
|
20
7
|
|
|
21
8
|
// src/lib/deleteGlob.ts
|
|
22
9
|
import fs from "node:fs";
|
|
@@ -32,7 +19,7 @@ var deleteGlob = /* @__PURE__ */ __name((globPath) => {
|
|
|
32
19
|
}, "deleteGlob");
|
|
33
20
|
|
|
34
21
|
// src/lib/loadConfig.ts
|
|
35
|
-
import
|
|
22
|
+
import chalk from "chalk";
|
|
36
23
|
import { cosmiconfig } from "cosmiconfig";
|
|
37
24
|
import deepmerge from "deepmerge";
|
|
38
25
|
var config;
|
|
@@ -46,7 +33,7 @@ var loadConfig = /* @__PURE__ */ __name(async (params) => {
|
|
|
46
33
|
config = cosmicConfigResult?.config;
|
|
47
34
|
const configFilePath = cosmicConfigResult?.filepath;
|
|
48
35
|
if (configFilePath) {
|
|
49
|
-
console.log(
|
|
36
|
+
console.log(chalk.gray(`Loading config from ${configFilePath}`));
|
|
50
37
|
}
|
|
51
38
|
return deepmerge(config, params ?? {});
|
|
52
39
|
}, "loadConfig");
|
|
@@ -60,7 +47,7 @@ var packageCleanOutputs = /* @__PURE__ */ __name(() => {
|
|
|
60
47
|
path.join(pkg, "build"),
|
|
61
48
|
path.join(pkg, "docs")
|
|
62
49
|
];
|
|
63
|
-
console.log(
|
|
50
|
+
console.log(chalk2.green(`Cleaning Outputs [${pkgName}]`));
|
|
64
51
|
for (let folder of folders) {
|
|
65
52
|
deleteGlob(folder);
|
|
66
53
|
}
|
|
@@ -69,11 +56,11 @@ var packageCleanOutputs = /* @__PURE__ */ __name(() => {
|
|
|
69
56
|
|
|
70
57
|
// src/actions/package/clean-typescript.ts
|
|
71
58
|
import path2 from "node:path";
|
|
72
|
-
import
|
|
59
|
+
import chalk3 from "chalk";
|
|
73
60
|
var packageCleanTypescript = /* @__PURE__ */ __name(() => {
|
|
74
61
|
const pkg = process.env.INIT_CWD ?? ".";
|
|
75
62
|
const pkgName = process.env.npm_package_name;
|
|
76
|
-
console.log(
|
|
63
|
+
console.log(chalk3.green(`Cleaning Typescript [${pkgName}]`));
|
|
77
64
|
const files = [
|
|
78
65
|
path2.join(pkg, "*.tsbuildinfo"),
|
|
79
66
|
path2.join(pkg, ".tsconfig.*"),
|
|
@@ -94,19 +81,19 @@ var packageClean = /* @__PURE__ */ __name(async () => {
|
|
|
94
81
|
}, "packageClean");
|
|
95
82
|
|
|
96
83
|
// src/actions/package/compile/compile.ts
|
|
97
|
-
import
|
|
84
|
+
import chalk7 from "chalk";
|
|
98
85
|
|
|
99
86
|
// src/actions/package/publint.ts
|
|
100
87
|
import { promises as fs2 } from "node:fs";
|
|
101
|
-
import
|
|
88
|
+
import chalk4 from "chalk";
|
|
102
89
|
import sortPackageJson from "sort-package-json";
|
|
103
90
|
var packagePublint = /* @__PURE__ */ __name(async (params) => {
|
|
104
91
|
const pkgDir = process.env.INIT_CWD;
|
|
105
92
|
const sortedPkg = sortPackageJson(await fs2.readFile(`${pkgDir}/package.json`, "utf8"));
|
|
106
93
|
await fs2.writeFile(`${pkgDir}/package.json`, sortedPkg);
|
|
107
94
|
const pkg = JSON.parse(await fs2.readFile(`${pkgDir}/package.json`, "utf8"));
|
|
108
|
-
console.log(
|
|
109
|
-
console.log(
|
|
95
|
+
console.log(chalk4.green(`Publint: ${pkg.name}`));
|
|
96
|
+
console.log(chalk4.gray(pkgDir));
|
|
110
97
|
const { publint } = await import("publint");
|
|
111
98
|
const { messages } = await publint({
|
|
112
99
|
level: "suggestion",
|
|
@@ -121,21 +108,21 @@ var packagePublint = /* @__PURE__ */ __name(async (params) => {
|
|
|
121
108
|
for (const message of validMessages) {
|
|
122
109
|
switch (message.type) {
|
|
123
110
|
case "error": {
|
|
124
|
-
console.error(
|
|
111
|
+
console.error(chalk4.red(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
125
112
|
break;
|
|
126
113
|
}
|
|
127
114
|
case "warning": {
|
|
128
|
-
console.warn(
|
|
115
|
+
console.warn(chalk4.yellow(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
129
116
|
break;
|
|
130
117
|
}
|
|
131
118
|
default: {
|
|
132
|
-
console.log(
|
|
119
|
+
console.log(chalk4.white(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
133
120
|
break;
|
|
134
121
|
}
|
|
135
122
|
}
|
|
136
123
|
}
|
|
137
124
|
if (params?.verbose) {
|
|
138
|
-
console.log(
|
|
125
|
+
console.log(chalk4.gray(`Publint [Finish]: ${pkgDir} [${validMessages.length}]`));
|
|
139
126
|
}
|
|
140
127
|
return validMessages.filter((message) => message.type === "error").length;
|
|
141
128
|
}, "packagePublint");
|
|
@@ -179,7 +166,7 @@ var buildEntries = /* @__PURE__ */ __name((folder, entryMode = "single", exclude
|
|
|
179
166
|
|
|
180
167
|
// src/actions/package/compile/packageCompileTscTypes.ts
|
|
181
168
|
import { cwd } from "node:process";
|
|
182
|
-
import
|
|
169
|
+
import chalk5 from "chalk";
|
|
183
170
|
import { createProgramFromConfig } from "tsc-prog";
|
|
184
171
|
import { DiagnosticCategory, formatDiagnosticsWithColorAndContext, getPreEmitDiagnostics, sys as sys2 } from "typescript";
|
|
185
172
|
|
|
@@ -236,7 +223,7 @@ var packageCompileTscTypes = /* @__PURE__ */ __name((folder = "src", config2 = {
|
|
|
236
223
|
".spec."
|
|
237
224
|
];
|
|
238
225
|
const files = buildEntries(folder, "all", verbose).filter((file) => validTsExt.find((ext) => file.endsWith(ext)) && !excludes.some((exclude) => file.includes(exclude)));
|
|
239
|
-
console.log(
|
|
226
|
+
console.log(chalk5.green(`Compiling Types ${pkg}: ${files.length}`));
|
|
240
227
|
if (files.length > 0) {
|
|
241
228
|
const program = createProgramFromConfig({
|
|
242
229
|
basePath: pkg ?? cwd(),
|
|
@@ -299,7 +286,7 @@ __name(deepMergeObjects, "deepMergeObjects");
|
|
|
299
286
|
|
|
300
287
|
// src/actions/package/compile/packageCompileTsc.ts
|
|
301
288
|
import { cwd as cwd2 } from "node:process";
|
|
302
|
-
import
|
|
289
|
+
import chalk6 from "chalk";
|
|
303
290
|
import { createProgramFromConfig as createProgramFromConfig2 } from "tsc-prog";
|
|
304
291
|
import { DiagnosticCategory as DiagnosticCategory2, formatDiagnosticsWithColorAndContext as formatDiagnosticsWithColorAndContext2, getPreEmitDiagnostics as getPreEmitDiagnostics2, sys as sys3 } from "typescript";
|
|
305
292
|
var packageCompileTsc = /* @__PURE__ */ __name((folder = "src", config2 = {}, compilerOptionsParam) => {
|
|
@@ -334,7 +321,7 @@ var packageCompileTsc = /* @__PURE__ */ __name((folder = "src", config2 = {}, co
|
|
|
334
321
|
".d.mts"
|
|
335
322
|
];
|
|
336
323
|
const files = buildEntries(folder, "all", verbose).filter((file) => validTsExt.find((ext) => file.endsWith(ext)) && includes.find((include) => file.includes(include)));
|
|
337
|
-
console.log(
|
|
324
|
+
console.log(chalk6.green(`Compiling Files ${pkg}: ${files.length}`));
|
|
338
325
|
if (files.length > 0) {
|
|
339
326
|
const program = createProgramFromConfig2({
|
|
340
327
|
basePath: pkg ?? cwd2(),
|
|
@@ -494,7 +481,7 @@ var packageCompileTsup = /* @__PURE__ */ __name(async (config2) => {
|
|
|
494
481
|
// src/actions/package/compile/compile.ts
|
|
495
482
|
var packageCompile = /* @__PURE__ */ __name(async (inConfig = {}) => {
|
|
496
483
|
const pkg = process.env.INIT_CWD;
|
|
497
|
-
console.log(
|
|
484
|
+
console.log(chalk7.green(`Compiling ${pkg}`));
|
|
498
485
|
const config2 = await loadConfig(inConfig);
|
|
499
486
|
const publint = config2.publint;
|
|
500
487
|
const tsupResults = await packageCompileTsup(config2);
|
|
@@ -506,7 +493,7 @@ var packageCompile = /* @__PURE__ */ __name(async (inConfig = {}) => {
|
|
|
506
493
|
|
|
507
494
|
// src/actions/package/copy-assets.ts
|
|
508
495
|
import path3 from "node:path/posix";
|
|
509
|
-
import
|
|
496
|
+
import chalk8 from "chalk";
|
|
510
497
|
import cpy from "cpy";
|
|
511
498
|
var copyTargetAssets = /* @__PURE__ */ __name(async (target, name, location) => {
|
|
512
499
|
try {
|
|
@@ -525,7 +512,7 @@ var copyTargetAssets = /* @__PURE__ */ __name(async (target, name, location) =>
|
|
|
525
512
|
flat: false
|
|
526
513
|
});
|
|
527
514
|
if (values.length > 0) {
|
|
528
|
-
console.log(
|
|
515
|
+
console.log(chalk8.green(`Copying Assets [${target.toUpperCase()}] - ${name} - ${location}`));
|
|
529
516
|
}
|
|
530
517
|
for (const value of values) {
|
|
531
518
|
console.log(`${value.split("/").pop()} => ./dist/${target}`);
|
|
@@ -553,169 +540,10 @@ var packageCopyAssets = /* @__PURE__ */ __name(async ({ target }) => {
|
|
|
553
540
|
}
|
|
554
541
|
}, "packageCopyAssets");
|
|
555
542
|
|
|
556
|
-
// src/actions/package/deps.ts
|
|
557
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
558
|
-
import { cwd as cwd3 } from "node:process";
|
|
559
|
-
import chalk10 from "chalk";
|
|
560
|
-
import depcheck from "depcheck";
|
|
561
|
-
var special = depcheck.special;
|
|
562
|
-
var defaultIgnorePatterns = [
|
|
563
|
-
"*.d.ts",
|
|
564
|
-
"dist",
|
|
565
|
-
".*",
|
|
566
|
-
"node_modules"
|
|
567
|
-
];
|
|
568
|
-
var defaultIgnoreDevDeps = [
|
|
569
|
-
"@xylabs/ts-scripts-yarn3",
|
|
570
|
-
"@xylabs/tsconfig",
|
|
571
|
-
"@xylabs/tsconfig-dom",
|
|
572
|
-
"@xylabs/tsconfig-react",
|
|
573
|
-
"typescript"
|
|
574
|
-
];
|
|
575
|
-
var defaultIgnoreDevPatterns = [
|
|
576
|
-
"*.stories.*",
|
|
577
|
-
"*.spec.*",
|
|
578
|
-
"spec",
|
|
579
|
-
"stories",
|
|
580
|
-
"tsconfig.json"
|
|
581
|
-
];
|
|
582
|
-
var reportUnused = /* @__PURE__ */ __name((name, unused) => {
|
|
583
|
-
if (unused.length > 0) {
|
|
584
|
-
const message = [
|
|
585
|
-
chalk10.yellow(`${unused.length} Unused ${name}`)
|
|
586
|
-
];
|
|
587
|
-
for (const value of unused) message.push(chalk10.gray(` ${value}`));
|
|
588
|
-
console.log(message.join("\n"));
|
|
589
|
-
}
|
|
590
|
-
}, "reportUnused");
|
|
591
|
-
var reportMissing = /* @__PURE__ */ __name((name, missing) => {
|
|
592
|
-
if (Object.keys(missing).length > 0) {
|
|
593
|
-
const message = [
|
|
594
|
-
chalk10.yellow(`${Object.entries(missing).length} Missing ${name}`)
|
|
595
|
-
];
|
|
596
|
-
for (const [key, value] of Object.entries(missing)) {
|
|
597
|
-
message.push(`${key}`, chalk10.gray(` ${value.at(0)}`));
|
|
598
|
-
}
|
|
599
|
-
console.log(chalk10.yellow(message.join("\n")));
|
|
600
|
-
}
|
|
601
|
-
}, "reportMissing");
|
|
602
|
-
var analyzeDeps = /* @__PURE__ */ __name(async (pkg, ignoreMatches) => {
|
|
603
|
-
const packageContent = existsSync(`${pkg}/package.json`) ? JSON.parse(readFileSync(`${pkg}/package.json`, {
|
|
604
|
-
encoding: "utf8"
|
|
605
|
-
})) : void 0;
|
|
606
|
-
const [srcUnused, allUnused] = await Promise.all([
|
|
607
|
-
depcheck(`${pkg}/src`, {
|
|
608
|
-
ignoreMatches,
|
|
609
|
-
ignorePatterns: [
|
|
610
|
-
...defaultIgnoreDevPatterns,
|
|
611
|
-
...defaultIgnorePatterns
|
|
612
|
-
],
|
|
613
|
-
package: packageContent
|
|
614
|
-
}),
|
|
615
|
-
depcheck(`${pkg}/.`, {
|
|
616
|
-
ignoreMatches: [
|
|
617
|
-
...ignoreMatches,
|
|
618
|
-
...defaultIgnoreDevDeps
|
|
619
|
-
],
|
|
620
|
-
ignorePatterns: [
|
|
621
|
-
...defaultIgnorePatterns
|
|
622
|
-
],
|
|
623
|
-
package: packageContent,
|
|
624
|
-
specials: [
|
|
625
|
-
special.eslint,
|
|
626
|
-
special.babel,
|
|
627
|
-
special.bin,
|
|
628
|
-
special.prettier,
|
|
629
|
-
special.jest,
|
|
630
|
-
special.mocha
|
|
631
|
-
]
|
|
632
|
-
})
|
|
633
|
-
]);
|
|
634
|
-
const unusedDeps = srcUnused.dependencies;
|
|
635
|
-
const unusedDevDeps = allUnused.devDependencies;
|
|
636
|
-
const usedDeps = srcUnused.using;
|
|
637
|
-
const usedDevDeps = allUnused.using;
|
|
638
|
-
const missing = {
|
|
639
|
-
...srcUnused.missing,
|
|
640
|
-
...allUnused.missing
|
|
641
|
-
};
|
|
642
|
-
const { invalidDirs, invalidFiles } = allUnused;
|
|
643
|
-
return {
|
|
644
|
-
invalidDirs,
|
|
645
|
-
invalidFiles,
|
|
646
|
-
missing,
|
|
647
|
-
unusedDeps,
|
|
648
|
-
unusedDevDeps,
|
|
649
|
-
usedDeps,
|
|
650
|
-
usedDevDeps
|
|
651
|
-
};
|
|
652
|
-
}, "analyzeDeps");
|
|
653
|
-
var packageDeps = /* @__PURE__ */ __name(async () => {
|
|
654
|
-
const pkg = process.env.INIT_CWD ?? cwd3();
|
|
655
|
-
const pkgName = process.env.npm_package_name;
|
|
656
|
-
const packageContent = existsSync(`${pkg}/package.json`) ? JSON.parse(readFileSync(`${pkg}/package.json`, {
|
|
657
|
-
encoding: "utf8"
|
|
658
|
-
})) : void 0;
|
|
659
|
-
const rawIgnore = existsSync(`${pkg}/.depcheckrc`) ? readFileSync(`${pkg}/.depcheckrc`, {
|
|
660
|
-
encoding: "utf8"
|
|
661
|
-
}).replace("ignores:", '"ignores":') : void 0;
|
|
662
|
-
let ignoreMatches = [];
|
|
663
|
-
try {
|
|
664
|
-
ignoreMatches = rawIgnore ? JSON.parse(`{${rawIgnore}}`).ignores : [];
|
|
665
|
-
} catch (ex) {
|
|
666
|
-
const error = ex;
|
|
667
|
-
console.log(`${pkgName} [${error.message}] Failed to parse .depcheckrc [${rawIgnore}]`);
|
|
668
|
-
}
|
|
669
|
-
const { invalidDirs, invalidFiles, unusedDeps, unusedDevDeps, usedDeps, usedDevDeps, missing } = await analyzeDeps(pkg, ignoreMatches);
|
|
670
|
-
const declaredDeps = Object.keys(packageContent.dependencies ?? {});
|
|
671
|
-
const declaredPeerDeps = Object.keys(packageContent.peerDependencies ?? {});
|
|
672
|
-
const declaredDevDeps = Object.keys(packageContent.devDependencies ?? {});
|
|
673
|
-
const missingDeps = Object.keys(usedDeps).filter((key) => !declaredDeps.includes(key) && !declaredPeerDeps.includes(key) && !key.startsWith("@types/"));
|
|
674
|
-
const missingDevDeps = Object.keys(usedDevDeps).filter((key) => !declaredDevDeps.includes(key) && !declaredDeps.includes(key));
|
|
675
|
-
const missingDepsObject = {};
|
|
676
|
-
for (const key of missingDeps) {
|
|
677
|
-
missingDepsObject[key] = missing[key] ?? [
|
|
678
|
-
`devDep should be dep [${key}]`
|
|
679
|
-
];
|
|
680
|
-
}
|
|
681
|
-
const missingDevDepsObject = {};
|
|
682
|
-
for (const key of missingDevDeps) {
|
|
683
|
-
if (missing[key]) {
|
|
684
|
-
missingDevDepsObject[key] = missing[key];
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
const errorCounts = [
|
|
688
|
-
unusedDeps.length,
|
|
689
|
-
unusedDevDeps.length,
|
|
690
|
-
Object.entries(invalidDirs).length,
|
|
691
|
-
Object.entries(invalidFiles).length,
|
|
692
|
-
Object.entries(missingDepsObject).length,
|
|
693
|
-
Object.entries(missingDevDepsObject).length
|
|
694
|
-
];
|
|
695
|
-
const errorCount = errorCounts.reduce((prev, count) => prev + count, 0);
|
|
696
|
-
if (errorCount > 0) {
|
|
697
|
-
console.log(`Deps [${pkgName}] = (${JSON.stringify(errorCounts)})`);
|
|
698
|
-
} else {
|
|
699
|
-
console.log(`Deps [${pkgName}] - Ok`);
|
|
700
|
-
}
|
|
701
|
-
reportUnused("dependencies", unusedDeps);
|
|
702
|
-
reportUnused("devDependencies", unusedDevDeps);
|
|
703
|
-
if (Object.entries(invalidDirs).length > 0) {
|
|
704
|
-
for (const [key, value] of Object.entries(invalidDirs)) console.warn(chalk10.gray(`Invalid Dir: ${key}: ${value}`));
|
|
705
|
-
}
|
|
706
|
-
if (Object.entries(invalidFiles).length > 0) {
|
|
707
|
-
for (const [key, value] of Object.entries(invalidFiles)) console.warn(chalk10.gray(`Invalid File: ${key}: ${value}`));
|
|
708
|
-
}
|
|
709
|
-
reportMissing("dependencies", missingDepsObject);
|
|
710
|
-
reportMissing("devDependencies", missingDevDepsObject);
|
|
711
|
-
checkResult(`Deps [${pkgName}]`, errorCount, "warn", false);
|
|
712
|
-
return 0;
|
|
713
|
-
}, "packageDeps");
|
|
714
|
-
|
|
715
543
|
// src/actions/package/gen-docs.ts
|
|
716
|
-
import { existsSync
|
|
544
|
+
import { existsSync } from "node:fs";
|
|
717
545
|
import path4 from "node:path";
|
|
718
|
-
import
|
|
546
|
+
import chalk9 from "chalk";
|
|
719
547
|
import { Application, ArgumentsReader, TSConfigReader, TypeDocReader } from "typedoc";
|
|
720
548
|
var ExitCodes = {
|
|
721
549
|
CompileError: 3,
|
|
@@ -728,7 +556,7 @@ var ExitCodes = {
|
|
|
728
556
|
};
|
|
729
557
|
var packageGenDocs = /* @__PURE__ */ __name(async () => {
|
|
730
558
|
const pkg = process.env.INIT_CWD;
|
|
731
|
-
if (pkg && !
|
|
559
|
+
if (pkg && !existsSync(path4.join(pkg, "typedoc.json"))) {
|
|
732
560
|
return;
|
|
733
561
|
}
|
|
734
562
|
const app = await Application.bootstrap({
|
|
@@ -817,16 +645,16 @@ var runTypeDoc = /* @__PURE__ */ __name(async (app) => {
|
|
|
817
645
|
return ExitCodes.OutputError;
|
|
818
646
|
}
|
|
819
647
|
}
|
|
820
|
-
console.log(
|
|
648
|
+
console.log(chalk9.green(`${pkgName} - Ok`));
|
|
821
649
|
return ExitCodes.Ok;
|
|
822
650
|
}, "runTypeDoc");
|
|
823
651
|
|
|
824
652
|
// src/actions/package/lint.ts
|
|
825
653
|
import { readdirSync } from "node:fs";
|
|
826
654
|
import path5 from "node:path";
|
|
827
|
-
import { cwd as
|
|
655
|
+
import { cwd as cwd3 } from "node:process";
|
|
828
656
|
import { pathToFileURL } from "node:url";
|
|
829
|
-
import
|
|
657
|
+
import chalk10 from "chalk";
|
|
830
658
|
import { ESLint } from "eslint";
|
|
831
659
|
import { findUp } from "find-up";
|
|
832
660
|
import picomatch from "picomatch";
|
|
@@ -843,10 +671,10 @@ var dumpMessages = /* @__PURE__ */ __name((lintResults) => {
|
|
|
843
671
|
];
|
|
844
672
|
for (const lintResult of lintResults) {
|
|
845
673
|
if (lintResult.messages.length > 0) {
|
|
846
|
-
console.log(
|
|
674
|
+
console.log(chalk10.gray(`
|
|
847
675
|
${lintResult.filePath}`));
|
|
848
676
|
for (const message of lintResult.messages) {
|
|
849
|
-
console.log(
|
|
677
|
+
console.log(chalk10.gray(` ${message.line}:${message.column}`), chalk10[colors[message.severity]](` ${severity[message.severity]}`), chalk10.white(` ${message.message}`), chalk10.gray(` ${message.ruleId}`));
|
|
850
678
|
}
|
|
851
679
|
}
|
|
852
680
|
}
|
|
@@ -860,7 +688,7 @@ async function getRootESLintConfig() {
|
|
|
860
688
|
}
|
|
861
689
|
__name(getRootESLintConfig, "getRootESLintConfig");
|
|
862
690
|
function getFiles(dir, ignoreFolders) {
|
|
863
|
-
const currentDirectory =
|
|
691
|
+
const currentDirectory = cwd3();
|
|
864
692
|
const subDirectory = dir.split(currentDirectory)[1];
|
|
865
693
|
if (ignoreFolders.includes(subDirectory)) return [];
|
|
866
694
|
return readdirSync(dir, {
|
|
@@ -899,9 +727,9 @@ var packageLint = /* @__PURE__ */ __name(async (fix = false, verbose = false, ca
|
|
|
899
727
|
warnIgnored: false,
|
|
900
728
|
cache
|
|
901
729
|
});
|
|
902
|
-
const files = getFiles(
|
|
730
|
+
const files = getFiles(cwd3(), ignoreFolders);
|
|
903
731
|
if (verbose) {
|
|
904
|
-
console.log(
|
|
732
|
+
console.log(chalk10.green(`Linting ${pkg} [files = ${files.length}]`));
|
|
905
733
|
}
|
|
906
734
|
const lintResults = await engine.lintFiles(files);
|
|
907
735
|
dumpMessages(lintResults);
|
|
@@ -911,7 +739,7 @@ var packageLint = /* @__PURE__ */ __name(async (fix = false, verbose = false, ca
|
|
|
911
739
|
const filesCountColor = files.length < 100 ? "green" : files.length < 1e3 ? "yellow" : "red";
|
|
912
740
|
const lintTime = Date.now() - start;
|
|
913
741
|
const lintTimeColor = lintTime < 1e3 ? "green" : lintTime < 3e3 ? "yellow" : "red";
|
|
914
|
-
console.log(
|
|
742
|
+
console.log(chalk10.white(`Linted ${chalk10[filesCountColor](files.length)} files in ${chalk10[lintTimeColor](lintTime)}ms`));
|
|
915
743
|
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
916
744
|
}, "packageLint");
|
|
917
745
|
|
|
@@ -929,7 +757,6 @@ export {
|
|
|
929
757
|
packageCompileTsup,
|
|
930
758
|
packageCompileTypes,
|
|
931
759
|
packageCopyAssets,
|
|
932
|
-
packageDeps,
|
|
933
760
|
packageGenDocs,
|
|
934
761
|
packageLint,
|
|
935
762
|
packagePublint,
|