diff --git a/src/api/install.ts b/src/api/install.ts index 336642de77..ca65eeecce 100644 --- a/src/api/install.ts +++ b/src/api/install.ts @@ -64,7 +64,7 @@ export type InstalledPackages = { export type TreeNode = { nodeId: string, - children: {[alias: string]: string}, // child nodeId by child alias name + children: () => {[alias: string]: string}, // child nodeId by child alias name pkg: InstalledPackage, depth: number, installable: boolean, @@ -440,10 +440,8 @@ async function installInContext ( installCtx.tree[nodeToBuild.nodeId] = { nodeId: nodeToBuild.nodeId, pkg: nodeToBuild.pkg, - get children() { - return buildTree(installCtx, nodeToBuild.nodeId, nodeToBuild.pkg.id, - installCtx.childrenByParentId[nodeToBuild.pkg.id], nodeToBuild.depth + 1, nodeToBuild.installable) - }, + children: () => buildTree(installCtx, nodeToBuild.nodeId, nodeToBuild.pkg.id, + installCtx.childrenByParentId[nodeToBuild.pkg.id], nodeToBuild.depth + 1, nodeToBuild.installable), depth: nodeToBuild.depth, installable: nodeToBuild.installable, } @@ -658,9 +656,7 @@ function buildTree ( ctx.tree[childNodeId] = { nodeId: childNodeId, pkg: ctx.installs[child.pkgId], - get children() { - return buildTree(ctx, childNodeId, child.pkgId, ctx.childrenByParentId[child.pkgId], depth + 1, installable); - }, + children: () => buildTree(ctx, childNodeId, child.pkgId, ctx.childrenByParentId[child.pkgId], depth + 1, installable), depth, installable, } diff --git a/src/install/installMultiple.ts b/src/install/installMultiple.ts index 7ca78c14c0..31de997c03 100644 --- a/src/install/installMultiple.ts +++ b/src/install/installMultiple.ts @@ -426,7 +426,7 @@ async function install ( ctx.tree[nodeId] = { nodeId, pkg: ctx.installs[fetchedPkg.id], - children: children.reduce((children, child) => { + children: () => children.reduce((children, child) => { children[child.alias] = child.nodeId return children }, {}), diff --git a/src/link/resolvePeers.ts b/src/link/resolvePeers.ts index 2809ae87da..085756f046 100644 --- a/src/link/resolvePeers.ts +++ b/src/link/resolvePeers.ts @@ -125,14 +125,15 @@ function resolvePeersOfNode ( return {} } - const parentPkgs = R.isEmpty(node.children) + const children = node.children(); + const parentPkgs = R.isEmpty(children) ? parentParentPkgs : Object.assign( {}, parentParentPkgs, - toPkgByName(R.keys(node.children).map(alias => ({alias: alias, node: ctx.tree[node.children[alias]]}))) + toPkgByName(R.keys(children).map(alias => ({alias: alias, node: ctx.tree[children[alias]]}))) ) - const unknownResolvedPeersOfChildren = resolvePeersOfChildren(node.children, parentPkgs, ctx, nodeId) + const unknownResolvedPeersOfChildren = resolvePeersOfChildren(children, parentPkgs, ctx, nodeId) const resolvedPeers = R.isEmpty(node.pkg.peerDependencies) ? {} @@ -177,7 +178,7 @@ function resolvePeersOfNode ( hardlinkedLocation, independent, optionalDependencies: node.pkg.optionalDependencies, - children: Object.assign(node.children, resolvedPeers), + children: Object.assign(children, resolvedPeers), depth: node.depth, absolutePath, prod: node.pkg.prod,