-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
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 e7a460f
Add vue typescript component to kitchen sink
graup bb84352
Fix docgen preset
shilman 322380f
Clean up typescriptOptions handling for docgen
shilman 267a01e
Clean up `react-ts` example and addon-essentials for testing
shilman 688dc43
React: Switch to react-docgen as the default config
shilman daf193a
Update failing tests
shilman 1e621e3
Update main.js typescript docgen handling
shilman 0b5b8c8
Update addon-jest.testresults.json
shilman d8431d3
Merge pull request #10816 from storybookjs/10790-fix-react-docgen-preset
shilman e88c51d
Merge branch 'next' into mrmckeb/issue10790
shilman 6a19a43
Update package.json
shilman 811b66b
FIX angular example tests
ndelangen 5eda5b9
FIX problem with building all examples in CI (offset was wrong)
ndelangen ef2d51c
Add vue-cli example application
graup 14d3e1b
Vue: Remove babel-preset-vue #4475
graup 1ea6595
feat: update types and defaults
mrmckeb cb1a515
Merge pull request #10821 from graup/graup/vue-cli-example
shilman 5270f07
Update package.json
shilman 5949c37
Merge branch 'next' into mrmckeb/issue10790
ndelangen 8bc3c9f
FIX tests
ndelangen a38d6cf
fix babel-loader-preview
tooppaaa 8a98ecf
fix missing deps
tooppaaa d3c9910
fix deepscan
tooppaaa 9b41d91
fix yarn lock
tooppaaa 03136b7
Debugging CI
shilman ce38dee
Debug CI
shilman 7948a71
Fix typescript-preset filtering
shilman bdbd62a
Build: Increase parallelism
shilman ebd8535
Attempt to unify ts-loader version for e2e tests
shilman 5f95289
Update yarn.lock
shilman c7dfb35
Increase cypress navigation timeout for debugging
shilman bd7d479
Fix presets for windows paths
shilman 3f4d4ef
Typescript: Filter out node_modules for docgen by default
shilman ee085e5
feat: improve shared types
mrmckeb 4a4ccb4
Zero-config typescript: Updated MIGRATION and storybook documentation
shilman 1336f76
Merge branch 'mrmckeb/issue10790' of github.com:storybookjs/storybook…
shilman 6dfb786
fix: correct TSDoc error in shared types
mrmckeb 3671955
Migrate sfc_vue fixture to use babel-preset-vue
shilman 7b8e614
Apply babel fix to vue fixture as well
graup b50442f
Revert removal of babel-preset-vue
graup 7a4724b
Revert removel of babel-preset-vue from app/vue
graup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 16 additions & 56 deletions
72
app/react/src/server/framework-preset-react-docgen.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.