From de87b1a99cc9bb42aa749328cede152f8ea0d6fb Mon Sep 17 00:00:00 2001 From: Jason Cassidy <47318351+jcassidyav@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:21:13 +0100 Subject: [PATCH 1/2] feat: build flag to append generated suffix to bundles --- lib/controllers/prepare-controller.ts | 9 +++++++-- lib/data/prepare-data.ts | 3 +++ lib/declarations.d.ts | 2 +- lib/definitions/prepare.d.ts | 2 ++ lib/options.ts | 1 + lib/services/webpack/webpack-compiler-service.ts | 4 ++++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/controllers/prepare-controller.ts b/lib/controllers/prepare-controller.ts index 1cc7abd09a..fd29e995e4 100644 --- a/lib/controllers/prepare-controller.ts +++ b/lib/controllers/prepare-controller.ts @@ -194,7 +194,7 @@ export class PrepareController extends EventEmitter { }; } - await this.writeRuntimePackageJson(projectData, platformData); + await this.writeRuntimePackageJson(projectData, platformData, prepareData); await this.$projectChangesService.savePrepareInfo( platformData, @@ -433,7 +433,8 @@ export class PrepareController extends EventEmitter { */ public async writeRuntimePackageJson( projectData: IProjectData, - platformData: IPlatformData + platformData: IPlatformData, + prepareData: IPrepareData = null ) { const configInfo = this.$projectConfigService.detectProjectConfigs( projectData.projectDir @@ -509,6 +510,10 @@ export class PrepareController extends EventEmitter { ); } + if (prepareData?.uniqueBundle) { + packageData.main = `${packageData.main}.${prepareData.uniqueBundle}`; + } + this.$fs.writeJson(packagePath, packageData); } diff --git a/lib/data/prepare-data.ts b/lib/data/prepare-data.ts index 1a3e990ae8..2af06adbeb 100644 --- a/lib/data/prepare-data.ts +++ b/lib/data/prepare-data.ts @@ -9,6 +9,7 @@ export class PrepareData extends ControllerDataBase { public watch?: boolean; public watchNative: boolean = true; public hostProjectPath?: string; + public uniqueBundle: number; constructor( public projectDir: string, @@ -43,6 +44,8 @@ export class PrepareData extends ControllerDataBase { this.watchNative = data.watchNative; } this.hostProjectPath = data.hostProjectPath; + + this.uniqueBundle = !this.watch && data.uniqueBundle ? Date.now() : 0; } } diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 4943f988b9..edb18142ed 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -709,7 +709,7 @@ interface IOptions dryRun: boolean; platformOverride: string; - + uniqueBundle: boolean; // allow arbitrary options [optionName: string]: any; } diff --git a/lib/definitions/prepare.d.ts b/lib/definitions/prepare.d.ts index b46c29c3ec..0755bc52bb 100644 --- a/lib/definitions/prepare.d.ts +++ b/lib/definitions/prepare.d.ts @@ -14,6 +14,8 @@ declare global { // embedding hostProjectPath?: string; + + uniqueBundle: number; } interface IiOSCodeSigningData { diff --git a/lib/options.ts b/lib/options.ts index ff70999ebb..d5dcd1b509 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -250,6 +250,7 @@ export class Options { default: true, }, dryRun: { type: OptionType.Boolean, hasSensitiveValue: false }, + uniqueBundle: { type: OptionType.Boolean, hasSensitiveValue: false }, }; } diff --git a/lib/services/webpack/webpack-compiler-service.ts b/lib/services/webpack/webpack-compiler-service.ts index bb356f9e42..ace717c378 100644 --- a/lib/services/webpack/webpack-compiler-service.ts +++ b/lib/services/webpack/webpack-compiler-service.ts @@ -436,6 +436,10 @@ export class WebpackCompilerService envData.sourceMap = envData.sourceMap === "true"; } + if (prepareData.uniqueBundle > 0) { + envData.uniqueBundle = prepareData.uniqueBundle; + } + return envData; } From 70ec3be9fc7352da934cf204d7b91e6146bfc7a7 Mon Sep 17 00:00:00 2001 From: Jason Cassidy <47318351+jcassidyav@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:27:26 +0100 Subject: [PATCH 2/2] fix tests --- test/controllers/prepare-controller.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/test/controllers/prepare-controller.ts b/test/controllers/prepare-controller.ts index 017a1edafa..a8bf78ad3b 100644 --- a/test/controllers/prepare-controller.ts +++ b/test/controllers/prepare-controller.ts @@ -14,6 +14,7 @@ const prepareData = { env: {}, watch: true, watchNative: true, + uniqueBundle: 0, }; let isCompileWithWatchCalled = false; @@ -72,9 +73,8 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector { }, }); - const prepareController: PrepareController = injector.resolve( - "prepareController" - ); + const prepareController: PrepareController = + injector.resolve("prepareController"); prepareController.emit = (eventName: string, eventData: any) => { emittedEventNames.push(eventName); emittedEventData.push(eventData); @@ -103,9 +103,8 @@ describe("prepareController", () => { it(`should execute native prepare and webpack's compilation for ${platform} platform when hasNativeChanges is ${hasNativeChanges}`, async () => { const injector = createTestInjector({ hasNativeChanges }); - const prepareController: PrepareController = injector.resolve( - "prepareController" - ); + const prepareController: PrepareController = + injector.resolve("prepareController"); await prepareController.prepare({ ...prepareData, platform }); assert.isTrue(isCompileWithWatchCalled); @@ -116,9 +115,8 @@ describe("prepareController", () => { it(`should respect native changes that are made before the initial preparation of the project had been done for ${platform}`, async () => { const injector = createTestInjector({ hasNativeChanges: false }); - const prepareController: PrepareController = injector.resolve( - "prepareController" - ); + const prepareController: PrepareController = + injector.resolve("prepareController"); const prepareNativePlatformService = injector.resolve( "prepareNativePlatformService" @@ -158,9 +156,8 @@ describe("prepareController", () => { it("shouldn't start the watcher when watch is false", async () => { const injector = createTestInjector({ hasNativeChanges: false }); - const prepareController: PrepareController = injector.resolve( - "prepareController" - ); + const prepareController: PrepareController = + injector.resolve("prepareController"); await prepareController.prepare({ ...prepareData, watch: false,