refactor(ngcc): add additional build marker helpers (#35079)
PR Close #35079
This commit is contained in:

committed by
Misko Hevery

parent
be34503b3c
commit
093ac3938e
@ -8,7 +8,8 @@
|
||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {hasBeenProcessed, markAsProcessed} from '../../src/packages/build_marker';
|
||||
import {NGCC_VERSION, cleanPackageJson, hasBeenProcessed, markAsProcessed, needsCleaning} from '../../src/packages/build_marker';
|
||||
import {EntryPointPackageJson} from '../../src/packages/entry_point';
|
||||
import {DirectPackageJsonUpdater} from '../../src/writing/package_json_updater';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
@ -194,5 +195,109 @@ runInEachFileSystem(() => {
|
||||
it('should return false if no markers exist',
|
||||
() => { expect(hasBeenProcessed({name: 'test'}, 'module')).toBe(false); });
|
||||
});
|
||||
|
||||
describe('needsCleaning()', () => {
|
||||
it('should return true if any format has been compiled with a different version', () => {
|
||||
expect(needsCleaning({
|
||||
name: 'test',
|
||||
__processed_by_ivy_ngcc__: {'fesm2015': '8.0.0', 'esm5': NGCC_VERSION}
|
||||
})).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if all formats have been compiled with the current version', () => {
|
||||
expect(needsCleaning({name: 'test', __processed_by_ivy_ngcc__: {'fesm2015': NGCC_VERSION}}))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
it('should return false if no formats have been compiled', () => {
|
||||
expect(needsCleaning({name: 'test', __processed_by_ivy_ngcc__: {}})).toBe(false);
|
||||
expect(needsCleaning({name: 'test'})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cleanPackageJson()', () => {
|
||||
it('should not touch the object if there is no build marker', () => {
|
||||
const packageJson: EntryPointPackageJson = {name: 'test-package'};
|
||||
const result = cleanPackageJson(packageJson);
|
||||
expect(result).toBe(false);
|
||||
expect(packageJson).toEqual({name: 'test-package'});
|
||||
});
|
||||
|
||||
it('should remove the processed marker', () => {
|
||||
const packageJson: EntryPointPackageJson = {
|
||||
name: 'test-package',
|
||||
__processed_by_ivy_ngcc__: {'fesm2015': '8.0.0'}
|
||||
};
|
||||
const result = cleanPackageJson(packageJson);
|
||||
expect(result).toBe(true);
|
||||
expect(packageJson).toEqual({name: 'test-package'});
|
||||
});
|
||||
|
||||
it('should remove new entry-point format properties', () => {
|
||||
const packageJson: EntryPointPackageJson = {
|
||||
name: 'test-package',
|
||||
__processed_by_ivy_ngcc__: {'fesm2015': '8.0.0'},
|
||||
fesm2015: 'index.js',
|
||||
fesm2015_ivy_ngcc: '__ivy_ngcc__/index.js'
|
||||
};
|
||||
const result = cleanPackageJson(packageJson);
|
||||
expect(result).toBe(true);
|
||||
expect(packageJson).toEqual({name: 'test-package', fesm2015: 'index.js'});
|
||||
});
|
||||
|
||||
it('should remove the prepublish script if there was a processed marker', () => {
|
||||
const packageJson: EntryPointPackageJson = {
|
||||
name: 'test-package',
|
||||
__processed_by_ivy_ngcc__: {'fesm2015': '8.0.0'},
|
||||
scripts: {prepublishOnly: 'added by ngcc', test: 'do testing'},
|
||||
};
|
||||
const result = cleanPackageJson(packageJson);
|
||||
expect(result).toBe(true);
|
||||
expect(packageJson).toEqual({
|
||||
name: 'test-package',
|
||||
scripts: {test: 'do testing'},
|
||||
});
|
||||
});
|
||||
|
||||
it('should revert and remove the backup for the prepublish script if there was a processed marker',
|
||||
() => {
|
||||
const packageJson: EntryPointPackageJson = {
|
||||
name: 'test-package',
|
||||
__processed_by_ivy_ngcc__: {'fesm2015': '8.0.0'},
|
||||
scripts: {
|
||||
prepublishOnly: 'added by ngcc',
|
||||
prepublishOnly__ivy_ngcc_bak: 'original',
|
||||
test: 'do testing'
|
||||
},
|
||||
};
|
||||
const result = cleanPackageJson(packageJson);
|
||||
expect(result).toBe(true);
|
||||
expect(packageJson).toEqual({
|
||||
name: 'test-package',
|
||||
scripts: {prepublishOnly: 'original', test: 'do testing'},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not touch the scripts if there was no processed marker', () => {
|
||||
const packageJson: EntryPointPackageJson = {
|
||||
name: 'test-package',
|
||||
scripts: {
|
||||
prepublishOnly: 'added by ngcc',
|
||||
prepublishOnly__ivy_ngcc_bak: 'original',
|
||||
test: 'do testing'
|
||||
},
|
||||
};
|
||||
const result = cleanPackageJson(packageJson);
|
||||
expect(result).toBe(false);
|
||||
expect(packageJson).toEqual({
|
||||
name: 'test-package',
|
||||
scripts: {
|
||||
prepublishOnly: 'added by ngcc',
|
||||
prepublishOnly__ivy_ngcc_bak: 'original',
|
||||
test: 'do testing'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user