mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-08 21:07:46 +00:00
The `getNodeBinPath()` function is problematic because it assumes that commands are installed in the `node_modules` directory alongside the detected lockfile. This works fine the majority of the time, but ends up not being the case when using a monorepo that uses a package manager in "linked" mode (i.e. pnpm by default). Consider the following: ``` . ├── pnpm-lock.yaml ├── node_modules ├── blog │ ├── node_modules │ │ ├── hexo -> .pnpm/hexo@3.9.0/node_modules/hexo ``` In this setup, adding the root-level `node_modules/.bin` would not make the `hexo` command be visible in the `$PATH`. To solve this issue, the new `getNodeBinPaths()` function returns an array of all directories up to the specified `root`, which can then be placed into the `$PATH`. It's also more efficient (synchronous) since it does not need to scan for a lockfile anymore (the `root` needs to be specified explicitly). The new function is being used in `@vercel/next` and `@vercel/static-build`. The `traverseUpDirectories()` function from CLI was moved to `build-utils` to implement this function. Consequently, that makes the implementations of `walkParentDirs()` and `walkParentDirsMulti()` simpler, since it's using this generator now.
18 lines
548 B
TypeScript
Vendored
18 lines
548 B
TypeScript
Vendored
import { join } from 'path';
|
|
import { getNodeBinPaths } from '../src/fs/run-user-scripts';
|
|
|
|
describe('getNodeBinPaths()', () => {
|
|
const cwd = process.cwd();
|
|
|
|
it('should return array of `node_modules/.bin` paths', () => {
|
|
const start = join(cwd, 'foo/bar/baz');
|
|
const paths = getNodeBinPaths({ start, base: cwd });
|
|
expect(paths).toEqual([
|
|
join(cwd, 'foo/bar/baz/node_modules/.bin'),
|
|
join(cwd, 'foo/bar/node_modules/.bin'),
|
|
join(cwd, 'foo/node_modules/.bin'),
|
|
join(cwd, 'node_modules/.bin'),
|
|
]);
|
|
});
|
|
});
|