Skip to content

Commit b42284d

Browse files
committed
fix(ci): make typecheck/lint/test build-order-independent
CI was red because the migration left three build-order assumptions that only surfaced in a fresh checkout: the typecheck job still ran the removed `yarn flow`; `make lint` and the typeCompat test resolved `react-draggable` to the generated build/cjs/cjs.d.ts, which doesn't exist before `yarn build`. The workflow's own verify ran against a pre-populated build/, hiding it. Repoint typings/tsconfig.json and test/typeCompat/tsconfig.json at the source entry (lib/cjs.ts) instead of the built declaration — same public surface, no build dependency. Drop the build-exists guard in typeCompat.test.ts. Replace the dead `yarn flow` CI step with `yarn tsc --noEmit`. Verified lint/typecheck/test/coverage/build all green with build/ absent.
1 parent 6618f76 commit b42284d

4 files changed

Lines changed: 22 additions & 31 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ jobs:
9898
- name: Install dependencies
9999
run: yarn install --frozen-lockfile
100100

101-
- name: Flow check
102-
run: yarn flow
101+
- name: TypeScript check (source)
102+
run: yarn tsc --noEmit
103103

104-
- name: TypeScript check
104+
- name: TypeScript check (public typings)
105105
run: yarn tsc -p typings

test/typeCompat.test.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import {describe, it, expect, beforeAll} from 'vitest';
1+
import {describe, it, expect} from 'vitest';
22
import {execFileSync} from 'node:child_process';
3-
import {existsSync} from 'node:fs';
43
import {resolve, dirname} from 'node:path';
54
import {fileURLToPath} from 'node:url';
65
import {createRequire} from 'node:module';
76

87
// ─────────────────────────────────────────────────────────────────────────────
98
// Public type-surface compatibility guard.
109
//
11-
// After the Flow -> TypeScript migration the public `.d.ts` is AUTO-GENERATED
12-
// from source (build/cjs/cjs.d.ts) instead of hand-written (the old
13-
// typings/index.d.ts, now deleted). This test asserts the generated surface is
14-
// still API-compatible with that old surface by compiling two type-assertion
15-
// files against the generated declaration with `tsc`:
10+
// After the Flow -> TypeScript migration the public `.d.ts` is generated from the
11+
// source entry (lib/cjs.ts) instead of hand-written (the old typings/index.d.ts,
12+
// now deleted). The published declaration is a faithful tsc/tsup projection of
13+
// that source surface, so this test asserts compatibility against the source
14+
// entry directly — which keeps the check build-order-independent (no prior
15+
// `yarn build` required) while exercising the exact public surface the shipped
16+
// `.d.ts` is derived from. The build itself (tsup --dts) is what guarantees the
17+
// declaration emits cleanly.
1618
//
19+
// Both projects below map `react-draggable` -> ../lib/cjs.ts and compile with
20+
// `tsc`:
1721
// 1. test/typeCompat/fixture.tsx — exhaustively exercises every exported name
1822
// and every prop from the old typings/index.d.ts. Removing/renaming/retyping
19-
// any export or prop makes this stop compiling.
23+
// any export or prop (e.g. narrowing children from ReactNode) stops it
24+
// compiling.
2025
// 2. typings/test.tsx — the project's existing consumer-style smoke test,
21-
// compiled UNCHANGED against the generated types (incl. zero-prop usage,
22-
// which only works if the public props remain optional like the old
23-
// `Partial<DraggableProps>` surface).
24-
//
25-
// If the CJS declaration hasn't been built yet, the test fails with an actionable
26-
// message rather than silently passing.
26+
// compiled UNCHANGED (incl. zero-prop usage, which only works if the public
27+
// props remain optional like the old `Partial<DraggableProps>` surface).
2728
// ─────────────────────────────────────────────────────────────────────────────
2829

2930
const __dirname = dirname(fileURLToPath(import.meta.url));
3031
const repoRoot = resolve(__dirname, '..');
3132
const require = createRequire(import.meta.url);
3233
const tscBin = require.resolve('typescript/bin/tsc');
33-
const generatedDts = resolve(repoRoot, 'build/cjs/cjs.d.ts');
3434

3535
function runTsc(projectDir: string): {ok: boolean; output: string} {
3636
try {
@@ -47,22 +47,13 @@ function runTsc(projectDir: string): {ok: boolean; output: string} {
4747
}
4848

4949
describe('public type-surface compatibility', () => {
50-
beforeAll(() => {
51-
if (!existsSync(generatedDts)) {
52-
throw new Error(
53-
`Generated declaration not found at ${generatedDts}. Run \`yarn build\` ` +
54-
`before running the type-compat test (it asserts against the built .d.ts).`
55-
);
56-
}
57-
});
58-
59-
it('generated .d.ts is API-compatible with the old hand-written surface', () => {
50+
it('public surface is API-compatible with the old hand-written surface', () => {
6051
const {ok, output} = runTsc(resolve(__dirname, 'typeCompat'));
6152
expect(output, output).toBe('');
6253
expect(ok).toBe(true);
6354
});
6455

65-
it('the existing typings/test.tsx still compiles unchanged against generated types', () => {
56+
it('the existing typings/test.tsx still compiles unchanged against the public surface', () => {
6657
const {ok, output} = runTsc(resolve(repoRoot, 'typings'));
6758
expect(output, output).toBe('');
6859
expect(ok).toBe(true);

test/typeCompat/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"types": ["react", "react-dom", "node"],
1111
"baseUrl": ".",
1212
"paths": {
13-
"react-draggable": ["../../build/cjs/cjs.d.ts"]
13+
"react-draggable": ["../../lib/cjs.ts"]
1414
}
1515
},
1616
"files": [

typings/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"esModuleInterop": true,
88
"baseUrl": ".",
99
"paths": {
10-
"react-draggable": ["../build/cjs/cjs.d.ts"]
10+
"react-draggable": ["../lib/cjs.ts"]
1111
}
1212
},
1313
"files": [

0 commit comments

Comments
 (0)