UNPKG

@dr.pogodin/react-utils

Version:

Collection of generic ReactJS components and utils

44 lines (38 loc) 1.6 kB
// Encapsulates access to "Build Info" data. // BEWARE: This should match the type of build info object generated by // Webpack build (see "/config/webpack/app-base.js"), and currently this // match is not checked automatically. // Depending on the build mode & environment, BUILD_INFO is either a global // variable defined at the app launch, or it is replaced by the actual value // by the Webpack build. let buildInfo; // On the client side "BUILD_INFO" should be injected by Webpack. Note, however, // that in test environment we may need situations were environment is mocked as // client-side, although no proper Webpack compilation is executed, thus no info // injected; because of this we don't do a hard environment check here. if (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO; /** * In scenarious where "BUILD_INFO" is not injected by Webpack (server-side, * tests, etc.) we expect the host codebase to explicitly set it before it is * ever requested. As a precaution, this function throws if build info has been * set already, unless `force` flag is explicitly set. * @param info * @param force */ export function setBuildInfo(info, force = false) { if (buildInfo !== undefined && !force) { throw Error('"Build Info" is already initialized'); } buildInfo = info; } /** * Returns "Build Info" object; throws if it has not been initialized yet. * @returns */ export function getBuildInfo() { if (buildInfo === undefined) { throw Error('"Build Info" has not been initialized yet'); } return buildInfo; } //# sourceMappingURL=buildInfo.js.map