Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for adding new plugin api namespace needs updating #13067

Closed
jcortell68 opened this issue Nov 7, 2023 · 2 comments · Fixed by #13153
Closed

Documentation for adding new plugin api namespace needs updating #13067

jcortell68 opened this issue Nov 7, 2023 · 2 comments · Fixed by #13153
Assignees

Comments

@jcortell68
Copy link
Contributor

jcortell68 commented Nov 7, 2023

This markdown explains how a Theia app developer can add a new plugin API namespace. I followed it a while back and it's been working great.

However, recently, our Theia app was adjusted to consume the backend in webpacked form (something that became possible in Theia 1.40.1), and that broke the custom API namespace. Specifically, the way backendInitPath is set is now invalid:

@injectable()
export class FooPluginApiProvider implements ExtPluginApiProvider {
    provideApi(): ExtPluginApi {
        return {
            frontendExtApi: {
                initPath: 'my-frontend-api-init',
                initFunction: 'fooInitializationFunction',
                initVariable: 'foo_global_variable'
            },
            backendInitPath: path.join(__dirname, 'my-backend-api-init')
        };
    }
}

So, this ticket involves a question and an ask:

Question: how should I set backendInitPath so that it works in the backend-webpacked environment
Ask: would be nice for the markdown to be updated with this information so others don't trip on this

@jcortell68
Copy link
Contributor Author

jcortell68 commented Nov 7, 2023

So, with a little help from my friends, turns out the code above doesn't need adjusting. What does need adjusting is the build configuration. Specifically, in the electron app's webpack.config.js, you need an entry to tell webpack to treat implementation.js with care:

const nodeConfig = require('./gen-webpack.node.config.js');
...
if (nodeConfig.config.entry) {
    nodeConfig.config.entry['my-backend-api-init'] = {
        import: require.resolve('@myapp/mypackage/lib/node/my-backend-api-init'),
        library: { type: 'commonjs2' }
    };
}

What that effectively does is puts a webpacked version of my-backend-api-init.js into the backend webpack directory as its own file. This way, when Theia dynamically imports the module, it's found.

__dirname above will effectively be something like {your-workspace}/electron-app/lib/backend. The js file that has the above code is there, as is the file my-backend-api-init.js. Both files in the same directory. Suddenly backendInitPath holds true.

No doubt, the same thing needs to be done for the frontend API initialization module, if you have one.

@jcortell68
Copy link
Contributor Author

jcortell68 commented Nov 7, 2023

I'll leave the ticket open as I do think it would be helpful for the markdown documentation to provide this additional insight. I wouldn't clutter that page up, though. I'd include a warning that the module specified for the API needs build-time special handling in the case of an app that uses a webpacked frontend/backend, and then provide a link to this ticket for the details?

@martin-fleck-at martin-fleck-at self-assigned this Nov 22, 2023
martin-fleck-at added a commit that referenced this issue Dec 18, 2023
#13153)

* Improve documentation on the addition of Plugin API in the plugin host

Fixes #13067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants