Skip to content

Commit b883783

Browse files
committed
Merge remote-tracking branch 'origin/main' into pre/v9-combined-testing
2 parents bb37020 + 27e94e8 commit b883783

File tree

1 file changed

+90
-28
lines changed

1 file changed

+90
-28
lines changed

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

Lines changed: 90 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ interface IBundlerCompilation {
5050
staleAssets: string[];
5151
}
5252

53+
/* for specific bundling debugging separate from logger */
54+
const debugLog = false;
55+
5356
export class BundlerCompilerService
5457
extends EventEmitter
5558
implements IBundlerCompilerService
@@ -118,7 +121,9 @@ export class BundlerCompilerService
118121
(message as IBundlerEmitMessage).emittedFiles
119122
) {
120123
message = message as IBundlerEmitMessage;
121-
console.log("Received Vite IPC message:", message);
124+
if (debugLog) {
125+
console.log("Received Vite IPC message:", message);
126+
}
122127

123128
// Copy Vite output files directly to platform destination
124129
const distOutput = path.join(projectData.projectDir, "dist");
@@ -127,15 +132,19 @@ export class BundlerCompilerService
127132
this.$options.hostProjectModuleName,
128133
);
129134

130-
console.log(`🔥 Copying from ${distOutput} to ${destDir}`);
135+
if (debugLog) {
136+
console.log(`🔥 Copying from ${distOutput} to ${destDir}`);
137+
}
131138

132139
// Determine which files to copy based on build type and changes
133140
if (message.isHMR) {
134141
// HMR updates: only copy changed files
135-
console.log(
136-
"🔥 HMR update - copying only changed files for:",
137-
message.changedFiles,
138-
);
142+
if (debugLog) {
143+
console.log(
144+
"🔥 HMR update - copying only changed files for:",
145+
message.changedFiles,
146+
);
147+
}
139148

140149
// For HTML template changes, we need to copy the component files that were rebuilt
141150
let filesToCopy = message.emittedFiles;
@@ -152,8 +161,35 @@ export class BundlerCompilerService
152161
f === "bundle.mjs" ||
153162
f === "bundle.mjs.map",
154163
);
164+
if (debugLog) {
165+
console.log(
166+
"🔥 HTML change detected - copying component files:",
167+
filesToCopy,
168+
);
169+
}
170+
}
171+
172+
this.copyViteBundleToNative(distOutput, destDir, filesToCopy);
173+
} else if (
174+
message.buildType === "incremental" &&
175+
message.changedFiles &&
176+
message.changedFiles.length > 0
177+
) {
178+
// Incremental builds: only copy files that are likely affected by the changes
179+
if (debugLog) {
155180
console.log(
156-
"🔥 HTML change detected - copying component files:",
181+
"🔥 Incremental build - copying only relevant files for:",
182+
message.changedFiles,
183+
);
184+
}
185+
186+
const filesToCopy = this.getIncrementalFilesToCopy(
187+
message.emittedFiles,
188+
message.changedFiles,
189+
);
190+
if (debugLog) {
191+
console.log(
192+
"🔥 Incremental build - files to copy:",
157193
filesToCopy,
158194
);
159195
}
@@ -178,16 +214,20 @@ export class BundlerCompilerService
178214

179215
this.copyViteBundleToNative(distOutput, destDir, filesToCopy);
180216
} else {
181-
console.log("🔥 Full build - copying all files");
217+
if (debugLog) {
218+
console.log("🔥 Full build - copying all files");
219+
}
182220
this.copyViteBundleToNative(distOutput, destDir);
183221
}
184222

185223
// Resolve the promise on first build completion
186224
if (isFirstBundlerWatchCompilation) {
187225
isFirstBundlerWatchCompilation = false;
188-
console.log(
189-
"Vite first build completed, resolving compileWithWatch",
190-
);
226+
if (debugLog) {
227+
console.log(
228+
"Vite first build completed, resolving compileWithWatch",
229+
);
230+
}
191231
resolve(childProcess);
192232
}
193233

