@naturalcycles/dev-lib 13.38.0 → 13.38.2
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/dist/cmd/build-prod-esm-cjs.command.js +2 -3
- package/dist/cmd/eslint-all.command.d.ts +1 -1
- package/dist/cmd/eslint-all.command.js +20 -8
- package/dist/cmd/lint-all.command.js +1 -1
- package/dist/cmd/tsc-prod.command.js +2 -2
- package/dist/util/jest.util.js +3 -3
- package/dist/util/lint.util.d.ts +2 -1
- package/dist/util/lint.util.js +13 -5
- package/dist/util/prettier.util.js +2 -2
- package/dist/util/stylelint.util.js +2 -2
- package/dist/util/tsc.util.js +5 -5
- package/package.json +1 -1
- package/dist/util/exec.util.d.ts +0 -4
- package/dist/util/exec.util.js +0 -56
|
@@ -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,
|
|
24
|
-
(0,
|
|
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',
|
|
@@ -8,7 +8,7 @@ const lint_util_1 = require("../util/lint.util");
|
|
|
8
8
|
/**
|
|
9
9
|
* Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
|
|
10
10
|
*/
|
|
11
|
-
function eslintAllCommand() {
|
|
11
|
+
async function eslintAllCommand() {
|
|
12
12
|
const { ext, fix } = yargs.options({
|
|
13
13
|
ext: {
|
|
14
14
|
type: 'string',
|
|
@@ -29,12 +29,24 @@ function eslintAllCommand() {
|
|
|
29
29
|
const tsconfigPathScripts = (0, lint_util_1.getTSConfigPathScripts)();
|
|
30
30
|
const tsconfigPathE2e = `./e2e/tsconfig.json`;
|
|
31
31
|
// todo: run on other dirs too, e.g pages, components, layouts
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
if (fix) {
|
|
33
|
+
await Promise.all([
|
|
34
|
+
// /src
|
|
35
|
+
(0, lint_util_1.runESLintAsync)(`./src`, eslintConfigPathRoot, undefined, extensions, fix),
|
|
36
|
+
// /scripts
|
|
37
|
+
(0, lint_util_1.runESLintAsync)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix),
|
|
38
|
+
// /e2e
|
|
39
|
+
(0, lint_util_1.runESLintAsync)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// with no-fix - let's run serially
|
|
44
|
+
// /src
|
|
45
|
+
await (0, lint_util_1.runESLintAsync)(`./src`, eslintConfigPathRoot, undefined, extensions, fix);
|
|
46
|
+
// /scripts
|
|
47
|
+
await (0, lint_util_1.runESLintAsync)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix);
|
|
48
|
+
// /e2e
|
|
49
|
+
await (0, lint_util_1.runESLintAsync)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix);
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
52
|
exports.eslintAllCommand = eslintAllCommand;
|
|
@@ -23,7 +23,7 @@ async function lintAllCommand() {
|
|
|
23
23
|
},
|
|
24
24
|
}).argv;
|
|
25
25
|
const hadChangesBefore = (0, nodejs_lib_1.gitHasUncommittedChanges)();
|
|
26
|
-
(0, eslint_all_command_1.eslintAllCommand)();
|
|
26
|
+
await (0, eslint_all_command_1.eslintAllCommand)();
|
|
27
27
|
if (fs.existsSync(`node_modules/stylelint`) &&
|
|
28
28
|
fs.existsSync(`node_modules/stylelint-config-standard-scss`)) {
|
|
29
29
|
(0, stylelint_util_1.stylelintAll)();
|
|
@@ -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,
|
|
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;
|
package/dist/util/jest.util.js
CHANGED
|
@@ -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,
|
|
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,
|
|
137
|
+
(0, nodejs_lib_1.execVoidCommandSync)('jest', (0, js_lib_1._uniq)(args), {
|
|
138
138
|
env,
|
|
139
139
|
});
|
|
140
140
|
}
|
package/dist/util/lint.util.d.ts
CHANGED
|
@@ -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
|
|
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>;
|
package/dist/util/lint.util.js
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
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,
|
|
30
|
+
(0, nodejs_lib_1.execVoidCommandSync)('stylelint', args);
|
|
31
31
|
}
|
|
32
32
|
exports.stylelintAll = stylelintAll;
|
package/dist/util/tsc.util.js
CHANGED
|
@@ -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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
package/dist/util/exec.util.d.ts
DELETED
|
@@ -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;
|
package/dist/util/exec.util.js
DELETED
|
@@ -1,56 +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
|
-
return resolve();
|
|
21
|
-
console.log(`${cmd} exited with code ${code}`);
|
|
22
|
-
process.exit(code);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.execVoidCommand = execVoidCommand;
|
|
27
|
-
function execVoidCommandSync(cmd, args = [], opt = {}) {
|
|
28
|
-
logExec(cmd, args, opt);
|
|
29
|
-
const r = cp.spawnSync(cmd, [...args], {
|
|
30
|
-
encoding: 'utf8',
|
|
31
|
-
stdio: 'inherit',
|
|
32
|
-
// shell: true, // removing shell breaks executing `tsc`
|
|
33
|
-
...opt,
|
|
34
|
-
env: {
|
|
35
|
-
...process.env,
|
|
36
|
-
...opt.env,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
if (r.status) {
|
|
40
|
-
console.log(`${cmd} exited with code ${r.status}`);
|
|
41
|
-
process.exit(r.status);
|
|
42
|
-
}
|
|
43
|
-
if (r.error) {
|
|
44
|
-
console.log(r.error);
|
|
45
|
-
process.exit(r.error.errno || 1);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.execVoidCommandSync = execVoidCommandSync;
|
|
49
|
-
function logExec(cmd, args = [], opt = {}) {
|
|
50
|
-
const cmdline = [
|
|
51
|
-
...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('=')),
|
|
52
|
-
cmd,
|
|
53
|
-
...args,
|
|
54
|
-
].join(' ');
|
|
55
|
-
console.log((0, colors_1.grey)(cmdline));
|
|
56
|
-
}
|