fix(cap-vite): don't auto restart when generated files update

This commit is contained in:
LemonNeko
2026-03-15 16:16:51 +08:00
parent 4fb47a0379
commit 3c03a45b0a
2 changed files with 16 additions and 2 deletions
+6
View File
@@ -76,6 +76,12 @@ describe('shouldRestartForNativeChange', () => {
expect(shouldRestartForNativeChange('/repo/app/src/main.ts', 'ios', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/ios/App/CapApp-SPM/Package.swift', 'ios', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/android/build/generated/file.kt', 'android', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml', 'android', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/android/capacitor.settings.gradle', 'android', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/android/app/capacitor.build.gradle', 'android', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/android/app/src/main/assets/public/index.html', 'android', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/android/app/src/main/assets/capacitor.plugins.json', 'android', '/repo/app')).toBe(false)
expect(shouldRestartForNativeChange('/repo/app/android/app/src/main/res/xml/config.xml', 'android', '/repo/app')).toBe(false)
})
it('ignores capacitor config json updates', () => {
+10 -2
View File
@@ -66,7 +66,14 @@ const ignoredPathPrefixesByPlatform: Record<CapacitorPlatform, string[][]> = {
ios: [
['App', 'CapApp-SPM'],
],
android: [],
android: [
['app', 'src', 'main', 'assets', 'public'],
['app', 'src', 'main', 'assets', 'capacitor.plugins.json'],
['app', 'src', 'main', 'res', 'xml', 'config.xml'],
['app', 'capacitor.build.gradle'],
['capacitor-cordova-android-plugins'],
['capacitor.settings.gradle'],
],
}
export function parseCapacitorPlatform(value: string | undefined): CapacitorPlatform | null {
@@ -128,7 +135,8 @@ export function shouldRestartForNativeChange(file: string, platform: CapacitorPl
prefix.every((segment, index) => relativeSegments[index] === segment),
)) {
// NOTICE: Capacitor regenerates ios/App/CapApp-SPM/Package.swift during `cap run`.
// Treating that generated tree as a native source change causes an infinite restart loop.
// It also rewrites several generated Android files and plugin trees during `cap update`.
// Treating those generated outputs as native source changes causes an infinite restart loop.
return false
}