@naturalcycles/dev-lib 13.40.2 → 13.42.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.
@@ -167,11 +167,23 @@ module.exports = {
167
167
  'undefined',
168
168
  ],
169
169
  'id-match': 2,
170
- 'import/order': 2,
170
+ 'import/order': [
171
+ 2,
172
+ {
173
+ alphabetize: {
174
+ order: 'asc',
175
+ },
176
+ },
177
+ ],
171
178
  'import/no-anonymous-default-export': 2,
172
179
  // 'import/namespace': 0, // issues with e.g globby
173
180
  // 'import/no-unresolved': 0, // breaks for type-aliases, e.g '@/store'
174
- // 'import/no-duplicates': 0,
181
+ 'import/no-duplicates': [2, { 'prefer-inline': false }],
182
+ 'import/export': 2,
183
+ 'import/no-empty-named-blocks': 2,
184
+ 'import/no-cycle': 2,
185
+ 'import/no-useless-path-segments': 2,
186
+ 'import/no-default-export': 2,
175
187
  'jsdoc/check-alignment': 2,
176
188
  // "jsdoc/check-indentation": "error",
177
189
  // 'jsdoc/newline-after-description': 2,
@@ -6,6 +6,7 @@
6
6
 
7
7
  const micromatch = require('micromatch')
8
8
  const fs = require('node:fs')
9
+ const { execSync } = require('node:child_process')
9
10
  const {
10
11
  prettierDirs,
11
12
  prettierExtensionsExclusive,
@@ -85,6 +86,20 @@ const linters = {
85
86
 
86
87
  return [`${dir}/resources/ktlint -F ${filesList}`]
87
88
  },
89
+
90
+ './.github/**/*.{yml,yaml}': match => {
91
+ if (!match.length) return []
92
+
93
+ if (!canRunBinary('actionlint')) {
94
+ console.log(
95
+ `actionlint is not installed and won't be run.\nThis is how to install it: https://github.com/rhysd/actionlint/blob/main/docs/install.md`,
96
+ )
97
+ return []
98
+ }
99
+
100
+ // run actionlint on all files at once, as it's fast anyway
101
+ return [`actionlint`]
102
+ },
88
103
  }
89
104
 
90
105
  // /scripts are separate, cause they require separate tsconfig.json
@@ -125,4 +140,13 @@ if (fs.existsSync(`./e2e`)) {
125
140
  })
126
141
  }
127
142
 
143
+ function canRunBinary(name) {
144
+ try {
145
+ execSync(`which ${name}`)
146
+ return true
147
+ } catch {
148
+ return false
149
+ }
150
+ }
151
+
128
152
  module.exports = linters
package/dist/bin/bt.js CHANGED
@@ -2,10 +2,9 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
6
5
  const jest_util_1 = require("../util/jest.util");
7
6
  const tsc_util_1 = require("../util/tsc.util");
