mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-21 07:29:37 +01: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:
parent
60593af129
commit
8f0508fc2e
@ -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",
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in New Issue
Block a user