@naturalcycles/dev-lib 19.21.1 → 19.23.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/cfg/lint-staged.config.js +10 -11
- package/dist/lint.util.js +24 -19
- package/package.json +1 -1
|
@@ -38,8 +38,10 @@ const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
|
|
|
38
38
|
|
|
39
39
|
const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
|
|
40
40
|
|
|
41
|
-
const prettierCmd =
|
|
42
|
-
|
|
41
|
+
const prettierCmd =
|
|
42
|
+
!!prettierConfigPath &&
|
|
43
|
+
`prettier --write --experimental-cli --config-path ${prettierConfigPath} --cache-location node_modules/.cache/prettier`
|
|
44
|
+
const eslintCmd = `eslint --fix --cache`
|
|
43
45
|
|
|
44
46
|
const stylelintExists =
|
|
45
47
|
!!stylelintConfigPath &&
|
|
@@ -70,7 +72,8 @@ const linters = {
|
|
|
70
72
|
if (!filesList) return []
|
|
71
73
|
return [
|
|
72
74
|
biomeCmd,
|
|
73
|
-
eslintConfigPathRoot &&
|
|
75
|
+
eslintConfigPathRoot &&
|
|
76
|
+
`${eslintCmd} --config ${eslintConfigPathRoot} --cache-location ./node_modules/.cache/eslint_src`,
|
|
74
77
|
prettierCmd,
|
|
75
78
|
]
|
|
76
79
|
.filter(Boolean)
|
|
@@ -143,9 +146,7 @@ const linters = {
|
|
|
143
146
|
|
|
144
147
|
// /scripts are separate, cause they require separate tsconfig.json
|
|
145
148
|
if (fs.existsSync(`./scripts`)) {
|
|
146
|
-
const eslintConfigPathScripts = ['./scripts/eslint.config.js'
|
|
147
|
-
fs.existsSync(p),
|
|
148
|
-
)
|
|
149
|
+
const eslintConfigPathScripts = ['./scripts/eslint.config.js'].find(p => fs.existsSync(p))
|
|
149
150
|
Object.assign(linters, {
|
|
150
151
|
// biome, eslint, Prettier
|
|
151
152
|
'./scripts/**/*.{ts,tsx,cts,mts,vue,html}': match => {
|
|
@@ -154,7 +155,7 @@ if (fs.existsSync(`./scripts`)) {
|
|
|
154
155
|
return [
|
|
155
156
|
biomeCmd,
|
|
156
157
|
eslintConfigPathScripts &&
|
|
157
|
-
`${eslintCmd} --config ${eslintConfigPathScripts} --parser-options=project:./scripts/tsconfig.json`,
|
|
158
|
+
`${eslintCmd} --config ${eslintConfigPathScripts} --parser-options=project:./scripts/tsconfig.json --cache-location ./node_modules/.cache/eslint_scripts`,
|
|
158
159
|
prettierCmd,
|
|
159
160
|
]
|
|
160
161
|
.filter(Boolean)
|
|
@@ -165,9 +166,7 @@ if (fs.existsSync(`./scripts`)) {
|
|
|
165
166
|
|
|
166
167
|
// /e2e
|
|
167
168
|
if (fs.existsSync(`./e2e`)) {
|
|
168
|
-
const eslintConfigPathE2e = ['./e2e/eslint.config.js'
|
|
169
|
-
fs.existsSync(p),
|
|
170
|
-
)
|
|
169
|
+
const eslintConfigPathE2e = ['./e2e/eslint.config.js'].find(p => fs.existsSync(p))
|
|
171
170
|
|
|
172
171
|
Object.assign(linters, {
|
|
173
172
|
// biome, eslint, Prettier
|
|
@@ -177,7 +176,7 @@ if (fs.existsSync(`./e2e`)) {
|
|
|
177
176
|
return [
|
|
178
177
|
biomeCmd,
|
|
179
178
|
eslintConfigPathE2e &&
|
|
180
|
-
`${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./e2e/tsconfig.json`,
|
|
179
|
+
`${eslintCmd} --config ${eslintConfigPathE2e} --parser-options=project:./e2e/tsconfig.json --cache-location ./node_modules/.cache/eslint_e2e`,
|
|
181
180
|
prettierCmd,
|
|
182
181
|
]
|
|
183
182
|
.filter(Boolean)
|
package/dist/lint.util.js
CHANGED
|
@@ -14,7 +14,7 @@ import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
|
|
|
14
14
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
15
15
|
import { _yargs } from '@naturalcycles/nodejs-lib/yargs';
|
|
16
16
|
import { eslintExtensions, lintExclude, minActionlintVersion, prettierDirs, prettierExtensionsAll, stylelintExtensions, } from '../cfg/_cnst.js';
|
|
17
|
-
import { cfgDir
|
|
17
|
+
import { cfgDir } from './paths.js';
|
|
18
18
|
const { CI } = process.env;
|
|
19
19
|
/**
|
|
20
20
|
* Run all linters.
|
|
@@ -88,43 +88,48 @@ export async function eslintAll(opt) {
|
|
|
88
88
|
...opt,
|
|
89
89
|
};
|
|
90
90
|
const extensions = ext.split(',');
|
|
91
|
-
const eslintConfigPathRoot = ['./eslint.config.js'].find(p => existsSync(p));
|
|
92
|
-
const eslintConfigPathScripts = ['./scripts/eslint.config.js', './eslint.config.js'].find(p => existsSync(p));
|
|
93
|
-
const eslintConfigPathE2e = ['./e2e/eslint.config.js', './eslint.config.js'].find(p => existsSync(p));
|
|
94
|
-
const tsconfigPathScripts = [`./scripts/tsconfig.json`].find(p => existsSync(p)) || `${scriptsDir}/tsconfig.json`;
|
|
95
|
-
const tsconfigPathE2e = `./e2e/tsconfig.json`;
|
|
96
|
-
// todo: run on other dirs too, e.g pages, components, layouts
|
|
97
91
|
if (fix) {
|
|
98
92
|
await Promise.all([
|
|
99
93
|
// /src
|
|
100
|
-
runESLint(
|
|
94
|
+
runESLint(`src`, extensions, fix),
|
|
101
95
|
// /scripts
|
|
102
|
-
runESLint(
|
|
96
|
+
runESLint(`scripts`, extensions, fix),
|
|
103
97
|
// /e2e
|
|
104
|
-
runESLint(
|
|
98
|
+
runESLint(`e2e`, extensions, fix),
|
|
105
99
|
]);
|
|
106
100
|
}
|
|
107
101
|
else {
|
|
108
102
|
// with no-fix - let's run serially
|
|
109
103
|
// /src
|
|
110
|
-
await runESLint(
|
|
104
|
+
await runESLint(`src`, extensions, fix);
|
|
111
105
|
// /scripts
|
|
112
|
-
await runESLint(
|
|
106
|
+
await runESLint(`scripts`, extensions, fix);
|
|
113
107
|
// /e2e
|
|
114
|
-
await runESLint(
|
|
108
|
+
await runESLint(`e2e`, extensions, fix);
|
|
115
109
|
}
|
|
116
110
|
console.log(`${boldGrey('eslint-all')} ${dimGrey(`took ` + _since(started))}`);
|
|
117
111
|
}
|
|
118
|
-
async function runESLint(dir,
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
async function runESLint(dir, extensions = eslintExtensions.split(','), fix = true) {
|
|
113
|
+
let configDir = dir;
|
|
114
|
+
if (dir === 'src') {
|
|
115
|
+
configDir = '.';
|
|
116
|
+
}
|
|
117
|
+
const eslintConfigPath = `${configDir}/eslint.config.js`;
|
|
118
|
+
const tsconfigPath = `${configDir}/tsconfig.json`;
|
|
119
|
+
if (!existsSync(dir) || !existsSync(eslintConfigPath) || !existsSync(tsconfigPath)) {
|
|
120
|
+
// faster to bail-out like this
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
121
123
|
const eslintPath = findPackageBinPath('eslint', 'eslint');
|
|
122
124
|
await exec2.spawnAsync(eslintPath, {
|
|
123
125
|
args: [
|
|
124
126
|
`--config`,
|
|
125
127
|
eslintConfigPath,
|
|
126
128
|
`${dir}/**/*.{${extensions.join(',')}}`,
|
|
127
|
-
|
|
129
|
+
`--parser-options=project:${tsconfigPath}`,
|
|
130
|
+
'--cache',
|
|
131
|
+
'--cache-location',
|
|
132
|
+
`./node_modules/.cache/eslint_${dir}`,
|
|
128
133
|
`--no-error-on-unmatched-pattern`,
|
|
129
134
|
`--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
|
|
130
135
|
fix ? `--fix` : '',
|
|
@@ -154,8 +159,8 @@ export function runPrettier(experimentalCli = true) {
|
|
|
154
159
|
args: [
|
|
155
160
|
`--write`,
|
|
156
161
|
`--log-level=warn`,
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
'--cache-location',
|
|
163
|
+
`node_modules/.cache/prettier`,
|
|
159
164
|
experimentalCli && `--experimental-cli`,
|
|
160
165
|
experimentalCli ? '--config-path' : `--config`,
|
|
161
166
|
prettierConfigPath,
|