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,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getFixturesSync = getFixturesSync;
7
+ exports.getFixtures = void 0;
8
+
9
+ var _FixtureLoader = require("react-cosmos-shared2/FixtureLoader");
10
+
11
+ var _react = require("react-cosmos-shared2/react");
12
+
13
+ var _userDeps = require("./shared/userDeps");
14
+
15
+ 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); } }
16
+
17
+ 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); }); }; }
18
+
19
+ var getFixtures = /*#__PURE__*/function () {
20
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(args) {
21
+ return regeneratorRuntime.wrap(function _callee$(_context) {
22
+ while (1) {
23
+ switch (_context.prev = _context.next) {
24
+ case 0:
25
+ return _context.abrupt("return", getFixturesSync(args));
26
+
27
+ case 1:
28
+ case "end":
29
+ return _context.stop();
30
+ }
31
+ }
32
+ }, _callee);
33
+ }));
34
+
35
+ return function getFixtures(_x) {
36
+ return _ref.apply(this, arguments);
37
+ };
38
+ }();
39
+
40
+ exports.getFixtures = getFixtures;
41
+
42
+ function getFixturesSync(_ref2) {
43
+ var cosmosConfig = _ref2.cosmosConfig;
44
+
45
+ var _getUserModules = (0, _userDeps.getUserModules)(cosmosConfig),
46
+ fixtureExportsByPath = _getUserModules.fixtureExportsByPath,
47
+ decoratorsByPath = _getUserModules.decoratorsByPath;
48
+
49
+ var fixtures = [];
50
+ Object.keys(fixtureExportsByPath).forEach(function (fixturePath) {
51
+ var fixtureExport = fixtureExportsByPath[fixturePath];
52
+
53
+ if ((0, _react.isMultiFixture)(fixtureExport)) {
54
+ // FIXME: Why does fixtureExport need to be cast as ReactFixtureMap when
55
+ // the type predicate returned by isMultiFixture already ensures it?
56
+ var multiFixtureExport = fixtureExport;
57
+ Object.keys(fixtureExport).forEach(function (fixtureName) {
58
+ var fixtureId = {
59
+ path: fixturePath,
60
+ name: fixtureName
61
+ };
62
+ fixtures.push({
63
+ fixtureId: fixtureId,
64
+ getElement: createFixtureElementGetter(multiFixtureExport[fixtureName], fixturePath, decoratorsByPath)
65
+ });
66
+ });
67
+ } else {
68
+ var fixtureId = {
69
+ path: fixturePath,
70
+ name: null
71
+ };
72
+ fixtures.push({
73
+ fixtureId: fixtureId,
74
+ getElement: createFixtureElementGetter(fixtureExport, fixturePath, decoratorsByPath)
75
+ });
76
+ }
77
+ });
78
+ return fixtures;
79
+ }
80
+
81
+ function createFixtureElementGetter(fixture, fixturePath, decoratorsByPath) {
82
+ var decorators = (0, _react.getSortedDecoratorsForFixturePath)(fixturePath, decoratorsByPath);
83
+ return function () {
84
+ return (0, _FixtureLoader.getDecoratedFixtureElement)(fixture, decorators, {
85
+ fixtureState: {},
86
+ setFixtureState: function setFixtureState() {},
87
+ onErrorReset: function onErrorReset() {}
88
+ });
89
+ };
90
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { CosmosConfig } from './config';
3
+ export declare type FixtureApi = {
4
+ absoluteFilePath: string;
5
+ fileName: string;
6
+ getElement: () => React.ReactElement<any>;
7
+ name: string | null;
8
+ parents: string[];
9
+ playgroundUrl: string;
10
+ relativeFilePath: string;
11
+ rendererUrl: string;
12
+ treePath: string[];
13
+ };
14
+ export declare function getFixtures2(cosmosConfig: CosmosConfig): FixtureApi[];
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getFixtures2 = getFixtures2;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _FixtureLoader = require("react-cosmos-shared2/FixtureLoader");
11
+
12
+ var _fixtureTree = require("react-cosmos-shared2/fixtureTree");
13
+
14
+ var _react = require("react-cosmos-shared2/react");
15
+
16
+ var _url = require("react-cosmos-shared2/url");
17
+
18
+ var _url2 = _interopRequireDefault(require("url"));
19
+
20
+ var _playgroundHtml = require("./shared/playgroundHtml");
21
+
22
+ var _userDeps = require("./shared/userDeps");
23
+
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+
26
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
27
+
28
+ 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."); }
29
+
30
+ 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); }
31
+
32
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
33
+
34
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
35
+
36
+ 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; }
37
+
38
+ function getFixtures2(cosmosConfig) {
39
+ var fixturesDir = cosmosConfig.fixturesDir,
40
+ fixtureFileSuffix = cosmosConfig.fixtureFileSuffix,
41
+ rootDir = cosmosConfig.rootDir;
42
+ var fixtureInfo = [];
43
+
44
+ var _getUserModules = (0, _userDeps.getUserModules)(cosmosConfig),
45
+ fixtureExportsByPath = _getUserModules.fixtureExportsByPath,
46
+ decoratorsByPath = _getUserModules.decoratorsByPath;
47
+
48
+ var fixtureNamesByPath = (0, _react.getFixtureNamesByPath)(fixtureExportsByPath);
49
+ var fixtureTree = (0, _fixtureTree.createFixtureTree)({
50
+ fixtures: fixtureNamesByPath,
51
+ fixturesDir: fixturesDir,
52
+ fixtureFileSuffix: fixtureFileSuffix
53
+ });
54
+ var flatFixtureTree = (0, _fixtureTree.flattenFixtureTree)(fixtureTree);
55
+ flatFixtureTree.forEach(function (_ref) {
56
+ var fileName = _ref.fileName,
57
+ fixtureId = _ref.fixtureId,
58
+ name = _ref.name,
59
+ parents = _ref.parents;
60
+ var fixtureExport = fixtureExportsByPath[fixtureId.path];
61
+ var fixture = fixtureId.name === null ? fixtureExport : fixtureExport[fixtureId.name];
62
+ var treePath = [].concat(_toConsumableArray(parents), [fileName]);
63
+ if (name) treePath.push(name);
64
+ fixtureInfo.push({
65
+ absoluteFilePath: _path.default.join(rootDir, fixtureId.path),
66
+ fileName: fileName,
67
+ getElement: createFixtureElementGetter(fixture, fixtureId.path, decoratorsByPath),
68
+ name: name,
69
+ parents: parents,
70
+ playgroundUrl: getPlaygroundUrl(cosmosConfig, fixtureId),
71
+ relativeFilePath: fixtureId.path,
72
+ rendererUrl: getRendererUrl(cosmosConfig, fixtureId),
73
+ treePath: treePath
74
+ });
75
+ });
76
+ return fixtureInfo;
77
+ }
78
+
79
+ function getPlaygroundUrl(cosmosConfig, fixtureId) {
80
+ var host = getPlaygroundHost(cosmosConfig);
81
+ var query = (0, _url.stringifyPlaygroundUrlQuery)({
82
+ fixtureId: fixtureId
83
+ });
84
+ return "".concat(host, "/?").concat(query);
85
+ }
86
+
87
+ function getRendererUrl(cosmosConfig, fixtureId) {
88
+ var publicUrl = cosmosConfig.publicUrl,
89
+ experimentalRendererUrl = cosmosConfig.experimentalRendererUrl;
90
+ var query = (0, _url.stringifyRendererUrlQuery)({
91
+ _fixtureId: fixtureId
92
+ });
93
+ if (experimentalRendererUrl) return "".concat(experimentalRendererUrl, "?").concat(query);
94
+ var host = getPlaygroundHost(cosmosConfig);
95
+
96
+ var urlPath = _url2.default.resolve(publicUrl, _playgroundHtml.RENDERER_FILENAME);
97
+
98
+ return "".concat(host).concat(urlPath, "?").concat(query);
99
+ }
100
+
101
+ function getPlaygroundHost(_ref2) {
102
+ var hostname = _ref2.hostname,
103
+ port = _ref2.port,
104
+ https = _ref2.https;
105
+ return "".concat(https ? 'https' : 'http', "://").concat(hostname || 'localhost', ":").concat(port);
106
+ }
107
+
108
+ function createFixtureElementGetter(fixture, fixturePath, decoratorsByPath) {
109
+ var decorators = (0, _react.getSortedDecoratorsForFixturePath)(fixturePath, decoratorsByPath);
110
+ return function () {
111
+ return (0, _FixtureLoader.getDecoratedFixtureElement)(fixture, decorators, {
112
+ fixtureState: {},
113
+ setFixtureState: function setFixtureState() {},
114
+ onErrorReset: function onErrorReset() {}
115
+ });
116
+ };
117
+ }
@@ -0,0 +1,4 @@
1
+ export { createCosmosConfig, detectCosmosConfig, getCosmosConfigAtPath, } from './config';
2
+ export { getFixtures, getFixturesSync } from './getFixtures';
3
+ export { FixtureApi, getFixtures2 } from './getFixtures2';
4
+ export { getFixtureUrls, getFixtureUrlsSync } from './getFixtureUrls';
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "createCosmosConfig", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _config.createCosmosConfig;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "detectCosmosConfig", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _config.detectCosmosConfig;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "getCosmosConfigAtPath", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _config.getCosmosConfigAtPath;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "getFixtures", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _getFixtures.getFixtures;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "getFixturesSync", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _getFixtures.getFixturesSync;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "FixtureApi", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _getFixtures2.FixtureApi;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "getFixtures2", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _getFixtures2.getFixtures2;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "getFixtureUrls", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _getFixtureUrls.getFixtureUrls;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "getFixtureUrlsSync", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _getFixtureUrls.getFixtureUrlsSync;
58
+ }
59
+ });
60
+
61
+ var _config = require("./config");
62
+
63
+ var _getFixtures = require("./getFixtures");
64
+
65
+ var _getFixtures2 = require("./getFixtures2");
66
+
67
+ var _getFixtureUrls = require("./getFixtureUrls");
@@ -0,0 +1,9 @@
1
+ import { ReactDecoratorsByPath, ReactFixtureExportsByPath } from 'react-cosmos-shared2/react';
2
+ import { NativeRendererConfig } from './shared/rendererConfig';
3
+ declare type Props = {
4
+ rendererConfig: NativeRendererConfig;
5
+ fixtures: ReactFixtureExportsByPath;
6
+ decorators: ReactDecoratorsByPath;
7
+ };
8
+ export declare function NativeFixtureLoader({ rendererConfig: { port }, fixtures, decorators, }: Props): JSX.Element;
9
+ export {};
package/dist/native.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.NativeFixtureLoader = NativeFixtureLoader;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _FixtureLoader = require("react-cosmos-shared2/FixtureLoader");
13
+
14
+ var ReactNative = _interopRequireWildcard(require("react-native"));
15
+
16
+ var _urlParse = _interopRequireDefault(require("url-parse"));
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ var View = ReactNative.View,
25
+ Text = ReactNative.Text,
26
+ StyleSheet = ReactNative.StyleSheet,
27
+ NativeModules = ReactNative.NativeModules; // https://stackoverflow.com/a/53655887/128816
28
+
29
+ var wsWarning = 'Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?';
30
+ if (ReactNative.LogBox) ReactNative.LogBox.ignoreLogs([wsWarning]);else if (ReactNative.YellowBox) ReactNative.YellowBox.ignoreWarnings([wsWarning]); // TODO: Generate unique ID per device
31
+
32
+ var rendererId = 'native-renderer';
33
+
34
+ function NativeFixtureLoader(_ref) {
35
+ var port = _ref.rendererConfig.port,
36
+ fixtures = _ref.fixtures,
37
+ decorators = _ref.decorators;
38
+ var socketUrl = getSocketUrl(port);
39
+ return /*#__PURE__*/_react.default.createElement(_FixtureLoader.FixtureLoader, {
40
+ rendererId: rendererId,
41
+ rendererConnect: (0, _FixtureLoader.createWebSocketsConnect)(socketUrl),
42
+ fixtures: fixtures,
43
+ selectedFixtureId: null,
44
+ systemDecorators: [],
45
+ userDecorators: decorators,
46
+ renderMessage: renderMessage
47
+ });
48
+ }
49
+
50
+ function getSocketUrl(port) {
51
+ var host = (0, _urlParse.default)(NativeModules.SourceCode.scriptURL).hostname;
52
+ return "ws://".concat(host, ":").concat(port);
53
+ }
54
+
55
+ function renderMessage(_ref2) {
56
+ var msg = _ref2.msg;
57
+ return /*#__PURE__*/_react.default.createElement(View, {
58
+ style: styles.container
59
+ }, /*#__PURE__*/_react.default.createElement(Text, null, msg));
60
+ }
61
+
62
+ var styles = StyleSheet.create({
63
+ container: {
64
+ flex: 1,
65
+ backgroundColor: '#fff',
66
+ alignItems: 'center',
67
+ justifyContent: 'center'
68
+ }
69
+ });
@@ -0,0 +1 @@
1
+ export declare function startNativeServer(): Promise<void>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.startNativeServer = startNativeServer;
7
+
8
+ var _openFile = require("./plugins/openFile");
9
+
10
+ var _userDepsFile = require("./plugins/userDepsFile");
11
+
12
+ var _devServer = require("./shared/devServer");
13
+
14
+ 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); } }
15
+
16
+ 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); }); }; }
17
+
18
+ function startNativeServer() {
19
+ return _startNativeServer.apply(this, arguments);
20
+ }
21
+
22
+ function _startNativeServer() {
23
+ _startNativeServer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
24
+ return regeneratorRuntime.wrap(function _callee$(_context) {
25
+ while (1) {
26
+ switch (_context.prev = _context.next) {
27
+ case 0:
28
+ _context.next = 2;
29
+ return (0, _devServer.startDevServer)('native', [_userDepsFile.userDepsFile, _openFile.openFile]);
30
+
31
+ case 2:
32
+ case "end":
33
+ return _context.stop();
34
+ }
35
+ }
36
+ }, _callee);
37
+ }));
38
+ return _startNativeServer.apply(this, arguments);
39
+ }
@@ -0,0 +1,2 @@
1
+ import { DevServerPluginArgs } from '../shared/devServer';
2
+ export declare function httpProxy({ cosmosConfig, expressApp }: DevServerPluginArgs): void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.httpProxy = httpProxy;
7
+
8
+ var _httpProxyMiddleware = require("http-proxy-middleware");
9
+
10
+ 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); }
11
+
12
+ function httpProxy(_ref) {
13
+ var cosmosConfig = _ref.cosmosConfig,
14
+ expressApp = _ref.expressApp;
15
+ var httpProxyConfig = getHttpProxyCosmosConfig(cosmosConfig);
16
+ Object.keys(httpProxyConfig).forEach(function (context) {
17
+ var config = httpProxyConfig[context];
18
+
19
+ if (typeof config === 'string') {
20
+ expressApp.use(context, (0, _httpProxyMiddleware.createProxyMiddleware)(context, {
21
+ target: config
22
+ }));
23
+ } else if (_typeof(config) === 'object') {
24
+ expressApp.use(context, (0, _httpProxyMiddleware.createProxyMiddleware)(context, config));
25
+ }
26
+ });
27
+ }
28
+
29
+ function getHttpProxyCosmosConfig(cosmosConfig) {
30
+ return cosmosConfig.httpProxy || {};
31
+ }
@@ -0,0 +1,2 @@
1
+ import { DevServerPluginArgs } from '../shared/devServer';
2
+ export declare function openFile({ cosmosConfig, expressApp }: DevServerPluginArgs): void;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.openFile = openFile;
7
+
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+
10
+ var _path = _interopRequireDefault(require("path"));
11
+
12
+ var _open = _interopRequireDefault(require("open"));
13
+
14
+ var _launchEditor = _interopRequireDefault(require("@skidding/launch-editor"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function openFile(_ref) {
19
+ var cosmosConfig = _ref.cosmosConfig,
20
+ expressApp = _ref.expressApp;
21
+ expressApp.get('/_open', function (req, res) {
22
+ var _getReqQuery = getReqQuery(req),
23
+ filePath = _getReqQuery.filePath,
24
+ line = _getReqQuery.line,
25
+ column = _getReqQuery.column;
26
+
27
+ if (!filePath) {
28
+ res.status(400).send("File path missing");
29
+ return;
30
+ }
31
+
32
+ var absFilePath = resolveFilePath(cosmosConfig, filePath);
33
+
34
+ if (!_fs.default.existsSync(absFilePath)) {
35
+ res.status(404).send("File not found at path: ".concat(absFilePath));
36
+ return;
37
+ }
38
+
39
+ new Promise(function (resolve, reject) {
40
+ var file = "".concat(absFilePath, ":").concat(line, ":").concat(column);
41
+ (0, _launchEditor.default)(file, function (fileName, errorMsg) {
42
+ return reject(errorMsg);
43
+ }); // If launchEditor doesn't report error within 500ms we assume it worked
44
+
45
+ setTimeout(resolve, 500);
46
+ }) // Fall back to open in case launchEditor fails. launchEditor only works
47
+ // when the editor app is already open, but is favorable because it can
48
+ // open a code file on a specific line & column.
49
+ .catch(function (err) {
50
+ return (0, _open.default)(absFilePath);
51
+ }).catch(function (err) {
52
+ return res.status(500).send('Failed to open file');
53
+ }).then(function () {
54
+ return res.send();
55
+ });
56
+ });
57
+ }
58
+
59
+ function getReqQuery(req) {
60
+ var _req$query = req.query,
61
+ filePath = _req$query.filePath,
62
+ line = _req$query.line,
63
+ column = _req$query.column;
64
+ if (typeof filePath !== 'string') throw new Error('filePath missing');
65
+ return {
66
+ filePath: filePath,
67
+ line: typeof line === 'string' ? parseInt(line, 10) : 1,
68
+ column: typeof column === 'string' ? parseInt(column, 10) : 1
69
+ };
70
+ }
71
+
72
+ function resolveFilePath(cosmosConfig, filePath) {
73
+ // This heuristic is needed because the open file endpoint is used for
74
+ // multiple applications, which provide different file path types:
75
+ // 1. Edit fixture button: Sends path relative to Cosmos rootDir
76
+ // 2. react-error-overlay runtime error: Sends absolute path
77
+ // 3. react-error-overlay compile error: Sends path relative to CWD
78
+ if (_path.default.isAbsolute(filePath)) {
79
+ return filePath;
80
+ }
81
+
82
+ var cosmosRelPath = _path.default.join(cosmosConfig.rootDir, filePath);
83
+
84
+ var cwdRelPath = _path.default.join(process.cwd(), filePath);
85
+
86
+ return _fs.default.existsSync(cosmosRelPath) ? cosmosRelPath : cwdRelPath;
87
+ }
@@ -0,0 +1,2 @@
1
+ import { DevServerPluginArgs } from '../shared/devServer';
2
+ export declare function userDepsFile(args: DevServerPluginArgs): Promise<(() => void) | undefined>;