react-cosmos 5.6.4

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.
Files changed (150) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/bin/cosmos-export.js +14 -0
  4. package/bin/cosmos-native.js +14 -0
  5. package/bin/cosmos.js +18 -0
  6. package/config.schema.json +186 -0
  7. package/dist/config/createCosmosConfig.d.ts +2 -0
  8. package/dist/config/createCosmosConfig.js +133 -0
  9. package/dist/config/detectCosmosConfig.d.ts +2 -0
  10. package/dist/config/detectCosmosConfig.js +57 -0
  11. package/dist/config/getCosmosConfigAtPath.d.ts +1 -0
  12. package/dist/config/getCosmosConfigAtPath.js +28 -0
  13. package/dist/config/index.d.ts +5 -0
  14. package/dist/config/index.js +51 -0
  15. package/dist/config/resolve.d.ts +1 -0
  16. package/dist/config/resolve.js +20 -0
  17. package/dist/config/shared.d.ts +29 -0
  18. package/dist/config/shared.js +17 -0
  19. package/dist/dom/DomFixtureLoader.d.ts +8 -0
  20. package/dist/dom/DomFixtureLoader.js +38 -0
  21. package/dist/dom/ErrorCatch.d.ts +15 -0
  22. package/dist/dom/ErrorCatch.js +117 -0
  23. package/dist/dom/container.d.ts +1 -0
  24. package/dist/dom/container.js +32 -0
  25. package/dist/dom/globalErrorHandler.d.ts +1 -0
  26. package/dist/dom/globalErrorHandler.js +14 -0
  27. package/dist/dom/index.d.ts +13 -0
  28. package/dist/dom/index.js +47 -0
  29. package/dist/dom/renderMessage.d.ts +3 -0
  30. package/dist/dom/renderMessage.js +30 -0
  31. package/dist/dom/rendererConnect.d.ts +1 -0
  32. package/dist/dom/rendererConnect.js +18 -0
  33. package/dist/dom/rendererId.d.ts +1 -0
  34. package/dist/dom/rendererId.js +26 -0
  35. package/dist/dom/selectedFixtureId.d.ts +2 -0
  36. package/dist/dom/selectedFixtureId.js +41 -0
  37. package/dist/dom/shared.d.ts +1 -0
  38. package/dist/dom/shared.js +14 -0
  39. package/dist/fixture.d.ts +1 -0
  40. package/dist/fixture.js +31 -0
  41. package/dist/getFixtureUrls.d.ts +8 -0
  42. package/dist/getFixtureUrls.js +98 -0
  43. package/dist/getFixtures.d.ts +13 -0
  44. package/dist/getFixtures.js +90 -0
  45. package/dist/getFixtures2.d.ts +14 -0
  46. package/dist/getFixtures2.js +117 -0
  47. package/dist/index.d.ts +4 -0
  48. package/dist/index.js +67 -0
  49. package/dist/native.d.ts +9 -0
  50. package/dist/native.js +69 -0
  51. package/dist/nativeServer.d.ts +1 -0
  52. package/dist/nativeServer.js +39 -0
  53. package/dist/plugins/httpProxy.d.ts +2 -0
  54. package/dist/plugins/httpProxy.js +31 -0
  55. package/dist/plugins/openFile.d.ts +2 -0
  56. package/dist/plugins/openFile.js +87 -0
  57. package/dist/plugins/userDepsFile.d.ts +2 -0
  58. package/dist/plugins/userDepsFile.js +164 -0
  59. package/dist/plugins/webpack/client/errorOverlay/index.d.ts +1 -0
  60. package/dist/plugins/webpack/client/errorOverlay/index.js +16 -0
  61. package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.d.ts +2 -0
  62. package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.js +63 -0
  63. package/dist/plugins/webpack/client/hmrErrorHandler.d.ts +1 -0
  64. package/dist/plugins/webpack/client/hmrErrorHandler.js +16 -0
  65. package/dist/plugins/webpack/client/index.d.ts +6 -0
  66. package/dist/plugins/webpack/client/index.js +43 -0
  67. package/dist/plugins/webpack/client/reactDevtoolsHook.d.ts +0 -0
  68. package/dist/plugins/webpack/client/reactDevtoolsHook.js +19 -0
  69. package/dist/plugins/webpack/client/userDeps.d.ts +5 -0
  70. package/dist/plugins/webpack/client/userDeps.js +15 -0
  71. package/dist/plugins/webpack/cosmosConfig/dom.d.ts +6 -0
  72. package/dist/plugins/webpack/cosmosConfig/dom.js +19 -0
  73. package/dist/plugins/webpack/cosmosConfig/webpack.d.ts +9 -0
  74. package/dist/plugins/webpack/cosmosConfig/webpack.js +88 -0
  75. package/dist/plugins/webpack/devServer.d.ts +2 -0
  76. package/dist/plugins/webpack/devServer.js +168 -0
  77. package/dist/plugins/webpack/export.d.ts +2 -0
  78. package/dist/plugins/webpack/export.js +135 -0
  79. package/dist/plugins/webpack/index.d.ts +2 -0
  80. package/dist/plugins/webpack/index.js +21 -0
  81. package/dist/plugins/webpack/shared.d.ts +2 -0
  82. package/dist/plugins/webpack/shared.js +22 -0
  83. package/dist/plugins/webpack/webpackConfig/default.d.ts +2 -0
  84. package/dist/plugins/webpack/webpackConfig/default.js +152 -0
  85. package/dist/plugins/webpack/webpackConfig/devServer.d.ts +3 -0
  86. package/dist/plugins/webpack/webpackConfig/devServer.js +144 -0
  87. package/dist/plugins/webpack/webpackConfig/export.d.ts +3 -0
  88. package/dist/plugins/webpack/webpackConfig/export.js +110 -0
  89. package/dist/plugins/webpack/webpackConfig/htmlPlugin.d.ts +16 -0
  90. package/dist/plugins/webpack/webpackConfig/htmlPlugin.js +80 -0
  91. package/dist/plugins/webpack/webpackConfig/index.d.ts +2 -0
  92. package/dist/plugins/webpack/webpackConfig/index.js +21 -0
  93. package/dist/plugins/webpack/webpackConfig/module.d.ts +3 -0
  94. package/dist/plugins/webpack/webpackConfig/module.js +18 -0
  95. package/dist/plugins/webpack/webpackConfig/shared.d.ts +11 -0
  96. package/dist/plugins/webpack/webpackConfig/shared.js +254 -0
  97. package/dist/plugins/webpack/webpackConfig/userDepsLoader.d.ts +1 -0
  98. package/dist/plugins/webpack/webpackConfig/userDepsLoader.js +36 -0
  99. package/dist/shared/cli.d.ts +5 -0
  100. package/dist/shared/cli.js +14 -0
  101. package/dist/shared/devServer/app.d.ts +5 -0
  102. package/dist/shared/devServer/app.js +51 -0
  103. package/dist/shared/devServer/httpServer.d.ts +11 -0
  104. package/dist/shared/devServer/httpServer.js +183 -0
  105. package/dist/shared/devServer/index.d.ts +18 -0
  106. package/dist/shared/devServer/index.js +209 -0
  107. package/dist/shared/devServer/messageHandler.d.ts +7 -0
  108. package/dist/shared/devServer/messageHandler.js +42 -0
  109. package/dist/shared/export.d.ts +6 -0
  110. package/dist/shared/export.js +137 -0
  111. package/dist/shared/fs.d.ts +4 -0
  112. package/dist/shared/fs.js +37 -0
  113. package/dist/shared/playgroundHtml.d.ts +6 -0
  114. package/dist/shared/playgroundHtml.js +116 -0
  115. package/dist/shared/pluginConfigs.d.ts +2 -0
  116. package/dist/shared/pluginConfigs.js +15 -0
  117. package/dist/shared/rendererConfig.d.ts +6 -0
  118. package/dist/shared/rendererConfig.js +5 -0
  119. package/dist/shared/shared.d.ts +6 -0
  120. package/dist/shared/shared.js +22 -0
  121. package/dist/shared/static/favicon.ico +0 -0
  122. package/dist/shared/static/index.html +19 -0
  123. package/dist/shared/static.d.ts +3 -0
  124. package/dist/shared/static.js +30 -0
  125. package/dist/shared/userDeps/findUserModulePaths.d.ts +11 -0
  126. package/dist/shared/userDeps/findUserModulePaths.js +45 -0
  127. package/dist/shared/userDeps/generateUserDepsModule.d.ts +9 -0
  128. package/dist/shared/userDeps/generateUserDepsModule.js +37 -0
  129. package/dist/shared/userDeps/getUserModules.d.ts +8 -0
  130. package/dist/shared/userDeps/getUserModules.js +45 -0
  131. package/dist/shared/userDeps/index.d.ts +4 -0
  132. package/dist/shared/userDeps/index.js +49 -0
  133. package/dist/shared/userDeps/shared.d.ts +6 -0
  134. package/dist/shared/userDeps/shared.js +32 -0
  135. package/dist/shared/userDeps/userDepsTemplate.d.ts +11 -0
  136. package/dist/shared/userDeps/userDepsTemplate.js +52 -0
  137. package/dist/webExport.d.ts +1 -0
  138. package/dist/webExport.js +37 -0
  139. package/dist/webServer.d.ts +1 -0
  140. package/dist/webServer.js +43 -0
  141. package/dom.d.ts +1 -0
  142. package/dom.js +2 -0
  143. package/fixture.d.ts +1 -0
  144. package/fixture.js +2 -0
  145. package/index.d.ts +1 -0
  146. package/index.js +2 -0
  147. package/native.d.ts +1 -0
  148. package/native.js +2 -0
  149. package/package.json +42 -0
  150. package/yarn-error.log +13450 -0
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ensureHtmlWebackPlugin = ensureHtmlWebackPlugin;
7
+ exports.getHtmlWebpackPlugin = getHtmlWebpackPlugin;
8
+
9
+ var _importFrom = _interopRequireDefault(require("import-from"));
10
+
11
+ var _lodash = require("lodash");
12
+
13
+ var _playgroundHtml = require("../../../shared/playgroundHtml");
14
+
15
+ var _shared = require("./shared");
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+
19
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
20
+
21
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
22
+
23
+ function _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; }
24
+
25
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
26
+
27
+ 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."); }
28
+
29
+ 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); }
30
+
31
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
32
+
33
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
34
+
35
+ 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; }
36
+
37
+ function ensureHtmlWebackPlugin(_ref, plugins) {
38
+ var rootDir = _ref.rootDir;
39
+
40
+ if ((0, _shared.hasPlugin)(plugins, 'HtmlWebpackPlugin')) {
41
+ return plugins.map(function (plugin) {
42
+ return isHtmlWebpackPlugin(plugin) ? changeHtmlPluginFilename(plugin) : plugin;
43
+ });
44
+ }
45
+
46
+ var htmlWebpackPlugin = getHtmlWebpackPlugin(rootDir);
47
+
48
+ if (!htmlWebpackPlugin) {
49
+ return plugins;
50
+ }
51
+
52
+ return [].concat(_toConsumableArray(plugins), [new htmlWebpackPlugin({
53
+ title: 'React Cosmos',
54
+ filename: _playgroundHtml.RENDERER_FILENAME
55
+ })]);
56
+ }
57
+
58
+ function getHtmlWebpackPlugin(rootDir) {
59
+ return _importFrom.default.silent(rootDir, 'html-webpack-plugin');
60
+ }
61
+
62
+ function isHtmlWebpackPlugin(plugin) {
63
+ return (0, _shared.isInstanceOfPlugin)(plugin, 'HtmlWebpackPlugin');
64
+ }
65
+
66
+ function changeHtmlPluginFilename(htmlPlugin) {
67
+ if (!isIndexHtmlWebpackPlugin(htmlPlugin)) return htmlPlugin;
68
+ var options = htmlPlugin.userOptions || htmlPlugin.options;
69
+ var safeOptions = (0, _lodash.omit)(options, 'chunks');
70
+ return new htmlPlugin.constructor(_objectSpread(_objectSpread({}, safeOptions), {}, {
71
+ filename: _playgroundHtml.RENDERER_FILENAME
72
+ }));
73
+ }
74
+
75
+ function isIndexHtmlWebpackPlugin(htmlPlugin) {
76
+ var _ref2 = htmlPlugin.userOptions || htmlPlugin.options,
77
+ filename = _ref2.filename;
78
+
79
+ return filename === 'index.html' || typeof filename !== 'string' || filename.endsWith('/index.html');
80
+ }
@@ -0,0 +1,2 @@
1
+ export { getDevWebpackConfig } from './devServer';
2
+ export { getExportWebpackConfig } from './export';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "getDevWebpackConfig", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _devServer.getDevWebpackConfig;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getExportWebpackConfig", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _export.getExportWebpackConfig;
16
+ }
17
+ });
18
+
19
+ var _devServer = require("./devServer");
20
+
21
+ var _export = require("./export");
@@ -0,0 +1,3 @@
1
+ export declare function getDefaultExport(module: any | {
2
+ default: any;
3
+ }): any;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDefaultExport = getDefaultExport;
7
+
8
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
9
+
10
+ // Get "default" export from either an ES or CJS module
11
+ // More context: https://github.com/react-cosmos/react-cosmos/issues/895
12
+ function getDefaultExport(module) {
13
+ if (_typeof(module) === 'object' && 'default' in module) {
14
+ return module.default;
15
+ }
16
+
17
+ return module;
18
+ }
@@ -0,0 +1,11 @@
1
+ import webpack from 'webpack';
2
+ import { CosmosConfig } from '../../../config';
3
+ export declare function getUserWebpackConfig(cosmosConfig: CosmosConfig, userWebpack: typeof webpack): Promise<webpack.Configuration>;
4
+ export declare function getBaseWebpackConfig(cosmosConfig: CosmosConfig, userWebpack: typeof webpack): Promise<webpack.Configuration>;
5
+ export declare function resolveClientPath(relPath: string): string;
6
+ export declare function getUserDepsLoaderRule(): webpack.RuleSetRule;
7
+ export declare function resolveLocalReactDeps(cosmosConfig: CosmosConfig, baseWebpackConfig: webpack.Configuration): webpack.ResolveOptions;
8
+ export declare function getGlobalsPlugin({ publicUrl }: CosmosConfig, userWebpack: typeof webpack, devServerOn: boolean): webpack.DefinePlugin;
9
+ export declare function hasPlugin(plugins: void | webpack.WebpackPluginInstance[], pluginName: string): boolean | void;
10
+ export declare function isInstanceOfPlugin(plugin: webpack.WebpackPluginInstance, constructorName: string): boolean;
11
+ export declare function getNodeEnv(): "development" | "production";
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getUserWebpackConfig = getUserWebpackConfig;
7
+ exports.getBaseWebpackConfig = getBaseWebpackConfig;
8
+ exports.resolveClientPath = resolveClientPath;
9
+ exports.getUserDepsLoaderRule = getUserDepsLoaderRule;
10
+ exports.resolveLocalReactDeps = resolveLocalReactDeps;
11
+ exports.getGlobalsPlugin = getGlobalsPlugin;
12
+ exports.hasPlugin = hasPlugin;
13
+ exports.isInstanceOfPlugin = isInstanceOfPlugin;
14
+ exports.getNodeEnv = getNodeEnv;
15
+
16
+ var _path = _interopRequireDefault(require("path"));
17
+
18
+ var _resolveFrom = _interopRequireDefault(require("resolve-from"));
19
+
20
+ var _cli = require("../../../shared/cli");
21
+
22
+ var _fs = require("../../../shared/fs");
23
+
24
+ var _webpack = require("../cosmosConfig/webpack");
25
+
26
+ var _default = require("./default");
27
+
28
+ var _module = require("./module");
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
33
+
34
+ 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."); }
35
+
36
+ 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); }
37
+
38
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
39
+
40
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
41
+
42
+ 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; }
43
+
44
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
45
+
46
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
47
+
48
+ function _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; }
49
+
50
+ 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); } }
51
+
52
+ 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); }); }; }
53
+
54
+ function getUserWebpackConfig(_x, _x2) {
55
+ return _getUserWebpackConfig.apply(this, arguments);
56
+ }
57
+
58
+ function _getUserWebpackConfig() {
59
+ _getUserWebpackConfig = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(cosmosConfig, userWebpack) {
60
+ var baseWebpackConfig, _createWebpackCosmosC, overridePath, relPath, webpackOverride;
61
+
62
+ return regeneratorRuntime.wrap(function _callee$(_context) {
63
+ while (1) {
64
+ switch (_context.prev = _context.next) {
65
+ case 0:
66
+ _context.next = 2;
67
+ return getBaseWebpackConfig(cosmosConfig, userWebpack);
68
+
69
+ case 2:
70
+ baseWebpackConfig = _context.sent;
71
+ _createWebpackCosmosC = (0, _webpack.createWebpackCosmosConfig)(cosmosConfig), overridePath = _createWebpackCosmosC.overridePath;
72
+
73
+ if (!(!overridePath || !(0, _fs.moduleExists)(overridePath))) {
74
+ _context.next = 6;
75
+ break;
76
+ }
77
+
78
+ return _context.abrupt("return", baseWebpackConfig);
79
+
80
+ case 6:
81
+ relPath = _path.default.relative(process.cwd(), overridePath);
82
+ console.log("[Cosmos] Overriding webpack config at ".concat(relPath));
83
+ webpackOverride = (0, _module.getDefaultExport)((0, _fs.requireModule)(overridePath));
84
+ return _context.abrupt("return", webpackOverride(baseWebpackConfig, getNodeEnv()));
85
+
86
+ case 10:
87
+ case "end":
88
+ return _context.stop();
89
+ }
90
+ }
91
+ }, _callee);
92
+ }));
93
+ return _getUserWebpackConfig.apply(this, arguments);
94
+ }
95
+
96
+ function getBaseWebpackConfig(_x3, _x4) {
97
+ return _getBaseWebpackConfig.apply(this, arguments);
98
+ }
99
+
100
+ function _getBaseWebpackConfig() {
101
+ _getBaseWebpackConfig = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(cosmosConfig, userWebpack) {
102
+ var rootDir, _createWebpackCosmosC2, configPath, relPath, userConfigExport, cliArgs;
103
+
104
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
105
+ while (1) {
106
+ switch (_context2.prev = _context2.next) {
107
+ case 0:
108
+ rootDir = cosmosConfig.rootDir;
109
+ _createWebpackCosmosC2 = (0, _webpack.createWebpackCosmosConfig)(cosmosConfig), configPath = _createWebpackCosmosC2.configPath;
110
+
111
+ if (!(!configPath || !(0, _fs.moduleExists)(configPath))) {
112
+ _context2.next = 5;
113
+ break;
114
+ }
115
+
116
+ console.log('[Cosmos] Using default webpack config');
117
+ return _context2.abrupt("return", (0, _default.getDefaultWebpackConfig)(userWebpack, rootDir));
118
+
119
+ case 5:
120
+ relPath = _path.default.relative(process.cwd(), configPath);
121
+ console.log("[Cosmos] Using webpack config found at ".concat(relPath));
122
+ userConfigExport = (0, _module.getDefaultExport)((0, _fs.requireModule)(configPath));
123
+ cliArgs = (0, _cli.getCliArgs)();
124
+
125
+ if (!(typeof userConfigExport === 'function')) {
126
+ _context2.next = 15;
127
+ break;
128
+ }
129
+
130
+ _context2.next = 12;
131
+ return userConfigExport(cliArgs.env || getNodeEnv(), cliArgs);
132
+
133
+ case 12:
134
+ _context2.t0 = _context2.sent;
135
+ _context2.next = 16;
136
+ break;
137
+
138
+ case 15:
139
+ _context2.t0 = userConfigExport;
140
+
141
+ case 16:
142
+ return _context2.abrupt("return", _context2.t0);
143
+
144
+ case 17:
145
+ case "end":
146
+ return _context2.stop();
147
+ }
148
+ }
149
+ }, _callee2);
150
+ }));
151
+ return _getBaseWebpackConfig.apply(this, arguments);
152
+ }
153
+
154
+ function resolveClientPath(relPath) {
155
+ return require.resolve("../client/".concat(relPath));
156
+ }
157
+
158
+ function getUserDepsLoaderRule() {
159
+ return {
160
+ loader: require.resolve('./userDepsLoader'),
161
+ include: resolveClientPath('userDeps')
162
+ };
163
+ }
164
+
165
+ function resolveLocalReactDeps(cosmosConfig, baseWebpackConfig) {
166
+ var rootDir = cosmosConfig.rootDir;
167
+ var _baseWebpackConfig$re = baseWebpackConfig.resolve,
168
+ resolve = _baseWebpackConfig$re === void 0 ? {} : _baseWebpackConfig$re;
169
+ var alias = resolve.alias || {}; // Preserve existing React aliases (eg. when using Preact)
170
+
171
+ var reactAlias = hasAlias(alias, 'react');
172
+ var reactDomAlias = hasAlias(alias, 'react-dom');
173
+
174
+ if (reactAlias && reactDomAlias) {
175
+ console.log('[Cosmos] React and React DOM aliases found in webpack config');
176
+ return resolve;
177
+ }
178
+
179
+ if (reactAlias) {
180
+ console.log('[Cosmos] React alias found in webpack config');
181
+ } else {
182
+ var reactPath = _resolveFrom.default.silent(rootDir, 'react');
183
+
184
+ if (!reactPath) throw new Error("[Cosmos] Local dependency not found: react");
185
+ alias = addAlias(alias, 'react', _path.default.dirname(reactPath));
186
+ }
187
+
188
+ if (reactDomAlias) {
189
+ console.log('[Cosmos] React DOM alias found in webpack config');
190
+ } else {
191
+ var reactDomPath = _resolveFrom.default.silent(rootDir, 'react-dom');
192
+
193
+ if (!reactDomPath) throw new Error("[Cosmos] Local dependency not found: react-dom");
194
+ alias = addAlias(alias, 'react-dom', _path.default.dirname(reactDomPath));
195
+ }
196
+
197
+ return _objectSpread(_objectSpread({}, resolve), {}, {
198
+ alias: alias
199
+ });
200
+ }
201
+
202
+ function getGlobalsPlugin(_ref, userWebpack, devServerOn) {
203
+ var publicUrl = _ref.publicUrl;
204
+ var cleanPublicUrl = removeTrailingSlash(publicUrl);
205
+ return new userWebpack.DefinePlugin({
206
+ // "if (__DEV__)" blocks get stripped when compiling a static export build
207
+ __DEV__: JSON.stringify(devServerOn),
208
+ 'process.env': {
209
+ NODE_ENV: JSON.stringify(getNodeEnv()),
210
+ PUBLIC_URL: JSON.stringify(cleanPublicUrl)
211
+ }
212
+ });
213
+ }
214
+
215
+ function hasPlugin(plugins, pluginName) {
216
+ return plugins && plugins.filter(function (p) {
217
+ return isInstanceOfPlugin(p, pluginName);
218
+ }).length > 0;
219
+ }
220
+
221
+ function isInstanceOfPlugin(plugin, constructorName) {
222
+ return plugin.constructor && plugin.constructor.name === constructorName;
223
+ }
224
+
225
+ function removeTrailingSlash(url) {
226
+ return url.replace(/\/$/, '');
227
+ }
228
+
229
+ function getNodeEnv() {
230
+ // Disallow non dev/prod environments, like "test" inside Jest, because
231
+ // they are not supported by webpack
232
+ return process.env.NODE_ENV === 'production' ? 'production' : 'development';
233
+ }
234
+
235
+ function hasAlias(alias, name) {
236
+ if (!alias) return false;
237
+ var exactName = "".concat(name, "$");
238
+
239
+ if (Array.isArray(alias)) {
240
+ return alias.some(function (a) {
241
+ return a.name === name || a.name === exactName;
242
+ });
243
+ } else {
244
+ var keys = Object.keys(alias);
245
+ return keys.includes(name) || keys.includes(exactName);
246
+ }
247
+ }
248
+
249
+ function addAlias(alias, name, value) {
250
+ return Array.isArray(alias) ? [].concat(_toConsumableArray(alias), [{
251
+ name: name,
252
+ alias: value
253
+ }]) : _objectSpread(_objectSpread({}, alias), {}, _defineProperty({}, name, value));
254
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _config = require("../../../config");
4
+
5
+ var _userDeps = require("../../../shared/userDeps");
6
+
7
+ var _dom = require("../cosmosConfig/dom");
8
+
9
+ module.exports = function injectUserDeps() {
10
+ var _this = this;
11
+
12
+ var cosmosConfig = (0, _config.detectCosmosConfig)(); // This ensures this loader is invalidated whenever a new file is added to or
13
+ // removed from user's project, which in turn triggers react-cosmos-voyager2
14
+ // to detect fixture files and finally update fixture list inside Playground.
15
+ // Note that while this may not be very performant, it's not the equivalent
16
+ // of require.context, which not only watches for file changes but also
17
+ // automatically bundles new files that match the watcher's query.
18
+ // https://github.com/webpack/webpack/issues/222#issuecomment-40691546
19
+
20
+ var watchDirs = cosmosConfig.watchDirs;
21
+ watchDirs.forEach(function (watchDir) {
22
+ return _this.addContextDependency(watchDir);
23
+ });
24
+
25
+ var _createDomCosmosConfi = (0, _dom.createDomCosmosConfig)(cosmosConfig),
26
+ containerQuerySelector = _createDomCosmosConfi.containerQuerySelector;
27
+
28
+ var rendererConfig = {
29
+ containerQuerySelector: containerQuerySelector
30
+ };
31
+ return (0, _userDeps.generateUserDepsModule)({
32
+ cosmosConfig: cosmosConfig,
33
+ rendererConfig: rendererConfig,
34
+ relativeToDir: null
35
+ });
36
+ };
@@ -0,0 +1,5 @@
1
+ export declare function getCliArgs(): {
2
+ [x: string]: unknown;
3
+ _: (string | number)[];
4
+ $0: string;
5
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCliArgs = getCliArgs;
7
+
8
+ var _yargs = _interopRequireDefault(require("yargs"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function getCliArgs() {
13
+ return _yargs.default.argv;
14
+ }
@@ -0,0 +1,5 @@
1
+ import express from 'express';
2
+ import { CosmosPluginConfig } from 'react-cosmos-plugin';
3
+ import { CosmosConfig } from '../../config';
4
+ import { PlatformType } from '../shared';
5
+ export declare function createApp(platformType: PlatformType, cosmosConfig: CosmosConfig, pluginConfigs: CosmosPluginConfig[]): express.Express;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createApp = createApp;
7
+
8
+ var _express = _interopRequireDefault(require("express"));
9
+
10
+ var _resolveFrom = _interopRequireDefault(require("resolve-from"));
11
+
12
+ var _playgroundHtml = require("../playgroundHtml");
13
+
14
+ var _static = require("../static");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function createApp(platformType, cosmosConfig, pluginConfigs) {
19
+ var app = (0, _express.default)();
20
+ var playgroundHtml = (0, _playgroundHtml.getDevPlaygroundHtml)(platformType, cosmosConfig, pluginConfigs);
21
+ app.get('/', function (req, res) {
22
+ res.send(playgroundHtml);
23
+ });
24
+ app.get('/_plugin/:scriptPath', function (req, res) {
25
+ var scriptPath = req.params.scriptPath;
26
+
27
+ if (!scriptPath) {
28
+ res.sendStatus(404);
29
+ return;
30
+ } // TODO: Restrict which scripts can be opened based on plugin configs
31
+
32
+
33
+ var cleanPath = "./".concat(decodeURIComponent(scriptPath));
34
+
35
+ var absolutePath = _resolveFrom.default.silent(cosmosConfig.rootDir, cleanPath);
36
+
37
+ if (!absolutePath) {
38
+ res.sendStatus(404);
39
+ return;
40
+ }
41
+
42
+ res.sendFile(absolutePath);
43
+ });
44
+ app.get('/_playground.js', function (req, res) {
45
+ res.sendFile(require.resolve('react-cosmos-playground2/dist'));
46
+ });
47
+ app.get('/_cosmos.ico', function (req, res) {
48
+ res.sendFile((0, _static.getStaticPath)('favicon.ico'));
49
+ });
50
+ return app;
51
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import http from 'http';
3
+ import https from 'https';
4
+ import { CosmosConfig } from '../../config';
5
+ declare type RequestListener = (request: http.IncomingMessage, response: http.ServerResponse) => void;
6
+ export declare function createHttpServer(cosmosConfig: CosmosConfig, requestListener: RequestListener): Promise<{
7
+ server: https.Server | http.Server;
8
+ start: () => Promise<void>;
9
+ stop: () => Promise<void>;
10
+ }>;
11
+ export {};