Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Deploy with CARS

on:
pull_request:
branches: [master]
push:
branches:
- master
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id='root'></div>
<div id='root'>
<div role='status' style='font: 18px system-ui,sans-serif; padding: 48px; text-align: center; color: #ddd; background: #121212; min-height: 100vh; box-sizing: border-box'>
Loading PeerPay…
</div>
</div>
</body>
</html>
21 changes: 21 additions & 0 deletions frontend/tooling/compact-prompt-icons.mjs
Original file line number Diff line number Diff line change
@@ -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,
}
},
}
}
28 changes: 28 additions & 0 deletions frontend/tooling/compact-prompt-icons.test.mjs
Original file line number Diff line number Diff line change
@@ -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/)
}
})
})
3 changes: 2 additions & 1 deletion frontend/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -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'
},
Expand Down
Loading