-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat: add conditional load of version #2605
Conversation
package.json
Outdated
"bench": "npm run gen-version && branchcmp -r 2 -g -s \"npm run benchmark\"", | ||
"benchmark": "npm run gen-version && npx concurrently -k -s first \"node ./examples/simple.js\" \"npx autocannon -c 100 -d 5 -p 10 localhost:3000/\"", | ||
"license-checker": "license-checker --production --onlyAllow=\"MIT;ISC;BSD-3-Clause;BSD-2-Clause\"", | ||
"gen-version": "node build/build-version.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also add this to prepublish hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of the publish stack. Can add if required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/fastify/releasify is usually used.
Since it eventually does npm publish
, I think standard npm prepublish hooks should work fine. prepublishOnly
seems like the right one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am 👎 on this as well. I don't think we should have to accommodate tools that modify source code they do not own. We ship a package.json
with our library. We should be able to work with that package.json
at run time. Reading the original issue, it sounds like the tooling the reporter uses removes that package.json
and that's not our fault.
@jsumners Original issue seems to be a valid used-case, though. Webpack is a popular solution for packaging serverless functions, and omitting package.json doesn't seem to be wrong in context. Do you think that skipping version check for when package.json is not found would be a better approach? |
I think we clearly state that we do not support such scenarios: Lines 12 to 20 in 341bbc8
|
I think the best solution is to skip the check if the file could not be loaded. |
In this case on the non packaged version the test stack will work and the built version would skip it indeed. So here https://github.com/fastify/fastify/blob/master/lib/pluginUtils.js#L89 we would just have to check if So if we're unable to load the version we set |
Il move that check in the module scope of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind to add a test for this? You might need to use proxyquire to mock fs
.
fastify.js
Outdated
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))) | ||
return pkg.version | ||
const pkgPath = path.join(__dirname, 'package.json') | ||
if (fs.existsSync(pkgPath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://nodejs.org/api/fs.html#fs_fs_accesssync_path_mode < let's use this instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using fs.accessSync
requires wrapping the block in a try/catch since that function throws an error on failure rather than returning a boolean
like fs.existsSync
.
Even addressing that, this change does not resolve the issue. I just tried with this change and the following error is outputted:
fastify not found, proceeding anyway
FastifyError [Error]: fastify-plugin: fastify-compress - expected '3.x' fastify version, '%s' is installed
at Object.checkVersion (webpack-internal:///./node_modules/fastify/lib/pluginUtils.js:96:63)
at Object.registerPlugin (webpack-internal:///./node_modules/fastify/lib/pluginUtils.js:110:16)
at Boot.override (webpack-internal:///./node_modules/fastify/lib/pluginOverride.js:28:57)
at Plugin.exec (webpack-internal:///./node_modules/avvio/plugin.js:79:33)
at Boot.loadPlugin (webpack-internal:///./node_modules/avvio/plugin.js:266:10)
at Task.release (webpack-internal:///./node_modules/fastq/queue.js:140:16)
at worked (webpack-internal:///./node_modules/fastq/queue.js:182:10)
at eval (webpack-internal:///./node_modules/avvio/plugin.js:269:7)
at done (webpack-internal:///./node_modules/avvio/plugin.js:201:5)
at check (webpack-internal:///./node_modules/avvio/plugin.js:225:9)
at internal/process/task_queues.js:153:7
at AsyncResource.runInAsyncScope (async_hooks.js:186:9)
at AsyncResource.runMicrotask (internal/process/task_queues.js:150:8)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 'FST_ERR_PLUGIN_VERSION_MISMATCH',
statusCode: 500
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fix: #2603
as discussed in #2604
edit: switching to conditional loading like mentioned in : #2605 (comment)
Checklist
npm run test
andnpm run benchmark
and the Code of conduct