Skip to content

Commit

Permalink
feat(all): Migrate to TypeScript 5.0 (#6579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Mar 20, 2023
1 parent c341bd0 commit 1e7d6af
Show file tree
Hide file tree
Showing 63 changed files with 429 additions and 172 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@
"@changesets/cli": "2.23.0",
"@octokit/action": "^3.18.1",
"@types/node": "^18.7.21",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"del": "^7.0.0",
"esbuild": "^0.15.18",
"esbuild": "^0.17.12",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-no-only-tests": "^2.6.0",
Expand All @@ -100,6 +100,6 @@
"pretty-bytes": "^6.0.0",
"tiny-glob": "^0.2.9",
"turbo": "1.2.5",
"typescript": "~4.7.3"
"typescript": "~5.0.2"
}
}
4 changes: 1 addition & 3 deletions packages/astro/src/@types/typed-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type EventMap = {
* myEmitter.emit("error", "x") // <- Will catch this type error;
* ```
*/
interface TypedEventEmitter<Events extends EventMap> {
export interface TypedEventEmitter<Events extends EventMap> {
addListener<E extends keyof Events>(event: E, listener: Events[E]): this;
on<E extends keyof Events>(event: E, listener: Events[E]): this;
once<E extends keyof Events>(event: E, listener: Events[E]): this;
Expand All @@ -45,5 +45,3 @@ interface TypedEventEmitter<Events extends EventMap> {
getMaxListeners(): number;
setMaxListeners(maxListeners: number): this;
}

export default TypedEventEmitter;
2 changes: 1 addition & 1 deletion packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import type { StaticBuildOptions } from '../core/build/types.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { ImageService, isLocalService, LocalImageService } from './services/service.js';
import { isLocalService, type ImageService, type LocalImageService } from './services/service.js';
import type { ImageMetadata, ImageTransform } from './types.js';

export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
Expand Down
7 changes: 6 additions & 1 deletion packages/astro/src/assets/services/sharp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { FormatEnum } from 'sharp';
import type { ImageQualityPreset, OutputFormat } from '../types.js';
import { baseService, BaseServiceTransform, LocalImageService, parseQuality } from './service.js';
import {
baseService,
parseQuality,
type BaseServiceTransform,
type LocalImageService,
} from './service.js';

let sharp: typeof import('sharp');

Expand Down
7 changes: 6 additions & 1 deletion packages/astro/src/assets/services/squoosh.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// TODO: Investigate removing this service once sharp lands WASM support, as libsquoosh is deprecated

import type { ImageQualityPreset, OutputFormat } from '../types.js';
import { baseService, BaseServiceTransform, LocalImageService, parseQuality } from './service.js';
import {
baseService,
parseQuality,
type BaseServiceTransform,
type LocalImageService,
} from './service.js';
import { processBuffer } from './vendor/squoosh/image-pool.js';
import type { Operation } from './vendor/squoosh/image.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/vendor/image-size/detector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { imageType, typeHandlers } from './types.js'
import { typeHandlers, type imageType } from './types.js'

const keys = Object.keys(typeHandlers) as imageType[]

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/vendor/image-size/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import Queue from "../queue/queue.js";
import { detector } from "./detector.js";
import { imageType, typeHandlers } from "./types.js";
import { typeHandlers, type imageType } from "./types.js";
import type { ISizeCalculationResult } from "./types/interface.js";

type CallbackFn = (e: Error | null, r?: ISizeCalculationResult) => void;
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/src/cli/check/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable no-console */
import { AstroCheck, DiagnosticSeverity, GetDiagnosticsResult } from '@astrojs/language-server';
import {
AstroCheck,
DiagnosticSeverity,
type GetDiagnosticsResult,
} from '@astrojs/language-server';
import type { FSWatcher } from 'chokidar';
import glob from 'fast-glob';
import fsMod, * as fs from 'fs';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/check/print.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Diagnostic, DiagnosticSeverity, offsetAt } from '@astrojs/language-server';
import { DiagnosticSeverity, offsetAt, type Diagnostic } from '@astrojs/language-server';
import {
bgRed,
bgWhite,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { ASTRO_VERSION } from '../core/constants.js';
import { collectErrorMetadata } from '../core/errors/dev/index.js';
import { createSafeError } from '../core/errors/index.js';
import { debug, error, info, LogOptions } from '../core/logger/core.js';
import { debug, error, info, type LogOptions } from '../core/logger/core.js';
import { enableVerboseLogging, nodeLogDestination } from '../core/logger/node.js';
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from '../core/messages.js';
import * as event from '../events/index.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/content/server-listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
import type { ViteDevServer } from 'vite';
import type { AstroSettings } from '../@types/astro.js';
import { loadTSConfig } from '../core/config/tsconfig.js';
import { info, LogOptions, warn } from '../core/logger/core.js';
import { info, warn, type LogOptions } from '../core/logger/core.js';
import { appendForwardSlash } from '../core/path.js';
import { createContentTypesGenerator } from './types-generator.js';
import { ContentPaths, getContentPaths, globalContentConfigObserver } from './utils.js';
import { getContentPaths, globalContentConfigObserver, type ContentPaths } from './utils.js';

interface ContentServerListenerParams {
fs: typeof fsMod;
Expand Down
14 changes: 7 additions & 7 deletions packages/astro/src/content/types-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { cyan } from 'kleur/colors';
import type fsMod from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { normalizePath, ViteDevServer } from 'vite';
import { normalizePath, type ViteDevServer } from 'vite';
import type { AstroSettings, ContentEntryType } from '../@types/astro.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { info, LogOptions, warn } from '../core/logger/core.js';
import { info, warn, type LogOptions } from '../core/logger/core.js';
import { isRelativePath } from '../core/path.js';
import { CONTENT_TYPES_FILE } from './consts.js';
import {
ContentConfig,
ContentObservable,
ContentPaths,
EntryInfo,
NoCollectionError,
getContentEntryExts,
getContentPaths,
getEntryInfo,
getEntrySlug,
getEntryType,
loadContentConfig,
NoCollectionError,
parseFrontmatter,
type ContentConfig,
type ContentObservable,
type ContentPaths,
type EntryInfo,
} from './utils.js';

type ChokidarEvent = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fsMod from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type { EmitFile } from 'rollup';
import { ErrorPayload as ViteErrorPayload, normalizePath, ViteDevServer } from 'vite';
import { normalizePath, type ViteDevServer, type ErrorPayload as ViteErrorPayload } from 'vite';
import { z } from 'zod';
import type { AstroConfig, AstroSettings } from '../@types/astro.js';
import { emitESMImage } from '../assets/utils/emitAsset.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/content/vite-plugin-content-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pathToFileURL } from 'url';
import type { Plugin } from 'vite';
import type { AstroSettings } from '../@types/astro.js';
import { moduleIsTopLevelPage, walkParentInfos } from '../core/build/graph.js';
import { BuildInternals, getPageDataByViteID } from '../core/build/internal.js';
import { getPageDataByViteID, type BuildInternals } from '../core/build/internal.js';
import type { AstroBuildPlugin } from '../core/build/plugin.js';
import type { StaticBuildOptions } from '../core/build/types';
import type { ModuleLoader } from '../core/module-loader/loader.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/content/vite-plugin-content-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { AstroError } from '../core/errors/errors.js';
import { escapeViteEnvReferences, getFileInfo } from '../vite-plugin-utils/index.js';
import { CONTENT_FLAG } from './consts.js';
import {
ContentConfig,
getContentEntryExts,
getContentPaths,
getEntryData,
Expand All @@ -18,6 +17,7 @@ import {
getEntryType,
globalContentConfigObserver,
patchAssets,
type ContentConfig,
} from './utils.js';
function isContentFlagImport(viteId: string, contentEntryExts: string[]) {
const { searchParams, pathname } = new URL(viteId, 'file://');
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import type yargs from 'yargs-parser';
import { loadTSConfig, resolveConfigPath } from '../config/index.js';
import {
defaultTSConfig,
frameworkWithTSSettings,
presets,
updateTSConfigForFramework,
type frameworkWithTSSettings,
} from '../config/tsconfig.js';
import { debug, info, LogOptions } from '../logger/core.js';
import { debug, info, type LogOptions } from '../logger/core.js';
import * as msg from '../messages.js';
import { printHelp } from '../messages.js';
import { appendForwardSlash } from '../path.js';
Expand Down Expand Up @@ -62,7 +62,7 @@ export default {
`;
const LIT_NPMRC_STUB = `\
# Lit libraries are required to be hoisted due to dependency issues.
public-hoist-pattern[]=*lit*
public-hoist-pattern[]=*lit*
`;

const OFFICIAL_ADAPTER_TO_IMPORT_MAP: Record<string, string> = {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
RouteData,
SSRElement,
} from '../../@types/astro';
import type { RouteInfo, SSRManifest as Manifest } from './types';
import type { SSRManifest as Manifest, RouteInfo } from './types';

import mime from 'mime';
import { attachToResponse, getSetCookiesFromResponse } from '../cookies/index.js';
Expand All @@ -16,8 +16,8 @@ import { joinPaths, prependForwardSlash, removeTrailingForwardSlash } from '../p
import {
createEnvironment,
createRenderContext,
Environment,
renderPage,
type Environment,
} from '../render/index.js';
import { RouteCache } from '../render/route-cache.js';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as fs from 'fs';
import type { IncomingMessage } from 'http';
import { TLSSocket } from 'tls';
import { deserializeManifest } from './common.js';
import { App, MatchOptions } from './index.js';
import { App, type MatchOptions } from './index.js';

const clientAddressSymbol = Symbol.for('astro.clientAddress');

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
generateImage as generateImageInternal,
getStaticImageList,
} from '../../assets/internal.js';
import { BuildInternals, hasPrerenderedPages } from '../../core/build/internal.js';
import { hasPrerenderedPages, type BuildInternals } from '../../core/build/internal.js';
import {
prependForwardSlash,
removeLeadingForwardSlash,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-css.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as crypto from 'node:crypto';
import * as npath from 'node:path';
import type { GetModuleInfo } from 'rollup';
import { Plugin as VitePlugin, ResolvedConfig, transformWithEsbuild } from 'vite';
import { transformWithEsbuild, type ResolvedConfig, type Plugin as VitePlugin } from 'vite';
import { isBuildableCSSRequest } from '../../render/dev/util.js';
import type { BuildInternals } from '../internal';
import type { AstroBuildPlugin } from '../plugin';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { StaticBuildOptions } from '../types';

import { pagesVirtualModuleId, resolvedPagesVirtualModuleId } from '../../app/index.js';
import { addRollupInput } from '../add-rollup-input.js';
import { BuildInternals, eachPageData, hasPrerenderedPages } from '../internal.js';
import { eachPageData, hasPrerenderedPages, type BuildInternals } from '../internal.js';

export function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { bgGreen, bgMagenta, black, dim } from 'kleur/colors';
import { fileURLToPath } from 'url';
import * as vite from 'vite';
import {
BuildInternals,
createBuildInternals,
eachPrerenderedPageData,
type BuildInternals,
} from '../../core/build/internal.js';
import { emptyDir, removeEmptyDirs } from '../../core/fs/index.js';
import { appendForwardSlash, prependForwardSlash } from '../../core/path.js';
Expand All @@ -21,7 +21,7 @@ import { info } from '../logger/core.js';
import { getOutDirWithinCwd } from './common.js';
import { generatePages } from './generate.js';
import { trackPageData } from './internal.js';
import { AstroBuildPluginContainer, createPluginContainer } from './plugin.js';
import { createPluginContainer, type AstroBuildPluginContainer } from './plugin.js';
import { registerAllPlugins } from './plugins/index.js';
import type { PageBuildData, StaticBuildOptions } from './types';
import { getTimeStat } from './util.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/compile/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AstroConfig } from '../../@types/astro';
import { compile, CompileProps, CompileResult } from './compile.js';
import { compile, type CompileProps, type CompileResult } from './compile.js';

type CompilationCache = Map<string, CompileResult>;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/compile/style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TransformOptions } from '@astrojs/compiler';
import fs from 'fs';
import { preprocessCSS, ResolvedConfig } from 'vite';
import { preprocessCSS, type ResolvedConfig } from 'vite';
import { AstroErrorData, CSSError, positionAt } from '../errors/index.js';

