From eec84c0d49e3d7d2259dcf6794eadd3e3c423184 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 17 Oct 2019 15:36:31 +0800 Subject: [PATCH] fix: fix "lint on commit" projects generation error (#4697) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- packages/@vue/cli-plugin-eslint/generator/index.js | 14 ++++++++++---- .../@vue/cli-plugin-typescript/generator/index.js | 2 +- packages/@vue/cli-ui/package.json | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/@vue/cli-plugin-eslint/generator/index.js b/packages/@vue/cli-plugin-eslint/generator/index.js index b5aa03d342..64688ff34f 100644 --- a/packages/@vue/cli-plugin-eslint/generator/index.js +++ b/packages/@vue/cli-plugin-eslint/generator/index.js @@ -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' @@ -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) {} }) } diff --git a/packages/@vue/cli-plugin-typescript/generator/index.js b/packages/@vue/cli-plugin-typescript/generator/index.js index 151bfa3020..d2f564dd18 100644 --- a/packages/@vue/cli-plugin-typescript/generator/index.js +++ b/packages/@vue/cli-plugin-typescript/generator/index.js @@ -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' diff --git a/packages/@vue/cli-ui/package.json b/packages/@vue/cli-ui/package.json index b84b3a31f6..f7c9244103 100644 --- a/packages/@vue/cli-ui/package.json +++ b/packages/@vue/cli-ui/package.json @@ -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",