@shuvi/toolpack 0.0.1-rc.9 → 1.0.0-rc.10
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/lib/babel/plugins/auto-css-modules.js +1 -1
- package/lib/babel/plugins/{loadable-plugin.d.ts → dynamic-plugin.d.ts} +1 -1
- package/lib/babel/plugins/{loadable-plugin.js → dynamic-plugin.js} +9 -9
- package/lib/babel/plugins/optimize-hook-destructuring.d.ts +1 -1
- package/lib/babel/plugins/optimize-hook-destructuring.js +4 -4
- package/lib/babel/preset.js +25 -5
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +5 -1
- package/lib/utils/bundle-require.d.ts +33 -0
- package/lib/utils/bundle-require.js +143 -0
- package/lib/utils/forkTsCheckerWebpackPlugin.js +2 -1
- package/lib/utils/formatWebpackMessages.d.ts +18 -4
- package/lib/utils/formatWebpackMessages.js +17 -14
- package/lib/webpack/config/base.d.ts +17 -4
- package/lib/webpack/config/base.js +144 -99
- package/lib/webpack/config/browser.d.ts +3 -4
- package/lib/webpack/config/browser.js +132 -56
- package/lib/webpack/config/index.js +18 -7
- package/lib/webpack/config/node.d.ts +3 -4
- package/lib/webpack/config/node.js +21 -28
- package/lib/webpack/config/parts/external.d.ts +3 -2
- package/lib/webpack/config/parts/external.js +16 -10
- package/lib/webpack/config/parts/helpers.d.ts +3 -1
- package/lib/webpack/config/parts/helpers.js +14 -1
- package/lib/webpack/config/parts/resolve.js +1 -0
- package/lib/webpack/config/parts/style.d.ts +5 -2
- package/lib/webpack/config/parts/style.js +125 -60
- package/lib/webpack/dynamic-dll/bundler/index.d.ts +22 -0
- package/lib/webpack/dynamic-dll/bundler/index.js +211 -0
- package/lib/webpack/dynamic-dll/bundler/webpack-config.d.ts +16 -0
- package/lib/webpack/dynamic-dll/bundler/webpack-config.js +116 -0
- package/lib/webpack/dynamic-dll/constants.d.ts +6 -0
- package/lib/webpack/dynamic-dll/constants.js +9 -0
- package/lib/webpack/dynamic-dll/dep/getCJSExports.d.ts +3 -0
- package/lib/webpack/dynamic-dll/dep/getCJSExports.js +58 -0
- package/lib/webpack/dynamic-dll/dep/getExposeFromContent.d.ts +1 -0
- package/lib/webpack/dynamic-dll/dep/getExposeFromContent.js +80 -0
- package/lib/webpack/dynamic-dll/dep/getModuleExports.d.ts +7 -0
- package/lib/webpack/dynamic-dll/dep/getModuleExports.js +46 -0
- package/lib/webpack/dynamic-dll/dep/index.d.ts +13 -0
- package/lib/webpack/dynamic-dll/dep/index.js +43 -0
- package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.d.ts +1 -0
- package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.js +15 -0
- package/lib/webpack/dynamic-dll/index.d.ts +35 -0
- package/lib/webpack/dynamic-dll/index.js +198 -0
- package/lib/webpack/dynamic-dll/metadata.d.ts +13 -0
- package/lib/webpack/dynamic-dll/metadata.js +62 -0
- package/lib/webpack/dynamic-dll/moduleCollector.d.ts +28 -0
- package/lib/webpack/dynamic-dll/moduleCollector.js +64 -0
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.d.ts +24 -0
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +70 -0
- package/lib/webpack/dynamic-dll/utils.d.ts +6 -0
- package/lib/webpack/dynamic-dll/utils.js +29 -0
- package/lib/webpack/index.d.ts +15 -0
- package/lib/webpack/index.js +110 -0
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +11 -0
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +40 -0
- package/lib/webpack/loaders/parcel-css-loader/index.d.ts +4 -0
- package/lib/webpack/loaders/parcel-css-loader/index.js +369 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/api.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/api.js +85 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.js +23 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.js +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.js +16 -0
- package/lib/webpack/loaders/parcel-css-loader/utils.d.ts +28 -0
- package/lib/webpack/loaders/parcel-css-loader/utils.js +869 -0
- package/lib/webpack/loaders/route-component-loader.js +25 -5
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
- package/lib/webpack/loaders/shuvi-swc-loader/index.d.ts +2 -0
- package/lib/webpack/loaders/shuvi-swc-loader/index.js +119 -0
- package/lib/webpack/plugins/build-manifest-plugin.js +44 -23
- package/lib/webpack/plugins/dynamic-public-path-plugin.d.ts +9 -0
- package/lib/webpack/plugins/dynamic-public-path-plugin.js +50 -0
- package/lib/webpack/plugins/fix-watching-plugin.d.ts +4 -0
- package/lib/webpack/plugins/fix-watching-plugin.js +23 -0
- package/lib/webpack/plugins/jsconfig-paths-plugin.d.ts +44 -0
- package/lib/webpack/plugins/jsconfig-paths-plugin.js +228 -0
- package/lib/webpack/plugins/module-replace-plugin/index.js +5 -1
- package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +7 -6
- package/lib/webpack/plugins/module-replace-plugin/plugin.js +56 -33
- package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +47 -7
- package/lib/webpack/plugins/require-cache-hot-reloader-plugin.js +9 -8
- package/lib/webpack/plugins/support-ts-extension-resolver-plugin.d.ts +4 -0
- package/lib/webpack/plugins/support-ts-extension-resolver-plugin.js +23 -0
- package/lib/webpack/types.d.ts +40 -0
- package/lib/webpack/types.js +2 -0
- package/package.json +46 -40
- package/lib/utils/emptyComponent.d.ts +0 -1
- package/lib/utils/emptyComponent.js +0 -7
- package/lib/utils/errorOverlayMiddleware.d.ts +0 -1
- package/lib/utils/errorOverlayMiddleware.js +0 -21
- package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
- package/lib/utils/hotDevClient/eventsource.js +0 -63
- package/lib/utils/hotDevClient/index.d.ts +0 -4
- package/lib/utils/hotDevClient/index.js +0 -289
- package/lib/utils/verifyTypeScriptSetup.d.ts +0 -5
- package/lib/utils/verifyTypeScriptSetup.js +0 -229
- package/lib/webpack/loaders/export-global-loader.d.ts +0 -7
- package/lib/webpack/loaders/export-global-loader.js +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/toolpack",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -20,63 +20,69 @@
|
|
|
20
20
|
"node": ">= 12.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@babel/
|
|
23
|
+
"@shuvi/compiler": "1.0.0-rc.10",
|
|
24
|
+
"@babel/core": "7.12.10",
|
|
25
|
+
"@babel/plugin-proposal-class-properties": "7.12.1",
|
|
25
26
|
"@babel/plugin-proposal-nullish-coalescing-operator": "7.10.1",
|
|
26
|
-
"@babel/plugin-proposal-numeric-separator": "7.
|
|
27
|
-
"@babel/plugin-proposal-object-rest-spread": "7.
|
|
28
|
-
"@babel/plugin-proposal-optional-chaining": "7.
|
|
27
|
+
"@babel/plugin-proposal-numeric-separator": "7.12.7",
|
|
28
|
+
"@babel/plugin-proposal-object-rest-spread": "7.12.1",
|
|
29
|
+
"@babel/plugin-proposal-optional-chaining": "7.12.7",
|
|
29
30
|
"@babel/plugin-syntax-bigint": "7.8.3",
|
|
30
31
|
"@babel/plugin-syntax-dynamic-import": "7.8.3",
|
|
31
|
-
"@babel/plugin-transform-runtime": "7.10
|
|
32
|
-
"@babel/preset-env": "7.
|
|
32
|
+
"@babel/plugin-transform-runtime": "7.12.10",
|
|
33
|
+
"@babel/preset-env": "7.12.11",
|
|
33
34
|
"@babel/preset-react": "7.10.1",
|
|
34
|
-
"@babel/preset-typescript": "7.
|
|
35
|
-
"@babel/runtime": "7.
|
|
36
|
-
"@
|
|
37
|
-
"@shuvi/
|
|
38
|
-
"@shuvi/utils": "
|
|
39
|
-
"babel-loader": "8.
|
|
35
|
+
"@babel/preset-typescript": "7.12.7",
|
|
36
|
+
"@babel/runtime": "7.12.5",
|
|
37
|
+
"@parcel/css": "1.2.0",
|
|
38
|
+
"@shuvi/shared": "1.0.0-rc.10",
|
|
39
|
+
"@shuvi/utils": "1.0.0-rc.10",
|
|
40
|
+
"babel-loader": "8.2.2",
|
|
40
41
|
"babel-plugin-syntax-jsx": "6.18.0",
|
|
41
42
|
"babel-plugin-transform-define": "2.0.0",
|
|
42
43
|
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
|
|
43
|
-
"
|
|
44
|
+
"browserslist": "4.19.1",
|
|
45
|
+
"buffer": "6.0.3",
|
|
46
|
+
"cross-spawn": "7.0.3",
|
|
44
47
|
"crypto-browserify": "3.12.0",
|
|
45
|
-
"css-loader": "
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
+
"css-loader": "5.0.1",
|
|
49
|
+
"css-minimizer-webpack-plugin": "3.4.1",
|
|
50
|
+
"es-module-lexer": "0.10.5",
|
|
51
|
+
"esbuild": "0.14.38",
|
|
52
|
+
"esbuild-loader": "^2.19.0",
|
|
53
|
+
"file-loader": "6.2.0",
|
|
54
|
+
"fork-ts-checker-webpack-plugin": "6.0.8",
|
|
55
|
+
"fs-extra": "9.0.1",
|
|
48
56
|
"ignore-loader": "0.1.2",
|
|
49
|
-
"launch-editor": "2.2.1",
|
|
50
57
|
"loader-utils": "2.0.0",
|
|
51
|
-
"mini-css-extract-plugin": "
|
|
58
|
+
"mini-css-extract-plugin": "1.3.9",
|
|
59
|
+
"mrmime": "1.0.0",
|
|
52
60
|
"path-browserify": "1.0.1",
|
|
53
|
-
"postcss": "8.
|
|
54
|
-
"postcss-flexbugs-fixes": "
|
|
55
|
-
"postcss-loader": "4.0
|
|
61
|
+
"postcss": "8.4.14",
|
|
62
|
+
"postcss-flexbugs-fixes": "5.0.2",
|
|
63
|
+
"postcss-loader": "4.1.0",
|
|
56
64
|
"postcss-preset-env": "6.7.0",
|
|
57
65
|
"process": "0.11.10",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"sass-loader": "10.0
|
|
66
|
+
"regenerator-runtime": "^0.13.9",
|
|
67
|
+
"@swc/helpers": "0.4.3",
|
|
68
|
+
"sass-loader": "10.1.0",
|
|
61
69
|
"stream-browserify": "3.0.0",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
70
|
+
"style-loader": "2.0.0",
|
|
71
|
+
"terser-webpack-plugin": "5.2.5",
|
|
72
|
+
"typescript": "4.7.4",
|
|
65
73
|
"vm-browserify": "1.1.2",
|
|
66
|
-
"webpack
|
|
74
|
+
"webpack": "5.73.0",
|
|
75
|
+
"webpack-bundle-analyzer": "4.3.0",
|
|
67
76
|
"webpack-chain": "6.5.1",
|
|
68
|
-
"webpack-sources": "2.0
|
|
77
|
+
"webpack-sources": "2.2.0",
|
|
78
|
+
"webpack-virtual-modules": "0.4.3"
|
|
69
79
|
},
|
|
70
80
|
"devDependencies": {
|
|
81
|
+
"@types/babel__core": "^7.1.19",
|
|
82
|
+
"@types/cross-spawn": "6.0.1",
|
|
71
83
|
"@types/loader-utils": "2.0.1",
|
|
72
|
-
"@types/mini-css-extract-plugin": "^
|
|
73
|
-
"@types/terser-webpack-plugin": "4.2.0",
|
|
84
|
+
"@types/mini-css-extract-plugin": "^1.2.2",
|
|
74
85
|
"@types/webpack-bundle-analyzer": "^3.8.0",
|
|
75
|
-
"memfs": "^3.1.2"
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
"peerDependencies": {
|
|
79
|
-
"webpack": "5.3.2"
|
|
80
|
-
},
|
|
81
|
-
"gitHead": "b0c352fb22c6f707e96c786d1d001c0588fc2833"
|
|
86
|
+
"memfs": "^3.1.2"
|
|
87
|
+
}
|
|
82
88
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (): null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createLaunchEditorMiddleware(launchEditorEndpoint: string): (req: any, res: any, next: any) => void;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const launch_editor_1 = __importDefault(require("launch-editor"));
|
|
7
|
-
function createLaunchEditorMiddleware(launchEditorEndpoint) {
|
|
8
|
-
return function launchEditorMiddleware(req, res, next) {
|
|
9
|
-
if (req.url.startsWith(launchEditorEndpoint)) {
|
|
10
|
-
const { query } = req.parsedUrl;
|
|
11
|
-
const lineNumber = parseInt(query.lineNumber, 10) || 1;
|
|
12
|
-
const colNumber = parseInt(query.colNumber, 10) || 1;
|
|
13
|
-
launch_editor_1.default(`${query.fileName}:${lineNumber}:${colNumber}`);
|
|
14
|
-
res.end();
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
next();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
exports.createLaunchEditorMiddleware = createLaunchEditorMiddleware;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function getEventSourceWrapper(options: any): any;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const eventCallbacks = [];
|
|
4
|
-
function EventSourceWrapper(options) {
|
|
5
|
-
var source;
|
|
6
|
-
var lastActivity = new Date();
|
|
7
|
-
var listeners = [];
|
|
8
|
-
if (!options.timeout) {
|
|
9
|
-
options.timeout = 20 * 1000;
|
|
10
|
-
}
|
|
11
|
-
init();
|
|
12
|
-
var timer = setInterval(function () {
|
|
13
|
-
if (new Date() - lastActivity > options.timeout) {
|
|
14
|
-
handleDisconnect();
|
|
15
|
-
}
|
|
16
|
-
}, options.timeout / 2);
|
|
17
|
-
function init() {
|
|
18
|
-
source = new window.EventSource(options.path);
|
|
19
|
-
source.onopen = handleOnline;
|
|
20
|
-
source.onerror = handleDisconnect;
|
|
21
|
-
source.onmessage = handleMessage;
|
|
22
|
-
}
|
|
23
|
-
function handleOnline() {
|
|
24
|
-
if (options.log)
|
|
25
|
-
console.log("[HMR] connected");
|
|
26
|
-
lastActivity = new Date();
|
|
27
|
-
}
|
|
28
|
-
function handleMessage(event) {
|
|
29
|
-
lastActivity = new Date();
|
|
30
|
-
for (var i = 0; i < listeners.length; i++) {
|
|
31
|
-
listeners[i](event);
|
|
32
|
-
}
|
|
33
|
-
if (event.data.indexOf("action") !== -1) {
|
|
34
|
-
eventCallbacks.forEach(cb => cb(event));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function handleDisconnect() {
|
|
38
|
-
clearInterval(timer);
|
|
39
|
-
source.close();
|
|
40
|
-
setTimeout(init, options.timeout);
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
onclose: () => {
|
|
44
|
-
clearTimeout(timer);
|
|
45
|
-
source.close();
|
|
46
|
-
},
|
|
47
|
-
addMessageListener: function (fn) {
|
|
48
|
-
listeners.push(fn);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function getEventSourceWrapper(options) {
|
|
53
|
-
if (!window.__whmEventSourceWrapper) {
|
|
54
|
-
window.__whmEventSourceWrapper = {};
|
|
55
|
-
}
|
|
56
|
-
if (!window.__whmEventSourceWrapper[options.path]) {
|
|
57
|
-
// cache the wrapper for other entries loaded on
|
|
58
|
-
// the same page with the same options.path
|
|
59
|
-
window.__whmEventSourceWrapper[options.path] = EventSourceWrapper(options);
|
|
60
|
-
}
|
|
61
|
-
return window.__whmEventSourceWrapper[options.path];
|
|
62
|
-
}
|
|
63
|
-
exports.getEventSourceWrapper = getEventSourceWrapper;
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
/**
|
|
4
|
-
MIT License
|
|
5
|
-
|
|
6
|
-
Copyright (c) 2013-present, Facebook, Inc.
|
|
7
|
-
|
|
8
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
in the Software without restriction, including without limitation the rights
|
|
11
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
furnished to do so, subject to the following conditions:
|
|
14
|
-
|
|
15
|
-
The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
copies or substantial portions of the Software.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
SOFTWARE.
|
|
25
|
-
*/
|
|
26
|
-
// This file is based on https://github.com/facebook/create-react-app/blob/v1.1.4/packages/react-dev-utils/webpackHotDevClient.js
|
|
27
|
-
// It's been edited to rely on webpack-hot-middleware.
|
|
28
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
38
|
-
if (mod && mod.__esModule) return mod;
|
|
39
|
-
var result = {};
|
|
40
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
41
|
-
result["default"] = mod;
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
const ErrorOverlay = __importStar(require("react-error-overlay"));
|
|
49
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
50
|
-
const formatWebpackMessages_1 = __importDefault(require("../formatWebpackMessages"));
|
|
51
|
-
const eventsource_1 = require("./eventsource");
|
|
52
|
-
// This alternative WebpackDevServer combines the functionality of:
|
|
53
|
-
// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js
|
|
54
|
-
// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js
|
|
55
|
-
// It only supports their simplest configuration (hot updates on same server).
|
|
56
|
-
// It makes some opinionated choices on top, like adding a syntax error overlay
|
|
57
|
-
// that looks similar to our console output. The error overlay is inspired by:
|
|
58
|
-
// https://github.com/glenjamin/webpack-hot-middleware
|
|
59
|
-
// This is a modified version of create-react-app's webpackHotDevClient.js
|
|
60
|
-
// It implements webpack-hot-middleware's EventSource events instead of webpack-dev-server's websocket.
|
|
61
|
-
// https://github.com/facebook/create-react-app/blob/25184c4e91ebabd16fe1cde3d8630830e4a36a01/packages/react-dev-utils/webpackHotDevClient.js
|
|
62
|
-
let hadRuntimeError = false;
|
|
63
|
-
let customHmrEventHandler;
|
|
64
|
-
function connect(options) {
|
|
65
|
-
// Open stack traces in an editor.
|
|
66
|
-
ErrorOverlay.setEditorHandler(function editorHandler({ fileName, lineNumber, colNumber }) {
|
|
67
|
-
// Resolve invalid paths coming from react-error-overlay
|
|
68
|
-
const resolvedFilename = fileName.replace(/^webpack:\/\/[^/]+/ /* webpack://namaspcae/resourcepath */, '');
|
|
69
|
-
fetch(options.launchEditorEndpoint +
|
|
70
|
-
'?fileName=' +
|
|
71
|
-
window.encodeURIComponent(resolvedFilename) +
|
|
72
|
-
'&lineNumber=' +
|
|
73
|
-
window.encodeURIComponent(lineNumber || 1) +
|
|
74
|
-
'&colNumber=' +
|
|
75
|
-
window.encodeURIComponent(colNumber || 1));
|
|
76
|
-
});
|
|
77
|
-
// We need to keep track of if there has been a runtime error.
|
|
78
|
-
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
79
|
-
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
80
|
-
// application. This is handled below when we are notified of a compile (code
|
|
81
|
-
// change).
|
|
82
|
-
// See https://github.com/facebook/create-react-app/issues/3096
|
|
83
|
-
ErrorOverlay.startReportingRuntimeErrors({
|
|
84
|
-
onError: function () {
|
|
85
|
-
hadRuntimeError = true;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
if (module.hot && typeof module.hot.dispose === 'function') {
|
|
89
|
-
module.hot.dispose(function () {
|
|
90
|
-
// TODO: why do we need this?
|
|
91
|
-
ErrorOverlay.stopReportingRuntimeErrors();
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
eventsource_1.getEventSourceWrapper(options).addMessageListener(event => {
|
|
95
|
-
// This is the heartbeat event
|
|
96
|
-
if (event.data === '\uD83D\uDC93') {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
processMessage(event);
|
|
101
|
-
}
|
|
102
|
-
catch (ex) {
|
|
103
|
-
console.warn('Invalid HMR message: ' + event.data + '\n' + ex);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
return {
|
|
107
|
-
subscribeToHmrEvent(handler) {
|
|
108
|
-
customHmrEventHandler = handler;
|
|
109
|
-
},
|
|
110
|
-
reportRuntimeError(err) {
|
|
111
|
-
ErrorOverlay.reportRuntimeError(err);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
exports.default = connect;
|
|
116
|
-
// Remember some state related to hot module replacement.
|
|
117
|
-
var isFirstCompilation = true;
|
|
118
|
-
var mostRecentCompilationHash = null;
|
|
119
|
-
var hasCompileErrors = false;
|
|
120
|
-
function clearOutdatedErrors() {
|
|
121
|
-
// Clean up outdated compile errors, if any.
|
|
122
|
-
if (typeof console !== 'undefined' && typeof console.clear === 'function') {
|
|
123
|
-
if (hasCompileErrors) {
|
|
124
|
-
console.clear();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function afterApplyUpdate(hasUpdates) {
|
|
129
|
-
tryDismissErrorOverlay();
|
|
130
|
-
}
|
|
131
|
-
// Successful compilation.
|
|
132
|
-
function handleSuccess() {
|
|
133
|
-
clearOutdatedErrors();
|
|
134
|
-
const isHotUpdate = !isFirstCompilation;
|
|
135
|
-
isFirstCompilation = false;
|
|
136
|
-
hasCompileErrors = false;
|
|
137
|
-
// Attempt to apply hot updates or reload.
|
|
138
|
-
if (isHotUpdate) {
|
|
139
|
-
tryApplyUpdates(function onHotUpdateSuccess(hasUpdates) {
|
|
140
|
-
// Only dismiss it when we're sure it's a hot update.
|
|
141
|
-
// Otherwise it would flicker right before the reload.
|
|
142
|
-
afterApplyUpdate(hasUpdates);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Compilation with warnings (e.g. ESLint).
|
|
147
|
-
function handleWarnings(warnings) {
|
|
148
|
-
clearOutdatedErrors();
|
|
149
|
-
// Print warnings to the console.
|
|
150
|
-
const formatted = formatWebpackMessages_1.default({
|
|
151
|
-
warnings: warnings,
|
|
152
|
-
errors: []
|
|
153
|
-
});
|
|
154
|
-
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
|
|
155
|
-
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
156
|
-
if (i === 5) {
|
|
157
|
-
console.warn('There were more warnings in other files.\n' +
|
|
158
|
-
'You can find a complete log in the terminal.');
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
console.warn(strip_ansi_1.default(formatted.warnings[i]));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// Compilation with errors (e.g. syntax error or missing modules).
|
|
166
|
-
function handleErrors(errors) {
|
|
167
|
-
clearOutdatedErrors();
|
|
168
|
-
isFirstCompilation = false;
|
|
169
|
-
hasCompileErrors = true;
|
|
170
|
-
// "Massage" webpack messages.
|
|
171
|
-
var formatted = formatWebpackMessages_1.default({
|
|
172
|
-
errors: errors,
|
|
173
|
-
warnings: []
|
|
174
|
-
});
|
|
175
|
-
// Only show the first error.
|
|
176
|
-
ErrorOverlay.reportBuildError(formatted.errors[0]);
|
|
177
|
-
// Also log them to the console.
|
|
178
|
-
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
|
179
|
-
for (var i = 0; i < formatted.errors.length; i++) {
|
|
180
|
-
console.error(strip_ansi_1.default(formatted.errors[i]));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
function tryDismissErrorOverlay() {
|
|
185
|
-
if (!hasCompileErrors) {
|
|
186
|
-
ErrorOverlay.dismissBuildError();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
// There is a newer version of the code available.
|
|
190
|
-
function handleAvailableHash(hash) {
|
|
191
|
-
// Update last known compilation hash.
|
|
192
|
-
mostRecentCompilationHash = hash;
|
|
193
|
-
}
|
|
194
|
-
// Handle messages from the server.
|
|
195
|
-
function processMessage(e) {
|
|
196
|
-
const obj = JSON.parse(e.data);
|
|
197
|
-
switch (obj.action) {
|
|
198
|
-
case 'building': {
|
|
199
|
-
console.log('[HMR] bundle ' + (obj.name ? "'" + obj.name + "' " : '') + 'rebuilding');
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
case 'built':
|
|
203
|
-
case 'sync': {
|
|
204
|
-
if (obj.hash) {
|
|
205
|
-
handleAvailableHash(obj.hash);
|
|
206
|
-
}
|
|
207
|
-
const { errors, warnings } = obj;
|
|
208
|
-
const hasErrors = Boolean(errors && errors.length);
|
|
209
|
-
if (hasErrors) {
|
|
210
|
-
return handleErrors(errors);
|
|
211
|
-
}
|
|
212
|
-
const hasWarnings = Boolean(warnings && warnings.length);
|
|
213
|
-
if (hasWarnings) {
|
|
214
|
-
return handleWarnings(warnings);
|
|
215
|
-
}
|
|
216
|
-
handleSuccess();
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
case 'warnings':
|
|
220
|
-
handleWarnings(obj.data);
|
|
221
|
-
break;
|
|
222
|
-
case 'errors':
|
|
223
|
-
handleErrors(obj.data);
|
|
224
|
-
break;
|
|
225
|
-
default: {
|
|
226
|
-
if (customHmrEventHandler) {
|
|
227
|
-
customHmrEventHandler(obj);
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
// Is there a newer version of this code available?
|
|
235
|
-
function isUpdateAvailable() {
|
|
236
|
-
/* globals __webpack_hash__ */
|
|
237
|
-
// __webpack_hash__ is the hash of the current compilation.
|
|
238
|
-
// It's a global variable injected by Webpack.
|
|
239
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
240
|
-
}
|
|
241
|
-
// Webpack disallows updates in other states.
|
|
242
|
-
function canApplyUpdates() {
|
|
243
|
-
return module.hot.status() === 'idle';
|
|
244
|
-
}
|
|
245
|
-
// Attempt to update code on the fly, fall back to a hard reload.
|
|
246
|
-
function tryApplyUpdates(onHotUpdateSuccess) {
|
|
247
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
-
if (!module.hot) {
|
|
249
|
-
// HotModuleReplacementPlugin is not in Webpack configuration.
|
|
250
|
-
console.error('HotModuleReplacementPlugin is not in Webpack configuration.');
|
|
251
|
-
// window.location.reload();
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
255
|
-
ErrorOverlay.dismissBuildError();
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
259
|
-
const needForcedReload = err || !updatedModules || hadRuntimeError;
|
|
260
|
-
if (needForcedReload) {
|
|
261
|
-
if (err) {
|
|
262
|
-
console.warn('Error while applying updates, reloading page', err);
|
|
263
|
-
}
|
|
264
|
-
if (hadRuntimeError) {
|
|
265
|
-
console.warn('Had runtime error previously, reloading page');
|
|
266
|
-
}
|
|
267
|
-
window.location.reload();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const hasUpdates = Boolean(updatedModules.length);
|
|
271
|
-
if (typeof onHotUpdateSuccess === 'function') {
|
|
272
|
-
// Maybe we want to do something.
|
|
273
|
-
onHotUpdateSuccess(hasUpdates);
|
|
274
|
-
}
|
|
275
|
-
if (isUpdateAvailable()) {
|
|
276
|
-
// While we were updating, there was a new update! Do it again.
|
|
277
|
-
tryApplyUpdates();
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
// https://webpack.github.io/docs/hot-module-replacement.html#check
|
|
281
|
-
try {
|
|
282
|
-
const updatedModules = yield module.hot.check(/* autoApply */ true);
|
|
283
|
-
handleApplyUpdates(null, updatedModules);
|
|
284
|
-
}
|
|
285
|
-
catch (err) {
|
|
286
|
-
handleApplyUpdates(err, null);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|