fix(ivy): ngcc - fail build-marker check if any formats were compiled with different ngcc (#29092)

Now we check the build-marker version for all the formats
rather than just the one we are going to compile.

This way we don't get into the situation where one format was
built with one version of ngcc and another format was built with
another version.

PR Close #29092
This commit is contained in:
Pete Bacon Darwin
2019-03-20 13:47:59 +00:00
committed by Matias Niemelä
parent 55ea8da6eb
commit 083fb99033
2 changed files with 61 additions and 7 deletions

View File

@ -10,7 +10,7 @@ import {readFileSync, writeFileSync} from 'fs';
import * as mockFs from 'mock-fs';
import {AbsoluteFsPath} from '../../../src/ngtsc/path';
import {checkMarker, writeMarker} from '../../src/packages/build_marker';
import {checkMarker, hasBeenProcessed, writeMarker} from '../../src/packages/build_marker';
import {EntryPoint} from '../../src/packages/entry_point';
function createMockFileSystem() {
@ -150,4 +150,52 @@ describe('Marker files', () => {
'Please completely remove `node_modules` and try again.');
});
});
describe('hasBeenProcessed', () => {
it('should return true if the marker exists for the given format property', () => {
expect(
hasBeenProcessed({__modified_by_ngcc__: {'fesm2015': '0.0.0-PLACEHOLDER'}}, 'fesm2015'))
.toBe(true);
});
it('should return false if the marker does not exist for the given format property', () => {
expect(hasBeenProcessed({__modified_by_ngcc__: {'fesm2015': '0.0.0-PLACEHOLDER'}}, 'module'))
.toBe(false);
});
it('should return false if the no markers exist',
() => { expect(hasBeenProcessed({}, 'module')).toBe(false); });
it('should throw an Error if the packageJson is not an object', () => {
expect(() => hasBeenProcessed(undefined, 'fesm2015'))
.toThrowError('`packageJson` parameter is invalid. It parameter must be an object.');
expect(
() => hasBeenProcessed(
'{"__modified_by_ngcc__": {"fesm2015": "0.0.0-PLACEHOLDER"}}', 'fesm2015'))
.toThrowError('`packageJson` parameter is invalid. It parameter must be an object.');
});
it('should throw an Error if the format has been compiled with a different version.', () => {
expect(() => hasBeenProcessed({__modified_by_ngcc__: {'fesm2015': '8.0.0'}}, 'fesm2015'))
.toThrowError(
'The ngcc compiler has changed since the last ngcc build.\n' +
'Please completely remove `node_modules` and try again.');
});
it('should throw an Error if any format has been compiled with a different version.', () => {
expect(() => hasBeenProcessed({__modified_by_ngcc__: {'fesm2015': '8.0.0'}}, 'module'))
.toThrowError(
'The ngcc compiler has changed since the last ngcc build.\n' +
'Please completely remove `node_modules` and try again.');
expect(
() => hasBeenProcessed(
{__modified_by_ngcc__: {'module': '0.0.0-PLACEHOLDER', 'fesm2015': '8.0.0'}},
'module'))
.toThrowError(
'The ngcc compiler has changed since the last ngcc build.\n' +
'Please completely remove `node_modules` and try again.');
expect(
() => hasBeenProcessed(
{__modified_by_ngcc__: {'module': '0.0.0-PLACEHOLDER', 'fesm2015': '8.0.0'}},
'fesm2015'))
.toThrowError(
'The ngcc compiler has changed since the last ngcc build.\n' +
'Please completely remove `node_modules` and try again.');
});
});
});