Skip to content

Commit

Permalink
Merge branch 'next' into tech/rebundle-syntax-highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Jun 10, 2022
2 parents b8c6cbf + b2f4390 commit 6ea5609
Show file tree
Hide file tree
Showing 60 changed files with 427 additions and 168 deletions.
45 changes: 22 additions & 23 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,32 +265,31 @@ jobs:
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
# TODO: we disabled this one because it keeps failing, we should fix it, and enable it again!
# - attach_workspace:
# at: .
# - run:
# name: Running local registry
# command: yarn local-registry --port 6000 --open
# background: true
# - run:
# name: Wait for registry
# command: yarn wait-on http://localhost:6000
# - run:
# name: run e2e tests cra
# command: yarn test:e2e-framework --pnp cra
- attach_workspace:
at: .
- run:
name: Running local registry
command: yarn local-registry --port 6000 --open
background: true
- run:
name: Wait for registry
command: yarn wait-on http://localhost:6000
- run:
name: run e2e tests cra
command: yarn test:e2e-framework --pnp cra
# - run:
# name: run e2e tests vue
# command: yarn test:e2e-framework --pnp sfcVue
# - run:
# name: prep artifacts
# when: always
# command: zip -r /tmp/storybook-e2e-testing-out.zip /tmp/storybook-e2e-testing
# - store_artifacts:
# path: /tmp/cypress-record
# destination: cypress
# - store_artifacts:
# path: /tmp/storybook-e2e-testing-out.zip
# destination: e2e
- run:
name: prep artifacts
when: always
command: zip -r /tmp/storybook-e2e-testing-out.zip /tmp/storybook-e2e-testing
- store_artifacts:
path: /tmp/cypress-record
destination: cypress
- store_artifacts:
path: /tmp/storybook-e2e-testing-out.zip
destination: e2e
e2e-tests-examples:
executor:
class: small
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ It allows you to browse a component library, view the different states of each c

<p align="center">
View README for:<br/>
<a href="https://github.com/storybookjs/storybook/blob/main/README.md" title="latest"><img alt="latest" src="https://img.shields.io/npm/v/@storybook/core/latest.svg" /></a>
<a href="https://github.com/storybookjs/storybook/blob/next/README.md" title="next"><img alt="next" src="https://img.shields.io/npm/v/@storybook/core/next.svg" /></a>
<a href="https://github.com/storybookjs/storybook/blob/main/README.md" title="latest"><img alt="latest" src="https://img.shields.io/npm/v/@storybook/core/latest?style=for-the-badge&logo=storybook&logoColor=ffffff&color=ff4785" /></a>
<a href="https://github.com/storybookjs/storybook/blob/next/README.md" title="next"><img alt="next" src="https://img.shields.io/npm/v/@storybook/core/next?style=for-the-badge&logo=storybook&logoColor=ffffff&color=purple" /></a>
</p>

