Skip to content

fix: dependency path is undefined #9013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 12, 2025
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
6 changes: 6 additions & 0 deletions .changeset/tall-geese-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"electron-builder": patch
---

fix: dependency path is undefined
16 changes: 10 additions & 6 deletions packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,16 @@ export class Packager {
if (config.buildDependenciesFromSource === true && platform.nodeName !== process.platform) {
log.info({ reason: "platform is different and buildDependenciesFromSource is set to true" }, "skipped dependencies rebuild")
} else {
await installOrRebuild(config, this.appDir, {
frameworkInfo,
platform: platform.nodeName,
arch: Arch[arch],
productionDeps: this.getNodeDependencyInfo(null, false) as Lazy<Array<NodeModuleDirInfo>>,
})
await installOrRebuild(
config,
{ appDir: this.appDir, projectDir: this.projectDir },
{
frameworkInfo,
platform: platform.nodeName,
arch: Arch[arch],
productionDeps: this.getNodeDependencyInfo(null, false) as Lazy<Array<NodeModuleDirInfo>>,
}
)
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion packages/app-builder-lib/src/util/appFileCopier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,18 @@ function validateFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {

/** @internal */
export async function computeNodeModuleFileSets(platformPackager: PlatformPackager<any>, mainMatcher: FileMatcher): Promise<Array<ResolvedFileSet>> {
const deps = await getNodeModules(platformPackager.info.appDir)
const projectDir = platformPackager.info.projectDir
const appDir = platformPackager.info.appDir

let deps = await getNodeModules(appDir)
if (projectDir !== appDir && deps.length === 0) {
const packageJson = require(path.join(appDir, "package.json"))
if (Object.keys(packageJson.dependencies || {}).length > 0) {
log.debug({ projectDir, appDir }, "no node_modules in app dir, trying to find in project dir")
deps = await getNodeModules(projectDir)
}
}

log.debug({ nodeModules: deps }, "collected node modules")

const nodeModuleExcludedExts = getNodeModuleExcludedExts(platformPackager)
Expand Down
21 changes: 12 additions & 9 deletions packages/app-builder-lib/src/util/yarn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as electronRebuild from "@electron/rebuild"
import { getProjectRootPath } from "@electron/rebuild/lib/search-module"
import { RebuildMode } from "@electron/rebuild/lib/types"
import { asArray, log, spawn } from "builder-util"
import { pathExists } from "fs-extra"
Expand All @@ -12,7 +11,7 @@ import { PM, detect, getPackageManagerVersion } from "../node-module-collector"
import { NodeModuleDirInfo } from "./packageDependencies"
import { rebuild as remoteRebuild } from "./rebuild/rebuild"

export async function installOrRebuild(config: Configuration, appDir: string, options: RebuildOptions, forceInstall = false) {
export async function installOrRebuild(config: Configuration, { appDir, projectDir }: DirectoryPaths, options: RebuildOptions, forceInstall = false) {
const effectiveOptions: RebuildOptions = {
buildFromSource: config.buildDependenciesFromSource === true,
additionalArgs: asArray(config.npmArgs),
Expand All @@ -29,9 +28,9 @@ export async function installOrRebuild(config: Configuration, appDir: string, op
}

if (forceInstall || !isDependenciesInstalled) {
await installDependencies(config, appDir, effectiveOptions)
await installDependencies(config, { appDir, projectDir }, effectiveOptions)
} else {
await rebuild(config, appDir, effectiveOptions)
await rebuild(config, { appDir, projectDir }, effectiveOptions)
}
}

Expand Down Expand Up @@ -91,12 +90,11 @@ async function checkYarnBerry(pm: PM) {
return version.split(".")[0] >= "2"
}

async function installDependencies(config: Configuration, appDir: string, options: RebuildOptions): Promise<any> {
async function installDependencies(config: Configuration, { appDir, projectDir }: DirectoryPaths, options: RebuildOptions): Promise<any> {
const platform = options.platform || process.platform
const arch = options.arch || process.arch
const additionalArgs = options.additionalArgs

const projectDir = await getProjectRootPath(appDir)
const pm = await detect({ cwd: projectDir })
log.info({ pm, platform, arch, projectDir, appDir }, `installing production dependencies`)
const execArgs = ["install"]
Expand All @@ -123,7 +121,7 @@ async function installDependencies(config: Configuration, appDir: string, option

// Some native dependencies no longer use `install` hook for building their native module, (yarn 3+ removed implicit link of `install` and `rebuild` steps)
// https://github.com/electron-userland/electron-builder/issues/8024
return rebuild(config, appDir, options)
return rebuild(config, { appDir, projectDir }, options)
}

export async function nodeGypRebuild(platform: NodeJS.Platform, arch: string, frameworkInfo: DesktopFrameworkInfo) {
Expand Down Expand Up @@ -170,8 +168,13 @@ export interface RebuildOptions {
additionalArgs?: Array<string> | null
}

export interface DirectoryPaths {
appDir: string
projectDir: string
}

/** @internal */
export async function rebuild(config: Configuration, appDir: string, options: RebuildOptions) {
export async function rebuild(config: Configuration, { appDir, projectDir }: DirectoryPaths, options: RebuildOptions) {
const configuration = {
dependencies: await options.productionDeps.value,
nodeExecPath: process.execPath,
Expand Down Expand Up @@ -205,7 +208,7 @@ export async function rebuild(config: Configuration, appDir: string, options: Re
arch,
platform,
buildFromSource,
projectRootPath: await getProjectRootPath(appDir),
projectRootPath: projectDir,
mode: (config.nativeRebuilder as RebuildMode) || "sequential",
disablePreGypCopy: true,
}
Expand Down
5 changes: 4 additions & 1 deletion packages/electron-builder/src/cli/install-app-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export async function installAppDeps(args: any) {
// if two package.json — force full install (user wants to install/update app deps in addition to dev)
await installOrRebuild(
config,
appDir,
{
appDir,
projectDir,
},
{
frameworkInfo: { version, useCustomDist: true },
platform: args.platform,
Expand Down
Loading