0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-04-01 02:42:23 -05:00

Merge pull request #590 from verdaccio/fix-flow

chore: increase usage of flow
This commit is contained in:
Juan Picado @jotadeveloper 2018-02-24 20:38:05 +01:00 committed by GitHub
commit 0d39becedf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 1848 additions and 777 deletions

View file

@ -75,6 +75,7 @@
"no-invalid-this": 2,
"new-cap": 2,
"one-var": 2,
"quote-props":["error", "as-needed"],
"no-console": [
2,
{

View file

@ -7,13 +7,19 @@
.*/coverage/.*
.*/.vscode/.*
.*/build/.*
[include]
.*/docs/.*
.*/scripts/.*
.*/assets/.*
.*/bin/.*
.*/systemd/.*
.*/website/.*
.*/wiki/.*
.*/docs/.*
.*/tools/.*
[libs]
node_modules/@verdaccio/types/lib/
[lints]
[options]
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
module.ignore_non_literal_requires=true

255
flow-typed/npm/js-yaml_vx.x.x.js vendored Normal file
View file

@ -0,0 +1,255 @@
// flow-typed signature: 10998829754884cf0b6f5fe169611a08
// flow-typed version: <<STUB>>/js-yaml_v3.10.0/flow_v0.64.0
/**
* This is an autogenerated libdef stub for:
*
* 'js-yaml'
*
* 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 'js-yaml' {
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 'js-yaml/bin/js-yaml' {
declare module.exports: any;
}
declare module 'js-yaml/dist/js-yaml' {
declare module.exports: any;
}
declare module 'js-yaml/dist/js-yaml.min' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/common' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/dumper' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/exception' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/loader' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/mark' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/schema' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/schema/core' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/schema/default_full' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/schema/default_safe' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/schema/failsafe' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/schema/json' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/binary' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/bool' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/float' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/int' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/js/function' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/js/regexp' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/js/undefined' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/map' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/merge' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/null' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/omap' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/pairs' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/seq' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/set' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/str' {
declare module.exports: any;
}
declare module 'js-yaml/lib/js-yaml/type/timestamp' {
declare module.exports: any;
}
// Filename aliases
declare module 'js-yaml/bin/js-yaml.js' {
declare module.exports: $Exports<'js-yaml/bin/js-yaml'>;
}
declare module 'js-yaml/dist/js-yaml.js' {
declare module.exports: $Exports<'js-yaml/dist/js-yaml'>;
}
declare module 'js-yaml/dist/js-yaml.min.js' {
declare module.exports: $Exports<'js-yaml/dist/js-yaml.min'>;
}
declare module 'js-yaml/index' {
declare module.exports: $Exports<'js-yaml'>;
}
declare module 'js-yaml/index.js' {
declare module.exports: $Exports<'js-yaml'>;
}
declare module 'js-yaml/lib/js-yaml.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml'>;
}
declare module 'js-yaml/lib/js-yaml/common.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/common'>;
}
declare module 'js-yaml/lib/js-yaml/dumper.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/dumper'>;
}
declare module 'js-yaml/lib/js-yaml/exception.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/exception'>;
}
declare module 'js-yaml/lib/js-yaml/loader.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/loader'>;
}
declare module 'js-yaml/lib/js-yaml/mark.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/mark'>;
}
declare module 'js-yaml/lib/js-yaml/schema.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/schema'>;
}
declare module 'js-yaml/lib/js-yaml/schema/core.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/schema/core'>;
}
declare module 'js-yaml/lib/js-yaml/schema/default_full.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/schema/default_full'>;
}
declare module 'js-yaml/lib/js-yaml/schema/default_safe.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/schema/default_safe'>;
}
declare module 'js-yaml/lib/js-yaml/schema/failsafe.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/schema/failsafe'>;
}
declare module 'js-yaml/lib/js-yaml/schema/json.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/schema/json'>;
}
declare module 'js-yaml/lib/js-yaml/type.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type'>;
}
declare module 'js-yaml/lib/js-yaml/type/binary.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/binary'>;
}
declare module 'js-yaml/lib/js-yaml/type/bool.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/bool'>;
}
declare module 'js-yaml/lib/js-yaml/type/float.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/float'>;
}
declare module 'js-yaml/lib/js-yaml/type/int.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/int'>;
}
declare module 'js-yaml/lib/js-yaml/type/js/function.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/js/function'>;
}
declare module 'js-yaml/lib/js-yaml/type/js/regexp.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/js/regexp'>;
}
declare module 'js-yaml/lib/js-yaml/type/js/undefined.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/js/undefined'>;
}
declare module 'js-yaml/lib/js-yaml/type/map.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/map'>;
}
declare module 'js-yaml/lib/js-yaml/type/merge.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/merge'>;
}
declare module 'js-yaml/lib/js-yaml/type/null.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/null'>;
}
declare module 'js-yaml/lib/js-yaml/type/omap.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/omap'>;
}
declare module 'js-yaml/lib/js-yaml/type/pairs.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/pairs'>;
}
declare module 'js-yaml/lib/js-yaml/type/seq.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/seq'>;
}
declare module 'js-yaml/lib/js-yaml/type/set.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/set'>;
}
declare module 'js-yaml/lib/js-yaml/type/str.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/str'>;
}
declare module 'js-yaml/lib/js-yaml/type/timestamp.js' {
declare module.exports: $Exports<'js-yaml/lib/js-yaml/type/timestamp'>;
}

80
flow-typed/npm/jsonwebtoken_vx.x.x.js vendored Normal file
View file

@ -0,0 +1,80 @@
// flow-typed signature: 4ec026fce9b8a945dbac93217027085d
// flow-typed version: <<STUB>>/jsonwebtoken_v8.1.1/flow_v0.64.0
/**
* This is an autogenerated libdef stub for:
*
* 'jsonwebtoken'
*
* 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 'jsonwebtoken' {
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 'jsonwebtoken/decode' {
declare module.exports: any;
}
declare module 'jsonwebtoken/lib/JsonWebTokenError' {
declare module.exports: any;
}
declare module 'jsonwebtoken/lib/NotBeforeError' {
declare module.exports: any;
}
declare module 'jsonwebtoken/lib/timespan' {
declare module.exports: any;
}
declare module 'jsonwebtoken/lib/TokenExpiredError' {
declare module.exports: any;
}
declare module 'jsonwebtoken/sign' {
declare module.exports: any;
}
declare module 'jsonwebtoken/verify' {
declare module.exports: any;
}
// Filename aliases
declare module 'jsonwebtoken/decode.js' {
declare module.exports: $Exports<'jsonwebtoken/decode'>;
}
declare module 'jsonwebtoken/index' {
declare module.exports: $Exports<'jsonwebtoken'>;
}
declare module 'jsonwebtoken/index.js' {
declare module.exports: $Exports<'jsonwebtoken'>;
}
declare module 'jsonwebtoken/lib/JsonWebTokenError.js' {
declare module.exports: $Exports<'jsonwebtoken/lib/JsonWebTokenError'>;
}
declare module 'jsonwebtoken/lib/NotBeforeError.js' {
declare module.exports: $Exports<'jsonwebtoken/lib/NotBeforeError'>;
}
declare module 'jsonwebtoken/lib/timespan.js' {
declare module.exports: $Exports<'jsonwebtoken/lib/timespan'>;
}
declare module 'jsonwebtoken/lib/TokenExpiredError.js' {
declare module.exports: $Exports<'jsonwebtoken/lib/TokenExpiredError'>;
}
declare module 'jsonwebtoken/sign.js' {
declare module.exports: $Exports<'jsonwebtoken/sign'>;
}
declare module 'jsonwebtoken/verify.js' {
declare module.exports: $Exports<'jsonwebtoken/verify'>;
}

431
flow-typed/npm/lunr_vx.x.x.js vendored Normal file
View file

@ -0,0 +1,431 @@
// flow-typed signature: e0027883db9b96a34c42414495ddfa2b
// flow-typed version: <<STUB>>/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'>;
}

109
flow-typed/npm/node-mocks-http_vx.x.x.js vendored Normal file
View file

@ -0,0 +1,109 @@
// flow-typed signature: 0c37b93b28df38b46c7edb9bc9d278ad
// flow-typed version: <<STUB>>/node-mocks-http_v1.6.7/flow_v0.64.0
/**
* This is an autogenerated libdef stub for:
*
* 'node-mocks-http'
*
* 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 'node-mocks-http' {
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 'node-mocks-http/lib/express/mock-application' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/express/mock-express' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/express/mock-request' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/express/utils/define-getter' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/http-mock' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/mockEventEmitter' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/mockRequest' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/mockResponse' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/mockWritableStream' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/node/_http_incoming' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/node/_http_server' {
declare module.exports: any;
}
declare module 'node-mocks-http/lib/node/http' {
declare module.exports: any;
}
// Filename aliases
declare module 'node-mocks-http/lib/express/mock-application.js' {
declare module.exports: $Exports<'node-mocks-http/lib/express/mock-application'>;
}
declare module 'node-mocks-http/lib/express/mock-express.js' {
declare module.exports: $Exports<'node-mocks-http/lib/express/mock-express'>;
}
declare module 'node-mocks-http/lib/express/mock-request.js' {
declare module.exports: $Exports<'node-mocks-http/lib/express/mock-request'>;
}
declare module 'node-mocks-http/lib/express/utils/define-getter.js' {
declare module.exports: $Exports<'node-mocks-http/lib/express/utils/define-getter'>;
}
declare module 'node-mocks-http/lib/http-mock.js' {
declare module.exports: $Exports<'node-mocks-http/lib/http-mock'>;
}
declare module 'node-mocks-http/lib/mockEventEmitter.js' {
declare module.exports: $Exports<'node-mocks-http/lib/mockEventEmitter'>;
}
declare module 'node-mocks-http/lib/mockRequest.js' {
declare module.exports: $Exports<'node-mocks-http/lib/mockRequest'>;
}
declare module 'node-mocks-http/lib/mockResponse.js' {
declare module.exports: $Exports<'node-mocks-http/lib/mockResponse'>;
}
declare module 'node-mocks-http/lib/mockWritableStream.js' {
declare module.exports: $Exports<'node-mocks-http/lib/mockWritableStream'>;
}
declare module 'node-mocks-http/lib/node/_http_incoming.js' {
declare module.exports: $Exports<'node-mocks-http/lib/node/_http_incoming'>;
}
declare module 'node-mocks-http/lib/node/_http_server.js' {
declare module.exports: $Exports<'node-mocks-http/lib/node/_http_server'>;
}
declare module 'node-mocks-http/lib/node/http.js' {
declare module.exports: $Exports<'node-mocks-http/lib/node/http'>;
}

View file

@ -1,31 +1,31 @@
/* eslint comma-dangle: 0 */
module.exports = {
'name': 'verdaccio-jest',
'verbose': true,
'collectCoverage': true,
'coveragePathIgnorePatterns': [
name: 'verdaccio-jest',
verbose: true,
collectCoverage: true,
coveragePathIgnorePatterns: [
'node_modules',
'fixtures'
],
'testEnvironment': 'jest-environment-jsdom-global',
'testRegex': '(/test/unit.*\\.spec|test/functional.*\\.func|/test/webui/.*\\.spec)\\.js',
testEnvironment: 'jest-environment-jsdom-global',
testRegex: '(/test/unit.*\\.spec|test/functional.*\\.func|/test/webui/.*\\.spec)\\.js',
// 'testRegex': '(test/functional.*\\.func)\\.js'
'setupFiles': [
setupFiles: [
'./test/webui/global.js'
],
'modulePathIgnorePatterns': [
modulePathIgnorePatterns: [
'global.js'
],
'testPathIgnorePatterns': [
testPathIgnorePatterns: [
'__snapshots__'
],
'moduleNameMapper': {
moduleNameMapper: {
'\\.(scss)$': '<rootDir>/node_modules/identity-obj-proxy',
'github-markdown-css': '<rootDir>/node_modules/identity-obj-proxy',
'\\.(png)$': '<rootDir>/node_modules/identity-obj-proxy'
},
'transformIgnorePatterns': [
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!react-syntax-highlighter)'
]
};

View file

@ -1,11 +1,11 @@
/* eslint comma-dangle: 0 */
module.exports = {
'name': 'verdaccio-e2e-jest',
'verbose': true,
'collectCoverage': false,
'globalSetup': './test/e2e/pre-setup.js',
'globalTeardown': './test/e2e/teardown.js',
'testEnvironment': './test/e2e/puppeteer_environment.js',
'testRegex': '(/test/e2e/e2e.*\\.spec)\\.js'
name: 'verdaccio-e2e-jest',
verbose: true,
collectCoverage: false,
globalSetup: './test/e2e/pre-setup.js',
globalTeardown: './test/e2e/teardown.js',
testEnvironment: './test/e2e/puppeteer_environment.js',
testRegex: '(/test/e2e/e2e.*\\.spec)\\.js'
};

View file

@ -52,7 +52,7 @@
"@commitlint/cli": "6.1.0",
"@commitlint/config-conventional": "6.1.0",
"@commitlint/travis-cli": "6.1.0",
"@verdaccio/types": "0.3.1",
"@verdaccio/types": "1.0.3",
"axios": "0.17.1",
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
@ -105,6 +105,7 @@
"jest-environment-jsdom-global": "1.0.3",
"jest-environment-node": "22.2.0",
"localstorage-memory": "1.0.2",
"node-mocks-http": "1.6.7",
"node-sass": "4.7.2",
"normalize.css": "7.0.0",
"ora": "1.4.0",

View file

@ -96,7 +96,7 @@ module.exports = function(router, auth, storage, config) {
});
};
if (Object.keys(req.body).length === 1 && Utils.is_object(req.body.users)) {
if (Object.keys(req.body).length === 1 && Utils.isObject(req.body.users)) {
// 501 status is more meaningful, but npm doesn't show error message for 5xx
return next( createError[404]('npm star|unstar calls are not implemented') );
}

View file

@ -6,8 +6,8 @@ import cors from 'cors';
import Storage from '../lib/storage';
import {loadPlugin} from '../lib/plugin-loader';
import hookDebug from './debug';
import Auth from '../lib/auth';
const Auth = require('../lib/auth');
const Logger = require('../lib/logger');
const Config = require('../lib/config');
const Middleware = require('./web/middleware');

View file

@ -65,7 +65,7 @@ module.exports.encodeScopePackage = function(req, res, next) {
};
module.exports.expect_json = function expect_json(req, res, next) {
if (!utils.is_object(req.body)) {
if (!utils.isObject(req.body)) {
return next( createError[400]('can\'t parse incoming json') );
}
next();

View file

@ -1,41 +1,46 @@
/* eslint prefer-spread: "off" */
/* eslint prefer-rest-params: "off" */
// @flow
import {loadPlugin} from '../lib/plugin-loader';
const Crypto = require('crypto');
import Crypto from 'crypto';
import jwt from 'jsonwebtoken';
import {ErrorCode} from './utils';
const Error = require('http-errors');
const Logger = require('./logger');
const jwt = require('jsonwebtoken');
import type {Config, Logger, Callback} from '@verdaccio/types';
import type {$Request, $Response, NextFunction} from 'express';
type $RequestExtend = $Request & {remote_user: any}
const LoggerApi = require('./logger');
/**
* Handles the authentification, load auth plugins.
*/
class Auth {
config: Config;
logger: Logger;
secret: string;
plugins: Array<any>;
/**
* @param {*} config config reference
*/
constructor(config) {
constructor(config: Config) {
this.config = config;
this.logger = Logger.logger.child({sub: 'auth'});
this.logger = LoggerApi.logger.child({sub: 'auth'});
this.secret = config.secret;
this.plugins = this._loadPlugin(config);
this._applyDefaultPlugins();
}
_loadPlugin(config: Config) {
const plugin_params = {
config: config,
config,
logger: this.logger,
};
if (config.users_file) {
if (!config.auth || !config.auth.htpasswd) {
// b/w compat
config.auth = config.auth || {};
config.auth.htpasswd = {file: config.users_file};
}
}
this.plugins = loadPlugin(config, config.auth, plugin_params, function(p) {
return loadPlugin(config, config.auth, plugin_params, function(p) {
return p.authenticate || p.allow_access || p.allow_publish;
});
}
_applyDefaultPlugins() {
const allow_action = function(action) {
return function(user, pkg, cb) {
let ok = pkg[action].reduce(function(prev, curr) {
@ -46,20 +51,20 @@ class Auth {
if (ok) return cb(null, true);
if (user.name) {
cb( Error[403]('user ' + user.name + ' is not allowed to ' + action + ' package ' + pkg.name) );
cb(ErrorCode.get403('user ' + user.name + ' is not allowed to ' + action + ' package ' + pkg.name));
} else {
cb( Error[403]('unregistered users are not allowed to ' + action + ' package ' + pkg.name) );
cb(ErrorCode.get403('unregistered users are not allowed to ' + action + ' package ' + pkg.name));
}
};
};
this.plugins.push({
authenticate: function(user, password, cb) {
return cb( Error[403]('bad username/password, access denied') );
cb(ErrorCode.get403('bad username/password, access denied'));
},
add_user: function(user, password, cb) {
return cb( Error[409]('registration is disabled') );
return cb(ErrorCode.get409('bad username/password, access denied'));
},
allow_access: allow_action('access'),
@ -67,13 +72,7 @@ class Auth {
});
}
/**
* Authenticate an user.
* @param {*} user
* @param {*} password
* @param {*} cb
*/
authenticate(user, password, cb) {
authenticate(user: string, password: string, cb: Callback) {
const plugins = this.plugins.slice(0)
;(function next() {
let p = plugins.shift();
@ -94,13 +93,7 @@ class Auth {
})();
}
/**
* Add a new user.
* @param {*} user
* @param {*} password
* @param {*} cb
*/
add_user(user, password, cb) {
add_user(user: string, password: string, cb: Callback) {
let self = this;
let plugins = this.plugins.slice(0)
@ -129,16 +122,13 @@ class Auth {
/**
* Allow user to access a package.
* @param {*} package_name
* @param {*} user
* @param {*} callback
*/
allow_access(package_name, user, callback) {
allow_access(packageName: string, user: string, callback: Callback) {
let plugins = this.plugins.slice(0);
let pkg = Object.assign({name: package_name},
this.config.getMatchedPackagesSpec(package_name))
// $FlowFixMe
let pkg = Object.assign({name: packageName}, this.config.getMatchedPackagesSpec(packageName));
;(function next() {
(function next() {
let p = plugins.shift();
if (typeof(p.allow_access) !== 'function') {
@ -162,16 +152,13 @@ class Auth {
/**
* Allow user to publish a package.
* @param {*} package_name
* @param {*} user
* @param {*} callback
*/
allow_publish(package_name, user, callback) {
allow_publish(packageName: string, user: string, callback: Callback) {
let plugins = this.plugins.slice(0);
let pkg = Object.assign({name: package_name},
this.config.getMatchedPackagesSpec(package_name))
// $FlowFixMe
let pkg = Object.assign({name: packageName}, this.config.getMatchedPackagesSpec(packageName));
;(function next() {
(function next() {
let p = plugins.shift();
if (typeof(p.allow_publish) !== 'function') {
@ -193,7 +180,7 @@ class Auth {
basic_middleware() {
let self = this;
let credentials;
return function(req, res, _next) {
return function(req: $RequestExtend, res: $Response, _next: NextFunction) {
req.pause();
const next = function(err) {
@ -222,7 +209,7 @@ class Auth {
let parts = authorization.split(' ');
if (parts.length !== 2) {
return next( Error[400]('bad authorization header') );
return next( ErrorCode.get400('bad authorization header') );
}
const scheme = parts[0];
@ -263,10 +250,12 @@ class Auth {
*/
bearer_middleware() {
let self = this;
return function(req, res, _next) {
return function(req: $RequestExtend, res: $Response, _next: NextFunction) {
req.pause();
const next = function(_err) {
req.resume();
/* eslint prefer-spread: "off" */
/* eslint prefer-rest-params: "off" */
return _next.apply(null, arguments);
};
@ -283,7 +272,7 @@ class Auth {
let parts = authorization.split(' ');
if (parts.length !== 2) {
return next( Error[400]('bad authorization header') );
return next( ErrorCode.get400('bad authorization header') );
}
let scheme = parts[0];
@ -300,6 +289,7 @@ class Auth {
}
req.remote_user = authenticatedUser(user.u, user.g);
// $FlowFixMe
req.remote_user.token = token;
next();
};
@ -310,7 +300,7 @@ class Auth {
* @return {Function}
*/
jwtMiddleware() {
return (req, res, _next) => {
return (req: $RequestExtend, res: $Response, _next: NextFunction) => {
if (req.remote_user !== null && req.remote_user.name !== undefined) return _next();
req.pause();
@ -343,7 +333,7 @@ class Auth {
* @param {string} expire_time
* @return {string}
*/
issue_token(user, expire_time) {
issue_token(user: any, expire_time: string) {
return jwt.sign(
{
user: user.name,
@ -362,7 +352,7 @@ class Auth {
* @param {*} token
* @return {Object}
*/
decode_token(token) {
decode_token(token: string) {
let decoded;
try {
decoded = jwt.verify(token, this.secret);
@ -375,10 +365,8 @@ class Auth {
/**
* Encrypt a string.
* @param {String} buf
* @return {Buffer}
*/
aes_encrypt(buf) {
aes_encrypt(buf: Buffer) {
const c = Crypto.createCipher('aes192', this.secret);
const b1 = c.update(buf);
const b2 = c.final();
@ -387,10 +375,8 @@ class Auth {
/**
* Dencrypt a string.
* @param {String} buf
* @return {Buffer}
*/
aes_decrypt(buf) {
aes_decrypt(buf: Buffer ) {
try {
const c = Crypto.createDecipher('aes192', this.secret);
const b1 = c.update(buf);
@ -417,11 +403,9 @@ function buildAnonymousUser() {
/**
* Authenticate an user.
* @param {*} name
* @param {*} groups
* @return {Object} { name: xx, groups: [], real_groups: [] }
*/
function authenticatedUser(name, groups) {
function authenticatedUser(name: string, groups: Array<any>) {
let _groups = (groups || []).concat(['$all', '$authenticated', '@all', '@authenticated', 'all']);
return {
name: name,
@ -430,4 +414,4 @@ function authenticatedUser(name, groups) {
};
}
module.exports = Auth;
export default Auth;

View file

@ -57,11 +57,11 @@ class Config {
assert(self.storage, 'CONFIG: storage path not defined');
const users = {
'all': true,
'anonymous': true,
'undefined': true,
'owner': true,
'none': true,
all: true,
anonymous: true,
undefined: true,
owner: true,
none: true,
};
const check_user_or_uplink = function(arg) {
@ -75,7 +75,7 @@ class Config {
// sanity check for strategic config properties
['users', 'uplinks', 'packages'].forEach(function(x) {
if (self[x] == null) self[x] = {};
assert(Utils.is_object(self[x]), `CONFIG: bad "${x}" value (object expected)`);
assert(Utils.isObject(self[x]), `CONFIG: bad "${x}" value (object expected)`);
});
// sanity check for users
for (let i in self.users) {

View file

@ -6,7 +6,6 @@ import Crypto from 'crypto';
import assert from 'assert';
import fs from 'fs';
import Path from 'path';
import Stream from 'stream';
import UrlNode from 'url';
import _ from 'lodash';
// $FlowFixMe
@ -172,7 +171,7 @@ class LocalStorage implements IStorage {
sha: version.dist.shasum,
};
/* eslint spaced-comment: 0 */
//$FlowFixMe
// $FlowFixMe
const upLink: string = version[Symbol.for('__verdaccio_uplink')];
if (_.isNil(upLink) === false) {
@ -192,7 +191,7 @@ class LocalStorage implements IStorage {
for (let up in packageInfo._uplinks) {
if (Object.prototype.hasOwnProperty.call(packageInfo._uplinks, up)) {
const need_change = !Utils.is_object(packageLocalJson._uplinks[up])
const need_change = !Utils.isObject(packageLocalJson._uplinks[up])
|| packageInfo._uplinks[up].etag !== packageLocalJson._uplinks[up].etag
|| packageInfo._uplinks[up].fetched !== packageLocalJson._uplinks[up].fetched;
@ -232,7 +231,9 @@ class LocalStorage implements IStorage {
* @param {*} tag
* @param {*} callback
*/
addVersion(name: string, version: string, metadata: Version,
addVersion(name: string,
version: string,
metadata: Version,
tag: string,
callback: Callback) {
this._updatePackage(name, (data, cb) => {
@ -247,10 +248,10 @@ class LocalStorage implements IStorage {
}
// if uploaded tarball has a different shasum, it's very likely that we have some kind of error
if (Utils.is_object(metadata.dist) && _.isString(metadata.dist.tarball)) {
if (Utils.isObject(metadata.dist) && _.isString(metadata.dist.tarball)) {
let tarball = metadata.dist.tarball.replace(/.*\//, '');
if (Utils.is_object(data._attachments[tarball])) {
if (Utils.isObject(data._attachments[tarball])) {
if (_.isNil(data._attachments[tarball].shasum) === false && _.isNil(metadata.dist.shasum) === false) {
if (data._attachments[tarball].shasum != metadata.dist.shasum) {
@ -338,7 +339,7 @@ class LocalStorage implements IStorage {
changePackage(name: string,
pkg: Package,
revision?: string, callback: Callback) {
if (!Utils.is_object(pkg.versions) || !Utils.is_object(pkg['dist-tags'])) {
if (!Utils.isObject(pkg.versions) || !Utils.isObject(pkg['dist-tags'])) {
return callback( Utils.ErrorCode.get422());
}
@ -533,7 +534,7 @@ class LocalStorage implements IStorage {
* @private
* @return {ReadTarball}
*/
_streamSuccessReadTarBall(storage: any, filename: string) {
_streamSuccessReadTarBall(storage: any, filename: string): IReadTarball {
const stream: IReadTarball = new ReadTarball();
const readTarballStream = storage.readTarball(filename);
const e404 = Utils.ErrorCode.get404;
@ -588,7 +589,7 @@ class LocalStorage implements IStorage {
* @return {Function}
*/
search(startKey: string, options: any) {
const stream = new Stream.PassThrough({objectMode: true});
const stream = new UploadTarball({objectMode: true});
this._eachPackage((item, cb) => {
fs.stat(item.path, (err, stats) => {
@ -603,27 +604,27 @@ class LocalStorage implements IStorage {
}
const listVersions: Array<string> = Object.keys(data.versions);
const versions: Array<string> = Utils.semver_sort(listVersions);
const versions: Array<string> = Utils.semverSort(listVersions);
const latest: string = data['dist-tags'] && data['dist-tags'].latest ? data['dist-tags'].latest : versions.pop();
if (data.versions[latest]) {
const version: Version = data.versions[latest];
const pkg: any = {
'name': version.name,
'description': version.description,
name: version.name,
description: version.description,
'dist-tags': {latest},
'maintainers': version.maintainers || [version.author].filter(Boolean),
'author': version.author,
'repository': version.repository,
'readmeFilename': version.readmeFilename || '',
'homepage': version.homepage,
'keywords': version.keywords,
'bugs': version.bugs,
'license': version.license,
'time': {
maintainers: version.maintainers || [version.author].filter(Boolean),
author: version.author,
repository: version.repository,
readmeFilename: version.readmeFilename || '',
homepage: version.homepage,
keywords: version.keywords,
bugs: version.bugs,
license: version.license,
time: {
modified: item.time ? new Date(item.time).toISOString() : stats.mtime,
},
'versions': {[latest]: 'latest'},
versions: {[latest]: 'latest'},
};
stream.push(pkg);

View file

@ -157,7 +157,7 @@ function print(type, msg, obj, colors) {
let _ref = name.split('.');
for (let _i = 0; _i < _ref.length; _i++) {
let id = _ref[_i];
if (Utils.is_object(str) || Array.isArray(str)) {
if (Utils.isObject(str) || Array.isArray(str)) {
str = str[id];
} else {
str = undefined;

View file

@ -1,5 +1,3 @@
'use strict';
const Handlebars = require('handlebars');
const request = require('request');
const _ = require('lodash');

View file

@ -1,14 +1,16 @@
// @flow
import Path from 'path';
import _ from 'lodash';
import logger from './logger';
import type {Config} from '@verdaccio/types';
/**
* Requires a module.
* @param {*} path the module's path
* @return {Object}
*/
function tryLoad(path) {
function tryLoad(path: string) {
try {
return require(path);
} catch(err) {
@ -37,13 +39,13 @@ function mergeConfig(appConfig, pluginConfig) {
* - A seccond attempt from node_modules, in case to have multiple match as for instance verdaccio-ldap
* and sinopia-ldap. All verdaccio prefix will have preferences.
* @param {*} config a reference of the configuration settings
* @param {*} plugin_configs
* @param {*} pluginConfigs
* @param {*} params a set of params to initialise the plugin
* @param {*} sanity_check callback that check the shape that should fulfill the plugin
* @param {*} sanityCheck callback that check the shape that should fulfill the plugin
* @return {Array} list of plugins
*/
function loadPlugin(config, plugin_configs, params, sanity_check) {
let plugins = Object.keys(plugin_configs || {}).map(function(p) {
function loadPlugin(config: Config, pluginConfigs: any, params: any, sanityCheck: Function) {
return Object.keys(pluginConfigs || {}).map(function(p) {
let plugin;
// try local plugins first
@ -78,18 +80,16 @@ function loadPlugin(config, plugin_configs, params, sanity_check) {
}
/* eslint new-cap:off */
plugin = isES6(plugin) ? new plugin.default(mergeConfig(config, plugin_configs[p]), params) : plugin(plugin_configs[p], params);
plugin = isES6(plugin) ? new plugin.default(mergeConfig(config, pluginConfigs[p]), params) : plugin(pluginConfigs[p], params);
/* eslint new-cap:off */
if (plugin === null || !sanity_check(plugin)) {
if (plugin === null || !sanityCheck(plugin)) {
logger.logger.error({content: p}, '@{content} doesn\'t look like a valid plugin');
throw Error('"' + p + '" doesn\'t look like a valid plugin');
}
logger.logger.warn({content: p}, 'Plugin successfully loaded: @{content}');
return plugin;
});
return plugins;
}
export {loadPlugin};

View file

@ -1,16 +1,21 @@
/* eslint no-invalid-this: "off" */
// @flow
const lunr = require('lunr');
import lunr from 'lunr';
import type {IStorageHandler, Version, IWebSearch} from '@verdaccio/types';
/**
* Handle the search Indexer.
*/
class Search {
class Search implements IWebSearch {
index: any;
storage: IStorageHandler;
/**
* Constructor.
*/
constructor() {
/* eslint no-invalid-this: "off" */
this.index = lunr(function() {
this.field('name', {boost: 10});
this.field('description', {boost: 4});
@ -26,18 +31,18 @@ class Search {
* @param {*} q the keyword
* @return {Array} list of results.
*/
query(q) {
return q === '*'
? this.storage.localStorage.localList.get().map( function( pkg ) {
query(query: string) {
return query === '*'
? this.storage.localStorage.localData.get().map( function( pkg ) {
return {ref: pkg, score: 1};
}) : this.index.search(q);
}) : this.index.search(query);
}
/**
* Add a new element to index
* @param {*} pkg the package
*/
add(pkg) {
add(pkg: Version) {
this.index.add({
id: pkg.name,
name: pkg.name,
@ -50,7 +55,7 @@ class Search {
* Remove an element from the index.
* @param {*} name the id element
*/
remove(name) {
remove(name: string) {
this.index.remove({id: name});
}
@ -72,7 +77,7 @@ class Search {
* Set up the {Storage}
* @param {*} storage An storage reference.
*/
configureStorage(storage) {
configureStorage(storage: IStorageHandler) {
this.storage = storage;
this.reindex();
}

View file

@ -1,7 +1,3 @@
/* eslint prefer-rest-params: "off" */
'use strict';
// see https://secure.flickr.com/photos/girliemac/sets/72157628409467125
const images = {
@ -69,6 +65,7 @@ module.exports.middleware = function(req, res, next) {
if (status in images) {
res.setHeader('X-Status-Cat', module.exports.get_image(status));
}
/* eslint prefer-rest-params: "off" */
_writeHead.apply(res, arguments);
};

View file

@ -17,13 +17,14 @@ const DEFAULT_REVISION: string = `0-0000000000000000`;
const generatePackageTemplate = function(name: string): Package {
return {
// standard things
'name': name,
'versions': {},
name,
versions: {},
'dist-tags': {},
'time': {},
'_distfiles': {},
'_attachments': {},
'_uplinks': {},
time: {},
_distfiles: {},
_attachments: {},
_uplinks: {},
_rev: '',
};
};
@ -41,7 +42,7 @@ function normalizePackage(pkg: Package) {
'time'];
pkgProperties.forEach((key) => {
if (_.isNil(Utils.is_object(pkg[key]))) {
if (_.isNil(Utils.isObject(pkg[key]))) {
pkg[key] = {};
}
});

View file

@ -17,6 +17,7 @@ import type {
IStorage,
IProxy,
IStorageHandler,
Versions,
ProxyList,
Package,
Config,
@ -27,17 +28,22 @@ import type {
Logger,
} from '@verdaccio/types';
import type {IReadTarball} from '@verdaccio/streams';
import type {IReadTarball, IUploadTarball} from '@verdaccio/streams';
const LoggerApi = require('../lib/logger');
const WHITELIST = ['_rev', 'name', 'versions', 'dist-tags', 'readme', 'time'];
const getDefaultMetadata = (name) => {
return {
'name': name,
'versions': {},
const getDefaultMetadata = function(name): Package {
const pkgMetadata: Package = {
name,
versions: {},
'dist-tags': {},
'_uplinks': {},
_uplinks: {},
_distfiles: {},
_attachments: {},
_rev: '',
};
return pkgMetadata;
};
/**
@ -63,9 +69,9 @@ class Storage implements IStorageHandler {
/**
* Add a {name} package to a system
Function checks if package with the same name is available from uplinks.
If it isn't, we create package locally
Used storages: local (write) && uplinks
Function checks if package with the same name is available from uplinks.
If it isn't, we create package locally
Used storages: local (write) && uplinks
* @param {*} name
* @param {*} metadata
* @param {*} callback
@ -97,6 +103,7 @@ class Storage implements IStorageHandler {
*/
const checkPackageRemote = () => {
return new Promise((resolve, reject) => {
// $FlowFixMe
self._syncUplinksMetadata(name, null, {}, (err, results, err_results) => {
// something weird
if (err && err.status !== 404) {
@ -111,7 +118,7 @@ class Storage implements IStorageHandler {
// if uplink fails with a status other than 404, we report failure
if (_.isNil(err_results[i][0]) === false) {
if (err_results[i][0].status !== 404) {
if (_.isNil(this.config.publish) === false &&
if (this.config.publish &&
_.isBoolean(this.config.publish.allow_offline) &&
this.config.publish.allow_offline) {
return resolve();
@ -159,20 +166,20 @@ class Storage implements IStorageHandler {
/**
* Add a new version of package {name} to a system
Used storages: local (write)
Used storages: local (write)
* @param {*} name
* @param {*} version
* @param {*} metadata
* @param {*} tag
* @param {*} callback
*/
addVersion(name: string, version: Version, metadata: Package, tag: string, callback: Callback) {
addVersion(name: string, version: string, metadata: Version, tag: string, callback: Callback) {
this.localStorage.addVersion(name, version, metadata, tag, callback);
}
/**
* Tags a package version with a provided tag
Used storages: local (write)
Used storages: local (write)
* @param {*} name
* @param {*} tag_hash
* @param {*} callback
@ -183,7 +190,7 @@ class Storage implements IStorageHandler {
/**
* Tags a package version with a provided tag
Used storages: local (write)
Used storages: local (write)
* @param {*} name
* @param {*} tag_hash
* @param {*} callback
@ -195,8 +202,8 @@ class Storage implements IStorageHandler {
/**
* Change an existing package (i.e. unpublish one version)
Function changes a package info from local storage and all uplinks with write access./
Used storages: local (write)
Function changes a package info from local storage and all uplinks with write access./
Used storages: local (write)
* @param {*} name
* @param {*} metadata
* @param {*} revision
@ -208,8 +215,8 @@ class Storage implements IStorageHandler {
/**
* Remove a package from a system
Function removes a package from local storage
Used storages: local (write)
Function removes a package from local storage
Used storages: local (write)
* @param {*} name
* @param {*} callback
*/
@ -220,11 +227,11 @@ class Storage implements IStorageHandler {
}
/**
Remove a tarball from a system
Function removes a tarball from local storage.
Tarball in question should not be linked to in any existing
versions, i.e. package version should be unpublished first.
Used storage: local (write)
Remove a tarball from a system
Function removes a tarball from local storage.
Tarball in question should not be linked to in any existing
versions, i.e. package version should be unpublished first.
Used storage: local (write)
* @param {*} name
* @param {*} filename
* @param {*} revision
@ -236,22 +243,22 @@ class Storage implements IStorageHandler {
/**
* Upload a tarball for {name} package
Function is syncronous and returns a WritableStream
Used storages: local (write)
Function is syncronous and returns a WritableStream
Used storages: local (write)
* @param {*} name
* @param {*} filename
* @return {Stream}
*/
add_tarball(name: string, filename: string) {
add_tarball(name: string, filename: string): IUploadTarball {
return this.localStorage.addTarball(name, filename);
}
/**
Get a tarball from a storage for {name} package
Function is syncronous and returns a ReadableStream
Function tries to read tarball locally, if it fails then it reads package
information in order to figure out where we can get this tarball from
Used storages: local || uplink (just one)
Get a tarball from a storage for {name} package
Function is syncronous and returns a ReadableStream
Function tries to read tarball locally, if it fails then it reads package
information in order to figure out where we can get this tarball from
Used storages: local || uplink (just one)
* @param {*} name
* @param {*} filename
* @return {Stream}
@ -266,7 +273,8 @@ class Storage implements IStorageHandler {
// information about it, so fetching package info is unnecessary
// trying local first
let localStream: IReadTarball = self.localStorage.getTarball(name, filename);
// flow: should be IReadTarball
let localStream: any = self.localStorage.getTarball(name, filename);
let is_open = false;
localStream.on('error', (err) => {
if (is_open || err.status !== 404) {
@ -276,7 +284,8 @@ class Storage implements IStorageHandler {
// local reported 404
let err404 = err;
localStream.abort();
localStream = null; // gc
// $FlowFixMe
localStream = null; // we force for garbage collector
self.localStorage.getPackageMetadata(name, (err, info: Package) => {
if (_.isNil(err) && info._distfiles && _.isNil(info._distfiles[filename]) === false) {
// information about this file exists locally
@ -285,7 +294,7 @@ class Storage implements IStorageHandler {
// we know nothing about this file, trying to get information elsewhere
self._syncUplinksMetadata(name, info, {}, (err, info: Package) => {
if (_.isNil(err) === false) {
return readStream.emit('error', err);
return readStream.emit('error', err);
}
if (_.isNil(info._distfiles) || _.isNil(info._distfiles[filename])) {
return readStream.emit('error', err404);
@ -367,7 +376,7 @@ class Storage implements IStorageHandler {
savestream.on('error', function(err) {
self.logger.warn( {err: err}
, 'error saving file: @{err.message}\n@{err.stack}' );
, 'error saving file: @{err.message}\n@{err.stack}' );
if (savestream) {
savestream.abort();
}
@ -381,11 +390,11 @@ class Storage implements IStorageHandler {
}
/**
Retrieve a package metadata for {name} package
Function invokes localStorage.getPackage and uplink.get_package for every
uplink with proxy_access rights against {name} and combines results
into one json object
Used storages: local && uplink (proxy_access)
Retrieve a package metadata for {name} package
Function invokes localStorage.getPackage and uplink.get_package for every
uplink with proxy_access rights against {name} and combines results
into one json object
Used storages: local && uplink (proxy_access)
* @param {object} options
* @property {string} options.name Package Name
@ -423,18 +432,18 @@ class Storage implements IStorageHandler {
result._attachments = {};
options.callback(null, result, uplink_errors);
});
});
});
}
/**
Retrieve remote and local packages more recent than {startkey}
Function streams all packages from all uplinks first, and then
local packages.
Note that local packages could override registry ones just because
they appear in JSON last. That's a trade-off we make to avoid
memory issues.
Used storages: local && uplink (proxy_access)
Retrieve remote and local packages more recent than {startkey}
Function streams all packages from all uplinks first, and then
local packages.
Note that local packages could override registry ones just because
they appear in JSON last. That's a trade-off we make to avoid
memory issues.
Used storages: local && uplink (proxy_access)
* @param {*} startkey
* @param {*} options
* @return {Stream}
@ -445,42 +454,42 @@ class Storage implements IStorageHandler {
let stream: any = new Stream.PassThrough({objectMode: true});
async.eachSeries(Object.keys(this.uplinks), function(up_name, cb) {
// shortcut: if `local=1` is supplied, don't call uplinks
if (options.req.query.local !== undefined) {
return cb();
}
// search by keyword for each uplink
let lstream: IUploadTarball = self.uplinks[up_name].search(options);
// join streams
lstream.pipe(stream, {end: false});
lstream.on('error', function(err) {
self.logger.error({err: err}, 'uplink error: @{err.message}');
cb(), cb = function() {};
});
lstream.on('end', function() {
cb(), cb = function() {};
});
stream.abort = function() {
if (lstream.abort) {
lstream.abort();
// shortcut: if `local=1` is supplied, don't call uplinks
if (options.req.query.local !== undefined) {
return cb();
}
cb(), cb = function() {};
};
},
// executed after all series
function() {
// attach a local search results
let lstream: IReadTarball = self.localStorage.search(startkey, options);
stream.abort = function() {
lstream.abort();
};
lstream.pipe(stream, {end: true});
lstream.on('error', function(err) {
self.logger.error({err: err}, 'search error: @{err.message}');
stream.end();
// search by keyword for each uplink
let lstream: IUploadTarball = self.uplinks[up_name].search(options);
// join streams
lstream.pipe(stream, {end: false});
lstream.on('error', function(err) {
self.logger.error({err: err}, 'uplink error: @{err.message}');
cb(), cb = function() {};
});
lstream.on('end', function() {
cb(), cb = function() {};
});
stream.abort = function() {
if (lstream.abort) {
lstream.abort();
}
cb(), cb = function() {};
};
},
// executed after all series
function() {
// attach a local search results
let lstream: IReadTarball = self.localStorage.search(startkey, options);
stream.abort = function() {
lstream.abort();
};
lstream.pipe(stream, {end: true});
lstream.on('error', function(err) {
self.logger.error({err: err}, 'search error: @{err.message}');
stream.end();
});
});
});
return stream;
}
@ -523,25 +532,18 @@ class Storage implements IStorageHandler {
/**
* Function fetches package metadata from uplinks and synchronizes it with local data
if package is available locally, it MUST be provided in pkginfo
returns callback(err, result, uplink_errors)
* @param {*} name
* @param {*} packageInfo
* @param {*} options
* @param {*} callback
if package is available locally, it MUST be provided in pkginfo
returns callback(err, result, uplink_errors)
*/
_syncUplinksMetadata(name: string, packageInfo: Package, options: any, callback: Callback) {
let exists = false;
_syncUplinksMetadata(name: string, packageInfo: Package, options: any, callback: Callback): void {
let exists = true;
const self = this;
const upLinks = [];
if (_.isNil(packageInfo)) {
if (!packageInfo || packageInfo === null) {
exists = false;
packageInfo = getDefaultMetadata(name);
} else {
exists = true;
}
for (let up in this.uplinks) {
if (this.config.hasProxyTo(name, up)) {
upLinks.push(this.uplinks[up]);
@ -553,7 +555,7 @@ class Storage implements IStorageHandler {
const _options = Object.assign({}, options);
let upLinkMeta = packageInfo._uplinks[upLink.upname];
if (Utils.is_object(upLinkMeta)) {
if (Utils.isObject(upLinkMeta)) {
const fetched = upLinkMeta.fetched;
@ -591,7 +593,7 @@ class Storage implements IStorageHandler {
// added to fix verdaccio#73
if ('time' in upLinkResponse) {
packageInfo['time'] = upLinkResponse.time;
packageInfo.time = upLinkResponse.time;
}
this._updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);
@ -616,8 +618,8 @@ class Storage implements IStorageHandler {
assert(!err && Array.isArray(upLinksErrors));
if (!exists) {
return callback( Utils.ErrorCode.get404('no such package available')
, null
, upLinksErrors );
, null
, upLinksErrors );
}
self.localStorage.updateVersions(name, packageInfo, function(err, packageJsonLocal: Package) {
@ -666,7 +668,7 @@ class Storage implements IStorageHandler {
/**
* Function gets a local info and an info from uplinks and tries to merge it
exported for unit tests only.
exported for unit tests only.
* @param {*} local
* @param {*} up
* @param {*} config

View file

@ -7,17 +7,19 @@ import _ from 'lodash';
import request from 'request';
import Stream from 'stream';
import URL from 'url';
import {parseInterval, is_object, ErrorCode} from './utils';
import {parseInterval, isObject, ErrorCode} from './utils';
import {ReadTarball} from '@verdaccio/streams';
import type {
IProxy,
Config,
UpLinkConf,
Callback,
Headers,
Logger,
} from '@verdaccio/types';
import type {IUploadTarball} from '@verdaccio/streams';
// import type {IUploadTarball, IReadTarball} from '@verdaccio/streams';
const LoggerApi = require('./logger');
const encode = function(thing) {
@ -42,15 +44,15 @@ const setConfig = (config, key, def) => {
* (same for storage.js, local-storage.js, up-storage.js)
*/
class ProxyStorage implements IProxy {
config: Config;
config: UpLinkConf;
failed_requests: number;
userAgent: string;
ca: string | void;
logger: Logger;
server_id: string;
url: any;
maxage: string;
timeout: string;
maxage: number;
timeout: number;
max_fails: number;
fail_timeout: number;
upname: string;
@ -76,11 +78,11 @@ class ProxyStorage implements IProxy {
this.config.url = this.config.url.replace(/\/$/, '');
if (Number(this.config.timeout) >= 1000) {
if (this.config.timeout && Number(this.config.timeout) >= 1000) {
this.logger.warn(['Too big timeout value: ' + this.config.timeout,
'We changed time format to nginx-like one',
'(see http://nginx.org/en/docs/syntax.html)',
'so please update your config accordingly'].join('\n'));
'We changed time format to nginx-like one',
'(see http://nginx.org/en/docs/syntax.html)',
'so please update your config accordingly'].join('\n'));
}
// a bunch of different configurable timers
@ -96,14 +98,14 @@ class ProxyStorage implements IProxy {
* @param {*} cb
* @return {Request}
*/
request(options: any, cb: Callback) {
request(options: any, cb?: Callback) {
let json;
if (this._statusCheck() === false) {
let streamRead = new Stream.Readable();
process.nextTick(function() {
if (_.isFunction(cb)) {
if (cb) {
cb(ErrorCode.get500('uplink is offline'));
}
// $FlowFixMe
@ -131,7 +133,7 @@ class ProxyStorage implements IProxy {
uri: uri,
}, 'making request: \'@{method} @{uri}\'');
if (is_object(options.json)) {
if (isObject(options.json)) {
json = JSON.stringify(options.json);
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
}
@ -142,6 +144,7 @@ class ProxyStorage implements IProxy {
// $FlowFixMe
processBody(err, body);
logActivity();
// $FlowFixMe
cb(err, res, body);
/**
@ -164,7 +167,7 @@ class ProxyStorage implements IProxy {
}
}
if (!err && is_object(body)) {
if (!err && isObject(body)) {
if (_.isString(body.error)) {
error = body.error;
}
@ -176,8 +179,8 @@ class ProxyStorage implements IProxy {
function logActivity() {
let message = '@{!status}, req: \'@{request.method} @{request.url}\'';
message += error
? ', error: @{!error}'
: ', bytes: @{bytes.in}/@{bytes.out}';
? ', error: @{!error}'
: ', bytes: @{bytes.in}/@{bytes.out}';
self.logger.warn({
err: err,
request: {method: method, url: uri},
@ -261,8 +264,9 @@ class ProxyStorage implements IProxy {
* @private
*/
_setAuth(headers: any) {
const auth = this.config.auth;
if (_.isNil(this.config.auth) || headers['authorization']) {
if (typeof auth === 'undefined' || headers['authorization']) {
return headers;
}
@ -273,10 +277,12 @@ class ProxyStorage implements IProxy {
// get NPM_TOKEN http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
// or get other variable export in env
let token: any = process.env.NPM_TOKEN;
if (this.config.auth.token) {
token = this.config.auth.token;
} else if (this.config.auth.token_env) {
token = process.env[this.config.auth.token_env];
if (auth.token) {
token = auth.token;
} else if (auth.token_env ) {
// $FlowFixMe
token = process.env[auth.token_env];
}
if (_.isNil(token)) {
@ -284,8 +290,9 @@ class ProxyStorage implements IProxy {
}
// define type Auth allow basic and bearer
const type = this.config.auth.type;
const type = auth.type;
this._setHeaderAuthorization(headers, type, token);
return headers;
}
@ -321,25 +328,28 @@ class ProxyStorage implements IProxy {
* Eg:
*
* uplinks:
npmjs:
url: https://registry.npmjs.org/
headers:
Accept: "application/vnd.npm.install-v2+json; q=1.0"
verdaccio-staging:
url: https://mycompany.com/npm
headers:
Accept: "application/json"
authorization: "Basic YourBase64EncodedCredentials=="
npmjs:
url: https://registry.npmjs.org/
headers:
Accept: "application/vnd.npm.install-v2+json; q=1.0"
verdaccio-staging:
url: https://mycompany.com/npm
headers:
Accept: "application/json"
authorization: "Basic YourBase64EncodedCredentials=="
* @param {Object} headers
* @private
*/
_overrideWithUplinkConfigHeaders(headers: any) {
_overrideWithUplinkConfigHeaders(headers: Headers) {
if (!this.config.headers) {
return headers;
}
// add/override headers specified in the config
/* eslint guard-for-in: 0 */
for (let key in this.config.headers) {
if (Object.prototype.hasOwnProperty.call(this.config.headers, key)) {
headers[key] = this.config.headers[key];
}
}
}
@ -349,10 +359,10 @@ class ProxyStorage implements IProxy {
* @return {Boolean}
*/
isUplinkValid(url: string) {
// $FlowFixMe
url = URL.parse(url);
// $FlowFixMe
return url.protocol === this.url.protocol && url.host === this.url.host && url.path.indexOf(this.url.path) === 0;
// $FlowFixMe
url = URL.parse(url);
// $FlowFixMe
return url.protocol === this.url.protocol && url.host === this.url.host && url.path.indexOf(this.url.path) === 0;
}
/**
@ -447,8 +457,8 @@ class ProxyStorage implements IProxy {
* @return {Stream}
*/
search(options: any) {
const transformStream: IUploadTarball = new Stream.PassThrough({objectMode: true});
const requestStream: IUploadTarball = this.request({
const transformStream: any = new Stream.PassThrough({objectMode: true});
const requestStream: stream$Readable = this.request({
uri: options.req.url,
req: options.req,
headers: {
@ -457,7 +467,7 @@ class ProxyStorage implements IProxy {
});
let parsePackage = (pkg) => {
if (is_object(pkg)) {
if (isObject(pkg)) {
transformStream.emit('data', pkg);
}
};
@ -486,6 +496,8 @@ class ProxyStorage implements IProxy {
});
transformStream.abort = () => {
// FIXME: this is clearly a potential issue
// $FlowFixMe
requestStream.abort();
transformStream.emit('end');
};
@ -509,8 +521,8 @@ class ProxyStorage implements IProxy {
if (this.proxy === false) {
headers['X-Forwarded-For'] = (
req && req.headers['x-forwarded-for']
? req.headers['x-forwarded-for'] + ', '
: ''
? req.headers['x-forwarded-for'] + ', '
: ''
) + req.connection.remoteAddress;
}
}
@ -518,8 +530,8 @@ class ProxyStorage implements IProxy {
// always attach Via header to avoid loops, even if we're not proxying
headers['Via'] =
req && req.headers['via']
? req.headers['via'] + ', '
: '';
? req.headers['via'] + ', '
: '';
headers['Via'] += '1.1 ' + this.server_id + ' (Verdaccio)';
}
@ -604,7 +616,7 @@ class ProxyStorage implements IProxy {
if (this.proxy) {
this.logger.debug({url: this.url.href, rule: noProxyItem},
'not using proxy for @{url}, excluded by @{rule} rule');
// $FlowFixMe
// $FlowFixMe
this.proxy = false;
}
break;

View file

@ -1,3 +1,5 @@
// @flow
import {generateGravatarUrl} from '../utils/user';
import assert from 'assert';
import semver from 'semver';
@ -6,15 +8,16 @@ import URL from 'url';
import fs from 'fs';
import _ from 'lodash';
import createError from 'http-errors';
import type {Package, Config} from '@verdaccio/types';
import type {$Request} from 'express';
const Logger = require('./logger');
/**
* Validate a package.
* @param {*} name
* @return {Boolean} whether the package is valid or not
*/
function validate_package(name) {
function validate_package(name: any): boolean {
name = name.split('/', 2);
if (name.length === 1) {
// normal package
@ -32,7 +35,7 @@ function validate_package(name) {
* @param {*} name the package name
* @return {Boolean} whether is valid or not
*/
function validate_name(name) {
function validate_name(name: string): boolean {
if (_.isString(name) === false) {
return false;
}
@ -54,7 +57,7 @@ function validate_name(name) {
* @param {*} obj the element
* @return {Boolean}
*/
function isObject(obj) {
function isObject(obj: any): boolean {
return _.isObject(obj) && _.isNull(obj) === false && _.isArray(obj) === false;
}
@ -65,7 +68,7 @@ function isObject(obj) {
* @param {*} name
* @return {Object} the object with additional properties as dist-tags ad versions
*/
function validate_metadata(object, name) {
function validate_metadata(object: Package, name: string) {
assert(isObject(object), 'not a json object');
assert.equal(object.name, name);
@ -82,12 +85,9 @@ function validate_metadata(object, name) {
/**
* Create base url for registry.
* @param {String} protocol
* @param {String} host
* @param {String} prefix
* @return {String} base registry url
*/
function combineBaseUrl(protocol, host, prefix) {
function combineBaseUrl(protocol: string, host: string, prefix?: string): string {
let result = `${protocol}://${host}`;
if (prefix) {
@ -108,7 +108,7 @@ function combineBaseUrl(protocol, host, prefix) {
* @param {*} config
* @return {String} a filtered package
*/
function filter_tarball_urls(pkg, req, config) {
function filter_tarball_urls(pkg: Package, req: $Request, config: Config) {
/**
* Filter a tarball url.
* @param {*} _url
@ -118,6 +118,7 @@ function filter_tarball_urls(pkg, req, config) {
if (!req.headers.host) {
return _url;
}
// $FlowFixMe
const filename = URL.parse(_url).pathname.replace(/^.*\//, '');
const base = combineBaseUrl(getWebProtocol(req), req.headers.host, config.url_prefix);
@ -142,7 +143,7 @@ function filter_tarball_urls(pkg, req, config) {
* @param {*} tag
* @return {Boolean} whether a package has been tagged
*/
function tag_version(data, version, tag) {
function tag_version(data: Package, version: string, tag: string) {
if (_.isEmpty(tag) === false) {
if (data['dist-tags'][tag] !== version) {
if (semver.parse(version, true)) {
@ -161,20 +162,20 @@ function tag_version(data, version, tag) {
/**
* Gets version from a package object taking into account semver weirdness.
* @param {*} object
* @param {*} version
* @return {String} return the semantic version of a package
*/
function get_version(object, version) {
function get_version(pkg: Package, version: any) {
// this condition must allow cast
if (object.versions[version] != null) {
return object.versions[version];
if (pkg.versions[version] != null) {
return pkg.versions[version];
}
try {
version = semver.parse(version, true);
for (let k in object.versions) {
if (version.compare(semver.parse(k, true)) === 0) {
return object.versions[k];
for (let versionItem in pkg.versions) {
// $FlowFixMe
if (version.compare(semver.parse(versionItem, true)) === 0) {
return pkg.versions[versionItem];
}
}
} catch (err) {
@ -196,7 +197,7 @@ function get_version(object, version) {
* @param {*} urlAddress the internet address definition
* @return {Object|Null} literal object that represent the address parsed
*/
function parse_address(urlAddress) {
function parse_address(urlAddress: any) {
//
// TODO: refactor it to something more reasonable?
//
@ -225,12 +226,10 @@ function parse_address(urlAddress) {
/**
* Function filters out bad semver versions and sorts the array.
* @param {*} array
* @return {Array} sorted Array
*/
function semverSort(array) {
return array
.filter(function(x) {
function semverSort(listVersions: Array<string>) {
return listVersions.filter(function(x) {
if (!semver.parse(x, true)) {
Logger.logger.warn( {ver: x}, 'ignoring bad version @{ver}' );
return false;
@ -245,32 +244,33 @@ function semverSort(array) {
* Flatten arrays of tags.
* @param {*} data
*/
function normalize_dist_tags(data) {
function normalize_dist_tags(pkg: Package) {
let sorted;
if (!data['dist-tags'].latest) {
if (!pkg['dist-tags'].latest) {
// overwrite latest with highest known version based on semver sort
sorted = semverSort(Object.keys(data.versions));
sorted = semverSort(Object.keys(pkg.versions));
if (sorted && sorted.length) {
data['dist-tags'].latest = sorted.pop();
pkg['dist-tags'].latest = sorted.pop();
}
}
for (let tag in data['dist-tags']) {
if (_.isArray(data['dist-tags'][tag])) {
if (data['dist-tags'][tag].length) {
for (let tag in pkg['dist-tags']) {
if (_.isArray(pkg['dist-tags'][tag])) {
if (pkg['dist-tags'][tag].length) {
// sort array
sorted = semverSort(data['dist-tags'][tag]);
// $FlowFixMe
sorted = semverSort(pkg['dist-tags'][tag]);
if (sorted.length) {
// use highest version based on semver sort
data['dist-tags'][tag] = sorted.pop();
pkg['dist-tags'][tag] = sorted.pop();
}
} else {
delete data['dist-tags'][tag];
delete pkg['dist-tags'][tag];
}
} else if (_.isString(data['dist-tags'][tag] )) {
if (!semver.parse(data['dist-tags'][tag], true)) {
} else if (_.isString(pkg['dist-tags'][tag] )) {
if (!semver.parse(pkg['dist-tags'][tag], true)) {
// if the version is invalid, delete the dist-tag entry
delete data['dist-tags'][tag];
delete pkg['dist-tags'][tag];
}
}
}
@ -278,14 +278,14 @@ function normalize_dist_tags(data) {
const parseIntervalTable = {
'': 1000,
'ms': 1,
's': 1000,
'm': 60*1000,
'h': 60*60*1000,
'd': 86400000,
'w': 7*86400000,
'M': 30*86400000,
'y': 365*86400000,
ms: 1,
s: 1000,
m: 60*1000,
h: 60*60*1000,
d: 86400000,
w: 7*86400000,
M: 30*86400000,
y: 365*86400000,
};
/**
@ -293,7 +293,7 @@ const parseIntervalTable = {
* @param {*} interval
* @return {Number}
*/
function parseInterval(interval) {
function parseInterval(interval: any) {
if (typeof(interval) === 'number') {
return interval * 1000;
}
@ -318,46 +318,46 @@ function parseInterval(interval) {
* @param {*} req
* @return {String}
*/
function getWebProtocol(req) {
function getWebProtocol(req: $Request) {
return req.get('X-Forwarded-Proto') || req.protocol;
}
const getLatestVersion = function(pkgInfo) {
const getLatestVersion = function(pkgInfo: Package) {
return pkgInfo['dist-tags'].latest;
};
const ErrorCode = {
get409: () => {
return createError(409, 'this package is already present');
get409: (message: string = 'this package is already present') => {
return createError(409, message);
},
get422: (customMessage) => {
get422: (customMessage?: string) => {
return createError(422, customMessage || 'bad data');
},
get400: (customMessage) => {
get400: (customMessage?: string) => {
return createError(400, customMessage);
},
get500: (customMessage) => {
get500: (customMessage?: string) => {
return customMessage ? createError(500, customMessage) : createError(500);
},
get403: () => {
return createError(403, 'can\'t use this filename');
get403: (message: string = 'can\'t use this filename') => {
return createError(403, message);
},
get503: () => {
return createError(500, 'resource temporarily unavailable');
},
get404: (customMessage) => {
get404: (customMessage?: string) => {
return createError(404, customMessage || 'no such package available');
},
};
const parseConfigFile = (config_path) => YAML.safeLoad(fs.readFileSync(config_path, 'utf8'));
const parseConfigFile = (configPath: string) => YAML.safeLoad(fs.readFileSync(configPath, 'utf8'));
/**
* Check whether the path already exist.
* @param {String} path
* @return {Boolean}
*/
function folder_exists(path) {
function folder_exists(path: string) {
try {
const stat = fs.statSync(path);
return stat.isDirectory();
@ -371,7 +371,7 @@ function folder_exists(path) {
* @param {String} path
* @return {Boolean}
*/
function fileExists(path) {
function fileExists(path: string) {
try {
const stat = fs.statSync(path);
return stat.isFile();
@ -380,7 +380,7 @@ function fileExists(path) {
}
}
function sortByName(packages) {
function sortByName(packages: Array<any>) {
return packages.sort(function(a, b) {
if (a.name < b.name) {
return -1;
@ -390,11 +390,11 @@ function sortByName(packages) {
});
}
function addScope(scope, packageName) {
function addScope(scope: string, packageName: string) {
return `@${scope}/${packageName}`;
}
function deleteProperties(propertiesToDelete, packageInfo) {
function deleteProperties(propertiesToDelete: Array<string>, packageInfo: Package) {
_.forEach(propertiesToDelete, (property) => {
delete packageInfo[property];
});
@ -402,7 +402,7 @@ function deleteProperties(propertiesToDelete, packageInfo) {
return packageInfo;
}
function addGravatarSupport(info) {
function addGravatarSupport(info: any) {
if (_.isString(_.get(info, 'latest.author.email'))) {
info.latest.author.avatar = generateGravatarUrl(info.latest.author.email);
} else {
@ -426,25 +426,27 @@ function addGravatarSupport(info) {
return info;
}
module.exports.addGravatarSupport = addGravatarSupport;
module.exports.deleteProperties = deleteProperties;
module.exports.addScope = addScope;
module.exports.sortByName = sortByName;
module.exports.folder_exists = folder_exists;
module.exports.file_exists = fileExists;
module.exports.parseInterval = parseInterval;
module.exports.semver_sort = semverSort;
module.exports.parse_address = parse_address;
module.exports.get_version = get_version;
module.exports.normalize_dist_tags = normalize_dist_tags;
module.exports.tag_version = tag_version;
module.exports.combineBaseUrl = combineBaseUrl;
module.exports.filter_tarball_urls = filter_tarball_urls;
module.exports.validate_metadata = validate_metadata;
module.exports.is_object = isObject;
module.exports.validate_name = validate_name;
module.exports.validate_package = validate_package;
module.exports.getWebProtocol = getWebProtocol;
module.exports.getLatestVersion = getLatestVersion;
module.exports.ErrorCode = ErrorCode;
module.exports.parseConfigFile = parseConfigFile;
export {
addGravatarSupport,
deleteProperties,
addScope,
sortByName,
folder_exists,
fileExists,
parseInterval,
semverSort,
parse_address,
get_version,
normalize_dist_tags,
tag_version,
combineBaseUrl,
filter_tarball_urls,
validate_metadata,
isObject,
validate_name,
validate_package,
getWebProtocol,
getLatestVersion,
ErrorCode,
parseConfigFile,
};

25
test/unit/auth.spec.js Normal file
View file

@ -0,0 +1,25 @@
// @flow
import Auth from '../../src/lib/auth';
jest.mock('../../src/lib/auth');
// $FlowFixMe
import configExample from './partials/config';
import AppConfig from '../../src/lib/config';
import {setup} from '../../src/lib/logger';
import type {IAuth, Config} from '@verdaccio/types';
setup(configExample.logs);
describe('AuthTest', () => {
test('should be defined', () => {
const config: Config = new AppConfig(configExample);
const auth: IAuth = new Auth(config);
expect(auth).toBeDefined();
expect(Auth).toHaveBeenCalledTimes(1);
});
});

View file

@ -10,7 +10,7 @@ import {readFile} from '../functional/lib/test.utils';
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`);
import type {IStorage} from '@verdaccio/types';
import type {IStorage, Config} from '@verdaccio/types';
setup([]);

View file

@ -1,5 +1,5 @@
const config = {
storage: __dirname + '/store/test-storage',
storage: `${__dirname}/store/test-storage`,
uplinks: {
'npmjs': {
'url': 'https://registry.npmjs.org/'
@ -17,6 +17,12 @@ const config = {
allow_publish: 'nobody'
},
'react': {
allow_access: '$all',
allow_publish: '$all',
proxy: 'npmjs'
},
'jquery': {
allow_access: '$all',
allow_publish: '$all',

View file

@ -1,7 +1,5 @@
'use strict';
let assert = require('assert');
let semver_sort = require('../../src/lib/utils').semver_sort;
let semverSort = require('../../src/lib/utils').semverSort;
import Storage from '../../src/lib/storage';
require('../../src/lib/logger').setup([]);
@ -57,9 +55,9 @@ describe('Storage._merge_versions versions', () => {
});
test('semver_sort', () => {
test('semverSort', () => {
assert.deepEqual(semver_sort(['1.2.3', '1.2', '1.2.3a', '1.2.3c', '1.2.3-b']),
assert.deepEqual(semverSort(['1.2.3', '1.2', '1.2.3a', '1.2.3c', '1.2.3-b']),
['1.2.3a',
'1.2.3-b',
'1.2.3c',

79
test/unit/store.spec.js Normal file
View file

@ -0,0 +1,79 @@
// @flow
import _ from 'lodash';
import httpMocks from 'node-mocks-http';
// $FlowFixMe
import configExample from './partials/config';
import AppConfig from '../../src/lib/config';
import Storage from '../../src/lib/storage';
import {setup} from '../../src/lib/logger';
import type {IStorageHandler, Config} from '@verdaccio/types';
setup(configExample.logs);
const generateStorage = function(): IStorageHandler {
const storageConfig = _.clone(configExample);
const storage = `./unit/partials/store/test-storage-store.spec`;
storageConfig.self_path = __dirname;
storageConfig.storage = storage;
const config: Config = new AppConfig(storageConfig);
return new Storage(config);
}
describe('StorageTest', () => {
jest.setTimeout(10000);
beforeAll((done)=> {
const storage: IStorageHandler = generateStorage();
var request = httpMocks.createRequest({
method: 'GET',
url: '/react',
params: {}
});
storage.getPackage({
name: 'react',
req: request,
callback: () => {
const stream = storage.get_tarball('react', 'react-16.1.0.tgz');
stream.on('content-length', function(content) {
if (content) {
expect(content).toBeTruthy();
done();
}
});
},
});
});
test('should be defined', () => {
const storage: IStorageHandler = generateStorage();
expect(storage).toBeDefined();
});
test('should fetch from uplink react metadata from nmpjs', (done) => {
const storage: IStorageHandler = generateStorage();
// $FlowFixMe
storage._syncUplinksMetadata('react', null, {}, (err, metadata, errors) => {
expect(metadata).toBeInstanceOf(Object);
done();
});
});
test('should fails on fetch from uplink metadata from nmpjs', (done) => {
const storage: IStorageHandler = generateStorage();
// $FlowFixMe
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
expect(errors).toBeInstanceOf(Array);
expect(errors[0][0].statusCode).toBe(404);
expect(errors[0][0].message).toMatch(/package doesn't exist on uplink/);
done();
});
});
});

View file

@ -6,13 +6,20 @@ import _ from 'lodash';
import configExample from './partials/config';
import {setup} from '../../src/lib/logger';
import type {UpLinkConf, Config} from '@verdaccio/types';
setup([]);
describe('UpStorge', () => {
const uplinkDefault = {
url: 'https://registry.npmjs.org/'
const uplinkDefault: UpLinkConf = {
url: 'https://registry.npmjs.org/',
fail_timeout: '5m',
max_fails: 2,
maxage: '2m',
timeout: '1m',
};
let generateProxy = (config: UpLinkConf = uplinkDefault) => {
const appConfig: Config = new AppConfig(configExample);

View file

@ -24,9 +24,9 @@ export default {
plugins: [
new webpack.DefinePlugin({
'__DEBUG__': true,
__DEBUG__: true,
'process.env.NODE_ENV': '"development"',
'__APP_VERSION__': `"${getPackageVersion()}"`,
__APP_VERSION__: `"${getPackageVersion()}"`,
}),
new HTMLWebpackPlugin({
title: 'Verdaccio',

View file

@ -18,9 +18,9 @@ const prodConf = {
plugins: [
new webpack.DefinePlugin({
'__DEBUG__': false,
__DEBUG__: false,
'process.env.NODE_ENV': '"production"',
'__APP_VERSION__': `"${getPackageVersion()}"`,
__APP_VERSION__: `"${getPackageVersion()}"`,
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,

829
yarn.lock

File diff suppressed because it is too large Load diff