diff --git a/.eslintrc.cjs b/.eslintrc.cjs index e6085ac647..95f00b4762 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -58,6 +58,16 @@ module.exports = { '@typescript-eslint/unbound-method': 'off', '@typescript-eslint/no-explicit-any': 'off', + // Enforce separate type imports for type-only imports to avoid bundling unneeded code + '@typescript-eslint/consistent-type-imports': [ + 'error', + { + prefer: 'type-imports', + fixStyle: 'separate-type-imports', + disallowTypeAnnotations: false, + }, + ], + // These rules enabled by the preset configs don't work well for us '@typescript-eslint/await-thenable': 'off', 'prefer-const': 'off', diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js index cc7bff82b2..e6f68a272f 100644 --- a/packages/astro-rss/test/rss.test.js +++ b/packages/astro-rss/test/rss.test.js @@ -1,18 +1,18 @@ -import rss, { getRssString } from '../dist/index.js'; -import { rssSchema } from '../dist/schema.js'; import chai from 'chai'; import chaiPromises from 'chai-as-promised'; import chaiXml from 'chai-xml'; +import rss, { getRssString } from '../dist/index.js'; +import { rssSchema } from '../dist/schema.js'; import { - title, description, - site, phpFeedItem, phpFeedItemWithContent, phpFeedItemWithCustomData, + site, + title, web1FeedItem, - web1FeedItemWithContent, web1FeedItemWithAllData, + web1FeedItemWithContent, } from './test-utils.js'; chai.use(chaiPromises); diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts index c4109ea1ed..1c55a93b98 100644 --- a/packages/astro/src/assets/build/generate.ts +++ b/packages/astro/src/assets/build/generate.ts @@ -1,7 +1,7 @@ import { dim, green } from 'kleur/colors'; import fs, { readFileSync } from 'node:fs'; import { basename, join } from 'node:path/posix'; -import PQueue from 'p-queue'; +import type PQueue from 'p-queue'; import type { AstroConfig } from '../../@types/astro.js'; import type { BuildPipeline } from '../../core/build/buildPipeline.js'; import { getOutDirWithinCwd } from '../../core/build/common.js'; diff --git a/packages/astro/src/core/build/buildPipeline.ts b/packages/astro/src/core/build/buildPipeline.ts index 87166b4f4a..623e89630f 100644 --- a/packages/astro/src/core/build/buildPipeline.ts +++ b/packages/astro/src/core/build/buildPipeline.ts @@ -2,7 +2,7 @@ import type { AstroConfig, AstroSettings, SSRLoadedRenderer } from '../../@types import { getOutputDirectory, isServerLikeOutput } from '../../prerender/utils.js'; import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import type { SSRManifest } from '../app/types.js'; -import { Logger } from '../logger/core.js'; +import type { Logger } from '../logger/core.js'; import { Pipeline } from '../pipeline.js'; import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js'; import { createEnvironment } from '../render/index.js'; diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index d9c061567d..99a7ad121b 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -10,7 +10,6 @@ import type { GetStaticPathsItem, RouteData, RouteType, - SSRElement, SSRError, SSRLoadedRenderer, SSRManifest, diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 0245e50c2f..fa45c9d6b6 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -24,7 +24,8 @@ import { resolveConfig } from '../config/config.js'; import { createNodeLogger } from '../config/logging.js'; import { createSettings } from '../config/settings.js'; import { createVite } from '../create-vite.js'; -import { Logger, levels, timerMessage } from '../logger/core.js'; +import type { Logger } from '../logger/core.js'; +import { levels, timerMessage } from '../logger/core.js'; import { apply as applyPolyfill } from '../polyfill.js'; import { RouteCache } from '../render/route-cache.js'; import { createRouteManifest } from '../routing/index.js'; diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index 2985dcab96..ed2369f7f3 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -5,7 +5,8 @@ import type { AstroConfig } from '../../@types/astro.js'; import { transform } from '@astrojs/compiler'; import { fileURLToPath } from 'node:url'; import { normalizePath } from 'vite'; -import { AggregateError, AstroError, CompilerError } from '../errors/errors.js'; +import type { AstroError } from '../errors/errors.js'; +import { AggregateError, CompilerError } from '../errors/errors.js'; import { AstroErrorData } from '../errors/index.js'; import { resolvePath } from '../util.js'; import { createStylePreprocessor } from './style.js'; diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index b19eae4ac4..3d77ef0c0c 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -1,4 +1,4 @@ -import nodeFs from 'node:fs'; +import type nodeFs from 'node:fs'; import { fileURLToPath } from 'node:url'; import * as vite from 'vite'; import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; diff --git a/packages/astro/src/core/logger/node.ts b/packages/astro/src/core/logger/node.ts index 727cafd1b2..2c75968d2f 100644 --- a/packages/astro/src/core/logger/node.ts +++ b/packages/astro/src/core/logger/node.ts @@ -1,5 +1,5 @@ import debugPackage from 'debug'; -import { Writable } from 'node:stream'; +import type { Writable } from 'node:stream'; import { getEventPrefix, levels, type LogMessage, type LogWritable } from './core.js'; type ConsoleStream = Writable & { diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index 0ad5df205f..3532c5f837 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -4,7 +4,8 @@ import type { Logger } from '../logger/core.js'; import { routeIsFallback } from '../redirects/helpers.js'; import { routeIsRedirect } from '../redirects/index.js'; import { getParams } from '../routing/params.js'; -import { RouteCache, callGetStaticPaths, findPathItemByKey } from './route-cache.js'; +import type { RouteCache } from './route-cache.js'; +import { callGetStaticPaths, findPathItemByKey } from './route-cache.js'; interface GetParamsAndPropsOptions { mod: ComponentInstance | undefined; diff --git a/packages/astro/src/core/render/route-cache.ts b/packages/astro/src/core/render/route-cache.ts index 4db5b75fd4..8a4e821a52 100644 --- a/packages/astro/src/core/render/route-cache.ts +++ b/packages/astro/src/core/render/route-cache.ts @@ -8,7 +8,6 @@ import type { RouteData, RuntimeMode, } from '../../@types/astro.js'; -import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; import { stringifyParams } from '../routing/params.js'; diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 9031eeb2df..d082c438fb 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -18,7 +18,7 @@ import type { SerializedSSRManifest } from '../core/app/types.js'; import type { PageBuildData } from '../core/build/types.js'; import { buildClientDirectiveEntrypoint } from '../core/client-directive/index.js'; import { mergeConfig } from '../core/config/index.js'; -import { AstroIntegrationLogger, type Logger } from '../core/logger/core.js'; +import type { AstroIntegrationLogger, Logger } from '../core/logger/core.js'; import { isServerLikeOutput } from '../prerender/utils.js'; import { validateSupportedFeatures } from './astroFeaturesValidation.js'; diff --git a/packages/astro/src/runtime/client/dev-overlay/entrypoint.ts b/packages/astro/src/runtime/client/dev-overlay/entrypoint.ts index 773d249310..f7c09dea6d 100644 --- a/packages/astro/src/runtime/client/dev-overlay/entrypoint.ts +++ b/packages/astro/src/runtime/client/dev-overlay/entrypoint.ts @@ -1,5 +1,5 @@ import type { DevOverlayPlugin as DevOverlayPluginDefinition } from '../../../@types/astro.js'; -import { type AstroDevOverlay, type DevOverlayPlugin } from './overlay.js'; +import type { AstroDevOverlay, DevOverlayPlugin } from './overlay.js'; import { settings } from './settings.js'; // @ts-expect-error import { loadDevOverlayPlugins } from 'astro:dev-overlay'; diff --git a/packages/astro/src/runtime/server/render/common.ts b/packages/astro/src/runtime/server/render/common.ts index 4087ef1a7e..f595dc78cf 100644 --- a/packages/astro/src/runtime/server/render/common.ts +++ b/packages/astro/src/runtime/server/render/common.ts @@ -1,7 +1,8 @@ import type { SSRResult } from '../../../@types/astro.js'; import type { RenderInstruction } from './instruction.js'; -import { HTMLBytes, HTMLString, markHTMLString } from '../escape.js'; +import type { HTMLBytes, HTMLString } from '../escape.js'; +import { markHTMLString } from '../escape.js'; import { determineIfNeedsHydrationScript, determinesIfNeedsDirectiveScript, diff --git a/packages/astro/src/runtime/server/render/component.ts b/packages/astro/src/runtime/server/render/component.ts index dfc5d6c5b6..42987f011e 100644 --- a/packages/astro/src/runtime/server/render/component.ts +++ b/packages/astro/src/runtime/server/render/component.ts @@ -8,7 +8,8 @@ import { createRenderInstruction, type RenderInstruction } from './instruction.j import { clsx } from 'clsx'; import { AstroError, AstroErrorData } from '../../../core/errors/index.js'; -import { HTMLBytes, markHTMLString } from '../escape.js'; +import type { HTMLBytes } from '../escape.js'; +import { markHTMLString } from '../escape.js'; import { extractDirectives, generateHydrateScript } from '../hydration.js'; import { serializeProps } from '../serialize.js'; import { shorthash } from '../shorthash.js'; diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index 92d8bb4a21..e5bf35b7fd 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -1,10 +1,5 @@ -import { - TRANSITION_AFTER_SWAP, - TransitionBeforeSwapEvent, - doPreparation, - doSwap, - type TransitionBeforePreparationEvent, -} from './events.js'; +import type { TransitionBeforePreparationEvent, TransitionBeforeSwapEvent } from './events.js'; +import { TRANSITION_AFTER_SWAP, doPreparation, doSwap } from './events.js'; import type { Direction, Fallback, Options } from './types.js'; type State = { diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 4e5d3237dc..d06a8338f6 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -1,11 +1,7 @@ import type { HmrContext, ModuleNode } from 'vite'; import type { AstroConfig } from '../@types/astro.js'; -import { - cachedCompilation, - invalidateCompilation, - isCached, - type CompileResult, -} from '../core/compile/index.js'; +import type { cachedCompilation } from '../core/compile/index.js'; +import { invalidateCompilation, isCached, type CompileResult } from '../core/compile/index.js'; import type { Logger } from '../core/logger/core.js'; import { isAstroSrcFile } from '../core/logger/vite.js'; import { isAstroScript } from './query.js'; diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 3c292ef2a4..4b9a032306 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -1,7 +1,7 @@ -import { loadFixture } from './test-utils.js'; import { expect } from 'chai'; import * as cheerio from 'cheerio'; import testAdapter from './test-adapter.js'; +import { loadFixture } from './test-utils.js'; describe('astro:i18n virtual module', () => { /** @type {import('./test-utils').Fixture} */ diff --git a/packages/integrations/markdoc/components/TreeNode.ts b/packages/integrations/markdoc/components/TreeNode.ts index dce10f6cc4..abec17d7be 100644 --- a/packages/integrations/markdoc/components/TreeNode.ts +++ b/packages/integrations/markdoc/components/TreeNode.ts @@ -1,17 +1,17 @@ -import type { AstroInstance } from 'astro'; import type { RenderableTreeNode } from '@markdoc/markdoc'; import Markdoc from '@markdoc/markdoc'; +import type { AstroInstance } from 'astro'; +import type { HTMLString } from 'astro/runtime/server/index.js'; import { createComponent, - renderComponent, - render, - renderScriptElement, - renderUniqueStylesheet, createHeadAndContent, - unescapeHTML, - renderTemplate, - HTMLString, isHTMLString, + render, + renderComponent, + renderScriptElement, + renderTemplate, + renderUniqueStylesheet, + unescapeHTML, } from 'astro/runtime/server/index.js'; export type TreeNode = diff --git a/packages/integrations/node/src/types.ts b/packages/integrations/node/src/types.ts index 1917d8cf36..273b805292 100644 --- a/packages/integrations/node/src/types.ts +++ b/packages/integrations/node/src/types.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from 'node:http'; +import type { IncomingMessage, ServerResponse } from 'node:http'; export interface UserOptions { /** diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 45f6948877..79f6f9dfcb 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -1,12 +1,8 @@ import type { AstroConfig, AstroIntegration } from 'astro'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import { - EnumChangefreq, - simpleSitemapAndIndex, - type LinkItem as LinkItemBase, - type SitemapItemLoose, -} from 'sitemap'; +import type { EnumChangefreq, LinkItem as LinkItemBase, SitemapItemLoose } from 'sitemap'; +import { simpleSitemapAndIndex } from 'sitemap'; import { ZodError } from 'zod'; import { generateSitemap } from './generate-sitemap.js';