resolve dependencies
1.0.0
npm i resolve-dependencies
resolve-dependencies最初はNexeのバンドラーという名前です。バンドラーを構築するつもりではありませんでしたが、それが一種のものです。
default: resolveSync(options: Options, ...opts: Options[]): Promise<Result>Options :オブジェクト|文字列- 開始するエントリ(if string)entries : string [] - トラバースのエントリポイントのリスト、CWDに対して解決されましたcwd :文字列- 解像度が発生するベースディレクトリloadContent : boolean-コンテンツをfilemapに含める必要があることを示します(これは、大きな依存ツリーでは不合理かもしれません)files : ({[key:string]:file | null})[] - すでに解決されたファイルのキャッシュexpand : 'All' | 「なし」| 「変数」 - モジュールコンテキストを拡張して追加のファイルを含める方法すべてのオプションは深くマージされ、文字列オプションはentriesとして追加されます
結果は結果オブジェクトの約束を返します:
Result :オブジェクトentries : {[key:entry]:file} - resolve方法と接続されたfilesのツリーに提供されるすべてのエントリfiles : {[key:abspath]:file} - 絶対パスによってキーがキーになったすべての解決されたファイルwarnings : string [] - filesの処理中に生成された配列警告Fileには次の形状があります
File :オブジェクト- ファイルを表すオブジェクトsize :番号- リンクまたはファイルのファイルサイズabsPath :文字列- ファイルへの絶対パスmoduleRoot : string |未定義- モジュールPackage.jsonを含むディレクトリpackage :任意の|未定義deps : {[key:request]:file | null} - ファイルで識別された依存関係、リクエストによってキー付きbelongsTo :ファイル|未定義- 所有モジュールのメインファイルrealSize :番号|未定義- アブスパスがシンリンクの場合、レアフルサイズに設定しますrealPath :文字列|未定義- アブスパスがシンブリンクの場合、RealPathに設定しますcontents :文字列|ヌルcontextExpanded : BooleanvariableImports : boolean 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.