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

Core: Zero-config TypeScript loading #10813

Merged
merged 42 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8310948
feat: add root TypeScript support
mrmckeb May 17, 2020
e7a460f
Add vue typescript component to kitchen sink
graup May 18, 2020
bb84352
Fix docgen preset
shilman May 18, 2020
322380f
Clean up typescriptOptions handling for docgen
shilman May 18, 2020
267a01e
Clean up `react-ts` example and addon-essentials for testing
shilman May 18, 2020
688dc43
React: Switch to react-docgen as the default config
shilman May 18, 2020
daf193a
Update failing tests
shilman May 18, 2020
1e621e3
Update main.js typescript docgen handling
shilman May 18, 2020
0b5b8c8
Update addon-jest.testresults.json
shilman May 18, 2020
d8431d3
Merge pull request #10816 from storybookjs/10790-fix-react-docgen-preset
shilman May 18, 2020
e88c51d
Merge branch 'next' into mrmckeb/issue10790
shilman May 18, 2020
6a19a43
Update package.json
shilman May 18, 2020
811b66b
FIX angular example tests
ndelangen May 18, 2020
5eda5b9
FIX problem with building all examples in CI (offset was wrong)
ndelangen May 18, 2020
ef2d51c
Add vue-cli example application
graup May 18, 2020
14d3e1b
Vue: Remove babel-preset-vue #4475
graup May 18, 2020
1ea6595
feat: update types and defaults
mrmckeb May 19, 2020
cb1a515
Merge pull request #10821 from graup/graup/vue-cli-example
shilman May 19, 2020
5270f07
Update package.json
shilman May 19, 2020
5949c37
Merge branch 'next' into mrmckeb/issue10790
ndelangen May 19, 2020
8bc3c9f
FIX tests
ndelangen May 19, 2020
a38d6cf
fix babel-loader-preview
tooppaaa May 19, 2020
8a98ecf
fix missing deps
tooppaaa May 19, 2020
d3c9910
fix deepscan
tooppaaa May 19, 2020
9b41d91
fix yarn lock
tooppaaa May 19, 2020
03136b7
Debugging CI
shilman May 20, 2020
ce38dee
Debug CI
shilman May 20, 2020
7948a71
Fix typescript-preset filtering
shilman May 20, 2020
bdbd62a
Build: Increase parallelism
shilman May 20, 2020
ebd8535
Attempt to unify ts-loader version for e2e tests
shilman May 20, 2020
5f95289
Update yarn.lock
shilman May 20, 2020
c7dfb35
Increase cypress navigation timeout for debugging
shilman May 20, 2020
bd7d479
Fix presets for windows paths
shilman May 20, 2020
3f4d4ef
Typescript: Filter out node_modules for docgen by default
shilman May 20, 2020
ee085e5
feat: improve shared types
mrmckeb May 20, 2020
4a4ccb4
Zero-config typescript: Updated MIGRATION and storybook documentation
shilman May 20, 2020
1336f76
Merge branch 'mrmckeb/issue10790' of github.com:storybookjs/storybook…
shilman May 20, 2020
6dfb786
fix: correct TSDoc error in shared types
mrmckeb May 20, 2020
3671955
Migrate sfc_vue fixture to use babel-preset-vue
shilman May 20, 2020
7b8e614
Apply babel fix to vue fixture as well
graup May 20, 2020
b50442f
Revert removal of babel-preset-vue
graup May 20, 2020
7a4724b
Revert removel of babel-preset-vue from app/vue
graup May 20, 2020
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: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- lib
chromatic:
<<: *defaults
parallelism: 10
parallelism: 11
steps:
- checkout
- attach_workspace:
Expand All @@ -77,7 +77,7 @@ jobs:
yarn packtracker
examples:
<<: *defaults
parallelism: 10
parallelism: 11
steps:
- checkout
- attach_workspace:
Expand Down
7 changes: 7 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<h1>Migration</h1>

