UNPKG

3.29 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.babel = babel;
7exports.previewAnnotations = void 0;
8exports.webpackFinal = webpackFinal;
9
10require("core-js/modules/es.promise.js");
11
12var _coreCommon = require("@storybook/core-common");
13
14var _reactDocgenTypescriptPlugin = _interopRequireDefault(require("@storybook/react-docgen-typescript-plugin"));
15
16var _docsTools = require("@storybook/docs-tools");
17
18function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
22function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
24function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
26async function babel(config, options) {
27 if (!(0, _docsTools.hasDocsOrControls)(options)) return config;
28 var typescriptOptions = await options.presets.apply('typescript', {});
29 var reactDocgen = typescriptOptions.reactDocgen;
30
31 if (typeof reactDocgen !== 'string') {
32 return config;
33 }
34
35 return _objectSpread(_objectSpread({}, config), {}, {
36 overrides: [...((config === null || config === void 0 ? void 0 : config.overrides) || []), {
37 test: reactDocgen === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/,
38 plugins: [[require.resolve('babel-plugin-react-docgen'), {
39 DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES'
40 }]]
41 }]
42 });
43}
44
45async function webpackFinal(config, options) {
46 if (!(0, _docsTools.hasDocsOrControls)(options)) return config;
47 var typescriptOptions = await options.presets.apply('typescript', {});
48 var reactDocgen = typescriptOptions.reactDocgen,
49 reactDocgenTypescriptOptions = typescriptOptions.reactDocgenTypescriptOptions;
50
51 if (reactDocgen !== 'react-docgen-typescript') {
52 return config;
53 }
54
55 return _objectSpread(_objectSpread({}, config), {}, {
56 plugins: [...config.plugins, new _reactDocgenTypescriptPlugin.default(_objectSpread(_objectSpread({}, reactDocgenTypescriptOptions), {}, {
57 // We *need* this set so that RDT returns default values in the same format as react-docgen
58 savePropValueAsString: true
59 }))]
60 });
61}
62
63var previewAnnotations = function (entry = [], options) {
64 if (!(0, _docsTools.hasDocsOrControls)(options)) return entry;
65 return [...entry, (0, _coreCommon.findDistEsm)(__dirname, 'client/docs/config')];
66};
67
68exports.previewAnnotations = previewAnnotations;
\No newline at end of file