vite-plugin-storybook-nextjs 3.3.1 → 3.3.2

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/dist/index.cjs CHANGED
@@ -18,11 +18,12 @@ var tsDedent = require('ts-dedent');
18
18
  var nextLoadJsConfig = require('next/dist/build/load-jsconfig.js');
19
19
  var vite = require('vite');
20
20
  var options_js = require('next/dist/build/swc/options.js');
21
- var nextServerConfig = require('next/dist/server/config.js');
22
21
  var constants_js = require('next/dist/shared/lib/constants.js');
23
22
  var MagicString = require('magic-string');
24
23
  var path = require('path');
25
24
  var imageSize = require('image-size');
25
+ var configShared_js = require('next/dist/server/config-shared.js');
26
+ var nextServerConfig = require('next/dist/server/config.js');
26
27
 
27
28
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
28
29
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -52,8 +53,8 @@ var Log__default = /*#__PURE__*/_interopDefault(Log);
52
53
  var fs2__default = /*#__PURE__*/_interopDefault(fs2);
53
54
  var loaderUtils__default = /*#__PURE__*/_interopDefault(loaderUtils);
54
55
  var nextLoadJsConfig__default = /*#__PURE__*/_interopDefault(nextLoadJsConfig);
55
- var nextServerConfig__default = /*#__PURE__*/_interopDefault(nextServerConfig);
56
56
  var MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
57
+ var nextServerConfig__default = /*#__PURE__*/_interopDefault(nextServerConfig);
57
58
 
58
59
  var __create = Object.create;
59
60
  var __defProp = Object.defineProperty;
@@ -4959,13 +4960,42 @@ var vitePluginNextMocks = () => ({
4959
4960
  };
4960
4961
  }
4961
4962
  });
4962
-
4963
- // src/index.ts
4964
- var require8 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
4965
4963
  var loadConfig = (
4966
4964
  // biome-ignore lint/suspicious/noExplicitAny: CJS support
4967
4965
  nextServerConfig__default.default.default || nextServerConfig__default.default
4968
4966
  );
