diff --git a/.changeset/small-peas-drop.md b/.changeset/small-peas-drop.md new file mode 100644 index 00000000000..41c74667f79 --- /dev/null +++ b/.changeset/small-peas-drop.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +chore: refactor electron dist logic to avoid unnecessary console logs diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index a1599a67bf8..8dd1de626f6 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -7082,7 +7082,7 @@ ] } ], - "description": "The function (or path to file or module id) to be run when staging the electron artifact environment.\nReturns the path to custom Electron build (e.g. `~/electron/out/R`) or folder of electron zips. Zip files must follow the pattern `electron-v${version}-${platformName}-${arch}.zip`, otherwise it will be assumed to be an unpacked Electron app directory" + "description": "The function (or path to file or module id) to be run when staging the electron artifact environment.\nReturns the path to custom Electron build (e.g. `~/electron/out/R`) or folder of electron zips.\n\nZip files must follow the pattern `electron-v${version}-${platformName}-${arch}.zip`, otherwise it will be assumed to be an unpacked Electron app directory" }, "electronDownload": { "$ref": "#/definitions/ElectronDownloadOptions", diff --git a/packages/app-builder-lib/src/configuration.ts b/packages/app-builder-lib/src/configuration.ts index edf5556cd9e..37f55ca3189 100644 --- a/packages/app-builder-lib/src/configuration.ts +++ b/packages/app-builder-lib/src/configuration.ts @@ -356,7 +356,9 @@ Configuration in the same way as `afterPack` (see above). readonly beforeBuild?: Hook | string | null /** * The function (or path to file or module id) to be run when staging the electron artifact environment. - * Returns the path to custom Electron build (e.g. `~/electron/out/R`) or folder of electron zips. Zip files must follow the pattern `electron-v${version}-${platformName}-${arch}.zip`, otherwise it will be assumed to be an unpacked Electron app directory + * Returns the path to custom Electron build (e.g. `~/electron/out/R`) or folder of electron zips. + * + * Zip files must follow the pattern `electron-v${version}-${platformName}-${arch}.zip`, otherwise it will be assumed to be an unpacked Electron app directory */ readonly electronDist?: Hook | string | null } diff --git a/packages/app-builder-lib/src/electron/ElectronFramework.ts b/packages/app-builder-lib/src/electron/ElectronFramework.ts index 21557d03fd6..3ac3c2d7616 100644 --- a/packages/app-builder-lib/src/electron/ElectronFramework.ts +++ b/packages/app-builder-lib/src/electron/ElectronFramework.ts @@ -185,22 +185,28 @@ export async function createElectronFrameworkSupport(configuration: Configuratio async function unpack(prepareOptions: PrepareApplicationStageDirectoryOptions, options: ElectronDownloadOptions, distMacOsAppName: string) { const { packager, appOutDir, platformName } = prepareOptions - let customElectronDist = packager.config.electronDist - try { - customElectronDist = await resolveFunction(packager.appInfo.type, customElectronDist, "electronDist") - } catch (_e: any) { - // ignored. We already log in `resolveFunction` if it fails, and we ignore here because electronDist could just be a folder path (backward compatibility) + const electronDist = packager.config.electronDist || null + let dist: string | null = null + // check if supplied a custom electron distributable/fork/predownloaded directory + if (typeof electronDist === "string") { + let resolvedDist: string + // check if custom electron hook file for import resolving + if ((await statOrNull(electronDist))?.isFile()) { + const customElectronDist: any = await resolveFunction(packager.appInfo.type, electronDist, "electronDist") + resolvedDist = await Promise.resolve(typeof customElectronDist === "function" ? customElectronDist(prepareOptions) : customElectronDist) + } else { + resolvedDist = electronDist + } + dist = path.isAbsolute(resolvedDist) ? resolvedDist : path.resolve(packager.projectDir, resolvedDist) } - let dist: string | undefined | null = await Promise.resolve(typeof customElectronDist === "function" ? customElectronDist(prepareOptions) : customElectronDist) if (dist != null) { const zipFile = `electron-v${options.version}-${platformName}-${options.arch}.zip` - const resolvedDist = path.isAbsolute(dist) ? dist : path.resolve(packager.projectDir, dist) - if ((await statOrNull(path.join(resolvedDist, zipFile))) != null) { - log.info({ resolvedDist, zipFile }, "resolved electronDist") - options.cache = resolvedDist + if ((await statOrNull(path.join(dist, zipFile))) != null) { + log.info({ dist, zipFile }, "resolved electronDist") + options.cache = dist dist = null } else { - log.warn({ electronDist: log.filePath(resolvedDist), expectedFile: zipFile }, "custom electronDist provided but no assets found") + log.info({ electronDist: log.filePath(dist), expectedFile: zipFile }, "custom electronDist provided but no zip found; assuming unpacked electron directory.") } }