Skip to content

Commit 5ca3622

Browse files
authored
feat(components): unify mode variable (#8091)
2 parents 7a2dc2d + 75add68 commit 5ca3622

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

packages/components/src/i18n.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ComponentKeys, ResourcePrefix } from './core/i18n';
22
import { getI18nInstance, initializeI18n } from './core/i18n';
3-
import { processEnv } from './schema';
3+
import { runtimeMode } from './schema';
44

55
type Options = {
66
count?: number;
@@ -14,6 +14,6 @@ export let translate = (key: TranslationKey, options?: Options) => {
1414
return i18n.translate(key, options);
1515
};
1616

17-
if (processEnv === 'test') {
17+
if (runtimeMode === 'test') {
1818
translate = (key): string => key;
1919
}

packages/components/src/schema/utils/prop.validators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const setState = <T>(component: Generic.Element.Component, propName: stri
110110
* Muss erstmal in sync bleiben, da sonst der
111111
* Tooltip nicht korrekt ausgerichtet wird.
112112
*/
113-
// if (component.hydrated === true || processEnv !== 'test') {
113+
// if (component.hydrated === true || runtimeMode !== 'test') {
114114
// clearTimeout(component.timeout as NodeJS.Timeout);
115115
// component.timeout = setTimeout(() => {
116116
// clearTimeout(component.timeout as NodeJS.Timeout);

packages/components/src/schema/utils/reuse.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const PROCESS_ENVS = ['development', 'production', 'test'] as const;
2-
type ProcessEnv = (typeof PROCESS_ENVS)[number];
3-
export let processEnv: ProcessEnv = 'development';
1+
const MODES = ['development', 'production', 'test'] as const;
2+
export type Mode = (typeof MODES)[number];
3+
4+
export let runtimeMode: Mode = 'development';
45
try {
5-
processEnv = process.env.NODE_ENV as ProcessEnv;
6+
runtimeMode = process.env.NODE_ENV as Mode;
67
} catch (e) {
7-
processEnv = 'production';
8+
runtimeMode = 'production';
89
}
910

1011
/**

packages/components/src/utils/align-floating-elements.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { arrow, computePosition, flip, offset, shift } from '@floating-ui/dom';
2-
import { processEnv } from '../schema';
2+
import { runtimeMode } from '../schema';
33

44
import type { AlignPropType } from '../schema';
55
type Arguments = {
@@ -9,7 +9,7 @@ type Arguments = {
99
align?: AlignPropType;
1010
};
1111
export const alignFloatingElements = async ({ floatingElement, referenceElement, arrowElement, align = 'top' }: Arguments) => {
12-
if (processEnv !== 'test') {
12+
if (runtimeMode !== 'test') {
1313
const middleware = [offset(arrowElement?.offsetHeight ?? 10), flip(), shift()];
1414
if (arrowElement) {
1515
middleware.push(arrow({ element: arrowElement }));

packages/components/src/utils/dev.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Email: kolibri@itzbund.de
6565

6666
let nonce = (): string => Math.floor(Math.random() * 16777215).toString(16);
6767

68-
if (processEnv === 'test') {
68+
if (runtimeMode === 'test') {
6969
nonce = (): string => 'nonce';
7070
}
7171

0 commit comments

Comments
 (0)