@squide/firefly-rsbuild-storybook 0.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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @squide/firefly-rsbuild-storybook
2
+
3
+ ## Usage
4
+
5
+ View the [user's documentation](https://workleap.github.io/wl-squide/).
6
+
7
+ ## 🤝 Contributing
8
+
9
+ View the [contributor's documentation](../../CONTRIBUTING.md).
10
+
11
+ ## License
12
+
13
+ Copyright © 2024, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/workleap/workleap-license/blob/master/LICENSE.
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@squide/firefly-rsbuild-storybook",
3
+ "author": "Workleap",
4
+ "version": "0.0.0",
5
+ "description": "Squide firefly helpers for Storybook and Rsbuild.",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/workleap/wl-squide.git",
10
+ "directory": "packages/firefly-rsbuild-storybook"
11
+ },
12
+ "type": "module",
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "provenance": true,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "default": "./dist/index.js"
21
+ }
22
+ }
23
+ },
24
+ "exports": "./src/index.ts",
25
+ "files": [
26
+ "src",
27
+ "dist",
28
+ "CHANGELOG.md"
29
+ ],
30
+ "scripts": {
31
+ "build": "rslib build --config ./rslib.build.ts",
32
+ "eslint": "eslint . --max-warnings=0 --cache --cache-location node_modules/.cache/eslint",
33
+ "typecheck": "tsc"
34
+ },
35
+ "peerDependencies": {
36
+ "@opentelemetry/api": "^1.9.0",
37
+ "@rsbuild/core": "^1.6.9",
38
+ "@tanstack/react-query": "^5.90.11",
39
+ "msw": "^2.12.3",
40
+ "react": "^18.0.0 || ^19.0.0",
41
+ "react-dom": "^18.0.0 || ^19.0.0",
42
+ "react-router": "^7.9.6",
43
+ "storybook": "^10.1.0",
44
+ "storybook-react-rsbuild": "^3.0.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "@opentelemetry/api": {
48
+ "optional": true
49
+ }
50
+ },
51
+ "dependencies": {
52
+ "@squide/env-vars": "workspace:*",
53
+ "@squide/firefly": "workspace:*",
54
+ "@squide/msw": "workspace:*",
55
+ "@workleap-telemetry/core": "^1.0.4",
56
+ "@workleap/logging": "^1.3.2"
57
+ },
58
+ "devDependencies": {
59
+ "@eslint/js": "9.39.1",
60
+ "@rsbuild/core": "1.6.9",
61
+ "@rslib/core": "0.18.2",
62
+ "@types/react": "19.2.7",
63
+ "@types/react-dom": "19.2.3",
64
+ "@typescript-eslint/parser": "8.48.0",
65
+ "@workleap/eslint-configs": "1.1.5",
66
+ "@workleap/rslib-configs": "1.1.3",
67
+ "@workleap/typescript-configs": "3.0.7",
68
+ "eslint": "9.39.1",
69
+ "typescript": "5.9.3",
70
+ "typescript-eslint": "8.48.0"
71
+ },
72
+ "sideEffects": false
73
+ }
@@ -0,0 +1,31 @@
1
+ import { FireflyRuntime, FireflyRuntimeOptions, FireflyRuntimeScope } from "@squide/firefly";
2
+ import { HoneycombInstrumentationPartialClient } from "@workleap-telemetry/core";
3
+ import { Logger } from "@workleap/logging";
4
+
5
+ export class StorybookRuntime extends FireflyRuntime {
6
+ constructor(options: FireflyRuntimeOptions = {}) {
7
+ const {
8
+ honeycombInstrumentationClient
9
+ } = options;
10
+
11
+ if (honeycombInstrumentationClient) {
12
+ throw new Error("[squide] A StorybookRuntime instance should not receive an Honeycomb client.");
13
+ }
14
+
15
+ super(options);
16
+ }
17
+
18
+ registerRoute() {
19
+ // Ignore routes registration because it doesn't matter for a Storybook host application.
20
+ }
21
+
22
+ get honeycombInstrumentationClient(): HoneycombInstrumentationPartialClient {
23
+ throw new Error("[squide] Cannot retrieve the Honeycomb instrumentation client from a StorybookRuntime instance.");
24
+ }
25
+
26
+ startScope(logger: Logger) {
27
+ return (new StorybookRuntimeScope(this, logger) as unknown) as StorybookRuntime;
28
+ }
29
+ }
30
+
31
+ export class StorybookRuntimeScope extends FireflyRuntimeScope { }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { initializeFireflyForStorybook, type InitializeFireflyForStorybookOptions } from "./initializeFireflyForStorybook.ts";
2
+ export { StorybookRuntime, StorybookRuntimeScope } from "./StorybookRuntime.ts";
3
+ export { FireflyDecorator, withFireflyDecorator, type FireflyDecoratorProps } from "./withFireflyDecorator.tsx";
4
+
@@ -0,0 +1,32 @@
1
+ import { EnvironmentVariables, EnvironmentVariablesPlugin } from "@squide/env-vars";
2
+ import { FireflyRuntime, ModuleRegisterFunction, toLocalModuleDefinitions } from "@squide/firefly";
3
+ import { MswPlugin } from "@squide/msw";
4
+ import { StorybookRuntime } from "./StorybookRuntime.ts";
5
+
6
+ export interface InitializeFireflyForStorybookOptions {
7
+ localModules?: ModuleRegisterFunction<FireflyRuntime>[];
8
+ environmentVariables?: EnvironmentVariables;
9
+ }
10
+
11
+ export async function initializeFireflyForStorybook(options: InitializeFireflyForStorybookOptions = {}) {
12
+ const {
13
+ localModules = [],
14
+ environmentVariables = {}
15
+ } = options;
16
+
17
+ const runtime = new StorybookRuntime({
18
+ mode: "development",
19
+ plugins: [
20
+ x => new MswPlugin(x),
21
+ x => new EnvironmentVariablesPlugin(x, {
22
+ variables: environmentVariables
23
+ })
24
+ ]
25
+ });
26
+
27
+ await runtime.moduleManager.registerModules([
28
+ ...toLocalModuleDefinitions(localModules)
29
+ ]);
30
+
31
+ return runtime;
32
+ }
@@ -0,0 +1,53 @@
1
+ import { AppRouter, FireflyProvider, FireflyRuntime } from "@squide/firefly";
2
+ import type { PropsWithChildren } from "react";
3
+ import { createMemoryRouter } from "react-router";
4
+ import { RouterProvider } from "react-router/dom";
5
+ import { Decorator } from "storybook-react-rsbuild";
6
+
7
+ export function withFireflyDecorator(runtime: FireflyRuntime): Decorator {
8
+ return story => {
9
+ return (
10
+ <FireflyDecorator runtime={runtime}>
11
+ {story()}
12
+ </FireflyDecorator>
13
+ );
14
+ };
15
+ }
16
+
17
+ export interface FireflyDecoratorProps extends PropsWithChildren {
18
+ runtime: FireflyRuntime;
19
+ }
20
+
21
+ export function FireflyDecorator(props: FireflyDecoratorProps) {
22
+ const {
23
+ runtime,
24
+ children: story
25
+ } = props;
26
+
27
+ return (
28
+ <FireflyProvider runtime={runtime}>
29
+ <AppRouter strictMode={false}>
30
+ {({ rootRoute, routerProviderProps }) => {
31
+ return (
32
+ <RouterProvider
33
+ router={createMemoryRouter([
34
+ {
35
+ element: rootRoute,
36
+ children: [
37
+ {
38
+ path: "/story",
39
+ element: story
40
+ }
41
+ ]
42
+ }
43
+ ], {
44
+ initialEntries: ["/story"]
45
+ })}
46
+ {...routerProviderProps}
47
+ />
48
+ );
49
+ }}
50
+ </AppRouter>
51
+ </FireflyProvider>
52
+ );
53
+ }