查找Node.js原生模块的源代码,以及有关类型化模块的解释。

huangapple go评论100阅读模式
英文:

Finding the source code of the node.js native modules, and explanation about typed modules

问题

我有一台Windows机器。
我尝试找到Node.js获取本机模块源代码的位置。
我找到的只有包含“仅类型”模块的@types文件。
例如,模块“assert”存在于Node.js的GitHub主目录中的master/lib文件夹中,但在我的机器上,我只找到了类型化的assert.d.ts文件。
这个文件assert.d.ts不包含任何实现,只包含了没有实现的类型化函数。

我应该在哪里找到我的机器使用的代码?

此外,在Visual Studio的调试模式下,如果可以使“Step Into”选项引导我进入真实的源代码,那将非常好。目前,当涉及到进入模块(例如require时),它只会忽略它。

此外,当我在模块名称上按CTRL+MOUSE_CLICK时,Visual Studio会跳转到“仅类型”文件。

有人能帮助我找到并轻松访问真正的代码吗?

我添加了一个示例。这是从assert.d.ts(位于user/AppData/.../@types/node/)中获取的:

function fail(message?: string | Error): never;

就这些了!而在assert.js中,

https://github.com/nodejs/node/blob/master/lib/assert.js

我们有函数的实现。

如果有人可以解释一下幕后发生了什么,我将不胜感激!

感谢大家!

英文:

I have a Windonws machine.
I try to find where node takes the source code for the native module.
All I found is the @types file which contain only such of "Typed Only" modules.
for example, the module "assert" exist in the node github in master/lib folder but in my machine all i find is the typedscript assert.d.ts.
This file, assert.d.ts, DOES NOT COINTAIN ANY INPLEMENTATION , it only contained typed function with no implementation.

Where can I find the code that my machine uses?

also, it will be very nice that the "Step Into" option in debug mode in Visual Studio will lead me to the real source code. right now, it just ignore it when it come to step into modules (on require for example).

Also, when i click CTRL+MOUSE_CLICK on the module name, Visual Studio bring to that "Typed Only" file.

Can someone help my to find and access easy to the real code?

I add an example. this is from assert.d.ts (on user/AppData/.../@types/node/)

function fail(message?: string | Error): never;

and that is all! while in the assert.js in

https://github.com/nodejs/node/blob/master/lib/assert.js

we have the implementation of the function.

If someone can explain me what is going on there behind the scenes I would appreciate it!

Thnaks all

答案1

得分: 0

如果您正在使用 TypeScript,IDE 将转到文件定义.d.ts。要找到实现,您必须转到位于包名称下的 node_modules。您将找到所有内容。

英文:

if you are using typescript, the IDE will go to the file definition .d.ts. To find the implementation you must go to your node_modules under the package name and you will have everything.

huangapple
  • 本文由 发表于 2020年1月6日 19:21:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611211.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定