如何屏蔽 Lerna 包的内部结构,使其他包无法导入它们?
我正在使用 Lerna monorepo。我经常看到一个包从另一个包的深处进行导入,例如:
import { SomeType } from "@schema/folder/folder/file.ts"
这是不可取的,因为有时我们需要在通过 index.d.ts
导出自动生成的类型之前对其进行转换。这有时会导致从包深处导入错误的、未转换的类型。
我想以某种方式限制一个包向其他包公开的文件/文件夹,因此这样的导入是不可能的:
import { SomeType } from "@schema" // valid
import { SomeType2 } from "@schema/folder/folder/file.ts" // invalid
我的选择是什么?
我不确定我还能提供什么其他信息,因为我对这些东西几乎没有经验。
I am working with a Lerna monorepo. I often see one package make imports from deep inside another package, for example:
import { SomeType } from "@schema/folder/folder/file.ts"
This is undesirable, because sometimes we need to transform auto-generated types before exporting them via index.d.ts
. This sometimes results in the wrong, non-transformed type being imported from deep inside the package.
I would like to somehow constrain the files/folders that one package exposes to the others, so such imports would not be possible:
import { SomeType } from "@schema" // valid
import { SomeType2 } from "@schema/folder/folder/file.ts" // invalid
What are my options?
I am not sure what other info I can provide since I have little to no experience with this stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用
eslint
时,您可以将no-restricted-imports
规则添加到包的 eslint 设置中:When you use
eslint
, you can add ano-restricted-imports
rule to the eslint settings of the package: