@naturalcycles/dev-lib 20.70.0 → 20.72.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/cfg/oxlint.config.js +8 -9
- package/dist/check.util.js +18 -18
- package/dist/release/notes.util.js +2 -1
- package/dist/testing/mockAllKindsOfThings.js +1 -0
- package/dist/vendor/mitm.d.ts +1 -1
- package/dist/vendor/mitm.js +11 -11
- package/package.json +1 -1
- package/readme.md +0 -5
package/cfg/oxlint.config.js
CHANGED
|
@@ -72,7 +72,7 @@ export const sharedConfig = {
|
|
|
72
72
|
{ blankLine: 'always', prev: '*', next: 'class' },
|
|
73
73
|
],
|
|
74
74
|
'@stylistic/lines-between-class-members': [2, 'always', { exceptAfterSingleLine: true }],
|
|
75
|
-
'nc/prefer-assert':
|
|
75
|
+
'nc/prefer-assert': 2,
|
|
76
76
|
complexity: [2, { max: 40 }],
|
|
77
77
|
'logical-assignment-operators': [
|
|
78
78
|
2,
|
|
@@ -96,8 +96,10 @@ export const sharedConfig = {
|
|
|
96
96
|
'object-shorthand': 2,
|
|
97
97
|
'valid-expect': 0,
|
|
98
98
|
'valid-title': 0,
|
|
99
|
-
'vitest/valid-title':
|
|
99
|
+
'vitest/valid-title': [2, { mustMatch: { it: '^should ' } }],
|
|
100
100
|
'valid-describe-callback': 0,
|
|
101
|
+
// Options arguments and variables are `opt`, never `opts`
|
|
102
|
+
'id-denylist': [2, 'opts'],
|
|
101
103
|
// 'id-denylist': [
|
|
102
104
|
// 0, // actually not useful
|
|
103
105
|
// 'any',
|
|
@@ -146,11 +148,14 @@ export const sharedConfig = {
|
|
|
146
148
|
name: 'Intl',
|
|
147
149
|
message: 'Use Intl2 instead.',
|
|
148
150
|
},
|
|
151
|
+
{ name: 'Date', message: 'Use localTime / localDate from @naturalcycles/js-lib/datetime.' },
|
|
149
152
|
],
|
|
150
153
|
'no-unused-expressions': 2,
|
|
151
154
|
'no-var': 2,
|
|
152
155
|
'unicode-bom': 2,
|
|
153
156
|
'no-extend-native': 2,
|
|
157
|
+
'no-prototype-builtins': 2,
|
|
158
|
+
'prefer-object-has-own': 2,
|
|
154
159
|
'no-extra-bind': 2,
|
|
155
160
|
'no-duplicate-imports': [
|
|
156
161
|
0, // disabled until auto-fix is there
|
|
@@ -462,13 +467,7 @@ export const sharedConfig = {
|
|
|
462
467
|
'vitest/prefer-called-exactly-once-with': 2,
|
|
463
468
|
'vitest/consistent-test-filename': 2,
|
|
464
469
|
'vitest/warn-todo': 0,
|
|
465
|
-
'vitest/consistent-test-it': [
|
|
466
|
-
2,
|
|
467
|
-
{
|
|
468
|
-
fn: 'test',
|
|
469
|
-
withinDescribe: 'test',
|
|
470
|
-
},
|
|
471
|
-
],
|
|
470
|
+
'vitest/consistent-test-it': [2, { fn: 'it', withinDescribe: 'it' }],
|
|
472
471
|
'vitest/max-nested-describe': [0, { max: 4 }], // not good
|
|
473
472
|
'vitest/no-alias-methods': 2,
|
|
474
473
|
'vitest/no-restricted-vi-methods': [
|
package/dist/check.util.js
CHANGED
|
@@ -4,7 +4,7 @@ import { findPackageJSON } from 'node:module';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { _isTruthy } from '@naturalcycles/js-lib';
|
|
6
6
|
import { _uniq } from '@naturalcycles/js-lib/array';
|
|
7
|
-
import { _since } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
7
|
+
import { _since, nowUnixMillis } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
8
8
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
9
9
|
import { _filterFalsyValues } from '@naturalcycles/js-lib/object/object.util.js';
|
|
10
10
|
import { semver2 } from '@naturalcycles/js-lib/semver';
|
|
@@ -24,7 +24,7 @@ const { CI } = process.env;
|
|
|
24
24
|
*/
|
|
25
25
|
export async function runCheck(opt = {}) {
|
|
26
26
|
const { fastLinters = true, eslint = true, stylelint = true, oxfmt = true, ktlint = true, typecheck = false, test = true, } = opt;
|
|
27
|
-
const started =
|
|
27
|
+
const started = nowUnixMillis();
|
|
28
28
|
let s;
|
|
29
29
|
const timings = {};
|
|
30
30
|
// const { commitOnChanges, failOnChanges } = _yargs().options({
|
|
@@ -49,52 +49,52 @@ export async function runCheck(opt = {}) {
|
|
|
49
49
|
const fix = !CI;
|
|
50
50
|
if (fastLinters) {
|
|
51
51
|
// Fast linters (that run in <1 second) go first
|
|
52
|
-
s =
|
|
52
|
+
s = nowUnixMillis();
|
|
53
53
|
if (runActionLint()) {
|
|
54
|
-
timings['actionlint'] =
|
|
54
|
+
timings['actionlint'] = nowUnixMillis() - s;
|
|
55
55
|
}
|
|
56
|
-
s =
|
|
56
|
+
s = nowUnixMillis();
|
|
57
57
|
if (runOxlint(fix)) {
|
|
58
|
-
timings['oxlint'] =
|
|
58
|
+
timings['oxlint'] = nowUnixMillis() - s;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
// From this point we start the "slow" linters, with ESLint leading the way
|
|
62
62
|
if (eslint) {
|
|
63
63
|
// We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
|
|
64
|
-
s =
|
|
64
|
+
s = nowUnixMillis();
|
|
65
65
|
if (eslintAll({ fix })) {
|
|
66
|
-
timings['eslint'] =
|
|
66
|
+
timings['eslint'] = nowUnixMillis() - s;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
if (stylelint &&
|
|
70
70
|
hasDependencyInNodeModules('stylelint') &&
|
|
71
71
|
hasDependencyInNodeModules('stylelint-config-standard-scss')) {
|
|
72
|
-
s =
|
|
72
|
+
s = nowUnixMillis();
|
|
73
73
|
if (stylelintAll(fix)) {
|
|
74
|
-
timings['stylelint'] =
|
|
74
|
+
timings['stylelint'] = nowUnixMillis() - s;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
if (oxfmt) {
|
|
78
|
-
s =
|
|
78
|
+
s = nowUnixMillis();
|
|
79
79
|
if (runOxfmt(fix)) {
|
|
80
|
-
timings['oxfmt'] =
|
|
80
|
+
timings['oxfmt'] = nowUnixMillis() - s;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
if (ktlint) {
|
|
84
|
-
s =
|
|
84
|
+
s = nowUnixMillis();
|
|
85
85
|
if (await runKTLint(fix)) {
|
|
86
|
-
timings['ktlint'] =
|
|
86
|
+
timings['ktlint'] = nowUnixMillis() - s;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
if (typecheck) {
|
|
90
|
-
s =
|
|
90
|
+
s = nowUnixMillis();
|
|
91
91
|
await runTypecheck();
|
|
92
|
-
timings['tsc'] =
|
|
92
|
+
timings['tsc'] = nowUnixMillis() - s;
|
|
93
93
|
}
|
|
94
94
|
if (test) {
|
|
95
|
-
s =
|
|
95
|
+
s = nowUnixMillis();
|
|
96
96
|
if (runTest()) {
|
|
97
|
-
timings['test'] =
|
|
97
|
+
timings['test'] = nowUnixMillis() - s;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
console.log(`${check(true)}${white(`check`)} ${dimGrey(`took ` + _since(started))}`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { localDate } from '@naturalcycles/js-lib/datetime/localDate.js';
|
|
1
2
|
/**
|
|
2
3
|
* Generate release notes markdown for a GitHub Release,
|
|
3
4
|
* following the format of `@semantic-release/release-notes-generator` (angular preset):
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
*/
|
|
6
7
|
export function generateReleaseNotes(input) {
|
|
7
8
|
const { repo, commits, lastTag, nextTag } = input;
|
|
8
|
-
const date = input.date ||
|
|
9
|
+
const date = input.date || localDate.todayInUTC().toISODate();
|
|
9
10
|
const header = lastTag
|
|
10
11
|
? `## [${nextTag}](${repo.url}/compare/${lastTag}...${nextTag}) (${date})`
|
|
11
12
|
: `## ${nextTag} (${date})`;
|
package/dist/vendor/mitm.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface BypassableSocket extends NetType.Socket {
|
|
|
11
11
|
bypass: () => void;
|
|
12
12
|
bypassed?: boolean;
|
|
13
13
|
}
|
|
14
|
-
export type ConnectCallback = (socket: BypassableSocket,
|
|
14
|
+
export type ConnectCallback = (socket: BypassableSocket, opt: SocketOptions) => void;
|
|
15
15
|
export interface Mitm {
|
|
16
16
|
on: (event: 'connect', callback: ConnectCallback) => void;
|
|
17
17
|
disable: () => void;
|
package/dist/vendor/mitm.js
CHANGED
|
@@ -18,7 +18,7 @@ export function createMitm() {
|
|
|
18
18
|
s[0][s[1]] = s[2];
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
function connect(orig,
|
|
21
|
+
function connect(orig, opt, done) {
|
|
22
22
|
// Create a bypassable socket that we'll pass to listeners
|
|
23
23
|
const socket = new Net.Socket();
|
|
24
24
|
socket.bypassed = false;
|
|
@@ -27,11 +27,11 @@ export function createMitm() {
|
|
|
27
27
|
};
|
|
28
28
|
// Emit connect event to all listeners
|
|
29
29
|
for (const listener of listeners) {
|
|
30
|
-
listener(socket,
|
|
30
|
+
listener(socket, opt);
|
|
31
31
|
}
|
|
32
32
|
// If bypassed, call the original connect function
|
|
33
33
|
if (socket.bypassed) {
|
|
34
|
-
return orig.call(Net,
|
|
34
|
+
return orig.call(Net, opt, done);
|
|
35
35
|
}
|
|
36
36
|
// Not bypassed - return the socket that will never actually connect.
|
|
37
37
|
// testOffline throws an error before we get here, so this is just a fallback.
|
|
@@ -43,12 +43,12 @@ export function createMitm() {
|
|
|
43
43
|
// connect(options, callback?)
|
|
44
44
|
// connect(path, callback?) - Unix socket
|
|
45
45
|
if (typeof args[0] === 'number') {
|
|
46
|
-
const
|
|
46
|
+
const opt = { port: args[0] };
|
|
47
47
|
if (typeof args[1] === 'string') {
|
|
48
|
-
|
|
49
|
-
return [
|
|
48
|
+
opt.host = args[1];
|
|
49
|
+
return [opt, args[2]];
|
|
50
50
|
}
|
|
51
|
-
return [
|
|
51
|
+
return [opt, args[1]];
|
|
52
52
|
}
|
|
53
53
|
if (typeof args[0] === 'object' && args[0] !== null) {
|
|
54
54
|
return [args[0], args[1]];
|
|
@@ -58,14 +58,14 @@ export function createMitm() {
|
|
|
58
58
|
}
|
|
59
59
|
function createNetConnect(orig) {
|
|
60
60
|
return function (...args) {
|
|
61
|
-
const [
|
|
62
|
-
return connect(orig,
|
|
61
|
+
const [opt, done] = normalizeArgs(args);
|
|
62
|
+
return connect(orig, opt, done);
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
function createTlsConnect(orig) {
|
|
66
66
|
return function (...args) {
|
|
67
|
-
const [
|
|
68
|
-
return connect(orig,
|
|
67
|
+
const [opt, done] = normalizeArgs(args);
|
|
68
|
+
return connect(orig, opt, done);
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
// Stub network functions
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -17,11 +17,6 @@
|
|
|
17
17
|
- actionlint
|
|
18
18
|
- lint-staged
|
|
19
19
|
|
|
20
|
-
The shared oxlint config ships an opt-in `nc/prefer-assert` rule, off by default. It flags an `if`
|
|
21
|
-
whose only statement is `throw new Error(...)` (or `AppError`, `AssertionError`) that reads better
|
|
22
|
-
as `_assert(condition, message, data)` from `@naturalcycles/js-lib/error`. Test files are exempt.
|
|
23
|
-
Turn it on in your `oxlint.config.ts` with `rules: { 'nc/prefer-assert': 2 }`.
|
|
24
|
-
|
|
25
20
|
## How to use
|
|
26
21
|
|
|
27
22
|
Install it:
|