diff --git a/.eslintrc.cjs b/.eslintrc.cjs index bb48bf9c307fd6..67dcb7209c6e2a 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -89,6 +89,7 @@ module.exports = defineConfig({ { prefer: 'type-imports' } ], + 'import/no-duplicates': 'error', 'import/order': 'error', 'sort-imports': [ 'error', diff --git a/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts b/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts index 01e4cc4c37d478..cd6608221512c9 100644 --- a/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts +++ b/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts @@ -1,5 +1,4 @@ import type * as babelCore from '@babel/core' -import type { Visitor, types as t } from '@babel/core' /** * Replace this: @@ -11,13 +10,13 @@ import type { Visitor, types as t } from '@babel/core' * var _jsx = require("react/jsx-runtime").jsx */ export function babelImportToRequire({ types: t }: typeof babelCore): { - visitor: Visitor + visitor: babelCore.Visitor } { return { visitor: { ImportDeclaration(path) { const decl = path.node - const spec = decl.specifiers[0] as t.ImportSpecifier + const spec = decl.specifiers[0] as babelCore.types.ImportSpecifier path.replaceWith( t.variableDeclaration('var', [ diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts index 2c49f508c8b5be..28825918895dde 100644 --- a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts @@ -1,9 +1,11 @@ import type * as babelCore from '@babel/core' -import type { PluginItem, types as t } from '@babel/core' -type RestoredJSX = [result: t.File | null | undefined, isCommonJS: boolean] +type RestoredJSX = [ + result: babelCore.types.File | null | undefined, + isCommonJS: boolean +] -let babelRestoreJSX: Promise | undefined +let babelRestoreJSX: Promise | undefined const jsxNotFound: RestoredJSX = [null, false] diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 6526f941319849..805df6fec674d0 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -1,6 +1,7 @@ import fs from 'fs' import type { Plugin, ViteDevServer } from 'vite' import { createFilter } from '@rollup/pluginutils' +/* eslint-disable import/no-duplicates */ import type { SFCBlock, SFCScriptCompileOptions, @@ -8,6 +9,7 @@ import type { SFCTemplateCompileOptions } from 'vue/compiler-sfc' import type * as _compiler from 'vue/compiler-sfc' +/* eslint-enable import/no-duplicates */ import { resolveCompiler } from './compiler' import { parseVueRequest } from './utils/query' import { getDescriptor, getSrcDescriptor } from './utils/descriptorCache' diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index ef5255ba8ee098..650a6630fc6b8f 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -6,9 +6,8 @@ import type { OutputOptions, PluginContext } from 'rollup' import MagicString from 'magic-string' import type { Plugin } from '../plugin' import type { ResolvedConfig } from '../config' -import { cleanUrl } from '../utils' +import { cleanUrl, getHash, normalizePath } from '../utils' import { FS_PREFIX } from '../constants' -import { getHash, normalizePath } from '../utils' export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 88d200832b447d..d5a48658493ce7 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -32,6 +32,7 @@ import { asyncReplace, cleanUrl, combineSourcemaps, + emptyCssComments, generateCodeFrame, getHash, isDataUrl, @@ -41,7 +42,6 @@ import { parseRequest, processSrcSet } from '../utils' -import { emptyCssComments } from '../utils' import type { Logger } from '../logger' import { addToHTMLProxyTransformResult } from './html' import { diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 7b02af2152cb70..22fabf27099c00 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -12,15 +12,15 @@ import type { SourceMap } from 'rollup' import { createFilter } from '@rollup/pluginutils' import type { TSConfckParseOptions, TSConfckParseResult } from 'tsconfck' import { TSConfckParseError, findAll, parse } from 'tsconfck' -import { combineSourcemaps } from '../utils' -import type { ResolvedConfig, ViteDevServer } from '..' import { cleanUrl, + combineSourcemaps, createDebugger, ensureWatchedFile, generateCodeFrame, toUpperCaseDriveLetter } from '../utils' +import type { ResolvedConfig, ViteDevServer } from '..' import type { Plugin } from '../plugin' import { searchForWorkspaceRoot } from '..' diff --git a/packages/vite/src/node/plugins/workerImportMetaUrl.ts b/packages/vite/src/node/plugins/workerImportMetaUrl.ts index 48d38dd0a1359e..9769ed0d010645 100644 --- a/packages/vite/src/node/plugins/workerImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/workerImportMetaUrl.ts @@ -5,8 +5,7 @@ import type { RollupError } from 'rollup' import { stripLiteral } from 'strip-literal' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' -import { cleanUrl, injectQuery } from '../utils' -import { parseRequest } from '../utils' +import { cleanUrl, injectQuery, parseRequest } from '../utils' import { ENV_ENTRY, ENV_PUBLIC_PATH } from '../constants' import type { ViteDevServer } from '..' import { workerFileToUrl } from './worker' diff --git a/packages/vite/src/node/preview.ts b/packages/vite/src/node/preview.ts index bb3aded53f686a..e66733d5c971b6 100644 --- a/packages/vite/src/node/preview.ts +++ b/packages/vite/src/node/preview.ts @@ -1,5 +1,4 @@ import path from 'path' -import type { Server } from 'http' import type * as http from 'http' import sirv from 'sirv' import connect from 'connect' @@ -47,7 +46,7 @@ export interface PreviewServer { /** * native Node http server instance */ - httpServer: Server + httpServer: http.Server /** * Print server urls */ diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index b7e05c2951ba00..4dafb7fc99b335 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -2,7 +2,6 @@ import fs from 'fs' import path from 'path' import type * as net from 'net' import type * as http from 'http' -import type { AddressInfo } from 'net' import { performance } from 'perf_hooks' import connect from 'connect' import corsMiddleware from 'cors' @@ -16,7 +15,7 @@ import type { CommonServerOptions } from '../http' import { httpServerStart, resolveHttpServer, resolveHttpsConfig } from '../http' import type { InlineConfig, ResolvedConfig } from '../config' import { mergeConfig, resolveConfig } from '../config' -import { isParentDirectory, normalizePath } from '../utils' +import { isParentDirectory, normalizePath, resolveHostname } from '../utils' import { ssrLoadModule } from '../ssr/ssrModuleLoader' import { resolveSSRExternal } from '../ssr/ssrExternal' import { @@ -26,7 +25,6 @@ import { import { ssrTransform } from '../ssr/ssrTransform' import { createOptimizedDeps } from '../optimizer/registerMissing' import type { OptimizedDeps } from '../optimizer' -import { resolveHostname } from '../utils' import { CLIENT_DIR } from '../constants' import type { Logger } from '../logger' import { printCommonServerUrls } from '../logger' @@ -452,7 +450,7 @@ export async function createServer( if (!middlewareMode && httpServer) { httpServer.once('listening', () => { // update actual port since this may be different from initial value - serverConfig.port = (httpServer.address() as AddressInfo).port + serverConfig.port = (httpServer.address() as net.AddressInfo).port }) } diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 4016f6a0b71741..ce021112779d4b 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -56,8 +56,9 @@ import type { FSWatcher } from 'chokidar' import colors from 'picocolors' import type * as postcss from 'postcss' import type { Plugin } from '../plugin' -import { cleanUrl, combineSourcemaps } from '../utils' import { + cleanUrl, + combineSourcemaps, createDebugger, ensureWatchedFile, generateCodeFrame, diff --git a/packages/vite/src/node/server/searchRoot.ts b/packages/vite/src/node/server/searchRoot.ts index 472f2ae6f005f0..1fa63eff4e024d 100644 --- a/packages/vite/src/node/server/searchRoot.ts +++ b/packages/vite/src/node/server/searchRoot.ts @@ -1,6 +1,5 @@ import fs from 'fs' -import { dirname } from 'path' -import { join } from 'path' +import { dirname, join } from 'path' import { isFileReadable } from '../utils' // https://github.com/vitejs/vite/issues/2820#issuecomment-812495079 diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 3748aa3b465b2c..1620105880743c 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -3,10 +3,9 @@ import os from 'os' import path from 'path' import { createHash } from 'crypto' import { promisify } from 'util' -import { URL, pathToFileURL } from 'url' +import { URL, URLSearchParams, pathToFileURL } from 'url' import { builtinModules } from 'module' import { performance } from 'perf_hooks' -import { URLSearchParams } from 'url' import resolve from 'resolve' import type { FSWatcher } from 'chokidar' import remapping from '@ampproject/remapping'