react-cosmos 5.7.2 → 6.0.0-alpha.5

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 (246) hide show
  1. package/bin/cosmos-export.js +4 -3
  2. package/bin/cosmos-native.js +4 -3
  3. package/bin/cosmos.js +5 -4
  4. package/config.schema.json +14 -4
  5. package/dist/index.d.ts +0 -6
  6. package/dist/index.js +0 -70
  7. package/dist/jest.d.ts +7 -0
  8. package/dist/jest.js +7 -0
  9. package/dist/{config → server/cosmosConfig}/createCosmosConfig.d.ts +1 -1
  10. package/dist/server/cosmosConfig/createCosmosConfig.js +84 -0
  11. package/dist/server/cosmosConfig/detectCosmosConfig.d.ts +2 -0
  12. package/dist/server/cosmosConfig/detectCosmosConfig.js +38 -0
  13. package/dist/{config → server/cosmosConfig}/getCosmosConfigAtPath.d.ts +1 -1
  14. package/dist/server/cosmosConfig/getCosmosConfigAtPath.js +12 -0
  15. package/dist/server/cosmosConfig/shared.d.ts +2 -0
  16. package/dist/server/cosmosConfig/shared.js +7 -0
  17. package/dist/{config/shared.d.ts → server/cosmosConfig/types.d.ts} +5 -5
  18. package/dist/server/cosmosPlugin/findCosmosPluginConfigs.d.ts +8 -0
  19. package/dist/server/cosmosPlugin/findCosmosPluginConfigs.js +14 -0
  20. package/dist/server/cosmosPlugin/pluginConfigs.d.ts +8 -0
  21. package/dist/server/cosmosPlugin/pluginConfigs.js +16 -0
  22. package/dist/server/cosmosPlugin/readCosmosPluginConfig.d.ts +8 -0
  23. package/dist/server/cosmosPlugin/readCosmosPluginConfig.js +31 -0
  24. package/dist/server/cosmosPlugin/types.d.ts +21 -0
  25. package/dist/server/devServer/corePlugins/httpProxy.d.ts +2 -0
  26. package/dist/server/devServer/corePlugins/httpProxy.js +18 -0
  27. package/dist/server/devServer/corePlugins/openFile.d.ts +2 -0
  28. package/dist/server/devServer/corePlugins/openFile.js +53 -0
  29. package/dist/server/devServer/corePlugins/pluginEndpoint.d.ts +2 -0
  30. package/dist/server/devServer/corePlugins/pluginEndpoint.js +17 -0
  31. package/dist/server/devServer/corePlugins/userDepsFile.d.ts +2 -0
  32. package/dist/server/devServer/corePlugins/userDepsFile.js +37 -0
  33. package/dist/server/devServer/expressApp.d.ts +5 -0
  34. package/dist/server/devServer/expressApp.js +21 -0
  35. package/dist/server/devServer/httpServer.d.ts +12 -0
  36. package/dist/server/devServer/httpServer.js +42 -0
  37. package/dist/{devServer → server/devServer}/messageHandler.d.ts +2 -2
  38. package/dist/server/devServer/messageHandler.js +29 -0
  39. package/dist/server/devServer/startDevServer.d.ts +2 -0
  40. package/dist/server/devServer/startDevServer.js +91 -0
  41. package/dist/server/export/generateExport.d.ts +1 -0
  42. package/dist/server/export/generateExport.js +97 -0
  43. package/dist/server/getFixtures/getFixtures.d.ts +14 -0
  44. package/dist/server/getFixtures/getFixtures.js +63 -0
  45. package/dist/server/shared/logPluginInfo.d.ts +2 -0
  46. package/dist/server/shared/logPluginInfo.js +8 -0
  47. package/dist/server/shared/playgroundHtml.d.ts +6 -0
  48. package/dist/server/shared/playgroundHtml.js +85 -0
  49. package/dist/server/shared/playgroundUrl.d.ts +2 -0
  50. package/dist/server/shared/playgroundUrl.js +6 -0
  51. package/dist/server/shared/requirePluginModule.d.ts +2 -0
  52. package/dist/server/shared/requirePluginModule.js +10 -0
  53. package/dist/server/shared/resolveUrlPath.d.ts +1 -0
  54. package/dist/server/shared/resolveUrlPath.js +12 -0
  55. package/dist/server/shared/staticPath.d.ts +1 -0
  56. package/dist/server/shared/staticPath.js +4 -0
  57. package/dist/{shared/static.d.ts → server/shared/staticServer.d.ts} +0 -1
  58. package/dist/server/shared/staticServer.js +12 -0
  59. package/dist/{shared → server}/static/index.html +1 -1
  60. package/dist/server/testHelpers/cwd.d.ts +1 -0
  61. package/dist/server/testHelpers/cwd.js +4 -0
  62. package/dist/server/testHelpers/mockConsole.d.ts +5 -0
  63. package/dist/server/testHelpers/mockConsole.js +11 -0
  64. package/dist/server/testHelpers/mockEsmRequire.js +13 -0
  65. package/dist/server/testHelpers/mockEsmResolve.d.ts +1 -0
  66. package/dist/server/testHelpers/mockEsmResolve.js +13 -0
  67. package/dist/server/testHelpers/mockEsmStaticPath.d.ts +1 -0
  68. package/dist/server/testHelpers/mockEsmStaticPath.js +7 -0
  69. package/dist/server/testHelpers/mockFetch.d.ts +2 -0
  70. package/dist/server/testHelpers/mockFetch.js +7 -0
  71. package/dist/server/testHelpers/mockFs.d.ts +5 -0
  72. package/dist/server/testHelpers/mockFs.js +64 -0
  73. package/dist/server/testHelpers/mockYargs.d.ts +2 -0
  74. package/dist/server/testHelpers/mockYargs.js +21 -0
  75. package/dist/{userDeps → server/userDeps}/findUserModulePaths.d.ts +2 -2
  76. package/dist/server/userDeps/findUserModulePaths.js +20 -0
  77. package/dist/server/userDeps/fixtureWatcher.d.ts +3 -0
  78. package/dist/server/userDeps/fixtureWatcher.js +20 -0
  79. package/dist/{userDeps → server/userDeps}/generateUserDepsModule.d.ts +3 -3
  80. package/dist/server/userDeps/generateUserDepsModule.js +18 -0
  81. package/dist/{userDeps → server/userDeps}/getUserModules.d.ts +3 -3
  82. package/dist/server/userDeps/getUserModules.js +25 -0
  83. package/dist/{userDeps → server/userDeps}/shared.d.ts +1 -1
  84. package/dist/server/userDeps/shared.js +20 -0
  85. package/dist/{userDeps → server/userDeps}/userDepsTemplate.d.ts +2 -2
  86. package/dist/server/userDeps/userDepsTemplate.js +49 -0
  87. package/dist/server/utils/cli.js +4 -0
  88. package/dist/server/utils/fs.d.ts +4 -0
  89. package/dist/server/utils/fs.js +24 -0
  90. package/dist/server/utils/isNodeError.d.ts +2 -0
  91. package/dist/server/utils/isNodeError.js +3 -0
  92. package/dist/server/utils/requireModule.d.ts +2 -0
  93. package/dist/server/utils/requireModule.js +13 -0
  94. package/dist/server/utils/requireSilent.d.ts +1 -0
  95. package/dist/server/utils/requireSilent.js +11 -0
  96. package/dist/server/utils/resolve.d.ts +2 -0
  97. package/dist/server/utils/resolve.js +14 -0
  98. package/dist/server/utils/resolveLoose.d.ts +1 -0
  99. package/dist/server/utils/resolveLoose.js +12 -0
  100. package/dist/server/utils/resolveSilent.d.ts +2 -0
  101. package/dist/server/utils/resolveSilent.js +22 -0
  102. package/dist/server/utils/slash.d.ts +1 -0
  103. package/dist/server/utils/slash.js +5 -0
  104. package/dist/server.d.ts +20 -0
  105. package/dist/server.js +20 -0
  106. package/index.d.ts +1 -1
  107. package/index.js +1 -2
  108. package/jest.d.ts +1 -0
  109. package/jest.js +1 -0
  110. package/package.json +17 -28
  111. package/server.d.ts +1 -0
  112. package/server.js +1 -0
  113. package/dist/config/createCosmosConfig.js +0 -133
  114. package/dist/config/detectCosmosConfig.d.ts +0 -2
  115. package/dist/config/detectCosmosConfig.js +0 -57
  116. package/dist/config/getCosmosConfigAtPath.js +0 -28
  117. package/dist/config/resolveModule.d.ts +0 -1
  118. package/dist/config/resolveModule.js +0 -20
  119. package/dist/config/shared.js +0 -17
  120. package/dist/devServer/app.d.ts +0 -5
  121. package/dist/devServer/app.js +0 -51
  122. package/dist/devServer/httpServer.d.ts +0 -11
  123. package/dist/devServer/httpServer.js +0 -183
  124. package/dist/devServer/messageHandler.js +0 -42
  125. package/dist/devServer/startDevServer.d.ts +0 -18
  126. package/dist/devServer/startDevServer.js +0 -209
  127. package/dist/dom/DomFixtureLoader.d.ts +0 -9
  128. package/dist/dom/DomFixtureLoader.js +0 -38
  129. package/dist/dom/ErrorCatch.d.ts +0 -15
  130. package/dist/dom/ErrorCatch.js +0 -117
  131. package/dist/dom/container.d.ts +0 -1
  132. package/dist/dom/container.js +0 -32
  133. package/dist/dom/globalErrorHandler.js +0 -14
  134. package/dist/dom/index.d.ts +0 -13
  135. package/dist/dom/index.js +0 -47
  136. package/dist/dom/renderMessage.d.ts +0 -4
  137. package/dist/dom/renderMessage.js +0 -30
  138. package/dist/dom/rendererConnect.d.ts +0 -1
  139. package/dist/dom/rendererConnect.js +0 -18
  140. package/dist/dom/rendererId.d.ts +0 -1
  141. package/dist/dom/rendererId.js +0 -26
  142. package/dist/dom/selectedFixtureId.d.ts +0 -2
  143. package/dist/dom/selectedFixtureId.js +0 -41
  144. package/dist/dom/shared.d.ts +0 -1
  145. package/dist/dom/shared.js +0 -14
  146. package/dist/export/generateExport.d.ts +0 -6
  147. package/dist/export/generateExport.js +0 -137
  148. package/dist/fixture.d.ts +0 -1
  149. package/dist/fixture.js +0 -31
  150. package/dist/generateWebExport.d.ts +0 -1
  151. package/dist/generateWebExport.js +0 -37
  152. package/dist/getFixtureUrls.d.ts +0 -8
  153. package/dist/getFixtureUrls.js +0 -97
  154. package/dist/getFixtures.d.ts +0 -13
  155. package/dist/getFixtures.js +0 -89
  156. package/dist/getFixtures2.d.ts +0 -14
  157. package/dist/getFixtures2.js +0 -117
  158. package/dist/native/NativeFixtureLoader.d.ts +0 -12
  159. package/dist/native/NativeFixtureLoader.js +0 -67
  160. package/dist/native/index.d.ts +0 -1
  161. package/dist/native/index.js +0 -25
  162. package/dist/plugins/httpProxy.d.ts +0 -2
  163. package/dist/plugins/httpProxy.js +0 -31
  164. package/dist/plugins/openFile.d.ts +0 -2
  165. package/dist/plugins/openFile.js +0 -87
  166. package/dist/plugins/userDepsFile.d.ts +0 -2
  167. package/dist/plugins/userDepsFile.js +0 -166
  168. package/dist/plugins/webpack/client/errorOverlay/index.d.ts +0 -1
  169. package/dist/plugins/webpack/client/errorOverlay/index.js +0 -16
  170. package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.d.ts +0 -2
  171. package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.js +0 -63
  172. package/dist/plugins/webpack/client/hmrErrorHandler.js +0 -16
  173. package/dist/plugins/webpack/client/index.d.ts +0 -6
  174. package/dist/plugins/webpack/client/index.js +0 -43
  175. package/dist/plugins/webpack/client/reactDevtoolsHook.d.ts +0 -0
  176. package/dist/plugins/webpack/client/reactDevtoolsHook.js +0 -19
  177. package/dist/plugins/webpack/client/userDeps.d.ts +0 -5
  178. package/dist/plugins/webpack/client/userDeps.js +0 -15
  179. package/dist/plugins/webpack/cosmosConfig/dom.d.ts +0 -6
  180. package/dist/plugins/webpack/cosmosConfig/dom.js +0 -19
  181. package/dist/plugins/webpack/cosmosConfig/webpack.d.ts +0 -10
  182. package/dist/plugins/webpack/cosmosConfig/webpack.js +0 -95
  183. package/dist/plugins/webpack/devServer.d.ts +0 -2
  184. package/dist/plugins/webpack/devServer.js +0 -168
  185. package/dist/plugins/webpack/export.d.ts +0 -2
  186. package/dist/plugins/webpack/export.js +0 -139
  187. package/dist/plugins/webpack/index.d.ts +0 -2
  188. package/dist/plugins/webpack/index.js +0 -21
  189. package/dist/plugins/webpack/shared.d.ts +0 -2
  190. package/dist/plugins/webpack/shared.js +0 -22
  191. package/dist/plugins/webpack/webpackConfig/getDefaultWebpackConfig.d.ts +0 -2
  192. package/dist/plugins/webpack/webpackConfig/getDefaultWebpackConfig.js +0 -152
  193. package/dist/plugins/webpack/webpackConfig/getDevWebpackConfig.d.ts +0 -3
  194. package/dist/plugins/webpack/webpackConfig/getDevWebpackConfig.js +0 -146
  195. package/dist/plugins/webpack/webpackConfig/getExportWebpackConfig.d.ts +0 -3
  196. package/dist/plugins/webpack/webpackConfig/getExportWebpackConfig.js +0 -111
  197. package/dist/plugins/webpack/webpackConfig/getUserWebpackConfig.d.ts +0 -3
  198. package/dist/plugins/webpack/webpackConfig/getUserWebpackConfig.js +0 -136
  199. package/dist/plugins/webpack/webpackConfig/getWebpackConfigModule.d.ts +0 -2
  200. package/dist/plugins/webpack/webpackConfig/getWebpackConfigModule.js +0 -45
  201. package/dist/plugins/webpack/webpackConfig/getWebpackConfigResolve.d.ts +0 -4
  202. package/dist/plugins/webpack/webpackConfig/getWebpackConfigResolve.js +0 -107
  203. package/dist/plugins/webpack/webpackConfig/getWebpackNodeEnv.d.ts +0 -1
  204. package/dist/plugins/webpack/webpackConfig/getWebpackNodeEnv.js +0 -12
  205. package/dist/plugins/webpack/webpackConfig/htmlPlugin.d.ts +0 -16
  206. package/dist/plugins/webpack/webpackConfig/htmlPlugin.js +0 -80
  207. package/dist/plugins/webpack/webpackConfig/plugins.d.ts +0 -5
  208. package/dist/plugins/webpack/webpackConfig/plugins.js +0 -37
  209. package/dist/plugins/webpack/webpackConfig/resolveWebpackClientPath.d.ts +0 -1
  210. package/dist/plugins/webpack/webpackConfig/resolveWebpackClientPath.js +0 -10
  211. package/dist/plugins/webpack/webpackConfig/userDepsLoader.js +0 -36
  212. package/dist/shared/cli.js +0 -14
  213. package/dist/shared/fs.d.ts +0 -4
  214. package/dist/shared/fs.js +0 -37
  215. package/dist/shared/playgroundHtml.d.ts +0 -6
  216. package/dist/shared/playgroundHtml.js +0 -116
  217. package/dist/shared/pluginConfigs.d.ts +0 -2
  218. package/dist/shared/pluginConfigs.js +0 -15
  219. package/dist/shared/rendererConfig.d.ts +0 -6
  220. package/dist/shared/rendererConfig.js +0 -5
  221. package/dist/shared/static.js +0 -30
  222. package/dist/shared/types.d.ts +0 -1
  223. package/dist/shared/types.js +0 -5
  224. package/dist/shared/utils.d.ts +0 -5
  225. package/dist/shared/utils.js +0 -22
  226. package/dist/startNativeServer.d.ts +0 -1
  227. package/dist/startNativeServer.js +0 -39
  228. package/dist/startWebServer.d.ts +0 -1
  229. package/dist/startWebServer.js +0 -43
  230. package/dist/userDeps/findUserModulePaths.js +0 -45
  231. package/dist/userDeps/generateUserDepsModule.js +0 -37
  232. package/dist/userDeps/getUserModules.js +0 -45
  233. package/dist/userDeps/shared.js +0 -32
  234. package/dist/userDeps/userDepsTemplate.js +0 -52
  235. package/dom.d.ts +0 -1
  236. package/dom.js +0 -2
  237. package/fixture.d.ts +0 -1
  238. package/fixture.js +0 -2
  239. package/native.d.ts +0 -1
  240. package/native.js +0 -2
  241. package/yarn-error.log +0 -13450
  242. /package/dist/{dom/globalErrorHandler.d.ts → server/cosmosConfig/types.js} +0 -0
  243. /package/dist/{plugins/webpack/client/hmrErrorHandler.d.ts → server/cosmosPlugin/types.js} +0 -0
  244. /package/dist/{shared → server}/static/favicon.ico +0 -0
  245. /package/dist/{plugins/webpack/webpackConfig/userDepsLoader.d.ts → server/testHelpers/mockEsmRequire.d.ts} +0 -0
  246. /package/dist/{shared → server/utils}/cli.d.ts +0 -0
