mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 09:41:46 +00:00
e0cec3dc95
feat(lint): add `types-location` rule and enable it for `lib/modules`
Reviewers consistently ask for exported types to be moved into a
colocated `types.ts`. Add a `renovate/types-location` oxlint rule that
reports `export interface` / `export type` declarations outside such a
file, and turn it on across `lib/modules`.
Re-exports (`export type { X }`, `export type *`), file-local types, and
values (enums, classes, functions) are left alone. `schema.ts` files and
`schema/` directories are excluded via config, matching how
`zod-schema-location` is configured — inferred types belong next to the
schema they are derived from.
Relocating the 87 existing violations means:
- new `types.ts` files for the modules that had none
- `terragrunt/common.ts` folded into its `types.ts`, as it held nothing
else
- `RangeBound` in `versioning/gradle/compare.ts` un-exported, since only
a file-local interface referenced it
- `bazel-module/parser/fragments.ts` split from its inferred types, which
now live in `parser/types.ts` and infer through a namespace import so
each schema keeps its merged name
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { isArray } from '@sindresorhus/is';
|
|
import semver from 'semver';
|
|
import { logger } from '../../../../logger/index.ts';
|
|
import { Lazy } from '../../../../util/lazy.ts';
|
|
import type { PackageJson } from '../schema.ts';
|
|
import { loadPackageJson } from '../utils.ts';
|
|
|
|
export function lazyLoadPackageJson(
|
|
lockFileDir: string,
|
|
): Lazy<Promise<PackageJson>> {
|
|
return new Lazy(() => loadPackageJson(lockFileDir));
|
|
}
|
|
|
|
export function getPackageManagerVersion(
|
|
name: string,
|
|
pkg: PackageJson,
|
|
): string | null {
|
|
if (pkg.volta?.[name]) {
|
|
const version = pkg.volta[name];
|
|
logger.debug(`Found ${name} constraint in package.json volta: ${version}`);
|
|
|
|
return version;
|
|
}
|
|
if (pkg.devEngines?.packageManager) {
|
|
const packageManagers = isArray(pkg.devEngines.packageManager)
|
|
? pkg.devEngines.packageManager
|
|
: [pkg.devEngines.packageManager];
|
|
const packageMgr = packageManagers.find((pm) => pm.name === name);
|
|
const version = packageMgr?.version;
|
|
// v8 ignore else -- TODO: add test #40625
|
|
if (version) {
|
|
logger.debug(
|
|
`Found ${name} constraint in package.json devEngines: ${version}`,
|
|
);
|
|
return version;
|
|
}
|
|
}
|
|
if (pkg.packageManager?.name === name) {
|
|
const version = pkg.packageManager.version;
|
|
logger.debug(
|
|
`Found ${name} constraint in package.json packageManager: ${version}`,
|
|
);
|
|
if (semver.valid(version)) {
|
|
return version;
|
|
}
|
|
return null;
|
|
}
|
|
if (pkg.engines?.[name]) {
|
|
const version = pkg.engines[name];
|
|
logger.debug(
|
|
`Found ${name} constraint in package.json engines: ${version}`,
|
|
);
|
|
return version;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getNodeOptions(nodeMaxMemory: number): string {
|
|
return `--max-old-space-size=${nodeMaxMemory}`;
|
|
}
|