Skip to content

Commit

Permalink
refactor: resolve-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Jul 16, 2020
1 parent 8ed9684 commit f7178fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
7 changes: 5 additions & 2 deletions packages/resolve-dependencies/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ export default async function (
const proceed = importer.hasRemovedDependencies || importer.wantedDependencies.some((wantedDep) => wantedDep['isNew'])
const resolveOpts = {
currentDepth: 0,
parentDependsOnPeers: proceed,
parentNodeId: `>${importer.id}>`,
parentPkg: {
installable: true,
nodeId: `>${importer.id}>`,
pkgId: importer.id,
},
proceed,
resolvedDependencies: {
...projectSnapshot.dependencies,
Expand Down
28 changes: 10 additions & 18 deletions packages/resolve-dependencies/src/resolveDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ export default async function resolveDependencies (
wantedDependencies: Array<WantedDependency & { updateDepth?: number }>,
options: {
currentDepth: number,
dependentId?: string,
parentIsInstallable?: boolean,
parentNodeId: string,
parentPkg: Pick<PkgAddress, 'nodeId' | 'installable' | 'pkgId'>,
// If the package has been updated, the dependencies
// which were used by the previous version are passed
// via this option
Expand All @@ -228,9 +226,7 @@ export default async function resolveDependencies (
})
const resolveDepOpts = {
currentDepth: options.currentDepth,
dependentId: options.dependentId,
parentIsInstallable: options.parentIsInstallable,
parentNodeId: options.parentNodeId,
parentPkg: options.parentPkg,
preferredVersions,
workspacePackages: options.workspacePackages,
}
Expand Down Expand Up @@ -284,9 +280,7 @@ export default async function resolveDependencies (
}),
{
currentDepth: options.currentDepth + 1,
dependentId: resolveDependencyResult.pkgId,
parentIsInstallable: resolveDependencyResult.installable,
parentNodeId: resolveDependencyResult.nodeId,
parentPkg: resolveDependencyResult,
preferredDependencies: resolveDependencyResult.updated
? extendedWantedDep.infoFromLockfile?.resolvedDependencies
: undefined,
Expand Down Expand Up @@ -484,9 +478,7 @@ type ResolveDependencyOptions = {
currentResolution?: Resolution,
depPath?: string,
dependencyLockfile?: PackageSnapshot,
dependentId?: string,
parentIsInstallable?: boolean,
parentNodeId: string,
parentPkg: Pick<PkgAddress, 'nodeId' | 'installable' | 'pkgId'>,
pkgId?: string,
preferredVersions: PreferredVersions,
proceed: boolean,
Expand All @@ -505,7 +497,7 @@ async function resolveDependency (
options.workspacePackages &&
wantedDepIsLocallyAvailable(options.workspacePackages, wantedDependency, { defaultTag: ctx.defaultTag, registry: ctx.registries.default }))
const proceed = update || options.proceed || !options.currentResolution
const parentIsInstallable = options.parentIsInstallable === undefined || options.parentIsInstallable
const parentIsInstallable = options.parentPkg.installable === undefined || options.parentPkg.installable

const currentLockfileContainsTheDep = options.depPath ? Boolean(ctx.currentLockfile.packages?.[options.depPath]) : undefined
const depIsLinked = Boolean(
Expand Down Expand Up @@ -547,20 +539,20 @@ async function resolveDependency (
pref: wantedDependency.pref,
version: wantedDependency.alias ? wantedDependency.pref : undefined,
},
parents: nodeIdToParents(options.parentNodeId, ctx.resolvedPackagesByPackageId),
parents: nodeIdToParents(options.parentPkg.nodeId, ctx.resolvedPackagesByPackageId),
prefix: ctx.prefix,
reason: 'resolution_failure',
})
return null
}
err.pkgsStack = nodeIdToParents(options.parentNodeId, ctx.resolvedPackagesByPackageId)
err.pkgsStack = nodeIdToParents(options.parentPkg.nodeId, ctx.resolvedPackagesByPackageId)
throw err
}

dependencyResolvedLogger.debug({
resolution: pkgResponse.body.id,
wanted: {
dependentId: options.dependentId,
dependentId: options.parentPkg.pkgId,
name: wantedDependency.alias,
rawSpec: wantedDependency.pref,
},
Expand Down Expand Up @@ -593,7 +585,7 @@ async function resolveDependency (

// For the root dependency dependentId will be undefined,
// that's why checking it
if (options.dependentId && nodeIdContainsSequence(options.parentNodeId, options.dependentId, pkgResponse.body.id)) {
if (options.parentPkg.pkgId && nodeIdContainsSequence(options.parentPkg.nodeId, options.parentPkg.pkgId, pkgResponse.body.id)) {
return null
}

Expand Down Expand Up @@ -654,7 +646,7 @@ async function resolveDependency (
}

// using colon as it will never be used inside a package ID
const nodeId = createNodeId(options.parentNodeId, pkgResponse.body.id)
const nodeId = createNodeId(options.parentPkg.nodeId, pkgResponse.body.id)

const currentIsInstallable = (
ctx.force ||
Expand Down

0 comments on commit f7178fa

Please sign in to comment.