Skip to content

Commit 39d56f4

Browse files
author
Github Action
committed
chore: synced pact-plugins docs
1 parent 7a6c519 commit 39d56f4

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

website/docs/implementation_guides/pact_plugins/docs/writing-plugin-guide.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ just the script files plus this manifest, installed the same way as any other pl
181181

182182
Your entry point script must define these global functions. Request/response "tables" below use plain Lua
183183
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).
185187

186188
- **`init(implementation, version) -> table`** - called once, right after your script is loaded. Must return an
187189
array of catalogue entries, each shaped as:
@@ -273,11 +275,35 @@ The driver registers a few host (native) functions as Lua globals before loading
273275
reference plugin; if your plugin needs different cryptographic or encoding primitives, either implement them in
274276
pure Lua or pull in a [LuaRocks package](#luarocks-support) that provides them.
275277

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+
276302
### LuaRocks support
277303

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`:
281307

282308
```
283309
<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
302328
compiled C extensions (under a rocks tree's `lib/lua`) are not, since those would need to be compiled
303329
per-platform, which defeats much of the point of writing a plugin in Lua in the first place.
304330

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+
305335
### Output and logging
306336

307337
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

Comments
 (0)