@naturalcycles/dev-lib 19.22.0 → 19.24.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.
@@ -39,8 +39,9 @@ const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
39
39
  const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
40
40
 
41
41
  const prettierCmd =
42
- !!prettierConfigPath && `prettier --write --experimental-cli --config-path ${prettierConfigPath}`
43
- const eslintCmd = `eslint --fix`
42
+ !!prettierConfigPath &&
43
+ `prettier --write --experimental-cli --config-path ${prettierConfigPath} --cache-location node_modules/.cache/prettier`
44
+ const eslintCmd = `eslint --fix --cache`
44
45
 
45
46
  const stylelintExists =
46
47
  !!stylelintConfigPath &&
@@ -71,7 +72,8 @@ const linters = {
71
72
  if (!filesList) return []
72
73
  return [
73
74
  biomeCmd,
74
- eslintConfigPathRoot && `${eslintCmd} --config ${eslintConfigPathRoot}`,
75
+ eslintConfigPathRoot &&
76
+ `${eslintCmd} --config ${eslintConfigPathRoot} --cache-location ./node_modules/.cache/eslint_src`,
75
77
  prettierCmd,
76
78
  ]
77
79
  .filter(Boolean)
@@ -144,9 +146,7 @@ const linters = {
144
146
 
145
147
  // /scripts are separate, cause they require separate tsconfig.json
146
148
  if (fs.existsSync(`./scripts`)) {
147
- const eslintConfigPathScripts = ['./scripts/eslint.config.js', './eslint.config.js'].find(p =>
148
- fs.existsSync(p),
149
- )
149
+ const eslintConfigPathScripts = ['./scripts/eslint.config.js'].find(p => fs.existsSync(p))
150
150
  Object.assign(linters, {
151
151
  // biome, eslint, Prettier
152
152
  './scripts/**/*.{ts,tsx,cts,mts,vue,html}': match => {
@@ -155,7 +155,7 @@ if (fs.existsSync(`./scripts`)) {
155
155
  return [
156
156
  biomeCmd,
157
157
  eslintConfigPathScripts &&
158
- `${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`,
159
159
  prettierCmd,
160
160
  ]
161
161
  .filter(Boolean)
@@ -166,9 +166,7 @@ if (fs.existsSync(`./scripts`)) {
166
166
 
167
167
  // /e2e
168
168
  if (fs.existsSync(`./e2e`)) {
169
- const eslintConfigPathE2e = ['./e2e/eslint.config.js', './eslint.config.js'].find(p =>
170
- fs.existsSync(p),
171
- )
169
+ const eslintConfigPathE2e = ['./e2e/eslint.config.js'].find(p => fs.existsSync(p))
172
170
 
173
171
  Object.assign(linters, {
174
172
  // biome, eslint, Prettier
@@ -178,7 +176,7 @@ if (fs.existsSync(`./e2e`)) {
178
176
  return [
179
177
  biomeCmd,
180
178
  eslintConfigPathE2e &&
181
- `${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`,
182
180
  prettierCmd,
183
181
  ]
184
182
  .filter(Boolean)
package/cfg/tsconfig.json CHANGED
@@ -56,6 +56,8 @@
56
56
  // ],
57
57
 
58
58
  // Other
59
+ "incremental": true,
60
+ "tsBuildInfoFile": "${configDir}/node_modules/.cache/src.tsbuildinfo",
59
61
  "pretty": true,
60
62
  "newLine": "lf",
61
63
  "experimentalDecorators": true
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, scriptsDir } from './paths.js';
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(`./src`, eslintConfigPathRoot, undefined, extensions, fix),
94
+ runESLint(`src`, extensions, fix),
101
95
  // /scripts
102
- runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, extensions, fix),
96
+ runESLint(`scripts`, extensions, fix),
103
97
  // /e2e
104
- runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, extensions, fix),
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(`./src`, eslintConfigPathRoot, undefined, extensions, fix);
104
+ await runESLint(`src`, extensions, fix);
111
105
  // /scripts
112
- await runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, extensions, fix);
106
+ await runESLint(`scripts`, extensions, fix);
113
107
  // /e2e
114
- await runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, extensions, fix);
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, eslintConfigPath, tsconfigPath, extensions = eslintExtensions.split(','), fix = true) {
119
- if (!eslintConfigPath || !existsSync(dir))
120
- return; // faster to bail-out like this
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
- ...(tsconfigPath ? [`--parser-options=project:${tsconfigPath}`] : []),
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
- // '--cache-location',
158
- // `${process.cwd()}/node_modules/.cache/prettier`,
162
+ '--cache-location',
163
+ `node_modules/.cache/prettier`,
159
164
  experimentalCli && `--experimental-cli`,
160
165
  experimentalCli ? '--config-path' : `--config`,
161
166
  prettierConfigPath,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "19.22.0",
4
+ "version": "19.24.0",
5
5
  "dependencies": {
6
6
  "@biomejs/biome": "^2",
7
7
  "@commitlint/cli": "^19",
@@ -5,7 +5,9 @@
5
5
  "extends": "../cfg/tsconfig.json",
6
6
  "compilerOptions": {
7
7
  "rootDir": "${configDir}/..",
8
- "outDir": "${configDir}/../dist"
8
+ "outDir": "${configDir}/../dist/scripts",
9
+ "noEmit": true,
10
+ "tsBuildInfoFile": "${configDir}/../node_modules/.cache/scripts.tsbuildinfo"
9
11
  },
10
12
  "exclude": ["**/__exclude"]
11
13
  }