@meistrari/tela-build 1.30.4 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'pathe'
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { resolveRepositoryRoot } from '../index'
|
|
7
|
+
|
|
8
|
+
const tempDirs: string[] = []
|
|
9
|
+
|
|
10
|
+
function makeTempRoot() {
|
|
11
|
+
const dir = mkdtempSync(join(tmpdir(), 'resolve-repository-root-'))
|
|
12
|
+
tempDirs.push(dir)
|
|
13
|
+
|
|
14
|
+
return dir
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
for (const dir of tempDirs.splice(0)) {
|
|
19
|
+
rmSync(dir, { recursive: true, force: true })
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('resolveRepositoryRoot', () => {
|
|
24
|
+
it('prefers Nuxt workspaceDir for monorepos running without .git in Docker', () => {
|
|
25
|
+
const workspaceRoot = makeTempRoot()
|
|
26
|
+
const appDir = join(workspaceRoot, 'apps/web')
|
|
27
|
+
|
|
28
|
+
mkdirSync(appDir, { recursive: true })
|
|
29
|
+
|
|
30
|
+
expect(resolveRepositoryRoot(appDir, workspaceRoot)).toBe(workspaceRoot)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('detects workspace roots from .git markers', () => {
|
|
34
|
+
const workspaceRoot = makeTempRoot()
|
|
35
|
+
const appDir = join(workspaceRoot, 'apps/web')
|
|
36
|
+
|
|
37
|
+
mkdirSync(appDir, { recursive: true })
|
|
38
|
+
writeFileSync(join(workspaceRoot, '.git'), 'gitdir: ../.git/worktrees/test\n')
|
|
39
|
+
|
|
40
|
+
expect(resolveRepositoryRoot(appDir)).toBe(workspaceRoot)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('detects workspace roots from pnpm-workspace.yaml', () => {
|
|
44
|
+
const workspaceRoot = makeTempRoot()
|
|
45
|
+
const appDir = join(workspaceRoot, 'apps/web')
|
|
46
|
+
|
|
47
|
+
mkdirSync(appDir, { recursive: true })
|
|
48
|
+
writeFileSync(join(workspaceRoot, 'pnpm-workspace.yaml'), 'packages:\n - apps/*\n')
|
|
49
|
+
|
|
50
|
+
expect(resolveRepositoryRoot(appDir)).toBe(workspaceRoot)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('detects workspace roots from package.json workspaces when workspaceDir is unavailable', () => {
|
|
54
|
+
const workspaceRoot = makeTempRoot()
|
|
55
|
+
const appDir = join(workspaceRoot, 'apps/web')
|
|
56
|
+
|
|
57
|
+
mkdirSync(appDir, { recursive: true })
|
|
58
|
+
writeFileSync(join(workspaceRoot, 'package.json'), JSON.stringify({
|
|
59
|
+
private: true,
|
|
60
|
+
workspaces: ['apps/*', 'packages/*'],
|
|
61
|
+
}))
|
|
62
|
+
|
|
63
|
+
expect(resolveRepositoryRoot(appDir)).toBe(workspaceRoot)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('falls back to the app root when no repository markers exist', () => {
|
|
67
|
+
const appDir = makeTempRoot()
|
|
68
|
+
|
|
69
|
+
expect(resolveRepositoryRoot(appDir)).toBe(appDir)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -72,7 +72,7 @@ export default defineNuxtModule<TelaBuildDocsOptions>({
|
|
|
72
72
|
// Run in background without blocking
|
|
73
73
|
setImmediate(async () => {
|
|
74
74
|
try {
|
|
75
|
-
const repositoryRoot = resolveRepositoryRoot(nuxt.options.rootDir)
|
|
75
|
+
const repositoryRoot = resolveRepositoryRoot(nuxt.options.rootDir, nuxt.options.workspaceDir)
|
|
76
76
|
try {
|
|
77
77
|
if (!options.outDir) {
|
|
78
78
|
ensureClaudeSymlink(repositoryRoot, logger, colors)
|
|
@@ -175,11 +175,15 @@ function resolveOutputDirectories(repositoryRoot: string, outDir?: string): stri
|
|
|
175
175
|
return [resolve(repositoryRoot, '.agents/skills')]
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
function resolveRepositoryRoot(startDir: string): string {
|
|
178
|
+
export function resolveRepositoryRoot(startDir: string, workspaceDir?: string): string {
|
|
179
|
+
if (workspaceDir && existsSync(resolve(workspaceDir))) {
|
|
180
|
+
return resolve(workspaceDir)
|
|
181
|
+
}
|
|
182
|
+
|
|
179
183
|
let currentDir = resolve(startDir)
|
|
180
184
|
|
|
181
185
|
while (true) {
|
|
182
|
-
if (
|
|
186
|
+
if (isRepositoryRoot(currentDir)) {
|
|
183
187
|
return currentDir
|
|
184
188
|
}
|
|
185
189
|
|
|
@@ -192,6 +196,25 @@ function resolveRepositoryRoot(startDir: string): string {
|
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
|
|
199
|
+
function isRepositoryRoot(directory: string): boolean {
|
|
200
|
+
if (existsSync(resolve(directory, '.git')) || existsSync(resolve(directory, 'pnpm-workspace.yaml'))) {
|
|
201
|
+
return true
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const packageJsonPath = resolve(directory, 'package.json')
|
|
205
|
+
if (!existsSync(packageJsonPath)) {
|
|
206
|
+
return false
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as { workspaces?: unknown }
|
|
211
|
+
return packageJson.workspaces !== undefined
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return false
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
195
218
|
function ensurePathsIgnored(repositoryRoot: string, targets: IgnoreTarget[]): void {
|
|
196
219
|
const gitignorePath = resolve(repositoryRoot, '.gitignore')
|
|
197
220
|
const existingLines = existsSync(gitignorePath)
|