mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Merge branch 'next' into fix(23454)-raw-button-contrast-ratio
This commit is contained in:
commit
2c264f1a6c
@ -84,7 +84,7 @@ commands:
|
||||
jobs:
|
||||
pretty-docs:
|
||||
executor:
|
||||
class: small
|
||||
class: medium
|
||||
name: sb_node_16_classic
|
||||
steps:
|
||||
- git-shallow-clone/checkout_advanced:
|
||||
@ -92,7 +92,7 @@ jobs:
|
||||
- restore_cache:
|
||||
name: Restore Yarn cache
|
||||
keys:
|
||||
- prettydocs-yarn-2-cache-v4--{{ checksum "code/yarn.lock" }}--{{ checksum "scripts/yarn.lock" }}
|
||||
- prettydocs-yarn-2-cache-v7--{{ checksum "code/yarn.lock" }}--{{ checksum "scripts/yarn.lock" }}
|
||||
- run:
|
||||
name: Install
|
||||
command: |
|
||||
@ -100,7 +100,7 @@ jobs:
|
||||
yarn install
|
||||
- save_cache:
|
||||
name: Save Yarn cache
|
||||
key: prettydocs-yarn-2-cache-v4--{{ checksum "code/yarn.lock" }}--{{ checksum "scripts/yarn.lock" }}
|
||||
key: prettydocs-yarn-2-cache-v7--{{ checksum "code/yarn.lock" }}--{{ checksum "scripts/yarn.lock" }}
|
||||
paths:
|
||||
- ~/.yarn/berry/cache
|
||||
- run:
|
||||
@ -499,11 +499,11 @@ workflows:
|
||||
requires:
|
||||
- unit-tests
|
||||
- create-sandboxes:
|
||||
parallelism: 12
|
||||
parallelism: 14
|
||||
requires:
|
||||
- build
|
||||
- build-sandboxes:
|
||||
parallelism: 12
|
||||
parallelism: 14
|
||||
requires:
|
||||
- create-sandboxes
|
||||
- chromatic-sandboxes:
|
||||
@ -523,7 +523,7 @@ workflows:
|
||||
requires:
|
||||
- build-sandboxes
|
||||
- bench:
|
||||
parallelism: 3
|
||||
parallelism: 5
|
||||
requires:
|
||||
- build-sandboxes
|
||||
# TODO: reenable once we find out the source of flakyness
|
||||
@ -555,11 +555,11 @@ workflows:
|
||||
requires:
|
||||
- unit-tests
|
||||
- create-sandboxes:
|
||||
parallelism: 21
|
||||
parallelism: 23
|
||||
requires:
|
||||
- build
|
||||
- build-sandboxes:
|
||||
parallelism: 21
|
||||
parallelism: 23
|
||||
requires:
|
||||
- create-sandboxes
|
||||
- chromatic-sandboxes:
|
||||
@ -579,7 +579,7 @@ workflows:
|
||||
requires:
|
||||
- build-sandboxes
|
||||
- bench:
|
||||
parallelism: 3
|
||||
parallelism: 5
|
||||
requires:
|
||||
- build-sandboxes
|
||||
# TODO: reenable once we find out the source of flakyness
|
||||
@ -609,14 +609,14 @@ workflows:
|
||||
requires:
|
||||
- build
|
||||
- create-sandboxes:
|
||||
parallelism: 36
|
||||
parallelism: 38
|
||||
requires:
|
||||
- build
|
||||
# - smoke-test-sandboxes: # disabled for now
|
||||
# requires:
|
||||
# - create-sandboxes
|
||||
- build-sandboxes:
|
||||
parallelism: 36
|
||||
parallelism: 38
|
||||
requires:
|
||||
- create-sandboxes
|
||||
- chromatic-sandboxes:
|
||||
@ -640,3 +640,4 @@ workflows:
|
||||
# parallelism: 4
|
||||
# requires:
|
||||
# - create-sandboxes
|
||||
|
||||
|
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
@ -163,7 +163,7 @@ jobs:
|
||||
yarn release:ensure-next-ahead --main-version "${{ steps.version.outputs.current-version }}"
|
||||
|
||||
git add ..
|
||||
git commit -m "Bump next to be one minor ahead of main [skip ci]"
|
||||
git diff --staged --quiet || git commit -m "Bump next to be one minor ahead of main [skip ci]"
|
||||
git push origin next
|
||||
|
||||
- name: Sync CHANGELOG.md from `main` to `next`
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@ test-results
|
||||
!/**/.yarn/plugins
|
||||
!/**/.yarn/sdks
|
||||
!/**/.yarn/versions
|
||||
!/**/.yarn/patches
|
||||
/**/.pnp.*
|
||||
!/node_modules
|
||||
|
||||
|
28
.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
generated
vendored
28
.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
generated
vendored
File diff suppressed because one or more lines are too long
873
.yarn/releases/yarn-3.5.1.cjs
generated
vendored
873
.yarn/releases/yarn-3.5.1.cjs
generated
vendored
File diff suppressed because one or more lines are too long
893
.yarn/releases/yarn-4.0.0.cjs
generated
vendored
Executable file
893
.yarn/releases/yarn-4.0.0.cjs
generated
vendored
Executable file
File diff suppressed because one or more lines are too long
10
.yarnrc.yml
10
.yarnrc.yml
@ -1,11 +1,11 @@
|
||||
compressionLevel: mixed
|
||||
|
||||
enableGlobalCache: false
|
||||
|
||||
installStatePath: ./.yarn/root-install-state.gz
|
||||
|
||||
nodeLinker: node-modules
|
||||
|
||||
npmPublishAccess: public
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
|
||||
spec: "@yarnpkg/plugin-workspace-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.5.1.cjs
|
||||
yarnPath: .yarn/releases/yarn-4.0.0.cjs
|
||||
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,3 +1,14 @@
|
||||
## 7.5.2
|
||||
|
||||
- Addon-themes: Fix globals not being set when using absolute path - [#24596](https://github.com/storybookjs/storybook/pull/24596), thanks [@JReinhold](https://github.com/JReinhold)!
|
||||
- CLI: Allow Yarn v4 in `link` command - [#24551](https://github.com/storybookjs/storybook/pull/24551), thanks [@yannbf](https://github.com/yannbf)!
|
||||
- Next.js: Support v14.0.0 - [#24593](https://github.com/storybookjs/storybook/pull/24593), thanks [@nikospapcom](https://github.com/nikospapcom)!
|
||||
|
||||
## 7.5.1
|
||||
|
||||
- Angular: update wrong type for webpackStatsJson in start-storybook schema.json - [#24494](https://github.com/storybookjs/storybook/pull/24494), thanks [@LucaVazz](https://github.com/LucaVazz)!
|
||||
- Themes: Run postinstall in shell for windows - [#24389](https://github.com/storybookjs/storybook/pull/24389), thanks [@Integrayshaun](https://github.com/Integrayshaun)!
|
||||
|
||||
## 7.5.0
|
||||
|
||||
Storybook 7.5 enhances your Storybook experience with several key updates:
|
||||
|
@ -1,3 +1,22 @@
|
||||
## 7.6.0-alpha.3
|
||||
|
||||
- Action: Attach spies on actions across stories when defined in meta - [#24451](https://github.com/storybookjs/storybook/pull/24451), thanks [@kasperpeulen](https://github.com/kasperpeulen)!
|
||||
- Addon A11y: Avoid CSP issue - [#24477](https://github.com/storybookjs/storybook/pull/24477), thanks [@Marklb](https://github.com/Marklb)!
|
||||
- Addon-themes: Fix globals not being set when using absolute path - [#24596](https://github.com/storybookjs/storybook/pull/24596), thanks [@JReinhold](https://github.com/JReinhold)!
|
||||
- CLI: Allow Yarn v4 in `link` command - [#24551](https://github.com/storybookjs/storybook/pull/24551), thanks [@yannbf](https://github.com/yannbf)!
|
||||
- Core-Server: Ignore all node_module folders for watchpack - [#24553](https://github.com/storybookjs/storybook/pull/24553), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
|
||||
- Core: Fix pnp support when cache dir is outside working dir - [#24572](https://github.com/storybookjs/storybook/pull/24572), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
|
||||
- Manager: Update `store.settings.lastTrackedStoryId` - [#24115](https://github.com/storybookjs/storybook/pull/24115), thanks [@rashidshamloo](https://github.com/rashidshamloo)!
|
||||
- Next.js: Support v14.0.0 - [#24593](https://github.com/storybookjs/storybook/pull/24593), thanks [@nikospapcom](https://github.com/nikospapcom)!
|
||||
- Test: Create @storybook/test package based on vitest - [#24392](https://github.com/storybookjs/storybook/pull/24392), thanks [@kasperpeulen](https://github.com/kasperpeulen)!
|
||||
|
||||
## 7.6.0-alpha.2
|
||||
|
||||
- Actions: Fix missing crypto module crashing React Native - [#24546](https://github.com/storybookjs/storybook/pull/24546), thanks [@dannyhw](https://github.com/dannyhw)!
|
||||
- Core: Fix post message channel location.search access for React Native - [#24545](https://github.com/storybookjs/storybook/pull/24545), thanks [@dannyhw](https://github.com/dannyhw)!
|
||||
- ManagerBuilder: Fix `"type": "commonjs"` compatibility - [#24534](https://github.com/storybookjs/storybook/pull/24534), thanks [@ndelangen](https://github.com/ndelangen)!
|
||||
- React: Upgrade `react-docgen` to v7 - [#24530](https://github.com/storybookjs/storybook/pull/24530), thanks [@shilman](https://github.com/shilman)!
|
||||
|
||||
## 7.6.0-alpha.1
|
||||
|
||||
- Angular: Add source-map option to builder - [#24466](https://github.com/storybookjs/storybook/pull/24466), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
|
||||
|
@ -29,6 +29,7 @@
|
||||
/code/addons/storyshots-core/ @ndelangen
|
||||
/code/addons/storyshots-puppeteer/ @ndelangen
|
||||
/code/addons/storysource/ @ndelangen
|
||||
/code/addons/themes/ @JReinhold @Integrayshaun
|
||||
/code/addons/toolbars/ @ndelangen @JReinhold
|
||||
/code/addons/viewport/ @yannbf @ndelangen
|
||||
|
||||
|
@ -476,7 +476,7 @@ No process is defined for this.
|
||||
|
||||
### Merges to `main` without versioning
|
||||
|
||||
As described in more details in [the Patch Releases section](#patch-releases), there are scenarios where you want to patch [unreleasable](#which-changes-are-considered-releasable-and-what-does-it-mean) content back to `main` without bumping versions or publishing a new release. This happens automatically as long as all the unpicked patch pull requests have unreleasable labels. In that case the prepared patch pull request will change form slighty, to just cherry-picking the patches without bumping the versions.
|
||||
As described in more details in [the Patch Releases section](#patch-releases), there are scenarios where you want to patch [unreleasable](#which-changes-are-considered-releasable-and-what-does-it-mean) content back to `main` without bumping versions or publishing a new release. This happens automatically as long as all the unpicked patch pull requests have unreleasable labels. In that case the prepared patch pull request will change form slightly, to just cherry-picking the patches without bumping the versions.
|
||||
|
||||
## FAQ
|
||||
|
||||
|
@ -9,3 +9,7 @@ svelte-check@3.4.6 (bug: 3.5.x): Type issues
|
||||
## code/ui/components/package.json
|
||||
|
||||
overlayscrollbars@2.2.1 (bug: 2.3.x): The Scrollbar doesn't disappear anymore by default. It might has something to do with the `scrollbars.autoHideSuspend` option, which was introduced in 2.3.0. https://github.com/KingSora/OverlayScrollbars/blob/master/packages/overlayscrollbars/CHANGELOG.md#230
|
||||
|
||||
## code/package.json
|
||||
|
||||
@babel/core@^7.23.2: Make sure we use the latest version of @babel/traverse, which is a dependency of @babel/core, since it contains a fix for a vulnerability: https://security.snyk.io/vuln/SNYK-JS-BABELTRAVERSE-5962462
|
||||
|
1
code/.gitignore
vendored
Normal file
1
code/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.nx/cache
|
@ -1 +1,3 @@
|
||||
*.mdx
|
||||
|
||||
/.nx/cache
|
37
code/.yarn/patches/@vitest-expect-npm-0.34.5-8031508efe.patch
generated
Normal file
37
code/.yarn/patches/@vitest-expect-npm-0.34.5-8031508efe.patch
generated
Normal file
@ -0,0 +1,37 @@
|
||||
diff --git a/dist/index.js b/dist/index.js
|
||||
index 5a61947ad50426d27390b4e82533179323ad3ba1..32bfc45909b645cb31cec2e204c8baa23f21fdd2 100644
|
||||
--- a/dist/index.js
|
||||
+++ b/dist/index.js
|
||||
@@ -6,23 +6,29 @@ import { processError } from '@vitest/utils/error';
|
||||
import { util } from 'chai';
|
||||
|
||||
const MATCHERS_OBJECT = Symbol.for("matchers-object");
|
||||
-const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
|
||||
+// Patched this symbol for storybook, so that @storybook/test can be used in a jest environment as well.
|
||||
+// Otherwise, vitest will override global jest matchers, and crash.
|
||||
+const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object-storybook");
|
||||
const GLOBAL_EXPECT = Symbol.for("expect-global");
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
||||
const globalState = /* @__PURE__ */ new WeakMap();
|
||||
- const matchers = /* @__PURE__ */ Object.create(null);
|
||||
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
||||
get: () => globalState
|
||||
});
|
||||
+}
|
||||
+
|
||||
+if (!Object.prototype.hasOwnProperty.call(globalThis, JEST_MATCHERS_OBJECT)) {
|
||||
+ const matchers = /* @__PURE__ */ Object.create(null);
|
||||
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
|
||||
configurable: true,
|
||||
get: () => ({
|
||||
- state: globalState.get(globalThis[GLOBAL_EXPECT]),
|
||||
+ state: globalThis[MATCHERS_OBJECT].get(globalThis[GLOBAL_EXPECT]),
|
||||
matchers
|
||||
})
|
||||
});
|
||||
}
|
||||
+
|
||||
function getState(expect) {
|
||||
return globalThis[MATCHERS_OBJECT].get(expect);
|
||||
}
|
@ -25,5 +25,5 @@ plugins:
|
||||
unsafeHttpWhitelist:
|
||||
- localhost
|
||||
|
||||
yarnPath: ../.yarn/releases/yarn-3.5.1.cjs
|
||||
yarnPath: ../.yarn/releases/yarn-4.0.0.cjs
|
||||
installStatePath: '../.yarn/code-install-state.gz'
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-a11y",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Test component compliance with web accessibility standards",
|
||||
"keywords": [
|
||||
"a11y",
|
||||
|
@ -45,12 +45,18 @@ const run = async (storyId: string) => {
|
||||
}
|
||||
|
||||
const result = await axe.run(htmlElement, options);
|
||||
|
||||
// Axe result contains class instances, which telejson deserializes in a
|
||||
// way that violates:
|
||||
// Content Security Policy directive: "script-src 'self' 'unsafe-inline'".
|
||||
const resultJson = JSON.parse(JSON.stringify(result));
|
||||
|
||||
// It's possible that we requested a new run on a different story.
|
||||
// Unfortunately, axe doesn't support a cancel method to abort current run.
|
||||
// We check if the story we run against is still the current one,
|
||||
// if not, trigger a new run using the current story
|
||||
if (activeStoryId === storyId) {
|
||||
channel.emit(EVENTS.RESULT, result);
|
||||
channel.emit(EVENTS.RESULT, resultJson);
|
||||
} else {
|
||||
active = false;
|
||||
run(activeStoryId);
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-actions",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Get UI feedback when an action is performed on an interactive element",
|
||||
"keywords": [
|
||||
"storybook",
|
||||
|
@ -1,7 +1,12 @@
|
||||
import type { ArgsEnhancer } from '@storybook/types';
|
||||
import { addActionsFromArgTypes, inferActionsFromArgTypesRegex } from './addArgsHelpers';
|
||||
import {
|
||||
addActionsFromArgTypes,
|
||||
attachActionsToFunctionMocks,
|
||||
inferActionsFromArgTypesRegex,
|
||||
} from './addArgsHelpers';
|
||||
|
||||
export const argsEnhancers: ArgsEnhancer[] = [
|
||||
addActionsFromArgTypes,
|
||||
inferActionsFromArgTypesRegex,
|
||||
attachActionsToFunctionMocks,
|
||||
];
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-underscore-dangle,no-param-reassign */
|
||||
import type { Args, Renderer, ArgsEnhancer } from '@storybook/types';
|
||||
import { action } from './runtime/action';
|
||||
|
||||
@ -31,7 +32,7 @@ export const inferActionsFromArgTypesRegex: ArgsEnhancer<Renderer> = (context) =
|
||||
|
||||
return argTypesMatchingRegex.reduce((acc, [name, argType]) => {
|
||||
if (isInInitialArgs(name, initialArgs)) {
|
||||
acc[name] = action(name);
|
||||
acc[name] = action(name, { implicit: true });
|
||||
}
|
||||
return acc;
|
||||
}, {} as Args);
|
||||
@ -61,3 +62,33 @@ export const addActionsFromArgTypes: ArgsEnhancer<Renderer> = (context) => {
|
||||
return acc;
|
||||
}, {} as Args);
|
||||
};
|
||||
|
||||
export const attachActionsToFunctionMocks: ArgsEnhancer<Renderer> = (context) => {
|
||||
const {
|
||||
initialArgs,
|
||||
argTypes,
|
||||
parameters: { actions },
|
||||
} = context;
|
||||
if (actions?.disable || !argTypes) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const argTypesWithAction = Object.entries(initialArgs).filter(
|
||||
([, value]) =>
|
||||
typeof value === 'function' &&
|
||||
'_isMockFunction' in value &&
|
||||
value._isMockFunction &&
|
||||
!value._actionAttached
|
||||
);
|
||||
|
||||
return argTypesWithAction.reduce((acc, [key, value]) => {
|
||||
const previous = value.getMockImplementation();
|
||||
value.mockImplementation((...args: unknown[]) => {
|
||||
action(key)(...args);
|
||||
return previous?.(...args);
|
||||
});
|
||||
// this enhancer is being called multiple times
|
||||
value._actionAttached = true;
|
||||
return acc;
|
||||
}, {} as Args);
|
||||
};
|
||||
|
@ -4,6 +4,7 @@ interface Options {
|
||||
depth: number; // backards compatibility, remove in 7.0
|
||||
clearOnStoryChange: boolean;
|
||||
limit: number;
|
||||
implicit: boolean;
|
||||
}
|
||||
|
||||
export type ActionOptions = Partial<Options> & Partial<TelejsonOptions>;
|
||||
|
@ -39,6 +39,14 @@ const serializeArg = <T>(a: T) => {
|
||||
return a;
|
||||
};
|
||||
|
||||
// TODO react native doesn't have the crypto module, we should figure out a better way to generate these ids.
|
||||
const generateId = () => {
|
||||
return typeof crypto === 'object' && typeof crypto.getRandomValues === 'function'
|
||||
? uuidv4()
|
||||
: // pseudo random id, example response lo1e7zm4832bkr7yfl7
|
||||
Date.now().toString(36) + Math.random().toString(36).substring(2);
|
||||
};
|
||||
|
||||
export function action(name: string, options: ActionOptions = {}): HandlerFunction {
|
||||
const actionOptions = {
|
||||
...config,
|
||||
@ -46,8 +54,26 @@ export function action(name: string, options: ActionOptions = {}): HandlerFuncti
|
||||
};
|
||||
|
||||
const handler = function actionHandler(...args: any[]) {
|
||||
// TODO: Enable once codemods are finished
|
||||
// if (options.implicit) {
|
||||
// const preview =
|
||||
// '__STORYBOOK_PREVIEW__' in global
|
||||
// ? (global.__STORYBOOK_PREVIEW__ as PreviewWeb<Renderer>)
|
||||
// : undefined;
|
||||
// if (
|
||||
// preview?.storyRenders.some(
|
||||
// (render) => render.phase === 'playing' || render.phase === 'rendering'
|
||||
// )
|
||||
// ) {
|
||||
// console.warn(
|
||||
// 'Can not use implicit actions during rendering or playing of a story.'
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
const channel = addons.getChannel();
|
||||
const id = uuidv4();
|
||||
// this makes sure that in js enviroments like react native you can still get an id
|
||||
const id = generateId();
|
||||
const minDepth = 5; // anything less is really just storybook internals
|
||||
const serializedArgs = args.map(serializeArg);
|
||||
const normalizedArgs = args.length > 1 ? serializedArgs : serializedArgs[0];
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-backgrounds",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Switch backgrounds to view components in different settings",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-controls",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Interact with component inputs dynamically in the Storybook UI",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -146,7 +146,6 @@ export default {
|
||||
jsxOptions: {},
|
||||
csfPluginOptions: null,
|
||||
mdxPluginOptions: {},
|
||||
transcludeMarkdown: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -157,16 +156,9 @@ export default {
|
||||
|
||||
`csfPluginOptions` is an object for configuring `@storybook/csf-plugin`. When set to `null` it tells docs not to run the `csf-plugin` at all, which can be used as an optimization, or if you're already using `csf-plugin` in your `main.js`.
|
||||
|
||||
The `transcludeMarkdown` option enables mdx files to import `.md` files and render them as a component.
|
||||
|
||||
```mdx
|
||||
import { Meta } from '@storybook/addon-docs';
|
||||
import Changelog from '../CHANGELOG.md';
|
||||
> With the release of version 7.0, it is no longer possible to import `.md` files directly into Storybook using the `transcludeMarkdown` [option](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#importing-plain-markdown-files-with-transcludemarkdown-has-changed). Instead, we recommend using the [`Markdown`](https://storybook.js.org/docs/react/api/doc-block-markdown) Doc Block for importing Markdown files into your Storybook documentation.
|
||||
|
||||
<Meta title="Changelog" />
|
||||
|
||||
<Changelog />
|
||||
```
|
||||
|
||||
## TypeScript configuration
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-docs",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Document component usage and properties in Markdown",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-essentials",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Curated addons to bring out the best of Storybook",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-mdx-gfm",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "GitHub Flavored Markdown in Storybook",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-highlight",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Highlight DOM nodes within your stories",
|
||||
"keywords": [
|
||||
"storybook-addons",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-interactions",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Automate, test and debug user interactions",
|
||||
"keywords": [
|
||||
"storybook-addons",
|
||||
|
@ -4,7 +4,7 @@ import { type Call, CallStates, type ControlStates } from '@storybook/instrument
|
||||
import { styled, typography } from '@storybook/theming';
|
||||
import { transparentize } from 'polished';
|
||||
|
||||
import { MatcherResult } from './MatcherResult';
|
||||
import { Expected, MatcherResult, Received } from './MatcherResult';
|
||||
import { MethodCall } from './MethodCall';
|
||||
import { StatusIcon } from './StatusIcon';
|
||||
|
||||
@ -120,6 +120,29 @@ const Exception = ({ exception }: { exception: Call['exception'] }) => {
|
||||
return (
|
||||
<RowMessage>
|
||||
<pre>{paragraphs[0]}</pre>
|
||||
|
||||
{exception.showDiff && exception.diff ? (
|
||||
<>
|
||||
<br />
|
||||
<MatcherResult message={exception.diff} style={{ padding: 0 }} />
|
||||
</>
|
||||
) : (
|
||||
<pre>
|
||||
<br />
|
||||
{exception.expected && (
|
||||
<>
|
||||
Expected: <Expected value={exception.expected} />
|
||||
<br />
|
||||
</>
|
||||
)}
|
||||
{exception.actual && (
|
||||
<>
|
||||
Received: <Received value={exception.actual} />
|
||||
<br />
|
||||
</>
|
||||
)}
|
||||
</pre>
|
||||
)}
|
||||
{more && <p>See the full stack trace in the browser console.</p>}
|
||||
</RowMessage>
|
||||
);
|
||||
|
@ -45,7 +45,13 @@ export const Expected = ({ value, parsed }: { value: any; parsed?: boolean }) =>
|
||||
return <StyledExpected>{value}</StyledExpected>;
|
||||
};
|
||||
|
||||
export const MatcherResult = ({ message }: { message: string }) => {
|
||||
export const MatcherResult = ({
|
||||
message,
|
||||
style = {},
|
||||
}: {
|
||||
message: string;
|
||||
style?: React.CSSProperties;
|
||||
}) => {
|
||||
const lines = message.split('\n');
|
||||
return (
|
||||
<pre
|
||||
@ -53,6 +59,7 @@ export const MatcherResult = ({ message }: { message: string }) => {
|
||||
margin: 0,
|
||||
padding: '8px 10px 8px 36px',
|
||||
fontSize: typography.size.s1,
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
{lines.flatMap((line: string, index: number) => {
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-param-reassign,no-underscore-dangle */
|
||||
/// <reference types="node" />
|
||||
|
||||
import { addons } from '@storybook/preview-api';
|
||||
@ -9,6 +10,7 @@ import type {
|
||||
PlayFunction,
|
||||
PlayFunctionContext,
|
||||
StepLabel,
|
||||
Args,
|
||||
} from '@storybook/types';
|
||||
import { instrument } from '@storybook/instrumenter';
|
||||
import { ModuleMocker } from 'jest-mock';
|
||||
@ -19,7 +21,6 @@ const fn = JestMock.fn.bind(JestMock);
|
||||
// Aliasing `fn` to `action` here, so we get a more descriptive label in the UI.
|
||||
const { action } = instrument({ action: fn }, { retain: true });
|
||||
const channel = addons.getChannel();
|
||||
const seen = new Set<any>();
|
||||
const spies: any[] = [];
|
||||
|
||||
channel.on(FORCE_REMOUNT, () => spies.forEach((mock) => mock?.mockClear?.()));
|
||||
@ -28,19 +29,17 @@ channel.on(STORY_RENDER_PHASE_CHANGED, ({ newPhase }) => {
|
||||
});
|
||||
|
||||
const addSpies = (id: string, val: any, key?: string): any => {
|
||||
if (seen.has(val)) return val;
|
||||
seen.add(val);
|
||||
try {
|
||||
if (Object.prototype.toString.call(val) === '[object Object]') {
|
||||
// We have to mutate the original object for this to survive HMR.
|
||||
// eslint-disable-next-line no-restricted-syntax, no-param-reassign
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const [k, v] of Object.entries(val)) val[k] = addSpies(id, v, k);
|
||||
return val;
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
return val.map((item, index) => addSpies(id, item, `${key}[${index}]`));
|
||||
}
|
||||
if (typeof val === 'function' && val.isAction) {
|
||||
if (typeof val === 'function' && val.isAction && !val._isMockFunction) {
|
||||
Object.defineProperty(val, 'name', { value: key, writable: false });
|
||||
Object.defineProperty(val, '__storyId__', { value: id, writable: false });
|
||||
const spy = action(val);
|
||||
@ -56,7 +55,25 @@ const addSpies = (id: string, val: any, key?: string): any => {
|
||||
const addActionsFromArgTypes: ArgsEnhancer<Renderer> = ({ id, initialArgs }) =>
|
||||
addSpies(id, initialArgs);
|
||||
|
||||
export const argsEnhancers = [addActionsFromArgTypes];
|
||||
const instrumentSpies: ArgsEnhancer = ({ initialArgs }) => {
|
||||
const argTypesWithAction = Object.entries(initialArgs).filter(
|
||||
([, value]) =>
|
||||
typeof value === 'function' &&
|
||||
'_isMockFunction' in value &&
|
||||
value._isMockFunction &&
|
||||
!value._instrumented
|
||||
);
|
||||
|
||||
return argTypesWithAction.reduce((acc, [key, value]) => {
|
||||
const instrumented = instrument({ [key]: () => value }, { retain: true })[key];
|
||||
acc[key] = instrumented();
|
||||
// this enhancer is being called multiple times
|
||||
value._instrumented = true;
|
||||
return acc;
|
||||
}, {} as Args);
|
||||
};
|
||||
|
||||
export const argsEnhancers = [addActionsFromArgTypes, instrumentSpies];
|
||||
|
||||
export const { step: runStep } = instrument(
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-jest",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "React storybook addon that show component jest report",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-links",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Link stories together to build demos and prototypes with your UI components",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-measure",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Inspect layouts by visualizing the box model",
|
||||
"keywords": [
|
||||
"storybook-addons",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-outline",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Outline all elements with CSS to help with layout placement and alignment",
|
||||
"keywords": [
|
||||
"storybook-addons",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-storyshots",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Take a code snapshot of every story automatically with Jest",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-storyshots-puppeteer",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Image snapshots addition to StoryShots based on puppeteer",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-storysource",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "View a story’s source code to see how it works and paste into your app",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-themes",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Switch between multiple themes for you components in Storybook",
|
||||
"keywords": [
|
||||
"css",
|
||||
|
@ -1,11 +1,7 @@
|
||||
import type { Renderer, ProjectAnnotations } from '@storybook/types';
|
||||
import { GLOBAL_KEY } from './constants';
|
||||
|
||||
const preview: ProjectAnnotations<Renderer> = {
|
||||
globals: {
|
||||
// Required to make sure SB picks this up from URL params
|
||||
[GLOBAL_KEY]: '',
|
||||
},
|
||||
export const globals: ProjectAnnotations<Renderer>['globals'] = {
|
||||
// Required to make sure SB picks this up from URL params
|
||||
[GLOBAL_KEY]: '',
|
||||
};
|
||||
|
||||
export default preview;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-toolbars",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Create your own toolbar items that control story rendering",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addon-viewport",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Build responsive components by adjusting Storybook’s viewport size and orientation",
|
||||
"keywords": [
|
||||
"addon",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/builder-manager",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook manager builder",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -45,7 +45,7 @@ export const getConfig: ManagerBuilder['getConfig'] = async (options) => {
|
||||
return {
|
||||
entryPoints: realEntryPoints,
|
||||
outdir: join(options.outputDir || './', 'sb-addons'),
|
||||
format: 'esm',
|
||||
format: 'iife',
|
||||
write: false,
|
||||
ignoreAnnotations: true,
|
||||
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx'],
|
||||
|
@ -9,7 +9,6 @@ Build your stories with [vite](https://vitejs.dev/) for fast startup times and n
|
||||
- [Getting started with Vite and Storybook (on a new project)](#getting-started-with-vite-and-storybook-on-a-new-project)
|
||||
- [Migration from webpack / CRA](#migration-from-webpack--cra)
|
||||
- [Customize Vite config](#customize-vite-config)
|
||||
- [Svelte Options](#svelte-options)
|
||||
- [TypeScript](#typescript)
|
||||
- [React Docgen](#react-docgen)
|
||||
- [Note about working directory](#note-about-working-directory)
|
||||
@ -113,10 +112,6 @@ The `configType` variable will be either `"DEVELOPMENT"` or `"PRODUCTION"`.
|
||||
|
||||
The function should return the updated Vite configuration.
|
||||
|
||||
### Svelte Options
|
||||
|
||||
When using this builder with Svelte, your `svelte.config.js` file will be used automatically.
|
||||
|
||||
### TypeScript
|
||||
|
||||
Configure your `.storybook/main.ts` to use TypeScript:
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/builder-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "A plugin to run and build Storybooks with Vite",
|
||||
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/builders/builder-vite/#readme",
|
||||
"bugs": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/builder-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook framework-agnostic API",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
@ -56,7 +56,7 @@
|
||||
"prep": "../../../scripts/prepare/bundle.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.22.0",
|
||||
"@babel/core": "^7.23.2",
|
||||
"@storybook/channels": "workspace:*",
|
||||
"@storybook/client-logger": "workspace:*",
|
||||
"@storybook/core-common": "workspace:*",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/addons",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook addons store",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/channel-postmessage",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/channel-websocket",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/client-api",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook Client API",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/core-client",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook framework-agnostic API",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/api",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook Manager API (facade)",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/preview-web",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/store",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -29,7 +29,7 @@ test.describe('addon-interactions', () => {
|
||||
await expect(welcome).toContainText('Welcome, Jane Doe!');
|
||||
|
||||
const interactionsTab = await page.locator('#tabbutton-storybook-interactions-panel');
|
||||
await expect(interactionsTab).toContainText(/(1)/);
|
||||
await expect(interactionsTab).toContainText(/(\d)/);
|
||||
await expect(interactionsTab).toBeVisible();
|
||||
|
||||
const panel = sbPage.panelContent();
|
||||
@ -37,7 +37,7 @@ test.describe('addon-interactions', () => {
|
||||
await expect(panel).toContainText(/userEvent.click/);
|
||||
await expect(panel).toBeVisible();
|
||||
|
||||
const done = await panel.locator('[data-testid=icon-done]');
|
||||
const done = await panel.locator('[data-testid=icon-done]').nth(0);
|
||||
await expect(done).toBeVisible();
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/angular",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
|
||||
"keywords": [
|
||||
"storybook",
|
||||
@ -81,7 +81,7 @@
|
||||
"@types/cross-spawn": "^6.0.2",
|
||||
"@types/tmp": "^0.2.3",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"jest": "^29.3.1",
|
||||
"jest": "^29.7.0",
|
||||
"jest-preset-angular": "^13.0.1",
|
||||
"jest-specific-snapshot": "^8.0.0",
|
||||
"tmp": "^0.2.1",
|
||||
|
@ -33,6 +33,7 @@ addToGlobalContext('cliVersion', versions.storybook);
|
||||
export type StorybookBuilderOptions = JsonObject & {
|
||||
browserTarget?: string | null;
|
||||
tsConfig?: string;
|
||||
test: boolean;
|
||||
docs: boolean;
|
||||
compodoc: boolean;
|
||||
compodocArgs: string[];
|
||||
|
@ -49,6 +49,11 @@
|
||||
"description": "Starts Storybook in documentation mode. Learn more about it : https://storybook.js.org/docs/react/writing-docs/build-documentation#preview-storybooks-documentation.",
|
||||
"default": false
|
||||
},
|
||||
"test": {
|
||||
"type": "boolean",
|
||||
"description": "Build the static version of the sandbox optimized for testing purposes",
|
||||
"default": false
|
||||
},
|
||||
"compodoc": {
|
||||
"type": "boolean",
|
||||
"description": "Execute compodoc before.",
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { Meta, StoryObj } from '@storybook/angular';
|
||||
import { moduleMetadata } from '@storybook/angular';
|
||||
import { within, userEvent } from '@storybook/testing-library';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { within, userEvent, expect } from '@storybook/test';
|
||||
|
||||
import Button from './button.component';
|
||||
import Header from './header.component';
|
||||
@ -38,9 +38,12 @@ export const LoggedIn: Story = {
|
||||
}),
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
const loginButton = await canvas.getByRole('button', {
|
||||
name: /Log in/i,
|
||||
});
|
||||
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
||||
await expect(loginButton).toBeInTheDocument();
|
||||
await userEvent.click(loginButton);
|
||||
await expect(loginButton).not.toBeInTheDocument();
|
||||
|
||||
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
||||
await expect(logoutButton).toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/ember",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Ember: Develop Ember Component in isolation with Hot Reloading.",
|
||||
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/frameworks/ember",
|
||||
"bugs": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/html-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for HTML and Vite: Develop HTML in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/html-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for HTML: View HTML snippets in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -14,7 +14,6 @@
|
||||
- [Next.js's Image Component](#nextjss-image-component)
|
||||
- [Local Images](#local-images)
|
||||
- [Remote Images](#remote-images)
|
||||
- [AVIF](#avif)
|
||||
- [Next.js Font Optimization](#nextjs-font-optimization)
|
||||
- [next/font/google](#nextfontgoogle)
|
||||
- [next/font/local](#nextfontlocal)
|
||||
@ -147,7 +146,7 @@ export default {
|
||||
|
||||
### Options
|
||||
|
||||
You can be pass an options object for addional configuration if needed.
|
||||
You can be pass an options object for additional configuration if needed.
|
||||
|
||||
For example:
|
||||
|
||||
@ -220,10 +219,6 @@ export default function Home() {
|
||||
}
|
||||
```
|
||||
|
||||
#### AVIF
|
||||
|
||||
This format is not supported by this framework yet. Feel free to [open up an issue](https://github.com/storybookjs/storybook/issues) if this is something you want to see.
|
||||
|
||||
### Next.js Font Optimization
|
||||
|
||||
[next/font](https://nextjs.org/docs/basic-features/font-optimization) is partially supported in Storybook. The packages `next/font/google` and `next/font/local` are supported.
|
||||
@ -864,7 +859,7 @@ Next.js comes with a lot of things for free out of the box like sass support, bu
|
||||
|
||||
Any webpack modifications desired for Storybook should be made in [.storybook/main.js](https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config).
|
||||
|
||||
Note: Not all webpack modifications are copy/paste-able between `next.config.js` and `.storybook/main.js`. It is recommended to do your reasearch on how to properly make your modifcation to Storybook's webpack config and on how [webpack works](https://webpack.js.org/concepts/).
|
||||
Note: Not all webpack modifications are copy/paste-able between `next.config.js` and `.storybook/main.js`. It is recommended to do your research on how to properly make your modification to Storybook's webpack config and on how [webpack works](https://webpack.js.org/concepts/).
|
||||
|
||||
Below is an example of how to add svgr support to Storybook with this framework.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/nextjs",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Next.js",
|
||||
"keywords": [
|
||||
"storybook",
|
||||
@ -74,7 +74,7 @@
|
||||
"prep": "../../../scripts/prepare/bundle.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.22.9",
|
||||
"@babel/core": "^7.23.2",
|
||||
"@babel/plugin-syntax-bigint": "^7.8.3",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
||||
"@babel/plugin-syntax-import-assertions": "^7.22.5",
|
||||
@ -82,11 +82,11 @@
|
||||
"@babel/plugin-transform-export-namespace-from": "^7.22.11",
|
||||
"@babel/plugin-transform-numeric-separator": "^7.22.11",
|
||||
"@babel/plugin-transform-object-rest-spread": "^7.22.15",
|
||||
"@babel/plugin-transform-runtime": "^7.22.9",
|
||||
"@babel/preset-env": "^7.22.9",
|
||||
"@babel/preset-react": "^7.22.5",
|
||||
"@babel/preset-typescript": "^7.22.5",
|
||||
"@babel/runtime": "^7.22.6",
|
||||
"@babel/plugin-transform-runtime": "^7.23.2",
|
||||
"@babel/preset-env": "^7.23.2",
|
||||
"@babel/preset-react": "^7.22.15",
|
||||
"@babel/preset-typescript": "^7.23.2",
|
||||
"@babel/runtime": "^7.23.2",
|
||||
"@storybook/addon-actions": "workspace:*",
|
||||
"@storybook/builder-webpack5": "workspace:*",
|
||||
"@storybook/core-common": "workspace:*",
|
||||
@ -100,7 +100,7 @@
|
||||
"find-up": "^5.0.0",
|
||||
"fs-extra": "^11.1.0",
|
||||
"image-size": "^1.0.0",
|
||||
"loader-utils": "^3.2.0",
|
||||
"loader-utils": "^3.2.1",
|
||||
"node-polyfill-webpack-plugin": "^2.0.1",
|
||||
"pnp-webpack-plugin": "^1.7.0",
|
||||
"postcss": "^8.4.21",
|
||||
@ -108,6 +108,7 @@
|
||||
"resolve-url-loader": "^5.0.0",
|
||||
"sass-loader": "^12.4.0",
|
||||
"semver": "^7.3.5",
|
||||
"sharp": "^0.32.6",
|
||||
"style-loader": "^3.3.1",
|
||||
"styled-jsx": "5.1.1",
|
||||
"ts-dedent": "^2.0.0",
|
||||
@ -115,17 +116,18 @@
|
||||
"tsconfig-paths-webpack-plugin": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/types": "^7.22.5",
|
||||
"@babel/types": "^7.23.0",
|
||||
"@types/babel__core": "^7",
|
||||
"@types/babel__plugin-transform-runtime": "^7",
|
||||
"@types/babel__preset-env": "^7",
|
||||
"next": "13.5.4",
|
||||
"@types/loader-utils": "^2.0.5",
|
||||
"next": "^14.0.0",
|
||||
"typescript": "^4.9.3",
|
||||
"webpack": "^5.65.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@next/font": "^13.0.0",
|
||||
"next": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
|
||||
"@next/font": "^13.0.0|| ^14.0.0",
|
||||
"next": "^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
||||
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
||||
"webpack": "^5.0.0"
|
||||
|
@ -13,10 +13,21 @@ import { defaultLoader } from './next-image-default-loader';
|
||||
|
||||
const ImageContext = ImageContextValue as typeof ImageContextType;
|
||||
|
||||
const MockedNextImage = ({ loader, ...props }: _NextImage.ImageProps) => {
|
||||
const imageParameters = React.useContext(ImageContext);
|
||||
const MockedNextImage = React.forwardRef<HTMLImageElement, _NextImage.ImageProps>(
|
||||
({ loader, ...props }, ref) => {
|
||||
const imageParameters = React.useContext(ImageContext);
|
||||
|
||||
return <OriginalNextImage {...imageParameters} {...props} loader={loader ?? defaultLoader} />;
|
||||
};
|
||||
return (
|
||||
<OriginalNextImage
|
||||
ref={ref}
|
||||
{...imageParameters}
|
||||
{...props}
|
||||
loader={loader ?? defaultLoader}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
MockedNextImage.displayName = 'NextImage';
|
||||
|
||||
export default MockedNextImage;
|
||||
|
@ -20,7 +20,7 @@ const configureImageDefaults = (baseConfig: WebpackConfig): void => {
|
||||
'next/image': path.resolve(__dirname, './images/next-image'),
|
||||
};
|
||||
|
||||
if (semver.satisfies(version, '^13.0.0')) {
|
||||
if (semver.satisfies(version, '>=13.0.0')) {
|
||||
resolve.alias = {
|
||||
...resolve.alias,
|
||||
'sb-original/next/legacy/image': require.resolve('next/legacy/image'),
|
||||
|
@ -1,29 +1,52 @@
|
||||
// @ts-expect-error (loader-utils has no webpack5 compatible types)
|
||||
import { interpolateName } from 'loader-utils';
|
||||
import imageSizeOf from 'image-size';
|
||||
import type { RawLoaderDefinition } from 'webpack';
|
||||
import type { NextConfig } from 'next';
|
||||
import sharp from 'sharp';
|
||||
import { cpus } from 'os';
|
||||
|
||||
interface LoaderOptions {
|
||||
filename: string;
|
||||
nextConfig: NextConfig;
|
||||
}
|
||||
|
||||
const nextImageLoaderStub: RawLoaderDefinition<LoaderOptions> = function (content) {
|
||||
if (sharp.concurrency() > 1) {
|
||||
// Reducing concurrency reduces the memory usage too.
|
||||
const divisor = process.env.NODE_ENV === 'development' ? 4 : 2;
|
||||
sharp.concurrency(Math.floor(Math.max(cpus().length / divisor, 1)));
|
||||
}
|
||||
|
||||
const nextImageLoaderStub: RawLoaderDefinition<LoaderOptions> = async function NextImageLoader(
|
||||
content
|
||||
) {
|
||||
const { filename, nextConfig } = this.getOptions();
|
||||
const outputPath = interpolateName(this, filename.replace('[ext]', '.[ext]'), {
|
||||
const opts = {
|
||||
context: this.rootContext,
|
||||
content,
|
||||
});
|
||||
};
|
||||
const outputPath = interpolateName(this, filename.replace('[ext]', '.[ext]'), opts);
|
||||
const extension = interpolateName(this, '[ext]', opts);
|
||||
|
||||
this.emitFile(outputPath, content);
|
||||
|
||||
const { width, height } = imageSizeOf(this.resourcePath);
|
||||
|
||||
if (nextConfig.images?.disableStaticImages) {
|
||||
return `const src = '${outputPath}'; export default src;`;
|
||||
}
|
||||
|
||||
let width;
|
||||
let height;
|
||||
|
||||
if (extension === 'avif') {
|
||||
const transformer = sharp(content);
|
||||
const result = await transformer.metadata();
|
||||
width = result.width;
|
||||
height = result.height;
|
||||
} else {
|
||||
const result = imageSizeOf(this.resourcePath);
|
||||
width = result.width;
|
||||
height = result.height;
|
||||
}
|
||||
|
||||
return `export default ${JSON.stringify({
|
||||
src: outputPath,
|
||||
height,
|
||||
|
@ -7,20 +7,11 @@ export function configureNextImport(baseConfig: WebpackConfig) {
|
||||
const nextJSVersion = getNextjsVersion();
|
||||
|
||||
const isNext12 = semver.satisfies(nextJSVersion, '~12');
|
||||
const isNext13 = semver.satisfies(nextJSVersion, '~13');
|
||||
const isNextVersionSmallerThan12dot2 = semver.lt(nextJSVersion, '12.2.0');
|
||||
const isNextVersionSmallerThan13 = semver.lt(nextJSVersion, '13.0.0');
|
||||
|
||||
baseConfig.plugins = baseConfig.plugins ?? [];
|
||||
|
||||
if (!isNext13) {
|
||||
baseConfig.plugins.push(
|
||||
new IgnorePlugin({
|
||||
resourceRegExp: /next\/legacy\/image$/,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (!isNext12 || isNextVersionSmallerThan12dot2) {
|
||||
baseConfig.plugins.push(
|
||||
new IgnorePlugin({
|
||||
@ -32,7 +23,8 @@ export function configureNextImport(baseConfig: WebpackConfig) {
|
||||
if (isNextVersionSmallerThan13) {
|
||||
baseConfig.plugins.push(
|
||||
new IgnorePlugin({
|
||||
resourceRegExp: /next\/dist\/shared\/lib\/hooks-client-context$/,
|
||||
// ignore next/dist/shared/lib/hooks-client-context and next/legacy/image imports
|
||||
resourceRegExp: /(next\/dist\/shared\/lib\/hooks-client-context|next\/legacy\/image)$/,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { within, userEvent } from '@storybook/testing-library';
|
||||
import { within, userEvent, expect } from '@storybook/test';
|
||||
import { Page } from './Page';
|
||||
|
||||
export default {
|
||||
@ -16,9 +16,12 @@ export const LoggedOut = {};
|
||||
export const LoggedIn = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
const loginButton = await canvas.getByRole('button', {
|
||||
name: /Log in/i,
|
||||
});
|
||||
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
||||
await expect(loginButton).toBeInTheDocument();
|
||||
await userEvent.click(loginButton);
|
||||
await expect(loginButton).not.toBeInTheDocument();
|
||||
|
||||
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
||||
await expect(logoutButton).toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import { within, userEvent } from '@storybook/testing-library';
|
||||
import { within, userEvent, expect } from '@storybook/test';
|
||||
|
||||
import { Page } from './Page';
|
||||
|
||||
@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
|
||||
export const LoggedIn: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
const loginButton = await canvas.getByRole('button', {
|
||||
name: /Log in/i,
|
||||
});
|
||||
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
||||
await expect(loginButton).toBeInTheDocument();
|
||||
await userEvent.click(loginButton);
|
||||
await expect(loginButton).not.toBeInTheDocument();
|
||||
|
||||
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
||||
await expect(logoutButton).toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import { within, userEvent } from '@storybook/testing-library';
|
||||
import { within, userEvent, expect } from '@storybook/test';
|
||||
|
||||
import { Page } from './Page';
|
||||
|
||||
@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
|
||||
export const LoggedIn: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
const loginButton = await canvas.getByRole('button', {
|
||||
name: /Log in/i,
|
||||
});
|
||||
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
||||
await expect(loginButton).toBeInTheDocument();
|
||||
await userEvent.click(loginButton);
|
||||
await expect(loginButton).not.toBeInTheDocument();
|
||||
|
||||
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
||||
await expect(logoutButton).toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
@ -1,8 +1,9 @@
|
||||
import React from 'react';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import Image from 'next/image';
|
||||
import { waitFor } from '@storybook/testing-library';
|
||||
|
||||
import Accessibility from '../../assets/accessibility.svg';
|
||||
import AvifImage from '../../assets/avif-test-image.avif';
|
||||
|
||||
export default {
|
||||
component: Image,
|
||||
@ -14,6 +15,13 @@ export default {
|
||||
|
||||
export const Default = {};
|
||||
|
||||
export const Avif = {
|
||||
args: {
|
||||
src: AvifImage,
|
||||
alt: 'Avif Test Image',
|
||||
},
|
||||
};
|
||||
|
||||
export const BlurredPlaceholder = {
|
||||
args: {
|
||||
placeholder: 'blur',
|
||||
@ -81,3 +89,16 @@ export const Eager = {
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const WithRef = {
|
||||
render() {
|
||||
const [ref, setRef] = useState(null);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Image src={Accessibility} alt="Accessibility" ref={setRef} />
|
||||
<p>Alt attribute of image: {ref?.alt}</p>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/preact-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Preact and Vite: Develop Preact components in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/preact-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Preact: Develop Preact Component in isolation.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/react-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for React and Vite: Develop React components in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
@ -53,7 +53,7 @@
|
||||
"@storybook/react": "workspace:*",
|
||||
"@vitejs/plugin-react": "^3.0.1",
|
||||
"magic-string": "^0.30.0",
|
||||
"react-docgen": "^6.0.2"
|
||||
"react-docgen": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.0.0",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/react-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for React: Develop React Component in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/server-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Server: View HTML snippets from a server in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/svelte-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Svelte and Vite: Develop Svelte components in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/svelte-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Svelte: Develop Svelte Component in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/sveltekit",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for SvelteKit",
|
||||
"keywords": [
|
||||
"storybook",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/vue-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Vue2 and Vite: Develop Vue2 Components in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/vue-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Vue: Develop Vue Component in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/vue3-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Vue3 and Vite: Develop Vue3 components in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/vue3-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for Vue 3: Develop Vue 3 Components in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/web-components-vite",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for web-components and Vite: Develop Web Components in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/web-components-webpack5",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook for web-components: View web components snippets in isolation with Hot Reloading.",
|
||||
"keywords": [
|
||||
"lit",
|
||||
@ -50,7 +50,7 @@
|
||||
"prep": "../../../scripts/prepare/bundle.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/preset-env": "^7.22.9",
|
||||
"@babel/preset-env": "^7.23.2",
|
||||
"@storybook/builder-webpack5": "workspace:*",
|
||||
"@storybook/core-common": "workspace:*",
|
||||
"@storybook/preset-web-components-webpack": "workspace:*",
|
||||
|
@ -23,6 +23,7 @@ const modulesToTransform = [
|
||||
'@angular',
|
||||
'@lit',
|
||||
'@mdx-js',
|
||||
'@vitest',
|
||||
'ccount',
|
||||
'character-entities',
|
||||
'decode-named-character-reference',
|
||||
@ -60,6 +61,8 @@ module.exports = {
|
||||
path.resolve('./__mocks__/fileMock.js'),
|
||||
'\\.(css|scss|stylesheet)$': path.resolve('./__mocks__/styleMock.js'),
|
||||
'\\.(md)$': path.resolve('./__mocks__/htmlMock.js'),
|
||||
'@vitest/utils/(.*)': '@vitest/utils/dist/$1.js',
|
||||
'@vitest/utils': '@vitest/utils/dist/index.js',
|
||||
},
|
||||
transform: {
|
||||
'^.+\\.(t|j)sx?$': ['@swc/jest', swcrc],
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/channels",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -103,7 +103,7 @@ export class PostMessageTransport implements ChannelTransport {
|
||||
|
||||
const frames = this.getFrames(target);
|
||||
|
||||
const query = qs.parse(location.search, { ignoreQueryPrefix: true });
|
||||
const query = qs.parse(location?.search || '', { ignoreQueryPrefix: true });
|
||||
|
||||
const data = stringify(
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sb",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook CLI",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "storybook",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook CLI",
|
||||
"keywords": [
|
||||
"storybook"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@storybook/cli",
|
||||
"version": "7.6.0-alpha.1",
|
||||
"version": "7.6.0-alpha.3",
|
||||
"description": "Storybook's CLI - easiest method of adding storybook to your projects",
|
||||
"keywords": [
|
||||
"cli",
|
||||
@ -55,9 +55,9 @@
|
||||
"test": "jest test/**/*.test.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.22.9",
|
||||
"@babel/preset-env": "^7.22.9",
|
||||
"@babel/types": "^7.22.5",
|
||||
"@babel/core": "^7.23.2",
|
||||
"@babel/preset-env": "^7.23.2",
|
||||
"@babel/types": "^7.23.0",
|
||||
"@ndelangen/get-tarball": "^3.0.7",
|
||||
"@storybook/codemod": "workspace:*",
|
||||
"@storybook/core-common": "workspace:*",
|
||||
|
BIN
code/lib/cli/rendererAssets/common/assets/avif-test-image.avif
Normal file
BIN
code/lib/cli/rendererAssets/common/assets/avif-test-image.avif
Normal file
Binary file not shown.
After Width: | Height: | Size: 829 B |
@ -259,6 +259,7 @@ command('build')
|
||||
)
|
||||
.option('--force-build-preview', 'Build the preview iframe even if you are using --preview-url')
|
||||
.option('--docs', 'Build a documentation-only site using addon-docs')
|
||||
.option('--test', 'Build stories optimized for testing purposes.')
|
||||
.action(async (options) => {
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
||||
logger.setLevel(program.loglevel);
|
||||
|
@ -251,7 +251,14 @@ export async function baseGenerator(
|
||||
|
||||
if (hasInteractiveStories(rendererId)) {
|
||||
addons.push('@storybook/addon-interactions');
|
||||
addonPackages.push('@storybook/addon-interactions', '@storybook/testing-library@^0.2.0-next.0');
|
||||
addonPackages.push('@storybook/addon-interactions');
|
||||
|
||||
// TODO: migrate template stories in solid and qwik to use @storybook/test
|
||||
if (['solid', 'qwik'].includes(rendererId)) {
|
||||
addonPackages.push('@storybook/testing-library');
|
||||
} else {
|
||||
addonPackages.push('@storybook/test');
|
||||
}
|
||||
}
|
||||
|
||||
const files = await fse.readdir(process.cwd());
|
||||
|
@ -1,6 +1,7 @@
|
||||
import fse from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { dedent } from 'ts-dedent';
|
||||
import { logger } from '@storybook/node-logger';
|
||||
import { externalFrameworks, SupportedLanguage } from '../project_types';
|
||||
|
||||
interface ConfigureMainOptions {
|
||||
@ -33,8 +34,6 @@ interface ConfigurePreviewOptions {
|
||||
rendererId: string;
|
||||
}
|
||||
|
||||
const logger = console;
|
||||
|
||||
/**
|
||||
* We need to clean up the paths in case of pnp
|
||||
* input: "path.dirname(require.resolve(path.join('@storybook/react-webpack5', 'package.json')))"
|
||||
@ -96,20 +95,25 @@ export async function configureMain({
|
||||
finalPrefixes.push(`/** @type { import('${frameworkPackage}').StorybookConfig } */`);
|
||||
}
|
||||
|
||||
const mainJsContents = mainConfigTemplate
|
||||
let mainJsContents = mainConfigTemplate
|
||||
.replace('<<import>>', `${imports.join('\n\n')}\n\n`)
|
||||
.replace('<<prefix>>', finalPrefixes.length > 0 ? `${finalPrefixes.join('\n\n')}\n` : '')
|
||||
.replace('<<type>>', isTypescript ? ': StorybookConfig' : '')
|
||||
.replace('<<mainContents>>', mainContents);
|
||||
|
||||
const prettier = (await import('prettier')).default;
|
||||
|
||||
const mainPath = `./${storybookConfigFolder}/main.${isTypescript ? 'ts' : 'js'}`;
|
||||
const prettyMain = prettier.format(dedent(mainJsContents), {
|
||||
...prettier.resolveConfig.sync(process.cwd()),
|
||||
filepath: mainPath,
|
||||
});
|
||||
await fse.writeFile(mainPath, prettyMain, { encoding: 'utf8' });
|
||||
|
||||
try {
|
||||
const prettier = (await import('prettier')).default;
|
||||
mainJsContents = prettier.format(dedent(mainJsContents), {
|
||||
...prettier.resolveConfig.sync(process.cwd()),
|
||||
filepath: mainPath,
|
||||
});
|
||||
} catch {
|
||||
logger.verbose(`Failed to prettify ${mainPath}`);
|
||||
}
|
||||
|
||||
await fse.writeFile(mainPath, mainJsContents, { encoding: 'utf8' });
|
||||
}
|
||||
|
||||
export async function configurePreview(options: ConfigurePreviewOptions) {
|
||||
@ -140,7 +144,7 @@ export async function configurePreview(options: ConfigurePreviewOptions) {
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
|
||||
const preview = dedent`
|
||||
let preview = dedent`
|
||||
${prefix}${prefix.length > 0 ? '\n' : ''}
|
||||
${
|
||||
!isTypescript && rendererPackage
|
||||
@ -163,11 +167,15 @@ export async function configurePreview(options: ConfigurePreviewOptions) {
|
||||
.replace(' \n', '')
|
||||
.trim();
|
||||
|
||||
const prettier = (await import('prettier')).default;
|
||||
try {
|
||||
const prettier = (await import('prettier')).default;
|
||||
preview = prettier.format(preview, {
|
||||
...prettier.resolveConfig.sync(process.cwd()),
|
||||
filepath: previewPath,
|
||||
});
|
||||
} catch {
|
||||
logger.verbose(`Failed to prettify ${previewPath}`);
|
||||
}
|
||||
|
||||
const prettyPreview = prettier.format(preview, {
|
||||
...prettier.resolveConfig.sync(process.cwd()),
|
||||
filepath: previewPath,
|
||||
});
|
||||
await fse.writeFile(previewPath, prettyPreview, { encoding: 'utf8' });
|
||||
await fse.writeFile(previewPath, preview, { encoding: 'utf8' });
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user