Skip to content

fix(scripts): add error handling to verify-treeshaking script #13192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
81 changes: 43 additions & 38 deletions scripts/verify-treeshaking.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,53 @@
import fs from 'node:fs'
import { exec } from './utils.js'

exec('pnpm', ['build', 'vue', '-f', 'global-runtime']).then(() => {
const errors = []
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 devBuild = fs.readFileSync(
'packages/vue/dist/vue.runtime.global.js',
'utf-8',
)
}

const prodBuild = fs.readFileSync(
'packages/vue/dist/vue.runtime.global.prod.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.',
)
}

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.',
const prodBuild = fs.readFileSync(
'packages/vue/dist/vue.runtime.global.prod.js',
'utf-8',
)
}

if (
prodBuild.includes('html,body,base') ||
prodBuild.includes('svg,animate,animateMotion') ||
prodBuild.includes('annotation,annotation-xml,maction')
) {
errors.push(
'prod build contains unexpected domTagConfig lists.\n' +
'This means helpers like isHTMLTag() is used in runtime code paths when it should be compiler-only.',
)
}
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 (errors.length) {
throw new Error(
`Found the following treeshaking errors:\n\n- ${errors.join('\n\n- ')}`,
)
}
})
if (
prodBuild.includes('html,body,base') ||
prodBuild.includes('svg,animate,animateMotion') ||
prodBuild.includes('annotation,annotation-xml,maction')
) {
errors.push(
'prod build contains unexpected domTagConfig 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- ')}`,
)
}
})
.catch(error => {
console.error(`Treeshaking verification failed: ${error.message}`)
process.exit(1)
})