Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Fix @angular/compiler version #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

milmazz
Copy link

@milmazz milmazz commented May 10, 2018

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.

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`.
@gonzofish
Copy link
Owner

Thanks for the PR @milmazz! I always appreciate fixes like this. Just for my information, what was happening that made you look into this?

@milmazz
Copy link
Author

milmazz commented May 11, 2018

@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/compiler@5.0.0. 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.

@gonzofish
Copy link
Owner

Great, I'll merge it and it release it tonight

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants