Skip to content

Commit

Permalink
getRepoUrl: Hardcode /tree/HEAD for simplicity.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Mar 12, 2024
1 parent 3582fe0 commit 5ddebfe
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/lib/getRepoUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import { PackageFile } from '../types/PackageFile'
import { PackageFileRepository } from '../types/PackageFileRepository'
import exists from './exists'

// extract the defaultBranchPath so it can be stripped in the final output
const defaultBranchPath = hostedGitInfo
.fromUrl('user/repo')
?.browse('')
.match(/(\/tree\/[a-zA-Z]+)/)?.[0]
const regexDefaultBranchPath = new RegExp(`${defaultBranchPath}$`)

/** Gets the repo url of an installed package. */
async function getPackageRepo(
packageName: string,
Expand Down Expand Up @@ -41,9 +34,6 @@ async function getPackageRepo(
return null
}

/** Remove the default branch path from a git url. */
const cleanRepoUrl = (url: string) => url.replace(/\/$/, '').replace(regexDefaultBranchPath, '')

/**
* @param packageName A package name as listed in package.json's dependencies list
* @param packageJson Optional param to specify a object representation of a package.json file instead of loading from node_modules
Expand Down Expand Up @@ -91,7 +81,8 @@ async function getRepoUrl(
if (typeof gitURL === 'string' && typeof directory === 'string') {
const hostedGitURL = hostedGitInfo.fromUrl(gitURL)?.browse(directory)
if (hostedGitURL !== undefined) {
return cleanRepoUrl(hostedGitURL)
// Remove the default branch path (/tree/HEAD) from a git url
return hostedGitURL.replace(/\/$/, '').replace(/\/tree\/HEAD$/, '')
}
}
return null
Expand Down

0 comments on commit 5ddebfe

Please sign in to comment.