@squide/firefly-rsbuild-storybook 1.0.4 → 2.0.0
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 +27 -0
- package/dist/initializeFireflyForStorybook.d.ts +3 -2
- package/dist/initializeFireflyForStorybook.js +1 -4
- package/dist/initializeFireflyForStorybook.js.map +1 -1
- package/dist/withFeatureFlagsOverrideDecorator.d.ts +2 -2
- package/dist/withFeatureFlagsOverrideDecorator.js +23 -19
- package/dist/withFeatureFlagsOverrideDecorator.js.map +1 -1
- package/package.json +27 -25
- package/src/initializeFireflyForStorybook.ts +4 -12
- package/src/withFeatureFlagsOverrideDecorator.tsx +22 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @squide/firefly-rsbuild-storybook
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#373](https://github.com/workleap/wl-squide/pull/373) [`f9138cc`](https://github.com/workleap/wl-squide/commit/f9138cc4bd0a1d175ad4bd7e695d1edd7fbe4c1c) Thanks [@alexasselin008](https://github.com/alexasselin008)! - - `withFeatureFlagsOverrideDecorator` now accept a single `overrides` argument. The feature flags are now retrieved directly from the runtime.
|
|
8
|
+
- Bumped dependencies.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [[`f9138cc`](https://github.com/workleap/wl-squide/commit/f9138cc4bd0a1d175ad4bd7e695d1edd7fbe4c1c), [`f9138cc`](https://github.com/workleap/wl-squide/commit/f9138cc4bd0a1d175ad4bd7e695d1edd7fbe4c1c)]:
|
|
13
|
+
- @squide/launch-darkly@1.0.5
|
|
14
|
+
- @squide/env-vars@1.4.14
|
|
15
|
+
- @squide/firefly@16.1.6
|
|
16
|
+
- @squide/msw@4.0.12
|
|
17
|
+
|
|
18
|
+
## 1.0.5
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- [#369](https://github.com/workleap/wl-squide/pull/369) [`a7fc49e`](https://github.com/workleap/wl-squide/commit/a7fc49ed2b111189cc310100482c1fcf37cfad58) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Bumped dependencies.
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`a7fc49e`](https://github.com/workleap/wl-squide/commit/a7fc49ed2b111189cc310100482c1fcf37cfad58)]:
|
|
25
|
+
- @squide/launch-darkly@1.0.4
|
|
26
|
+
- @squide/env-vars@1.4.13
|
|
27
|
+
- @squide/firefly@16.1.5
|
|
28
|
+
- @squide/msw@4.0.11
|
|
29
|
+
|
|
3
30
|
## 1.0.4
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { EnvironmentVariables } from "@squide/env-vars";
|
|
2
2
|
import { FireflyRuntime, ModuleRegisterFunction } from "@squide/firefly";
|
|
3
|
+
import { FeatureFlags } from "@squide/launch-darkly";
|
|
3
4
|
import { RootLogger } from "@workleap/logging";
|
|
4
|
-
import { LDClient
|
|
5
|
+
import { LDClient } from "launchdarkly-js-client-sdk";
|
|
5
6
|
import { StorybookRuntime } from "./StorybookRuntime.ts";
|
|
6
7
|
export interface InitializeFireflyForStorybookOptions {
|
|
7
8
|
localModules?: ModuleRegisterFunction<FireflyRuntime>[];
|
|
8
9
|
environmentVariables?: EnvironmentVariables;
|
|
9
|
-
featureFlags?:
|
|
10
|
+
featureFlags?: Partial<FeatureFlags>;
|
|
10
11
|
launchDarklyClient?: LDClient;
|
|
11
12
|
loggers?: RootLogger[];
|
|
12
13
|
}
|
|
@@ -48,10 +48,7 @@ async function initializeFireflyForStorybook(options = {}) {
|
|
|
48
48
|
(x)=>new EnvironmentVariablesPlugin(x, {
|
|
49
49
|
variables: environmentVariables
|
|
50
50
|
}),
|
|
51
|
-
(x)=>new LaunchDarklyPlugin(x,
|
|
52
|
-
// 2- If feature flags are provided and it's an instance of Map, use the argument.
|
|
53
|
-
// 3- If feature flags are provided (or the default value) and it's an object literal, convert the object to a Map instance.
|
|
54
|
-
launchDarklyClient ?? new InMemoryLaunchDarklyClient(featureFlags instanceof Map ? featureFlags : new Map(Object.entries(featureFlags))))
|
|
51
|
+
(x)=>new LaunchDarklyPlugin(x, launchDarklyClient ?? new InMemoryLaunchDarklyClient(featureFlags))
|
|
55
52
|
];
|
|
56
53
|
const runtime = new StorybookRuntime({
|
|
57
54
|
mode: "development",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializeFireflyForStorybook.js","sources":["../src/initializeFireflyForStorybook.ts"],"sourcesContent":["import { EnvironmentVariables, EnvironmentVariablesPlugin } from \"@squide/env-vars\";\nimport { FireflyRuntime, InMemoryLaunchDarklyClient, LaunchDarklyPlugin, ModuleRegisterFunction, PluginFactory, toLocalModuleDefinitions } from \"@squide/firefly\";\nimport { MswPlugin } from \"@squide/msw\";\nimport { RootLogger } from \"@workleap/logging\";\nimport { LDClient
|
|
1
|
+
{"version":3,"file":"initializeFireflyForStorybook.js","sources":["../src/initializeFireflyForStorybook.ts"],"sourcesContent":["import { EnvironmentVariables, EnvironmentVariablesPlugin } from \"@squide/env-vars\";\nimport { FireflyRuntime, InMemoryLaunchDarklyClient, LaunchDarklyPlugin, ModuleRegisterFunction, PluginFactory, toLocalModuleDefinitions } from \"@squide/firefly\";\nimport { FeatureFlags } from \"@squide/launch-darkly\";\nimport { MswPlugin } from \"@squide/msw\";\nimport { RootLogger } from \"@workleap/logging\";\nimport { LDClient } from \"launchdarkly-js-client-sdk\";\nimport { StorybookRuntime } from \"./StorybookRuntime.ts\";\n\nexport interface InitializeFireflyForStorybookOptions {\n localModules?: ModuleRegisterFunction<FireflyRuntime>[];\n environmentVariables?: EnvironmentVariables;\n featureFlags?: Partial<FeatureFlags>;\n launchDarklyClient?: LDClient;\n loggers?: RootLogger[];\n}\n\nfunction logInitializationState(\n runtime: FireflyRuntime,\n options: InitializeFireflyForStorybookOptions,\n plugins: PluginFactory<FireflyRuntime>[]\n) {\n const {\n localModules,\n environmentVariables,\n featureFlags,\n launchDarklyClient\n } = options;\n const scope = (runtime.logger as RootLogger).startScope(\"[squide] Initializing the application.\");\n\n try {\n scope.information(\"[squide] Mode: development\");\n\n if (localModules) {\n scope\n .withText(\"[squide] Local modules:\")\n .withObject(localModules)\n .information();\n }\n\n scope.information(\"[squide] Use MSW: Yes\");\n\n if (environmentVariables && Object.keys(environmentVariables).length > 0) {\n scope\n .withText(\"[squide] Environment variables:\")\n .withObject(environmentVariables)\n .information();\n }\n\n if (featureFlags) {\n scope\n .withText(\"[squide] Feature flags:\")\n .withObject(featureFlags)\n .information();\n }\n\n if (launchDarklyClient) {\n scope\n .withText(\"[squide] LaunchDarkly client:\")\n .withObject(launchDarklyClient)\n .information();\n }\n\n if (plugins.length > 0) {\n scope\n .withText(\"[squide] Plugins:\")\n .withObject(plugins)\n .information();\n }\n } finally {\n scope.end();\n }\n}\n\nexport async function initializeFireflyForStorybook(options: InitializeFireflyForStorybookOptions = {}) {\n const {\n localModules,\n environmentVariables,\n featureFlags = {},\n launchDarklyClient,\n loggers\n } = options;\n\n const plugins: PluginFactory<FireflyRuntime>[] = [\n x => new MswPlugin(x),\n x => new EnvironmentVariablesPlugin(x, {\n variables: environmentVariables\n }),\n x => new LaunchDarklyPlugin(x, launchDarklyClient ?? new InMemoryLaunchDarklyClient(featureFlags))\n ];\n\n const runtime = new StorybookRuntime({\n mode: \"development\",\n plugins,\n loggers\n });\n\n logInitializationState(runtime, options, plugins);\n\n if (localModules && localModules.length > 0) {\n await runtime.moduleManager.registerModules([\n ...toLocalModuleDefinitions(localModules)\n ]);\n }\n\n return runtime;\n}\n"],"names":["EnvironmentVariablesPlugin","InMemoryLaunchDarklyClient","LaunchDarklyPlugin","toLocalModuleDefinitions","MswPlugin","StorybookRuntime","logInitializationState","runtime","options","plugins","localModules","environmentVariables","featureFlags","launchDarklyClient","scope","Object","initializeFireflyForStorybook","loggers","x"],"mappings":";;;;;;;;;;;;;;AAAoF;AAC8E;AAE1H;AAGiB;AAUzD,SAASM,uBACLC,OAAuB,EACvBC,OAA6C,EAC7CC,OAAwC;IAExC,MAAM,EACFC,YAAY,EACZC,oBAAoB,EACpBC,YAAY,EACZC,kBAAkB,EACrB,GAAGL;IACJ,MAAMM,QAASP,QAAQ,MAAM,CAAgB,UAAU,CAAC;IAExD,IAAI;QACAO,MAAM,WAAW,CAAC;QAElB,IAAIJ,cAAc;YACdI,MACK,QAAQ,CAAC,2BACT,UAAU,CAACJ,cACX,WAAW;QACpB;QAEAI,MAAM,WAAW,CAAC;QAElB,IAAIH,wBAAwBI,OAAO,IAAI,CAACJ,sBAAsB,MAAM,GAAG,GAAG;YACtEG,MACK,QAAQ,CAAC,mCACT,UAAU,CAACH,sBACX,WAAW;QACpB;QAEA,IAAIC,cAAc;YACdE,MACK,QAAQ,CAAC,2BACT,UAAU,CAACF,cACX,WAAW;QACpB;QAEA,IAAIC,oBAAoB;YACpBC,MACK,QAAQ,CAAC,iCACT,UAAU,CAACD,oBACX,WAAW;QACpB;QAEA,IAAIJ,QAAQ,MAAM,GAAG,GAAG;YACpBK,MACK,QAAQ,CAAC,qBACT,UAAU,CAACL,SACX,WAAW;QACpB;IACJ,SAAU;QACNK,MAAM,GAAG;IACb;AACJ;AAEO,eAAeE,8BAA8BR,UAAgD,CAAC,CAAC;IAClG,MAAM,EACFE,YAAY,EACZC,oBAAoB,EACpBC,eAAe,CAAC,CAAC,EACjBC,kBAAkB,EAClBI,OAAO,EACV,GAAGT;IAEJ,MAAMC,UAA2C;QAC7CS,CAAAA,IAAK,IAAId,SAASA,CAACc;QACnBA,CAAAA,IAAK,IAAIlB,0BAA0BA,CAACkB,GAAG;gBACnC,WAAWP;YACf;QACAO,CAAAA,IAAK,IAAIhB,kBAAkBA,CAACgB,GAAGL,sBAAsB,IAAIZ,0BAA0BA,CAACW;KACvF;IAED,MAAML,UAAU,IAAIF,gBAAgBA,CAAC;QACjC,MAAM;QACNI;QACAQ;IACJ;IAEAX,uBAAuBC,SAASC,SAASC;IAEzC,IAAIC,gBAAgBA,aAAa,MAAM,GAAG,GAAG;QACzC,MAAMH,QAAQ,aAAa,CAAC,eAAe,CAAC;eACrCJ,wBAAwBA,CAACO;SAC/B;IACL;IAEA,OAAOH;AACX"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FeatureFlags } from "@squide/launch-darkly";
|
|
2
2
|
import { Decorator } from "storybook-react-rsbuild";
|
|
3
|
-
export declare function withFeatureFlagsOverrideDecorator
|
|
3
|
+
export declare function withFeatureFlagsOverrideDecorator(overrides: Partial<FeatureFlags>): Decorator;
|
|
@@ -1,41 +1,45 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { isEditableLaunchDarklyClient, useLaunchDarklyClient } from "@squide/launch-darkly";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
3
4
|
|
|
4
5
|
;// CONCATENATED MODULE: external "react/jsx-runtime"
|
|
5
6
|
|
|
7
|
+
;// CONCATENATED MODULE: external "@squide/launch-darkly"
|
|
8
|
+
|
|
6
9
|
;// CONCATENATED MODULE: external "react"
|
|
7
10
|
|
|
8
11
|
;// CONCATENATED MODULE: ./src/withFeatureFlagsOverrideDecorator.tsx
|
|
9
12
|
|
|
10
13
|
|
|
14
|
+
|
|
15
|
+
// Used to override the flags in a "useEffect" hook but then the unit test were not working.
|
|
16
|
+
// To fix the unit tests, the flags are now overrided directly in the render function.
|
|
11
17
|
function OverrideFeatureFlags(props) {
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
18
|
+
const { overrides, children } = props;
|
|
19
|
+
const transactionRef = useRef(undefined);
|
|
20
|
+
const client = useLaunchDarklyClient();
|
|
21
|
+
// eslint-disable-next-line react-hooks/refs
|
|
22
|
+
if (!transactionRef.current) {
|
|
23
|
+
if (!isEditableLaunchDarklyClient(client)) {
|
|
24
|
+
throw new Error("[squide] The withFeatureFlagsOverrideDecorator hook can only be used with an EditableLaunchDarklyClient instance.");
|
|
25
|
+
}
|
|
26
|
+
transactionRef.current = client.startTransaction();
|
|
27
|
+
client.setFeatureFlags(overrides);
|
|
28
|
+
}
|
|
29
|
+
useEffect(()=>{
|
|
20
30
|
return ()=>{
|
|
21
31
|
// Reset the feature flags to the original values.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
32
|
+
transactionRef.current?.undo();
|
|
33
|
+
transactionRef.current = undefined;
|
|
25
34
|
};
|
|
26
35
|
}, [
|
|
27
|
-
|
|
28
|
-
overrides
|
|
36
|
+
transactionRef
|
|
29
37
|
]);
|
|
30
38
|
return children;
|
|
31
39
|
}
|
|
32
|
-
function withFeatureFlagsOverrideDecorator(
|
|
33
|
-
if (!(featureFlags instanceof Map)) {
|
|
34
|
-
throw new TypeError("[squide] The \"featureFlags\" argument must be a Map instance.");
|
|
35
|
-
}
|
|
40
|
+
function withFeatureFlagsOverrideDecorator(overrides) {
|
|
36
41
|
return (story)=>{
|
|
37
42
|
return /*#__PURE__*/ jsx(OverrideFeatureFlags, {
|
|
38
|
-
featureFlags: featureFlags,
|
|
39
43
|
overrides: overrides,
|
|
40
44
|
children: story()
|
|
41
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withFeatureFlagsOverrideDecorator.js","sources":["../src/withFeatureFlagsOverrideDecorator.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"withFeatureFlagsOverrideDecorator.js","sources":["../src/withFeatureFlagsOverrideDecorator.tsx"],"sourcesContent":["import { FeatureFlags, isEditableLaunchDarklyClient, LaunchDarklyClientTransaction, useLaunchDarklyClient } from \"@squide/launch-darkly\";\nimport { PropsWithChildren, useEffect, useRef } from \"react\";\nimport { Decorator } from \"storybook-react-rsbuild\";\n\ninterface OverrideFeatureFlagsProps extends PropsWithChildren {\n overrides: Partial<FeatureFlags>;\n}\n\n// Used to override the flags in a \"useEffect\" hook but then the unit test were not working.\n// To fix the unit tests, the flags are now overrided directly in the render function.\nfunction OverrideFeatureFlags(props: OverrideFeatureFlagsProps) {\n const {\n overrides,\n children\n } = props;\n\n const transactionRef = useRef<LaunchDarklyClientTransaction | undefined>(undefined);\n const client = useLaunchDarklyClient();\n\n // eslint-disable-next-line react-hooks/refs\n if (!transactionRef.current) {\n if (!isEditableLaunchDarklyClient(client)) {\n throw new Error(\"[squide] The withFeatureFlagsOverrideDecorator hook can only be used with an EditableLaunchDarklyClient instance.\");\n }\n\n transactionRef.current = client.startTransaction();\n client.setFeatureFlags(overrides);\n }\n\n useEffect(() => {\n return () => {\n // Reset the feature flags to the original values.\n transactionRef.current?.undo();\n transactionRef.current = undefined;\n };\n }, [transactionRef]);\n\n return children;\n}\n\nexport function withFeatureFlagsOverrideDecorator(overrides: Partial<FeatureFlags>): Decorator {\n return story => {\n return (\n <OverrideFeatureFlags overrides={overrides}>\n {story()}\n </OverrideFeatureFlags>\n );\n };\n}\n"],"names":["isEditableLaunchDarklyClient","useLaunchDarklyClient","useEffect","useRef","OverrideFeatureFlags","props","overrides","children","transactionRef","undefined","client","Error","withFeatureFlagsOverrideDecorator","story"],"mappings":";;;;;;;;;;;;AAAyI;AAC5E;AAO7D,4FAA4F;AAC5F,sFAAsF;AACtF,SAASI,qBAAqBC,KAAgC;IAC1D,MAAM,EACFC,SAAS,EACTC,QAAQ,EACX,GAAGF;IAEJ,MAAMG,iBAAiBL,MAAMA,CAA4CM;IACzE,MAAMC,SAAST,qBAAqBA;IAEpC,4CAA4C;IAC5C,IAAI,CAACO,eAAe,OAAO,EAAE;QACzB,IAAI,CAACR,4BAA4BA,CAACU,SAAS;YACvC,MAAM,IAAIC,MAAM;QACpB;QAEAH,eAAe,OAAO,GAAGE,OAAO,gBAAgB;QAChDA,OAAO,eAAe,CAACJ;IAC3B;IAEAJ,SAASA,CAAC;QACN,OAAO;YACH,kDAAkD;YAClDM,eAAe,OAAO,EAAE;YACxBA,eAAe,OAAO,GAAGC;QAC7B;IACJ,GAAG;QAACD;KAAe;IAEnB,OAAOD;AACX;AAEO,SAASK,kCAAkCN,SAAgC;IAC9E,OAAOO,CAAAA;QACH,qBACI,IAACT;YAAqB,WAAWE;sBAC5BO;;IAGb;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squide/firefly-rsbuild-storybook",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "Squide firefly helpers for Storybook and Rsbuild.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
],
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@opentelemetry/api": "^1.9.0",
|
|
31
|
-
"@rsbuild/core": "^1.
|
|
32
|
-
"@tanstack/react-query": "^5.90.
|
|
31
|
+
"@rsbuild/core": "^1.7.2",
|
|
32
|
+
"@tanstack/react-query": "^5.90.20",
|
|
33
33
|
"launchdarkly-js-client-sdk": "^3.9.0",
|
|
34
|
-
"msw": "^2.12.
|
|
34
|
+
"msw": "^2.12.7",
|
|
35
35
|
"react": "^18.0.0 || ^19.0.0",
|
|
36
36
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
37
|
-
"react-router": "^7.
|
|
38
|
-
"storybook": "^10.
|
|
39
|
-
"storybook-react-rsbuild": "^3.
|
|
37
|
+
"react-router": "^7.13.0",
|
|
38
|
+
"storybook": "^10.2.0",
|
|
39
|
+
"storybook-react-rsbuild": "^3.2.2"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@opentelemetry/api": {
|
|
@@ -44,35 +44,37 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@workleap-telemetry/core": "^1.0.
|
|
48
|
-
"@workleap/logging": "^1.3.
|
|
49
|
-
"@squide/env-vars": "1.4.
|
|
50
|
-
"@squide/firefly": "16.1.
|
|
51
|
-
"@squide/launch-darkly": "1.0.
|
|
52
|
-
"@squide/msw": "4.0.
|
|
47
|
+
"@workleap-telemetry/core": "^1.0.7",
|
|
48
|
+
"@workleap/logging": "^1.3.4",
|
|
49
|
+
"@squide/env-vars": "1.4.14",
|
|
50
|
+
"@squide/firefly": "16.1.6",
|
|
51
|
+
"@squide/launch-darkly": "1.0.5",
|
|
52
|
+
"@squide/msw": "4.0.12"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@eslint/js": "9.39.
|
|
56
|
-
"@rsbuild/core": "1.
|
|
57
|
-
"@rslib/core": "0.
|
|
58
|
-
"@
|
|
55
|
+
"@eslint/js": "9.39.2",
|
|
56
|
+
"@rsbuild/core": "1.7.2",
|
|
57
|
+
"@rslib/core": "0.19.3",
|
|
58
|
+
"@testing-library/react": "16.3.2",
|
|
59
|
+
"@types/react": "19.2.9",
|
|
59
60
|
"@types/react-dom": "19.2.3",
|
|
60
|
-
"@typescript-eslint/parser": "8.
|
|
61
|
+
"@typescript-eslint/parser": "8.54.0",
|
|
62
|
+
"@typescript/native-preview": "7.0.0-dev.20260127.1",
|
|
61
63
|
"@vitejs/plugin-react": "5.1.2",
|
|
62
|
-
"@workleap/eslint-configs": "1.1.
|
|
63
|
-
"@workleap/rslib-configs": "1.1.
|
|
64
|
+
"@workleap/eslint-configs": "1.1.10",
|
|
65
|
+
"@workleap/rslib-configs": "1.1.5",
|
|
64
66
|
"@workleap/typescript-configs": "3.0.7",
|
|
65
|
-
"eslint": "9.39.
|
|
66
|
-
"happy-dom": "20.
|
|
67
|
+
"eslint": "9.39.2",
|
|
68
|
+
"happy-dom": "20.3.9",
|
|
67
69
|
"typescript": "5.9.3",
|
|
68
|
-
"typescript-eslint": "8.
|
|
69
|
-
"vitest": "4.0.
|
|
70
|
+
"typescript-eslint": "8.54.0",
|
|
71
|
+
"vitest": "4.0.18"
|
|
70
72
|
},
|
|
71
73
|
"sideEffects": false,
|
|
72
74
|
"scripts": {
|
|
73
75
|
"build": "rslib build --config ./rslib.build.ts",
|
|
74
76
|
"eslint": "eslint . --max-warnings=0 --cache --cache-location node_modules/.cache/eslint",
|
|
75
|
-
"typecheck": "
|
|
77
|
+
"typecheck": "tsgo",
|
|
76
78
|
"test": "vitest --config vitest.config.ts --no-watch"
|
|
77
79
|
}
|
|
78
80
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { EnvironmentVariables, EnvironmentVariablesPlugin } from "@squide/env-vars";
|
|
2
2
|
import { FireflyRuntime, InMemoryLaunchDarklyClient, LaunchDarklyPlugin, ModuleRegisterFunction, PluginFactory, toLocalModuleDefinitions } from "@squide/firefly";
|
|
3
|
+
import { FeatureFlags } from "@squide/launch-darkly";
|
|
3
4
|
import { MswPlugin } from "@squide/msw";
|
|
4
5
|
import { RootLogger } from "@workleap/logging";
|
|
5
|
-
import { LDClient
|
|
6
|
+
import { LDClient } from "launchdarkly-js-client-sdk";
|
|
6
7
|
import { StorybookRuntime } from "./StorybookRuntime.ts";
|
|
7
8
|
|
|
8
9
|
export interface InitializeFireflyForStorybookOptions {
|
|
9
10
|
localModules?: ModuleRegisterFunction<FireflyRuntime>[];
|
|
10
11
|
environmentVariables?: EnvironmentVariables;
|
|
11
|
-
featureFlags?:
|
|
12
|
+
featureFlags?: Partial<FeatureFlags>;
|
|
12
13
|
launchDarklyClient?: LDClient;
|
|
13
14
|
loggers?: RootLogger[];
|
|
14
15
|
}
|
|
@@ -84,16 +85,7 @@ export async function initializeFireflyForStorybook(options: InitializeFireflyFo
|
|
|
84
85
|
x => new EnvironmentVariablesPlugin(x, {
|
|
85
86
|
variables: environmentVariables
|
|
86
87
|
}),
|
|
87
|
-
x => new LaunchDarklyPlugin(
|
|
88
|
-
x,
|
|
89
|
-
// 1- If no client is provided create it.
|
|
90
|
-
// 2- If feature flags are provided and it's an instance of Map, use the argument.
|
|
91
|
-
// 3- If feature flags are provided (or the default value) and it's an object literal, convert the object to a Map instance.
|
|
92
|
-
launchDarklyClient ?? new InMemoryLaunchDarklyClient(featureFlags instanceof Map
|
|
93
|
-
? featureFlags
|
|
94
|
-
: new Map<string, LDFlagValue>(Object.entries(featureFlags))
|
|
95
|
-
)
|
|
96
|
-
)
|
|
88
|
+
x => new LaunchDarklyPlugin(x, launchDarklyClient ?? new InMemoryLaunchDarklyClient(featureFlags))
|
|
97
89
|
];
|
|
98
90
|
|
|
99
91
|
const runtime = new StorybookRuntime({
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PropsWithChildren,
|
|
1
|
+
import { FeatureFlags, isEditableLaunchDarklyClient, LaunchDarklyClientTransaction, useLaunchDarklyClient } from "@squide/launch-darkly";
|
|
2
|
+
import { PropsWithChildren, useEffect, useRef } from "react";
|
|
3
3
|
import { Decorator } from "storybook-react-rsbuild";
|
|
4
4
|
|
|
5
5
|
interface OverrideFeatureFlagsProps extends PropsWithChildren {
|
|
6
|
-
|
|
7
|
-
overrides: Record<string, LDFlagValue>;
|
|
6
|
+
overrides: Partial<FeatureFlags>;
|
|
8
7
|
}
|
|
9
8
|
|
|
9
|
+
// Used to override the flags in a "useEffect" hook but then the unit test were not working.
|
|
10
|
+
// To fix the unit tests, the flags are now overrided directly in the render function.
|
|
10
11
|
function OverrideFeatureFlags(props: OverrideFeatureFlagsProps) {
|
|
11
12
|
const {
|
|
12
|
-
featureFlags,
|
|
13
13
|
overrides,
|
|
14
14
|
children
|
|
15
15
|
} = props;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const originalValues: Record<string, LDFlagValue> = {};
|
|
17
|
+
const transactionRef = useRef<LaunchDarklyClientTransaction | undefined>(undefined);
|
|
18
|
+
const client = useLaunchDarklyClient();
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// eslint-disable-next-line react-hooks/refs
|
|
21
|
+
if (!transactionRef.current) {
|
|
22
|
+
if (!isEditableLaunchDarklyClient(client)) {
|
|
23
|
+
throw new Error("[squide] The withFeatureFlagsOverrideDecorator hook can only be used with an EditableLaunchDarklyClient instance.");
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
+
transactionRef.current = client.startTransaction();
|
|
27
|
+
client.setFeatureFlags(overrides);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
26
31
|
return () => {
|
|
27
32
|
// Reset the feature flags to the original values.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
33
|
+
transactionRef.current?.undo();
|
|
34
|
+
transactionRef.current = undefined;
|
|
31
35
|
};
|
|
32
|
-
}, [
|
|
36
|
+
}, [transactionRef]);
|
|
33
37
|
|
|
34
38
|
return children;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
export function withFeatureFlagsOverrideDecorator
|
|
38
|
-
if (!(featureFlags instanceof Map)) {
|
|
39
|
-
throw new TypeError("[squide] The \"featureFlags\" argument must be a Map instance.");
|
|
40
|
-
}
|
|
41
|
-
|
|
41
|
+
export function withFeatureFlagsOverrideDecorator(overrides: Partial<FeatureFlags>): Decorator {
|
|
42
42
|
return story => {
|
|
43
43
|
return (
|
|
44
|
-
<OverrideFeatureFlags
|
|
44
|
+
<OverrideFeatureFlags overrides={overrides}>
|
|
45
45
|
{story()}
|
|
46
46
|
</OverrideFeatureFlags>
|
|
47
47
|
);
|