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:
parent
33cf14740d
commit
4c58a46b43
8 changed files with 20 additions and 31 deletions
|
@ -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
|
||||
|
|
|
@ -31,12 +31,13 @@ export async function exec(options: SpawnOptions, cmd, args): Promise<ExecOutput
|
|||
}
|
||||
|
||||
const childProcess = spawn(cmd, args, spawnOptions);
|
||||
// @ts-ignore
|
||||
if (childProcess.stdout) {
|
||||
const rl = createInterface({ input: childProcess.stdout });
|
||||
|
||||
rl.on('line', function (line) {
|
||||
stdout += line;
|
||||
});
|
||||
}
|
||||
|
||||
const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -45,14 +46,9 @@ export async function exec(options: SpawnOptions, cmd, args): Promise<ExecOutput
|
|||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -3,7 +3,7 @@ export interface PackageAccess {
|
|||
publish?: string[];
|
||||
proxy?: string[];
|
||||
access?: string[];
|
||||
unpublish: string[];
|
||||
unpublish?: string[];
|
||||
}
|
||||
|
||||
export interface PackageList {
|
||||
|
|
|
@ -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(',');
|
||||
|
|
Loading…
Reference in a new issue