/* eslint-disable @typescript-eslint/naming-convention */
// eslint-disable-next-line spaced-comment
/// — provides types for import.meta.env
import { ExposedDependencies } from '@servicetitan/startup-utils';
import { ExposedInstanceDependencies } from './common';
declare global {
export const EXPOSED_DEPENDENCIES: ExposedDependencies | undefined;
export const EXPOSED_INSTANCE_DEPENDENCIES: ExposedInstanceDependencies | undefined;
export const WEB_COMPONENT_NAME: string | undefined;
}
/*
* Safely access a value that may not exist. Returns undefined instead of
* throwing a ReferenceError. Used below to try global constants first
* (set by webpack DefinePlugin), then fall back to import.meta.env
* (set by Vite's define config). One of these will always be defined
* depending on which bundler built the code.
*/
function get(fetch: () => T) {
try {
return fetch();
} catch {
return undefined;
}
}
const _EXPOSED_DEPENDENCIES =
get(() => {
return EXPOSED_DEPENDENCIES;
}) ??
get(() => {
return import.meta.env.EXPOSED_DEPENDENCIES;
});
const _WEB_COMPONENT_NAME =
get(() => {
return WEB_COMPONENT_NAME;
}) ??
get(() => {
return import.meta.env.WEB_COMPONENT_NAME;
});
const _EXPOSED_INSTANCE_DEPENDENCIES =
get(() => {
return EXPOSED_INSTANCE_DEPENDENCIES;
}) ??
get(() => {
return import.meta.env.EXPOSED_INSTANCE_DEPENDENCIES;
});
export {
_EXPOSED_DEPENDENCIES as EXPOSED_DEPENDENCIES,
_EXPOSED_INSTANCE_DEPENDENCIES as EXPOSED_INSTANCE_DEPENDENCIES,
_WEB_COMPONENT_NAME as WEB_COMPONENT_NAME,
};