diff --git a/.changeset/stale-candles-boil.md b/.changeset/stale-candles-boil.md new file mode 100644 index 0000000000..f60503ac60 --- /dev/null +++ b/.changeset/stale-candles-boil.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": minor +--- + +feat: add `beforePack` hook to build process with the same payload interface as that of `afterPack` diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index bd2bcd5890..e24e92cc78 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -5820,6 +5820,20 @@ ], "description": "The function (or path to file or module id) to be [run after all artifacts are build](#afterAllArtifactBuild)." }, + "beforePack": { + "anyOf": [ + { + "typeof": "function" + }, + { + "type": [ + "null", + "string" + ] + } + ], + "description": "The function (or path to file or module id) to be [run before pack](#beforepack)" + }, "afterPack": { "anyOf": [ { diff --git a/packages/app-builder-lib/src/configuration.ts b/packages/app-builder-lib/src/configuration.ts index e2bf3f82bc..e243b46aa5 100644 --- a/packages/app-builder-lib/src/configuration.ts +++ b/packages/app-builder-lib/src/configuration.ts @@ -195,6 +195,8 @@ export interface Configuration extends PlatformSpecificBuildOptions { */ readonly framework?: string | null + readonly beforePack?: ((context: BeforePackContext) => Promise | any) | string | null + /** * The function (or path to file or module id) to be [run after pack](#afterpack) (but before pack into distributable format and sign). */ @@ -262,7 +264,7 @@ export interface Configuration extends PlatformSpecificBuildOptions { readonly removePackageKeywords?: boolean } -export interface AfterPackContext { +interface PackContext { readonly outDir: string readonly appOutDir: string readonly packager: PlatformPackager @@ -270,6 +272,8 @@ export interface AfterPackContext { readonly arch: Arch readonly targets: Array } +export type AfterPackContext = PackContext +export type BeforePackContext = PackContext export interface MetadataDirectories { /** diff --git a/packages/app-builder-lib/src/platformPackager.ts b/packages/app-builder-lib/src/platformPackager.ts index 0bf08a5d9d..911397bed4 100644 --- a/packages/app-builder-lib/src/platformPackager.ts +++ b/packages/app-builder-lib/src/platformPackager.ts @@ -201,6 +201,18 @@ export abstract class PlatformPackager return } + const beforePack = resolveFunction(this.config.beforePack, "beforePack") + if (beforePack != null) { + await beforePack({ + appOutDir, + outDir, + arch, + targets, + packager: this, + electronPlatformName: platformName, + }) + } + await this.info.installAppDependencies(this.platform, arch) if (this.info.cancellationToken.cancelled) {