From 7ce6abf3b27c32c98b6c2fbb460bd487d3d2f9e8 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 14 Jul 2018 12:16:27 +0200 Subject: [PATCH] chore: update flow to 0.75.0 --- flow-typed/npm/express_v4.16.x.js | 33 ++++++++++--- package.json | 4 +- src/lib/local-storage.js | 16 +++---- src/lib/plugin-loader.js | 12 +++-- src/lib/storage.js | 2 +- src/lib/up-storage.js | 2 +- src/lib/utils.js | 4 +- test/flow/plugins/auth/complete.js | 50 ++++++++++++++++++++ test/flow/plugins/partials/config.example.js | 0 test/unit/partials/plugin/authenticate.js | 2 +- yarn.lock | 12 ++--- 11 files changed, 106 insertions(+), 31 deletions(-) create mode 100644 test/flow/plugins/auth/complete.js create mode 100644 test/flow/plugins/partials/config.example.js diff --git a/flow-typed/npm/express_v4.16.x.js b/flow-typed/npm/express_v4.16.x.js index 15a5dfe60..52fc3ba34 100644 --- a/flow-typed/npm/express_v4.16.x.js +++ b/flow-typed/npm/express_v4.16.x.js @@ -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 | ((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, }; } diff --git a/package.json b/package.json index d24ad47ac..410c6585d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/local-storage.js b/src/lib/local-storage.js index a844d8464..327d75fd9 100644 --- a/src/lib/local-storage.js +++ b/src/lib/local-storage.js @@ -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; })); } diff --git a/src/lib/plugin-loader.js b/src/lib/plugin-loader.js index 6db23b78f..f2cfec2ec 100644 --- a/src/lib/plugin-loader.js +++ b/src/lib/plugin-loader.js @@ -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( + 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)) { diff --git a/src/lib/storage.js b/src/lib/storage.js index e66173941..fdbe3b6ac 100644 --- a/src/lib/storage.js +++ b/src/lib/storage.js @@ -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; diff --git a/src/lib/up-storage.js b/src/lib/up-storage.js index a789deb54..7ec176292 100644 --- a/src/lib/up-storage.js +++ b/src/lib/up-storage.js @@ -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, diff --git a/src/lib/utils.js b/src/lib/utils.js index 2b70b0837..ec0303d99 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -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) { +function semverSort(listVersions: Array): 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) { +function sortByName(packages: Array): string[] { return packages.sort(function(a, b) { if (a.name < b.name) { return -1; diff --git a/test/flow/plugins/auth/complete.js b/test/flow/plugins/auth/complete.js new file mode 100644 index 000000000..4da7c7c6c --- /dev/null +++ b/test/flow/plugins/auth/complete.js @@ -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); \ No newline at end of file diff --git a/test/flow/plugins/partials/config.example.js b/test/flow/plugins/partials/config.example.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/unit/partials/plugin/authenticate.js b/test/unit/partials/plugin/authenticate.js index 545980ed2..24fa44b99 100644 --- a/test/unit/partials/plugin/authenticate.js +++ b/test/unit/partials/plugin/authenticate.js @@ -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); diff --git a/yarn.lock b/yarn.lock index adfe7ae1b..af308aa3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"