@@ -3,10 +3,11 @@
3
3
  // Set the env before any code reads it
4
4
  process.env.NODE_ENV = process.env.NODE_ENV || 'production';
5
5
 
6
- require('regenerator-runtime/runtime');
7
- const { generateWebExport } = require('../dist/generateWebExport');
6
+ const { generateExport } = await import(
7
+ '../dist/server/export/generateExport.js'
8
+ );
8
9
 
9
- generateWebExport().catch(err => {
10
+ generateExport().catch(err => {
10
11
  console.log('[Cosmos] Export failed...');
11
12
  console.log(`\n (╯°□°)╯︵ ┻━┻\n`);
12
13
  console.log(err);
@@ -3,10 +3,11 @@
3
3
  // Set the env before any code reads it
4
4
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
5
5
 
6
- require('regenerator-runtime/runtime');
7
- const { startNativeServer } = require('../dist/startNativeServer');
6
+ const { startDevServer } = await import(
7
+ '../dist/server/devServer/startDevServer.js'
8
+ );
8
9
 
9
- startNativeServer().catch(err => {
10
+ startDevServer('native').catch(err => {
10
11
  console.log('[Cosmos] Server crashed...');
11
12
  console.log(`\n (╯°□°)╯︵ ┻━┻\n`);
12
13
  console.log(err);
package/bin/cosmos.js CHANGED
@@ -3,14 +3,15 @@
3
3
  // Set the env before any code reads it
4
4
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
5
5
 
6
+ const { startDevServer } = await import(
7
+ '../dist/server/devServer/startDevServer.js'
8
+ );
9
+
6
10
  // Auto disable Fast Refresh in CRA 4 until integration is implemented
7
11
  // https://github.com/react-cosmos/react-cosmos/issues/1272
8
12
  process.env.FAST_REFRESH = process.env.FAST_REFRESH || false;
9
13
 
10
- require('regenerator-runtime/runtime');
11
- const { startWebServer } = require('../dist/startWebServer');
12
-
13
- startWebServer().catch(err => {
14
+ startDevServer('web').catch(err => {
14
15
  console.log('[Cosmos] Server crashed...');
15
16
  console.log(`\n (╯°□°)╯︵ ┻━┻\n`);
16
17
  console.log(err);
@@ -17,8 +17,12 @@
17
17
  "type": "string",
18
18
  "minLength": 1
19
19
  },
20
+ "detectLocalPlugins": {
21
+ "description": "Automatically detect and load local plugins",
22
+ "type": "boolean"
23
+ },
20
24
  "disablePlugins": {
21
- "description": "Disable plugins",
25
+ "description": "Disable all plugins 3rd party plugins",
22
26
  "type": "boolean"
23
27
  },
24
28
  "staticPath": {
@@ -26,6 +30,12 @@
26
30
  "type": "string",
27
31
  "minLength": 1
28
32
  },
33
+ "plugins": {
34
+ "description": "Module IDs of Cosmos plugins (eg. \"react-cosmos-plugin-open-fixture\" or \"../path/to/my-plugin\").",
35
+ "type": "array",
36
+ "items": { "type": "string", "minLength": 1 },
37
+ "uniqueItems": true
38
+ },
29
39
  "publicUrl": {
30
40
  "description": "Base URL for static assets. [default: \"/\"]",
31
41
  "type": "string"
@@ -117,8 +127,8 @@
117
127
  "items": { "type": "string", "minLength": 1 },
118
128
  "uniqueItems": true
119
129
  },
120
- "experimentalRendererUrl": {
121
- "description": "Custom renderer URL. This setting disables webpack bundling and allows integration with other build tools like Snowpack. [default: null]",
130
+ "rendererUrl": {
131
+ "description": "Required when renderer doesn't run on the same port (or host) as the Playground. Useful for integrations with build tools. [default: null]",
122
132
  "anyOf": [{ "type": "string", "minLength": 1 }, { "type": "null" }]
123
133
  },
124
134
  "dom": {
@@ -154,7 +164,7 @@
154
164
  "type": "boolean"
155
165
  },
156
166
  "reloadOnFail": {
157
- "description": "When using webpack's Hot Module Replacement, enable automatic location reload after webpack fails to update modules. [default: true]",
167
+ "description": "When using webpack's Hot Module Replacement, enable automatic location reload after webpack fails to update modules. [default: false]",
158
168
  "type": "boolean"
159
169
  }
160
170
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +0,0 @@
1
- export { createCosmosConfig } from './config/createCosmosConfig';
2
- export { detectCosmosConfig } from './config/detectCosmosConfig';
3
- export { getCosmosConfigAtPath } from './config/getCosmosConfigAtPath';
4
- export { getFixtures, getFixturesSync } from './getFixtures';
5
- export { FixtureApi, getFixtures2 } from './getFixtures2';
6
- export { getFixtureUrls, getFixtureUrlsSync } from './getFixtureUrls';
package/dist/index.js CHANGED
@@ -1,71 +1 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "FixtureApi", {
7
- enumerable: true,
8
- get: function get() {
9
- return _getFixtures2.FixtureApi;
10
- }
11
- });
12
- Object.defineProperty(exports, "createCosmosConfig", {
13
- enumerable: true,
14
- get: function get() {
15
- return _createCosmosConfig.createCosmosConfig;
16
- }
17
- });
18
- Object.defineProperty(exports, "detectCosmosConfig", {
19
- enumerable: true,
20
- get: function get() {
21
- return _detectCosmosConfig.detectCosmosConfig;
22
- }
23
- });
24
- Object.defineProperty(exports, "getCosmosConfigAtPath", {
25
- enumerable: true,
26
- get: function get() {
27
- return _getCosmosConfigAtPath.getCosmosConfigAtPath;
28
- }
29
- });
30
- Object.defineProperty(exports, "getFixtureUrls", {
31
- enumerable: true,
32
- get: function get() {
33
- return _getFixtureUrls.getFixtureUrls;
34
- }
35
- });
36
- Object.defineProperty(exports, "getFixtureUrlsSync", {
37
- enumerable: true,
38
- get: function get() {
39
- return _getFixtureUrls.getFixtureUrlsSync;
40
- }
41
- });
42
- Object.defineProperty(exports, "getFixtures", {
43
- enumerable: true,
44
- get: function get() {
45
- return _getFixtures.getFixtures;
46
- }
47
- });
48
- Object.defineProperty(exports, "getFixtures2", {
49
- enumerable: true,
50
- get: function get() {
51
- return _getFixtures2.getFixtures2;
52
- }
53
- });
54
- Object.defineProperty(exports, "getFixturesSync", {
55
- enumerable: true,
56
- get: function get() {
57
- return _getFixtures.getFixturesSync;
58
- }
59
- });
60
-
61
- var _createCosmosConfig = require("./config/createCosmosConfig");
62
-
63
- var _detectCosmosConfig = require("./config/detectCosmosConfig");
64
-
65
- var _getCosmosConfigAtPath = require("./config/getCosmosConfigAtPath");
66
-
67
- var _getFixtures = require("./getFixtures");
68
-
69
- var _getFixtures2 = require("./getFixtures2");
70
-
71
- var _getFixtureUrls = require("./getFixtureUrls");
package/dist/jest.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './server/testHelpers/mockConsole.js';
2
+ export * from './server/testHelpers/mockEsmRequire.js';
3
+ export * from './server/testHelpers/mockEsmResolve.js';
4
+ export * from './server/testHelpers/mockEsmStaticPath.js';
5
+ export * from './server/testHelpers/mockFetch.js';
6
+ export * from './server/testHelpers/mockFs.js';
7
+ export * from './server/testHelpers/mockYargs.js';
package/dist/jest.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from './server/testHelpers/mockConsole.js';
2
+ export * from './server/testHelpers/mockEsmRequire.js';
3
+ export * from './server/testHelpers/mockEsmResolve.js';
4
+ export * from './server/testHelpers/mockEsmStaticPath.js';
5
+ export * from './server/testHelpers/mockFetch.js';
6
+ export * from './server/testHelpers/mockFs.js';
7
+ export * from './server/testHelpers/mockYargs.js';
@@ -1,2 +1,2 @@
1
- import { CosmosConfig, CosmosConfigInput } from './shared';
1
+ import { CosmosConfig, CosmosConfigInput } from './types.js';
2
2
  export declare function createCosmosConfig(rootDir: string, cosmosConfigInput?: CosmosConfigInput): CosmosConfig;
@@ -0,0 +1,84 @@
1
+ import path from 'path';
2
+ import { getCliArgs } from '../utils/cli.js';
3
+ import { resolveLoose } from '../utils/resolveLoose.js';
4
+ export function createCosmosConfig(rootDir, cosmosConfigInput = {}) {
5
+ return {
6
+ ...cosmosConfigInput,
7
+ rootDir,
8
+ exportPath: getExportPath(cosmosConfigInput, rootDir),
9
+ detectLocalPlugins: cosmosConfigInput.detectLocalPlugins ?? true,
10
+ disablePlugins: cosmosConfigInput.disablePlugins ?? false,
11
+ fixtureFileSuffix: getFixtureFileSuffix(cosmosConfigInput),
12
+ fixturesDir: getFixturesDir(cosmosConfigInput),
13
+ globalImports: getGlobalImports(cosmosConfigInput, rootDir),
14
+ hostname: getHostname(cosmosConfigInput),
15
+ https: getHttps(cosmosConfigInput),
16
+ httpsOptions: getHttpsOptions(cosmosConfigInput, rootDir),
17
+ port: getPort(cosmosConfigInput),
18
+ plugins: getPlugins(cosmosConfigInput, rootDir),
19
+ publicUrl: getPublicUrl(cosmosConfigInput),
20
+ staticPath: getStaticPath(cosmosConfigInput, rootDir),
21
+ userDepsFilePath: getUserDepsFilePath(cosmosConfigInput, rootDir),
22
+ watchDirs: getWatchDirs(cosmosConfigInput, rootDir),
23
+ rendererUrl: cosmosConfigInput.rendererUrl ?? null,
24
+ ui: cosmosConfigInput.ui || {},
25
+ };
26
+ }
27
+ function getExportPath(cosmosConfigInput, rootDir) {
28
+ const { exportPath = 'cosmos-export' } = cosmosConfigInput;
29
+ return path.resolve(rootDir, exportPath);
30
+ }
31
+ function getStaticPath(cosmosConfigInput, rootDir) {
32
+ const { staticPath = null } = cosmosConfigInput;
33
+ return staticPath && path.resolve(rootDir, staticPath);
34
+ }
35
+ function getHttps(cosmosConfigInput) {
36
+ const { https = false } = cosmosConfigInput;
37
+ return https;
38
+ }
39
+ function getHttpsOptions(cosmosConfigInput, rootDir) {
40
+ if (cosmosConfigInput.httpsOptions?.keyPath &&
41
+ cosmosConfigInput.httpsOptions?.certPath) {
42
+ return {
43
+ keyPath: path.resolve(rootDir, cosmosConfigInput.httpsOptions.keyPath),
44
+ certPath: path.resolve(rootDir, cosmosConfigInput.httpsOptions.certPath),
45
+ };
46
+ }
47
+ return null;
48
+ }
49
+ function getPublicUrl({ publicUrl = '/' }) {
50
+ return publicUrl;
51
+ }
52
+ function getFixturesDir({ fixturesDir = '__fixtures__' }) {
53
+ return fixturesDir;
54
+ }
55
+ function getFixtureFileSuffix({ fixtureFileSuffix = 'fixture', }) {
56
+ return fixtureFileSuffix;
57
+ }
58
+ function getWatchDirs(cosmosConfigInput, rootDir) {
59
+ const { watchDirs = ['.'] } = cosmosConfigInput;
60
+ return watchDirs.map(watchDir => path.resolve(rootDir, watchDir));
61
+ }
62
+ function getUserDepsFilePath(cosmosConfigInput, rootDir) {
63
+ const { userDepsFilePath = 'cosmos.userdeps.js' } = cosmosConfigInput;
64
+ return path.resolve(rootDir, userDepsFilePath);
65
+ }
66
+ function getHostname({ hostname = null }) {
67
+ return hostname;
68
+ }
69
+ function getPort(cosmosConfigInput) {
70
+ const cliArgs = getCliArgs();
71
+ if (typeof cliArgs.port === 'number') {
72
+ return cliArgs.port;
73
+ }
74
+ const { port = 5000 } = cosmosConfigInput;
75
+ return port;
76
+ }
77
+ function getGlobalImports(cosmosConfigInput, rootDir) {
78
+ const { globalImports = [] } = cosmosConfigInput;
79
+ return globalImports.map(globalImport => resolveLoose(rootDir, globalImport));
80
+ }
81
+ function getPlugins(cosmosConfigInput, rootDir) {
82
+ const { plugins = [] } = cosmosConfigInput;
83
+ return plugins.map(plugin => resolveLoose(rootDir, plugin));
84
+ }
@@ -0,0 +1,2 @@
1
+ export declare function detectCosmosConfig(): Promise<import("./types.js").CosmosConfig>;
2
+ export declare function detectCosmosConfigPath(): string | null;
@@ -0,0 +1,38 @@
1
+ import path from 'path';
2
+ import { getCliArgs } from '../utils/cli.js';
3
+ import { dirExists, fileExists, moduleExists } from '../utils/fs.js';
4
+ import { createCosmosConfig } from './createCosmosConfig.js';
5
+ import { getCosmosConfigAtPath } from './getCosmosConfigAtPath.js';
6
+ import { getCurrentDir } from './shared.js';
7
+ export async function detectCosmosConfig() {
8
+ const cosmosConfigPath = detectCosmosConfigPath();
9
+ return cosmosConfigPath
10
+ ? getCosmosConfigAtPath(cosmosConfigPath)
11
+ : createCosmosConfig(detectRootDir());
12
+ }
13
+ export function detectCosmosConfigPath() {
14
+ const rootDir = detectRootDir();
15
+ const cliArgs = getCliArgs();
16
+ // CLI support for --config path/to/cosmos.config.json
17
+ if (typeof cliArgs.config === 'string') {
18
+ if (path.extname(cliArgs.config) !== '.json')
19
+ throw new Error(`[Cosmos] Invalid config file type: ${cliArgs.config} (must be .json)`);
20
+ const absPath = path.resolve(rootDir, cliArgs.config);
21
+ if (!fileExists(absPath))
22
+ throw new Error(`[Cosmos] Config not found at path: ${cliArgs.config}`);
23
+ return absPath;
24
+ }
25
+ const defaultConfigPath = path.join(rootDir, 'cosmos.config.json');
26
+ return moduleExists(defaultConfigPath) ? defaultConfigPath : null;
27
+ }
28
+ function detectRootDir() {
29
+ const cliArgs = getCliArgs();
30
+ // CLI support for --root-dir path/to/project
31
+ if (typeof cliArgs.rootDir === 'string') {
32
+ const absPath = path.resolve(getCurrentDir(), cliArgs.rootDir);
33
+ if (!dirExists(absPath))
34
+ throw new Error(`[Cosmos] Dir not found at path: ${cliArgs.rootDir}`);
35
+ return absPath;
36
+ }
37
+ return getCurrentDir();
38
+ }
@@ -1 +1 @@
1
- export declare function getCosmosConfigAtPath(cosmosConfigPath: string): import("./shared").CosmosConfig;
1
+ export declare function getCosmosConfigAtPath(cosmosConfigPath: string): Promise<import("./types.js").CosmosConfig>;
@@ -0,0 +1,12 @@
1
+ import path from 'path';
2
+ import { createCosmosConfig } from './createCosmosConfig.js';
3
+ import { importConfigFile } from './shared.js';
4
+ export async function getCosmosConfigAtPath(cosmosConfigPath) {
5
+ const cosmosConfigInput = await importConfigFile(cosmosConfigPath);
6
+ const rootDir = deriveRootDir(cosmosConfigPath, cosmosConfigInput);
7
+ return createCosmosConfig(rootDir, cosmosConfigInput);
8
+ }
9
+ function deriveRootDir(cosmosConfigPath, { rootDir }) {
10
+ const configDir = path.dirname(cosmosConfigPath);
11
+ return rootDir ? path.resolve(configDir, rootDir) : configDir;
12
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getCurrentDir(): string;
2
+ export declare function importConfigFile(cosmosConfigPath: string): Promise<Partial<import("./types.js").CosmosConfig>>;
@@ -0,0 +1,7 @@
1
+ import { importModule } from '../utils/fs.js';
2
+ export function getCurrentDir() {
3
+ return process.cwd();
4
+ }
5
+ export async function importConfigFile(cosmosConfigPath) {
6
+ return importModule(cosmosConfigPath);
7
+ }
@@ -2,8 +2,9 @@ interface HttpsOptions {
2
2
  keyPath: string;
3
3
  certPath: string;
4
4
  }
5
- export declare type CosmosConfig = {
5
+ export type CosmosConfig = {
6
6
  exportPath: string;
7
+ detectLocalPlugins: boolean;
7
8
  disablePlugins: boolean;
8
9
  fixtureFileSuffix: string;
9
10
  fixturesDir: string;
@@ -12,18 +13,17 @@ export declare type CosmosConfig = {
12
13
  https: boolean;
13
14
  httpsOptions: null | HttpsOptions;
14
15
  port: number;
16
+ plugins: string[];
15
17
  publicUrl: string;
18
+ rendererUrl: string | null;
16
19
  rootDir: string;
17
20
  staticPath: null | string;
18
21
  userDepsFilePath: string;
19
22
  watchDirs: string[];
20
- experimentalRendererUrl: string | null;
21
23
  [option: string]: unknown;
22
24
  ui: {
23
25
  [pluginName: string]: {};
24
26
  };
25
27
  };
26
- export declare type CosmosConfigInput = Partial<CosmosConfig>;
27
- export declare function getCurrentDir(): string;
28
- export declare function requireConfigFile(cosmosConfigPath: string): CosmosConfigInput;
28
+ export type CosmosConfigInput = Partial<CosmosConfig>;
29
29
  export {};
@@ -0,0 +1,8 @@
1
+ import { CosmosPluginConfig } from 'react-cosmos-core';
2
+ type Args = {
3
+ rootDir: string;
4
+ relativePaths: boolean;
5
+ ignore?: string[];
6
+ };
7
+ export declare function findCosmosPluginConfigs({ rootDir, relativePaths, ignore, }: Args): Promise<CosmosPluginConfig[]>;
8
+ export {};
@@ -0,0 +1,14 @@
1
+ import glob from 'glob';
2
+ import { readCosmosPluginConfig } from './readCosmosPluginConfig.js';
3
+ export async function findCosmosPluginConfigs({ rootDir, relativePaths, ignore, }) {
4
+ const configPaths = findCosmosPluginConfigPaths(rootDir, ignore);
5
+ return Promise.all(configPaths.map(configPath => readCosmosPluginConfig({ rootDir, configPath, relativePaths })));
6
+ }
7
+ const defaultIgnore = ['**/node_modules/**'];
8
+ function findCosmosPluginConfigPaths(rootDir, ignore = defaultIgnore) {
9
+ return glob.sync('**/cosmos.plugin.json', {
10
+ cwd: rootDir,
11
+ absolute: true,
12
+ ignore,
13
+ });
14
+ }
@@ -0,0 +1,8 @@
1
+ import { CosmosPluginConfig } from 'react-cosmos-core';
2
+ import { CosmosConfig } from '../cosmosConfig/types.js';
3
+ type GetPluginConfigArgs = {
4
+ cosmosConfig: CosmosConfig;
5
+ relativePaths: boolean;
6
+ };
7
+ export declare function getPluginConfigs({ cosmosConfig, relativePaths, }: GetPluginConfigArgs): Promise<CosmosPluginConfig[]>;
8
+ export {};
@@ -0,0 +1,16 @@
1
+ import { findCosmosPluginConfigs } from './findCosmosPluginConfigs.js';
2
+ import { readCosmosPluginConfig } from './readCosmosPluginConfig.js';
3
+ export async function getPluginConfigs({ cosmosConfig, relativePaths, }) {
4
+ const { rootDir, detectLocalPlugins, disablePlugins, plugins, exportPath } = cosmosConfig;
5
+ if (disablePlugins)
6
+ return [];
7
+ const moduleConfigs = await Promise.all(plugins.map(configPath => readCosmosPluginConfig({ rootDir, configPath, relativePaths })));
8
+ if (!detectLocalPlugins)
9
+ return moduleConfigs;
10
+ const localConfigs = await findCosmosPluginConfigs({
11
+ rootDir,
12
+ ignore: [`${exportPath}/**`],
13
+ relativePaths,
14
+ });
15
+ return [...moduleConfigs, ...localConfigs];
16
+ }
@@ -0,0 +1,8 @@
1
+ import { CosmosPluginConfig } from 'react-cosmos-core';
2
+ type ReadCosmosPluginConfigArgs = {
3
+ rootDir: string;
4
+ configPath: string;
5
+ relativePaths: boolean;
6
+ };
7
+ export declare function readCosmosPluginConfig({ rootDir, configPath, relativePaths, }: ReadCosmosPluginConfigArgs): Promise<CosmosPluginConfig>;
8
+ export {};
@@ -0,0 +1,31 @@
1
+ import path from 'path';
2
+ import { importModule } from '../utils/fs.js';
3
+ import { resolveSilent } from '../utils/resolveSilent.js';
4
+ export async function readCosmosPluginConfig({ rootDir, configPath, relativePaths, }) {
5
+ const rawConfig = await importModule(configPath);
6
+ const pluginRootDir = path.dirname(configPath);
7
+ const config = {
8
+ name: rawConfig.name,
9
+ rootDir: relativePaths
10
+ ? path.relative(rootDir, pluginRootDir)
11
+ : pluginRootDir,
12
+ };
13
+ if (rawConfig.ui) {
14
+ config.ui = resolvePluginPath(config.name, rootDir, pluginRootDir, rawConfig.ui, relativePaths);
15
+ }
16
+ if (rawConfig.devServer) {
17
+ config.devServer = resolvePluginPath(config.name, rootDir, pluginRootDir, rawConfig.devServer, relativePaths);
18
+ }
19
+ if (rawConfig.export) {
20
+ config.export = resolvePluginPath(config.name, rootDir, pluginRootDir, rawConfig.export, relativePaths);
21
+ }
22
+ return config;
23
+ }
24
+ function resolvePluginPath(pluginName, rootDir, pluginRootDir, filePath, relativePath) {
25
+ const absolutePath = path.join(pluginRootDir, filePath);
26
+ const resolvedPath = resolveSilent(absolutePath);
27
+ if (!resolvedPath) {
28
+ throw new Error(`Invalid path in plugin "${pluginName}": ${filePath}`);
29
+ }
30
+ return relativePath ? path.relative(rootDir, resolvedPath) : resolvedPath;
31
+ }
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import express from 'express';
3
+ import http from 'http';
4
+ import { MessageType } from 'react-cosmos-core';
5
+ import { CosmosConfig } from '../cosmosConfig/types.js';
6
+ export type PlatformType = 'web' | 'native';
7
+ export type DevServerPluginArgs = {
8
+ cosmosConfig: CosmosConfig;
9
+ platformType: PlatformType;
10
+ httpServer: http.Server;
11
+ expressApp: express.Express;
12
+ sendMessage(msg: MessageType): unknown;
13
+ };
14
+ export type DevServerPluginCleanupCallback = () => unknown;
15
+ export type DevServerPluginReturnValue = void | null | DevServerPluginCleanupCallback;
16
+ export type DevServerPluginReturn = DevServerPluginReturnValue | Promise<DevServerPluginReturnValue>;
17
+ export type DevServerPlugin = (args: DevServerPluginArgs) => DevServerPluginReturn;
18
+ export type ExportPluginArgs = {
19
+ cosmosConfig: CosmosConfig;
20
+ };
21
+ export type ExportPlugin = (args: ExportPluginArgs) => unknown;
@@ -0,0 +1,2 @@
1
+ import { DevServerPluginArgs } from '../../cosmosPlugin/types.js';
2
+ export declare function httpProxyDevServerPlugin({ platformType, cosmosConfig, expressApp, }: DevServerPluginArgs): void;
@@ -0,0 +1,18 @@
1
+ import { createProxyMiddleware } from 'http-proxy-middleware';
2
+ export function httpProxyDevServerPlugin({ platformType, cosmosConfig, expressApp, }) {
3
+ if (platformType !== 'web')
4
+ return;
5
+ const httpProxyConfig = getHttpProxyCosmosConfig(cosmosConfig);
6
+ Object.keys(httpProxyConfig).forEach(context => {
7
+ const config = httpProxyConfig[context];
8
+ if (typeof config === 'string') {
9
+ expressApp.use(context, createProxyMiddleware(context, { target: config }));
10
+ }
11
+ else if (typeof config === 'object') {
12
+ expressApp.use(context, createProxyMiddleware(context, config));
13
+ }
14
+ });
15
+ }
16
+ function getHttpProxyCosmosConfig(cosmosConfig) {
17
+ return (cosmosConfig.httpProxy || {});
18
+ }
@@ -0,0 +1,2 @@
1
+ import { DevServerPluginArgs } from '../../cosmosPlugin/types.js';
2
+ export default function openFileDevServerPlugin({ cosmosConfig, expressApp, }: DevServerPluginArgs): void;
@@ -0,0 +1,53 @@
1
+ import launchEditor from '@skidding/launch-editor';
2
+ import fs from 'fs';
3
+ import open from 'open';
4
+ import path from 'path';
5
+ export default function openFileDevServerPlugin({ cosmosConfig, expressApp, }) {
6
+ expressApp.get('/_open', (req, res) => {
7
+ const { filePath, line, column } = getReqQuery(req);
8
+ if (!filePath) {
9
+ res.status(400).send(`File path missing`);
10
+ return;
11
+ }
12
+ const absFilePath = resolveFilePath(cosmosConfig.rootDir, filePath);
13
+ if (!fs.existsSync(absFilePath)) {
14
+ res.status(404).send(`File not found at path: ${absFilePath}`);
15
+ return;
16
+ }
17
+ new Promise((resolve, reject) => {
18
+ const file = `${absFilePath}:${line}:${column}`;
19
+ launchEditor(file, (fileName, errorMsg) => reject(errorMsg));
20
+ // If launchEditor doesn't report error within 500ms we assume it worked
21
+ setTimeout(resolve, 500);
22
+ })
23
+ // Fall back to open in case launchEditor fails. launchEditor only works
24
+ // when the editor app is already open, but is favorable because it can
25
+ // open a code file on a specific line & column.
26
+ .catch(err => open(absFilePath))
27
+ .catch(err => res.status(500).send('Failed to open file'))
28
+ .then(() => res.send());
29
+ });
30
+ }
31
+ function getReqQuery(req) {
32
+ const { filePath, line, column } = req.query;
33
+ if (typeof filePath !== 'string')
34
+ throw new Error('filePath missing');
35
+ return {
36
+ filePath,
37
+ line: typeof line === 'string' ? parseInt(line, 10) : 1,
38
+ column: typeof column === 'string' ? parseInt(column, 10) : 1,
39
+ };
40
+ }
41
+ function resolveFilePath(rootDir, filePath) {
42
+ // This heuristic is needed because the open file endpoint is used for
43
+ // multiple applications, which provide different file path types:
44
+ // 1. Edit fixture button: Sends path relative to Cosmos rootDir
45
+ // 2. react-error-overlay runtime error: Sends absolute path
46
+ // 3. react-error-overlay compile error: Sends path relative to CWD
47
+ if (path.isAbsolute(filePath)) {
48
+ return filePath;
49
+ }
50
+ const cosmosRelPath = path.join(rootDir, filePath);
51
+ const cwdRelPath = path.join(process.cwd(), filePath);
52
+ return fs.existsSync(cosmosRelPath) ? cosmosRelPath : cwdRelPath;
53
+ }
@@ -0,0 +1,2 @@
1
+ import { DevServerPluginArgs } from '../../cosmosPlugin/types.js';
2
+ export default function pluginEndpointDevServerPlugin({ cosmosConfig, expressApp, }: DevServerPluginArgs): void;
@@ -0,0 +1,17 @@
1
+ import { resolveFromSilent, resolveSilent } from '../../utils/resolveSilent.js';
2
+ export default function pluginEndpointDevServerPlugin({ cosmosConfig, expressApp, }) {
3
+ expressApp.get('/_plugin/*.js', (req, res) => {
4
+ const moduleId = req.params['0'];
5
+ if (!moduleId) {
6
+ res.sendStatus(404);
7
+ return;
8
+ }
9
+ const resolvedPath = resolveSilent(`/${moduleId}`) ||
10
+ resolveFromSilent(cosmosConfig.rootDir, moduleId);
11
+ if (!resolvedPath) {
12
+ res.sendStatus(404);
13
+ return;
14
+ }
15
+ res.sendFile(resolvedPath);
16
+ });
17
+ }
@@ -0,0 +1,2 @@
1
+ import { DevServerPluginArgs } from '../../cosmosPlugin/types.js';
2
+ export declare function userDepsFileDevServerPlugin(args: DevServerPluginArgs): Promise<(() => void) | undefined>;