@@ -224,15 +264,19 @@ export class BundlerCompilerService
224264
});
225265

226266
if (message.isHMR) {
227-
console.log(
228-
"🔥 Skipping BUNDLER_COMPILATION_COMPLETE for HMR update - app will not restart",
229-
);
267+
if (debugLog) {
268+
console.log(
269+
"🔥 Skipping BUNDLER_COMPILATION_COMPLETE for HMR update - app will not restart",
270+
);
271+
}
230272
} else {
231273
// Only emit BUNDLER_COMPILATION_COMPLETE for non-HMR builds
232274
// This prevents the CLI from restarting the app during HMR updates
233-
console.log(
234-
"🔥 Emitting BUNDLER_COMPILATION_COMPLETE for full build",
235-
);
275+
if (debugLog) {
276+
console.log(
277+
"🔥 Emitting BUNDLER_COMPILATION_COMPLETE for full build",
278+
);
279+
}
236280
this.emit(BUNDLER_COMPILATION_COMPLETE, data);
237281
}
238282
return;
@@ -537,7 +581,9 @@ export class BundlerCompilerService
537581
});
538582
}
539583

540-
console.log("args:", args);
584+
if (debugLog) {
585+
console.log("args:", args);
586+
}
541587

542588
const childProcess = this.$childProcess.spawn(
543589
process.execPath,
@@ -881,17 +927,21 @@ export class BundlerCompilerService
881927
specificFiles: string[] = null,
882928
) {
883929
// Clean and copy Vite output to native platform folder
884-
console.log(`Copying Vite bundle from "${distOutput}" to "${destDir}"`);
930+
if (debugLog) {
931+
console.log(`Copying Vite bundle from "${distOutput}" to "${destDir}"`);
932+
}
885933

886934
const fs = require("fs");
887935

888936
try {
889937
if (specificFiles) {
890938
// Selective mode: only copy specific files (HMR or incremental)
891-
console.log(
892-
"🔥 Selective copy - copying specific files:",
893-
specificFiles,
894-
);
939+
if (debugLog) {
940+
console.log(
941+
"🔥 Selective copy - copying specific files:",
942+
specificFiles,
943+
);
944+
}
895945

896946
// Ensure destination directory exists
897947
fs.mkdirSync(destDir, { recursive: true });
@@ -908,11 +958,15 @@ export class BundlerCompilerService
908958

909959
fs.copyFileSync(srcPath, destPath);
910960

911-
console.log(`🔥 Copied ${file}`);
961+
if (debugLog) {
962+
console.log(`🔥 Copied ${file}`);
963+
}
912964
}
913965
} else {
914966
// Full build mode: clean and copy everything
915-
console.log("🔥 Full build: Copying all files");
967+
if (debugLog) {
968+
console.log("🔥 Full build: Copying all files");
969+
}
916970

917971
// Clean destination directory
918972
if (fs.existsSync(destDir)) {
@@ -995,18 +1049,26 @@ export class BundlerCompilerService
9951049
const ws = new WebSocket("ws://localhost:24678");
9961050

9971051
ws.on("open", () => {
998-
console.log("🔥 Sending HMR notification to bridge:", message.type);
1052+
if (debugLog) {
1053+
console.log("🔥 Sending HMR notification to bridge:", message.type);
1054+
}
9991055
ws.send(JSON.stringify(message));
10001056
ws.close();
10011057
});
10021058

10031059
ws.on("error", () => {
10041060
// HMR bridge not available, which is fine
1005-
console.log("🔥 HMR bridge not available (this is normal without HMR)");
1061+
if (debugLog) {
1062+
console.log(
1063+
"🔥 HMR bridge not available (this is normal without HMR)",
1064+
);
1065+
}
10061066
});
10071067
} catch (error) {
10081068
// WebSocket not available, which is fine
1009-
console.log("🔥 WebSocket not available for HMR notifications");
1069+
if (debugLog) {
1070+
console.log("🔥 WebSocket not available for HMR notifications");
1071+
}
10101072
}
10111073
}
10121074

0 commit comments

Comments
 (0)