【问题标题】:tsconfig.json - add filesGlob entries for directories above tsconfig filetsconfig.json - 为 tsconfig 文件上方的目录添加 filesGlob 条目
【发布时间】:2017-07-31 14:23:55
【问题描述】:

我正在尝试使用 Typescript 在现有 Zend Framework 2 项目上创建 CasperJS 前端测试。

ZF2 项目结构是这样设置的:

project
- .composer
- config
- data 
- module
-- Application
-- Module1
--- config (module1 config)
--- src (php sources)
--- view (module1 view files)
--- test
---- Module1Test (has PHPUnit tests)
---- UI
----- Tests
------ SubArea
------ testArea.casper.ts
-- Module2
 ...
- public
- vendor
- tests
-- backend
-- frontend
--- casperjs
...
---- tsconfig.json

我试图让我的 tsconfig.json 查找并编译每个应用程序模块 Test 目录中的所有 *.casper.ts 文件,并编译到 root/tests/frontend 中的临时目录中。大约有30个模块。

目前我的文件如下所示:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "outDir": "./_tmp/build/"
  },
  "filesGlob": [
    "../../../module/**/test/UI/Tests/Demo/*.casper.ts",
    "!./node_modules/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

但它没有找到任何文件。

如何制定 filesGlob 规则以在 tsconfig.json 文件本身上方的目录中查找文件? 就像:

"../../../module/**/test/UI/Tests/Demo/*.casper.ts"

谢谢

【问题讨论】:

  • 是什么阻止您将构建相关文件(tsconfigtslintpackage.jsonnode_modules)放在项目的根目录中?这就是它们在逻辑上所属的地方,特别是如果您有 .ts 文件不在您的“前端根目录”下。
  • 根项目是ZF2项目,不是ts/js/casper项目。这些东西目前仅用于测试。我们还有其他事情要做,如果一切都在根源上,它就会变成狂野的西部。
  • +1 用于将 tsconfig 放在项目目录的根目录中,您的 filesGlob 中的文件模式看起来像狂野的西部,在目录中跳转等等 :)。它还将为您简化事情。您可能还应该寻找 [long-ass-path]/**/*.casper.ts 它将在 Demo 文件夹的任何子目录中获取您的 casper.ts 文件。
  • 此外,如果您的项目的文件夹结构发生变化,那么您使用的文字路径将成为维护的噩梦。我建议简单地将整个 ../../../blah/blah/blah/blah 路径替换为 ../../../**/*.casper.ts - 再次将 tsconfig 移动到项目根目录,您的路径将被简化为 **/*.casper.ts

标签: typescript tsconfig


【解决方案1】:

filesGlobdeprecated,自 Typescript 2.0 起在 tsconfig.json 中引入了 include

include 中指定的路径支持 glob 模式。

另外,为带有双星号的casper.ts 文件使用更宽泛的路径,如以下格式所示:

{
"compilerOptions": {
 ...
},
"include": ["./**/casper.ts"]
}

【讨论】:

  • 晚了将近 4 年 :D
  • @JoaoCarlos 哈哈,是的,迟到总比没有好。希望它能帮助其他遇到同样问题的人。
猜你喜欢
  • 2020-12-29
  • 1970-01-01
  • 2019-09-17
  • 2018-05-22
  • 1970-01-01
  • 2019-01-04
  • 2013-12-07
  • 2019-03-03
  • 2016-06-09
相关资源
最近更新 更多