diff --git a/.eslintrc.js b/.eslintrc.js index 4b0f7a6dd..064100523 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,7 +9,8 @@ module.exports = { 'sort-keys': 'off', 'typescript-sort-keys/interface': 'off', 'import/extensions': 'off', - 'import/no-unresolved': 'off' + 'import/no-unresolved': 'off', + '@typescript-eslint/consistent-type-imports': 'error' }, overrides: [ { diff --git a/packages/alias/src/index.ts b/packages/alias/src/index.ts index 10abdcfde..9d6788f3a 100755 --- a/packages/alias/src/index.ts +++ b/packages/alias/src/index.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; import type { ResolvedAlias, ResolverFunction, ResolverObject, RollupAliasOptions } from '../types'; diff --git a/packages/alias/types/index.d.ts b/packages/alias/types/index.d.ts index 67dd2afd5..52cc2a471 100644 --- a/packages/alias/types/index.d.ts +++ b/packages/alias/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin, PluginHooks } from 'rollup'; +import type { Plugin, PluginHooks } from 'rollup'; type MapToFunction = T extends Function ? T : never; diff --git a/packages/auto-install/src/index.ts b/packages/auto-install/src/index.ts index 21852574f..13dbd7b07 100644 --- a/packages/auto-install/src/index.ts +++ b/packages/auto-install/src/index.ts @@ -4,7 +4,7 @@ import mod from 'module'; import { exec } from 'child_process'; import { promisify } from 'util'; -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; import type { RollupAutoInstallOptions } from '../types'; diff --git a/packages/auto-install/types/index.d.ts b/packages/auto-install/types/index.d.ts index 5fc712a18..d9e564445 100644 --- a/packages/auto-install/types/index.d.ts +++ b/packages/auto-install/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; export interface RollupAutoInstallOptions { /** diff --git a/packages/babel/test/types.ts b/packages/babel/test/types.ts index 4c9027d69..0f5515345 100644 --- a/packages/babel/test/types.ts +++ b/packages/babel/test/types.ts @@ -1,4 +1,5 @@ /** eslint-disable @typescript-eslint/no-unused-vars */ +import type { RollupOptions } from 'rollup'; import babelPlugin, { babel, @@ -8,7 +9,7 @@ import babelPlugin, { createBabelOutputPluginFactory } from '../types'; -const rollupConfig: import('rollup').RollupOptions = { +const rollupConfig: RollupOptions = { input: 'main.js', output: { file: 'bundle.js', diff --git a/packages/babel/types/index.d.ts b/packages/babel/types/index.d.ts index 475337fee..1a82da7ba 100644 --- a/packages/babel/types/index.d.ts +++ b/packages/babel/types/index.d.ts @@ -1,6 +1,6 @@ -import { Plugin, PluginContext, TransformPluginContext } from 'rollup'; -import { FilterPattern, CreateFilter } from '@rollup/pluginutils'; -import * as babelCore from '@babel/core'; +import type { Plugin, PluginContext, TransformPluginContext } from 'rollup'; +import type { FilterPattern, CreateFilter } from '@rollup/pluginutils'; +import type * as babelCore from '@babel/core'; export interface RollupBabelInputPluginOptions extends Omit { diff --git a/packages/beep/types/index.d.ts b/packages/beep/types/index.d.ts index 6df01ce2f..9b6abcc0d 100644 --- a/packages/beep/types/index.d.ts +++ b/packages/beep/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; /** * 🍣 A Rollup plugin that beeps when a build ends with errors. diff --git a/packages/buble/src/index.ts b/packages/buble/src/index.ts index 3d8a1d39e..7e69f8eb2 100644 --- a/packages/buble/src/index.ts +++ b/packages/buble/src/index.ts @@ -1,5 +1,5 @@ import { transform } from 'buble'; -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; import { createFilter } from '@rollup/pluginutils'; import type { RollupBubleOptions } from '../types'; diff --git a/packages/buble/test/types.ts b/packages/buble/test/types.ts index 189187867..0dc0ce037 100755 --- a/packages/buble/test/types.ts +++ b/packages/buble/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import buble from '..'; diff --git a/packages/buble/types/index.d.ts b/packages/buble/types/index.d.ts index 81e956f40..8368f6f20 100755 --- a/packages/buble/types/index.d.ts +++ b/packages/buble/types/index.d.ts @@ -1,6 +1,6 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { TransformOptions } from 'buble'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { TransformOptions } from 'buble'; +import type { Plugin } from 'rollup'; export interface RollupBubleOptions extends TransformOptions { /** diff --git a/packages/commonjs/types/index.d.ts b/packages/commonjs/types/index.d.ts index 7edcb7dec..0b79f9ebf 100644 --- a/packages/commonjs/types/index.d.ts +++ b/packages/commonjs/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; type RequireReturnsDefaultOption = boolean | 'auto' | 'preferred' | 'namespace'; type DefaultIsModuleExportsOption = boolean | 'auto'; diff --git a/packages/data-uri/src/index.ts b/packages/data-uri/src/index.ts index cd2e5fa08..d12b197ff 100644 --- a/packages/data-uri/src/index.ts +++ b/packages/data-uri/src/index.ts @@ -1,6 +1,6 @@ import { URL } from 'url'; -import { Plugin, RollupError } from 'rollup'; +import type { Plugin, RollupError } from 'rollup'; import { dataToEsm } from '@rollup/pluginutils'; diff --git a/packages/data-uri/types/index.d.ts b/packages/data-uri/types/index.d.ts index 8dc7336cc..c00a67485 100644 --- a/packages/data-uri/types/index.d.ts +++ b/packages/data-uri/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; /** * A Rollup plugin which imports modules from Data URIs. diff --git a/packages/dsv/test/types.ts b/packages/dsv/test/types.ts index 1fd15a29a..f48fb7319 100644 --- a/packages/dsv/test/types.ts +++ b/packages/dsv/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import dsv from '..'; diff --git a/packages/dsv/types/index.d.ts b/packages/dsv/types/index.d.ts index 463ad1ea6..f923829cd 100644 --- a/packages/dsv/types/index.d.ts +++ b/packages/dsv/types/index.d.ts @@ -1,6 +1,6 @@ -import { DSVRowString } from 'd3-dsv'; -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { DSVRowString } from 'd3-dsv'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; interface RollupDsvOptions { /** diff --git a/packages/dynamic-import-vars/test/types.ts b/packages/dynamic-import-vars/test/types.ts index 2872477d2..df1915914 100644 --- a/packages/dynamic-import-vars/test/types.ts +++ b/packages/dynamic-import-vars/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import dynamicImportVars, { dynamicImportToGlob } from '../src'; diff --git a/packages/dynamic-import-vars/types/index.d.ts b/packages/dynamic-import-vars/types/index.d.ts index 30f92892a..ca4af9c4c 100644 --- a/packages/dynamic-import-vars/types/index.d.ts +++ b/packages/dynamic-import-vars/types/index.d.ts @@ -1,5 +1,6 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; +import type { BaseNode } from 'estree'; interface RollupDynamicImportVariablesOptions { /** @@ -24,10 +25,7 @@ interface RollupDynamicImportVariablesOptions { export class VariableDynamicImportError extends Error {} -export function dynamicImportToGlob( - node: import('estree').BaseNode, - sourceString: string -): null | string; +export function dynamicImportToGlob(node: BaseNode, sourceString: string): null | string; /** * Support variables in dynamic imports in Rollup. diff --git a/packages/eslint/src/index.ts b/packages/eslint/src/index.ts index a69d23e8f..64abb2594 100755 --- a/packages/eslint/src/index.ts +++ b/packages/eslint/src/index.ts @@ -1,6 +1,6 @@ import { relative, resolve, sep } from 'path'; -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; import { createFilter } from '@rollup/pluginutils'; import { ESLint } from 'eslint'; diff --git a/packages/eslint/types/index.d.ts b/packages/eslint/types/index.d.ts index c0615cdea..25890e971 100755 --- a/packages/eslint/types/index.d.ts +++ b/packages/eslint/types/index.d.ts @@ -1,6 +1,6 @@ -import { Plugin } from 'rollup'; -import { CLIEngine, ESLint } from 'eslint'; -import { CreateFilter } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; +import type { CLIEngine, ESLint } from 'eslint'; +import type { CreateFilter } from '@rollup/pluginutils'; export interface RollupEslintOptions extends ESLint.Options { /** diff --git a/packages/graphql/test/types.ts b/packages/graphql/test/types.ts index 4cc4a6d5d..a17730036 100755 --- a/packages/graphql/test/types.ts +++ b/packages/graphql/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import graphql from '..'; diff --git a/packages/graphql/types/index.d.ts b/packages/graphql/types/index.d.ts index 369e620d7..1c01e665c 100755 --- a/packages/graphql/types/index.d.ts +++ b/packages/graphql/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; export interface RollupGraphqlOptions { /** diff --git a/packages/html/src/index.ts b/packages/html/src/index.ts index a3fa6bc28..c22650057 100644 --- a/packages/html/src/index.ts +++ b/packages/html/src/index.ts @@ -1,6 +1,6 @@ import { extname } from 'path'; -import { Plugin, NormalizedOutputOptions, OutputBundle, EmittedAsset } from 'rollup'; +import type { Plugin, NormalizedOutputOptions, OutputBundle, EmittedAsset } from 'rollup'; import type { RollupHtmlOptions, RollupHtmlTemplateOptions } from '../types'; diff --git a/packages/html/types/index.d.ts b/packages/html/types/index.d.ts index 4943eb3ca..f8d62ef33 100644 --- a/packages/html/types/index.d.ts +++ b/packages/html/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup'; +import type { Plugin, OutputChunk, OutputAsset, OutputBundle } from 'rollup'; export interface RollupHtmlTemplateOptions { title: string; diff --git a/packages/image/test/types.ts b/packages/image/test/types.ts index 8a3848f5e..6069d172a 100644 --- a/packages/image/test/types.ts +++ b/packages/image/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import image from '..'; diff --git a/packages/image/types/index.d.ts b/packages/image/types/index.d.ts index c711570a0..fd5a9163c 100644 --- a/packages/image/types/index.d.ts +++ b/packages/image/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; interface RollupImageOptions { /** diff --git a/packages/inject/test/types.ts b/packages/inject/test/types.ts index 00eec291f..2de3bc2ea 100644 --- a/packages/inject/test/types.ts +++ b/packages/inject/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import inject from '..'; diff --git a/packages/inject/types/index.d.ts b/packages/inject/types/index.d.ts index 7ec16c5c7..646522ec2 100644 --- a/packages/inject/types/index.d.ts +++ b/packages/inject/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; type Injectment = string | [string, string]; diff --git a/packages/json/test/types.ts b/packages/json/test/types.ts index 1f8cc3cec..0dadfb2c4 100755 --- a/packages/json/test/types.ts +++ b/packages/json/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import json from '..'; diff --git a/packages/json/types/index.d.ts b/packages/json/types/index.d.ts index e25b88fa6..6ef037a23 100755 --- a/packages/json/types/index.d.ts +++ b/packages/json/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; export interface RollupJsonOptions { /** diff --git a/packages/legacy/test/types.ts b/packages/legacy/test/types.ts index 85ccf32c0..b1f1461af 100644 --- a/packages/legacy/test/types.ts +++ b/packages/legacy/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import legacy from '..'; diff --git a/packages/legacy/types/index.d.ts b/packages/legacy/types/index.d.ts index da1bc70a6..f1b4ccdb3 100644 --- a/packages/legacy/types/index.d.ts +++ b/packages/legacy/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; interface RollupLegacyOptions { [key: string]: string | { [key: string]: string }; diff --git a/packages/multi-entry/test/types.ts b/packages/multi-entry/test/types.ts index 373d36b62..edaf69a66 100644 --- a/packages/multi-entry/test/types.ts +++ b/packages/multi-entry/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import multiEntry from '..'; diff --git a/packages/multi-entry/types/index.d.ts b/packages/multi-entry/types/index.d.ts index 0d6c085c3..608ca9dc6 100644 --- a/packages/multi-entry/types/index.d.ts +++ b/packages/multi-entry/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; interface RollupMultiEntryOptions { /** diff --git a/packages/node-resolve/types/index.d.ts b/packages/node-resolve/types/index.d.ts index 11d5bfc18..20b35169e 100755 --- a/packages/node-resolve/types/index.d.ts +++ b/packages/node-resolve/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; export const DEFAULTS: { customResolveOptions: {}; diff --git a/packages/pluginutils/src/attachScopes.ts b/packages/pluginutils/src/attachScopes.ts index 78b421c75..d5dace4ed 100755 --- a/packages/pluginutils/src/attachScopes.ts +++ b/packages/pluginutils/src/attachScopes.ts @@ -1,4 +1,4 @@ -import * as estree from 'estree'; +import type * as estree from 'estree'; import { walk } from 'estree-walker'; diff --git a/packages/pluginutils/src/extractAssignedNames.ts b/packages/pluginutils/src/extractAssignedNames.ts index 9729373d1..e7fd3df66 100755 --- a/packages/pluginutils/src/extractAssignedNames.ts +++ b/packages/pluginutils/src/extractAssignedNames.ts @@ -1,3 +1,11 @@ +import type { + ArrayPattern, + AssignmentPattern, + Identifier, + ObjectPattern, + RestElement +} from 'estree'; + import type { ExtractAssignedNames } from '../types'; interface Extractors { @@ -5,23 +13,23 @@ interface Extractors { } const extractors: Extractors = { - ArrayPattern(names: string[], param: import('estree').ArrayPattern) { + ArrayPattern(names: string[], param: ArrayPattern) { for (const element of param.elements) { if (element) extractors[element.type](names, element); } }, - AssignmentPattern(names: string[], param: import('estree').AssignmentPattern) { + AssignmentPattern(names: string[], param: AssignmentPattern) { extractors[param.left.type](names, param.left); }, - Identifier(names: string[], param: import('estree').Identifier) { + Identifier(names: string[], param: Identifier) { names.push(param.name); }, MemberExpression() {}, - ObjectPattern(names: string[], param: import('estree').ObjectPattern) { + ObjectPattern(names: string[], param: ObjectPattern) { for (const prop of param.properties) { // @ts-ignore Typescript reports that this is not a valid type if (prop.type === 'RestElement') { @@ -32,7 +40,7 @@ const extractors: Extractors = { } }, - RestElement(names: string[], param: import('estree').RestElement) { + RestElement(names: string[], param: RestElement) { extractors[param.argument.type](names, param.argument); } }; diff --git a/packages/pluginutils/test/attachScopes.ts b/packages/pluginutils/test/attachScopes.ts index eb4c6bdb1..1f82eb002 100755 --- a/packages/pluginutils/test/attachScopes.ts +++ b/packages/pluginutils/test/attachScopes.ts @@ -1,9 +1,10 @@ -import * as estree from 'estree'; +import type * as estree from 'estree'; import test from 'ava'; import { parse } from 'acorn'; -import { attachScopes, AttachedScope } from '../'; +import type { AttachedScope } from '../'; +import { attachScopes } from '../'; test('attaches a scope to the top level', (t) => { const ast = parse('var foo;', { ecmaVersion: 2020, sourceType: 'module' }); diff --git a/packages/pluginutils/types/index.d.ts b/packages/pluginutils/types/index.d.ts index 9d0be7507..fb96d6346 100755 --- a/packages/pluginutils/types/index.d.ts +++ b/packages/pluginutils/types/index.d.ts @@ -1,4 +1,4 @@ -import { BaseNode } from 'estree'; +import type { BaseNode } from 'estree'; export interface AttachedScope { parent?: AttachedScope; diff --git a/packages/replace/test/types.ts b/packages/replace/test/types.ts index 28197d689..4dda56bc6 100755 --- a/packages/replace/test/types.ts +++ b/packages/replace/test/types.ts @@ -1,7 +1,7 @@ // @ts-check import { dirname } from 'path'; -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import replace from '..'; diff --git a/packages/replace/types/index.d.ts b/packages/replace/types/index.d.ts index f0fa8d10d..1f0794719 100755 --- a/packages/replace/types/index.d.ts +++ b/packages/replace/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; type Replacement = string | ((id: string) => string); diff --git a/packages/run/src/index.ts b/packages/run/src/index.ts index c71a9545d..a4f5e575e 100644 --- a/packages/run/src/index.ts +++ b/packages/run/src/index.ts @@ -1,7 +1,8 @@ -import { ChildProcess, fork } from 'child_process'; +import type { ChildProcess } from 'child_process'; +import { fork } from 'child_process'; import { resolve, join, dirname } from 'path'; -import { Plugin, RenderedChunk } from 'rollup'; +import type { Plugin, RenderedChunk } from 'rollup'; import type { RollupRunOptions } from '../types'; diff --git a/packages/run/types/index.d.ts b/packages/run/types/index.d.ts index c91da9987..d546be160 100644 --- a/packages/run/types/index.d.ts +++ b/packages/run/types/index.d.ts @@ -1,6 +1,6 @@ -import { ForkOptions } from 'child_process'; +import type { ForkOptions } from 'child_process'; -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; export interface RollupRunOptions extends ForkOptions { args?: readonly string[]; diff --git a/packages/strip/test/types.ts b/packages/strip/test/types.ts index 3ff4dff1f..5e918277c 100644 --- a/packages/strip/test/types.ts +++ b/packages/strip/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import strip from '../types/index'; diff --git a/packages/strip/types/index.d.ts b/packages/strip/types/index.d.ts index 3c4b83fdc..7aa3ae554 100644 --- a/packages/strip/types/index.d.ts +++ b/packages/strip/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; interface RollupStripOptions { /** diff --git a/packages/sucrase/test/types.ts b/packages/sucrase/test/types.ts index 3b0f0d737..e4e7f2c66 100644 --- a/packages/sucrase/test/types.ts +++ b/packages/sucrase/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import sucrase from '..'; diff --git a/packages/sucrase/types/index.d.ts b/packages/sucrase/types/index.d.ts index 5160e4226..3b2147b1a 100644 --- a/packages/sucrase/types/index.d.ts +++ b/packages/sucrase/types/index.d.ts @@ -1,6 +1,6 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; -import { Options as SucraseOptions } from 'sucrase'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; +import type { Options as SucraseOptions } from 'sucrase'; interface RollupSucraseOptions extends Pick< diff --git a/packages/typescript/src/diagnostics/emit.ts b/packages/typescript/src/diagnostics/emit.ts index 7c2ed30a9..6eaefa6e6 100644 --- a/packages/typescript/src/diagnostics/emit.ts +++ b/packages/typescript/src/diagnostics/emit.ts @@ -1,7 +1,8 @@ -import { PluginContext } from 'rollup'; +import type { PluginContext } from 'rollup'; +import type typescript from 'typescript'; import type { Diagnostic, DiagnosticReporter } from 'typescript'; -import { DiagnosticsHost } from './host'; +import type { DiagnosticsHost } from './host'; import diagnosticToWarning from './toWarning'; // `Cannot compile modules into 'es6' when targeting 'ES5' or lower.` @@ -11,7 +12,7 @@ const CANNOT_COMPILE_ESM = 1204; * Emit a Rollup warning or error for a Typescript type error. */ export function emitDiagnostic( - ts: typeof import('typescript'), + ts: typeof typescript, context: PluginContext, host: DiagnosticsHost, diagnostic: Diagnostic @@ -32,7 +33,7 @@ export function emitDiagnostic( } export function buildDiagnosticReporter( - ts: typeof import('typescript'), + ts: typeof typescript, context: PluginContext, host: DiagnosticsHost ): DiagnosticReporter { @@ -45,7 +46,7 @@ export function buildDiagnosticReporter( * For each type error reported by Typescript, emit a Rollup warning or error. */ export function emitDiagnostics( - ts: typeof import('typescript'), + ts: typeof typescript, context: PluginContext, host: DiagnosticsHost, diagnostics: readonly Diagnostic[] | undefined diff --git a/packages/typescript/src/diagnostics/host.ts b/packages/typescript/src/diagnostics/host.ts index 72ae0af74..8e949aa47 100644 --- a/packages/typescript/src/diagnostics/host.ts +++ b/packages/typescript/src/diagnostics/host.ts @@ -1,3 +1,4 @@ +import type typescript from 'typescript'; import type { CompilerOptions, FormatDiagnosticsHost } from 'typescript'; export interface DiagnosticsHost extends FormatDiagnosticsHost { @@ -12,7 +13,7 @@ export interface DiagnosticsHost extends FormatDiagnosticsHost { * @see https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API */ export default function createFormattingHost( - ts: typeof import('typescript'), + ts: typeof typescript, compilerOptions: CompilerOptions ): DiagnosticsHost { return { diff --git a/packages/typescript/src/diagnostics/toWarning.ts b/packages/typescript/src/diagnostics/toWarning.ts index 713ab68a5..d588472ff 100644 --- a/packages/typescript/src/diagnostics/toWarning.ts +++ b/packages/typescript/src/diagnostics/toWarning.ts @@ -1,11 +1,12 @@ -import { RollupWarning } from 'rollup'; +import type typescript from 'typescript'; +import type { RollupWarning } from 'rollup'; import type { Diagnostic, FormatDiagnosticsHost } from 'typescript'; /** * Converts a Typescript type error into an equivalent Rollup warning object. */ export default function diagnosticToWarning( - ts: typeof import('typescript'), + ts: typeof typescript, host: FormatDiagnosticsHost | null, diagnostic: Diagnostic ) { diff --git a/packages/typescript/src/index.ts b/packages/typescript/src/index.ts index 97e51be50..3c964d004 100644 --- a/packages/typescript/src/index.ts +++ b/packages/typescript/src/index.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import { createFilter } from '@rollup/pluginutils'; -import { Plugin, RollupOptions, SourceDescription } from 'rollup'; +import type { Plugin, RollupOptions, SourceDescription } from 'rollup'; import type { Watch } from 'typescript'; import type { RollupTypescriptOptions } from '../types'; diff --git a/packages/typescript/src/moduleResolution.ts b/packages/typescript/src/moduleResolution.ts index 2b9afff4e..2351a1a02 100644 --- a/packages/typescript/src/moduleResolution.ts +++ b/packages/typescript/src/moduleResolution.ts @@ -1,3 +1,4 @@ +import type typescript from 'typescript'; import type { ModuleResolutionHost, ResolvedModuleFull, @@ -5,7 +6,7 @@ import type { ModuleKind } from 'typescript'; -import { DiagnosticsHost } from './diagnostics/host'; +import type { DiagnosticsHost } from './diagnostics/host'; type ModuleResolverHost = Partial & DiagnosticsHost; @@ -22,7 +23,7 @@ export type Resolver = ( * with methods for sanitizing filenames and getting compiler options. */ export default function createModuleResolver( - ts: typeof import('typescript'), + ts: typeof typescript, host: ModuleResolverHost ): Resolver { const compilerOptions = host.getCompilationSettings(); diff --git a/packages/typescript/src/options/normalize.ts b/packages/typescript/src/options/normalize.ts index 4e919b666..922fb3dee 100644 --- a/packages/typescript/src/options/normalize.ts +++ b/packages/typescript/src/options/normalize.ts @@ -1,7 +1,9 @@ /* eslint-disable no-param-reassign */ import { resolve } from 'path'; -import { CompilerOptions, PartialCompilerOptions } from './interfaces'; +import type typescript from 'typescript'; + +import type { CompilerOptions, PartialCompilerOptions } from './interfaces'; export const DIRECTORY_PROPS = ['outDir', 'declarationDir'] as const; @@ -25,10 +27,7 @@ export function makePathsAbsolute(compilerOptions: PartialCompilerOptions, relat * @param compilerOptions Compiler options to _mutate_. * @returns True if the source map compiler option was not initially set. */ -export function normalizeCompilerOptions( - ts: typeof import('typescript'), - compilerOptions: CompilerOptions -) { +export function normalizeCompilerOptions(ts: typeof typescript, compilerOptions: CompilerOptions) { let autoSetSourceMap = false; if (compilerOptions.inlineSourceMap) { // Force separate source map files for Rollup to work with. diff --git a/packages/typescript/src/options/tsconfig.ts b/packages/typescript/src/options/tsconfig.ts index 2391ea1b2..885bf824f 100644 --- a/packages/typescript/src/options/tsconfig.ts +++ b/packages/typescript/src/options/tsconfig.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; -import { PluginContext } from 'rollup'; +import type { PluginContext } from 'rollup'; import typescript from 'typescript'; import type { Diagnostic, @@ -17,13 +17,11 @@ import type { import type { RollupTypescriptOptions } from '../../types'; import diagnosticToWarning from '../diagnostics/toWarning'; +import type { CompilerOptions, EnumCompilerOptions, PartialCompilerOptions } from './interfaces'; import { - CompilerOptions, DEFAULT_COMPILER_OPTIONS, - EnumCompilerOptions, FORCED_COMPILER_OPTIONS, - OVERRIDABLE_EMIT_COMPILER_OPTIONS, - PartialCompilerOptions + OVERRIDABLE_EMIT_COMPILER_OPTIONS } from './interfaces'; import { normalizeCompilerOptions, makePathsAbsolute } from './normalize'; @@ -51,7 +49,7 @@ function makeForcedCompilerOptions(noForceEmit: boolean) { * If `false` is passed, then a null path is returned. * @returns The absolute path, or null if the file does not exist. */ -function getTsConfigPath(ts: typeof import('typescript'), relativePath?: string | false) { +function getTsConfigPath(ts: typeof typescript, relativePath?: string | false) { if (relativePath === false) return null; // Resolve path to file. `tsConfigOption` defaults to 'tsconfig.json'. @@ -75,7 +73,7 @@ function getTsConfigPath(ts: typeof import('typescript'), relativePath?: string * @param explicitPath If true, the path was set by the plugin user. * If false, the path was computed automatically. */ -function readTsConfigFile(ts: typeof import('typescript'), tsConfigPath: string) { +function readTsConfigFile(ts: typeof typescript, tsConfigPath: string) { const { config, error } = ts.readConfigFile(tsConfigPath, (path) => readFileSync(path, 'utf8')); if (error) { throw Object.assign(Error(), diagnosticToWarning(ts, null, error)); @@ -123,7 +121,7 @@ function setModuleResolutionKind(parsedConfig: ParsedCommandLine): ParsedCommand }; } -const configCache = new Map() as import('typescript').Map; +const configCache = new Map() as typescript.Map; /** * Parse the Typescript config to use with the plugin. @@ -137,7 +135,7 @@ const configCache = new Map() as import('typescript').Map { declarations: string[]; @@ -55,7 +57,7 @@ export function getEmittedFile( * containing files emitted by the Typescript compiler. */ export default function findTypescriptOutput( - ts: typeof import('typescript'), + ts: typeof typescript, parsedOptions: ParsedCommandLine, id: string, emittedFiles: ReadonlyMap, diff --git a/packages/typescript/src/preflight.ts b/packages/typescript/src/preflight.ts index 0a06f3e79..fce693e5e 100644 --- a/packages/typescript/src/preflight.ts +++ b/packages/typescript/src/preflight.ts @@ -1,7 +1,7 @@ -import { PluginContext, RollupOptions } from 'rollup'; +import type { PluginContext, RollupOptions } from 'rollup'; import typescript from 'typescript'; -import { TypeScriptConfig } from './options/tsconfig'; +import type { TypeScriptConfig } from './options/tsconfig'; // import { resolveIdAsync } from './tslib'; const { ModuleKind } = typescript; diff --git a/packages/typescript/src/tslib.ts b/packages/typescript/src/tslib.ts index 51c287567..1d35ce537 100644 --- a/packages/typescript/src/tslib.ts +++ b/packages/typescript/src/tslib.ts @@ -1,6 +1,7 @@ import { fileURLToPath } from 'url'; -import resolve, { SyncOpts } from 'resolve'; +import type { SyncOpts } from 'resolve'; +import resolve from 'resolve'; // const resolveIdAsync = (file: string, opts: AsyncOpts) => // new Promise((fulfil, reject) => diff --git a/packages/typescript/src/watchProgram.ts b/packages/typescript/src/watchProgram.ts index 544012d0f..07bf25d18 100644 --- a/packages/typescript/src/watchProgram.ts +++ b/packages/typescript/src/watchProgram.ts @@ -1,4 +1,4 @@ -import { PluginContext } from 'rollup'; +import type { PluginContext } from 'rollup'; import typescript from 'typescript'; import type { Diagnostic, @@ -12,8 +12,8 @@ import type { import type { CustomTransformerFactories } from '../types'; import { buildDiagnosticReporter } from './diagnostics/emit'; -import { DiagnosticsHost } from './diagnostics/host'; -import { Resolver } from './moduleResolution'; +import type { DiagnosticsHost } from './diagnostics/host'; +import type { Resolver } from './moduleResolution'; import { mergeTransformers } from './customTransformers'; const { DiagnosticCategory } = typescript; @@ -132,7 +132,7 @@ export class WatchProgramHelper { * @see https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API */ function createWatchHost( - ts: typeof import('typescript'), + ts: typeof typescript, context: PluginContext, { formatHost, @@ -195,7 +195,7 @@ function createWatchHost( } export default function createWatchProgram( - ts: typeof import('typescript'), + ts: typeof typescript, context: PluginContext, options: CreateProgramOptions ) { diff --git a/packages/typescript/test/fixtures/project-references/animals/dog.ts b/packages/typescript/test/fixtures/project-references/animals/dog.ts index ee004ea16..40d62e38c 100644 --- a/packages/typescript/test/fixtures/project-references/animals/dog.ts +++ b/packages/typescript/test/fixtures/project-references/animals/dog.ts @@ -1,4 +1,4 @@ -import Animal from '.'; +import type Animal from '.'; import { makeRandomName } from '../core/utilities'; diff --git a/packages/typescript/test/fixtures/project-references/zoo/zoo.ts b/packages/typescript/test/fixtures/project-references/zoo/zoo.ts index d9ed15d66..5e7ea75d3 100644 --- a/packages/typescript/test/fixtures/project-references/zoo/zoo.ts +++ b/packages/typescript/test/fixtures/project-references/zoo/zoo.ts @@ -1,5 +1,6 @@ // import Animal from '../animals/index'; -import { Dog, createDog } from '../animals/index'; +import type { Dog} from '../animals/index'; +import { createDog } from '../animals/index'; export default function createZoo(): Array { return [createDog()]; diff --git a/packages/typescript/test/tslib.ts b/packages/typescript/test/tslib.ts index aeb10ede1..cbb95820a 100644 --- a/packages/typescript/test/tslib.ts +++ b/packages/typescript/test/tslib.ts @@ -1,7 +1,8 @@ import { platform } from 'os'; import test from 'ava'; -import { rollup, RollupError } from 'rollup'; +import type { RollupError } from 'rollup'; +import { rollup } from 'rollup'; import typescript from '..'; diff --git a/packages/typescript/types/index.d.ts b/packages/typescript/types/index.d.ts index 58aea9573..6d4a30f00 100644 --- a/packages/typescript/types/index.d.ts +++ b/packages/typescript/types/index.d.ts @@ -1,7 +1,9 @@ /* eslint-disable no-use-before-define */ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; -import { +import type _typescript from 'typescript'; + +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; +import type { CompilerOptions, CompilerOptionsValue, CustomTransformers, @@ -65,7 +67,7 @@ export interface RollupTypescriptPluginOptions { /** * Overrides TypeScript used for transpilation */ - typescript?: typeof import('typescript'); + typescript?: typeof _typescript; /** * Overrides the injected TypeScript helpers with a custom version. */ diff --git a/packages/url/test/types.ts b/packages/url/test/types.ts index c6c2375bc..ae6c60b8d 100644 --- a/packages/url/test/types.ts +++ b/packages/url/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import url from '..'; diff --git a/packages/url/types/index.d.ts b/packages/url/types/index.d.ts index 510405065..d852ba6e9 100644 --- a/packages/url/types/index.d.ts +++ b/packages/url/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; interface RollupUrlOptions { // Note: the @default tag below uses the zero-width character joiner "‍" to escape the "*/" diff --git a/packages/virtual/src/index.ts b/packages/virtual/src/index.ts index f4b25c189..511b5bfad 100644 --- a/packages/virtual/src/index.ts +++ b/packages/virtual/src/index.ts @@ -1,8 +1,8 @@ import * as path from 'path'; -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; -import { RollupVirtualOptions } from '../'; +import type { RollupVirtualOptions } from '../'; const PREFIX = `\0virtual:`; diff --git a/packages/virtual/types/index.d.ts b/packages/virtual/types/index.d.ts index 1853ce84e..34fd38186 100644 --- a/packages/virtual/types/index.d.ts +++ b/packages/virtual/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; export interface RollupVirtualOptions { [id: string]: string; diff --git a/packages/wasm/src/index.ts b/packages/wasm/src/index.ts index b2d13f167..7eeb130ab 100644 --- a/packages/wasm/src/index.ts +++ b/packages/wasm/src/index.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { createHash } from 'crypto'; -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; import type { RollupWasmOptions } from '../types'; diff --git a/packages/wasm/types/index.d.ts b/packages/wasm/types/index.d.ts index e00fb8c2a..8bc64a0d2 100644 --- a/packages/wasm/types/index.d.ts +++ b/packages/wasm/types/index.d.ts @@ -1,4 +1,4 @@ -import { Plugin } from 'rollup'; +import type { Plugin } from 'rollup'; /** * - `"auto"` will determine the environment at runtime and invoke the correct methods accordingly diff --git a/packages/yaml/test/types.ts b/packages/yaml/test/types.ts index 02616e955..50be794ce 100644 --- a/packages/yaml/test/types.ts +++ b/packages/yaml/test/types.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from 'rollup'; +import type { RollupOptions } from 'rollup'; import yaml from '..'; diff --git a/packages/yaml/types/index.d.ts b/packages/yaml/types/index.d.ts index f7a6da730..a4986d053 100644 --- a/packages/yaml/types/index.d.ts +++ b/packages/yaml/types/index.d.ts @@ -1,5 +1,5 @@ -import { FilterPattern } from '@rollup/pluginutils'; -import { Plugin } from 'rollup'; +import type { FilterPattern } from '@rollup/pluginutils'; +import type { Plugin } from 'rollup'; type ValidYamlType = | number diff --git a/util/test.d.ts b/util/test.d.ts index 14ce32bd8..13aea36ef 100644 --- a/util/test.d.ts +++ b/util/test.d.ts @@ -1,6 +1,6 @@ /* eslint-disable import/no-extraneous-dependencies */ -import { RollupBuild, OutputOptions, OutputChunk, OutputAsset } from 'rollup'; -import { Assertions } from 'ava'; +import type { RollupBuild, OutputOptions, OutputChunk, OutputAsset } from 'rollup'; +import type { Assertions } from 'ava'; interface GetCode { (bundle: RollupBuild, outputOptions?: OutputOptions | null, allFiles?: false): Promise;