@attached and @plain import attribute

Many APIs come with plugins that improve the power of the API and make using it more magical. However, some APIs can use a lot of plugins (like Publish) and the amount of imports you have to place on the top of your file gets huge.

@attached import would import the module it is in every time the module being imported is imported.
With that, a simple import Publish would give also import import SplashPublishPlugin too as long as SplashPublishPlugin has @attached import Publish somewhere in the module.

If that doesn't make since, think of it this way: @attached is the reverse of @_exported.

Sometimes, however, you might want to get only the primary module and none of the plugins. This would be done by placing @plain import instead of just import.

With that, if you use @plain import Publish it would only import Publish and not SplashPublishPlugin even if SplashPublishPlugin has @attached import Publish somewhere in the module.

This seems to be covering the same ground as Cross-import overlays.


They both talk about changing import functionality, but mine focuses more on adding a module to another in one on import, not changing the imported module based on what other modules are being imported.

Just a question for anyone looking: Should multiple @attached imports in one module lead to a build error?