vercel-labs/agent-skills / skills/vercel-optimize
vercel-optimize
VerifiedUse for Vercel cost and performance optimization on deployed projects, especially Next.js, SvelteKit, Nuxt, and limited Astro apps. Collect Vercel metrics, usage, project config, and code scan results first; investigate only metric-backed candidates; produce ranked recommendations grounded in verified files and version-aware Vercel/framework docs. Trigger for Vercel bill reduction, slow or expensive routes, caching opportunities, Function Invocations, Build Minutes, Fast Data Transfer, Core Web Vitals, Bot Management, Fluid compute, or cost breakdown requests.
lib/scanners/edge-heavy-import.mjs
View on GitHub// Flag node-only / heavy imports in edge-runtime files (either a
// middleware basename or an `export const runtime = 'edge'`). These
// either fail at deploy (node: builtins, native bindings) or inflate
// cold-start latency. Line-anchored matches + type-only-import skip
// keep FP low.
const EDGE_RUNTIME_RE = /export\s+const\s+runtime\s*=\s*['"]edge['"]/;
const IMPORT_RE = /^\s*import\s+(?:type\s+)?(?:[^'"]*\s+from\s+)?['"]([^'"]+)['"]/gm;
const DYNAMIC_IMPORT_RE = /\bimport\(\s*['"]([^'"]+)['"]\s*\)/g;
const REQUIRE_RE = /\brequire\(\s*['"]([^'"]+)['"]\s*\)/g;
const TYPE_IMPORT_RE = /^\s*import\s+type\s+/;
const HEAVY_PATTERNS = [
/^node:/,
/^sharp$/,
/^@aws-sdk\//,
/^@prisma\/client$/,
/^prisma$/,
/^pg$/,
/^mysql2(?:\/|$)/,
/^puppeteer(?:-core)?(?:\/|$)/,
/^playwright(?:-core)?(?:\/|$)/,
/^bcrypt$/,
/^jsonwebtoken$/,
/^canvas$/,
/^@google-cloud\//,
];
export const metadata = {
id: 'edge-heavy-import',
title: 'Heavy / node-only import inside edge-runtime file',
severity: 'high',
billingDimension: 'function-duration',
trafficIndependent: true,
description:
'Edge runtime is a constrained sandbox with no node: builtins and a much smaller cold-start budget than Node functions. Heavy SDKs (sharp, @aws-sdk/*, @prisma/client, pg, puppeteer) either fail at deploy or inflate cold-start latency. Move the import to a Node runtime function, or replace with an edge-compatible alternative (e.g., neon-driver instead of pg).',
fix:
'Either (a) drop the `export const runtime = \'edge\'` so the route runs on Node (default in 2026), or (b) replace the heavy import with an edge-compatible alternative. For DB: use @neondatabase/serverless or @planetscale/database instead of pg/mysql2. For image: do the work in a Node route handler. For auth signing: use jose (Web Crypto) instead of jsonwebtoken.',
citations: [
'https://vercel.com/docs/functions/runtimes/edge-runtime',
'https://vercel.com/docs/fluid-compute',
],
excludeGlobs: ['node_modules/**', '.next/**', 'dist/**', '__tests__/**', '**/*.test.*', '**/*.spec.*'],
includeGlobs: ['**/*.{ts,tsx,js,mjs}'],
};
export function scan({ files }) {
const out = [];
for (const { path, content } of files) {
if (!isEdgeRuntimeFile(path, content)) continue;
const lines = content.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
// Type-only imports are erased at compile, never reach runtime.
if (TYPE_IMPORT_RE.test(line)) continue;
const specifiers = extractSpecifiers(line);
for (const spec of specifiers) {
const match = HEAVY_PATTERNS.find((re) => re.test(spec));
if (!match) continue;
out.push({
pattern: metadata.id,
file: path,
line: i + 1,
evidence: `import "${spec}" in edge-runtime file`,
edgeReason: isMiddleware(path) ? 'middleware (always edge)' : 'export const runtime = "edge"',
importedModule: spec,
trafficIndependent: metadata.trafficIndependent,
});
}
}
}
return out;
}
function isEdgeRuntimeFile(path, content) {
return isMiddleware(path) || EDGE_RUNTIME_RE.test(content);
}
function isMiddleware(path) {
return /(?:^|\/)middleware\.(ts|tsx|js|mjs)$/.test(path);
}
function extractSpecifiers(line) {
const out = new Set();
// IMPORT_RE has `gm` flag — reset lastIndex per call.
IMPORT_RE.lastIndex = 0;
let m;
while ((m = IMPORT_RE.exec(line)) !== null) out.add(m[1]);
DYNAMIC_IMPORT_RE.lastIndex = 0;
while ((m = DYNAMIC_IMPORT_RE.exec(line)) !== null) out.add(m[1]);
REQUIRE_RE.lastIndex = 0;
while ((m = REQUIRE_RE.exec(line)) !== null) out.add(m[1]);
return [...out];
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |