4

我正在为我的新项目使用NestJs

我正在使用此命令添加所有文件。 git add .

当我在添加所有文件后提交时,赫斯基会阻止提交并向我显示此错误。

[文件路径]/.spec.ts' 不包含在项目中。

husky > pre-commit hook 失败(添加 --no-verify 绕过)

我隐式添加了该文件,但它仍然向我抛出该错误。

我的 tsconfig.json 文件

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "allowJs": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "lib": ["dom", "es2018", "esnext"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

这就是我在 package.json 文件中添加 husky 命令的方式

 "scripts": {
    "lint": "tslint -p tsconfig.json -c tslint.json",
  },


"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "post-commit": "git push origin HEAD"
    }
  },
  "lint-staged": {
    "*.ts": [
      "tslint -p tsconfig.json -c tslint.json",
      "git add"
    ]
  },
4

2 回答 2

3

If you are on windows OS, the hooks script which will include in your package.json should be of this form below

"husky": {
    "hooks": {
      "pre-push": "set CI=true&&npm test"
    }
  },

For other Operating System make use of below snippet

 "husky": {
 "hooks": {
 "pre-push": "CI=true npm test"}},

More information on: https://facebook.github.io/create-react-app/docs/running-tests#on-your-own-environment

于 2019-10-28T17:10:32.517 回答
0

可能是因为您的 tsconfig.json 文件"**/*.spec.ts"中的属性具有 as 值,您的预提交挂钩失败了吗?exclude

你能像这样编辑文件并测试它吗:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "allowJs": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "lib": ["dom", "es2018", "esnext"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
于 2019-01-08T09:42:33.127 回答