Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ 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, {
await installOrRebuild(config, this.appDir, this.projectDir, {
frameworkInfo,
platform: platform.nodeName,
arch: Arch[arch],
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
16 changes: 7 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: string, projectDir: string, options: RebuildOptions, forceInstall = false) {
Comment thread
mmaietta marked this conversation as resolved.
Outdated
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: string, projectDir: string, 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 @@ -171,7 +169,7 @@ export interface RebuildOptions {
}

/** @internal */
export async function rebuild(config: Configuration, appDir: string, options: RebuildOptions) {
export async function rebuild(config: Configuration, appDir: string, projectDir: string, options: RebuildOptions) {
const configuration = {
dependencies: await options.productionDeps.value,
nodeExecPath: process.execPath,
Expand Down Expand Up @@ -205,7 +203,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
1 change: 1 addition & 0 deletions packages/electron-builder/src/cli/install-app-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function installAppDeps(args: any) {
await installOrRebuild(
config,
appDir,
projectDir,
{
frameworkInfo: { version, useCustomDist: true },
platform: args.platform,
Expand Down
Loading