@kitschpatrol/typescript-config 8.1.0 → 8.3.0
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 +4 -5
- package/init/.vscode/tasks.json +39 -0
- package/init/tsconfig.build.json +1 -2
- package/init/tsconfig.json +5 -4
- package/package.json +5 -3
- package/readme.md +58 -7
- package/tsconfigs/astro.json +14 -0
- package/tsconfigs/base.json +0 -1
- package/tsconfigs/svelte.json +14 -0
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import"cosmiconfig";import"cosmiconfig-typescript-loader";import{execa as e}from"execa";import t from"fs-extra";import n from"node:fs";import r from"node:path";import{PassThrough as
|
|
3
|
-
`)
|
|
4
|
-
`)}})}function
|
|
5
|
-
`);
|
|
6
|
-
`),1;let d=r.join(r.dirname(u),`init`),f=r.dirname(l),p=(i===`file`||i===`package`)&&a!==void 0&&c!==void 0;try{if(p){let n=Object.keys(c)[0],r=t.readJsonSync(l);if(i===`package`){e.write(`Merging: \nPackage config key "${n}" → "${f}" (Because --location is set to "package")\n`);let i=C(r,c);t.writeJSONSync(l,i,{spaces:` `}),await O(l)}else n!==void 0&&Object.keys(r).includes(n)&&(e.write(`Deleting: \nPackage config key "${n}" in "${f}" (Because --location is set to "file")\n`),delete r[n],t.writeJSONSync(l,r,{spaces:` `}),await O(l))}if(!await t.pathExists(d))return 0;if((await t.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 t.copy(d,f,{async filter(o,s){let c=n.statSync(o).isFile(),l=n.existsSync(s);if(c){if(p&&i===`package`&&o.includes(a))return l?(e.write(`Deleting: \n"${o}" → "${s}" (Because --location is set to "package")\n`),t.removeSync(s)):e.write(`Skipping: \n"${o}" → "${s}" (Because --location is set to "package")\n`),!1;if(l&&(s.includes(`.vscode/`)||s.includes(`package.json`))&&r.extname(s)===`.json`){e.write(`Merging: \n"${o}" → "${s}"\n`);let n=t.readJSONSync(o),r=C(t.readJSONSync(s),n);return t.writeJSONSync(s,r,{spaces:` `}),await O(s),!1}return l?(e.write(`Overwriting: \n"${o}" → "${s}"\n`),await O(s),!0):(e.write(`Copying: \n"${o}" → "${s}"\n`),await O(s),!0)}return!0},overwrite:!0})}catch(e){return console.error(String(e)),1}return 0}async function U(e){let{commands:{fix:t,init:n,lint:r,printConfig:i},description:a,logColor:o,logPrefix:s,name:c,showSummary:l,verbose:f}=e,p=j(s,o);p.pipe(process.stdout);let m=u(d(process.argv)).scriptName(c).usage(`$0 <command>`,a);n!==void 0&&m.command({builder(e){let t=n.locationOptionFlag?e.option(`location`,{choices:[`file`,`package`],default:`file`,describe:`Where to store the configuration.`,type:`string`}):e;return l?B(t):t},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=z(e.skip),i=await V(p,[],t===void 0?[]:[`--location`,t],[{async execute(e,t,r){return H(e,r.at(1),n.configFile,n.configPackageJson)},name:`copyAndMergeInitFiles`},...n.commands??[]],void 0,void 0,r);process.exitCode=i}}),r!==void 0&&m.command({builder(e){let t=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`});return l?B(t):t},command:r.positionalArgumentMode===`none`?`lint`:r.positionalArgumentMode===`optional`?`lint [files..]`:`lint <files..>`,describe:r.description,async handler(e){let t=e.files??[],n=z(e.skip),i=await V(p,t,[],r.commands,f,l,n);process.exitCode=i}}),t!==void 0&&m.command({builder(e){let n=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`});return l?B(n):n},command:t.positionalArgumentMode===`none`?`fix`:t.positionalArgumentMode===`optional`?`fix [files..]`:`fix <files..>`,describe:t.description,async handler(e){let n=e.files??[],r=z(e.skip),i=await V(p,n,[],t.commands,void 0,void 0,r);process.exitCode=i}}),i!==void 0&&m.command({builder(e){let t=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`});return l?B(t):t},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=t===void 0?[]:[t],r=z(e.skip),a=await V(p,n,[],i.commands,f,l,r);process.exitCode=a}}),m.alias(`h`,`help`),m.version(y),m.alias(`v`,`version`),m.help(),m.wrap(process.stdout.isTTY?Math.min(120,m.terminalWidth()):0),await m.parseAsync()}const W={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.`};async function G(){let e=w(),n=[`svelte.config.js`,`svelte.config.mjs`,`svelte.config.cjs`].map(async n=>t.exists(r.join(e,n)));return(await Promise.all(n)).some(Boolean)}async function K(e){return e.write("Skipping `tsc` since this is a Svelte project. Consider running `svelte-check` instead.\n"),0}async function q(){return await G()?[{execute:K,name:K.name}]:[{cwdOverride:`package-dir`,name:`tsc`,optionFlags:[`--noEmit`]}]}await U({commands:{init:{locationOptionFlag:!1},lint:{commands:await q(),description:`Run type checking on your project. ${W.packageRun} ${W.monorepoRun}`,positionalArgumentMode:`none`},printConfig:{commands:[{name:`tsc`,optionFlags:[`--showConfig`],prettyJsonOutput:!0}],description:`Print the TypeScript configuration for the project. ${W.packageSearch} ${W.monorepoSearch}`,positionalArgumentMode:`none`}},description:`Kitschpatrol's TypeScript shared configuration tools.`,logColor:`blueBright`,logPrefix:`[TypeScript Config]`,name:`ksc-typescript`,order:3});export{};
|
|
2
|
+
import"cosmiconfig";import"cosmiconfig-typescript-loader";import{execa as e}from"execa";import t from"fs-extra";import n from"node:fs";import{availableParallelism as r}from"node:os";import i from"node:path";import{PassThrough as a,Transform as o}from"node:stream";import{fileURLToPath as s}from"node:url";import{packageUp as c,packageUpSync as l}from"package-up";import u from"yargs";import{hideBin as d}from"yargs/helpers";import f from"picocolors";import{stripVTControlCharacters as p}from"node:util";import m from"@pinojs/json-colorizer";import h from"decircular";import g from"deepmerge";import _ from"json-stringify-pretty-compact";import{findWorkspacesRoot as v}from"find-workspaces";import y from"node:fs/promises";var b=`8.3.0`;const ee=[`json`,`machine`,`native`],te=ee;function x(e){return typeof e==`string`&&ee.includes(e)}function S(){let e=process.env.KSC_FORMAT;return x(e)?e:`native`}function ne(){let{argv:e}=process;for(let[t,n]of e.entries()){let r;n===`--format`?r=e[t+1]:n.startsWith(`--format=`)&&(r=n.slice(9)),x(r)&&(process.env.KSC_FORMAT=r)}}function re(){let{env:e}=process;if(e.NO_COLOR!==void 0&&e.NO_COLOR!==``)return!1;if(e.FORCE_COLOR!==void 0)return e.FORCE_COLOR!==`0`&&e.FORCE_COLOR!==`false`;if(e.TERM===`dumb`)return!1}function C(e,{ciColor:t=!0}={}){let n=re();return n===void 0?e.isTTY===!0||t&&!!process.env.CI:n}function w(){return S()===`json`?process.stderr:process.stdout}function T(){return S()===`machine`?f.createColors(!1):f.createColors(C(w()))}function E(e){if(!e)return{FORCE_COLOR:`0`,NO_COLOR:`1`};let t=process.env.FORCE_COLOR;return t===void 0||t===``?{FORCE_COLOR:`1`}:{}}function ie(e,t){let n=i.isAbsolute(e)?e:i.resolve(t,e),r=i.relative(process.cwd(),n);return r===``?`.`:r}const ae=/\s*\n\s*/gv,oe=/\r?\n/v;function se(e){let t=e.message.replaceAll(ae,` `),n=e.rule===void 0?e.tool:`${e.tool}/${e.rule}`;return e.file===void 0?`${e.severity}: ${t} [${n}]`:`${e.file}:${e.line??1}:${e.column??1}: ${e.severity}: ${t} [${n}]`}function ce(e,t){let n=(e.file??``).localeCompare(t.file??``);if(n!==0)return n;let r=(e.line??0)-(t.line??0);return r===0?(e.column??0)-(t.column??0):r}function le(e,t){let n=t.toSorted(ce);return{cwd:process.cwd(),diagnostics:n,success:e.every(e=>e.exitCode===0),summary:{errors:n.filter(e=>e.severity===`error`).length,infos:n.filter(e=>e.severity===`info`).length,warnings:n.filter(e=>e.severity===`warning`).length},tools:e,version:1}}function D(e){return p(e).split(oe).map(e=>e.trimEnd()).filter(e=>e.trim().length>0)}function ue(e){return e instanceof Error&&`exitCode`in e&&typeof e.exitCode==`number`}function O(e){return C(process.stdout,{ciColor:!1})?de(e):k(e)}function k(e){return _(h(e),{indent:2,replacer(e,t){return typeof t==`function`?t.name:t}})}function de(e){return m(k(e),{colors:{BRACKET:`gray`}})}const fe=(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]=A(e[i],a,n):e.includes(a)||r.push(a);return r};function A(e,t,n={arrayMerge:fe}){return g(e,t,n)}function j(e){let{tasks:t}=e;return Array.isArray(t)?t:[]}function pe(e,t){let n=[...j(e)];for(let e of j(t)){let t=n.findIndex(t=>t.label!==void 0&&t.label===e.label);t===-1?n.push(e):n[t]=e}return{...e,...t,tasks:n}}function M(){let e=l();if(e===void 0)throw Error(`No package.json found.`);return i.dirname(e)}function N(){let e=v();return e===null?M():i.resolve(e.location)}function P(e){if(e===`workspace-root`)return N();if(e===`package-dir`)return M();if(typeof e==`string`){if(!t.pathExistsSync(e))throw Error(`Custom cwd directory does not exist: ${e}`);return e}return process.cwd()}async function me(e,t){try{let{default:n}=await import(`prettier`),r=await n.resolveConfig(e),i=await n.format(t,{filepath:e,...r});await y.writeFile(e,i,`utf8`)}catch{console.warn(`Skipped formatting ${e} since Prettier is not installed.`)}}async function F(e){try{await me(e,await y.readFile(e,`utf8`))}catch{}}const I=/\r?\n/v;function L(e){let t=``,n=t=>t.filter(t=>t.trim()!==``&&!e(p(t))).map(e=>`${e}\n`).join(``);return new o({flush(e){e(void 0,n([t]))},transform(e,r,i){let a=(t+e.toString()).split(I);t=a.pop()??``,i(void 0,n(a))}})}function R(e,t){let n=S()===`native`?e:void 0,r=n===void 0||n===``?``:t===void 0?n:T()[t](n),i=``,a=e=>e.filter(e=>e.trim().length>0).map(e=>r===``?`${e}\n`:`${r} ${e}\n`).join(``);return new o({flush(e){e(void 0,a([i]))},transform(e,t,n){let r=(i+e.toString()).split(I);i=r.pop()??``,n(void 0,a(r))}})}async function he(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 z(e,t){return t===1?e:e+`s`}async function B(e){return typeof e==`function`?e():e}async function ge(e,t,n,r,i){let a;if(r.logPrefix===void 0)a=e;else{let t=R(r.logPrefix,r.logColor);t.pipe(e),a=t}i&&a.write(T().bold(`Running: "${r.name}() with Positional arguments: ${String(t)} and Option flags: ${String(n)}"`)+`
|
|
3
|
+
`);try{return await r.execute(a,t,n)}catch(e){return console.error(String(e)),1}}function V(e,t,n,r,a){return[...e.subcommands??[],...e.receiveOptionFlags?n:[],...r??[],...a&&e.cache!==void 0?[...e.cache.flags,`--cache-location`,i.join(N(),`node_modules`,`.cache`,`ksc`,e.cache.name)]:[],...e.receivePositionalArguments?t:[],...e.positionalArguments??[]]}async function _e(t,n,r,i,o,s){let c=1,l;if(i.logPrefix===void 0)l=t;else{let e=R(i.logPrefix,i.logColor);e.pipe(t),l=e}let u=V(i,n,r,i.optionFlags,o),d=P(i.cwdOverride);s&&l.write(`Running: "${i.name} ${u.join(` `)}"\n`);let f=i.prettyJsonOutput?new a:l,p=E(S()===`native`&&i.prettyJsonOutput!==!0&&C(w()));try{let t=e(i.name,u,{cwd:d,env:{...p},preferLocal:!0,reject:!1,stdin:`inherit`});if(i.outputFilter){let e=L(i.outputFilter),n=L(i.outputFilter);t.stdout.pipe(e).pipe(f,{end:!1}),t.stderr.pipe(n).pipe(f,{end:!1})}else t.stdout.pipe(f,{end:!1}),t.stderr.pipe(f,{end:!1});let n=await t;if(i.prettyJsonOutput){f.end();let e=await he(f),t=O(JSON.parse(e)).split(`
|
|
4
|
+
`);for(let e of t)l.write(`${e}\n`)}c=n.exitCode??1}catch(e){console.error(`${i.name} failed with error:`),console.error(e),ue(e)&&(c=typeof e.exitCode==`number`?e.exitCode:1)}return c}function H(e){return`execute`in e}function U(e){return`kind`in e}async function W(t,n,r,i,a){let o=V(r,t,n,r.collect?.optionFlags??r.optionFlags,i),s=P(r.cwdOverride);try{let t=e(r.name,o,{cwd:s,env:E(!1),preferLocal:!0,reject:!1,stdin:`inherit`});a!==void 0&&t.stderr.pipe(a,{end:!1});let n=await t;return{cwd:s,exitCode:n.exitCode??1,stderr:n.stderr,stdout:n.stdout}}catch(e){return console.error(`${r.name} failed with error:`),console.error(e),{cwd:s,exitCode:ue(e)&&typeof e.exitCode==`number`?e.exitCode:1,stderr:``,stdout:``}}}function ve(e){return typeof e==`object`&&!!e&&`version`in e&&e.version===1&&`diagnostics`in e&&Array.isArray(e.diagnostics)&&`tools`in e&&Array.isArray(e.tools)}async function ye(e,t,n,r,i){let o=Date.now(),s=()=>Date.now()-o;if(H(r)){if(r.collect!==void 0)try{let{diagnostics:e,exitCode:i,unparsed:a}=await r.collect(t,n);return{diagnostics:e,exitCode:i,tools:[{durationMs:s(),exitCode:i,name:r.name,unparsed:a}]}}catch(e){return{diagnostics:[],exitCode:1,tools:[{durationMs:s(),exitCode:1,name:r.name,unparsed:[String(e)]}]}}let e=``,i=new a;i.on(`data`,t=>{e+=t.toString()});let o;try{o=await r.execute(i,t,n)}catch(t){e+=`\n${String(t)}`,o=1}return{diagnostics:[],exitCode:o,tools:[{durationMs:s(),exitCode:o,name:r.name,unparsed:D(e)}]}}if(U(r))throw Error(`Command groups must be expanded before collection`);if(r.outputFormatAware){let a=await W(t,n,r,i,e);try{let e=JSON.parse(a.stdout);if(!ve(e))throw Error(`Child output is not a lint report`);return{diagnostics:e.diagnostics,exitCode:a.exitCode,tools:e.tools}}catch{return{diagnostics:[],exitCode:a.exitCode,tools:[{durationMs:s(),exitCode:a.exitCode,name:r.name,unparsed:D(a.stdout)}]}}}let c=await W(t,n,r,i);if(r.collect!==void 0)try{let{diagnostics:e,unparsed:t}=r.collect.parse(c);return{diagnostics:e,exitCode:c.exitCode,tools:[{durationMs:s(),exitCode:c.exitCode,name:r.name,unparsed:t}]}}catch(e){return{diagnostics:[],exitCode:c.exitCode,tools:[{durationMs:s(),exitCode:c.exitCode,name:r.name,unparsed:[...D(c.stdout),...D(c.stderr),String(e)]}]}}return{diagnostics:[],exitCode:c.exitCode,tools:[{durationMs:s(),exitCode:c.exitCode,name:r.name,unparsed:[...D(c.stdout),...D(c.stderr)]}]}}const be=/^ksc-/v;function G(e){return e.replace(be,``)}function K(e){return e===void 0||e.length===0?[]:e.flatMap(e=>e.split(`,`)).map(e=>G(e.trim()))}function q(e){return e.option(`skip`,{array:!0,describe:`Tool names to skip (with or without "ksc-" prefix).`,type:`string`})}function J(e){return e.option(`format`,{choices:te,default:`native`,describe:`Output format: "native" streams each tool's own output, "machine" prints one parseable line per issue for editor problem matchers, "json" prints an aggregate report.`})}function Y(e){return e.option(`cache`,{boolean:!0,default:!0,describe:`Use tool-native caches stored below node_modules/.cache/ksc at the workspace root. Disable with --no-cache.`})}function xe(e,t){return t===`native`||t===`machine`&&!H(e)&&!U(e)&&e.outputFormatAware===!0}function Se(e,t){for(let n of t.diagnostics)e.write(`${se(n)}\n`);for(let n of t.tools)for(let t of n.unparsed)e.write(`${t}\n`)}function Ce(){return Math.min(4,r())}var we=class{concurrency;active=0;queue=[];constructor(e){this.concurrency=e}async run(e){this.active>=this.concurrency&&await new Promise(e=>{this.queue.push(e)}),this.active+=1;try{return await e()}finally{--this.active,this.queue.shift()?.()}}};async function Te(e){let n=e.cache??!1,r=e.concurrency??Ce();if(!Number.isInteger(r)||r<1)throw Error(`Concurrency must be a positive integer.`);return n&&await t.ensureDir(i.join(N(),`node_modules`,`.cache`,`ksc`)),{cache:n,scheduler:new we(r)}}function Ee(e,t){return e.positionalArgumentMode===`none`?[]:t.length>0?t:e.positionalArgumentDefault===void 0?[]:[e.positionalArgumentDefault]}function De(e,t){if(t.logPrefix===void 0)return e;let n=R(t.logPrefix,t.logColor);return n.pipe(e),n}async function X(e,t){if(U(e)){if(t.nativeVerbose){let n=[e.subcommand,...t.positionalArguments].join(` `);t.logStream.write(`Running: "${e.name} ${n}"\n`)}let n=De(t.logStream,e);try{let r=await Z(await B(e.commands),{...t,logStream:n,nativeVerbose:e.verbose,positionalArguments:Ee(e,t.positionalArguments)},e.parallel===!0);return{diagnostics:r.flatMap(({diagnostics:e})=>e),exitCode:+!r.every(({exitCode:e})=>e===0),machineOutcomes:r.flatMap(({machineOutcomes:e})=>e),name:e.name,tools:r.flatMap(({tools:e})=>e)}}catch(r){let i=String(r),a={durationMs:0,exitCode:1,name:e.name,unparsed:[i]};return t.format===`native`&&n.write(`${i}\n`),{diagnostics:[],exitCode:1,machineOutcomes:[{diagnostics:[],exitCode:1,tools:[a]}],name:e.name,tools:[a]}}}return t.scheduler.run(async()=>{if(xe(e,t.format))return{diagnostics:[],exitCode:await(H(e)?ge(t.logStream,t.positionalArguments,t.optionFlags,e,t.nativeVerbose):_e(t.logStream,t.positionalArguments,t.optionFlags,e,t.cache,t.nativeVerbose)),machineOutcomes:[],name:e.name,tools:[]};let n=await ye(t.logStream,t.positionalArguments,t.optionFlags,e,t.cache);return{diagnostics:n.diagnostics,exitCode:n.exitCode,machineOutcomes:[n],name:e.name,tools:n.tools}})}async function Z(e,t,n){if(!n||t.scheduler.concurrency===1){let n=[];for(let r of e)n.push(await X(r,t));return n}await Promise.resolve();let r=new Map;for(let[t,n]of e.entries()){let e=n.stage??0,i=r.get(e)??[];i.push({command:n,index:t}),r.set(e,i)}let i=Array.from({length:e.length}),a=r.keys().toArray().toSorted((e,t)=>e-t);for(let e of a){let n=r.get(e)??[],a=await Promise.all(n.map(async({command:e,index:n})=>({index:n,outcome:await X(e,t)})));for(let{index:e,outcome:t}of a)i[e]=t}return i.filter(e=>e!==void 0)}function Oe(e,t,n){let r=[],i=[];for(let e of t)n.length>0&&n.includes(G(e.name))?i.push(e):r.push(e);if(n.length>0){let r=new Set(i.map(e=>G(e.name))),a=n.filter(e=>!r.has(e));if(a.length>0){let n=t.map(e=>G(e.name)).join(`, `);e.write(`⚠️ ${T().yellow(`Unrecognized --skip ${z(`value`,a.length)}: ${a.join(`, `)}. Available: ${n}`)}\n`)}}return{commandsToRun:r,skippedCommands:i}}async function Q(e,t,n,r,i,a,o,s=`native`){let c=typeof s==`string`?{}:s,l=typeof s==`string`?s:c.format??`native`,{commandsToRun:u,skippedCommands:d}=Oe(e,r,o??[]),f=l===`native`&&i,{cache:p,scheduler:m}=await Te(c),h=await Z(u,{cache:p,format:l,logStream:e,nativeVerbose:f,optionFlags:n,positionalArguments:t,scheduler:m},c.parallel===!0),g=h.map(({exitCode:e,name:t})=>({exitCode:e,name:t})),_=h.flatMap(({tools:e})=>e),v=h.flatMap(({diagnostics:e})=>e);if(l===`machine`)for(let t of h)for(let n of t.machineOutcomes)Se(e,n);let y=r.length,b=T();if(l===`native`&&d.length>0){let t=d.map(({name:e})=>e),n=b.bold(`${t.length} / ${y} ${z(`Command`,t.length)} Skipped:`);e.write(`⏭️ ${b.dim(n)} ${b.dim(t.join(`, `))}\n`)}if(l===`native`&&a){let t=g.filter(({exitCode:e})=>e===0).map(({name:e})=>e),n=g.filter(({exitCode:e})=>e!==0).map(({name:e})=>e);if(t.length>0){let n=b.bold(`${t.length} / ${y} ${z(`Command`,t.length)} Succeeded:`);e.write(`✅ ${b.green(n)} ${b.green(t.join(`, `))}\n`)}if(n.length>0){let t=b.bold(`${n.length} / ${y} ${z(`Command`,n.length)} Failed:`);e.write(`❌ ${b.red(t)} ${b.red(n.join(`, `))}\n`)}}return{exitCode:+!g.every(({exitCode:e})=>e===0),report:l===`json`?le(_,v):void 0}}async function ke(e,r,a,o){let l=await c();if(l===void 0)throw Error("The `init` command must be used in a directory with a package.json file");let u=await c({cwd:s(import.meta.url)});if(u===void 0)return e.write(`Error: The script being called was not in a package, weird.
|
|
5
|
+
`),1;let d=i.join(i.dirname(u),`init`),f=i.dirname(l),p=(r===`file`||r===`package`)&&a!==void 0&&o!==void 0;try{if(p){let n=Object.keys(o)[0],i=t.readJsonSync(l);if(r===`package`){e.write(`Merging: \nPackage config key "${n}" → "${f}" (Because --location is set to "package")\n`);let r=A(i,o);t.writeJSONSync(l,r,{spaces:` `}),await F(l)}else n!==void 0&&Object.keys(i).includes(n)&&(e.write(`Deleting: \nPackage config key "${n}" in "${f}" (Because --location is set to "file")\n`),delete i[n],t.writeJSONSync(l,i,{spaces:` `}),await F(l))}if(!await t.pathExists(d))return 0;if((await t.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 t.copy(d,f,{async filter(o,s){let c=n.statSync(o).isFile(),l=n.existsSync(s);if(c){if(p&&r===`package`&&o.includes(a))return l?(e.write(`Deleting: \n"${o}" → "${s}" (Because --location is set to "package")\n`),t.removeSync(s)):e.write(`Skipping: \n"${o}" → "${s}" (Because --location is set to "package")\n`),!1;if(l&&(s.includes(`.vscode/`)||s.includes(`package.json`))&&i.extname(s)===`.json`){e.write(`Merging: \n"${o}" → "${s}"\n`);let n=t.readJSONSync(o),r=t.readJSONSync(s),i=s.endsWith(`.vscode/tasks.json`)?pe(r,n):A(r,n);return t.writeJSONSync(s,i,{spaces:` `}),await F(s),!1}return l?(e.write(`Overwriting: \n"${o}" → "${s}"\n`),await F(s),!0):(e.write(`Copying: \n"${o}" → "${s}"\n`),await F(s),!0)}return!0},overwrite:!0})}catch(e){return console.error(String(e)),1}return 0}async function Ae(e){let{commands:{fix:t,init:n,lint:r,printConfig:i},description:a,logColor:o,logPrefix:s,name:c,showSummary:l,verbose:f}=e;ne();let p=R(s,o);p.pipe(w());let m=u(d(process.argv)).scriptName(c).usage(`$0 <command>`,a);n!==void 0&&m.command({builder(e){let t=n.locationOptionFlag?e.option(`location`,{choices:[`file`,`package`],default:`file`,describe:`Where to store the configuration.`,type:`string`}):e;return l?q(t):t},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=K(e.skip),{exitCode:i}=await Q(p,[],t===void 0?[]:[`--location`,t],[{async execute(e,t,r){return ke(e,r.at(1),n.configFile,n.configPackageJson)},name:`copyAndMergeInitFiles`},...n.commands??[]],void 0,void 0,r);process.exitCode=i}}),r!==void 0&&m.command({builder(e){let t=Y(J(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`})));return l?q(t):t},command:r.positionalArgumentMode===`none`?`lint`:r.positionalArgumentMode===`optional`?`lint [files..]`:`lint <files..>`,describe:r.description,async handler(e){let t=e.files??[],n=K(e.skip),i=S(),{exitCode:a,report:o}=await Q(p,t,[],await B(r.commands),f,l,n,{cache:e.cache,format:i,parallel:r.parallel});o!==void 0&&process.stdout.write(`${O(o)}\n`),process.exitCode=a}}),t!==void 0&&m.command({builder(e){let n=Y(J(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`})));return l?q(n):n},command:t.positionalArgumentMode===`none`?`fix`:t.positionalArgumentMode===`optional`?`fix [files..]`:`fix <files..>`,describe:t.description,async handler(e){let n=e.files??[],r=K(e.skip),i=S(),{exitCode:a,report:o}=await Q(p,n,[],await B(t.commands),void 0,void 0,r,{cache:e.cache,format:i,parallel:t.parallel});o!==void 0&&process.stdout.write(`${O(o)}\n`),process.exitCode=a}}),i!==void 0&&m.command({builder(e){let t=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`});return l?q(t):t},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=t===void 0?[]:[t],r=K(e.skip),{exitCode:a}=await Q(p,n,[],await B(i.commands),f,l,r);process.exitCode=a}}),m.alias(`h`,`help`),m.version(b),m.alias(`v`,`version`),m.help(),m.wrap(process.stdout.isTTY?Math.min(120,m.terminalWidth()):0),await m.parseAsync()}const $={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.`},je=/^(?<file>.+?)\((?<line>\d+),(?<column>\d+)\): (?<severity>error|warning) (?<code>TS\d+): (?<message>.*)$/v,Me=/^(?<severity>error|warning) (?<code>TS\d+): (?<message>.*)$/v,Ne=/^\s/v,Pe=/^(?:Loading svelte-check in workspace: |Getting Svelte diagnostics\.\.\.|svelte-check found 0 errors and 0 warnings$)/v,Fe=/^\d+ (?:START "|COMPLETED \d+ FILES 0 ERRORS 0 WARNINGS 0 FILES_WITH_PROBLEMS$)/v;function Ie(e){return Pe.test(e)||Fe.test(e)}function Le(e){let t=[],n=[];for(let r of D(`${e.stdout}\n${e.stderr}`)){let i=je.exec(r);if(i?.groups!==void 0){let{code:n,column:r,file:a,line:o,message:s,severity:c}=i.groups;t.push({column:Number(r),file:ie(a??``,e.cwd),line:Number(o),message:s??``,rule:n,severity:c===`warning`?`warning`:`error`,tool:`tsc`});continue}let a=Me.exec(r);if(a?.groups!==void 0){let{code:e,message:n,severity:r}=a.groups;t.push({message:n??``,rule:e,severity:r===`warning`?`warning`:`error`,tool:`tsc`});continue}let o=t.at(-1);if(o!==void 0&&Ne.test(r)){o.message+=`\n${r.trim()}`;continue}n.push(r)}return{diagnostics:t,unparsed:n}}async function Re(){let e=M(),n=await t.readJson(i.join(e,`package.json`));return new Set([...Object.keys(n.dependencies??{}),...Object.keys(n.devDependencies??{})])}async function ze(){let e=await Re(),t=e.has(`@astrojs/check`),n=e.has(`svelte-check`);if(t||n){let e=[];return t&&e.push({cwdOverride:`package-dir`,name:`astro`,subcommands:[`check`]}),n&&e.push({cwdOverride:`package-dir`,name:`svelte-check`,optionFlags:t?[]:[`--tsconfig`,`./tsconfig.json`],outputFilter:Ie}),e}return[{collect:{parse:Le},cwdOverride:`package-dir`,name:`tsc`,optionFlags:[`--noEmit`]}]}await Ae({commands:{init:{locationOptionFlag:!1},lint:{commands:ze,description:`Run type checking on your project. ${$.packageRun} ${$.monorepoRun}`,positionalArgumentMode:`none`},printConfig:{commands:[{name:`tsc`,optionFlags:[`--showConfig`],prettyJsonOutput:!0}],description:`Print the TypeScript configuration for the project. ${$.packageSearch} ${$.monorepoSearch}`,positionalArgumentMode:`none`}},description:`Kitschpatrol's TypeScript shared configuration tools.`,logColor:`blueBright`,logPrefix:`[TypeScript Config]`,name:`ksc-typescript`,order:3});export{};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"tasks": [
|
|
4
|
+
{
|
|
5
|
+
"label": "ksc-typescript lint",
|
|
6
|
+
"detail": "Run type checking on your project.",
|
|
7
|
+
"type": "shell",
|
|
8
|
+
"command": "pnpm exec ksc-typescript lint --format machine",
|
|
9
|
+
"options": {
|
|
10
|
+
"cwd": "${workspaceFolder}"
|
|
11
|
+
},
|
|
12
|
+
"presentation": {
|
|
13
|
+
"clear": true,
|
|
14
|
+
"echo": true,
|
|
15
|
+
"focus": false,
|
|
16
|
+
"panel": "dedicated",
|
|
17
|
+
"reveal": "silent",
|
|
18
|
+
"revealProblems": "onProblem",
|
|
19
|
+
"showReuseMessage": false
|
|
20
|
+
},
|
|
21
|
+
"problemMatcher": [
|
|
22
|
+
{
|
|
23
|
+
"owner": "ksc",
|
|
24
|
+
"source": "ksc",
|
|
25
|
+
"fileLocation": ["relative", "${workspaceFolder}"],
|
|
26
|
+
"pattern": {
|
|
27
|
+
"regexp": "^(.+?):(\\d+):(\\d+): (error|warning|info): (.+) \\[([^\\]]+)\\]$",
|
|
28
|
+
"file": 1,
|
|
29
|
+
"line": 2,
|
|
30
|
+
"column": 3,
|
|
31
|
+
"severity": 4,
|
|
32
|
+
"message": 5,
|
|
33
|
+
"code": 6
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
package/init/tsconfig.build.json
CHANGED
package/init/tsconfig.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@kitschpatrol/typescript-config",
|
|
3
|
-
|
|
4
3
|
"compilerOptions": {
|
|
5
4
|
// TypeScript 6.0 no longer includes @types packages automatically
|
|
6
5
|
"types": ["node"]
|
|
6
|
+
// Consider enabling for new projects
|
|
7
|
+
// https://www.typescriptlang.org/tsconfig/#exactOptionalPropertyTypes
|
|
8
|
+
// "exactOptionalPropertyTypes": true
|
|
7
9
|
},
|
|
8
|
-
|
|
9
10
|
// Includes project dot-files files for typescript-eslint integration
|
|
10
|
-
"include": ["
|
|
11
|
-
"exclude": ["
|
|
11
|
+
"include": ["**/**.*"],
|
|
12
|
+
"exclude": ["dist/"]
|
|
12
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/typescript-config",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "TypeScript configuration for @kitschpatrol/shared-config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shared-config",
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"type": "module",
|
|
28
28
|
"exports": {
|
|
29
|
-
".": "./tsconfigs/base.json"
|
|
29
|
+
".": "./tsconfigs/base.json",
|
|
30
|
+
"./astro": "./tsconfigs/astro.json",
|
|
31
|
+
"./svelte": "./tsconfigs/svelte.json"
|
|
30
32
|
},
|
|
31
33
|
"bin": {
|
|
32
34
|
"ksc-typescript": "bin/cli.js"
|
|
@@ -42,7 +44,7 @@
|
|
|
42
44
|
"cosmiconfig-typescript-loader": "^6.3.0",
|
|
43
45
|
"decircular": "^1.0.0",
|
|
44
46
|
"deepmerge": "^4.3.1",
|
|
45
|
-
"execa": "^
|
|
47
|
+
"execa": "^10.0.0",
|
|
46
48
|
"find-workspaces": "^0.3.1",
|
|
47
49
|
"fs-extra": "^11.3.6",
|
|
48
50
|
"json-stringify-pretty-compact": "^4.0.0",
|
package/readme.md
CHANGED
|
@@ -57,6 +57,32 @@ To use just this TypeScript config in isolation:
|
|
|
57
57
|
pnpm exec ksc-typescript init
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
### Astro and Svelte projects
|
|
61
|
+
|
|
62
|
+
Framework-specific configs are also exported. Each extends the base config and overrides only what the framework requires.
|
|
63
|
+
|
|
64
|
+
In an Astro project, the entire `tsconfig.json` is:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"extends": "@kitschpatrol/typescript-config/astro"
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This mirrors the `astro/tsconfigs/strict` preset that `create-astro` scaffolds by default, including the `.astro/types.d.ts` include and `dist` exclude, layered over the base config.
|
|
73
|
+
|
|
74
|
+
In a SvelteKit project, extend both this config and SvelteKit's generated config, with the generated config last so its per-project `paths`, `rootDirs`, `include`, and `exclude` take precedence:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"extends": ["@kitschpatrol/typescript-config/svelte", "./.svelte-kit/tsconfig.json"]
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This mirrors the `tsconfig.json` that `sv create` scaffolds for SvelteKit projects. Standalone Svelte projects without SvelteKit (Vite's split `tsconfig.app.json` / `tsconfig.node.json` layout) aren't covered by this config.
|
|
83
|
+
|
|
84
|
+
See the [Svelte and Astro caveat](#svelte-and-astro-caveat) below for how `ksc-typescript lint` handles type checking in these projects.
|
|
85
|
+
|
|
60
86
|
## Usage
|
|
61
87
|
|
|
62
88
|
You can call `ksc-typescript` directly, or use the script bundled with the config.
|
|
@@ -147,10 +173,12 @@ Usage:
|
|
|
147
173
|
ksc-typescript lint
|
|
148
174
|
```
|
|
149
175
|
|
|
150
|
-
| Option | Description
|
|
151
|
-
| ------------------- |
|
|
152
|
-
| `--
|
|
153
|
-
| `--
|
|
176
|
+
| Option | Description | Type | Default |
|
|
177
|
+
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ---------- |
|
|
178
|
+
| `--format` | Output format: "native" streams each tool's own output, "machine" prints one parseable line per issue for editor problem matchers, "json" prints an aggregate report. | `"json"` `"machine"` `"native"` | `"native"` |
|
|
179
|
+
| `--cache` | Use tool-native caches stored below node\_modules/.cache/ksc at the workspace root. Disable with --no-cache. | `boolean` | `true` |
|
|
180
|
+
| `--help`<br>`-h` | Show help | `boolean` | |
|
|
181
|
+
| `--version`<br>`-v` | Show version number | `boolean` | |
|
|
154
182
|
|
|
155
183
|
#### Subcommand: `ksc-typescript print-config`
|
|
156
184
|
|
|
@@ -169,13 +197,36 @@ ksc-typescript print-config
|
|
|
169
197
|
|
|
170
198
|
<!-- /cli-help -->
|
|
171
199
|
|
|
200
|
+
### VS Code tasks
|
|
201
|
+
|
|
202
|
+
`ksc-typescript init` adds a `.vscode/tasks.json` with a single task:
|
|
203
|
+
|
|
204
|
+
- **`ksc-typescript lint`** runs `ksc-typescript lint --format machine`, type checking the project
|
|
205
|
+
|
|
206
|
+
If you're using the complete [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config) package, you'd more likely want to run:
|
|
207
|
+
|
|
208
|
+
- **`ksc lint`** runs `ksc lint --format machine`, which runs all `ksc lint` tools across the whole project
|
|
209
|
+
- **`ksc fix`** runs `ksc fix --format machine`, which applies all `ksc fix` auto-fixes and reports anything unfixable
|
|
210
|
+
|
|
211
|
+
Run them via the _Tasks: Run Task_ command (or the _Terminal → Run Task…_ menu item).
|
|
212
|
+
|
|
213
|
+
Each task's problem matcher parses the machine-format output and populates VS Code's [Problems panel](https://code.visualstudio.com/docs/debugtest/debugging#_errors-and-warnings) with every reported issue, pointing to the offending file, line, and column.
|
|
214
|
+
|
|
215
|
+
The tasks share a problem matcher owner with the other `@kitschpatrol/shared-config` tasks, so the panel reflects the most recent run rather than stacking duplicates.
|
|
216
|
+
|
|
217
|
+
If your project already has a `.vscode/tasks.json`, `init` merges by task label: your own tasks are left alone, and same-label tasks are replaced with the latest definitions.
|
|
218
|
+
|
|
172
219
|
## Notes
|
|
173
220
|
|
|
174
|
-
### Svelte caveat
|
|
221
|
+
### Svelte and Astro caveat
|
|
222
|
+
|
|
223
|
+
The `tsc` command ignores `.svelte` and `.astro` files, and [errors](https://github.com/sveltejs/language-tools/issues/2527) on plain `.ts` files that import them. So, if `svelte-check` or `@astrojs/check` is declared in your package's dependencies or devDependencies, the `ksc-typescript lint` command runs that checker instead of `tsc --noEmit`:
|
|
175
224
|
|
|
176
|
-
|
|
225
|
+
- `svelte-check` → `svelte-check --tsconfig ./tsconfig.json` (covers `.svelte` and plain `.ts` / `.js` files)
|
|
226
|
+
- `@astrojs/check` → `astro check` (covers `.astro` and plain `.ts` / `.js` files)
|
|
227
|
+
- Both → `astro check` plus `svelte-check` scoped to `.svelte` files only
|
|
177
228
|
|
|
178
|
-
|
|
229
|
+
If neither checker is declared, `tsc --noEmit` runs as usual, even in projects with a `svelte.config.js` or `astro.config.mjs` file.
|
|
179
230
|
|
|
180
231
|
### General
|
|
181
232
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// Astro treats .astro files (and framework islands) as JSX left for its own compiler
|
|
5
|
+
"jsx": "preserve",
|
|
6
|
+
// Astro leaves lib unset, pulling in DOM.Iterable via the target's defaults
|
|
7
|
+
"lib": ["ES2025", "DOM", "DOM.Iterable"],
|
|
8
|
+
// Astro requires CJS interop for importing CommonJS modules in ESM
|
|
9
|
+
"esModuleInterop": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["${configDir}/.astro/types.d.ts", "${configDir}/**/*"],
|
|
12
|
+
// Mirrors astro/tsconfigs/base, which resolves these against the project root
|
|
13
|
+
"exclude": ["${configDir}/dist"]
|
|
14
|
+
}
|
package/tsconfigs/base.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
// SvelteKit generates per-project paths, rootDirs, include, and exclude, so
|
|
3
|
+
// projects must extend both configs, with the generated config last:
|
|
4
|
+
// "extends": ["@kitschpatrol/typescript-config/svelte", "./.svelte-kit/tsconfig.json"]
|
|
5
|
+
"extends": "./base.json",
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
// The sv create template rewrites relative .ts import extensions in emitted output
|
|
8
|
+
"rewriteRelativeImportExtensions": true,
|
|
9
|
+
// The sv create template enables source maps for svelte-package output
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
// The sv create template enables CJS interop for importing CommonJS modules in ESM
|
|
12
|
+
"esModuleInterop": true
|
|
13
|
+
}
|
|
14
|
+
}
|