Skip to content

Commit

Permalink
chore: refactor electronDist logic to avoid unnecessary/misleading …
Browse files Browse the repository at this point in the history
…console logs (#8639)
  • Loading branch information
mmaietta authored Oct 30, 2024
1 parent 3d31094 commit 2800662
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-peas-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

chore: refactor electron dist logic to avoid unnecessary console logs
2 changes: 1 addition & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/app-builder-lib/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ Configuration in the same way as `afterPack` (see above).
readonly beforeBuild?: Hook<BeforeBuildContext, boolean | void> | 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<PrepareApplicationStageDirectoryOptions, string> | string | null
}
Expand Down
28 changes: 17 additions & 11 deletions packages/app-builder-lib/src/electron/ElectronFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}

Expand Down

0 comments on commit 2800662

Please sign in to comment.