0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-27 22:59:51 -05:00

fix: search implementation depends now of each plugin

It had still file system remaining logic on search, this will force plugin to implement search. Whether plugin do not has such implementation a warning  is displayed in the console and search will return remote search results for each endpoint anyway.
This commit is contained in:
Juan Picado @jotadeveloper 2018-06-09 09:23:13 +02:00
parent 60593af129
commit 8f0508fc2e
No known key found for this signature in database
GPG key ID: 18AC54485952D158
3 changed files with 37 additions and 77 deletions

View file

@ -16,7 +16,7 @@
},
"dependencies": {
"@verdaccio/file-locking": "0.0.7",
"@verdaccio/local-storage": "1.0.3",
"@verdaccio/local-storage": "1.1.2",
"@verdaccio/streams": "1.0.0",
"JSONStream": "1.3.2",
"async": "2.6.0",
@ -52,7 +52,7 @@
"@commitlint/cli": "6.1.3",
"@commitlint/config-conventional": "6.1.3",
"@commitlint/travis-cli": "6.1.3",
"@verdaccio/types": "2.1.1",
"@verdaccio/types": "3.0.0",
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "8.2.2",

View file

@ -3,12 +3,9 @@
/* eslint prefer-rest-params: 0 */
import assert from 'assert';
import fs from 'fs';
import Path from 'path';
import UrlNode from 'url';
import _ from 'lodash';
// $FlowFixMe
import async from 'async';
import {ErrorCode, isObject, getLatestVersion, tagVersion, validateName, DIST_TAGS} from './utils';
import {
generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme,
@ -575,29 +572,21 @@ class LocalStorage implements IStorage {
const stream = new UploadTarball({objectMode: true});
this._searchEachPackage((item, cb) => {
fs.stat(item.path, (err, stats) => {
if (_.isNil(err) === false) {
return cb(err);
}
if (stats.mtime.getTime() > parseInt(startKey, 10)) {
this.getPackageMetadata(item.name, (err: Error, data: Package) => {
if (err) {
return cb(err);
}
const time = item.time ? new Date(item.time).toISOString() : stats.mtime;
const result = prepareSearchPackage(data, time);
if (_.isNil(result) === false) {
stream.push(result);
}
cb();
});
} else {
if (item.time > parseInt(startKey, 10)) {
this.getPackageMetadata(item.name, (err: Error, data: Package) => {
if (err) {
return cb(err);
}
const time = new Date(item.time).toISOString();
const result = prepareSearchPackage(data, time);
if (_.isNil(result) === false) {
stream.push(result);
}
cb();
}
});
});
} else {
cb();
}
}, function onEnd(err) {
if (err) {
return stream.emit('error', err);
@ -665,48 +654,13 @@ class LocalStorage implements IStorage {
* @param {*} onEnd
*/
_searchEachPackage(onPackage: Callback, onEnd: Callback) {
const storages = this._getCustomPackageLocalStorages();
const base = Path.dirname(this.config.self_path);
async.eachSeries(Object.keys(storages), function(storage, cb) {
fs.readdir(Path.resolve(base, storage), function(err, files) {
if (err) {
return cb(err);
}
async.eachSeries(files, function(file, cb) {
if (file.match(/^@/)) {
// scoped
fs.readdir(Path.resolve(base, storage, file), function(err, files) {
if (err) {
return cb(err);
}
async.eachSeries(files, (file2, cb) => {
if (validateName(file2)) {
const item = {
name: `${file}/${file2}`,
path: Path.resolve(base, storage, file, file2),
};
onPackage(item, cb);
} else {
cb();
}
}, cb);
});
} else if (validateName(file)) {
onPackage({
name: file,
path: Path.resolve(base, storage, file),
}, cb);
} else {
cb();
}
}, cb);
});
}, onEnd);
// save wait whether plugin still do not support search functionality
if (_.isNil(this.localData.search)) {
this.logger.warn('plugin search not implemented yet');
onEnd();
} else {
this.localData.search(onPackage, onEnd, validateName);
}
}
/**

View file

@ -242,13 +242,13 @@
lockfile "1.0.3"
lodash "4.17.10"
"@verdaccio/local-storage@1.0.3":
version "1.0.3"
resolved "https://registry.npmjs.org/@verdaccio/local-storage/-/local-storage-1.0.3.tgz#f7916afbde27e725339b1fa1e11566c3734b5194"
"@verdaccio/local-storage@1.1.2":
version "1.1.2"
resolved "https://registry.npmjs.org/@verdaccio/local-storage/-/local-storage-1.1.2.tgz#938f1da741d148db020bbe68bfb21e86d38e3177"
dependencies:
"@verdaccio/file-locking" "0.0.7"
"@verdaccio/streams" "1.0.0"
async "2.6.0"
async "2.6.1"
http-errors "1.6.2"
lodash "4.17.10"
mkdirp "0.5.1"
@ -257,9 +257,9 @@
version "1.0.0"
resolved "https://registry.npmjs.org/@verdaccio/streams/-/streams-1.0.0.tgz#d5d24c6747208728b9fd16b908e3932c3fb1f864"
"@verdaccio/types@2.1.1":
version "2.1.1"
resolved "https://registry.npmjs.org/@verdaccio/types/-/types-2.1.1.tgz#d0ff73154a9e389b828df3d5046e26fbb67f3233"
"@verdaccio/types@3.0.0":
version "3.0.0"
resolved "https://registry.npmjs.org/@verdaccio/types/-/types-3.0.0.tgz#1f5ad5c959955b320181ac9968dd894f209985bc"
"@webassemblyjs/ast@1.5.9":
version "1.5.9"
@ -689,6 +689,12 @@ async@2.6.0, async@^2.1.4, async@^2.5.0:
dependencies:
lodash "^4.14.0"
async@2.6.1:
version "2.6.1"
resolved "https://registry.npmjs.org/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610"
dependencies:
lodash "^4.17.10"
async@^1.4.0, async@^1.5.2:
version "1.5.2"
resolved "https://registry.npmjs.org/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
@ -5820,7 +5826,7 @@ lodash.upperfirst@4.3.1:
version "4.3.1"
resolved "https://registry.npmjs.org/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce"
lodash@4.17.10, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@~4.17.4:
lodash@4.17.10, lodash@^4.0.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@~4.17.4:
version "4.17.10"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"