Skip to content

Conversation

@fox1t
Copy link
Member

@fox1t fox1t commented Aug 19, 2020

Fixes: #101

Checklist

@fox1t fox1t closed this Aug 19, 2020
@fox1t fox1t reopened this Aug 19, 2020
@fox1t
Copy link
Member Author

fox1t commented Aug 19, 2020

Still need proper ESM tests. Going to add them.

@fox1t
Copy link
Member Author

fox1t commented Aug 19, 2020

Test added

@fox1t fox1t requested review from Eomm and mcollina August 19, 2020 08:27
@mcollina
Copy link
Member

a better solution is to move this check from fastify-plugin to fastify itself.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

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

Good work!

Copy link

@L2jLiga L2jLiga left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit d3b2ca4 into fastify:master Aug 20, 2020
// 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]) {
Copy link
Member

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' ) {
//...

Copy link
Member

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?

Copy link
Member

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...

Copy link
Member

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' ]

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Is something like this ok?
image

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fastify not found, proceeding anyway if running ES module Node.js program

6 participants