Skip to content

Commit

Permalink
fix: fix "lint on commit" projects generation error (#4697)
Browse files Browse the repository at this point in the history
Fixes #4694
Fixes #4695

Fix the "ENOENT: no such file or directory … debugnode_module/sms/index.js" error.

The problem are caused by 2 issues:
1. The `lint-staged` packages introduced an old version of debug,
causing node_module deduping, thus changing the node_module layout
2. The dependencies required in the cached `lint` module is no longer at
its originial position, thus the "ENOENT" error.

This change still does not fix the PNPM 4 issue, considering its smaller
user base, we'll fix it later.
  • Loading branch information
sodatea committed Oct 17, 2019
1 parent 8b08c73 commit eec84c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions packages/@vue/cli-plugin-eslint/generator/index.js
Expand Up @@ -68,7 +68,7 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {

if (lintOn.includes('commit')) {
Object.assign(pkg.devDependencies, {
'lint-staged': '^8.1.5'
'lint-staged': '^9.4.2'
})
pkg.gitHooks = {
'pre-commit': 'lint-staged'
Expand Down Expand Up @@ -103,12 +103,18 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
}
}

const lint = require('../lint')

// In PNPM v4, due to their implementation of the module resolution mechanism,
// put require('../lint') in the callback would raise a "Module not found" error,
// But we cannot cache the file outside the callback,
// because the node_module layout may change after the "intall additional dependencies"
// phase, thus making the cached module fail to execute.
// FIXME: at the moment we have to catch the bug and silently fail. Need to fix later.
module.exports.hooks = (api) => {
// lint & fix after create to ensure files adhere to chosen config
api.afterAnyInvoke(() => {
lint({ silent: true }, api)
try {
require('../lint')({ silent: true }, api)
} catch (e) {}
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-typescript/generator/index.js
Expand Up @@ -42,7 +42,7 @@ module.exports = (api, {
if (lintOn.includes('commit')) {
api.extendPackage({
devDependencies: {
'lint-staged': '^8.1.5'
'lint-staged': '^9.4.2'
},
gitHooks: {
'pre-commit': 'lint-staged'
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-ui/package.json
Expand Up @@ -78,7 +78,7 @@
"cross-env": "^5.1.5",
"eslint": "^5.16.0",
"eslint-plugin-graphql": "^3.0.3",
"lint-staged": "^8.1.5",
"lint-staged": "^9.4.2",
"lodash.debounce": "^4.0.8",
"portal-vue": "^1.3.0",
"rimraf": "^2.6.2",
Expand Down

0 comments on commit eec84c0

Please sign in to comment.