Fix @angular/compiler version#98
Conversation
This will fix cases when the command:
npm list --depth=0 '@angular/compiler
returns a line like this `@angular/compiler@^5.0.0`, which will trigger
an error when you do the following comparison:
```
const majorCompilerVersion = +compilerVersion.split('.')[0];
if (majorCompilerVersion >= 5) {
// ...
}
```
`majorCompilerVersion` in these cases will be `NaN`.
|
Thanks for the PR @milmazz! I always appreciate fixes like this. Just for my information, what was happening that made you look into this? |
|
@gonzofish The error I was getting at the beginning was the same as this one, even after pointing So, I started looking at the way the build works and I found this section: if (majorCompilerVersion >= 5) {
const exitCode = ngc(['--project', path.resolve(rootDir, `tsconfig.es${ type }.json`)]);
return evaluateExitCode(exitCode);
} else {
ngc({ project: path.resolve(rootDir, `tsconfig.es${ type }.json`)})
.then((exitCode) =>
evaluateExitCode(exitCode)
)
}Somehow the const lines = ['@angular/compiler@^5.0.0'];
const compilerLine = lines.find((line) => line.indexOf('@angular/compiler@') !== -1);
let version = compilerLine.match(/\bangular\/compiler@[^\s]+\s?/) || [''];
version = version[0].trim().replace('angular/compiler@', ''); // ==> "^5.0.0"
const majorCompilerVersion = +version.split('.')[0]; // ==> Expected: 5, Result: NaNSo, that's why the ngc({ project: path.resolve(rootDir, `tsconfig.es${ type }.json`)})
.then((exitCode) =>
evaluateExitCode(exitCode)
)instead of: const exitCode = ngc(['--project', path.resolve(rootDir, `tsconfig.es${ type }.json`)]);
return evaluateExitCode(exitCode);Hope this help to clarify my scenario. |
|
Great, I'll merge it and it release it tonight |
This will fix cases when the command:
returns a line like this
@angular/compiler@^5.0.0, which will trigger an error when you do the following comparison:Because in these cases
majorCompilerVersionwill beNaN.