匹配npm脚本中的多个文件扩展名 [英] Match multiple file extensions in npm script

查看:101
本文介绍了匹配npm脚本中的多个文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个npm脚本,我想同时匹配tstsx文件扩展名...类似下面的内容:

I have an npm script where I want to match both ts and tsx file extensions... something like below:

"test": "mocha ..... app/test/**/*.spec.{ts,tsx}"

但是,以上语法不起作用.正确的语法是什么?

However, the above syntax doesn't work. What's the correct syntax for doing this?

推荐答案

您的模式正确.您的问题是您的外壳程序正在尝试为您扩展glob,而不是让mocha扩展它.

Your pattern is correct. Your problem is that your shell is attempting to expand your glob for you instead of letting mocha expand it.

要解决此问题,您需要对glob进行双引号(请注意,双引号必须使用\进行JSON转义):

To fix this, you need to double-quote your glob (note that double-quotes must be JSON-escaped with \):

"test": "mocha ..... \"app/test/**/*.spec.{ts,tsx}\""

如果您不关心Windows支持,也可以使用单引号(并且不需要使用JSON换码).

Single quotes will also work (and won't need JSON-escaped) if you don't care about Windows support.

这篇关于匹配npm脚本中的多个文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