Skip to content

Commit

Permalink
Support rc in version checks (#3879)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed May 4, 2022
1 parent 44b580e commit 2c3aa4f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ function fastify (options) {

Object.defineProperties(fastify, {
pluginName: {
configurable: true,
get () {
if (this[kPluginNameChain].length > 1) {
return this[kPluginNameChain].join(' -> ')
Expand All @@ -323,18 +324,23 @@ function fastify (options) {
}
},
prefix: {
configurable: true,
get () { return this[kRoutePrefix] }
},
validatorCompiler: {
configurable: true,
get () { return this[kSchemaController].getValidatorCompiler() }
},
serializerCompiler: {
configurable: true,
get () { return this[kSchemaController].getSerializerCompiler() }
},
version: {
configurable: true,
get () { return VERSION }
},
errorHandler: {
configurable: true,
get () {
return this[kErrorHandler].func
}
Expand Down
3 changes: 2 additions & 1 deletion lib/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ function checkVersion (fn) {

const requiredVersion = meta.fastify

if (requiredVersion && !semver.satisfies(this.version, requiredVersion)) {
const sanitizedVersion = this.version.replace(/-rc.\d+$/, '')
if (requiredVersion && !semver.satisfies(sanitizedVersion, requiredVersion)) {
throw new FST_ERR_PLUGIN_VERSION_MISMATCH(meta.name, requiredVersion, this.version)
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,27 @@ test('plugin metadata - version not matching requirement 3', t => {
done()
}
})

test('plugin metadata - release candidate', t => {
t.plan(2)
const fastify = Fastify()
Object.defineProperty(fastify, 'version', {
value: '99.0.0-rc.1'
})

plugin[Symbol.for('plugin-meta')] = {
name: 'plugin',
fastify: '99.x'
}

fastify.register(plugin)

fastify.ready((err) => {
t.error(err)
t.pass('everything right')
})

function plugin (instance, opts, done) {
done()
}
})

0 comments on commit 2c3aa4f

Please sign in to comment.