0.2.2 • Published 1 year ago

import-chain v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

import-chain

show which file import the target file

通过一级级的查找引用目标文件的父文件,来找到引用目标文件的最顶层文件,并且给出引用链路。

可以用它来做什么?

  1. 当我们修改一个文件之后,可以通过这个库来得知这个修改的影响范围。
  2. 可以和 lint-staged 搭配,获取每次 commit 的影响范围
  3. 可以检测哪些文件没有被使用

这个库导出一个函数 getImportChain,它的第一个参数是需要查找的目标文件路径数据,第二个参数是配置项,配置项的签名是:

export interface ImportChainOptions {
  includedPath?: string[]           // 目标文件路径数组,会被传入 fast-glob 里面
  excludedPath?: string[]           // 不包含的目标文件路径数组,会被传入 fast-glob 的 ignore里面
  extensions: string[]              // 支持的文件后缀,默认值为:['.ts', '.vue', '.js', '.jsx', '.tsx', '.d.ts']
  baseUrl?: string                  // 和 tsconfig 里面的 baseUrl 一样,默认值为 '.'
  paths?: Record<string, string[]>  // 和 tsconfig 里面的 paths 一样
  tsconfigPath?: string             // tsconfig 的路径。默认会查找根目录下的 tsconfig
}

函数会返回一个数组,里面的每一项的签名如下:

export interface ImportChainResultItem {
  path: string            // 目标文件的路径
  root: string[]          // 目标文件被引用的顶层文件
  parents: string[][]     // 目标文件的被引用链路
}

cli

这个库还能被当做 cli 使用。只不过 cli 只能识别一个目标文件,使用方法如下:

import-chain './pages/**/*.vue' './components/**/*.vue' './components/package-options/mobile/sku/components/time.vue'

cli 会识别最后一个 args 作为目标文件,前面的 args 都会识别为 includedPath。

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago