mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
### Related Issues
Improves how `vc build` handles monorepos. In short, this introduces
monorepo manager detection logic and then some helpful defaults so users
don't have to manually specify a `buildCommand` or `installCommand` when
linking a project within a monorepo.
### 📋 Checklist
<!--
Please keep your PR as a Draft until the checklist is complete
-->
#### Tests
- [ ] The code changed/added as part of this PR has been covered with
tests
- [ ] All tests pass locally with `yarn test-unit`
#### Code Review
- [ ] This PR has a concise title and thorough description useful to a
reviewer
- [ ] Issue from task tracker has a link to this PR
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { promises } from 'fs';
|
|
import path from 'path';
|
|
|
|
import { DetectorFilesystem } from '../../src';
|
|
import { DetectorFilesystemStat } from '../../src/detectors/filesystem';
|
|
|
|
const { stat, readFile, readdir } = promises;
|
|
|
|
export class FixtureFilesystem extends DetectorFilesystem {
|
|
private rootPath: string;
|
|
|
|
constructor(fixturePath: string) {
|
|
super();
|
|
|
|
this.rootPath = fixturePath;
|
|
}
|
|
|
|
async _hasPath(name: string): Promise<boolean> {
|
|
try {
|
|
const filePath = path.join(this.rootPath, name);
|
|
await stat(filePath);
|
|
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
async _readFile(name: string): Promise<Buffer> {
|
|
const filePath = path.join(this.rootPath, name);
|
|
return readFile(filePath);
|
|
}
|
|
async _isFile(name: string): Promise<boolean> {
|
|
const filePath = path.join(this.rootPath, name);
|
|
return (await stat(filePath)).isFile();
|
|
}
|
|
|
|
async _readdir(name: string): Promise<DetectorFilesystemStat[]> {
|
|
const dirPath = path.join(this.rootPath, name);
|
|
const files = await readdir(dirPath, { withFileTypes: true });
|
|
|
|
return files.map(file => ({
|
|
name: file.name,
|
|
type: file.isFile() ? 'file' : 'dir',
|
|
path: path.join(name, file.name),
|
|
}));
|
|
}
|
|
|
|
_chdir(name: string): DetectorFilesystem {
|
|
return new FixtureFilesystem(path.join(this.rootPath, name));
|
|
}
|
|
}
|