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.
This commit is contained in:
Ben Newman
2016-02-29 15:18:10 -05:00
parent 99cb96fcf7
commit 9ff3cdc7eb

View File

@@ -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);