From 9c29461ee527121a7b5d8283682c737e5c52cf6b Mon Sep 17 00:00:00 2001 From: Fredrik Strand Oseberg Date: Tue, 12 Mar 2024 13:29:52 +0100 Subject: [PATCH] chore: add a script that validates that we don't use prohibited mui material-icons import (#6516) This PR adds a check that should fail the build if we use disallowed imports from `@mui/icons-material` --- .github/workflows/build_frontend_prs.yml | 1 + frontend/check-imports.rc | 7 +++++++ frontend/package.json | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100755 frontend/check-imports.rc diff --git a/.github/workflows/build_frontend_prs.yml b/.github/workflows/build_frontend_prs.yml index 6bf533c0671..7f7b2dbe181 100644 --- a/.github/workflows/build_frontend_prs.yml +++ b/.github/workflows/build_frontend_prs.yml @@ -20,6 +20,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} + - run: yarn run lint:material:icons - run: yarn --frozen-lockfile - run: yarn run lint:check - run: yarn run test diff --git a/frontend/check-imports.rc b/frontend/check-imports.rc new file mode 100755 index 00000000000..b367a6eaa38 --- /dev/null +++ b/frontend/check-imports.rc @@ -0,0 +1,7 @@ +if grep -R --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx" "from '@mui/icons-material'" src; then + echo "Prohibited import from '@mui/icons-material' found. Use default imports referencing the file instead of the + global package. Example: import Delete from '@mui/icons-material/Delete';'" + exit 1 +else + echo "No prohibited imports from '@mui/icons-material' found." +fi diff --git a/frontend/package.json b/frontend/package.json index f75c83d65b5..9c26908c1f0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -2,12 +2,15 @@ "name": "unleash-frontend-local", "version": "0.0.0", "private": true, - "files": ["index.js", "build"], + "files": [ + "index.js", + "build" + ], "engines": { "node": ">=18" }, "scripts": { - "build": "vite build", + "build": "yarn run lint:material:icons && vite build", "dev": "vite", "start": "vite", "start:prod": "vite build && vite preview", @@ -19,6 +22,7 @@ "test": "NODE_OPTIONS=\"${NODE_OPTIONS} --no-experimental-fetch\" vitest run", "test:snapshot": "NODE_OPTIONS=\"${NODE_OPTIONS} --no-experimental-fetch\" yarn test -u", "test:watch": "NODE_OPTIONS=\"${NODE_OPTIONS} --no-experimental-fetch\" vitest watch", + "lint:material:icons": "./check-imports.rc", "lint": "biome lint src --apply", "lint:check": "biome check src", "fmt": "biome format src --write", @@ -142,7 +146,11 @@ } }, "browserslist": { - "production": [">0.2%", "not dead", "not op_mini all"], + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], "development": [ "last 1 chrome version", "last 1 firefox version",