ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.52k stars 8.15k forks source link

🐛[BUG] package.json 中定义的 hooks pre-commit 没有生效 #5989

Closed maxmeng93 closed 4 years ago

maxmeng93 commented 4 years ago

🐛 bug 描述

git commit 时,钩子没有生效,没有检查代码

{
  "name": "magic",
  "version": "1.0.0",
  "private": true,
  "description": "magic",
  "scripts": {
    "analyze": "cross-env ANALYZE=1 umi build",
    "build": "umi build",
    "deploy": "npm run site && npm run gh-pages",
    "dev": "npm run start:dev",
    "format-imports": "cross-env import-sort --write '**/*.{js,jsx,ts,tsx}'",
    "lint": "npm run lint:js && npm run lint:style && npm run lint:prettier",
    "lint-staged": "lint-staged",
    "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
    "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
    "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
    "lint:prettier": "check-prettier lint",
    "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
    "prettier": "prettier -c --write \"**/*\"",
    "start": "cross-env UMI_UI=none umi dev",
    "start:dev": "cross-env REACT_APP_ENV=dev MOCK=none umi dev",
    "start:no-mock": "cross-env MOCK=none umi dev",
    "start:no-ui": "cross-env UMI_UI=none umi dev",
    "start:pre": "cross-env REACT_APP_ENV=pre umi dev",
    "start:test": "cross-env REACT_APP_ENV=test MOCK=none umi dev",
    "test": "umi test",
    "test:all": "node ./tests/run-tests.js",
    "test:component": "umi test ./src/components",
    "tsc": "tsc",
    "ui": "umi ui"
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run lint-staged"
    }
  },
  "lint-staged": {
    "**/*.less": "stylelint --syntax less",
    "**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js",
    "**/*.{js,jsx,tsx,ts,less,md,json}": [
      "prettier --write",
      "git add"
    ]
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 10"
  ],
  "dependencies": {
    "@ant-design/icons": "^4.0.0-rc.0",
    "@ant-design/pro-layout": "^5.0.0",
    "@antv/g2plot": "^0.11.31",
    "antd": "^4.0.0-rc.5",
    "axios": "^0.19.2",
    "classnames": "^2.2.6",
    "dva": "^2.6.0-beta.20",
    "lodash": "^4.17.15",
    "lodash-decorators": "^6.0.0",
    "lodash.debounce": "^4.0.8",
    "lodash.isequal": "^4.5.0",
    "mockjs": "^1.0.1-beta3",
    "moment": "^2.24.0",
    "numeral": "^2.0.6",
    "nzh": "^1.0.3",
    "omit.js": "^1.0.2",
    "path-to-regexp": "^2.4.0",
    "prop-types": "^15.5.10",
    "qs": "^6.9.1",
    "react": "^16.12.0",
    "react-copy-to-clipboard": "^5.0.2",
    "react-dom": "^16.12.0",
    "react-fittext": "^1.0.0",
    "react-helmet": "^5.2.1",
    "react-router": "^4.3.1",
    "redux": "^4.0.5",
    "umi": "^2.13.3",
    "umi-plugin-antd-theme": "^1.0.15",
    "umi-plugin-pro-block": "^1.3.6",
    "umi-plugin-react": "^1.15.2",
    "umi-request": "^1.2.18",
    "use-merge-value": "^1.0.1"
  },
  "devDependencies": {
    "@ant-design/pro-cli": "^1.0.19",
    "@types/classnames": "^2.2.9",
    "@types/express": "^4.17.2",
    "@types/history": "^4.7.5",
    "@types/jest": "^25.1.2",
    "@types/lodash": "^4.14.149",
    "@types/lodash.debounce": "^4.0.6",
    "@types/lodash.isequal": "^4.5.5",
    "@types/qs": "^6.9.1",
    "@types/react": "^16.9.19",
    "@types/react-dom": "^16.9.5",
    "@types/react-helmet": "^5.0.15",
    "@types/react-router": "^5.1.4",
    "@umijs/fabric": "^2.0.2",
    "chalk": "^3.0.0",
    "check-prettier": "^1.0.3",
    "cross-env": "^7.0.0",
    "cross-port-killer": "^1.2.1",
    "enzyme": "^3.11.0",
    "eslint": "^6.8.0",
    "express": "^4.17.1",
    "husky": "^4.2.3",
    "import-sort-cli": "^6.0.0",
    "import-sort-parser-babylon": "^6.0.0",
    "import-sort-parser-typescript": "^6.0.0",
    "import-sort-style-module": "^6.0.0",
    "jsdom-global": "^3.0.2",
    "lint-staged": "^10.0.7",
    "mockjs": "^1.1.0",
    "node-fetch": "^2.6.0",
    "prettier": "^1.19.1",
    "pro-download": "^1.0.1",
    "stylelint": "^13.2.0",
    "umi-plugin-antd-icon-config": "^1.0.3",
    "umi-plugin-ga": "^1.1.5",
    "umi-plugin-pro": "^1.0.2",
    "umi-types": "^0.5.12"
  },
  "engines": {
    "node": ">=10.0.0"
  },
  "checkFiles": [
    "src/**/*.js*",
    "src/**/*.ts*",
    "src/**/*.less",
    "config/**/*.js*",
    "scripts/**/*.js"
  ]
}

📷 复现步骤

🏞 期望结果

💻 复现代码

© 版本信息

🚑 其他信息

chenshuai2144 commented 4 years ago

husky 依赖是不是安装失败了, husky 会在 .git 中注册hooks,你可以删除依赖重新安装一下

maxmeng93 commented 4 years ago

确实是依赖问题

ghost commented 4 years ago

你好解决了嘛,跟你一样的项目配置,遇到同样的问题,请问你是怎么解决的

ghost commented 4 years ago

你好,跟你一样的项目版本信息,遇到同样的问题,请问你是怎么解决的尼,不胜感激

afc163 commented 4 years ago

https://github.com/cnpm/cnpm/issues/318

cnpm 有问题。

ghost commented 4 years ago

直接用npm安装就没有问题了嘛?

maxmeng93 commented 4 years ago

你好解决了嘛,跟你一样的项目配置,遇到同样的问题,请问你是怎么解决的

把 husky 重装了一下

nnmax commented 3 years ago

eslint --ext .js,.jsx,.ts,.tsx 这个命令有问题吧?看看 eslint 官网对 --ext 参数的描述