@kitschpatrol/stylelint-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 +7 -5
- package/dist/index.d.ts +14 -13
- package/package.json +2 -8
- package/readme.md +8 -10
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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 from"node:fs";import a from"node:path";import{PassThrough as o,Transform as s}from"node:stream";import{fileURLToPath as c}from"node:url";import{packageUp as l,packageUpSync as u}from"package-up";import d from"picocolors";import f from"yargs";import{hideBin as p}from"yargs/helpers";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";import b from"stylelint";var
|
|
3
|
-
`);
|
|
4
|
-
`),
|
|
5
|
-
`)
|
|
6
|
-
`);
|
|
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 from"node:fs";import a from"node:path";import{PassThrough as o,Transform as s}from"node:stream";import{fileURLToPath as c}from"node:url";import{packageUp as l,packageUpSync as u}from"package-up";import d from"picocolors";import f from"yargs";import{hideBin as p}from"yargs/helpers";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";import{stripVTControlCharacters as b}from"node:util";import x from"stylelint";var S=`7.0.1`;function C(e){return e instanceof Error&&`exitCode`in e&&typeof e.exitCode==`number`}function w(e){return m(_(h(e),{indent:2,replacer(e,t){return typeof t==`function`?t.name:t}}),{colors:{BRACKET:`gray`}})}const T=(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:T}){return g(e,t,n)}function D(){let e=u();if(e===void 0)throw Error(`No package.json found.`);return a.dirname(e)}function O(){let e=v();return e===null?D():a.resolve(e.location)}function k(e){let t=a.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 j(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 M(e){try{await j(e,await y.readFile(e,`utf8`))}catch{}}const N=/\r?\n/;function P(e){return new s({transform(t,n,r){let i=t.toString().split(N).filter(t=>t.trim()!==``&&!e(b(t))).join(`
|
|
3
|
+
`);this.push(i+`
|
|
4
|
+
`),r()}})}function F(e,t){return new s({transform(n,r,i){let a=n.toString().split(N).filter(e=>e.trim().length>0).map(n=>`${e?t===void 0?e:d[t](e):``} ${n}\n`).join(``);this.push(a),i()}})}async function I(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 L(e,t){return t===1?e:e+`s`}async function R(e,t,n,r,i){let a=1,o;if(r.logPrefix===void 0)o=e;else{let t=F(r.logPrefix,r.logColor);t.pipe(e),o=t}i&&o.write(d.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 z(e,t,r,i,a){let s=1,c;if(i.logPrefix===void 0)c=e;else{let t=F(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 o: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=P(i.outputFilter),n=P(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 I(m),t=w(JSON.parse(e)).split(`
|
|
5
|
+
`);for(let e of t)c.write(`${e}\n`)}s=e.exitCode??1}catch(e){console.error(`${i.name} failed with error:`),console.error(e),C(e)&&(s=typeof e.exitCode==`number`?e.exitCode:1)}return s}function B(e){return`execute`in e}async function V(e,t,n,r,i,a){let o=[];for(let a of r){let r=await(B(a)?R(e,t,n,a,i):z(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(`✅ ${d.green(d.bold(`${t.length} / ${r} ${L(`Command`,t.length)} Succeeded:`))} ${d.green(t.join(`, `))}\n`),n.length>0&&e.write(`❌ ${d.red(d.bold(`${n.length} / ${r} ${L(`Command`,n.length)} Failed:`))} ${d.red(n.join(`, `))}\n`)}return o.every(({exitCode:e})=>e===0)?0:1}async function H(e,t,n,o){let s=await l();if(s===void 0)throw Error("The `init` command must be used in a directory with a package.json file");let u=await l({cwd:c(import.meta.url)});if(u===void 0)return e.write(`Error: The script being called was not in a package, weird.
|
|
6
|
+
`),1;let d=a.join(a.dirname(u),`init`),f=a.dirname(s),p=(t===`file`||t===`package`)&&n!==void 0&&o!==void 0;try{if(p){let n=Object.keys(o)[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=E(t,o);r.writeJSONSync(s,i,{spaces:` `}),await M(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 M(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(o,s){let c=i.statSync(o).isFile(),l=i.existsSync(s);if(c){if(p&&t===`package`&&o.includes(n))return l?(e.write(`Deleting: \n"${o}" → "${s}" (Because --location is set to "package")\n`),r.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`))&&a.extname(s)===`.json`){e.write(`Merging: \n"${o}" → "${s}"\n`);let t=r.readJSONSync(o),n=E(r.readJSONSync(s),t);return r.writeJSONSync(s,n,{spaces:` `}),await M(s),!1}return l?(e.write(`Overwriting: \n"${o}" → "${s}"\n`),await M(s),!0):(e.write(`Copying: \n"${o}" → "${s}"\n`),await M(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:u}=e,d=F(s,o);d.pipe(process.stdout);let m=f(p(process.argv)).scriptName(c).usage(`$0 <command>`,a);n!==void 0&&m.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 V(d,[],t===void 0?[]:[`--location`,t],[{async execute(e,t,r){return H(e,r.at(1),n.configFile,n.configPackageJson)},name:`copyAndMergeInitFiles`},...n.commands??[]]);process.exit(r)}}),r!==void 0&&m.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 V(d,e.files??[],[],r.commands,u,l);process.exit(t)}}),t!==void 0&&m.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 V(d,e.files??[],[],t.commands);process.exit(n)}}),i!==void 0&&m.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 V(d,t===void 0?[]:[t],[],i.commands,u,l);process.exit(n)}}),m.alias(`h`,`help`),m.version(S),m.alias(`v`,`version`),m.help(),m.wrap(process.stdout.isTTY?Math.min(120,m.terminalWidth()):0),await m.parseAsync()}async function W(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 G={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.`},K=[`--ignore-path`,k(`.gitignore`)??`.gitignore`,`--allow-empty-input`],q=`**/*.{${[`css`,`scss`,`sass`,`svelte`,`html`,`astro`,`tsx`,`jsx`,`php`,`vue`].join(`,`)}}`;async function J(e,t){let n=`stylelint`,r=await W(n);if(r===void 0)return 1;let{filepath:i,isEmpty:o}=r;if(o)return e.write(`Configuration is empty.
|
|
7
|
+
`),0;e.write(`Found ${n} configuration at "${i}"\n`);let s;t.length>0?(s=a.join(process.cwd(),t[0]),e.write(`Showing config for file at "${s}"\n`)):s=A(`package-dir`);let c=w(await x.resolveConfig(s)).split(`
|
|
8
|
+
`);for(let t of c)e.write(`${t}\n`);return 0}await U({commands:{fix:{commands:[{name:`stylelint`,optionFlags:[...K,`--fix`],receivePositionalArguments:!0}],description:`Fix your project with Stylelint. ${G.fileRun}`,positionalArgumentDefault:q,positionalArgumentMode:`optional`},init:{configFile:`stylelint.config.js`,configPackageJson:{stylelint:{extends:`@kitschpatrol/stylelint-config`}},locationOptionFlag:!0},lint:{commands:[{name:`stylelint`,optionFlags:K,receivePositionalArguments:!0}],description:`Lint your project with Stylelint. ${G.fileRun}`,positionalArgumentDefault:q,positionalArgumentMode:`optional`},printConfig:{commands:[{execute:J,name:J.name}],description:`Print the effective Stylelint configuration. ${G.optionalFileRun}.`,positionalArgumentMode:`optional`}},description:`Kitschpatrol's Stylelint shared configuration tools.`,logColor:`greenBright`,logPrefix:`[Stylelint]`,name:`ksc-stylelint`,order:5});export{};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,21 +3,22 @@ import { Config } from "stylelint";
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
declare const sharedStylelintConfig: Config;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @see [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config)
|
|
6
|
+
* **@Kitschpatrol's Shared Stylelint Configuration**
|
|
7
|
+
*
|
|
9
8
|
* @example
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* import { stylelintConfig } from '@kitschpatrol/stylelint-config'
|
|
10
|
+
*
|
|
11
|
+
* export default stylelintConfig({
|
|
12
|
+
* ignoreFiles: ['example.html'],
|
|
13
|
+
* rules: {
|
|
14
|
+
* 'alpha-value-notation': 'number',
|
|
15
|
+
* 'selector-class-pattern': null,
|
|
16
|
+
* },
|
|
17
|
+
* })
|
|
12
18
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 'alpha-value-notation': 'number',
|
|
17
|
-
* 'selector-class-pattern': null,
|
|
18
|
-
* },
|
|
19
|
-
* })
|
|
20
|
-
* ```
|
|
19
|
+
* @see [@kitschpatrol/stylelint-config](https://github.com/kitschpatrol/shared-config/tree/main/packages/stylelint-config)
|
|
20
|
+
*
|
|
21
|
+
* @see [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config)
|
|
21
22
|
*/
|
|
22
23
|
declare function stylelintConfig(config?: Config): Config;
|
|
23
24
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/stylelint-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Stylelint configuration for @kitschpatrol/shared-config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stylelint-config",
|
|
@@ -60,13 +60,7 @@
|
|
|
60
60
|
"yargs": "^18.0.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
64
|
-
},
|
|
65
|
-
"devEngines": {
|
|
66
|
-
"runtime": {
|
|
67
|
-
"name": "node",
|
|
68
|
-
"version": ">=22.18.0"
|
|
69
|
-
}
|
|
63
|
+
"node": ">=22.18.0"
|
|
70
64
|
},
|
|
71
65
|
"publishConfig": {
|
|
72
66
|
"access": "public"
|
package/readme.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
<!--+ Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. +-->
|
|
2
|
-
|
|
3
1
|
<!-- title -->
|
|
4
2
|
|
|
5
3
|
# @kitschpatrol/stylelint-config
|
|
@@ -162,11 +160,11 @@ Usage:
|
|
|
162
160
|
ksc-stylelint init
|
|
163
161
|
```
|
|
164
162
|
|
|
165
|
-
| Option | Description
|
|
166
|
-
| ------------------- |
|
|
167
|
-
| `--location` |
|
|
168
|
-
| `--help`<br>`-h` | Show help
|
|
169
|
-
| `--version`<br>`-v` | Show version number
|
|
163
|
+
| Option | Description | Type | Default |
|
|
164
|
+
| ------------------- | --------------------------------- | -------------------- | -------- |
|
|
165
|
+
| `--location` | Where to store the configuration. | `"file"` `"package"` | `"file"` |
|
|
166
|
+
| `--help`<br>`-h` | Show help | `boolean` | |
|
|
167
|
+
| `--version`<br>`-v` | Show version number | `boolean` | |
|
|
170
168
|
|
|
171
169
|
#### Subcommand: `ksc-stylelint lint`
|
|
172
170
|
|
|
@@ -216,9 +214,9 @@ Usage:
|
|
|
216
214
|
ksc-stylelint print-config [file]
|
|
217
215
|
```
|
|
218
216
|
|
|
219
|
-
| Positional Argument | Description
|
|
220
|
-
| ------------------- |
|
|
221
|
-
| `file` | File or glob pattern to
|
|
217
|
+
| Positional Argument | Description | Type |
|
|
218
|
+
| ------------------- | ------------------------------------------------ | -------- |
|
|
219
|
+
| `file` | File or glob pattern to print configuration for. | `string` |
|
|
222
220
|
|
|
223
221
|
| Option | Description | Type |
|
|
224
222
|
| ------------------- | ------------------- | --------- |
|