4967
+ var TURBOPACK_RUST_REACT_COMPILER_ERROR = "`experimental.turbopackRustReactCompiler` is only supported with Turbopack.";
4968
+ async function loadNextConfig(phase, dir) {
4969
+ try {
4970
+ return await loadConfig(phase, dir);
4971
+ } catch (error) {
4972
+ if (!isTurbopackRustReactCompilerError(error)) {
4973
+ throw error;
4974
+ }
4975
+ }
4976
+ const rawConfigModule = await loadConfig(phase, dir, { rawConfig: true });
4977
+ const rawConfig = interopDefault(rawConfigModule);
4978
+ const normalizedConfig = await configShared_js.normalizeConfig(phase, rawConfig);
4979
+ const {
4980
+ turbopackRustReactCompiler: _turbopackRustReactCompiler,
4981
+ ...experimental
4982
+ } = normalizedConfig.experimental ?? {};
4983
+ return loadConfig(phase, dir, {
4984
+ customConfig: {
4985
+ ...normalizedConfig,
4986
+ experimental
4987
+ }
4988
+ });
4989
+ }
4990
+ function isTurbopackRustReactCompilerError(error) {
4991
+ return error instanceof Error && error.message.startsWith(TURBOPACK_RUST_REACT_COMPILER_ERROR);
4992
+ }
4993
+ function interopDefault(module) {
4994
+ return module.default ?? module;
4995
+ }
4996
+
4997
+ // src/index.ts
4998
+ var require8 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
4969
4999
  function VitePlugin({
4970
5000
  dir = process.cwd(),
4971
5001
  image
@@ -4975,9 +5005,10 @@ function VitePlugin({
4975
5005
  const nextConfigResolver = Promise.withResolvers();
4976
5006
  const nodeEnv = process.env.NODE_ENV;
4977
5007
  const phase = nodeEnv === "development" ? constants_js.PHASE_DEVELOPMENT_SERVER : nodeEnv === "test" ? constants_js.PHASE_TEST : constants_js.PHASE_PRODUCTION_BUILD;
4978
- loadConfig(phase, resolvedDir).then((nextConfig) => {
4979
- nextConfigResolver.resolve(nextConfig);
4980
- });
5008
+ loadNextConfig(phase, resolvedDir).then(
5009
+ nextConfigResolver.resolve,
5010
+ nextConfigResolver.reject
5011
+ );
4981
5012
  return [
4982
5013
  isVite8orNewer ? null : nextConfigResolver.promise.then(async (nextConfig) => {
4983
5014
  const loadedJSConfig = await nextLoadJsConfig__default.default(resolvedDir, nextConfig);
package/dist/index.js CHANGED
@@ -16,11 +16,12 @@ import { dedent } from 'ts-dedent';
16
16
  import nextLoadJsConfig from 'next/dist/build/load-jsconfig.js';
17
17
  import { createFilter } from 'vite';
18
18
  import { getParserOptions } from 'next/dist/build/swc/options.js';
19
- import nextServerConfig from 'next/dist/server/config.js';
20
19
  import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST, PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants.js';
21
20
  import MagicString from 'magic-string';
22
21
  import { win32 as win32$1, posix as posix$1, isAbsolute as isAbsolute$1, resolve as resolve$1 } from 'path';
23
22
  import { imageSize } from 'image-size';
23
+ import { normalizeConfig } from 'next/dist/server/config-shared.js';
24
+ import nextServerConfig from 'next/dist/server/config.js';
24
25
 
25
26
  var __create = Object.create;
26
27
  var __defProp = Object.defineProperty;
@@ -4926,13 +4927,42 @@ var vitePluginNextMocks = () => ({
4926
4927
  };
4927
4928
  }
4928
4929
  });
4929
-
4930
- // src/index.ts
4931
- var require8 = createRequire(import.meta.url);
4932
4930
  var loadConfig = (
4933
4931
  // biome-ignore lint/suspicious/noExplicitAny: CJS support
4934
4932
  nextServerConfig.default || nextServerConfig
4935
4933
  );
4934
+ var TURBOPACK_RUST_REACT_COMPILER_ERROR = "`experimental.turbopackRustReactCompiler` is only supported with Turbopack.";
4935
+ async function loadNextConfig(phase, dir) {
4936
+ try {
4937
+ return await loadConfig(phase, dir);
4938
+ } catch (error) {
4939
+ if (!isTurbopackRustReactCompilerError(error)) {
4940
+ throw error;
4941
+ }
4942
+ }
4943
+ const rawConfigModule = await loadConfig(phase, dir, { rawConfig: true });
4944
+ const rawConfig = interopDefault(rawConfigModule);
4945
+ const normalizedConfig = await normalizeConfig(phase, rawConfig);
4946
+ const {
4947
+ turbopackRustReactCompiler: _turbopackRustReactCompiler,
4948
+ ...experimental
4949
+ } = normalizedConfig.experimental ?? {};
4950
+ return loadConfig(phase, dir, {
4951
+ customConfig: {
4952
+ ...normalizedConfig,
4953
+ experimental
4954
+ }
4955
+ });
4956
+ }
4957
+ function isTurbopackRustReactCompilerError(error) {
4958
+ return error instanceof Error && error.message.startsWith(TURBOPACK_RUST_REACT_COMPILER_ERROR);
4959
+ }
4960
+ function interopDefault(module) {
4961
+ return module.default ?? module;
4962
+ }
4963
+
4964
+ // src/index.ts
4965
+ var require8 = createRequire(import.meta.url);
4936
4966
  function VitePlugin({
4937
4967
  dir = process.cwd(),
4938
4968
  image
@@ -4942,9 +4972,10 @@ function VitePlugin({
4942
4972
  const nextConfigResolver = Promise.withResolvers();
4943
4973
  const nodeEnv = process.env.NODE_ENV;
4944
4974
  const phase = nodeEnv === "development" ? PHASE_DEVELOPMENT_SERVER : nodeEnv === "test" ? PHASE_TEST : PHASE_PRODUCTION_BUILD;
4945
- loadConfig(phase, resolvedDir).then((nextConfig) => {
4946
- nextConfigResolver.resolve(nextConfig);
4947
- });
4975
+ loadNextConfig(phase, resolvedDir).then(
4976
+ nextConfigResolver.resolve,
4977
+ nextConfigResolver.reject
4978
+ );
4948
4979
  return [
4949
4980
  isVite8orNewer ? null : nextConfigResolver.promise.then(async (nextConfig) => {
4950
4981
  const loadedJSConfig = await nextLoadJsConfig(resolvedDir, nextConfig);
@@ -57,16 +57,17 @@ var getRouter = () => {
57
57
  }
58
58
  return navigationAPI;
59
59
  };
60
+ var forbidden2 = actual__namespace.forbidden;
61
+ var unauthorized2 = actual__namespace.unauthorized;
62
+ var unstable_isUnrecognizedActionError2 = actual__namespace.unstable_isUnrecognizedActionError;
60
63
  var redirect = test.fn(
61
- (url, type = actual__namespace.RedirectType.push) => {
64
+ (url, type = "push") => {
62
65
  throw redirect_js.getRedirectError(url, type, redirectStatusCode_js.RedirectStatusCode.SeeOther);
63
66
  }
64
67
  ).mockName("next/navigation::redirect");
65
- var permanentRedirect = test.fn(
66
- (url, type = actual__namespace.RedirectType.push) => {
67
- throw redirect_js.getRedirectError(url, type, redirectStatusCode_js.RedirectStatusCode.SeeOther);
68
- }
69
- ).mockName("next/navigation::permanentRedirect");
68
+ var permanentRedirect = test.fn((url, type = "push") => {
69
+ throw redirect_js.getRedirectError(url, type, redirectStatusCode_js.RedirectStatusCode.SeeOther);
70
+ }).mockName("next/navigation::permanentRedirect");
70
71
  var useSearchParams2 = test.fn(
71
72
  actual__namespace.useSearchParams
72
73
  ).mockName("next/navigation::useSearchParams");
@@ -95,11 +96,26 @@ var useParams2 = test.fn(
95
96
  actual__namespace.useParams
96
97
  ).mockName("next/navigation::useParams");
97
98
 
99
+ Object.defineProperty(exports, "ReadonlyURLSearchParams", {
100
+ enumerable: true,
101
+ get: function () { return actual.ReadonlyURLSearchParams; }
102
+ });
103
+ Object.defineProperty(exports, "RedirectType", {
104
+ enumerable: true,
105
+ get: function () { return actual.RedirectType; }
106
+ });
107
+ Object.defineProperty(exports, "ServerInsertedHTMLContext", {
108
+ enumerable: true,
109
+ get: function () { return actual.ServerInsertedHTMLContext; }
110
+ });
98
111
  exports.createNavigation = createNavigation;
112
+ exports.forbidden = forbidden2;
99
113
  exports.getRouter = getRouter;
100
114
  exports.notFound = notFound2;
101
115
  exports.permanentRedirect = permanentRedirect;
102
116
  exports.redirect = redirect;
117
+ exports.unauthorized = unauthorized2;
118
+ exports.unstable_isUnrecognizedActionError = unstable_isUnrecognizedActionError2;
103
119
  exports.unstable_rethrow = unstable_rethrow2;
104
120
  exports.useParams = useParams2;
105
121
  exports.usePathname = usePathname2;
@@ -1,8 +1,11 @@
1
1
  import * as actual from 'next/dist/client/components/navigation.js';
2
2
  export * from 'next/dist/client/components/navigation.js';
3
+ export { ReadonlyURLSearchParams, RedirectType, ServerInsertedHTMLContext } from 'next/dist/client/components/navigation.js';
4
+ import { getRedirectError } from 'next/dist/client/components/redirect.js';
3
5
  import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
4
6
  import { Mock } from 'storybook/test';
5
7
 
8
+ type RedirectType = Parameters<typeof getRedirectError>[1];
6
9
  declare const createNavigation: (overrides?: Record<string, (...params: unknown[]) => unknown>) => {
7
10
  push: Mock;
8
11
  replace: Mock;
@@ -20,8 +23,11 @@ declare const getRouter: () => {
20
23
  refresh: Mock;
21
24
  };
22
25
 
23
- declare const redirect: Mock<(url: string, type?: actual.RedirectType) => never>;
24
- declare const permanentRedirect: Mock<(url: string, type?: actual.RedirectType) => never>;
26
+ declare const forbidden: typeof actual.forbidden;
27
+ declare const unauthorized: typeof actual.unauthorized;
28
+ declare const unstable_isUnrecognizedActionError: typeof actual.unstable_isUnrecognizedActionError;
29
+ declare const redirect: Mock<(url: string, type?: RedirectType) => never>;
30
+ declare const permanentRedirect: Mock<(url: string, type?: RedirectType) => never>;
25
31
  declare const useSearchParams: Mock<() => actual.ReadonlyURLSearchParams>;
26
32
  declare const usePathname: Mock<() => string>;
27
33
  declare const useSelectedLayoutSegment: Mock<(parallelRouteKey?: string) => string | null>;
@@ -35,4 +41,4 @@ interface Params {
35
41
  }
36
42
  declare const useParams: Mock<() => Params>;
37
43
 
38
- export { createNavigation, getRouter, notFound, permanentRedirect, redirect, unstable_rethrow, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
44
+ export { createNavigation, forbidden, getRouter, notFound, permanentRedirect, redirect, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
@@ -1,8 +1,11 @@
1
1
  import * as actual from 'next/dist/client/components/navigation.js';
2
2
  export * from 'next/dist/client/components/navigation.js';
3
+ export { ReadonlyURLSearchParams, RedirectType, ServerInsertedHTMLContext } from 'next/dist/client/components/navigation.js';
4
+ import { getRedirectError } from 'next/dist/client/components/redirect.js';
3
5
  import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
4
6
  import { Mock } from 'storybook/test';
5
7
 
8
+ type RedirectType = Parameters<typeof getRedirectError>[1];
6
9
  declare const createNavigation: (overrides?: Record<string, (...params: unknown[]) => unknown>) => {
7
10
  push: Mock;
8
11
  replace: Mock;
@@ -20,8 +23,11 @@ declare const getRouter: () => {
20
23
  refresh: Mock;
21
24
  };
22
25
 
23
- declare const redirect: Mock<(url: string, type?: actual.RedirectType) => never>;
24
- declare const permanentRedirect: Mock<(url: string, type?: actual.RedirectType) => never>;
26
+ declare const forbidden: typeof actual.forbidden;
27
+ declare const unauthorized: typeof actual.unauthorized;
28
+ declare const unstable_isUnrecognizedActionError: typeof actual.unstable_isUnrecognizedActionError;
29
+ declare const redirect: Mock<(url: string, type?: RedirectType) => never>;
30
+ declare const permanentRedirect: Mock<(url: string, type?: RedirectType) => never>;
25
31
  declare const useSearchParams: Mock<() => actual.ReadonlyURLSearchParams>;
26
32
  declare const usePathname: Mock<() => string>;
27
33
  declare const useSelectedLayoutSegment: Mock<(parallelRouteKey?: string) => string | null>;
@@ -35,4 +41,4 @@ interface Params {
35
41
  }
36
42
  declare const useParams: Mock<() => Params>;
37
43
 
38
- export { createNavigation, getRouter, notFound, permanentRedirect, redirect, unstable_rethrow, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
44
+ export { createNavigation, forbidden, getRouter, notFound, permanentRedirect, redirect, unauthorized, unstable_isUnrecognizedActionError, unstable_rethrow, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
@@ -1,5 +1,6 @@
1
1
  import * as actual from 'next/dist/client/components/navigation.js';
2
2
  export * from 'next/dist/client/components/navigation.js';
3
+ export { ReadonlyURLSearchParams, RedirectType, ServerInsertedHTMLContext } from 'next/dist/client/components/navigation.js';
3
4
  import { RedirectStatusCode } from 'next/dist/client/components/redirect-status-code.js';
4
5
  import { getRedirectError } from 'next/dist/client/components/redirect.js';
5
6
  import { NextjsRouterMocksNotAvailable } from 'storybook/internal/preview-errors';
@@ -36,16 +37,17 @@ var getRouter = () => {
36
37
  }
37
38
  return navigationAPI;
38
39
  };
40
+ var forbidden2 = actual.forbidden;
41
+ var unauthorized2 = actual.unauthorized;
42
+ var unstable_isUnrecognizedActionError2 = actual.unstable_isUnrecognizedActionError;
39
43
  var redirect = fn(
40
- (url, type = actual.RedirectType.push) => {
44
+ (url, type = "push") => {
41
45
  throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
42
46
  }
43
47
  ).mockName("next/navigation::redirect");
44
- var permanentRedirect = fn(
45
- (url, type = actual.RedirectType.push) => {
46
- throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
47
- }
48
- ).mockName("next/navigation::permanentRedirect");
48
+ var permanentRedirect = fn((url, type = "push") => {
49
+ throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
50
+ }).mockName("next/navigation::permanentRedirect");
49
51
  var useSearchParams2 = fn(
50
52
  actual.useSearchParams
51
53
  ).mockName("next/navigation::useSearchParams");
@@ -74,4 +76,4 @@ var useParams2 = fn(
74
76
  actual.useParams
75
77
  ).mockName("next/navigation::useParams");
76
78
 
77
- export { createNavigation, getRouter, notFound2 as notFound, permanentRedirect, redirect, unstable_rethrow2 as unstable_rethrow, useParams2 as useParams, usePathname2 as usePathname, useRouter2 as useRouter, useSearchParams2 as useSearchParams, useSelectedLayoutSegment2 as useSelectedLayoutSegment, useSelectedLayoutSegments2 as useSelectedLayoutSegments, useServerInsertedHTML2 as useServerInsertedHTML };
79
+ export { createNavigation, forbidden2 as forbidden, getRouter, notFound2 as notFound, permanentRedirect, redirect, unauthorized2 as unauthorized, unstable_isUnrecognizedActionError2 as unstable_isUnrecognizedActionError, unstable_rethrow2 as unstable_rethrow, useParams2 as useParams, usePathname2 as usePathname, useRouter2 as useRouter, useSearchParams2 as useSearchParams, useSelectedLayoutSegment2 as useSelectedLayoutSegment, useSelectedLayoutSegments2 as useSelectedLayoutSegments, useServerInsertedHTML2 as useServerInsertedHTML };
@@ -126,6 +126,10 @@ var useRouter2 = test.fn(
126
126
  ).mockName("next/router::useRouter");
127
127
  var withRouter2 = test.fn(singletonRouter__namespace.withRouter).mockName("next/router::withRouter");
128
128
 
129
+ Object.defineProperty(exports, "Router", {
130
+ enumerable: true,
131
+ get: function () { return router.Router; }
132
+ });
129
133
  exports.createRouter = createRouter;
130
134
  exports.default = router_default;
131
135
  exports.getRouter = getRouter;
@@ -6,6 +6,7 @@ import { NextRouter } from 'next/router.js';
6
6
  import { ComponentType } from 'react';
7
7
  import { Mock } from 'storybook/test';
8
8
  export * from 'next/dist/client/router';
9
+ export { Router } from 'next/dist/client/router';
9
10
 
10
11
  /**
11
12
  * Creates a next/router router API mock. Used internally.
@@ -6,6 +6,7 @@ import { NextRouter } from 'next/router.js';
6
6
  import { ComponentType } from 'react';
7
7
  import { Mock } from 'storybook/test';
8
8
  export * from 'next/dist/client/router';
9
+ export { Router } from 'next/dist/client/router';
9
10
 
10
11
  /**
11
12
  * Creates a next/router router API mock. Used internally.
@@ -3,6 +3,7 @@ import singletonRouter__default from 'next/dist/client/router.js';
3
3
  import { NextjsRouterMocksNotAvailable } from 'storybook/internal/preview-errors';
4
4
  import { fn } from 'storybook/test';
5
5
  export * from 'next/dist/client/router';
6
+ export { Router } from 'next/dist/client/router';
6
7
 
7
8
  // src/plugins/next-mocks/alias/router/index.ts
8
9
  var defaultRouterState = {
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "3.3.1",
3
+ "version": "3.3.2",
4
+ "bugs": {
5
+ "url": "https://github.com/storybookjs/vite-plugin-storybook-nextjs/issues"
6
+ },
4
7
  "repository": {
5
8
  "type": "git",
6
9
  "url": "https://github.com/storybookjs/vite-plugin-storybook-nextjs.git"
@@ -29,7 +32,7 @@
29
32
  "default": "./dist/index.js"
30
33
  },
31
34
  "require": {
32
- "types": "./dist/index.d.cjs",
35
+ "types": "./dist/index.d.cts",
33
36
  "default": "./dist/index.cjs"
34
37
  }
35
38
  },
@@ -74,7 +77,7 @@
74
77
  "@types/react": "^18",
75
78
  "@types/semver": "^7.5.8",
76
79
  "lefthook": "^1.6.16",
77
- "next": "16.0.0",
80
+ "next": "16.3.0-preview.5",
78
81
  "pathe": "^2.0.3",
79
82
  "pkg-pr-new": "^0.0.63",
80
83
  "react": "19.2.0",
@@ -87,7 +90,7 @@
87
90
  "vitest": "^3.0.0"
88
91
  },
89
92
  "dependencies": {
90
- "@next/env": "16.0.0",
93
+ "@next/env": "16.3.0-preview.5",
91
94
  "image-size": "^2.0.0",
92
95
  "magic-string": "^0.30.11",
93
96
  "module-alias": "^2.2.3",