@naturalcycles/dev-lib 12.13.4 → 12.15.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.
@@ -3,11 +3,12 @@
3
3
  * Extendable.
4
4
  */
5
5
 
6
+ const fs = require('fs')
7
+
6
8
  const runInIDE = process.argv.includes('--runTestsByPath')
7
9
  const ideIntegrationTest = runInIDE && process.argv.some(a => a.endsWith('.integration.test.ts'))
8
10
  const ideManualTest = runInIDE && process.argv.some(a => a.endsWith('.manual.test.ts'))
9
-
10
- const fs = require('fs')
11
+ const { CI } = process.env
11
12
  const cwd = process.cwd()
12
13
 
13
14
  // Set 'setupFilesAfterEnv' only if it exists
@@ -106,9 +107,13 @@ module.exports = {
106
107
  '!**/*.component.ts',
107
108
  '!**/*.modal.ts',
108
109
  ],
110
+ // default: ["clover", "json", "lcov", "text"]
111
+ coverageReporters: ['clover', 'json', 'lcov', !CI && 'text'].filter(Boolean),
112
+ // CI: only jest-junit reporter (no default)
113
+ // not-CI: only default reporter, but not jest-junit
109
114
  reporters: [
110
115
  'default',
111
- [
116
+ CI && [
112
117
  'jest-junit',
113
118
  {
114
119
  suiteName: 'jest tests',
@@ -120,5 +125,5 @@ module.exports = {
120
125
  ancestorSeparator: ' ',
121
126
  },
122
127
  ],
123
- ],
128
+ ].filter(Boolean),
124
129
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  const fs = require('fs')
7
+ const { CI } = process.env
7
8
  const cwd = process.cwd()
8
9
 
9
10
  // Set 'setupFilesAfterEnv' only if it exists
@@ -21,10 +22,9 @@ module.exports = {
21
22
  testMatch: ['<rootDir>/src/**/*.integration.test.ts'],
22
23
  testPathIgnorePatterns: ['<rootDir>/.*/__exclude/'],
23
24
  setupFilesAfterEnv,
24
- coverageDirectory: 'tmp/coverage-integration',
25
25
  reporters: [
26
26
  'default',
27
- [
27
+ CI && [
28
28
  'jest-junit',
29
29
  {
30
30
  suiteName: 'jest tests',
@@ -36,5 +36,5 @@ module.exports = {
36
36
  ancestorSeparator: ' ',
37
37
  },
38
38
  ],
39
- ],
39
+ ].filter(Boolean),
40
40
  }
@@ -21,7 +21,5 @@ module.exports = {
21
21
  testMatch: ['<rootDir>/src/**/*.manual.test.ts'],
22
22
  testPathIgnorePatterns: ['<rootDir>/.*/__exclude/'],
23
23
  setupFilesAfterEnv,
24
- // Should never need coverage or reporters, but anyway
25
- coverageDirectory: 'tmp/coverage-manual',
26
24
  reporters: ['default'],
27
25
  }
@@ -79,7 +79,14 @@ const linters = {
79
79
  '**/*.{kt,kts}': match => {
80
80
  const filesList = micromatch.not(match, lintExclude).join(' ')
81
81
  if (!filesList) return []
82
- return [`ktlint -F ${filesList}`]
82
+ const dir = './node_modules/@naturalcycles/ktlint'
83
+
84
+ if (!fs.existsSync(dir)) {
85
+ console.log(`!!\n!! Please install @naturalcycles/ktlint to lint *.kt files\n!!\n`, filesList)
86
+ return []
87
+ }
88
+
89
+ return [`${dir}/resources/ktlint -F ${filesList}`]
83
90
  },
84
91
  }
85
92
 
@@ -14,35 +14,39 @@ end_of_line = lf
14
14
  trim_trailing_whitespace = true
15
15
  insert_final_newline = true
16
16
 
17
- [**.md]
17
+ [*.md]
18
18
  trim_trailing_whitespace = false
19
19
  indent_size = 4
20
20
 
21
- [**.html]
21
+ [*.html]
22
22
  indent_size = 2
23
23
 
24
- [**.{css,scss}]
24
+ [*.{css,scss}]
25
25
  indent_size = 2
26
26
 
27
- [**.{js,ts}]
27
+ [*.{js,ts}]
28
28
  indent_size = 2
29
29
 
30
- [**.json]
30
+ [*.json]
31
31
  indent_size = 2
32
32
 
33
- [**.xml]
34
- indent_size = 2
35
-
36
- [**.java]
33
+ [*.java]
37
34
  indent_size = 4
38
35
 
39
- [**.sql]
36
+ [*.{kt,kts}]
37
+ disabled_rules=no-wildcard-imports
38
+ ij_kotlin_imports_layout=*,java.**,javax.**,kotlin.**,^ # default IntelliJ IDEA style, same as alphabetical, but with "java", "javax", "kotlin" and alias imports in the end of the imports list
39
+
40
+ [*.xml]
41
+ indent_size = 2
42
+
43
+ [*.sql]
40
44
  indent_size = 2
41
45
 
42
46
  [.eslintrc]
43
47
  indent_size = 2
44
48
 
45
- [**.min.*]
49
+ [*.min.*]
46
50
  indent_style = ignore
47
51
  trim_trailing_whitespace = false
48
52
  insert_final_newline = ignore
package/dist/bin/bt.js CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const fs = require("fs");
4
+ const fs = require("fs-extra");
5
5
  const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
6
6
  const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
7
7
  const jest_util_1 = require("../util/jest.util");
8
8
  const tsc_util_1 = require("../util/tsc.util");
9
9
  (0, script_1.runScript)(async () => {
10
- fs.rmSync('./dist', { recursive: true, force: true });
10
+ fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
11
+ // fs.rmSync('./dist', { recursive: true, force: true })
11
12
  await (0, tsc_util_1.tsc)();
12
13
  await (0, tsc_scripts_command_1.tscScriptsCommand)();
13
14
  await (0, jest_util_1.runJest)();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const fs = require("fs-extra");
5
+ const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
6
+ const lint_all_command_1 = require("../cmd/lint-all.command");
7
+ const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
8
+ const jest_util_1 = require("../util/jest.util");
9
+ const tsc_util_1 = require("../util/tsc.util");
10
+ (0, script_1.runScript)(async () => {
11
+ await (0, lint_all_command_1.lintAllCommand)();
12
+ fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
13
+ // fs.rmSync('./dist', { recursive: true, force: true })
14
+ await (0, tsc_util_1.tsc)();
15
+ await (0, tsc_scripts_command_1.tscScriptsCommand)();
16
+ await (0, jest_util_1.runJest)();
17
+ });
package/dist/bin/build.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const fs = require("fs");
4
+ const fs = require("fs-extra");
5
5
  const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
6
6
  const tsc_scripts_command_1 = require("../cmd/tsc-scripts.command");
7
7
  const tsc_util_1 = require("../util/tsc.util");
8
8
  (0, script_1.runScript)(async () => {
9
- fs.rmSync('./dist', { recursive: true, force: true });
9
+ fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
10
+ // fs.rmSync('./dist', { recursive: true, force: true })
10
11
  await (0, tsc_util_1.tsc)();
11
12
  await (0, tsc_scripts_command_1.tscScriptsCommand)();
12
13
  });
@@ -4,5 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
5
5
  const jest_util_1 = require("../util/jest.util");
6
6
  (0, script_1.runScript)(async () => {
7
- await (0, jest_util_1.runJest)({ ci: true });
7
+ console.log('! "yarn test-ci" is deprecated, use plain `yarn test` instead !');
8
+ await (0, jest_util_1.runJest)();
8
9
  });
@@ -4,5 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
5
5
  const jest_util_1 = require("../util/jest.util");
6
6
  (0, script_1.runScript)(async () => {
7
- await (0, jest_util_1.runJest)({ integration: true, ci: true });
7
+ console.log('! "yarn test-integration-ci" is deprecated, use plain `yarn test-integration` instead !');
8
+ await (0, jest_util_1.runJest)({ integration: true });
8
9
  });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildProdESMCJSCommand = void 0;
4
- const fs = require("fs");
4
+ const fs = require("fs-extra");
5
5
  const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
6
6
  // You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
7
7
  const TSCONF_CJS_PATH = `./tsconfig.cjs.prod.json`;
@@ -11,8 +11,11 @@ async function buildProdESMCJSCommand() {
11
11
  const [cjsExists, esmExists] = [
12
12
  fs.existsSync(TSCONF_CJS_PATH),
13
13
  fs.existsSync(TSCONF_ESM_PATH),
14
- fs.rmSync('./dist', { recursive: true, force: true }),
15
- fs.rmSync('./dist-esm', { recursive: true, force: true }),
14
+ // it doesn't delete the dir itself, to prevent IDE jumping
15
+ fs.emptyDirSync('./dist'),
16
+ fs.emptyDirSync('./dist-esm'),
17
+ // fs.rmSync('./dist', { recursive: true, force: true }),
18
+ // fs.rmSync('./dist-esm', { recursive: true, force: true }),
16
19
  ];
17
20
  const cjsPath = cjsExists ? TSCONF_CJS_PATH : TSCONF_PATH;
18
21
  const esmPath = esmExists ? TSCONF_ESM_PATH : TSCONF_PATH;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildProdCommand = void 0;
4
- const fs = require("fs");
4
+ const fs = require("fs-extra");
5
5
  const build_copy_command_1 = require("./build-copy.command");
6
6
  const tsc_prod_command_1 = require("./tsc-prod.command");
7
7
  async function buildProdCommand() {
8
- fs.rmSync('./dist', { recursive: true, force: true });
8
+ fs.emptyDirSync('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
9
+ // fs.rmSync('./dist', { recursive: true, force: true })
9
10
  (0, build_copy_command_1.buildCopyCommand)();
10
11
  await (0, tsc_prod_command_1.tscProdCommand)();
11
12
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lintAllCommand = void 0;
4
+ const fs = require("fs");
4
5
  const yargs = require("yargs");
5
6
  const git_util_1 = require("../util/git.util");
6
7
  const prettier_util_1 = require("../util/prettier.util");
@@ -21,10 +22,14 @@ async function lintAllCommand() {
21
22
  },
22
23
  }).argv;
23
24
  const hadChangesBefore = await (0, git_util_1.gitHasUncommittedChanges)();
24
- // Currently we position ESLint before TSLint, but let's monitor if it's ok
25
25
  await (0, eslint_all_command_1.eslintAllCommand)();
26
26
  await (0, stylelint_util_1.stylelintAll)();
27
27
  await (0, prettier_util_1.runPrettier)();
28
+ // Running ktlintAll (experimental!)
29
+ if (fs.existsSync(`node_modules/@naturalcycles/ktlint`)) {
30
+ const ktlintLib = require('@naturalcycles/ktlint');
31
+ await ktlintLib.ktlintAll();
32
+ }
28
33
  if (commitOnChanges || failOnChanges) {
29
34
  // detect changes
30
35
  const hasChanges = await (0, git_util_1.gitHasUncommittedChanges)();
@@ -33,9 +38,7 @@ async function lintAllCommand() {
33
38
  console.log(`lint-all: there are changes before running lint-all, will not commit`);
34
39
  }
35
40
  else {
36
- const msg = 'style(lint-all): ' +
37
- (0, git_util_1.commitMessageToTitleMessage)(await (0, git_util_1.getLastGitCommitMsg)()) +
38
- '\n\n[skip ci]';
41
+ const msg = 'style(ci): ' + (0, git_util_1.commitMessageToTitleMessage)(await (0, git_util_1.getLastGitCommitMsg)()) + '\n\n[skip ci]';
39
42
  // pull, commit, push changes
40
43
  await (0, git_util_1.gitPull)();
41
44
  await (0, git_util_1.gitCommitAll)(msg);
@@ -1,12 +1,11 @@
1
- export declare function getJestConfigPath(): string | undefined;
2
- export declare function getJestIntegrationConfigPath(): string | undefined;
3
- export declare function getJestManualConfigPath(): string | undefined;
1
+ export declare function getJestConfigPath(): string;
2
+ export declare function getJestIntegrationConfigPath(): string;
3
+ export declare function getJestManualConfigPath(): string;
4
4
  /**
5
5
  * Detects if jest is run with all tests, or with specific tests.
6
6
  */
7
7
  export declare function isRunningAllTests(): boolean;
8
8
  interface RunJestOpt {
9
- ci?: boolean;
10
9
  integration?: boolean;
11
10
  manual?: boolean;
12
11
  leaks?: boolean;
@@ -8,7 +8,7 @@ const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
8
8
  const paths_cnst_1 = require("../cnst/paths.cnst");
9
9
  const test_util_1 = require("./test.util");
10
10
  function getJestConfigPath() {
11
- return fs.existsSync(`./jest.config.js`) ? undefined : `${paths_cnst_1.cfgDir}/jest.config.js`;
11
+ return fs.existsSync(`./jest.config.js`) ? './jest.config.js' : `${paths_cnst_1.cfgDir}/jest.config.js`;
12
12
  }
13
13
  exports.getJestConfigPath = getJestConfigPath;
14
14
  function getJestIntegrationConfigPath() {
@@ -41,16 +41,9 @@ async function runJest(opt = {}) {
41
41
  console.log((0, colors_1.dimGrey)(`node_modules/${(0, colors_1.white)('jest')} not found, skipping tests`));
42
42
  return;
43
43
  }
44
- const { ci, integration, manual, leaks } = opt;
44
+ const { CI, TZ = 'UTC', APP_ENV, JEST_NO_ALPHABETIC, NODE_OPTIONS } = process.env;
45
+ const { integration, manual, leaks } = opt;
45
46
  const processArgs = process.argv.slice(2);
46
- // console.log(processArgs) // todo: solve to run it in dev-lib
47
- // Allow to override --maxWorkers
48
- let maxWorkers = processArgs.find(a => a.startsWith('--maxWorkers'));
49
- const args = ['--logHeapUsage', '--passWithNoTests', ...processArgs];
50
- const env = {
51
- TZ: process.env.TZ || 'UTC',
52
- DEBUG_COLORS: '1',
53
- };
54
47
  let jestConfig;
55
48
  if (manual) {
56
49
  jestConfig = getJestManualConfigPath();
@@ -61,20 +54,35 @@ async function runJest(opt = {}) {
61
54
  else {
62
55
  jestConfig = getJestConfigPath();
63
56
  }
64
- if (jestConfig) {
65
- args.push(`--config=${jestConfig}`);
66
- }
67
- if (ci) {
68
- args.push('--ci', '--coverage');
69
- maxWorkers = maxWorkers || '--maxWorkers=2';
57
+ // Allow to override --maxWorkers
58
+ let maxWorkers = processArgs.find(a => a.startsWith('--maxWorkers'));
59
+ const args = [
60
+ `--config=${jestConfig}`,
61
+ '--logHeapUsage',
62
+ '--passWithNoTests',
63
+ ...processArgs,
64
+ ];
65
+ const env = {
66
+ TZ,
67
+ DEBUG_COLORS: '1',
68
+ };
69
+ if (CI) {
70
+ args.push('--ci');
71
+ if (!integration && !manual) {
72
+ // Coverage only makes sense for unit tests, not for integration/manual
73
+ args.push('--coverage');
74
+ }
75
+ // We used to default to 2, but due to memory being an issue for Jest - now we default to 1,
76
+ // as it's the most memory-efficient way
77
+ maxWorkers || (maxWorkers = '--maxWorkers=1');
70
78
  }
71
79
  // Running all tests - will use `--silent` to suppress console-logs, will also set process.env.JEST_SILENT=1
72
- if (ci || isRunningAllTests()) {
80
+ if (CI || isRunningAllTests()) {
73
81
  args.push('--silent');
74
82
  }
75
83
  if (leaks) {
76
84
  args.push('--detectOpenHandles', '--detectLeaks');
77
- maxWorkers = maxWorkers || '--maxWorkers=1';
85
+ maxWorkers || (maxWorkers = '--maxWorkers=1');
78
86
  }
79
87
  if (maxWorkers)
80
88
  args.push(maxWorkers);
@@ -83,15 +91,14 @@ async function runJest(opt = {}) {
83
91
  JEST_SILENT: '1',
84
92
  });
85
93
  }
86
- if (!integration && !manual && !process.env['APP_ENV']) {
94
+ if (!integration && !manual && !APP_ENV) {
87
95
  Object.assign(env, {
88
96
  APP_ENV: 'test',
89
97
  });
90
98
  }
91
- if (!process.env['JEST_NO_ALPHABETIC']) {
99
+ if (!JEST_NO_ALPHABETIC) {
92
100
  args.push(`--testSequencer=${paths_cnst_1.cfgDir}/jest.alphabetic.sequencer.js`);
93
101
  }
94
- const { NODE_OPTIONS } = process.env;
95
102
  if (NODE_OPTIONS) {
96
103
  console.log(`${(0, colors_1.dimGrey)('NODE_OPTIONS: ' + NODE_OPTIONS)}`);
97
104
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "12.13.4",
3
+ "version": "12.15.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "tsn-debug": "tsn testScript.ts",
7
7
  "bt": "tsn ./src/bin/bt.ts",
8
+ "btl": "tsn ./src/bin/btl.ts",
8
9
  "build": "tsn ./src/bin/build.ts",
9
10
  "tsc-prod": "tsn ./src/bin/tsc-prod.ts",
10
11
  "tsc-scripts": "tsn ./src/bin/tsc-scripts.ts",
@@ -77,6 +78,7 @@
77
78
  "types": "dist/index.d.ts",
78
79
  "bin": {
79
80
  "bt": "dist/bin/bt.js",
81
+ "btl": "dist/bin/btl.js",
80
82
  "build": "dist/bin/build.js",
81
83
  "build-copy": "dist/bin/build-copy.js",
82
84
  "build-prod": "dist/bin/build-prod.js",
package/readme.md CHANGED
@@ -67,6 +67,7 @@ These commands are available to be called as `yarn <command>`, because they are
67
67
  - `build`: "Development build". Checks that "everything compiles". Does
68
68
  `del ./dist && tsc && tsc-scripts`
69
69
  - `bt`: "Build & Test". Does `del ./dist && tsc && tsc-scripts && test`
70
+ - `btl`: "Build, Test & Lint". Does `lint-all && tsc && test`
70
71
 
71
72
  - `build-copy`: copies _additional files_ into `dist` folder (e.g `*.json`)
72
73
  - `build-prod`: "Production build". Does `del ./dist && build-copy && tsc-prod`
@@ -96,11 +97,10 @@ All test commands set `TZ=UTC`. You can override it by providing `TZ` env variab
96
97
  running a test command. Adds `APP_ENV=test` env var (for all runs except integration). Automatically
97
98
  adds `--silent` (and `JEST_SILENT` env var) if all tests are run.
98
99
 
99
- - `test`: runs unit tests (all tests _except_ `*.integration.test.ts` and `*.manual.test.ts`)
100
- - `test-ci`: runs test in CI environment, with coverage. Includes fix for "CircleCI out of memory
101
- issue"
100
+ - `test`: runs unit tests (all tests _except_ `*.integration.test.ts` and `*.manual.test.ts`).
101
+ Detects `CI` env variable, adds `--coverage` if in CI. Uses `default` reporter in `!CI`, otherwise
102
+ `jest-junit` reporter. Includes fix for "CircleCI out of memory issue"
102
103
  - `test-integration`: runs `*.integration.test.ts` with `jest.integration-test.config.js` config.
103
- - `test-integration-ci`
104
104
  - `test-manual`: runs `*.manual.test.ts` with `jest.manual-test.config.js`.
105
105
  - `test-leaks`: runs Jest with `--logHeapUsage --detectOpenHandles --detectLeaks` (requires `weak`
106
106
  module to be installed in target project).
@@ -149,11 +149,10 @@ Pass `--ext` (e.g `--ext ts,html`) to override the list of ESLint extensions (de
149
149
 
150
150
  `ktlint` will be used by lint-staged for all `**/*.{kt,kts}` files.
151
151
 
152
- Please install it with `brew install ktlint`.
152
+ ~~Please install it with `brew install ktlint`.~~
153
153
 
154
- Currently `ktlint` has a bug of not supporting absolute paths, to work around it use
155
- [this instruction](https://github.com/pinterest/ktlint/issues/1131#issuecomment-947570851) to
156
- install a working version.
154
+ Install it **locally** in you project by adding
155
+ [`@naturalcycles/ktlint`](https://github.com/NaturalCycles/ktlint) to your **dev**Dependencies.
157
156
 
158
157
  #### Other commands
159
158