Skip to content

Commit 2149ba2

Browse files
authored
fix(capacitor): use proper types for capacitor v7 support (#30228)
Issue number: resolves internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Currently, Capacitor types are outdated in Ionic Framework and we're accessing a type property that no longer exists in Capacitor 7.0.0+ ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> This PR updates the capacitor version and addresses removal of `.Plugins` from `@capacitor/core`'s `CapacitorGlobal`, which we rely on to dynamically access plugins that the user may or may not have installed. The fix for this was creating a custom type definition to support accessing `Plugins`. While `Plugins` was removed from Capacitor if we were accessing it directly from core, we're pulling it from the window in the browser, where it's still exposed, so we just needed to make our type reflect that. ## Does this introduce a breaking change? - [ ] Yes - [X] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Technically, this issue does not prevent Framework from working with Capacitor 7 because it's only a typing issue, but it's still a minor issue that should be addressed in our effort to support Capacitor 7. This PR, along with #30195, should make it ready for that.
1 parent b6b43ae commit 2149ba2

File tree

3 files changed

+48
-36
lines changed

3 files changed

+48
-36
lines changed

core/package-lock.json

Lines changed: 35 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
},
3838
"devDependencies": {
3939
"@axe-core/playwright": "^4.10.0",
40-
"@capacitor/core": "^6.0.0",
41-
"@capacitor/haptics": "^6.0.0",
42-
"@capacitor/keyboard": "^6.0.0",
43-
"@capacitor/status-bar": "^6.0.0",
40+
"@capacitor/core": "^7.0.0",
41+
"@capacitor/haptics": "^7.0.0",
42+
"@capacitor/keyboard": "^7.0.0",
43+
"@capacitor/status-bar": "^7.0.0",
4444
"@clack/prompts": "^0.10.0",
4545
"@ionic/eslint-config": "^0.3.0",
4646
"@ionic/prettier-config": "^2.0.0",

core/src/utils/native/capacitor.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import type { CapacitorGlobal } from '@capacitor/core';
22
import { win } from '@utils/browser';
33

4+
type CustomCapacitorGlobal = CapacitorGlobal & {
5+
// Capacitor from @capacitor/core no longer exports Plugins, but we're pulling
6+
// Capacitor from window.Capacitor, which does
7+
Plugins: {
8+
[key: string]: any;
9+
};
10+
};
11+
412
export const getCapacitor = () => {
513
if (win !== undefined) {
6-
return (win as any).Capacitor as CapacitorGlobal;
14+
return (win as any).Capacitor as CustomCapacitorGlobal;
715
}
816
return undefined;
917
};

0 commit comments

Comments
 (0)