@naturalcycles/dev-lib 19.38.1 → 20.0.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.
Files changed (34) hide show
  1. package/cfg/biome.jsonc +1 -0
  2. package/cfg/eslint.config.js +19 -8
  3. package/cfg/lint-staged.config.js +23 -94
  4. package/cfg/tsconfig.e2e.json +6 -5
  5. package/cfg/tsconfig.json +1 -1
  6. package/cfg/tsconfig.scripts.json +5 -4
  7. package/dist/{bin → src/bin}/dev-lib.js +0 -0
  8. package/dist/{bin → src/bin}/out.js +0 -0
  9. package/dist/{lint.util.js → src/lint.util.js} +10 -32
  10. package/package.json +1 -1
  11. package/scripts/tsconfig.json +0 -8
  12. /package/dist/{bin → src/bin}/dev-lib.d.ts +0 -0
  13. /package/dist/{bin → src/bin}/out.d.ts +0 -0
  14. /package/dist/{build.util.d.ts → src/build.util.d.ts} +0 -0
  15. /package/dist/{build.util.js → src/build.util.js} +0 -0
  16. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  17. /package/dist/{index.js → src/index.js} +0 -0
  18. /package/dist/{init-from-dev-lib.command.d.ts → src/init-from-dev-lib.command.d.ts} +0 -0
  19. /package/dist/{init-from-dev-lib.command.js → src/init-from-dev-lib.command.js} +0 -0
  20. /package/dist/{lint.util.d.ts → src/lint.util.d.ts} +0 -0
  21. /package/dist/{paths.d.ts → src/paths.d.ts} +0 -0
  22. /package/dist/{paths.js → src/paths.js} +0 -0
  23. /package/dist/{test.util.d.ts → src/test.util.d.ts} +0 -0
  24. /package/dist/{test.util.js → src/test.util.js} +0 -0
  25. /package/dist/{testing → src/testing}/index.d.ts +0 -0
  26. /package/dist/{testing → src/testing}/index.js +0 -0
  27. /package/dist/{testing → src/testing}/mockAllKindsOfThings.d.ts +0 -0
  28. /package/dist/{testing → src/testing}/mockAllKindsOfThings.js +0 -0
  29. /package/dist/{testing → src/testing}/testOffline.d.ts +0 -0
  30. /package/dist/{testing → src/testing}/testOffline.js +0 -0
  31. /package/dist/{testing → src/testing}/testing.util.d.ts +0 -0
  32. /package/dist/{testing → src/testing}/testing.util.js +0 -0
  33. /package/dist/{testing → src/testing}/time.d.ts +0 -0
  34. /package/dist/{testing → src/testing}/time.js +0 -0
package/cfg/biome.jsonc CHANGED
@@ -7,6 +7,7 @@
7
7
  "src/**",
8
8
  "scripts/**",
9
9
  "!**/*.html",
10
+ "!**/*.scss",
10
11
  "!**/tsconfig.json",
11
12
  "!**/tsconfig.*.json",
12
13
  "!**/__exclude",
@@ -19,18 +19,23 @@ import eslintVueRules from './eslint-vue-rules.js'
19
19
  import eslintVitestRules from './eslint-vitest-rules.js'
20
20
  import eslintPrettierRules from './eslint-prettier-rules.js'
21
21
  import eslintBiomeRules from './eslint-biome-rules.js'
22
+ import fs from 'node:fs'
22
23
 
23
24
  const defaultFiles = ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts']
25
+ const srcFiles = ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.cts', 'src/**/*.mts']
26
+ const scriptsFiles = ['scripts/**/*.ts', 'scripts/**/*.tsx', 'scripts/**/*.cts', 'scripts/**/*.mts']
27
+ const e2eFiles = ['e2e/**/*.ts', 'e2e/**/*.tsx', 'e2e/**/*.cts', 'e2e/**/*.mts']
24
28
  const testFiles = ['**/*.test.ts', '**/*.test.tsx', '**/*.test.cts', '**/*.test.mts']
25
29
 
26
- const config = getEslintConfigForDir(process.cwd())
30
+ const cwd = process.cwd()
31
+ const config = getEslintConfigForDir()
27
32
  export default config
28
33
 
