mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 18:43:40 +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
90 lines
2.5 KiB
TypeScript
90 lines
2.5 KiB
TypeScript
import is from '@sindresorhus/is';
|
|
import { logger } from '../../../../logger/index.ts';
|
|
import { regEx } from '../../../../util/regex.ts';
|
|
import { parseUrl } from '../../../../util/url.ts';
|
|
import { NpmDatasource } from '../../../datasource/npm/index.ts';
|
|
import type { PackageDependency } from '../../types.ts';
|
|
import type { NpmManagerData, NpmUrlParsedResult } from '../types.ts';
|
|
import { HomebrewUrlHandler } from './base.ts';
|
|
|
|
export class NpmUrlHandler extends HomebrewUrlHandler {
|
|
readonly type = 'npm';
|
|
|
|
parseUrl(urlStr: string): NpmUrlParsedResult | null {
|
|
if (!is.nonEmptyString(urlStr)) {
|
|
logger.debug({ urlStr }, 'Invalid URL string');
|
|
return null;
|
|
}
|
|
|
|
const url = parseUrl(urlStr);
|
|
if (url?.hostname !== 'registry.npmjs.org') {
|
|
logger.once.debug(
|
|
{ hostname: url?.hostname },
|
|
'Homebrew only support NPM packages hosted on registry.npmjs.org',
|
|
);
|
|
return null;
|
|
}
|
|
|
|
// Pattern: /<packageName>/-/<filename>-<version>.tgz
|
|
// For scoped: /@scope/name/-/name-version.tgz
|
|
// For unscoped: /name/-/name-version.tgz
|
|
const pattern = regEx(
|
|
/^\/(?<packageName>(?:@[^/]+\/)?[^/]+)\/-\/[^/]+-(?<version>[\d.]+(?:-[a-zA-Z0-9.-]*)?)\.tgz$/,
|
|
);
|
|
|
|
const match = pattern.exec(url.pathname);
|
|
|
|
const version = match?.groups?.version;
|
|
const packageName = match?.groups?.packageName;
|
|
if (!packageName || !version) {
|
|
logger.debug(
|
|
{ pathname: url.pathname },
|
|
'Path does not contain a valid NPM package name or version',
|
|
);
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
type: 'npm',
|
|
currentValue: version,
|
|
packageName,
|
|
};
|
|
}
|
|
|
|
createDependency(
|
|
parsed: NpmUrlParsedResult,
|
|
sha256: string | null,
|
|
url: string,
|
|
): PackageDependency<NpmManagerData> {
|
|
return {
|
|
depName: parsed.packageName,
|
|
currentValue: parsed.currentValue,
|
|
datasource: NpmDatasource.id,
|
|
managerData: {
|
|
type: 'npm',
|
|
packageName: parsed.packageName,
|
|
sha256,
|
|
url,
|
|
},
|
|
};
|
|
}
|
|
|
|
buildArchiveUrls(
|
|
managerData: NpmManagerData,
|
|
newVersion: string,
|
|
): string[] | null {
|
|
const { packageName } = managerData;
|
|
|
|
// Extract filename from package name
|
|
// Scoped: @foo/bar -> bar
|
|
// Unscoped: bar -> bar
|
|
const filename = packageName.includes('/')
|
|
? packageName.split('/')[1]
|
|
: packageName;
|
|
|
|
return [
|
|
`https://registry.npmjs.org/${packageName}/-/${filename}-${newVersion}.tgz`,
|
|
];
|
|
}
|
|
}
|