@naturalcycles/dev-lib 20.16.1 → 20.17.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/biome.jsonc +5 -11
- package/cfg/vitest.config.d.ts +6 -1
- package/cfg/vitest.config.js +65 -66
- package/dist/bin/dev-lib.js +19 -9
- package/dist/build.util.d.ts +2 -4
- package/dist/build.util.js +3 -1
- package/dist/lint.util.d.ts +2 -0
- package/dist/lint.util.js +9 -2
- package/package.json +1 -1
package/cfg/biome.jsonc
CHANGED
|
@@ -3,18 +3,12 @@
|
|
|
3
3
|
"root": false,
|
|
4
4
|
"files": {
|
|
5
5
|
"includes": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"!**/*.css",
|
|
11
|
-
"!**/*.scss",
|
|
12
|
-
"!**/tsconfig.json",
|
|
13
|
-
"!**/tsconfig.*.json",
|
|
6
|
+
"**/*.ts",
|
|
7
|
+
"**/*.tsx",
|
|
8
|
+
"**/*.js",
|
|
9
|
+
"**/*.jsx",
|
|
14
10
|
"!**/__exclude",
|
|
15
|
-
"!**/try.ts"
|
|
16
|
-
"!**/*.compact.json",
|
|
17
|
-
"!**/*.mock.json"
|
|
11
|
+
"!**/try.ts"
|
|
18
12
|
]
|
|
19
13
|
},
|
|
20
14
|
"formatter": {
|
package/cfg/vitest.config.d.ts
CHANGED
|
@@ -10,10 +10,15 @@ import type { InlineConfig } from 'vitest/node'
|
|
|
10
10
|
// bail: 1,
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
+
Pass `import.meta.dirname` as cwd if running from a monorepo.
|
|
14
|
+
|
|
13
15
|
*/
|
|
14
16
|
export function defineVitestConfig(config?: Partial<ViteUserConfig>, cwd?: string): ViteUserConfig
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Pass `import.meta.dirname` as cwd if running from a monorepo.
|
|
20
|
+
*/
|
|
21
|
+
export function getSharedConfig(cwd?: string): InlineConfig
|
|
17
22
|
|
|
18
23
|
export const CollectReporter: any
|
|
19
24
|
export const SummaryReporter: any
|
package/cfg/vitest.config.js
CHANGED
|
@@ -37,13 +37,10 @@ if (silent) {
|
|
|
37
37
|
* })
|
|
38
38
|
*/
|
|
39
39
|
export function defineVitestConfig(config, cwd) {
|
|
40
|
-
const setupFiles = getSetupFiles(testType, cwd)
|
|
41
|
-
|
|
42
40
|
const mergedConfig = defineConfig({
|
|
43
41
|
...config,
|
|
44
42
|
test: {
|
|
45
|
-
...
|
|
46
|
-
setupFiles,
|
|
43
|
+
...getSharedConfig(cwd),
|
|
47
44
|
...config?.test,
|
|
48
45
|
},
|
|
49
46
|
})
|
|
@@ -70,65 +67,67 @@ export function defineVitestConfig(config, cwd) {
|
|
|
70
67
|
/**
|
|
71
68
|
* Shared config for Vitest.
|
|
72
69
|
*/
|
|
73
|
-
export
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
70
|
+
export function getSharedConfig(cwd) {
|
|
71
|
+
return {
|
|
72
|
+
pool,
|
|
73
|
+
maxWorkers,
|
|
74
|
+
isolate: false,
|
|
75
|
+
watch: false,
|
|
76
|
+
// dir: 'src',
|
|
77
|
+
restoreMocks: true,
|
|
78
|
+
silent,
|
|
79
|
+
setupFiles: getSetupFiles(testType, cwd),
|
|
80
|
+
logHeapUsage: true,
|
|
81
|
+
testTimeout: 60_000,
|
|
82
|
+
slowTestThreshold: isCI ? 500 : 300, // higher threshold in CI
|
|
83
|
+
sequence: {
|
|
84
|
+
sequencer: VitestAlphabeticSequencer,
|
|
85
|
+
// shuffle: {
|
|
86
|
+
// files: true,
|
|
87
|
+
// tests: false,
|
|
88
|
+
// },
|
|
89
|
+
// seed: 1, // this makes the order of tests deterministic (but still not alphabetic)
|
|
90
|
+
},
|
|
91
|
+
include,
|
|
92
|
+
exclude,
|
|
93
|
+
reporters: [
|
|
94
|
+
'default',
|
|
95
|
+
new SummaryReporter(),
|
|
96
|
+
junitReporterEnabled && [
|
|
97
|
+
'junit',
|
|
98
|
+
{
|
|
99
|
+
suiteName: `${testType} tests`,
|
|
100
|
+
// classNameTemplate: '{filename} - {classname}',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
].filter(Boolean),
|
|
104
|
+
// outputFile location is specified for compatibility with the previous jest config
|
|
105
|
+
outputFile: junitReporterEnabled ? `./tmp/jest/${testType}.xml` : undefined,
|
|
106
|
+
coverage: {
|
|
107
|
+
enabled: coverageEnabled,
|
|
108
|
+
reporter: ['html', 'lcov', 'json', 'json-summary', !isCI && 'text'].filter(Boolean),
|
|
109
|
+
include: ['src/**/*.{ts,tsx}'],
|
|
110
|
+
exclude: [
|
|
111
|
+
'**/__exclude/**',
|
|
112
|
+
'scripts/**',
|
|
113
|
+
'public/**',
|
|
114
|
+
'src/index.{ts,tsx}',
|
|
115
|
+
'src/test/**',
|
|
116
|
+
'src/typings/**',
|
|
117
|
+
'src/{env,environment,environments}/**',
|
|
118
|
+
'src/bin/**',
|
|
119
|
+
'src/vendor/**',
|
|
120
|
+
'**/*.test.*',
|
|
121
|
+
'**/*.script.*',
|
|
122
|
+
'**/*.module.*',
|
|
123
|
+
'**/*.mock.*',
|
|
124
|
+
'**/*.page.{ts,tsx}',
|
|
125
|
+
'**/*.component.{ts,tsx}',
|
|
126
|
+
'**/*.directive.{ts,tsx}',
|
|
127
|
+
'**/*.modal.{ts,tsx}',
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
}
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
function doesItRunInIDE() {
|
|
@@ -184,14 +183,14 @@ function isRunningAllTests() {
|
|
|
184
183
|
return !hasPositionalArgs
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
function getSetupFiles(testType, cwd =
|
|
186
|
+
function getSetupFiles(testType, cwd = process.cwd()) {
|
|
188
187
|
// Set 'setupFiles' only if setup files exist
|
|
189
188
|
const setupFiles = []
|
|
190
189
|
if (fs.existsSync(`${cwd}/src/test/setupVitest.ts`)) {
|
|
191
|
-
setupFiles.push(
|
|
190
|
+
setupFiles.push(`${cwd}/src/test/setupVitest.ts`)
|
|
192
191
|
}
|
|
193
192
|
if (fs.existsSync(`${cwd}/src/test/setupVitest.${testType}.ts`)) {
|
|
194
|
-
setupFiles.push(
|
|
193
|
+
setupFiles.push(`${cwd}/src/test/setupVitest.${testType}.ts`)
|
|
195
194
|
}
|
|
196
195
|
return setupFiles
|
|
197
196
|
}
|
package/dist/bin/dev-lib.js
CHANGED
|
@@ -5,17 +5,22 @@ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
|
5
5
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
6
6
|
import { runScript } from '@naturalcycles/nodejs-lib/runScript';
|
|
7
7
|
import { buildCopy, buildProd, runTSCInFolders } from '../build.util.js';
|
|
8
|
-
import { eslintAll, lintAllCommand, lintStagedCommand, runBiome, runCommitlintCommand, runOxlint, runPrettier, stylelintAll, } from '../lint.util.js';
|
|
8
|
+
import { eslintAll, lintAllCommand, lintStagedCommand, requireOxlintConfig, runBiome, runCommitlintCommand, runOxlint, runPrettier, stylelintAll, } from '../lint.util.js';
|
|
9
9
|
import { runTest } from '../test.util.js';
|
|
10
10
|
const commands = [
|
|
11
11
|
new Separator(), // build
|
|
12
|
+
{ name: 'check', fn: check, desc: '"Run all possible checks": lint, typecheck, then test.' },
|
|
13
|
+
{ name: 'bt', fn: bt, desc: 'Build & Test: run "typecheck" (via oxlint) and then "test".' },
|
|
12
14
|
{
|
|
13
15
|
name: 'typecheck',
|
|
14
|
-
fn:
|
|
15
|
-
desc: 'Run typecheck
|
|
16
|
+
fn: typecheckWithOxlint,
|
|
17
|
+
desc: 'Run typecheck via oxlint --type-aware',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'typecheck-with-tsc',
|
|
21
|
+
fn: typecheckWithTSC,
|
|
22
|
+
desc: 'Run typecheck (tsc) in folders (src, scripts, e2e) if there is tsconfig.json present. Deprecated, use oxlint type-checking instead.',
|
|
16
23
|
},
|
|
17
|
-
{ name: 'bt', fn: bt, desc: 'Build & Test: run "typecheck" (tsc) and then "test".' },
|
|
18
|
-
{ name: 'check', fn: lbt, desc: '"Run all possible checks": lint, typecheck, then test.' },
|
|
19
24
|
{
|
|
20
25
|
name: 'build',
|
|
21
26
|
fn: buildProd,
|
|
@@ -145,15 +150,20 @@ runScript(async () => {
|
|
|
145
150
|
}
|
|
146
151
|
await commandMap[cmd].fn();
|
|
147
152
|
});
|
|
148
|
-
async function
|
|
153
|
+
async function check() {
|
|
149
154
|
await lintAllCommand();
|
|
150
|
-
|
|
155
|
+
runTest();
|
|
151
156
|
}
|
|
152
157
|
async function bt() {
|
|
153
|
-
await
|
|
158
|
+
await typecheckWithOxlint();
|
|
154
159
|
runTest();
|
|
155
160
|
}
|
|
156
|
-
async function
|
|
161
|
+
async function typecheckWithOxlint() {
|
|
162
|
+
requireOxlintConfig();
|
|
163
|
+
const fix = !CI;
|
|
164
|
+
runOxlint(fix);
|
|
165
|
+
}
|
|
166
|
+
async function typecheckWithTSC() {
|
|
157
167
|
await runTSCInFolders(['src', 'scripts', 'e2e'], ['--noEmit']);
|
|
158
168
|
}
|
|
159
169
|
async function cleanDist() {
|
package/dist/build.util.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export declare function buildProd(): Promise<void>;
|
|
2
2
|
/**
|
|
3
3
|
* Use 'src' to indicate root.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated - oxlint should be used for type-checking instead, it's faster.
|
|
4
6
|
*/
|
|
5
7
|
export declare function runTSCInFolders(dirs: string[], args?: string[], parallel?: boolean): Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
* Pass 'src' to run in root.
|
|
8
|
-
*/
|
|
9
|
-
export declare function runTSCInFolder(dir: string, args?: string[]): Promise<void>;
|
|
10
8
|
export declare function runTSCProd(args?: string[]): Promise<void>;
|
|
11
9
|
export declare function buildCopy(): void;
|
package/dist/build.util.js
CHANGED
|
@@ -11,6 +11,8 @@ export async function buildProd() {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Use 'src' to indicate root.
|
|
14
|
+
*
|
|
15
|
+
* @deprecated - oxlint should be used for type-checking instead, it's faster.
|
|
14
16
|
*/
|
|
15
17
|
export async function runTSCInFolders(dirs, args = [], parallel = true) {
|
|
16
18
|
if (parallel) {
|
|
@@ -25,7 +27,7 @@ export async function runTSCInFolders(dirs, args = [], parallel = true) {
|
|
|
25
27
|
/**
|
|
26
28
|
* Pass 'src' to run in root.
|
|
27
29
|
*/
|
|
28
|
-
|
|
30
|
+
async function runTSCInFolder(dir, args = []) {
|
|
29
31
|
let configDir = dir;
|
|
30
32
|
if (dir === 'src') {
|
|
31
33
|
configDir = '';
|
package/dist/lint.util.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ interface EslintAllOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function eslintAll(opt?: EslintAllOptions): void;
|
|
14
14
|
export declare function runOxlint(fix?: boolean): void;
|
|
15
|
+
export declare function requireOxlintConfig(): void;
|
|
16
|
+
export declare function hasOxlintConfig(): boolean;
|
|
15
17
|
interface RunPrettierOptions {
|
|
16
18
|
experimentalCli?: boolean;
|
|
17
19
|
fix?: boolean;
|
package/dist/lint.util.js
CHANGED
|
@@ -132,8 +132,8 @@ function runESLint(extensions = eslintExtensions.split(','), fix = true) {
|
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
export function runOxlint(fix = true) {
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
if (!hasOxlintConfig()) {
|
|
136
|
+
console.log('.oxlintrc.json is not found, skipping to run oxlint');
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
const oxlintPath = findPackageBinPath('oxlint', 'oxlint');
|
|
@@ -151,6 +151,13 @@ export function runOxlint(fix = true) {
|
|
|
151
151
|
shell: false,
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
+
export function requireOxlintConfig() {
|
|
155
|
+
_assert(hasOxlintConfig(), '.oxlintrc.json config is not found');
|
|
156
|
+
}
|
|
157
|
+
export function hasOxlintConfig() {
|
|
158
|
+
const oxlintConfigPath = `.oxlintrc.json`;
|
|
159
|
+
return existsSync(oxlintConfigPath);
|
|
160
|
+
}
|
|
154
161
|
const prettierPaths = [
|
|
155
162
|
// Everything inside these folders
|
|
156
163
|
`./{${prettierDirs.join(',')}}/**/*.{${prettierExtensionsAll}}`,
|