@naturalcycles/dev-lib 19.31.0 → 19.32.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.
@@ -19,7 +19,7 @@ import { execSync } from 'node:child_process'
19
19
  import { _assert } from '@naturalcycles/js-lib/error/assert.js'
20
20
  import { semver2 } from '@naturalcycles/js-lib/semver'
21
21
  import { exec2 } from '@naturalcycles/nodejs-lib/exec2'
22
-
22
+ import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
23
23
  import {
24
24
  prettierDirs,
25
25
  prettierExtensionsExclusive,
@@ -39,9 +39,22 @@ const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
39
39
 
40
40
  // const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
41
41
 
42
- const prettierCmd =
43
- !!prettierConfigPath &&
44
- `prettier --write --experimental-cli --config-path ${prettierConfigPath} --cache-location node_modules/.cache/prettier`
42
+ let prettierCmd = undefined
43
+
44
+ if (prettierConfigPath) {
45
+ const experimental = !hasPrettierOverrides()
46
+ prettierCmd = [
47
+ 'prettier --write --log-level=warn',
48
+ experimental && '--cache-location',
49
+ experimental && 'node_modules/.cache/prettier',
50
+ experimental && `--experimental-cli`,
51
+ experimental ? '--config-path' : `--config`,
52
+ prettierConfigPath,
53
+ ]
54
+ .filter(Boolean)
55
+ .join(' ')
56
+ }
57
+
45
58
  const eslintCmd = [
46
59
  'eslint',
47
60
  '--fix',
@@ -128,13 +141,16 @@ export function runBiomeEslintPrettier(match, dir) {
128
141
  configDir = '.'
129
142
  }
130
143
 
144
+ const cwd = process.cwd()
131
145
  const eslintConfigPath = `${configDir}/eslint.config.js`
132
- const tsconfigPath = `${configDir}/tsconfig.json`
146
+ const tsconfigPath = [cwd, configDir !== '.' && configDir, 'tsconfig.json']
147
+ .filter(Boolean)
148
+ .join('/')
133
149
 
134
150
  return [
135
151
  biomeCmd,
136
152
  eslintConfigPath &&
137
- `${eslintCmd} --config ${eslintConfigPath} --parser-options=tsconfigRootDir:. --parser-options=project:${tsconfigPath} --cache-location node_modules/.cache/eslint_${dir}`,
153
+ `${eslintCmd} --config ${eslintConfigPath} --parser-options=project:${tsconfigPath} --cache-location node_modules/.cache/eslint_${dir}`,
138
154
  prettierCmd,
139
155
  ]
140
156
  .filter(Boolean)
@@ -219,4 +235,12 @@ function getActionLintVersion() {
219
235
  }
220
236
  }
221
237
 
238
+ function hasPrettierOverrides() {
239
+ try {
240
+ return fs2.readText('prettier.config.js').includes('overrides')
241
+ } catch {
242
+ return false
243
+ }
244
+ }
245
+
222
246
  export default linters
@@ -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(dimGrey(`${check(cacheFound)} tsc ${dir} cache found: ${cacheFound}`));
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,
@@ -74,5 +74,5 @@ export function buildCopy() {
74
74
  });
75
75
  }
