Skip to content

Commit

Permalink
refactor: use parseDepPath instead
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Dec 26, 2024
1 parent 0dce3be commit 65e3939
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions releasing/plugin-commands-deploy/src/createDeployFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function createDeployFiles ({
deployedProjectRealPath,
projectRootDirRealPath,
})
const depPath = createFileUrlDepPath({ resolvedPath: projectRootDirRealPath }, allProjects)
const depPath = createFileUrlDepPath({ resolvedPath: projectRootDirRealPath, suffix: '' }, allProjects)
targetPackageSnapshots[depPath] = packageSnapshot
}

Expand Down Expand Up @@ -257,47 +257,32 @@ function convertResolvedDependencies (
interface ResolveLinkOrFileResult {
scheme: 'link:' | 'file:'
resolvedPath: string
suffix?: string
suffix: string
}

function resolveLinkOrFile (spec: string, opts: Pick<ConvertOptions, 'lockfileDir' | 'projectRootDirRealPath'>): ResolveLinkOrFileResult | undefined {
const { id, peersSuffix: suffix } = dp.parseDepPath(spec)
const { lockfileDir, projectRootDirRealPath } = opts

if (spec.startsWith('link:')) {
const targetPath = spec.slice('link:'.length)
if (id.startsWith('link:')) {
const targetPath = id.slice('link:'.length)
return {
scheme: 'link:',
resolvedPath: path.resolve(projectRootDirRealPath, targetPath),
suffix,
}
}

if (spec.startsWith('file:')) {
const targetPath = spec.slice('file:'.length)
if (id.startsWith('file:')) {
const targetPath = id.slice('file:'.length)
return {
scheme: 'file:',
resolvedPath: path.resolve(lockfileDir, targetPath),
suffix,
}
}

const { nonSemverVersion, patchHash, peersSuffix, version } = dp.parse(spec)
if (!nonSemverVersion) return undefined

if (version) {
throw new Error(`Something goes wrong, version should be undefined but isn't: ${version}`)
}

const parseResult = resolveLinkOrFile(nonSemverVersion, opts)
if (!parseResult) return undefined

if (parseResult.suffix) {
throw new Error(`Something goes wrong, suffix should be undefined but isn't: ${parseResult.suffix}`)
}

if (patchHash || peersSuffix) {
parseResult.suffix = `${patchHash ?? ''}${peersSuffix ?? ''}`
}

return parseResult
return undefined
}

function createFileUrlDepPath (
Expand Down

0 comments on commit 65e3939

Please sign in to comment.