* feat(types): move Emigrate types to separate package Also refactor the types to use discriminating unions for easier error handling and such. Errors passed to storage plugins should now be serialized and storage plugins are expected to return already serialized errors on failed history entries. * fix(mysql): handle the new type changes * fix(storage-fs): handle the new type changes * feat(cli): better error handling and types Adapt to the new types from the @emigrate/types package, like discriminating union types and serializing and deserializing errors
31 lines
797 B
TypeScript
31 lines
797 B
TypeScript
import fs from 'node:fs/promises';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { UnexpectedError } from './errors.js';
|
|
|
|
type PackageInfo = {
|
|
version: string;
|
|
};
|
|
|
|
const getPackageInfo = async () => {
|
|
const packageInfoPath = fileURLToPath(new URL('../package.json', import.meta.url));
|
|
|
|
try {
|
|
const content = await fs.readFile(packageInfoPath, 'utf8');
|
|
const packageJson: unknown = JSON.parse(content);
|
|
|
|
if (
|
|
typeof packageJson === 'object' &&
|
|
packageJson &&
|
|
'version' in packageJson &&
|
|
typeof packageJson.version === 'string'
|
|
) {
|
|
return packageJson as PackageInfo;
|
|
}
|
|
} catch {
|
|
// ignore
|
|
}
|
|
|
|
throw new UnexpectedError(`Could not read package info from: ${packageInfoPath}`);
|
|
};
|
|
|
|
export const { version } = await getPackageInfo();
|