angular-librarian
angular-librarian copied to clipboard
Fix @angular/compiler version
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) {
// ...
}
Because in these cases majorCompilerVersion 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 angular-librarian to git+https://github.com/gonzofish/angular-librarian.git in my package.json and doing ngl up.
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 build.js was not getting the right majorCompilerVersion (5 in my case), and then, I check that you run the command npm list --depth=0 '@angular/compiler' to get the angular compiler version, this command in my case returned a line like this: @angular/compiler@^5.0.0 when the expected line is something like this: @angular/[email protected]. For that reason, when you do:
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: NaN
So, that's why the build.js script was trying to execute:
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