diff --git a/.changeset/tidy-beans-smile.md b/.changeset/tidy-beans-smile.md new file mode 100644 index 00000000000..627d1d9ef34 --- /dev/null +++ b/.changeset/tidy-beans-smile.md @@ -0,0 +1,5 @@ +--- +'react-docgen': patch +--- + +Support Babel 8 dependency overrides for parsing and traversal, including TypeScript generic props, inherited interfaces, function types, and mapped types. Preserve Babel 7 compatibility. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c81c218d60..22577fb3434 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,16 +15,33 @@ env: jobs: tests: strategy: + fail-fast: false matrix: + babel: ["7", "8"] node: ["22.13.0", "24", "25", "26"] os: ["ubuntu"] + exclude: + # Babel 8 requires Node.js 22.18.0 or newer on the 22.x line. + - babel: "8" + node: "22.13.0" include: + - os: ubuntu + node: "22.18.0" + babel: "8" - os: macos node: "24" + babel: "7" + - os: macos + node: "24" + babel: "8" + - os: windows + node: "24" + babel: "7" - os: windows node: "24" + babel: "8" - name: Tests (Node.js v${{ matrix.node }}, ${{ matrix.os }}) + name: Tests (Babel ${{ matrix.babel }}, Node.js v${{ matrix.node }}, ${{ matrix.os }}) runs-on: ${{ matrix.os }}-latest steps: @@ -43,13 +60,21 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile + # Compile against the declared Babel 7 types before testing each runtime. + - name: Build packages + run: pnpm build + + - name: Install Babel 8 runtime + if: "${{ matrix.babel == '8' }}" + run: pnpm --filter react-docgen add --save-exact @babel/core@8.0.1 @babel/traverse@8.0.4 @babel/types@8.0.4 + - name: Unit tests with coverage if: "${{ matrix.node == env.NODE_VERSION }}" - run: pnpm test -- --coverage + run: pnpm --filter react-docgen --filter @react-docgen/cli --parallel --no-bail test --coverage - name: Unit tests if: "${{ matrix.node != env.NODE_VERSION }}" - run: pnpm test + run: pnpm --filter react-docgen --filter @react-docgen/cli --parallel --no-bail test - name: Upload coverage if: "${{ matrix.node == env.NODE_VERSION }}" @@ -57,7 +82,7 @@ jobs: uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2 with: parallel: true - flag-name: test-${{ matrix.os }} + flag-name: test-babel-${{ matrix.babel }}-${{ matrix.os }} finish: needs: tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7b34655b005..b81da617193 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,26 @@ We actively welcome your pull requests. 4. Ensure the test suite passes. 5. Make sure your code lints and typechecks. +## Babel compatibility tests + +CI runs all library and CLI tests separately with Babel 7 and Babel 8. +Both runs build with the declared Babel 7 dependencies first. The Babel 8 +run then replaces the runtime dependencies, including those used by CLI +subprocesses. This checks runtime compatibility, not compilation with Babel 8 types. + +To reproduce the Babel 8 run in a clean checkout: + +```sh +pnpm install --frozen-lockfile +pnpm build +pnpm --filter react-docgen add --save-exact @babel/core@8.0.1 @babel/traverse@8.0.4 @babel/types@8.0.4 +pnpm --filter react-docgen --filter @react-docgen/cli --parallel --no-bail test --coverage +``` + +The install command changes `packages/react-docgen/package.json` and +`pnpm-lock.yaml`. After testing, restore those two files and run +`pnpm install --frozen-lockfile` to return to Babel 7. + ## Issues We use GitHub issues to track public bugs. Please ensure your description is clear and has sufficient instructions to be able to reproduce the issue. diff --git a/packages/react-docgen/src/__tests__/parserCompatibility-test.ts b/packages/react-docgen/src/__tests__/parserCompatibility-test.ts new file mode 100644 index 00000000000..c086c0dd96a --- /dev/null +++ b/packages/react-docgen/src/__tests__/parserCompatibility-test.ts @@ -0,0 +1,73 @@ +import { parse } from '../main.js'; +import { expect, test } from 'vitest'; + +test('parses components', () => { + const result = parse('export function Button() { return