@naturalcycles/dev-lib 20.26.0 → 20.27.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/_cnst.js +1 -1
- package/cfg/biome.jsonc +18 -25
- package/cfg/eslint-rules.js +14 -14
- package/cfg/eslint.config.js +6 -8
- package/cfg/lint-staged.config.js +20 -39
- package/cfg/vitest.config.js +2 -2
- package/cfg/vitestAlphabeticSequencer.js +1 -1
- package/dist/bin/dev-lib.js +4 -4
- package/dist/check.util.d.ts +6 -9
- package/dist/check.util.js +29 -64
- package/package.json +2 -5
- package/cfg/init/.prettierignore +0 -4
- package/cfg/init/prettier.config.js +0 -3
- package/cfg/prettier.config.js +0 -30
package/cfg/_cnst.js
CHANGED
|
@@ -7,7 +7,7 @@ const prettierExtensionsAll =
|
|
|
7
7
|
const eslintExtensions = 'ts,tsx,cts,mts,html'
|
|
8
8
|
const stylelintExtensions = 'css,scss'
|
|
9
9
|
const lintExclude = ['./**/__exclude/**', './**/dist/**', './**/cache/**', './CHANGELOG.md']
|
|
10
|
-
const minActionlintVersion = '1.7.
|
|
10
|
+
const minActionlintVersion = '1.7.10'
|
|
11
11
|
|
|
12
12
|
export {
|
|
13
13
|
prettierDirs,
|
package/cfg/biome.jsonc
CHANGED
|
@@ -2,14 +2,7 @@
|
|
|
2
2
|
"$schema": "https://biomejs.dev/schemas/2.3.10/schema.json",
|
|
3
3
|
"root": false,
|
|
4
4
|
"files": {
|
|
5
|
-
"includes": [
|
|
6
|
-
"**/*.ts",
|
|
7
|
-
"**/*.tsx",
|
|
8
|
-
"**/*.js",
|
|
9
|
-
"**/*.jsx",
|
|
10
|
-
"!**/__exclude",
|
|
11
|
-
"!**/try.ts"
|
|
12
|
-
]
|
|
5
|
+
"includes": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "!**/__exclude", "!**/try.ts"],
|
|
13
6
|
},
|
|
14
7
|
"formatter": {
|
|
15
8
|
"enabled": true,
|
|
@@ -18,7 +11,7 @@
|
|
|
18
11
|
"indentWidth": 2,
|
|
19
12
|
"lineEnding": "lf",
|
|
20
13
|
"lineWidth": 100,
|
|
21
|
-
"attributePosition": "auto"
|
|
14
|
+
"attributePosition": "auto",
|
|
22
15
|
},
|
|
23
16
|
"assist": { "actions": { "source": { "organizeImports": "off" } } },
|
|
24
17
|
"linter": {
|
|
@@ -28,7 +21,7 @@
|
|
|
28
21
|
"performance": {
|
|
29
22
|
"noAccumulatingSpread": "off", // oxlint
|
|
30
23
|
// "useTopLevelRegex": "error" // consider
|
|
31
|
-
"noDelete": "off" // oxlint
|
|
24
|
+
"noDelete": "off", // oxlint
|
|
32
25
|
},
|
|
33
26
|
"correctness": {
|
|
34
27
|
"useImportExtensions": "off", // oxlint
|
|
@@ -41,8 +34,8 @@
|
|
|
41
34
|
"noUnusedVariables": {
|
|
42
35
|
"fix": "none",
|
|
43
36
|
"level": "off", // oxlint
|
|
44
|
-
"options": {}
|
|
45
|
-
}
|
|
37
|
+
"options": {},
|
|
38
|
+
},
|
|
46
39
|
},
|
|
47
40
|
"style": {
|
|
48
41
|
// "useDefaultSwitchClause": "error", // consider`
|
|
@@ -68,7 +61,7 @@
|
|
|
68
61
|
"useSingleVarDeclarator": "error",
|
|
69
62
|
"noInferrableTypes": "error",
|
|
70
63
|
"noUselessElse": "error",
|
|
71
|
-
"useArrayLiterals": "error"
|
|
64
|
+
"useArrayLiterals": "error",
|
|
72
65
|
// "noCommonJs": "error" // oxlint
|
|
73
66
|
},
|
|
74
67
|
"suspicious": {
|
|
@@ -86,7 +79,7 @@
|
|
|
86
79
|
"noImportAssign": "off",
|
|
87
80
|
"noDoubleEquals": "off", // oxlint
|
|
88
81
|
"noDocumentCookie": "off", // ox
|
|
89
|
-
"noEmptyInterface": "off"
|
|
82
|
+
"noEmptyInterface": "off",
|
|
90
83
|
},
|
|
91
84
|
"complexity": {
|
|
92
85
|
"useDateNow": "error",
|
|
@@ -99,10 +92,10 @@
|
|
|
99
92
|
"useLiteralKeys": "off",
|
|
100
93
|
"noBannedTypes": "off",
|
|
101
94
|
"noCommaOperator": "off", // ox
|
|
102
|
-
"noArguments": "error"
|
|
95
|
+
"noArguments": "error",
|
|
103
96
|
},
|
|
104
|
-
"nursery": {}
|
|
105
|
-
}
|
|
97
|
+
"nursery": {},
|
|
98
|
+
},
|
|
106
99
|
},
|
|
107
100
|
"javascript": {
|
|
108
101
|
"formatter": {
|
|
@@ -114,8 +107,8 @@
|
|
|
114
107
|
"bracketSpacing": true,
|
|
115
108
|
"bracketSameLine": false,
|
|
116
109
|
"quoteStyle": "single",
|
|
117
|
-
"attributePosition": "auto"
|
|
118
|
-
}
|
|
110
|
+
"attributePosition": "auto",
|
|
111
|
+
},
|
|
119
112
|
},
|
|
120
113
|
"overrides": [
|
|
121
114
|
{
|
|
@@ -125,10 +118,10 @@
|
|
|
125
118
|
"correctness": {
|
|
126
119
|
// doesn't work well with *.vue files
|
|
127
120
|
"noUnusedImports": "off",
|
|
128
|
-
"noUnusedVariables": "off"
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
]
|
|
121
|
+
"noUnusedVariables": "off",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
],
|
|
134
127
|
}
|
package/cfg/eslint-rules.js
CHANGED
|
@@ -168,21 +168,21 @@ export default {
|
|
|
168
168
|
'undefined',
|
|
169
169
|
],
|
|
170
170
|
'id-match': 2,
|
|
171
|
-
'simple-import-sort/imports': [
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
],
|
|
178
|
-
'simple-import-sort/exports': 2,
|
|
171
|
+
// 'simple-import-sort/imports': [
|
|
172
|
+
// 2,
|
|
173
|
+
// {
|
|
174
|
+
// // This is what "removes any newlines between imports":
|
|
175
|
+
// groups: [[String.raw`^\u0000`, '^node:', String.raw`^@?\w`, '^', String.raw`^\.`]],
|
|
176
|
+
// },
|
|
177
|
+
// ],
|
|
178
|
+
// 'simple-import-sort/exports': 2,
|
|
179
179
|
// 'import-x/order': 0, // disabled in favor of `simple-import-sort`
|
|
180
180
|
// 'import-x/namespace': 0, // issues with e.g globby
|
|
181
181
|
// 'import-x/no-unresolved': 0, // breaks for type-aliases, e.g '@/store'
|
|
182
|
-
'import-x/no-anonymous-default-export': 0, // oxlint
|
|
183
|
-
'import-x/no-duplicates': [0, { 'prefer-inline': false }], // oxlint
|
|
184
|
-
'import-x/export': 2, // todo: oxlint when it matures
|
|
185
|
-
'import-x/no-empty-named-blocks': 0, // oxlint
|
|
182
|
+
// 'import-x/no-anonymous-default-export': 0, // oxlint
|
|
183
|
+
// 'import-x/no-duplicates': [0, { 'prefer-inline': false }], // oxlint
|
|
184
|
+
// 'import-x/export': 2, // todo: oxlint when it matures
|
|
185
|
+
// 'import-x/no-empty-named-blocks': 0, // oxlint
|
|
186
186
|
// Disabling no-cycle as the slowest rule. Oxlint is to be adopted instead
|
|
187
187
|
// 'import-x/no-cycle': [
|
|
188
188
|
// 2,
|
|
@@ -192,8 +192,8 @@ export default {
|
|
|
192
192
|
// maxDepth: 10,
|
|
193
193
|
// },
|
|
194
194
|
// ],
|
|
195
|
-
'import-x/no-useless-path-segments': 2,
|
|
196
|
-
'import-x/no-default-export': 0, // biome, oxlint
|
|
195
|
+
// 'import-x/no-useless-path-segments': 2,
|
|
196
|
+
// 'import-x/no-default-export': 0, // biome, oxlint
|
|
197
197
|
// 'import-x/no-commonjs': 2, // biome `noCommonJs`
|
|
198
198
|
// 'import-x/extensions': [2, 'always'], // biome useImportExtensions
|
|
199
199
|
'no-array-constructor': 0,
|
package/cfg/eslint.config.js
CHANGED
|
@@ -4,15 +4,13 @@
|
|
|
4
4
|
* Shared eslint FLAT config.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import globals from 'globals'
|
|
8
7
|
import eslint from '@eslint/js'
|
|
9
|
-
import tseslint from 'typescript-eslint'
|
|
10
8
|
import eslintPluginOxlint from 'eslint-plugin-oxlint'
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import eslintRules from './eslint-rules.js'
|
|
14
|
-
import eslintPrettierRules from './eslint-prettier-rules.js'
|
|
9
|
+
import globals from 'globals'
|
|
10
|
+
import tseslint from 'typescript-eslint'
|
|
15
11
|
import eslintBiomeRules from './eslint-biome-rules.js'
|
|
12
|
+
import eslintPrettierRules from './eslint-prettier-rules.js'
|
|
13
|
+
import eslintRules from './eslint-rules.js'
|
|
16
14
|
|
|
17
15
|
const defaultFiles = ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts']
|
|
18
16
|
const srcFiles = ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.cts', 'src/**/*.mts']
|
|
@@ -95,9 +93,9 @@ function getConfig(_tsconfigPath) {
|
|
|
95
93
|
return {
|
|
96
94
|
plugins: {
|
|
97
95
|
'@typescript-eslint': tseslint.plugin,
|
|
98
|
-
'import-x': eslintPluginImportX,
|
|
96
|
+
// 'import-x': eslintPluginImportX,
|
|
99
97
|
// 'unused-imports': require('eslint-plugin-unused-imports'), // disabled in favor of biome rules
|
|
100
|
-
'simple-import-sort': eslintPluginSimpleImportSort,
|
|
98
|
+
// 'simple-import-sort': eslintPluginSimpleImportSort,
|
|
101
99
|
// jsdoc: eslintPluginJsdoc, // oxlint
|
|
102
100
|
// '@stylistic': eslintPluginStylistic, // oxlint custom plugin
|
|
103
101
|
},
|
|
@@ -12,16 +12,15 @@ const {
|
|
|
12
12
|
|
|
13
13
|
console.log(`lint-staged.config.js runs on node ${node} ${platform} ${arch}`)
|
|
14
14
|
|
|
15
|
-
import fs from 'node:fs'
|
|
16
|
-
import micromatch from 'micromatch'
|
|
17
15
|
import { execSync } from 'node:child_process'
|
|
16
|
+
import fs from 'node:fs'
|
|
18
17
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
19
18
|
import { semver2 } from '@naturalcycles/js-lib/semver'
|
|
20
19
|
import { exec2 } from '@naturalcycles/nodejs-lib/exec2'
|
|
21
|
-
import
|
|
20
|
+
import micromatch from 'micromatch'
|
|
22
21
|
import { prettierExtensionsAll, lintExclude, minActionlintVersion } from './_cnst.js'
|
|
23
22
|
|
|
24
|
-
const
|
|
23
|
+
const oxfmtConfigPath = ['.oxfmtrc.jsonc', '.oxfmtrc.json'].find(fs.existsSync)
|
|
25
24
|
|
|
26
25
|
const stylelintConfigPath = [`stylelint.config.js`].find(fs.existsSync)
|
|
27
26
|
|
|
@@ -29,20 +28,10 @@ const eslintConfigPath = ['eslint.config.js'].find(fs.existsSync)
|
|
|
29
28
|
|
|
30
29
|
const oxlintConfigPath = ['.oxlintrc.json'].find(fs.existsSync)
|
|
31
30
|
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
prettierCmd = [
|
|
37
|
-
'prettier --write --log-level=warn',
|
|
38
|
-
experimental && '--cache-location',
|
|
39
|
-
experimental && 'node_modules/.cache/prettier',
|
|
40
|
-
experimental && `--experimental-cli`,
|
|
41
|
-
experimental ? '--config-path' : `--config`,
|
|
42
|
-
prettierConfigPath,
|
|
43
|
-
]
|
|
44
|
-
.filter(Boolean)
|
|
45
|
-
.join(' ')
|
|
31
|
+
let oxfmtCmd = undefined
|
|
32
|
+
|
|
33
|
+
if (oxfmtConfigPath) {
|
|
34
|
+
oxfmtCmd = 'oxfmt'
|
|
46
35
|
}
|
|
47
36
|
|
|
48
37
|
let eslintCmd = undefined
|
|
@@ -89,12 +78,12 @@ const biomeConfigPath = ['biome.jsonc'].find(p => fs.existsSync(p))
|
|
|
89
78
|
const biomeCmd = biomeConfigPath && `biome lint --write --unsafe --no-errors-on-unmatched`
|
|
90
79
|
|
|
91
80
|
const linters = {
|
|
92
|
-
// biome, oxlint, eslint, stylelint,
|
|
81
|
+
// biome, oxlint, eslint, stylelint, oxfmt
|
|
93
82
|
[`./{src,scripts,e2e}/**/*.{${prettierExtensionsAll}}`]: match =>
|
|
94
|
-
|
|
83
|
+
runBiomeEslintStylelintOxfmt(match),
|
|
95
84
|
|
|
96
|
-
// Files in root dir:
|
|
97
|
-
[`./*.{${prettierExtensionsAll}}`]:
|
|
85
|
+
// Files in root dir: oxfmt
|
|
86
|
+
[`./*.{${prettierExtensionsAll}}`]: runOxfmt,
|
|
98
87
|
|
|
99
88
|
// ktlint
|
|
100
89
|
'**/*.{kt,kts}': runKtlint,
|
|
@@ -102,31 +91,31 @@ const linters = {
|
|
|
102
91
|
'./.github/**/*.{yml,yaml}': runActionlint,
|
|
103
92
|
}
|
|
104
93
|
|
|
105
|
-
export function
|
|
94
|
+
export function runBiomeEslintStylelintOxfmt(match) {
|
|
106
95
|
const filesList = getFilesList(match)
|
|
107
96
|
if (!filesList) return []
|
|
108
97
|
|
|
109
|
-
return [biomeCmd, oxlintCmd, eslintCmd, stylelintCmd,
|
|
98
|
+
return [biomeCmd, oxlintCmd, eslintCmd, stylelintCmd, oxfmtCmd]
|
|
110
99
|
.filter(Boolean)
|
|
111
100
|
.map(s => `${s} ${filesList}`)
|
|
112
101
|
}
|
|
113
102
|
|
|
114
|
-
export function
|
|
103
|
+
export function runBiomeOxlintOxfmt(match) {
|
|
115
104
|
const filesList = getFilesList(match)
|
|
116
105
|
if (!filesList) return []
|
|
117
|
-
return [biomeCmd, oxlintCmd,
|
|
106
|
+
return [biomeCmd, oxlintCmd, oxfmtCmd].filter(Boolean).map(s => `${s} ${filesList}`)
|
|
118
107
|
}
|
|
119
108
|
|
|
120
|
-
export function
|
|
109
|
+
export function runOxlintOxfmt(match) {
|
|
121
110
|
const filesList = getFilesList(match)
|
|
122
111
|
if (!filesList) return []
|
|
123
|
-
return [oxlintCmd,
|
|
112
|
+
return [oxlintCmd, oxfmtCmd].filter(Boolean).map(s => `${s} ${filesList}`)
|
|
124
113
|
}
|
|
125
114
|
|
|
126
|
-
export function
|
|
115
|
+
export function runOxfmt(match) {
|
|
127
116
|
const filesList = getFilesList(match)
|
|
128
|
-
if (!filesList || !
|
|
129
|
-
return [
|
|
117
|
+
if (!filesList || !oxfmtCmd) return []
|
|
118
|
+
return [oxfmtCmd].map(s => `${s} ${filesList}`)
|
|
130
119
|
}
|
|
131
120
|
|
|
132
121
|
export function runKtlint(match) {
|
|
@@ -194,12 +183,4 @@ function getActionLintVersion() {
|
|
|
194
183
|
}
|
|
195
184
|
}
|
|
196
185
|
|
|
197
|
-
function hasPrettierOverrides() {
|
|
198
|
-
try {
|
|
199
|
-
return fs2.readText('prettier.config.js').includes('overrides')
|
|
200
|
-
} catch {
|
|
201
|
-
return false
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
186
|
export default linters
|
package/cfg/vitest.config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
|
-
import { VitestAlphabeticSequencer } from './vitestAlphabeticSequencer.js'
|
|
3
2
|
import { defineConfig } from 'vitest/config'
|
|
4
|
-
import { SummaryReporter } from './summaryReporter.js'
|
|
5
3
|
import { SummaryOnlyReporter } from './summaryOnlyReporter.js'
|
|
4
|
+
import { SummaryReporter } from './summaryReporter.js'
|
|
5
|
+
import { VitestAlphabeticSequencer } from './vitestAlphabeticSequencer.js'
|
|
6
6
|
export { SummaryReporter } from './summaryReporter.js'
|
|
7
7
|
export { CollectReporter } from './collectReporter.js'
|
|
8
8
|
export { SummaryOnlyReporter } from './summaryOnlyReporter.js'
|
package/dist/bin/dev-lib.js
CHANGED
|
@@ -3,7 +3,7 @@ import { _by } from '@naturalcycles/js-lib/array/array.util.js';
|
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
4
4
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
5
5
|
import { runScript } from '@naturalcycles/nodejs-lib/runScript';
|
|
6
|
-
import { buildCopy, buildProd, eslintAll, lintStagedCommand, requireOxlintConfig, runBiome, runCheck,
|
|
6
|
+
import { buildCopy, buildProd, eslintAll, lintStagedCommand, requireOxlintConfig, runBiome, runCheck, runOxfmt, runOxlint, runTest, stylelintAll, typecheckWithTS, typecheckWithTSC, typecheckWithTSGO, } from '../check.util.js';
|
|
7
7
|
import { runCommitlint } from '../commitlint.js';
|
|
8
8
|
const commands = [
|
|
9
9
|
{ name: 'check', fn: runCheck, desc: '"Run all possible checks": lint, typecheck, then test.' },
|
|
@@ -70,7 +70,7 @@ const commands = [
|
|
|
70
70
|
typecheck: false,
|
|
71
71
|
test: false,
|
|
72
72
|
}),
|
|
73
|
-
desc: 'Run all linters: eslint,
|
|
73
|
+
desc: 'Run all linters: eslint, oxfmt, stylelint, ktlint, actionlint.',
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
name: 'lint-staged',
|
|
@@ -105,7 +105,7 @@ const commands = [
|
|
|
105
105
|
desc: 'Run biome linter on all files with "auto-fix" disabled. Useful for debugging.',
|
|
106
106
|
interactiveOnly: true,
|
|
107
107
|
},
|
|
108
|
-
{ name: '
|
|
108
|
+
{ name: 'oxfmt', fn: runOxfmt, desc: 'Run oxfmt on all files.' },
|
|
109
109
|
{ name: 'stylelint', fn: stylelintAll, desc: 'Run stylelint on all files.' },
|
|
110
110
|
{
|
|
111
111
|
name: 'stylelint --no-fix',
|
|
@@ -164,7 +164,7 @@ runScript(async () => {
|
|
|
164
164
|
async function quickCheck() {
|
|
165
165
|
await runCheck({
|
|
166
166
|
eslint: false,
|
|
167
|
-
|
|
167
|
+
oxfmt: false,
|
|
168
168
|
stylelint: false,
|
|
169
169
|
typecheck: false,
|
|
170
170
|
});
|
package/dist/check.util.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface CheckOptions {
|
|
|
7
7
|
fastLinters?: boolean;
|
|
8
8
|
eslint?: boolean;
|
|
9
9
|
stylelint?: boolean;
|
|
10
|
-
|
|
10
|
+
oxfmt?: boolean;
|
|
11
11
|
ktlint?: boolean;
|
|
12
12
|
/**
|
|
13
13
|
* true - run tsgo, otherwise tsc
|
|
@@ -38,16 +38,13 @@ export declare function eslintAll(opt?: EslintAllOptions): boolean;
|
|
|
38
38
|
* Returns true if it ran.
|
|
39
39
|
*/
|
|
40
40
|
export declare function runOxlint(fix?: boolean): boolean;
|
|
41
|
-
export declare function requireOxlintConfig(): void;
|
|
42
|
-
export declare function hasOxlintConfig(): boolean;
|
|
43
|
-
interface RunPrettierOptions {
|
|
44
|
-
experimentalCli?: boolean;
|
|
45
|
-
fix?: boolean;
|
|
46
|
-
}
|
|
47
41
|
/**
|
|
48
42
|
* Returns true if it ran.
|
|
49
43
|
*/
|
|
50
|
-
export declare function
|
|
44
|
+
export declare function runOxfmt(fix?: boolean): boolean;
|
|
45
|
+
export declare function requireOxlintConfig(): void;
|
|
46
|
+
export declare function hasOxlintConfig(): boolean;
|
|
47
|
+
export declare function hasOxfmtConfig(): boolean;
|
|
51
48
|
/**
|
|
52
49
|
* Returns true if it ran.
|
|
53
50
|
*/
|
|
@@ -73,7 +70,7 @@ export declare function runTSCInFolders(dirs: string[], args?: string[], paralle
|
|
|
73
70
|
/**
|
|
74
71
|
* Use 'src' to indicate root.
|
|
75
72
|
*/
|
|
76
|
-
export declare function runTSGOInFolders(dirs: string[], args?: string[]
|
|
73
|
+
export declare function runTSGOInFolders(dirs: string[], args?: string[]): Promise<void>;
|
|
77
74
|
export declare function runTSCProd(args?: string[]): Promise<void>;
|
|
78
75
|
export declare function buildCopy(): void;
|
|
79
76
|
interface RunTestOptions {
|
package/dist/check.util.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createRequire } from 'node:module';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { _isTruthy } from '@naturalcycles/js-lib';
|
|
6
6
|
import { _uniq } from '@naturalcycles/js-lib/array';
|
|
7
|
-
import {
|
|
7
|
+
import { _since } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
8
8
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
9
9
|
import { _filterFalsyValues } from '@naturalcycles/js-lib/object/object.util.js';
|
|
10
10
|
import { semver2 } from '@naturalcycles/js-lib/semver';
|
|
@@ -14,7 +14,7 @@ import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
|
|
|
14
14
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
15
15
|
import { kpySync } from '@naturalcycles/nodejs-lib/kpy';
|
|
16
16
|
import { _yargs } from '@naturalcycles/nodejs-lib/yargs';
|
|
17
|
-
import { eslintExtensions, lintExclude, minActionlintVersion, prettierDirs,
|
|
17
|
+
import { eslintExtensions, lintExclude, minActionlintVersion, prettierDirs, stylelintExtensions, } from '../cfg/_cnst.js';
|
|
18
18
|
import { cfgDir } from './paths.js';
|
|
19
19
|
const { CI, ESLINT_CONCURRENCY } = process.env;
|
|
20
20
|
/**
|
|
@@ -23,7 +23,7 @@ const { CI, ESLINT_CONCURRENCY } = process.env;
|
|
|
23
23
|
* If full=false - the "slow" linters are skipped.
|
|
24
24
|
*/
|
|
25
25
|
export async function runCheck(opt = {}) {
|
|
26
|
-
const { fastLinters = true, eslint = true, stylelint = true,
|
|
26
|
+
const { fastLinters = true, eslint = true, stylelint = true, oxfmt = true, ktlint = true, typecheck = true, test = true, } = opt;
|
|
27
27
|
const started = Date.now();
|
|
28
28
|
let s;
|
|
29
29
|
const timings = {};
|
|
@@ -75,10 +75,10 @@ export async function runCheck(opt = {}) {
|
|
|
75
75
|
timings['stylelint'] = Date.now() - s;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
if (
|
|
78
|
+
if (oxfmt) {
|
|
79
79
|
s = Date.now();
|
|
80
|
-
if (
|
|
81
|
-
timings['
|
|
80
|
+
if (runOxfmt(fix)) {
|
|
81
|
+
timings['oxfmt'] = Date.now() - s;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (ktlint) {
|
|
@@ -110,7 +110,7 @@ export async function runCheck(opt = {}) {
|
|
|
110
110
|
}
|
|
111
111
|
console.log(`${check(true)}${white(`check`)} ${dimGrey(`took ` + _since(started))}`);
|
|
112
112
|
for (const [job, ms] of _stringMapEntries(timings)) {
|
|
113
|
-
console.log(`${job.padStart(12, ' ')}: ${String(
|
|
113
|
+
console.log(`${job.padStart(12, ' ')}: ${String(ms).padStart(5, ' ')} ms`);
|
|
114
114
|
}
|
|
115
115
|
// if (needToTrackChanges) {
|
|
116
116
|
// const gitStatusAfter = gitStatus()
|
|
@@ -217,56 +217,32 @@ export function runOxlint(fix = true) {
|
|
|
217
217
|
});
|
|
218
218
|
return true;
|
|
219
219
|
}
|
|
220
|
-
export function requireOxlintConfig() {
|
|
221
|
-
_assert(hasOxlintConfig(), '.oxlintrc.json config is not found');
|
|
222
|
-
}
|
|
223
|
-
export function hasOxlintConfig() {
|
|
224
|
-
const oxlintConfigPath = `.oxlintrc.json`;
|
|
225
|
-
return existsSync(oxlintConfigPath);
|
|
226
|
-
}
|
|
227
|
-
const prettierPaths = [
|
|
228
|
-
// Everything inside these folders
|
|
229
|
-
`./{${prettierDirs.join(',')}}/**/*.{${prettierExtensionsAll}}`,
|
|
230
|
-
// Root
|
|
231
|
-
`./*.{${prettierExtensionsAll}}`,
|
|
232
|
-
// Exclude
|
|
233
|
-
...lintExclude.map((s) => `!${s}`),
|
|
234
|
-
];
|
|
235
220
|
/**
|
|
236
221
|
* Returns true if it ran.
|
|
237
222
|
*/
|
|
238
|
-
export function
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (!prettierConfigPath) {
|
|
223
|
+
export function runOxfmt(fix = true) {
|
|
224
|
+
if (!hasOxfmtConfig()) {
|
|
225
|
+
console.log('.oxfmtrc.json(c) is not found, skipping to run oxfmt');
|
|
242
226
|
return false;
|
|
243
227
|
}
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (hasPrettierOverrides()) {
|
|
249
|
-
experimentalCli = false;
|
|
250
|
-
console.log(' prettier experimental mode disabled due to "overrides" in prettier.config.js');
|
|
251
|
-
}
|
|
252
|
-
// prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
|
|
253
|
-
exec2.spawn(prettierPath, {
|
|
254
|
-
name: fix ? 'prettier' : 'prettier --check',
|
|
255
|
-
args: [
|
|
256
|
-
fix ? `--write` : '--check',
|
|
257
|
-
`--log-level=warn`,
|
|
258
|
-
// non-experimental-cli has different cache format, hence disabling it
|
|
259
|
-
experimentalCli && '--cache-location',
|
|
260
|
-
experimentalCli && cacheLocation,
|
|
261
|
-
experimentalCli && `--experimental-cli`,
|
|
262
|
-
experimentalCli ? '--config-path' : `--config`,
|
|
263
|
-
prettierConfigPath,
|
|
264
|
-
...prettierPaths,
|
|
265
|
-
].filter(_isTruthy),
|
|
228
|
+
const oxlintPath = findPackageBinPath('oxfmt', 'oxfmt');
|
|
229
|
+
exec2.spawn(oxlintPath, {
|
|
230
|
+
name: ['oxfmt', !fix && '--check'].filter(Boolean).join(' '),
|
|
231
|
+
args: [!fix && '--check', '--no-error-on-unmatched-pattern'].filter(_isTruthy),
|
|
266
232
|
shell: false,
|
|
267
233
|
});
|
|
268
234
|
return true;
|
|
269
235
|
}
|
|
236
|
+
export function requireOxlintConfig() {
|
|
237
|
+
_assert(hasOxlintConfig(), '.oxlintrc.json config is not found');
|
|
238
|
+
}
|
|
239
|
+
export function hasOxlintConfig() {
|
|
240
|
+
const oxlintConfigPath = `.oxlintrc.json`;
|
|
241
|
+
return existsSync(oxlintConfigPath);
|
|
242
|
+
}
|
|
243
|
+
export function hasOxfmtConfig() {
|
|
244
|
+
return ['.oxfmtrc.jsonc', '.oxfmtrc.json'].some(existsSync);
|
|
245
|
+
}
|
|
270
246
|
const stylelintPaths = [
|
|
271
247
|
// Everything inside these folders
|
|
272
248
|
`./{${prettierDirs.join(',')}}/**/*.{${stylelintExtensions}}`,
|
|
@@ -376,6 +352,7 @@ export async function buildProd() {
|
|
|
376
352
|
export async function typecheckWithTS() {
|
|
377
353
|
if (hasDependencyInNodeModules('@typescript/native-preview')) {
|
|
378
354
|
await typecheckWithTSGO();
|
|
355
|
+
return;
|
|
379
356
|
}
|
|
380
357
|
await typecheckWithTSC();
|
|
381
358
|
}
|
|
@@ -423,14 +400,10 @@ async function runTSCInFolder(dir, args = []) {
|
|
|
423
400
|
/**
|
|
424
401
|
* Use 'src' to indicate root.
|
|
425
402
|
*/
|
|
426
|
-
export async function runTSGOInFolders(dirs, args = []
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
else {
|
|
431
|
-
for (const dir of dirs) {
|
|
432
|
-
await runTSGOInFolder(dir, args);
|
|
433
|
-
}
|
|
403
|
+
export async function runTSGOInFolders(dirs, args = []) {
|
|
404
|
+
// Run sequential, since tsgo (unlike tsc) uses all cpu cores already
|
|
405
|
+
for (const dir of dirs) {
|
|
406
|
+
await runTSGOInFolder(dir, args);
|
|
434
407
|
}
|
|
435
408
|
}
|
|
436
409
|
/**
|
|
@@ -544,14 +517,6 @@ export function findPackageBinPath(pkg, cmd) {
|
|
|
544
517
|
const { bin } = fs2.readJson(packageJsonPath);
|
|
545
518
|
return path.join(path.dirname(packageJsonPath), typeof bin === 'string' ? bin : bin[cmd]);
|
|
546
519
|
}
|
|
547
|
-
function hasPrettierOverrides() {
|
|
548
|
-
try {
|
|
549
|
-
return fs2.readText('prettier.config.js').includes('overrides');
|
|
550
|
-
}
|
|
551
|
-
catch {
|
|
552
|
-
return false;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
520
|
function check(predicate) {
|
|
556
521
|
return predicate ? ' ✓ ' : ' ';
|
|
557
522
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "20.
|
|
4
|
+
"version": "20.27.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@biomejs/biome": "^2",
|
|
7
7
|
"@eslint/js": "^9",
|
|
@@ -10,15 +10,13 @@
|
|
|
10
10
|
"@naturalcycles/nodejs-lib": "^15",
|
|
11
11
|
"@vitest/coverage-v8": "^4",
|
|
12
12
|
"eslint": "^9",
|
|
13
|
-
"eslint-plugin-import-x": "^4",
|
|
14
13
|
"eslint-plugin-oxlint": "^1",
|
|
15
|
-
"eslint-plugin-simple-import-sort": "^12",
|
|
16
14
|
"globals": "^17",
|
|
17
15
|
"lint-staged": "^16",
|
|
18
16
|
"micromatch": "^4",
|
|
17
|
+
"oxfmt": "*",
|
|
19
18
|
"oxlint": "^1",
|
|
20
19
|
"oxlint-tsgolint": "*",
|
|
21
|
-
"prettier": "^3",
|
|
22
20
|
"typescript-eslint": "^8"
|
|
23
21
|
},
|
|
24
22
|
"peerDependencies": {
|
|
@@ -48,7 +46,6 @@
|
|
|
48
46
|
"./cfg/biome.jsonc": "./cfg/biome.jsonc",
|
|
49
47
|
"./cfg/eslint.config.js": "./cfg/eslint.config.js",
|
|
50
48
|
"./cfg/oxlint.config.json": "./cfg/oxlint.config.json",
|
|
51
|
-
"./cfg/prettier.config.js": "./cfg/prettier.config.js",
|
|
52
49
|
"./cfg/stylelint.config.js": "./cfg/stylelint.config.js",
|
|
53
50
|
"./cfg/tsconfig.src.json": "./cfg/tsconfig.src.json",
|
|
54
51
|
"./cfg/tsconfig.scripts.json": "./cfg/tsconfig.scripts.json",
|
package/cfg/init/.prettierignore
DELETED
package/cfg/prettier.config.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default config for `prettier`.
|
|
3
|
-
* Extendable.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
printWidth: 100,
|
|
8
|
-
tabWidth: 2,
|
|
9
|
-
useTabs: false,
|
|
10
|
-
semi: false,
|
|
11
|
-
singleQuote: true,
|
|
12
|
-
quoteProps: 'as-needed',
|
|
13
|
-
jsxSingleQuote: false,
|
|
14
|
-
trailingComma: 'all',
|
|
15
|
-
bracketSpacing: true,
|
|
16
|
-
bracketSameLine: false,
|
|
17
|
-
arrowParens: 'avoid',
|
|
18
|
-
proseWrap: 'always',
|
|
19
|
-
htmlWhitespaceSensitivity: 'css',
|
|
20
|
-
endOfLine: 'lf',
|
|
21
|
-
overrides: [
|
|
22
|
-
{
|
|
23
|
-
// https://github.com/prettier/prettier/blob/main/CHANGELOG.md#use-json-parser-for-tsconfigjson-by-default-16012-by-sosukesuzuki
|
|
24
|
-
files: ['**/tsconfig.json', '**/tsconfig.*.json'],
|
|
25
|
-
options: {
|
|
26
|
-
parser: 'jsonc',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
}
|