Skip to content

Commit

Permalink
fix: improve type description
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling committed May 9, 2024
1 parent 4c92c6a commit 91a0cf4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/port/controller/PackageVersionFileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export class PackageVersionFileController extends AbstractController {

if (possibleFile) {
const route = `/${fullname}/${versionSpec}/files${possibleFile.path}${hasMeta ? '?meta' : ''}`;

ctx.redirect(route);

return;
}

Expand All @@ -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<PackageVersionFile | undefined>} 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;
}
}
}
Expand Down

0 comments on commit 91a0cf4

Please sign in to comment.