We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug
I use verdaccio-minio as a reference when implementing verdaccio-redis-storage, and I find a bug of the search API.
verdaccio-minio
verdaccio-minio/src/index.ts
Line 97 in 83912ae
public search(onPackage: Callback, onEnd: Callback, validate: (name: string) => boolean): void { this.retry(() => this.db.search(validate)) .then((results) => Promise.all(results.map((r) => this.stat(r, onPackage)))) .then(() => onEnd(null)) .catch((error) => onEnd(error)); } ... private async stat(name: string, onPackage: Callback): Promise<void> { const stat = await this.retry(() => this.client.stat(name)); onPackage(stat); <------ }
The onPackage(stat) is incorrect. The API is onPackage(stat, callback) (see _searchEachPackage below). Because it has a callback, it needs promisify.
onPackage(stat)
onPackage(stat, callback)
_searchEachPackage
promisify
https://github.com/verdaccio/verdaccio/blob/2a2ba63476e6babe05d5d7a3ce54d506e0c6ac18/src/lib/local-storage.ts#L613
public search(startKey: string, options: any): IReadTarball { const stream = new ReadTarball({ objectMode: true }); this._searchEachPackage( (item: Package, cb: CallbackAction): void => { // @ts-ignore if (item.time > parseInt(startKey, 10)) { this.getPackageMetadata(item.name, (err: VerdaccioError, data: Package): void => { if (err) { return cb(err); } // @ts-ignore const time = new Date(item.time).toISOString(); const result = prepareSearchPackage(data, time); if (_.isNil(result) === false) { stream.push(result); } cb(null); }); } else { cb(null); } }, function onEnd(err): void { if (err) { stream.emit('error', err); return; } stream.end(); } ); return stream; }
The unit test hides the issue because the mocked onPackage method is just a mock.
onPackage
verdaccio-minio/src/index.test.ts
Line 75 in 83912ae
To Fix
private async stat(name: string, onPackage: Callback): Promise<void> { const stat = await this.retry(() => this.client.stat(name)); return new Promise((resolve, reject) => { onPackage(stat, err => { if (err) reject(err); else resolve(); }); }); }
Reference https://github.com/openupm/verdaccio-redis-storage/blob/611076f001bbaa91837bbc1f589ed5f7eb447e9a/src/plugin.ts#L82
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
I use
verdaccio-minio
as a reference when implementing verdaccio-redis-storage, and I find a bug of the search API.verdaccio-minio/src/index.ts
Line 97 in 83912ae
The
onPackage(stat)
is incorrect. The API isonPackage(stat, callback)
(see_searchEachPackage
below). Because it has a callback, it needspromisify
.https://github.com/verdaccio/verdaccio/blob/2a2ba63476e6babe05d5d7a3ce54d506e0c6ac18/src/lib/local-storage.ts#L613
The unit test hides the issue because the mocked
onPackage
method is just a mock.verdaccio-minio/src/index.test.ts
Line 75 in 83912ae
To Fix
Reference https://github.com/openupm/verdaccio-redis-storage/blob/611076f001bbaa91837bbc1f589ed5f7eb447e9a/src/plugin.ts#L82
The text was updated successfully, but these errors were encountered: