@naturalcycles/dev-lib 19.28.0 → 19.30.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/biome.jsonc CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
3
3
  "root": false,
4
4
  "files": {
5
5
  "includes": [
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "correctness": {
37
37
  "useImportExtensions": "error",
38
+ "useParseIntRadix": "off",
38
39
  "noUnusedFunctionParameters": "error",
39
40
  // noUnusedImports + noUnusedVariables can replace eslint-plugin-unused-vars!
40
41
  "noUnusedImports": "error",
@@ -73,6 +74,7 @@
73
74
  },
74
75
  "suspicious": {
75
76
  "useNumberToFixedDigitsArgument": "error",
77
+ "useIterableCallbackReturn": "off",
76
78
  "useErrorMessage": "error",
77
79
  "noEvolvingTypes": "error",
78
80
  "noExplicitAny": "off",
@@ -77,6 +77,7 @@ const commands = [
77
77
  fn: () => runBiome(),
78
78
  desc: 'Run biome linter on all files.',
79
79
  },
80
+ { name: 'biome-no-fix', deprecated: true, fn: () => runBiome(false) },
80
81
  {
81
82
  name: 'biome --no-fix',
82
83
  fn: () => runBiome(false),
@@ -11,8 +11,12 @@ interface EslintAllOptions {
11
11
  * Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
12
12
  */
13
13
  export declare function eslintAll(opt?: EslintAllOptions): Promise<void>;
14
- export declare function runPrettier(experimentalCli?: boolean): void;
15
- export declare function stylelintAll(): void;
14
+ interface RunPrettierOptions {
15
+ experimentalCli?: boolean;
16
+ fix?: boolean;
17
+ }
18
+ export declare function runPrettier(opt?: RunPrettierOptions): void;
19
+ export declare function stylelintAll(fix?: boolean): void;
16
20
  export declare function lintStagedCommand(): Promise<void>;
17
21
  export declare function runCommitlintCommand(): void;
18
22
  export declare function requireActionlintVersion(): void;
package/dist/lint.util.js CHANGED
@@ -7,7 +7,6 @@ import { _since } from '@naturalcycles/js-lib/datetime/time.util.js';
7
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
- import { _truncate } from '@naturalcycles/js-lib/string/string.util.js';
11
10
  import { git2 } from '@naturalcycles/nodejs-lib';
12
11
  import { boldGrey, dimGrey, grey } from '@naturalcycles/nodejs-lib/colors';
13
12
  import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
@@ -21,52 +20,60 @@ const { CI, ESLINT_CONCURRENCY } = process.env;
21
20
  */
22
21
  export async function lintAllCommand() {
23
22
  const started = Date.now();
24
- const { commitOnChanges, failOnChanges } = _yargs().options({
25
- commitOnChanges: {
26
- type: 'boolean',
27
- default: false,
28
- },
29
- failOnChanges: {
30
- type: 'boolean',
31
- default: false,
32
- },
33
- }).argv;
34
- const needToTrackChanges = commitOnChanges || failOnChanges;
35
- const gitStatusAtStart = gitStatus();
36
- if (needToTrackChanges && gitStatusAtStart) {
37
- console.log('lint-all: git shows changes before run:');
38
- console.log(gitStatusAtStart);
39
- }
23
+ // const { commitOnChanges, failOnChanges } = _yargs().options({
24
+ // commitOnChanges: {
25
+ // type: 'boolean',
26
+ // default: false,
27
+ // },
28
+ // failOnChanges: {
29
+ // type: 'boolean',
30
+ // default: false,
31
+ // },
32
+ // }).argv
33
+ // const needToTrackChanges = commitOnChanges || failOnChanges
34
+ // const gitStatusAtStart = gitStatus()
35
+ // if (needToTrackChanges && gitStatusAtStart) {
36
+ // console.log('lint-all: git shows changes before run:')
37
+ // console.log(gitStatusAtStart)
38
+ // }
39
+ // In CI, Github Actions doesn't allow us to push and then run CI on changes again
40
+ // (known limitation / "infinite run loop" prevention)
41
+ // That's why we run in "no-fix" mode in CI, and "fix" mode locally
42
+ const fix = !CI;
40
43
  // Fast linters (that run in <1 second) go first
41
44
  runActionLint();
42
- runBiome();
45
+ runBiome(fix);
43
46
  // From this point we start the "slow" linters, with ESLint leading the way
44
47
  // We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
45
- await eslintAll();
48
+ await eslintAll({
49
+ fix,
50
+ });
46
51
  if (existsSync(`node_modules/stylelint`) &&
47
52
  existsSync(`node_modules/stylelint-config-standard-scss`)) {
48
- stylelintAll();
53
+ stylelintAll(fix);
49
54
  }
50
- runPrettier();
51
- await runKTLint();
55
+ runPrettier({ fix });
56
+ await runKTLint(fix);
52
57
  console.log(`${boldGrey('lint-all')} ${dimGrey(`took ` + _since(started))}`);
53
- if (needToTrackChanges) {
54
- const gitStatusAfter = gitStatus();
55
- const hasChanges = gitStatusAfter !== gitStatusAtStart;
56
- if (!hasChanges)
57
- return;
58
- const msg = 'style(ci): ' + _truncate(git2.commitMessageToTitleMessage(git2.getLastGitCommitMsg()), 60);
59
- // pull, commit, push changes
60
- git2.pull();
61
- git2.commitAll(msg);
62
- git2.push();
63
- // fail on changes
64
- if (failOnChanges) {
65
- console.log(gitStatusAfter);
66
- console.log('lint-all failOnChanges: exiting with status 1');
67
- process.exitCode = 1;
68
- }
69
- }
58
+ // if (needToTrackChanges) {
59
+ // const gitStatusAfter = gitStatus()
60
+ // const hasChanges = gitStatusAfter !== gitStatusAtStart
61
+ // if (!hasChanges) return
62
+ // const msg =
63
+ // 'style(ci): ' + _truncate(git2.commitMessageToTitleMessage(git2.getLastGitCommitMsg()), 60)
64
+ //
65
+ // // pull, commit, push changes
66
+ // git2.pull()
67
+ // git2.commitAll(msg)
68
+ // git2.push()
69
+ //
70
+ // // fail on changes
71
+ // if (failOnChanges) {
72
+ // console.log(gitStatusAfter)
73
+ // console.log('lint-all failOnChanges: exiting with status 1')
74
+ // process.exitCode = 1
75
+ // }
76
+ // }
70
77
  }
71
78
  /**
72
79
  * Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
@@ -80,7 +87,7 @@ export async function eslintAll(opt) {
80
87
  },
81
88
  fix: {
82
89
  type: 'boolean',
83
- default: true,
90
+ default: !CI, // defaults to false in CI, true otherwise
84
91
  },
85
92
  });
86
93
  const { ext, fix } = {
@@ -88,23 +95,19 @@ export async function eslintAll(opt) {
88
95
  ...opt,
89
96
  };
90
97
  const extensions = ext.split(',');
91
- if (fix) {
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) {
92
102
  await Promise.all([
93
- // /src
94
103
  runESLint(`src`, extensions, fix),
95
- // /scripts
96
104
  runESLint(`scripts`, extensions, fix),
97
- // /e2e
98
105
  runESLint(`e2e`, extensions, fix),
99
106
  ]);
100
107
  }
101
108
  else {
102
- // with no-fix - let's run serially
103
- // /src
104
109
  await runESLint(`src`, extensions, fix);
105
- // /scripts
106
110
  await runESLint(`scripts`, extensions, fix);
107
- // /e2e
108
111
  await runESLint(`e2e`, extensions, fix);
109
112
  }
110
113
  console.log(`${boldGrey('eslint-all')} ${dimGrey(`took ` + _since(started))}`);
@@ -138,7 +141,7 @@ async function runESLint(dir, extensions = eslintExtensions.split(','), fix = tr
138
141
  cacheLocation,
139
142
  `--no-error-on-unmatched-pattern`,
140
143
  `--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
141
- fix ? `--fix` : '',
144
+ fix ? `--fix` : '--no-fix',
142
145
  ].filter(_isTruthy),
143
146
  shell: false,
144
147
  env: _filterFalsyValues({
@@ -155,7 +158,8 @@ const prettierPaths = [
155
158
  // Exclude
156
159
  ...lintExclude.map((s) => `!${s}`),
157
160
  ];
158
- export function runPrettier(experimentalCli = true) {
161
+ export function runPrettier(opt = {}) {
162
+ const { experimentalCli = true, fix = true } = opt;
159
163
  const prettierConfigPath = [`./prettier.config.js`].find(f => existsSync(f));
160
164
  if (!prettierConfigPath)
161
165
  return;
@@ -166,7 +170,7 @@ export function runPrettier(experimentalCli = true) {
166
170
  // prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
167
171
  exec2.spawn(prettierPath, {
168
172
  args: [
169
- `--write`,
173
+ fix ? `--write` : '--check',
170
174
  `--log-level=warn`,
171
175
  '--cache-location',
172
176
  cacheLocation,
@@ -184,13 +188,14 @@ const stylelintPaths = [
184
188
  // Exclude
185
189
  ...lintExclude.map((s) => `!${s}`),
186
190
  ];
187
- export function stylelintAll() {
188
- const { fix } = _yargs().options({
191
+ export function stylelintAll(fix) {
192
+ const argv = _yargs().options({
189
193
  fix: {
190
194
  type: 'boolean',
191
- default: true,
195
+ default: !CI, // defaults to false in CI, true otherwise
192
196
  },
193
197
  }).argv;
198
+ fix ??= argv.fix;
194
199
  const config = [`./stylelint.config.js`].find(f => existsSync(f));
195
200
  if (!config)
196
201
  return;
@@ -229,12 +234,12 @@ export function runCommitlintCommand() {
229
234
  log: false,
230
235
  });
231
236
  }
232
- async function runKTLint() {
237
+ async function runKTLint(fix = true) {
233
238
  if (!existsSync(`node_modules/@naturalcycles/ktlint`))
234
239
  return;
235
240
  // @ts-expect-error ktlint is not installed (due to size in node_modules), but it's ok
236
241
  const { ktlintAll } = await import('@naturalcycles/ktlint');
237
- await ktlintAll();
242
+ await ktlintAll(fix ? ['-F'] : []);
238
243
  }
239
244
  function runActionLint() {
240
245
  // Only run if there is a folder of `.github/workflows`, otherwise actionlint will fail
@@ -261,12 +266,6 @@ export function getActionLintVersion() {
261
266
  return exec2.exec('actionlint --version').split('\n')[0];
262
267
  }
263
268
  export function runBiome(fix = true) {
264
- // if (!fs.existsSync(`node_modules/@biomejs/biome`)) {
265
- // if (verbose) {
266
- // console.log(`biome is not installed (checked in node_modules/@biomejs/biome), skipping`)
267
- // }
268
- // return
269
- // }
270
269
  const configPath = `biome.jsonc`;
271
270
  if (!existsSync(configPath)) {
272
271
  console.log(`biome is skipped, because ./biome.jsonc is not present`);
@@ -289,14 +288,13 @@ function canRunBinary(name) {
289
288
  return false;
290
289
  }
291
290
  }
292
- function gitStatus() {
293
- try {
294
- return execSync('git status -s', {
295
- encoding: 'utf8',
296
- });
297
- }
298
- catch { }
299
- }
291
+ // function gitStatus(): string | undefined {
292
+ // try {
293
+ // return execSync('git status -s', {
294
+ // encoding: 'utf8',
295
+ // })
296
+ // } catch {}
297
+ // }
300
298
  const require = createRequire(import.meta.url);
301
299
  export function findPackageBinPath(pkg, cmd) {
302
300
  const packageJsonPath = require.resolve(`${pkg}/package.json`);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "19.28.0",
4
+ "version": "19.30.0",
5
5
  "dependencies": {
6
- "@biomejs/biome": "2.1.3",
6
+ "@biomejs/biome": "^2",
7
7
  "@commitlint/cli": "^19",
8
8
  "@commitlint/config-conventional": "^19",
9
9
  "@eslint/js": "^9",
@@ -103,6 +103,7 @@
103
103
  "lint": "tsx ./src/bin/dev-lib.ts lint",
104
104
  "eslint": "tsx ./src/bin/dev-lib.ts eslint",
105
105
  "eslint-no-fix": "tsx ./src/bin/dev-lib.ts eslint-no-fix",
106
+ "biome-no-fix": "tsx ./src/bin/dev-lib.ts biome-no-fix",
106
107
  "lint-staged-debug": "tsx ./src/bin/dev-lib.ts lint-staged"
107
108
  }
108
109
  }
@@ -1,5 +0,0 @@
1
- {
2
- "root": true,
3
- "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
4
- "extends": ["node_modules/@naturalcycles/dev-lib/cfg/biome.jsonc"]
5
- }