From 9ff3cdc7eb198410f23ea7e8836eb2787ce5f730 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 29 Feb 2016 15:18:10 -0500 Subject: [PATCH] Ensure every file the ImportScanner scans has a valid sourcePath. Packages published before the modules package existed may acquire a dependency on the modules package upon upgrading to Meteor 1.3, because they depended on the ecmascript package, which now implies the modules package. If the previously published isopacket does not provide a sourcePath or path property, then we should use the servePath property instead. With that fix in place, I am now strictly enforcing that all files scanned by the ImportScanner actually exist on disk. Should fix #5871. --- tools/isobuild/import-scanner.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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);