chore(deps): upgrade TypeScript to v5.5 and enable isolatedDeclarations

This commit is contained in:
Joakim Carlstein 2024-06-27 13:18:31 +02:00 committed by Joakim Carlstein
parent ef848a0553
commit d779286084
31 changed files with 512 additions and 458 deletions

View file

@ -0,0 +1,10 @@
---
'@emigrate/reporter-pino': patch
'@emigrate/plugin-tools': patch
'@emigrate/postgres': patch
'@emigrate/tsconfig': patch
'@emigrate/mysql': patch
'@emigrate/cli': patch
---
Upgrade TypeScript to v5.5 and enable [isolatedDeclarations](https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#isolated-declarations)

View file

@ -80,9 +80,9 @@
"lint-staged": "15.2.0",
"npm-run-all": "4.1.5",
"prettier": "3.1.1",
"tsx": "4.7.0",
"tsx": "4.15.7",
"turbo": "1.10.16",
"typescript": "5.3.3",
"typescript": "5.5.2",
"xo": "0.56.0"
}
}

View file

@ -1,12 +1,12 @@
import { type MigrationHistoryEntry, type MigrationMetadata, type MigrationMetadataFinished } from '@emigrate/types';
import { toMigrationMetadata } from './to-migration-metadata.js';
import { getMigrations as getMigrationsOriginal } from './get-migrations.js';
import { getMigrations as getMigrationsOriginal, type GetMigrationsFunction } from './get-migrations.js';
export async function* collectMigrations(
cwd: string,
directory: string,
history: AsyncIterable<MigrationHistoryEntry>,
getMigrations = getMigrationsOriginal,
getMigrations: GetMigrationsFunction = getMigrationsOriginal,
): AsyncIterable<MigrationMetadata | MigrationMetadataFinished> {
const allMigrations = await getMigrations(cwd, directory);
const seen = new Set<string>();

View file

@ -17,7 +17,7 @@ export default async function listCommand({
storage: storageConfig,
color,
cwd,
}: Config & ExtraFlags) {
}: Config & ExtraFlags): Promise<number> {
if (!directory) {
throw MissingOptionError.fromOption('directory');
}

View file

@ -24,7 +24,7 @@ type ExtraFlags = {
export default async function newCommand(
{ directory, template, reporter: reporterConfig, plugins = [], cwd, extension, color }: Config & ExtraFlags,
name: string,
) {
): Promise<void> {
if (!directory) {
throw MissingOptionError.fromOption('directory');
}

View file

@ -39,7 +39,7 @@ export default async function removeCommand(
getMigrations,
}: Config & ExtraFlags,
name: string,
) {
): Promise<number> {
if (!directory) {
throw MissingOptionError.fromOption('directory');
}

View file

@ -8,7 +8,7 @@ import { serializeError, errorConstructors, deserializeError } from 'serialize-e
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' });
export const toError = (error: unknown) => (error instanceof Error ? error : new Error(String(error)));
export const toError = (error: unknown): Error => (error instanceof Error ? error : new Error(String(error)));
export const toSerializedError = (error: unknown) => {
const errorInstance = toError(error);
@ -30,7 +30,7 @@ export class EmigrateError extends Error {
export class ShowUsageError extends EmigrateError {}
export class MissingOptionError extends ShowUsageError {
static fromOption(option: string | string[]) {
static fromOption(option: string | string[]): MissingOptionError {
return new MissingOptionError(
`Missing required option: ${Array.isArray(option) ? formatter.format(option) : option}`,
undefined,
@ -48,7 +48,7 @@ export class MissingOptionError extends ShowUsageError {
}
export class MissingArgumentsError extends ShowUsageError {
static fromArgument(argument: string) {
static fromArgument(argument: string): MissingArgumentsError {
return new MissingArgumentsError(`Missing required argument: ${argument}`, undefined, argument);
}
@ -62,7 +62,7 @@ export class MissingArgumentsError extends ShowUsageError {
}
export class OptionNeededError extends ShowUsageError {
static fromOption(option: string, message: string) {
static fromOption(option: string, message: string): OptionNeededError {
return new OptionNeededError(message, undefined, option);
}
@ -76,7 +76,7 @@ export class OptionNeededError extends ShowUsageError {
}
export class BadOptionError extends ShowUsageError {
static fromOption(option: string, message: string) {
static fromOption(option: string, message: string): BadOptionError {
return new BadOptionError(message, undefined, option);
}
@ -96,7 +96,7 @@ export class UnexpectedError extends EmigrateError {
}
export class MigrationHistoryError extends EmigrateError {
static fromHistoryEntry(entry: FailedMigrationHistoryEntry) {
static fromHistoryEntry(entry: FailedMigrationHistoryEntry): MigrationHistoryError {
return new MigrationHistoryError(`Migration ${entry.name} is in a failed state, it should be fixed and removed`, {
cause: deserializeError(entry.error),
});
@ -108,7 +108,7 @@ export class MigrationHistoryError extends EmigrateError {
}
export class MigrationLoadError extends EmigrateError {
static fromMetadata(metadata: MigrationMetadata, cause?: Error) {
static fromMetadata(metadata: MigrationMetadata, cause?: Error): MigrationLoadError {
return new MigrationLoadError(`Failed to load migration file: ${metadata.relativeFilePath}`, { cause });
}
@ -118,7 +118,7 @@ export class MigrationLoadError extends EmigrateError {
}
export class MigrationRunError extends EmigrateError {
static fromMetadata(metadata: FailedMigrationMetadata) {
static fromMetadata(metadata: FailedMigrationMetadata): MigrationRunError {
return new MigrationRunError(`Failed to run migration: ${metadata.relativeFilePath}`, { cause: metadata.error });
}
@ -128,7 +128,7 @@ export class MigrationRunError extends EmigrateError {
}
export class MigrationNotRunError extends EmigrateError {
static fromMetadata(metadata: MigrationMetadata, cause?: Error) {
static fromMetadata(metadata: MigrationMetadata, cause?: Error): MigrationNotRunError {
return new MigrationNotRunError(`Migration "${metadata.name}" is not in the migration history`, { cause });
}
@ -138,7 +138,7 @@ export class MigrationNotRunError extends EmigrateError {
}
export class MigrationRemovalError extends EmigrateError {
static fromMetadata(metadata: MigrationMetadata, cause?: Error) {
static fromMetadata(metadata: MigrationMetadata, cause?: Error): MigrationRemovalError {
return new MigrationRemovalError(`Failed to remove migration: ${metadata.relativeFilePath}`, { cause });
}
@ -148,7 +148,7 @@ export class MigrationRemovalError extends EmigrateError {
}
export class StorageInitError extends EmigrateError {
static fromError(error: Error) {
static fromError(error: Error): StorageInitError {
return new StorageInitError('Could not initialize storage', { cause: error });
}
@ -158,11 +158,11 @@ export class StorageInitError extends EmigrateError {
}
export class CommandAbortError extends EmigrateError {
static fromSignal(signal: NodeJS.Signals) {
static fromSignal(signal: NodeJS.Signals): CommandAbortError {
return new CommandAbortError(`Command aborted due to signal: ${signal}`);
}
static fromReason(reason: string, cause?: unknown) {
static fromReason(reason: string, cause?: unknown): CommandAbortError {
return new CommandAbortError(`Command aborted: ${reason}`, { cause });
}
@ -172,7 +172,7 @@ export class CommandAbortError extends EmigrateError {
}
export class ExecutionDesertedError extends EmigrateError {
static fromReason(reason: string, cause?: Error) {
static fromReason(reason: string, cause?: Error): ExecutionDesertedError {
return new ExecutionDesertedError(`Execution deserted: ${reason}`, { cause });
}

View file

@ -1,6 +1,6 @@
import process from 'node:process';
export const getDuration = (start: [number, number]) => {
export const getDuration = (start: [number, number]): number => {
const [seconds, nanoseconds] = process.hrtime(start);
return seconds * 1000 + nanoseconds / 1_000_000;
};

View file

@ -39,6 +39,6 @@ export const getMigrations = async (cwd: string, directory: string): Promise<Mig
extension: withLeadingPeriod(path.extname(name)),
directory,
cwd,
} satisfies MigrationMetadata;
};
});
};

View file

@ -28,4 +28,7 @@ const getPackageInfo = async () => {
throw new UnexpectedError(`Could not read package info from: ${packageInfoPath}`);
};
export const { version } = await getPackageInfo();
const packageInfo = await getPackageInfo();
// eslint-disable-next-line prefer-destructuring
export const version: string = packageInfo.version;

View file

@ -1,5 +1,5 @@
export * from './types.js';
export const emigrate = () => {
export const emigrate = (): void => {
// console.log('Done!');
};

View file

@ -471,6 +471,6 @@ class DefaultReporter implements Required<EmigrateReporter> {
}
}
const reporterDefault = interactive ? new DefaultFancyReporter() : new DefaultReporter();
const reporterDefault: EmigrateReporter = interactive ? new DefaultFancyReporter() : new DefaultReporter();
export default reporterDefault;

View file

@ -1,7 +1,8 @@
import type { EmigrateReporter } from '@emigrate/types';
import { type Config } from '../types.js';
import * as reporters from './index.js';
export const getStandardReporter = (reporter?: Config['reporter']) => {
export const getStandardReporter = (reporter?: Config['reporter']): EmigrateReporter | undefined => {
if (!reporter) {
return reporters.pretty;
}
@ -10,5 +11,5 @@ export const getStandardReporter = (reporter?: Config['reporter']) => {
return reporters[reporter as keyof typeof reporters];
}
return; // eslint-disable-line no-useless-return
return undefined;
};

View file

@ -55,6 +55,6 @@ class JsonReporter implements EmigrateReporter {
}
}
const jsonReporter = new JsonReporter() as EmigrateReporter;
const jsonReporter: EmigrateReporter = new JsonReporter();
export default jsonReporter;

View file

@ -15,7 +15,7 @@ export type Mocked<T> = {
[K in keyof T]: Mock<T[K]>;
};
export async function noop() {
export async function noop(): Promise<void> {
// noop
}
@ -31,8 +31,8 @@ export function getErrorCause(error: Error | undefined): Error | SerializedError
return undefined;
}
export function getMockedStorage(historyEntries: Array<string | MigrationHistoryEntry>) {
const storage: Mocked<Storage> = {
export function getMockedStorage(historyEntries: Array<string | MigrationHistoryEntry>): Mocked<Storage> {
return {
lock: mock.fn(async (migrations) => migrations),
unlock: mock.fn(async () => {
// void
@ -45,8 +45,6 @@ export function getMockedStorage(historyEntries: Array<string | MigrationHistory
onError: mock.fn(),
end: mock.fn(),
};
return storage;
}
export function getMockedReporter(): Mocked<Required<EmigrateReporter>> {

View file

@ -1 +1 @@
export const withLeadingPeriod = (string: string) => (string.startsWith('.') ? string : `.${string}`);
export const withLeadingPeriod = (string: string): string => (string.startsWith('.') ? string : `.${string}`);

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

View file

@ -13,7 +13,9 @@ import {
} from 'mysql2/promise';
import { getTimestampPrefix, sanitizeMigrationName } from '@emigrate/plugin-tools';
import {
type Awaitable,
type MigrationMetadata,
type MigrationFunction,
type EmigrateStorage,
type LoaderPlugin,
type Storage,
@ -345,17 +347,6 @@ export const createMysqlStorage = ({ table = defaultTable, connection }: MysqlSt
};
};
export const { initializeStorage } = createMysqlStorage({
table: process.env['MYSQL_TABLE'],
connection: process.env['MYSQL_URL'] ?? {
host: process.env['MYSQL_HOST'],
port: process.env['MYSQL_PORT'] ? Number.parseInt(process.env['MYSQL_PORT'], 10) : undefined,
user: process.env['MYSQL_USER'],
password: process.env['MYSQL_PASSWORD'],
database: process.env['MYSQL_DATABASE'],
},
});
export const createMysqlLoader = ({ connection }: MysqlLoaderOptions): LoaderPlugin => {
return {
loadableExtensions: ['.sql'],
@ -374,7 +365,16 @@ export const createMysqlLoader = ({ connection }: MysqlLoaderOptions): LoaderPlu
};
};
export const { loadableExtensions, loadMigration } = createMysqlLoader({
export const generateMigration: GenerateMigrationFunction = async (name) => {
return {
filename: `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.sql`,
content: `-- Migration: ${name}
`,
};
};
const storage = createMysqlStorage({
table: process.env['MYSQL_TABLE'],
connection: process.env['MYSQL_URL'] ?? {
host: process.env['MYSQL_HOST'],
port: process.env['MYSQL_PORT'] ? Number.parseInt(process.env['MYSQL_PORT'], 10) : undefined,
@ -384,13 +384,22 @@ export const { loadableExtensions, loadMigration } = createMysqlLoader({
},
});
export const generateMigration: GenerateMigrationFunction = async (name) => {
return {
filename: `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.sql`,
content: `-- Migration: ${name}
`,
};
};
const loader = createMysqlLoader({
connection: process.env['MYSQL_URL'] ?? {
host: process.env['MYSQL_HOST'],
port: process.env['MYSQL_PORT'] ? Number.parseInt(process.env['MYSQL_PORT'], 10) : undefined,
user: process.env['MYSQL_USER'],
password: process.env['MYSQL_PASSWORD'],
database: process.env['MYSQL_DATABASE'],
},
});
// eslint-disable-next-line prefer-destructuring
export const initializeStorage: () => Promise<Storage> = storage.initializeStorage;
// eslint-disable-next-line prefer-destructuring
export const loadableExtensions: string[] = loader.loadableExtensions;
// eslint-disable-next-line prefer-destructuring
export const loadMigration: (migration: MigrationMetadata) => Awaitable<MigrationFunction> = loader.loadMigration;
const defaultExport: EmigrateStorage & LoaderPlugin & GeneratorPlugin = {
initializeStorage,

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

View file

@ -204,7 +204,7 @@ const load = async <T>(
*
* @returns A timestamp string in the format YYYYMMDDHHmmssmmm
*/
export const getTimestampPrefix = () => new Date().toISOString().replaceAll(/[-:ZT.]/g, '');
export const getTimestampPrefix = (): string => new Date().toISOString().replaceAll(/[-:ZT.]/g, '');
/**
* A utility function to sanitize a migration name so that it can be used as a filename
@ -212,7 +212,7 @@ export const getTimestampPrefix = () => new Date().toISOString().replaceAll(/[-:
* @param name A migration name to sanitize
* @returns A sanitized migration name that can be used as a filename
*/
export const sanitizeMigrationName = (name: string) =>
export const sanitizeMigrationName = (name: string): string =>
name
.replaceAll(/[\W/\\:|*?'"<>_]+/g, '_')
.trim()

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

View file

@ -11,6 +11,8 @@ import {
type GeneratorPlugin,
type SerializedError,
type MigrationHistoryEntry,
type Awaitable,
type MigrationFunction,
} from '@emigrate/types';
const defaultTable = 'migrations';
@ -255,17 +257,6 @@ export const createPostgresStorage = ({
};
};
export const { initializeStorage } = createPostgresStorage({
table: process.env['POSTGRES_TABLE'],
connection: process.env['POSTGRES_URL'] ?? {
host: process.env['POSTGRES_HOST'],
port: process.env['POSTGRES_PORT'] ? Number.parseInt(process.env['POSTGRES_PORT'], 10) : undefined,
user: process.env['POSTGRES_USER'],
password: process.env['POSTGRES_PASSWORD'],
database: process.env['POSTGRES_DB'],
},
});
export const createPostgresLoader = ({ connection }: PostgresLoaderOptions): LoaderPlugin => {
return {
loadableExtensions: ['.sql'],
@ -284,7 +275,16 @@ export const createPostgresLoader = ({ connection }: PostgresLoaderOptions): Loa
};
};
export const { loadableExtensions, loadMigration } = createPostgresLoader({
export const generateMigration: GenerateMigrationFunction = async (name) => {
return {
filename: `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.sql`,
content: `-- Migration: ${name}
`,
};
};
const storage = createPostgresStorage({
table: process.env['POSTGRES_TABLE'],
connection: process.env['POSTGRES_URL'] ?? {
host: process.env['POSTGRES_HOST'],
port: process.env['POSTGRES_PORT'] ? Number.parseInt(process.env['POSTGRES_PORT'], 10) : undefined,
@ -294,13 +294,22 @@ export const { loadableExtensions, loadMigration } = createPostgresLoader({
},
});
export const generateMigration: GenerateMigrationFunction = async (name) => {
return {
filename: `${getTimestampPrefix()}_${sanitizeMigrationName(name)}.sql`,
content: `-- Migration: ${name}
`,
};
};
const loader = createPostgresLoader({
connection: process.env['POSTGRES_URL'] ?? {
host: process.env['POSTGRES_HOST'],
port: process.env['POSTGRES_PORT'] ? Number.parseInt(process.env['POSTGRES_PORT'], 10) : undefined,
user: process.env['POSTGRES_USER'],
password: process.env['POSTGRES_PASSWORD'],
database: process.env['POSTGRES_DB'],
},
});
// eslint-disable-next-line prefer-destructuring
export const initializeStorage: () => Promise<Storage> = storage.initializeStorage;
// eslint-disable-next-line prefer-destructuring
export const loadableExtensions: string[] = loader.loadableExtensions;
// eslint-disable-next-line prefer-destructuring
export const loadMigration: (migration: MigrationMetadata) => Awaitable<MigrationFunction> = loader.loadMigration;
const defaultExport: EmigrateStorage & LoaderPlugin & GeneratorPlugin = {
initializeStorage,

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

View file

@ -204,6 +204,8 @@ export const createPinoReporter = (options: PinoReporterOptions = {}): EmigrateR
return new PinoReporter(options);
};
export default createPinoReporter({
const defaultExport: EmigrateReporter = createPinoReporter({
level: process.env['LOG_LEVEL'],
});
export default defaultExport;

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

View file

@ -11,6 +11,7 @@
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"isolatedDeclarations": true,
"incremental": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
@ -31,5 +32,7 @@
"strict": true,
"target": "ES2022",
"lib": ["ESNext", "DOM", "DOM.Iterable"]
}
},
"include": ["${configDir}/src"],
"exclude": ["${configDir}/dist"]
}

View file

@ -3,6 +3,7 @@
"display": "Build",
"extends": "./base.json",
"compilerOptions": {
"noEmit": false
"noEmit": false,
"outDir": "${configDir}/dist"
}
}

View file

@ -1,8 +1,3 @@
{
"extends": "@emigrate/tsconfig/build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
"extends": "@emigrate/tsconfig/build.json"
}

722
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff