@naturalcycles/dev-lib 20.49.3 → 20.51.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.
@@ -11,7 +11,11 @@ export class SummaryReporter {
11
11
  let stats = []
12
12
 
13
13
  for (const mod of testModules) {
14
- const name = mod.moduleId.split('/').at(-1)
14
+ // In the monorepo root run testModules span all projects, so prefix with the
15
+ // (short) package name to disambiguate identically-named files across packages.
16
+ const pkg = mod.project?.name?.split('/').at(-1)
17
+ const file = mod.moduleId.split('/').at(-1)
18
+ const name = pkg ? `${pkg} ${file}` : file
15
19
  const diag = mod.diagnostic()
16
20
  stats.push({ name, ms: diag.duration })
17
21
  }
@@ -20,6 +20,13 @@ export function defineVitestConfig(config?: Partial<ViteUserConfig>, cwd?: strin
20
20
  */
21
21
  export function getSharedConfig(cwd?: string): InlineConfig
22
22
 
23
+ /**
24
+ * Reporters for the monorepo root config (Vitest `projects` mode), where
25
+ * `reporters` is a root-only option. Returns the compact 'agent' reporter for
26
+ * agents, otherwise the default reporters plus a monorepo-wide SummaryReporter.
27
+ */
28
+ export function getRootReporters(): InlineConfig['reporters']
29
+
23
30
  export const CollectReporter: any
24
31
 
25
32
  export class SummaryReporter {}
@@ -128,16 +128,10 @@ export function getSharedConfig(cwd) {
128
128
  }
129
129
 
130
130
  function getReporters(junitReporterEnabled, testType) {
131
- // VITEST_REPORTER env var allows overriding the default reporter
132
- const { VITEST_REPORTER, GITHUB_ACTIONS } = process.env
133
- if (VITEST_REPORTER) {
134
- return [VITEST_REPORTER]
135
- }
136
-
137
- if (isAgent) {
138
- return ['agent']
139
- }
131
+ const override = getReporterOverride()
132
+ if (override) return override
140
133
 
134
+ const { GITHUB_ACTIONS } = process.env
141
135
  return [
142
136
  'default',
143
137
  GITHUB_ACTIONS && 'github-actions',
@@ -152,6 +146,50 @@ function getReporters(junitReporterEnabled, testType) {
152
146
  ].filter(Boolean)
153
147
  }
154
148
 
149
+ /**
150
+ * Reporters for the monorepo root config (Vitest `projects` mode).
151
+ *
152
+ * `reporters` is a root-only Vitest option: per-project reporters are ignored
153
+ * when running via `projects`. So the per-package SummaryReporter never runs in
154
+ * the aggregate root run, and - crucially - a root-level SummaryReporter sees
155
+ * the test modules of ALL projects at once, letting it report the slowest tests
156
+ * across the entire monorepo.
157
+ *
158
+ * Use it in the root vitest.config.ts:
159
+ *
160
+ * export default defineConfig({
161
+ * test: {
162
+ * projects: ['./packages/*'],
163
+ * reporters: getRootReporters(),
164
+ * },
165
+ * })
166
+ */
167
+ export function getRootReporters() {
168
+ const override = getReporterOverride()
169
+ if (override) return override
170
+
171
+ const { GITHUB_ACTIONS } = process.env
172
+ return ['default', GITHUB_ACTIONS && 'github-actions', new SummaryReporter()].filter(Boolean)
173
+ }
174
+
175
+ /**
176
+ * Reporter overrides shared by both the per-package and root configs:
177
+ * - VITEST_REPORTER env var fully replaces the reporter set
178
+ * - agents get the compact 'agent' reporter, with no summary
179
+ *
180
+ * Returns `undefined` when no override applies (caller uses its own defaults).
181
+ */
182
+ function getReporterOverride() {
183
+ const { VITEST_REPORTER } = process.env
184
+ if (VITEST_REPORTER) {
185
+ return [VITEST_REPORTER]
186
+ }
187
+ if (isAgent) {
188
+ return ['agent']
189
+ }
190
+ return undefined
191
+ }
192
+
155
193
  function doesItRunInIDE() {
156
194
  // example command line below:
157
195
  // /usr/local/bin/node /Users/some/Idea/some/node_modules/vitest/vitest.mjs --run --reporter /Users/some/Library/Application Support/JetBrains/IntelliJIdea2025.2/plugins/javascript-plugin/helpers/vitest-intellij/node_modules/vitest-intellij-reporter-safe.js --testNamePattern=^ ?case 001: empty data$ /Users/some/Idea/some/src/some/some.integration.test.ts
@@ -9,11 +9,11 @@ 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';
11
11
  import { _stringMapEntries } from '@naturalcycles/js-lib/types';
12
+ import { _parseArgs } from '@naturalcycles/nodejs-lib/args';
12
13
  import { dimGrey, white } from '@naturalcycles/nodejs-lib/colors';
13
14
  import { exec2 } from '@naturalcycles/nodejs-lib/exec2';
14
15
  import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
15
16
  import { kpySync } from '@naturalcycles/nodejs-lib/kpy';
16
- import { _yargs } from '@naturalcycles/nodejs-lib/yargs';
17
17
  import { eslintExtensions, lintExclude, minActionlintVersion, prettierDirs, stylelintExtensions, } from '../cfg/_cnst.js';
18
18
  import { cfgDir } from './paths.js';
19
19
  const { CI } = process.env;
@@ -137,7 +137,7 @@ export async function runCheck(opt = {}) {
137
137
  * Returns true if it ran
138
138
  */
139
139
  export function eslintAll(opt) {
140
- const { argv } = _yargs().options({
140
+ const argv = _parseArgs({
141
141
  ext: {
142
142
  type: 'string',
143
143
  default: eslintExtensions,
@@ -249,12 +249,12 @@ const stylelintPaths = [
249
249
  * Returns true if it ran.
250
250
  */
251
251
  export function stylelintAll(fix) {
252
- const argv = _yargs().options({
252
+ const argv = _parseArgs({
253
253
  fix: {
254
254
  type: 'boolean',
255
255
  default: !CI, // defaults to false in CI, true otherwise
256
256
  },
257
- }).argv;
257
+ });
258
258
  fix ??= argv.fix;
259
259
  const config = [`./stylelint.config.js`].find(f => existsSync(f));
260
260
  if (!config) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "20.49.3",
4
+ "version": "20.51.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15",
@@ -11,7 +11,7 @@
11
11
  "lint-staged": "^17",
12
12
  "oxfmt": "^0",
13
13
  "oxlint": "^1",
14
- "oxlint-tsgolint": "^0",
14
+ "oxlint-tsgolint": "0.23.0",
15
15
  "picomatch": "^4",
16
16
  "prompts": "^2",
17
17
  "std-env": "^4"