Skip to content

Commit d10b817

Browse files
authored
feat: build flag to append generated suffix to bundles (#5814)
1 parent 4176e98 commit d10b817

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

lib/controllers/prepare-controller.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class PrepareController extends EventEmitter {
194194
};
195195
}
196196

197-
await this.writeRuntimePackageJson(projectData, platformData);
197+
await this.writeRuntimePackageJson(projectData, platformData, prepareData);
198198

199199
await this.$projectChangesService.savePrepareInfo(
200200
platformData,
@@ -433,7 +433,8 @@ export class PrepareController extends EventEmitter {
433433
*/
434434
public async writeRuntimePackageJson(
435435
projectData: IProjectData,
436-
platformData: IPlatformData
436+
platformData: IPlatformData,
437+
prepareData: IPrepareData = null
437438
) {
438439
const configInfo = this.$projectConfigService.detectProjectConfigs(
439440
projectData.projectDir
@@ -509,6 +510,10 @@ export class PrepareController extends EventEmitter {
509510
);
510511
}
511512

513+
if (prepareData?.uniqueBundle) {
514+
packageData.main = `${packageData.main}.${prepareData.uniqueBundle}`;
515+
}
516+
512517
this.$fs.writeJson(packagePath, packageData);
513518
}
514519

lib/data/prepare-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class PrepareData extends ControllerDataBase {
99
public watch?: boolean;
1010
public watchNative: boolean = true;
1111
public hostProjectPath?: string;
12+
public uniqueBundle: number;
1213

1314
constructor(
1415
public projectDir: string,
@@ -43,6 +44,8 @@ export class PrepareData extends ControllerDataBase {
4344
this.watchNative = data.watchNative;
4445
}
4546
this.hostProjectPath = data.hostProjectPath;
47+
48+
this.uniqueBundle = !this.watch && data.uniqueBundle ? Date.now() : 0;
4649
}
4750
}
4851

lib/declarations.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ interface IOptions
709709
dryRun: boolean;
710710

711711
platformOverride: string;
712-
712+
uniqueBundle: boolean;
713713
// allow arbitrary options
714714
[optionName: string]: any;
715715
}

lib/definitions/prepare.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ declare global {
1414

1515
// embedding
1616
hostProjectPath?: string;
17+
18+
uniqueBundle: number;
1719
}
1820

1921
interface IiOSCodeSigningData {

lib/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ export class Options {
250250
default: true,
251251
},
252252
dryRun: { type: OptionType.Boolean, hasSensitiveValue: false },
253+
uniqueBundle: { type: OptionType.Boolean, hasSensitiveValue: false },
253254
};
254255
}
255256

lib/services/webpack/webpack-compiler-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ export class WebpackCompilerService
436436
envData.sourceMap = envData.sourceMap === "true";
437437
}
438438

439+
if (prepareData.uniqueBundle > 0) {
440+
envData.uniqueBundle = prepareData.uniqueBundle;
441+
}
442+
439443
return envData;
440444
}
441445

test/controllers/prepare-controller.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const prepareData = {
1414
env: {},
1515
watch: true,
1616
watchNative: true,
17+
uniqueBundle: 0,
1718
};
1819

1920
let isCompileWithWatchCalled = false;
@@ -72,9 +73,8 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector {
7273
},
7374
});
7475

75-
const prepareController: PrepareController = injector.resolve(
76-
"prepareController"
77-
);
76+
const prepareController: PrepareController =
77+
injector.resolve("prepareController");
7878
prepareController.emit = (eventName: string, eventData: any) => {
7979
emittedEventNames.push(eventName);
8080
emittedEventData.push(eventData);
@@ -103,9 +103,8 @@ describe("prepareController", () => {
103103
it(`should execute native prepare and webpack's compilation for ${platform} platform when hasNativeChanges is ${hasNativeChanges}`, async () => {
104104
const injector = createTestInjector({ hasNativeChanges });
105105

106-
const prepareController: PrepareController = injector.resolve(
107-
"prepareController"
108-
);
106+
const prepareController: PrepareController =
107+
injector.resolve("prepareController");
109108
await prepareController.prepare({ ...prepareData, platform });
110109

111110
assert.isTrue(isCompileWithWatchCalled);
@@ -116,9 +115,8 @@ describe("prepareController", () => {
116115
it(`should respect native changes that are made before the initial preparation of the project had been done for ${platform}`, async () => {
117116
const injector = createTestInjector({ hasNativeChanges: false });
118117

119-
const prepareController: PrepareController = injector.resolve(
120-
"prepareController"
121-
);
118+
const prepareController: PrepareController =
119+
injector.resolve("prepareController");
122120

123121
const prepareNativePlatformService = injector.resolve(
124122
"prepareNativePlatformService"
@@ -158,9 +156,8 @@ describe("prepareController", () => {
158156
it("shouldn't start the watcher when watch is false", async () => {
159157
const injector = createTestInjector({ hasNativeChanges: false });
160158

161-
const prepareController: PrepareController = injector.resolve(
162-
"prepareController"
163-
);
159+
const prepareController: PrepareController =
160+
injector.resolve("prepareController");
164161
await prepareController.prepare({
165162
...prepareData,
166163
watch: false,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy