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.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/bin/cosmos-export.js +14 -0
- package/bin/cosmos-native.js +14 -0
- package/bin/cosmos.js +18 -0
- package/config.schema.json +186 -0
- package/dist/config/createCosmosConfig.d.ts +2 -0
- package/dist/config/createCosmosConfig.js +133 -0
- package/dist/config/detectCosmosConfig.d.ts +2 -0
- package/dist/config/detectCosmosConfig.js +57 -0
- package/dist/config/getCosmosConfigAtPath.d.ts +1 -0
- package/dist/config/getCosmosConfigAtPath.js +28 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +51 -0
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.js +20 -0
- package/dist/config/shared.d.ts +29 -0
- package/dist/config/shared.js +17 -0
- package/dist/dom/DomFixtureLoader.d.ts +8 -0
- package/dist/dom/DomFixtureLoader.js +38 -0
- package/dist/dom/ErrorCatch.d.ts +15 -0
- package/dist/dom/ErrorCatch.js +117 -0
- package/dist/dom/container.d.ts +1 -0
- package/dist/dom/container.js +32 -0
- package/dist/dom/globalErrorHandler.d.ts +1 -0
- package/dist/dom/globalErrorHandler.js +14 -0
- package/dist/dom/index.d.ts +13 -0
- package/dist/dom/index.js +47 -0
- package/dist/dom/renderMessage.d.ts +3 -0
- package/dist/dom/renderMessage.js +30 -0
- package/dist/dom/rendererConnect.d.ts +1 -0
- package/dist/dom/rendererConnect.js +18 -0
- package/dist/dom/rendererId.d.ts +1 -0
- package/dist/dom/rendererId.js +26 -0
- package/dist/dom/selectedFixtureId.d.ts +2 -0
- package/dist/dom/selectedFixtureId.js +41 -0
- package/dist/dom/shared.d.ts +1 -0
- package/dist/dom/shared.js +14 -0
- package/dist/fixture.d.ts +1 -0
- package/dist/fixture.js +31 -0
- package/dist/getFixtureUrls.d.ts +8 -0
- package/dist/getFixtureUrls.js +98 -0
- package/dist/getFixtures.d.ts +13 -0
- package/dist/getFixtures.js +90 -0
- package/dist/getFixtures2.d.ts +14 -0
- package/dist/getFixtures2.js +117 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +67 -0
- package/dist/native.d.ts +9 -0
- package/dist/native.js +69 -0
- package/dist/nativeServer.d.ts +1 -0
- package/dist/nativeServer.js +39 -0
- package/dist/plugins/httpProxy.d.ts +2 -0
- package/dist/plugins/httpProxy.js +31 -0
- package/dist/plugins/openFile.d.ts +2 -0
- package/dist/plugins/openFile.js +87 -0
- package/dist/plugins/userDepsFile.d.ts +2 -0
- package/dist/plugins/userDepsFile.js +164 -0
- package/dist/plugins/webpack/client/errorOverlay/index.d.ts +1 -0
- package/dist/plugins/webpack/client/errorOverlay/index.js +16 -0
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.d.ts +2 -0
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.js +63 -0
- package/dist/plugins/webpack/client/hmrErrorHandler.d.ts +1 -0
- package/dist/plugins/webpack/client/hmrErrorHandler.js +16 -0
- package/dist/plugins/webpack/client/index.d.ts +6 -0
- package/dist/plugins/webpack/client/index.js +43 -0
- package/dist/plugins/webpack/client/reactDevtoolsHook.d.ts +0 -0
- package/dist/plugins/webpack/client/reactDevtoolsHook.js +19 -0
- package/dist/plugins/webpack/client/userDeps.d.ts +5 -0
- package/dist/plugins/webpack/client/userDeps.js +15 -0
- package/dist/plugins/webpack/cosmosConfig/dom.d.ts +6 -0
- package/dist/plugins/webpack/cosmosConfig/dom.js +19 -0
- package/dist/plugins/webpack/cosmosConfig/webpack.d.ts +9 -0
- package/dist/plugins/webpack/cosmosConfig/webpack.js +88 -0
- package/dist/plugins/webpack/devServer.d.ts +2 -0
- package/dist/plugins/webpack/devServer.js +168 -0
- package/dist/plugins/webpack/export.d.ts +2 -0
- package/dist/plugins/webpack/export.js +135 -0
- package/dist/plugins/webpack/index.d.ts +2 -0
- package/dist/plugins/webpack/index.js +21 -0
- package/dist/plugins/webpack/shared.d.ts +2 -0
- package/dist/plugins/webpack/shared.js +22 -0
- package/dist/plugins/webpack/webpackConfig/default.d.ts +2 -0
- package/dist/plugins/webpack/webpackConfig/default.js +152 -0
- package/dist/plugins/webpack/webpackConfig/devServer.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/devServer.js +144 -0
- package/dist/plugins/webpack/webpackConfig/export.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/export.js +110 -0
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.d.ts +16 -0
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.js +80 -0
- package/dist/plugins/webpack/webpackConfig/index.d.ts +2 -0
- package/dist/plugins/webpack/webpackConfig/index.js +21 -0
- package/dist/plugins/webpack/webpackConfig/module.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/module.js +18 -0
- package/dist/plugins/webpack/webpackConfig/shared.d.ts +11 -0
- package/dist/plugins/webpack/webpackConfig/shared.js +254 -0
- package/dist/plugins/webpack/webpackConfig/userDepsLoader.d.ts +1 -0
- package/dist/plugins/webpack/webpackConfig/userDepsLoader.js +36 -0
- package/dist/shared/cli.d.ts +5 -0
- package/dist/shared/cli.js +14 -0
- package/dist/shared/devServer/app.d.ts +5 -0
- package/dist/shared/devServer/app.js +51 -0
- package/dist/shared/devServer/httpServer.d.ts +11 -0
- package/dist/shared/devServer/httpServer.js +183 -0
- package/dist/shared/devServer/index.d.ts +18 -0
- package/dist/shared/devServer/index.js +209 -0
- package/dist/shared/devServer/messageHandler.d.ts +7 -0
- package/dist/shared/devServer/messageHandler.js +42 -0
- package/dist/shared/export.d.ts +6 -0
- package/dist/shared/export.js +137 -0
- package/dist/shared/fs.d.ts +4 -0
- package/dist/shared/fs.js +37 -0
- package/dist/shared/playgroundHtml.d.ts +6 -0
- package/dist/shared/playgroundHtml.js +116 -0
- package/dist/shared/pluginConfigs.d.ts +2 -0
- package/dist/shared/pluginConfigs.js +15 -0
- package/dist/shared/rendererConfig.d.ts +6 -0
- package/dist/shared/rendererConfig.js +5 -0
- package/dist/shared/shared.d.ts +6 -0
- package/dist/shared/shared.js +22 -0
- package/dist/shared/static/favicon.ico +0 -0
- package/dist/shared/static/index.html +19 -0
- package/dist/shared/static.d.ts +3 -0
- package/dist/shared/static.js +30 -0
- package/dist/shared/userDeps/findUserModulePaths.d.ts +11 -0
- package/dist/shared/userDeps/findUserModulePaths.js +45 -0
- package/dist/shared/userDeps/generateUserDepsModule.d.ts +9 -0
- package/dist/shared/userDeps/generateUserDepsModule.js +37 -0
- package/dist/shared/userDeps/getUserModules.d.ts +8 -0
- package/dist/shared/userDeps/getUserModules.js +45 -0
- package/dist/shared/userDeps/index.d.ts +4 -0
- package/dist/shared/userDeps/index.js +49 -0
- package/dist/shared/userDeps/shared.d.ts +6 -0
- package/dist/shared/userDeps/shared.js +32 -0
- package/dist/shared/userDeps/userDepsTemplate.d.ts +11 -0
- package/dist/shared/userDeps/userDepsTemplate.js +52 -0
- package/dist/webExport.d.ts +1 -0
- package/dist/webExport.js +37 -0
- package/dist/webServer.d.ts +1 -0
- package/dist/webServer.js +43 -0
- package/dom.d.ts +1 -0
- package/dom.js +2 -0
- package/fixture.d.ts +1 -0
- package/fixture.js +2 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/native.d.ts +1 -0
- package/native.js +2 -0
- package/package.json +42 -0
- package/yarn-error.log +13450 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.userDepsFile = userDepsFile;
|
|
7
|
+
|
|
8
|
+
var _chokidar = require("chokidar");
|
|
9
|
+
|
|
10
|
+
var _fs = require("fs");
|
|
11
|
+
|
|
12
|
+
var _lodash = require("lodash");
|
|
13
|
+
|
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
|
15
|
+
|
|
16
|
+
var _util = _interopRequireDefault(require("util.promisify"));
|
|
17
|
+
|
|
18
|
+
var _cli = require("../shared/cli");
|
|
19
|
+
|
|
20
|
+
var _userDeps = require("../shared/userDeps");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
25
|
+
|
|
26
|
+
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."); }
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
31
|
+
|
|
32
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
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); } }
|
|
37
|
+
|
|
38
|
+
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); }); }; }
|
|
39
|
+
|
|
40
|
+
var writeFileAsync = (0, _util.default)(_fs.writeFile);
|
|
41
|
+
|
|
42
|
+
function userDepsFile(_x) {
|
|
43
|
+
return _userDepsFile.apply(this, arguments);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _userDepsFile() {
|
|
47
|
+
_userDepsFile = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(args) {
|
|
48
|
+
var cosmosConfig, watcher;
|
|
49
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
50
|
+
while (1) {
|
|
51
|
+
switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
if (shouldGenerateUserDepsFile(args)) {
|
|
54
|
+
_context.next = 2;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return _context.abrupt("return");
|
|
59
|
+
|
|
60
|
+
case 2:
|
|
61
|
+
cosmosConfig = args.cosmosConfig;
|
|
62
|
+
_context.next = 5;
|
|
63
|
+
return generateUserDepsFile(cosmosConfig);
|
|
64
|
+
|
|
65
|
+
case 5:
|
|
66
|
+
_context.next = 7;
|
|
67
|
+
return startFixtureFileWatcher(cosmosConfig);
|
|
68
|
+
|
|
69
|
+
case 7:
|
|
70
|
+
watcher = _context.sent;
|
|
71
|
+
return _context.abrupt("return", function () {
|
|
72
|
+
watcher.close();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
case 9:
|
|
76
|
+
case "end":
|
|
77
|
+
return _context.stop();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, _callee);
|
|
81
|
+
}));
|
|
82
|
+
return _userDepsFile.apply(this, arguments);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function shouldGenerateUserDepsFile(_ref) {
|
|
86
|
+
var cosmosConfig = _ref.cosmosConfig,
|
|
87
|
+
platformType = _ref.platformType;
|
|
88
|
+
return platformType === 'native' || cosmosConfig.experimentalRendererUrl !== null || // CLI support for --external-userdeps flag (useful with react-native-web)
|
|
89
|
+
Boolean((0, _cli.getCliArgs)().externalUserdeps);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var DEBOUNCE_INTERVAL = 50;
|
|
93
|
+
|
|
94
|
+
function startFixtureFileWatcher(_x2) {
|
|
95
|
+
return _startFixtureFileWatcher.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function _startFixtureFileWatcher() {
|
|
99
|
+
_startFixtureFileWatcher = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(cosmosConfig) {
|
|
100
|
+
var fixturesDir, fixtureFileSuffix, FILE_PATTERNS;
|
|
101
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
102
|
+
while (1) {
|
|
103
|
+
switch (_context2.prev = _context2.next) {
|
|
104
|
+
case 0:
|
|
105
|
+
fixturesDir = cosmosConfig.fixturesDir, fixtureFileSuffix = cosmosConfig.fixtureFileSuffix;
|
|
106
|
+
FILE_PATTERNS = [].concat(_toConsumableArray((0, _userDeps.getFixturePatterns)(fixturesDir, fixtureFileSuffix)), _toConsumableArray((0, _userDeps.getDecoratorPatterns)()));
|
|
107
|
+
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
108
|
+
var watcher = (0, _chokidar.watch)(FILE_PATTERNS, {
|
|
109
|
+
ignored: (0, _userDeps.getIgnorePatterns)(),
|
|
110
|
+
ignoreInitial: true,
|
|
111
|
+
cwd: cosmosConfig.rootDir
|
|
112
|
+
}).on('ready', function () {
|
|
113
|
+
return resolve(watcher);
|
|
114
|
+
}).on('all', (0, _lodash.debounce)(function () {
|
|
115
|
+
return generateUserDepsFile(cosmosConfig);
|
|
116
|
+
}, DEBOUNCE_INTERVAL));
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
case 3:
|
|
120
|
+
case "end":
|
|
121
|
+
return _context2.stop();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, _callee2);
|
|
125
|
+
}));
|
|
126
|
+
return _startFixtureFileWatcher.apply(this, arguments);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function generateUserDepsFile(_x3) {
|
|
130
|
+
return _generateUserDepsFile.apply(this, arguments);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function _generateUserDepsFile() {
|
|
134
|
+
_generateUserDepsFile = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(cosmosConfig) {
|
|
135
|
+
var userDepsFilePath, port, rendererConfig, userDepsModule, relUserDepsFilePath;
|
|
136
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
137
|
+
while (1) {
|
|
138
|
+
switch (_context3.prev = _context3.next) {
|
|
139
|
+
case 0:
|
|
140
|
+
userDepsFilePath = cosmosConfig.userDepsFilePath, port = cosmosConfig.port;
|
|
141
|
+
rendererConfig = {
|
|
142
|
+
port: port
|
|
143
|
+
};
|
|
144
|
+
userDepsModule = (0, _userDeps.generateUserDepsModule)({
|
|
145
|
+
cosmosConfig: cosmosConfig,
|
|
146
|
+
rendererConfig: rendererConfig,
|
|
147
|
+
relativeToDir: _path.default.dirname(userDepsFilePath)
|
|
148
|
+
});
|
|
149
|
+
_context3.next = 5;
|
|
150
|
+
return writeFileAsync(userDepsFilePath, userDepsModule, 'utf8');
|
|
151
|
+
|
|
152
|
+
case 5:
|
|
153
|
+
relUserDepsFilePath = _path.default.relative(process.cwd(), userDepsFilePath);
|
|
154
|
+
console.log("[Cosmos] Generated ".concat(relUserDepsFilePath));
|
|
155
|
+
|
|
156
|
+
case 7:
|
|
157
|
+
case "end":
|
|
158
|
+
return _context3.stop();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}, _callee3);
|
|
162
|
+
}));
|
|
163
|
+
return _generateUserDepsFile.apply(this, arguments);
|
|
164
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dismissErrorOverlay(): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.dismissErrorOverlay = dismissErrorOverlay;
|
|
7
|
+
|
|
8
|
+
if (__DEV__) {
|
|
9
|
+
require('./reactErrorOverlay').init();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function dismissErrorOverlay() {
|
|
13
|
+
if (__DEV__) {
|
|
14
|
+
require('./reactErrorOverlay').dismiss();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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.init = init;
|
|
9
|
+
exports.dismiss = dismiss;
|
|
10
|
+
|
|
11
|
+
var _url = require("react-cosmos-shared2/url");
|
|
12
|
+
|
|
13
|
+
var ErrorOverlay = _interopRequireWildcard(require("react-error-overlay"));
|
|
14
|
+
|
|
15
|
+
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); }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
|
|
19
|
+
var LAUNCH_EDITOR_ENDPOINT = '/_open';
|
|
20
|
+
|
|
21
|
+
function init() {
|
|
22
|
+
ErrorOverlay.startReportingRuntimeErrors({
|
|
23
|
+
filename: process.env.PUBLIC_URL + '/main.js'
|
|
24
|
+
});
|
|
25
|
+
ErrorOverlay.setEditorHandler(function (errorLocation) {
|
|
26
|
+
return window.fetch(getLaunchEditorUrl(errorLocation));
|
|
27
|
+
});
|
|
28
|
+
setUpBuildErrorReporting();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function dismiss() {
|
|
32
|
+
ErrorOverlay.dismissRuntimeErrors();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getLaunchEditorUrl(errorLocation) {
|
|
36
|
+
return "".concat(LAUNCH_EDITOR_ENDPOINT, "?").concat((0, _url.stringifyUrlQuery)({
|
|
37
|
+
filePath: errorLocation.fileName,
|
|
38
|
+
line: errorLocation.lineNumber || 1,
|
|
39
|
+
column: errorLocation.colNumber || 1
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function setUpBuildErrorReporting() {
|
|
44
|
+
var clientWindow = window;
|
|
45
|
+
|
|
46
|
+
if (clientWindow.__webpack_hot_middleware_reporter__ === undefined) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
clientWindow.__webpack_hot_middleware_reporter__.useCustomOverlay({
|
|
51
|
+
showProblems: function showProblems(type, obj) {
|
|
52
|
+
if (type !== 'errors') {
|
|
53
|
+
// We might've went from errors -> warnings
|
|
54
|
+
ErrorOverlay.dismissBuildError();
|
|
55
|
+
} else {
|
|
56
|
+
ErrorOverlay.reportBuildError(obj[0]);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
clear: function clear() {
|
|
60
|
+
ErrorOverlay.dismissBuildError();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _dom = require("../../../dom");
|
|
4
|
+
|
|
5
|
+
if (__DEV__) {
|
|
6
|
+
var webpackRendererConnect = _dom.rendererConnect;
|
|
7
|
+
|
|
8
|
+
window.onHotReloadError = function () {
|
|
9
|
+
return webpackRendererConnect.postMessage({
|
|
10
|
+
type: 'rendererHmrFail',
|
|
11
|
+
payload: {
|
|
12
|
+
rendererId: _dom.rendererId
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("regenerator-runtime/runtime");
|
|
4
|
+
|
|
5
|
+
require("core-js/features/promise");
|
|
6
|
+
|
|
7
|
+
require("core-js/features/array/find");
|
|
8
|
+
|
|
9
|
+
require("core-js/features/array/includes");
|
|
10
|
+
|
|
11
|
+
require("core-js/features/array/fill");
|
|
12
|
+
|
|
13
|
+
var _dom = require("../../../dom");
|
|
14
|
+
|
|
15
|
+
var _errorOverlay = require("./errorOverlay");
|
|
16
|
+
|
|
17
|
+
require("./hmrErrorHandler");
|
|
18
|
+
|
|
19
|
+
mount();
|
|
20
|
+
|
|
21
|
+
function mount() {
|
|
22
|
+
// Use dynamic import to load updated modules upon hot reloading
|
|
23
|
+
var _require = require('./userDeps'),
|
|
24
|
+
rendererConfig = _require.rendererConfig,
|
|
25
|
+
fixtures = _require.fixtures,
|
|
26
|
+
decorators = _require.decorators;
|
|
27
|
+
|
|
28
|
+
(0, _dom.mountDomRenderer)({
|
|
29
|
+
rendererConfig: rendererConfig,
|
|
30
|
+
fixtures: fixtures,
|
|
31
|
+
decorators: decorators,
|
|
32
|
+
onErrorReset: _errorOverlay.dismissErrorOverlay
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (module.hot) {
|
|
37
|
+
module.hot.accept('./userDeps', function () {
|
|
38
|
+
// If a previous error has been solved, the error overlay auto-closes nicely.
|
|
39
|
+
// If the error persists, however, the overlay will pop up again on its own
|
|
40
|
+
(0, _errorOverlay.dismissErrorOverlay)();
|
|
41
|
+
mount();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// TLDR: This has to be done before React is imported
|
|
4
|
+
// https://github.com/facebook/react-devtools/issues/76#issuecomment-128091900
|
|
5
|
+
// More context: User-defined "global imports" have to be imported *after* this
|
|
6
|
+
// file (because they can import React), but *before* the main renderer entry
|
|
7
|
+
// point (because the user's global imports have to take effect before we
|
|
8
|
+
// import fixture and decorator modules). For this reason this file has to be
|
|
9
|
+
// imported by hand in each renderer implementation.
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
if (process.env.NODE_ENV === 'development') {
|
|
12
|
+
// Accessing the parent window can throw when loading a static export without
|
|
13
|
+
// a web server (i.e. via file:/// protocol)
|
|
14
|
+
try {
|
|
15
|
+
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.warn('Could not access parent React devtools hook');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ReactDecoratorsByPath, ReactFixtureExportsByPath } from 'react-cosmos-shared2/react';
|
|
2
|
+
import { DomRendererConfig } from '../../../shared/rendererConfig';
|
|
3
|
+
export declare const rendererConfig: DomRendererConfig;
|
|
4
|
+
export declare const fixtures: ReactFixtureExportsByPath;
|
|
5
|
+
export declare const decorators: ReactDecoratorsByPath;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.decorators = exports.fixtures = exports.rendererConfig = void 0;
|
|
7
|
+
// NOTE: Renderer data is statically injected at compile time
|
|
8
|
+
var rendererConfig = {
|
|
9
|
+
containerQuerySelector: null
|
|
10
|
+
};
|
|
11
|
+
exports.rendererConfig = rendererConfig;
|
|
12
|
+
var fixtures = {};
|
|
13
|
+
exports.fixtures = fixtures;
|
|
14
|
+
var decorators = {};
|
|
15
|
+
exports.decorators = decorators;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDomCosmosConfig = createDomCosmosConfig;
|
|
7
|
+
|
|
8
|
+
function createDomCosmosConfig(cosmosConfig) {
|
|
9
|
+
var configInput = cosmosConfig.dom || {};
|
|
10
|
+
return {
|
|
11
|
+
containerQuerySelector: getContainerQuerySelector(configInput)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getContainerQuerySelector(_ref) {
|
|
16
|
+
var _ref$containerQuerySe = _ref.containerQuerySelector,
|
|
17
|
+
containerQuerySelector = _ref$containerQuerySe === void 0 ? null : _ref$containerQuerySe;
|
|
18
|
+
return containerQuerySelector;
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CosmosConfig } from '../../../config';
|
|
2
|
+
declare type WebpackCosmosConfig = {
|
|
3
|
+
configPath: null | string;
|
|
4
|
+
overridePath: null | string;
|
|
5
|
+
includeHashInOutputFilename: boolean;
|
|
6
|
+
hotReload: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function createWebpackCosmosConfig(cosmosConfig: CosmosConfig): WebpackCosmosConfig;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createWebpackCosmosConfig = createWebpackCosmosConfig;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _config = require("../../../config");
|
|
11
|
+
|
|
12
|
+
var _fs = require("../../../shared/fs");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function createWebpackCosmosConfig(cosmosConfig) {
|
|
17
|
+
var rootDir = cosmosConfig.rootDir;
|
|
18
|
+
var configInput = cosmosConfig.webpack || {};
|
|
19
|
+
return {
|
|
20
|
+
configPath: getWebpackConfigPath(configInput, rootDir),
|
|
21
|
+
overridePath: getWebpackOverridePath(configInput, rootDir),
|
|
22
|
+
includeHashInOutputFilename: getIncludeHashInOutputFilename(configInput),
|
|
23
|
+
hotReload: getHotReload(configInput)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getWebpackConfigPath(_ref, rootDir) {
|
|
28
|
+
var configPath = _ref.configPath;
|
|
29
|
+
|
|
30
|
+
if (typeof configPath === 'undefined') {
|
|
31
|
+
return (0, _config.resolveModule)(rootDir, 'webpack.config.js');
|
|
32
|
+
} // User can choose to prevent automatical use of an existing webpack.config.js
|
|
33
|
+
// file (relative to the root dir) by setting configPath to null
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if (!configPath) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var absPath = (0, _config.resolveModule)(rootDir, configPath);
|
|
41
|
+
|
|
42
|
+
if (!(0, _fs.fileExists)(absPath)) {
|
|
43
|
+
var relPath = _path.default.relative(process.cwd(), absPath);
|
|
44
|
+
|
|
45
|
+
throw new Error("webpack config not found at path: ".concat(relPath));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return absPath;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getWebpackOverridePath(_ref2, rootDir) {
|
|
52
|
+
var overridePath = _ref2.overridePath;
|
|
53
|
+
|
|
54
|
+
if (typeof overridePath === 'undefined') {
|
|
55
|
+
return (0, _config.resolveModule)(rootDir, 'webpack.override.js');
|
|
56
|
+
} // User can choose to prevent automatical use of an existing webpack.override.js
|
|
57
|
+
// file (relative to the root dir) by setting overridePath to null
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if (!overridePath) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var absPath = (0, _config.resolveModule)(rootDir, overridePath);
|
|
65
|
+
|
|
66
|
+
if (!(0, _fs.fileExists)(absPath)) {
|
|
67
|
+
var relPath = _path.default.relative(process.cwd(), absPath);
|
|
68
|
+
|
|
69
|
+
throw new Error("webpack override module not found at path: ".concat(relPath));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return absPath;
|
|
73
|
+
} // Default value is False to not break backwards compatibility
|
|
74
|
+
// In future releases it's better to mark this as @deprecated and set
|
|
75
|
+
// output.filename to "[name].[contenthash].js" by default
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
function getIncludeHashInOutputFilename(_ref3) {
|
|
79
|
+
var _ref3$includeHashInOu = _ref3.includeHashInOutputFilename,
|
|
80
|
+
includeHashInOutputFilename = _ref3$includeHashInOu === void 0 ? false : _ref3$includeHashInOu;
|
|
81
|
+
return includeHashInOutputFilename;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getHotReload(_ref4) {
|
|
85
|
+
var _ref4$hotReload = _ref4.hotReload,
|
|
86
|
+
hotReload = _ref4$hotReload === void 0 ? true : _ref4$hotReload;
|
|
87
|
+
return hotReload;
|
|
88
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.webpackDevServer = webpackDevServer;
|
|
7
|
+
|
|
8
|
+
var _webpackHotMiddleware = _interopRequireDefault(require("@skidding/webpack-hot-middleware"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _shared = require("../../shared/shared");
|
|
13
|
+
|
|
14
|
+
var _static = require("../../shared/static");
|
|
15
|
+
|
|
16
|
+
var _webpack = require("./cosmosConfig/webpack");
|
|
17
|
+
|
|
18
|
+
var _shared2 = require("./shared");
|
|
19
|
+
|
|
20
|
+
var _webpackConfig = require("./webpackConfig");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
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); } }
|
|
25
|
+
|
|
26
|
+
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); }); }; }
|
|
27
|
+
|
|
28
|
+
function webpackDevServer(_x) {
|
|
29
|
+
return _webpackDevServer.apply(this, arguments);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _webpackDevServer() {
|
|
33
|
+
_webpackDevServer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref) {
|
|
34
|
+
var cosmosConfig, expressApp, sendMessage, userWebpack, webpackConfig, webpackDerivedStaticPath, sendBuildMessage, webpackCompiler, onCompilationDone, wdm, wdmInst, _createWebpackCosmosC, hotReload;
|
|
35
|
+
|
|
36
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
37
|
+
while (1) {
|
|
38
|
+
switch (_context2.prev = _context2.next) {
|
|
39
|
+
case 0:
|
|
40
|
+
sendBuildMessage = function _sendBuildMessage(msg) {
|
|
41
|
+
sendMessage(msg);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
cosmosConfig = _ref.cosmosConfig, expressApp = _ref.expressApp, sendMessage = _ref.sendMessage;
|
|
45
|
+
|
|
46
|
+
if (!cosmosConfig.experimentalRendererUrl) {
|
|
47
|
+
_context2.next = 4;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return _context2.abrupt("return");
|
|
52
|
+
|
|
53
|
+
case 4:
|
|
54
|
+
userWebpack = (0, _shared2.getWebpack)(cosmosConfig.rootDir);
|
|
55
|
+
|
|
56
|
+
if (userWebpack) {
|
|
57
|
+
_context2.next = 7;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return _context2.abrupt("return");
|
|
62
|
+
|
|
63
|
+
case 7:
|
|
64
|
+
_context2.next = 9;
|
|
65
|
+
return (0, _webpackConfig.getDevWebpackConfig)(cosmosConfig, userWebpack);
|
|
66
|
+
|
|
67
|
+
case 9:
|
|
68
|
+
webpackConfig = _context2.sent;
|
|
69
|
+
|
|
70
|
+
// Serve static path derived from devServer.contentBase webpack config
|
|
71
|
+
if (cosmosConfig.staticPath === null) {
|
|
72
|
+
webpackDerivedStaticPath = getWebpackStaticPath(webpackConfig);
|
|
73
|
+
|
|
74
|
+
if (webpackDerivedStaticPath !== null) {
|
|
75
|
+
(0, _static.serveStaticDir)(expressApp, _path.default.resolve(cosmosConfig.rootDir, webpackDerivedStaticPath), cosmosConfig.publicUrl);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
webpackCompiler = userWebpack(webpackConfig);
|
|
80
|
+
webpackCompiler.hooks.invalid.tap('Cosmos', function (filePath) {
|
|
81
|
+
if (typeof filePath === 'string') {
|
|
82
|
+
var relFilePath = _path.default.relative(process.cwd(), filePath);
|
|
83
|
+
|
|
84
|
+
console.log('[Cosmos] webpack build invalidated by', relFilePath);
|
|
85
|
+
} else {
|
|
86
|
+
console.log('[Cosmos] webpack build invalidated by unknown file');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
sendBuildMessage({
|
|
90
|
+
type: 'buildStart'
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
webpackCompiler.hooks.failed.tap('Cosmos', function () {
|
|
94
|
+
sendBuildMessage({
|
|
95
|
+
type: 'buildError'
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
onCompilationDone = new Promise(function (resolve) {
|
|
99
|
+
webpackCompiler.hooks.done.tap('Cosmos', function (stats) {
|
|
100
|
+
resolve();
|
|
101
|
+
|
|
102
|
+
if (stats.hasErrors()) {
|
|
103
|
+
sendBuildMessage({
|
|
104
|
+
type: 'buildError'
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
sendBuildMessage({
|
|
108
|
+
type: 'buildDone'
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
console.log('[Cosmos] Building webpack...'); // Why import WDM here instead of at module level? Because it imports webpack,
|
|
114
|
+
// which might not be installed in the user's codebase. If this were to happen
|
|
115
|
+
// the Cosmos server would crash with a cryptic import error. See import here:
|
|
116
|
+
// https://github.com/webpack/webpack-dev-middleware/blob/eb2e32bab57df11bdfbbac19474eb16817d504fe/lib/fs.js#L8
|
|
117
|
+
// Instead, prior to importing WDM we check if webpack is installed and fail
|
|
118
|
+
// gracefully if not.
|
|
119
|
+
|
|
120
|
+
wdm = require('webpack-dev-middleware');
|
|
121
|
+
wdmInst = wdm(webpackCompiler, {
|
|
122
|
+
// publicPath is the base path for the webpack assets and has to match
|
|
123
|
+
// webpack.output.path
|
|
124
|
+
publicPath: (0, _shared.removeLeadingDot)(cosmosConfig.publicUrl)
|
|
125
|
+
});
|
|
126
|
+
expressApp.use(wdmInst);
|
|
127
|
+
_createWebpackCosmosC = (0, _webpack.createWebpackCosmosConfig)(cosmosConfig), hotReload = _createWebpackCosmosC.hotReload;
|
|
128
|
+
|
|
129
|
+
if (hotReload) {
|
|
130
|
+
expressApp.use((0, _webpackHotMiddleware.default)(webpackCompiler));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
_context2.next = 23;
|
|
134
|
+
return onCompilationDone;
|
|
135
|
+
|
|
136
|
+
case 23:
|
|
137
|
+
return _context2.abrupt("return", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
138
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
139
|
+
while (1) {
|
|
140
|
+
switch (_context.prev = _context.next) {
|
|
141
|
+
case 0:
|
|
142
|
+
_context.next = 2;
|
|
143
|
+
return new Promise(function (res) {
|
|
144
|
+
return wdmInst.close(res);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
case 2:
|
|
148
|
+
case "end":
|
|
149
|
+
return _context.stop();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}, _callee);
|
|
153
|
+
})));
|
|
154
|
+
|
|
155
|
+
case 24:
|
|
156
|
+
case "end":
|
|
157
|
+
return _context2.stop();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}, _callee2);
|
|
161
|
+
}));
|
|
162
|
+
return _webpackDevServer.apply(this, arguments);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function getWebpackStaticPath(_ref2) {
|
|
166
|
+
var devServer = _ref2.devServer;
|
|
167
|
+
return devServer && typeof devServer.contentBase === 'string' ? devServer.contentBase : null;
|
|
168
|
+
}
|