You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/implementation_guides/pact_plugins/docs/writing-plugin-guide.md
+34-4Lines changed: 34 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -181,7 +181,9 @@ just the script files plus this manifest, installed the same way as any other pl
181
181
182
182
Your entry point script must define these global functions. Request/response "tables" below use plain Lua
183
183
tables with string keys, mapping directly to the fields of the corresponding gRPC message (see the
184
-
[proto file](https://github.com/pact-foundation/pact-plugins/blob/main/proto/plugin.proto)) - the driver converts between the two automatically.
184
+
[proto file](https://github.com/pact-foundation/pact-plugins/blob/main/proto/plugin.proto)) - the driver converts between the two automatically. For a complete,
185
+
field-by-field reference of every function and table shape mentioned below, see the
186
+
[Lua plugin function reference](https://github.com/pact-foundation/pact-plugins/blob/main/lua-plugin-reference.md).
185
187
186
188
-**`init(implementation, version) -> table`** - called once, right after your script is loaded. Must return an
187
189
array of catalogue entries, each shaped as:
@@ -273,11 +275,35 @@ The driver registers a few host (native) functions as Lua globals before loading
273
275
reference plugin; if your plugin needs different cryptographic or encoding primitives, either implement them in
274
276
pure Lua or pull in a [LuaRocks package](#luarocks-support) that provides them.
275
277
278
+
### Vendoring dependencies (preferred)
279
+
280
+
For any pure-Lua dependency your plugin needs, prefer copying its source directly into your plugin directory
281
+
over relying on an installed LuaRocks tree (below). The [JWT reference plugin](https://github.com/pact-foundation/pact-plugins/blob/main/plugins/jwt) does exactly
282
+
this - `base64.lua`, `json.lua`, and `inspect.lua` are vendored straight into `plugins/jwt/`, not fetched via
283
+
LuaRocks.
284
+
285
+
Both drivers add the plugin's own directory (i.e. `pluginDir`, the directory containing `pact-plugin.json` -
286
+
not the directory your entry point script happens to live in, if you've nested it in a subdirectory) to
287
+
`package.path` unconditionally:
288
+
289
+
```
290
+
<plugin_dir>/?.lua
291
+
<plugin_dir>/?/init.lua
292
+
```
293
+
294
+
so `require "some_lib"` finds either a flat `some_lib.lua` or a directory-style `some_lib/init.lua`, whichever
295
+
shape the dependency happens to use - just copy its files into your plugin directory and `require` them.
296
+
297
+
Vendoring is the preferred approach because it keeps a Pact user's install step exactly the same as for any
298
+
other Lua plugin - they don't need LuaRocks, or any rocks tree, installed on their machine at all. Reach for
299
+
[LuaRocks support](#luarocks-support) below only where vendoring is impractical, e.g. an unusually large
300
+
dependency, or one you expect several installed plugins to share.
301
+
276
302
### LuaRocks support
277
303
278
-
Pure-Lua packages installed via [LuaRocks](https://luarocks.org/) are available to `require` in your script,
279
-
without needing to vendor every third-party library you depend on. Both drivers add the standard LuaRocks
280
-
per-Lua-version tree layout to `package.path`:
304
+
As a secondary, opt-in mechanism, pure-Lua packages installed via [LuaRocks](https://luarocks.org/) are also
305
+
available to `require` in your script. Both drivers add the standard LuaRocks per-Lua-version tree layout to
306
+
`package.path`:
281
307
282
308
```
283
309
<rocks_dir>/share/lua/5.4/?.lua
@@ -302,6 +328,10 @@ than erroring, since not every Lua plugin needs rocks. Only pure-Lua packages ar
302
328
compiled C extensions (under a rocks tree's `lib/lua`) are not, since those would need to be compiled
303
329
per-platform, which defeats much of the point of writing a plugin in Lua in the first place.
304
330
331
+
Unlike vendoring, this requires a Pact user to have LuaRocks (and the specific rocks your plugin depends on)
332
+
installed on their machine before your plugin will work - a real, if small, piece of extra setup your users
333
+
have to do that vendoring avoids entirely. Prefer vendoring wherever it's practical.
334
+
305
335
### Output and logging
306
336
307
337
Lua plugins don't have their own OS-level stdout/stderr the way a gRPC child process does - they run embedded in
0 commit comments