Skip to main content
Libraries change. A method can be renamed, removed, or keep its name and change its meaning. A plugin that narrates the old meaning for new code is worse than no plugin, so Narrator gives plugins three tools: a declared version range, the major version each package declares, and an option for pinning a major version by hand.

Declare the library you read

Set library to the npm package your plugin reads and the semver range you wrote it against.
Every plugin in the repository declares its range. The field is metadata: the engine doesn’t read it, but tools can, for example to warn when a project’s installed version is outside the range. Declaring it costs nothing.

Handle breaking majors

When two majors of a library use the same name for different things, the plugin can’t tell from the code alone which one it is reading. It can tell from the file’s package, though. When the narrator has a dependency index, e.libraryMajor("effect") returns the major version the nearest package.json declares, for example 3 for "^3.10.0". Plugins whose libraries changed meaning also take a version option, which wins over the package:
When neither is known, the plugin runs in auto mode. Auto mode reads the names from both majors, and for a name whose meaning changed it uses a phrasing written to be true in either version. So the order is: the pinned version, then the package’s declared major, then auto. Here is the same Effect schema read with each setting. In Effect 3, Schema.Date decodes a date from a string. In Effect 4 it is a date value.
Effect 3
English
Effect 4
English
Effect.catch is another example. In Effect 4 it catches every failure. In Effect 3 it takes a discriminator and catches one kind of failure. Pinning to one major also drops the other major’s names entirely, so a v3-only API in a v4 codebase is narrated generically instead of being explained with the wrong meaning.

Writing a versioned plugin

Resolve the version inside your rules, because the engine only knows the file’s package once narration starts:
The Effect plugin keeps its rules in groups and merges one table per mode up front, then picks a table per file. You can copy the pattern:
Test each mode. The repository’s Effect tests narrate the same snippet with version: 3, version: 4 and no version, and assert each output. The Elysia tests do the same with versions 1 and 2.