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