Skip to content

Commit be95279

Browse files
committed
revert(create): drop .git support from findWorkspaceRoot
Per PR review: extending `findWorkspaceRoot` to recognize `.git` as a project boundary is out of scope for this PR. Restore it to the original monorepo-marker-only behavior (`pnpm-workspace.yaml`, `workspaces` in `package.json`, `lerna.json`). `getConfiguredDefaultTemplate` still walks up via `findWorkspaceRoot` so monorepo layouts continue to pick up the root `vite.config.ts` from any subdirectory. Standalone git repos (no monorepo marker) now only see a config that sits at the cwd. Update `org-resolve.spec.ts` to exercise the walk-up via `pnpm-workspace.yaml` instead of `.git`, and remove the nested-`.git`- subproject test since there's nothing for that case to assert against anymore.
1 parent 740f662 commit be95279

2 files changed

Lines changed: 10 additions & 36 deletions

File tree

packages/cli/src/create/__tests__/org-resolve.spec.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('getConfiguredDefaultTemplate', () => {
1717
fs.rmSync(repoRoot, { recursive: true, force: true });
1818
});
1919

20-
function writeRepoConfig(defaultTemplate: string): void {
21-
fs.mkdirSync(path.join(repoRoot, '.git'), { recursive: true });
20+
function writeMonorepoConfig(defaultTemplate: string): void {
21+
fs.writeFileSync(path.join(repoRoot, 'pnpm-workspace.yaml'), "packages:\n - 'apps/*'\n");
2222
// Plain object export instead of `defineConfig` — the test only
2323
// needs the shape to be readable, and dropping the `vite-plus`
2424
// import avoids noisy module-not-found warnings from vite's loader.
@@ -29,13 +29,13 @@ describe('getConfiguredDefaultTemplate', () => {
2929
fs.writeFileSync(path.join(repoRoot, 'package.json'), '{"name":"fixture"}');
3030
}
3131

32-
it('reads the defaultTemplate from the repo root when invoked at the root', async () => {
33-
writeRepoConfig('@your-org');
32+
it('reads the defaultTemplate from the workspace root when invoked at the root', async () => {
33+
writeMonorepoConfig('@your-org');
3434
expect(await getConfiguredDefaultTemplate(repoRoot)).toBe('@your-org');
3535
});
3636

37-
it('walks up from a subdirectory to find the repo root config', async () => {
38-
writeRepoConfig('@your-org');
37+
it('walks up from a workspace subdirectory to find the root config', async () => {
38+
writeMonorepoConfig('@your-org');
3939
const deep = path.join(repoRoot, 'apps', 'web', 'src');
4040
fs.mkdirSync(deep, { recursive: true });
4141
expect(await getConfiguredDefaultTemplate(deep)).toBe('@your-org');
@@ -48,25 +48,9 @@ describe('getConfiguredDefaultTemplate', () => {
4848
});
4949

5050
it('returns undefined when vite.config has no create.defaultTemplate', async () => {
51-
fs.mkdirSync(path.join(repoRoot, '.git'), { recursive: true });
51+
fs.writeFileSync(path.join(repoRoot, 'pnpm-workspace.yaml'), "packages:\n - 'apps/*'\n");
5252
fs.writeFileSync(path.join(repoRoot, 'vite.config.ts'), 'export default {};\n');
5353
fs.writeFileSync(path.join(repoRoot, 'package.json'), '{"name":"fixture"}');
5454
expect(await getConfiguredDefaultTemplate(repoRoot)).toBeUndefined();
5555
});
56-
57-
it('prefers the monorepo root over a nested `.git` subproject', async () => {
58-
// Monorepo root carries the vite config + workspace marker…
59-
fs.writeFileSync(path.join(repoRoot, 'pnpm-workspace.yaml'), "packages:\n - 'apps/*'\n");
60-
fs.writeFileSync(
61-
path.join(repoRoot, 'vite.config.ts'),
62-
"export default { create: { defaultTemplate: '@your-org' } };\n",
63-
);
64-
fs.writeFileSync(path.join(repoRoot, 'package.json'), '{"name":"monorepo"}');
65-
// …but a nested package has its own `.git` (e.g. submodule). The
66-
// nested `.git` must NOT shadow the monorepo marker above it.
67-
const nested = path.join(repoRoot, 'apps', 'web');
68-
fs.mkdirSync(path.join(nested, '.git'), { recursive: true });
69-
fs.writeFileSync(path.join(nested, 'package.json'), '{"name":"web"}');
70-
expect(await getConfiguredDefaultTemplate(nested)).toBe('@your-org');
71-
});
7256
});

packages/cli/src/resolve-vite-config.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,11 @@ export function hasViteConfig(dir: string): boolean {
3939
}
4040

4141
/**
42-
* Find the workspace / repo root by walking up from `startDir`.
43-
*
44-
* Monorepo markers (`pnpm-workspace.yaml`, `workspaces` in `package.json`,
45-
* `lerna.json`) win globally — they always take precedence over any
46-
* `.git` seen along the way, so a subproject with its own `.git` (git
47-
* submodule, nested clone) can't preempt a marker higher up the tree.
48-
* `.git` is only returned when the walk finishes without finding any
49-
* monorepo marker.
42+
* Find the workspace root by walking up from `startDir` looking for
43+
* monorepo indicators (pnpm-workspace.yaml, workspaces in package.json, lerna.json).
5044
*/
5145
export function findWorkspaceRoot(startDir: string): string | undefined {
5246
let dir = path.resolve(startDir);
53-
let gitFallback: string | undefined;
5447
while (true) {
5548
if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) {
5649
return dir;
@@ -69,16 +62,13 @@ export function findWorkspaceRoot(startDir: string): string | undefined {
6962
if (fs.existsSync(path.join(dir, 'lerna.json'))) {
7063
return dir;
7164
}
72-
if (gitFallback === undefined && fs.existsSync(path.join(dir, '.git'))) {
73-
gitFallback = dir;
74-
}
7565
const parent = path.dirname(dir);
7666
if (parent === dir) {
7767
break;
7868
}
7969
dir = parent;
8070
}
81-
return gitFallback;
71+
return undefined;
8272
}
8373

8474
export interface ResolveViteConfigOptions {

0 commit comments

Comments
 (0)