29
34
  /**
30
35
  * This function only exists, because typescript-eslint started to have an issue with auto-detecting tsconfigRootDir.
31
36
  * If the issue is fixed - we can remove this and come back to having just a single config.
32
37
  */
33
- export function getEslintConfigForDir(dir) {
38
+ function getEslintConfigForDir() {
34
39
  return [
35
40
  {
36
41
  ...eslint.configs.recommended,
@@ -52,7 +57,6 @@ export function getEslintConfigForDir(dir) {
52
57
  files: defaultFiles,
53
58
  },
54
59
  // https://eslint.vuejs.org/user-guide/#user-guide
55
- // ...require('eslint-plugin-vue').configs['flat/recommended'],
56
60
  ...eslintPluginVue.configs['flat/recommended'].map(c => ({
57
61
  ...c,
58
62
  files: defaultFiles,
@@ -73,8 +77,16 @@ export function getEslintConfigForDir(dir) {
73
77
  },
74
78
  },
75
79
  {
76
- files: defaultFiles,
77
- ...getConfig(dir),
80
+ files: srcFiles,
81
+ ...getConfig(`${cwd}/tsconfig.json`),
82
+ },
83
+ {
84
+ files: scriptsFiles,
85
+ ...getConfig(`${cwd}/tsconfig.scripts.json`),
86
+ },
87
+ {
88
+ files: e2eFiles,
89
+ ...getConfig(`${cwd}/tsconfig.e2e.json`),
78
90
  },
79
91
  {
80
92
  ignores: ['**/__exclude/**', '**/*.scss', '**/*.js'],
@@ -82,7 +94,7 @@ export function getEslintConfigForDir(dir) {
82
94
  ].filter(Boolean)
83
95
  }
84
96
 
85
- function getConfig(dir) {
97
+ function getConfig(tsconfigPath) {
86
98
  return {
87
99
  plugins: {
88
100
  '@typescript-eslint': tseslint.plugin,
@@ -100,9 +112,8 @@ function getConfig(dir) {
100
112
  ...globals.vitest,
101
113
  NodeJS: 'readonly',
102
114
  },
103
- // parser: tseslint.parser,
104
115
  parserOptions: {
105
- project: `${dir}/tsconfig.json`,
116
+ project: fs.existsSync(tsconfigPath) ? tsconfigPath : undefined,
106
117
  // tsconfigRootDir: cwd,
107
118
  parser: tseslint.parser,
108
119
  extraFileExtensions: ['.vue', '.html'],
@@ -20,24 +20,13 @@ 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
- import {
24
- prettierDirs,
25
- prettierExtensionsExclusive,
26
- prettierExtensionsAll,
27
- stylelintExtensions,
28
- lintExclude,
29
- minActionlintVersion,
30
- } from './_cnst.js'
23
+ import { prettierExtensionsAll, lintExclude, minActionlintVersion } from './_cnst.js'
31
24
 
32
25
  const prettierConfigPath = [`prettier.config.js`].find(fs.existsSync)
33
26
 
34
27
  const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
35
28
 
36
- // this is to support "Solution style tsconfig.json" (as used in Angular10, for example)
37
- // const tsconfigPathRoot = ['tsconfig.base.json'].find(p => fs.existsSync(p)) || 'tsconfig.json'
38
- // const tsconfigPathRoot = 'tsconfig.json'
39
-
40
- // const eslintConfigPathRoot = ['eslint.config.js'].find(p => fs.existsSync(p))
29
+ const eslintConfigPath = ['eslint.config.js'].find(fs.existsSync)
41
30
 
42
31
  let prettierCmd = undefined
43
32
 
@@ -55,16 +44,22 @@ if (prettierConfigPath) {
55
44
  .join(' ')
56
45
  }
57
46
 
58
- const eslintCmd = [
59
- 'eslint',
60
- '--fix',
61
- '--cache',
62
- // concurrency is disabled here, as it's not expected to help,
63
- // since we're running on a limited set of files already
64
- // ESLINT_CONCURRENCY && `--concurrency=${ESLINT_CONCURRENCY}`,
65
- ]
66
- .filter(Boolean)
67
- .join(' ')
47
+ let eslintCmd = undefined
48
+
49
+ if (eslintConfigPath) {
50
+ eslintCmd = [
51
+ 'eslint',
52
+ '--fix',
53
+ `--config ${eslintConfigPath}`,
54
+ '--cache',
55
+ '--cache-location node_modules/.cache/eslint',
56
+ // concurrency is disabled here, as it's not expected to help,
57
+ // since we're running on a limited set of files already
58
+ // ESLINT_CONCURRENCY && `--concurrency=${ESLINT_CONCURRENCY}`,
59
+ ]
60
+ .filter(Boolean)
61
+ .join(' ')
62
+ }
68
63
 
69
64
  const stylelintExists =
70
65
  !!stylelintConfigPath &&
@@ -72,42 +67,13 @@ const stylelintExists =
72
67
  fs.existsSync('node_modules/stylelint-config-standard-scss')
73
68
  const stylelintCmd = stylelintExists ? `stylelint --fix --config ${stylelintConfigPath}` : undefined
74
69
 
75
- // const biomeInstalled = fs.existsSync('node_modules/@biomejs/biome')
76
70
  const biomeConfigPath = ['biome.jsonc'].find(p => fs.existsSync(p))
77
71
  const biomeCmd = biomeConfigPath && `biome lint --write --unsafe --no-errors-on-unmatched`
78
72
 
79
- // if (!eslintConfigPathRoot) {
80
- // console.log('eslint is skipped, because ./eslint.config.js is not present')
81
- // }
82
- // if (!prettierCmd) {
83
- // console.log('prettier is skipped, because ./prettier.config.js is not present')
84
- // }
85
- // if (!stylelintCmd) {
86
- // console.log(
87
- // 'stylelint is skipped, because ./stylelint.config.js is not present, or stylelint and/or stylelint-config-standard-scss are not installed',
88
- // )
89
- // }
90
-
91
73
  const linters = {
92
- // biome, eslint, prettier
93
- './src/**/*.{ts,tsx,cts,mts,vue,html}': match => runBiomeEslintPrettier(match, 'src'),
94
-
95
- // For all other files we run only Prettier (because e.g eslint screws *.scss files)
96
- // todo: this should be no longer needed when flat eslint config is default and it has global ignore of scss files
97
- [`./{${prettierDirs}}/**/*.{${prettierExtensionsExclusive}}`]: runPrettier,
98
-
99
- // Files for ESLint + Prettier
100
- // doesn't work, cause typescript parser+rules are conflicting
101
- // [`./{${prettierDirs}}/**/*.{js,jsx}`]: match => {
102
- // const filesList = micromatch.not(match, lintExclude).join(' ')
103
- // if (!filesList) return []
104
- // return [
105
- // `${eslintCmd} --config ${eslintConfigPathRoot} --parser=espree`,
106
- // prettierCmd].map(s => `${s} ${filesList}`)
107
- // },
108
-
109
- // Files for Biome + Stylelint + Prettier
110
- [`./{${prettierDirs}}/**/*.{${stylelintExtensions}}`]: runBiomeStylelintPrettier,
74
+ // biome, eslint, stylelint, prettier
75
+ [`./{src,scripts,e2e}/**/*.{${prettierExtensionsAll}}`]: match =>
76
+ runBiomeEslintStylelintPrettier(match),
111
77
 
112
78
  // Files in root dir: prettier
113
79
  [`./*.{${prettierExtensionsAll}}`]: runPrettier,
@@ -118,41 +84,11 @@ const linters = {
118
84
  './.github/**/*.{yml,yaml}': runActionlint,
119
85
  }
120
86
 
121
- // /scripts are separate, cause they require separate tsconfig.json
122
- if (fs.existsSync(`./scripts`)) {
123
- Object.assign(linters, {
124
- './scripts/**/*.{ts,tsx,cts,mts,vue,html}': match => runBiomeEslintPrettier(match, 'scripts'),
125
- })
126
- }
127
-
128
- // /e2e
129
- if (fs.existsSync(`./e2e`)) {
130
- Object.assign(linters, {
131
- './e2e/**/*.{ts,tsx,cts,mts}': match => runBiomeEslintPrettier(match, 'e2e'),
132
- })
133
- }
134
-
135
- export function runBiomeEslintPrettier(match, dir) {
87
+ export function runBiomeEslintStylelintPrettier(match) {
136
88
  const filesList = getFilesList(match)
137
89
  if (!filesList) return []
138
90
 
139
- let configDir = dir
140
- if (dir === 'src') {
141
- configDir = '.'
142
- }
143
-
144
- const cwd = process.cwd()
145
- const eslintConfigPath = `${configDir}/eslint.config.js`
146
- const tsconfigPath = [cwd, configDir !== '.' && configDir, 'tsconfig.json']
147
- .filter(Boolean)
148
- .join('/')
149
-
150
- return [
151
- biomeCmd,
152
- eslintConfigPath &&
153
- `${eslintCmd} --config ${eslintConfigPath} --parser-options=project:${tsconfigPath} --cache-location node_modules/.cache/eslint_${dir}`,
154
- prettierCmd,
155
- ]
91
+ return [biomeCmd, eslintCmd, stylelintCmd, prettierCmd]
156
92
  .filter(Boolean)
157
93
  .map(s => `${s} ${filesList}`)
158
94
  }
@@ -163,13 +99,6 @@ export function runPrettier(match) {
163
99
  return [prettierCmd].map(s => `${s} ${filesList}`)
164
100
  }
165
101
 
166
- export function runBiomeStylelintPrettier(match) {
167
- const filesList = getFilesList(match)
168
- if (!filesList) return []
169
- // Biome's css/scss support is still in nursery, so Biome is disabled for now
170
- return [stylelintCmd, prettierCmd].filter(Boolean).map(s => `${s} ${filesList}`)
171
- }
172
-
173
102
  export function runKtlint(match) {
174
103
  const filesList = getFilesList(match)
175
104
  if (!filesList) return []
@@ -4,13 +4,13 @@
4
4
  {
5
5
  "extends": "./tsconfig.json",
6
6
  "compilerOptions": {
7
- "rootDir": "${configDir}/..",
7
+ "rootDir": "${configDir}",
8
8
  "baseUrl": "${configDir}",
9
- "outDir": "${configDir}/../dist/e2e",
9
+ "outDir": "${configDir}/dist/e2e",
10
10
  "paths": {
11
- "@src/*": ["${configDir}/../src/*"]
11
+ "@src/*": ["${configDir}/src/*"]
12
12
  },
13
- "tsBuildInfoFile": "${configDir}/../node_modules/.cache/e2e.tsbuildinfo",
13
+ "tsBuildInfoFile": "${configDir}/node_modules/.cache/e2e.tsbuildinfo",
14
14
  "module": "esnext",
15
15
  "moduleResolution": "bundler",
16
16
  "lib": ["esnext", "dom", "dom.iterable"]
@@ -18,8 +18,9 @@
18
18
  // it's needed, because playwright doesn't support ${configDir} properly
19
19
  // "baseUrl": ".",
20
20
  // "paths": {
21
- // "@src/*": ["../src/*"],
21
+ // "@src/*": ["./src/*"],
22
22
  // },
23
23
  },
24
+ // "include": ["e2e"],
24
25
  "exclude": ["**/__exclude"]
25
26
  }
package/cfg/tsconfig.json CHANGED
@@ -5,7 +5,7 @@
5
5
  //
6
6
  {
7
7
  "compilerOptions": {
8
- "rootDir": "${configDir}/src",
8
+ "rootDir": "${configDir}",
9
9
  "baseUrl": "${configDir}/src",
10
10
  "outDir": "${configDir}/dist",
11
11
  // Target/module
@@ -4,13 +4,14 @@
4
4
  {
5
5
  "extends": "./tsconfig.json",
6
6
  "compilerOptions": {
7
- "rootDir": "${configDir}/..",
7
+ "rootDir": "${configDir}",
8
8
  "baseUrl": "${configDir}",
9
- "outDir": "${configDir}/../dist/scripts",
9
+ "outDir": "${configDir}/dist/scripts",
10
10
  "paths": {
11
- "@src/*": ["${configDir}/../src/*"]
11
+ "@src/*": ["${configDir}/src/*"]
12
12
  },
13
- "tsBuildInfoFile": "${configDir}/../node_modules/.cache/scripts.tsbuildinfo"
13
+ "tsBuildInfoFile": "${configDir}/node_modules/.cache/scripts.tsbuildinfo"
14
14
  },
15
+ // "include": ["scripts"],
15
16
  "exclude": ["**/__exclude"]
16
17
  }
File without changes
File without changes
@@ -95,49 +95,28 @@ export async function eslintAll(opt) {
95
95
  ...opt,
96
96
  };
97
97
  const extensions = ext.split(',');
98
- // The only time we don't parallelize is when run locally with no-fix,
99
- // so errors can be seen properly
100
- const runInParallel = fix || !!CI;
101
- if (runInParallel) {
102
- await Promise.all([
103
- runESLint(`src`, extensions, fix),
104
- runESLint(`scripts`, extensions, fix),
105
- runESLint(`e2e`, extensions, fix),
106
- ]);
107
- }
108
- else {
109
- await runESLint(`src`, extensions, fix);
110
- await runESLint(`scripts`, extensions, fix);
111
- await runESLint(`e2e`, extensions, fix);
112
- }
98
+ await runESLint(extensions, fix);
113
99
  console.log(`${check(true)}${white(`eslint-all`)} ${dimGrey(`took ` + _since(started))}`);
114
100
  }
115
- async function runESLint(dir, extensions = eslintExtensions.split(','), fix = true) {
116
- let configDir = dir;
117
- if (dir === 'src') {
118
- configDir = '.';
119
- }
120
- const cwd = process.cwd();
121
- const eslintConfigPath = `${configDir}/eslint.config.js`;
122
- const tsconfigPath = [cwd, configDir !== '.' && configDir, 'tsconfig.json']
123
- .filter(Boolean)
124
- .join('/');
125
- if (!existsSync(dir) || !existsSync(eslintConfigPath) || !existsSync(tsconfigPath)) {
101
+ async function runESLint(extensions = eslintExtensions.split(','), fix = true) {
102
+ const eslintConfigPath = `eslint.config.js`;
103
+ const tsconfigPath = 'tsconfig.json';
104
+ if (!existsSync(eslintConfigPath) || !existsSync(tsconfigPath)) {
126
105
  // faster to bail-out like this
127
106
  return;
128
107
  }
129
108
  // const tsconfigRootDir = [cwd, configDir !== '.' && configDir].filter(Boolean).join('/')
130
109
  const eslintPath = findPackageBinPath('eslint', 'eslint');
131
- const cacheLocation = `node_modules/.cache/eslint_${dir}`;
110
+ const cacheLocation = `node_modules/.cache/eslint`;
132
111
  const cacheFound = existsSync(cacheLocation);
133
- console.log(dimGrey(`${check(cacheFound)}eslint ${dir} cache found: ${cacheFound}`));
112
+ console.log(dimGrey(`${check(cacheFound)}eslint cache found: ${cacheFound}`));
134
113
  await exec2.spawnAsync(eslintPath, {
135
- name: ['eslint', dir, !fix && '--no-fix'].filter(Boolean).join(' '),
114
+ name: ['eslint', !fix && '--no-fix'].filter(Boolean).join(' '),
136
115
  args: [
137
116
  `--config`,
138
117
  eslintConfigPath,
139
- `${dir}/**/*.{${extensions.join(',')}}`,
140
- `--parser-options=project:${tsconfigPath}`,
118
+ `{src,scripts,e2e}/**/*.{${extensions.join(',')}}`,
119
+ // `--parser-options=project:${tsconfigPath}`,
141
120
  // The next line fixes the `typescript-eslint` 8.37 bug of resolving tsconfig.json
142
121
  // `--parser-options=tsconfigRootDir:${tsconfigRootDir}`,
143
122
  ESLINT_CONCURRENCY && `--concurrency=${ESLINT_CONCURRENCY}`,
@@ -145,7 +124,6 @@ async function runESLint(dir, extensions = eslintExtensions.split(','), fix = tr
145
124
  '--cache-location',
146
125
  cacheLocation,
147
126
  `--no-error-on-unmatched-pattern`,
148
- `--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
149
127
  fix ? `--fix` : '--no-fix',
150
128
  ].filter(_isTruthy),
151
129
  shell: false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "19.38.1",
4
+ "version": "20.0.0",
5
5
  "dependencies": {
6
6
  "@biomejs/biome": "^2",
7
7
  "@commitlint/cli": "^19",
@@ -1,8 +0,0 @@
1
- //
2
- // tsconfig.json for /scripts
3
- //
4
- {
5
- "extends": "../cfg/tsconfig.scripts.json",
6
- "compilerOptions": {},
7
- "exclude": ["**/__exclude"]
8
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes