Skip to content

Commit 897112a

Browse files
committed
ci: verify common treeshaking issues in CI
1 parent 73ae6ad commit 897112a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ jobs:
8585
- name: Run e2e tests
8686
run: pnpm run test-e2e
8787

88+
- name: verify treeshaking
89+
run: node scripts/verify-treeshaking.js
90+
8891
lint-and-test-dts:
8992
runs-on: ubuntu-latest
9093
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

scripts/verify-treeshaking.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// @ts-check
2+
import fs from 'node:fs'
3+
import { execa } from 'execa'
4+
5+
execa('node', ['scripts/build.js', 'vue', '-f', 'global-runtime']).then(() => {
6+
const errors = []
7+
8+
const devBuild = fs.readFileSync(
9+
'packages/vue/dist/vue.runtime.global.js',
10+
'utf-8'
11+
)
12+
13+
if (devBuild.includes('__spreadValues')) {
14+
errors.push(
15+
'dev build contains unexpected esbuild object spread helper.\n' +
16+
'This means { ...obj } syntax is used in runtime code. This should be ' +
17+
'refactoed to use the `extend` helper to avoid the extra code.'
18+
)
19+
}
20+
21+
const prodBuild = fs.readFileSync(
22+
'packages/vue/dist/vue.runtime.global.prod.js',
23+
'utf-8'
24+
)
25+
26+
if (prodBuild.includes('Vue warn')) {
27+
errors.push(
28+
'prod build contains unexpected warning-related code.\n' +
29+
'This means there are calls of warn() that are not guarded by the __DEV__ condition.'
30+
)
31+
}
32+
33+
if (
34+
prodBuild.includes('html,body,base') ||
35+
prodBuild.includes('svg,animate,animateMotion') ||
36+
prodBuild.includes('annotation,annotation-xml,maction')
37+
) {
38+
errors.push(
39+
'prod build contains unexpected domTagConifg lists.\n' +
40+
'This means helpers like isHTMLTag() is used in runtime code paths when it should be compiler-only.'
41+
)
42+
}
43+
44+
if (errors.length) {
45+
throw new Error(
46+
`Found the following treeshaking errors:\n\n- ${errors.join('\n\n- ')}`
47+
)
48+
}
49+
})

0 commit comments

Comments
 (0)