vite-plugin-storybook-nextjs 1.1.2 → 2.0.0--canary.33.4e40e92.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 CHANGED
@@ -3,6 +3,7 @@
3
3
  This is a Vite plugin that allows you to use Next.js features in Vite. It is the basis for `@storybook/experimental-nextjs-vite` and should be used when running portable stories in Vitest.
4
4
 
5
5
  ## Features
6
+
6
7
  - **Next.js Integration**: Seamlessly integrate Next.js features into your Vite project.
7
8
  - **Storybook Compatibility**: Acts as the foundation for [the `@storybook/experimental-nextjs-vite` framework](https://storybook.js.org/docs/get-started/frameworks/nextjs#with-vite), enabling you to use Storybook with Next.js in a Vite environment.
8
9
  - **Portable Stories**: Ideal for running portable stories in Vitest, ensuring your components are tested in an environment that closely mirrors production.
@@ -77,9 +78,7 @@ This plugin is necessary to run portable stories in Vitest, as it provides the n
77
78
 
78
79
  ## Automatic story transformation
79
80
 
80
- (⚠️ **Experimental**)
81
-
82
- The experimental `@storybook/experimental-addon-test` can be used to automatically transform your stories at Vitest runtime to in-memory test files. This allows you to run your stories in a Vitest environment without needing to manually transform your stories. Please visit https://storybook.js.org/docs/8.3/writing-tests/test-runner-with-vitest for more information.
81
+ The addon `@storybook/addon-test` can be used to automatically transform your stories at Vitest runtime to in-memory test files. This allows you to run your stories in a Vitest environment without needing to manually transform your stories. Please visit https://storybook.js.org/docs/8.3/writing-tests/test-runner-with-vitest for more information.
83
82
 
84
83
  ## Limitations and differences to the Webpack5-based integration of Next.js in Storybook
85
84
 
package/dist/index.cjs CHANGED
@@ -23,8 +23,9 @@ var options_js = require('next/dist/build/swc/options.js');
23
23
  var nextServerConfig = require('next/dist/server/config.js');
24
24
  var constants_js = require('next/dist/shared/lib/constants.js');
25
25
  var MagicString = require('magic-string');
26
+ var os = require('os');
26
27
  var querystring = require('querystring');
27
- var imageSize = require('image-size');
28
+ var imageSizeOf = require('image-size');
28
29
 
29
30
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
30
31
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -56,6 +57,7 @@ var loaderUtils__default = /*#__PURE__*/_interopDefault(loaderUtils);
56
57
  var nextLoadJsConfig__default = /*#__PURE__*/_interopDefault(nextLoadJsConfig);
57
58
  var nextServerConfig__default = /*#__PURE__*/_interopDefault(nextServerConfig);
58
59
  var MagicString__default = /*#__PURE__*/_interopDefault(MagicString);
60
+ var imageSizeOf__default = /*#__PURE__*/_interopDefault(imageSizeOf);
59
61
 
60
62
  var __create = Object.create;
61
63
  var __defProp = Object.defineProperty;
@@ -2673,7 +2675,19 @@ var excludeImporterPattern = /\.(css|scss|sass)$/;
2673
2675
  var virtualImage = "virtual:next-image";
2674
2676
  var virtualNextImage = "virtual:next/image";
2675
2677
  var virtualNextLegacyImage = "virtual:next/legacy/image";
2678
+ var sharp;
2676
2679
  var require4 = 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)));