- [From version 5.3.x to 6.0.x](#from-version-53x-to-60x)
- [Zero config typescript](#zero-config-typescript)
- [Backgrounds addon has a new api](#backgrounds-addon-has-a-new-api)
- [CRA preset removed](#cra-preset-removed)
- [Args passed as first argument to story](#args-passed-as-first-argument-to-story)
Expand Down Expand Up @@ -113,6 +114,12 @@

## From version 5.3.x to 6.0.x

### Zero config typescript

Storybook has built-in Typescript support in 6.0. That means you should remove your complex Typescript configurations from your `.storybook` config. We've tried to pick sensible defaults that work out of the box, especially for nice prop table generation in `@storybook/addon-docs`.

To migrate from an old setup, we recommend deleting any typescript-specific webpack/babel configurations in your project. If you want to override the defaults, see the [typescript configuration docs](https://github.com/storybookjs/storybook/blob/next/docs/src/pages/configurations/typescript-config/index.md).

### Backgrounds addon has a new api

Starting in 6.0, the backgrounds addon now receives an object instead of an array as parameter, with a property to define the default background.
Expand Down
1 change: 0 additions & 1 deletion app/angular/src/server/framework-preset-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export function webpack(
},
resolve: {
...config.resolve,
extensions: ['.ts', '.tsx', ...config.resolve.extensions],
},
plugins: [
...config.plugins,
Expand Down
1 change: 1 addition & 0 deletions app/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"lodash": "^4.17.15",
"prop-types": "^15.7.2",
"react-dev-utils": "^10.0.0",
"react-docgen-typescript-loader": "^3.7.2",
"regenerator-runtime": "^0.13.3",
"semver": "^7.3.2",
"ts-dedent": "^1.1.1",
Expand Down
72 changes: 16 additions & 56 deletions app/react/src/server/framework-preset-react-docgen.test.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,36 @@
import { TransformOptions } from '@babel/core';
import * as preset from './framework-preset-react-docgen';

describe('framework-preset-react-docgen', () => {
const babelPluginReactDocgenPath = require.resolve('babel-plugin-react-docgen');

it('should return the config with the extra plugins when `plugins` is an array.', () => {
it('should return the config with the extra plugin', () => {
const babelConfig = {
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['foo-plugin'],
};

const config = preset.babel(babelConfig);

expect(config).toEqual({
babelrc: false,
plugins: [
'foo-plugin',
[
babelPluginReactDocgenPath,
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
},
],
],
presets: ['env', 'foo-preset'],
const config = preset.babel(babelConfig, {
typescriptOptions: { check: false, reactDocgen: 'react-docgen' },
});
});

it('should return the config with the extra plugins when `plugins` is not an array.', () => {
const babelConfig: TransformOptions = {
babelrc: false,
presets: ['env', 'foo-preset'],
plugins: ['bar-plugin'],
};

const config = preset.babel(babelConfig);

expect(config).toEqual({
babelrc: false,
plugins: [
'bar-plugin',
[
babelPluginReactDocgenPath,
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
},
],
],
presets: ['env', 'foo-preset'],
});
});

it('should return the config only with the extra plugins when `plugins` is not present.', () => {
const babelConfig = {
babelrc: false,
plugins: ['foo-plugin'],
presets: ['env', 'foo-preset'],
};

const config = preset.babel(babelConfig);

expect(config).toEqual({
babelrc: false,
plugins: [
[
babelPluginReactDocgenPath,
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
},
],
overrides: [
{
test: /\.(mjs|tsx?|jsx?)$/,
plugins: [
[
babelPluginReactDocgenPath,
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
},
],
],
},
],
presets: ['env', 'foo-preset'],
});
});
});
54 changes: 41 additions & 13 deletions app/react/src/server/framework-preset-react-docgen.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
import { TransformOptions } from '@babel/core';
import type { TransformOptions } from '@babel/core';
import type { Configuration } from 'webpack';
import type { StorybookOptions } from '@storybook/core/types';

export function babel(config: TransformOptions) {
// Ensure plugins are defined or fallback to an array to avoid empty values.
const babelConfigPlugins = config.plugins || [];

const extraPlugins = [
[
require.resolve('babel-plugin-react-docgen'),
export function babel(config: TransformOptions, { typescriptOptions }: StorybookOptions) {
const { reactDocgen } = typescriptOptions;
if (!reactDocgen) {
return config;
}
return {
...config,
overrides: [
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
test: reactDocgen === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/,
plugins: [
[
require.resolve('babel-plugin-react-docgen'),
{
DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES',
},
],
],
},
],
];
};
}

// If `babelConfigPlugins` is not an `Array`, calling `concat` will inject it
// as a single value, if it is an `Array` it will spread.
export function webpackFinal(config: Configuration, { typescriptOptions }: StorybookOptions) {
const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions;
if (reactDocgen !== 'react-docgen-typescript') return config;
return {
...config,
plugins: [].concat(babelConfigPlugins, extraPlugins),
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.tsx?$/,
// include: path.resolve(__dirname, "../src"),
use: [
{
loader: require.resolve('react-docgen-typescript-loader'),
options: reactDocgenTypescriptOptions,
},
],
},
],
},
};
}
2 changes: 2 additions & 0 deletions app/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"global": "^4.3.2",
"regenerator-runtime": "^0.13.3",
"ts-dedent": "^1.1.1",
"ts-loader": "^6.2.2",
"webpack": "^4.43.0"
},
"devDependencies": {
Expand All @@ -57,6 +58,7 @@
"css-loader": "*",
"react": "*",
"react-dom": "*",
"ts-loader": "^6.2.2",
"vue": "^2.6.8",
"vue-loader": "^15.7.0",
"vue-template-compiler": "^2.6.8"
Expand Down
12 changes: 12 additions & 0 deletions app/vue/src/server/framework-preset-vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ export function webpack(config: Configuration) {
loader: require.resolve('vue-loader'),
options: {},
},
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('ts-loader'),
options: {
transpileOnly: true,
appendTsSuffixTo: [/\.vue$/],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrmckeb @graup will this run ts-loader on all *.vue even if the project is not a TS project? Is that an issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I'm not 100% sure, but if you remove lang="ts" from a TS SCF it stops working, so I assume ts-loader only gets applied if you specify that. Anyway, ts-loader without type checking is basically a no-op for .js files, so it wouldn't cause any issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested, this was from the PR @graup did for the TS preset - my understanding from the docs is that it should operate as @graup says above.

},
},
],
},
],
},
resolve: {
Expand Down
2 changes: 1 addition & 1 deletion cypress/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const visit = (route = '') => {
.clearLocalStorage()
.visit(getUrl(route))
.get(`#storybook-preview-iframe`)
.then({ timeout: 10000 }, (iframe) => {
.then({ timeout: 15000 }, (iframe) => {
return cy.wrap(iframe, { timeout: 10000 }).should(() => {
const content: Document | null = (iframe[0] as HTMLIFrameElement).contentDocument;
const element: HTMLElement | null = content !== null ? content.documentElement : null;
Expand Down
Loading