Skip to content

Commit eec84c0

Browse files
authored
fix: fix "lint on commit" projects generation error (#4697)
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.
1 parent 8b08c73 commit eec84c0

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

packages/@vue/cli-plugin-eslint/generator/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
6868

6969
if (lintOn.includes('commit')) {
7070
Object.assign(pkg.devDependencies, {
71-
'lint-staged': '^8.1.5'
71+
'lint-staged': '^9.4.2'
7272
})
7373
pkg.gitHooks = {
7474
'pre-commit': 'lint-staged'
@@ -103,12 +103,18 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
103103
}
104104
}
105105

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

packages/@vue/cli-plugin-typescript/generator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = (api, {
4242
if (lintOn.includes('commit')) {
4343
api.extendPackage({
4444
devDependencies: {
45-
'lint-staged': '^8.1.5'
45+
'lint-staged': '^9.4.2'
4646
},
4747
gitHooks: {
4848
'pre-commit': 'lint-staged'

packages/@vue/cli-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"cross-env": "^5.1.5",
7979
"eslint": "^5.16.0",
8080
"eslint-plugin-graphql": "^3.0.3",
81-
"lint-staged": "^8.1.5",
81+
"lint-staged": "^9.4.2",
8282
"lodash.debounce": "^4.0.8",
8383
"portal-vue": "^1.3.0",
8484
"rimraf": "^2.6.2",

0 commit comments

Comments
 (0)