vite-plugin-storybook-nextjs 3.1.4 → 3.1.6

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
 
@@ -4298,6 +4297,21 @@ function vitePluginNextFont() {
4298
4297
  }
4299
4298
  };
4300
4299
  }
4300
+ var require2 = 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)));
4301
+ var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
4302
+ var isVitestEnv = process.env.VITEST === "true";
4303
+ function getExecutionEnvironment(config) {
4304
+ return isVitestEnv && config.test?.browser?.enabled !== true ? "node" : "browser";
4305
+ }
4306
+ var getNextjsVersion = () => require2("next/package.json").version;
4307
+ var getNextjsMajorVersion = () => {
4308
+ try {
4309
+ const version = getNextjsVersion();
4310
+ return Number.parseInt(version.split(".")[0], 10);
4311
+ } catch (error) {
4312
+ return 16;
4313
+ }
4314
+ };
4301
4315
 
4302
4316
  // src/utils/swc/styles.ts
4303
4317
  function getStyledComponentsOptions(styledComponentsConfig, development) {
@@ -4340,8 +4354,8 @@ function getEmotionOptions(emotionConfig, development) {
4340
4354
  }
4341
4355
 
4342
4356
  // src/utils/swc/options.ts
4343
- var require2 = 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)));
4344
- var regeneratorRuntimePath = require2.resolve(
4357
+ var require3 = 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)));
4358
+ var regeneratorRuntimePath = require3.resolve(
4345
4359
  "next/dist/compiled/regenerator-runtime"
4346
4360
  );
4347
4361
  function getBaseSWCOptions({
@@ -4368,7 +4382,7 @@ function getBaseSWCOptions({
4368
4382
  const useDefineForClassFields = Boolean(
4369
4383
  jsConfig?.compilerOptions?.useDefineForClassFields
4370
4384
  );
4371
- const plugins = (swcPlugins ?? []).filter(Array.isArray).map(([name, options]) => [require2.resolve(name), options]);
4385
+ const plugins = (swcPlugins ?? []).filter(Array.isArray).map(([name, options]) => [require3.resolve(name), options]);
4372
4386
  return {
4373
4387
  jsc: {
4374
4388
  ...resolvedBaseUrl && paths ? {
@@ -4556,8 +4570,9 @@ function vitePluginNextSwc(rootDir, nextConfigResolver) {
4556
4570
  await loadSWCBindingsEagerly(nextConfig);
4557
4571
  const serverWatchIgnored = config.server?.watch?.ignored;
4558
4572
  const isServerWatchIgnoredArray = Array.isArray(serverWatchIgnored);
4559
- if (config.test?.environment === "node" || config.test?.environment === "edge-runtime" || config.test?.browser?.enabled !== false) {
4560
- isServerEnvironment = true;
4573
+ isServerEnvironment = false;
4574
+ if (isVitestEnv) {
4575
+ isServerEnvironment = config.test?.environment === "node" || config.test?.environment === "edge-runtime" || config.test?.browser?.enabled !== true;
4561
4576
  }
4562
4577
  return {
4563
4578
  // esbuild: {
@@ -4696,21 +4711,6 @@ var reservedWords = "break case class catch const continue debugger default dele
4696
4711
  var builtins = "arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl";
4697
4712
  var forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(" "));
4698
4713
  forbiddenIdentifiers.add("");
4699
- var require3 = 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)));
4700
- var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
4701
- var isVitestEnv = process.env.VITEST === "true";
4702
- function getExecutionEnvironment(config) {
4703
- return isVitestEnv && config.test?.browser?.enabled !== true ? "node" : "browser";
4704
- }
4705
- var getNextjsVersion = () => require3("next/package.json").version;
4706
- var getNextjsMajorVersion = () => {
4707
- try {
4708
- const version = getNextjsVersion();
4709
- return Number.parseInt(version.split(".")[0], 10);
4710
- } catch (error) {
4711
- return 16;
4712
- }
4713
- };
4714
4714
  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)));
4715
4715
  var getEntryPoint = (subPath, env) => require4.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
4716
4716
  var getAlias = (env) => ({
@@ -4728,9 +4728,19 @@ var warnOnce = (message) => {
4728
4728
  };
4729
4729
  var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
4730
4730
  var excludeImporterPattern = /\.(css|scss|sass)$/;
4731
- var virtualImage = "virtual:next-image";
4731
+ var virtualImagePrefix = "\0virtual:next-image:";
4732
4732
  var virtualNextImage = "virtual:next/image";
4733
4733
  var virtualNextLegacyImage = "virtual:next/legacy/image";
4734
+ function encodeBase64Url(str) {
4735
+ const base64 = Buffer.from(str).toString("base64");
4736
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
4737
+ }
4738
+ function decodeBase64Url(str) {
4739
+ const padding = (4 - str.length % 4) % 4;
4740
+ const withPadding = str + "=".repeat(padding);
4741
+ const base64 = withPadding.replace(/-/g, "+").replace(/_/g, "/");
4742
+ return Buffer.from(base64, "base64").toString();
4743
+ }
4734
4744
  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
4745
  function vitePluginNextImage(nextConfigResolver, options = {}) {
4736
4746
  let isBrowser = !isVitestEnv;
@@ -4778,14 +4788,14 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4778
4788
  For more info and recommended configuration, see: https://github.com/storybookjs/vite-plugin-storybook-nextjs/blob/main/README.md#faq-includingexcluding-images`
4779
4789
  );
4780
4790
  }
4781
- if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImage)) {
4791
+ if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImagePrefix)) {
4782
4792
  const isAbsolute3 = posix.isAbsolute(id);
4783
4793
  const imagePath = importer ? isAbsolute3 ? source : posix.join(posix.dirname(importer), source) : source;
4784
4794
  const pathForFilter = imagePath.replace(postfixRE, "");
4785
4795
  if (!filter(pathForFilter)) {
4786
4796
  return null;
4787
4797
  }
4788
- return `${virtualImage}?${querystring.encode({ imagePath })}`;
4798
+ return `${virtualImagePrefix}${encodeBase64Url(imagePath)}`;
4789
4799
  }
4790
4800
  if (id === "next/image" && importer !== virtualNextImage) {
4791
4801
  return virtualNextImage;
@@ -4809,9 +4819,8 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4809
4819
  )
4810
4820
  )).toString("utf-8");
