@naturalcycles/dev-lib 15.12.0 → 15.13.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.
- package/dist/build.util.js +36 -30
- package/dist/lint.util.js +34 -39
- package/dist/test.util.js +8 -2
- package/dist/yarn.util.js +7 -7
- package/package.json +1 -1
package/dist/build.util.js
CHANGED
|
@@ -8,7 +8,6 @@ exports.runTSCProd = runTSCProd;
|
|
|
8
8
|
exports.buildCopy = buildCopy;
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
11
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
12
11
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
13
12
|
async function buildEsmCjs() {
|
|
14
13
|
// You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
|
|
@@ -24,28 +23,34 @@ async function buildEsmCjs() {
|
|
|
24
23
|
const cjsPath = cjsExists ? TSCONF_CJS_PATH : TSCONF_PROD_PATH;
|
|
25
24
|
const esmPath = esmExists ? TSCONF_ESM_PATH : TSCONF_PROD_PATH;
|
|
26
25
|
await Promise.all([
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
26
|
+
nodejs_lib_1.exec2.spawnAsync('tsc', {
|
|
27
|
+
args: [
|
|
28
|
+
'-P',
|
|
29
|
+
cjsPath,
|
|
30
|
+
'--outDir',
|
|
31
|
+
'./dist',
|
|
32
|
+
'--module',
|
|
33
|
+
'nodenext',
|
|
34
|
+
'--moduleResolution',
|
|
35
|
+
'nodenext',
|
|
36
|
+
],
|
|
37
|
+
shell: false,
|
|
38
|
+
}),
|
|
39
|
+
nodejs_lib_1.exec2.spawnAsync('tsc', {
|
|
40
|
+
args: [
|
|
41
|
+
'-P',
|
|
42
|
+
esmPath,
|
|
43
|
+
'--outDir',
|
|
44
|
+
'./dist-esm',
|
|
45
|
+
'--module',
|
|
46
|
+
'esnext',
|
|
47
|
+
'--moduleResolution',
|
|
48
|
+
'bundler',
|
|
49
|
+
'--declaration',
|
|
50
|
+
'false',
|
|
51
|
+
],
|
|
52
|
+
shell: false,
|
|
53
|
+
}),
|
|
49
54
|
]);
|
|
50
55
|
}
|
|
51
56
|
async function buildProd() {
|
|
@@ -74,16 +79,17 @@ async function runTSCInFolder(tsconfigPath, args = []) {
|
|
|
74
79
|
console.log(`Skipping to run tsc for ${tsconfigPath}, as it doesn't exist`);
|
|
75
80
|
return;
|
|
76
81
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
await nodejs_lib_1.exec2.spawnAsync(`tsc`, {
|
|
83
|
+
args: ['-P', tsconfigPath, ...args],
|
|
84
|
+
shell: false,
|
|
85
|
+
});
|
|
80
86
|
}
|
|
81
87
|
async function runTSCProd() {
|
|
82
88
|
const tsconfigPath = [`./tsconfig.prod.json`].find(p => node_fs_1.default.existsSync(p)) || 'tsconfig.json';
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
await nodejs_lib_1.exec2.spawnAsync(`tsc`, {
|
|
90
|
+
args: ['-P', tsconfigPath],
|
|
91
|
+
shell: false,
|
|
92
|
+
});
|
|
87
93
|
}
|
|
88
94
|
function buildCopy() {
|
|
89
95
|
const baseDir = 'src';
|
package/dist/lint.util.js
CHANGED
|
@@ -54,11 +54,11 @@ async function lintAllCommand() {
|
|
|
54
54
|
const hasChanges = gitStatusAfter !== gitStatusAtStart;
|
|
55
55
|
if (!hasChanges)
|
|
56
56
|
return;
|
|
57
|
-
const msg = 'style(ci): ' + (0, js_lib_1._truncate)(
|
|
57
|
+
const msg = 'style(ci): ' + (0, js_lib_1._truncate)(nodejs_lib_1.git2.commitMessageToTitleMessage(nodejs_lib_1.git2.getLastGitCommitMsg()), 60);
|
|
58
58
|
// pull, commit, push changes
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
nodejs_lib_1.git2.pull();
|
|
60
|
+
nodejs_lib_1.git2.commitAll(msg);
|
|
61
|
+
nodejs_lib_1.git2.push();
|
|
62
62
|
// fail on changes
|
|
63
63
|
if (failOnChanges) {
|
|
64
64
|
console.log(gitStatusAfter);
|
|
@@ -123,15 +123,18 @@ async function eslintAll(opt) {
|
|
|
123
123
|
async function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
|
|
124
124
|
if (!eslintConfigPath || !node_fs_1.default.existsSync(dir))
|
|
125
125
|
return; // faster to bail-out like this
|
|
126
|
-
await
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
126
|
+
await nodejs_lib_1.exec2.spawnAsync('eslint', {
|
|
127
|
+
args: [
|
|
128
|
+
`--config`,
|
|
129
|
+
eslintConfigPath,
|
|
130
|
+
`${dir}/**/*.{${extensions.join(',')}}`,
|
|
131
|
+
...(tsconfigPath ? [`--parser-options=project:${tsconfigPath}`] : []),
|
|
132
|
+
`--no-error-on-unmatched-pattern`,
|
|
133
|
+
`--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
|
|
134
|
+
fix ? `--fix` : '',
|
|
135
|
+
].filter(Boolean),
|
|
136
|
+
shell: false,
|
|
137
|
+
});
|
|
135
138
|
}
|
|
136
139
|
const prettierPaths = [
|
|
137
140
|
// Everything inside these folders
|
|
@@ -146,13 +149,10 @@ function runPrettier() {
|
|
|
146
149
|
if (!prettierConfigPath)
|
|
147
150
|
return;
|
|
148
151
|
// prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
|
|
149
|
-
|
|
150
|
-
`--write`,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
prettierConfigPath,
|
|
154
|
-
...prettierPaths,
|
|
155
|
-
]);
|
|
152
|
+
nodejs_lib_1.exec2.spawn('prettier', {
|
|
153
|
+
args: [`--write`, `--log-level=warn`, `--config`, prettierConfigPath, ...prettierPaths],
|
|
154
|
+
shell: false,
|
|
155
|
+
});
|
|
156
156
|
}
|
|
157
157
|
const stylelintPaths = [
|
|
158
158
|
// Everything inside these folders
|
|
@@ -170,7 +170,10 @@ function stylelintAll() {
|
|
|
170
170
|
const config = [`./stylelint.config.js`].find(f => node_fs_1.default.existsSync(f));
|
|
171
171
|
if (!config)
|
|
172
172
|
return;
|
|
173
|
-
|
|
173
|
+
nodejs_lib_1.exec2.spawn('stylelint', {
|
|
174
|
+
args: [fix ? `--fix` : '', `--allow-empty-input`, `--config`, config, ...stylelintPaths].filter(Boolean),
|
|
175
|
+
shell: false,
|
|
176
|
+
});
|
|
174
177
|
}
|
|
175
178
|
async function lintStagedCommand() {
|
|
176
179
|
// const cwd = process.cwd()
|
|
@@ -202,11 +205,13 @@ function runCommitlintCommand() {
|
|
|
202
205
|
const config = node_fs_1.default.existsSync(localConfig) ? localConfig : sharedConfig;
|
|
203
206
|
const env = {
|
|
204
207
|
...process.env, // important to pass it through, to preserve $PATH
|
|
205
|
-
GIT_BRANCH:
|
|
208
|
+
GIT_BRANCH: nodejs_lib_1.git2.getCurrentBranchName(),
|
|
206
209
|
};
|
|
207
210
|
// await execWithArgs(`commitlint`, [`--edit`, editMsg, `--config`, config], { env })
|
|
208
|
-
|
|
211
|
+
nodejs_lib_1.exec2.spawn(`node ./node_modules/.bin/commitlint --edit ${editMsg} --config ${config}`, {
|
|
209
212
|
env,
|
|
213
|
+
passProcessEnv: false,
|
|
214
|
+
forceColor: false,
|
|
210
215
|
});
|
|
211
216
|
}
|
|
212
217
|
async function runKTLint() {
|
|
@@ -220,9 +225,7 @@ function runActionLint() {
|
|
|
220
225
|
if (!node_fs_1.default.existsSync('.github/workflows'))
|
|
221
226
|
return;
|
|
222
227
|
if (canRunBinary('actionlint')) {
|
|
223
|
-
|
|
224
|
-
(0, nodejs_lib_1.execVoidCommandSync)(`actionlint`);
|
|
225
|
-
console.log(`${(0, nodejs_lib_1.boldGrey)('actionlint')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
|
|
228
|
+
nodejs_lib_1.exec2.spawn(`actionlint`);
|
|
226
229
|
}
|
|
227
230
|
else {
|
|
228
231
|
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`);
|
|
@@ -241,7 +244,11 @@ function runBiome(fix = true) {
|
|
|
241
244
|
return;
|
|
242
245
|
}
|
|
243
246
|
const dirs = [`src`, `scripts`, `e2e`, `playwright`].filter(d => node_fs_1.default.existsSync(d));
|
|
244
|
-
|
|
247
|
+
nodejs_lib_1.exec2.spawn(`biome`, {
|
|
248
|
+
args: [`lint`, fix && '--write', fix && '--unsafe', '--no-errors-on-unmatched', ...dirs].filter(js_lib_1._isTruthy),
|
|
249
|
+
logFinish: false,
|
|
250
|
+
shell: false,
|
|
251
|
+
});
|
|
245
252
|
}
|
|
246
253
|
function canRunBinary(name) {
|
|
247
254
|
try {
|
|
@@ -260,15 +267,3 @@ function gitStatus() {
|
|
|
260
267
|
}
|
|
261
268
|
catch { }
|
|
262
269
|
}
|
|
263
|
-
function execSync(cmd, opt) {
|
|
264
|
-
try {
|
|
265
|
-
node_child_process_1.default.execSync(cmd, {
|
|
266
|
-
...opt,
|
|
267
|
-
encoding: 'utf8',
|
|
268
|
-
stdio: 'inherit',
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
catch {
|
|
272
|
-
process.exit(1);
|
|
273
|
-
}
|
|
274
|
-
}
|
package/dist/test.util.js
CHANGED
|
@@ -82,13 +82,19 @@ function runJest(opt = {}) {
|
|
|
82
82
|
const totalShards = Number(JEST_SHARDS);
|
|
83
83
|
const shards = (0, js_lib_1._range)(1, totalShards + 1);
|
|
84
84
|
for (const shard of shards) {
|
|
85
|
-
|
|
85
|
+
nodejs_lib_1.exec2.spawn('jest', {
|
|
86
|
+
args: (0, js_lib_1._uniq)([...args, `--shard=${shard}/${totalShards}`]),
|
|
87
|
+
logFinish: false,
|
|
88
|
+
shell: false,
|
|
86
89
|
env,
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
else {
|
|
91
|
-
|
|
94
|
+
nodejs_lib_1.exec2.spawn('jest', {
|
|
95
|
+
args: (0, js_lib_1._uniq)(args),
|
|
96
|
+
logFinish: false,
|
|
97
|
+
shell: false,
|
|
92
98
|
env,
|
|
93
99
|
});
|
|
94
100
|
}
|
package/dist/yarn.util.js
CHANGED
|
@@ -6,15 +6,15 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
7
7
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
8
|
function up() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
nodejs_lib_1.exec2.spawn('yarn upgrade');
|
|
10
|
+
nodejs_lib_1.exec2.spawn('yarn-deduplicate');
|
|
11
|
+
nodejs_lib_1.exec2.spawn('yarn');
|
|
12
12
|
if (node_fs_1.default.existsSync(`node_modules/patch-package`)) {
|
|
13
|
-
|
|
13
|
+
nodejs_lib_1.exec2.spawn('patch-package');
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
function upnc() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
nodejs_lib_1.exec2.spawn('yarn upgrade --pattern @naturalcycles');
|
|
18
|
+
nodejs_lib_1.exec2.spawn('yarn-deduplicate');
|
|
19
|
+
nodejs_lib_1.exec2.spawn('yarn');
|
|
20
20
|
}
|