fix(bundler): copy the vite bundle to native in non-watch builds#6056
fix(bundler): copy the vite bundle to native in non-watch builds#6056JumpLink wants to merge 2 commits into
Conversation
The Vite bundler integration copies its output (`.ns-vite-build/`) into the native project's `assets/app` only from the watch-mode IPC handler in `compileWithWatch` (the `emittedFiles` message). A non-watch build — `ns build`, or `ns run --justlaunch` — runs `compileWithoutWatch`, which has no IPC channel (`startBundleProcess` sets `stdio: "inherit"` when `prepareData.watch` is false) and never calls `copyViteBundleToNative`. The Vite output is therefore left in `.ns-vite-build/`, `assets/app` stays empty, and the Static Binding Generator fails with "Couldn't find sbg-bindings.txt" (no JS input). Webpack/rspack are unaffected — they write directly into the platform folder. Copy the full Vite bundle in `compileWithoutWatch`'s `close` handler on a successful (exit code 0) build, mirroring the full-build branch of the watch-mode copy.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughCentralized Vite path computation with getVitePaths; watch-mode IPC now uses those paths for incremental or full copying; non-watch builds copy the full ChangesVite path helper and copy behaviors
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/services/bundler/bundler-compiler-service.ts (1)
392-399: 💤 Low valueConsider extracting path computation into a helper method.
The
distOutputanddestDirpath computations are duplicated from the watch mode handler (lines 129-136). Extracting them into a helper method would reduce duplication and make future changes easier.♻️ Optional refactor to reduce duplication
Add a helper method to the class:
private getVitePaths( platformData: IPlatformData, projectData: IProjectData, ): { distOutput: string; destDir: string } { const distOutput = path.join( projectData.projectDir, ".ns-vite-build", ); const destDir = path.join( platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName, ); return { distOutput, destDir }; }Then use it in both watch mode (line 129) and non-watch mode (line 392):
- const distOutput = path.join( - projectData.projectDir, - ".ns-vite-build", - ); - const destDir = path.join( - platformData.appDestinationDirectoryPath, - this.$options.hostProjectModuleName, - ); + const { distOutput, destDir } = this.getVitePaths(platformData, projectData);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/services/bundler/bundler-compiler-service.ts` around lines 392 - 399, Extract the duplicated path calculations for distOutput and destDir into a private helper on the class (e.g., getVitePaths(platformData: IPlatformData, projectData: IProjectData): { distOutput: string; destDir: string }) that returns the two paths computed with path.join(projectData.projectDir, ".ns-vite-build") and path.join(platformData.appDestinationDirectoryPath, this.$options.hostProjectModuleName); replace the duplicated blocks in the watch-mode handler and the non-watch block currently computing distOutput/destDir in bundler-compiler-service.ts with calls to getVitePaths(...) so both places use the single helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/services/bundler/bundler-compiler-service.ts`:
- Around line 392-399: Extract the duplicated path calculations for distOutput
and destDir into a private helper on the class (e.g., getVitePaths(platformData:
IPlatformData, projectData: IProjectData): { distOutput: string; destDir: string
}) that returns the two paths computed with path.join(projectData.projectDir,
".ns-vite-build") and path.join(platformData.appDestinationDirectoryPath,
this.$options.hostProjectModuleName); replace the duplicated blocks in the
watch-mode handler and the non-watch block currently computing
distOutput/destDir in bundler-compiler-service.ts with calls to
getVitePaths(...) so both places use the single helper.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 72595c5e-2dbb-49fa-925c-a9f54606e5ac
📒 Files selected for processing (1)
lib/services/bundler/bundler-compiler-service.ts
Share the .ns-vite-build / assets-app path computation between the watch-mode emittedFiles copy and the non-watch copy (CodeRabbit review).
Problem
With
bundler: 'vite', a non-watch build leaves the app's JS out of the APK/IPA, so the build fails.The Vite output (
.ns-vite-build/) is copied into the native project'sassets/apponly from the watch-mode IPC handler incompileWithWatch— thechildProcess.on("message", …)branch that readsmessage.emittedFilesand callscopyViteBundleToNative. A non-watch build (ns build, orns run --justlaunch) runscompileWithoutWatch, which:startBundleProcesssetsstdio: "inherit"whenprepareData.watchisfalse, soprocess.send(...)in the Vite child is a no-op and the"message"handler never fires; andcopyViteBundleToNativeitself.So the Vite output stays in
.ns-vite-build/,<platform>/.../assets/appstays empty, and the Static Binding Generator fails:Webpack/rspack are unaffected — they write directly into the platform folder rather than into
.ns-vite-build/.Repro
Any
bundler: 'vite'app:ns build android # or: ns run android --justlaunch→ gradle fails at the SBG step because
assets/apphas only the runtimepackage.jsonand no bundle.ns run android(watch mode) works, which is what masks the bug.Fix
Copy the full Vite bundle in
compileWithoutWatch'sclosehandler on a successful (exit code 0) build, mirroring the full-build branch of the watch-mode copy (copyViteBundleToNative(distOutput, destDir)), guarded onthis.getBundler() === "vite".Notes
tscis clean.compileWithoutWatch/compileWithWatchunit tests currently cover only the config-path error path (not the build/copy flow), so this matches the existing coverage. Happy to add a test that stubs the child-processclose+ assertscopyViteBundleToNativeis called if you'd like.@gjsify/nativescript-vite; reproduced with stock@nativescript/vite+ns build android.Summary by CodeRabbit