4811
4821
  }
4812
- const [source, query] = id.split("?");
4813
- if (virtualImage === source) {
4814
- const imagePath = querystring.decode(query).imagePath;
4822
+ if (id.startsWith(virtualImagePrefix)) {
4823
+ const imagePath = decodeBase64Url(id.slice(virtualImagePrefix.length));
4815
4824
  const nextConfig = await nextConfigResolver.promise;
4816
4825
  try {
4817
4826
  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
 
@@ -4265,6 +4264,21 @@ function vitePluginNextFont() {
4265
4264
  }
4266
4265
  };
4267
4266
  }
4267
+ var require2 = createRequire(import.meta.url);
4268
+ var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
4269
+ var isVitestEnv = process.env.VITEST === "true";
4270
+ function getExecutionEnvironment(config) {
4271
+ return isVitestEnv && config.test?.browser?.enabled !== true ? "node" : "browser";
4272
+ }
4273
+ var getNextjsVersion = () => require2("next/package.json").version;
4274
+ var getNextjsMajorVersion = () => {
4275
+ try {
4276
+ const version = getNextjsVersion();
4277
+ return Number.parseInt(version.split(".")[0], 10);
4278
+ } catch (error) {
4279
+ return 16;
4280
+ }
4281
+ };
4268
4282
 
4269
4283
  // src/utils/swc/styles.ts
4270
4284
  function getStyledComponentsOptions(styledComponentsConfig, development) {
@@ -4307,8 +4321,8 @@ function getEmotionOptions(emotionConfig, development) {
4307
4321
  }
4308
4322
 
4309
4323
  // src/utils/swc/options.ts
4310
- var require2 = createRequire(import.meta.url);
4311
- var regeneratorRuntimePath = require2.resolve(
4324
+ var require3 = createRequire(import.meta.url);
4325
+ var regeneratorRuntimePath = require3.resolve(
4312
4326
  "next/dist/compiled/regenerator-runtime"
4313
4327
  );
4314
4328
  function getBaseSWCOptions({
@@ -4335,7 +4349,7 @@ function getBaseSWCOptions({
4335
4349
  const useDefineForClassFields = Boolean(
4336
4350
  jsConfig?.compilerOptions?.useDefineForClassFields
4337
4351
  );
4338
- const plugins = (swcPlugins ?? []).filter(Array.isArray).map(([name, options]) => [require2.resolve(name), options]);
4352
+ const plugins = (swcPlugins ?? []).filter(Array.isArray).map(([name, options]) => [require3.resolve(name), options]);
4339
4353
  return {
4340
4354
  jsc: {
4341
4355
  ...resolvedBaseUrl && paths ? {
@@ -4523,8 +4537,9 @@ function vitePluginNextSwc(rootDir, nextConfigResolver) {
4523
4537
  await loadSWCBindingsEagerly(nextConfig);
4524
4538
  const serverWatchIgnored = config.server?.watch?.ignored;
4525
4539
  const isServerWatchIgnoredArray = Array.isArray(serverWatchIgnored);
4526
- if (config.test?.environment === "node" || config.test?.environment === "edge-runtime" || config.test?.browser?.enabled !== false) {
4527
- isServerEnvironment = true;
4540
+ isServerEnvironment = false;
4541
+ if (isVitestEnv) {
4542
+ isServerEnvironment = config.test?.environment === "node" || config.test?.environment === "edge-runtime" || config.test?.browser?.enabled !== true;
4528
4543
  }
4529
4544
  return {
4530
4545
  // esbuild: {
@@ -4663,21 +4678,6 @@ var reservedWords = "break case class catch const continue debugger default dele
4663
4678
  var builtins = "arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl";
4664
4679
  var forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(" "));
4665
4680
  forbiddenIdentifiers.add("");
4666
- var require3 = createRequire(import.meta.url);
4667
- var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
4668
- var isVitestEnv = process.env.VITEST === "true";
4669
- function getExecutionEnvironment(config) {
4670
- return isVitestEnv && config.test?.browser?.enabled !== true ? "node" : "browser";
4671
- }
4672
- var getNextjsVersion = () => require3("next/package.json").version;
4673
- var getNextjsMajorVersion = () => {
4674
- try {
4675
- const version = getNextjsVersion();
4676
- return Number.parseInt(version.split(".")[0], 10);
4677
- } catch (error) {
4678
- return 16;
4679
- }
4680
- };
4681
4681
  var require4 = createRequire(import.meta.url);
4682
4682
  var getEntryPoint = (subPath, env) => require4.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
4683
4683
  var getAlias = (env) => ({
@@ -4695,9 +4695,19 @@ var warnOnce = (message) => {
4695
4695
  };
4696
4696
  var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
4697
4697
  var excludeImporterPattern = /\.(css|scss|sass)$/;
4698
- var virtualImage = "virtual:next-image";
4698
+ var virtualImagePrefix = "\0virtual:next-image:";
4699
4699
  var virtualNextImage = "virtual:next/image";
4700
4700
  var virtualNextLegacyImage = "virtual:next/legacy/image";
4701
+ function encodeBase64Url(str) {
4702
+ const base64 = Buffer.from(str).toString("base64");
4703
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
4704
+ }
4705
+ function decodeBase64Url(str) {
4706
+ const padding = (4 - str.length % 4) % 4;
4707
+ const withPadding = str + "=".repeat(padding);
4708
+ const base64 = withPadding.replace(/-/g, "+").replace(/_/g, "/");
4709
+ return Buffer.from(base64, "base64").toString();
4710
+ }
4701
4711
  var require5 = createRequire(import.meta.url);
4702
4712
  function vitePluginNextImage(nextConfigResolver, options = {}) {
4703
4713
  let isBrowser = !isVitestEnv;
@@ -4745,14 +4755,14 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4745
4755
  For more info and recommended configuration, see: https://github.com/storybookjs/vite-plugin-storybook-nextjs/blob/main/README.md#faq-includingexcluding-images`
4746
4756
  );
4747
4757
  }
4748
- if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImage)) {
4758
+ if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImagePrefix)) {
4749
4759
  const isAbsolute3 = posix.isAbsolute(id);
4750
4760
  const imagePath = importer ? isAbsolute3 ? source : posix.join(posix.dirname(importer), source) : source;
4751
4761
  const pathForFilter = imagePath.replace(postfixRE, "");
4752
4762
  if (!filter(pathForFilter)) {
4753
4763
  return null;
4754
4764
  }
4755
- return `${virtualImage}?${encode({ imagePath })}`;
4765
+ return `${virtualImagePrefix}${encodeBase64Url(imagePath)}`;
4756
4766
  }
4757
4767
  if (id === "next/image" && importer !== virtualNextImage) {
4758
4768
  return virtualNextImage;
@@ -4776,9 +4786,8 @@ function vitePluginNextImage(nextConfigResolver, options = {}) {
4776
4786
  )
4777
4787
  )).toString("utf-8");
4778
4788
  }
4779
- const [source, query] = id.split("?");
4780
- if (virtualImage === source) {
4781
- const imagePath = decode(query).imagePath;
4789
+ if (id.startsWith(virtualImagePrefix)) {
4790
+ const imagePath = decodeBase64Url(id.slice(virtualImagePrefix.length));
4782
4791
  const nextConfig = await nextConfigResolver.promise;
4783
4792
  try {
4784
4793
  if (nextConfig.images?.disableStaticImages) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vite-plugin",