Skip to content

Commit 1932bb9

Browse files
authored
fix: noImplicitAny ts (#568)
> Attempted to apply the `noImplicitAny`, parameter types should be specified unless any is manually declared. * 🐞 Fixed an issue in bugVersionAdvice where AbbreviatedManifest was being set abnormally. * 🤖 Added index.d.ts to store declarations for dependencies without types. * 🤔 skipLibCheck has no effect on leoric for now, so it cannot be enabled temporarily. -------- > 尝试应用 `noImplicitAny` 配置,除非手动声明 any,否则需要指定参数类型 * 🐞 修复 bugVersionAdvice 中,AbbreviatedManifest 设置异常 * 🤖 添加 index.d.ts 存放无类型依赖声明 * 🤔 skipLibCheck 对 leoric 失效,暂时无法开启 ![image](https://github.com/cnpm/cnpmcore/assets/5574625/7ed9d22e-cac8-4202-ba3c-d4c26eb7dc00)
1 parent 3297121 commit 1932bb9

33 files changed

+239
-79
lines changed

app/common/FileUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ const WHITE_FILENAME_CONTENT_TYPES = {
105105
'.eslintignore': PLAIN_TEXT,
106106
'.jshintrc': 'application/json',
107107
'.eslintrc': 'application/json',
108-
};
108+
} as const;
109109

110110
export function mimeLookup(filepath: string) {
111111
const filename = path.basename(filepath).toLowerCase();
112112
if (filename.endsWith('.ts')) return PLAIN_TEXT;
113113
if (filename.endsWith('.lock')) return PLAIN_TEXT;
114114
return mime.lookup(filename) ||
115-
WHITE_FILENAME_CONTENT_TYPES[filename] ||
115+
WHITE_FILENAME_CONTENT_TYPES[filename as keyof typeof WHITE_FILENAME_CONTENT_TYPES] ||
116116
DEFAULT_CONTENT_TYPE;
117117
}

app/common/UserUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function integrity(plain: string): string {
3434
}
3535

3636
export function checkIntegrity(plain: string, expectedIntegrity: string): boolean {
37-
return ssri.checkData(plain, expectedIntegrity);
37+
return !!ssri.checkData(plain, expectedIntegrity);
3838
}
3939

4040
export function sha512(plain: string): string {

app/common/adapter/NPMRegistry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
HttpClientRequestOptions,
1212
HttpClientResponse,
1313
} from 'egg';
14+
import { PackageManifestType } from '../../repository/PackageRepository';
1415

1516
type HttpMethod = HttpClientRequestOptions['method'];
1617

@@ -40,7 +41,7 @@ export class NPMRegistry {
4041
this.registryHost = registryHost;
4142
}
4243

43-
public async getFullManifests(fullname: string, optionalConfig?: {retries?:number, remoteAuthToken?:string}): Promise<RegistryResponse> {
44+
public async getFullManifests(fullname: string, optionalConfig?: { retries?: number, remoteAuthToken?: string }): Promise<{ method: HttpMethod } & HttpClientResponse<PackageManifestType>> {
4445
let retries = optionalConfig?.retries || 3;
4546
// set query t=timestamp, make sure CDN cache disable
4647
// cache=0 is sync worker request flag

app/common/adapter/binary/AbstractBinary.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export type FetchResult = {
1717
nextParams?: any;
1818
};
1919

20+
const platforms = [ 'darwin', 'linux', 'win32' ] as const;
21+
2022
export const BINARY_ADAPTER_ATTRIBUTE = Symbol('BINARY_ADAPTER_ATTRIBUTE');
2123

2224
export abstract class AbstractBinary {
@@ -74,7 +76,7 @@ export abstract class AbstractBinary {
7476

7577
protected listNodePlatforms() {
7678
// https://nodejs.org/api/os.html#osplatform
77-
return [ 'darwin', 'linux', 'win32' ];
79+
return platforms;
7880
}
7981

8082
protected listNodeArchs(binaryConfig?: BinaryTaskConfig) {
@@ -87,11 +89,11 @@ export abstract class AbstractBinary {
8789
};
8890
}
8991

90-
protected listNodeLibcs() {
92+
protected listNodeLibcs(): Record<typeof platforms[number], string[]> {
9193
// https://github.com/lovell/detect-libc/blob/master/lib/detect-libc.js#L42
9294
return {
93-
linux: [ 'glibc', 'musl' ],
9495
darwin: [ 'unknown' ],
96+
linux: [ 'glibc', 'musl' ],
9597
win32: [ 'unknown' ],
9698
};
9799
}

app/common/adapter/binary/PlaywrightBinary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const DOWNLOAD_PATHS = {
189189
'android': {
190190
'<unknown>': 'builds/android/%s/android.zip',
191191
},
192-
};
192+
} as const;
193193

194194
@SingletonProto()
195195
@BinaryAdapter(BinaryType.Playwright)
@@ -215,7 +215,7 @@ export class PlaywrightBinary extends AbstractBinary {
215215
.filter(version => version.match(/^(?:\d+\.\d+\.\d+)(?:-beta-\d+)?$/))
216216
// select recently update 20 items
217217
.slice(-20);
218-
const browsers: { name: string; revision: string; browserVersion: string; revisionOverrides?: Record<string, string> }[] = [];
218+
const browsers: { name: keyof typeof DOWNLOAD_PATHS; revision: string; browserVersion: string; revisionOverrides?: Record<string, string> }[] = [];
219219
await Promise.all(
220220
packageVersions.map(version =>
221221
this.requestJSON(

app/common/adapter/changesStream/CnpmjsorgChangesStream.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import { AbstractChangeStream, RegistryChangesStream } from './AbstractChangesSt
66

77
const MAX_LIMIT = 10000;
88

9+
type FetchResults = {
10+
results: {
11+
seq: number;
12+
type: string;
13+
id: string;
14+
changes: Record<string, string>[];
15+
gmt_modified: Date,
16+
}[];
17+
};
18+
919
@SingletonProto()
1020
@RegistryChangesStream(RegistryType.Cnpmjsorg)
1121
export class CnpmjsorgChangesStream extends AbstractChangeStream {
@@ -18,13 +28,13 @@ export class CnpmjsorgChangesStream extends AbstractChangeStream {
1828
return since;
1929
}
2030

21-
private async tryFetch(registry: Registry, since: string, limit = 1000) {
31+
private async tryFetch(registry: Registry, since: string, limit = 1000): Promise<{ data: FetchResults }> {
2232
if (limit > MAX_LIMIT) {
2333
throw new E500(`limit too large, current since: ${since}, limit: ${limit}`);
2434
}
2535
const db = this.getChangesStreamUrl(registry, since, limit);
2636
// json mode
27-
const res = await this.httpclient.request(db, {
37+
const res = await this.httpclient.request<FetchResults>(db, {
2838
followRedirect: true,
2939
timeout: 30000,
3040
dataType: 'json',

app/core/entity/BugVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type BugVersionPackages = Record<string, BugVersionPackage>;
88
export class BugVersion {
99
private readonly data: BugVersionPackages;
1010

11-
constructor(data) {
11+
constructor(data: BugVersionPackages) {
1212
this.data = data;
1313
}
1414

app/core/entity/Hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Hook extends Entity {
4848
}
4949

5050
// payload 可能会特别大,如果做多次 stringify 浪费太多 cpu
51-
signPayload(payload: object): { digest, payloadStr } {
51+
signPayload(payload: object) {
5252
const payloadStr = JSON.stringify(payload);
5353
const digest = crypto.createHmac('sha256', this.secret)
5454
.update(JSON.stringify(payload))

app/core/entity/SqlRange.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class SqlRange {
3838
};
3939
}
4040
const paddingSemver = new PaddingSemVer(comparator.semver);
41-
const operator = OPERATOR_MAP[comparator.operator];
41+
const operator = OPERATOR_MAP[comparator.operator as keyof typeof OPERATOR_MAP];
4242
if (!operator) {
4343
throw new Error(`unknown operator ${comparator.operator}`);
4444
}

app/core/service/BugVersionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class BugVersionService {
4040
const packageVersionJson = (await this.distRepository.findPackageVersionManifest(pkg!.packageId, tag!.version)) as PackageJSONType;
4141
if (!packageVersionJson) return;
4242
const data = packageVersionJson.config?.['bug-versions'];
43-
bugVersion = new BugVersion(data);
43+
bugVersion = new BugVersion(data || {});
4444
this.bugVersionStore.setBugVersion(bugVersion, tag!.version);
4545
}
4646
return bugVersion;

0 commit comments

Comments
 (0)