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.