diff --git a/tools/isobuild/import-scanner.js b/tools/isobuild/import-scanner.js index 8eb0eefb10..59656195f0 100644 --- a/tools/isobuild/import-scanner.js +++ b/tools/isobuild/import-scanner.js @@ -98,7 +98,7 @@ export default class ImportScanner { addInputFiles(files) { files.forEach(file => { - const absPath = pathJoin(this.sourceRoot, file.sourcePath); + const absPath = this._ensureSourcePath(file); const dotExt = "." + file.type; const dataString = file.data.toString("utf8"); @@ -188,6 +188,29 @@ export default class ImportScanner { }); } + _ensureSourcePath(file) { + let sourcePath = + file.sourcePath || + file.path || + file.servePath; + + if (sourcePath.startsWith("/")) { + sourcePath = pathRelative(this.sourceRoot, sourcePath); + if (sourcePath.startsWith("..")) { + throw new Error("sourcePath outside sourceRoot: " + sourcePath); + } + } + + const info = this._joinAndStat(this.sourceRoot, sourcePath); + if (! info || ! info.stat.isFile()) { + throw new Error("sourcePath not a file: " + sourcePath); + } + + file.sourcePath = sourcePath; + + return info.path; + } + _findImportedModuleIdentifiers(file) { if (IMPORT_SCANNER_CACHE.has(file.hash)) { return IMPORT_SCANNER_CACHE.get(file.hash);