Skip to content

Commit

Permalink
chore: prefer type imports (#5835)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Dec 19, 2021
1 parent 10e8f85 commit 7186857
Show file tree
Hide file tree
Showing 95 changed files with 337 additions and 337 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.cjs
Expand Up @@ -89,7 +89,11 @@ module.exports = defineConfig({
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off', // maybe we should turn this on in a new PR
'@typescript-eslint/no-unused-vars': 'off', // maybe we should turn this on in a new PR
'@typescript-eslint/no-var-requires': 'off'
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports' }
]
},
overrides: [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/create-vite/__tests__/cli.spec.ts
@@ -1,5 +1,6 @@
/* eslint-disable node/no-extraneous-import */
import { commandSync, ExecaSyncReturnValue, SyncOptions } from 'execa'
import type { ExecaSyncReturnValue, SyncOptions } from 'execa'
import { commandSync } from 'execa'
import { mkdirpSync, readdirSync, remove, writeFileSync } from 'fs-extra'
import { join } from 'path'

Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-vue-ts/src/env.d.ts
@@ -1,7 +1,7 @@
/// <reference types="vite/client" />

declare module '*.vue' {
import { DefineComponent } from 'vue'
import type { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/react-emotion/vite.config.ts
@@ -1,6 +1,7 @@
import react from '@vitejs/plugin-react'
import type { UserConfig } from 'vite'

const config: import('vite').UserConfig = {
const config: UserConfig = {
plugins: [
react({
jsxImportSource: '@emotion/react',
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/react/vite.config.ts
@@ -1,6 +1,7 @@
import react from '@vitejs/plugin-react'
import type { UserConfig } from 'vite'

const config: import('vite').UserConfig = {
const config: UserConfig = {
plugins: [react()],
build: {
// to make tests faster
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/shims.d.ts
Expand Up @@ -4,7 +4,7 @@ declare module 'css-color-names' {
}

declare module '*.vue' {
import { ComponentOptions } from 'vue'
import type { ComponentOptions } from 'vue'
const component: ComponentOptions
export default component
}
2 changes: 1 addition & 1 deletion packages/playground/testUtils.ts
Expand Up @@ -5,7 +5,7 @@
import fs from 'fs'
import path from 'path'
import colors from 'css-color-names'
import { ElementHandle } from 'playwright-chromium'
import type { ElementHandle } from 'playwright-chromium'
import type { Manifest } from 'vite'

export function slash(p: string): string {
Expand Down
@@ -1,4 +1,5 @@
// @ts-nocheck
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { NestedWithExtendsTypeOnlyClass } from './not-used-type'

class NestedWithExtendsBase {
Expand Down
1 change: 1 addition & 0 deletions packages/playground/tsconfig-json/nested/main.ts
@@ -1,4 +1,5 @@
// @ts-nocheck
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { NestedTypeOnlyClass } from './not-used-type'

class NestedBase {
Expand Down
1 change: 1 addition & 0 deletions packages/playground/tsconfig-json/src/main.ts
Expand Up @@ -2,6 +2,7 @@
import '../nested/main'
import '../nested-with-extends/main'

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { MainTypeOnlyClass } from './not-used-type'

class MainBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/vue/CustomBlockPlugin.ts
@@ -1,4 +1,4 @@
import { Plugin } from 'vite'
import type { Plugin } from 'vite'

export const vueI18nPlugin: Plugin = {
name: 'vue-i18n',
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/worker/__tests__/worker.spec.ts
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'
import { untilUpdated, isBuild, testDir } from '../../testUtils'
import { Page } from 'playwright-chromium'
import type { Page } from 'playwright-chromium'

test('normal', async () => {
await page.click('.ping')
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-legacy/index.d.ts
@@ -1,4 +1,4 @@
import { Plugin } from 'vite'
import type { Plugin } from 'vite'

export interface Options {
/**
Expand Down
@@ -1,3 +1,4 @@
import type * as babelCore from '@babel/core'
import type { types as t, Visitor } from '@babel/core'

/**
Expand All @@ -9,9 +10,7 @@ import type { types as t, Visitor } from '@babel/core'
*
* var _jsx = require("react/jsx-runtime").jsx
*/
export function babelImportToRequire({
types: t
}: typeof import('@babel/core')): {
export function babelImportToRequire({ types: t }: typeof babelCore): {
visitor: Visitor
} {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react/src/jsx-runtime/babel-restore-jsx.ts
Expand Up @@ -2,7 +2,7 @@
* https://github.com/flying-sheep/babel-plugin-transform-react-createelement-to-jsx
* @license GNU General Public License v3.0
*/
import * as babel from '@babel/core'
import type * as babel from '@babel/core'

/**
* Visitor factory for babel, converting React.createElement(...) to <jsx ...>...</jsx>
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-react/src/jsx-runtime/restore-jsx.ts
@@ -1,3 +1,4 @@
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]
Expand All @@ -8,7 +9,7 @@ const jsxNotFound: RestoredJSX = [null, false]

/** Restore JSX from `React.createElement` calls */
export async function restoreJSX(
babel: typeof import('@babel/core'),
babel: typeof babelCore,
code: string,
filename: string
): Promise<RestoredJSX> {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue-jsx/index.d.ts
@@ -1,6 +1,6 @@
import { Plugin } from 'vite'
import { VueJSXPluginOptions } from '@vue/babel-plugin-jsx'
import { FilterPattern } from '@rollup/pluginutils'
import type { Plugin } from 'vite'
import type { VueJSXPluginOptions } from '@vue/babel-plugin-jsx'
import type { FilterPattern } from '@rollup/pluginutils'

declare interface FilterOptions {
include?: FilterPattern
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/compiler.ts
Expand Up @@ -5,7 +5,7 @@ declare module 'vue/compiler-sfc' {
}
}

import * as _compiler from 'vue/compiler-sfc'
import type * as _compiler from 'vue/compiler-sfc'

export function resolveCompiler(root: string): typeof _compiler {
// resolve from project root first, then fallback to peer dep (if any)
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue/src/handleHotUpdate.ts
@@ -1,13 +1,13 @@
import _debug from 'debug'
import { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import {
createDescriptor,
getDescriptor,
setPrevDescriptor
} from './utils/descriptorCache'
import { getResolvedScript, setResolvedScript } from './script'
import { ModuleNode, HmrContext } from 'vite'
import { ResolvedOptions } from '.'
import type { ModuleNode, HmrContext } from 'vite'
import type { ResolvedOptions } from '.'

const debug = _debug('vite:hmr')

Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue/src/index.ts
@@ -1,13 +1,13 @@
import fs from 'fs'
import { Plugin, ViteDevServer } from 'vite'
import type { Plugin, ViteDevServer } from 'vite'
import { createFilter } from '@rollup/pluginutils'
import {
import type {
SFCBlock,
SFCScriptCompileOptions,
SFCStyleCompileOptions,
SFCTemplateCompileOptions
} from 'vue/compiler-sfc'
import * as _compiler from 'vue/compiler-sfc'
import type * as _compiler from 'vue/compiler-sfc'
import { resolveCompiler } from './compiler'
import { parseVueRequest } from './utils/query'
import { getDescriptor, getSrcDescriptor } from './utils/descriptorCache'
Expand Down
9 changes: 5 additions & 4 deletions packages/plugin-vue/src/main.ts
@@ -1,18 +1,19 @@
import qs from 'querystring'
import path from 'path'
import { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import { ResolvedOptions } from '.'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { ResolvedOptions } from '.'
import {
createDescriptor,
getPrevDescriptor,
setSrcDescriptor
} from './utils/descriptorCache'
import { PluginContext, SourceMap, TransformPluginContext } from 'rollup'
import type { PluginContext, SourceMap, TransformPluginContext } from 'rollup'
import { normalizePath } from '@rollup/pluginutils'
import { resolveScript, isUseInlineTemplate } from './script'
import { transformTemplateInMain } from './template'
import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate'
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map'
import type { RawSourceMap } from 'source-map'
import { SourceMapConsumer, SourceMapGenerator } from 'source-map'
import { createRollupError } from './utils/error'
import { transformWithEsbuild } from 'vite'
import { EXPORT_HELPER_ID } from './helper'
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue/src/script.ts
@@ -1,5 +1,5 @@
import { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc'
import { ResolvedOptions } from '.'
import type { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc'
import type { ResolvedOptions } from '.'
import { resolveTemplateCompilerOptions } from './template'

// ssr and non ssr builds would output different script content
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue/src/style.ts
@@ -1,6 +1,6 @@
import { SFCDescriptor } from 'vue/compiler-sfc'
import { TransformPluginContext } from 'rollup'
import { ResolvedOptions } from '.'
import type { SFCDescriptor } from 'vue/compiler-sfc'
import type { TransformPluginContext } from 'rollup'
import type { ResolvedOptions } from '.'

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function transformStyle(
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue/src/template.ts
@@ -1,13 +1,13 @@
import path from 'path'
import slash from 'slash'
import {
import type {
SFCDescriptor,
SFCTemplateCompileOptions,
SFCTemplateCompileResults,
CompilerOptions
} from 'vue/compiler-sfc'
import { PluginContext, TransformPluginContext } from 'rollup'
import { ResolvedOptions } from '.'
import type { PluginContext, TransformPluginContext } from 'rollup'
import type { ResolvedOptions } from '.'
import { getResolvedScript } from './script'
import { createRollupError } from './utils/error'

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue/src/utils/descriptorCache.ts
Expand Up @@ -2,8 +2,8 @@ import fs from 'fs'
import path from 'path'
import slash from 'slash'
import hash from 'hash-sum'
import { CompilerError, SFCDescriptor } from 'vue/compiler-sfc'
import { ResolvedOptions, VueQuery } from '..'
import type { CompilerError, SFCDescriptor } from 'vue/compiler-sfc'
import type { ResolvedOptions, VueQuery } from '..'

// compiler-sfc should be exported so it can be re-used
export interface SFCParseResult {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue/src/utils/error.ts
@@ -1,5 +1,5 @@
import { CompilerError } from 'vue/compiler-sfc'
import { RollupError } from 'rollup'
import type { CompilerError } from 'vue/compiler-sfc'
import type { RollupError } from 'rollup'

export function createRollupError(
id: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/client/client.ts
@@ -1,12 +1,12 @@
import {
import type {
ErrorPayload,
FullReloadPayload,
HMRPayload,
PrunePayload,
Update,
UpdatePayload
} from 'types/hmrPayload'
import { CustomEventName } from 'types/customEvent'
import type { CustomEventName } from 'types/customEvent'
import { ErrorOverlay, overlayId } from './overlay'
// eslint-disable-next-line node/no-missing-import
import '@vite/env'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/client/overlay.ts
@@ -1,4 +1,4 @@
import { ErrorPayload } from 'types/hmrPayload'
import type { ErrorPayload } from 'types/hmrPayload'

const template = /*html*/ `
<style>
Expand Down
11 changes: 3 additions & 8 deletions packages/vite/src/node/__tests__/config.spec.ts
@@ -1,11 +1,6 @@
import { InlineConfig } from '..'
import {
mergeConfig,
resolveConfig,
UserConfigExport,
resolveEnvPrefix,
UserConfig
} from '../config'
import type { InlineConfig } from '..'
import type { UserConfigExport, UserConfig } from '../config'
import { mergeConfig, resolveConfig, resolveEnvPrefix } from '../config'

describe('mergeConfig', () => {
test('handles configs with different alias schemas', () => {
Expand Down
18 changes: 10 additions & 8 deletions packages/vite/src/node/build.ts
@@ -1,8 +1,9 @@
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'
import { resolveConfig, InlineConfig, ResolvedConfig } from './config'
import Rollup, {
import type { InlineConfig, ResolvedConfig } from './config'
import { resolveConfig } from './config'
import type {
Plugin,
RollupBuild,
RollupOptions,
Expand All @@ -18,25 +19,26 @@ import Rollup, {
RollupError,
ModuleFormat
} from 'rollup'
import type Rollup from 'rollup'
import { buildReporterPlugin } from './plugins/reporter'
import { buildHtmlPlugin } from './plugins/html'
import { buildEsbuildPlugin } from './plugins/esbuild'
import { terserPlugin } from './plugins/terser'
import { Terser } from 'types/terser'
import type { Terser } from 'types/terser'
import { copyDir, emptyDir, lookupFile, normalizePath } from './utils'
import { manifestPlugin } from './plugins/manifest'
import commonjsPlugin from '@rollup/plugin-commonjs'
import { RollupCommonJSOptions } from 'types/commonjs'
import type { RollupCommonJSOptions } from 'types/commonjs'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
import { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
import { Logger } from './logger'
import { TransformOptions } from 'esbuild'
import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
import type { Logger } from './logger'
import type { TransformOptions } from 'esbuild'
import { dataURIPlugin } from './plugins/dataUri'
import { buildImportAnalysisPlugin } from './plugins/importAnalysisBuild'
import { resolveSSRExternal, shouldExternalizeForSSR } from './ssr/ssrExternal'
import { ssrManifestPlugin } from './ssr/ssrManifestPlugin'
import { isCSSRequest } from './plugins/css'
import { DepOptimizationMetadata } from './optimizer'
import type { DepOptimizationMetadata } from './optimizer'
import { scanImports } from './optimizer/scan'
import { assetImportMetaUrlPlugin } from './plugins/assetImportMetaUrl'
import { loadFallbackPlugin } from './plugins/loadFallback'
Expand Down
7 changes: 4 additions & 3 deletions packages/vite/src/node/cli.ts
@@ -1,9 +1,10 @@
import { cac } from 'cac'
import chalk from 'chalk'
import { performance } from 'perf_hooks'
import { BuildOptions } from './build'
import { ServerOptions } from './server'
import { createLogger, LogLevel } from './logger'
import type { BuildOptions } from './build'
import type { ServerOptions } from './server'
import type { LogLevel } from './logger'
import { createLogger } from './logger'
import { resolveConfig } from '.'
import { preview } from './preview'

Expand Down

0 comments on commit 7186857

Please sign in to comment.