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:
parent
55ea8da6eb
commit
083fb99033
|
@ -22,18 +22,24 @@ export const NGCC_VERSION = '0.0.0-PLACEHOLDER';
|
|||
* @param packageJson The parsed contents of the package.json file for the entry-point.
|
||||
* @param format The entry-point format property in the package.json to check.
|
||||
* @returns true if the entry-point and format have already been processed with this ngcc version.
|
||||
* @throws Error if the entry-point has already been processed with a different ngcc
|
||||
* version.
|
||||
* @throws Error if the `packageJson` property is not an object.
|
||||
* @throws Error if the entry-point has already been processed with a different ngcc version.
|
||||
*/
|
||||
export function hasBeenProcessed(packageJson: any, format: string): boolean {
|
||||
const compiledVersion =
|
||||
packageJson && packageJson.__modified_by_ngcc__ && packageJson.__modified_by_ngcc__[format];
|
||||
if (compiledVersion && compiledVersion !== NGCC_VERSION) {
|
||||
if (typeof packageJson !== 'object') {
|
||||
throw new Error('`packageJson` parameter is invalid. It parameter must be an object.');
|
||||
}
|
||||
if (!packageJson.__modified_by_ngcc__) {
|
||||
return false;
|
||||
}
|
||||
if (Object.keys(packageJson.__modified_by_ngcc__)
|
||||
.some(property => packageJson.__modified_by_ngcc__[property] !== NGCC_VERSION)) {
|
||||
throw new Error(
|
||||
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||
'Please completely remove `node_modules` and try again.');
|
||||
}
|
||||
return !!compiledVersion;
|
||||
|
||||
return packageJson.__modified_by_ngcc__[format] === NGCC_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue