Skip to content

Commit e55b0d6

Browse files
Refactor install and build commands in Vercel configuration and enhance package installation logic
- Updated the installCommand and buildCommand in vercel.json to check for the existence of specific files before executing commands, improving robustness. - Added a function to wipe cached node_modules in install-app-with-packages.mjs to ensure clean installations. - Enhanced the installSourceOnlyPackage function to handle package installations more effectively, addressing issues with npm and pnpm flags. This improves the deployment process and ensures compatibility across different environments.
1 parent ec7f6a0 commit e55b0d6

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

apps/docs/vercel.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
"destination": "/api/$1"
7373
}
7474
],
75-
"installCommand": "node lib/scripts/vercel-install.mjs || node apps/docs/lib/scripts/vercel-install.mjs",
76-
"buildCommand": "pnpm build || pnpm --dir apps/docs build",
75+
"installCommand": "if [ -f lib/scripts/vercel-install.mjs ]; then node lib/scripts/vercel-install.mjs; else node apps/docs/lib/scripts/vercel-install.mjs; fi",
76+
"buildCommand": "if [ -f apps/docs/package.json ]; then pnpm --dir apps/docs build; else pnpm build; fi",
7777
"devCommand": "next dev",
7878
"framework": "nextjs",
7979
"outputDirectory": ".next",

tooling/scripts/install-app-with-packages.mjs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
* Website also links apps/website/node_modules/next to the upload root:
1919
* @vercel/next resolves next/package.json from cwd, not the app directory.
2020
* Source-only packages (@lomi./ui) still get their own install: Next compiles
21-
* those package sources and cannot see the app node_modules tree. @lomi./pay
22-
* installs with --omit=dev --omit=peer so it does not pull a second Next.
21+
* those package sources and cannot see the app node_modules tree. Docs keeps
22+
* pnpm for that install (npm 10 `--omit=peer` crashes with edgesOut on Node
23+
* 22, and a restored `.pnpm` tree from cache makes it worse). Website/admin
24+
* npm deploys still use `npm install --omit=dev --omit=peer`. @lomi./pay
25+
* installs with the same omit flags so it does not pull a second Next.
2326
*
2427
* Usage: node tooling/scripts/install-app-with-packages.mjs <app-dir>
2528
* e.g. node tooling/scripts/install-app-with-packages.mjs apps/docs
@@ -167,6 +170,14 @@ function excludeAdminGrowthAgentFromTsc(appDir) {
167170
);
168171
}
169172

173+
function wipeCachedNodeModules(dir) {
174+
if (!process.env.VERCEL && !process.env.CI) return;
175+
const nm = path.join(dir, "node_modules");
176+
if (!existsSync(nm)) return;
177+
rmSync(nm, { recursive: true, force: true });
178+
console.log(`==> removed cached ${path.relative(ROOT, nm)}`);
179+
}
180+
170181
function installDeps(appRel, dir, { frozen }) {
171182
if (useNpm(appRel)) {
172183
run("npm", ["install", "--ignore-scripts", "--include=dev"], dir);
@@ -175,6 +186,27 @@ function installDeps(appRel, dir, { frozen }) {
175186
const args = ["install", "--ignore-workspace"];
176187
if (frozen && existsSync(path.join(dir, "pnpm-lock.yaml"))) {
177188
args.push("--frozen-lockfile");
189+
} else if (!existsSync(path.join(dir, "pnpm-lock.yaml"))) {
190+
args.push("--no-frozen-lockfile");
191+
}
192+
run("pnpm", args, dir);
193+
}
194+
195+
function installSourceOnlyPackage(appRel, dir) {
196+
wipeCachedNodeModules(dir);
197+
if (useNpm(appRel)) {
198+
run("npm", ["install", "--ignore-scripts", "--omit=dev", "--omit=peer"], dir);
199+
return;
200+
}
201+
const args = [
202+
"install",
203+
"--ignore-workspace",
204+
"--ignore-scripts",
205+
"--prod",
206+
"--config.auto-install-peers=false",
207+
];
208+
if (!existsSync(path.join(dir, "pnpm-lock.yaml"))) {
209+
args.push("--no-frozen-lockfile");
178210
}
179211
run("pnpm", args, dir);
180212
}
@@ -248,15 +280,11 @@ function installFileApp(appRel, pkg, { frozen }) {
248280
if (packageJson.scripts?.build) {
249281
installDeps(appRel, dir, { frozen: false });
250282
runBuildScript(appRel, dir);
251-
} else if (rel === "packages/pay") {
252-
// pay ships TypeScript. A full install pulls a second Next from
253-
// peerDependencies and breaks checkout typecheck on NextRequest.
254-
run("npm", ["install", "--ignore-scripts", "--omit=dev", "--omit=peer"], dir);
255283
} else {
256284
// Source-only packages such as @lomi./ui still need runtime deps
257-
// (clsx, radix). Omit dev and peers so React 18 types do not leak
258-
// into the Next 19 typecheck of packages/pay.
259-
run("npm", ["install", "--ignore-scripts", "--omit=dev", "--omit=peer"], dir);
285+
// (clsx, radix). Omit dev and peers so React 18 types / a second
286+
// Next (pay) do not leak into the consuming app.
287+
installSourceOnlyPackage(appRel, dir);
260288
}
261289
hoistNodeModules(dir);
262290
}

0 commit comments

Comments
 (0)