vite-plugin-storybook-nextjs 0.0.13 → 0.0.15

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
@@ -7,7 +7,6 @@ var fs3 = require('fs');
7
7
  var env = require('@next/env');
8
8
  var Log = require('next/dist/build/output/log.js');
9
9
  var index_js = require('next/dist/build/swc/index.js');
10
- var constants_js = require('next/dist/shared/lib/constants.js');
11
10
  var fs2 = require('fs/promises');
12
11
  var fetchCssFromGoogleFonts_js = require('next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts.js');
13
12
  var getFontAxes_js = require('next/dist/compiled/@next/font/dist/google/get-font-axes.js');
@@ -21,6 +20,8 @@ var findPagesDir_js = require('next/dist/lib/find-pages-dir.js');
21
20
  var utils_js = require('next/dist/build/utils.js');
22
21
  var options_js = require('next/dist/build/swc/options.js');
23
22
  var loadConfig = require('next/dist/server/config.js');
23
+ var constants_js = require('next/dist/shared/lib/constants.js');
24
+ var MagicString = require('magic-string');
24
25
  var os = require('os');
25
26
  var querystring = require('querystring');
26
27
  var imageSizeOf = require('image-size');
@@ -35,9 +36,15 @@ var fs2__default = /*#__PURE__*/_interopDefault(fs2);
35
36
  var loaderUtils__default = /*#__PURE__*/_interopDefault(loaderUtils);
36
37
  var loadJsConfig__default = /*#__PURE__*/_interopDefault(loadJsConfig);
37
38
  var loadConfig__default = /*#__PURE__*/_interopDefault(loadConfig);
39
+ var MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
38
40
  var imageSizeOf__default = /*#__PURE__*/_interopDefault(imageSizeOf);
39
41
 
40
- // src/index.ts
42
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
43
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
44
+ }) : x)(function(x) {
45
+ if (typeof require !== "undefined") return require.apply(this, arguments);
46
+ throw Error('Dynamic require of "' + x + '" is not supported');
47
+ });
41
48
  var nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/;
42
49
  async function loadEnvironmentConfig(dir, dev) {
43
50
  return env.loadEnvConfig(dir, dev, Log__default.default);
@@ -722,11 +729,40 @@ if (typeof Promise.withResolvers === "undefined") {
722
729
  return { promise, resolve: resolve4, reject };
723
730
  };
724
731
  }
732
+ var vitePluginNextDynamic = () => ({
733
+ name: "vite-plugin-storybook-nextjs-dynamic",
734
+ transform(code, id) {
735
+ const dynamicImportRegex = /dynamic\(\s*async\s*\(\s*\)\s*=>\s*\{\s*typeof\s*require\.resolveWeak\s*!==\s*"undefined"\s*&&\s*require\.resolveWeak\(([^)]+)\);\s*\}/g;
736
+ if (dynamicImportRegex.test(code)) {
737
+ const s = new MagicString__default.default(code);
738
+ dynamicImportRegex.lastIndex = 0;
739
+ let match = dynamicImportRegex.exec(code);
740
+ while (match !== null) {
741
+ const [fullMatch, importPath] = match;
742
+ const newImport = `dynamic(() => import(${importPath})`;
743
+ s.overwrite(match.index, match.index + fullMatch.length, newImport);
744
+ match = dynamicImportRegex.exec(code);
745
+ }
746
+ return {
747
+ code: s.toString(),
748
+ map: s.generateMap({ hires: true })
749
+ };
750
+ }
751
+ return null;
752
+ }
753
+ });
725
754
 
726
755
  // src/utils.ts
727
756
  var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
728
757
  var isVitestEnv = process.env.VITEST === "true";
729
758
 
759
+ // src/plugins/next-image/alias/index.tsx
760
+ var getEntryPoint = (subPath, env) => __require.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
761
+ var getAlias = (env) => ({
762
+ "sb-original/default-loader": getEntryPoint("image-default-loader", env),
763
+ "sb-original/image-context": getEntryPoint("image-context", env)
764
+ });
765
+
730
766
  // src/plugins/next-image/plugin.ts
731
767
  var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
732
768
  var excludeImporterPattern = /\.(css|scss|sass)$/;
@@ -746,11 +782,6 @@ try {
746
782
  "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
747
783
  );
748
784
  }
