Merge branch 'compiletime-types' into 'main'

Add types to compileTime modules

See merge request soapbox-pub/soapbox!2733
This commit is contained in:
Alex Gleason 2023-09-20 21:16:02 +00:00
commit 29db5b23cc
5 changed files with 30 additions and 29 deletions

View File

@ -28,12 +28,16 @@ const sanitizeBasename = (path: string | undefined = ''): string => {
return `/${trim(path, '/')}`; return `/${trim(path, '/')}`;
}; };
export default () => ({ const env = {
data: {
NODE_ENV: NODE_ENV || 'development', NODE_ENV: NODE_ENV || 'development',
BACKEND_URL: sanitizeURL(BACKEND_URL), BACKEND_URL: sanitizeURL(BACKEND_URL),
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY), FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
FE_INSTANCE_SOURCE_DIR: FE_INSTANCE_SOURCE_DIR || 'instance', FE_INSTANCE_SOURCE_DIR: FE_INSTANCE_SOURCE_DIR || 'instance',
SENTRY_DSN, SENTRY_DSN,
}, };
export type SoapboxEnv = typeof env;
export default () => ({
data: env,
}); });

View File

@ -1,16 +1,9 @@
// @ts-nocheck import type { SoapboxEnv } from './build-config-compiletime';
const {
NODE_ENV,
BACKEND_URL,
FE_SUBDIRECTORY,
FE_INSTANCE_SOURCE_DIR,
SENTRY_DSN,
} = import.meta.compileTime('./build-config-compiletime.ts');
export { export const {
NODE_ENV, NODE_ENV,
BACKEND_URL, BACKEND_URL,
FE_SUBDIRECTORY, FE_SUBDIRECTORY,
FE_INSTANCE_SOURCE_DIR, FE_INSTANCE_SOURCE_DIR,
SENTRY_DSN, SENTRY_DSN,
}; } = import.meta.compileTime<SoapboxEnv>('./build-config-compiletime.ts');

View File

@ -9,7 +9,7 @@ import type {
Status as StatusEntity, Status as StatusEntity,
} from 'soapbox/types/entities'; } from 'soapbox/types/entities';
const locales = import.meta.compileTime('./web-push-locales.ts'); const locales = import.meta.compileTime<Record<string, Record<string, string>>>('./web-push-locales.ts');
/** Limit before we start grouping device notifications into a single notification. */ /** Limit before we start grouping device notifications into a single notification. */
const MAX_NOTIFICATIONS = 5; const MAX_NOTIFICATIONS = 5;

View File

@ -35,8 +35,7 @@ const version = (pkg: Record<string, any>) => {
return pkg.version; return pkg.version;
}; };
export default () => ({ const code = {
data: {
name: pkg.name, name: pkg.name,
displayName: pkg.displayName, displayName: pkg.displayName,
url: pkg.repository.url, url: pkg.repository.url,
@ -44,5 +43,10 @@ export default () => ({
version: version(pkg), version: version(pkg),
homepage: pkg.homepage, homepage: pkg.homepage,
ref: CI_COMMIT_TAG || CI_COMMIT_SHA || tryGit('git rev-parse HEAD'), ref: CI_COMMIT_TAG || CI_COMMIT_SHA || tryGit('git rev-parse HEAD'),
}, };
export type Code = typeof code;
export default () => ({
data: code,
}); });

View File

@ -1,3 +1,3 @@
const data: any = import.meta.compileTime('./code-compiletime.ts'); import type { Code } from './code-compiletime';
export default data; export default import.meta.compileTime<Code>('./code-compiletime.ts');