fix(bgm): resolve include patterns relative to package dir
The default include matched every yaml across the games root, so a package could absorb a sibling game's defs (e.g. two game#main setups). Resolve patterns against the package declaration's directory instead; a leading slash marks a pattern as root-relative.
This commit is contained in:
@@ -101,7 +101,8 @@ export function collectPackages(defMap: DefMap, rootDir: string): Package[] {
|
||||
const role = def.value['role'] as Role;
|
||||
if (role === 'package') {
|
||||
const pkg = asPackage(def, file);
|
||||
accs.push(new PackageAcc(pkg, defMap, rootDir));
|
||||
const baseDir = path.posix.dirname(file).replace(/^\/+/, '');
|
||||
accs.push(new PackageAcc(pkg, defMap, rootDir, baseDir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,6 +126,8 @@ class PackageAcc {
|
||||
readonly pkg: PackageDef,
|
||||
private readonly defs: DefMap,
|
||||
private readonly rootDir: string,
|
||||
/** Path-style directory of the package declaration, e.g. `carcassonne`. */
|
||||
private readonly baseDir: string,
|
||||
) {}
|
||||
|
||||
collect() {
|
||||
@@ -152,10 +155,17 @@ class PackageAcc {
|
||||
private expandIncludes(patterns: string[]): string[] {
|
||||
// Match include patterns against the parsed definitions' names, which
|
||||
// cover both real files and markdown code blocks. Patterns are relative
|
||||
// to the games root (e.g. `./**/*.yaml`).
|
||||
// to the package declaration's own directory (e.g. `./**/*.yaml` means
|
||||
// this package's folder and below), so a package never absorbs defs from
|
||||
// a sibling game. A leading `/` marks a pattern as root-relative.
|
||||
// Def names carry a leading `/` (from the empty games root), so resolved
|
||||
// patterns are prefixed to match.
|
||||
const names = new Set<string>();
|
||||
for (const pattern of patterns) {
|
||||
const matcher = picomatch(pattern, { dot: true });
|
||||
const resolved = pattern.startsWith('/')
|
||||
? pattern
|
||||
: `/${path.posix.join(this.baseDir, pattern)}`;
|
||||
const matcher = picomatch(resolved, { dot: true });
|
||||
for (const name of this.defs.defs.keys()) {
|
||||
if (matcher(name)) names.add(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user