storybook-framework-cedarjs 4.2.0 → 4.2.1-next.258

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.
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../src/mocks/MockProviders.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAA;AAsBzB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAWA,CAAA"}
1
+ {"version":3,"file":"MockProviders.d.ts","sourceRoot":"","sources":["../../src/mocks/MockProviders.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAA;AA2BzB,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAWA,CAAA"}
@@ -4,13 +4,7 @@ import { useAuth } from "@cedarjs/testing/auth";
4
4
  import { RedwoodProvider } from "@cedarjs/web";
5
5
  import { RedwoodApolloProvider } from "@cedarjs/web/apollo";
6
6
  import { MockParamsProvider } from "./MockParamsProvider.js";
7
- let UserRoutes;
8
- try {
9
- const userRoutesModule = require("~__REDWOOD__USER_ROUTES_FOR_MOCK");
10
- UserRoutes = userRoutesModule.default;
11
- } catch {
12
- UserRoutes = () => /* @__PURE__ */ React.createElement(React.Fragment, null);
13
- }
7
+ import UserRoutes from "~__CEDAR__USER_ROUTES_FOR_MOCK";
14
8
  const MockProviders = ({ children }) => {
15
9
  return /* @__PURE__ */ React.createElement(RedwoodProvider, { titleTemplate: "%PageTitle | %AppTitle" }, /* @__PURE__ */ React.createElement(RedwoodApolloProvider, { useAuth }, /* @__PURE__ */ React.createElement(UserRoutes, null), /* @__PURE__ */ React.createElement(LocationProvider, null, /* @__PURE__ */ React.createElement(MockParamsProvider, null, children))));
16
10
  };
@@ -6,7 +6,7 @@ import {
6
6
  } from "@cedarjs/testing/web";
7
7
  import { MockProviders } from "./MockProviders.js";
8
8
  const MockingLoader = async () => {
9
- import.meta.glob("~__REDWOOD__USER_WEB_SRC/**/*.+(mock).(js|ts)", {
9
+ import.meta.glob("~__CEDAR__USER_WEB_SRC/**/*.+(mock).(js|ts)", {
10
10
  eager: true
11
11
  });
12
12
  await startMSW("browsers");
@@ -1 +1 @@
1
- {"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAUtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAWjD,eAAO,MAAM,IAAI,EAAE,cAAc,CAAC,MAAM,CAGvC,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,oBAAoB,CAKpE,CAAA;AAID,eAAO,MAAM,SAAS,EAAE,eAAe,CAAC,WAAW,CA6BlD,CAAA"}
1
+ {"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAWtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAWjD,eAAO,MAAM,IAAI,EAAE,cAAc,CAAC,MAAM,CAGvC,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,oBAAoB,CAKpE,CAAA;AAID,eAAO,MAAM,SAAS,EAAE,eAAe,CAAC,WAAW,CAoLlD,CAAA"}
package/dist/preset.js CHANGED
@@ -1,3 +1,4 @@
1
+ import fs from "node:fs";
1
2
  import { createRequire } from "node:module";
2
3
  import path from "node:path";
3
4
  import { mergeConfig } from "vite";
@@ -25,31 +26,163 @@ const previewAnnotations = (entries = []) => {
25
26
  };
26
27
  const cedarProjectPaths = getPaths();
27
28
  const viteFinal = async (config) => {
28
- const { plugins = [] } = config;
29
+ const plugins = (config.plugins ?? []).filter(
30
+ (p) => !p || Array.isArray(p) || p.name !== "cedar-entry-injection"
31
+ );
29
32
  plugins.unshift(await reactDocgen());
30
33
  plugins.unshift(nodePolyfills());
31
- return mergeConfig(config, {
32
- // This is necessary as it otherwise just points to the `web` directory,
33
- // but it needs to point to `web/src`
34
- root: cedarProjectPaths.web.src,
35
- plugins: [mockRouter(), mockAuth(), autoImports],
36
- resolve: {
37
- alias: {
38
- "~__REDWOOD__USER_ROUTES_FOR_MOCK": cedarProjectPaths.web.routes,
39
- "~__REDWOOD__USER_WEB_SRC": cedarProjectPaths.web.src
34
+ return mergeConfig(
35
+ { ...config, plugins },
36
+ {
37
+ plugins: [mockRouter(), mockAuth(), autoImports],
38
+ resolve: {
39
+ alias: {
40
+ "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarProjectPaths.web.routes,
41
+ "~__CEDAR__USER_WEB_SRC": cedarProjectPaths.web.src,
42
+ // @cedarjs/web imports @apollo/client via explicit .cjs sub-paths
43
+ // (e.g. `@apollo/client/cache/cache.cjs`). In a Node.js / tsc build
44
+ // context these resolve fine, but Vite (ESM-first, browser target)
45
+ // falls back to a ?import CJS interop that can't statically detect
46
+ // named exports, causing runtime SyntaxErrors. Alias the .cjs paths
47
+ // to their package-root equivalents so Vite resolves them through
48
+ // Apollo's package.json `exports` field and picks up the ESM build.
49
+ "@apollo/client/cache/cache.cjs": "@apollo/client/cache",
50
+ "@apollo/client/core/core.cjs": "@apollo/client/core",
51
+ "@apollo/client/link/context/context.cjs": "@apollo/client/link/context",
52
+ "@apollo/client/link/core/core.cjs": "@apollo/client/link/core",
53
+ "@apollo/client/link/persisted-queries/persisted-queries.cjs": "@apollo/client/link/persisted-queries",
54
+ "@apollo/client/react/hooks/hooks.cjs": "@apollo/client/react/hooks",
55
+ "@apollo/client/react/react.cjs": "@apollo/client/react",
56
+ "@apollo/client/utilities/utilities.cjs": "@apollo/client/utilities",
57
+ // graphql ships CJS-only; alias the explicit sub-path to the package
58
+ // root so Vite resolves it through the exports field (ESM build).
59
+ "graphql/language/printer.js": "graphql"
60
+ }
61
+ },
62
+ optimizeDeps: {
63
+ // Without this, on first run, Vite throws: `The file does not exist at
64
+ // "{project path}/web/node_modules/.cache/sb-vite/deps/DocsRenderer-NNNQARDV-DEXCJJZJ.js?v=c640a8fa"
65
+ // which is in the optimize deps directory.`
66
+ // This refers to @storybook/addon-docs, which is included as part of @storybook/addon-essentials.
67
+ // the docs addon then includes itself here: https://github.com/storybookjs/storybook/blob/a496ec48c708eed753a5251d55fa07947a869e62/code/addons/docs/src/preset.ts#L198C3-L198C27
68
+ // which I believe gets included by the builder here: https://github.com/storybookjs/storybook/blob/a496ec48c708eed753a5251d55fa07947a869e62/code/builders/builder-vite/src/optimizeDeps.ts#L117
69
+ // TODO: Figure out why this error is being thrown so that this can be removed.
70
+ //
71
+ // Exclude storybook-framework-cedarjs from pre-bundling. Its
72
+ // MockProviders module has a static import of the
73
+ // ~__CEDAR__USER_ROUTES_FOR_MOCK alias, which esbuild would try to
74
+ // resolve during pre-bundling. That leads esbuild into user Cell files
75
+ // which have no default export (Cedar's Cell transform doesn't run
76
+ // during esbuild dep scan), causing pre-bundling to fail entirely.
77
+ // When excluded, Vite serves the package directly through its normal
78
+ // transform pipeline, which does run the Cell plugin correctly.
79
+ exclude: ["@storybook/addon-docs", "storybook-framework-cedarjs"],
80
+ // Force pre-bundling of CJS-only packages that are only reachable through
81
+ // storybook-framework-cedarjs (excluded above). Without this, Vite serves
82
+ // them via ?import interop, which can't detect named exports in CJS files.
83
+ //
84
+ // Also pre-bundle the Apollo .cjs sub-paths that @cedarjs/web imports.
85
+ // resolve.alias redirects them in the transform pipeline, but esbuild
86
+ // (dep optimizer) ignores resolve.alias. Without this, Vite discovers
87
+ // them on the first page load and triggers a mid-session reload, which
88
+ // tears down the StorybookProvider's GraphQLHooksProvider context and
89
+ // breaks nested-Cell stories. These are structural deps of @cedarjs/web
90
+ // itself, so this list is valid for all Cedar apps, not just the test
91
+ // project.
92
+ include: [
93
+ "rehackt",
94
+ "@apollo/client/cache/cache.cjs",
95
+ "@apollo/client/core/core.cjs",
96
+ "@apollo/client/link/context/context.cjs",
97
+ "@apollo/client/link/core/core.cjs",
98
+ "@apollo/client/link/persisted-queries/persisted-queries.cjs",
99
+ "@apollo/client/react/hooks/hooks.cjs",
100
+ "@apollo/client/react/react.cjs",
101
+ "@apollo/client/utilities/utilities.cjs",
102
+ "graphql/language/printer.js",
103
+ // Pre-bundle node-polyfill shims so Vite doesn't discover them
104
+ // mid-session when storybook-framework-cedarjs (which uses
105
+ // nodePolyfills()) is first rendered. Without this, each shim
106
+ // triggers a separate optimized-deps reload that tears down
107
+ // GraphQLHooksProvider and breaks nested-Cell stories.
108
+ "vite-plugin-node-polyfills/shims/buffer",
109
+ "vite-plugin-node-polyfills/shims/global",
110
+ "vite-plugin-node-polyfills/shims/process",
111
+ // Pre-bundle @cedarjs/testing and graphql-tag so they don't cause
112
+ // mid-session reloads when StorybookProvider loads mock files.
113
+ "@cedarjs/testing/web",
114
+ // Sub-path explicitly imported by @cedarjs/router mock infrastructure
115
+ "@cedarjs/testing/web/MockRouter.js",
116
+ "@cedarjs/testing/auth",
117
+ "graphql-tag",
118
+ // Pre-bundle @cedarjs/web so there is only one instance of
119
+ // GraphQLHooksProvider. Without this, the pre-bundled dep graph and
120
+ // the Vite transform pipeline can each produce their own copy of
121
+ // the module, so RedwoodApolloProvider sets context in one copy
122
+ // while NamedCell reads from the other, causing the
123
+ // "You must register a useQuery hook via the GraphQLHooksProvider"
124
+ // error when a Cell is nested inside another story.
125
+ "@cedarjs/web",
126
+ "@cedarjs/web/apollo"
127
+ ],
128
+ esbuildOptions: {
129
+ plugins: [
130
+ {
131
+ // Cedar's Cell transform (a Vite plugin) injects `export default
132
+ // createCell(...)` at transform time, which doesn't run during
133
+ // esbuild's dep scan. Without a default export, esbuild crashes
134
+ // the scan with "No matching export ... for import 'default'",
135
+ // causing Vite to skip pre-bundling entirely.
136
+ //
137
+ // We must NOT return the real Cell file contents here. If esbuild
138
+ // follows the Cell's imports (e.g. createCell from @cedarjs/web),
139
+ // it pulls GraphQLHooksProvider into its own pre-bundled chunk
140
+ // separately from the @cedarjs/web chunk. That produces two
141
+ // distinct GraphQLHooksContext instances, so the context set by
142
+ // RedwoodApolloProvider is invisible to the Cell's useQuery,
143
+ // causing "You must register a useQuery hook via the
144
+ // GraphQLHooksProvider".
145
+ //
146
+ // Instead we synthesize a stub module: we scan the source for
147
+ // exported names and re-export them as empty stubs, plus add a
148
+ // default export. esbuild treats the Cell as a leaf (no real
149
+ // imports to follow), keeping @cedarjs/web in a single chunk.
150
+ // The real Cell transform runs later via Vite's normal pipeline.
151
+ name: "cedar-cell-stub",
152
+ setup(build) {
153
+ build.onLoad({ filter: /Cell\.[jt]sx?$/ }, async (args) => {
154
+ if (args.path.includes("node_modules")) {
155
+ return void 0;
156
+ }
157
+ const src = await fs.promises.readFile(args.path, "utf-8");
158
+ const exportedNames = /* @__PURE__ */ new Set();
159
+ for (const m of src.matchAll(
160
+ /^export\s+(?:const|let|var|function|class)\s+(\w+)/gm
161
+ )) {
162
+ exportedNames.add(m[1]);
163
+ }
164
+ for (const m of src.matchAll(/^export\s*\{([^}]+)\}/gm)) {
165
+ for (const part of m[1].split(",")) {
166
+ const name = (part.split(/\bas\b/).pop() ?? "").trim();
167
+ if (name) {
168
+ exportedNames.add(name);
169
+ }
170
+ }
171
+ }
172
+ const namedStubs = [...exportedNames].filter((n) => n !== "default").map((n) => `export const ${n} = undefined`).join("\n");
173
+ return {
174
+ contents: `${namedStubs}
175
+ export default {}`,
176
+ loader: "js"
177
+ };
178
+ });
179
+ }
180
+ }
181
+ ]
182
+ }
40
183
  }
41
- },
42
- optimizeDeps: {
43
- // Without this, on first run, Vite throws: `The file does not exist at
44
- // "{project path}/web/node_modules/.cache/sb-vite/deps/DocsRenderer-NNNQARDV-DEXCJJZJ.js?v=c640a8fa"
45
- // which is in the optimize deps directory.`
46
- // This refers to @storybook/addon-docs, which is included as part of @storybook/addon-essentials.
47
- // the docs addon then includes itself here: https://github.com/storybookjs/storybook/blob/a496ec48c708eed753a5251d55fa07947a869e62/code/addons/docs/src/preset.ts#L198C3-L198C27
48
- // which I believe gets included by the builder here: https://github.com/storybookjs/storybook/blob/a496ec48c708eed753a5251d55fa07947a869e62/code/builders/builder-vite/src/optimizeDeps.ts#L117
49
- // TODO: Figure out why this error is being thrown so that this can be removed.
50
- exclude: ["@storybook/addon-docs"]
51
184
  }
52
- });
185
+ );
53
186
  };
54
187
  export {
55
188
  core,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-framework-cedarjs",
3
- "version": "4.2.0",
3
+ "version": "4.2.1-next.258",
4
4
  "description": "Storybook for CedarJS",
5
5
  "keywords": [
6
6
  "Storybook",
@@ -50,11 +50,11 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@cedarjs/testing": "4.2.0",
53
- "@rollup/pluginutils": "5.3.0",
53
+ "@rollup/pluginutils": "5.4.0",
54
54
  "@storybook/addon-essentials": "8.6.14",
55
55
  "@storybook/builder-vite": "8.6.18",
56
56
  "@storybook/react": "8.6.18",
57
- "empathic": "2.0.0",
57
+ "empathic": "2.0.1",
58
58
  "magic-string": "0.30.21",
59
59
  "react-docgen": "7.1.1",
60
60
  "tsconfig-paths": "^3.15.0",
@@ -64,10 +64,10 @@
64
64
  "devDependencies": {
65
65
  "@storybook/types": "8.6.14",
66
66
  "@types/node": "24.10.4",
67
- "tsx": "4.21.0",
67
+ "tsx": "4.22.4",
68
68
  "typescript": "5.9.3",
69
- "vite": "7.3.2",
70
- "vitest": "3.2.4"
69
+ "vite": "7.3.5",
70
+ "vitest": "3.2.6"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "@cedarjs/project-config": "4.2.0",