@kitschpatrol/shared-config 7.1.0 → 7.2.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 +1 -1
- package/dist/index.d.ts +30 -0
- package/dist/index.js +1 -0
- package/package.json +25 -15
- package/readme.md +26 -0
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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 ee from"json-stringify-pretty-compact";import{findWorkspaces as te,findWorkspacesRoot as ne}from"find-workspaces";import v,{access as re}from"node:fs/promises";import{stripVTControlCharacters as y}from"node:util";import{getDefaultConfigLoader as b,resolveConfigFileImports as x}from"cspell-lib";import{lint as ie}from"cspell";import"deepmerge-ts";import{loadConfig as S}from"mdat";import{globby as ae}from"globby";import C,{gt as w,minVersion as oe}from"semver";import{readWantedLockfile as se}from"@pnpm/lockfile.fs";import ce from"stylelint";var le=`7.
|
|
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 ee from"json-stringify-pretty-compact";import{findWorkspaces as te,findWorkspacesRoot as ne}from"find-workspaces";import v,{access as re}from"node:fs/promises";import{stripVTControlCharacters as y}from"node:util";import{getDefaultConfigLoader as b,resolveConfigFileImports as x}from"cspell-lib";import{lint as ie}from"cspell";import"deepmerge-ts";import{loadConfig as S}from"mdat";import{globby as ae}from"globby";import C,{gt as w,minVersion as oe}from"semver";import{readWantedLockfile as se}from"@pnpm/lockfile.fs";import ce from"stylelint";var le=`7.2.0`;function ue(e){return e instanceof Error&&`exitCode`in e&&typeof e.exitCode==`number`}function T(e){return h(ee(g(e),{indent:2,replacer(e,t){return typeof t==`function`?t.name:t}}),{colors:{BRACKET:`gray`}})}const de=(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]=E(e[i],a,n):e.includes(a)||r.push(a);return r};function E(e,t,n={arrayMerge:de}){return _(e,t,n)}function fe(e,t){return e.startsWith(t+o.sep)}function pe(){let e=D(),t=new Set([e]),n=te();if(n!==null)for(let r of n){let n=o.resolve(r.location);fe(n,e)&&t.add(n)}return[...t]}function D(){let e=d();if(e===void 0)throw Error(`No package.json found.`);return o.dirname(e)}function me(){return ne()!==null}function O(){let e=ne();return e===null?D():o.resolve(e.location)}function k(e){let t=o.join(O(),e);if(r.existsSync(t))return t}function A(e){if(e===`workspace-root`)return O();if(e===`package-dir`)return D();if(typeof e==`string`){if(!r.pathExistsSync(e))throw Error(`Custom cwd directory does not exist: ${e}`);return e}return process.cwd()}async function he(e,t){try{let{default:n}=await import(`prettier`),r=await n.resolveConfig(e),i=await n.format(t,{filepath:e,...r});await v.writeFile(e,i,`utf8`)}catch{console.warn(`Skipped formatting ${e} since Prettier is not installed.`)}}async function j(e){try{await he(e,await v.readFile(e,`utf8`))}catch{}}const ge=/\r?\n/;function M(e){return new c({transform(t,n,r){let i=t.toString().split(ge).filter(t=>t.trim()!==``&&!e(y(t))).join(`
|
|
3
3
|
`);this.push(i+`
|
|
4
4
|
`),r()}})}function N(e,t){return new c({transform(n,r,i){let a=n.toString().split(ge).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 _e(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 ve(e){return e.replaceAll(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,e=>`-`+e.toLowerCase())}function P(e,t){return t===1?e:e+`s`}async function ye(e,t,n,r,i){let a=1,o;if(r.logPrefix===void 0)o=e;else{let t=N(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 be(e,t,r,i,a){let o=1,c;if(i.logPrefix===void 0)c=e;else{let t=N(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=A(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=M(i.outputFilter),n=M(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 _e(m),t=T(JSON.parse(e)).split(`
|
|
5
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),ue(e)&&(o=typeof e.exitCode==`number`?e.exitCode:1)}return o}function xe(e){return`execute`in e}const Se=/^ksc-/;function F(e){return e.replace(Se,``)}function I(e){return e===void 0||e.length===0?[]:e.flatMap(e=>e.split(`,`)).map(e=>F(e.trim()))}function L(e){return e.option(`skip`,{array:!0,describe:`Tool names to skip (with or without "ksc-" prefix).`,type:`string`})}async function R(e,t,n,r,i,a,o){let s=o??[],c=[],l=[];for(let e of r)s.length>0&&s.includes(F(e.name))?l.push(e):c.push(e);if(s.length>0){let t=new Set(l.map(e=>F(e.name))),n=s.filter(e=>!t.has(e));if(n.length>0){let t=r.map(e=>F(e.name)).join(`, `);e.write(`⚠️ ${f.yellow(`Unrecognized --skip ${P(`value`,n.length)}: ${n.join(`, `)}. Available: ${t}`)}\n`)}}let u=[];for(let r of c){let a=await(xe(r)?ye(e,t,n,r,i):be(e,t,n,r,i));u.push({exitCode:a,name:r.name})}let d=r.length;if(l.length>0){let t=l.map(({name:e})=>e);e.write(`⏭️ ${f.dim(f.bold(`${t.length} / ${d} ${P(`Command`,t.length)} Skipped:`))} ${f.dim(t.join(`, `))}\n`)}if(a){let t=u.filter(({exitCode:e})=>e===0).map(({name:e})=>e),n=u.filter(({exitCode:e})=>e!==0).map(({name:e})=>e);t.length>0&&e.write(`✅ ${f.green(f.bold(`${t.length} / ${d} ${P(`Command`,t.length)} Succeeded:`))} ${f.green(t.join(`, `))}\n`),n.length>0&&e.write(`❌ ${f.red(f.bold(`${n.length} / ${d} ${P(`Command`,n.length)} Failed:`))} ${f.red(n.join(`, `))}\n`)}return u.every(({exitCode:e})=>e===0)?0:1}async function Ce(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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FileType, FileType as FileType$1 } from "@kitschpatrol/prettier-config";
|
|
2
|
+
|
|
3
|
+
//#region src/api.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Fix a source string by running all shared-config tools in sequence: Mdat →
|
|
6
|
+
* ESLint → Stylelint → Prettier. Each tool silently skips content it doesn't
|
|
7
|
+
* understand.
|
|
8
|
+
*
|
|
9
|
+
* @param source - The source code to fix.
|
|
10
|
+
* @param fileType - A file extension (e.g. `'ts'`, `'css'`, `'md'`) or virtual
|
|
11
|
+
* filepath for parser inference. Defaults to `'ts'`.
|
|
12
|
+
*
|
|
13
|
+
* @returns The fixed source string.
|
|
14
|
+
*/
|
|
15
|
+
declare function fix(source: string, fileType?: FileType$1): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Fix a file in place by running all shared-config tools in sequence: Mdat →
|
|
18
|
+
* ESLint → Stylelint → Prettier. Each tool silently skips content it doesn't
|
|
19
|
+
* understand.
|
|
20
|
+
*
|
|
21
|
+
* @param filePath - Path to the file to fix.
|
|
22
|
+
*/
|
|
23
|
+
declare function fixFile(filePath: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Clear all cached tool modules and instances. Subsequent calls to `fix` or
|
|
26
|
+
* `fixFile` will re-import all tools.
|
|
27
|
+
*/
|
|
28
|
+
declare function clearCache(): void;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { type FileType, clearCache, fix, fixFile };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{clearCache as e,fix as t,fixFile as n}from"@kitschpatrol/eslint-config";import{clearCache as r,fix as i,fixFile as a}from"@kitschpatrol/mdat-config";import{clearCache as o,fix as s,fixFile as c}from"@kitschpatrol/prettier-config";import{clearCache as l,fix as u,fixFile as d}from"@kitschpatrol/stylelint-config";async function f(e,n){let r=e;try{r=await i(r)}catch{}try{r=await t(r,n)}catch{}try{r=await u(r,n)}catch{}try{r=await s(r,n)}catch{}return r}async function p(e){try{await a(e)}catch{}try{await n(e)}catch{}try{await d(e)}catch{}try{await c(e)}catch{}}function m(){r(),e(),l(),o()}export{m as clearCache,f as fix,p as fixFile};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/shared-config",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
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",
|
|
@@ -30,19 +30,28 @@
|
|
|
30
30
|
},
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"type": "module",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"main": "dist/index.js",
|
|
40
|
+
"types": "dist/index.d.ts",
|
|
33
41
|
"bin": {
|
|
34
42
|
"ksc": "bin/cli.js"
|
|
35
43
|
},
|
|
36
44
|
"files": [
|
|
37
|
-
"bin/*"
|
|
45
|
+
"bin/*",
|
|
46
|
+
"dist/*"
|
|
38
47
|
],
|
|
39
48
|
"dependencies": {
|
|
40
49
|
"@pinojs/json-colorizer": "^4.0.0",
|
|
41
50
|
"@pnpm/lockfile.fs": "^1001.1.32",
|
|
42
51
|
"cosmiconfig": "^9.0.1",
|
|
43
52
|
"cosmiconfig-typescript-loader": "^6.2.0",
|
|
44
|
-
"cspell": "^
|
|
45
|
-
"cspell-lib": "^
|
|
53
|
+
"cspell": "^10.0.0",
|
|
54
|
+
"cspell-lib": "^10.0.0",
|
|
46
55
|
"decircular": "^1.0.0",
|
|
47
56
|
"deepmerge": "^4.3.1",
|
|
48
57
|
"deepmerge-ts": "^7.1.5",
|
|
@@ -51,22 +60,22 @@
|
|
|
51
60
|
"fs-extra": "^11.3.4",
|
|
52
61
|
"globby": "^16.2.0",
|
|
53
62
|
"json-stringify-pretty-compact": "^4.0.0",
|
|
54
|
-
"mdat": "^2.2.
|
|
63
|
+
"mdat": "^2.2.1",
|
|
55
64
|
"package-up": "^5.0.0",
|
|
56
65
|
"picocolors": "^1.1.1",
|
|
57
66
|
"prettier": "^3.8.1",
|
|
58
67
|
"semver": "^7.7.4",
|
|
59
68
|
"stylelint": "^17.6.0",
|
|
60
69
|
"yargs": "^18.0.0",
|
|
61
|
-
"@kitschpatrol/cspell-config": "7.
|
|
62
|
-
"@kitschpatrol/eslint-config": "7.
|
|
63
|
-
"@kitschpatrol/
|
|
64
|
-
"@kitschpatrol/
|
|
65
|
-
"@kitschpatrol/
|
|
66
|
-
"@kitschpatrol/
|
|
67
|
-
"@kitschpatrol/
|
|
68
|
-
"@kitschpatrol/typescript-config": "7.
|
|
69
|
-
"@kitschpatrol/
|
|
70
|
+
"@kitschpatrol/cspell-config": "7.2.0",
|
|
71
|
+
"@kitschpatrol/eslint-config": "7.2.0",
|
|
72
|
+
"@kitschpatrol/knip-config": "7.2.0",
|
|
73
|
+
"@kitschpatrol/prettier-config": "7.2.0",
|
|
74
|
+
"@kitschpatrol/mdat-config": "7.2.0",
|
|
75
|
+
"@kitschpatrol/remark-config": "7.2.0",
|
|
76
|
+
"@kitschpatrol/stylelint-config": "7.2.0",
|
|
77
|
+
"@kitschpatrol/typescript-config": "7.2.0",
|
|
78
|
+
"@kitschpatrol/repo-config": "7.2.0"
|
|
70
79
|
},
|
|
71
80
|
"engines": {
|
|
72
81
|
"node": ">=22.18.0"
|
|
@@ -77,6 +86,7 @@
|
|
|
77
86
|
"scripts": {
|
|
78
87
|
"build": "tsdown",
|
|
79
88
|
"clean": "pnpm run bin-restore ; git clean -fdX",
|
|
80
|
-
"cli": "node ./bin/cli.js"
|
|
89
|
+
"cli": "node ./bin/cli.js",
|
|
90
|
+
"test": "vitest run"
|
|
81
91
|
}
|
|
82
92
|
}
|
package/readme.md
CHANGED
|
@@ -324,6 +324,32 @@ ksc print-config [file]
|
|
|
324
324
|
|
|
325
325
|
Recall that the `@kitschpatrol/shared-config` package aggregates integration and invocation of the other tool-specific packages in this monorepo. Running a cli command on `ksc` effectively runs the same command against all the tool-specific packages.
|
|
326
326
|
|
|
327
|
+
### API
|
|
328
|
+
|
|
329
|
+
The package also exports `fix`, `fixFile` functions that run all shared-config tools in sequence, matching the order of `ksc fix`: Mdat → ESLint → Stylelint → Prettier. Each tool silently skips content it doesn't understand.
|
|
330
|
+
|
|
331
|
+
The CLI is preferred, but there are occasionally edge cases where it's handy to run a string or a generated file through the shared-config pipeline without leaving TypeScript.
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
import { clearCache, fix, fixFile } from '@kitschpatrol/shared-config'
|
|
335
|
+
|
|
336
|
+
// Fix a string with all tools (defaults to TypeScript)
|
|
337
|
+
const fixed = await fix('let x = 1\nconsole.log(x)\n')
|
|
338
|
+
|
|
339
|
+
// Fix with a file type hint
|
|
340
|
+
const fixedCss = await fix(cssSource, 'css')
|
|
341
|
+
const fixedMarkdown = await fix(mdSource, 'md')
|
|
342
|
+
|
|
343
|
+
// Fix a file in place with all tools
|
|
344
|
+
await fixFile('./src/index.ts')
|
|
345
|
+
await fixFile('./src/styles.css')
|
|
346
|
+
|
|
347
|
+
// Clear all cached tool modules
|
|
348
|
+
clearCache()
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Each sub-package with a `fix` command also exports its own `fix`, `fixFile`, and `clearCache` for standalone use. See the individual package readmes for details. (With the exception of, `ksc-repo`, whose `fix` behavior is too file-specific to be generically useful.)
|
|
352
|
+
|
|
327
353
|
## Implementation notes
|
|
328
354
|
|
|
329
355
|
### Line endings
|