@naturalcycles/dev-lib 13.38.1 → 13.38.3

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.
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildProdESMCJSCommand = void 0;
4
4
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const exec_util_1 = require("../util/exec.util");
6
5
  // You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
7
6
  const TSCONF_CJS_PATH = `./tsconfig.cjs.prod.json`;
8
7
  const TSCONF_ESM_PATH = `./tsconfig.esm.prod.json`;
@@ -20,8 +19,8 @@ async function buildProdESMCJSCommand() {
20
19
  const cjsPath = cjsExists ? TSCONF_CJS_PATH : TSCONF_PATH;
21
20
  const esmPath = esmExists ? TSCONF_ESM_PATH : TSCONF_PATH;
22
21
  await Promise.all([
23
- (0, exec_util_1.execVoidCommand)('tsc', ['-P', cjsPath, '--outDir', './dist', '--module', 'commonjs']),
24
- (0, exec_util_1.execVoidCommand)('tsc', [
22
+ (0, nodejs_lib_1.execVoidCommand)('tsc', ['-P', cjsPath, '--outDir', './dist', '--module', 'commonjs']),
23
+ (0, nodejs_lib_1.execVoidCommand)('tsc', [
25
24
  '-P',
26
25
  esmPath,
27
26
  '--outDir',
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
3
3
  */
4
- export declare function eslintAllCommand(): void;
4
+ export declare function eslintAllCommand(): Promise<void>;
@@ -2,13 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.eslintAllCommand = void 0;
4
4
  const fs = require("node:fs");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
6
+ const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
5
7
  const yargs = require("yargs");
6
8
  const paths_cnst_1 = require("../cnst/paths.cnst");
7
9
  const lint_util_1 = require("../util/lint.util");
8
10
  /**
9
11
  * Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
10
12
  */
11
- function eslintAllCommand() {
13
+ async function eslintAllCommand() {
14
+ const started = Date.now();
12
15
  const { ext, fix } = yargs.options({
13
16
  ext: {
14
17
  type: 'string',
@@ -29,12 +32,25 @@ function eslintAllCommand() {
29
32
  const tsconfigPathScripts = (0, lint_util_1.getTSConfigPathScripts)();
30
33
  const tsconfigPathE2e = `./e2e/tsconfig.json`;
31
34
  // todo: run on other dirs too, e.g pages, components, layouts
32
- // /src
33
- // await runESLint(`./src`, eslintConfigPathRoot, tsconfigPath, extensions)
34
- (0, lint_util_1.runESLint)(`./src`, eslintConfigPathRoot, undefined, extensions, fix);
35
- // /scripts
36
- (0, lint_util_1.runESLint)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix);
37
- // /e2e
38
- (0, lint_util_1.runESLint)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix);
35
+ if (fix) {
36
+ await Promise.all([
37
+ // /src
38
+ (0, lint_util_1.runESLintAsync)(`./src`, eslintConfigPathRoot, undefined, extensions, fix),
39
+ // /scripts
40
+ (0, lint_util_1.runESLintAsync)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix),
41
+ // /e2e
42
+ (0, lint_util_1.runESLintAsync)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix),
43
+ ]);
44
+ }
45
+ else {
46
+ // with no-fix - let's run serially
47
+ // /src
48
+ await (0, lint_util_1.runESLintAsync)(`./src`, eslintConfigPathRoot, undefined, extensions, fix);
49
+ // /scripts
50
+ await (0, lint_util_1.runESLintAsync)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix);
51
+ // /e2e
52
+ await (0, lint_util_1.runESLintAsync)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix);
53
+ }
54
+ console.log(`${(0, colors_1.boldGrey)('eslint-all')} ${(0, colors_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
39
55
  }
40
56
  exports.eslintAllCommand = eslintAllCommand;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lintAllCommand = void 0;
4
4
  const fs = require("node:fs");
5
+ const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
7
  const yargs = require("yargs");
7
8
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
@@ -12,6 +13,7 @@ const eslint_all_command_1 = require("./eslint-all.command");
12
13
  * We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
13
14
  */
14
15
  async function lintAllCommand() {
16
+ const started = Date.now();
15
17
  const { commitOnChanges, failOnChanges } = yargs.options({
16
18
  commitOnChanges: {
17
19
  type: 'boolean',
@@ -23,7 +25,7 @@ async function lintAllCommand() {
23
25
  },
24
26
  }).argv;
25
27
  const hadChangesBefore = (0, nodejs_lib_1.gitHasUncommittedChanges)();
26
- (0, eslint_all_command_1.eslintAllCommand)();
28
+ await (0, eslint_all_command_1.eslintAllCommand)();
27
29
  if (fs.existsSync(`node_modules/stylelint`) &&
28
30
  fs.existsSync(`node_modules/stylelint-config-standard-scss`)) {
29
31
  (0, stylelint_util_1.stylelintAll)();
@@ -33,6 +35,7 @@ async function lintAllCommand() {
33
35
  const ktlintLib = require('@naturalcycles/ktlint');
34
36
  await ktlintLib.ktlintAll();
35
37
  }
38
+ console.log(`${(0, colors_1.boldGrey)('lint-all')} ${(0, colors_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
36
39
  if (commitOnChanges || failOnChanges) {
37
40
  // detect changes
38
41
  const hasChanges = (0, nodejs_lib_1.gitHasUncommittedChanges)();
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tscProdCommand = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
6
  const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
6
- const exec_util_1 = require("../util/exec.util");
7
7
  function tscProdCommand() {
8
8
  // You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
9
9
  const projectTsconfigPath = `./tsconfig.prod.json`;
10
10
  const args = ['-P', projectTsconfigPath];
11
11
  const started = Date.now();
12
- (0, exec_util_1.execVoidCommandSync)(`tsc`, args);
12
+ (0, nodejs_lib_1.execVoidCommandSync)(`tsc`, args);
13
13
  console.log(`${(0, colors_1.boldGrey)('tsc prod')} ${(0, colors_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
14
14
  }
15
15
  exports.tscProdCommand = tscProdCommand;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runJest = exports.isRunningAllTests = exports.getJestManualConfigPath = exports.getJestIntegrationConfigPath = exports.getJestConfigPath = void 0;
4
4
  const fs = require("node:fs");
5
5
  const os = require("node:os");
6
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
7
  const js_lib_1 = require("@naturalcycles/js-lib");
7
8
  const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
8
9
  const paths_cnst_1 = require("../cnst/paths.cnst");
9
- const exec_util_1 = require("./exec.util");
10
10
  const test_util_1 = require("./test.util");
11
11
  function getJestConfigPath() {
12
12
  return fs.existsSync(`./jest.config.js`) ? './jest.config.js' : `${paths_cnst_1.cfgDir}/jest.config.js`;
@@ -128,13 +128,13 @@ function runJest(opt = {}) {
128
128
  const totalShards = Number(JEST_SHARDS);
129
129
  const shards = (0, js_lib_1._range)(1, totalShards + 1);
130
130
  for (const shard of shards) {
131
- (0, exec_util_1.execVoidCommandSync)('jest', (0, js_lib_1._uniq)([...args, `--shard=${shard}/${totalShards}`]), {
131
+ (0, nodejs_lib_1.execVoidCommandSync)('jest', (0, js_lib_1._uniq)([...args, `--shard=${shard}/${totalShards}`]), {
132
132
  env,
133
133
  });
134
134
  }
135
135
  }
136
136
  else {
137
- (0, exec_util_1.execVoidCommandSync)('jest', (0, js_lib_1._uniq)(args), {
137
+ (0, nodejs_lib_1.execVoidCommandSync)('jest', (0, js_lib_1._uniq)(args), {
138
138
  env,
139
139
  });
140
140
  }
@@ -1,3 +1,4 @@
1
1
  export declare function getTSConfigPath(): string;
2
2
  export declare function getTSConfigPathScripts(): string;
3
- export declare function runESLint(dir: string, eslintConfigPath: string, tsconfigPath: string | undefined, extensions?: string[], fix?: boolean): void;
3
+ export declare function runESLint(dir: string, eslintConfigPath: string, tsconfigPath?: string, extensions?: string[], fix?: boolean): void;
4
+ export declare function runESLintAsync(dir: string, eslintConfigPath: string, tsconfigPath?: string, extensions?: string[], fix?: boolean): Promise<void>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runESLint = exports.getTSConfigPathScripts = exports.getTSConfigPath = void 0;
3
+ exports.runESLintAsync = exports.runESLint = exports.getTSConfigPathScripts = exports.getTSConfigPath = void 0;
4
4
  const fs = require("node:fs");
5
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
6
  const paths_cnst_1 = require("../cnst/paths.cnst");
6
- const exec_util_1 = require("./exec.util");
7
7
  function getTSConfigPath() {
8
8
  // this is to support "Solution style tsconfig.json" (as used in Angular10, for example)
9
9
  // return [`./tsconfig.base.json`].find(p => fs.existsSync(p)) || `./tsconfig.json`
@@ -17,7 +17,17 @@ exports.getTSConfigPathScripts = getTSConfigPathScripts;
17
17
  function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
18
18
  if (!fs.existsSync(dir))
19
19
  return; // faster to bail-out like this
20
- const args = [
20
+ (0, nodejs_lib_1.execVoidCommandSync)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix));
21
+ }
22
+ exports.runESLint = runESLint;
23
+ async function runESLintAsync(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
24
+ if (!fs.existsSync(dir))
25
+ return; // faster to bail-out like this
26
+ await (0, nodejs_lib_1.execVoidCommand)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix));
27
+ }
28
+ exports.runESLintAsync = runESLintAsync;
29
+ function getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
30
+ return [
21
31
  `--config`,
22
32
  eslintConfigPath,
23
33
  `${dir}/**/*.{${extensions.join(',')}}`,
@@ -26,6 +36,4 @@ function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx
26
36
  `--report-unused-disable-directives`,
27
37
  fix ? `--fix` : '',
28
38
  ].filter(Boolean);
29
- (0, exec_util_1.execVoidCommandSync)('eslint', args);
30
39
  }
31
- exports.runESLint = runESLint;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runPrettier = void 0;
4
4
  const fs = require("node:fs");
5
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
6
  const paths_cnst_1 = require("../cnst/paths.cnst");
6
- const exec_util_1 = require("./exec.util");
7
7
  const { prettierDirs, prettierExtensionsAll, lintExclude } = require('../../cfg/_cnst');
8
8
  const prettierPaths = [
9
9
  // Everything inside these folders
@@ -18,6 +18,6 @@ function runPrettier() {
18
18
  const prettierConfigPath = [`./prettier.config.js`].find(f => fs.existsSync(f)) || `${paths_cnst_1.cfgDir}/prettier.config.js`;
19
19
  // prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
20
20
  const args = [`--write`, `--log-level=warn`, `--config`, prettierConfigPath, ...prettierPaths];
21
- (0, exec_util_1.execVoidCommandSync)('prettier', args);
21
+ (0, nodejs_lib_1.execVoidCommandSync)('prettier', args);
22
22
  }
23
23
  exports.runPrettier = runPrettier;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stylelintAll = exports.stylelintPaths = void 0;
4
4
  const fs = require("node:fs");
5
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
6
  const yargs = require("yargs");
6
7
  const paths_cnst_1 = require("../cnst/paths.cnst");
7
- const exec_util_1 = require("./exec.util");
8
8
  const { prettierDirs, stylelintExtensions, lintExclude } = require('../../cfg/_cnst');
9
9
  exports.stylelintPaths = [
10
10
  // Everything inside these folders
@@ -27,6 +27,6 @@ function stylelintAll() {
27
27
  config,
28
28
  ...exports.stylelintPaths,
29
29
  ].filter(Boolean);
30
- (0, exec_util_1.execVoidCommandSync)('stylelint', args);
30
+ (0, nodejs_lib_1.execVoidCommandSync)('stylelint', args);
31
31
  }
32
32
  exports.stylelintAll = stylelintAll;
@@ -2,11 +2,11 @@
2
2
  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 fs = require("node:fs");
5
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
7
  const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
7
8
  const fs_1 = require("@naturalcycles/nodejs-lib/dist/fs");
8
9
  const paths_cnst_1 = require("../cnst/paths.cnst");
9
- const exec_util_1 = require("./exec.util");
10
10
  async function tscMainAndScripts(noEmit = false) {
11
11
  await Promise.all([tscAsync(noEmit), tscScriptsAsync()]);
12
12
  }
@@ -14,14 +14,14 @@ exports.tscMainAndScripts = tscMainAndScripts;
14
14
  function tsc(noEmit = false) {
15
15
  const started = Date.now();
16
16
  const args = [noEmit && '--noEmit'].filter(js_lib_1._isTruthy);
17
- (0, exec_util_1.execVoidCommandSync)('tsc', args);
17
+ (0, nodejs_lib_1.execVoidCommandSync)('tsc', args);
18
18
  console.log(`${(0, colors_1.boldGrey)('tsc')} ${(0, colors_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
19
19
  }
20
20
  exports.tsc = tsc;
21
21
  async function tscAsync(noEmit = false) {
22
22
  const started = Date.now();
23
23
  const args = [noEmit && '--noEmit'].filter(js_lib_1._isTruthy);
24
- await (0, exec_util_1.execVoidCommand)('tsc', args);
24
+ await (0, nodejs_lib_1.execVoidCommand)('tsc', args);
25
25
  console.log(`${(0, colors_1.boldGrey)('tsc')} ${(0, colors_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
26
26
  }
27
27
  exports.tscAsync = tscAsync;
@@ -33,7 +33,7 @@ function tscScripts() {
33
33
  const projectTsconfigPath = ensureProjectTsconfigScripts();
34
34
  const args = ['-P', projectTsconfigPath, '--noEmit'];
35
35
  const started = Date.now();
36
- (0, exec_util_1.execVoidCommandSync)(`tsc`, args);
36
+ (0, nodejs_lib_1.execVoidCommandSync)(`tsc`, args);
37
37
  console.log(`${(0, colors_1.boldGrey)('tsc scripts')} ${(0, colors_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
38
38
  }
39
39
  exports.tscScripts = tscScripts;
@@ -45,7 +45,7 @@ async function tscScriptsAsync() {
45
45
  const projectTsconfigPath = ensureProjectTsconfigScripts();
46
46
  const args = ['-P', projectTsconfigPath, '--noEmit'];
47
47
  const started = Date.now();
48
- await (0, exec_util_1.execVoidCommand)(`tsc`, args);
48
+ await (0, nodejs_lib_1.execVoidCommand)(`tsc`, args);
49
49
  console.log(`${(0, colors_1.boldGrey)('tsc scripts')} ${(0, colors_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
50
50
  }
51
51
  exports.tscScriptsAsync = tscScriptsAsync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "13.38.1",
3
+ "version": "13.38.3",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "tsn-debug": "tsn testScript.ts",
@@ -1,4 +0,0 @@
1
- /// <reference types="node" />
2
- import { SpawnOptions } from 'node:child_process';
3
- export declare function execVoidCommand(cmd: string, args?: string[], opt?: SpawnOptions): Promise<void>;
4
- export declare function execVoidCommandSync(cmd: string, args?: string[], opt?: SpawnOptions): void;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.execVoidCommandSync = exports.execVoidCommand = void 0;
4
- const cp = require("node:child_process");
5
- const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
6
- async function execVoidCommand(cmd, args = [], opt = {}) {
7
- logExec(cmd, args, opt);
8
- await new Promise(resolve => {
9
- const p = cp.spawn(cmd, [...args], {
10
- stdio: 'inherit',
11
- // shell: true,
12
- ...opt,
13
- env: {
14
- ...process.env,
15
- ...opt.env,
16
- },
17
- });
18
- p.on('close', code => {
19
- if (code) {
20
- console.log(`${cmd} exited with code ${code}`);
21
- process.exit(code);
22
- }
23
- resolve();
24
- });
25
- });
26
- }
27
- exports.execVoidCommand = execVoidCommand;
28
- function execVoidCommandSync(cmd, args = [], opt = {}) {
29
- logExec(cmd, args, opt);
30
- const r = cp.spawnSync(cmd, [...args], {
31
- encoding: 'utf8',
32
- stdio: 'inherit',
33
- // shell: true, // removing shell breaks executing `tsc`
34
- ...opt,
35
- env: {
36
- ...process.env,
37
- ...opt.env,
38
- },
39
- });
40
- if (r.status) {
41
- console.log(`${cmd} exited with code ${r.status}`);
42
- process.exit(r.status);
43
- }
44
- if (r.error) {
45
- console.log(r.error);
46
- process.exit(r.error.errno || 1);
47
- }
48
- }
49
- exports.execVoidCommandSync = execVoidCommandSync;
50
- function logExec(cmd, args = [], opt = {}) {
51
- const cmdline = [
52
- ...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('=')),
53
- cmd,
54
- ...args,
55
- ].join(' ');
56
- console.log((0, colors_1.grey)(cmdline));
57
- }