From 3b120830c5cb3d6cc091b24121e4da9cc75ad852 Mon Sep 17 00:00:00 2001 From: "@jotadeveloper" <@jotadeveloper> Date: Thu, 28 Dec 2017 14:56:56 +0100 Subject: [PATCH] fix: move to local storage the fs location handler --- plugins/local-storage/package.json | 2 +- plugins/local-storage/src/local-database.js | 25 +++++++++++++++++++-- plugins/local-storage/yarn.lock | 6 ++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/plugins/local-storage/package.json b/plugins/local-storage/package.json index f52a7e8f..9dc470fa 100644 --- a/plugins/local-storage/package.json +++ b/plugins/local-storage/package.json @@ -20,7 +20,7 @@ "mkdirp": "0.5.1" }, "devDependencies": { - "@verdaccio/types": "0.1.0", + "@verdaccio/types": "^0.1.1", "babel-cli": "6.24.1", "babel-core": "6.25.0", "babel-eslint": "7.2.3", diff --git a/plugins/local-storage/src/local-database.js b/plugins/local-storage/src/local-database.js index d84526b5..115da993 100644 --- a/plugins/local-storage/src/local-database.js +++ b/plugins/local-storage/src/local-database.js @@ -6,7 +6,7 @@ import Path from 'path'; import LocalFS from './local-fs'; import mkdirp from 'mkdirp'; import type {StorageList, LocalStorage, Logger, Config} from '@verdaccio/types'; -import type {ILocalPackageManager, ILocalData} from '@verdaccio/local-storage'; +import type {IPackageStorage, ILocalData} from '@verdaccio/local-storage'; /** * Handle local database. @@ -91,7 +91,14 @@ import type {ILocalPackageManager, ILocalData} from '@verdaccio/local-storage'; } } - getPackageStorage(packageInfo: string, packagePath: string): ILocalPackageManager { + getPackageStorage(packageInfo: string): IPackageStorage { + const packagePath: string = this._getLocalStoragePath(this.config.getMatchedPackagesSpec(packageInfo).storage); + + if (_.isString(packagePath) === false) { + this.logger.debug( {name: packageInfo}, 'this package has no storage defined: @{name}' ); + return; + } + const packageStoragePath: string = Path.join( Path.resolve(Path.dirname(this.config.self_path || ''), packagePath), packageInfo); @@ -99,6 +106,20 @@ import type {ILocalPackageManager, ILocalData} from '@verdaccio/local-storage'; return new LocalFS(packageStoragePath, this.logger); } + /** + * Verify the right local storage location. + * @param {String} path + * @return {String} + * @private + */ + _getLocalStoragePath(path: string): string { + if (_.isNil(path) === false) { + return path; + } + + return this.config.storage; + } + /** * Build the local database path. * @param {Object} config diff --git a/plugins/local-storage/yarn.lock b/plugins/local-storage/yarn.lock index b6110bb9..b3f087c4 100644 --- a/plugins/local-storage/yarn.lock +++ b/plugins/local-storage/yarn.lock @@ -13,9 +13,9 @@ version "0.0.2" resolved "https://registry.npmjs.org/@verdaccio/streams/-/streams-0.0.2.tgz#72cd65449e657b462a1ca094f663cad9ea872427" -"@verdaccio/types@0.1.0": - version "0.1.0" - resolved "https://registry.npmjs.org/@verdaccio/types/-/types-0.1.0.tgz#2a0a6066bbbb7841d29298463e761147fb1f7f00" +"@verdaccio/types@^0.1.1": + version "0.1.1" + resolved "https://registry.npmjs.org/@verdaccio/types/-/types-0.1.1.tgz#0801494fbd0284f6e92d94c85b90d97ba9dfa1c8" abab@^1.0.3: version "1.0.4"