vite-plugin-storybook-nextjs 1.0.8 → 1.0.9
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 +29 -19
- package/dist/index.js +24 -14
- package/dist/plugins/next-image/alias/next-image.d.cts +1 -1
- package/dist/plugins/next-image/alias/next-image.d.ts +1 -1
- package/dist/plugins/next-mocks/alias/headers/cookies.d.cts +1 -1
- package/dist/plugins/next-mocks/alias/headers/cookies.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var path2 = require('path');
|
|
4
4
|
var module$1 = require('module');
|
|
5
5
|
var defineEnvPlugin_js = require('next/dist/build/webpack/plugins/define-env-plugin.js');
|
|
6
6
|
var fs3 = require('fs');
|
|
7
7
|
var nextEnv = 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 findPagesDir_js = require('next/dist/lib/find-pages-dir.js');
|
|
10
11
|
var fs2 = require('fs/promises');
|
|
11
12
|
var fetchCssFromGoogleFonts_js = require('next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts.js');
|
|
12
13
|
var getFontAxes_js = require('next/dist/compiled/@next/font/dist/google/get-font-axes.js');
|
|
@@ -16,7 +17,6 @@ var loaderUtils = require('next/dist/compiled/loader-utils3/index.js');
|
|
|
16
17
|
var validateLocalFontFunctionCall_js = require('next/dist/compiled/@next/font/dist/local/validate-local-font-function-call.js');
|
|
17
18
|
var tsDedent = require('ts-dedent');
|
|
18
19
|
var nextLoadJsConfig = require('next/dist/build/load-jsconfig.js');
|
|
19
|
-
var findPagesDir_js = require('next/dist/lib/find-pages-dir.js');
|
|
20
20
|
var vite = require('vite');
|
|
21
21
|
var utils_js = require('next/dist/build/utils.js');
|
|
22
22
|
var options_js = require('next/dist/build/swc/options.js');
|
|
@@ -48,7 +48,7 @@ function _interopNamespace(e) {
|
|
|
48
48
|
return Object.freeze(n);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
var
|
|
51
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
52
52
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
53
53
|
var nextEnv__namespace = /*#__PURE__*/_interopNamespace(nextEnv);
|
|
54
54
|
var Log__default = /*#__PURE__*/_interopDefault(Log);
|
|
@@ -81,7 +81,7 @@ async function loadClosestPackageJson(dir, attempts = 1) {
|
|
|
81
81
|
const mainPath = attempts === 1 ? ["."] : new Array(attempts).fill("..");
|
|
82
82
|
try {
|
|
83
83
|
const file = await fs3__default.default.promises.readFile(
|
|
84
|
-
|
|
84
|
+
path2.join(dir, ...mainPath, "package.json"),
|
|
85
85
|
"utf8"
|
|
86
86
|
);
|
|
87
87
|
return JSON.parse(file);
|
|
@@ -89,12 +89,22 @@ async function loadClosestPackageJson(dir, attempts = 1) {
|
|
|
89
89
|
return loadClosestPackageJson(dir, attempts + 1);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
function findNextDirectories(dir) {
|
|
93
|
+
try {
|
|
94
|
+
return findPagesDir_js.findPagesDir(dir);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
return {
|
|
97
|
+
appDir: path2__default.default.join(dir, "app"),
|
|
98
|
+
pagesDir: path2__default.default.join(dir, "pages")
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
92
102
|
|
|
93
103
|
// src/plugins/next-env/plugin.ts
|
|
94
104
|
function vitePluginNextEnv(rootDir, nextConfigResolver) {
|
|
95
105
|
let envConfig;
|
|
96
106
|
let isDev;
|
|
97
|
-
const resolvedDir =
|
|
107
|
+
const resolvedDir = path2.resolve(rootDir);
|
|
98
108
|
return {
|
|
99
109
|
name: "vite-plugin-storybook-nextjs-env",
|
|
100
110
|
enforce: "pre",
|
|
@@ -344,7 +354,7 @@ function vitePluginNextFont() {
|
|
|
344
354
|
return null;
|
|
345
355
|
}
|
|
346
356
|
let fontFaceDeclaration;
|
|
347
|
-
const pathSep =
|
|
357
|
+
const pathSep = path2__default.default.sep;
|
|
348
358
|
if (sourceWithoutQuery.endsWith(
|
|
349
359
|
["next", "font", "google", "target.css"].join(pathSep)
|
|
350
360
|
)) {
|
|
@@ -353,17 +363,17 @@ function vitePluginNextFont() {
|
|
|
353
363
|
if (sourceWithoutQuery.endsWith(
|
|
354
364
|
["next", "font", "local", "target.css"].join(pathSep)
|
|
355
365
|
)) {
|
|
356
|
-
const importerDirPath =
|
|
366
|
+
const importerDirPath = path2__default.default.dirname(fontOptions.filename);
|
|
357
367
|
const emitFont = async (importerRelativeFontPath) => {
|
|
358
|
-
const fontExtension =
|
|
359
|
-
const fontBaseName =
|
|
368
|
+
const fontExtension = path2__default.default.extname(importerRelativeFontPath);
|
|
369
|
+
const fontBaseName = path2__default.default.basename(
|
|
360
370
|
importerRelativeFontPath,
|
|
361
371
|
fontExtension
|
|
362
372
|
);
|
|
363
|
-
const fontPath =
|
|
373
|
+
const fontPath = path2__default.default.join(importerDirPath, importerRelativeFontPath);
|
|
364
374
|
if (devMode) {
|
|
365
375
|
return {
|
|
366
|
-
fontPath:
|
|
376
|
+
fontPath: path2__default.default.join(cwd, fontPath),
|
|
367
377
|
fontReferenceId: void 0
|
|
368
378
|
};
|
|
369
379
|
}
|
|
@@ -610,7 +620,7 @@ var getVitestSWCTransformConfig = ({
|
|
|
610
620
|
swcPlugins: nextConfig.experimental.swcPlugins,
|
|
611
621
|
compiler: nextConfig?.compiler,
|
|
612
622
|
esm: isEsmProject,
|
|
613
|
-
swcCacheDir:
|
|
623
|
+
swcCacheDir: path2__default.default.join(
|
|
614
624
|
rootDir,
|
|
615
625
|
nextConfig.distDir ?? ".next",
|
|
616
626
|
"cache",
|
|
@@ -623,7 +633,7 @@ var getVitestSWCTransformConfig = ({
|
|
|
623
633
|
...baseOptions,
|
|
624
634
|
fontLoaders: {
|
|
625
635
|
fontLoaders: ["next/font/local", "next/font/google"],
|
|
626
|
-
relativeFilePathFromRoot:
|
|
636
|
+
relativeFilePathFromRoot: path2__default.default.relative(rootDir, filename)
|
|
627
637
|
},
|
|
628
638
|
cjsRequireOptimizer: {
|
|
629
639
|
packages: {
|
|
@@ -683,13 +693,13 @@ function vitePluginNextSwc(rootDir, nextConfigResolver) {
|
|
|
683
693
|
let isDev;
|
|
684
694
|
let isEsmProject;
|
|
685
695
|
const filter = vite.createFilter(included, excluded);
|
|
686
|
-
const resolvedDir =
|
|
696
|
+
const resolvedDir = path2.resolve(rootDir);
|
|
687
697
|
return {
|
|
688
698
|
name: "vite-plugin-storybook-nextjs-swc",
|
|
689
699
|
enforce: "pre",
|
|
690
700
|
async config(config, env) {
|
|
691
701
|
const nextConfig = await nextConfigResolver.promise;
|
|
692
|
-
nextDirectories =
|
|
702
|
+
nextDirectories = findNextDirectories(resolvedDir);
|
|
693
703
|
loadedJSConfig = await loadJsConfig(resolvedDir, nextConfig);
|
|
694
704
|
isDev = env.mode !== "production";
|
|
695
705
|
await loadClosestPackageJson(resolvedDir);
|
|
@@ -827,8 +837,8 @@ function vitePluginNextImage(nextConfigResolver) {
|
|
|
827
837
|
return null;
|
|
828
838
|
}
|
|
829
839
|
if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImage)) {
|
|
830
|
-
const isAbsolute =
|
|
831
|
-
const imagePath = importer ? isAbsolute ? source :
|
|
840
|
+
const isAbsolute = path2__default.default.isAbsolute(id);
|
|
841
|
+
const imagePath = importer ? isAbsolute ? source : path2__default.default.join(path2__default.default.dirname(importer), source) : source;
|
|
832
842
|
return `${virtualImage}?imagePath=${imagePath}`;
|
|
833
843
|
}
|
|
834
844
|
if (id === "next/image" && importer !== virtualNextImage) {
|
|
@@ -857,7 +867,7 @@ function vitePluginNextImage(nextConfigResolver) {
|
|
|
857
867
|
if (virtualImage === source) {
|
|
858
868
|
const imagePath = querystring.decode(query).imagePath;
|
|
859
869
|
const nextConfig = await nextConfigResolver.promise;
|
|
860
|
-
const extension =
|
|
870
|
+
const extension = path2__default.default.extname(imagePath);
|
|
861
871
|
try {
|
|
862
872
|
if (nextConfig.images?.disableStaticImages) {
|
|
863
873
|
return tsDedent.dedent`
|
|
@@ -949,7 +959,7 @@ var loadConfig = (
|
|
|
949
959
|
nextServerConfig__default.default.default || nextServerConfig__default.default
|
|
950
960
|
);
|
|
951
961
|
function VitePlugin({ dir = process.cwd() } = {}) {
|
|
952
|
-
const resolvedDir =
|
|
962
|
+
const resolvedDir = path2.resolve(dir);
|
|
953
963
|
const nextConfigResolver = Promise.withResolvers();
|
|
954
964
|
return [
|
|
955
965
|
{
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path2, { resolve, join } from 'node:path';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { getDefineEnv } from 'next/dist/build/webpack/plugins/define-env-plugin.js';
|
|
4
4
|
import fs3 from 'node:fs';
|
|
5
5
|
import * as nextEnv 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 { findPagesDir } from 'next/dist/lib/find-pages-dir.js';
|
|
8
9
|
import fs2 from 'node:fs/promises';
|
|
9
10
|
import { fetchCSSFromGoogleFonts } from 'next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts.js';
|
|
10
11
|
import { getFontAxes } from 'next/dist/compiled/@next/font/dist/google/get-font-axes.js';
|
|
@@ -14,7 +15,6 @@ import loaderUtils from 'next/dist/compiled/loader-utils3/index.js';
|
|
|
14
15
|
import { validateLocalFontFunctionCall } from 'next/dist/compiled/@next/font/dist/local/validate-local-font-function-call.js';
|
|
15
16
|
import { dedent } from 'ts-dedent';
|
|
16
17
|
import nextLoadJsConfig from 'next/dist/build/load-jsconfig.js';
|
|
17
|
-
import { findPagesDir } from 'next/dist/lib/find-pages-dir.js';
|
|
18
18
|
import { createFilter } from 'vite';
|
|
19
19
|
import { getSupportedBrowsers } from 'next/dist/build/utils.js';
|
|
20
20
|
import { getParserOptions } from 'next/dist/build/swc/options.js';
|
|
@@ -55,6 +55,16 @@ async function loadClosestPackageJson(dir, attempts = 1) {
|
|
|
55
55
|
return loadClosestPackageJson(dir, attempts + 1);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
function findNextDirectories(dir) {
|
|
59
|
+
try {
|
|
60
|
+
return findPagesDir(dir);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return {
|
|
63
|
+
appDir: path2.join(dir, "app"),
|
|
64
|
+
pagesDir: path2.join(dir, "pages")
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
58
68
|
|
|
59
69
|
// src/plugins/next-env/plugin.ts
|
|
60
70
|
function vitePluginNextEnv(rootDir, nextConfigResolver) {
|
|
@@ -310,7 +320,7 @@ function vitePluginNextFont() {
|
|
|
310
320
|
return null;
|
|
311
321
|
}
|
|
312
322
|
let fontFaceDeclaration;
|
|
313
|
-
const pathSep =
|
|
323
|
+
const pathSep = path2.sep;
|
|
314
324
|
if (sourceWithoutQuery.endsWith(
|
|
315
325
|
["next", "font", "google", "target.css"].join(pathSep)
|
|
316
326
|
)) {
|
|
@@ -319,17 +329,17 @@ function vitePluginNextFont() {
|
|
|
319
329
|
if (sourceWithoutQuery.endsWith(
|
|
320
330
|
["next", "font", "local", "target.css"].join(pathSep)
|
|
321
331
|
)) {
|
|
322
|
-
const importerDirPath =
|
|
332
|
+
const importerDirPath = path2.dirname(fontOptions.filename);
|
|
323
333
|
const emitFont = async (importerRelativeFontPath) => {
|
|
324
|
-
const fontExtension =
|
|
325
|
-
const fontBaseName =
|
|
334
|
+
const fontExtension = path2.extname(importerRelativeFontPath);
|
|
335
|
+
const fontBaseName = path2.basename(
|
|
326
336
|
importerRelativeFontPath,
|
|
327
337
|
fontExtension
|
|
328
338
|
);
|
|
329
|
-
const fontPath =
|
|
339
|
+
const fontPath = path2.join(importerDirPath, importerRelativeFontPath);
|
|
330
340
|
if (devMode) {
|
|
331
341
|
return {
|
|
332
|
-
fontPath:
|
|
342
|
+
fontPath: path2.join(cwd, fontPath),
|
|
333
343
|
fontReferenceId: void 0
|
|
334
344
|
};
|
|
335
345
|
}
|
|
@@ -576,7 +586,7 @@ var getVitestSWCTransformConfig = ({
|
|
|
576
586
|
swcPlugins: nextConfig.experimental.swcPlugins,
|
|
577
587
|
compiler: nextConfig?.compiler,
|
|
578
588
|
esm: isEsmProject,
|
|
579
|
-
swcCacheDir:
|
|
589
|
+
swcCacheDir: path2.join(
|
|
580
590
|
rootDir,
|
|
581
591
|
nextConfig.distDir ?? ".next",
|
|
582
592
|
"cache",
|
|
@@ -589,7 +599,7 @@ var getVitestSWCTransformConfig = ({
|
|
|
589
599
|
...baseOptions,
|
|
590
600
|
fontLoaders: {
|
|
591
601
|
fontLoaders: ["next/font/local", "next/font/google"],
|
|
592
|
-
relativeFilePathFromRoot:
|
|
602
|
+
relativeFilePathFromRoot: path2.relative(rootDir, filename)
|
|
593
603
|
},
|
|
594
604
|
cjsRequireOptimizer: {
|
|
595
605
|
packages: {
|
|
@@ -655,7 +665,7 @@ function vitePluginNextSwc(rootDir, nextConfigResolver) {
|
|
|
655
665
|
enforce: "pre",
|
|
656
666
|
async config(config, env) {
|
|
657
667
|
const nextConfig = await nextConfigResolver.promise;
|
|
658
|
-
nextDirectories =
|
|
668
|
+
nextDirectories = findNextDirectories(resolvedDir);
|
|
659
669
|
loadedJSConfig = await loadJsConfig(resolvedDir, nextConfig);
|
|
660
670
|
isDev = env.mode !== "production";
|
|
661
671
|
await loadClosestPackageJson(resolvedDir);
|
|
@@ -793,8 +803,8 @@ function vitePluginNextImage(nextConfigResolver) {
|
|
|
793
803
|
return null;
|
|
794
804
|
}
|
|
795
805
|
if (includePattern2.test(source) && !excludeImporterPattern.test(importer ?? "") && !importer?.startsWith(virtualImage)) {
|
|
796
|
-
const isAbsolute =
|
|
797
|
-
const imagePath = importer ? isAbsolute ? source :
|
|
806
|
+
const isAbsolute = path2.isAbsolute(id);
|
|
807
|
+
const imagePath = importer ? isAbsolute ? source : path2.join(path2.dirname(importer), source) : source;
|
|
798
808
|
return `${virtualImage}?imagePath=${imagePath}`;
|
|
799
809
|
}
|
|
800
810
|
if (id === "next/image" && importer !== virtualNextImage) {
|
|
@@ -823,7 +833,7 @@ function vitePluginNextImage(nextConfigResolver) {
|
|
|
823
833
|
if (virtualImage === source) {
|
|
824
834
|
const imagePath = decode(query).imagePath;
|
|
825
835
|
const nextConfig = await nextConfigResolver.promise;
|
|
826
|
-
const extension =
|
|
836
|
+
const extension = path2.extname(imagePath);
|
|
827
837
|
try {
|
|
828
838
|
if (nextConfig.images?.disableStaticImages) {
|
|
829
839
|
return dedent`
|
|
@@ -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>, "
|
|
5
|
+
declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
|
|
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>, "
|
|
5
|
+
declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
|
|
6
6
|
src: string | next_dist_shared_lib_get_img_props.StaticImport;
|
|
7
7
|
alt: string;
|
|
8
8
|
width?: number | `${number}` | undefined;
|
|
@@ -4,7 +4,7 @@ import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies/index.j
|
|
|
4
4
|
|
|
5
5
|
declare class RequestCookiesMock extends RequestCookies {
|
|
6
6
|
get: vitest.Mock<[name: string] | [next_dist_compiled__edge_runtime_cookies.RequestCookie], next_dist_compiled__edge_runtime_cookies.RequestCookie | undefined>;
|
|
7
|
-
getAll: vitest.Mock<[next_dist_compiled__edge_runtime_cookies.RequestCookie] | [name: string]
|
|
7
|
+
getAll: vitest.Mock<[] | [next_dist_compiled__edge_runtime_cookies.RequestCookie] | [name: string], next_dist_compiled__edge_runtime_cookies.RequestCookie[]>;
|
|
8
8
|
has: vitest.Mock<[name: string], boolean>;
|
|
9
9
|
set: vitest.Mock<[key: string, value: string] | [options: next_dist_compiled__edge_runtime_cookies.RequestCookie], this>;
|
|
10
10
|
delete: vitest.Mock<[names: string | string[]], boolean | boolean[]>;
|
|
@@ -4,7 +4,7 @@ import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies/index.j
|
|
|
4
4
|
|
|
5
5
|
declare class RequestCookiesMock extends RequestCookies {
|
|
6
6
|
get: vitest.Mock<[name: string] | [next_dist_compiled__edge_runtime_cookies.RequestCookie], next_dist_compiled__edge_runtime_cookies.RequestCookie | undefined>;
|
|
7
|
-
getAll: vitest.Mock<[next_dist_compiled__edge_runtime_cookies.RequestCookie] | [name: string]
|
|
7
|
+
getAll: vitest.Mock<[] | [next_dist_compiled__edge_runtime_cookies.RequestCookie] | [name: string], next_dist_compiled__edge_runtime_cookies.RequestCookie[]>;
|
|
8
8
|
has: vitest.Mock<[name: string], boolean>;
|
|
9
9
|
set: vitest.Mock<[key: string, value: string] | [options: next_dist_compiled__edge_runtime_cookies.RequestCookie], this>;
|
|
10
10
|
delete: vitest.Mock<[names: string | string[]], boolean | boolean[]>;
|