fix(compiler): Reflector generates imports for '..' relative modules.

Fixes #9003
Closes #9004
This commit is contained in:
Chuck Jazdzewski 2016-06-03 12:23:35 -07:00
parent ddd2ac4f55
commit 35ea02fb81
1 changed files with 9 additions and 1 deletions

View File

@ -61,7 +61,8 @@ export class NodeReflectorHost implements StaticReflectorHost, ImportGenerator {
fs.writeFileSync(importedFile, '');
}
const parts = importedFile.replace(EXT, '').split(path.sep).filter(p => !!p);
const importModuleName = importedFile.replace(EXT, '');
const parts = importModuleName.split(path.sep).filter(p => !!p);
for (let index = parts.length - 1; index >= 0; index--) {
let candidate = parts.slice(index, parts.length).join(path.sep);
@ -72,6 +73,13 @@ export class NodeReflectorHost implements StaticReflectorHost, ImportGenerator {
return candidate;
}
}
// Try a relative import
let candidate = path.relative(path.dirname(containingFile), importModuleName);
if (this.resolve(candidate, containingFile) === importedFile) {
return candidate;
}
throw new Error(
`Unable to find any resolvable import for ${importedFile} relative to ${containingFile}`);
}