verdaccio-memory
Advanced tools
Comparing version
@@ -17,8 +17,11 @@ 'use strict'; | ||
var DEFAULT_LIMIT = 1000; | ||
var LocalMemory = function () { | ||
function LocalMemory(config, logger) { | ||
function LocalMemory(config, options) { | ||
_classCallCheck(this, LocalMemory); | ||
this.config = config; | ||
this.logger = logger; | ||
this.limit = config.limit || DEFAULT_LIMIT; | ||
this.logger = options.logger; | ||
this.data = this._createEmtpyDatabase(); | ||
@@ -31,4 +34,12 @@ this.data.secret = config.checkSecretKey(this.data.secret); | ||
value: function add(name) { | ||
if (this.data.list.indexOf(name) === -1) { | ||
this.data.list.push(name); | ||
var list = this.data.list; | ||
if (list.length < this.limit) { | ||
if (list.indexOf(name) === -1) { | ||
list.push(name); | ||
} | ||
} else { | ||
this.logger.info({ limit: this.limit }, 'Storage memory has reached limit of @{limit} packages'); | ||
return new Error('Storage memory has reached limit of limit packages'); | ||
} | ||
@@ -39,5 +50,7 @@ } | ||
value: function remove(name) { | ||
var i = this.data.list.indexOf(name); | ||
var list = this.data.list; | ||
var i = list.indexOf(name); | ||
if (i !== -1) { | ||
this.data.list.splice(i, 1); | ||
list.splice(i, 1); | ||
} | ||
@@ -44,0 +57,0 @@ } |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.fileExist = undefined; | ||
exports.fileExist = exports.noSuchFile = undefined; | ||
@@ -28,4 +28,3 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var fs = new _memoryFs2.default(); | ||
var noSuchFile = 'ENOENT'; | ||
var noSuchFile = exports.noSuchFile = 'ENOENT'; | ||
var fileExist = exports.fileExist = 'EEXISTS'; | ||
@@ -46,3 +45,3 @@ | ||
var err = new Error(message); | ||
var err = (0, _httpErrors2.default)(404, message); | ||
// $FlowFixMe | ||
@@ -53,2 +52,4 @@ err.code = noSuchFile; | ||
var fs = new _memoryFs2.default(); | ||
var MemoryHandler = function () { | ||
@@ -65,5 +66,11 @@ function MemoryHandler(packageName, data, logger) { | ||
key: 'updatePackage', | ||
value: function updatePackage(name, updateHandler, onWrite, transformPackage, onEnd) { | ||
var json = this._getStorage(name); | ||
value: function updatePackage(pkgFileName, updateHandler, onWrite, transformPackage, onEnd) { | ||
var json = this._getStorage(pkgFileName); | ||
try { | ||
json = JSON.parse(json); | ||
} catch (err) { | ||
return onEnd(err); | ||
} | ||
updateHandler(json, function (err) { | ||
@@ -73,3 +80,7 @@ if (err) { | ||
} | ||
onWrite(name, transformPackage(json), onEnd); | ||
try { | ||
onWrite(pkgFileName, transformPackage(json), onEnd); | ||
} catch (err) { | ||
return onEnd(fSError('error on parse', 500)); | ||
} | ||
}); | ||
@@ -96,3 +107,10 @@ } | ||
value: function savePackage(name, value, cb) { | ||
this.data[name] = JSON.parse(JSON.stringify(value)); | ||
try { | ||
var json = JSON.stringify(value, null, '\t'); | ||
this.data[name] = json; | ||
} catch (err) { | ||
cb(fSError(err.message, 500)); | ||
} | ||
cb(null); | ||
@@ -104,4 +122,9 @@ } | ||
var json = this._getStorage(name); | ||
var isJson = typeof json === 'undefined'; | ||
cb(typeof json === 'undefined' ? noPackageFoundError() : null, json); | ||
try { | ||
cb(isJson ? noPackageFoundError() : null, JSON.parse(json)); | ||
} catch (err) { | ||
cb(noPackageFoundError()); | ||
} | ||
} | ||
@@ -111,7 +134,6 @@ }, { | ||
value: function writeTarball(name) { | ||
var uploadStream = new _streams.UploadTarball(); | ||
var temporalName = `/${name}`; | ||
setTimeout(function () { | ||
process.nextTick(function () { | ||
fs.exists(temporalName, function (exists) { | ||
@@ -136,2 +158,3 @@ if (exists) { | ||
uploadStream.abort = function () { | ||
uploadStream.emit('error', fSError('transmision aborted', 400)); | ||
file.end(); | ||
@@ -145,3 +168,3 @@ }; | ||
}); | ||
}, 10); | ||
}); | ||
@@ -157,3 +180,3 @@ return uploadStream; | ||
setTimeout(function () { | ||
process.nextTick(function () { | ||
fs.exists(pathName, function (exists) { | ||
@@ -168,9 +191,12 @@ if (!exists) { | ||
readStream.pipe(readTarballStream); | ||
readStream.on('error', function (error) { | ||
readTarballStream.emit('error', error); | ||
}); | ||
readTarballStream.abort = function () { | ||
readStream.close(); | ||
readStream.destroy(fSError('read has been aborted', 400)); | ||
}; | ||
} | ||
}); | ||
}, 10); | ||
}); | ||
@@ -177,0 +203,0 @@ return readTarballStream; |
{ | ||
"name": "verdaccio-memory", | ||
"version": "0.0.3", | ||
"version": "0.0.6", | ||
"description": "storage implementation in memory", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "npm run flow && npm run lint && jest", | ||
"lint": "eslint .", | ||
"pretest": "npm run lint", | ||
"test": "jest", | ||
"precommit": "lint-staged", | ||
"format": "prettier --single-quote --trailing-comma none --write \"{src,test}/**/*.js\"", | ||
"lint": "npm run flow && eslint .", | ||
"flow": "flow", | ||
"prepublish": "npm run build", | ||
"commitmsg": "commitlint -e $GIT_PARAMS", | ||
"build": "babel src/ --out-dir lib/ --copy-files --ignore ___tests___" | ||
}, | ||
"dependencies": { | ||
"@verdaccio/streams": "^0.0.2", | ||
"@verdaccio/streams": "^1.0.0", | ||
"http-errors": "1.6.2", | ||
@@ -19,20 +23,28 @@ "memory-fs": "^0.4.1" | ||
"devDependencies": { | ||
"@verdaccio/types": "0.1.1", | ||
"babel-cli": "6.24.1", | ||
"babel-core": "6.25.0", | ||
"babel-eslint": "7.2.3", | ||
"babel-jest": "21.2.0", | ||
"babel-plugin-flow-runtime": "0.11.1", | ||
"babel-plugin-istanbul": "4.1.4", | ||
"@commitlint/cli": "6.0.2", | ||
"@commitlint/config-conventional": "6.0.4", | ||
"@commitlint/travis-cli": "6.0.2", | ||
"@verdaccio/types": "0.2.0", | ||
"babel-cli": "6.26.0", | ||
"babel-core": "6.26.0", | ||
"babel-eslint": "8.2.1", | ||
"babel-jest": "22.1.0", | ||
"babel-plugin-flow-runtime": "0.15.0", | ||
"babel-plugin-istanbul": "4.1.5", | ||
"babel-plugin-transform-async-to-generator": "6.24.1", | ||
"babel-preset-env": "1.6.0", | ||
"babel-preset-env": "1.6.1", | ||
"babel-preset-flow": "6.23.0", | ||
"cross-env": "5.0.5", | ||
"eslint": "4.4.1", | ||
"cross-env": "5.1.3", | ||
"eslint": "4.16.0", | ||
"eslint-config-google": "0.9.1", | ||
"eslint-plugin-flowtype": "2.35.0", | ||
"eslint-plugin-jest": "21.2.0", | ||
"eslint-plugin-flowtype": "2.42.0", | ||
"eslint-config-prettier": "2.9.0", | ||
"eslint-plugin-jest": "21.7.0", | ||
"eslint-plugin-prettier": "2.5.0", | ||
"flow-bin": "0.52.0", | ||
"flow-runtime": "0.13.0", | ||
"jest": "21.2.1", | ||
"flow-runtime": "0.16.0", | ||
"husky": "0.14.3", | ||
"jest": "22.1.4", | ||
"lint-staged": "6.1.0", | ||
"prettier": "1.10.2", | ||
"rmdir-sync": "1.0.1" | ||
@@ -45,2 +57,14 @@ }, | ||
], | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"npm run format", | ||
"npm run lint", | ||
"git add" | ||
] | ||
}, | ||
"author": "Juan Picado <juanpicado19@gmail.com>", | ||
@@ -47,0 +71,0 @@ "private": false, |
@@ -9,2 +9,10 @@ # verdaccio-memory | ||
### Requirements | ||
This plugin won't work with versiones minimum as `3.0.0-alpha.7` | ||
``` | ||
npm install -g verdaccio@3.0.0-alpha.7 | ||
``` | ||
Complete configuration example: | ||
@@ -15,4 +23,4 @@ | ||
memory: | ||
cache: true | ||
``` | ||
limit: 1000 | ||
``` | ||
@@ -30,3 +38,3 @@ in `config.yaml` | ||
memory: | ||
cache: true | ||
limit: 1000 | ||
``` | ||
@@ -33,0 +41,0 @@ |
12961
19.83%8
14.29%243
15.17%45
21.62%27
42.11%+ Added
- Removed
Updated