0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

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 <dnafication@users.noreply.github.com>
This commit is contained in:
Dina Basumatary 2023-10-27 02:49:05 +11:00 committed by GitHub
parent 33cf14740d
commit 4c58a46b43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 31 deletions

View file

@ -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: 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) - 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 ```shell

View file

@ -31,12 +31,13 @@ export async function exec(options: SpawnOptions, cmd, args): Promise<ExecOutput
} }
const childProcess = spawn(cmd, args, spawnOptions); const childProcess = spawn(cmd, args, spawnOptions);
// @ts-ignore if (childProcess.stdout) {
const rl = createInterface({ input: childProcess.stdout }); const rl = createInterface({ input: childProcess.stdout });
rl.on('line', function (line) { rl.on('line', function (line) {
stdout += line; stdout += line;
}); });
}
const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `); const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -45,14 +46,9 @@ export async function exec(options: SpawnOptions, cmd, args): Promise<ExecOutput
resolve({ stdout, stderr }); resolve({ stdout, stderr });
} else { } else {
err.message += `${error}...\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`; err.message += `${error}...\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`;
return reject({ stdout, stderr: err }); const errorObj = { stdout, stderr: err };
return reject(errorObj);
} }
}); });
}); });
} }
export function silentNpm(...args): Promise<ExecOutput> {
debug('run silent npm %o', args);
// @ts-ignore
return exec({ silent: true }, 'npm', args);
}

View file

@ -5,7 +5,6 @@ import { join } from 'path';
import { fileUtils } from '@verdaccio/core'; import { fileUtils } from '@verdaccio/core';
export function createProject(projectName: string) { export function createProject(projectName: string) {
// @ts-ignore
const tempRootFolder = global.__namespace.getItem('dir-suite-root'); const tempRootFolder = global.__namespace.getItem('dir-suite-root');
const verdaccioInstall = join(tempRootFolder, projectName); const verdaccioInstall = join(tempRootFolder, projectName);
fs.mkdirSync(verdaccioInstall); fs.mkdirSync(verdaccioInstall);

View file

@ -43,7 +43,6 @@ export default function (config: Config, auth: Auth, storage: Storage): Router {
app.param('org_couchdb_user', match(/^org\.couchdb\.user:/)); app.param('org_couchdb_user', match(/^org\.couchdb\.user:/));
app.use(auth.apiJWTmiddleware()); app.use(auth.apiJWTmiddleware());
app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' })); app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' }));
// @ts-ignore
app.use(antiLoop(config)); app.use(antiLoop(config));
// encode / in a scoped package name to be matched as a single parameter in routes // encode / in a scoped package name to be matched as a single parameter in routes
app.use(encodeScopePackage); app.use(encodeScopePackage);

View file

@ -196,10 +196,10 @@ export function publishPackage(storage: Storage): any {
requestOptions: { requestOptions: {
host: req.hostname, host: req.hostname,
protocol: req.protocol, protocol: req.protocol,
// @ts-ignore headers: req.headers as { [key: string]: string },
headers: req.headers,
username, username,
}, },
uplinksLook: false,
}); });
res.status(HTTP_STATUS.CREATED); res.status(HTTP_STATUS.CREATED);

View file

@ -1,5 +1,5 @@
import buildDebug from 'debug'; import buildDebug from 'debug';
import { NextFunction, Request, RequestHandler, Response } from 'express'; import { NextFunction, Request, Response } from 'express';
import _ from 'lodash'; import _ from 'lodash';
import { HTPasswd } from 'verdaccio-htpasswd'; import { HTPasswd } from 'verdaccio-htpasswd';
@ -308,12 +308,11 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
debug('allow unpublish for %o', packageName); debug('allow unpublish for %o', packageName);
for (const plugin of this.plugins) { 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); debug('allow unpublish for %o plugin does not implement allow_unpublish', packageName);
continue; continue;
} else { } else {
// @ts-ignore plugin.allow_unpublish(user, pkg, (err, ok): void => {
plugin.allow_unpublish!(user, pkg, (err, ok: boolean): void => {
if (err) { if (err) {
debug( debug(
'forbidden publish for %o, it will fallback on unpublish permissions', '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) { if (_.isNil(ok) === true) {
debug('bypass unpublish for %o, publish will handle the access', packageName); debug('bypass unpublish for %o, publish will handle the access', packageName);
// @ts-ignore return this.allow_publish({ packageName, packageVersion }, user, callback);
// eslint-disable-next-line
return this.allow_publish(...arguments);
} }
if (ok) { if (ok) {
@ -350,7 +347,7 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
const pkg = Object.assign( const pkg = Object.assign(
{ name: packageName, version: packageVersion }, { name: packageName, version: packageVersion },
getMatchedPackagesSpec(packageName, this.config.packages) getMatchedPackagesSpec(packageName, this.config.packages)
) as any; );
debug('allow publish for %o init | plugins: %o', packageName, plugins.length); debug('allow publish for %o init | plugins: %o', packageName, plugins.length);
(function next(): void { (function next(): void {
@ -378,7 +375,7 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
})(); })();
} }
public apiJWTmiddleware(): RequestHandler { public apiJWTmiddleware() {
debug('jwt middleware'); debug('jwt middleware');
const plugins = this.plugins.slice(0); const plugins = this.plugins.slice(0);
const helpers = { createAnonymousRemoteUser, createRemoteUser }; const helpers = { createAnonymousRemoteUser, createRemoteUser };
@ -388,7 +385,6 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
} }
} }
// @ts-ignore
return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction) => { return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction) => {
req.pause(); req.pause();
@ -519,8 +515,7 @@ class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
/** /**
* JWT middleware for WebUI * JWT middleware for WebUI
*/ */
public webUIJWTmiddleware(): RequestHandler { public webUIJWTmiddleware(): $NextFunctionVer {
// @ts-ignore
return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction): void => { return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction): void => {
if (this._isRemoteUserValid(req.remote_user)) { if (this._isRemoteUserValid(req.remote_user)) {
return _next(); return _next();

View file

@ -3,7 +3,7 @@ export interface PackageAccess {
publish?: string[]; publish?: string[];
proxy?: string[]; proxy?: string[];
access?: string[]; access?: string[];
unpublish: string[]; unpublish?: string[];
} }
export interface PackageList { export interface PackageList {

View file

@ -8,7 +8,7 @@ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
* @param config * @param config
* @returns * @returns
*/ */
export function antiLoop(config: Config): Function { export function antiLoop(config: Config) {
return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void { return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
if (req?.headers?.via != null) { if (req?.headers?.via != null) {
const arr = req.get('via')?.split(','); const arr = req.get('via')?.split(',');