Repository navigation
feat: debug Vite projects with HMR when @nativescript/vite serves source maps - #303
NathanWalker wants to merge 1 commit into
Conversation
…rce maps @nativescript/vite 8.0.23 serves HMR app modules with inline source maps, so breakpoints bind without restarting the app on every change. Only add --no-hmr for older versions (or when the version can't be read) and for Vue projects, whose single-file components are still served without maps.
edusperoni
left a comment
There was a problem hiding this comment.
Looks good. Checked the version gate against the published packages: @nativescript/vite 8.0.23 was published at 23:13 UTC, 5 minutes after NativeScript/NativeScript#11629 merged, and it contains the fix (hmr/server/served-module-sourcemap.js is new, and websocket-ns-m.js now calls appendInlineSourceMap); 8.0.22 has neither. So VITE_HMR_SOURCE_MAPS_VERSION = '8.0.23' is right and the "before merging" condition is met.
One non-blocking note: hasDependency(appRoot, 'nativescript-vue') only reads the app's own package.json. In a monorepo where nativescript-vue is declared at the root (typical Nx setup), Vue isn't detected, HMR stays on, and breakpoints in .vue files won't bind. Detecting the installed package by walking up parent folders (like the @nativescript/vite version lookup already does) would be more consistent; the worst case of a false positive is losing HMR while debugging, not losing debugging. Fine as a follow-up.
Suggest merging this one before #304 so #304 can reuse hasDependency.
Problem
Debugging a Vite project with
ns debug iosand HMR on (the normal workflow) didn't work, so the extension forced--no-hmrfor every Vite project. The cause was in@nativescript/vite: its/ns/mdevice route served app modules without source maps, so js-debug could not mapsrc/*.tsxbreakpoints to the code that ran.That is fixed in NativeScript/NativeScript#11629, which serves app modules with inline maps.
Change
--no-hmris added only when it is still needed:@nativescript/viteis older thanVITE_HMR_SOURCE_MAPS_VERSION(8.0.23), or its version can't be read (missing package, Yarn PnP); ornativescript-vue, because.vuecomponents are served by separate routes that still have no maps.node_modules/@nativescript/vite, searching parent folders as well, so monorepos are covered.--hmr/--no-hmrintnsArgsis always used as given, as before.Before merging:
VITE_HMR_SOURCE_MAPS_VERSIONmust match the@nativescript/viterelease that ships NativeScript/NativeScript#11629.Verification
getInstalledPackageVersion/hasDependency.ns debug ios --watch, iOS simulator) with the patched@nativescript/vite. I drove js-debug 1.140 over DAP with the samepwa-nodeattach configDebugManagerbuilds, includingcomputeSourceMapOptionsoutput:.ts/.tsxsources bind.