From 4c58a46b437b6893cd8466bcca32f8f6e10d6df5 Mon Sep 17 00:00:00 2001 From: Dina Basumatary Date: Fri, 27 Oct 2023 02:49:05 +1100 Subject: [PATCH] Get rid of @ts-ignore (iteration 1 or many more to go) (#4079) * Update process.ts - Removed the silentNpm function. not being used anywhere - Type guard for childProcess.stdout - fix type errors * typo * remove @ts-ignore * remove ts-ignore * chore: remove type already inferred * chore: fix types * chore: fix types and add typeguard * chore: fix pnpm 8.9.0 * revert an incorrect change --------- Co-authored-by: Dina Basumatary --- CONTRIBUTING.md | 2 +- e2e/cli/cli-commons/src/process.ts | 20 ++++++++----------- e2e/cli/cli-commons/src/utils.ts | 1 - packages/api/src/index.ts | 1 - packages/api/src/publish.ts | 4 ++-- packages/auth/src/auth.ts | 19 +++++++----------- packages/core/types/src/manifest.ts | 2 +- .../middleware/src/middlewares/antiLoop.ts | 2 +- 8 files changed, 20 insertions(+), 31 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ef8573e19..13fe52944 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -165,7 +165,7 @@ of the output is sent to the logger module. Once you have perform your changes in the code base, the build and tests passes you can publish a local version: -- Ensure you have build all modules (or the one you have modified) +- Ensure you have built all modules by running `pnpm build` (or the one you have modified) - Run `pnpm local:publish:release` to launch a local registry and publish all packages into it. This command will be alive until server is killed (Control Key + C) ```shell diff --git a/e2e/cli/cli-commons/src/process.ts b/e2e/cli/cli-commons/src/process.ts index 9b8763bd9..b177ae482 100644 --- a/e2e/cli/cli-commons/src/process.ts +++ b/e2e/cli/cli-commons/src/process.ts @@ -31,12 +31,13 @@ export async function exec(options: SpawnOptions, cmd, args): Promise { @@ -45,14 +46,9 @@ export async function exec(options: SpawnOptions, cmd, args): Promise { - debug('run silent npm %o', args); - // @ts-ignore - return exec({ silent: true }, 'npm', args); -} diff --git a/e2e/cli/cli-commons/src/utils.ts b/e2e/cli/cli-commons/src/utils.ts index 22d1eb84b..8f017f316 100644 --- a/e2e/cli/cli-commons/src/utils.ts +++ b/e2e/cli/cli-commons/src/utils.ts @@ -5,7 +5,6 @@ import { join } from 'path'; import { fileUtils } from '@verdaccio/core'; export function createProject(projectName: string) { - // @ts-ignore const tempRootFolder = global.__namespace.getItem('dir-suite-root'); const verdaccioInstall = join(tempRootFolder, projectName); fs.mkdirSync(verdaccioInstall); diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 3368e796e..e4a3b9a1a 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -43,7 +43,6 @@ export default function (config: Config, auth: Auth, storage: Storage): Router { app.param('org_couchdb_user', match(/^org\.couchdb\.user:/)); app.use(auth.apiJWTmiddleware()); app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' })); - // @ts-ignore app.use(antiLoop(config)); // encode / in a scoped package name to be matched as a single parameter in routes app.use(encodeScopePackage); diff --git a/packages/api/src/publish.ts b/packages/api/src/publish.ts index 27c864320..62353fb90 100644 --- a/packages/api/src/publish.ts +++ b/packages/api/src/publish.ts @@ -196,10 +196,10 @@ export function publishPackage(storage: Storage): any { requestOptions: { host: req.hostname, protocol: req.protocol, - // @ts-ignore - headers: req.headers, + headers: req.headers as { [key: string]: string }, username, }, + uplinksLook: false, }); res.status(HTTP_STATUS.CREATED); diff --git a/packages/auth/src/auth.ts b/packages/auth/src/auth.ts index 8bc0078de..8b91f0659 100644 --- a/packages/auth/src/auth.ts +++ b/packages/auth/src/auth.ts @@ -1,5 +1,5 @@ import buildDebug from 'debug'; -import { NextFunction, Request, RequestHandler, Response } from 'express'; +import { NextFunction, Request, Response } from 'express'; import _ from 'lodash'; import { HTPasswd } from 'verdaccio-htpasswd'; @@ -308,12 +308,11 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth { debug('allow unpublish for %o', packageName); for (const plugin of this.plugins) { - if (_.isNil(plugin) || isFunction(plugin.allow_unpublish) === false) { + if (typeof plugin?.allow_unpublish !== 'function') { debug('allow unpublish for %o plugin does not implement allow_unpublish', packageName); continue; } else { - // @ts-ignore - plugin.allow_unpublish!(user, pkg, (err, ok: boolean): void => { + plugin.allow_unpublish(user, pkg, (err, ok): void => { if (err) { debug( 'forbidden publish for %o, it will fallback on unpublish permissions', @@ -324,9 +323,7 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth { if (_.isNil(ok) === true) { debug('bypass unpublish for %o, publish will handle the access', packageName); - // @ts-ignore - // eslint-disable-next-line - return this.allow_publish(...arguments); + return this.allow_publish({ packageName, packageVersion }, user, callback); } if (ok) { @@ -350,7 +347,7 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth { const pkg = Object.assign( { name: packageName, version: packageVersion }, getMatchedPackagesSpec(packageName, this.config.packages) - ) as any; + ); debug('allow publish for %o init | plugins: %o', packageName, plugins.length); (function next(): void { @@ -378,7 +375,7 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth { })(); } - public apiJWTmiddleware(): RequestHandler { + public apiJWTmiddleware() { debug('jwt middleware'); const plugins = this.plugins.slice(0); const helpers = { createAnonymousRemoteUser, createRemoteUser }; @@ -388,7 +385,6 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth { } } - // @ts-ignore return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction) => { req.pause(); @@ -519,8 +515,7 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth { /** * JWT middleware for WebUI */ - public webUIJWTmiddleware(): RequestHandler { - // @ts-ignore + public webUIJWTmiddleware(): $NextFunctionVer { return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction): void => { if (this._isRemoteUserValid(req.remote_user)) { return _next(); diff --git a/packages/core/types/src/manifest.ts b/packages/core/types/src/manifest.ts index 14be3bd67..6bc887c93 100644 --- a/packages/core/types/src/manifest.ts +++ b/packages/core/types/src/manifest.ts @@ -3,7 +3,7 @@ export interface PackageAccess { publish?: string[]; proxy?: string[]; access?: string[]; - unpublish: string[]; + unpublish?: string[]; } export interface PackageList { diff --git a/packages/middleware/src/middlewares/antiLoop.ts b/packages/middleware/src/middlewares/antiLoop.ts index 0aeb1a05f..2d6cc4be2 100644 --- a/packages/middleware/src/middlewares/antiLoop.ts +++ b/packages/middleware/src/middlewares/antiLoop.ts @@ -8,7 +8,7 @@ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types'; * @param config * @returns */ -export function antiLoop(config: Config): Function { +export function antiLoop(config: Config) { return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void { if (req?.headers?.via != null) { const arr = req.get('via')?.split(',');