How do I determine the package that installed a javascript executable?

I have file called node_modules/.bin/openapi. I was trying to figure out:

  • where the source is for that; and
  • what package created it.

I have solved the problem and I now want to know how to do this efficiently. The file node_modules/.bin/openapi is created by the @redocly/cli package. Inside the package.json it has:

"bin": {
  "openapi": "bin/cli.js",
  "redocly": "bin/cli.js"
},

The file node_modules/@redocly/cli/bin/cli.js is very simple:

#!/usr/bin/env node
  
require('../lib/index');

That’s the same file that was getting installed into node_modules/.bin/openapi.

But how can you efficiently, given an install artifact like node_modules/.bin/openapi, trace back to the package that created it?