diff --git a/package.json b/package.json index 24424f512..5e25d5dd1 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,8 @@ }, "dependencies": { "@verdaccio/file-locking": "0.0.5", - "@verdaccio/local-storage": "0.1.0", + "@verdaccio/local-storage": "0.1.2", "@verdaccio/streams": "0.0.2", - "@verdaccio/types": "0.1.0", "JSONStream": "^1.1.1", "apache-md5": "^1.1.2", "async": "^2.6.0", @@ -49,6 +48,7 @@ "unix-crypt-td-js": "^1.0.0" }, "devDependencies": { + "@verdaccio/types": "0.1.1", "axios": "0.17.1", "babel-cli": "6.26.0", "babel-core": "6.26.0", @@ -84,8 +84,8 @@ "eslint-plugin-babel": "4.1.2", "eslint-plugin-flowtype": "2.39.1", "eslint-plugin-import": "2.8.0", - "eslint-plugin-react": "7.5.1", "eslint-plugin-jest": "^21.2.0", + "eslint-plugin-react": "7.5.1", "extract-text-webpack-plugin": "3.0.2", "file-loader": "1.1.5", "flow-bin": "0.52.0", @@ -138,6 +138,7 @@ "pretest": "npm run code:build", "test": "cross-env NODE_ENV=test BABEL_ENV=test jest --maxWorkers 2", "test:unit": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/unit.*\\.spec|/test/webui/.*\\.spec)\\.js' --maxWorkers 2", + "test:func": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/functional.*\\.func)\\.js' --maxWorkers 2", "pre:ci": "npm run lint && npm run build:webui", "coverage:publish": "codecov", "lint": "npm run flow && eslint .", diff --git a/src/lib/local-storage.js b/src/lib/local-storage.js index 162c5f3e6..f5917180d 100644 --- a/src/lib/local-storage.js +++ b/src/lib/local-storage.js @@ -71,13 +71,13 @@ class LocalStorage implements IStorage { } addPackage(name: string, pkg: Package, callback: Callback) { - const storage: IPackageStorage = this._getLocalStorage(name); + const storage: any = this._getLocalStorage(name); if (_.isNil(storage)) { return callback( Utils.ErrorCode.get404('this package cannot be added')); } - storage.createPackage(pkgFileName, generatePackageTemplate(name), (err) => { + storage.createPackage(name, generatePackageTemplate(name), (err) => { if (_.isNull(err) === false && err.code === fileExist) { return callback( Utils.ErrorCode.get409()); } @@ -98,13 +98,13 @@ class LocalStorage implements IStorage { * @return {Function} */ removePackage(name: string, callback: Callback) { - let storage: IPackageStorage = this._getLocalStorage(name); + let storage: any = this._getLocalStorage(name); if (_.isNil(storage)) { return callback( Utils.ErrorCode.get404()); } - storage.readPackage(pkgFileName, (err, data) => { + storage.readPackage(name, (err, data) => { if (_.isNil(err) === false) { if (err.code === noSuchFile) { return callback( Utils.ErrorCode.get404()); @@ -121,7 +121,6 @@ class LocalStorage implements IStorage { // This will happen when database is locked return callback(Utils.ErrorCode.get422(removeFailed.message)); } - storage.deletePackage(pkgFileName, (err) => { if (err) { return callback(err); @@ -407,6 +406,7 @@ class LocalStorage implements IStorage { const uploadStream = new UploadTarball(); const _transform = uploadStream._transform; const storage = this._getLocalStorage(name); + uploadStream.abort = function() {}; uploadStream.done = function() {}; @@ -527,7 +527,7 @@ class LocalStorage implements IStorage { * @private * @return {ReadTarball} */ - _streamSuccessReadTarBall(storage: IPackageStorage, filename: string) { + _streamSuccessReadTarBall(storage: any, filename: string) { const stream = new ReadTarball(); const readTarballStream = storage.readTarball(filename); const e404 = Utils.ErrorCode.get404; @@ -572,7 +572,7 @@ class LocalStorage implements IStorage { return callback( Utils.ErrorCode.get404() ); } - this._readPackage(storage, callback); + this._readPackage(name, storage, callback); } /** @@ -645,14 +645,7 @@ class LocalStorage implements IStorage { * @return {Object} */ _getLocalStorage(packageInfo: string): IPackageStorage { - const path: string = this._getLocalStoragePath(this.config.getMatchedPackagesSpec(packageInfo).storage); - - if (_.isString(path) === false) { - this.logger.debug( {name: packageInfo}, 'this package has no storage defined: @{name}' ); - return; - } - - return this.localData.getPackageStorage(packageInfo, path); + return this.localData.getPackageStorage(packageInfo); } /** @@ -660,8 +653,8 @@ class LocalStorage implements IStorage { * @param {Object} storage * @param {Function} callback */ - _readPackage(storage: IPackageStorage, callback: Callback) { - storage.readPackage(pkgFileName, (err, result) => { + _readPackage(name: string, storage: any, callback: Callback) { + storage.readPackage(name, (err, result) => { if (err) { if (err.code === noSuchFile) { return callback( Utils.ErrorCode.get404() ); @@ -674,20 +667,6 @@ class LocalStorage implements IStorage { }); } - /** - * 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; - } - /** * Walks through each package and calls `on_package` on them. * @param {*} onPackage @@ -751,12 +730,12 @@ class LocalStorage implements IStorage { * @return {Function} */ _readCreatePackage(name: string, callback: Callback) { - const storage: IPackageStorage = this._getLocalStorage(name); + const storage: any = this._getLocalStorage(name); if (_.isNil(storage)) { return this._createNewPackage(name, callback); } - storage.readPackage(pkgFileName, (err, data) => { + storage.readPackage(name, (err, data) => { // TODO: race condition if (_.isNil(err) === false) { if (err.code === noSuchFile) { @@ -812,11 +791,11 @@ class LocalStorage implements IStorage { * @return {Function} */ _writePackage(name: string, json: Package, callback: Callback) { - const storage: IPackageStorage = this._getLocalStorage(name); + const storage: any = this._getLocalStorage(name); if (_.isNil(storage)) { return callback(); } - storage.savePackage(pkgFileName, this._setDefaultRevision(json), callback); + storage.savePackage(name, this._setDefaultRevision(json), callback); } _setDefaultRevision(json: Package) { @@ -830,7 +809,7 @@ class LocalStorage implements IStorage { return json; } - _deleteAttachments(storage: IPackageStorage, attachments: string[], callback: Callback): void { + _deleteAttachments(storage: any, attachments: string[], callback: Callback): void { const unlinkNext = function(cb) { if (_.isEmpty(attachments)) { return cb(); diff --git a/src/lib/plugin-loader.js b/src/lib/plugin-loader.js index 5557f6610..10bf8a885 100644 --- a/src/lib/plugin-loader.js +++ b/src/lib/plugin-loader.js @@ -27,6 +27,10 @@ function isES6(plugin) { return Object.keys(plugin).includes('default'); } +function mergeConfig(appConfig, pluginConfig) { + return _.merge(appConfig, pluginConfig); +} + /** * Load a plugin following the rules * - First try to load from the internal directory plugins (which will disappear soon or later). @@ -74,7 +78,7 @@ function loadPlugin(config, plugin_configs, params, sanity_check) { } /* eslint new-cap:off */ - plugin = isES6(plugin) ? new plugin.default(plugin_configs[p], params) : plugin(plugin_configs[p], params); + plugin = isES6(plugin) ? new plugin.default(mergeConfig(config, plugin_configs[p]), params) : plugin(plugin_configs[p], params); /* eslint new-cap:off */ if (plugin === null || !sanity_check(plugin)) { diff --git a/yarn.lock b/yarn.lock index 81d07f77e..0a1eb63f4 100644 Binary files a/yarn.lock and b/yarn.lock differ