[英]Is there a way to set `//@dart=2.12` for an entire package/lib/folder?
When migrating large code bases to nnbd, it would be helpful if we could opt entire local packages in/out of NNBD.在将大型代码库迁移到 nnbd 时,如果我们可以选择整个本地包加入/退出 NNBD,将会很有帮助。 For example, I may want to migrate some of my leaf nodes first, like
/lib/helper_widgets/*
before moving onto the higher-order views.例如,我可能想先迁移一些叶节点,例如
/lib/helper_widgets/*
,然后再迁移到高阶视图。
Currently dart supports this on a per file basis using // @dart=2.12
which is fairly tedious if your package has many files.目前 dart 使用
// @dart=2.12
在每个文件的基础上支持此功能,如果您的 package 有很多文件,这是相当乏味的。
I was hoping I could do this with lib
and part of
, but this just gives me a compile error, to add a header to each file.我希望我可以使用
lib
和part of
来做到这一点,但这只会给我一个编译错误,将 header 添加到每个文件中。
[Edit] A pragmatic solution here is to run something like find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/"
[编辑] 一个实用的解决方案是运行
find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/"
find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/"
find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/"
on your project. find. -name "*.dart" | xargs sed -i "1s/^/\/\/ @dart=2.9\n/"
在你的项目上。 That will put the 2.9 import in every file.这会将 2.9 导入到每个文件中。 At that pt, you can use find/replace to just turn on entire sub-directories of your /lib code.
在那个 pt,您可以使用 find/replace 来打开 /lib 代码的整个子目录。
It's gonna be either per file, or with the pubspec.yaml
.它可以是每个文件,也可以是
pubspec.yaml
。 The pubspec method will change the entire package. pubspec 方法会改变整个 package。 If you use
dart migrate
, that's one of the steps it performs.如果您使用
dart migrate
,这是它执行的步骤之一。 Then be sure to dart pub upgrade
, because a different set of dependencies will then be available.然后一定要
dart pub upgrade
,因为随后会有一组不同的依赖项可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.