mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 10:33:39 +00:00
c32e2391a0
Refs #45216 The object counterpart to `prefer-coerce-array`: `x ?? {}` becomes `coerceObject(x)`. The rule flags a `??` whose default is a bare `{}` literal, so a populated default or an asserted `({} as Foo)` still passes; a `x ?? y ?? {}` chain maps onto `coerceObject(x, y)`. Every hit across `lib/` converted cleanly, so no disable comments were needed.
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
import { isArray, isString, isTruthy } from '@sindresorhus/is';
|
|
import { logger } from '../../../../../logger/index.ts';
|
|
import {
|
|
getParentDir,
|
|
getSiblingFileName,
|
|
} from '../../../../../util/fs/index.ts';
|
|
import { coerceObject } from '../../../../../util/object.ts';
|
|
import type { PackageFile } from '../../../types.ts';
|
|
import type { NpmManagerData } from '../../types.ts';
|
|
import { detectPnpmWorkspaces } from '../pnpm.ts';
|
|
import { matchesAnyPattern } from '../utils.ts';
|
|
|
|
export async function detectMonorepos(
|
|
packageFiles: Partial<PackageFile<NpmManagerData>>[],
|
|
): Promise<void> {
|
|
await detectPnpmWorkspaces(packageFiles);
|
|
logger.debug('Detecting workspaces');
|
|
for (const p of packageFiles) {
|
|
const { packageFile, npmrc, managerData = {}, skipInstalls } = p;
|
|
const {
|
|
npmLock,
|
|
yarnZeroInstall,
|
|
hasPackageManager,
|
|
workspacesPackages,
|
|
yarnLock,
|
|
} = managerData;
|
|
|
|
const packages = workspacesPackages as string[] | undefined;
|
|
if (packages?.length) {
|
|
const internalPackagePatterns = (
|
|
isArray(packages) ? packages : [packages]
|
|
).map((pattern) => getSiblingFileName(packageFile!, pattern));
|
|
const internalPackageFiles = packageFiles.filter((sp) =>
|
|
matchesAnyPattern(
|
|
getParentDir(sp.packageFile!),
|
|
internalPackagePatterns,
|
|
),
|
|
);
|
|
const internalPackageNames = internalPackageFiles
|
|
.map((sp) => sp.managerData?.packageJsonName)
|
|
.filter(isTruthy);
|
|
|
|
p.deps?.forEach((dep) => {
|
|
if (
|
|
isString(dep.depName) &&
|
|
internalPackageNames.includes(dep.depName)
|
|
) {
|
|
dep.isInternal = true;
|
|
}
|
|
});
|
|
|
|
for (const subPackage of internalPackageFiles) {
|
|
subPackage.managerData = coerceObject(subPackage.managerData);
|
|
subPackage.managerData.yarnZeroInstall = yarnZeroInstall;
|
|
subPackage.managerData.hasPackageManager = hasPackageManager;
|
|
subPackage.managerData.yarnLock ??= yarnLock;
|
|
subPackage.managerData.npmLock ??= npmLock;
|
|
subPackage.skipInstalls = skipInstalls && subPackage.skipInstalls; // skip if both are true
|
|
subPackage.managerData.workspacesPackages = workspacesPackages;
|
|
subPackage.npmrc ??= npmrc;
|
|
|
|
if (p.extractedConstraints) {
|
|
subPackage.extractedConstraints = {
|
|
...p.extractedConstraints,
|
|
...subPackage.extractedConstraints,
|
|
};
|
|
}
|
|
|
|
subPackage.deps?.forEach((dep) => {
|
|
if (
|
|
isString(dep.depName) &&
|
|
internalPackageNames.includes(dep.depName)
|
|
) {
|
|
dep.isInternal = true;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|