比如引入了
const fs = require('fs')
const express = require('express')
如何判断 fs 和 express 哪个是内建模块,哪个是第三方模块
比如引入了
const fs = require('fs')
const express = require('express')
如何判断 fs 和 express 哪个是内建模块,哪个是第三方模块
|
yanggJul 23, 2018
1
|
|
TonniJul 23, 2018
2
```
require.resolve('jquery').includes('node_modules') ``` 这样? |
|
yanggJul 23, 2018
3
const builtinMods = new Set(Object.keys(process.binding('natives')).filter(x => !/^_|^(internal|v8|node-inspect)/.test(x)))
buildinMods.has('fs') |
|
123sJul 23, 2018
4
你是想随便了解一下还是?
|
|
7
@123s 是这样的,我最近在写一份 tslint 的自定义 rule,该 rule 的主要功能就是区分 import 的模块的类型,把模块分类,然后代码格式化
|
|
yanggJul 23, 2018
9
@zzhbbdbbd 1 楼那个包的源码,
`process.binding` returns internal module, like require. It's not public, so you shouldn't rely on it in your code, but you can use it to play with node's low level objects, if you want to understand how things work. For example, here timer_wrap binding is registered. It exports Timer constructor. In lib/timers.js it's imported https://stackoverflow.com/questions/24042861/nodejs-what-does-process-binding-mean 你可以直接看 process.binding('fs')就知道大概他是干嘛的了 |
|
10
1. require.resolve(x) === x
2. require.resolve.paths(x) === null 需要 8.9 3. process.binding(x) 私有接口,还包括一些不能 require 的内部模块 |