NodeJS 查找函数句柄的模块/文件

htrmnn0y  于 5个月前  发布在  Node.js
关注(0)|答案(1)|浏览(94)

在NodeJS中,给定一个函数句柄,如何找到声明该函数的文件或模块?
举例来说:

// File 1

import { test } from './file1'

function fileFile(fn: Function){
   //... here's my issue
}

console.log(findFile(test)) // Logs '~/a/b/file1.js'

个字符
我尝试过不同的方法,从使用v8require。我找不到一个合适的方法来做到这一点。我想找到fn.toString()的内容,但不会那么可靠。
想法呢?

h9vpoimq

h9vpoimq1#

即使在搜索和询问几个AI机器人。我没有找到它。但有一个解决方案。
我偶然发现了[[FunctionLocation]],然后当我搜索那个特定的词时,我发现了https://github.com/midrissi/func-loc
“我知道,就一会儿。”

相关问题