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.
This commit is contained in:
Shane
2025-03-05 17:14:45 -08:00
committed by GitHub
parent b6b43ae292
commit 2149ba2c8d
3 changed files with 48 additions and 36 deletions

66
core/package-lock.json generated
View File

@ -15,10 +15,10 @@
}, },
"devDependencies": { "devDependencies": {
"@axe-core/playwright": "^4.10.0", "@axe-core/playwright": "^4.10.0",
"@capacitor/core": "^6.0.0", "@capacitor/core": "^7.0.0",
"@capacitor/haptics": "^6.0.0", "@capacitor/haptics": "^7.0.0",
"@capacitor/keyboard": "^6.0.0", "@capacitor/keyboard": "^7.0.0",
"@capacitor/status-bar": "^6.0.0", "@capacitor/status-bar": "^7.0.0",
"@clack/prompts": "^0.10.0", "@clack/prompts": "^0.10.0",
"@ionic/eslint-config": "^0.3.0", "@ionic/eslint-config": "^0.3.0",
"@ionic/prettier-config": "^2.0.0", "@ionic/prettier-config": "^2.0.0",
@ -663,39 +663,43 @@
"dev": true "dev": true
}, },
"node_modules/@capacitor/core": { "node_modules/@capacitor/core": {
"version": "6.2.0", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/@capacitor/core/-/core-6.2.0.tgz", "resolved": "https://registry.npmjs.org/@capacitor/core/-/core-7.0.1.tgz",
"integrity": "sha512-B9IlJtDpUqhhYb+T8+cp2Db/3RETX36STgjeU2kQZBs/SLAcFiMama227o+msRjLeo3DO+7HJjWVA1+XlyyPEg==", "integrity": "sha512-1Ob9bvA/p8g8aNwK6VesxEekGXowLVf6APjkW4LRnr05H+7z/bke+Q5pn9zqh/GgTbIxAQ/rwZrAZvvxkdm1UA==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.1.0" "tslib": "^2.1.0"
} }
}, },
"node_modules/@capacitor/haptics": { "node_modules/@capacitor/haptics": {
"version": "6.0.2", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/@capacitor/haptics/-/haptics-6.0.2.tgz", "resolved": "https://registry.npmjs.org/@capacitor/haptics/-/haptics-7.0.0.tgz",
"integrity": "sha512-xcFdIH4iIIeW2+1lzmlYMVicqB9ytaiuZ9NE3a9laKFPvMGC7hdj6i6tHFezwPJ/96xkHOwXT2b0F8Mh9xtTWg==", "integrity": "sha512-8uI8rWyAbq8EzkjS+sHZSncyzujHzVbuLKgj8J5H0yUL6+r26F16gVA2iuQuIBvzbSMy7Y0/pUuWlwZr/H8AKg==",
"dev": true, "dev": true,
"license": "MIT",
"peerDependencies": { "peerDependencies": {
"@capacitor/core": "^6.0.0" "@capacitor/core": ">=7.0.0"
} }
}, },
"node_modules/@capacitor/keyboard": { "node_modules/@capacitor/keyboard": {
"version": "6.0.3", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-6.0.3.tgz", "resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-7.0.0.tgz",
"integrity": "sha512-V/mURxBI68HvClYjrGBlOriWkwYN7r+cWid/igJz/3scNc/V81DgQ9fpoLr4W0I5NY7YxOesjIJLuLO+LT18mQ==", "integrity": "sha512-Tqwy8wG+sx4UqiFCX4Q+bFw6uKgG7BiHKAPpeefoIgoEB8H8Jf3xZNZoVPnJIMuPsCdSvuyHXZbJXH9IEEirGA==",
"dev": true, "dev": true,
"license": "MIT",
"peerDependencies": { "peerDependencies": {
"@capacitor/core": "^6.0.0" "@capacitor/core": ">=7.0.0"
} }
}, },
"node_modules/@capacitor/status-bar": { "node_modules/@capacitor/status-bar": {
"version": "6.0.2", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/@capacitor/status-bar/-/status-bar-6.0.2.tgz", "resolved": "https://registry.npmjs.org/@capacitor/status-bar/-/status-bar-7.0.0.tgz",
"integrity": "sha512-AmRIX6QvFemItlY7/69ARkIAqitRQqJ2qwgZmD1KqgFb78pH+XFXm1guvS/a8CuOOm/IqZ4ddDbl20yxtBqzGA==", "integrity": "sha512-wsvPkWkoSOXMIgVHu4c6P1sOuDSZ1ClUo5OpLRwj7u8DYzlV4jlmNzztQn2Lvsiqx1z4kfukSaqe40k1Lo4c9g==",
"dev": true, "dev": true,
"license": "MIT",
"peerDependencies": { "peerDependencies": {
"@capacitor/core": "^6.0.0" "@capacitor/core": ">=7.0.0"
} }
}, },
"node_modules/@clack/core": { "node_modules/@clack/core": {
@ -10977,32 +10981,32 @@
"dev": true "dev": true
}, },
"@capacitor/core": { "@capacitor/core": {
"version": "6.2.0", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/@capacitor/core/-/core-6.2.0.tgz", "resolved": "https://registry.npmjs.org/@capacitor/core/-/core-7.0.1.tgz",
"integrity": "sha512-B9IlJtDpUqhhYb+T8+cp2Db/3RETX36STgjeU2kQZBs/SLAcFiMama227o+msRjLeo3DO+7HJjWVA1+XlyyPEg==", "integrity": "sha512-1Ob9bvA/p8g8aNwK6VesxEekGXowLVf6APjkW4LRnr05H+7z/bke+Q5pn9zqh/GgTbIxAQ/rwZrAZvvxkdm1UA==",
"dev": true, "dev": true,
"requires": { "requires": {
"tslib": "^2.1.0" "tslib": "^2.1.0"
} }
}, },
"@capacitor/haptics": { "@capacitor/haptics": {
"version": "6.0.2", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/@capacitor/haptics/-/haptics-6.0.2.tgz", "resolved": "https://registry.npmjs.org/@capacitor/haptics/-/haptics-7.0.0.tgz",
"integrity": "sha512-xcFdIH4iIIeW2+1lzmlYMVicqB9ytaiuZ9NE3a9laKFPvMGC7hdj6i6tHFezwPJ/96xkHOwXT2b0F8Mh9xtTWg==", "integrity": "sha512-8uI8rWyAbq8EzkjS+sHZSncyzujHzVbuLKgj8J5H0yUL6+r26F16gVA2iuQuIBvzbSMy7Y0/pUuWlwZr/H8AKg==",
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },
"@capacitor/keyboard": { "@capacitor/keyboard": {
"version": "6.0.3", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-6.0.3.tgz", "resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-7.0.0.tgz",
"integrity": "sha512-V/mURxBI68HvClYjrGBlOriWkwYN7r+cWid/igJz/3scNc/V81DgQ9fpoLr4W0I5NY7YxOesjIJLuLO+LT18mQ==", "integrity": "sha512-Tqwy8wG+sx4UqiFCX4Q+bFw6uKgG7BiHKAPpeefoIgoEB8H8Jf3xZNZoVPnJIMuPsCdSvuyHXZbJXH9IEEirGA==",
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },
"@capacitor/status-bar": { "@capacitor/status-bar": {
"version": "6.0.2", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/@capacitor/status-bar/-/status-bar-6.0.2.tgz", "resolved": "https://registry.npmjs.org/@capacitor/status-bar/-/status-bar-7.0.0.tgz",
"integrity": "sha512-AmRIX6QvFemItlY7/69ARkIAqitRQqJ2qwgZmD1KqgFb78pH+XFXm1guvS/a8CuOOm/IqZ4ddDbl20yxtBqzGA==", "integrity": "sha512-wsvPkWkoSOXMIgVHu4c6P1sOuDSZ1ClUo5OpLRwj7u8DYzlV4jlmNzztQn2Lvsiqx1z4kfukSaqe40k1Lo4c9g==",
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },

View File

@ -37,10 +37,10 @@
}, },
"devDependencies": { "devDependencies": {
"@axe-core/playwright": "^4.10.0", "@axe-core/playwright": "^4.10.0",
"@capacitor/core": "^6.0.0", "@capacitor/core": "^7.0.0",
"@capacitor/haptics": "^6.0.0", "@capacitor/haptics": "^7.0.0",
"@capacitor/keyboard": "^6.0.0", "@capacitor/keyboard": "^7.0.0",
"@capacitor/status-bar": "^6.0.0", "@capacitor/status-bar": "^7.0.0",
"@clack/prompts": "^0.10.0", "@clack/prompts": "^0.10.0",
"@ionic/eslint-config": "^0.3.0", "@ionic/eslint-config": "^0.3.0",
"@ionic/prettier-config": "^2.0.0", "@ionic/prettier-config": "^2.0.0",

View File

@ -1,9 +1,17 @@
import type { CapacitorGlobal } from '@capacitor/core'; import type { CapacitorGlobal } from '@capacitor/core';
import { win } from '@utils/browser'; import { win } from '@utils/browser';
type CustomCapacitorGlobal = CapacitorGlobal & {
// Capacitor from @capacitor/core no longer exports Plugins, but we're pulling
// Capacitor from window.Capacitor, which does
Plugins: {
[key: string]: any;
};
};
export const getCapacitor = () => { export const getCapacitor = () => {
if (win !== undefined) { if (win !== undefined) {
return (win as any).Capacitor as CapacitorGlobal; return (win as any).Capacitor as CustomCapacitorGlobal;
} }
return undefined; return undefined;
}; };