mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
Merge pull request #28918 from storybookjs/yann/add-sveltekit-portable-stories
SvelteKit: Introduce portable stories support
This commit is contained in:
commit
31c9141ec9
@ -723,7 +723,7 @@ workflows:
|
|||||||
requires:
|
requires:
|
||||||
- build-sandboxes
|
- build-sandboxes
|
||||||
- vitest-integration:
|
- vitest-integration:
|
||||||
parallelism: 4
|
parallelism: 5
|
||||||
requires:
|
requires:
|
||||||
- create-sandboxes
|
- create-sandboxes
|
||||||
- bench:
|
- bench:
|
||||||
@ -789,7 +789,7 @@ workflows:
|
|||||||
requires:
|
requires:
|
||||||
- build-sandboxes
|
- build-sandboxes
|
||||||
- vitest-integration:
|
- vitest-integration:
|
||||||
parallelism: 4
|
parallelism: 5
|
||||||
requires:
|
requires:
|
||||||
- create-sandboxes
|
- create-sandboxes
|
||||||
- test-portable-stories:
|
- test-portable-stories:
|
||||||
@ -856,7 +856,7 @@ workflows:
|
|||||||
requires:
|
requires:
|
||||||
- build-sandboxes
|
- build-sandboxes
|
||||||
- vitest-integration:
|
- vitest-integration:
|
||||||
parallelism: 8
|
parallelism: 11
|
||||||
requires:
|
requires:
|
||||||
- create-sandboxes
|
- create-sandboxes
|
||||||
- test-portable-stories:
|
- test-portable-stories:
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"node": "./dist/index.js",
|
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
|
"node": "./dist/index.js",
|
||||||
"require": "./dist/index.js"
|
"require": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"./dist/preview.mjs": {
|
"./dist/preview.mjs": {
|
||||||
@ -36,6 +36,11 @@
|
|||||||
"types": "./dist/preset.d.ts",
|
"types": "./dist/preset.d.ts",
|
||||||
"require": "./dist/preset.js"
|
"require": "./dist/preset.js"
|
||||||
},
|
},
|
||||||
|
"./vite": {
|
||||||
|
"types": "./dist/vite.d.ts",
|
||||||
|
"require": "./dist/vite.js",
|
||||||
|
"import": "./dist/vite.mjs"
|
||||||
|
},
|
||||||
"./package.json": "./package.json"
|
"./package.json": "./package.json"
|
||||||
},
|
},
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -78,7 +83,8 @@
|
|||||||
"entries": [
|
"entries": [
|
||||||
"./src/index.ts",
|
"./src/index.ts",
|
||||||
"./src/preview.ts",
|
"./src/preview.ts",
|
||||||
"./src/preset.ts"
|
"./src/preset.ts",
|
||||||
|
"./src/vite.ts"
|
||||||
],
|
],
|
||||||
"platform": "node"
|
"platform": "node"
|
||||||
},
|
},
|
||||||
|
5
code/frameworks/sveltekit/src/vite.ts
Normal file
5
code/frameworks/sveltekit/src/vite.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { mockSveltekitStores } from './plugins/mock-sveltekit-stores';
|
||||||
|
|
||||||
|
export const storybookSveltekitPlugin = () => {
|
||||||
|
return [mockSveltekitStores()];
|
||||||
|
};
|
@ -2,6 +2,6 @@
|
|||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form use:enhance>
|
<form use:enhance method="post">
|
||||||
<button>enhance</button>
|
<button>enhance</button>
|
||||||
</form>
|
</form>
|
@ -449,8 +449,7 @@ const baseTemplates = {
|
|||||||
renderer: '@storybook/svelte',
|
renderer: '@storybook/svelte',
|
||||||
builder: '@storybook/builder-vite',
|
builder: '@storybook/builder-vite',
|
||||||
},
|
},
|
||||||
// TODO: remove vitest-integration filter once project annotations exist for sveltekit
|
skipTasks: ['e2e-tests-dev', 'bench'],
|
||||||
skipTasks: ['e2e-tests-dev', 'bench', 'vitest-integration'],
|
|
||||||
},
|
},
|
||||||
'svelte-kit/skeleton-ts': {
|
'svelte-kit/skeleton-ts': {
|
||||||
name: 'SvelteKit Latest (Vite | TypeScript)',
|
name: 'SvelteKit Latest (Vite | TypeScript)',
|
||||||
@ -461,8 +460,7 @@ const baseTemplates = {
|
|||||||
renderer: '@storybook/svelte',
|
renderer: '@storybook/svelte',
|
||||||
builder: '@storybook/builder-vite',
|
builder: '@storybook/builder-vite',
|
||||||
},
|
},
|
||||||
// TODO: remove vitest-integration filter once project annotations exist for sveltekit
|
skipTasks: ['e2e-tests-dev', 'bench'],
|
||||||
skipTasks: ['e2e-tests-dev', 'bench', 'vitest-integration'],
|
|
||||||
},
|
},
|
||||||
'svelte-kit/prerelease-ts': {
|
'svelte-kit/prerelease-ts': {
|
||||||
name: 'SvelteKit Prerelease (Vite | TypeScript)',
|
name: 'SvelteKit Prerelease (Vite | TypeScript)',
|
||||||
@ -473,7 +471,7 @@ const baseTemplates = {
|
|||||||
renderer: '@storybook/svelte',
|
renderer: '@storybook/svelte',
|
||||||
builder: '@storybook/builder-vite',
|
builder: '@storybook/builder-vite',
|
||||||
},
|
},
|
||||||
skipTasks: ['e2e-tests-dev', 'bench', 'vitest-integration'],
|
skipTasks: ['e2e-tests-dev', 'bench'],
|
||||||
},
|
},
|
||||||
'lit-vite/default-js': {
|
'lit-vite/default-js': {
|
||||||
name: 'Lit Latest (Vite | JavaScript)',
|
name: 'Lit Latest (Vite | JavaScript)',
|
||||||
|
@ -360,17 +360,40 @@ async function linkPackageStories(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getVitestPluginInfo = (details: TemplateDetails) => {
|
||||||
|
let frameworkPluginImport = '';
|
||||||
|
let frameworkPluginCall = '';
|
||||||
|
|
||||||
|
const framework = details.template.expected.framework;
|
||||||
|
const isNextjs = framework.includes('nextjs');
|
||||||
|
const isSveltekit = framework.includes('sveltekit');
|
||||||
|
|
||||||
|
if (isNextjs) {
|
||||||
|
frameworkPluginImport = "import vitePluginNext from 'vite-plugin-storybook-nextjs'";
|
||||||
|
frameworkPluginCall = 'vitePluginNext()';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSveltekit) {
|
||||||
|
frameworkPluginImport = "import { storybookSveltekitPlugin } from '@storybook/sveltekit/vite'";
|
||||||
|
frameworkPluginCall = 'storybookSveltekitPlugin()';
|
||||||
|
}
|
||||||
|
|
||||||
|
return { frameworkPluginImport, frameworkPluginCall };
|
||||||
|
};
|
||||||
|
|
||||||
export async function setupVitest(details: TemplateDetails, options: PassedOptionValues) {
|
export async function setupVitest(details: TemplateDetails, options: PassedOptionValues) {
|
||||||
const { sandboxDir, template } = details;
|
const { sandboxDir, template } = details;
|
||||||
|
|
||||||
const isVue = template.expected.renderer === '@storybook/vue3';
|
const isVue = template.expected.renderer === '@storybook/vue3';
|
||||||
const isNextjs = template.expected.framework.includes('nextjs');
|
const isNextjs = template.expected.framework.includes('nextjs');
|
||||||
|
const { frameworkPluginCall, frameworkPluginImport } = getVitestPluginInfo(details);
|
||||||
// const isAngular = template.expected.framework === '@storybook/angular';
|
// const isAngular = template.expected.framework === '@storybook/angular';
|
||||||
|
|
||||||
const portableStoriesFrameworks = [
|
const portableStoriesFrameworks = [
|
||||||
'@storybook/nextjs',
|
'@storybook/nextjs',
|
||||||
'@storybook/experimental-nextjs-vite',
|
'@storybook/experimental-nextjs-vite',
|
||||||
// TODO: add sveltekit and angular once we enable their sandboxes
|
'@storybook/sveltekit',
|
||||||
|
// TODO: add angular once we enable their sandboxes
|
||||||
];
|
];
|
||||||
const storybookPackage = portableStoriesFrameworks.includes(template.expected.framework)
|
const storybookPackage = portableStoriesFrameworks.includes(template.expected.framework)
|
||||||
? template.expected.framework
|
? template.expected.framework
|
||||||
@ -409,7 +432,7 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
|
|||||||
dedent`
|
dedent`
|
||||||
import { defineWorkspace, defaultExclude } from "vitest/config";
|
import { defineWorkspace, defaultExclude } from "vitest/config";
|
||||||
import { storybookTest } from "@storybook/experimental-addon-vitest/plugin";
|
import { storybookTest } from "@storybook/experimental-addon-vitest/plugin";
|
||||||
${isNextjs ? "import vitePluginNext from 'vite-plugin-storybook-nextjs'" : ''}
|
${frameworkPluginImport}
|
||||||
|
|
||||||
export default defineWorkspace([
|
export default defineWorkspace([
|
||||||
{
|
{
|
||||||
@ -421,7 +444,7 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
|
|||||||
include: ["vitest"],
|
include: ["vitest"],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
${isNextjs ? 'vitePluginNext(),' : ''}
|
${frameworkPluginCall}
|
||||||
],
|
],
|
||||||
${
|
${
|
||||||
isNextjs
|
isNextjs
|
||||||
@ -452,14 +475,6 @@ export async function setupVitest(details: TemplateDetails, options: PassedOptio
|
|||||||
...defaultExclude,
|
...defaultExclude,
|
||||||
// TODO: investigate TypeError: Cannot read properties of null (reading 'useContext')
|
// TODO: investigate TypeError: Cannot read properties of null (reading 'useContext')
|
||||||
"**/*argtypes*",
|
"**/*argtypes*",
|
||||||
// TODO (SVELTEKIT): Failures related to missing framework annotations
|
|
||||||
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/navigation.stories*",
|
|
||||||
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/hrefs.stories*",
|
|
||||||
// TODO (SVELTEKIT): Investigate Error: use:enhance can only be used on <form> fields with method="POST"
|
|
||||||
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/forms.stories*",
|
|
||||||
// TODO (SVELTE|SVELTEKIT): Typescript preprocessor issue
|
|
||||||
"**/frameworks/svelte-vite_svelte-vite-default-ts/ts-docs.stories.*",
|
|
||||||
"**/frameworks/sveltekit_svelte-kit-skeleton-ts/ts-docs.stories.*",
|
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* TODO: Either fix or acknowledge limitation of:
|
* TODO: Either fix or acknowledge limitation of:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user