Skip to content

Commit 7121939

Browse files
@jotadevelopersergiohgz
authored andcommitted
fix: missing error code
1 parent 9ea68cd commit 7121939

File tree

6 files changed

+48
-13
lines changed

6 files changed

+48
-13
lines changed

plugins/local-storage/.npmignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ test/
1818
*.tmp-*
1919
_storage/
2020
circle.yml
21-
travis.yml
21+
travis.yml
22+
*.md
23+
coverage/
24+
jest.config.js
25+
jestEnvironment.js

plugins/local-storage/package-lock.json

Lines changed: 25 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/local-storage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@verdaccio/file-locking": "^0.0.5",
1515
"@verdaccio/streams": "^0.0.2",
1616
"async": "2.5.0",
17-
"http-errors": "1.4.0",
17+
"http-errors": "1.6.2",
1818
"lodash": "4.17.4",
1919
"mkdirp": "0.5.1"
2020
},

plugins/local-storage/src/___tests___/local-fs.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import mkdirp from 'mkdirp';
55
import fs from 'fs';
66
import rm from 'rmdir-sync';
77
import type {ILocalFS, Logger} from '@verdaccio/types';
8-
import LocalFS from '../local-fs';
8+
import LocalFS, {fileExist} from '../local-fs';
99

1010
let localFs: ILocalFS;
1111
let localTempStorage: string;
@@ -75,6 +75,14 @@ describe('Local FS test', ()=> {
7575
});
7676
});
7777

78+
test('createJSON() fails by fileExist', (done) => {
79+
localFs.createJSON(path.join(localTempStorage, 'package5'), '{data:6}', (err)=> {
80+
expect(err).not.toBeNull();
81+
expect(err.code).toBe(fileExist);
82+
done();
83+
});
84+
});
85+
7886
test('deleteJSON()', (done) => {
7987
localFs.deleteJSON(path.join(localTempStorage, 'package5'), (err)=> {
8088
expect(err).toBeNull();

plugins/local-storage/src/local-data.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ import type {ILocalData, ILocalFS, StorageList, LocalStorage, Logger, Config} fr
5151
* @return {Error|*}
5252
*/
5353
remove(name: string) {
54-
const i = this.data.list.indexOf(name);
55-
if (i !== -1) {
56-
this.data.list.splice(i, 1);
54+
const pkgName = this.get().indexOf(name);
55+
if (pkgName !== -1) {
56+
this.data.list.splice(pkgName, 1);
5757
}
58+
5859
return this.sync();
5960
}
6061

plugins/local-storage/src/local-fs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import {UploadTarball, ReadTarball} from '@verdaccio/streams';
1111
import {unlockFile, readFile} from '@verdaccio/file-locking';
1212
import type {ILocalFS, Callback, Logger} from '@verdaccio/types';
1313

14-
const fileExist: string = 'EEXISTS';
15-
const noSuchFile: string = 'ENOENT';
14+
export const fileExist: string = 'EEXISTS';
15+
export const noSuchFile: string = 'ENOENT';
1616

1717
const fSError = function(message: string): HttpError {
1818
const err: HttpError = createError(409, message);
19+
err.code = message;
20+
1921
return err;
2022
};
2123

0 commit comments

Comments
 (0)