fix(build): contain clean targets within repository

This commit is contained in:
Tianyi Cui
2026-07-26 02:51:58 +08:00
parent 3ccdf4ac46
commit 6dd1ce1c9b
5 changed files with 45 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
@@ -59,4 +59,21 @@ describe('RepositoryCleaner', () => {
await expect(new RepositoryCleaner(root).clean()).rejects.toThrow('packages/removed/ghost/notes.txt')
expect(existsSync(join(root, 'products/shell/lib'))).toBe(true)
})
it('refuses project outputs reached through a symlink outside the repository', async () => {
const root = fixture()
const externalProject = fixture()
write(join(root, 'tsconfig.json'), JSON.stringify({ files: [], references: [{ path: './linked' }] }))
write(join(externalProject, 'tsconfig.json'), JSON.stringify({
compilerOptions: { composite: true, outDir: 'lib/types' },
include: ['src'],
}))
write(join(externalProject, 'src/index.ts'), 'export {}\n')
write(join(externalProject, 'lib/types/index.js'))
symlinkSync(externalProject, join(root, 'linked'), process.platform === 'win32' ? 'junction' : 'dir')
await expect(new RepositoryCleaner(root).clean()).rejects.toThrow('outside repository')
expect(existsSync(join(externalProject, 'lib/types/index.js'))).toBe(true)
})
})