export function createStylePreprocessor({
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type * as vite from 'vite';
import type yargs from 'yargs-parser';
import type { AstroSettings } from '../../@types/astro';
import { attachContentServerListeners } from '../../content/index.js';
import { info, LogOptions, warn } from '../logger/core.js';
import { info, warn, type LogOptions } from '../logger/core.js';
import * as msg from '../messages.js';
import { printHelp } from '../messages.js';
import { startContainer } from './container.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/endpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { renderEndpoint } from '../../runtime/server/index.js';
import { ASTRO_VERSION } from '../constants.js';
import { AstroCookies, attachToResponse } from '../cookies/index.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
import { LogOptions, warn } from '../logger/core.js';
import { getParamsAndProps, GetParamsAndPropsError } from '../render/core.js';
import { warn, type LogOptions } from '../logger/core.js';
import { GetParamsAndPropsError, getParamsAndProps } from '../render/core.js';

const clientAddressSymbol = Symbol.for('astro.clientAddress');

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/errors/dev/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
import stripAnsi from 'strip-ansi';
import type { ESBuildTransformResult } from 'vite';
import type { SSRError } from '../../../@types/astro.js';
import { AggregateError, ErrorWithMetadata } from '../errors.js';
import { AggregateError, type ErrorWithMetadata } from '../errors.js';
import { codeFrame } from '../printer.js';
import { normalizeLF } from '../utils.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/errors/dev/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from 'url';
import type { ErrorPayload } from 'vite';
import type { ModuleLoader } from '../../module-loader/index.js';
import { AstroErrorData } from '../errors-data.js';
import { AstroError, ErrorWithMetadata } from '../errors.js';
import { AstroError, type ErrorWithMetadata } from '../errors.js';
import { createSafeError } from '../utils.js';
import type { SSRLoadedRenderer } from './../../../@types/astro.js';
import { renderErrorMarkdown } from './utils.js';
Expand Down
6 changes: 2 additions & 4 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export interface ErrorData {
hint?: string | ((...params: any) => string);
}

// TODO: Replace with `satisfies` once TS 4.9 is out
const defineErrors = <T extends Record<string, ErrorData>>(errs: T) => errs;
export const AstroErrorData = defineErrors({
export const AstroErrorData = {
/**
* @docs
* @kind heading
Expand Down Expand Up @@ -819,7 +817,7 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
title: 'Unknown Error.',
code: 99999,
},
} as const);
} as const satisfies Record<string, ErrorData>;

type ValueOf<T> = T[keyof T];
export type AstroErrorCodes = ValueOf<{
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/errors/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DiagnosticCode } from '@astrojs/compiler/shared/diagnostics.js';
import type { SSRError } from '../../@types/astro.js';
import { AstroErrorCodes, AstroErrorData, ErrorData } from './errors-data.js';
import { AstroErrorData, type AstroErrorCodes, type ErrorData } from './errors-data.js';

/**
* Get the line and character based on the offset
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import type { ResolvedServerUrls } from 'vite';
import type { ZodError } from 'zod';
import { renderErrorMarkdown } from './errors/dev/utils.js';
import { AstroError, CompilerError, ErrorWithMetadata } from './errors/index.js';
import { AstroError, CompilerError, type ErrorWithMetadata } from './errors/index.js';
import { emoji, padMultilineString } from './util.js';

const PREFIX_PADDING = 6;
Expand Down
Loading

0 comments on commit 1e7d6af

Please sign in to comment.