Fixes fastify version check in ESM context#102
Fixes fastify version check in ESM context#102mcollina merged 6 commits intofastify:masterfrom fox1t:master
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. |
| // 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.
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.
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.
You're probably right... will create a little console.log example...
There was a problem hiding this comment.
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.
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.
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.
yep, go for the fix here. Essentially we need to try all of those locations.

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