From 1602840ed1d5b79bb36102385da9f7ef91ce2370 Mon Sep 17 00:00:00 2001 From: Priscila Date: Fri, 17 Aug 2018 12:14:23 +0200 Subject: [PATCH] feat: replaced lunr by lunr-mutable (#915) --- flow-typed/npm/lunr-mutable-indexes_vx.x.x.js | 74 +++ flow-typed/npm/lunr_vx.x.x.js | 431 ------------------ package.json | 2 +- src/lib/search.js | 20 +- src/webui/components/Package/index.js | 10 +- src/webui/components/Package/package.scss | 11 + src/webui/components/PackageList/index.js | 4 +- .../__snapshots__/package.spec.js.snap | 4 +- .../__snapshots__/packagelist.spec.js.snap | 2 +- types/index.js | 3 +- yarn.lock | Bin 386307 -> 386546 bytes 11 files changed, 114 insertions(+), 447 deletions(-) create mode 100644 flow-typed/npm/lunr-mutable-indexes_vx.x.x.js delete mode 100644 flow-typed/npm/lunr_vx.x.x.js diff --git a/flow-typed/npm/lunr-mutable-indexes_vx.x.x.js b/flow-typed/npm/lunr-mutable-indexes_vx.x.x.js new file mode 100644 index 000000000..1b98a703a --- /dev/null +++ b/flow-typed/npm/lunr-mutable-indexes_vx.x.x.js @@ -0,0 +1,74 @@ +// flow-typed signature: f588bf5982dc1140e97108be62b860db +// flow-typed version: <>/lunr-mutable-indexes_v2.3.1/flow_v0.77.0 + +/** + * This is an autogenerated libdef stub for: + * + * 'lunr-mutable-indexes' + * + * Fill this stub out by replacing all the `any` types. + * + * Once filled out, we encourage you to share your work with the + * community by sending a pull request to: + * https://github.com/flowtype/flow-typed + */ + +declare module 'lunr-mutable-indexes' { + declare module.exports: any; +} + +/** + * We include stubs for each file inside this npm package in case you need to + * require those files directly. Feel free to delete any files that aren't + * needed. + */ +declare module 'lunr-mutable-indexes/lib/lunr_mutable' { + declare module.exports: any; +} + +declare module 'lunr-mutable-indexes/lib/mutable_builder' { + declare module.exports: any; +} + +declare module 'lunr-mutable-indexes/lib/mutable_index' { + declare module.exports: any; +} + +declare module 'lunr-mutable-indexes/lunr-mutable' { + declare module.exports: any; +} + +declare module 'lunr-mutable-indexes/test/mutable_serialization_test' { + declare module.exports: any; +} + +declare module 'lunr-mutable-indexes/test/mutable_sugar_test' { + declare module.exports: any; +} + +declare module 'lunr-mutable-indexes/test/mutable_test' { + declare module.exports: any; +} + +// Filename aliases +declare module 'lunr-mutable-indexes/lib/lunr_mutable.js' { + declare module.exports: $Exports<'lunr-mutable-indexes/lib/lunr_mutable'>; +} +declare module 'lunr-mutable-indexes/lib/mutable_builder.js' { + declare module.exports: $Exports<'lunr-mutable-indexes/lib/mutable_builder'>; +} +declare module 'lunr-mutable-indexes/lib/mutable_index.js' { + declare module.exports: $Exports<'lunr-mutable-indexes/lib/mutable_index'>; +} +declare module 'lunr-mutable-indexes/lunr-mutable.js' { + declare module.exports: $Exports<'lunr-mutable-indexes/lunr-mutable'>; +} +declare module 'lunr-mutable-indexes/test/mutable_serialization_test.js' { + declare module.exports: $Exports<'lunr-mutable-indexes/test/mutable_serialization_test'>; +} +declare module 'lunr-mutable-indexes/test/mutable_sugar_test.js' { + declare module.exports: $Exports<'lunr-mutable-indexes/test/mutable_sugar_test'>; +} +declare module 'lunr-mutable-indexes/test/mutable_test.js' { + declare module.exports: $Exports<'lunr-mutable-indexes/test/mutable_test'>; +} diff --git a/flow-typed/npm/lunr_vx.x.x.js b/flow-typed/npm/lunr_vx.x.x.js deleted file mode 100644 index 5bab109ed..000000000 --- a/flow-typed/npm/lunr_vx.x.x.js +++ /dev/null @@ -1,431 +0,0 @@ -// flow-typed signature: e0027883db9b96a34c42414495ddfa2b -// flow-typed version: <>/lunr_v0.7.2/flow_v0.64.0 - -/** - * This is an autogenerated libdef stub for: - * - * 'lunr' - * - * Fill this stub out by replacing all the `any` types. - * - * Once filled out, we encourage you to share your work with the - * community by sending a pull request to: - * https://github.com/flowtype/flow-typed - */ - -declare module 'lunr' { - declare module.exports: any; -} - -/** - * We include stubs for each file inside this npm package in case you need to - * require those files directly. Feel free to delete any files that aren't - * needed. - */ -declare module 'lunr/app' { - declare module.exports: any; -} - -declare module 'lunr/example/app' { - declare module.exports: any; -} - -declare module 'lunr/example/index_builder' { - declare module.exports: any; -} - -declare module 'lunr/example/jquery' { - declare module.exports: any; -} - -declare module 'lunr/example/mustache' { - declare module.exports: any; -} - -declare module 'lunr/example/require' { - declare module.exports: any; -} - -declare module 'lunr/example/text' { - declare module.exports: any; -} - -declare module 'lunr/lib/document_store' { - declare module.exports: any; -} - -declare module 'lunr/lib/event_emitter' { - declare module.exports: any; -} - -declare module 'lunr/lib/index' { - declare module.exports: any; -} - -declare module 'lunr/lib/lunr' { - declare module.exports: any; -} - -declare module 'lunr/lib/pipeline' { - declare module.exports: any; -} - -declare module 'lunr/lib/sorted_set' { - declare module.exports: any; -} - -declare module 'lunr/lib/stemmer' { - declare module.exports: any; -} - -declare module 'lunr/lib/stop_word_filter' { - declare module.exports: any; -} - -declare module 'lunr/lib/token_store' { - declare module.exports: any; -} - -declare module 'lunr/lib/tokenizer' { - declare module.exports: any; -} - -declare module 'lunr/lib/trimmer' { - declare module.exports: any; -} - -declare module 'lunr/lib/utils' { - declare module.exports: any; -} - -declare module 'lunr/lib/vector' { - declare module.exports: any; -} - -declare module 'lunr/lunr' { - declare module.exports: any; -} - -declare module 'lunr/lunr.min' { - declare module.exports: any; -} - -declare module 'lunr/perf/document_store_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/env/bench' { - declare module.exports: any; -} - -declare module 'lunr/perf/env/benchmark' { - declare module.exports: any; -} - -declare module 'lunr/perf/env/jquery' { - declare module.exports: any; -} - -declare module 'lunr/perf/env/mustache' { - declare module.exports: any; -} - -declare module 'lunr/perf/fixtures/questions' { - declare module.exports: any; -} - -declare module 'lunr/perf/foo_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/index_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/pipeline_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/set_index_of_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/sorted_set_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/stemmer_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/token_store_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/tokenizer_test' { - declare module.exports: any; -} - -declare module 'lunr/perf/vector_test' { - declare module.exports: any; -} - -declare module 'lunr/server' { - declare module.exports: any; -} - -declare module 'lunr/test/env/augment.min' { - declare module.exports: any; -} - -declare module 'lunr/test/env/jquery' { - declare module.exports: any; -} - -declare module 'lunr/test/env/qunit' { - declare module.exports: any; -} - -declare module 'lunr/test/env/runner' { - declare module.exports: any; -} - -declare module 'lunr/test/event_emitter_test' { - declare module.exports: any; -} - -declare module 'lunr/test/index_test' { - declare module.exports: any; -} - -declare module 'lunr/test/lunr_test' { - declare module.exports: any; -} - -declare module 'lunr/test/pipeline_test' { - declare module.exports: any; -} - -declare module 'lunr/test/search_test' { - declare module.exports: any; -} - -declare module 'lunr/test/serialisation_test' { - declare module.exports: any; -} - -declare module 'lunr/test/sorted_set_test' { - declare module.exports: any; -} - -declare module 'lunr/test/stemmer_test' { - declare module.exports: any; -} - -declare module 'lunr/test/stop_word_filter_test' { - declare module.exports: any; -} - -declare module 'lunr/test/store_node_test' { - declare module.exports: any; -} - -declare module 'lunr/test/store_test' { - declare module.exports: any; -} - -declare module 'lunr/test/test_helper' { - declare module.exports: any; -} - -declare module 'lunr/test/token_store_test' { - declare module.exports: any; -} - -declare module 'lunr/test/tokenizer_test' { - declare module.exports: any; -} - -declare module 'lunr/test/trimmer_test' { - declare module.exports: any; -} - -declare module 'lunr/test/vector_test' { - declare module.exports: any; -} - -// Filename aliases -declare module 'lunr/app.js' { - declare module.exports: $Exports<'lunr/app'>; -} -declare module 'lunr/example/app.js' { - declare module.exports: $Exports<'lunr/example/app'>; -} -declare module 'lunr/example/index_builder.js' { - declare module.exports: $Exports<'lunr/example/index_builder'>; -} -declare module 'lunr/example/jquery.js' { - declare module.exports: $Exports<'lunr/example/jquery'>; -} -declare module 'lunr/example/mustache.js' { - declare module.exports: $Exports<'lunr/example/mustache'>; -} -declare module 'lunr/example/require.js' { - declare module.exports: $Exports<'lunr/example/require'>; -} -declare module 'lunr/example/text.js' { - declare module.exports: $Exports<'lunr/example/text'>; -} -declare module 'lunr/lib/document_store.js' { - declare module.exports: $Exports<'lunr/lib/document_store'>; -} -declare module 'lunr/lib/event_emitter.js' { - declare module.exports: $Exports<'lunr/lib/event_emitter'>; -} -declare module 'lunr/lib/index.js' { - declare module.exports: $Exports<'lunr/lib/index'>; -} -declare module 'lunr/lib/lunr.js' { - declare module.exports: $Exports<'lunr/lib/lunr'>; -} -declare module 'lunr/lib/pipeline.js' { - declare module.exports: $Exports<'lunr/lib/pipeline'>; -} -declare module 'lunr/lib/sorted_set.js' { - declare module.exports: $Exports<'lunr/lib/sorted_set'>; -} -declare module 'lunr/lib/stemmer.js' { - declare module.exports: $Exports<'lunr/lib/stemmer'>; -} -declare module 'lunr/lib/stop_word_filter.js' { - declare module.exports: $Exports<'lunr/lib/stop_word_filter'>; -} -declare module 'lunr/lib/token_store.js' { - declare module.exports: $Exports<'lunr/lib/token_store'>; -} -declare module 'lunr/lib/tokenizer.js' { - declare module.exports: $Exports<'lunr/lib/tokenizer'>; -} -declare module 'lunr/lib/trimmer.js' { - declare module.exports: $Exports<'lunr/lib/trimmer'>; -} -declare module 'lunr/lib/utils.js' { - declare module.exports: $Exports<'lunr/lib/utils'>; -} -declare module 'lunr/lib/vector.js' { - declare module.exports: $Exports<'lunr/lib/vector'>; -} -declare module 'lunr/lunr.js' { - declare module.exports: $Exports<'lunr/lunr'>; -} -declare module 'lunr/lunr.min.js' { - declare module.exports: $Exports<'lunr/lunr.min'>; -} -declare module 'lunr/perf/document_store_test.js' { - declare module.exports: $Exports<'lunr/perf/document_store_test'>; -} -declare module 'lunr/perf/env/bench.js' { - declare module.exports: $Exports<'lunr/perf/env/bench'>; -} -declare module 'lunr/perf/env/benchmark.js' { - declare module.exports: $Exports<'lunr/perf/env/benchmark'>; -} -declare module 'lunr/perf/env/jquery.js' { - declare module.exports: $Exports<'lunr/perf/env/jquery'>; -} -declare module 'lunr/perf/env/mustache.js' { - declare module.exports: $Exports<'lunr/perf/env/mustache'>; -} -declare module 'lunr/perf/fixtures/questions.js' { - declare module.exports: $Exports<'lunr/perf/fixtures/questions'>; -} -declare module 'lunr/perf/foo_test.js' { - declare module.exports: $Exports<'lunr/perf/foo_test'>; -} -declare module 'lunr/perf/index_test.js' { - declare module.exports: $Exports<'lunr/perf/index_test'>; -} -declare module 'lunr/perf/pipeline_test.js' { - declare module.exports: $Exports<'lunr/perf/pipeline_test'>; -} -declare module 'lunr/perf/set_index_of_test.js' { - declare module.exports: $Exports<'lunr/perf/set_index_of_test'>; -} -declare module 'lunr/perf/sorted_set_test.js' { - declare module.exports: $Exports<'lunr/perf/sorted_set_test'>; -} -declare module 'lunr/perf/stemmer_test.js' { - declare module.exports: $Exports<'lunr/perf/stemmer_test'>; -} -declare module 'lunr/perf/token_store_test.js' { - declare module.exports: $Exports<'lunr/perf/token_store_test'>; -} -declare module 'lunr/perf/tokenizer_test.js' { - declare module.exports: $Exports<'lunr/perf/tokenizer_test'>; -} -declare module 'lunr/perf/vector_test.js' { - declare module.exports: $Exports<'lunr/perf/vector_test'>; -} -declare module 'lunr/server.js' { - declare module.exports: $Exports<'lunr/server'>; -} -declare module 'lunr/test/env/augment.min.js' { - declare module.exports: $Exports<'lunr/test/env/augment.min'>; -} -declare module 'lunr/test/env/jquery.js' { - declare module.exports: $Exports<'lunr/test/env/jquery'>; -} -declare module 'lunr/test/env/qunit.js' { - declare module.exports: $Exports<'lunr/test/env/qunit'>; -} -declare module 'lunr/test/env/runner.js' { - declare module.exports: $Exports<'lunr/test/env/runner'>; -} -declare module 'lunr/test/event_emitter_test.js' { - declare module.exports: $Exports<'lunr/test/event_emitter_test'>; -} -declare module 'lunr/test/index_test.js' { - declare module.exports: $Exports<'lunr/test/index_test'>; -} -declare module 'lunr/test/lunr_test.js' { - declare module.exports: $Exports<'lunr/test/lunr_test'>; -} -declare module 'lunr/test/pipeline_test.js' { - declare module.exports: $Exports<'lunr/test/pipeline_test'>; -} -declare module 'lunr/test/search_test.js' { - declare module.exports: $Exports<'lunr/test/search_test'>; -} -declare module 'lunr/test/serialisation_test.js' { - declare module.exports: $Exports<'lunr/test/serialisation_test'>; -} -declare module 'lunr/test/sorted_set_test.js' { - declare module.exports: $Exports<'lunr/test/sorted_set_test'>; -} -declare module 'lunr/test/stemmer_test.js' { - declare module.exports: $Exports<'lunr/test/stemmer_test'>; -} -declare module 'lunr/test/stop_word_filter_test.js' { - declare module.exports: $Exports<'lunr/test/stop_word_filter_test'>; -} -declare module 'lunr/test/store_node_test.js' { - declare module.exports: $Exports<'lunr/test/store_node_test'>; -} -declare module 'lunr/test/store_test.js' { - declare module.exports: $Exports<'lunr/test/store_test'>; -} -declare module 'lunr/test/test_helper.js' { - declare module.exports: $Exports<'lunr/test/test_helper'>; -} -declare module 'lunr/test/token_store_test.js' { - declare module.exports: $Exports<'lunr/test/token_store_test'>; -} -declare module 'lunr/test/tokenizer_test.js' { - declare module.exports: $Exports<'lunr/test/tokenizer_test'>; -} -declare module 'lunr/test/trimmer_test.js' { - declare module.exports: $Exports<'lunr/test/trimmer_test'>; -} -declare module 'lunr/test/vector_test.js' { - declare module.exports: $Exports<'lunr/test/vector_test'>; -} diff --git a/package.json b/package.json index 7b0842f1a..a5ff583d6 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "lint-staged": "7.2.0", "lockfile": "1.0.4", "lodash": "4.17.10", - "lunr": "0.7.0", + "lunr-mutable-indexes": "2.3.1", "marked": "0.4.0", "mime": "2.3.1", "minimatch": "3.0.4", diff --git a/src/lib/search.js b/src/lib/search.js index c9bbd972a..8f6a7aac6 100644 --- a/src/lib/search.js +++ b/src/lib/search.js @@ -1,29 +1,31 @@ // @flow -import lunr from 'lunr'; +import lunrMutable from 'lunr-mutable-indexes'; import type {Version} from '@verdaccio/types'; import type {IStorageHandler, IWebSearch} from '../../types'; /** * Handle the search Indexer. */ class Search implements IWebSearch { - index: any; + index: lunrMutable.index; storage: IStorageHandler; /** * Constructor. */ constructor() { - /* eslint no-invalid-this: "off" */ - this.index = lunr(function() { + /* eslint no-invalid-this: "off" */ + this.index = lunrMutable(function() { this.field('name', {boost: 10}); this.field('description', {boost: 4}); this.field('author', {boost: 6}); + this.field('keywords', {boost: 7}); + this.field('version'); this.field('readme'); }); } - /** + /** * Performs a query to the indexer. * If the keyword is a * it returns all local elements * otherwise performs a search @@ -36,10 +38,10 @@ class Search implements IWebSearch { items.map( function( pkg ) { return {ref: pkg, score: 1}; }); - }) : this.index.search(query); - } + }) : this.index.search(`*${query}*`); + } - /** + /** * Add a new element to index * @param {*} pkg the package */ @@ -48,6 +50,8 @@ class Search implements IWebSearch { id: pkg.name, name: pkg.name, description: pkg.description, + version: `v${pkg.version}`, + keywords: pkg.keywords, author: pkg._npmUser ? pkg._npmUser.name : '???', }); } diff --git a/src/webui/components/Package/index.js b/src/webui/components/Package/index.js index da27a277f..6bb2f0989 100644 --- a/src/webui/components/Package/index.js +++ b/src/webui/components/Package/index.js @@ -7,7 +7,7 @@ import {formatDateDistance} from '../../utils/package'; import classes from './package.scss'; -const Package = ({name, version, author, description, license, time}) => { +const Package = ({name, version, author, description, license, time, keywords}) => { return (
@@ -25,6 +25,13 @@ const Package = ({name, version, author, description, license, time}) => { {description}

+
+ {keywords && keywords.map((keyword, index) => ( + + {keyword} + + ))} +
{time ? `Published ${formatDateDistance(time)} ago` : ''} @@ -42,6 +49,7 @@ Package.propTypes = { version: PropTypes.string, author: PropTypes.string, description: PropTypes.string, + keywords: PropTypes.array, license: PropTypes.string, time: PropTypes.oneOfType([ PropTypes.string, diff --git a/src/webui/components/Package/package.scss b/src/webui/components/Package/package.scss index bd06de98e..adcb49d1e 100644 --- a/src/webui/components/Package/package.scss +++ b/src/webui/components/Package/package.scss @@ -18,6 +18,17 @@ .package { } } + .tags { + margin: 0 0.5em 0.5em 0; + white-space: nowrap; + font-size: $font-size-sm; + :global { + .el-tag { + margin-right: 5px; + } + } + } + .details { display: flex; font-size: 80%; diff --git a/src/webui/components/PackageList/index.js b/src/webui/components/PackageList/index.js index f4373c071..fb24865c6 100644 --- a/src/webui/components/PackageList/index.js +++ b/src/webui/components/PackageList/index.js @@ -36,12 +36,12 @@ export default class PackageList extends React.Component { renderList() { return this.props.packages.map((pkg, i) => { - const {name, version, description, time} = pkg; + const {name, version, description, time, keywords} = pkg; const author = formatAuthor(pkg.author); const license = formatLicense(pkg.license); return (
  • - +
  • ); }); diff --git a/test/unit/webui/components/__snapshots__/package.spec.js.snap b/test/unit/webui/components/__snapshots__/package.spec.js.snap index 0856e2075..45fb81c01 100644 --- a/test/unit/webui/components/__snapshots__/package.spec.js.snap +++ b/test/unit/webui/components/__snapshots__/package.spec.js.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should load the component 1`] = `"

    verdaccio v1.0.0

    By: Sam

    Private NPM repository

    Published about 1 month ago
    MIT
    "`; +exports[` component should load the component 1`] = `"

    verdaccio v1.0.0

    By: Sam

    Private NPM repository

    Published about 1 month ago
    MIT
    "`; -exports[` component should load the component without author 1`] = `"

    verdaccio v1.0.0

    Private NPM repository

    Published about 1 month ago
    MIT
    "`; +exports[` component should load the component without author 1`] = `"

    verdaccio v1.0.0

    Private NPM repository

    Published about 1 month ago
    MIT
    "`; diff --git a/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap b/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap index 03c91b26b..b17ab9d4a 100644 --- a/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap +++ b/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should load the component with packages 1`] = `""`; +exports[` component should load the component with packages 1`] = `""`; diff --git a/types/index.js b/types/index.js index b5f989119..e0e6eba2c 100644 --- a/types/index.js +++ b/types/index.js @@ -17,6 +17,7 @@ import type { IReadTarball, } from '@verdaccio/streams'; import type {ILocalData} from '@verdaccio/local-storage'; +import lunrMutable from 'lunr-mutable-indexes'; import type {NextFunction, $Request, $Response} from 'request'; export type StringValue = verdaccio$StringValue; @@ -75,7 +76,7 @@ export interface IAuth extends IBasicAuth, IAuthMiddleware, IAuthWebUI { } export interface IWebSearch { - index: any; + index: lunrMutable.index; storage: IStorageHandler; query(query: string): any; add(pkg: Version): void; diff --git a/yarn.lock b/yarn.lock index fdda21f14c4b783a02b63b1ff60cc6c4d2543d61..cc96b7937d82aa4d0698d67cd61c2acd1e0f3433 100644 GIT binary patch delta 259 zcmZoZCI0EOctZ*`|@ z)-}>I)-%*ANv~2iO*S$}NldaZPPIrjGBhwYGD|bFw6HWwvM@49O0`HcOSLpHu}qo# zaj&=m$S4IRJ6i>ib^`?)AZ?;&pv1+c1d?&UkeI&MlF@qlyEbMXBZP&9hQ?-wW{E~g wW(GznDanQgmc~Yj=1FN5i6*ILsix+sNolFcDQQOSI_=Cr%(7jlo%MPw0G(7&$^ZZW delta 91 zcmex#TDfXq;%2Vr*e**)H9|48$zkr8`)!#{vMUlO1vZ