-
-
Notifications
You must be signed in to change notification settings - Fork 44
Fixes fastify version check in ESM context #102
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
Conversation
|
Still need proper ESM tests. Going to add them. |
|
Test added |
|
a better solution is to move this check from fastify-plugin to fastify itself. |
mcollina
left a comment
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
RafaelGSS
left a comment
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.
Good work!
L2jLiga
left a comment
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.
👍
mcollina
left a comment
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
| // We need to dynamically compute this to support yarn pnp | ||
| pkgPath = join(dirname(require.resolve('fastify', { paths: [require.main.filename] })), 'package.json') | ||
| pkgPath = resolvePkgPath(require.main.filename) | ||
| } else if (process.argv[1]) { |
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.
In AWS Lambda this is causing the unwanted log statement "fastify not found, proceeding anyway"
In AWS Lambda the process.argv are: [ '/var/lang/bin/node', '/var/runtime/index.js' ]
@mcollina Do you want me to create a PR to check it like this?
//...
} else if (process.argv[1] && process.argv[1] !== '/var/runtime/index.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.
I don't think that's a correct fix. What's the require.main and require.name.filename in lambdas?
In other terms, I think your breakage was caused by b3f4aa1#diff-18e559ebd3cc204a52bc1dc3db2adf8b not this PR.
Can you open a new issue?
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.
You're probably right... will create a little console.log example...
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.
require.main.filename = /var/runtime/index.js
require.main = {
id: '.',
path: '/var/runtime',
exports: {},
parent: null,
filename: '/var/runtime/index.js',
loaded: true,
children: [
Module {
id: '/var/runtime/RAPIDClient.js',
path: '/var/runtime',
exports: [Function: RAPIDClient],
parent: [Circular],
filename: '/var/runtime/RAPIDClient.js',
loaded: true,
children: [Array],
paths: [Array]
},
Module {
id: '/var/runtime/Runtime.js',
path: '/var/runtime',
exports: [Function: Runtime],
parent: [Circular],
filename: '/var/runtime/Runtime.js',
loaded: true,
children: [Array],
paths: [Array]
},
Module {
id: '/var/runtime/UserFunction.js',
path: '/var/runtime',
exports: [Object],
parent: [Circular],
filename: '/var/runtime/UserFunction.js',
loaded: true,
children: [Array],
paths: [Array]
},
Module {
id: '/var/runtime/Errors.js',
path: '/var/runtime',
exports: [Object],
parent: [Module],
filename: '/var/runtime/Errors.js',
loaded: true,
children: [],
paths: [Array]
},
Module {
id: '/var/runtime/BeforeExitListener.js',
path: '/var/runtime',
exports: [Object],
parent: [Module],
filename: '/var/runtime/BeforeExitListener.js',
loaded: true,
children: [],
paths: [Array]
},
Module {
id: '/var/runtime/LogPatch.js',
path: '/var/runtime',
exports: [Object],
parent: [Module],
filename: '/var/runtime/LogPatch.js',
loaded: true,
children: [],
paths: [Array]
}
],
paths: [ '/var/runtime/node_modules', '/var/node_modules', '/node_modules' ]
}
process.argv = [ '/var/lang/bin/node', '/var/runtime/index.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.
So I think this fix was wrong all the way. Instead of using an if, we need to try them all. Can you send a PR?
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.
Can try to do a quick-fix PR for fastify-plugin, but not enough time for fastify/fastify#2507
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.
yep, go for the fix here. Essentially we need to try all of those locations.
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.
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.

Fixes: #101
Checklist
npm run testandnpm run benchmarkand the Code of conduct