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:
@@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url';
|
||||
import { loadDefs, collectPackages } from './collect.js';
|
||||
|
||||
const fixtureRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '__fixtures__', 'harbor');
|
||||
const multiRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '__fixtures__', 'vite-build', 'games');
|
||||
|
||||
describe('collectPackages', () => {
|
||||
it('collects the harbor package from markdown code blocks', () => {
|
||||
@@ -60,6 +61,23 @@ describe('collectPackages', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('scopes include patterns to the package declaration directory', () => {
|
||||
// Two packages share a games root. Each uses the default `./**/*.yaml`
|
||||
// include, which must resolve relative to its own folder so neither
|
||||
// absorbs the other's defs (both define a `game#main` setup).
|
||||
const defMap = loadDefs('', multiRoot);
|
||||
const packages = collectPackages(defMap, multiRoot);
|
||||
|
||||
expect(packages).toHaveLength(2);
|
||||
const azul = packages.find((p) => p.meta.id === 'azul')!;
|
||||
const harbor = packages.find((p) => p.meta.id === 'harbor')!;
|
||||
|
||||
expect([...azul.parts.keys()]).toEqual(['tile#blue']);
|
||||
expect([...azul.setups.keys()]).toEqual(['game#main']);
|
||||
expect([...harbor.parts.keys()]).toEqual(['token#wood']);
|
||||
expect([...harbor.setups.keys()]).toEqual(['game#main']);
|
||||
});
|
||||
|
||||
it('throws on a duplicate type#id', () => {
|
||||
const defMap = loadDefs('', fixtureRoot);
|
||||
// Inject a duplicate part into the map under a new file name.
|
||||
|
||||
Reference in New Issue
Block a user