Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SvelteKit: Automigration #20094

Merged
merged 23 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
11ba2d3
add initial sveltekit migraiton based on nextjs PR
JReinhold Dec 2, 2022
70f46a9
working tests
JReinhold Dec 3, 2022
8e4bb12
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/sv…
JReinhold Dec 3, 2022
599f270
fix test
JReinhold Dec 5, 2022
353e1f1
add more tests
JReinhold Dec 6, 2022
506bf2f
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/sv…
JReinhold Dec 6, 2022
8014d48
add migration docs around svelteOptions
JReinhold Dec 6, 2022
f21b170
handle 6.5 svelte vite setups - before newFrameworks fix
JReinhold Dec 6, 2022
d26a1c2
typos
JReinhold Dec 6, 2022
ce21620
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/sv…
JReinhold Dec 6, 2022
3519a53
remove comment about migrating types
JReinhold Dec 6, 2022
20bcbbc
fix missing dependency in sveltekit framework
JReinhold Dec 6, 2022
ec24aaa
Merge branch 'next' into jeppe/sveltekit-framework-automigration
JReinhold Dec 6, 2022
20e364e
add @storybook/svelte to lockfile
JReinhold Dec 6, 2022
aca2484
Merge branch 'jeppe/sveltekit-framework-automigration' of github.com:…
JReinhold Dec 6, 2022
66fa6ac
simplify tests to make them pass CI
JReinhold Dec 7, 2022
43b56e4
Merge branch 'next' of github.com:storybookjs/storybook into jeppe/sv…
JReinhold Dec 7, 2022
2d2ea59
Merge branch 'next' into jeppe/sveltekit-framework-automigration
JReinhold Dec 8, 2022
ec1bd98
Apply suggestions from code review
JReinhold Dec 9, 2022
1a38dd2
don't remove @storybook/svelte renderer
JReinhold Dec 9, 2022
37b69a0
Merge branch 'jeppe/sveltekit-framework-automigration' of github.com:…
JReinhold Dec 9, 2022
52c87ee
implement ConfigFile.removeField and use it, run SK migration before …
JReinhold Dec 9, 2022
caf0643
Merge branch 'next' into jeppe/sveltekit-framework-automigration
shilman Dec 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ When using a [Vite-based framework](#framework-field-mandatory), Storybook will
Some settings will be overridden by storybook so that it can function properly, and the merged settings can be modified using `viteFinal` in `.storybook/main.js` (see the [Storybook Vite configuration docs](https://storybook.js.org/docs/react/builders/vite#configuration)).
If you were using `viteFinal` in 6.5 to simply merge in your project's standard vite config, you can now remove it.

For Svelte projects this means that the `svelteOptions` property in the `main.js` config can be omitted in most cases, as it will be loaded automatically via the project's `vite.config.js`. An exception to this is when the project needs different Svelte options for Storybook than the Vite config provides for the application itself.

#### Vite cache moved to node_modules/.cache/.vite-storybook

Previously, Storybook's Vite builder placed cache files in node_modules/.vite-storybook. However, it's more common for tools to place cached files into `node_modules/.cache`, and putting them there makes it quick and easy to clear the cache for multiple tools at once. We don't expect this change will cause any problems, but it's something that users of Storybook Vite projects should know about. It can be configured by setting `cacheDir` in `viteFinal` within `.storybook/main.js` [Storybook Vite configuration docs](https://storybook.js.org/docs/react/builders/vite#configuration)).
Expand All @@ -601,6 +603,8 @@ export default {
};
```

Also see the note in [Vite builder uses vite config automatically](#vite-builder-uses-vite-config-automatically) about removing `svelteOptions`.

#### Removed docs.getContainer and getPage parameters

It is no longer possible to set `parameters.docs.getContainer()` and `getPage()`. Instead use `parameters.docs.container` or `parameters.docs.page` directly.
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"dependencies": {
"@storybook/builder-vite": "7.0.0-alpha.62",
"@storybook/svelte": "7.0.0-alpha.62",
"@storybook/svelte-vite": "7.0.0-alpha.62"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions code/lib/cli/src/automigrate/fixes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { newFrameworks } from './new-frameworks';
import { removedGlobalClientAPIs } from './remove-global-client-apis';
import { mdx1to2 } from './mdx-1-to-2';
import { docsPageAutomatic } from './docsPage-automatic';
import { sveltekitFramework } from './sveltekit-framework';
import { addReact } from './add-react';

export * from '../types';
Expand All @@ -23,6 +24,7 @@ export const fixes: Fix[] = [
vue3,
mainjsFramework,
eslintPlugin,
sveltekitFramework,
builderVite,
sbScripts,
newFrameworks,
Expand Down
3 changes: 1 addition & 2 deletions code/lib/cli/src/automigrate/fixes/new-frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ export const newFrameworks: Fix<NewFrameworkRunOptions> = {

if (currentCore) {
if (Object.keys(currentCore).length === 0) {
// TODO: this should delete the field instead
main.setFieldValue(['core'], {});
main.removeField(['core']);
} else {
main.setFieldValue(['core'], currentCore);
}
Expand Down
174 changes: 174 additions & 0 deletions code/lib/cli/src/automigrate/fixes/sveltekit-framework.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/* eslint-disable no-underscore-dangle */
import type { StorybookConfig } from 'lib/types/src';
import path from 'path';
import type { JsPackageManager, PackageJson } from '../../js-package-manager';
import { sveltekitFramework } from './sveltekit-framework';

// eslint-disable-next-line global-require, jest/no-mocks-import
jest.mock('fs-extra', () => require('../../../../../__mocks__/fs-extra'));

const checkSvelteKitFramework = async ({
packageJson,
main,
}: {
packageJson: PackageJson;
main?: Partial<StorybookConfig>;
}) => {
if (main) {
// eslint-disable-next-line global-require
require('fs-extra').__setMockFiles({
[path.join('.storybook', 'main.js')]: `module.exports = ${JSON.stringify(main)};`,
});
} else {
// eslint-disable-next-line global-require
require('fs-extra').__setMockFiles({});
}
const packageManager = {
retrievePackageJson: () => ({ dependencies: {}, devDependencies: {}, ...packageJson }),
} as JsPackageManager;

return sveltekitFramework.check({ packageManager });
};

describe('SvelteKit framework fix', () => {
describe('should no-op', () => {
it('in SB < v7.0.0', async () => {
const packageJson = {
dependencies: { '@sveltejs/kit': '^1.0.0-next.571', '@storybook/svelte': '^6.2.0' },
};
const main = { framework: '@storybook/svelte-vite' };
await expect(checkSvelteKitFramework({ packageJson, main })).resolves.toBeFalsy();
});

describe('in SB >= v7.0.0', () => {
it('in non-SvelteKit projects', async () => {
const packageJson = {
dependencies: { svelte: '^3.53.1', '@storybook/svelte-vite': '^7.0.0' },
};
const main = {
framework: '@storybook/svelte-vite',
};
await expect(checkSvelteKitFramework({ packageJson, main })).resolves.toBeFalsy();
});

it('without main', async () => {
const packageJson = {
dependencies: { '@sveltejs/kit': '^1.0.0-next.571', '@storybook/svelte': '^7.0.0' },
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
};
await expect(checkSvelteKitFramework({ packageJson })).rejects.toThrow();
});

it('without framework field in main', async () => {
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
const packageJson = {
dependencies: { '@sveltejs/kit': '^1.0.0-next.571', '@storybook/svelte': '^7.0.0' },
};
const main = {};
await expect(checkSvelteKitFramework({ packageJson, main })).rejects.toThrow();
});

it('with unsupported framework', async () => {
const packageJson = {
dependencies: {
'@sveltejs/kit': '^1.0.0-next.571',
'@storybook/svelte-vite': '^7.0.0',
'@storybook/html': '^7.0.0',
},
};
const main = {
framework: '@storybook/html',
};
await expect(checkSvelteKitFramework({ packageJson, main })).rejects.toThrow();
});

it('with unsupported framework+builder from SB 6.5', async () => {
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
const packageJson = {
dependencies: {
'@sveltejs/kit': '^1.0.0-next.571',
'@storybook/svelte-webpack5': '^7.0.0',
'@storybook/svelte': '^7.0.0',
},
};
const main = {
framework: '@storybook/svelte',
core: { builder: '@storybook/builder-webpack5' },
};
await expect(checkSvelteKitFramework({ packageJson, main })).rejects.toThrow();
});

it('with @storybook/svelte-webpack5 framework', async () => {
JReinhold marked this conversation as resolved.
Show resolved Hide resolved
const packageJson = {
dependencies: {
'@storybook/svelte': '^7.0.0',
'@storybook/svelte-webpack5': '^7.0.0',
'@sveltejs/kit': '^1.0.0-next.571',
},
};
const main = {
framework: '@storybook/svelte-webpack5',
};
await expect(checkSvelteKitFramework({ packageJson, main })).rejects.toThrow();
});
});
});

describe('should migrate', () => {
it('from @storybook/svelte-vite', async () => {
const packageJson = {
dependencies: {
'@storybook/svelte': '^7.0.0',
'@storybook/svelte-vite': '^7.0.0',
'@sveltejs/kit': '^1.0.0-next.571',
},
};
const main = {
framework: '@storybook/svelte-vite',
};
await expect(checkSvelteKitFramework({ packageJson, main })).resolves.toMatchObject({
packageJson,
main: expect.objectContaining({}),
frameworkOptions: undefined,
dependenciesToRemove: ['@storybook/svelte-vite'],
});
});

it('from @storybook/svelte framework and @storybook/builder-vite builder', async () => {
const packageJson = {
dependencies: {
'@storybook/svelte': '^7.0.0',
'@storybook/builder-vite': '^7.0.0',
'@sveltejs/kit': '^1.0.0-next.571',
},
};
const main = {
framework: '@storybook/svelte',
core: { builder: '@storybook/builder-vite' },
};
await expect(checkSvelteKitFramework({ packageJson, main })).resolves.toMatchObject({
packageJson,
main: expect.objectContaining({}),
frameworkOptions: undefined,
dependenciesToRemove: ['@storybook/builder-vite'],
});
});

it('from @storybook/svelte framework and storybook-builder-vite builder', async () => {
const packageJson = {
dependencies: {
'@storybook/svelte': '^7.0.0',
'storybook-builder-vite': '^0.2.5',
'@sveltejs/kit': '^1.0.0-next.571',
},
};
const main = {
framework: '@storybook/svelte',
core: { builder: 'storybook-builder-vite' },
};
await expect(checkSvelteKitFramework({ packageJson, main })).resolves.toMatchObject({
packageJson,
main: expect.objectContaining({}),
frameworkOptions: undefined,
dependenciesToRemove: ['storybook-builder-vite'],
});
});
});
});
Loading