Skip to content

Commit

Permalink
[cli] Use getNodeBinPaths() in vc dev (#10225)
Browse files Browse the repository at this point in the history
This allows for the "dev command" of a Project to work better in monorepos, where the dev server might live up the node_modules hierarchy within the repo.
  • Loading branch information
TooTallNate committed Jul 19, 2023
1 parent ce4633f commit 7b01a07
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-bobcats-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vercel': patch
---

Use `getNodeBinPaths()` in `vc dev`
8 changes: 5 additions & 3 deletions packages/cli/src/commands/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export default async function dev(

let projectSettings: ProjectSettings | undefined;
let envValues: Record<string, string> = {};
let repoRoot: string | undefined;
if (link.status === 'linked') {
const { project, org, repoRoot } = link;
const { project, org } = link;

// If repo linked, update `cwd` to the repo root
if (repoRoot) {
cwd = repoRoot;
if (link.repoRoot) {
repoRoot = cwd = link.repoRoot;
}

client.config.currentTeam = org.type === 'team' ? org.id : undefined;
Expand All @@ -82,6 +83,7 @@ export default async function dev(
output,
projectSettings,
envValues,
repoRoot,
});

// listen to SIGTERM for graceful shutdown
Expand Down
11 changes: 7 additions & 4 deletions packages/cli/src/util/dev/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
Builder,
cloneEnv,
Env,
getNodeBinPath,
getNodeBinPaths,
StartDevServerResult,
FileFsRef,
PackageJson,
Expand Down Expand Up @@ -124,6 +124,7 @@ function sortBuilders(buildA: Builder, buildB: Builder) {

export default class DevServer {
public cwd: string;
public repoRoot: string;
public output: Output;
public proxy: httpProxy;
public envConfigs: EnvConfigs;
Expand Down Expand Up @@ -169,6 +170,7 @@ export default class DevServer {

constructor(cwd: string, options: DevServerOptions) {
this.cwd = cwd;
this.repoRoot = options.repoRoot ?? cwd;
this.output = options.output;
this.envConfigs = { buildEnv: {}, runEnv: {}, allEnv: {} };
this.envValues = options.envValues || {};
Expand Down Expand Up @@ -1412,7 +1414,7 @@ export default class DevServer {
files,
entrypoint: middleware.entrypoint,
workPath,
repoRootPath: this.cwd,
repoRootPath: this.repoRoot,
config: middleware.config || {},
meta: {
isDev: true,
Expand Down Expand Up @@ -1849,7 +1851,7 @@ export default class DevServer {
entrypoint: match.entrypoint,
workPath,
config: match.config || {},
repoRootPath: this.cwd,
repoRootPath: this.repoRoot,
meta: {
isDev: true,
requestPath,
Expand Down Expand Up @@ -2237,7 +2239,8 @@ export default class DevServer {
);

// add the node_modules/.bin directory to the PATH
const nodeBinPath = await getNodeBinPath({ cwd });
const nodeBinPaths = getNodeBinPaths({ base: this.repoRoot, start: cwd });
const nodeBinPath = nodeBinPaths.join(path.delimiter);
env.PATH = `${nodeBinPath}${path.delimiter}${env.PATH}`;

// This is necesary so that the dev command in the Project
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/util/dev/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface DevServerOptions {
output: Output;
projectSettings?: ProjectSettings;
envValues?: Record<string, string>;
repoRoot?: string;
}

export interface EnvConfigs {
Expand Down

0 comments on commit 7b01a07

Please sign in to comment.