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

committed by
Misko Hevery

parent
cc43bfa725
commit
3cf55c195b
@ -6,11 +6,53 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {AbsoluteFsPath} from '../../../src/ngtsc/file_system';
|
||||
import {NGCC_PROPERTY_EXTENSION} from '../writing/new_entry_point_file_writer';
|
||||
import {PackageJsonUpdater} from '../writing/package_json_updater';
|
||||
import {EntryPointPackageJson, PackageJsonFormatProperties} from './entry_point';
|
||||
|
||||
export const NGCC_VERSION = '0.0.0-PLACEHOLDER';
|
||||
|
||||
/**
|
||||
* Returns true if there is a format in this entry-point that was compiled with an outdated version
|
||||
* of ngcc.
|
||||
*
|
||||
* @param packageJson The parsed contents of the package.json for the entry-point
|
||||
*/
|
||||
export function needsCleaning(packageJson: EntryPointPackageJson): boolean {
|
||||
return Object.values(packageJson.__processed_by_ivy_ngcc__ || {})
|
||||
.some(value => value !== NGCC_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean any build marker artifacts from the given `packageJson` object.
|
||||
* @param packageJson The parsed contents of the package.json to modify
|
||||
* @returns true if the package was modified during cleaning
|
||||
*/
|
||||
export function cleanPackageJson(packageJson: EntryPointPackageJson): boolean {
|
||||
if (packageJson.__processed_by_ivy_ngcc__ !== undefined) {
|
||||
// Remove the actual marker
|
||||
delete packageJson.__processed_by_ivy_ngcc__;
|
||||
// Remove new format properties that have been added by ngcc
|
||||
for (const prop of Object.keys(packageJson)) {
|
||||
if (prop.endsWith(NGCC_PROPERTY_EXTENSION)) {
|
||||
delete packageJson[prop];
|
||||
}
|
||||
}
|
||||
|
||||
// Also remove the prebulish script if we modified it
|
||||
const scripts = packageJson.scripts;
|
||||
if (scripts !== undefined && scripts.prepublishOnly) {
|
||||
delete scripts.prepublishOnly;
|
||||
if (scripts.prepublishOnly__ivy_ngcc_bak !== undefined) {
|
||||
scripts.prepublishOnly = scripts.prepublishOnly__ivy_ngcc_bak;
|
||||
delete scripts.prepublishOnly__ivy_ngcc_bak;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether ngcc has already processed a given entry-point format.
|
||||
*
|
||||
|
Reference in New Issue
Block a user