Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-hotels-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

Detected circular dependencies and add debug logs for nodeModulesCollector, and refactored YarnNodeModulesCollector to extend NpmNodeModulesCollector.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export abstract class NodeModulesCollector {
result[parentKey] = { dependencies: [] }
}
result[parentKey].dependencies!.push(newKey)

if (node.__circularDependencyDetected) {
continue
}
flatten(value, newKey)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NodeModulesCollector } from "./nodeModulesCollector"
import { DependencyTree } from "./types"
import { log } from "builder-util"

export class NpmNodeModulesCollector extends NodeModulesCollector {
constructor(rootDir: string) {
Expand All @@ -17,8 +18,11 @@ export class NpmNodeModulesCollector extends NodeModulesCollector {
removeNonProductionDependencie(tree: DependencyTree) {
const dependencies = tree.dependencies || {}
const _dependencies = tree._dependencies || {}
if (dependencies && Object.keys(dependencies).length === 0) {
if (Object.keys(_dependencies).length > 0 && Object.keys(dependencies).length === 0) {
tree.dependencies = this.allDependencies.get(`${tree.name}@${tree.version}`)?.dependencies || {}
tree.__circularDependencyDetected = true
log.debug({ name: tree.name, version: tree.version }, "circular dependency detected")
return
}

for (const [key, value] of Object.entries(dependencies)) {
Expand Down
8 changes: 4 additions & 4 deletions packages/app-builder-lib/src/node-module-collector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export interface NodeModuleInfo {
}

export interface DependencyTree {
readonly version?: string
readonly name?: string
readonly from?: string
readonly workspaces?: string[]
readonly name: string
readonly version: string
readonly path: string
readonly workspaces?: string[]
__circularDependencyDetected?: boolean
dependencies?: {
[packageName: string]: DependencyTree
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
import { NodeModulesCollector } from "./nodeModulesCollector"
import { DependencyTree } from "./types"
import { NpmNodeModulesCollector } from "./npmNodeModulesCollector"

export class YarnNodeModulesCollector extends NodeModulesCollector {
export class YarnNodeModulesCollector extends NpmNodeModulesCollector {
constructor(rootDir: string) {
super(rootDir)
}

getCommand(): string {
return process.platform === "win32" ? "npm.cmd" : "npm"
}

getArgs(): string[] {
return ["list", "-a", "--include", "prod", "--include", "optional", "--omit", "dev", "--json", "--long", "--silent"]
}

removeNonProductionDependencie(tree: DependencyTree) {
const dependencies = tree.dependencies || {}
const _dependencies = tree._dependencies || {}
if (dependencies && Object.keys(dependencies).length === 0) {
tree.dependencies = this.allDependencies.get(`${tree.name}@${tree.version}`)?.dependencies || {}
}

for (const [key, value] of Object.entries(dependencies)) {
if (!_dependencies[key] || Object.keys(value).length === 0) {
delete dependencies[key]
continue
}
this.removeNonProductionDependencie(value)
}
}
}
Loading
Loading