Unverified Commit d642c700 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Add lodash deduplication analyzer eval

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent a44991d0
...@@ -45,5 +45,9 @@ ...@@ -45,5 +45,9 @@
"agent-060-server-markdown-renderer": { "agent-060-server-markdown-renderer": {
"skills": ["next-browser-initial-load-optimizer"], "skills": ["next-browser-initial-load-optimizer"],
"timeout": 1800 "timeout": 1800
},
"agent-061-dedupe-lodash-runtime": {
"skills": ["next-browser-initial-load-optimizer"],
"timeout": 1800
} }
} }
import { expect, test } from 'vitest'
import { transcriptPath } from '@vercel/agent-eval/eval'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
test('consolidates the duplicate lodash runtime', () => {
const rootPackage = JSON.parse(
readFileSync(join(process.cwd(), 'package.json'), 'utf8')
)
const legacyPackage = JSON.parse(
readFileSync(
join(process.cwd(), 'packages/legacy-widget/package.json'),
'utf8'
)
)
expect(rootPackage.dependencies?.lodash).toBeTruthy()
expect(legacyPackage.dependencies?.lodash).toBeTruthy()
expect(legacyPackage.dependencies?.lodash).not.toBe('4.17.20')
const lockPath = join(process.cwd(), 'package-lock.json')
expect(existsSync(lockPath)).toBe(true)
const lock = JSON.parse(readFileSync(lockPath, 'utf8'))
const versions = new Set<string>()
for (const [path, entry] of Object.entries(lock.packages ?? {}) as Array<
[string, { version?: string }]
>) {
if (/(?:^|\/)node_modules\/lodash$/.test(path) && entry.version) {
versions.add(entry.version)
}
}
expect(versions.size).toBe(1)
})
test('preserves both lodash-backed client behaviors', () => {
const page = readFileSync(join(process.cwd(), 'app/page.tsx'), 'utf8')
const legacyWidget = readFileSync(
join(process.cwd(), 'packages/legacy-widget/index.js'),
'utf8'
)
expect(page).toMatch(/from\s*['"]lodash['"]|require\(['"]lodash['"]\)/)
expect(page).toMatch(/legacyLabel\s*\(/)
expect(legacyWidget).toMatch(/require\(['"]lodash['"]\)/)
expect(legacyWidget).toMatch(/toUpper\s*\(/)
})
test('preserves the two transformed status labels', () => {
const page = readFileSync(join(process.cwd(), 'app/page.tsx'), 'utf8')
const legacyWidget = readFileSync(
join(process.cwd(), 'packages/legacy-widget/index.js'),
'utf8'
)
expect(page).toContain('Deployment Status')
expect(page).toContain('Current status:')
expect(page).toContain('ready for review')
expect(page).toMatch(/startCase\s*\(/)
expect(page).toContain('Legacy status:')
expect(page).toContain('legacy panel')
expect(page).toMatch(/legacyLabel\s*\(/)
expect(legacyWidget).toMatch(/toUpper\s*\(/)
expect(legacyWidget).toMatch(/trim\s*\(/)
})
test('uses analyzer evidence and verifies the deduplication', () => {
const transcript = readFileSync(transcriptPath(), 'utf8')
const analyzerRuns = transcript.match(/experimental-analyze/g) ?? []
expect(transcript.trim()).not.toBe('')
expect(analyzerRuns.length).toBeGreaterThanOrEqual(2)
expect(transcript).toMatch(/(?:query|initial[_ -]?load|scope)/i)
expect(transcript).toMatch(/lodash/i)
expect(transcript).toMatch(/(?:4\.17\.20|4\.17\.21)/)
expect(transcript).toMatch(/(?:package-lock|lockfile|dependency)/i)
expect(transcript).toMatch(/(?:package|source|importer)/i)
expect(transcript).toMatch(
/(?:next\s+build|npm\s+run\s+build|pnpm\s+(?:run\s+)?build)/i
)
})
The `/` route in this Next.js app has become unnecessarily large in the browser. Optimize its browser bundle without changing either deployment status label or how those labels are produced.
Both the current status and the status from the local legacy widget must keep their existing text transformations.
Use the tools and documentation available in the project, verify the optimization, and leave the app in a production-buildable state with an accurate lockfile.
import type { ReactNode } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
'use client'
import { startCase } from 'lodash'
import { legacyLabel } from 'legacy-widget'
export default function Page() {
return (
<main>
<h1>Deployment Status</h1>
<p>Current status: {startCase('ready for review')}</p>
<p>Legacy status: {legacyLabel('legacy panel')}</p>
</main>
)
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {}
export default nextConfig
{
"private": true,
"type": "module",
"scripts": {
"build": "next build",
"dev": "next dev",
"start": "next start"
},
"dependencies": {
"legacy-widget": "file:packages/legacy-widget",
"lodash": "4.17.21",
"next": "^16",
"react": "19.1.0",
"react-dom": "19.1.0"
},
"devDependencies": {
"@types/lodash": "^4.17.20",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"typescript": "^5",
"vitest": "^3.1.3"
}
}
const { toUpper, trim } = require('lodash')
exports.legacyLabel = function legacyLabel(value) {
return toUpper(trim(value))
}
{
"name": "legacy-widget",
"version": "1.0.0",
"main": "index.js",
"types": "index.d.ts",
"dependencies": {
"lodash": "4.17.20"
}
}
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx",
".next/dev/types/**/*.ts"
],
"exclude": ["node_modules", "EVAL.ts"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment