diff --git a/.eslintrc.json b/.eslintrc.json index 8cfb1b1e801..c521cee7d2c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,7 +23,7 @@ "lib/**/*", "lib-*/**/*", "types/**/*", - "test-types/**/*" + "consumer-test/**/*" ], "globals": { "__DEV__": "readonly" diff --git a/.github/workflows/test_types.yml b/.github/workflows/consumer_test.yml similarity index 71% rename from .github/workflows/test_types.yml rename to .github/workflows/consumer_test.yml index d53a05e69e0..659b0a7addf 100644 --- a/.github/workflows/test_types.yml +++ b/.github/workflows/consumer_test.yml @@ -1,12 +1,12 @@ -name: Test types +name: Consumer test on: push: {branches: main} - pull_request: {branches: main} + pull_request: workflow_dispatch: jobs: - test-types: - name: Test types + consumer-test: + name: Consumer test runs-on: ubuntu-latest steps: - name: Checkout repository @@ -38,8 +38,14 @@ jobs: run: npm link - name: Link and test - working-directory: test-types + id: link-and-test + working-directory: consumer-test run: | npm install npm link @primer/react npm run check + + - name: Add annotation + if: failure() && steps.link-and-test.conclusion == 'failure' + run: | + echo "::error file=tsconfig.build.json::Test package could not build. See https://github.com/primer/react/blob/main/consumer-test" diff --git a/test-types/App.tsx b/consumer-test/App.tsx similarity index 100% rename from test-types/App.tsx rename to consumer-test/App.tsx diff --git a/consumer-test/README.md b/consumer-test/README.md new file mode 100644 index 00000000000..6e7ac65e3ba --- /dev/null +++ b/consumer-test/README.md @@ -0,0 +1,25 @@ +# Primer React Consumer Test + +This directory is used to run a simple test that asserts that a consumer of +Primer React can build their own project with strict TypeScript options enabled, +including `"skipLibCheck": false`. + +During Primer React's build process, we run the TypeScript compiler and output +`.d.ts` declaration files for consumers of Primer React that are using +TypeScript. If the build script runs with a TypeScript configuration that has +any files in its `types` or `typeRoots` that import any of our development +dependencies, it's possible for our build output to be polluted by interface +augmentations in those dependencies, or in transitive dependencies. + +The best way to avoid this is to ensure that any files that import development +dependencies are excluded in our `tsconfig.build.json` file we use to build +Primer React. + +If a mistake is made and a file is omitted, we will catch those when we attempt +to build this consumer library, which has `"skipLibCheck": false` in its +TypeScript configuration. + +For historical context, see these issues: + +- [v27.0.0 breaks TypeScript typings](https://github.com/primer/react/issues/1163) +- [Storybook dependency changes types in build output](https://github.com/primer/react/issues/1849) diff --git a/test-types/package.json b/consumer-test/package.json similarity index 100% rename from test-types/package.json rename to consumer-test/package.json diff --git a/test-types/tsconfig.json b/consumer-test/tsconfig.json similarity index 100% rename from test-types/tsconfig.json rename to consumer-test/tsconfig.json