Review of the gate found the reason-comment span too narrow: a comment on the
line above `catch`, or trailing the closing brace, was rejected, so the natural
place to explain a clause did not count. The span now starts at the preceding
token and ends with the line closing the clause.
A binding pattern that names nothing (`catch ({})`, `catch ([])`,
`catch ({ _ })`) counted as naming the error. The gate now requires one bound
name other than `_`.
`--record REF` writes the inventory for a merged tree and refuses any clause the
named revision does not already carry, so no command allows a clause this branch
introduced; a merge that lands recorded clauses is the only case that adds
entries. The no-op body boundary (`catch { "use strict" }`) and the tolerance
for a file the parser cannot read past are stated in the module docblock and
pinned by specification rows.
66 lines
2.4 KiB
TypeScript
66 lines
2.4 KiB
TypeScript
/** Temporary-repository fixture shared by recorded-inventory gate specs. */
|
|
|
|
import { execFileSync } from 'node:child_process'
|
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { dirname, join } from 'node:path'
|
|
|
|
/** Repository roots created by {@link createInventoryRepo}, removed by {@link removeInventoryRepos}. */
|
|
const roots: string[] = []
|
|
|
|
/**
|
|
* Write one fixture file, creating its parent directories.
|
|
* @param root - fixture repository root.
|
|
* @param file - repository-relative path.
|
|
* @param contents - file text.
|
|
*/
|
|
export function writeFixture(root: string, file: string, contents: string): void {
|
|
const path = join(root, file)
|
|
mkdirSync(dirname(path), { recursive: true })
|
|
writeFileSync(path, contents)
|
|
}
|
|
|
|
/**
|
|
* Run one Git command in a fixture repository.
|
|
* @param root - fixture repository root.
|
|
* @param args - Git arguments.
|
|
*/
|
|
export function gitFixture(root: string, ...args: string[]): void {
|
|
execFileSync('git', args, { cwd: root, stdio: 'pipe' })
|
|
}
|
|
|
|
/**
|
|
* Commit every change in a fixture repository.
|
|
* @param root - fixture repository root.
|
|
* @param message - commit message.
|
|
*/
|
|
export function commitFixture(root: string, message: string): void {
|
|
gitFixture(root, 'commit', '--quiet', '--message', message)
|
|
}
|
|
|
|
/**
|
|
* Create a temporary repository with one seed source file per scanned area and an empty inventory.
|
|
* @param baselinePath - repository-relative inventory path the gate reads.
|
|
* @param seed - contents of each area's seed source file.
|
|
* @returns the repository root, tracked for {@link removeInventoryRepos}.
|
|
*/
|
|
export function createInventoryRepo(baselinePath: string, seed: string): string {
|
|
const root = mkdtempSync(join(tmpdir(), 'dsh-inventory-'))
|
|
roots.push(root)
|
|
gitFixture(root, 'init', '--quiet')
|
|
// A runner without a global Git identity must still be able to commit this fixture.
|
|
gitFixture(root, 'config', 'user.email', '[email protected]')
|
|
gitFixture(root, 'config', 'user.name', 'Fixture')
|
|
for (const area of ['packages', 'apps', 'scripts', 'website']) {
|
|
writeFixture(root, `${area}/seed.ts`, seed)
|
|
}
|
|
writeFixture(root, baselinePath, '{}\n')
|
|
gitFixture(root, 'add', '.')
|
|
return root
|
|
}
|
|
|
|
/** Remove every repository created by {@link createInventoryRepo}. */
|
|
export function removeInventoryRepos(): void {
|
|
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
|
|
}
|