@rexezuge/tooling 1.12.0 → 1.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/README.md +124 -14
- package/dist/eslint-manifest.d.ts +25 -0
- package/dist/eslint-manifest.d.ts.map +1 -0
- package/dist/eslint-manifest.js +1 -0
- package/dist/eslint-manifest.js.map +7 -0
- package/dist/eslint-strict.d.ts +45 -0
- package/dist/eslint-strict.d.ts.map +1 -0
- package/dist/eslint-strict.js +1 -0
- package/dist/eslint-strict.js.map +7 -0
- package/dist/eslint.d.ts +20 -3
- package/dist/eslint.d.ts.map +1 -1
- package/dist/eslint.js +1 -1
- package/dist/eslint.js.map +3 -3
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/manifest-validate.d.ts +14 -0
- package/dist/manifest-validate.d.ts.map +1 -0
- package/dist/manifest-validate.js +1 -0
- package/dist/manifest-validate.js.map +7 -0
- package/dist/manifest.d.ts +159 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +3 -0
- package/dist/manifest.js.map +7 -0
- package/dist/scripts/check-god-files.d.ts.map +1 -1
- package/dist/scripts/check-god-files.js +2 -2
- package/dist/scripts/check-god-files.js.map +3 -3
- package/dist/test/mocks/cloudflare-workers.d.ts +6 -103
- package/dist/test/mocks/cloudflare-workers.d.ts.map +1 -1
- package/dist/test/mocks/cloudflare-workers.js +1 -1
- package/dist/test/mocks/cloudflare-workers.js.map +3 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js.map +2 -2
- package/dist/vitest-aliases.d.ts +3 -0
- package/dist/vitest-aliases.d.ts.map +1 -1
- package/dist/vitest-aliases.js +1 -1
- package/dist/vitest-aliases.js.map +3 -3
- package/dist/vitest-repo.d.ts +2 -1
- package/dist/vitest-repo.d.ts.map +1 -1
- package/dist/vitest-repo.js +1 -1
- package/dist/vitest-repo.js.map +3 -3
- package/dist/vitest.d.ts +2 -1
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +1 -1
- package/dist/vitest.js.map +3 -3
- package/package.json +14 -3
- package/presets/prettier.d.mts +4 -0
- package/presets/prettier.mjs +16 -0
- package/presets/tsconfig/base.json +19 -0
- package/presets/tsconfig/web.json +10 -0
- package/presets/tsconfig/worker.json +9 -0
- package/schema/manifest.schema.json +105 -0
- package/src/eslint-manifest.ts +71 -0
- package/src/eslint-strict.test.ts +106 -0
- package/src/eslint-strict.ts +191 -0
- package/src/eslint.ts +36 -8
- package/src/index.ts +15 -2
- package/src/manifest-validate.ts +202 -0
- package/src/manifest.test.ts +228 -0
- package/src/manifest.ts +194 -0
- package/src/presets.test.ts +63 -0
- package/src/scripts/check-god-files.ts +3 -0
- package/src/test/mocks/cloudflare-workers.ts +6 -113
- package/src/vite.ts +1 -0
- package/src/vitest-aliases.test.ts +23 -0
- package/src/vitest-aliases.ts +22 -1
- package/src/vitest-factories.test.ts +30 -1
- package/src/vitest-repo.ts +5 -2
- package/src/vitest.ts +5 -2
package/src/vitest-aliases.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
1
3
|
import { fileURLToPath } from 'node:url';
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -113,9 +115,24 @@ export interface WorkspaceAliasesOptions {
|
|
|
113
115
|
readonly extraAliases?: readonly VitestAlias[];
|
|
114
116
|
}
|
|
115
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Where the kit's own `cloudflare:workers` mock lives, or `null` when
|
|
120
|
+
* `@rexezuge/testing` is not resolvable from here.
|
|
121
|
+
*/
|
|
122
|
+
function kitWorkersMock(): string | null {
|
|
123
|
+
try {
|
|
124
|
+
return createRequire(import.meta.url).resolve('@rexezuge/testing/cloudflare-workers');
|
|
125
|
+
} catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
116
130
|
/**
|
|
117
131
|
* Build the workspace alias table for a consumer repo.
|
|
118
132
|
*
|
|
133
|
+
* `cloudflare:workers` resolves to `<root>/test/mocks/cloudflare-workers.ts` when
|
|
134
|
+
* that file exists, and otherwise to `@rexezuge/testing/cloudflare-workers`.
|
|
135
|
+
*
|
|
119
136
|
* Aliases point at source rather than at built output, so a test exercises the
|
|
120
137
|
* code the worker would run without a build step. `background` resolves under
|
|
121
138
|
* `apps/`; every other package under `packages/`. `@/` maps to the API worker
|
|
@@ -133,7 +150,11 @@ export function workspaceAliases(options: WorkspaceAliasesOptions): VitestAlias[
|
|
|
133
150
|
aliases.push({ find: `${scope}/${name}`, replacement: at(dir) });
|
|
134
151
|
}
|
|
135
152
|
for (const mock of mocks) {
|
|
136
|
-
|
|
153
|
+
const local = at(`test/mocks/cloudflare-${mock}.ts`);
|
|
154
|
+
// A repo with no copy of its own gets the kit's: the `workers` mock is a
|
|
155
|
+
// superset of the thirteen family copies, so deleting yours is safe.
|
|
156
|
+
const kit = mock === 'workers' && !existsSync(local) ? kitWorkersMock() : null;
|
|
157
|
+
aliases.push({ find: `cloudflare:${mock}`, replacement: kit ?? local });
|
|
137
158
|
}
|
|
138
159
|
const apiSrc = at('apps/api/src');
|
|
139
160
|
const webSrc = at('apps/web/src');
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
2
6
|
import { defineUnitVitestConfig } from './vitest.ts';
|
|
3
7
|
import { defineWebVitestConfig } from './vitest-web.ts';
|
|
4
8
|
import { defineRepoVitestConfig } from './vitest-repo.ts';
|
|
@@ -125,3 +129,28 @@ describe('defineIntegrationVitestConfig', () => {
|
|
|
125
129
|
expect(test['pool']).toBeUndefined();
|
|
126
130
|
});
|
|
127
131
|
});
|
|
132
|
+
|
|
133
|
+
describe('coverage thresholds from the manifest', () => {
|
|
134
|
+
const coverageOf = (config: unknown): { thresholds?: unknown } => (testOf(config)['coverage'] ?? {}) as { thresholds?: unknown };
|
|
135
|
+
let dir: string;
|
|
136
|
+
let root: string;
|
|
137
|
+
beforeAll(() => {
|
|
138
|
+
dir = mkdtempSync(path.join(tmpdir(), 'vitest-manifest-'));
|
|
139
|
+
root = pathToFileURL(`${dir}/`).href;
|
|
140
|
+
writeFileSync(
|
|
141
|
+
path.join(dir, '.rexezuge.jsonc'),
|
|
142
|
+
'{ "name": "x", "scope": "@x", "quality": { "coverage": { "lines": 71, "branches": 62, "functions": 73, "statements": 74 } } }',
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
afterAll(() => rmSync(dir, { recursive: true, force: true }));
|
|
146
|
+
|
|
147
|
+
const floor = { lines: 71, branches: 62, functions: 73, statements: 74 };
|
|
148
|
+
it('defaults the unit and repo factories to the manifest floor', () => {
|
|
149
|
+
expect(coverageOf(defineUnitVitestConfig({ root })).thresholds).toEqual(floor);
|
|
150
|
+
expect(coverageOf(defineRepoVitestConfig({ scope: '@x', root })).thresholds).toEqual(floor);
|
|
151
|
+
});
|
|
152
|
+
it('lets an explicit option win, and sets none without a manifest', () => {
|
|
153
|
+
expect(coverageOf(defineUnitVitestConfig({ root, thresholds: { lines: 5 } })).thresholds).toEqual({ lines: 5 });
|
|
154
|
+
expect(coverageOf(defineUnitVitestConfig({ root: ROOT })).thresholds).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
});
|
package/src/vitest-repo.ts
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import { defineConfig, type Plugin } from 'vitest/config';
|
|
27
27
|
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import { manifestCoverageThresholds } from './manifest.ts';
|
|
28
29
|
import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
|
|
29
30
|
import type { VitestAlias } from './vitest-aliases.ts';
|
|
30
31
|
import type { CoverageThresholds } from './vitest.ts';
|
|
@@ -140,7 +141,8 @@ export interface RepoVitestConfigOptions {
|
|
|
140
141
|
*/
|
|
141
142
|
readonly includeIndexBarrels?: boolean;
|
|
142
143
|
/**
|
|
143
|
-
* Coverage floors.
|
|
144
|
+
* Coverage floors. Defaults to the manifest's `quality.coverage` (`.rexezuge.jsonc`
|
|
145
|
+
* at `root`); without one, no floor.
|
|
144
146
|
*/
|
|
145
147
|
readonly thresholds?: CoverageThresholds;
|
|
146
148
|
/**
|
|
@@ -206,6 +208,7 @@ const INDEX_BARREL_EXCLUDE = '**/index.ts';
|
|
|
206
208
|
*/
|
|
207
209
|
export function defineRepoVitestConfig(options: RepoVitestConfigOptions): ReturnType<typeof defineConfig> {
|
|
208
210
|
const root = options.root ?? new URL('.', import.meta.url).href;
|
|
211
|
+
const thresholds = options.thresholds ?? manifestCoverageThresholds(root);
|
|
209
212
|
const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;
|
|
210
213
|
const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;
|
|
211
214
|
const noExternal = [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])];
|
|
@@ -275,7 +278,7 @@ export function defineRepoVitestConfig(options: RepoVitestConfigOptions): Return
|
|
|
275
278
|
exclude: options.includeIndexBarrels
|
|
276
279
|
? [...CANONICAL_COVERAGE_EXCLUDE.filter((glob) => glob !== INDEX_BARREL_EXCLUDE), ...(options.coverageExclude ?? [])]
|
|
277
280
|
: [...CANONICAL_COVERAGE_EXCLUDE, ...(options.coverageExclude ?? [])],
|
|
278
|
-
...(
|
|
281
|
+
...(thresholds !== undefined && { thresholds: { ...thresholds } }),
|
|
279
282
|
},
|
|
280
283
|
},
|
|
281
284
|
});
|
package/src/vitest.ts
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
import { defineConfig, type Plugin } from 'vitest/config';
|
|
37
|
+
import { manifestCoverageThresholds } from './manifest.ts';
|
|
37
38
|
import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_DEDUPE, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
|
|
38
39
|
import type { VitestAlias } from './vitest-aliases.ts';
|
|
39
40
|
|
|
@@ -147,7 +148,8 @@ export interface UnitVitestConfigOptions {
|
|
|
147
148
|
*/
|
|
148
149
|
readonly includeIndexBarrels?: boolean;
|
|
149
150
|
/**
|
|
150
|
-
* Coverage floors.
|
|
151
|
+
* Coverage floors. Defaults to the manifest's `quality.coverage` (`.rexezuge.jsonc`
|
|
152
|
+
* at `root`); without one, no floor.
|
|
151
153
|
*/
|
|
152
154
|
readonly thresholds?: CoverageThresholds;
|
|
153
155
|
/**
|
|
@@ -220,6 +222,7 @@ function coverageExcludeFor(options: { coverageExclude?: readonly string[]; incl
|
|
|
220
222
|
*/
|
|
221
223
|
export function defineUnitVitestConfig(options: UnitVitestConfigOptions = {}): ReturnType<typeof defineConfig> {
|
|
222
224
|
const root = options.root ?? new URL('.', import.meta.url).href;
|
|
225
|
+
const thresholds = options.thresholds ?? manifestCoverageThresholds(root);
|
|
223
226
|
const coverageInclude = options.coverageInclude ?? ['apps/api/src/**/*.ts', 'apps/background/src/**/*.ts', 'packages/**/src/**/*.ts'];
|
|
224
227
|
const coverageExclude = coverageExcludeFor(options);
|
|
225
228
|
const baseAliases = workspaceAliases({
|
|
@@ -278,7 +281,7 @@ export function defineUnitVitestConfig(options: UnitVitestConfigOptions = {}): R
|
|
|
278
281
|
reportsDirectory: options.reportsDirectory ?? './coverage',
|
|
279
282
|
include: [...coverageInclude],
|
|
280
283
|
exclude: coverageExclude,
|
|
281
|
-
...(
|
|
284
|
+
...(thresholds !== undefined && { thresholds: { ...thresholds } }),
|
|
282
285
|
},
|
|
283
286
|
},
|
|
284
287
|
});
|