Skip to content

Commit

Permalink
fix: correct native dependency tree mismatch in app-builder rebuild (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
leey0818 authored Sep 13, 2024
1 parent 27a8a60 commit 55671bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/chatty-rice-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"electron-builder": patch
---

fix: correct native dependency tree mismatch in app-builder rebuild
8 changes: 4 additions & 4 deletions packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export class Packager {

private nodeDependencyInfo = new Map<string, Lazy<Array<any>>>()

getNodeDependencyInfo(platform: Platform | null): Lazy<Array<NodeModuleInfo | NodeModuleDirInfo>> {
let key = ""
getNodeDependencyInfo(platform: Platform | null, flatten: boolean = true): Lazy<Array<NodeModuleInfo | NodeModuleDirInfo>> {
let key = "" + flatten.toString()
let excludedDependencies: Array<string> | null = null
if (platform != null && this.framework.getExcludedDependencies != null) {
excludedDependencies = this.framework.getExcludedDependencies(platform)
Expand All @@ -145,7 +145,7 @@ export class Packager {

let result = this.nodeDependencyInfo.get(key)
if (result == null) {
result = createLazyProductionDeps(this.appDir, excludedDependencies)
result = createLazyProductionDeps(this.appDir, excludedDependencies, flatten)
this.nodeDependencyInfo.set(key, result)
}
return result
Expand Down Expand Up @@ -543,7 +543,7 @@ export class Packager {
frameworkInfo,
platform: platform.nodeName,
arch: Arch[arch],
productionDeps: this.getNodeDependencyInfo(null) as Lazy<Array<NodeModuleDirInfo>>,
productionDeps: this.getNodeDependencyInfo(null, false) as Lazy<Array<NodeModuleDirInfo>>,
})
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/app-builder-lib/src/util/packageDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Lazy } from "lazy-val"
import { executeAppBuilderAsJson } from "./appBuilder"

export function createLazyProductionDeps(projectDir: string, excludedDependencies: Array<string> | null) {
export function createLazyProductionDeps<T extends boolean>(projectDir: string, excludedDependencies: Array<string> | null, flatten: T) {
return new Lazy(async () => {
const args = ["node-dep-tree", "--flatten", "--dir", projectDir]
const args = ["node-dep-tree", "--dir", projectDir]
if (flatten) args.push("--flatten")
if (excludedDependencies != null) {
for (const name of excludedDependencies) {
args.push("--exclude-dep", name)
}
}
return executeAppBuilderAsJson<Array<any>>(args)
return executeAppBuilderAsJson<Array<T extends true ? NodeModuleInfo : NodeModuleDirInfo>>(args)
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/cli/install-app-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function installAppDeps(args: any) {
frameworkInfo: { version, useCustomDist: true },
platform: args.platform,
arch: args.arch,
productionDeps: createLazyProductionDeps(appDir, null),
productionDeps: createLazyProductionDeps(appDir, null, false),
},
appDir !== projectDir
)
Expand Down

0 comments on commit 55671bd

Please sign in to comment.