diff --git a/core/src/definitions.ts b/core/src/definitions.ts index f75a29d39..a8259607c 100644 --- a/core/src/definitions.ts +++ b/core/src/definitions.ts @@ -1,4 +1,3 @@ -import type { PluginRegistry } from './legacy/legacy-definitions'; import type { CapacitorException } from './util'; export interface CapacitorGlobal { @@ -44,21 +43,6 @@ export interface CapacitorGlobal { DEBUG?: boolean; isLoggingEnabled?: boolean; - - // Deprecated in v3, will be removed from v4 - - /** - * @deprecated Plugins should be imported instead. Deprecated in - * v3 and Capacitor.Plugins property definition will not be exported in v4. - */ - Plugins: PluginRegistry; - - /** - * Called when a plugin method is not available. Defaults to console - * logging a warning. Provided for backwards compatibility. - * @deprecated Deprecated in v3, will be removed from v4 - */ - pluginMethodNoop: (target: any, key: PropertyKey, pluginName: string) => Promise; } /** diff --git a/core/src/global.ts b/core/src/global.ts index e710f6e0a..423bc76fb 100644 --- a/core/src/global.ts +++ b/core/src/global.ts @@ -1,6 +1,4 @@ -import { legacyRegisterWebPlugin } from './legacy/legacy-web-plugin-merge'; import { initCapacitorGlobal } from './runtime'; -import type { WebPlugin } from './web-plugin'; export const Capacitor = /*#__PURE__*/ initCapacitorGlobal( typeof globalThis !== 'undefined' @@ -15,23 +13,3 @@ export const Capacitor = /*#__PURE__*/ initCapacitorGlobal( ); export const registerPlugin = Capacitor.registerPlugin; - -/** - * @deprecated Provided for backwards compatibility for Capacitor v2 plugins. - * Capacitor v3 plugins should import the plugin directly. This "Plugins" - * export is deprecated in v3, and will be removed in v4. - */ -export const Plugins = Capacitor.Plugins; - -/** - * Provided for backwards compatibility. Use the registerPlugin() API - * instead, and provide the web plugin as the "web" implmenetation. - * For example - * - * export const Example = registerPlugin('Example', { - * web: () => import('./web').then(m => new m.Example()) - * }) - * - * @deprecated Deprecated in v3, will be removed from v4. - */ -export const registerWebPlugin = (plugin: WebPlugin): void => legacyRegisterWebPlugin(Capacitor, plugin); diff --git a/core/src/index.ts b/core/src/index.ts index 64eec9307..b189c71f4 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -17,7 +17,7 @@ export { CapacitorPlatforms, addPlatform, setPlatform } from './platforms'; export { Capacitor, registerPlugin } from './global'; // Base WebPlugin -export { WebPlugin, WebPluginConfig, ListenerCallback } from './web-plugin'; +export { WebPlugin, ListenerCallback } from './web-plugin'; // Core Plugins APIs export { CapacitorCookies, CapacitorHttp, WebView, buildRequestInit } from './core-plugins'; @@ -38,15 +38,3 @@ export type { // Constants export { CapacitorException, ExceptionCode } from './util'; - -// Legacy Global APIs -export { Plugins, registerWebPlugin } from './global'; - -// Legacy Type Definitions -export type { - CallbackID, - CancellableCallback, - ISODateString, - PluginConfig, - PluginRegistry, -} from './legacy/legacy-definitions'; diff --git a/core/src/legacy/legacy-definitions.ts b/core/src/legacy/legacy-definitions.ts deleted file mode 100644 index d4e2b6eb2..000000000 --- a/core/src/legacy/legacy-definitions.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @deprecated - */ -export interface PluginRegistry { - [pluginName: string]: { - [prop: string]: any; - }; -} - -/** - * @deprecated - */ -export interface PluginConfig { - id: string; - name: string; -} - -/** - * @deprecated - */ -export type ISODateString = string; - -/** - * @deprecated - */ -export type CallbackID = string; - -/** - * CancellableCallback is a simple wrapper that a method will - * return to make it easy to cancel any repeated callback the method - * might have set up. For example: a geolocation watch. - * @deprecated - */ -export interface CancellableCallback { - /** - * The cancel function for this method - * - * @deprecated - */ - cancel: (...args: any[]) => any; -} diff --git a/core/src/legacy/legacy-web-plugin-merge.ts b/core/src/legacy/legacy-web-plugin-merge.ts deleted file mode 100644 index a27c4df36..000000000 --- a/core/src/legacy/legacy-web-plugin-merge.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { CapacitorGlobal } from '../definitions'; -import type { WebPlugin } from '../web-plugin'; - -export const legacyRegisterWebPlugin = (cap: CapacitorGlobal, webPlugin: WebPlugin): void => { - const config = webPlugin.config; - const Plugins = cap.Plugins; - - if (!config?.name) { - // TODO: add link to upgrade guide - throw new Error( - `Capacitor WebPlugin is using the deprecated "registerWebPlugin()" function, but without the config. Please use "registerPlugin()" instead to register this web plugin."`, - ); - } - - // TODO: add link to upgrade guide - console.warn(`Capacitor plugin "${config.name}" is using the deprecated "registerWebPlugin()" function`); - - if (!Plugins[config.name] || config?.platforms?.includes(cap.getPlatform())) { - // Add the web plugin into the plugins registry if there already isn't - // an existing one. If it doesn't already exist, that means - // there's no existing native implementation for it. - // - OR - - // If we already have a plugin registered (meaning it was defined in the native layer), - // then we should only overwrite it if the corresponding web plugin activates on - // a certain platform. For example: Geolocation uses the WebPlugin on Android but not iOS - Plugins[config.name] = webPlugin; - } -}; diff --git a/core/src/runtime.ts b/core/src/runtime.ts index bd10e42d9..db530701f 100644 --- a/core/src/runtime.ts +++ b/core/src/runtime.ts @@ -54,10 +54,6 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => { const handleError = (err: Error) => win.console.error(err); - const pluginMethodNoop = (_target: any, prop: PropertyKey, pluginName: string) => { - return Promise.reject(`${pluginName} does not have an implementation of "${prop as any}".`); - }; - const registeredPlugins = new Map(); const defaultRegisterPlugin = (pluginName: string, jsImplementations: PluginImplementations = {}): any => { @@ -214,7 +210,6 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => { cap.handleError = handleError; cap.isNativePlatform = isNativePlatform; cap.isPluginAvailable = isPluginAvailable; - cap.pluginMethodNoop = pluginMethodNoop; cap.registerPlugin = registerPlugin; cap.Exception = CapacitorException; cap.DEBUG = !!cap.DEBUG; diff --git a/core/src/tests/legacy.spec.ts b/core/src/tests/legacy.spec.ts deleted file mode 100644 index 22f74c085..000000000 --- a/core/src/tests/legacy.spec.ts +++ /dev/null @@ -1,180 +0,0 @@ -/** - * @jest-environment jsdom - */ - -import { initBridge } from '../../native-bridge'; -import type { CapacitorGlobal } from '../definitions'; -import type { WindowCapacitor } from '../definitions-internal'; -import { legacyRegisterWebPlugin } from '../legacy/legacy-web-plugin-merge'; -import { createCapacitor } from '../runtime'; -import { WebPlugin } from '../web-plugin'; - -describe('legacy', () => { - let win: WindowCapacitor; - let cap: CapacitorGlobal; - const LegacyWebPlugin = class extends WebPlugin {}; - const orgConsoleWarn = console.warn; - const noop = () => { - // do nothing - }; - - beforeAll(() => { - console.warn = noop; - win = {}; - initBridge(win); - }); - - afterAll(() => { - console.warn = orgConsoleWarn; - }); - - it('registerWebPlugin() when native implementation already provided, and same platform config provided', () => { - win = { - androidBridge: { postMessage: noop }, - }; - cap = createCapacitor(win) as any; - - const MockNativePlugin = {} as any; - cap.Plugins['Legacy'] = MockNativePlugin; - - const Legacy = new LegacyWebPlugin({ - name: 'Legacy', - platforms: ['android'], - }); - legacyRegisterWebPlugin(cap, Legacy); - - expect(Legacy.config.name).toBe('Legacy'); - expect(cap.Plugins['Legacy']).toBe(Legacy); - }); - - it('do not registerWebPlugin() when native implementation already provided', () => { - win = { - androidBridge: { postMessage: noop }, - }; - cap = createCapacitor(win) as any; - - const MockNativePlugin = {} as any; - cap.Plugins['Legacy'] = MockNativePlugin; - - const Legacy = new LegacyWebPlugin({ name: 'Legacy' }); - legacyRegisterWebPlugin(cap, Legacy); - - expect(Legacy.config.name).toBe('Legacy'); - expect(cap.Plugins['Legacy']).toBe(MockNativePlugin); - }); - - it('registerWebPlugin() when platforms provided and no native implementation', () => { - win = {}; - cap = createCapacitor(win) as any; - - const Legacy = new LegacyWebPlugin({ name: 'Legacy', platforms: ['web'] }); - legacyRegisterWebPlugin(cap, Legacy); - - expect(Legacy.config.name).toBe('Legacy'); - expect(cap.Plugins['Legacy']).toBe(Legacy); - }); - - it('registerWebPlugin() when platforms not provided and no native implementation', () => { - win = {}; - cap = createCapacitor(win) as any; - - const Legacy = new LegacyWebPlugin({ name: 'Legacy' }); - legacyRegisterWebPlugin(cap, Legacy); - - expect(Legacy.config.name).toBe('Legacy'); - expect(cap.Plugins['Legacy']).toBe(Legacy); - }); - - it('error registerWebPlugin() w/out config.name', async () => { - win = {}; - cap = createCapacitor(win) as any; - - expect(() => { - legacyRegisterWebPlugin(cap, new LegacyWebPlugin({} as any)); - }).toThrowError( - 'Capacitor WebPlugin is using the deprecated "registerWebPlugin()" function, but without the config. Please use "registerPlugin()" instead to register this web plugin."', - ); - }); - - it('error registerWebPlugin() w/out config', async () => { - win = {}; - cap = createCapacitor(win) as any; - - expect(() => { - legacyRegisterWebPlugin(cap, new LegacyWebPlugin()); - }).toThrowError( - 'Capacitor WebPlugin is using the deprecated "registerWebPlugin()" function, but without the config. Please use "registerPlugin()" instead to register this web plugin."', - ); - }); - - it('doc.addEventListener backbutton', (done) => { - const AppWeb = class { - async addListener(eventName: string) { - expect(eventName).toBe('backButton'); - done(); - } - }; - const bbCallback = () => { - // ignore - }; - win = { - document: { - addEventListener(eventName: string) { - expect(eventName).toBe('backbutton'); - }, - }, - androidBridge: { postMessage: noop }, - }; - initBridge(win); - cap = createCapacitor(win); - cap.registerPlugin('App', { - web: new AppWeb(), - android: new AppWeb(), - }); - - win.document.addEventListener('backbutton', bbCallback); - }); - - it('doc.addEventListener deviceready', (done) => { - win = { - document: { - addEventListener() { - // ignore - }, - }, - androidBridge: { postMessage: noop }, - }; - initBridge(win); - createCapacitor(win); - win.document.addEventListener('deviceready', done); - }); - - it('add navigator.app.exitApp', () => { - win = { - navigator: {}, - androidBridge: { postMessage: noop }, - }; - initBridge(win); - createCapacitor(win); - expect(win.navigator.app.exitApp).toBeDefined(); - }); - - it('cordova global', () => { - win = { - androidBridge: { postMessage: noop }, - }; - initBridge(win); - createCapacitor(win); - expect(win.cordova).toBeDefined(); - }); - - it('use existing cordova global', () => { - const existingCordova: any = {}; - win = { - cordova: existingCordova, - }; - initBridge(win); - createCapacitor(win); - expect(win.cordova).toBe(existingCordova); - }); -}); diff --git a/core/src/tests/plugin.spec.ts b/core/src/tests/plugin.spec.ts index e9d6a4f5c..570134a02 100644 --- a/core/src/tests/plugin.spec.ts +++ b/core/src/tests/plugin.spec.ts @@ -36,14 +36,6 @@ describe('plugin', () => { const Awesome = cap.registerPlugin('Awesome'); await Awesome.mph(); done('did not throw'); - } catch (e) { - expect(e.message).toBe(`"Awesome.mph()" is not implemented on android`); - expect(e.code).toBe(ExceptionCode.Unimplemented); - } - - try { - await cap.Plugins.Awesome.mph(); - done('did not throw'); } catch (e) { expect(e.message).toBe(`"Awesome.mph()" is not implemented on android`); expect(e.code).toBe(ExceptionCode.Unimplemented); @@ -68,9 +60,6 @@ describe('plugin', () => { const results1 = await Awesome.mph(); expect(results1).toBe(88); - - const results2 = await cap.Plugins.Awesome.mph(); - expect(results2).toBe(88); }); it('error from missing native implementation', async (done) => { @@ -87,14 +76,6 @@ describe('plugin', () => { const Awesome = cap.registerPlugin('Awesome'); await Awesome.mph(); done('did not throw'); - } catch (e) { - expect(e.message).toBe(`"Awesome" plugin is not implemented on android`); - expect(e.code).toBe(ExceptionCode.Unimplemented); - } - - try { - await cap.Plugins.Awesome.mph(); - done('did not throw'); } catch (e) { expect(e.message).toBe(`"Awesome" plugin is not implemented on android`); expect(e.code).toBe(ExceptionCode.Unimplemented); @@ -117,13 +98,6 @@ describe('plugin', () => { try { await Awesome.mph(); done('did not throw'); - } catch (e) { - expect(e).toBe('unable to load module'); - } - - try { - await cap.Plugins.Awesome.mph(); - done('did not throw'); } catch (e) { expect(e).toBe('unable to load module'); done(); @@ -148,9 +122,7 @@ describe('plugin', () => { }); const p1 = Awesome.mph(); - const p2 = cap.Plugins.Awesome.mph(); expect(await p1).toBe(88); - expect(await p2).toBe(88); const rtn2 = await Awesome.mph(); expect(rtn2).toBe(88); @@ -178,9 +150,6 @@ describe('plugin', () => { const rtn2 = await Awesome.mph(); expect(rtn2).toBe(88); - - const rtn3 = await cap.Plugins.Awesome.mph(); - expect(rtn3).toBe(88); }); it('call method that had an error', async () => { @@ -198,7 +167,6 @@ describe('plugin', () => { }); expect(async () => Awesome.mph()).rejects.toThrowError('nope!'); - expect(async () => cap.Plugins.Awesome.mph()).rejects.toThrowError('nope!'); }); it('missing method on lazy loaded implementation', async (done) => { @@ -211,14 +179,6 @@ describe('plugin', () => { try { await Awesome.mph(); done('did not throw error'); - } catch (e) { - expect(e.message).toBe(`"Awesome.mph()" is not implemented on web`); - expect(e.code).toBe(ExceptionCode.Unimplemented); - } - - try { - await cap.Plugins.Awesome.mph(); - done('did not throw error'); } catch (e) { expect(e.message).toBe(`"Awesome.mph()" is not implemented on web`); expect(e.code).toBe(ExceptionCode.Unimplemented); @@ -239,14 +199,6 @@ describe('plugin', () => { try { await Awesome.mph(); done('should throw error'); - } catch (e) { - expect(e.message).toBe(`"Awesome.mph()" is not implemented on android`); - expect(e.code).toBe(ExceptionCode.Unimplemented); - } - - try { - await cap.Plugins.Awesome.mph(); - done('should throw error'); } catch (e) { expect(e.message).toBe(`"Awesome.mph()" is not implemented on android`); expect(e.code).toBe(ExceptionCode.Unimplemented); @@ -263,14 +215,6 @@ describe('plugin', () => { try { await Awesome.mph(); done('should throw error'); - } catch (e) { - expect(e.message).toBe(`"Awesome" plugin is not implemented on web`); - expect(e.code).toBe(ExceptionCode.Unimplemented); - } - - try { - await cap.Plugins.Awesome.mph(); - done('should throw error'); } catch (e) { expect(e.message).toBe(`"Awesome" plugin is not implemented on web`); expect(e.code).toBe(ExceptionCode.Unimplemented); @@ -292,14 +236,6 @@ describe('plugin', () => { try { await Awesome.mph(); done('should throw error'); - } catch (e) { - expect(e.message).toBe(`"Awesome" plugin is not implemented on android`); - expect(e.code).toBe(ExceptionCode.Unimplemented); - } - - try { - await cap.Plugins.Awesome.mph(); - done('should throw error'); } catch (e) { expect(e.message).toBe(`"Awesome" plugin is not implemented on android`); expect(e.code).toBe(ExceptionCode.Unimplemented); diff --git a/core/src/web-plugin.ts b/core/src/web-plugin.ts index 144c32fa3..b58c1aa7a 100644 --- a/core/src/web-plugin.ts +++ b/core/src/web-plugin.ts @@ -7,25 +7,10 @@ import type { CapacitorException } from './util'; * Base class web plugins should extend. */ export class WebPlugin implements Plugin { - /** - * @deprecated WebPluginConfig deprecated in v3 and will be removed in v4. - */ - config?: WebPluginConfig; - protected listeners: { [eventName: string]: ListenerCallback[] } = {}; protected retainedEventArguments: { [eventName: string]: any[] } = {}; protected windowListeners: { [eventName: string]: WindowListenerHandle } = {}; - constructor(config?: WebPluginConfig) { - if (config) { - // TODO: add link to upgrade guide - console.warn( - `Capacitor WebPlugin "${config.name}" config object was deprecated in v3 and will be removed in v4.`, - ); - this.config = config; - } - } - addListener(eventName: string, listenerFunc: ListenerCallback): Promise { let firstListener = false; @@ -158,17 +143,3 @@ export interface WindowListenerHandle { pluginEventName: string; handler: (event: any) => void; } - -/** - * @deprecated Deprecated in v3, removing in v4. - */ -export interface WebPluginConfig { - /** - * @deprecated Deprecated in v3, removing in v4. - */ - readonly name: string; - /** - * @deprecated Deprecated in v3, removing in v4. - */ - platforms?: string[]; -}