@@ -177,9 +177,16 @@ fn load_environment_from_dir(path: &Path) -> anyhow::Result<TargetEnvironment> {
177
177
/// for example when it supports multiple versions of the Spin or WASI interfaces.)
178
178
///
179
179
/// In terms of implementation, internally the environment is represented by a
180
- /// WIT package that adheres to a specific naming convention (that the worlds for
181
- /// a given trigger type are exactly whose names begin `trigger-xxx` where
182
- /// `xxx` is the Spin trigger type).
180
+ /// WIT package that adheres to a specific naming convention - namely that the worlds for
181
+ /// a given trigger type are exactly whose names begin with one of:
182
+ ///
183
+ /// * `trigger-xxx`
184
+ /// * `xxx-trigger`
185
+ /// * `spin-xxx` (a convention used by some plugins)
186
+ ///
187
+ /// where `xxx` is the Spin trigger type. This flexibility is intended to maximise
188
+ /// reuse of existing WIT files rather than needing to create custom ones to
189
+ /// define environments.
183
190
pub struct TargetEnvironment {
184
191
name : String ,
185
192
decoded : wit_parser:: decoding:: DecodedWasm ,
@@ -243,10 +250,16 @@ impl TargetEnvironment {
243
250
/// Returns true if the given trigger type provides the world identified by
244
251
/// `world` in this environment.
245
252
pub fn is_world_for ( & self , trigger_type : & TriggerType , world : & wit_parser:: World ) -> bool {
246
- world . name . starts_with ( & format ! ( "trigger-{ trigger_type}" ) )
253
+ self . matches_world_name ( trigger_type, world )
247
254
&& world. package . is_some_and ( |p| p == self . package_id )
248
255
}
249
256
257
+ fn matches_world_name ( & self , trigger_type : & TriggerType , world : & wit_parser:: World ) -> bool {
258
+ world. name . starts_with ( & format ! ( "trigger-{trigger_type}" ) )
259
+ || world. name . starts_with ( & format ! ( "{trigger_type}-trigger" ) )
260
+ || world. name . starts_with ( & format ! ( "spin-{trigger_type}" ) )
261
+ }
262
+
250
263
/// Returns true if the given trigger type can run in this environment.
251
264
pub fn supports_trigger_type ( & self , trigger_type : & TriggerType ) -> bool {
252
265
self . decoded
0 commit comments