749
- var getEntryPoint = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
750
- var getAlias = (env) => ({
751
- "sb-original/default-loader": getEntryPoint("image-default-loader", env),
752
- "sb-original/image-context": getEntryPoint("image-context", env)
753
- });
754
785
  function vitePluginNextImage(nextConfigResolver) {
755
786
  let isBrowser = !isVitestEnv;
756
787
  return {
@@ -846,16 +877,21 @@ var getEntryPoint2 = (subPath, env) => require4.resolve(`${VITEST_PLUGIN_NAME}/$
846
877
  var getAlias2 = (env) => ({
847
878
  "next/headers": getEntryPoint2("headers", env),
848
879
  "@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
880
+ "@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
849
881
  "next/navigation": getEntryPoint2("navigation", env),
850
882
  "@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
883
+ "@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
851
884
  "next/router": getEntryPoint2("router", env),
852
885
  "@storybook/nextjs/router.mock": getEntryPoint2("router", env),
886
+ "@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
853
887
  "next/cache": getEntryPoint2("cache", env),
854
888
  "@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
889
+ "@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
855
890
  "server-only": getEntryPoint2("server-only", env),
856
891
  "@opentelemetry/api": require4.resolve(
857
- "next/dist/compiled/@opentelemetry/api/index.js"
858
- )
892
+ "next/dist/compiled/@opentelemetry/api"
893
+ ),
894
+ "next/dynamic": getEntryPoint2("dynamic", env)
859
895
  });
860
896
  var vitePluginNextMocks = () => ({
861
897
  name: "vite-plugin-next-mocks",
@@ -926,7 +962,8 @@ function VitePlugin({ dir = process.cwd() } = {}) {
926
962
  vitePluginNextSwc(dir, nextConfigResolver),
927
963
  vitePluginNextEnv(dir, nextConfigResolver),
928
964
  vitePluginNextImage(nextConfigResolver),
929
- vitePluginNextMocks()
965
+ vitePluginNextMocks(),
966
+ vitePluginNextDynamic()
930
967
  ];
931
968
  }
932
969
  var src_default = VitePlugin;
package/dist/index.js CHANGED
@@ -5,7 +5,6 @@ import fs3 from 'node:fs';
5
5
  import { loadEnvConfig } from '@next/env';
6
6
  import Log from 'next/dist/build/output/log.js';
7
7
  import { transform, loadBindings, lockfilePatchPromise } from 'next/dist/build/swc/index.js';
8
- import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST, PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants.js';
9
8
  import fs2 from 'node:fs/promises';
10
9
  import { fetchCSSFromGoogleFonts } from 'next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts.js';
11
10
  import { getFontAxes } from 'next/dist/compiled/@next/font/dist/google/get-font-axes.js';
@@ -19,11 +18,18 @@ import { findPagesDir } from 'next/dist/lib/find-pages-dir.js';
19
18
  import { getSupportedBrowsers } from 'next/dist/build/utils.js';
20
19
  import { getParserOptions } from 'next/dist/build/swc/options.js';
21
20
  import loadConfig from 'next/dist/server/config.js';
21
+ import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST, PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants.js';
22
+ import MagicString from 'magic-string';
22
23
  import { cpus } from 'node:os';
23
24
  import { decode } from 'node:querystring';
24
25
  import imageSizeOf from 'image-size';
25
26
 
26
- // src/index.ts
27
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
28
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
29
+ }) : x)(function(x) {
30
+ if (typeof require !== "undefined") return require.apply(this, arguments);
31
+ throw Error('Dynamic require of "' + x + '" is not supported');
32
+ });
27
33
  var nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/;
28
34
  async function loadEnvironmentConfig(dir, dev) {
29
35
  return loadEnvConfig(dir, dev, Log);
@@ -708,11 +714,40 @@ if (typeof Promise.withResolvers === "undefined") {
708
714
  return { promise, resolve: resolve4, reject };
709
715
  };
710
716
  }
717
+ var vitePluginNextDynamic = () => ({
718
+ name: "vite-plugin-storybook-nextjs-dynamic",
719
+ transform(code, id) {
720
+ const dynamicImportRegex = /dynamic\(\s*async\s*\(\s*\)\s*=>\s*\{\s*typeof\s*require\.resolveWeak\s*!==\s*"undefined"\s*&&\s*require\.resolveWeak\(([^)]+)\);\s*\}/g;
721
+ if (dynamicImportRegex.test(code)) {
722
+ const s = new MagicString(code);
723
+ dynamicImportRegex.lastIndex = 0;
724
+ let match = dynamicImportRegex.exec(code);
725
+ while (match !== null) {
726
+ const [fullMatch, importPath] = match;
727
+ const newImport = `dynamic(() => import(${importPath})`;
728
+ s.overwrite(match.index, match.index + fullMatch.length, newImport);
729
+ match = dynamicImportRegex.exec(code);
730
+ }
731
+ return {
732
+ code: s.toString(),
733
+ map: s.generateMap({ hires: true })
734
+ };
735
+ }
736
+ return null;
737
+ }
738
+ });
711
739
 
712
740
  // src/utils.ts
713
741
  var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
714
742
  var isVitestEnv = process.env.VITEST === "true";
715
743
 
744
+ // src/plugins/next-image/alias/index.tsx
745
+ var getEntryPoint = (subPath, env) => __require.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
746
+ var getAlias = (env) => ({
747
+ "sb-original/default-loader": getEntryPoint("image-default-loader", env),
748
+ "sb-original/image-context": getEntryPoint("image-context", env)
749
+ });
750
+
716
751
  // src/plugins/next-image/plugin.ts
717
752
  var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
718
753
  var excludeImporterPattern = /\.(css|scss|sass)$/;
@@ -732,11 +767,6 @@ try {
732
767
  "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
733
768
  );
734
769
  }
735
- var getEntryPoint = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
736
- var getAlias = (env) => ({
737
- "sb-original/default-loader": getEntryPoint("image-default-loader", env),
738
- "sb-original/image-context": getEntryPoint("image-context", env)
739
- });
740
770
  function vitePluginNextImage(nextConfigResolver) {
741
771
  let isBrowser = !isVitestEnv;
742
772
  return {
@@ -832,16 +862,21 @@ var getEntryPoint2 = (subPath, env) => require4.resolve(`${VITEST_PLUGIN_NAME}/$
832
862
  var getAlias2 = (env) => ({
833
863
  "next/headers": getEntryPoint2("headers", env),
834
864
  "@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
865
+ "@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
835
866
  "next/navigation": getEntryPoint2("navigation", env),
836
867
  "@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
868
+ "@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
837
869
  "next/router": getEntryPoint2("router", env),
838
870
  "@storybook/nextjs/router.mock": getEntryPoint2("router", env),
871
+ "@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
839
872
  "next/cache": getEntryPoint2("cache", env),
840
873
  "@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
874
+ "@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
841
875
  "server-only": getEntryPoint2("server-only", env),
842
876
  "@opentelemetry/api": require4.resolve(
843
- "next/dist/compiled/@opentelemetry/api/index.js"
844
- )
877
+ "next/dist/compiled/@opentelemetry/api"
878
+ ),
879
+ "next/dynamic": getEntryPoint2("dynamic", env)
845
880
  });
846
881
  var vitePluginNextMocks = () => ({
847
882
  name: "vite-plugin-next-mocks",
@@ -912,7 +947,8 @@ function VitePlugin({ dir = process.cwd() } = {}) {
912
947
  vitePluginNextSwc(dir, nextConfigResolver),
913
948
  vitePluginNextEnv(dir, nextConfigResolver),
914
949
  vitePluginNextImage(nextConfigResolver),
915
- vitePluginNextMocks()
950
+ vitePluginNextMocks(),
951
+ vitePluginNextDynamic()
916
952
  ];
917
953
  }
918
954
  var src_default = VitePlugin;
@@ -2,65 +2,56 @@
2
2
 
3
3
  var module$1 = require('module');
4
4
  var moduleAlias = require('module-alias');
5
- require('fs');
6
- var os = require('os');
7
- require('path');
8
- require('querystring');
9
- require('image-size');
10
- require('ts-dedent');
11
5
 
12
6
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
8
 
15
9
  var moduleAlias__default = /*#__PURE__*/_interopDefault(moduleAlias);
16
10
 
17
- // src/mocks/storybook.global.ts
11
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
+ }) : x)(function(x) {
14
+ if (typeof require !== "undefined") return require.apply(this, arguments);
15
+ throw Error('Dynamic require of "' + x + '" is not supported');
16
+ });
18
17
 
19
18
  // src/utils.ts
20
19
  var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
21
20
  process.env.VITEST === "true";
22
21
 
23
- // src/plugins/next-image/plugin.ts
24
- var sharp;
25
- var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
26
- try {
27
- sharp = require2("sharp");
28
- if (sharp && sharp.concurrency() > 1) {
29
- const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
30
- sharp.concurrency(Math.floor(Math.max(os.cpus().length / divisor, 1)));
31
- }
32
- } catch (e) {
33
- console.warn(
34
- "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
35
- );
36
- }
37
- var getEntryPoint = (subPath, env) => require2.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
22
+ // src/plugins/next-image/alias/index.tsx
23
+ var getEntryPoint = (subPath, env) => __require.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
38
24
  var getAlias = (env) => ({
39
25
  "sb-original/default-loader": getEntryPoint("image-default-loader", env),
40
26
  "sb-original/image-context": getEntryPoint("image-context", env)
41
27
  });
42
- var require3 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
43
- var getEntryPoint2 = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
28
+ var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
29
+ var getEntryPoint2 = (subPath, env) => require2.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
44
30
  var getAlias2 = (env) => ({
45
31
  "next/headers": getEntryPoint2("headers", env),
46
32
  "@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
33
+ "@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
47
34
  "next/navigation": getEntryPoint2("navigation", env),
48
35
  "@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
36
+ "@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
49
37
  "next/router": getEntryPoint2("router", env),
50
38
  "@storybook/nextjs/router.mock": getEntryPoint2("router", env),
39
+ "@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
51
40
  "next/cache": getEntryPoint2("cache", env),
52
41
  "@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
42
+ "@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
53
43
  "server-only": getEntryPoint2("server-only", env),
54
- "@opentelemetry/api": require3.resolve(
55
- "next/dist/compiled/@opentelemetry/api/index.js"
56
- )
44
+ "@opentelemetry/api": require2.resolve(
45
+ "next/dist/compiled/@opentelemetry/api"
46
+ ),
47
+ "next/dynamic": getEntryPoint2("dynamic", env)
57
48
  });
58
49
 
59
50
  // src/mocks/storybook.global.ts
60
- var require4 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
51
+ var require3 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('out.js', document.baseURI).href)));
61
52
  moduleAlias__default.default.addAliases({
62
53
  react: "next/dist/compiled/react",
63
- "react-dom/test-utils": require4.resolve(
54
+ "react-dom/test-utils": require3.resolve(
64
55
  "next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
65
56
  ),
66
57
  "react-dom": "next/dist/compiled/react-dom",
@@ -1,56 +1,50 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import moduleAlias from 'module-alias';
3
- import { cpus } from 'node:os';
4
- import 'image-size';
5
- import 'ts-dedent';
6
3
 
7
- // src/mocks/storybook.global.ts
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + x + '" is not supported');
9
+ });
8
10
 
