@naturalcycles/dev-lib 17.1.2 → 17.2.1

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.
@@ -85,7 +85,7 @@ module.exports = {
85
85
  // "@mysticatea/eslint-plugin/no-this-in-static": 0,
86
86
  '@typescript-eslint/ban-types': 0,
87
87
  '@typescript-eslint/consistent-type-exports': 0,
88
- '@typescript-eslint/consistent-type-imports': 0,
88
+ // '@typescript-eslint/consistent-type-imports': 0, // `useImportType` is currently disabled
89
89
  '@typescript-eslint/default-param-last': 0,
90
90
  '@typescript-eslint/dot-notation': 0,
91
91
  '@typescript-eslint/no-dupe-class-members': 0,
@@ -12,7 +12,8 @@ const maxWorkers = getMaxWorkers()
12
12
  const minWorkers = maxWorkers
13
13
  // threads are tested to be ~10% faster than forks in CI (and no change locally)
14
14
  // UPD: it was not statistically significant, so, reverting back to forks which is more stable
15
- const pool = 'forks'
15
+ // UPD2: in a different experiment, threads show ~10% faster locally, consistently
16
+ const pool = 'threads'
16
17
  process.env.TZ ||= 'UTC'
17
18
 
18
19
  if (testType === 'unit') {
@@ -48,6 +49,7 @@ export const sharedConfig = {
48
49
  setupFiles,
49
50
  logHeapUsage: true,
50
51
  testTimeout: 60_000,
52
+ slowTestThreshold: isCI ? 500 : 300, // higher threshold in CI
51
53
  sequence: {
52
54
  sequencer: VitestAlphabeticSequencer,
53
55
  // shuffle: {
@@ -6,8 +6,6 @@ exports.runTSCInFolders = runTSCInFolders;
6
6
  exports.runTSCInFolder = runTSCInFolder;
7
7
  exports.runTSCProd = runTSCProd;
8
8
  exports.buildCopy = buildCopy;
9
- const tslib_1 = require("tslib");
10
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
11
9
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
12
10
  async function buildEsmCjs() {
13
11
  // You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
@@ -81,7 +79,7 @@ async function runTSCInFolders(tsconfigPaths, args = [], parallel = true) {
81
79
  * Pass '.' to run in root.
82
80
  */
83
81
  async function runTSCInFolder(tsconfigPath, args = []) {
84
- if (!node_fs_1.default.existsSync(tsconfigPath)) {
82
+ if (!nodejs_lib_1.fs2.pathExists(tsconfigPath)) {
85
83
  console.log(`Skipping to run tsc for ${tsconfigPath}, as it doesn't exist`);
86
84
  return;
87
85
  }
@@ -91,7 +89,7 @@ async function runTSCInFolder(tsconfigPath, args = []) {
91
89
  });
92
90
  }
93
91
  async function runTSCProd(args = []) {
94
- const tsconfigPath = [`./tsconfig.prod.json`].find(p => node_fs_1.default.existsSync(p)) || 'tsconfig.json';
92
+ const tsconfigPath = [`./tsconfig.prod.json`].find(p => nodejs_lib_1.fs2.pathExists(p)) || 'tsconfig.json';
95
93
  await nodejs_lib_1.exec2.spawnAsync(`tsc`, {
96
94
  args: ['-P', tsconfigPath, '--noEmit', 'false', '--noCheck', ...args],
97
95
  shell: false,
package/dist/lint.util.js CHANGED
@@ -9,9 +9,8 @@ exports.runCommitlintCommand = runCommitlintCommand;
9
9
  exports.requireActionlintVersion = requireActionlintVersion;
10
10
  exports.getActionLintVersion = getActionLintVersion;
11
11
  exports.runBiome = runBiome;
12
- const tslib_1 = require("tslib");
13
- const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
14
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
12
+ const node_child_process_1 = require("node:child_process");
13
+ const node_fs_1 = require("node:fs");
15
14
  const js_lib_1 = require("@naturalcycles/js-lib");
16
15
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
17
16
  const paths_1 = require("./paths");
@@ -43,8 +42,8 @@ async function lintAllCommand() {
43
42
  // From this point we start the "slow" linters, with ESLint leading the way
44
43
  // We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
45
44
  await eslintAll();
46
- if (node_fs_1.default.existsSync(`node_modules/stylelint`) &&
47
- node_fs_1.default.existsSync(`node_modules/stylelint-config-standard-scss`)) {
45
+ if ((0, node_fs_1.existsSync)(`node_modules/stylelint`) &&
46
+ (0, node_fs_1.existsSync)(`node_modules/stylelint-config-standard-scss`)) {
48
47
  stylelintAll();
49
48
  }
50
49
  runPrettier();
@@ -88,20 +87,20 @@ async function eslintAll(opt) {
88
87
  ...opt,
89
88
  };
90
89
  const extensions = ext.split(',');
91
- const eslintConfigPathRoot = ['./eslint.config.js', './eslint.config.cjs'].find(p => node_fs_1.default.existsSync(p));
90
+ const eslintConfigPathRoot = ['./eslint.config.js', './eslint.config.cjs'].find(p => (0, node_fs_1.existsSync)(p));
92
91
  const eslintConfigPathScripts = [
93
92
  './scripts/eslint.config.js',
94
93
  './scripts/eslint.config.cjs',
95
94
  './eslint.config.js',
96
95
  './eslint.config.cjs',
97
- ].find(p => node_fs_1.default.existsSync(p));
96
+ ].find(p => (0, node_fs_1.existsSync)(p));
98
97
  const eslintConfigPathE2e = [
99
98
  './e2e/eslint.config.js',
100
99
  './e2e/eslint.config.cjs',
101
100
  './eslint.config.js',
102
101
  './eslint.config.cjs',
103
- ].find(p => node_fs_1.default.existsSync(p));
104
- const tsconfigPathScripts = [`./scripts/tsconfig.json`].find(p => node_fs_1.default.existsSync(p)) || `${paths_1.scriptsDir}/tsconfig.json`;
102
+ ].find(p => (0, node_fs_1.existsSync)(p));
103
+ const tsconfigPathScripts = [`./scripts/tsconfig.json`].find(p => (0, node_fs_1.existsSync)(p)) || `${paths_1.scriptsDir}/tsconfig.json`;
105
104
  const tsconfigPathE2e = `./e2e/tsconfig.json`;
106
105
  // todo: run on other dirs too, e.g pages, components, layouts
107
106
  if (fix) {
@@ -126,7 +125,7 @@ async function eslintAll(opt) {
126
125
  console.log(`${(0, nodejs_lib_1.boldGrey)('eslint-all')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
127
126
  }
128
127
  async function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = eslintExtensions, fix = true) {
129
- if (!eslintConfigPath || !node_fs_1.default.existsSync(dir))
128
+ if (!eslintConfigPath || !(0, node_fs_1.existsSync)(dir))
130
129
  return; // faster to bail-out like this
131
130
  await nodejs_lib_1.exec2.spawnAsync('eslint', {
132
131
  args: [
@@ -150,7 +149,7 @@ const prettierPaths = [
150
149
  ...lintExclude.map((s) => `!${s}`),
151
150
  ];
152
151
  function runPrettier() {
153
- const prettierConfigPath = [`./prettier.config.js`, `./prettier.config.cjs`].find(f => node_fs_1.default.existsSync(f));
152
+ const prettierConfigPath = [`./prettier.config.js`, `./prettier.config.cjs`].find(f => (0, node_fs_1.existsSync)(f));
154
153
  if (!prettierConfigPath)
155
154
  return;
156
155
  // prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
@@ -172,7 +171,7 @@ function stylelintAll() {
172
171
  default: true,
173
172
  },
174
173
  }).argv;
175
- const config = [`./stylelint.config.js`].find(f => node_fs_1.default.existsSync(f));
174
+ const config = [`./stylelint.config.js`].find(f => (0, node_fs_1.existsSync)(f));
176
175
  if (!config)
177
176
  return;
178
177
  nodejs_lib_1.exec2.spawn('stylelint', {
@@ -183,7 +182,7 @@ function stylelintAll() {
183
182
  async function lintStagedCommand() {
184
183
  const localConfig = `./lint-staged.config.js`;
185
184
  const sharedConfig = `${paths_1.cfgDir}/lint-staged.config.js`;
186
- const config = node_fs_1.default.existsSync(localConfig) ? localConfig : sharedConfig;
185
+ const config = (0, node_fs_1.existsSync)(localConfig) ? localConfig : sharedConfig;
187
186
  const { default: lintStaged } = await import('lint-staged');
188
187
  const success = await lintStaged({
189
188
  configPath: config,
@@ -197,7 +196,7 @@ function runCommitlintCommand() {
197
196
  const cwd = process.cwd();
198
197
  const localConfig = `${cwd}/commitlint.config.js`;
199
198
  const sharedConfig = `${paths_1.cfgDir}/commitlint.config.js`;
200
- const config = node_fs_1.default.existsSync(localConfig) ? localConfig : sharedConfig;
199
+ const config = (0, node_fs_1.existsSync)(localConfig) ? localConfig : sharedConfig;
201
200
  const env = {
202
201
  GIT_BRANCH: nodejs_lib_1.git2.getCurrentBranchName(),
203
202
  };
@@ -210,14 +209,14 @@ function runCommitlintCommand() {
210
209
  });
211
210
  }
212
211
  async function runKTLint() {
213
- if (!node_fs_1.default.existsSync(`node_modules/@naturalcycles/ktlint`))
212
+ if (!(0, node_fs_1.existsSync)(`node_modules/@naturalcycles/ktlint`))
214
213
  return;
215
214
  const ktlintLib = require('@naturalcycles/ktlint');
216
215
  await ktlintLib.ktlintAll();
217
216
  }
218
217
  function runActionLint() {
219
218
  // Only run if there is a folder of `.github/workflows`, otherwise actionlint will fail
220
- if (!node_fs_1.default.existsSync('.github/workflows'))
219
+ if (!(0, node_fs_1.existsSync)('.github/workflows'))
221
220
  return;
222
221
  if (canRunBinary('actionlint')) {
223
222
  requireActionlintVersion();
@@ -247,11 +246,11 @@ function runBiome(fix = true) {
247
246
  // return
248
247
  // }
249
248
  const configPath = `biome.jsonc`;
250
- if (!node_fs_1.default.existsSync(configPath)) {
249
+ if (!(0, node_fs_1.existsSync)(configPath)) {
251
250
  console.log(`biome is skipped, because ./biome.jsonc is not present`);
252
251
  return;
253
252
  }
254
- const dirs = [`src`, `scripts`, `e2e`].filter(d => node_fs_1.default.existsSync(d));
253
+ const dirs = [`src`, `scripts`, `e2e`].filter(d => (0, node_fs_1.existsSync)(d));
255
254
  nodejs_lib_1.exec2.spawn(`biome`, {
256
255
  args: [`lint`, fix && '--write', fix && '--unsafe', '--no-errors-on-unmatched', ...dirs].filter(js_lib_1._isTruthy),
257
256
  logFinish: false,
@@ -260,7 +259,7 @@ function runBiome(fix = true) {
260
259
  }
261
260
  function canRunBinary(name) {
262
261
  try {
263
- node_child_process_1.default.execSync(`which ${name}`);
262
+ (0, node_child_process_1.execSync)(`which ${name}`);
264
263
  return true;
265
264
  }
266
265
  catch {
@@ -269,7 +268,7 @@ function canRunBinary(name) {
269
268
  }
270
269
  function gitStatus() {
271
270
  try {
272
- return node_child_process_1.default.execSync('git status -s', {
271
+ return (0, node_child_process_1.execSync)('git status -s', {
273
272
  encoding: 'utf8',
274
273
  });
275
274
  }
package/dist/paths.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.scriptsDir = exports.cfgOverwriteDir = exports.cfgDir = exports.testDir = exports.srcDir = exports.projectDir = void 0;
4
- const tslib_1 = require("tslib");
5
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
6
- exports.projectDir = node_path_1.default.join(__dirname, '..');
4
+ const node_path_1 = require("node:path");
5
+ exports.projectDir = (0, node_path_1.join)(__dirname, '..');
7
6
  exports.srcDir = `${exports.projectDir}/src`;
8
7
  exports.testDir = `${exports.srcDir}/test`;
9
8
  exports.cfgDir = `${exports.projectDir}/cfg`;
package/dist/test.util.js CHANGED
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runTest = runTest;
4
- const tslib_1 = require("tslib");
5
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
4
+ const node_fs_1 = require("node:fs");
6
5
  const js_lib_1 = require("@naturalcycles/js-lib");
7
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
7
  const paths_1 = require("./paths");
@@ -132,18 +131,18 @@ function runJest(opt) {
132
131
  * Returns true if module with given name exists in _target project's_ node_modules.
133
132
  */
134
133
  function nodeModuleExists(moduleName) {
135
- return node_fs_1.default.existsSync(`./node_modules/${moduleName}`);
134
+ return (0, node_fs_1.existsSync)(`./node_modules/${moduleName}`);
136
135
  }
137
136
  function getJestConfigPath() {
138
- return node_fs_1.default.existsSync(`./jest.config.js`) ? './jest.config.js' : undefined;
137
+ return (0, node_fs_1.existsSync)(`./jest.config.js`) ? './jest.config.js' : undefined;
139
138
  }
140
139
  function getJestIntegrationConfigPath() {
141
- return node_fs_1.default.existsSync(`./jest.integration-test.config.js`)
140
+ return (0, node_fs_1.existsSync)(`./jest.integration-test.config.js`)
142
141
  ? `./jest.integration-test.config.js`
143
142
  : `${paths_1.cfgDir}/jest.integration-test.config.js`;
144
143
  }
145
144
  function getJestManualConfigPath() {
146
- return node_fs_1.default.existsSync(`./jest.manual-test.config.js`)
145
+ return (0, node_fs_1.existsSync)(`./jest.manual-test.config.js`)
147
146
  ? `./jest.manual-test.config.js`
148
147
  : `${paths_1.cfgDir}/jest.manual-test.config.js`;
149
148
  }
@@ -1,6 +1,4 @@
1
- import timekeeper from 'timekeeper';
2
1
  export * from './mockAllKindsOfThings';
3
2
  export * from './testing.util';
4
3
  export * from './testOffline.util';
5
4
  export * from './time.util';
6
- export { timekeeper };
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timekeeper = void 0;
4
3
  const tslib_1 = require("tslib");
5
- const timekeeper_1 = tslib_1.__importDefault(require("timekeeper"));
6
- exports.timekeeper = timekeeper_1.default;
7
4
  tslib_1.__exportStar(require("./mockAllKindsOfThings"), exports);
8
5
  tslib_1.__exportStar(require("./testing.util"), exports);
9
6
  tslib_1.__exportStar(require("./testOffline.util"), exports);
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MOCK_TS_2018_06_21 = void 0;
4
4
  exports.mockTime = mockTime;
5
5
  exports.resetTime = resetTime;
6
- const tslib_1 = require("tslib");
7
- const timekeeper_1 = tslib_1.__importDefault(require("timekeeper"));
8
6
  exports.MOCK_TS_2018_06_21 = 1_529_539_200;
9
7
  /**
10
8
  * Locks time-related functions to return always same time.
11
9
  * For deterministic tests.
12
10
  */
13
11
  function mockTime(ts = exports.MOCK_TS_2018_06_21) {
14
- timekeeper_1.default.freeze(ts * 1000);
12
+ const timekeeper = require('timekeeper');
13
+ timekeeper.freeze(ts * 1000);
15
14
  }
16
15
  function resetTime() {
17
- timekeeper_1.default.reset();
16
+ const timekeeper = require('timekeeper');
17
+ timekeeper.reset();
18
18
  }
package/dist/yarn.util.js CHANGED
@@ -2,14 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.up = up;
4
4
  exports.upnc = upnc;
5
- const tslib_1 = require("tslib");
6
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
5
+ const node_fs_1 = require("node:fs");
7
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
7
  function up() {
9
8
  nodejs_lib_1.exec2.spawn('yarn upgrade');
10
9
  nodejs_lib_1.exec2.spawn('yarn-deduplicate');
11
10
  nodejs_lib_1.exec2.spawn('yarn');
12
- if (node_fs_1.default.existsSync(`node_modules/patch-package`)) {
11
+ if ((0, node_fs_1.existsSync)(`node_modules/patch-package`)) {
13
12
  nodejs_lib_1.exec2.spawn('patch-package');
14
13
  }
15
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "17.1.2",
3
+ "version": "17.2.1",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "tsn-debug": "tsx scripts/testScript.ts",
package/readme.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - ESLint
18
18
  - Biome
19
19
  - Stylelint
20
- - Jest
20
+ - Jest / Vitest
21
21
  - ktlint
22
22
  - actionlint
23
23
  - lint-staged
@@ -218,6 +218,7 @@ These files are meant to be extended in target project, so act as _recommended d
218
218
  - `eslint.config.js`
219
219
  - `biome.jsonc`
220
220
  - `jest.config.js`
221
+ - `vitest.config.mjs`
221
222
 
222
223
  ## eslint
223
224