chore(deps): upgrade TypeScript to v5.5 and enable isolatedDeclarations
This commit is contained in:
parent
ef848a0553
commit
d779286084
31 changed files with 512 additions and 458 deletions
|
|
@ -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>();
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export default async function removeCommand(
|
|||
getMigrations,
|
||||
}: Config & ExtraFlags,
|
||||
name: string,
|
||||
) {
|
||||
): Promise<number> {
|
||||
if (!directory) {
|
||||
throw MissingOptionError.fromOption('directory');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,6 +39,6 @@ export const getMigrations = async (cwd: string, directory: string): Promise<Mig
|
|||
extension: withLeadingPeriod(path.extname(name)),
|
||||
directory,
|
||||
cwd,
|
||||
} satisfies MigrationMetadata;
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export * from './types.js';
|
||||
|
||||
export const emigrate = () => {
|
||||
export const emigrate = (): void => {
|
||||
// console.log('Done!');
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -55,6 +55,6 @@ class JsonReporter implements EmigrateReporter {
|
|||
}
|
||||
}
|
||||
|
||||
const jsonReporter = new JsonReporter() as EmigrateReporter;
|
||||
const jsonReporter: EmigrateReporter = new JsonReporter();
|
||||
|
||||
export default jsonReporter;
|
||||
|
|
|
|||
|
|
@ -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>> {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export const withLeadingPeriod = (string: string) => (string.startsWith('.') ? string : `.${string}`);
|
||||
export const withLeadingPeriod = (string: string): string => (string.startsWith('.') ? string : `.${string}`);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
{
|
||||
"extends": "@emigrate/tsconfig/build.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"extends": "@emigrate/tsconfig/build.json"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue