-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
PoC - cli: filter Theia extensions #9309
Conversation
#9300 prompted me to find a solution for when we need typings for a package, but we might not want to bring all of its contributions into our app because it is a transitive dependency. This PR gives more control into what gets loaded through inversify into your application, at the extension/module level. I want to get feedback if it is something others here also wanted to be able to do. |
This mechanism should be complementary to #9069. I discussed on this issue having a build-time mechanic, and while this PR is different from what I described back then, it should still be beneficial to application developers. I also remember @thegecko had troubles with |
Cc @arekzaluski |
0c70808
to
a6d8859
Compare
I simplified the logic and the options a bit. See commit message/PR description. |
Our generators currently collect any Theia extension installed in node_modules and mount them into your application without leaving you much of a choice. An alternative could be to create your own generators, but this is a lot of maintenance work. This commit simplifies the process of controlling what ends up in your applications by adding new loading strategies: - all: Like before, use everything found in node_modules - explicitDependenciesOnly: only use what is defined in your dependencies This is configurable from an application package.json through the theia.extensions.loading.strategy field. In addition to those strategies, you can also specify an includes list and an excludes list. Using those, you can define regular expressions to filter extensions even more precisely. The matching will be done on the candidate inversify modules path. When using the `explicitDependenciesOnly` the includes list will be evaluated as "in addition to explicit dependencies". If you want the includes list to be absolute again, use the default 'all' strategy so that only what's defined in includes is included. Note that preventing an extension from having its inversify modules loaded won't prevent it from being included in your bundles. Bundling should also mostly work no matter what you exclude, but if another extension was relying on a given Symbol it will most likely break at runtime. In such a case it is your responsability to bind the missing symbols using a custom Theia extension, specific to your use-cases. Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
a6d8859
to
5754eb4
Compare
I agree! This PR should work well in combination with #9317 to allow application developers to exclude whole extensions at build time as well as individual contributions from included extensions at runtime. |
I'll hold this for now. |
See #9317 |
Our generators currently collect any Theia extension installed in
node_modules and mount them into your application without leaving you
much of a choice.
An alternative could be to create your own generators, but this is a lot
of maintenance work.
This commit simplifies the process of controlling what ends up in your
applications by adding new loading strategies:
dependencies
This is configurable from an application package.json through the
theia.extensions.loading.strategy field.
In addition to those strategies, you can also specify an includes list
and an excludes list. Using those, you can define regular expressions to
filter extensions even more precisely. The matching will be done on the
candidate inversify modules path.
When using the
explicitDependenciesOnly
the includes list will beevaluated as "in addition to explicit dependencies". If you want the
includes list to be absolute again, use the default 'all' strategy so
that only what's defined in includes is included.
Note that preventing an extension from having its inversify modules
loaded won't prevent it from being included in your bundles. Bundling
should also mostly work no matter what you exclude, but if another
extension was relying on a given Symbol it will most likely break at
runtime. In such a case it is your responsability to bind the missing
symbols using a custom Theia extension, specific to your use-cases.
How to test
Edit
examples/browser/package.json
to have the following fields:After rebuilding the browser app, inspect the
src-gen/frontend/index.js
andsrc-gen/backend/server.js
files and make sure that no modules are matching theexcludes
list.To test the
explicitDependenciesOnly
you can remove@theia/terminal
from the browser app dependencies and make sure it doesn't get included in the previously mentioned files, but it should be included when using theall
strategy.Review checklist
Reminder for reviewers