{"_id":"@capacitor/plugin-cordova-compat","_rev":"22-9491de0bbeea0160302e6572fa9d835f","name":"@capacitor/plugin-cordova-compat","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@capacitor/plugin-cordova-compat","version":"1.0.0","author":{"name":"Ionic Team"},"license":"MIT","_id":"@capacitor/plugin-cordova-compat@1.0.0","maintainers":[{"name":"itschaced","email":"chace@ionic.io"},{"name":"it_mike_s","email":"mike.summerfeldt@gmail.com"},{"name":"larsmikkelsen","email":"lars@ionic.io"},{"name":"giralte-ionic","email":"giralte@ionic.io"},{"name":"steven0351-ionic","email":"steven.sherry@ionic.io"},{"name":"jpender","email":"joey@ionic.io"},{"name":"ionicjs","email":"hi@ionic.io"},{"name":"maxlynch","email":"max@ionic.io"},{"name":"mhartington","email":"mikehartington@gmail.com"},{"name":"jcesarmobile","email":"jcesarmobile@gmail.com"},{"name":"cmapoole","email":"carl@ionic.io"},{"name":"nhyatt","email":"nick@ionic.io"}],"dist":{"shasum":"c146d698bd32801f1e9dd730113c6addf2de5777","tarball":"https://registry.npmjs.org/@capacitor/plugin-cordova-compat/-/plugin-cordova-compat-1.0.0.tgz","fileCount":28,"integrity":"sha512-d8+MXLQ1s5CMX9wSjX3qtNOHav6AxT4aAP0PrqseIlTZxSv698xigRwb2FOQNfuACyFDcBJJSS1m7PZxPEvMPQ==","signatures":[{"sig":"MEYCIQCf1U6MVqE9Be62n3vh0vLexFw1DneWnogWwO7QPkjMtQIhAME6aXWhBqwqRcAdJy06dElCwtiYfsW/FFoummjP9NHV","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":114501,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj8+EGACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoZuQ/8DALGRrjiLobxmRB6y7TRB73GMPM3bVj6Ij2DAUTML9DXcqsL\r\nbfXmm34XgaeoWrSSpmBI8E5LhAJuo/JGcpxQ2CCyS8rGpYpBQ9tXT+JmW35G\r\nEaZBy4CPpdLwzO7hnjBCWJhofOvaskQDc07cu6rYhPlzHQ9tw95xzsWZMPsE\r\nPiu68EUsCI+0GivLfniPUYUiYYwY4Ht9pm3eRlG1T8i9iiSnS/C30E8G06uB\r\neocT9UwZkDsNolGQBUMHUNC3fpfNJLq58kabd8FXQyQ8NTvn6Qyo+WdQ9/yD\r\np9PJalbovCp+HJ4jFEZSfXUO2MP6TIcqwfKlXMYnT7x0sJn6+gIIBtHCEmAi\r\nj+y+14gZaMho1AVztk44FFXXFpFwtZIhXDWWRIDVFOYEW+0Je0edt9jSAoNo\r\nZ3i2B2l9+V56LhOE695B0a70mQt//wV82GBCAgHjnOvD5qzH3wmGdMfsz9Zr\r\n1HD+J9tiXv4ci+Xk2bMlqsorPbWAqLC+wXb+sCBhFuN63VQkzUOikpqJIhnG\r\nGrVdHbw3fwhGgUcan9osd+M2n6rBIj2qa3r9L6GLEiRoWYKmyvZ/6xDfGMnF\r\nhW1+xxY6j5MdCjuZOwGNh3QMBBIL96mqe/aYpltk+gk2j40swL/ES1bNW/ro\r\n3MBMhnRkpw5gQ+xlwJ8ALH6VGCz9PPrtR3k=\r\n=K30T\r\n-----END PGP SIGNATURE-----\r\n"},"cordova":{"id":"capacitor-plugin-cordova-compat","platforms":["android","ios"]},"engines":{"cordovaDependencies":{"3.0.0":{"cordova":">=10.0.0","cordova-android":">=10.0.0"}}},"gitHead":"1935b5e03c2589aa3b8eac38ca8c8fd553530e30","scripts":{"release":"npx np --no-tests"},"_npmUser":{"name":"it_mike_s","email":"mike.summerfeldt@gmail.com"},"_npmVersion":"8.19.3","description":"Use Capacitor Plugins in a Cordova app.","directories":{},"_nodeVersion":"18.13.0","_hasShrinkwrap":false,"devDependencies":{"np":"^7.6.2"},"_npmOperationalInternal":{"tmp":"tmp/plugin-cordova-compat_1.0.0_1676927238118_0.3711192729098103","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-02-20T21:07:18.039Z","modified":"2026-09-28T18:17:28.185Z","1.0.0":"2023-02-20T21:07:18.268Z"},"author":{"name":"Ionic Team"},"license":"MIT","description":"Use Capacitor Plugins in a Cordova app.","maintainers":[{"email":"chace.daniels@outsystems.com","name":"itschaced"},{"email":"hi@ionic.io","name":"ionicjs"},{"email":"jcesarmobile@gmail.com","name":"jcesarmobile"},{"email":"vitor.oliveira@outsystems.com","name":"vmfo"},{"email":"joey@ionic.io","name":"jpender"},{"email":"mark@ionic.io","name":"mark-ionic"},{"email":"chuckynes@gmail.com","name":"chuckytuh"},{"email":"nuno.azevedo@outsystems.com","name":"nuno.azevedo-outsystems"},{"email":"trevorlambert11@gmail.com","name":"trevorlambert"},{"email":"agerardojacinto@gmail.com","name":"alexgerardojacinto"},{"email":"pedro.gustavo.bilro@outsystems.com","name":"os-pedrobilro"},{"email":"eric.harvey@outsystems.com","name":"harvdoggy"},{"email":"joey.pender@outsystems.com","name":"jpender-os"},{"email":"andre.destro@outsystems.com","name":"ndr"},{"email":"kepa.baum.totorica@outsystems.com","name":"kepatoto"},{"email":"rui.moreira.mendes@outsystems.com","name":"rui.mendes"},{"email":"emer@emer.net","name":"markemer"},{"email":"ossplugins@outsystems.com","name":"capacitor-plugin-bot"},{"email":"horodyski@ionic.io","name":"eric-ionic"},{"email":"rui.alves@outsystems.com","name":"os-ruialves"}],"readme":"# Capacitor plugin Compatability for Cordova apps\n#### Use your favorite Capacitor plugins in your cordova app!\n\n> __Note:__ Capacitor plugins must explicitly support this compatability layer to be used with this system. Find out how to add that compatability to your plugin below.\n\n## Usage:\n\n1.  Run `npm i @capacitor/plugin-cordova-compat` in your cordova app.\n2.  Run `cordova plugin add @capacitor/plugin-cordova-compat` in your cordova app.\n3.  Install Capacitor plugins that have support for the compatability layer and enjoy!\n\n## Using configuration for Capacitor Plugins:\n\n1. Create a `capacitor.config.json` file in your project root with the following structure:\n```json\n{\n  \"plugins\": {}\n}\n```\n2. Add your configuration according to the plugins docs. For example the `Tester` plugin wants a word to log on start up so the config would look like this:\n```json\n{\n  \"plugins\": {\n    \"Tester\": {\n      \"wordToLogOnLoad\": \"Hello!!!\"\n    }\n  }\n}\n```\n\n## How to add cordova compatability to your Capacitor plugin:\n\n1.  You need to find a few bits of info before proceding:\n    1.   Find your exported name for your plugin. Normally this will be in your `src/index.ts` file and look similar to the below where the name is circled in <span style=\"color:red\">__red__</span>. This will be replacing any `{{PLUGIN_EXPORT_NAME}}` you see in the files we will be creating in these instructions. You will also need a all lower case version to replace any `{{PLUGIN_EXPORT_NAME_LOWERCASE}}`. (ex. `Tester` and `tester` respecfully) [<img src=\"https://i.imgur.com/fz9l861.png\">](https://i.imgur.com/fz9l861.png)\n\n    2.  Find your current plugin version from your `package.json` files `version` property. This will be replacing any `{{PLUGIN_VERSION}}` you see in the files we will be creating in these instructions. (ex. `1.0.1`)\n\n    3.  Find your android package name in your `android/src/main/AndroidManifest.xml` file, it will be a string in a `package=\"PACKAGE_HERE\"`. This will be replacing any `{{ANDROID_PACKAGE}}` you see in the files we will be creating in these instructions. You will also need a path based version to replace any `{{ANDROID_PACKAGE_PATH}}`. (ex. `com.example.testerplugin` and `com/example/testerplugin` respecfully)\n\n2.  Create a `cordova` folder in the root of the Capacitor plugin (where it's `package.json` is).\n\n3.  Create two folders in the new `cordova` folder: `www` and `src`\n\n4.  Create two folders in the new `cordova/src` folder: `android` and `ios`\n\n5.  In the `cordova/src/android` folder create a `{{PLUGIN_EXPORT_NAME}}.gradle` file with the contents below. This is where any android dependencies or other gradle settings needed by the android side of your plugin will need to be copied/placed should you need any. \n```gradle\nbuildscript {\n    repositories {\n        google()\n        mavenCentral()\n    }\n    dependencies {}\n}\n\nallprojects {\n    repositories {\n        google()\n        mavenCentral()\n    }\n}\n\ndependencies {\n}\n\next.postBuildExtras = {\n}\n```\n\n6.  In the `cordova/www` folder create a `{{PLUGIN_EXPORT_NAME}}.js` file with the contents below (remember to do replacements). Modify the methods array to contain all the names of the methods your plugin exposes to its users.\n```javascript\nvar exec = require('cordova/exec');\n\nvar PLUGIN_NAME = '{{PLUGIN_EXPORT_NAME}}Plugin';\n\nconst methods = [\n  'echo'\n];\n\nconst exportThis = methods.reduce((e, m) => {\n  e[m] = args =>\n    new Promise((resolve, reject) =>\n      exec(resolve, reject, PLUGIN_NAME, m, args ? [args] : []),\n    );\n  return e;\n}, {});\n\nmodule.exports = exportThis;\n```\n\n7.  In the `cordova/src/ios` folder create a `{{PLUGIN_EXPORT_NAME}}Plugin.swift` file with the contents below (remember to do replacements). In this file you can see we have the example `echo` function using the implemention code of our Capacitor plugin but for cordova. You will need to create these shim function in the same style for your iOS plugin. (remember to use the `createCall` function to be able to return as you will be used to in Capacitor)\n```swift\nimport Foundation\n\n@objc({{PLUGIN_EXPORT_NAME}}Plugin)\npublic class {{PLUGIN_EXPORT_NAME}}Plugin: CAPPlugin {\n    private lazy var implementation: {{PLUGIN_EXPORT_NAME}} = {{PLUGIN_EXPORT_NAME}}()\n\n    // Called when plugin is loaded.\n    override public func pluginInitialize() {\n        super.pluginInitialize()\n    }\n\n    // Replace with your methods.\n    @objc func echo(_ command: CDVInvokedUrlCommand) {\n        // This line is needed to translate cordova to Capacitor API\n        let call = createCall(command)\n    \n        let value = call.getString(\"value\") ?? \"\"\n        call.resolve([\n            \"value\": implementation.echo(value)\n        ])\n    }\n}\n```\n\n8.  In the root of your plugins folder (where the package.json is) create a `plugin.xml` file with the content below replacing where needed and following any comments for extra instructions.\n```xml\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<plugin xmlns=\"http://apache.org/cordova/ns/plugins/1.0\" id=\"{{PLUGIN_EXPORT_NAME_LOWERCASE}}-plugin\" version=\"{{PLUGIN_VERSION}}\">\n    <name>{{PLUGIN_EXPORT_NAME_LOWERCASE}}-plugin</name>\n    <description>{{PLUGIN_EXPORT_NAME_LOWERCASE}}-plugin</description>\n    <license>SEE LICENSE</license>\n    <keywords>capacitor,{{PLUGIN_EXPORT_NAME_LOWERCASE}},cordova</keywords>\n\n    <js-module src=\"cordova/www/{{PLUGIN_EXPORT_NAME}}.js\" name=\"{{PLUGIN_EXPORT_NAME_LOWERCASE}}plugin\">\n        <runs/>\n        <clobbers target=\"{{PLUGIN_EXPORT_NAME}}\"/>\n    </js-module>\n    <platform name=\"android\">\n        <config-file target=\"res/xml/config.xml\" parent=\"/*\">\n            <feature name=\"{{PLUGIN_EXPORT_NAME}}Plugin\">\n                <param name=\"android-package\" value=\"{{ANDROID_PACKAGE}}.{{PLUGIN_EXPORT_NAME}}Plugin\"/>\n                <param name=\"onload\" value=\"true\"/>\n            </feature>\n        </config-file>\n        <config-file target=\"AndroidManifest.xml\" parent=\"/*\">\n            <uses-permission android:name=\"android.permission.INTERNET\"/>\n        </config-file>\n        <framework src=\"cordova/src/android/{{PLUGIN_EXPORT_NAME}}.gradle\" custom=\"true\" type=\"gradleReference\" />\n\n        <!-- add implementation and call code files from your capacitor plugin below. Example: -->\n\n        <!-- Call code: -->\n        <!-- <source-file src=\"android/src/main/java/{{ANDROID_PACKAGE_PATH}}/{{PLUGIN_EXPORT_NAME}}Plugin.java\" target-dir=\"src/{{ANDROID_PACKAGE_PATH}}\"/> -->\n\n        <!-- Implementation code: -->\n        <!-- <source-file src=\"android/src/main/java/{{ANDROID_PACKAGE_PATH}}/{{PLUGIN_EXPORT_NAME}}.java\" target-dir=\"src/{{ANDROID_PACKAGE_PATH}}\"/> -->\n    </platform>\n\n    <!-- ios -->\n    <platform name=\"ios\">\n        <config-file target=\"config.xml\" parent=\"/*\">\n            <feature name=\"{{PLUGIN_EXPORT_NAME}}Plugin\">\n                <param name=\"ios-package\" value=\"{{PLUGIN_EXPORT_NAME}}Plugin\" onload=\"true\"/>\n            </feature>\n            <preference name=\"UseSwiftLanguageVersion\" value=\"5\"/>\n        </config-file>\n        <dependency id=\"cordova-plugin-add-swift-support\" version=\"2.0.2\"/>\n        <source-file src=\"cordova/src/ios/{{PLUGIN_EXPORT_NAME}}Plugin.swift\"/>\n\n        <!-- add implementation files from your capacitor plugin below (do not include call code like android, ios needs the shim we create in the setup instructions). Example: -->\n\n        <!-- Implementation code: -->\n        <!-- <source-file src=\"ios/Plugin/{{PLUGIN_EXPORT_NAME}}.swift\"/> -->\n    </platform>\n\n</plugin>\n```\n\n9.  In your `src/index.ts` where you found your `{{PLUGIN_EXPORT_NAME}}` you can make changes to make the cordova usage of the plugin the same as the usage of the capacitor side by making replacements to the below and using this as your `src/index.ts`. Note this is based on basic capacitor plugin creation, and if you are doing anything custom here you will need to add that in as well. \n```typescript\nimport { registerPlugin } from '@capacitor/core';\n\nimport type { {{PLUGIN_EXPORT_NAME}}Plugin } from './definitions';\n\nlet {{PLUGIN_EXPORT_NAME}}Impl;\n\nif ((window as any).cordova !== undefined && (window as any).cordova.platformVersion !== '1.0.0') {\n  {{PLUGIN_EXPORT_NAME}}Impl = new Proxy({}, {\n    get(_target, property) {\n      return (window as any).{{PLUGIN_EXPORT_NAME}}[property];\n    }\n  });\n} else {\n  {{PLUGIN_EXPORT_NAME}}Impl = registerPlugin<TesterPlugin>('Tester', {\n    web: () => import('./web').then(m => new m.TesterWeb()),\n  });\n}\n\nconst {{PLUGIN_EXPORT_NAME}} = {{PLUGIN_EXPORT_NAME}}Impl as {{PLUGIN_EXPORT_NAME}}Plugin;\n\nexport * from './definitions';\nexport { {{PLUGIN_EXPORT_NAME}} };\n```\n\n10. You will need to add some properties to your `package.json` so cordova will reconize your plugin. Add the below to the end of your `package.json` while doing any replacements needed like the above steps.\n```json\n  \"cordova\": {\n    \"id\": \"{{PLUGIN_EXPORT_NAME_LOWERCASE}}-plugin\",\n    \"platforms\": [\n      \"android\",\n      \"ios\"\n    ]\n  },\n  \"engines\": {\n    \"cordovaDependencies\": {\n      \"3.0.0\": {\n        \"cordova\": \">100\"\n      }\n    }\n  }\n```\n\n11. Also in your `package.json` be sure to include the new files created in these steps in your package when published. For example if you use the `files` property in the `package.json` it would look like the below with the changes in this step.\n```json\n  \"files\": [\n    ...,\n    \"cordova/\",\n    \"plugin.xml\"\n  ],\n```","readmeFilename":"README.md"}