@scaleway/use-growthbook 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scaleway/use-growthbook
2
2
 
3
+ ## 2.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1943](https://github.com/scaleway/scaleway-lib/pull/1943) [`e726def`](https://github.com/scaleway/scaleway-lib/commit/e726def8e0cb4593f800f9acecca51b173ae907a) Thanks [@philibea](https://github.com/philibea)! - Migration from rollup to vite
8
+
3
9
  ## 2.0.2
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,12 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { Attributes, ErrorCallback, LoadConfig, ToolConfig, TrackingCallback } from './types';
3
+ type AbTestProviderProps = {
4
+ children: ReactNode;
5
+ config: ToolConfig;
6
+ trackingCallback: TrackingCallback;
7
+ errorCallback: ErrorCallback;
8
+ attributes: Attributes;
9
+ loadConfig?: LoadConfig;
10
+ };
11
+ export declare const AbTestProvider: ({ children, config, trackingCallback, errorCallback, attributes, loadConfig, }: AbTestProviderProps) => import("react").JSX.Element;
12
+ export {};
@@ -1,62 +1,50 @@
1
- import { GrowthBookProvider, GrowthBook } from '@growthbook/growthbook-react';
2
- import { useMemo, useCallback, useEffect } from 'react';
3
- import { jsx } from 'react/jsx-runtime';
4
-
5
- const defaultLoadConfig = {
6
- autoRefresh: false,
1
+ import { jsx as h } from "react/jsx-runtime";
2
+ import { GrowthBookProvider as m, GrowthBook as a } from "@growthbook/growthbook-react";
3
+ import { useMemo as w, useCallback as d, useEffect as i } from "react";
4
+ const p = {
5
+ autoRefresh: !1,
7
6
  timeout: 500,
8
- skipCache: false
9
- };
10
- const getGrowthBookInstance = ({
7
+ skipCache: !1
8
+ }, A = ({
11
9
  config: {
12
- apiHost,
13
- clientKey,
14
- enableDevMode,
15
- backgroundSync,
16
- subscribeToChanges
10
+ apiHost: c,
11
+ clientKey: t,
12
+ enableDevMode: r,
13
+ backgroundSync: e,
14
+ subscribeToChanges: s
17
15
  },
18
- trackingCallback
19
- }) => new GrowthBook({
20
- apiHost,
21
- clientKey,
22
- enableDevMode,
23
- trackingCallback,
24
- backgroundSync,
25
- subscribeToChanges
26
- });
27
- const AbTestProvider = ({
28
- children,
29
- config,
30
- trackingCallback,
31
- errorCallback,
32
- attributes,
33
- loadConfig
16
+ trackingCallback: u
17
+ }) => new a({
18
+ apiHost: c,
19
+ clientKey: t,
20
+ enableDevMode: r,
21
+ trackingCallback: u,
22
+ backgroundSync: e,
23
+ subscribeToChanges: s
24
+ }), x = ({
25
+ children: c,
26
+ config: t,
27
+ trackingCallback: r,
28
+ errorCallback: e,
29
+ attributes: s,
30
+ loadConfig: u
34
31
  }) => {
35
- const growthbook = useMemo(() => getGrowthBookInstance({
36
- config,
37
- trackingCallback
38
- }), [trackingCallback, config]);
39
- const loadFeature = useCallback(async () => {
40
- if (config.clientKey) {
41
- await growthbook.loadFeatures(loadConfig ?? defaultLoadConfig);
42
- }
43
- }, [growthbook, config, loadConfig]);
44
- useEffect(() => {
45
- loadFeature().catch(errorCallback);
46
- }, [loadFeature, errorCallback]);
47
- useEffect(() => {
48
- const currentAttributes = growthbook.getAttributes();
49
- if (currentAttributes !== attributes) {
50
- growthbook.setAttributes({
51
- ...currentAttributes,
52
- ...attributes
53
- }).catch(errorCallback);
54
- }
55
- }, [attributes, growthbook, errorCallback]);
56
- return jsx(GrowthBookProvider, {
57
- growthbook: growthbook,
58
- children: children
59
- });
32
+ const o = w(
33
+ () => A({ config: t, trackingCallback: r }),
34
+ [r, t]
35
+ ), n = d(async () => {
36
+ t.clientKey && await o.loadFeatures(u ?? p);
37
+ }, [o, t, u]);
38
+ return i(() => {
39
+ n().catch(e);
40
+ }, [n, e]), i(() => {
41
+ const f = o.getAttributes();
42
+ f !== s && o.setAttributes({
43
+ ...f,
44
+ ...s
45
+ }).catch(e);
46
+ }, [s, o, e]), /* @__PURE__ */ h(m, { growthbook: o, children: c });
47
+ };
48
+ export {
49
+ x as AbTestProvider
60
50
  };
61
-
62
- export { AbTestProvider };
package/dist/index.d.ts CHANGED
@@ -1,29 +1,5 @@
1
- import { Context, GrowthBook } from '@growthbook/growthbook-react';
2
- export { FeatureString, FeaturesReady, IfFeatureEnabled, useExperiment, useFeature, useFeatureIsOn, useFeatureValue, useGrowthBook, useGrowthBookSSR, withRunExperiment } from '@growthbook/growthbook-react';
3
- import * as react from 'react';
4
- import { ReactNode } from 'react';
5
-
6
- type Attributes = Record<string, string | number | undefined>;
7
- /**
8
- * @param {boolean} [autoRefresh] - false.
9
- * @param {number} [timeout] - 500.
10
- * @param {boolean} [skipCache] - false.
11
- */
12
- type LoadConfig = NonNullable<Parameters<GrowthBook['loadFeatures']>[0]>;
13
- type ToolConfig = Pick<Context, 'apiHost' | 'clientKey' | 'enableDevMode' | 'backgroundSync' | 'subscribeToChanges'>;
14
- type TrackingCallback = NonNullable<Context['trackingCallback']>;
15
- type ErrorCallback = (error: Error | string) => void | null;
16
-
17
- declare const useAbTestAttributes: () => [Attributes, (attributes: Attributes) => void];
18
-
19
- type AbTestProviderProps = {
20
- children: ReactNode;
21
- config: ToolConfig;
22
- trackingCallback: TrackingCallback;
23
- errorCallback: ErrorCallback;
24
- attributes: Attributes;
25
- loadConfig?: LoadConfig;
26
- };
27
- declare const AbTestProvider: ({ children, config, trackingCallback, errorCallback, attributes, loadConfig, }: AbTestProviderProps) => react.JSX.Element;
28
-
29
- export { AbTestProvider, type ErrorCallback, type ToolConfig, type TrackingCallback, useAbTestAttributes };
1
+ export { useExperiment, useFeature, withRunExperiment, useFeatureIsOn, useFeatureValue, useGrowthBook, useGrowthBookSSR, } from '@growthbook/growthbook-react';
2
+ export { FeatureString, FeaturesReady, IfFeatureEnabled, } from '@growthbook/growthbook-react';
3
+ export { useAbTestAttributes } from './useAbTestAttributes';
4
+ export { AbTestProvider } from './AbTestProvider';
5
+ export type { TrackingCallback, ErrorCallback, ToolConfig } from './types';
package/dist/index.js CHANGED
@@ -1,3 +1,17 @@
1
- export { FeatureString, FeaturesReady, IfFeatureEnabled, useExperiment, useFeature, useFeatureIsOn, useFeatureValue, useGrowthBook, useGrowthBookSSR, withRunExperiment } from '@growthbook/growthbook-react';
2
- export { useAbTestAttributes } from './useAbTestAttributes.js';
3
- export { AbTestProvider } from './AbTestProvider.js';
1
+ import { FeatureString as t, FeaturesReady as u, IfFeatureEnabled as o, useExperiment as s, useFeature as a, useFeatureIsOn as i, useFeatureValue as n, useGrowthBook as F, useGrowthBookSSR as m, withRunExperiment as p } from "@growthbook/growthbook-react";
2
+ import { useAbTestAttributes as b } from "./useAbTestAttributes.js";
3
+ import { AbTestProvider as d } from "./AbTestProvider.js";
4
+ export {
5
+ d as AbTestProvider,
6
+ t as FeatureString,
7
+ u as FeaturesReady,
8
+ o as IfFeatureEnabled,
9
+ b as useAbTestAttributes,
10
+ s as useExperiment,
11
+ a as useFeature,
12
+ i as useFeatureIsOn,
13
+ n as useFeatureValue,
14
+ F as useGrowthBook,
15
+ m as useGrowthBookSSR,
16
+ p as withRunExperiment
17
+ };
@@ -0,0 +1,11 @@
1
+ import type { Context, GrowthBook } from '@growthbook/growthbook-react';
2
+ export type Attributes = Record<string, string | number | undefined>;
3
+ /**
4
+ * @param {boolean} [autoRefresh] - false.
5
+ * @param {number} [timeout] - 500.
6
+ * @param {boolean} [skipCache] - false.
7
+ */
8
+ export type LoadConfig = NonNullable<Parameters<GrowthBook['loadFeatures']>[0]>;
9
+ export type ToolConfig = Pick<Context, 'apiHost' | 'clientKey' | 'enableDevMode' | 'backgroundSync' | 'subscribeToChanges'>;
10
+ export type TrackingCallback = NonNullable<Context['trackingCallback']>;
11
+ export type ErrorCallback = (error: Error | string) => void | null;
@@ -0,0 +1,5 @@
1
+ import type { Attributes } from './types';
2
+ export declare const useAbTestAttributes: () => [
3
+ Attributes,
4
+ (attributes: Attributes) => void
5
+ ];
@@ -1,16 +1,16 @@
1
- import { useGrowthBook } from '@growthbook/growthbook-react';
2
-
3
- const useAbTestAttributes = () => {
4
- const growthBook = useGrowthBook();
5
- if (growthBook) {
6
- const attributes = growthBook.getAttributes();
7
- const setAttributes = newAttributes => growthBook.setAttributes({
8
- ...attributes,
9
- ...newAttributes
10
- });
11
- return [attributes, setAttributes];
1
+ import { useGrowthBook as r } from "@growthbook/growthbook-react";
2
+ const i = () => {
3
+ const t = r();
4
+ if (t) {
5
+ const e = t.getAttributes();
6
+ return [e, (s) => t.setAttributes({
7
+ ...e,
8
+ ...s
9
+ })];
12
10
  }
13
- return [{}, () => {}];
11
+ return [{}, () => {
12
+ }];
13
+ };
14
+ export {
15
+ i as useAbTestAttributes
14
16
  };
15
-
16
- export { useAbTestAttributes };
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@scaleway/use-growthbook",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Utility package to expose AB test tool",
5
- "type": "module",
6
5
  "engines": {
7
6
  "node": ">=20.x"
8
7
  },
8
+ "sideEffects": false,
9
+ "type": "module",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
9
12
  "exports": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
12
17
  },
13
- "sideEffects": false,
14
18
  "publishConfig": {
15
19
  "access": "public"
16
20
  },
@@ -32,5 +36,12 @@
32
36
  },
33
37
  "peerDependencies": {
34
38
  "react": "18.x"
39
+ },
40
+ "scripts": {
41
+ "typecheck": "tsc --noEmit",
42
+ "type:generate": "tsc --declaration -p tsconfig.build.json",
43
+ "build": "vite build --config vite.config.ts && pnpm run type:generate",
44
+ "build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
45
+ "lint": "eslint --report-unused-disable-directives --cache --cache-strategy content --ext ts,tsx ."
35
46
  }
36
47
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "emitDeclarationOnly": true,
6
+ "rootDir": "src",
7
+ "outDir": "dist"
8
+ },
9
+ "exclude": [
10
+ "*.config.ts",
11
+ "*.setup.ts",
12
+ "**/__tests__",
13
+ "**/__mocks__",
14
+ "src/**/*.test.tsx"
15
+ ]
16
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["src/**/*.ts", "src/**/*.tsx", "*.config.ts"]
4
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,6 @@
1
+ /* eslint-disable eslint-comments/disable-enable-pair */
2
+ /* eslint-disable import/no-relative-packages */
3
+ import { defineConfig, mergeConfig } from 'vite'
4
+ import { defaultConfig } from '../../vite.config'
5
+
6
+ export default mergeConfig(defineConfig(defaultConfig), {})