| 107 | } |
| 108 | |
| 109 | function checkVersion (fn) { |
| 110 | const meta = getMeta(fn) |
| 111 | if (meta?.fastify == null) return |
| 112 | |
| 113 | const requiredVersion = meta.fastify |
| 114 | |
| 115 | const fastifyRc = rcRegex.test(this.version) |
| 116 | if (fastifyRc === true && semver.gt(this.version, semver.coerce(requiredVersion)) === true) { |
| 117 | // A Fastify release candidate phase is taking place. In order to reduce |
| 118 | // the effort needed to test plugins with the RC, we allow plugins targeting |
| 119 | // the prior Fastify release to be loaded. |
| 120 | return |
| 121 | } |
| 122 | if (requiredVersion && semver.satisfies(this.version, requiredVersion, { includePrerelease: fastifyRc }) === false) { |
| 123 | // We are not in a release candidate phase. Thus, we must honor the semver |
| 124 | // ranges defined by the plugin's metadata. Which is to say, if the plugin |
| 125 | // expects an older version of Fastify than the _current_ version, we will |
| 126 | // throw an error. |
| 127 | throw new FST_ERR_PLUGIN_VERSION_MISMATCH(meta.name, requiredVersion, this.version) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | function registerPluginName (fn) { |
| 132 | const meta = getMeta(fn) |