Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rc in version checks #3879

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)) {
Comment on lines +106 to +107
Copy link
Member

@jsumners jsumners May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about?:

const fastifyRc = /-rc.+$/.test(this.version)
if (requiredVersion && semver.satisfies(santizedVersion, requiredVersion, { includePrerelease: fastifyRc }) === false) {

https://github.com/npm/node-semver/tree/c56a701f45653940ee8536eafe43b3e46c11d6cc#functions

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'
}
Comment on lines +1039 to +1042
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should specify fastify: '^98.0.0'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is expected and the current case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is that an RC Fastify allows plugins that require earlier versions of Fastify with ^fastify-version instead of >=fastify-version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand, can you open a fresh issue if you think it's a bug?


fastify.register(plugin)

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

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