Merge pull request #3 from microsoft/jagore/check-update-symmetry

Make sure inherit check is symmetric with update behavior.
This commit is contained in:
Kenneth Chau 2021-01-22 13:03:18 -08:00 коммит произвёл GitHub
Родитель c72cab613b c82ce0bf62
Коммит bdee81a662
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 996 добавлений и 974 удалений

975
dist/package-inherit-cli.js поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу

975
dist/package-inherit.js поставляемый

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -13,8 +13,9 @@ export function generateInheritedPackageJson(cwd: string) {
for (const [pkg, info] of Object.entries(allPackages)) { for (const [pkg, info] of Object.entries(allPackages)) {
// workspace-tools typings are not comprehensive about what is possible, so we force cast it // workspace-tools typings are not comprehensive about what is possible, so we force cast it
if (info.inherits) { if (info.inherits) {
const inheritInfo = (info.inherits as unknown) as InheritsInfo; const inheritSpecifiers = (info.inherits as unknown) as InheritsInfo;
for (const specifier of inheritInfo) { let mergedInheritInfo = {};
for (const specifier of inheritSpecifiers) {
const file = resolveInRepo(pkg, specifier, allPackages); const file = resolveInRepo(pkg, specifier, allPackages);
if (!file) { if (!file) {
@ -23,11 +24,18 @@ export function generateInheritedPackageJson(cwd: string) {
const inheritInfo = JSON.parse(fs.readFileSync(file, "utf-8")); const inheritInfo = JSON.parse(fs.readFileSync(file, "utf-8"));
// Merge inherit infos for given package together before checking shouldUpdate. This will
// allows inherit check behavior to be symmetric with update behavior, which updates packages
// defined in multiple inherit files to their last occurrence.
for (const key of keys) { for (const key of keys) {
if (shouldUpdate(info[key], inheritInfo[key])) { mergedInheritInfo[key] = { ...mergedInheritInfo[key], ...inheritInfo[key] };
info[key] = { ...(info[key] as any), ...inheritInfo[key] }; }
modifiedPackages.push(pkg); }
}
for (const key of keys) {
if (shouldUpdate(info[key], mergedInheritInfo[key])) {
info[key] = { ...(info[key] as any), ...mergedInheritInfo[key] };
modifiedPackages.push(pkg);
} }
} }
} }