From 7b18589fa62a73a142ab97f47b25b3f0a02f1e8c Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 10 Jul 2023 11:04:32 -0500 Subject: [PATCH 1/4] chore(npm): add types packages as optional peer deps --- consumer-test/App.tsx | 1 + consumer-test/package.json | 6 ++++++ package-lock.json | 14 ++++++++++++++ package.json | 15 +++++++++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/consumer-test/App.tsx b/consumer-test/App.tsx index a34d321edf8..0d947c6888d 100644 --- a/consumer-test/App.tsx +++ b/consumer-test/App.tsx @@ -1,3 +1,4 @@ +import React from 'react' import {Box} from '@primer/react' export default function App() { diff --git a/consumer-test/package.json b/consumer-test/package.json index 41915e5fab5..fd56c86bf03 100644 --- a/consumer-test/package.json +++ b/consumer-test/package.json @@ -3,7 +3,13 @@ "check": "tsc --noEmit" }, "dependencies": { + "@types/react": "^18.2.14", + "@types/react-dom": "^18.2.6", + "@types/styled-components": "^5.1.11", "@primer/react": "*", + "react": "^18.0.0", + "react-dom": "^18.0.0", + "styled-components": "^5.3.11", "typescript": "~4.7.2" } } diff --git a/package-lock.json b/package-lock.json index 3244d936886..f760343fe00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -178,9 +178,23 @@ "npm": ">=7" }, "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "@types/styled-components": "^5.1.11", "react": "^18.0.0", "react-dom": "^18.0.0", "styled-components": "4.x || 5.x" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + }, + "@types/styled-components": { + "optional": true + } } }, "node_modules/@actions/core": { diff --git a/package.json b/package.json index e47bb5e631d..85151f46bd1 100644 --- a/package.json +++ b/package.json @@ -258,12 +258,23 @@ "yaml": "2.2.2" }, "peerDependencies": { + "@types/react": "^18.0.0", + "@types/react-dom": "^18.0.0", + "@types/styled-components": "^5.1.11", "react": "^18.0.0", "react-dom": "^18.0.0", "styled-components": "4.x || 5.x" }, - "optionalPeerDependencies": { - "@types/styled-components": "^5.1.11" + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + }, + "@types/styled-components": { + "optional": true + } }, "prettier": "@github/prettier-config", "size-limit": [ From 48d218d443ecbe9d719f3646c7b8b70a8f6ad6ee Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 10 Jul 2023 11:28:59 -0500 Subject: [PATCH 2/4] chore(deps): update lockfile --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index f760343fe00..57651e09d79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -178,8 +178,8 @@ "npm": ">=7" }, "peerDependencies": { - "@types/react": "*", - "@types/react-dom": "*", + "@types/react": "^18.0.0", + "@types/react-dom": "^18.0.0", "@types/styled-components": "^5.1.11", "react": "^18.0.0", "react-dom": "^18.0.0", From f5b56971d4ff2912fac0e8899cb5f3e2484d0f87 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 10 Jul 2023 11:29:31 -0500 Subject: [PATCH 3/4] ci: update consumer test workflow to use npm pack versus npm link --- .github/workflows/consumer_test.yml | 32 +++++++++-------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/.github/workflows/consumer_test.yml b/.github/workflows/consumer_test.yml index feaa389ae3b..adbec5b83bc 100644 --- a/.github/workflows/consumer_test.yml +++ b/.github/workflows/consumer_test.yml @@ -11,41 +11,29 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: 18 cache: npm - - # `prepare` is a special case in `npm` and likes to run all the time, even - # with `--ignore-scripts` and even when using `npm link @primer/react - # --ignore-scripts`. This just removes it entirely for the duration of - # this workflow. - - name: Remove "prepare" script - run: npm pkg delete scripts.prepare - - name: Install dependencies run: npm ci - - name: Build run: npm run build - - - name: Install only production dependencies - run: npm ci --production - - - name: Link - run: npm link - - - name: Link and test - id: link-and-test + # Output the artifact as a tarball in `consumer-test`. Write the + # information for this package in `consumer-test/pack.json` so we can read + # from it later to install the package + - name: Create a tarball for the package + run: npm pack --pack-destination consumer-test --json > consumer-test/pack.json + - name: Test + id: test working-directory: consumer-test run: | + # Read the filename for the tarball from `pack.json` + npm install $(jq -r '.[0].filename' pack.json) npm install - npm link @primer/react npm run check - - name: Add annotation - if: failure() && steps.link-and-test.conclusion == 'failure' + if: failure() && steps.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" From f17566703b807aceca33cb7cf1a788d90764b105 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 10 Jul 2023 11:33:02 -0500 Subject: [PATCH 4/4] ci: reset package workspace --- .github/workflows/consumer_test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/consumer_test.yml b/.github/workflows/consumer_test.yml index adbec5b83bc..5775e2d16d6 100644 --- a/.github/workflows/consumer_test.yml +++ b/.github/workflows/consumer_test.yml @@ -25,6 +25,10 @@ jobs: # from it later to install the package - name: Create a tarball for the package run: npm pack --pack-destination consumer-test --json > consumer-test/pack.json + - name: Clean package directory + run: | + npm run clean + rm -rf node_modules - name: Test id: test working-directory: consumer-test