From 07a7ec3b81212406b7915cda3155d26f036b1b19 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Fri, 2 Feb 2024 15:56:02 -0500 Subject: [PATCH] chore(build): add script to stop exporting demos in built files (#10063) * chore(build): add script to stop exporting demos in built files * chore(build): update to remove demo exports from shipped TS files also * chore(ci): update deployment to clean exports of demos --- .github/workflows/release.yml | 16 +--------------- package.json | 1 + packages/react-core/package.json | 3 ++- packages/react-core/scripts/cleanDistExports.js | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 packages/react-core/scripts/cleanDistExports.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6285416ac42..074954e5150 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -335,22 +335,8 @@ jobs: key: ${{ runner.os }}-yarn-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock') }} - run: yarn install --frozen-lockfile if: steps.yarn-cache.outputs.cache-hit != 'true' - - uses: actions/cache@v2 - id: dist - name: Cache dist - with: - path: | - packages/*/dist - packages/*/next - packages/*/deprecated - packages/*/components - packages/react-styles/css - packages/react-core/layouts - packages/react-core/helpers - key: ${{ runner.os }}-dist-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('yarn.lock', 'package.json', 'packages/*/*', '!packages/*/dist', '!packages/*/node_modules') }} - name: Build dist - run: yarn build && yarn build:umd + run: yarn build && yarn build:umd && yarn clean:exports if: steps.dist.outputs.cache-hit != 'true' - name: Deploy to NPM and Github run: .github/release.sh - diff --git a/package.json b/package.json index f8c3db8b07e..7c4fd7f5c0f 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "build:single:packages": "lerna run build:single:packages", "clean": "yarn clean:build && lerna run clean --parallel", "clean:build": "rimraf .cache .eslintcache coverage", + "clean:exports": "lerna run clean:exports --parallel --stream", "generate": "yarn plop", "lint": "node --max-old-space-size=4096 node_modules/.bin/eslint --ext js,jsx,ts,tsx --cache", "lint:all": "yarn lint:md && yarn lint:versions && yarn lint:ts", diff --git a/packages/react-core/package.json b/packages/react-core/package.json index ea4209da6dc..ad8eaa94634 100644 --- a/packages/react-core/package.json +++ b/packages/react-core/package.json @@ -42,7 +42,8 @@ "build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json", "clean": "rimraf dist components layouts helpers next deprecated node_modules", "generate": "node scripts/copyStyles.js", - "subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json" + "subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json", + "clean:exports": "node scripts/cleanDistExports.js" }, "dependencies": { "@patternfly/react-icons": "^5.2.0-prerelease.10", diff --git a/packages/react-core/scripts/cleanDistExports.js b/packages/react-core/scripts/cleanDistExports.js new file mode 100644 index 00000000000..58e4dcd07f2 --- /dev/null +++ b/packages/react-core/scripts/cleanDistExports.js @@ -0,0 +1,14 @@ +const fs = require('fs'); +const path = require('path'); + +const distIndexFiles = ['esm', 'js'].map((dir) => path.join(process.cwd(), 'dist', dir, 'index.js')); +const distIndexDeclarationFiles = ['esm', 'js'].map((dir) => path.join(process.cwd(), 'dist', dir, 'index.d.ts')); + +[...distIndexFiles, ...distIndexDeclarationFiles].forEach((file) => { + const fileContents = fs.readFileSync(file, 'utf8'); + const newFileContents = fileContents + .split('\n') + .filter((line) => !line.includes('demos')) + .join('\n'); + fs.writeFileSync(file, newFileContents); +});