9
11
  // src/utils.ts
10
12
  var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
11
13
  process.env.VITEST === "true";
12
14
 
13
- // src/plugins/next-image/plugin.ts
14
- var sharp;
15
- var require2 = createRequire(import.meta.url);
16
- try {
17
- sharp = require2("sharp");
18
- if (sharp && sharp.concurrency() > 1) {
19
- const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
20
- sharp.concurrency(Math.floor(Math.max(cpus().length / divisor, 1)));
21
- }
22
- } catch (e) {
23
- console.warn(
24
- "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
25
- );
26
- }
27
- var getEntryPoint = (subPath, env) => require2.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
15
+ // src/plugins/next-image/alias/index.tsx
16
+ var getEntryPoint = (subPath, env) => __require.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
28
17
  var getAlias = (env) => ({
29
18
  "sb-original/default-loader": getEntryPoint("image-default-loader", env),
30
19
  "sb-original/image-context": getEntryPoint("image-context", env)
31
20
  });
32
- var require3 = createRequire(import.meta.url);
33
- var getEntryPoint2 = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
21
+ var require2 = createRequire(import.meta.url);
22
+ var getEntryPoint2 = (subPath, env) => require2.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
34
23
  var getAlias2 = (env) => ({
35
24
  "next/headers": getEntryPoint2("headers", env),
36
25
  "@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
26
+ "@storybook/nextjs-vite/headers.mock": getEntryPoint2("headers", env),
37
27
  "next/navigation": getEntryPoint2("navigation", env),
38
28
  "@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
29
+ "@storybook/nextjs-vite/navigation.mock": getEntryPoint2("navigation", env),
39
30
  "next/router": getEntryPoint2("router", env),
40
31
  "@storybook/nextjs/router.mock": getEntryPoint2("router", env),
32
+ "@storybook/nextjs-vite/router.mock": getEntryPoint2("router", env),
41
33
  "next/cache": getEntryPoint2("cache", env),
42
34
  "@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
35
+ "@storybook/nextjs-vite/cache.mock": getEntryPoint2("cache", env),
43
36
  "server-only": getEntryPoint2("server-only", env),
44
- "@opentelemetry/api": require3.resolve(
45
- "next/dist/compiled/@opentelemetry/api/index.js"
46
- )
37
+ "@opentelemetry/api": require2.resolve(
38
+ "next/dist/compiled/@opentelemetry/api"
39
+ ),
40
+ "next/dynamic": getEntryPoint2("dynamic", env)
47
41
  });
