vite-plugin-storybook-nextjs 3.1.3 → 3.1.5

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
@@ -22,7 +22,6 @@ var options_js = require('next/dist/build/swc/options.js');
22
22
  var nextServerConfig = require('next/dist/server/config.js');
23
23
  var constants_js = require('next/dist/shared/lib/constants.js');
24
24
  var MagicString = require('magic-string');
25
- var querystring = require('querystring');
26
25
  var path = require('path');
27
26
  var imageSize = require('image-size');
28
27
 
@@ -4728,9 +4727,19 @@ var warnOnce = (message) => {
4728
4727
  };
4729
4728
  var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
4730
4729
  var excludeImporterPattern = /\.(css|scss|sass)$/;
4731
- var virtualImage = "virtual:next-image";
4730
+ var virtualImagePrefix = "\0virtual:next-image:";
4732
4731
  var virtualNextImage = "virtual:next/image";
4733
4732
  var virtualNextLegacyImage = "virtual:next/legacy/image";
4733
+ function encodeBase64Url(str) {
4734
+ const base64 = Buffer.from(str).toString("base64");
4735
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
4736
+ }
4737
+ function decodeBase64Url(str) {
4738
+ const padding = (4 - str.length % 4) % 4;
4739
+ const withPadding = str + "=".repeat(padding);
4740
+ const base64 = withPadding.replace(/-/g, "+").replace(/_/g, "/");
4741
+ return Buffer.from(base64, "base64").toString();
4742
+ }
4734
4743
  var require5 = 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)));
4735
4744
  function vitePluginNextImage(nextConfigResolver, options = {}) {
4736
4745
  let isBrowser = !isVitestEnv;
@@ -4778,14 +4787,14 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4778
4787
  For more info and recommended configuration, see: https://github.com/storybookjs/vite-plugin-storybook-nextjs/blob/main/README.md#faq-includingexcluding-images`
4779
4788
  );
4780
4789
  }
4781
- if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImage)) {
4790
+ if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImagePrefix)) {
4782
4791
  const isAbsolute3 = posix.isAbsolute(id);
4783
4792
  const imagePath = importer ? isAbsolute3 ? source : posix.join(posix.dirname(importer), source) : source;
4784
4793
  const pathForFilter = imagePath.replace(postfixRE, "");
4785
4794
  if (!filter(pathForFilter)) {
4786
4795
  return null;
4787
4796
  }
4788
- return `${virtualImage}?${querystring.encode({ imagePath })}`;
4797
+ return `${virtualImagePrefix}${encodeBase64Url(imagePath)}`;
4789
4798
  }
4790
4799
  if (id === "next/image" && importer !== virtualNextImage) {
4791
4800
  return virtualNextImage;
@@ -4809,9 +4818,8 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4809
4818
  )
4810
4819
  )).toString("utf-8");
4811
4820
  }
