From e81f9af7b13732a34cd72f19939d5006e2a5a8f4 Mon Sep 17 00:00:00 2001 From: "longgui.wjb" Date: Mon, 29 Nov 2021 15:15:23 +0800 Subject: [PATCH] fix: prepare before lintStaged mode and fix nullish issue --- packages/middleware-lint/src/core.ts | 2 +- packages/middleware-lint/src/index.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/middleware-lint/src/core.ts b/packages/middleware-lint/src/core.ts index 64de6241..33aa9fae 100644 --- a/packages/middleware-lint/src/core.ts +++ b/packages/middleware-lint/src/core.ts @@ -231,7 +231,7 @@ export const prepareDeps = async (ctx: Context, projectInfo: IProjectInfo) => { const needInstallDeps = deps .filter(dep => { - const projectDepVersion = projectDeps[dep.name] || projectDevDeps[dep.name]; + const projectDepVersion = projectDeps?.[dep.name] || projectDevDeps?.[dep.name]; if (!projectDepVersion) { ctx.console.warn(`${dep.name} not installed in project.`); return true; diff --git a/packages/middleware-lint/src/index.ts b/packages/middleware-lint/src/index.ts index b572fc45..cbd6282a 100644 --- a/packages/middleware-lint/src/index.ts +++ b/packages/middleware-lint/src/index.ts @@ -24,6 +24,15 @@ const handler: Handler = opts => { const projectInfo = await getProjectInfo(ctx.cwd); debug("projectInfo", projectInfo); + // Async Remove unused .eslintrc files + // Async Remove unused .prettierrc files + await rmRcFiles({ console: ctx.console, cwd: ctx.cwd }); + + // Async overwrite .prettierrc.js file + await readAndForceWriteRc({ console: ctx.console, cwd: ctx.cwd, projectInfo }); + + await prepareDeps(ctx, projectInfo); + if (options.lintStaged) { // Support LintStaged // Before all logic, simple and fast @@ -42,15 +51,6 @@ const handler: Handler = opts => { return next(); } - // Async Remove unused .eslintrc files - // Async Remove unused .prettierrc files - await rmRcFiles({ console: ctx.console, cwd: ctx.cwd }); - - // Async overwrite .prettierrc.js file - await readAndForceWriteRc({ console: ctx.console, cwd: ctx.cwd, projectInfo }); - - await prepareDeps(ctx, projectInfo); - if (!options.realtime && !options.noEmit) { await execLint({ autoFix: options.autoFix, cache: options.cache, prettier: options.prettier, projectInfo }, ctx); }