reactjs / reactjs/react-docgen
Can't reuse Babel plugins from Storybook
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 3.8k
- Fork
- 316
- Merge trung bình
- 5 giờ 7 phút
- Pull request đã merge (30 ngày)
- 4
Mô tả
I'm trying hard to add Storybook to a CRA(CO) app with some custom Babel plugins, but no matter what I do, I get complaints from react-docgen, stating there's no proposal for the pipeline operator:
WARN Failed to parse [...]/src/utils/Alerts.js with react-docgen. Please use the below error message and the content of the file which causes the error to report the issue to the maintainers of react-docgen. https://github.com/reactjs/react-docgen
SyntaxError: ./src/utils/Alerts.js: Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option. (21:60)
19 | }
20 |
> 21 | static #find = id => store.getState() |> getAlerts |> find(#, { id })
| ^
22 |
Unfortunately, this is a private project, so I can't provide reproducible examples :(
But I hope someone can find some jarring issue on the config files below, or any other idea brighter than Perplexity Pro could give me through the whole afternoon and night of this day.... 😞
I couldn't find a way to try to feed Babel configs directly to react-docgen without duplicating the Babel plugins and causing other issues.
Storybook version is 7.6.20 (because we're stuck in Node v16 for a while), but react-docgen is 7.1.1.
//craco.config.js
const webpack = require('webpack')
module.exports = {
babel: { loaderOptions: { configFile: true } },
webpack: {
configure: (webpackConfig) => {
webpackConfig.module.rules.push({
test: /\.pem$/i,
type: 'asset/source',
})
return webpackConfig
},
plugins: {
add: [
new webpack.DefinePlugin({ __SENTRY_DEBUG__: false })
],
},
},
}
//.storybook/main.js
/** @type { import('@storybook/react-webpack5').StorybookConfig } */
export default {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/preset-create-react-app",
"@storybook/addon-onboarding",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-webpack5",
options: {
builder: { useSWC: false },
},
},
// typescript: { reactDocgen: false }, //no clue why, but this can't get the correct pipelineOperator settings from Babel
babel: config => ({
...config,
loaderOptions: {
...config.loaderOptions,
configFile: true
},
}),
docs: {
autodocs: "tag",
},
staticDirs: ["../public"],
};
//.babel.config.js
module.exports = {
'plugins': [
'@babel/plugin-proposal-do-expressions',
'@babel/plugin-transform-class-static-block',
['@babel/plugin-proposal-pipeline-operator', { proposal: 'hack', topicToken: '#' }],
//future ideas in case they seem useful
// "@babel/plugin-proposal-throw-expressions"
// "@babel/plugin-proposal-export-default-from"
],
}
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách so sánh .storybook/main.js, .babel.config.js và craco.config.js để xác định react-docgen nhận cấu hình Babel nào. Tái hiện lỗi phân tích cú pháp toán tử pipeline trong một thiết lập công khai hoặc tối thiểu, sau đó xác minh rằng việc tạo tài liệu Storybook tuân theo proposal và topic token đã cấu hình mà không có cấu hình xung đột.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, typescript, webpack
- Lĩnh vực
- documentation, tooling
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100