resolve dependencies
1.0.0
npm i resolve-dependencies
resolve-dependencies最初是Nexe的Bundler。我们不是要建造一个捆绑器,而是那样。
default: resolveSync(options: Options, ...opts: Options[]): Promise<Result>Options :对象|字符串- 从(如果字符串)开始的条目entries :字符串[] - 针对遍历的入口点列表,针对CWD解决cwd :字符串- 分辨率从loadContent : boolean-指示应包括int filemap的内容(对于大依赖树来说可能是不合理的)files : ({[键:字符串]:文件| null})[] - 已经解决的文件的缓存expand : '全部'| '无'| “变量” - 如何扩展模块上下文以包括额外的文件所有选项都深入合并,添加字符串选项作为entries
结果返回结果对象的承诺:
Result :对象entries : {[键:输入]:file} - 提供给resolve方法的所有条目和连接files的树files : {[键:abspath]:文件} - 所有已解决的文件均由其绝对路径键入warnings :字符串[] - 处理files时生成的数组警告File具有以下形状
File :对象- 代表文件的对象size :数字- 链接或文件的文件大小absPath :字符串- 文件的绝对路径moduleRoot :字符串|未定义的- 包含模块包的目录。package :任何|不明确的deps : {[键:请求]:文件| null} - 文件中标识的依赖项,由请求键键belongsTo :文件|未定义- 拥有模块的主文件realSize :数字|未定义- 如果斜肌是符号链接,则设置为realfile尺寸realPath :字符串|未定义- 如果斜肌是符号链接,则将其设置为真实路径contents :字符串|无效的contextExpanded :布尔值variableImports :布尔值 import resolveDependencies from 'resolve-dependencies'
const { entries , files } = resolveDependencies ( './entry-file.js' )
console . log ( entries [ './entry-file.js' ] )
// {
// absPath: "/path/to/entry-file.js",
// contents: "console.log('hello world')",
// realSize: 26,
// realPath: "/path/to/entry/lib/file.js"
// size: 12
// variableImports: false,
// deps: {
// "./dependency": {
// absPath: "/path/to/dependency.js"
// ...
// },
// path: null, //node builtin does not resolve
// mkdirp: {
// absPath: "/path/to/node_modules/mkdirp/index.js",
// modulePath: "/path/to/node_modules/mkdirp",
// package: {
// name: "mkdirp"
// ...
// }
// }
// }
// }
// `files` is a similar structure to entries, but
// is flat and keyed by the file's absolute path.