vite-plugin-storybook-nextjs 0.0.13--canary.8.d70ae00.0 → 0.0.13--canary.8.c64d6ac.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/dist/index.cjs +934 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.js +61 -90
- package/dist/mocks/storybook.global.cjs +69 -0
- package/dist/mocks/storybook.global.d.cts +2 -0
- package/dist/mocks/storybook.global.js +40 -17
- package/dist/plugins/next-image/alias/image-context.cjs +8 -0
- package/dist/plugins/next-image/alias/image-context.d.cts +13 -0
- package/dist/plugins/next-image/alias/image-default-loader.cjs +40 -0
- package/dist/plugins/next-image/alias/image-default-loader.d.cts +5 -0
- package/dist/plugins/next-image/alias/next-image.cjs +53 -0
- package/dist/plugins/next-image/alias/next-image.d.cts +30 -0
- package/dist/plugins/next-image/alias/next-image.d.ts +1 -1
- package/dist/plugins/next-image/alias/next-legacy-image.cjs +27 -0
- package/dist/plugins/next-image/alias/next-legacy-image.d.cts +6 -0
- package/dist/plugins/next-mocks/alias/cache/index.d.ts +16 -0
- package/dist/plugins/next-mocks/alias/cache/index.js +18 -0
- package/dist/plugins/next-mocks/alias/headers/cookies.d.ts +14 -0
- package/dist/plugins/next-mocks/alias/headers/cookies.js +72 -0
- package/dist/plugins/next-mocks/alias/headers/headers.d.ts +21 -0
- package/dist/plugins/next-mocks/alias/headers/headers.js +38 -0
- package/dist/plugins/next-mocks/alias/headers/index.d.ts +11 -0
- package/dist/plugins/next-mocks/alias/headers/index.js +70 -0
- package/dist/plugins/next-mocks/alias/navigation/index.d.ts +38 -0
- package/dist/plugins/next-mocks/alias/navigation/index.js +74 -0
- package/dist/plugins/next-mocks/alias/router/index.d.ts +45 -0
- package/dist/plugins/next-mocks/alias/router/index.js +108 -0
- package/dist/plugins/next-mocks/alias/rsc/server-only.d.ts +3 -0
- package/dist/plugins/next-mocks/alias/rsc/server-only.js +4 -0
- package/package.json +21 -17
- /package/dist/{cache → plugins/next-mocks/alias/cache}/index.cjs +0 -0
- /package/dist/{cache → plugins/next-mocks/alias/cache}/index.d.cts +0 -0
- /package/dist/{headers → plugins/next-mocks/alias/headers}/cookies.cjs +0 -0
- /package/dist/{headers → plugins/next-mocks/alias/headers}/cookies.d.cts +0 -0
- /package/dist/{headers → plugins/next-mocks/alias/headers}/headers.cjs +0 -0
- /package/dist/{headers → plugins/next-mocks/alias/headers}/headers.d.cts +0 -0
- /package/dist/{headers → plugins/next-mocks/alias/headers}/index.cjs +0 -0
- /package/dist/{headers → plugins/next-mocks/alias/headers}/index.d.cts +0 -0
- /package/dist/{navigation → plugins/next-mocks/alias/navigation}/index.cjs +0 -0
- /package/dist/{navigation → plugins/next-mocks/alias/navigation}/index.d.cts +0 -0
- /package/dist/{router → plugins/next-mocks/alias/router}/index.cjs +0 -0
- /package/dist/{router → plugins/next-mocks/alias/router}/index.d.cts +0 -0
- /package/dist/{rsc → plugins/next-mocks/alias/rsc}/server-only.cjs +0 -0
- /package/dist/{rsc → plugins/next-mocks/alias/rsc}/server-only.d.cts +0 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type VitePluginOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Provide the path to your Next.js project directory
|
|
6
|
+
* @default process.cwd()
|
|
7
|
+
*/
|
|
8
|
+
dir?: string;
|
|
9
|
+
};
|
|
10
|
+
declare function VitePlugin({ dir }?: VitePluginOptions): Plugin[];
|
|
11
|
+
|
|
12
|
+
export { VitePlugin as default };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import path, { 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
|
-
import
|
|
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
8
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST, PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants.js';
|
|
@@ -21,16 +21,9 @@ import { getParserOptions } from 'next/dist/build/swc/options.js';
|
|
|
21
21
|
import loadConfig from 'next/dist/server/config.js';
|
|
22
22
|
import { cpus } from 'node:os';
|
|
23
23
|
import { decode } from 'node:querystring';
|
|
24
|
-
import { fileURLToPath, URL } from 'node:url';
|
|
25
24
|
import imageSizeOf from 'image-size';
|
|
26
25
|
|
|
27
|
-
|
|
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
|
-
});
|
|
33
|
-
var { loadEnvConfig } = nextEnv;
|
|
26
|
+
// src/index.ts
|
|
34
27
|
var nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/;
|
|
35
28
|
async function loadEnvironmentConfig(dir, dev) {
|
|
36
29
|
return loadEnvConfig(dir, dev, Log);
|
|
@@ -655,7 +648,7 @@ function vitePluginNextSwc(rootDir, nextConfigResolver) {
|
|
|
655
648
|
async config(config, env) {
|
|
656
649
|
const nextConfig = await nextConfigResolver.promise;
|
|
657
650
|
nextDirectories = findPagesDir(resolvedDir);
|
|
658
|
-
loadedJSConfig = await loadJsConfig
|
|
651
|
+
loadedJSConfig = await loadJsConfig(resolvedDir, nextConfig);
|
|
659
652
|
isDev = env.mode !== "production";
|
|
660
653
|
await loadClosestPackageJson(resolvedDir);
|
|
661
654
|
isEsmProject = true;
|
|
@@ -715,16 +708,21 @@ if (typeof Promise.withResolvers === "undefined") {
|
|
|
715
708
|
return { promise, resolve: resolve4, reject };
|
|
716
709
|
};
|
|
717
710
|
}
|
|
711
|
+
|
|
712
|
+
// src/utils.ts
|
|
713
|
+
var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
|
|
714
|
+
var isVitestEnv = process.env.VITEST === "true";
|
|
715
|
+
|
|
716
|
+
// src/plugins/next-image/plugin.ts
|
|
718
717
|
var includePattern2 = /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/;
|
|
719
718
|
var excludeImporterPattern = /\.(css|scss|sass)$/;
|
|
720
719
|
var virtualImage = "virtual:next-image";
|
|
721
720
|
var virtualNextImage = "virtual:next/image";
|
|
722
721
|
var virtualNextLegacyImage = "virtual:next/legacy/image";
|
|
723
|
-
var virtualNextImageDefaultLoader = "virtual:next/image-default-loader";
|
|
724
|
-
var virtualNextImageContext = "virtual:next/image-context";
|
|
725
722
|
var sharp;
|
|
723
|
+
var require3 = createRequire(import.meta.url);
|
|
726
724
|
try {
|
|
727
|
-
sharp =
|
|
725
|
+
sharp = require3("sharp");
|
|
728
726
|
if (sharp && sharp.concurrency() > 1) {
|
|
729
727
|
const divisor = process.env.NODE_ENV === "development" ? 4 : 2;
|
|
730
728
|
sharp.concurrency(Math.floor(Math.max(cpus().length / divisor, 1)));
|
|
@@ -734,12 +732,25 @@ try {
|
|
|
734
732
|
"You have to install sharp in order to use image optimization features in Next.js. AVIF support is also disabled."
|
|
735
733
|
);
|
|
736
734
|
}
|
|
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
|
+
});
|
|
737
740
|
function vitePluginNextImage(nextConfigResolver) {
|
|
741
|
+
let isBrowser = !isVitestEnv;
|
|
738
742
|
return {
|
|
739
743
|
name: "vite-plugin-storybook-nextjs-image",
|
|
740
744
|
enforce: "pre",
|
|
741
745
|
async config(config, env) {
|
|
742
|
-
|
|
746
|
+
if (config.test?.browser?.enabled === true) {
|
|
747
|
+
isBrowser = true;
|
|
748
|
+
}
|
|
749
|
+
return {
|
|
750
|
+
resolve: {
|
|
751
|
+
alias: getAlias(isBrowser ? "browser" : "node")
|
|
752
|
+
}
|
|
753
|
+
};
|
|
743
754
|
},
|
|
744
755
|
async resolveId(id, importer) {
|
|
745
756
|
const [source, queryA] = id.split("?");
|
|
@@ -757,52 +768,19 @@ function vitePluginNextImage(nextConfigResolver) {
|
|
|
757
768
|
if (id === "next/legacy/image" && importer !== virtualNextLegacyImage) {
|
|
758
769
|
return virtualNextLegacyImage;
|
|
759
770
|
}
|
|
760
|
-
if (id === "sb-original/image-context") {
|
|
761
|
-
return virtualNextImageContext;
|
|
762
|
-
}
|
|
763
|
-
if (id === "sb-original/default-loader") {
|
|
764
|
-
return virtualNextImageDefaultLoader;
|
|
765
|
-
}
|
|
766
771
|
return null;
|
|
767
772
|
},
|
|
768
773
|
async load(id) {
|
|
774
|
+
const aliasEnv = isBrowser ? "browser" : "node";
|
|
769
775
|
if (virtualNextImage === id) {
|
|
770
776
|
return (await fs3.promises.readFile(
|
|
771
|
-
|
|
772
|
-
new URL(
|
|
773
|
-
"./plugins/next-image/alias/next-image.js",
|
|
774
|
-
import.meta.url
|
|
775
|
-
)
|
|
776
|
-
)
|
|
777
|
+
require3.resolve(`${VITEST_PLUGIN_NAME}/${aliasEnv}/mocks/image`)
|
|
777
778
|
)).toString("utf-8");
|
|
778
779
|
}
|
|
779
780
|
if (virtualNextLegacyImage === id) {
|
|
780
781
|
return (await fs3.promises.readFile(
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
"./plugins/next-image/alias/next-legacy-image.js",
|
|
784
|
-
import.meta.url
|
|
785
|
-
)
|
|
786
|
-
)
|
|
787
|
-
)).toString("utf-8");
|
|
788
|
-
}
|
|
789
|
-
if (virtualNextImageDefaultLoader === id) {
|
|
790
|
-
return (await fs3.promises.readFile(
|
|
791
|
-
fileURLToPath(
|
|
792
|
-
new URL(
|
|
793
|
-
"./plugins/next-image/alias/image-default-loader.js",
|
|
794
|
-
import.meta.url
|
|
795
|
-
)
|
|
796
|
-
)
|
|
797
|
-
)).toString("utf-8");
|
|
798
|
-
}
|
|
799
|
-
if (virtualNextImageContext === id) {
|
|
800
|
-
return (await fs3.promises.readFile(
|
|
801
|
-
fileURLToPath(
|
|
802
|
-
new URL(
|
|
803
|
-
"./plugins/next-image/alias/image-context.js",
|
|
804
|
-
import.meta.url
|
|
805
|
-
)
|
|
782
|
+
require3.resolve(
|
|
783
|
+
`${VITEST_PLUGIN_NAME}/${aliasEnv}/mocks/legacy-image`
|
|
806
784
|
)
|
|
807
785
|
)).toString("utf-8");
|
|
808
786
|
}
|
|
@@ -849,52 +827,46 @@ function vitePluginNextImage(nextConfigResolver) {
|
|
|
849
827
|
}
|
|
850
828
|
};
|
|
851
829
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
var
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
"
|
|
861
|
-
"
|
|
862
|
-
"
|
|
863
|
-
"
|
|
864
|
-
"
|
|
865
|
-
"@storybook/nextjs/router.mock": getEntryPoint("mocks/router"),
|
|
866
|
-
"next/cache": getEntryPoint("mocks/cache"),
|
|
867
|
-
"@storybook/nextjs/cache.mock": getEntryPoint("mocks/cache"),
|
|
868
|
-
"server-only": getEntryPoint("mocks/server-only"),
|
|
869
|
-
"@opentelemetry/api": require3.resolve(
|
|
830
|
+
var require4 = createRequire(import.meta.url);
|
|
831
|
+
var getEntryPoint2 = (subPath, env) => require4.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
|
|
832
|
+
var getAlias2 = (env) => ({
|
|
833
|
+
"next/headers": getEntryPoint2("headers", env),
|
|
834
|
+
"@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
|
|
835
|
+
"next/navigation": getEntryPoint2("navigation", env),
|
|
836
|
+
"@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
|
|
837
|
+
"next/router": getEntryPoint2("router", env),
|
|
838
|
+
"@storybook/nextjs/router.mock": getEntryPoint2("router", env),
|
|
839
|
+
"next/cache": getEntryPoint2("cache", env),
|
|
840
|
+
"@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
|
|
841
|
+
"server-only": getEntryPoint2("server-only", env),
|
|
842
|
+
"@opentelemetry/api": require4.resolve(
|
|
870
843
|
"next/dist/compiled/@opentelemetry/api/index.js"
|
|
871
844
|
)
|
|
872
|
-
};
|
|
845
|
+
});
|
|
873
846
|
var vitePluginNextMocks = () => ({
|
|
874
847
|
name: "vite-plugin-next-mocks",
|
|
875
|
-
config: () =>
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
848
|
+
config: (env) => {
|
|
849
|
+
const aliasEnv = isVitestEnv && env.test?.browser?.enabled !== true ? "node" : "browser";
|
|
850
|
+
return {
|
|
851
|
+
resolve: {
|
|
852
|
+
alias: getAlias2(aliasEnv)
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
}
|
|
880
856
|
});
|
|
881
857
|
|
|
882
858
|
// src/index.ts
|
|
883
|
-
var
|
|
859
|
+
var require5 = createRequire(import.meta.url);
|
|
884
860
|
function VitePlugin({ dir = process.cwd() } = {}) {
|
|
885
861
|
const resolvedDir = resolve(dir);
|
|
886
862
|
const nextConfigResolver = Promise.withResolvers();
|
|
887
|
-
const isVitestEnv = process.env.VITEST === "true";
|
|
888
863
|
return [
|
|
889
864
|
{
|
|
890
865
|
name: "vite-plugin-storybook-nextjs",
|
|
891
866
|
enforce: "pre",
|
|
892
867
|
async config(config, env) {
|
|
893
868
|
const phase = env.mode === "development" ? PHASE_DEVELOPMENT_SERVER : env.mode === "test" ? PHASE_TEST : PHASE_PRODUCTION_BUILD;
|
|
894
|
-
nextConfigResolver.resolve(
|
|
895
|
-
// @ts-ignore TODO figure out why TypeScript is complaining about this
|
|
896
|
-
await loadConfig.default(phase, resolvedDir)
|
|
897
|
-
);
|
|
869
|
+
nextConfigResolver.resolve(await loadConfig(phase, resolvedDir));
|
|
898
870
|
return {
|
|
899
871
|
...!isVitestEnv && {
|
|
900
872
|
resolve: {
|
|
@@ -906,24 +878,23 @@ function VitePlugin({ dir = process.cwd() } = {}) {
|
|
|
906
878
|
},
|
|
907
879
|
test: {
|
|
908
880
|
alias: {
|
|
909
|
-
"react/jsx-dev-runtime":
|
|
881
|
+
"react/jsx-dev-runtime": require5.resolve(
|
|
910
882
|
"next/dist/compiled/react/jsx-dev-runtime.js"
|
|
911
883
|
),
|
|
912
|
-
"react/jsx-runtime":
|
|
884
|
+
"react/jsx-runtime": require5.resolve(
|
|
913
885
|
"next/dist/compiled/react/jsx-runtime.js"
|
|
914
886
|
),
|
|
915
|
-
react:
|
|
916
|
-
"react-dom/test-utils":
|
|
887
|
+
react: require5.resolve("next/dist/compiled/react"),
|
|
888
|
+
"react-dom/test-utils": require5.resolve(
|
|
917
889
|
"next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
|
|
918
890
|
),
|
|
919
|
-
"react-dom/cjs/react-dom.development.js":
|
|
891
|
+
"react-dom/cjs/react-dom.development.js": require5.resolve(
|
|
920
892
|
"next/dist/compiled/react-dom/cjs/react-dom.development.js"
|
|
921
893
|
),
|
|
922
|
-
"react-dom/client":
|
|
894
|
+
"react-dom/client": require5.resolve(
|
|
923
895
|
"next/dist/compiled/react-dom/client.js"
|
|
924
896
|
),
|
|
925
|
-
"react-dom":
|
|
926
|
-
...alias
|
|
897
|
+
"react-dom": require5.resolve("next/dist/compiled/react-dom")
|
|
927
898
|
}
|
|
928
899
|
}
|
|
929
900
|
};
|
|
@@ -931,7 +902,7 @@ function VitePlugin({ dir = process.cwd() } = {}) {
|
|
|
931
902
|
configResolved(config) {
|
|
932
903
|
if (!config.test?.browser?.enabled) {
|
|
933
904
|
config.test.setupFiles = [
|
|
934
|
-
|
|
905
|
+
require5.resolve("./mocks/storybook.global.js"),
|
|
935
906
|
...config.test?.setupFiles ?? []
|
|
936
907
|
];
|
|
937
908
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var module$1 = require('module');
|
|
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
|
+
|
|
12
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var moduleAlias__default = /*#__PURE__*/_interopDefault(moduleAlias);
|
|
16
|
+
|
|
17
|
+
// src/mocks/storybook.global.ts
|
|
18
|
+
|
|
19
|
+
// src/utils.ts
|
|
20
|
+
var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
|
|
21
|
+
process.env.VITEST === "true";
|
|
22
|
+
|
|
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}`);
|
|
38
|
+
var getAlias = (env) => ({
|
|
39
|
+
"sb-original/default-loader": getEntryPoint("image-default-loader", env),
|
|
40
|
+
"sb-original/image-context": getEntryPoint("image-context", env)
|
|
41
|
+
});
|
|
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}`);
|
|
44
|
+
var getAlias2 = (env) => ({
|
|
45
|
+
"next/headers": getEntryPoint2("headers", env),
|
|
46
|
+
"@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
|
|
47
|
+
"next/navigation": getEntryPoint2("navigation", env),
|
|
48
|
+
"@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
|
|
49
|
+
"next/router": getEntryPoint2("router", env),
|
|
50
|
+
"@storybook/nextjs/router.mock": getEntryPoint2("router", env),
|
|
51
|
+
"next/cache": getEntryPoint2("cache", env),
|
|
52
|
+
"@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
|
|
53
|
+
"server-only": getEntryPoint2("server-only", env),
|
|
54
|
+
"@opentelemetry/api": require3.resolve(
|
|
55
|
+
"next/dist/compiled/@opentelemetry/api/index.js"
|
|
56
|
+
)
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// 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)));
|
|
61
|
+
moduleAlias__default.default.addAliases({
|
|
62
|
+
react: "next/dist/compiled/react",
|
|
63
|
+
"react-dom/test-utils": require4.resolve(
|
|
64
|
+
"next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
|
|
65
|
+
),
|
|
66
|
+
"react-dom": "next/dist/compiled/react-dom",
|
|
67
|
+
...getAlias2("node"),
|
|
68
|
+
...getAlias("node")
|
|
69
|
+
});
|
|
@@ -1,36 +1,59 @@
|
|
|
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';
|
|
3
6
|
|
|
4
7
|
// src/mocks/storybook.global.ts
|
|
5
8
|
|
|
6
9
|
// src/utils.ts
|
|
7
10
|
var VITEST_PLUGIN_NAME = "vite-plugin-storybook-nextjs";
|
|
11
|
+
process.env.VITEST === "true";
|
|
8
12
|
|
|
9
|
-
// src/plugins/next-
|
|
10
|
-
var
|
|
13
|
+
// src/plugins/next-image/plugin.ts
|
|
14
|
+
var sharp;
|
|
11
15
|
var require2 = createRequire(import.meta.url);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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}`);
|
|
28
|
+
var getAlias = (env) => ({
|
|
29
|
+
"sb-original/default-loader": getEntryPoint("image-default-loader", env),
|
|
30
|
+
"sb-original/image-context": getEntryPoint("image-context", env)
|
|
31
|
+
});
|
|
32
|
+
var require3 = createRequire(import.meta.url);
|
|
33
|
+
var getEntryPoint2 = (subPath, env) => require3.resolve(`${VITEST_PLUGIN_NAME}/${env}/mocks/${subPath}`);
|
|
34
|
+
var getAlias2 = (env) => ({
|
|
35
|
+
"next/headers": getEntryPoint2("headers", env),
|
|
36
|
+
"@storybook/nextjs/headers.mock": getEntryPoint2("headers", env),
|
|
37
|
+
"next/navigation": getEntryPoint2("navigation", env),
|
|
38
|
+
"@storybook/nextjs/navigation.mock": getEntryPoint2("navigation", env),
|
|
39
|
+
"next/router": getEntryPoint2("router", env),
|
|
40
|
+
"@storybook/nextjs/router.mock": getEntryPoint2("router", env),
|
|
41
|
+
"next/cache": getEntryPoint2("cache", env),
|
|
42
|
+
"@storybook/nextjs/cache.mock": getEntryPoint2("cache", env),
|
|
43
|
+
"server-only": getEntryPoint2("server-only", env),
|
|
44
|
+
"@opentelemetry/api": require3.resolve(
|
|
23
45
|
"next/dist/compiled/@opentelemetry/api/index.js"
|
|
24
46
|
)
|
|
25
|
-
};
|
|
47
|
+
});
|
|
26
48
|
|
|
27
49
|
// src/mocks/storybook.global.ts
|
|
28
|
-
var
|
|
50
|
+
var require4 = createRequire(import.meta.url);
|
|
29
51
|
moduleAlias.addAliases({
|
|
30
52
|
react: "next/dist/compiled/react",
|
|
31
|
-
"react-dom/test-utils":
|
|
53
|
+
"react-dom/test-utils": require4.resolve(
|
|
32
54
|
"next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
|
|
33
55
|
),
|
|
34
56
|
"react-dom": "next/dist/compiled/react-dom",
|
|
35
|
-
...
|
|
57
|
+
...getAlias2("node"),
|
|
58
|
+
...getAlias("node")
|
|
36
59
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'next/dist/compiled/react';
|
|
2
|
+
import { ImageProps, StaticImageData } from 'next/image';
|
|
3
|
+
import { ImageProps as ImageProps$1 } from 'next/legacy/image';
|
|
4
|
+
|
|
5
|
+
interface StaticRequire {
|
|
6
|
+
default: StaticImageData;
|
|
7
|
+
}
|
|
8
|
+
declare type StaticImport = StaticRequire | StaticImageData;
|
|
9
|
+
declare const ImageContext: React.Context<Partial<Omit<ImageProps, "src"> & {
|
|
10
|
+
src: string | StaticImport;
|
|
11
|
+
}> & Omit<ImageProps$1, "src">>;
|
|
12
|
+
|
|
13
|
+
export { ImageContext };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/plugins/next-image/alias/image-default-loader.tsx
|
|
4
|
+
var defaultLoader = ({
|
|
5
|
+
src,
|
|
6
|
+
width,
|
|
7
|
+
quality = 75
|
|
8
|
+
}) => {
|
|
9
|
+
const missingValues = [];
|
|
10
|
+
if (!src) {
|
|
11
|
+
missingValues.push("src");
|
|
12
|
+
}
|
|
13
|
+
if (!width) {
|
|
14
|
+
missingValues.push("width");
|
|
15
|
+
}
|
|
16
|
+
if (missingValues.length > 0) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Next Image Optimization requires ${missingValues.join(
|
|
19
|
+
", "
|
|
20
|
+
)} to be provided. Make sure you pass them as props to the \`next/image\` component. Received: ${JSON.stringify(
|
|
21
|
+
{
|
|
22
|
+
src,
|
|
23
|
+
width,
|
|
24
|
+
quality
|
|
25
|
+
}
|
|
26
|
+
)}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const url = new URL(src, window.location.href);
|
|
30
|
+
if (!url.searchParams.has("w") && !url.searchParams.has("q")) {
|
|
31
|
+
url.searchParams.set("w", width.toString());
|
|
32
|
+
url.searchParams.set("q", quality.toString());
|
|
33
|
+
}
|
|
34
|
+
if (!src.startsWith("http://") && !src.startsWith("https://")) {
|
|
35
|
+
return url.toString().slice(url.origin.length);
|
|
36
|
+
}
|
|
37
|
+
return url.toString();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.defaultLoader = defaultLoader;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var NextImageNamespace = require('next/image');
|
|
6
|
+
var defaultLoader = require('sb-original/default-loader');
|
|
7
|
+
var imageContext = require('sb-original/image-context');
|
|
8
|
+
var React = require('next/dist/compiled/react');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
function _interopNamespace(e) {
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var NextImageNamespace__namespace = /*#__PURE__*/_interopNamespace(NextImageNamespace);
|
|
31
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
32
|
+
|
|
33
|
+
// src/plugins/next-image/alias/next-image.tsx
|
|
34
|
+
var OriginalNextImage = NextImageNamespace__namespace.default;
|
|
35
|
+
var { getImageProps: originalGetImageProps } = NextImageNamespace__namespace;
|
|
36
|
+
var MockedNextImage = React__default.default.forwardRef(({ loader, ...props }, ref) => {
|
|
37
|
+
const imageParameters = React__default.default.useContext(imageContext.ImageContext);
|
|
38
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
|
39
|
+
OriginalNextImage,
|
|
40
|
+
{
|
|
41
|
+
ref,
|
|
42
|
+
...imageParameters,
|
|
43
|
+
...props,
|
|
44
|
+
loader: loader ?? defaultLoader.defaultLoader
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
MockedNextImage.displayName = "NextImage";
|
|
49
|
+
var getImageProps = (props) => originalGetImageProps?.({ loader: defaultLoader.defaultLoader, ...props });
|
|
50
|
+
var next_image_default = MockedNextImage;
|
|
51
|
+
|
|
52
|
+
exports.default = next_image_default;
|
|
53
|
+
exports.getImageProps = getImageProps;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-img-props';
|
|
2
|
+
import * as _NextImage from 'next/image';
|
|
3
|
+
import React__default from 'next/dist/compiled/react';
|
|
4
|
+
|
|
5
|
+
declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
|
|
6
|
+
src: string | next_dist_shared_lib_get_img_props.StaticImport;
|
|
7
|
+
alt: string;
|
|
8
|
+
width?: number | `${number}` | undefined;
|
|
9
|
+
height?: number | `${number}` | undefined;
|
|
10
|
+
fill?: boolean | undefined;
|
|
11
|
+
loader?: _NextImage.ImageLoader | undefined;
|
|
12
|
+
quality?: number | `${number}` | undefined;
|
|
13
|
+
priority?: boolean | undefined;
|
|
14
|
+
loading?: "lazy" | "eager" | undefined;
|
|
15
|
+
placeholder?: next_dist_shared_lib_get_img_props.PlaceholderValue | undefined;
|
|
16
|
+
blurDataURL?: string | undefined;
|
|
17
|
+
unoptimized?: boolean | undefined;
|
|
18
|
+
overrideSrc?: string | undefined;
|
|
19
|
+
onLoadingComplete?: next_dist_shared_lib_get_img_props.OnLoadingComplete | undefined;
|
|
20
|
+
layout?: string | undefined;
|
|
21
|
+
objectFit?: string | undefined;
|
|
22
|
+
objectPosition?: string | undefined;
|
|
23
|
+
lazyBoundary?: string | undefined;
|
|
24
|
+
lazyRoot?: string | undefined;
|
|
25
|
+
} & React__default.RefAttributes<HTMLImageElement>>;
|
|
26
|
+
declare const getImageProps: (props: _NextImage.ImageProps) => {
|
|
27
|
+
props: next_dist_shared_lib_get_img_props.ImgProps;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { MockedNextImage as default, getImageProps };
|
|
@@ -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;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var OriginalNextLegacyImage = require('next/legacy/image');
|
|
4
|
+
var defaultLoader = require('sb-original/default-loader');
|
|
5
|
+
var imageContext = require('sb-original/image-context');
|
|
6
|
+
var React = require('next/dist/compiled/react');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var OriginalNextLegacyImage__default = /*#__PURE__*/_interopDefault(OriginalNextLegacyImage);
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
12
|
+
|
|
13
|
+
// src/plugins/next-image/alias/next-legacy-image.tsx
|
|
14
|
+
function NextLegacyImage({ loader, ...props }) {
|
|
15
|
+
const imageParameters = React__default.default.useContext(imageContext.ImageContext);
|
|
16
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
|
17
|
+
OriginalNextLegacyImage__default.default,
|
|
18
|
+
{
|
|
19
|
+
...imageParameters,
|
|
20
|
+
...props,
|
|
21
|
+
loader: loader ?? defaultLoader.defaultLoader
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
var next_legacy_image_default = NextLegacyImage;
|
|
26
|
+
|
|
27
|
+
module.exports = next_legacy_image_default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React__default from 'next/dist/compiled/react';
|
|
2
|
+
import * as _NextLegacyImage from 'next/legacy/image';
|
|
3
|
+
|
|
4
|
+
declare function NextLegacyImage({ loader, ...props }: _NextLegacyImage.ImageProps): React__default.JSX.Element;
|
|
5
|
+
|
|
6
|
+
export { NextLegacyImage as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
7
|
+
declare const revalidatePath: vitest.Mock<any, any>;
|
|
8
|
+
declare const revalidateTag: vitest.Mock<any, any>;
|
|
9
|
+
declare const cacheExports: {
|
|
10
|
+
unstable_cache: typeof unstable_cache;
|
|
11
|
+
revalidateTag: vitest.Mock<any, any>;
|
|
12
|
+
revalidatePath: vitest.Mock<any, any>;
|
|
13
|
+
unstable_noStore: typeof unstable_noStore;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { cacheExports as default, revalidatePath, revalidateTag };
|