From 91a0cf47c18f1fa216b0454a807cdeb922865a25 Mon Sep 17 00:00:00 2001 From: chilingling Date: Thu, 9 May 2024 23:03:38 +0800 Subject: [PATCH] fix: improve type description --- .../PackageVersionFileController.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/port/controller/PackageVersionFileController.ts b/app/port/controller/PackageVersionFileController.ts index 60316bab0..6e9180867 100644 --- a/app/port/controller/PackageVersionFileController.ts +++ b/app/port/controller/PackageVersionFileController.ts @@ -152,7 +152,9 @@ export class PackageVersionFileController extends AbstractController { if (possibleFile) { const route = `/${fullname}/${versionSpec}/files${possibleFile.path}${hasMeta ? '?meta' : ''}`; + ctx.redirect(route); + return; } @@ -174,21 +176,19 @@ export class PackageVersionFileController extends AbstractController { /** * compatibility with unpkg * 1. try to match alias entry. e.g. accessing `index.js` or `index.json` using /index - * 2. if given path is directory and has `index.js` file, redirect to it. e.g. using `lib` alias to access `lib/index.js` - * @param packageVersion - * @param path - * @return + * 2. if given path is directory and has `index.js` file, redirect to it. e.g. using `lib` alias to access `lib/index.js` or `lib/index.json` + * @param {PackageVersion} packageVersion packageVersion + * @param {String} path filepath + * @return {Promise} return packageVersionFile or null */ - async #searchPossibleEntries(packageVersion: any, path: string) { - const possiblePath = [ `${path}.js`, `${path}.json`, `${path}/index.js` ]; + async #searchPossibleEntries(packageVersion: PackageVersion, path: string) { + const possiblePath = [ `${path}.js`, `${path}.json`, `${path}/index.js`, `${path}/index.json` ]; - const possibleFiles = possiblePath.map(pathItem => this.packageVersionFileService.showPackageVersionFile(packageVersion, pathItem)); + for (const pathItem of possiblePath) { + const file = await this.packageVersionFileService.showPackageVersionFile(packageVersion, pathItem); - const files = await Promise.allSettled(possibleFiles); - - for (const file of files) { - if (file.status === 'fulfilled' && file.value) { - return file.value; + if (file) { + return file; } } }