48
42
 
49
43
  // src/mocks/storybook.global.ts
50
- var require4 = createRequire(import.meta.url);
44
+ var require3 = createRequire(import.meta.url);
51
45
  moduleAlias.addAliases({
52
46
  react: "next/dist/compiled/react",
53
- "react-dom/test-utils": require4.resolve(
47
+ "react-dom/test-utils": require3.resolve(
54
48
  "next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
55
49
  ),
56
50
  "react-dom": "next/dist/compiled/react-dom",
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
2
2
  import * as _NextImage from 'next/image';
3
3
  import React__default from 'next/dist/compiled/react';
4
4
 
5
- declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "width" | "height" | "loading" | "alt"> & {
6
6
  src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
7
  alt: string;
8
8
  width?: number | `${number}` | undefined;
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
2
2
  import * as _NextImage from 'next/image';
3
3
  import React__default from 'next/dist/compiled/react';
4
4
 
5
- declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "width" | "height" | "loading" | "alt"> & {
6
6
  src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
7
  alt: string;
8
8
  width?: number | `${number}` | undefined;
@@ -3,28 +3,22 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var test = require('@storybook/test');
6
- var unstableCache_js = require('next/dist/server/web/spec-extension/unstable-cache.js');
7
- var unstableNoStore_js = require('next/dist/server/web/spec-extension/unstable-no-store.js');
8
6
 
9
7
  // src/plugins/next-mocks/alias/cache/index.ts
10
8
  var revalidatePath = test.fn().mockName("next/cache::revalidatePath");
11
9
  var revalidateTag = test.fn().mockName("next/cache::revalidateTag");
10
+ var unstable_cache = test.fn().mockName("next/cache::unstable_cache").mockImplementation((cb) => cb);
11
+ var unstable_noStore = test.fn().mockName("next/cache::unstable_noStore");
12
12
  var cacheExports = {
13
- unstable_cache: unstableCache_js.unstable_cache,
13
+ unstable_cache,
14
14
  revalidateTag,
15
15
  revalidatePath,
16
- unstable_noStore: unstableNoStore_js.unstable_noStore
16
+ unstable_noStore
17
17
  };
18
18
  var cache_default = cacheExports;
19
19
 
20
- Object.defineProperty(exports, "unstable_cache", {
21
- enumerable: true,
22
- get: function () { return unstableCache_js.unstable_cache; }
23
- });
24
- Object.defineProperty(exports, "unstable_noStore", {
25
- enumerable: true,
26
- get: function () { return unstableNoStore_js.unstable_noStore; }
27
- });
28
20
  exports.default = cache_default;
29
21
  exports.revalidatePath = revalidatePath;
30
22
  exports.revalidateTag = revalidateTag;
23
+ exports.unstable_cache = unstable_cache;
24
+ exports.unstable_noStore = unstable_noStore;
@@ -1,16 +1,14 @@
1
1
  import * as vitest from 'vitest';
2
- import { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache.js';
3
- export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache.js';
4
- import { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store.js';
5
- export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store.js';
6
2
 
7
3
  declare const revalidatePath: vitest.Mock<any, any>;
8
4
  declare const revalidateTag: vitest.Mock<any, any>;
5
+ declare const unstable_cache: vitest.Mock<any, any>;
6
+ declare const unstable_noStore: vitest.Mock<any, any>;
9
7
  declare const cacheExports: {
10
- unstable_cache: typeof unstable_cache;
8
+ unstable_cache: vitest.Mock<any, any>;
11
9
  revalidateTag: vitest.Mock<any, any>;
12
10
  revalidatePath: vitest.Mock<any, any>;
13
- unstable_noStore: typeof unstable_noStore;
11
+ unstable_noStore: vitest.Mock<any, any>;
14
12
  };
15
13
 
16
- export { cacheExports as default, revalidatePath, revalidateTag };
14
+ export { cacheExports as default, revalidatePath, revalidateTag, unstable_cache, unstable_noStore };
@@ -1,16 +1,14 @@
1
1
  import * as vitest from 'vitest';
2
- import { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache.js';
3
- export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache.js';
4
- import { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store.js';
5
- export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store.js';
6
2
 
7
3
  declare const revalidatePath: vitest.Mock<any, any>;
8
4
  declare const revalidateTag: vitest.Mock<any, any>;
5
+ declare const unstable_cache: vitest.Mock<any, any>;
6
+ declare const unstable_noStore: vitest.Mock<any, any>;
9
7
  declare const cacheExports: {
10
- unstable_cache: typeof unstable_cache;
8
+ unstable_cache: vitest.Mock<any, any>;
11
9
  revalidateTag: vitest.Mock<any, any>;
12
10
  revalidatePath: vitest.Mock<any, any>;
13
- unstable_noStore: typeof unstable_noStore;
11
+ unstable_noStore: vitest.Mock<any, any>;
14
12
  };
15
13
 
16
- export { cacheExports as default, revalidatePath, revalidateTag };
14
+ export { cacheExports as default, revalidatePath, revalidateTag, unstable_cache, unstable_noStore };
@@ -1,12 +1,10 @@
1
1
  import { fn } from '@storybook/test';
2
- import { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache.js';
3
- export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache.js';
4
- import { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store.js';
5
- export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store.js';
6
2
 
7
3
  // src/plugins/next-mocks/alias/cache/index.ts
8
4
  var revalidatePath = fn().mockName("next/cache::revalidatePath");
9
5
  var revalidateTag = fn().mockName("next/cache::revalidateTag");
6
+ var unstable_cache = fn().mockName("next/cache::unstable_cache").mockImplementation((cb) => cb);
7
+ var unstable_noStore = fn().mockName("next/cache::unstable_noStore");
10
8
  var cacheExports = {
11
9
  unstable_cache,
12
10
  revalidateTag,
@@ -15,4 +13,4 @@ var cacheExports = {
15
13
  };
16
14
  var cache_default = cacheExports;
17
15
 
18
- export { cache_default as default, revalidatePath, revalidateTag };
16
+ export { cache_default as default, revalidatePath, revalidateTag, unstable_cache, unstable_noStore };
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Loadable = require('next/dist/shared/lib/loadable.shared-runtime.js');
6
+ var React = require('react');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var Loadable__default = /*#__PURE__*/_interopDefault(Loadable);
11
+ var React__default = /*#__PURE__*/_interopDefault(React);
12
+
13
+ // src/plugins/next-mocks/alias/dynamic/index.tsx
14
+ function convertModule(mod) {
15
+ return { default: mod?.default || mod };
16
+ }
17
+ function noSSR() {
18
+ throw new Error("noSSR is not implemented in Storybook");
19
+ }
20
+ function dynamic(dynamicOptions, options) {
21
+ const loadableFn = Loadable__default.default;
22
+ if (options?.ssr === false) {
23
+ delete options.ssr;
24
+ }
25
+ let loadableOptions = {
26
+ // A loading component is not required, so we default it
27
+ loading: ({ error, isLoading, pastDelay }) => {
28
+ if (!pastDelay) return null;
29
+ if (process.env.NODE_ENV !== "production") {
30
+ if (isLoading) {
31
+ return null;
32
+ }
33
+ if (error) {
34
+ return /* @__PURE__ */ React__default.default.createElement("p", null, error.message, /* @__PURE__ */ React__default.default.createElement("br", null), error.stack);
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+ };
40
+ if (dynamicOptions instanceof Promise) {
41
+ loadableOptions.loader = () => dynamicOptions;
42
+ } else if (typeof dynamicOptions === "function") {
43
+ loadableOptions.loader = dynamicOptions;
44
+ } else if (typeof dynamicOptions === "object") {
45
+ loadableOptions = { ...loadableOptions, ...dynamicOptions };
46
+ }
47
+ loadableOptions = { ...loadableOptions, ...options };
48
+ const loaderFn = loadableOptions.loader;
49
+ const loader = () => loaderFn != null ? loaderFn().then(convertModule) : Promise.resolve(convertModule(() => null));
50
+ if (loadableOptions.loadableGenerated) {
51
+ loadableOptions = {
52
+ ...loadableOptions,
53
+ ...loadableOptions.loadableGenerated
54
+ };
55
+ delete loadableOptions.loadableGenerated;
56
+ }
57
+ return loadableFn({ ...loadableOptions, loader });
58
+ }
59
+
60
+ exports.default = dynamic;
61
+ exports.noSSR = noSSR;
@@ -0,0 +1,37 @@
1
+ import React__default, { JSX } from 'react';
2
+
3
+ type ComponentModule<P = Record<string, unknown>> = {
4
+ default: React__default.ComponentType<P>;
5
+ };
6
+ declare type LoaderComponent<P = Record<string, unknown>> = Promise<React__default.ComponentType<P> | ComponentModule<P>>;
7
+ declare type Loader<P = Record<string, unknown>> = (() => LoaderComponent<P>) | LoaderComponent<P>;
8
+ type LoaderMap = {
9
+ [module: string]: () => Loader<unknown>;
10
+ };
11
+ type LoadableGeneratedOptions = {
12
+ webpack?(): unknown;
13
+ modules?(): LoaderMap;
14
+ };
15
+ type DynamicOptionsLoadingProps = {
16
+ error?: Error | null;
17
+ isLoading?: boolean;
18
+ pastDelay?: boolean;
19
+ retry?: () => void;
20
+ timedOut?: boolean;
21
+ };
22
+ type DynamicOptions<P = Record<string, unknown>> = LoadableGeneratedOptions & {
23
+ loading?: (loadingProps: DynamicOptionsLoadingProps) => JSX.Element | null;
24
+ loader?: Loader<P> | LoaderMap;
25
+ loadableGenerated?: LoadableGeneratedOptions;
26
+ ssr?: boolean;
27
+ };
28
+ declare function noSSR<P = Record<string, unknown>>(): React__default.ComponentType<P>;
29
+ /**
30
+ * This function lets you dynamically import a component.
31
+ * It uses [React.lazy()](https://react.dev/reference/react/lazy) with [Suspense](https://react.dev/reference/react/Suspense) under the hood.
32
+ *
33
+ * Read more: [Next.js Docs: `next/dynamic`](https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#nextdynamic)
34
+ */
35
+ declare function dynamic<P = Record<string, unknown>>(dynamicOptions: DynamicOptions<P> | Loader<P>, options?: DynamicOptions<P>): React__default.ComponentType<P>;
36
+
37
+ export { type LoaderComponent, dynamic as default, noSSR };
@@ -0,0 +1,37 @@
1
+ import React__default, { JSX } from 'react';
2
+
3
+ type ComponentModule<P = Record<string, unknown>> = {
4
+ default: React__default.ComponentType<P>;
5
+ };
6
+ declare type LoaderComponent<P = Record<string, unknown>> = Promise<React__default.ComponentType<P> | ComponentModule<P>>;
7
+ declare type Loader<P = Record<string, unknown>> = (() => LoaderComponent<P>) | LoaderComponent<P>;
8
+ type LoaderMap = {
9
+ [module: string]: () => Loader<unknown>;
10
+ };
11
+ type LoadableGeneratedOptions = {
12
+ webpack?(): unknown;
13
+ modules?(): LoaderMap;
14
+ };
15
+ type DynamicOptionsLoadingProps = {
16
+ error?: Error | null;
17
+ isLoading?: boolean;
18
+ pastDelay?: boolean;
19
+ retry?: () => void;
20
+ timedOut?: boolean;
21
+ };
22
+ type DynamicOptions<P = Record<string, unknown>> = LoadableGeneratedOptions & {
23
+ loading?: (loadingProps: DynamicOptionsLoadingProps) => JSX.Element | null;
24
+ loader?: Loader<P> | LoaderMap;
25
+ loadableGenerated?: LoadableGeneratedOptions;
26
+ ssr?: boolean;
27
+ };
28
+ declare function noSSR<P = Record<string, unknown>>(): React__default.ComponentType<P>;
29
+ /**
30
+ * This function lets you dynamically import a component.
31
+ * It uses [React.lazy()](https://react.dev/reference/react/lazy) with [Suspense](https://react.dev/reference/react/Suspense) under the hood.
32
+ *
33
+ * Read more: [Next.js Docs: `next/dynamic`](https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading#nextdynamic)
34
+ */
35
+ declare function dynamic<P = Record<string, unknown>>(dynamicOptions: DynamicOptions<P> | Loader<P>, options?: DynamicOptions<P>): React__default.ComponentType<P>;
36
+
37
+ export { type LoaderComponent, dynamic as default, noSSR };
@@ -0,0 +1,51 @@
1
+ import Loadable from 'next/dist/shared/lib/loadable.shared-runtime.js';
2
+ import React from 'react';
3
+
4
+ // src/plugins/next-mocks/alias/dynamic/index.tsx
5
+ function convertModule(mod) {
6
+ return { default: mod?.default || mod };
7
+ }
8
+ function noSSR() {
9
+ throw new Error("noSSR is not implemented in Storybook");
10
+ }
11
+ function dynamic(dynamicOptions, options) {
12
+ const loadableFn = Loadable;
13
+ if (options?.ssr === false) {
14
+ delete options.ssr;
15
+ }
16
+ let loadableOptions = {
17
+ // A loading component is not required, so we default it
18
+ loading: ({ error, isLoading, pastDelay }) => {
19
+ if (!pastDelay) return null;
20
+ if (process.env.NODE_ENV !== "production") {
21
+ if (isLoading) {
22
+ return null;
23
+ }
24
+ if (error) {
25
+ return /* @__PURE__ */ React.createElement("p", null, error.message, /* @__PURE__ */ React.createElement("br", null), error.stack);
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ };
31
+ if (dynamicOptions instanceof Promise) {
32
+ loadableOptions.loader = () => dynamicOptions;
33
+ } else if (typeof dynamicOptions === "function") {
34
+ loadableOptions.loader = dynamicOptions;
35
+ } else if (typeof dynamicOptions === "object") {
36
+ loadableOptions = { ...loadableOptions, ...dynamicOptions };
37
+ }
38
+ loadableOptions = { ...loadableOptions, ...options };
39
+ const loaderFn = loadableOptions.loader;
40
+ const loader = () => loaderFn != null ? loaderFn().then(convertModule) : Promise.resolve(convertModule(() => null));
41
+ if (loadableOptions.loadableGenerated) {
42
+ loadableOptions = {
43
+ ...loadableOptions,
44
+ ...loadableOptions.loadableGenerated
45
+ };
46
+ delete loadableOptions.loadableGenerated;
47
+ }
48
+ return loadableFn({ ...loadableOptions, loader });
49
+ }
50
+
51
+ export { dynamic as default, noSSR };
@@ -1,4 +1,4 @@
1
- import * as react from 'react';
1
+ import * as React from 'react';
2
2
  import * as next_dist_shared_lib_app_router_context_shared_runtime from 'next/dist/shared/lib/app-router-context.shared-runtime';
3
3
  import { Mock } from '@storybook/test';
4
4
  import * as actual from 'next/dist/client/components/navigation.js';
@@ -28,7 +28,7 @@ declare const usePathname: Mock<[], string>;
28
28
  declare const useSelectedLayoutSegment: Mock<[parallelRouteKey?: string | undefined], string | null>;
29
29
  declare const useSelectedLayoutSegments: Mock<[parallelRouteKey?: string | undefined], string[]>;
30
30
  declare const useRouter: Mock<[], next_dist_shared_lib_app_router_context_shared_runtime.AppRouterInstance>;
31
- declare const useServerInsertedHTML: Mock<[callback: () => react.ReactNode], void>;
31
+ declare const useServerInsertedHTML: Mock<[callback: () => React.ReactNode], void>;
32
32
  declare const notFound: Mock<[], never>;
33
33
  interface Params {
34
34
  [key: string]: string | string[];
@@ -1,4 +1,4 @@
1
- import * as react from 'react';
1
+ import * as React from 'react';
2
2
  import * as next_dist_shared_lib_app_router_context_shared_runtime from 'next/dist/shared/lib/app-router-context.shared-runtime';
3
3
  import { Mock } from '@storybook/test';
4
4
  import * as actual from 'next/dist/client/components/navigation.js';
@@ -28,7 +28,7 @@ declare const usePathname: Mock<[], string>;
28
28
  declare const useSelectedLayoutSegment: Mock<[parallelRouteKey?: string | undefined], string | null>;
29
29
  declare const useSelectedLayoutSegments: Mock<[parallelRouteKey?: string | undefined], string[]>;
30
30
  declare const useRouter: Mock<[], next_dist_shared_lib_app_router_context_shared_runtime.AppRouterInstance>;
31
- declare const useServerInsertedHTML: Mock<[callback: () => react.ReactNode], void>;
31
+ declare const useServerInsertedHTML: Mock<[callback: () => React.ReactNode], void>;
32
32
  declare const notFound: Mock<[], never>;
33
33
  interface Params {
34
34
  [key: string]: string | string[];
@@ -1,4 +1,4 @@
1
- import * as react from 'react';
1
+ import * as React from 'react';
2
2
  import * as next_dist_client_with_router from 'next/dist/client/with-router';
3
3
  import * as next_types from 'next/types';
4
4
  import { Mock } from '@storybook/test';
@@ -40,6 +40,6 @@ declare const getRouter: () => {
40
40
  };
41
41
 
42
42
  declare const useRouter: Mock<[], originalRouter.NextRouter>;
43
- declare const withRouter: Mock<[ComposedComponent: next_types.NextComponentType<next_types.NextPageContext, any, next_dist_client_with_router.WithRouterProps>], react.ComponentType<next_dist_client_with_router.ExcludeRouterProps<next_dist_client_with_router.WithRouterProps>>>;
43
+ declare const withRouter: Mock<[ComposedComponent: next_types.NextComponentType<next_types.NextPageContext, any, next_dist_client_with_router.WithRouterProps>], React.ComponentType<next_dist_client_with_router.ExcludeRouterProps<next_dist_client_with_router.WithRouterProps>>>;
44
44
 
45
45
  export { createRouter, getRouter, useRouter, withRouter };
@@ -1,4 +1,4 @@
1
- import * as react from 'react';
1
+ import * as React from 'react';
2
2
  import * as next_dist_client_with_router from 'next/dist/client/with-router';
3
3
  import * as next_types from 'next/types';
4
4
  import { Mock } from '@storybook/test';
@@ -40,6 +40,6 @@ declare const getRouter: () => {
40
40
  };
41
41
 
42
42
  declare const useRouter: Mock<[], originalRouter.NextRouter>;
43
- declare const withRouter: Mock<[ComposedComponent: next_types.NextComponentType<next_types.NextPageContext, any, next_dist_client_with_router.WithRouterProps>], react.ComponentType<next_dist_client_with_router.ExcludeRouterProps<next_dist_client_with_router.WithRouterProps>>>;
43
+ declare const withRouter: Mock<[ComposedComponent: next_types.NextComponentType<next_types.NextPageContext, any, next_dist_client_with_router.WithRouterProps>], React.ComponentType<next_dist_client_with_router.ExcludeRouterProps<next_dist_client_with_router.WithRouterProps>>>;
44
44
 
45
45
  export { createRouter, getRouter, useRouter, withRouter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vite-plugin",
@@ -28,6 +28,7 @@
28
28
  "./browser/mocks/headers": "./dist/plugins/next-mocks/alias/headers/index.js",
29
29
  "./browser/mocks/router": "./dist/plugins/next-mocks/alias/router/index.js",
30
30
  "./browser/mocks/server-only": "./dist/plugins/next-mocks/alias/rsc/server-only.js",
31
+ "./browser/mocks/dynamic": "./dist/plugins/next-mocks/alias/dynamic/index.js",
31
32
  "./browser/mocks/image": "./dist/plugins/next-image/alias/next-image.js",
32
33
  "./browser/mocks/legacy-image": "./dist/plugins/next-image/alias/next-legacy-image.js",
33
34
  "./browser/mocks/image-default-loader": "./dist/plugins/next-image/alias/image-default-loader.js",
@@ -37,6 +38,7 @@
37
38
  "./node/mocks/headers": "./dist/plugins/next-mocks/alias/headers/index.cjs",
38
39
  "./node/mocks/router": "./dist/plugins/next-mocks/alias/router/index.cjs",
39
40
  "./node/mocks/server-only": "./dist/plugins/next-mocks/alias/rsc/server-only.cjs",
41
+ "./node/mocks/dynamic": "./dist/plugins/next-mocks/alias/dynamic/index.cjs",
40
42
  "./node/mocks/image": "./dist/plugins/next-image/alias/next-image.cjs",
41
43
  "./node/mocks/legacy-image": "./dist/plugins/next-image/alias/next-legacy-image.cjs",
42
44
  "./node/mocks/image-default-loader": "./dist/plugins/next-image/alias/image-default-loader.cjs",
@@ -77,6 +79,7 @@
77
79
  "dependencies": {
78
80
  "@next/env": "^14.2.5",
79
81
  "image-size": "^1.1.1",
82
+ "magic-string": "^0.30.11",
80
83
  "module-alias": "^2.2.3",
81
84
  "ts-dedent": "^2.2.0"
82
85
  },