76
76
  function check(predicate) {
77
- return predicate ? '✔️ ' : ' ';
77
+ return predicate ? ' ' : ' ';
78
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 } from '@naturalcycles/nodejs-lib/colors';
11
+ import { dimGrey, white } 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(`${check(true)} lint-all`)} ${dimGrey(`took ` + _since(started))}`);
57
+ console.log(`${check(true)}${white(`lint-all`)} ${dimGrey(`took ` + _since(started))}`);
58
58
  // if (needToTrackChanges) {
59
59
  // const gitStatusAfter = gitStatus()
60
60
  // const hasChanges = gitStatusAfter !== gitStatusAtStart
@@ -110,23 +110,27 @@ 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(`${check(true)} eslint-all`)} ${dimGrey(`took ` + _since(started))}`);
113
+ console.log(`${check(true)}${white(`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 = `${configDir}/tsconfig.json`;
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(dimGrey(`${check(cacheFound)} eslint ${dir} cache found: ${cacheFound}`));
133
+ console.log(dimGrey(`${check(cacheFound)}eslint ${dir} cache found: ${cacheFound}`));
130
134
  await exec2.spawnAsync(eslintPath, {
131
135
  name: ['eslint', dir, !fix && '--no-fix'].filter(Boolean).join(' '),
132
136
  args: [
@@ -135,7 +139,7 @@ async function runESLint(dir, extensions = eslintExtensions.split(','), fix = tr
135
139
  `${dir}/**/*.{${extensions.join(',')}}`,
136
140
  `--parser-options=project:${tsconfigPath}`,
137
141
  // The next line fixes the `typescript-eslint` 8.37 bug of resolving tsconfig.json
138
- `--parser-options=tsconfigRootDir:.`,
142
+ // `--parser-options=tsconfigRootDir:${tsconfigRootDir}`,
139
143
  ESLINT_CONCURRENCY && `--concurrency=${ESLINT_CONCURRENCY}`,
140
144
  '--cache',
141
145
  '--cache-location',
@@ -160,22 +164,27 @@ const prettierPaths = [
160
164
  ...lintExclude.map((s) => `!${s}`),
161
165
  ];
162
166
  export function runPrettier(opt = {}) {
163
- const { experimentalCli = true, fix = true } = opt;
167
+ let { experimentalCli = true, fix = true } = opt;
164
168
  const prettierConfigPath = [`./prettier.config.js`].find(f => existsSync(f));
165
169
  if (!prettierConfigPath)
166
170
  return;
167
171
  const prettierPath = findPackageBinPath('prettier', 'prettier');
168
172
  const cacheLocation = 'node_modules/.cache/prettier';
169
173
  const cacheFound = existsSync(cacheLocation);
170
- console.log(dimGrey(`${check(cacheFound)} prettier cache found: ${cacheFound}`));
174
+ console.log(dimGrey(`${check(cacheFound)}prettier cache found: ${cacheFound}`));
175
+ if (hasPrettierOverrides()) {
176
+ experimentalCli = false;
177
+ console.log(' prettier experimental mode disabled due to "overrides" in prettier.config.js');
178
+ }
171
179
  // prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
172
180
  exec2.spawn(prettierPath, {
173
181
  name: fix ? 'prettier' : 'prettier --check',
174
182
  args: [
175
183
  fix ? `--write` : '--check',
176
184
  `--log-level=warn`,
177
- '--cache-location',
178
- cacheLocation,
185
+ // non-experimental-cli has different cache format, hence disabling it
186
+ experimentalCli && '--cache-location',
187
+ experimentalCli && cacheLocation,
179
188
  experimentalCli && `--experimental-cli`,
180
189
  experimentalCli ? '--config-path' : `--config`,
181
190
  prettierConfigPath,
@@ -305,6 +314,14 @@ export function findPackageBinPath(pkg, cmd) {
305
314
  const { bin } = fs2.readJson(packageJsonPath);
306
315
  return path.join(path.dirname(packageJsonPath), typeof bin === 'string' ? bin : bin[cmd]);
307
316
  }
317
+ function hasPrettierOverrides() {
318
+ try {
319
+ return fs2.readText('prettier.config.js').includes('overrides');
320
+ }
321
+ catch {
322
+ return false;
323
+ }
324
+ }
308
325
  function check(predicate) {
309
- return predicate ? '✔️ ' : ' ';
326
+ return predicate ? ' ' : ' ';
310
327
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "19.31.0",
4
+ "version": "19.32.0",
5
5
  "dependencies": {
6
6
  "@biomejs/biome": "^2",
7
7
  "@commitlint/cli": "^19",