@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 CHANGED
@@ -3,18 +3,12 @@
3
3
  "root": false,
4
4
  "files": {
5
5
  "includes": [
6
- "*",
7
- "src/**",
8
- "scripts/**",
9
- "!**/*.html",
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": {
@@ -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
- export const sharedConfig: InlineConfig
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
@@ -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
- ...sharedConfig,
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 const sharedConfig = {
74
- pool,
75
- maxWorkers,
76
- isolate: false,
77
- watch: false,
78
- // dir: 'src',
79
- restoreMocks: true,
80
- silent,
81
- setupFiles: getSetupFiles(testType),
82
- logHeapUsage: true,
83
- testTimeout: 60_000,
84
- slowTestThreshold: isCI ? 500 : 300, // higher threshold in CI
85
- sequence: {
86
- sequencer: VitestAlphabeticSequencer,
87
- // shuffle: {
88
- // files: true,
89
- // tests: false,
90
- // },
91
- // seed: 1, // this makes the order of tests deterministic (but still not alphabetic)
92
- },
93
- include,
94
- exclude,
95
- reporters: [
96
- 'default',
97
- new SummaryReporter(),
98
- junitReporterEnabled && [
99
- 'junit',
100
- {
101
- suiteName: `${testType} tests`,
102
- // classNameTemplate: '{filename} - {classname}',
103
- },
104
- ],
105
- ].filter(Boolean),
106
- // outputFile location is specified for compatibility with the previous jest config
107
- outputFile: junitReporterEnabled ? `./tmp/jest/${testType}.xml` : undefined,
108
- coverage: {
109
- enabled: coverageEnabled,
110
- reporter: ['html', 'lcov', 'json', 'json-summary', !isCI && 'text'].filter(Boolean),
111
- include: ['src/**/*.{ts,tsx}'],
112
- exclude: [
113
- '**/__exclude/**',
114
- 'scripts/**',
115
- 'public/**',
116
- 'src/index.{ts,tsx}',
117
- 'src/test/**',
118
- 'src/typings/**',
119
- 'src/{env,environment,environments}/**',
120
- 'src/bin/**',
121
- 'src/vendor/**',
122
- '**/*.test.*',
123
- '**/*.script.*',
124
- '**/*.module.*',
125
- '**/*.mock.*',
126
- '**/*.page.{ts,tsx}',
127
- '**/*.component.{ts,tsx}',
128
- '**/*.directive.{ts,tsx}',
129
- '**/*.modal.{ts,tsx}',
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('./src/test/setupVitest.ts')
190
+ setupFiles.push(`${cwd}/src/test/setupVitest.ts`)
192
191
  }
193
192
  if (fs.existsSync(`${cwd}/src/test/setupVitest.${testType}.ts`)) {
194
- setupFiles.push(`./src/test/setupVitest.${testType}.ts`)
193
+ setupFiles.push(`${cwd}/src/test/setupVitest.${testType}.ts`)
195
194
  }
196
195
  return setupFiles
197
196
  }
@@ -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: typecheck,
15
- desc: 'Run typecheck (tsc) in folders (src, scripts, e2e) if there is tsconfig.json present',
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 lbt() {
153
+ async function check() {
149
154
  await lintAllCommand();
150
- await bt();
155
+ runTest();
151
156
  }
152
157
  async function bt() {
153
- await typecheck();
158
+ await typecheckWithOxlint();
154
159
  runTest();
155
160
  }
156
- async function typecheck() {
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() {
@@ -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;
@@ -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
- export async function runTSCInFolder(dir, args = []) {
30
+ async function runTSCInFolder(dir, args = []) {
29
31
  let configDir = dir;
30
32
  if (dir === 'src') {
31
33
  configDir = '';
@@ -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
- const oxlintConfigPath = `.oxlintrc.json`;
136
- if (!existsSync(oxlintConfigPath)) {
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}}`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "20.16.1",
4
+ "version": "20.17.0",
5
5
  "dependencies": {
6
6
  "@biomejs/biome": "^2",
7
7
  "@commitlint/cli": "^20",