Add types to compileTime modules

This commit is contained in:
Alex Gleason 2023-09-20 16:02:36 -05:00
parent 2a78515acd
commit 389ec700b8
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
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, '/')}`;
}; };
const env = {
NODE_ENV: NODE_ENV || 'development',
BACKEND_URL: sanitizeURL(BACKEND_URL),
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
FE_INSTANCE_SOURCE_DIR: FE_INSTANCE_SOURCE_DIR || 'instance',
SENTRY_DSN,
};
export type SoapboxEnv = typeof env;
export default () => ({ export default () => ({
data: { data: env,
NODE_ENV: NODE_ENV || 'development',
BACKEND_URL: sanitizeURL(BACKEND_URL),
FE_SUBDIRECTORY: sanitizeBasename(FE_SUBDIRECTORY),
FE_INSTANCE_SOURCE_DIR: FE_INSTANCE_SOURCE_DIR || 'instance',
SENTRY_DSN,
},
}); });

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

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');