@kitschpatrol/shared-config 6.2.0 → 7.0.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/bin/cli.js +11 -11
- package/package.json +12 -18
- package/readme.md +15 -18
package/bin/cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cosmiconfig as e}from"cosmiconfig";import{TypeScriptLoader as t}from"cosmiconfig-typescript-loader";import{execa as n}from"execa";import r from"fs-extra";import i,{constants as a}from"node:fs";import o from"node:path";import{PassThrough as s,Transform as c}from"node:stream";import{fileURLToPath as l}from"node:url";import{packageUp as u,packageUpSync as d}from"package-up";import f from"picocolors";import p from"yargs";import{hideBin as m}from"yargs/helpers";import h from"@pinojs/json-colorizer";import g from"decircular";import _ from"deepmerge";import v from"json-stringify-pretty-compact";import{findWorkspaces as ee,findWorkspacesRoot as y}from"find-workspaces";import b,{access as te}from"node:fs/promises";import{
|
|
2
|
+
import{cosmiconfig as e}from"cosmiconfig";import{TypeScriptLoader as t}from"cosmiconfig-typescript-loader";import{execa as n}from"execa";import r from"fs-extra";import i,{constants as a}from"node:fs";import o from"node:path";import{PassThrough as s,Transform as c}from"node:stream";import{fileURLToPath as l}from"node:url";import{packageUp as u,packageUpSync as d}from"package-up";import f from"picocolors";import p from"yargs";import{hideBin as m}from"yargs/helpers";import h from"@pinojs/json-colorizer";import g from"decircular";import _ from"deepmerge";import v from"json-stringify-pretty-compact";import{findWorkspaces as ee,findWorkspacesRoot as y}from"find-workspaces";import b,{access as te}from"node:fs/promises";import{stripVTControlCharacters as x}from"node:util";import{getDefaultConfigLoader as S,resolveConfigFileImports as C}from"cspell-lib";import{lint as ne}from"cspell";import"deepmerge-ts";import{loadConfig as w}from"mdat";import{globby as re}from"globby";import T,{gt as E,minVersion as ie}from"semver";import{readWantedLockfile as ae}from"@pnpm/lockfile.fs";import oe from"stylelint";var se=`7.0.1`;function ce(e){return e instanceof Error&&`exitCode`in e&&typeof e.exitCode==`number`}function D(e){return h(v(g(e),{indent:2,replacer(e,t){return typeof t==`function`?t.name:t}}),{colors:{BRACKET:`gray`}})}const le=(e,t,n)=>{let r=[...e];for(let[i,a]of t.entries())r[i]===void 0?r[i]=n.cloneUnlessOtherwiseSpecified(a,n):n.isMergeableObject(a)?r[i]=O(e[i],a,n):e.includes(a)||r.push(a);return r};function O(e,t,n={arrayMerge:le}){return _(e,t,n)}function ue(e,t){return e.startsWith(t+o.sep)}function de(){let e=k(),t=new Set([e]),n=ee();if(n!==null)for(let r of n){let n=o.resolve(r.location);ue(n,e)&&t.add(n)}return[...t]}function k(){let e=d();if(e===void 0)throw Error(`No package.json found.`);return o.dirname(e)}function fe(){return y()!==null}function A(){let e=y();return e===null?k():o.resolve(e.location)}function j(e){let t=o.join(A(),e);if(r.existsSync(t))return t}function M(e){if(e===`workspace-root`)return A();if(e===`package-dir`)return k();if(typeof e==`string`){if(!r.pathExistsSync(e))throw Error(`Custom cwd directory does not exist: ${e}`);return e}return process.cwd()}async function pe(e,t){try{let{default:n}=await import(`prettier`),r=await n.resolveConfig(e),i=await n.format(t,{filepath:e,...r});await b.writeFile(e,i,`utf8`)}catch{console.warn(`Skipped formatting ${e} since Prettier is not installed.`)}}async function N(e){try{await pe(e,await b.readFile(e,`utf8`))}catch{}}const P=/\r?\n/;function F(e){return new c({transform(t,n,r){let i=t.toString().split(P).filter(t=>t.trim()!==``&&!e(x(t))).join(`
|
|
3
3
|
`);this.push(i+`
|
|
4
|
-
`),r()}})}function
|
|
5
|
-
`);for(let e of t)c.write(`${e}\n`)}o=e.exitCode??1}catch(e){console.error(`${i.name} failed with error:`),console.error(e),
|
|
6
|
-
`),1;let d=o.join(o.dirname(c),`init`),f=o.dirname(s),p=(t===`file`||t===`package`)&&n!==void 0&&a!==void 0;try{if(p){let n=Object.keys(a)[0];if(t===`package`){let t=r.readJsonSync(s);e.write(`Merging: \nPackage config key "${n}" → "${f}" (Because --location is set to "package")\n`);let i=
|
|
7
|
-
`),0;let o=
|
|
8
|
-
`);for(let e of o)t.write(`${e}\n`);return 0},name:`Cosmiconfig ${e}`}}async function
|
|
9
|
-
`);for(let t of n)e.write(`${t}\n`);return 0}const
|
|
10
|
-
`);for(let t of r)e.write(`${t}\n`);return 0}async function
|
|
11
|
-
`);for(let n of t)e.write(`${n}\n`);return 0}async function
|
|
12
|
-
`),0;e.write(`Found ${n} configuration at "${i}"\n`);let s;t.length>0?(s=o.join(process.cwd(),t[0]),e.write(`Showing config for file at "${s}"\n`)):s=
|
|
13
|
-
`);for(let t of c)e.write(`${t}\n`);return 0}const
|
|
4
|
+
`),r()}})}function I(e,t){return new c({transform(n,r,i){let a=n.toString().split(P).filter(e=>e.trim().length>0).map(n=>`${e?t===void 0?e:f[t](e):``} ${n}\n`).join(``);this.push(a),i()}})}async function me(e){let t=[];return new Promise((n,r)=>{e.on(`data`,e=>t.push(e)),e.on(`error`,e=>{r(e)}),e.on(`end`,()=>{n(Buffer.concat(t).toString(`utf8`))})})}function he(e){return e.replaceAll(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,e=>`-`+e.toLowerCase())}function L(e,t){return t===1?e:e+`s`}async function ge(e,t,n,r,i){let a=1,o;if(r.logPrefix===void 0)o=e;else{let t=I(r.logPrefix,r.logColor);t.pipe(e),o=t}i&&o.write(f.bold(`Running: "${r.name}() with Positional arguments: ${String(t)} and Option flags: ${String(n)}"`));try{a=await r.execute(o,t,n)}catch(e){console.error(String(e)),a=1}return a}async function _e(e,t,r,i,a){let o=1,c;if(i.logPrefix===void 0)c=e;else{let t=I(i.logPrefix,i.logColor);t.pipe(e),c=t}let l=i.subcommands??[],u=[...i.receivePositionalArguments?t:[],...i.positionalArguments??[]],d=[...i.receiveOptionFlags?r:[],...i.optionFlags??[]],f=[...l,...d,...u],p=M(i.cwdOverride);a&&c.write(`Running: "${i.name} ${f.join(` `)}"`);let m=i.prettyJsonOutput?new s:c;try{let e=n(i.name,f,{cwd:p,env:{...process.env.NO_COLOR===void 0?{FORCE_COLOR:`true`}:{}},preferLocal:!0,reject:!1,stdin:`inherit`});if(i.outputFilter){let t=F(i.outputFilter),n=F(i.outputFilter);e.stdout.pipe(t).pipe(m,{end:!1}),e.stderr.pipe(n).pipe(m,{end:!1})}else e.stdout.pipe(m,{end:!1}),e.stderr.pipe(m,{end:!1});if(await e,i.prettyJsonOutput){m.end();let e=await me(m),t=D(JSON.parse(e)).split(`
|
|
5
|
+
`);for(let e of t)c.write(`${e}\n`)}o=e.exitCode??1}catch(e){console.error(`${i.name} failed with error:`),console.error(e),ce(e)&&(o=typeof e.exitCode==`number`?e.exitCode:1)}return o}function ve(e){return`execute`in e}async function R(e,t,n,r,i,a){let o=[];for(let a of r){let r=await(ve(a)?ge(e,t,n,a,i):_e(e,t,n,a,i));o.push({exitCode:r,name:a.name})}if(a){let t=o.filter(({exitCode:e})=>e===0).map(({name:e})=>e),n=o.filter(({exitCode:e})=>e!==0).map(({name:e})=>e),r=o.length;t.length>0&&e.write(`✅ ${f.green(f.bold(`${t.length} / ${r} ${L(`Command`,t.length)} Succeeded:`))} ${f.green(t.join(`, `))}\n`),n.length>0&&e.write(`❌ ${f.red(f.bold(`${n.length} / ${r} ${L(`Command`,n.length)} Failed:`))} ${f.red(n.join(`, `))}\n`)}return o.every(({exitCode:e})=>e===0)?0:1}async function ye(e,t,n,a){let s=await u();if(s===void 0)throw Error("The `init` command must be used in a directory with a package.json file");let c=await u({cwd:l(import.meta.url)});if(c===void 0)return e.write(`Error: The script being called was not in a package, weird.
|
|
6
|
+
`),1;let d=o.join(o.dirname(c),`init`),f=o.dirname(s),p=(t===`file`||t===`package`)&&n!==void 0&&a!==void 0;try{if(p){let n=Object.keys(a)[0];if(t===`package`){let t=r.readJsonSync(s);e.write(`Merging: \nPackage config key "${n}" → "${f}" (Because --location is set to "package")\n`);let i=O(t,a);r.writeJSONSync(s,i,{spaces:` `}),await N(s)}else{let t=r.readJsonSync(s);Object.keys(t).includes(n)&&(e.write(`Deleting: \nPackage config key "${n}" in "${f}" (Because --location is set to "file")\n`),delete t[n],r.writeJSONSync(s,t,{spaces:` `}),await N(s))}}if(!await r.pathExists(d))return 0;if((await r.readdir(d)).length===0)return e.write(`Source directory "${d}" is empty.\n`),0;e.write(`Adding initial configuration files from:\n"${d}" → "${f}"\n`),await r.copy(d,f,{async filter(a,s){let c=i.statSync(a).isFile(),l=i.existsSync(s);if(c){if(p&&t===`package`&&a.includes(n))return l?(e.write(`Deleting: \n"${a}" → "${s}" (Because --location is set to "package")\n`),r.removeSync(s)):e.write(`Skipping: \n"${a}" → "${s}" (Because --location is set to "package")\n`),!1;if(l&&(s.includes(`.vscode/`)||s.includes(`package.json`))&&o.extname(s)===`.json`){e.write(`Merging: \n"${a}" → "${s}"\n`);let t=r.readJSONSync(a),n=O(r.readJSONSync(s),t);return r.writeJSONSync(s,n,{spaces:` `}),await N(s),!1}return l?(e.write(`Overwriting: \n"${a}" → "${s}"\n`),await N(s),!0):(e.write(`Copying: \n"${a}" → "${s}"\n`),await N(s),!0)}return!0},overwrite:!0})}catch(e){return console.error(String(e)),1}return 0}async function be(e){let{commands:{fix:t,init:n,lint:r,printConfig:i},description:a,logColor:o,logPrefix:s,name:c,showSummary:l,verbose:u}=e,d=I(s,o);d.pipe(process.stdout);let f=p(m(process.argv)).scriptName(c).usage(`$0 <command>`,a);n!==void 0&&f.command({builder(e){return n.locationOptionFlag?e.option(`location`,{choices:[`file`,`package`],default:`file`,describe:`Where to store the configuration.`,type:`string`}):e},command:`init`,describe:n.description??`Initialize by copying starter config files to your project root${n.locationOptionFlag?` or to your package.json file.`:`.`}`,async handler(e){let t=n.locationOptionFlag?e.location:void 0,r=await R(d,[],t===void 0?[]:[`--location`,t],[{async execute(e,t,r){return ye(e,r.at(1),n.configFile,n.configPackageJson)},name:`copyAndMergeInitFiles`},...n.commands??[]]);process.exit(r)}}),r!==void 0&&f.command({builder(e){return r.positionalArgumentMode===`none`?e:e.positional(`files`,{array:!0,...r.positionalArgumentDefault===void 0?{}:{default:r.positionalArgumentDefault},describe:`Files or glob pattern to lint.`,type:`string`})},command:r.positionalArgumentMode===`none`?`lint`:r.positionalArgumentMode===`optional`?`lint [files..]`:`lint <files..>`,describe:r.description,async handler(e){let t=await R(d,e.files??[],[],r.commands,u,l);process.exit(t)}}),t!==void 0&&f.command({builder(e){return t.positionalArgumentMode===`none`?e:e.positional(`files`,{array:!0,...t.positionalArgumentDefault===void 0?{}:{default:t.positionalArgumentDefault},describe:`Files or glob pattern to fix.`,type:`string`})},command:t.positionalArgumentMode===`none`?`fix`:t.positionalArgumentMode===`optional`?`fix [files..]`:`fix <files..>`,describe:t.description,async handler(e){let n=await R(d,e.files??[],[],t.commands);process.exit(n)}}),i!==void 0&&f.command({builder(e){return i.positionalArgumentMode===`none`?e:e.positional(`file`,{...i.positionalArgumentDefault===void 0?{}:{default:i.positionalArgumentDefault},describe:`File or glob pattern to print configuration for.`,type:`string`})},command:i.positionalArgumentMode===`none`?`print-config`:i.positionalArgumentMode===`optional`?`print-config [file]`:`print-config <file>`,describe:i.description,async handler(e){let t=e.file??void 0,n=await R(d,t===void 0?[]:[t],[],i.commands,u,l);process.exit(n)}}),f.alias(`h`,`help`),f.version(se),f.alias(`v`,`version`),f.help(),f.wrap(process.stdout.isTTY?Math.min(120,f.terminalWidth()):0),await f.parseAsync()}function z(e){return{async execute(t){let n=await B(e);if(n===void 0)return 1;let{config:r,filepath:i,isEmpty:a}=n;if(t.write(`Found ${e} configuration at "${i}"\n`),a)return t.write(`Configuration is empty.
|
|
7
|
+
`),0;let o=D(r).split(`
|
|
8
|
+
`);for(let e of o)t.write(`${e}\n`);return 0},name:`Cosmiconfig ${e}`}}async function B(n){let r=e(n,{loaders:{".ts":t()},searchStrategy:`project`});try{let e=await r.search();if(e===null){console.error(`No ${n} configuration found.`);return}return e}catch(e){console.error(`Error while searching for ${n} configuration:`,e);return}}const V={fileRun:`Matches files below the current working directory by default.`,monorepoRun:`In a monorepo, it will also run in all packages below the current working directory.`,monorepoSearch:`Searches up to the root of a monorepo if necessary.`,multiArgumentCaveat:`Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope.`,multiOptionCaveat:`Will use option flags where possible if provided, but some of the invoked tools will ignore them.`,optionalFileRun:`Package-scoped by default, file-scoped if a file argument is provided.`,packageRun:`Package-scoped.`,packageSearch:`Package-scoped.`},xe=/['\u2019\u2018]s$/;async function Se(e=[`.`]){let t=await S().searchForConfigFile(void 0);if(t===void 0)throw Error(`No CSpell configuration found.`);let{settings:n,url:r}=t;if(n.words===void 0||n.words.length===0)return[];let i=[...n.words];return n.words=void 0,await ne(e,{config:{settings:n,url:r},progress:!1,unique:!0,wordsOnly:!0},{issue({text:e,uri:t}){i=i.filter(n=>n.toLowerCase()!==e.toLowerCase().replace(xe,``)||t===r.href)}}),i}async function Ce(){let e=await S().searchForConfigFile(void 0);if(e===void 0)throw Error(`No CSpell configuration found.`);let t=await C(e);if(t.ignorePaths===void 0)return``;let n=[];for(let e of t.ignorePaths)n.push(typeof e==`string`?e:e.glob);return n.join(`,`)}async function H(e,t){let n=await Se(t);if(n.length>0){let t=I(`[Unused Words]`,`cyanBright`);t.pipe(e);for(let e of n)t.write(`${e}\n`);return 1}return 0}async function we(){let e=import.meta.resolve(`@kitschpatrol/cspell-config`),t=await u({cwd:o.dirname(l(e))});if(t===void 0)throw Error(`Could not find Case Police dictionary parent package.`);let n=o.join(o.dirname(t),`dictionaries`,`case-police.json`);try{await te(n,a.F_OK)}catch{throw Error(`Case Police dictionary file "${n}" does not exist.`)}return n}async function U(e,t){let n=`[Case Police]`,r=F(e=>{let t=x(e);return!t.startsWith(n)||!t.includes(`→`)});return r.pipe(e),R(r,t,[],[{logColor:`cyanBright`,logPrefix:n,name:`case-police`,optionFlags:[`--dict`,await we(),`--ignore`,await Ce()],receivePositionalArguments:!0}])}async function W(e){let t=await S().searchForConfigFile(void 0);if(t===void 0)throw Error(`No CSpell configuration found.`);e.write(`Found cspell readme configuration at "${l(t.url)}"\n`);let n=D(await C(t)).split(`
|
|
9
|
+
`);for(let t of n)e.write(`${t}\n`);return 0}const Te={commands:{init:{configFile:`cspell.config.ts`,configPackageJson:{cspell:{import:`@kitschpatrol/cspell-config`}},locationOptionFlag:!0},lint:{commands:[{name:`cspell`,optionFlags:[`--quiet`],receivePositionalArguments:!0},{execute:H,name:H.name},{execute:U,name:U.name}],description:`Check for spelling mistakes. ${V.fileRun}`,positionalArgumentDefault:`**/*`,positionalArgumentMode:`optional`},printConfig:{commands:[{execute:W,name:W.name}],description:`Print the resolved CSpell configuration. ${V.packageSearch} ${V.monorepoSearch}`,positionalArgumentMode:`none`}},description:`Kitschpatrol's CSpell shared configuration tools. (Automated fixes are handled by ESLint.)`,logColor:`cyan`,logPrefix:`[CSpell]`,name:`ksc-cspell`,order:6};async function G(e,t){let n;if(t.length>0){let r=o.join(process.cwd(),t[0]);e.write(`Showing configuration for file: ${r}\n`),n={name:`eslint`,optionFlags:[`--print-config`],receivePositionalArguments:!0}}else n=z(`eslint`);return R(e,t,[],[n])}const Ee={commands:{fix:{commands:[{name:`eslint`,optionFlags:[`--fix`],receivePositionalArguments:!0}],description:`Fix your project with ESLint. ${V.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},init:{locationOptionFlag:!1},lint:{commands:[{name:`eslint`,optionFlags:[`--max-warnings`,`0`],receivePositionalArguments:!0}],description:`Lint your project with ESLint. ${V.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},printConfig:{commands:[{execute:G,name:G.name}],description:`Print the effective ESLint configuration. ${V.optionalFileRun} Use \`@eslint/config-inspector\` for a more detailed view.`,positionalArgumentMode:`optional`}},description:`Kitschpatrol's ESLint shared configuration tools.`,logColor:`magenta`,logPrefix:`[ESLint]`,name:`ksc-eslint`,order:4},De={entry:[`{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!`,`src/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!`,`src/{bin,lib,cli}/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!`,`scripts/**/*.{js,mjs,cjs,ts,mts,cts}`,`.remarkrc.{js,mjs,cjs,ts,mts,cts}`,`cspell.config.{js,mjs,cjs,ts,mts,cts}`,`eslint.config.{js,mjs,cjs,ts,mts,cts}`,`mdat.config.{js,mjs,cjs,ts,mts,cts}`,`prettier.config.{js,mjs,cjs,ts,mts,cts}`,`stylelint.config.{js,mjs,cjs,ts,mts,cts}`],ignoreBinaries:[`ksc-repo`,`ksc-mdat`,`ksc-typescript`,`ksc-eslint`,`ksc-stylelint`,`ksc-cspell`,`ksc-knip`,`ksc-remark`,`ksc-prettier`,`op`,`gh`],ignoreDependencies:[`@kitschpatrol/cspell-config`,`@kitschpatrol/dict-en-wiktionary`,`@kitschpatrol/eslint-config`,`@kitschpatrol/knip-config`,`@kitschpatrol/mdat-config`,`@kitschpatrol/prettier-config`,`@kitschpatrol/remark-config`,`@kitschpatrol/repo-config`,`@kitschpatrol/stylelint-config`,`@kitschpatrol/typescript-config`,`@prettier/plugin-php`,`@prettier/plugin-ruby`,`@prettier/plugin-xml`,`prettier-plugin-packagejson`,`prettier-plugin-sh`,`prettier-plugin-tailwindcss`,`prettier-plugin-toml`]};function Oe(){if(fe()){let e=k(),t=A();if(e!==t){let n=o.relative(t,e);if(n)return[`--workspace`,n.split(o.sep).join(`/`)]}}return[]}function ke(){return{knip:De}}const Ae={commands:{init:{configFile:`knip.config.ts`,configPackageJson:ke(),locationOptionFlag:!0},lint:{commands:[{cwdOverride:`workspace-root`,name:`knip`,optionFlags:[`--no-progress`,`--no-config-hints`,...Oe()]}],description:`Check for unused code and dependencies. ${V.packageRun} ${V.monorepoRun}`,positionalArgumentMode:`none`},printConfig:{commands:[z(`knip`)],description:`Print the effective Knip configuration. ${V.packageSearch} ${V.monorepoSearch}`,positionalArgumentMode:`none`}},description:`Kitschpatrol's Knip shared configuration tools.`,logColor:`cyan`,logPrefix:`[Knip]`,name:`ksc-knip`,order:7};async function je(){return(await B(`mdat`))?.filepath}async function K(e){let t=`mdat`,n=await B(t);n!==void 0&&e.write(`Found ${t} readme configuration at "${n.filepath}"\n`);let r=D(await w({additionalConfig:await w()})).split(`
|
|
10
|
+
`);for(let t of r)e.write(`${t}\n`);return 0}async function q(e){let t=de(),n=await je(),r=[];for(let i of t)r.push({cwdOverride:i,name:`mdat`,optionFlags:n?[`--config`,n,`--format`]:[`--format`],subcommands:[e]});return r}const Me={commands:{fix:{commands:await q(`expand`),description:`Expand all Mdat content placeholders in your readme.md file(s). ${V.packageRun} ${V.monorepoRun}`,positionalArgumentMode:`none`},init:{configFile:`mdat.config.ts`,configPackageJson:{mdat:{$import:`node_modules/@kitschpatrol/mdat-config/dist/index.js`}},locationOptionFlag:!0},lint:{commands:await q(`check`),description:`Validate that all Mdat content placeholders in your readme.md file(s) have been expanded and are up to date. ${V.packageRun} ${V.monorepoRun}`,positionalArgumentMode:`none`},printConfig:{commands:[{execute:K,name:K.name}],description:`Print the effective Mdat configuration. ${V.packageSearch}. ${V.monorepoSearch}.`,positionalArgumentMode:`none`}},description:`Kitschpatrol's Mdat shared configuration tools.`,logColor:`green`,logPrefix:`[Mdat Config]`,name:`ksc-mdat`,order:2},J=[`--log-level=warn`,`--plugin=@prettier/plugin-php`,`--plugin=@prettier/plugin-ruby`,`--plugin=@prettier/plugin-xml`,`--plugin=prettier-plugin-astro`,`--plugin=prettier-plugin-packagejson`,`--plugin=prettier-plugin-sh`,`--plugin=prettier-plugin-svelte`,`--plugin=prettier-plugin-toml`,`--ignore-path=${j(`.gitignore`)??`.gitignore`}`,`--ignore-path=${j(`.prettierignore`)??`.prettierignore`}`],Ne={commands:{fix:{commands:[{name:`prettier`,optionFlags:[...J,`--write`],outputFilter:e=>e.includes(`Ignored unknown option { jsdoc`),receivePositionalArguments:!0}],description:`Format files according to your Prettier configuration. ${V.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},init:{configFile:`prettier.config.ts`,configPackageJson:{prettier:`@kitschpatrol/prettier-config`},locationOptionFlag:!0},lint:{commands:[{name:`prettier`,optionFlags:[...J,`--check`],outputFilter:e=>e.includes(`Ignored unknown option { jsdoc`),receivePositionalArguments:!0}],description:`Check that files are formatted according to your Prettier configuration. ${V.fileRun}`,positionalArgumentDefault:`.`,positionalArgumentMode:`optional`},printConfig:{commands:[z(`prettier`)],description:`Print the effective Prettier configuration. ${V.packageSearch}. ${V.monorepoSearch}.`,positionalArgumentMode:`none`}},description:`Kitschpatrol's Prettier shared configuration tools.`,logColor:`blue`,logPrefix:`[Prettier]`,name:`ksc-prettier`,order:9},Pe={commands:{init:{configFile:`.remarkrc.js`,configPackageJson:{remarkConfig:{plugins:[`@kitschpatrol/remark-config`]}},locationOptionFlag:!0},printConfig:{commands:[z(`remark`)],description:`Print the effective Remark configuration. ${V.packageSearch} ${V.monorepoSearch}`,positionalArgumentMode:`none`}},description:`Kitschpatrol's Remark and Remark Lint shared configuration tools. (Actual linting and fixing is managed through @kitschpatrol/eslint-config.)`,logColor:`blue`,logPrefix:`[remarklint]`,name:`ksc-remark`,order:8},Fe=[/Version 2\.0,?\s*January 2004/g,/Version 1,?\s*February 1989/g,/Version 2,?\s*June 1991/g,/Version 3,?\s*29 June 2007/g,/Version 2\.1,?\s*February 1999/g,/Version 3,?\s*19 November 2007/g,/Version 1\.0\s*-\s*August 17th,?\s*2003/g,/Version 1\.1,?\s*March 2000/g,/Version 1\.2,?\s*November 2002/g,/Version 1\.3,?\s*3 November 2008/g,/Version 1\.0\s*-\s*22 November 2005/g,/Version 1\.1\s*-\s*26 February 2007/g,/Version 2,?\s*December 2004/g,/20 December 1996/g,/December 20,?\s*1996/g,/11 March 1996/g,/28 March 2007/g,/November 1,?\s*2008/g,/August 1,?\s*2009/g,/1 April 19\d{2}/g,/Copyright \(c\) 2000-2006,?\s*The Perl Foundation/gi,/Copyright \(C\) (?:\d{4},?\s*)+Free Software Foundation/g],Ie=[`node_modules/**`,`test/**`];function Le(e){let t=e;for(let e of Fe)e.lastIndex=0,t=t.replace(e,e=>e.replaceAll(/\d/g,`X`));return t}const Re=/(\d{4})\s*-\s*(\d{4})/,ze=/(\d{4})/;function Be(e,t){let n=Le(e),r=Re,i=r.exec(n);if(i){let[,n,a]=i;if(Number.parseInt(a,10)!==t){let a=`${n}-${t}`;return e.slice(0,i.index)+e.slice(i.index).replace(r,a)}return e}let a=ze,o=a.exec(n);if(o){let[,n]=o;if(Number.parseInt(n,10)!==t){let r=`${n}-${t}`;return e.slice(0,o.index)+e.slice(o.index).replace(a,r)}return e}return e}async function Ve(e,t=!1){let n=new Date().getFullYear(),r=[],i=await re([`**/license.txt`,`**/license`,...Ie.map(e=>`!${e}`)],{caseSensitiveMatch:!1,cwd:k(),followSymbolicLinks:!1,gitignore:!0});for(let e of i)r.push(e);let a=[];for(let e of r)try{let r=await b.readFile(e,`utf8`),i=Be(r,n);i!==r&&(a.push(e),t&&await b.writeFile(e,i,`utf8`))}catch(t){console.error(`Failed to process ${e}:`,t)}if(a.length>0){e.write(`${t?`Fixed`:`Found`} ${a.length} license ${L(`file`,a.length)} with outdated copyright year:\n`);for(let t of a)e.write(` - ${t}\n`);return t?0:1}return 0}async function He(e){return Ve(e,!1)}async function Ue(e){return Ve(e,!0)}const Y=`pnpm-lock.yaml`;function We(e){let t=A(),n=o.resolve(e);for(;;){if(r.existsSync(o.join(n,Y)))return n;if(n===t)break;let e=o.dirname(n);if(e===n)break;n=e}}function Ge(e,t,n){let r=`${e}@${t}`;if(r in n)return r;if(t in n)return t}async function Ke(e){let t=We(e);if(!t)throw Error(`${Y} not found at or above "${e}".`);let n=o.join(t,Y),r=await ae(t,{ignoreIncompatible:!1});if(!r?.importers)throw Error(`Lockfile at "${n}" is unreadable or missing importers.`);let i=r.packages??{},a,s,c={},l={};function u(e,t){let n,r=new Set;function a(e,t){if(t.startsWith(`link:`))return;let o=Ge(e,t,i);if(!o||r.has(o))return;r.add(o);let s=i[o],c=s?.engines?.node;if(c){let e=ie(c)?.version;e&&(!n||E(e,n))&&(n=e)}if(s?.dependencies)for(let[e,t]of Object.entries(s.dependencies))typeof t==`string`&&a(e,t)}return a(e,t),n}function d(e,t){for(let[n,r]of Object.entries(e)){let e=u(n,typeof r==`string`?r:r.version);if(e){let r=t?l:c;r[e]??=new Set,r[e].add(n);let i=t?s:a;(!i||E(e,i))&&(t?s=e:a=e)}}}let f=o.relative(t,e)||`.`,p=r.importers[f];p&&(p.dependencies&&d(p.dependencies,!1),p.devDependencies&&d(p.devDependencies,!0));let m=a&&s?E(a,s)?`>=${a}`:`>=${s}`:a?`>=${a}`:s?`>=${s}`:void 0;return{dependencies:a?{topLevelCauses:[...c[a]],version:`>=${a}`}:void 0,devDependencies:s?{topLevelCauses:[...l[s]],version:`>=${s}`}:void 0,lockfile:n,version:m}}function qe(e){let t=e.devEngines;if(t?.runtime)return(Array.isArray(t.runtime)?t.runtime:[t.runtime]).find(e=>e.name===`node`)?.version}function Je(e,t){let n=e.devEngines??{};if(n.runtime)if(Array.isArray(n.runtime)){let e=n.runtime.findIndex(e=>e.name===`node`);e===-1?n.runtime.push({name:`node`,version:t}):n.runtime[e].version=t}else n.runtime.name===`node`?n.runtime.version=t:n.runtime=[n.runtime,{name:`node`,version:t}];else n.runtime={name:`node`,version:t};e.devEngines=n}function Ye(e){let t=e.devEngines;t?.runtime&&(Array.isArray(t.runtime)?(t.runtime=t.runtime.filter(e=>e.name!==`node`),t.runtime.length===0?delete t.runtime:t.runtime.length===1&&(t.runtime=t.runtime[0])):t.runtime.name===`node`&&delete t.runtime,Object.keys(t).length===0&&delete e.devEngines)}function X(e){return e.length===0?``:` (from ${e.join(`, `)})`}async function Xe(e,t,n){let i=o.join(n,`package.json`);if(!r.existsSync(i))return 0;let a=r.readJsonSync(i),s=a.engines?.node,c=qe(a),l=await Ke(n),u=l.dependencies?.version,d=l.dependencies?.topLevelCauses??[],f=l.version,p=l.devDependencies?.topLevelCauses??[],m=[];if(u!==void 0)if(s===void 0){if(m.push(`Missing engines.node — suggest setting to "${u}"${X(d)}`),t){let e=a.engines??{};e.node=u,a.engines=e}}else{let e=T.minVersion(s),n=T.minVersion(u);e&&n&&T.lt(e,n)&&(m.push(`engines.node is "${s}" but production dependencies require at least "${u}"${X(d)}`),t&&(a.engines.node=u))}let h=(()=>{if(u&&s){let e=T.minVersion(u),t=T.minVersion(s);if(e&&t)return T.gt(e,t)?u:s}return u??s})(),g=h?T.minVersion(h):void 0,_=f?T.minVersion(f):void 0,v=_&&g&&T.gt(_,g);if(f!==void 0&&v)if(c===void 0)m.push(`devDependencies require a higher Node.js minimum (${f}) than engines.node (${h??`none`}) — suggest adding devEngines.runtime for node with version "${f}"${X(p)}`),t&&Je(a,f);else{let e=T.minVersion(c);e&&T.lt(e,_)&&(m.push(`devEngines.runtime.version for node is "${c}" but all dependencies require at least "${f}"${X(p)}`),t&&Je(a,f))}else if(c!==void 0){let e=T.minVersion(c);e&&g&&T.lte(e,g)&&(m.push(`devEngines.runtime.version for node is redundant (engines.node already covers the requirement) — suggest removing`),t&&Ye(a))}if(m.length>0){e.write(`${t?`Fixed`:`Found`} ${m.length} Node.js version ${L(`issue`,m.length)} in ${i}:\n`);for(let t of m)e.write(` - ${t}\n`);return t?(r.writeJsonSync(i,a,{spaces:` `}),await N(i),0):1}return 0}async function Z(e,t){let n=de(),r=0;for(let i of n)await Xe(e,t,i)!==0&&(r=1);return r}async function Ze(e){let t=D(await Ke(k())).split(`
|
|
11
|
+
`);for(let n of t)e.write(`${n}\n`);return 0}async function Qe(e){return Z(e,!1)}async function $e(e){return Z(e,!0)}const et={commands:{fix:{commands:[{execute:Ue,name:He.name},{execute:$e,name:$e.name}],description:`Fix common issues like outdated copyright years in license files. ${V.packageRun} ${V.monorepoRun}`,positionalArgumentMode:`none`},init:{locationOptionFlag:!1},lint:{commands:[{execute:He,name:Ue.name},{execute:Qe,name:Qe.name}],description:`Check the repo for common issues. ${V.packageRun} ${V.monorepoRun}`,positionalArgumentMode:`none`},printConfig:{commands:[{execute:Ze,name:Ze.name}],description:`Print minimum Node.js version constraints from the pnpm lockfile.`,positionalArgumentMode:`none`}},description:`Kitschpatrol's repository-related shared configuration tools.`,logColor:`gray`,logPrefix:`[Repo Config]`,name:`ksc-repo`,order:1},tt=[`--ignore-path`,j(`.gitignore`)??`.gitignore`,`--allow-empty-input`],nt=`**/*.{${[`css`,`scss`,`sass`,`svelte`,`html`,`astro`,`tsx`,`jsx`,`php`,`vue`].join(`,`)}}`;async function rt(e,t){let n=`stylelint`,r=await B(n);if(r===void 0)return 1;let{filepath:i,isEmpty:a}=r;if(a)return e.write(`Configuration is empty.
|
|
12
|
+
`),0;e.write(`Found ${n} configuration at "${i}"\n`);let s;t.length>0?(s=o.join(process.cwd(),t[0]),e.write(`Showing config for file at "${s}"\n`)):s=M(`package-dir`);let c=D(await oe.resolveConfig(s)).split(`
|
|
13
|
+
`);for(let t of c)e.write(`${t}\n`);return 0}const it={commands:{fix:{commands:[{name:`stylelint`,optionFlags:[...tt,`--fix`],receivePositionalArguments:!0}],description:`Fix your project with Stylelint. ${V.fileRun}`,positionalArgumentDefault:nt,positionalArgumentMode:`optional`},init:{configFile:`stylelint.config.js`,configPackageJson:{stylelint:{extends:`@kitschpatrol/stylelint-config`}},locationOptionFlag:!0},lint:{commands:[{name:`stylelint`,optionFlags:tt,receivePositionalArguments:!0}],description:`Lint your project with Stylelint. ${V.fileRun}`,positionalArgumentDefault:nt,positionalArgumentMode:`optional`},printConfig:{commands:[{execute:rt,name:rt.name}],description:`Print the effective Stylelint configuration. ${V.optionalFileRun}.`,positionalArgumentMode:`optional`}},description:`Kitschpatrol's Stylelint shared configuration tools.`,logColor:`greenBright`,logPrefix:`[Stylelint]`,name:`ksc-stylelint`,order:5};async function at(){let e=k(),t=[`svelte.config.js`,`svelte.config.mjs`,`svelte.config.cjs`].map(async t=>r.exists(o.join(e,t)));return(await Promise.all(t)).some(Boolean)}async function ot(e){return e.write("Skipping `tsc` since this is a Svelte project. Consider running `svelte-check` instead.\n"),0}async function st(){return await at()?[{execute:ot,name:ot.name}]:[{cwdOverride:`package-dir`,name:`tsc`,optionFlags:[`--noEmit`]}]}const Q=[Ee,Te,Ae,Me,Ne,Pe,et,it,{commands:{init:{locationOptionFlag:!1},lint:{commands:await st(),description:`Run type checking on your project. ${V.packageRun} ${V.monorepoRun}`,positionalArgumentMode:`none`},printConfig:{commands:[{name:`tsc`,optionFlags:[`--showConfig`],prettyJsonOutput:!0}],description:`Print the TypeScript configuration for the project. ${V.packageSearch} ${V.monorepoSearch}`,positionalArgumentMode:`none`}},description:`Kitschpatrol's TypeScript shared configuration tools.`,logColor:`blueBright`,logPrefix:`[TypeScript Config]`,name:`ksc-typescript`,order:3}];function $(e,t){t.sort((e,t)=>e.order-t.order);let n=[];for(let r of t)Object.keys(r.commands).includes(e)&&n.push({name:r.name,...e===`init`?{receiveOptionFlags:r.commands[e]?.locationOptionFlag}:{receivePositionalArguments:r.commands[e]?.positionalArgumentMode!==`none`},subcommands:[he(e)]});return n}await be({commands:{fix:{commands:$(`fix`,Q),description:`Fix your project with multiple tools in one go. ${V.multiArgumentCaveat}`,positionalArgumentMode:`optional`},init:{commands:$(`init`,Q),description:`Initialize configuration files for the entire suite of @kitschpatrol/shared-config tools. ${V.multiOptionCaveat}`,locationOptionFlag:!0},lint:{commands:$(`lint`,Q),description:`Lint your project with multiple tools in one go. ${V.multiArgumentCaveat}`,positionalArgumentMode:`optional`},printConfig:{commands:$(`printConfig`,Q),description:`Print aggregated tool configuration data. ${V.multiArgumentCaveat}`,positionalArgumentMode:`optional`}},description:`Run aggregated @kitschpatrol/shared-config commands.`,logColor:`yellow`,logPrefix:`🔬`,name:`ksc`,order:0,showSummary:!0,verbose:!0});export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/shared-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "A collection of shared configurations, linters, and formatting tools for TypeScript projects. All managed as a single dependency, and invoked via a single CLI command.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shared-config",
|
|
@@ -51,31 +51,25 @@
|
|
|
51
51
|
"fs-extra": "^11.3.4",
|
|
52
52
|
"globby": "^16.2.0",
|
|
53
53
|
"json-stringify-pretty-compact": "^4.0.0",
|
|
54
|
-
"mdat": "^
|
|
54
|
+
"mdat": "^2.0.1",
|
|
55
55
|
"package-up": "^5.0.0",
|
|
56
56
|
"picocolors": "^1.1.1",
|
|
57
57
|
"prettier": "^3.8.1",
|
|
58
58
|
"semver": "^7.7.4",
|
|
59
59
|
"stylelint": "^17.6.0",
|
|
60
60
|
"yargs": "^18.0.0",
|
|
61
|
-
"@kitschpatrol/cspell-config": "
|
|
62
|
-
"@kitschpatrol/
|
|
63
|
-
"@kitschpatrol/
|
|
64
|
-
"@kitschpatrol/
|
|
65
|
-
"@kitschpatrol/
|
|
66
|
-
"@kitschpatrol/
|
|
67
|
-
"@kitschpatrol/
|
|
68
|
-
"@kitschpatrol/
|
|
69
|
-
"@kitschpatrol/
|
|
61
|
+
"@kitschpatrol/cspell-config": "7.0.1",
|
|
62
|
+
"@kitschpatrol/knip-config": "7.0.1",
|
|
63
|
+
"@kitschpatrol/eslint-config": "7.0.1",
|
|
64
|
+
"@kitschpatrol/prettier-config": "7.0.1",
|
|
65
|
+
"@kitschpatrol/mdat-config": "7.0.1",
|
|
66
|
+
"@kitschpatrol/remark-config": "7.0.1",
|
|
67
|
+
"@kitschpatrol/stylelint-config": "7.0.1",
|
|
68
|
+
"@kitschpatrol/repo-config": "7.0.1",
|
|
69
|
+
"@kitschpatrol/typescript-config": "7.0.1"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
72
|
-
"node": ">=
|
|
73
|
-
},
|
|
74
|
-
"devEngines": {
|
|
75
|
-
"runtime": {
|
|
76
|
-
"name": "node",
|
|
77
|
-
"version": ">=22.18.0"
|
|
78
|
-
}
|
|
72
|
+
"node": ">=22.18.0"
|
|
79
73
|
},
|
|
80
74
|
"publishConfig": {
|
|
81
75
|
"access": "public"
|
package/readme.md
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<!-- title { prefix: "🔬 " } -->
|
|
1
|
+
<!-- title({ prefix: "🔬 " }) -->
|
|
4
2
|
|
|
5
3
|
# 🔬 @kitschpatrol/shared-config
|
|
6
4
|
|
|
7
5
|
<!-- /title -->
|
|
8
6
|
|
|
9
|
-
<!--
|
|
7
|
+
<!-- //automatic badge expansion disabled due to build complexity -->
|
|
10
8
|
|
|
11
9
|
[](https://npmjs.com/package/@kitschpatrol/shared-config)
|
|
12
10
|
[](https://opensource.org/licenses/MIT)
|
|
13
|
-
|
|
14
|
-
<!-- /badges -->
|
|
11
|
+
[](https://github.com/kitschpatrol/shared-config/actions/workflows/ci.yml)
|
|
15
12
|
|
|
16
13
|
<!-- description -->
|
|
17
14
|
|
|
@@ -19,7 +16,7 @@
|
|
|
19
16
|
|
|
20
17
|
<!-- /description -->
|
|
21
18
|
|
|
22
|
-
<!-- table-of-contents
|
|
19
|
+
<!-- table-of-contents({ depth: 2 }) -->
|
|
23
20
|
|
|
24
21
|
## Table of contents
|
|
25
22
|
|
|
@@ -59,7 +56,7 @@ It takes care of dependencies, configuration, invocation, and reporting for the
|
|
|
59
56
|
- [VS Code](https://code.visualstudio.com) (extension recommendations and extension settings)
|
|
60
57
|
- [Mdat](https://github.com/kitschpatrol/mdat) (my markdown templating and expansion tool)
|
|
61
58
|
- [remarklint](https://github.com/remarkjs/remark-lint)
|
|
62
|
-
- Basic repo boilerplate (`.
|
|
59
|
+
- Basic repo boilerplate (`.gitignore`, GitHub actions, etc.)
|
|
63
60
|
|
|
64
61
|
### Packages
|
|
65
62
|
|
|
@@ -117,7 +114,7 @@ The top-level `ksc` command also takes care of some nuances in terms of _which_
|
|
|
117
114
|
|
|
118
115
|
### Dependencies
|
|
119
116
|
|
|
120
|
-
[Node](https://nodejs.org) >=
|
|
117
|
+
[Node](https://nodejs.org) >=22.18.0 is required, and [pnpm](https://pnpm.io) >=10 is recommended. NPM and yarn might work as well, but I haven't tested them.
|
|
121
118
|
|
|
122
119
|
### Installation
|
|
123
120
|
|
|
@@ -220,7 +217,7 @@ pnpm run fix
|
|
|
220
217
|
|
|
221
218
|
### CLI
|
|
222
219
|
|
|
223
|
-
<!-- cli-help
|
|
220
|
+
<!-- cli-help({ cliCommand: 'ksc' }) -->
|
|
224
221
|
|
|
225
222
|
#### Command: `ksc`
|
|
226
223
|
|
|
@@ -258,11 +255,11 @@ Usage:
|
|
|
258
255
|
ksc init
|
|
259
256
|
```
|
|
260
257
|
|
|
261
|
-
| Option | Description
|
|
262
|
-
| ------------------- |
|
|
263
|
-
| `--location` |
|
|
264
|
-
| `--help`<br>`-h` | Show help
|
|
265
|
-
| `--version`<br>`-v` | Show version number
|
|
258
|
+
| Option | Description | Type | Default |
|
|
259
|
+
| ------------------- | --------------------------------- | -------------------- | -------- |
|
|
260
|
+
| `--location` | Where to store the configuration. | `"file"` `"package"` | `"file"` |
|
|
261
|
+
| `--help`<br>`-h` | Show help | `boolean` | |
|
|
262
|
+
| `--version`<br>`-v` | Show version number | `boolean` | |
|
|
266
263
|
|
|
267
264
|
#### Subcommand: `ksc lint`
|
|
268
265
|
|
|
@@ -312,9 +309,9 @@ Usage:
|
|
|
312
309
|
ksc print-config [file]
|
|
313
310
|
```
|
|
314
311
|
|
|
315
|
-
| Positional Argument | Description
|
|
316
|
-
| ------------------- |
|
|
317
|
-
| `file` | File or glob pattern to
|
|
312
|
+
| Positional Argument | Description | Type |
|
|
313
|
+
| ------------------- | ------------------------------------------------ | -------- |
|
|
314
|
+
| `file` | File or glob pattern to print configuration for. | `string` |
|
|
318
315
|
|
|
319
316
|
| Option | Description | Type |
|
|
320
317
|
| ------------------- | ------------------- | --------- |
|