0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-17 23:45:29 -05:00

chore: update flow to 0.75.0

This commit is contained in:
Juan Picado @jotadeveloper 2018-07-14 12:16:27 +02:00
parent eecc98f671
commit 7ce6abf3b2
No known key found for this signature in database
GPG key ID: 18AC54485952D158
11 changed files with 106 additions and 31 deletions

View file

@ -1,5 +1,5 @@
// flow-typed signature: 41a220e96fcef89a09244ac3797039e8
// flow-typed version: 9f7cf2ab0c/express_v4.16.x/flow_>=v0.32.x
// flow-typed signature: cc24a4e737d9dfb8e1381c3bd4ebaa65
// flow-typed version: d11eab7bb5/express_v4.16.x/flow_>=v0.32.x
import type { Server } from "http";
import type { Socket } from "net";
@ -195,13 +195,11 @@ declare class express$Router extends express$Route {
id: string
) => mixed
): void;
// Can't use regular callable signature syntax due to https://github.com/facebook/flow/issues/3084
$call: (
(
req: http$IncomingMessage,
res: http$ServerResponse,
next?: ?express$NextFunction
) => void;
): void;
}
/*
@ -250,6 +248,12 @@ declare class express$Application extends express$Router mixins events$EventEmit
res: http$ServerResponse,
next?: ?express$NextFunction
): void;
// callable signature is not inherited
(
req: http$IncomingMessage,
res: http$ServerResponse,
next?: ?express$NextFunction
): void;
}
declare type JsonOptions = {
@ -266,6 +270,20 @@ declare type JsonOptions = {
) => mixed
};
declare type express$UrlEncodedOptions = {
extended?: boolean,
inflate?: boolean,
limit?: string | number,
parameterLimit?: number,
type?: string | Array<string> | ((req: express$Request) => boolean),
verify?: (
req: express$Request,
res: express$Response,
buf: Buffer,
encoding: string
) => mixed,
}
declare module "express" {
declare export type RouterOptions = express$RouterOptions;
declare export type CookieOptions = express$CookieOptions;
@ -280,6 +298,7 @@ declare module "express" {
(): express$Application, // If you try to call like a function, it will use this signature
json: (opts: ?JsonOptions) => express$Middleware,
static: (root: string, options?: Object) => express$Middleware, // `static` property on the function
Router: typeof express$Router // `Router` property on the function
Router: typeof express$Router, // `Router` property on the function
urlencoded: (opts: ?express$UrlEncodedOptions) => express$Middleware,
};
}

View file

@ -52,7 +52,7 @@
"devDependencies": {
"@commitlint/cli": "6.1.3",
"@commitlint/config-conventional": "6.1.3",
"@verdaccio/types": "3.0.1",
"@verdaccio/types": "3.1.0",
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "8.2.2",
@ -91,7 +91,7 @@
"eslint-plugin-jest": "21.17.0",
"eslint-plugin-react": "7.10.0",
"file-loader": "1.1.11",
"flow-bin": "0.69.0",
"flow-bin": "0.75.0",
"flow-runtime": "0.17.0",
"friendly-errors-webpack-plugin": "1.7.0",
"github-markdown-css": "2.10.0",

View file

@ -396,8 +396,8 @@ class LocalStorage implements IStorage {
const _transform = uploadStream._transform;
const storage = this._getLocalStorage(name);
uploadStream.abort = function() {};
uploadStream.done = function() {};
(uploadStream: any).abort = function() {};
(uploadStream: any).done = function() {};
uploadStream._transform = function(data) {
shaOneHash.update(data);
@ -459,11 +459,11 @@ class LocalStorage implements IStorage {
});
});
uploadStream.abort = function() {
(uploadStream: any).abort = function() {
writeStream.abort();
};
uploadStream.done = function() {
(uploadStream: any).done = function() {
if (!length) {
uploadStream.emit('error', ErrorCode.getBadData('refusing to accept zero-length file'));
writeStream.abort();
@ -521,7 +521,7 @@ class LocalStorage implements IStorage {
const readTarballStream = storage.readTarball(filename);
const e404 = ErrorCode.getNotFound;
stream.abort = function() {
(stream: any).abort = function() {
if (_.isNil(readTarballStream) === false) {
readTarballStream.abort();
}
@ -800,7 +800,7 @@ class LocalStorage implements IStorage {
return this.localData.setSecret(config.checkSecretKey(secretKey));
}
_loadStorage(config: Config, logger: Logger) {
_loadStorage(config: Config, logger: Logger): ILocalData {
const Storage = this._loadStorePlugin();
if (_.isNil(Storage)) {
@ -811,13 +811,13 @@ class LocalStorage implements IStorage {
}
}
_loadStorePlugin() {
_loadStorePlugin(): ILocalData {
const plugin_params = {
config: this.config,
logger: this.logger,
};
return _.head(loadPlugin(this.config, this.config.store, plugin_params, function(plugin) {
return _.head(loadPlugin(this.config, this.config.store, plugin_params, (plugin) => {
return plugin.getPackageStorage;
}));
}

View file

@ -44,8 +44,12 @@ function isES6(plugin) {
* @param {*} sanityCheck callback that check the shape that should fulfill the plugin
* @return {Array} list of plugins
*/
function loadPlugin(config: Config, pluginConfigs: any, params: any, sanityCheck: Function) {
return Object.keys(pluginConfigs || {}).map(function(pluginId) {
function loadPlugin<T>(
config: Config,
pluginConfigs: any = {},
params: any,
sanityCheck: Function): T[] {
return Object.keys(pluginConfigs).map((pluginId: string) => {
let plugin;
// try local plugins first
@ -79,7 +83,9 @@ function loadPlugin(config: Config, pluginConfigs: any, params: any, sanityCheck
throw Error('"' + pluginId + '" doesn\'t look like a valid plugin');
}
/* eslint new-cap:off */
plugin = isES6(plugin) ? new plugin.default(mergeConfig(config, pluginConfigs[pluginId]), params) : plugin(pluginConfigs[pluginId], params);
plugin = isES6(plugin)
? new plugin.default(mergeConfig(config, pluginConfigs[pluginId]), params)
: plugin(pluginConfigs[pluginId], params);
/* eslint new-cap:off */
if (plugin === null || !sanityCheck(plugin)) {

View file

@ -136,7 +136,7 @@ class Storage implements IStorageHandler {
*/
getTarball(name: string, filename: string) {
let readStream = new ReadTarball();
readStream.abort = function() {};
(readStream: any).abort = function() {};
let self = this;

View file

@ -430,7 +430,7 @@ class ProxyStorage implements IProxy {
let current_length = 0;
let expected_length;
stream.abort = () => {};
(stream: any).abort = () => {};
const readStream = this.request({
uri_full: url,
encoding: null,

View file

@ -253,7 +253,7 @@ function parse_address(urlAddress: any) {
* Function filters out bad semver versions and sorts the array.
* @return {Array} sorted Array
*/
function semverSort(listVersions: Array<string>) {
function semverSort(listVersions: Array<string>): string[] {
return listVersions.filter(function(x) {
if (!semver.parse(x, true)) {
Logger.logger.warn( {ver: x}, 'ignoring bad version @{ver}' );
@ -409,7 +409,7 @@ function fileExists(path: string) {
}
}
function sortByName(packages: Array<any>) {
function sortByName(packages: Array<any>): string[] {
return packages.sort(function(a, b) {
if (a.name < b.name) {
return -1;

View file

@ -0,0 +1,50 @@
// @flow
import Config from '../../../../src/lib/config';
import LoggerApi from '../../../../src/lib/logger';
import type {
AuthPlugin,
Config as AppConfig,
IAuthPlugin,
Logger,
PluginOptions
} from '@verdaccio/types';
// this class is not aim to be tested, just to check flow definitions
class ExampleAuthPlugin implements IAuthPlugin {
config: AppConfig;
logger: Logger;
constructor(config: AppConfig, options: PluginOptions) {
this.config = config;
this.logger = options.logger;
}
authenticate(user: string, password: string, cb: verdaccio$Callback): void {
cb();
}
allow_access(packageName: string, user: string, cb: verdaccio$Callback): void {
cb();
}
allow_publish(packageName: string, user: string, cb: verdaccio$Callback): void {
cb();
}
}
const config1: AppConfig = new Config({
storage: './storage',
self_path: '/home/sotrage'
});
const options: PluginOptions = {
config: config1,
logger: LoggerApi.logger.child()
}
// $FlowFixMe
const instance1: AuthPlugin = new ExampleAuthPlugin(config1, options);
console.log(instance1);

View file

@ -1,7 +1,7 @@
module.exports = function ( ) {
return {
authenticate ( user, pass, callback ) {
authenticate( user, pass, callback ) {
/* user and pass are used here to forward errors
and success types respectively for testing purposes */
callback(user, pass);

View file

@ -234,9 +234,9 @@
version "1.0.0"
resolved "https://registry.npmjs.org/@verdaccio/streams/-/streams-1.0.0.tgz#d5d24c6747208728b9fd16b908e3932c3fb1f864"
"@verdaccio/types@3.0.1":
version "3.0.1"
resolved "https://registry.npmjs.org/@verdaccio/types/-/types-3.0.1.tgz#8cdfd74a8a070ad797a056652f257f9ead3717f9"
"@verdaccio/types@3.1.0":
version "3.1.0"
resolved "https://registry.npmjs.org/@verdaccio/types/-/types-3.1.0.tgz#b4b376c80e787aa9ab59794fbbabf81fedb9cdba"
"@webassemblyjs/ast@1.5.9":
version "1.5.9"
@ -3833,9 +3833,9 @@ flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
flow-bin@0.69.0:
version "0.69.0"
resolved "https://registry.npmjs.org/flow-bin/-/flow-bin-0.69.0.tgz#053159a684a6051fcbf0b71a2eb19a9679082da6"
flow-bin@0.75.0:
version "0.75.0"
resolved "https://registry.npmjs.org/flow-bin/-/flow-bin-0.75.0.tgz#b96d1ee99d3b446a3226be66b4013224ce9df260"
flow-config-parser@^0.3.0:
version "0.3.0"