fix(ngcc): make the build-marker error more clear (#32712)
The previous message was confusing as it could be interpreted as only deleting the package mentioned. Now we compute and display the actual node_modules path to remove. See https://github.com/angular/angular/issues/31354#issuecomment-532080537 PR Close #32712
This commit is contained in:
parent
c1346462db
commit
0ea4875b10
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AbsoluteFsPath, FileSystem, dirname} from '../../../src/ngtsc/file_system';
|
import {AbsoluteFsPath, basename, dirname, isRoot} from '../../../src/ngtsc/file_system';
|
||||||
import {PackageJsonUpdater} from '../writing/package_json_updater';
|
import {PackageJsonUpdater} from '../writing/package_json_updater';
|
||||||
import {EntryPointPackageJson, PackageJsonFormatProperties} from './entry_point';
|
import {EntryPointPackageJson, PackageJsonFormatProperties} from './entry_point';
|
||||||
|
|
||||||
|
@ -31,9 +31,13 @@ export function hasBeenProcessed(
|
||||||
}
|
}
|
||||||
if (Object.keys(packageJson.__processed_by_ivy_ngcc__)
|
if (Object.keys(packageJson.__processed_by_ivy_ngcc__)
|
||||||
.some(property => packageJson.__processed_by_ivy_ngcc__ ![property] !== NGCC_VERSION)) {
|
.some(property => packageJson.__processed_by_ivy_ngcc__ ![property] !== NGCC_VERSION)) {
|
||||||
|
let nodeModulesFolderPath = entryPointPath;
|
||||||
|
while (!isRoot(nodeModulesFolderPath) && basename(nodeModulesFolderPath) !== 'node_modules') {
|
||||||
|
nodeModulesFolderPath = dirname(nodeModulesFolderPath);
|
||||||
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The ngcc compiler has changed since the last ngcc build.\n' +
|
`The ngcc compiler has changed since the last ngcc build.\n` +
|
||||||
`Please completely remove the "node_modules" folder containing "${entryPointPath}" and try again.`);
|
`Please remove "${isRoot(nodeModulesFolderPath) ? entryPointPath : nodeModulesFolderPath}" and try again.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return packageJson.__processed_by_ivy_ngcc__[format] === NGCC_VERSION;
|
return packageJson.__processed_by_ivy_ngcc__[format] === NGCC_VERSION;
|
||||||
|
|
|
@ -178,8 +178,12 @@ runInEachFileSystem(() => {
|
||||||
|
|
||||||
describe('hasBeenProcessed', () => {
|
describe('hasBeenProcessed', () => {
|
||||||
let entryPointPath: AbsoluteFsPath;
|
let entryPointPath: AbsoluteFsPath;
|
||||||
|
let nodeModulesPath: AbsoluteFsPath;
|
||||||
|
|
||||||
beforeEach(() => entryPointPath = _('/node_modules/test'));
|
beforeEach(() => {
|
||||||
|
entryPointPath = _('/node_modules/test');
|
||||||
|
nodeModulesPath = _('/node_modules');
|
||||||
|
});
|
||||||
|
|
||||||
it('should return true if the marker exists for the given format property', () => {
|
it('should return true if the marker exists for the given format property', () => {
|
||||||
expect(hasBeenProcessed(
|
expect(hasBeenProcessed(
|
||||||
|
@ -187,14 +191,17 @@ runInEachFileSystem(() => {
|
||||||
'fesm2015', entryPointPath))
|
'fesm2015', entryPointPath))
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if the marker does not exist for the given format property', () => {
|
it('should return false if the marker does not exist for the given format property', () => {
|
||||||
expect(hasBeenProcessed(
|
expect(hasBeenProcessed(
|
||||||
{name: 'test', __processed_by_ivy_ngcc__: {'fesm2015': '0.0.0-PLACEHOLDER'}},
|
{name: 'test', __processed_by_ivy_ngcc__: {'fesm2015': '0.0.0-PLACEHOLDER'}},
|
||||||
'module', entryPointPath))
|
'module', entryPointPath))
|
||||||
.toBe(false);
|
.toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if no markers exist',
|
it('should return false if no markers exist',
|
||||||
() => { expect(hasBeenProcessed({name: 'test'}, 'module', entryPointPath)).toBe(false); });
|
() => { expect(hasBeenProcessed({name: 'test'}, 'module', entryPointPath)).toBe(false); });
|
||||||
|
|
||||||
it('should throw an Error if the format has been compiled with a different version.', () => {
|
it('should throw an Error if the format has been compiled with a different version.', () => {
|
||||||
expect(
|
expect(
|
||||||
() => hasBeenProcessed(
|
() => hasBeenProcessed(
|
||||||
|
@ -202,8 +209,9 @@ runInEachFileSystem(() => {
|
||||||
entryPointPath))
|
entryPointPath))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
'The ngcc compiler has changed since the last ngcc build.\n' +
|
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||||
`Please completely remove the "node_modules" folder containing "${entryPointPath}" and try again.`);
|
`Please remove "${nodeModulesPath}" and try again.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an Error if any format has been compiled with a different version.', () => {
|
it('should throw an Error if any format has been compiled with a different version.', () => {
|
||||||
expect(
|
expect(
|
||||||
() => hasBeenProcessed(
|
() => hasBeenProcessed(
|
||||||
|
@ -211,7 +219,7 @@ runInEachFileSystem(() => {
|
||||||
entryPointPath))
|
entryPointPath))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
'The ngcc compiler has changed since the last ngcc build.\n' +
|
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||||
`Please completely remove the "node_modules" folder containing "${entryPointPath}" and try again.`);
|
`Please remove "${nodeModulesPath}" and try again.`);
|
||||||
expect(
|
expect(
|
||||||
() => hasBeenProcessed(
|
() => hasBeenProcessed(
|
||||||
{
|
{
|
||||||
|
@ -221,7 +229,7 @@ runInEachFileSystem(() => {
|
||||||
'module', entryPointPath))
|
'module', entryPointPath))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
'The ngcc compiler has changed since the last ngcc build.\n' +
|
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||||
`Please completely remove the "node_modules" folder containing "${entryPointPath}" and try again.`);
|
`Please remove "${nodeModulesPath}" and try again.`);
|
||||||
expect(
|
expect(
|
||||||
() => hasBeenProcessed(
|
() => hasBeenProcessed(
|
||||||
{
|
{
|
||||||
|
@ -231,7 +239,34 @@ runInEachFileSystem(() => {
|
||||||
'fesm2015', entryPointPath))
|
'fesm2015', entryPointPath))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
'The ngcc compiler has changed since the last ngcc build.\n' +
|
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||||
`Please completely remove the "node_modules" folder containing "${entryPointPath}" and try again.`);
|
`Please remove "${nodeModulesPath}" and try again.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an Error, with the appropriate path to remove, if the format has been compiled with a different version',
|
||||||
|
() => {
|
||||||
|
expect(
|
||||||
|
() => hasBeenProcessed(
|
||||||
|
{name: 'test', __processed_by_ivy_ngcc__: {'fesm2015': '8.0.0'}}, 'fesm2015',
|
||||||
|
_('/node_modules/test')))
|
||||||
|
.toThrowError(
|
||||||
|
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||||
|
`Please remove "${_('/node_modules')}" and try again.`);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
() => hasBeenProcessed(
|
||||||
|
{name: 'nested', __processed_by_ivy_ngcc__: {'fesm2015': '8.0.0'}}, 'fesm2015',
|
||||||
|
_('/node_modules/test/node_modules/nested')))
|
||||||
|
.toThrowError(
|
||||||
|
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||||
|
`Please remove "${_('/node_modules/test/node_modules')}" and try again.`);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
() => hasBeenProcessed(
|
||||||
|
{name: 'test', __processed_by_ivy_ngcc__: {'fesm2015': '8.0.0'}}, 'fesm2015',
|
||||||
|
_('/dist/test')))
|
||||||
|
.toThrowError(
|
||||||
|
'The ngcc compiler has changed since the last ngcc build.\n' +
|
||||||
|
`Please remove "${_('/dist/test')}" and try again.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue