diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index e619620..e1b76ff 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,6 +1,8 @@ name: Deploy with CARS on: + pull_request: + branches: [master] push: branches: - master @@ -14,8 +16,38 @@ permissions: contents: read jobs: + verify: + name: Verify frontend + runs-on: ubuntu-latest + timeout-minutes: 10 + defaults: + run: + working-directory: frontend + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 + with: + node-version: 22 + cache: npm + cache-dependency-path: frontend/package-lock.json + - run: npm ci + - run: npm test + - run: npx tsc --noEmit + - run: npm run build + - name: Bound startup JavaScript + run: | + node --input-type=module - <<'JS' + import { readdirSync, statSync } from 'node:fs' + const files = readdirSync('build/assets').filter(name => /^index-.*\.js$/.test(name)) + if (files.length !== 1 || statSync('build/assets/' + files[0]).size > 2200000) { + throw new Error('PeerPay startup bundle exceeds its reviewed 2.2 MB budget') + } + JS + deploy: name: Verify and deploy + if: github.event_name != 'pull_request' + needs: verify runs-on: ubuntu-latest timeout-minutes: 30 env: diff --git a/frontend/index.html b/frontend/index.html index 200c82b..acd0cb3 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -15,6 +15,10 @@ -
+
+
+ Loading PeerPay… +
+
diff --git a/frontend/tooling/compact-prompt-icons.mjs b/frontend/tooling/compact-prompt-icons.mjs new file mode 100644 index 0000000..ab0437e --- /dev/null +++ b/frontend/tooling/compact-prompt-icons.mjs @@ -0,0 +1,21 @@ +// metanet-react-prompt 1.0.6 uses one icon through a CommonJS barrel require. +// That require retains the entire Material icon library in the startup bundle. +// Keep its behavior, replacing only this known import with the individual icon. +export function compactPromptIcons() { + return { + name: 'compact-metanet-prompt-icons', + enforce: 'pre', + transform(code, id) { + if (!id.replaceAll('\\', '/').endsWith('/metanet-react-prompt/out/src/components/DownloadButton.js')) return null + const original = 'const icons_material_1 = require("@mui/icons-material");' + const uses = [...code.matchAll(/icons_material_1\.([A-Za-z0-9_]+)/g)].map(match => match[1]) + if (code.split(original).length !== 2 || !uses.length || uses.some(name => name !== 'KeyboardArrowDownOutlined')) { + throw new Error('metanet-react-prompt icon implementation changed; review the narrow import before building') + } + return { + code: code.replace(original, 'const icons_material_1 = { KeyboardArrowDownOutlined: require("@mui/icons-material/KeyboardArrowDownOutlined").default };'), + map: null, + } + }, + } +} diff --git a/frontend/tooling/compact-prompt-icons.test.mjs b/frontend/tooling/compact-prompt-icons.test.mjs new file mode 100644 index 0000000..fb339e5 --- /dev/null +++ b/frontend/tooling/compact-prompt-icons.test.mjs @@ -0,0 +1,28 @@ +import { describe, it, expect } from 'vitest' +import { readFileSync } from 'node:fs' +import { createRequire } from 'node:module' +import { compactPromptIcons } from './compact-prompt-icons.mjs' + +const require = createRequire(import.meta.url) +const path = require.resolve('metanet-react-prompt').replace(/out\/src\/index\.js$/, 'out/src/components/DownloadButton.js') + +describe('prompt icon startup import', () => { + it('rewrites the installed dependency to its single used icon', () => { + const source = readFileSync(path, 'utf8') + const result = compactPromptIcons().transform(source, path) + expect(result.code).not.toContain('require("@mui/icons-material")') + expect(result.code).toContain('require("@mui/icons-material/KeyboardArrowDownOutlined").default') + expect(result.code).toContain('icons_material_1.KeyboardArrowDownOutlined') + }) + + it('does not rewrite application imports or another dependency', () => { + expect(compactPromptIcons().transform('require("@mui/icons-material")', '/other/DownloadButton.js')).toBeNull() + }) + + it('rejects changed imports or additional icon usage instead of emitting a broken UI', () => { + const source = readFileSync(path, 'utf8') + for (const changed of [source.replace('const icons_material_1', 'const renamed'), source + '\nicons_material_1.UnexpectedIcon;']) { + expect(() => compactPromptIcons().transform(changed, path)).toThrow(/implementation changed/) + } + }) +}) diff --git a/frontend/vite.config.mjs b/frontend/vite.config.mjs index c768778..fa8072f 100644 --- a/frontend/vite.config.mjs +++ b/frontend/vite.config.mjs @@ -1,8 +1,9 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import { compactPromptIcons } from './tooling/compact-prompt-icons.mjs' export default defineConfig({ - plugins: [react()], + plugins: [compactPromptIcons(), react()], build: { outDir: 'build' },