4812
- const [source, query] = id.split("?");
4813
- if (virtualImage === source) {
4814
- const imagePath = querystring.decode(query).imagePath;
4821
+ if (id.startsWith(virtualImagePrefix)) {
4822
+ const imagePath = decodeBase64Url(id.slice(virtualImagePrefix.length));
4815
4823
  const nextConfig = await nextConfigResolver.promise;
4816
4824
  try {
4817
4825
  if (nextConfig.images?.disableStaticImages) {
package/dist/index.js CHANGED
@@ -20,7 +20,6 @@ import { getParserOptions } from 'next/dist/build/swc/options.js';
20
20
  import nextServerConfig from 'next/dist/server/config.js';
21
21
  import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST, PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants.js';
22
22
  import MagicString from 'magic-string';
23
- import { decode, encode } from 'querystring';
24
23
  import { win32 as win32$1, posix as posix$1, isAbsolute as isAbsolute$1, resolve as resolve$1 } from 'path';
25
24
  import { imageSize } from 'image-size';
26
25
 
@@ -4695,9 +4694,19 @@ var warnOnce = (message) => {
4695
4694
  };
4696
4695
  var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
4697
4696
  var excludeImporterPattern = /\.(css|scss|sass)$/;
4698
- var virtualImage = "virtual:next-image";
4697
+ var virtualImagePrefix = "\0virtual:next-image:";
4699
4698
  var virtualNextImage = "virtual:next/image";
4700
4699
  var virtualNextLegacyImage = "virtual:next/legacy/image";
4700
+ function encodeBase64Url(str) {
4701
+ const base64 = Buffer.from(str).toString("base64");
4702
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
4703
+ }
4704
+ function decodeBase64Url(str) {
4705
+ const padding = (4 - str.length % 4) % 4;
4706
+ const withPadding = str + "=".repeat(padding);
4707
+ const base64 = withPadding.replace(/-/g, "+").replace(/_/g, "/");
4708
+ return Buffer.from(base64, "base64").toString();
4709
+ }
4701
4710
  var require5 = createRequire(import.meta.url);
4702
4711
  function vitePluginNextImage(nextConfigResolver, options = {}) {
4703
4712
  let isBrowser = !isVitestEnv;
@@ -4745,14 +4754,14 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4745
4754
  For more info and recommended configuration, see: https://github.com/storybookjs/vite-plugin-storybook-nextjs/blob/main/README.md#faq-includingexcluding-images`
4746
4755
  );
4747
4756
  }
4748
- if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImage)) {
4757
+ if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImagePrefix)) {
4749
4758
  const isAbsolute3 = posix.isAbsolute(id);
4750
4759
  const imagePath = importer ? isAbsolute3 ? source : posix.join(posix.dirname(importer), source) : source;
4751
4760
  const pathForFilter = imagePath.replace(postfixRE, "");
4752
4761
  if (!filter(pathForFilter)) {
4753
4762
  return null;
4754
4763
  }
4755
- return `${virtualImage}?${encode({ imagePath })}`;
4764
+ return `${virtualImagePrefix}${encodeBase64Url(imagePath)}`;
4756
4765
  }
4757
4766
  if (id === "next/image" && importer !== virtualNextImage) {
4758
4767
  return virtualNextImage;
@@ -4776,9 +4785,8 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4776
4785
  )
4777
4786
  )).toString("utf-8");
4778
4787
  }
4779
- const [source, query] = id.split("?");
4780
- if (virtualImage === source) {
4781
- const imagePath = decode(query).imagePath;
4788
+ if (id.startsWith(virtualImagePrefix)) {
4789
+ const imagePath = decodeBase64Url(id.slice(virtualImagePrefix.length));
4782
4790
  const nextConfig = await nextConfigResolver.promise;
4783
4791
  try {
4784
4792
  if (nextConfig.images?.disableStaticImages) {
@@ -19,9 +19,6 @@ function noSSR() {
19
19
  }
20
20
  function dynamic(dynamicOptions, options) {
21
21
  const loadableFn = Loadable__default.default;
22
- if (options?.ssr === false) {
23
- delete options.ssr;
24
- }
25
22
  let loadableOptions = {
26
23
  // A loading component is not required, so we default it
27
24
  loading: ({ error, isLoading, pastDelay }) => {
@@ -54,6 +51,11 @@ function dynamic(dynamicOptions, options) {
54
51
  };
55
52
  delete loadableOptions.loadableGenerated;
56
53
  }
54
+ if (typeof loadableOptions.ssr === "boolean" && !loadableOptions.ssr) {
55
+ delete loadableOptions.ssr;
56
+ delete loadableOptions.webpack;
57
+ delete loadableOptions.modules;
58
+ }
57
59
  return loadableFn({ ...loadableOptions, loader });
58
60
  }
59
61
 
@@ -10,9 +10,6 @@ function noSSR() {
10
10
  }
11
11
  function dynamic(dynamicOptions, options) {
12
12
  const loadableFn = Loadable;
13
- if (options?.ssr === false) {
14
- delete options.ssr;
15
- }
16
13
  let loadableOptions = {
17
14
  // A loading component is not required, so we default it
18
15
  loading: ({ error, isLoading, pastDelay }) => {
@@ -45,6 +42,11 @@ function dynamic(dynamicOptions, options) {
45
42
  };
46
43
  delete loadableOptions.loadableGenerated;
47
44
  }
45
+ if (typeof loadableOptions.ssr === "boolean" && !loadableOptions.ssr) {
46
+ delete loadableOptions.ssr;
47
+ delete loadableOptions.webpack;
48
+ delete loadableOptions.modules;
49
+ }
48
50
  return loadableFn({ ...loadableOptions, loader });
49
51
  }
50
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vite-plugin",