@storybook/preset-react-webpack 7.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Storybook Webpack preset for React
2
+
3
+ This package is a [preset](https://storybook.js.org/docs/react/addons/writing-presets#presets-api) that configures Storybook's webpack settings for handling React.
4
+ It's an internal package that's not intended to be used directly by users.
5
+
6
+ - More info on [Storybook for React](https://storybook.js.org/docs/react/get-started/introduction)
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getReactScriptsPath = getReactScriptsPath;
7
+ exports.isReactScriptsInstalled = isReactScriptsInstalled;
8
+
9
+ require("core-js/modules/es.array.join.js");
10
+
11
+ require("core-js/modules/es.regexp.exec.js");
12
+
13
+ require("core-js/modules/es.string.match.js");
14
+
15
+ var _fs = _interopRequireDefault(require("fs"));
16
+
17
+ var _path = _interopRequireDefault(require("path"));
18
+
19
+ var _semver = _interopRequireDefault(require("@storybook/semver"));
20
+
21
+ var _nodeLogger = require("@storybook/node-logger");
22
+
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+
25
+ var appDirectory = _fs.default.realpathSync(process.cwd());
26
+
27
+ var reactScriptsPath;
28
+
29
+ function getReactScriptsPath() {
30
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
31
+ noCache = _ref.noCache;
32
+
33
+ if (reactScriptsPath && !noCache) return reactScriptsPath;
34
+
35
+ var reactScriptsScriptPath = _fs.default.realpathSync(_path.default.join(appDirectory, '/node_modules/.bin/react-scripts'));
36
+
37
+ try {
38
+ // Note: Since there is no symlink for .bin/react-scripts on Windows
39
+ // we'll parse react-scripts file to find actual package path.
40
+ // This is important if you use fork of CRA.
41
+ var pathIsNotResolved = /node_modules[\\/]\.bin[\\/]react-scripts/i.test(reactScriptsScriptPath);
42
+
43
+ if (pathIsNotResolved) {
44
+ var content = _fs.default.readFileSync(reactScriptsScriptPath, 'utf8');
45
+
46
+ var packagePathMatch = content.match(/"\$basedir[\\/]([^\s]+?[\\/]bin[\\/]react-scripts\.js")/i);
47
+
48
+ if (packagePathMatch && packagePathMatch.length > 1) {
49
+ reactScriptsScriptPath = _path.default.join(appDirectory, '/node_modules/.bin/', packagePathMatch[1]);
50
+ }
51
+ }
52
+ } catch (e) {
53
+ _nodeLogger.logger.warn("Error occurred during react-scripts package path resolving: ".concat(e));
54
+ }
55
+
56
+ reactScriptsPath = _path.default.join(reactScriptsScriptPath, '../..');
57
+
58
+ var scriptsPkgJson = _path.default.join(reactScriptsPath, 'package.json');
59
+
60
+ if (!_fs.default.existsSync(scriptsPkgJson)) {
61
+ reactScriptsPath = 'react-scripts';
62
+ }
63
+
64
+ return reactScriptsPath;
65
+ }
66
+
67
+ function isReactScriptsInstalled() {
68
+ var requiredVersion = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '2.0.0';
69
+
70
+ try {
71
+ // eslint-disable-next-line import/no-dynamic-require,global-require
72
+ var reactScriptsJson = require(_path.default.join(getReactScriptsPath(), 'package.json'));
73
+
74
+ return !_semver.default.gtr(requiredVersion, reactScriptsJson.version);
75
+ } catch (e) {
76
+ return false;
77
+ }
78
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.webpackFinal = void 0;
7
+
8
+ require("core-js/modules/es.object.to-string.js");
9
+
10
+ require("core-js/modules/es.function.name.js");
11
+
12
+ require("core-js/modules/es.regexp.exec.js");
13
+
14
+ var _nodeLogger = require("@storybook/node-logger");
15
+
16
+ var _craConfig = require("./cra-config");
17
+
18
+ var checkForNewPreset = function checkForNewPreset(presetsList) {
19
+ var hasNewPreset = presetsList.some(function (preset) {
20
+ var presetName = typeof preset === 'string' ? preset : preset.name;
21
+ return /@storybook(\/|\\)preset-create-react-app/.test(presetName);
22
+ });
23
+
24
+ if (!hasNewPreset) {
25
+ _nodeLogger.logger.warn('Storybook support for Create React App is now a separate preset.');
26
+
27
+ _nodeLogger.logger.warn('To use the new preset, install `@storybook/preset-create-react-app` and add it to the list of `addons` in your `.storybook/main.js` config file.');
28
+
29
+ _nodeLogger.logger.warn('The built-in preset has been disabled in Storybook 6.0.');
30
+ }
31
+ };
32
+
33
+ var webpackFinal = function webpackFinal(config, _ref) {
34
+ var presetsList = _ref.presetsList;
35
+
36
+ if ((0, _craConfig.isReactScriptsInstalled)()) {
37
+ checkForNewPreset(presetsList);
38
+ }
39
+
40
+ return config;
41
+ };
42
+
43
+ exports.webpackFinal = webpackFinal;
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ require("core-js/modules/es.symbol.js");
6
+
7
+ require("core-js/modules/es.symbol.description.js");
8
+
9
+ require("core-js/modules/es.symbol.iterator.js");
10
+
11
+ require("core-js/modules/es.array.iterator.js");
12
+
13
+ require("core-js/modules/es.string.iterator.js");
14
+
15
+ require("core-js/modules/web.dom-collections.iterator.js");
16
+
17
+ require("core-js/modules/es.array.from.js");
18
+
19
+ require("core-js/modules/es.array.slice.js");
20
+
21
+ require("core-js/modules/es.function.name.js");
22
+
23
+ require("core-js/modules/es.regexp.exec.js");
24
+
25
+ require("core-js/modules/es.symbol.async-iterator.js");
26
+
27
+ require("core-js/modules/es.symbol.to-string-tag.js");
28
+
29
+ require("core-js/modules/es.json.to-string-tag.js");
30
+
31
+ require("core-js/modules/es.math.to-string-tag.js");
32
+
33
+ require("core-js/modules/es.object.get-prototype-of.js");
34
+
35
+ require("core-js/modules/web.dom-collections.for-each.js");
36
+
37
+ Object.defineProperty(exports, "__esModule", {
38
+ value: true
39
+ });
40
+ exports.webpackFinal = exports.babel = void 0;
41
+
42
+ require("core-js/modules/es.object.assign.js");
43
+
44
+ require("core-js/modules/es.array.concat.js");
45
+
46
+ require("core-js/modules/es.object.to-string.js");
47
+
48
+ require("core-js/modules/es.promise.js");
49
+
50
+ var _reactDocgenTypescriptPlugin = _interopRequireDefault(require("@storybook/react-docgen-typescript-plugin"));
51
+
52
+ var _docsTools = require("@storybook/docs-tools");
53
+
54
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
55
+
56
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
57
+
58
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
59
+
60
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
61
+
62
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
63
+
64
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
65
+
66
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
67
+
68
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
69
+
70
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
71
+
72
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
73
+
74
+ var babel = /*#__PURE__*/function () {
75
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, options) {
76
+ var typescriptOptions, reactDocgen;
77
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
78
+ while (1) {
79
+ switch (_context.prev = _context.next) {
80
+ case 0:
81
+ if ((0, _docsTools.hasDocsOrControls)(options)) {
82
+ _context.next = 2;
83
+ break;
84
+ }
85
+
86
+ return _context.abrupt("return", config);
87
+
88
+ case 2:
89
+ _context.next = 4;
90
+ return options.presets.apply('typescript', {});
91
+
92
+ case 4:
93
+ typescriptOptions = _context.sent;
94
+ reactDocgen = typescriptOptions.reactDocgen;
95
+
96
+ if (!(typeof reactDocgen !== 'string')) {
97
+ _context.next = 8;
98
+ break;
99
+ }
100
+
101
+ return _context.abrupt("return", config);
102
+
103
+ case 8:
104
+ return _context.abrupt("return", Object.assign({}, config, {
105
+ overrides: [].concat(_toConsumableArray((config === null || config === void 0 ? void 0 : config.overrides) || []), [{
106
+ test: reactDocgen === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/,
107
+ plugins: [[require.resolve('babel-plugin-react-docgen'), {
108
+ DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES'
109
+ }]]
110
+ }])
111
+ }));
112
+
113
+ case 9:
114
+ case "end":
115
+ return _context.stop();
116
+ }
117
+ }
118
+ }, _callee);
119
+ }));
120
+
121
+ return function babel(_x, _x2) {
122
+ return _ref.apply(this, arguments);
123
+ };
124
+ }();
125
+
126
+ exports.babel = babel;
127
+
128
+ var webpackFinal = /*#__PURE__*/function () {
129
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config, options) {
130
+ var typescriptOptions, reactDocgen, reactDocgenTypescriptOptions;
131
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
132
+ while (1) {
133
+ switch (_context2.prev = _context2.next) {
134
+ case 0:
135
+ if ((0, _docsTools.hasDocsOrControls)(options)) {
136
+ _context2.next = 2;
137
+ break;
138
+ }
139
+
140
+ return _context2.abrupt("return", config);
141
+
142
+ case 2:
143
+ _context2.next = 4;
144
+ return options.presets.apply('typescript', {});
145
+
146
+ case 4:
147
+ typescriptOptions = _context2.sent;
148
+ reactDocgen = typescriptOptions.reactDocgen, reactDocgenTypescriptOptions = typescriptOptions.reactDocgenTypescriptOptions;
149
+
150
+ if (!(reactDocgen !== 'react-docgen-typescript')) {
151
+ _context2.next = 8;
152
+ break;
153
+ }
154
+
155
+ return _context2.abrupt("return", config);
156
+
157
+ case 8:
158
+ return _context2.abrupt("return", Object.assign({}, config, {
159
+ plugins: [].concat(_toConsumableArray(config.plugins), [new _reactDocgenTypescriptPlugin.default(Object.assign({}, reactDocgenTypescriptOptions, {
160
+ // We *need* this set so that RDT returns default values in the same format as react-docgen
161
+ savePropValueAsString: true
162
+ }))])
163
+ }));
164
+
165
+ case 9:
166
+ case "end":
167
+ return _context2.stop();
168
+ }
169
+ }
170
+ }, _callee2);
171
+ }));
172
+
173
+ return function webpackFinal(_x3, _x4) {
174
+ return _ref2.apply(this, arguments);
175
+ };
176
+ }();
177
+
178
+ exports.webpackFinal = webpackFinal;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ require("core-js/modules/es.symbol.js");
6
+
7
+ require("core-js/modules/es.symbol.description.js");
8
+
9
+ require("core-js/modules/es.symbol.iterator.js");
10
+
11
+ require("core-js/modules/es.array.iterator.js");
12
+
13
+ require("core-js/modules/es.string.iterator.js");
14
+
15
+ require("core-js/modules/web.dom-collections.iterator.js");
16
+
17
+ require("core-js/modules/es.array.from.js");
18
+
19
+ require("core-js/modules/es.array.slice.js");
20
+
21
+ require("core-js/modules/es.function.name.js");
22
+
23
+ require("core-js/modules/es.regexp.exec.js");
24
+
25
+ require("core-js/modules/es.symbol.async-iterator.js");
26
+
27
+ require("core-js/modules/es.symbol.to-string-tag.js");
28
+
29
+ require("core-js/modules/es.json.to-string-tag.js");
30
+
31
+ require("core-js/modules/es.math.to-string-tag.js");
32
+
33
+ require("core-js/modules/es.object.get-prototype-of.js");
34
+
35
+ require("core-js/modules/web.dom-collections.for-each.js");
36
+
37
+ Object.defineProperty(exports, "__esModule", {
38
+ value: true
39
+ });
40
+ exports.webpackFinal = void 0;
41
+
42
+ require("core-js/modules/es.object.assign.js");
43
+
44
+ require("core-js/modules/es.array.filter.js");
45
+
46
+ require("core-js/modules/es.object.to-string.js");
47
+
48
+ require("core-js/modules/es.array.concat.js");
49
+
50
+ require("core-js/modules/es.string.starts-with.js");
51
+
52
+ require("core-js/modules/es.promise.js");
53
+
54
+ var _fsExtra = require("fs-extra");
55
+
56
+ var _webpack = require("webpack");
57
+
58
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
59
+
60
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
61
+
62
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
63
+
64
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
65
+
66
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
67
+
68
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
69
+
70
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
71
+
72
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
73
+
74
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
75
+
76
+ // this is a hack to allow importing react-dom/client even when it's not available
77
+ // this should be removed once we drop support for react-dom < 18
78
+ var webpackFinal = /*#__PURE__*/function () {
79
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
80
+ var reactDomPkg;
81
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
82
+ while (1) {
83
+ switch (_context.prev = _context.next) {
84
+ case 0:
85
+ _context.next = 2;
86
+ return (0, _fsExtra.readJSON)(require.resolve('react-dom/package.json'));
87
+
88
+ case 2:
89
+ reactDomPkg = _context.sent;
90
+ return _context.abrupt("return", Object.assign({}, config, {
91
+ plugins: [].concat(_toConsumableArray(config.plugins), [reactDomPkg.version.startsWith('18') || reactDomPkg.version.startsWith('0.0.0') ? null : new _webpack.IgnorePlugin({
92
+ resourceRegExp: /react-dom\/client$/,
93
+ contextRegExp: /(renderers\/react|renderers\\react|@storybook\/react|@storybook\\react)/ // TODO this needs to work for both in our MONOREPO and in the user's NODE_MODULES
94
+
95
+ })]).filter(Boolean)
96
+ }));
97
+
98
+ case 4:
99
+ case "end":
100
+ return _context.stop();
101
+ }
102
+ }
103
+ }, _callee);
104
+ }));
105
+
106
+ return function webpackFinal(_x) {
107
+ return _ref.apply(this, arguments);
108
+ };
109
+ }();
110
+
111
+ exports.webpackFinal = webpackFinal;
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.js");
4
+
5
+ require("core-js/modules/es.symbol.description.js");
6
+
7
+ require("core-js/modules/es.symbol.iterator.js");
8
+
9
+ require("core-js/modules/es.array.iterator.js");
10
+
11
+ require("core-js/modules/es.string.iterator.js");
12
+
13
+ require("core-js/modules/web.dom-collections.iterator.js");
14
+
15
+ require("core-js/modules/es.symbol.async-iterator.js");
16
+
17
+ require("core-js/modules/es.symbol.to-string-tag.js");
18
+
19
+ require("core-js/modules/es.json.to-string-tag.js");
20
+
21
+ require("core-js/modules/es.math.to-string-tag.js");
22
+
23
+ require("core-js/modules/es.object.get-prototype-of.js");
24
+
25
+ require("core-js/modules/web.dom-collections.for-each.js");
26
+
27
+ require("core-js/modules/es.array.slice.js");
28
+
29
+ require("core-js/modules/es.array.from.js");
30
+
31
+ require("core-js/modules/es.regexp.exec.js");
32
+
33
+ Object.defineProperty(exports, "__esModule", {
34
+ value: true
35
+ });
36
+ exports.webpackFinal = exports.babelDefault = exports.babel = void 0;
37
+
38
+ require("core-js/modules/es.object.assign.js");
39
+
40
+ require("core-js/modules/es.array.concat.js");
41
+
42
+ require("core-js/modules/es.array.includes.js");
43
+
44
+ require("core-js/modules/es.string.includes.js");
45
+
46
+ require("core-js/modules/es.array.join.js");
47
+
48
+ require("core-js/modules/es.array.find.js");
49
+
50
+ require("core-js/modules/es.object.to-string.js");
51
+
52
+ require("core-js/modules/es.function.name.js");
53
+
54
+ require("core-js/modules/es.promise.js");
55
+
56
+ var _path = _interopRequireDefault(require("path"));
57
+
58
+ var _reactRefreshWebpackPlugin = _interopRequireDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
59
+
60
+ var _nodeLogger = require("@storybook/node-logger");
61
+
62
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
+
64
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
65
+
66
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
67
+
68
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
69
+
70
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
71
+
72
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
73
+
74
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
75
+
76
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
77
+
78
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
79
+
80
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
81
+
82
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
83
+
84
+ var useFastRefresh = /*#__PURE__*/function () {
85
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
86
+ var isDevelopment, framework, reactOptions;
87
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
88
+ while (1) {
89
+ switch (_context.prev = _context.next) {
90
+ case 0:
91
+ isDevelopment = options.configType === 'DEVELOPMENT';
92
+ _context.next = 3;
93
+ return options.presets.apply('framework');
94
+
95
+ case 3:
96
+ framework = _context.sent;
97
+ reactOptions = _typeof(framework) === 'object' ? framework.options : {};
98
+ return _context.abrupt("return", isDevelopment && (reactOptions.fastRefresh || process.env.FAST_REFRESH === 'true'));
99
+
100
+ case 6:
101
+ case "end":
102
+ return _context.stop();
103
+ }
104
+ }
105
+ }, _callee);
106
+ }));
107
+
108
+ return function useFastRefresh(_x) {
109
+ return _ref.apply(this, arguments);
110
+ };
111
+ }();
112
+
113
+ var babel = /*#__PURE__*/function () {
114
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config, options) {
115
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
116
+ while (1) {
117
+ switch (_context2.prev = _context2.next) {
118
+ case 0:
119
+ _context2.next = 2;
120
+ return useFastRefresh(options);
121
+
122
+ case 2:
123
+ if (_context2.sent) {
124
+ _context2.next = 4;
125
+ break;
126
+ }
127
+
128
+ return _context2.abrupt("return", config);
129
+
130
+ case 4:
131
+ return _context2.abrupt("return", Object.assign({}, config, {
132
+ plugins: [[require.resolve('react-refresh/babel'), {}, 'storybook-react-refresh']].concat(_toConsumableArray(config.plugins || []))
133
+ }));
134
+
135
+ case 5:
136
+ case "end":
137
+ return _context2.stop();
138
+ }
139
+ }
140
+ }, _callee2);
141
+ }));
142
+
143
+ return function babel(_x2, _x3) {
144
+ return _ref2.apply(this, arguments);
145
+ };
146
+ }();
147
+
148
+ exports.babel = babel;
149
+
150
+ var storybookReactDirName = _path.default.dirname(require.resolve('@storybook/preset-react-webpack/package.json')); // TODO: improve node_modules detection
151
+
152
+
153
+ var context = storybookReactDirName.includes('node_modules') ? _path.default.join(storybookReactDirName, '../../') // Real life case, already in node_modules
154
+ : _path.default.join(storybookReactDirName, '../../node_modules'); // SB Monorepo
155
+
156
+ var hasJsxRuntime = function hasJsxRuntime() {
157
+ try {
158
+ require.resolve('react/jsx-runtime', {
159
+ paths: [context]
160
+ });
161
+
162
+ return true;
163
+ } catch (e) {
164
+ return false;
165
+ }
166
+ };
167
+
168
+ var babelDefault = /*#__PURE__*/function () {
169
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(config) {
170
+ var presetReactOptions;
171
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
172
+ while (1) {
173
+ switch (_context3.prev = _context3.next) {
174
+ case 0:
175
+ presetReactOptions = hasJsxRuntime() ? {
176
+ runtime: 'automatic'
177
+ } : {};
178
+ return _context3.abrupt("return", Object.assign({}, config, {
179
+ presets: [].concat(_toConsumableArray((config === null || config === void 0 ? void 0 : config.presets) || []), [[require.resolve('@babel/preset-react'), presetReactOptions], require.resolve('@babel/preset-flow')]),
180
+ plugins: [].concat(_toConsumableArray((config === null || config === void 0 ? void 0 : config.plugins) || []), [require.resolve('babel-plugin-add-react-displayname')])
181
+ }));
182
+
183
+ case 2:
184
+ case "end":
185
+ return _context3.stop();
186
+ }
187
+ }
188
+ }, _callee3);
189
+ }));
190
+
191
+ return function babelDefault(_x4) {
192
+ return _ref3.apply(this, arguments);
193
+ };
194
+ }();
195
+
196
+ exports.babelDefault = babelDefault;
197
+
198
+ var webpackFinal = /*#__PURE__*/function () {
199
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config, options) {
200
+ var hasReactRefresh;
201
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
202
+ while (1) {
203
+ switch (_context4.prev = _context4.next) {
204
+ case 0:
205
+ _context4.next = 2;
206
+ return useFastRefresh(options);
207
+
208
+ case 2:
209
+ if (_context4.sent) {
210
+ _context4.next = 4;
211
+ break;
212
+ }
213
+
214
+ return _context4.abrupt("return", config);
215
+
216
+ case 4:
217
+ // matches the name of the plugin in CRA.
218
+ hasReactRefresh = config.plugins.find(function (p) {
219
+ return p.constructor.name === 'ReactRefreshPlugin';
220
+ });
221
+
222
+ if (!hasReactRefresh) {
223
+ _context4.next = 8;
224
+ break;
225
+ }
226
+
227
+ _nodeLogger.logger.warn("=> React refresh is already set. You don't need to set the option");
228
+
229
+ return _context4.abrupt("return", config);
230
+
231
+ case 8:
232
+ _nodeLogger.logger.info('=> Using React fast refresh');
233
+
234
+ return _context4.abrupt("return", Object.assign({}, config, {
235
+ plugins: [].concat(_toConsumableArray(config.plugins), [// Storybook uses webpack-hot-middleware https://github.com/storybookjs/storybook/issues/14114
236
+ new _reactRefreshWebpackPlugin.default({
237
+ overlay: {
238
+ sockIntegration: 'whm'
239
+ }
240
+ })])
241
+ }));
242
+
243
+ case 10:
244
+ case "end":
245
+ return _context4.stop();
246
+ }
247
+ }
248
+ }, _callee4);
249
+ }));
250
+
251
+ return function webpackFinal(_x5, _x6) {
252
+ return _ref4.apply(this, arguments);
253
+ };
254
+ }();
255
+
256
+ exports.webpackFinal = webpackFinal;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.to-string.js");
4
+
5
+ require("core-js/modules/web.dom-collections.for-each.js");
6
+
7
+ require("core-js/modules/es.object.keys.js");
8
+
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ var _exportNames = {
13
+ addons: true
14
+ };
15
+ exports.addons = void 0;
16
+
17
+ var _types = require("./types");
18
+
19
+ Object.keys(_types).forEach(function (key) {
20
+ if (key === "default" || key === "__esModule") return;
21
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
22
+ if (key in exports && exports[key] === _types[key]) return;
23
+ Object.defineProperty(exports, key, {
24
+ enumerable: true,
25
+ get: function get() {
26
+ return _types[key];
27
+ }
28
+ });
29
+ });
30
+ var addons = [require.resolve('./framework-preset-react'), require.resolve('./framework-preset-react-dom-hack'), require.resolve('./framework-preset-cra'), require.resolve('./framework-preset-react-docs')];
31
+ exports.addons = addons;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,49 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import semver from '@storybook/semver';
4
+ import { logger } from '@storybook/node-logger';
5
+ const appDirectory = fs.realpathSync(process.cwd());
6
+ let reactScriptsPath;
7
+ export function getReactScriptsPath({
8
+ noCache
9
+ } = {}) {
10
+ if (reactScriptsPath && !noCache) return reactScriptsPath;
11
+ let reactScriptsScriptPath = fs.realpathSync(path.join(appDirectory, '/node_modules/.bin/react-scripts'));
12
+
13
+ try {
14
+ // Note: Since there is no symlink for .bin/react-scripts on Windows
15
+ // we'll parse react-scripts file to find actual package path.
16
+ // This is important if you use fork of CRA.
17
+ const pathIsNotResolved = /node_modules[\\/]\.bin[\\/]react-scripts/i.test(reactScriptsScriptPath);
18
+
19
+ if (pathIsNotResolved) {
20
+ const content = fs.readFileSync(reactScriptsScriptPath, 'utf8');
21
+ const packagePathMatch = content.match(/"\$basedir[\\/]([^\s]+?[\\/]bin[\\/]react-scripts\.js")/i);
22
+
23
+ if (packagePathMatch && packagePathMatch.length > 1) {
24
+ reactScriptsScriptPath = path.join(appDirectory, '/node_modules/.bin/', packagePathMatch[1]);
25
+ }
26
+ }
27
+ } catch (e) {
28
+ logger.warn(`Error occurred during react-scripts package path resolving: ${e}`);
29
+ }
30
+
31
+ reactScriptsPath = path.join(reactScriptsScriptPath, '../..');
32
+ const scriptsPkgJson = path.join(reactScriptsPath, 'package.json');
33
+
34
+ if (!fs.existsSync(scriptsPkgJson)) {
35
+ reactScriptsPath = 'react-scripts';
36
+ }
37
+
38
+ return reactScriptsPath;
39
+ }
40
+ export function isReactScriptsInstalled(requiredVersion = '2.0.0') {
41
+ try {
42
+ // eslint-disable-next-line import/no-dynamic-require,global-require
43
+ const reactScriptsJson = require(path.join(getReactScriptsPath(), 'package.json'));
44
+
45
+ return !semver.gtr(requiredVersion, reactScriptsJson.version);
46
+ } catch (e) {
47
+ return false;
48
+ }
49
+ }
@@ -0,0 +1,25 @@
1
+ import { logger } from '@storybook/node-logger';
2
+ import { isReactScriptsInstalled } from './cra-config';
3
+
4
+ const checkForNewPreset = presetsList => {
5
+ const hasNewPreset = presetsList.some(preset => {
6
+ const presetName = typeof preset === 'string' ? preset : preset.name;
7
+ return /@storybook(\/|\\)preset-create-react-app/.test(presetName);
8
+ });
9
+
10
+ if (!hasNewPreset) {
11
+ logger.warn('Storybook support for Create React App is now a separate preset.');
12
+ logger.warn('To use the new preset, install `@storybook/preset-create-react-app` and add it to the list of `addons` in your `.storybook/main.js` config file.');
13
+ logger.warn('The built-in preset has been disabled in Storybook 6.0.');
14
+ }
15
+ };
16
+
17
+ export const webpackFinal = (config, {
18
+ presetsList
19
+ }) => {
20
+ if (isReactScriptsInstalled()) {
21
+ checkForNewPreset(presetsList);
22
+ }
23
+
24
+ return config;
25
+ };
@@ -0,0 +1,41 @@
1
+ import ReactDocgenTypescriptPlugin from '@storybook/react-docgen-typescript-plugin';
2
+ import { hasDocsOrControls } from '@storybook/docs-tools';
3
+ export const babel = async (config, options) => {
4
+ if (!hasDocsOrControls(options)) return config;
5
+ const typescriptOptions = await options.presets.apply('typescript', {});
6
+ const {
7
+ reactDocgen
8
+ } = typescriptOptions;
9
+
10
+ if (typeof reactDocgen !== 'string') {
11
+ return config;
12
+ }
13
+
14
+ return Object.assign({}, config, {
15
+ overrides: [...(config?.overrides || []), {
16
+ test: reactDocgen === 'react-docgen' ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/,
17
+ plugins: [[require.resolve('babel-plugin-react-docgen'), {
18
+ DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES'
19
+ }]]
20
+ }]
21
+ });
22
+ };
23
+ export const webpackFinal = async (config, options) => {
24
+ if (!hasDocsOrControls(options)) return config;
25
+ const typescriptOptions = await options.presets.apply('typescript', {});
26
+ const {
27
+ reactDocgen,
28
+ reactDocgenTypescriptOptions
29
+ } = typescriptOptions;
30
+
31
+ if (reactDocgen !== 'react-docgen-typescript') {
32
+ return config;
33
+ }
34
+
35
+ return Object.assign({}, config, {
36
+ plugins: [...config.plugins, new ReactDocgenTypescriptPlugin(Object.assign({}, reactDocgenTypescriptOptions, {
37
+ // We *need* this set so that RDT returns default values in the same format as react-docgen
38
+ savePropValueAsString: true
39
+ }))]
40
+ });
41
+ };
@@ -0,0 +1,14 @@
1
+ import { readJSON } from 'fs-extra';
2
+ import { IgnorePlugin } from 'webpack';
3
+ // this is a hack to allow importing react-dom/client even when it's not available
4
+ // this should be removed once we drop support for react-dom < 18
5
+ export const webpackFinal = async config => {
6
+ const reactDomPkg = await readJSON(require.resolve('react-dom/package.json'));
7
+ return Object.assign({}, config, {
8
+ plugins: [...config.plugins, reactDomPkg.version.startsWith('18') || reactDomPkg.version.startsWith('0.0.0') ? null : new IgnorePlugin({
9
+ resourceRegExp: /react-dom\/client$/,
10
+ contextRegExp: /(renderers\/react|renderers\\react|@storybook\/react|@storybook\\react)/ // TODO this needs to work for both in our MONOREPO and in the user's NODE_MODULES
11
+
12
+ })].filter(Boolean)
13
+ });
14
+ };
@@ -0,0 +1,63 @@
1
+ import path from 'path';
2
+ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
3
+ import { logger } from '@storybook/node-logger';
4
+
5
+ const useFastRefresh = async options => {
6
+ const isDevelopment = options.configType === 'DEVELOPMENT';
7
+ const framework = await options.presets.apply('framework');
8
+ const reactOptions = typeof framework === 'object' ? framework.options : {};
9
+ return isDevelopment && (reactOptions.fastRefresh || process.env.FAST_REFRESH === 'true');
10
+ };
11
+
12
+ export const babel = async (config, options) => {
13
+ if (!(await useFastRefresh(options))) return config;
14
+ return Object.assign({}, config, {
15
+ plugins: [[require.resolve('react-refresh/babel'), {}, 'storybook-react-refresh'], ...(config.plugins || [])]
16
+ });
17
+ };
18
+ const storybookReactDirName = path.dirname(require.resolve('@storybook/preset-react-webpack/package.json')); // TODO: improve node_modules detection
19
+
20
+ const context = storybookReactDirName.includes('node_modules') ? path.join(storybookReactDirName, '../../') // Real life case, already in node_modules
21
+ : path.join(storybookReactDirName, '../../node_modules'); // SB Monorepo
22
+
23
+ const hasJsxRuntime = () => {
24
+ try {
25
+ require.resolve('react/jsx-runtime', {
26
+ paths: [context]
27
+ });
28
+
29
+ return true;
30
+ } catch (e) {
31
+ return false;
32
+ }
33
+ };
34
+
35
+ export const babelDefault = async config => {
36
+ const presetReactOptions = hasJsxRuntime() ? {
37
+ runtime: 'automatic'
38
+ } : {};
39
+ return Object.assign({}, config, {
40
+ presets: [...(config?.presets || []), [require.resolve('@babel/preset-react'), presetReactOptions], require.resolve('@babel/preset-flow')],
41
+ plugins: [...(config?.plugins || []), require.resolve('babel-plugin-add-react-displayname')]
42
+ });
43
+ };
44
+ export const webpackFinal = async (config, options) => {
45
+ if (!(await useFastRefresh(options))) return config; // matches the name of the plugin in CRA.
46
+
47
+ const hasReactRefresh = config.plugins.find(p => p.constructor.name === 'ReactRefreshPlugin');
48
+
49
+ if (hasReactRefresh) {
50
+ logger.warn("=> React refresh is already set. You don't need to set the option");
51
+ return config;
52
+ }
53
+
54
+ logger.info('=> Using React fast refresh');
55
+ return Object.assign({}, config, {
56
+ plugins: [...config.plugins, // Storybook uses webpack-hot-middleware https://github.com/storybookjs/storybook/issues/14114
57
+ new ReactRefreshWebpackPlugin({
58
+ overlay: {
59
+ sockIntegration: 'whm'
60
+ }
61
+ })]
62
+ });
63
+ };
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export const addons = [require.resolve('./framework-preset-react'), require.resolve('./framework-preset-react-dom-hack'), require.resolve('./framework-preset-cra'), require.resolve('./framework-preset-react-docs')];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare function getReactScriptsPath({ noCache }?: {
2
+ noCache?: boolean;
3
+ }): string;
4
+ export declare function isReactScriptsInstalled(requiredVersion?: string): boolean;
@@ -0,0 +1,2 @@
1
+ import type { StorybookConfig } from '@storybook/core-webpack';
2
+ export declare const webpackFinal: StorybookConfig['webpack'];
@@ -0,0 +1,3 @@
1
+ import type { StorybookConfig } from './types';
2
+ export declare const babel: StorybookConfig['babel'];
3
+ export declare const webpackFinal: StorybookConfig['webpackFinal'];
@@ -0,0 +1,2 @@
1
+ import type { StorybookConfig } from '@storybook/core-webpack';
2
+ export declare const webpackFinal: StorybookConfig['webpackFinal'];
@@ -0,0 +1,4 @@
1
+ import type { StorybookConfig } from '@storybook/core-webpack';
2
+ export declare const babel: StorybookConfig['babel'];
3
+ export declare const babelDefault: StorybookConfig['babelDefault'];
4
+ export declare const webpackFinal: StorybookConfig['webpackFinal'];
@@ -0,0 +1,3 @@
1
+ import type { StorybookConfig } from './types';
2
+ export * from './types';
3
+ export declare const addons: StorybookConfig['addons'];
@@ -0,0 +1,42 @@
1
+ import type { CommonWebpackConfiguration, StorybookConfig as BaseStorybookConfig, TypescriptOptions as BaseTypescriptOptions } from '@storybook/core-webpack';
2
+ import type { PluginOptions as ReactDocgenTypescriptOptions } from '@storybook/react-docgen-typescript-plugin';
3
+ export type { BuilderResult } from '@storybook/core-webpack';
4
+ export interface ReactOptions {
5
+ fastRefresh?: boolean;
6
+ strictMode?: boolean;
7
+ /**
8
+ * Use React's legacy root API to mount components
9
+ * @description
10
+ * React has introduced a new root API with React 18.x to enable a whole set of new features (e.g. concurrent features)
11
+ * If this flag is true, the legacy Root API is used to mount components to make it easier to migrate step by step to React 18.
12
+ * @default false
13
+ */
14
+ legacyRootApi?: boolean;
15
+ }
16
+ /**
17
+ * The interface for Storybook configuration in `main.ts` files.
18
+ */
19
+ export interface ReactConfig {
20
+ framework: string | {
21
+ name: '@storybook/react';
22
+ options: ReactOptions;
23
+ };
24
+ }
25
+ export declare type TypescriptOptions = BaseTypescriptOptions & {
26
+ /**
27
+ * Sets the type of Docgen when working with React and TypeScript
28
+ *
29
+ * @default `'react-docgen-typescript'`
30
+ */
31
+ reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
32
+ /**
33
+ * Configures `react-docgen-typescript-plugin`
34
+ *
35
+ * @default
36
+ * @see https://github.com/storybookjs/storybook/blob/next/lib/builder-webpack5/src/config/defaults.js#L4-L6
37
+ */
38
+ reactDocgenTypescriptOptions: ReactDocgenTypescriptOptions;
39
+ };
40
+ export declare type StorybookConfig<TWebpackConfiguration = CommonWebpackConfiguration> = BaseStorybookConfig<TWebpackConfiguration> & ReactConfig & {
41
+ typescript?: Partial<TypescriptOptions>;
42
+ };
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@storybook/preset-react-webpack",
3
+ "version": "7.0.0-alpha.0",
4
+ "description": "Storybook for React: Develop React Component in isolation with Hot Reloading.",
5
+ "keywords": [
6
+ "storybook"
7
+ ],
8
+ "homepage": "https://github.com/storybookjs/storybook/tree/main/presets/react-webpack",
9
+ "bugs": {
10
+ "url": "https://github.com/storybookjs/storybook/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/storybookjs/storybook.git",
15
+ "directory": "presets/react-webpack"
16
+ },
17
+ "funding": {
18
+ "type": "opencollective",
19
+ "url": "https://opencollective.com/storybook"
20
+ },
21
+ "license": "MIT",
22
+ "main": "dist/cjs/index.js",
23
+ "module": "dist/esm/index.js",
24
+ "types": "dist/types/index.d.ts",
25
+ "files": [
26
+ "dist/**/*",
27
+ "types/**/*",
28
+ "README.md",
29
+ "*.js",
30
+ "*.d.ts"
31
+ ],
32
+ "scripts": {
33
+ "prepare": "node ../../scripts/prepare.js"
34
+ },
35
+ "dependencies": {
36
+ "@babel/preset-flow": "^7.12.1",
37
+ "@babel/preset-react": "^7.12.10",
38
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
39
+ "@storybook/core-webpack": "7.0.0-alpha.0",
40
+ "@storybook/docs-tools": "7.0.0-alpha.0",
41
+ "@storybook/node-logger": "7.0.0-alpha.0",
42
+ "@storybook/react": "7.0.0-alpha.0",
43
+ "@storybook/react-docgen-typescript-plugin": "1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0",
44
+ "@storybook/semver": "^7.3.2",
45
+ "@types/node": "^14.14.20 || ^16.0.0",
46
+ "babel-plugin-add-react-displayname": "^0.0.5",
47
+ "babel-plugin-react-docgen": "^4.2.1",
48
+ "core-js": "^3.8.2",
49
+ "fs-extra": "^9.0.1",
50
+ "react-refresh": "^0.11.0",
51
+ "regenerator-runtime": "^0.13.7"
52
+ },
53
+ "devDependencies": {
54
+ "@types/util-deprecate": "^1.0.0"
55
+ },
56
+ "peerDependencies": {
57
+ "@babel/core": "^7.11.5",
58
+ "jest-specific-snapshot": "^4.0.0",
59
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
60
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
61
+ "require-from-string": "^2.0.2",
62
+ "webpack": "5"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "@babel/core": {
66
+ "optional": true
67
+ },
68
+ "typescript": {
69
+ "optional": true
70
+ }
71
+ },
72
+ "engines": {
73
+ "node": ">=10.13.0"
74
+ },
75
+ "publishConfig": {
76
+ "access": "public"
77
+ },
78
+ "gitHead": "c82d897ea765da8cf4fbbcc2af1f28c808a93e23"
79
+ }
package/preset.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/index');