Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build flag to append generated suffix to bundles #5814

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -509,6 +510,10 @@ export class PrepareController extends EventEmitter {
);
}

if (prepareData?.uniqueBundle) {
packageData.main = `${packageData.main}.${prepareData.uniqueBundle}`;
}

this.$fs.writeJson(packagePath, packageData);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/data/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ interface IOptions
dryRun: boolean;

platformOverride: string;

uniqueBundle: boolean;
// allow arbitrary options
[optionName: string]: any;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/definitions/prepare.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare global {

// embedding
hostProjectPath?: string;

uniqueBundle: number;
}

interface IiOSCodeSigningData {
Expand Down
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export class Options {
default: true,
},
dryRun: { type: OptionType.Boolean, hasSensitiveValue: false },
uniqueBundle: { type: OptionType.Boolean, hasSensitiveValue: false },
};
}

Expand Down
4 changes: 4 additions & 0 deletions lib/services/webpack/webpack-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ export class WebpackCompilerService
envData.sourceMap = envData.sourceMap === "true";
}

if (prepareData.uniqueBundle > 0) {
envData.uniqueBundle = prepareData.uniqueBundle;
}

return envData;
}

Expand Down
21 changes: 9 additions & 12 deletions test/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const prepareData = {
env: {},
watch: true,
watchNative: true,
uniqueBundle: 0,
};

let isCompileWithWatchCalled = false;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand Down