[英]Exclude node_modules recursively
I came across a specific issue when setting up Firebase in my project directory. 在我的项目目录中设置Firebase时遇到一个特定问题。
Initially, project's hierarchy could be summed up by the following : 最初,项目的层次结构可以归纳为以下内容:
.
./src
./src/my_code.js
./src/my_code.test.js
./node_modules
./node_modules/...
./package.json
To run my tests, I'm using mocha. 为了运行测试,我正在使用摩卡咖啡。
On this very website, I found a really useful regexp able to match all *.test.js files in the whole project hierarchy, except the node_modules "branch" : 在这个网站上,我发现了一个非常有用的正则表达式,可以匹配整个项目层次结构中的所有* .test.js文件,除了node_modules “ branch”:
./{,!(node_modules)/**}/*test.js
Next step for me was to initialize Firebase Functions & Hosting in the directory. 对我而言,下一步是在目录中初始化Firebase Functions&Hosting。
A design choice was made to set up the functions
folder in ./src
. 进行了设计选择,以在
./src
设置functions
文件夹。
After running firebase init
and answering all the questions, my folder looked like that : 运行
firebase init
并回答所有问题后,我的文件夹如下所示:
.
./src
./src/my_code.js
./src/my_code.test.js
// ===== NEW =====
./src/functions
./src/functions/index.js
./src/functions/index.test.js
./src/functions/node_modules
./src/functions/node_modules/...
./src/functions/package.json
// ===============
./node_modules
.node_modules/...
./package.json
The problem lies in that the regexp appears not to exclude the ./src/functions/node_modules
folder . 问题在于regexp似乎不排除
./src/functions/node_modules
文件夹 。
I'm not really at ease to extend this cool regexp, not knowing if I have to add **
or a !(src/functions/node_modules)
somewhere. 我真的不容易扩展这个很酷的正则表达式,不知道我是否必须在某个地方添加
**
或!(src/functions/node_modules)
。
I took a deep look into this mochajs' issue . 我对这个mochajs的问题进行了深入研究。
First of all, it appears that, as @Wiktor mentioned in my question's comments, ./{,!(node_modules)/**}/*test.js
isn't a regex, but a glob. 首先, 正如@Wiktor在我的问题的评论中提到的那样,。/
./{,!(node_modules)/**}/*test.js
,!( ./{,!(node_modules)/**}/*test.js
不是正则表达式,而是一个问题。
I didn't investigated this concept further for now, because mochajs
now implement an --exclude
flag feature. 我现在没有进一步研究这个概念,因为
mochajs
现在实现了--exclude
标志功能。
My solution is the following : mocha \\"./**/*test.js\\" --exclude \\"./**/node_modules/**\\"
. 我的解决方案如下:
mocha \\"./**/*test.js\\" --exclude \\"./**/node_modules/**\\"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.