feat(bgm): resolve relative part assets against source dir
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
*
|
||||
* See docs/bgm-format.md for the format's concrete behavior.
|
||||
*/
|
||||
import * as path from 'node:path';
|
||||
import picomatch from 'picomatch';
|
||||
import { collectVirtualFiles } from './markdown.js';
|
||||
import { parseDefText, readDefFiles } from './parse.js';
|
||||
@@ -218,7 +219,13 @@ function asPackage(def: ParsedDef, source: string): PackageDef {
|
||||
|
||||
function asPart(obj: Record<string, unknown>, source: string): Part {
|
||||
try {
|
||||
return validatePart(obj) as unknown as Part;
|
||||
const part = validatePart(obj) as unknown as Part;
|
||||
// Resolve relative asset paths against the directory of the source file
|
||||
// (path-style name relative to the games root, e.g. `harbor/parts/`).
|
||||
// Real files may carry a leading slash from an empty root; strip it.
|
||||
const dir = path.posix.dirname(source).replace(/^\/+/, '');
|
||||
part.baseUrl = dir ? `${dir}/` : '';
|
||||
return part;
|
||||
} catch (err) {
|
||||
throw wrapZod(err, source);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user