8
- (0, nodejs_lib_2.runScript)(async () => {
7
+ (0, nodejs_lib_1.runScript)(async () => {
9
8
  (0, nodejs_lib_1._emptyDirSync)('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
10
9
  // fs.rmSync('./dist', { recursive: true, force: true })
11
10
  await (0, tsc_util_1.tscMainAndScripts)(true);
package/dist/bin/btl.js CHANGED
@@ -2,11 +2,10 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
6
5
  const lint_all_command_1 = require("../cmd/lint-all.command");
7
6
  const jest_util_1 = require("../util/jest.util");
8
7
  const tsc_util_1 = require("../util/tsc.util");
9
- (0, nodejs_lib_2.runScript)(async () => {
8
+ (0, nodejs_lib_1.runScript)(async () => {
10
9
  await (0, lint_all_command_1.lintAllCommand)();
11
10
  (0, nodejs_lib_1._emptyDirSync)('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
12
11
  // fs.rmSync('./dist', { recursive: true, force: true })
package/dist/bin/build.js CHANGED
@@ -2,9 +2,8 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
6
5
  const tsc_util_1 = require("../util/tsc.util");
7
- (0, nodejs_lib_2.runScript)(async () => {
6
+ (0, nodejs_lib_1.runScript)(async () => {
8
7
  (0, nodejs_lib_1._emptyDirSync)('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
9
8
  // fs.rmSync('./dist', { recursive: true, force: true })
10
9
  await (0, tsc_util_1.tscMainAndScripts)(true);
@@ -2,9 +2,8 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
6
5
  const paths_cnst_1 = require("../cnst/paths.cnst");
7
- (0, nodejs_lib_2.runScript)(() => {
6
+ (0, nodejs_lib_1.runScript)(() => {
8
7
  (0, nodejs_lib_1.kpySync)({
9
8
  baseDir: paths_cnst_1.cfgOverwriteDir,
10
9
  outputDir: './',
@@ -1,4 +1,4 @@
1
1
  /**
2
- * We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
2
+ * Run all linters.
3
3
  */
4
4
  export declare function lintAllCommand(): Promise<void>;
@@ -2,16 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lintAllCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const node_child_process_1 = require("node:child_process");
5
6
  const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
7
7
  const js_lib_1 = require("@naturalcycles/js-lib");
8
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
9
  const yargs_1 = tslib_1.__importDefault(require("yargs"));
9
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
10
10
  const prettier_util_1 = require("../util/prettier.util");
11
11
  const stylelint_util_1 = require("../util/stylelint.util");
12
12
  const eslint_all_command_1 = require("./eslint-all.command");
13
13
  /**
14
- * We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
14
+ * Run all linters.
15
15
  */
16
16
  async function lintAllCommand() {
17
17
  const started = Date.now();
@@ -25,7 +25,25 @@ async function lintAllCommand() {
25
25
  default: false,
26
26
  },
27
27
  }).argv;
28
- const hadChangesBefore = (0, nodejs_lib_2.gitHasUncommittedChanges)();
28
+ if (canRunBinary('actionlint')) {
29
+ const env_1 = { stack: [], error: void 0, hasError: false };
30
+ try {
31
+ const _ = tslib_1.__addDisposableResource(env_1, (0, js_lib_1._blockTimer)('actionlint'), false);
32
+ (0, nodejs_lib_1.execVoidCommandSync)(`actionlint`);
33
+ }
34
+ catch (e_1) {
35
+ env_1.error = e_1;
36
+ env_1.hasError = true;
37
+ }
38
+ finally {
39
+ tslib_1.__disposeResources(env_1);
40
+ }
41
+ }
42
+ else {
43
+ console.log(`actionlint is not installed and won't be run.\nThis is how to install it: https://github.com/rhysd/actionlint/blob/main/docs/install.md`);
44
+ }
45
+ const hadChangesBefore = (0, nodejs_lib_1.gitHasUncommittedChanges)();
46
+ // We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
29
47
  await (0, eslint_all_command_1.eslintAllCommand)();
30
48
  if (node_fs_1.default.existsSync(`node_modules/stylelint`) &&
31
49
  node_fs_1.default.existsSync(`node_modules/stylelint-config-standard-scss`)) {
@@ -39,17 +57,17 @@ async function lintAllCommand() {
39
57
  console.log(`${(0, nodejs_lib_1.boldGrey)('lint-all')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
40
58
  if (commitOnChanges || failOnChanges) {
41
59
  // detect changes
42
- const hasChanges = (0, nodejs_lib_2.gitHasUncommittedChanges)();
60
+ const hasChanges = (0, nodejs_lib_1.gitHasUncommittedChanges)();
43
61
  if (hasChanges) {
44
62
  if (hadChangesBefore) {
45
63
  console.log(`lint-all: there are changes before running lint-all, will not commit`);
46
64
  }
47
65
  else {
48
- const msg = 'style(ci): ' + (0, js_lib_1._truncate)((0, nodejs_lib_2.commitMessageToTitleMessage)((0, nodejs_lib_2.getLastGitCommitMsg)()), 60);
66
+ const msg = 'style(ci): ' + (0, js_lib_1._truncate)((0, nodejs_lib_1.commitMessageToTitleMessage)((0, nodejs_lib_1.getLastGitCommitMsg)()), 60);
49
67
  // pull, commit, push changes
50
- (0, nodejs_lib_2.gitPull)();
51
- (0, nodejs_lib_2.gitCommitAll)(msg);
52
- (0, nodejs_lib_2.gitPush)();
68
+ (0, nodejs_lib_1.gitPull)();
69
+ (0, nodejs_lib_1.gitCommitAll)(msg);
70
+ (0, nodejs_lib_1.gitPush)();
53
71
  }
54
72
  // fail on changes
55
73
  if (failOnChanges) {
@@ -60,3 +78,12 @@ async function lintAllCommand() {
60
78
  }
61
79
  }
62
80
  exports.lintAllCommand = lintAllCommand;
81
+ function canRunBinary(name) {
82
+ try {
83
+ (0, node_child_process_1.execSync)(`which ${name}`);
84
+ return true;
85
+ }
86
+ catch {
87
+ return false;
88
+ }
89
+ }
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tscProdCommand = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
7
6
  function tscProdCommand() {
8
7
  // You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
9
8
  const projectTsconfigPath = `./tsconfig.prod.json`;
10
9
  const args = ['-P', projectTsconfigPath];
11
10
  const started = Date.now();
12
11
  (0, nodejs_lib_1.execVoidCommandSync)(`tsc`, args);
13
- console.log(`${(0, nodejs_lib_2.boldGrey)('tsc prod')} ${(0, nodejs_lib_2.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
12
+ console.log(`${(0, nodejs_lib_1.boldGrey)('tsc prod')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
14
13
  }
15
14
  exports.tscProdCommand = tscProdCommand;
@@ -1,8 +1,8 @@
1
+ import { expectTypeOf } from 'expect-type';
1
2
  import timekeeper from 'timekeeper';
2
3
  export * from '../jestOffline.util';
3
4
  export * from './expect.util';
4
5
  export * from './mockAllKindsOfThings';
5
6
  export * from './testing.util';
6
7
  export * from './time.util';
7
- import { expectTypeOf } from 'expect-type';
8
8
  export { timekeeper, expectTypeOf };
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.expectTypeOf = exports.timekeeper = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const expect_type_1 = require("expect-type");
6
+ Object.defineProperty(exports, "expectTypeOf", { enumerable: true, get: function () { return expect_type_1.expectTypeOf; } });
5
7
  const timekeeper_1 = tslib_1.__importDefault(require("timekeeper"));
6
8
  exports.timekeeper = timekeeper_1.default;
7
9
  tslib_1.__exportStar(require("../jestOffline.util"), exports);
@@ -9,5 +11,3 @@ tslib_1.__exportStar(require("./expect.util"), exports);
9
11
  tslib_1.__exportStar(require("./mockAllKindsOfThings"), exports);
10
12
  tslib_1.__exportStar(require("./testing.util"), exports);
11
13
  tslib_1.__exportStar(require("./time.util"), exports);
12
- const expect_type_1 = require("expect-type");
13
- Object.defineProperty(exports, "expectTypeOf", { enumerable: true, get: function () { return expect_type_1.expectTypeOf; } });
@@ -4,9 +4,8 @@ exports.runJest = exports.isRunningAllTests = exports.getJestManualConfigPath =
4
4
  const tslib_1 = require("tslib");
5
5
  const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
6
  const node_os_1 = tslib_1.__importDefault(require("node:os"));
7
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
7
  const js_lib_1 = require("@naturalcycles/js-lib");
9
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
8
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
10
9
  const paths_cnst_1 = require("../cnst/paths.cnst");
11
10
  const test_util_1 = require("./test.util");
12
11
  function getJestConfigPath() {
@@ -40,7 +39,7 @@ exports.isRunningAllTests = isRunningAllTests;
40
39
  */
41
40
  function runJest(opt = {}) {
42
41
  if (!(0, test_util_1.nodeModuleExists)('jest')) {
43
- console.log((0, nodejs_lib_2.dimGrey)(`node_modules/${(0, nodejs_lib_2.white)('jest')} not found, skipping tests`));
42
+ console.log((0, nodejs_lib_1.dimGrey)(`node_modules/${(0, nodejs_lib_1.white)('jest')} not found, skipping tests`));
44
43
  return;
45
44
  }
46
45
  const { CI, CIRCLECI, CPU_LIMIT, TZ = 'UTC', APP_ENV, JEST_NO_ALPHABETIC, JEST_SHARDS, NODE_OPTIONS = 'not defined', } = process.env;
@@ -116,7 +115,7 @@ function runJest(opt = {}) {
116
115
  }
117
116
  const availableParallelism = node_os_1.default.availableParallelism?.();
118
117
  const cpus = node_os_1.default.cpus().length;
119
- console.log(`${(0, nodejs_lib_2.dimGrey)(Object.entries({
118
+ console.log(`${(0, nodejs_lib_1.dimGrey)(Object.entries({
120
119
  node,
121
120
  NODE_OPTIONS,
122
121
  cpus,
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ensureProjectTsconfigScripts = exports.tscScriptsAsync = exports.tscScripts = exports.tscAsync = exports.tsc = exports.tscMainAndScripts = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
7
6
  const js_lib_1 = require("@naturalcycles/js-lib");
8
- const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
9
- const nodejs_lib_3 = require("@naturalcycles/nodejs-lib");
7
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
10
8
  const paths_cnst_1 = require("../cnst/paths.cnst");
11
9
  async function tscMainAndScripts(noEmit = false) {
12
10
  await Promise.all([tscAsync(noEmit), tscScriptsAsync()]);
@@ -16,14 +14,14 @@ function tsc(noEmit = false) {
16
14
  const started = Date.now();
17
15
  const args = [noEmit && '--noEmit'].filter(js_lib_1._isTruthy);
18
16
  (0, nodejs_lib_1.execVoidCommandSync)('tsc', args);
19
- console.log(`${(0, nodejs_lib_2.boldGrey)('tsc')} ${(0, nodejs_lib_2.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
17
+ console.log(`${(0, nodejs_lib_1.boldGrey)('tsc')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
20
18
  }
21
19
  exports.tsc = tsc;
22
20
  async function tscAsync(noEmit = false) {
23
21
  const started = Date.now();
24
22
  const args = [noEmit && '--noEmit'].filter(js_lib_1._isTruthy);
25
23
  await (0, nodejs_lib_1.execVoidCommand)('tsc', args);
26
- console.log(`${(0, nodejs_lib_2.boldGrey)('tsc')} ${(0, nodejs_lib_2.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
24
+ console.log(`${(0, nodejs_lib_1.boldGrey)('tsc')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
27
25
  }
28
26
  exports.tscAsync = tscAsync;
29
27
  function tscScripts() {
@@ -35,7 +33,7 @@ function tscScripts() {
35
33
  const args = ['-P', projectTsconfigPath, '--noEmit'];
36
34
  const started = Date.now();
37
35
  (0, nodejs_lib_1.execVoidCommandSync)(`tsc`, args);
38
- console.log(`${(0, nodejs_lib_2.boldGrey)('tsc scripts')} ${(0, nodejs_lib_2.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
36
+ console.log(`${(0, nodejs_lib_1.boldGrey)('tsc scripts')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
39
37
  }
40
38
  exports.tscScripts = tscScripts;
41
39
  async function tscScriptsAsync() {
@@ -47,7 +45,7 @@ async function tscScriptsAsync() {
47
45
  const args = ['-P', projectTsconfigPath, '--noEmit'];
48
46
  const started = Date.now();
49
47
  await (0, nodejs_lib_1.execVoidCommand)(`tsc`, args);
50
- console.log(`${(0, nodejs_lib_2.boldGrey)('tsc scripts')} ${(0, nodejs_lib_2.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
48
+ console.log(`${(0, nodejs_lib_1.boldGrey)('tsc scripts')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
51
49
  }
52
50
  exports.tscScriptsAsync = tscScriptsAsync;
53
51
  /**
@@ -58,12 +56,12 @@ function ensureProjectTsconfigScripts() {
58
56
  if (!node_fs_1.default.existsSync(projectTsconfigPath)) {
59
57
  // You cannot just use a shared `tsconfig.scripts.json` because of relative paths for `include`
60
58
  // So, it will be copied into the project
61
- (0, nodejs_lib_3.kpySync)({
59
+ (0, nodejs_lib_1.kpySync)({
62
60
  baseDir: `${paths_cnst_1.cfgDir}/init/scripts/`,
63
61
  inputPatterns: ['tsconfig.json'],
64
62
  outputDir: './scripts',
65
63
  });
66
- console.log(`${(0, nodejs_lib_2.boldGrey)('/scripts/tsconfig.json')} file is automatically added`);
64
+ console.log(`${(0, nodejs_lib_1.boldGrey)('/scripts/tsconfig.json')} file is automatically added`);
67
65
  }
68
66
  return projectTsconfigPath;
69
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "13.40.2",
3
+ "version": "13.42.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "tsn-debug": "tsn testScript.ts",
@@ -51,6 +51,7 @@
51
51
  "husky": "^8.0.1",
52
52
  "jest-junit": "^16.0.0",
53
53
  "lint-staged": "^14.0.0",
54
+ "micromatch": "^4.0.5",
54
55
  "mitm": "^1.7.0",
55
56
  "prettier": "^3.0.0",
56
57
  "timekeeper": "^2.2.0",
@@ -61,7 +62,7 @@
61
62
  "devDependencies": {
62
63
  "jest": "^29.0.0",
63
64
  "stylelint": "^15.0.0",
64
- "stylelint-config-standard-scss": "^10.0.0"
65
+ "stylelint-config-standard-scss": "^11.0.0"
65
66
  },
66
67
  "files": [
67
68
  "dist",
package/readme.md CHANGED
@@ -137,7 +137,7 @@ If you need to execute shards **in parallel**, you can follow e.g
137
137
 
138
138
  #### Lint commands
139
139
 
140
- - `lint-all`: runs ESLint, Stylelint, Prettier, in the right order.
140
+ - `lint-all`: runs ESLint, Stylelint, Prettier, actionlint, ktlint in the right order.
141
141
 
142
142
  - `--commitOnChanges` will commit lint-modified changes and push them
143
143
  - `--failOnChanges` will exit with status 1 in the end (will fail the command)