2680
+ try {
2681
+ sharp = require4("sharp");
2682
+ if (sharp && sharp.concurrency() > 1) {
2683
+ const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
2684
+ sharp.concurrency(Math.floor(Math.max(os.cpus().length / divisor, 1)));
2685
+ }
2686
+ } catch (e) {
2687
+ console.warn(
2688
+ "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
2689
+ );
2690
+ }
2677
2691
  function vitePluginNextImage(nextConfigResolver) {
2678
2692
  let isBrowser = !isVitestEnv;
2679
2693
  return {
@@ -2725,6 +2739,7 @@ function vitePluginNextImage(nextConfigResolver) {
2725
2739
  if (virtualImage === source) {
2726
2740
  const imagePath = querystring.decode(query).imagePath;
2727
2741
  const nextConfig = await nextConfigResolver.promise;
2742
+ const extension = path2__default.default.extname(imagePath);
2728
2743
  try {
2729
2744
  if (nextConfig.images?.disableStaticImages) {
2730
2745
  return tsDedent.dedent`
@@ -2733,7 +2748,18 @@ function vitePluginNextImage(nextConfigResolver) {
2733
2748
  `;
2734
2749
  }
2735
2750
  const imageData = await fs3__default.default.promises.readFile(imagePath);
2736
- const { width, height } = imageSize.imageSize(imageData);
2751
+ let width;
2752
+ let height;
2753
+ if (extension === ".avif" && sharp) {
2754
+ const transformer = sharp(Buffer.from(imageData));
2755
+ const result = await transformer.metadata();
2756
+ width = result.width;
2757
+ height = result.height;
2758
+ } else {
2759
+ const result = imageSizeOf__default.default(imageData);
2760
+ width = result.width;
2761
+ height = result.height;
2762
+ }
2737
2763
  return tsDedent.dedent`
2738
2764
  import src from "${imagePath}?ignore";
2739
2765
  export default {
package/dist/index.js CHANGED
@@ -21,8 +21,9 @@ import { getParserOptions } from 'next/dist/build/swc/options.js';
21
21
  import nextServerConfig from 'next/dist/server/config.js';
22
22
  import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST, PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants.js';
23
23
  import MagicString from 'magic-string';
24
+ import { cpus } from 'node:os';
24
25
  import { decode } from 'node:querystring';
25
- import { imageSize } from 'image-size';
26
+ import imageSizeOf from 'image-size';
26
27
 
27
28
  var __create = Object.create;
28
29
  var __defProp = Object.defineProperty;
@@ -2640,7 +2641,19 @@ var excludeImporterPattern = /\.(css|scss|sass)$/;
2640
2641
  var virtualImage = "virtual:next-image";
2641
2642
  var virtualNextImage = "virtual:next/image";
2642
2643
  var virtualNextLegacyImage = "virtual:next/legacy/image";
2644
+ var sharp;
2643
2645
  var require4 = createRequire(import.meta.url);
2646
+ try {
2647
+ sharp = require4("sharp");
2648
+ if (sharp && sharp.concurrency() > 1) {
2649
+ const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
2650
+ sharp.concurrency(Math.floor(Math.max(cpus().length / divisor, 1)));
2651
+ }
2652
+ } catch (e) {
2653
+ console.warn(
2654
+ "You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
2655
+ );
2656
+ }
2644
2657
  function vitePluginNextImage(nextConfigResolver) {
2645
2658
  let isBrowser = !isVitestEnv;
2646
2659
  return {
@@ -2692,6 +2705,7 @@ function vitePluginNextImage(nextConfigResolver) {
2692
2705
  if (virtualImage === source) {
2693
2706
  const imagePath = decode(query).imagePath;
2694
2707
  const nextConfig = await nextConfigResolver.promise;
2708
+ const extension = path2.extname(imagePath);
2695
2709
  try {
2696
2710
  if (nextConfig.images?.disableStaticImages) {
2697
2711
  return dedent`
@@ -2700,7 +2714,18 @@ function vitePluginNextImage(nextConfigResolver) {
2700
2714
  `;
2701
2715
  }
2702
2716
  const imageData = await fs3.promises.readFile(imagePath);
2703
- const { width, height } = imageSize(imageData);
2717
+ let width;
2718
+ let height;
2719
+ if (extension === ".avif" && sharp) {
2720
+ const transformer = sharp(Buffer.from(imageData));
2721
+ const result = await transformer.metadata();
2722
+ width = result.width;
2723
+ height = result.height;
2724
+ } else {
2725
+ const result = imageSizeOf(imageData);
2726
+ width = result.width;
2727
+ height = result.height;
2728
+ }
2704
2729
  return dedent`
2705
2730
  import src from "${imagePath}?ignore";
2706
2731
  export default {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var test = require('@storybook/test');
5
+ var test = require('storybook/test');
6
6
 
7
7
  // src/plugins/next-mocks/alias/cache/index.ts
8
8
  var revalidatePath = test.fn().mockName(
@@ -1,4 +1,4 @@
1
- import { fn } from '@storybook/test';
1
+ import { fn } from 'storybook/test';
2
2
 
3
3
  // src/plugins/next-mocks/alias/cache/index.ts
4
4
  var revalidatePath = fn().mockName(
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var test = require('@storybook/test');
4
3
  var index_js = require('next/dist/compiled/@edge-runtime/cookies/index.js');
4
+ var test = require('storybook/test');
5
5
  var draftMode = require('next/dist/server/request/draft-mode');
6
6
  var headers2 = require('next/dist/server/request/headers');
7
7
  var headers_js = require('next/dist/server/web/spec-extension/adapters/headers.js');
@@ -1,5 +1,5 @@
1
- import { fn } from '@storybook/test';
2
1
  import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies/index.js';
2
+ import { fn } from 'storybook/test';
3
3
  import { draftMode } from 'next/dist/server/request/draft-mode';
4
4
  import * as headers2 from 'next/dist/server/request/headers';
5
5
  import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers.js';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var test = require('@storybook/test');
3
+ var test = require('storybook/test');
4
4
  var headers_js = require('next/dist/server/web/spec-extension/adapters/headers.js');
5
5
 
6
6
  // src/plugins/next-mocks/alias/headers/headers.ts
@@ -1,4 +1,4 @@
1
- import { fn } from '@storybook/test';
1
+ import { fn } from 'storybook/test';
2
2
  import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers.js';
3
3
 
4
4
  // src/plugins/next-mocks/alias/headers/headers.ts
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var test = require('@storybook/test');
4
3
  var draftMode = require('next/dist/server/request/draft-mode');
5
4
  var headers2 = require('next/dist/server/request/headers');
5
+ var test = require('storybook/test');
6
6
  var headers_js = require('next/dist/server/web/spec-extension/adapters/headers.js');
7
7
  var index_js = require('next/dist/compiled/@edge-runtime/cookies/index.js');
8
8
 
@@ -1,7 +1,7 @@
1
- import { fn } from '@storybook/test';
2
1
  import { draftMode } from 'next/dist/server/request/draft-mode';
3
2
  import * as headers2 from 'next/dist/server/request/headers';
4
3
  export { UnsafeUnwrappedHeaders } from 'next/dist/server/request/headers';
4
+ import { fn } from 'storybook/test';
5
5
  import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers.js';
6
6
  import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies/index.js';
7
7
 
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var test = require('@storybook/test');
4
3
  var actual = require('next/dist/client/components/navigation.js');
5
4
  var redirectStatusCode_js = require('next/dist/client/components/redirect-status-code.js');
6
5
  var redirect_js = require('next/dist/client/components/redirect.js');
7
6
  var previewErrors = require('storybook/internal/preview-errors');
7
+ var test = require('storybook/test');
8
8
 
9
9
  function _interopNamespace(e) {
10
10
  if (e && e.__esModule) return e;
@@ -1,7 +1,7 @@
1
- import { Mock } from '@storybook/test';
2
1
  import * as actual from 'next/dist/client/components/navigation.js';
3
2
  export * from 'next/dist/client/components/navigation.js';
4
3
  import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
4
+ import { Mock } from 'storybook/test';
5
5
 
6
6
  declare const createNavigation: (overrides?: Record<string, (...params: unknown[]) => unknown>) => {
7
7
  push: Mock;
@@ -1,7 +1,7 @@
1
- import { Mock } from '@storybook/test';
2
1
  import * as actual from 'next/dist/client/components/navigation.js';
3
2
  export * from 'next/dist/client/components/navigation.js';
4
3
  import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
4
+ import { Mock } from 'storybook/test';
5
5
 
6
6
  declare const createNavigation: (overrides?: Record<string, (...params: unknown[]) => unknown>) => {
7
7
  push: Mock;
@@ -1,9 +1,9 @@
1
- import { fn } from '@storybook/test';
2
1
  import * as actual from 'next/dist/client/components/navigation.js';
3
2
  export * from 'next/dist/client/components/navigation.js';
4
3
  import { RedirectStatusCode } from 'next/dist/client/components/redirect-status-code.js';
5
4
  import { getRedirectError } from 'next/dist/client/components/redirect.js';
6
5
  import { NextjsRouterMocksNotAvailable } from 'storybook/internal/preview-errors';
6
+ import { fn } from 'storybook/test';
7
7
 
8
8
  // src/plugins/next-mocks/alias/navigation/index.ts
9
9
  var navigationAPI;
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var test = require('@storybook/test');
6
5
  var singletonRouter = require('next/dist/client/router.js');
7
6
  var previewErrors = require('storybook/internal/preview-errors');
7
+ var test = require('storybook/test');
8
8
  var router = require('next/dist/client/router');
9
9
 
10
10
  function _interopNamespace(e) {
@@ -1,10 +1,10 @@
1
- import { Mock } from '@storybook/test';
2
1
  import { NextComponentType, NextPageContext } from 'next';
3
2
  import singletonRouter from 'next/dist/client/router.js';
4
3
  export { default } from 'next/dist/client/router.js';
5
4
  import { WithRouterProps, ExcludeRouterProps } from 'next/dist/client/with-router';
6
5
  import { NextRouter } from 'next/router.js';
7
6
  import { ComponentType } from 'react';
7
+ import { Mock } from 'storybook/test';
8
8
  export * from 'next/dist/client/router';
9
9
 
10
10
  /**
@@ -1,10 +1,10 @@
1
- import { Mock } from '@storybook/test';
2
1
  import { NextComponentType, NextPageContext } from 'next';
3
2
  import singletonRouter from 'next/dist/client/router.js';
4
3
  export { default } from 'next/dist/client/router.js';
5
4
  import { WithRouterProps, ExcludeRouterProps } from 'next/dist/client/with-router';
6
5
  import { NextRouter } from 'next/router.js';
7
6
  import { ComponentType } from 'react';
7
+ import { Mock } from 'storybook/test';
8
8
  export * from 'next/dist/client/router';
9
9
 
10
10
  /**
@@ -1,7 +1,7 @@
1
- import { fn } from '@storybook/test';
2
1
  import * as singletonRouter from 'next/dist/client/router.js';
3
2
  import singletonRouter__default from 'next/dist/client/router.js';
4
3
  import { NextjsRouterMocksNotAvailable } from 'storybook/internal/preview-errors';
4
+ import { fn } from 'storybook/test';
5
5
  export * from 'next/dist/client/router';
6
6
 
7
7
  // src/plugins/next-mocks/alias/router/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "1.1.2",
3
+ "version": "2.0.0--canary.33.4e40e92.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vite-plugin",
@@ -61,14 +61,12 @@
61
61
  "release": "auto shipit"
62
62
  },
63
63
  "peerDependencies": {
64
- "@storybook/test": "^8.3.0",
65
64
  "next": "^14.1.0 || ^15.0.0",
66
- "storybook": "^8.3.0",
65
+ "storybook": "^9.0.0-0",
67
66
  "vite": "^5.0.0 || ^6.0.0"
68
67
  },
69
68
  "devDependencies": {
70
69
  "@biomejs/biome": "1.8.1",
71
- "@storybook/test": "^8.3.0",
72
70
  "@types/node": "^18",
73
71
  "@types/react": "^18",
74
72
  "@types/semver": "^7.5.8",
@@ -78,6 +76,7 @@
78
76
  "react": "19.0.0-rc-66855b96-20241106",
79
77
  "rollup": "^4.18.0",
80
78
  "semver": "^7.6.3",
79
+ "sharp": "^0.33.4",
81
80
  "storybook": "^8.3.0",
82
81
  "tsup": "^8.1.0",
83
82
  "typescript": "^5.0.0",
@@ -87,11 +86,14 @@
87
86
  "packageManager": "pnpm@9.4.0",
88
87
  "dependencies": {
89
88
  "@next/env": "^15.0.3",
90
- "image-size": "^2.0.0",
89
+ "image-size": "^1.1.1",
91
90
  "magic-string": "^0.30.11",
92
91
  "module-alias": "^2.2.3",
93
92
  "ts-dedent": "^2.2.0"
94
93
  },
94
+ "optionalDependencies": {
95
+ "sharp": "^0.33.4"
96
+ },
95
97
  "publishConfig": {
96
98
  "access": "public"
97
99
  },