question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin Import Proposal

See original GitHub issue

Please feel free to comment on this proposal. Thanks!


@capacitor/core should provide a registerPlugin function that takes an object of implementations for each platform. For Android and iOS, the plugins proxy can be used. For web, the web implementation will need to be provided.

registerPlugin will return a RegisteredPlugin object with a getImplementation method that returns the instance of the plugin for the current platform.

The “echo” example will be used for this proposal.

echo-plugin/index.ts

import { Plugins, registerPlugin } from '@capacitor/core';
import { EchoPluginWeb } from './web';

export interface EchoPlugin {
  echo: (something: string) => string;
}

const Plugin = registerPlugin<EchoPlugin>('Echo', {
  android: Plugins.EchoPlugin,
  ios: Plugins.EchoPlugin,
  web: new EchoPluginWeb(),
}).getImplementation();

export { Plugin };

echo-plugin/web.ts

import { WebPlugin } from '@capacitor/core';
import type { EchoPlugin } from '.';

export class EchoPluginWeb extends WebPlugin implements EchoPlugin {
  constructor() {
    super({ name: 'Echo' });
  }

  ...
}

my-app/some-page.tsx

import { Echo } from 'echo-plugin';

await Echo.echo('hello world');

// TODO: Figure out testing.
export class Foo {
  constructor() {
    Echo.echo();
  }
}

This shouldn’t be a breaking change because plugins will need to opt-in to using registerPlugin in order for the new plugin import to work. (Previously, users of the plugin would have to import { Plugins } from '@capacitor/core';).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
imhoffdcommented, Jul 21, 2020

Yeah, but not super important to the proposal, I’ll add ... to make it clear there’s more implementation details.

0reactions
ionitron-bot[bot]commented, Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@babel/plugin-proposal-dynamic-import - npm
Start using @babel/plugin-proposal-dynamic-import in your project by running `npm i @babel/plugin-proposal-dynamic-import`.
Read more >
@babel/plugin-proposal-dynamic-import - Package Manager
Fast, reliable, and secure dependency management.
Read more >
@babel/plugin-proposal-dynamic-import - npm package | Snyk
The npm package @babel/plugin-proposal-dynamic-import receives a total of 19,171,382 weekly downloads. As such, @babel/plugin-proposal-dynamic-import popularity ...
Read more >
babel/plugin-proposal-dynamic-import - NPM Package Overview
The npm package @babel/plugin-proposal-dynamic-import receives a total of 18,369,877 weekly downloads. As such, @babel/plugin-proposal-dynamic- ...
Read more >
tc39/proposal-import-assertions - GitHub
The Import Assertions proposal adds an inline syntax for module import statements to pass on more information alongside the module specifier.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found