This commit upgrades TypeScript from 5.4 to 5.5 and enables the
`noImplicitAny` option for stricter type checking. It refactors code to
comply with `noImplicitAny` and adapts to new TypeScript features and
limitations.
Key changes:
- Migrate from TypeScript 5.4 to 5.5
- Enable `noImplicitAny` for stricter type checking
- Refactor code to comply with new TypeScript features and limitations
Other supporting changes:
- Refactor progress bar handling for type safety
- Drop 'I' prefix from interfaces to align with new code convention
- Update TypeScript target from `ES2017` and `ES2018`.
This allows named capturing groups. Otherwise, new TypeScript compiler
does not compile the project and shows the following error:
```
...
TimestampedFilenameGenerator.spec.ts:105:23 - error TS1503: Named capturing groups are only available when targeting 'ES2018' or later
const pattern = /^(?<timestamp>\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})-(?<scriptName>[^.]+?)(?:\.(?<extension>[^.]+))?$/;// timestamp-scriptName.extension
...
```
- Refactor usage of `electron-progressbar` for type safety and
less complexity.
69 lines
2.7 KiB
TypeScript
69 lines
2.7 KiB
TypeScript
import { resolve, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { VITE_USER_DEFINED_ENVIRONMENT_KEYS } from './src/infrastructure/EnvironmentVariables/Vite/ViteEnvironmentKeys';
|
|
import tsconfigJson from './tsconfig.json' assert { type: 'json' };
|
|
import packageJson from './package.json' assert { type: 'json' };
|
|
|
|
type ViteAliasDefinitions = Record<string, string>;
|
|
|
|
export function getAliases(): ViteAliasDefinitions {
|
|
return {
|
|
...getPathAliasesFromTsConfig(),
|
|
...getElectronProcessSpecificModuleAliases(),
|
|
};
|
|
}
|
|
|
|
export function getSelfDirectoryAbsolutePath() {
|
|
const filePath = fileURLToPath(import.meta.url);
|
|
const directoryPath = dirname(filePath);
|
|
return directoryPath;
|
|
}
|
|
|
|
type ViteEnvironmentKeyValues = {
|
|
[K in
|
|
typeof VITE_USER_DEFINED_ENVIRONMENT_KEYS[keyof typeof VITE_USER_DEFINED_ENVIRONMENT_KEYS]
|
|
]: string
|
|
};
|
|
|
|
type ViteGlobalVariableReplacementDefinitions = Record<string, string>;
|
|
|
|
export function getClientEnvironmentVariables(): ViteGlobalVariableReplacementDefinitions {
|
|
const environmentVariables: ViteEnvironmentKeyValues = {
|
|
[VITE_USER_DEFINED_ENVIRONMENT_KEYS.NAME]: packageJson.name,
|
|
[VITE_USER_DEFINED_ENVIRONMENT_KEYS.VERSION]: packageJson.version,
|
|
[VITE_USER_DEFINED_ENVIRONMENT_KEYS.REPOSITORY_URL]: packageJson.repository.url,
|
|
[VITE_USER_DEFINED_ENVIRONMENT_KEYS.HOMEPAGE_URL]: packageJson.homepage,
|
|
[VITE_USER_DEFINED_ENVIRONMENT_KEYS.SLOGAN]: packageJson.slogan,
|
|
};
|
|
return Object.entries(environmentVariables).reduce((acc, [key, value]) => {
|
|
const formattedEnvVariableKey = `import.meta.env.${key}`;
|
|
const jsonEncodedEnvVariableValue = JSON.stringify(value);
|
|
return { ...acc, [formattedEnvVariableKey]: jsonEncodedEnvVariableValue };
|
|
}, {});
|
|
}
|
|
|
|
function getPathAliasesFromTsConfig(): ViteAliasDefinitions {
|
|
const { paths } = tsconfigJson.compilerOptions;
|
|
return Object.keys(paths).reduce((aliases, pathName: keyof typeof paths) => {
|
|
const pathFolder = paths[pathName][0];
|
|
const aliasFolder = pathFolder.substring(0, pathFolder.length - 1); // trim * from end
|
|
const aliasName = pathName.substring(0, pathName.length - 2); // trim /* from end
|
|
const aliasPath = resolve(getSelfDirectoryAbsolutePath(), aliasFolder);
|
|
aliases[aliasName] = aliasPath;
|
|
return aliases;
|
|
}, {} as ViteAliasDefinitions);
|
|
}
|
|
|
|
function getElectronProcessSpecificModuleAliases(): ViteAliasDefinitions {
|
|
// Workaround for Vite not being able to build tests with scoped Electron module imports.
|
|
const electronProcessScopedModuleAliases = [
|
|
'electron/main',
|
|
'electron/renderer',
|
|
'electron/common',
|
|
] as const;
|
|
return electronProcessScopedModuleAliases.reduce((aliases, alias) => {
|
|
aliases[alias] = 'electron';
|
|
return aliases;
|
|
}, {} as ViteAliasDefinitions);
|
|
}
|