## Table of contents
Expand Down Expand Up @@ -92,19 +92,19 @@ For additional help, join us in the [Storybook Discord](https://discord.gg/story

### Supported Frameworks

| Framework | Demo | |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| [React](app/react) | [v6.4.x](https://storybookjs.netlify.com/official-storybook/?path=/story/*) | [![React](https://img.shields.io/npm/dm/@storybook/react.svg)](app/react) |
| [Vue](app/vue) | [v6.4.x](https://storybookjs.netlify.com/vue-kitchen-sink/) | [![Vue](https://img.shields.io/npm/dm/@storybook/vue.svg)](app/vue) |
| [Angular](app/angular) | [v6.4.x](https://storybookjs.netlify.com/angular-cli/) | [![Angular](https://img.shields.io/npm/dm/@storybook/angular.svg)](app/angular) |
| [Web components](app/web-components) | [v6.4.x](https://storybookjs.netlify.com/web-components-kitchen-sink/) | [![Svelte](https://img.shields.io/npm/dm/@storybook/web-components.svg)](app/web-components) |
| [React Native](https://github.com/storybookjs/react-native) | - | [![React Native](https://img.shields.io/npm/dm/@storybook/react-native.svg)](https://github.com/storybookjs/react-native) |
| [HTML](app/html) | [v6.4.x](https://storybookjs.netlify.com/html-kitchen-sink/) | [![HTML](https://img.shields.io/npm/dm/@storybook/html.svg)](app/html) |
| [Ember](app/ember) | [v6.4.x](https://storybookjs.netlify.com/ember-cli/) | [![Ember](https://img.shields.io/npm/dm/@storybook/ember.svg)](app/ember) |
| [Svelte](app/svelte) | [v6.4.x](https://storybookjs.netlify.com/svelte-kitchen-sink/) | [![Svelte](https://img.shields.io/npm/dm/@storybook/svelte.svg)](app/svelte) |
| [Preact](app/preact) | [v6.4.x](https://storybookjs.netlify.com/preact-kitchen-sink/) | [![Preact](https://img.shields.io/npm/dm/@storybook/preact.svg)](app/preact) |
| [Marionette.js](https://github.com/storybookjs/marionette) | - | [![Marionette.js](https://img.shields.io/npm/dm/@storybook/marionette.svg)](https://github.com/storybookjs/marionette) |
| [Android, iOS, Flutter](https://github.com/storybookjs/native) | [v6.4.x](https://storybookjs.github.io/native/@storybook/native-flutter-example/index.html) | [![Native](https://img.shields.io/npm/dm/@storybook/native.svg)](https://github.com/storybookjs/native) |
| Framework | Demo | |
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| [React](app/react) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/react/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/official-storybook/?path=/story/*) | [![React](https://img.shields.io/npm/dm/@storybook/react?style=flat-square&color=eee)](app/react) |
| [Vue](app/vue) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/vue/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/vue-kitchen-sink/) | [![Vue](https://img.shields.io/npm/dm/@storybook/vue?style=flat-square&color=eee)](app/vue) |
| [Angular](app/angular) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/angular/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/angular-cli/) | [![Angular](https://img.shields.io/npm/dm/@storybook/angular?style=flat-square&color=eee)](app/angular) |
| [Web components](app/web-components) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/web-components/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/web-components-kitchen-sink/) | [![Svelte](https://img.shields.io/npm/dm/@storybook/web-components?style=flat-square&color=eee)](app/web-components) |
| [React Native](https://github.com/storybookjs/react-native) | - | [![React Native](https://img.shields.io/npm/dm/@storybook/react-native?style=flat-square&color=eee)](https://github.com/storybookjs/react-native) |
| [HTML](app/html) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/html/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/html-kitchen-sink/) | [![HTML](https://img.shields.io/npm/dm/@storybook/html?style=flat-square&color=eee)](app/html) |
| [Ember](app/ember) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/ember/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/ember-cli/) | [![Ember](https://img.shields.io/npm/dm/@storybook/ember?style=flat-square&color=eee)](app/ember) |
| [Svelte](app/svelte) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/svelte/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/svelte-kitchen-sink/) | [![Svelte](https://img.shields.io/npm/dm/@storybook/svelte?style=flat-square&color=eee)](app/svelte) |
| [Preact](app/preact) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/preact/latest?style=flat-square&color=blue&label)](https://storybookjs.netlify.com/preact-kitchen-sink/) | [![Preact](https://img.shields.io/npm/dm/@storybook/preact?style=flat-square&color=eee)](app/preact) |
| [Marionette.js](https://github.com/storybookjs/marionette) | - | [![Marionette.js](https://img.shields.io/npm/dm/@storybook/marionette?style=flat-square&color=eee)](https://github.com/storybookjs/marionette) |
| [Android, iOS, Flutter](https://github.com/storybookjs/native) | [![Storybook demo](https://img.shields.io/npm/v/@storybook/native/latest?style=flat-square&color=blue&label)](https://storybookjs.github.io/native/@storybook/native-flutter-example/index.html) | [![Native](https://img.shields.io/npm/dm/@storybook/native?style=flat-square&color=eee)](https://github.com/storybookjs/native) |

### Sub Projects

Expand Down
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Supported Versions

| Version | Supported |
| ---------- | ------------------ |
| 6.3, 6.4 | :white_check_mark: |
| Version | Supported |
| --------------- | ------------------ |
| 6.3, 6.4, 6.5 | :white_check_mark: |

## Reporting a Vulnerability

Expand Down
12 changes: 9 additions & 3 deletions app/angular/src/client/preview/angular-beta/StorybookModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import deprecate from 'util-deprecate';
import { ICollection, StoryFnAngularReturnType } from '../types';
import { storyPropsProvider } from './StorybookProvider';
import { isComponentAlreadyDeclaredInModules } from './utils/NgModulesAnalyzer';
import { isDeclarable } from './utils/NgComponentAnalyzer';
import { isDeclarable, isStandaloneComponent } from './utils/NgComponentAnalyzer';
import { createStorybookWrapperComponent } from './StorybookWrapperComponent';
import { computesTemplateFromComponent } from './ComputesTemplateFromComponent';

Expand Down Expand Up @@ -61,22 +61,28 @@ export const getStorybookModuleMetadata = (
props
);

const isStandalone = isStandaloneComponent(component);
// Look recursively (deep) if the component is not already declared by an import module
const requiresComponentDeclaration =
isDeclarable(component) &&
!isComponentAlreadyDeclaredInModules(
component,
moduleMetadata.declarations,
moduleMetadata.imports
);
) &&
!isStandalone;

return {
declarations: [
...(requiresComponentDeclaration ? [component] : []),
ComponentToInject,
...(moduleMetadata.declarations ?? []),
],
imports: [BrowserModule, ...(moduleMetadata.imports ?? [])],
imports: [
BrowserModule,
...(isStandalone ? [component] : []),
...(moduleMetadata.imports ?? []),
],
providers: [storyPropsProvider(storyProps$), ...(moduleMetadata.providers ?? [])],
entryComponents: [...(moduleMetadata.entryComponents ?? [])],
schemas: [...(moduleMetadata.schemas ?? [])],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
isComponent,
isDeclarable,
getComponentDecoratorMetadata,
isStandaloneComponent,
} from './NgComponentAnalyzer';

describe('getComponentInputsOutputs', () => {
Expand Down Expand Up @@ -235,6 +236,46 @@ describe('isComponent', () => {
});
});

describe('isStandaloneComponent', () => {
it('should return true with a Component with "standalone: true"', () => {
// TODO: `standalone` is only available in Angular v14. Remove cast to `any` once
// Angular deps are updated to v14.x.x.
@Component({ standalone: true } as any)
class FooComponent {}

expect(isStandaloneComponent(FooComponent)).toEqual(true);
});

it('should return false with a Component with "standalone: false"', () => {
// TODO: `standalone` is only available in Angular v14. Remove cast to `any` once
// Angular deps are updated to v14.x.x.
@Component({ standalone: false } as any)
class FooComponent {}

expect(isStandaloneComponent(FooComponent)).toEqual(false);
});

it('should return false with a Component without the "standalone" property', () => {
@Component({})
class FooComponent {}

expect(isStandaloneComponent(FooComponent)).toEqual(false);
});

it('should return false with simple class', () => {
class FooPipe {}

expect(isStandaloneComponent(FooPipe)).toEqual(false);
});

it('should return false with Directive', () => {
@Directive()
class FooDirective {}

expect(isStandaloneComponent(FooDirective)).toEqual(false);
});
});

describe('getComponentDecoratorMetadata', () => {
it('should return Component with a Component', () => {
@Component({ selector: 'foo' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ export const isComponent = (component: any): component is Type<unknown> => {
return (decorators || []).some((d) => d instanceof Component);
};

export const isStandaloneComponent = (component: any): component is Type<unknown> => {
if (!component) {
return false;
}

const decorators = reflectionCapabilities.annotations(component);

// TODO: `standalone` is only available in Angular v14. Remove cast to `any` once
// Angular deps are updated to v14.x.x.
return (decorators || []).some((d) => d instanceof Component && (d as any).standalone);
};

/**
* Returns all component decorator properties
* is used to get all `@Input` and `@Output` Decorator
Expand Down
2 changes: 1 addition & 1 deletion app/vue/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { render, renderToDOM } from './render';
export { decorateStory } from './decorateStory';
export { decorateStory as applyDecorators } from './decorateStory';

export const parameters = { framework: 'vue' };
2 changes: 1 addition & 1 deletion app/vue3/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { render, renderToDOM } from './render';
export { decorateStory } from './decorateStory';
export { decorateStory as applyDecorators } from './decorateStory';

export const parameters = { framework: 'vue3' };
21 changes: 15 additions & 6 deletions docs/addons/writing-addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ Once you've gone through the prompts, your `package.json` should look like:

### Build system

We'll need to add the necessary dependencies and make some adjustments. Run the following commands:
We'll need to add the necessary dependencies and make some adjustments. Run the following command to install the required dependencies:

```shell
# Installs React and Babel CLI
yarn add react react-dom @babel/cli
<!-- prettier-ignore-start -->

# Adds Storybook:
<CodeSnippets
paths={[
'common/storybook-write-addon-install-dependencies.yarn.js.mdx',
'common/storybook-write-addon-install-dependencies.npm.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

Initialize a local Storybook instance to allow you to test your addon.

```shell
npx sb init
```

Expand Down Expand Up @@ -246,4 +255,4 @@ To dive deeper, we recommend Storybook's [creating an addon](https://storybook.j

### Addon kit

To help you jumpstart the addon development, the Storybook maintainers created an [`addon-kit`](https://github.com/storybookjs/addon-kit), use it to bootstrap your next addon.
To help you jumpstart the addon development, the Storybook maintainers created an [`addon-kit`](https://github.com/storybookjs/addon-kit), use it to bootstrap your next addon.
34 changes: 26 additions & 8 deletions docs/builders/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,34 @@ You can import `.json` files and have them expanded to a JavaScript object:

<!-- prettier-ignore-end -->

If you want to know the exact details of the Webpack config, the best way is to run either of the following:
If you want to know the exact details of the Webpack config, the best way is to run either of the following commands:

```shell
For development mode:

## Development mode
yarn start-storybook --debug-webpack
<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-debug-webpack-dev.yarn.js.mdx',
'common/storybook-debug-webpack-dev.npm.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

For production mode:

## Production mode
yarn build-storybook --debug-webpack
```

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'common/storybook-debug-webpack-prod.yarn.js.mdx',
'common/storybook-debug-webpack-prod.npm.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

### Code splitting

Expand Down Expand Up @@ -199,5 +217,5 @@ When working with TypeScript projects, the default Webpack configuration may fai
#### Learn more about builders

- [Vite builder](./vite.md) for bundling with Vite
- [Webpack builder](./webpack.md) for bundling with Webpack
- Webpack builder for bundling with Webpack
- [Builder API](./builder-api.md) for building a Storybook builder
6 changes: 6 additions & 0 deletions docs/configure/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ If you supply an environment variable prefixed with `STORYBOOK_`, it will be ava
STORYBOOK_THEME=red STORYBOOK_DATA_KEY=12345 npm run storybook
```

<div class="aside">

💡 Do not store any secrets (e.g., private API keys) or other types of sensitive information in your Storybook. Environment variables are embedded into the build, meaning anyone can view them by inspecting your files.

</div>

Then we can access these environment variables anywhere inside our preview JavaScript code like below:

<!-- prettier-ignore-start -->
Expand Down
Loading

0 comments on commit 6ea5609

Please sign in to comment.