@naturalcycles/dev-lib 19.30.0 → 19.31.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/cfg/lint-staged.config.js +5 -2
- package/dist/build.util.js +6 -3
- package/dist/lint.util.js +18 -7
- package/package.json +1 -1
|
@@ -128,13 +128,16 @@ export function runBiomeEslintPrettier(match, dir) {
|
|
|
128
128
|
configDir = '.'
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
const cwd = process.cwd()
|
|
131
132
|
const eslintConfigPath = `${configDir}/eslint.config.js`
|
|
132
|
-
const tsconfigPath =
|
|
133
|
+
const tsconfigPath = [cwd, configDir !== '.' && configDir, 'tsconfig.json']
|
|
134
|
+
.filter(Boolean)
|
|
135
|
+
.join('/')
|
|
133
136
|
|
|
134
137
|
return [
|
|
135
138
|
biomeCmd,
|
|
136
139
|
eslintConfigPath &&
|
|
137
|
-
`${eslintCmd} --config ${eslintConfigPath} --parser-options=
|
|
140
|
+
`${eslintCmd} --config ${eslintConfigPath} --parser-options=project:${tsconfigPath} --cache-location node_modules/.cache/eslint_${dir}`,
|
|
138
141
|
prettierCmd,
|
|
139
142
|
]
|
|
140
143
|
.filter(Boolean)
|
package/dist/build.util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { dimGrey } from '@naturalcycles/nodejs-lib/colors';
|
|
3
3
|
import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
|
|
4
4
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
5
5
|
import { kpySync } from '@naturalcycles/nodejs-lib/kpy';
|
|
@@ -38,7 +38,7 @@ export async function runTSCInFolder(dir, args = []) {
|
|
|
38
38
|
const tscPath = findPackageBinPath('typescript', 'tsc');
|
|
39
39
|
const cacheLocation = `node_modules/.cache/${dir}.tsbuildinfo`;
|
|
40
40
|
const cacheFound = existsSync(cacheLocation);
|
|
41
|
-
console.log(
|
|
41
|
+
console.log(dimGrey(`${check(cacheFound)} tsc ${dir} cache found: ${cacheFound}`));
|
|
42
42
|
await exec2.spawnAsync(tscPath, {
|
|
43
43
|
args: ['-P', tsconfigPath, ...args],
|
|
44
44
|
shell: false,
|
|
@@ -49,7 +49,7 @@ export async function runTSCProd(args = []) {
|
|
|
49
49
|
const tscPath = findPackageBinPath('typescript', 'tsc');
|
|
50
50
|
const cacheLocation = `node_modules/.cache/src.tsbuildinfo`;
|
|
51
51
|
const cacheFound = existsSync(cacheLocation);
|
|
52
|
-
console.log(
|
|
52
|
+
console.log(dimGrey(` tsc src cache found: ${cacheFound}`));
|
|
53
53
|
await exec2.spawnAsync(tscPath, {
|
|
54
54
|
args: ['-P', tsconfigPath, '--noEmit', 'false', '--noCheck', ...args],
|
|
55
55
|
shell: false,
|
|
@@ -73,3 +73,6 @@ export function buildCopy() {
|
|
|
73
73
|
dotfiles: true,
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
+
function check(predicate) {
|
|
77
|
+
return predicate ? '✔️ ' : ' ';
|
|
78
|
+
}
|
package/dist/lint.util.js
CHANGED
|
@@ -8,7 +8,7 @@ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
|
8
8
|
import { _filterFalsyValues } from '@naturalcycles/js-lib/object/object.util.js';
|
|
9
9
|
import { semver2 } from '@naturalcycles/js-lib/semver';
|
|
10
10
|
import { git2 } from '@naturalcycles/nodejs-lib';
|
|
11
|
-
import { boldGrey, dimGrey
|
|
11
|
+
import { boldGrey, dimGrey } from '@naturalcycles/nodejs-lib/colors';
|
|
12
12
|
import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
|
|
13
13
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
14
14
|
import { _yargs } from '@naturalcycles/nodejs-lib/yargs';
|
|
@@ -54,7 +54,7 @@ export async function lintAllCommand() {
|
|
|
54
54
|
}
|
|
55
55
|
runPrettier({ fix });
|
|
56
56
|
await runKTLint(fix);
|
|
57
|
-
console.log(`${boldGrey(
|
|
57
|
+
console.log(`${boldGrey(`${check(true)} lint-all`)} ${dimGrey(`took ` + _since(started))}`);
|
|
58
58
|
// if (needToTrackChanges) {
|
|
59
59
|
// const gitStatusAfter = gitStatus()
|
|
60
60
|
// const hasChanges = gitStatusAfter !== gitStatusAtStart
|
|
@@ -110,31 +110,36 @@ export async function eslintAll(opt) {
|
|
|
110
110
|
await runESLint(`scripts`, extensions, fix);
|
|
111
111
|
await runESLint(`e2e`, extensions, fix);
|
|
112
112
|
}
|
|
113
|
-
console.log(`${boldGrey(
|
|
113
|
+
console.log(`${boldGrey(`${check(true)} eslint-all`)} ${dimGrey(`took ` + _since(started))}`);
|
|
114
114
|
}
|
|
115
115
|
async function runESLint(dir, extensions = eslintExtensions.split(','), fix = true) {
|
|
116
116
|
let configDir = dir;
|
|
117
117
|
if (dir === 'src') {
|
|
118
118
|
configDir = '.';
|
|
119
119
|
}
|
|
120
|
+
const cwd = process.cwd();
|
|
120
121
|
const eslintConfigPath = `${configDir}/eslint.config.js`;
|
|
121
|
-
const tsconfigPath =
|
|
122
|
+
const tsconfigPath = [cwd, configDir !== '.' && configDir, 'tsconfig.json']
|
|
123
|
+
.filter(Boolean)
|
|
124
|
+
.join('/');
|
|
122
125
|
if (!existsSync(dir) || !existsSync(eslintConfigPath) || !existsSync(tsconfigPath)) {
|
|
123
126
|
// faster to bail-out like this
|
|
124
127
|
return;
|
|
125
128
|
}
|
|
129
|
+
// const tsconfigRootDir = [cwd, configDir !== '.' && configDir].filter(Boolean).join('/')
|
|
126
130
|
const eslintPath = findPackageBinPath('eslint', 'eslint');
|
|
127
131
|
const cacheLocation = `node_modules/.cache/eslint_${dir}`;
|
|
128
132
|
const cacheFound = existsSync(cacheLocation);
|
|
129
|
-
console.log(
|
|
133
|
+
console.log(dimGrey(`${check(cacheFound)} eslint ${dir} cache found: ${cacheFound}`));
|
|
130
134
|
await exec2.spawnAsync(eslintPath, {
|
|
135
|
+
name: ['eslint', dir, !fix && '--no-fix'].filter(Boolean).join(' '),
|
|
131
136
|
args: [
|
|
132
137
|
`--config`,
|
|
133
138
|
eslintConfigPath,
|
|
134
139
|
`${dir}/**/*.{${extensions.join(',')}}`,
|
|
135
140
|
`--parser-options=project:${tsconfigPath}`,
|
|
136
141
|
// The next line fixes the `typescript-eslint` 8.37 bug of resolving tsconfig.json
|
|
137
|
-
`--parser-options=tsconfigRootDir
|
|
142
|
+
// `--parser-options=tsconfigRootDir:${tsconfigRootDir}`,
|
|
138
143
|
ESLINT_CONCURRENCY && `--concurrency=${ESLINT_CONCURRENCY}`,
|
|
139
144
|
'--cache',
|
|
140
145
|
'--cache-location',
|
|
@@ -166,9 +171,10 @@ export function runPrettier(opt = {}) {
|
|
|
166
171
|
const prettierPath = findPackageBinPath('prettier', 'prettier');
|
|
167
172
|
const cacheLocation = 'node_modules/.cache/prettier';
|
|
168
173
|
const cacheFound = existsSync(cacheLocation);
|
|
169
|
-
console.log(
|
|
174
|
+
console.log(dimGrey(`${check(cacheFound)} prettier cache found: ${cacheFound}`));
|
|
170
175
|
// prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
|
|
171
176
|
exec2.spawn(prettierPath, {
|
|
177
|
+
name: fix ? 'prettier' : 'prettier --check',
|
|
172
178
|
args: [
|
|
173
179
|
fix ? `--write` : '--check',
|
|
174
180
|
`--log-level=warn`,
|
|
@@ -201,6 +207,7 @@ export function stylelintAll(fix) {
|
|
|
201
207
|
return;
|
|
202
208
|
// stylelint is never hoisted from dev-lib, so, no need to search for its path
|
|
203
209
|
exec2.spawn('stylelint', {
|
|
210
|
+
name: fix ? 'stylelint' : 'stylelint --no-fix',
|
|
204
211
|
args: [fix ? `--fix` : '', `--allow-empty-input`, `--config`, config, ...stylelintPaths].filter(Boolean),
|
|
205
212
|
shell: false,
|
|
206
213
|
});
|
|
@@ -274,6 +281,7 @@ export function runBiome(fix = true) {
|
|
|
274
281
|
const biomePath = findPackageBinPath('@biomejs/biome', 'biome');
|
|
275
282
|
const dirs = [`src`, `scripts`, `e2e`].filter(d => existsSync(d));
|
|
276
283
|
exec2.spawn(biomePath, {
|
|
284
|
+
name: fix ? 'biome' : 'biome --no-fix',
|
|
277
285
|
args: [`lint`, fix && '--write', fix && '--unsafe', '--no-errors-on-unmatched', ...dirs].filter(_isTruthy),
|
|
278
286
|
logFinish: false,
|
|
279
287
|
shell: false,
|
|
@@ -301,3 +309,6 @@ export function findPackageBinPath(pkg, cmd) {
|
|
|
301
309
|
const { bin } = fs2.readJson(packageJsonPath);
|
|
302
310
|
return path.join(path.dirname(packageJsonPath), typeof bin === 'string' ? bin : bin[cmd]);
|
|
303
311
|
}
|
|
312
|
+
function check(predicate) {
|
|
313
|
+
return predicate ? '✔️ ' : ' ';
|
|
314
|
+
}
|