@ohos-ports/rsbuild-core 1.7.2-beta.1
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 +27 -0
- package/bin/rsbuild.js +20 -0
- package/compiled/@jridgewell/remapping/index.d.ts +1 -0
- package/compiled/@jridgewell/remapping/index.js +1222 -0
- package/compiled/@jridgewell/remapping/license +19 -0
- package/compiled/@jridgewell/remapping/package.json +1 -0
- package/compiled/@jridgewell/trace-mapping/index.d.ts +194 -0
- package/compiled/@jridgewell/trace-mapping/index.js +1408 -0
- package/compiled/@jridgewell/trace-mapping/license +19 -0
- package/compiled/@jridgewell/trace-mapping/package.json +1 -0
- package/compiled/chokidar/index.d.ts +384 -0
- package/compiled/chokidar/index.js +1793 -0
- package/compiled/chokidar/license +21 -0
- package/compiled/chokidar/package.json +1 -0
- package/compiled/connect/index.d.ts +90 -0
- package/compiled/connect/index.js +1240 -0
- package/compiled/connect/license +25 -0
- package/compiled/connect/package.json +1 -0
- package/compiled/cors/index.d.ts +56 -0
- package/compiled/cors/index.js +371 -0
- package/compiled/cors/license +22 -0
- package/compiled/cors/package.json +1 -0
- package/compiled/css-loader/api.js +85 -0
- package/compiled/css-loader/getUrl.js +26 -0
- package/compiled/css-loader/index.d.ts +1 -0
- package/compiled/css-loader/index.js +2 -0
- package/compiled/css-loader/license +20 -0
- package/compiled/css-loader/noSourceMaps.js +5 -0
- package/compiled/css-loader/package.json +1 -0
- package/compiled/css-loader/sourceMaps.js +16 -0
- package/compiled/html-rspack-plugin/default_index.ejs +9 -0
- package/compiled/html-rspack-plugin/index.d.ts +290 -0
- package/compiled/html-rspack-plugin/index.js +1602 -0
- package/compiled/html-rspack-plugin/license +20 -0
- package/compiled/html-rspack-plugin/loader.js +166 -0
- package/compiled/html-rspack-plugin/package.json +1 -0
- package/compiled/http-proxy-middleware/index.d.ts +319 -0
- package/compiled/http-proxy-middleware/index.js +5284 -0
- package/compiled/http-proxy-middleware/license +22 -0
- package/compiled/http-proxy-middleware/package.json +1 -0
- package/compiled/launch-editor-middleware/index.d.ts +1 -0
- package/compiled/launch-editor-middleware/index.js +719 -0
- package/compiled/launch-editor-middleware/license +21 -0
- package/compiled/launch-editor-middleware/package.json +1 -0
- package/compiled/memfs/index.d.ts +1462 -0
- package/compiled/memfs/index.js +1 -0
- package/compiled/memfs/license +201 -0
- package/compiled/memfs/package.json +1 -0
- package/compiled/mrmime/index.d.ts +4 -0
- package/compiled/mrmime/index.js +456 -0
- package/compiled/mrmime/package.json +1 -0
- package/compiled/picocolors/index.d.ts +55 -0
- package/compiled/picocolors/index.js +108 -0
- package/compiled/picocolors/license +15 -0
- package/compiled/picocolors/package.json +1 -0
- package/compiled/postcss/index.js +1 -0
- package/compiled/postcss/lib/at-rule.d.ts +140 -0
- package/compiled/postcss/lib/comment.d.ts +68 -0
- package/compiled/postcss/lib/container.d.ts +483 -0
- package/compiled/postcss/lib/css-syntax-error.d.ts +248 -0
- package/compiled/postcss/lib/declaration.d.ts +151 -0
- package/compiled/postcss/lib/document.d.ts +69 -0
- package/compiled/postcss/lib/fromJSON.d.ts +9 -0
- package/compiled/postcss/lib/input.d.ts +227 -0
- package/compiled/postcss/lib/lazy-result.d.ts +190 -0
- package/compiled/postcss/lib/list.d.ts +60 -0
- package/compiled/postcss/lib/no-work-result.d.ts +46 -0
- package/compiled/postcss/lib/node.d.ts +556 -0
- package/compiled/postcss/lib/parse.d.ts +9 -0
- package/compiled/postcss/lib/postcss.d.ts +458 -0
- package/compiled/postcss/lib/previous-map.d.ts +81 -0
- package/compiled/postcss/lib/processor.d.ts +115 -0
- package/compiled/postcss/lib/result.d.ts +205 -0
- package/compiled/postcss/lib/root.d.ts +87 -0
- package/compiled/postcss/lib/rule.d.ts +126 -0
- package/compiled/postcss/lib/source-map-js.d.ts +4 -0
- package/compiled/postcss/lib/stringifier.d.ts +46 -0
- package/compiled/postcss/lib/stringify.d.ts +9 -0
- package/compiled/postcss/lib/warning.d.ts +147 -0
- package/compiled/postcss/license +20 -0
- package/compiled/postcss/package.json +1 -0
- package/compiled/postcss-loader/index.d.ts +1 -0
- package/compiled/postcss-loader/index.js +720 -0
- package/compiled/postcss-loader/license +20 -0
- package/compiled/postcss-loader/package.json +1 -0
- package/compiled/rslog/index.d.ts +67 -0
- package/compiled/rslog/license +21 -0
- package/compiled/rslog/package.json +1 -0
- package/compiled/rspack-chain/license +22 -0
- package/compiled/rspack-chain/package.json +1 -0
- package/compiled/rspack-chain/types/index.d.ts +545 -0
- package/compiled/rspack-manifest-plugin/index.d.ts +48 -0
- package/compiled/rspack-manifest-plugin/index.js +409 -0
- package/compiled/rspack-manifest-plugin/license +21 -0
- package/compiled/rspack-manifest-plugin/package.json +1 -0
- package/compiled/sirv/index.d.ts +1 -0
- package/compiled/sirv/index.js +274 -0
- package/compiled/sirv/package.json +1 -0
- package/compiled/style-loader/index.d.ts +1 -0
- package/compiled/style-loader/index.js +427 -0
- package/compiled/style-loader/license +20 -0
- package/compiled/style-loader/package.json +1 -0
- package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
- package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
- package/compiled/style-loader/runtime/insertBySelector.js +34 -0
- package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
- package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
- package/compiled/style-loader/runtime/isOldIE.js +17 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
- package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
- package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
- package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
- package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
- package/compiled/tinyglobby/index.d.ts +46 -0
- package/compiled/tinyglobby/index.js +2664 -0
- package/compiled/tinyglobby/license +21 -0
- package/compiled/tinyglobby/package.json +1 -0
- package/compiled/webpack-bundle-analyzer/index.d.ts +160 -0
- package/compiled/webpack-bundle-analyzer/index.js +23 -0
- package/compiled/webpack-bundle-analyzer/license +20 -0
- package/compiled/webpack-bundle-analyzer/package.json +1 -0
- package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
- package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
- package/compiled/webpack-merge/index.d.ts +31 -0
- package/compiled/webpack-merge/index.js +1200 -0
- package/compiled/webpack-merge/license +20 -0
- package/compiled/webpack-merge/package.json +1 -0
- package/compiled/ws/index.d.ts +437 -0
- package/compiled/ws/index.js +3161 -0
- package/compiled/ws/license +20 -0
- package/compiled/ws/package.json +1 -0
- package/dist/0~open.js +427 -0
- package/dist/0~range-parser.js +49 -0
- package/dist/0~range-parser.js.LICENSE.txt +6 -0
- package/dist/131.js +9305 -0
- package/dist/131.js.LICENSE.txt +26 -0
- package/dist/136.mjs +42 -0
- package/dist/2~open.cjs +436 -0
- package/dist/2~range-parser.cjs +52 -0
- package/dist/2~range-parser.cjs.LICENSE.txt +6 -0
- package/dist/client/59.js +22 -0
- package/dist/client/hmr.js +206 -0
- package/dist/client/overlay.js +203 -0
- package/dist/ignoreCssLoader.mjs +3 -0
- package/dist/index.cjs +9456 -0
- package/dist/index.cjs.LICENSE.txt +26 -0
- package/dist/index.js +1 -0
- package/dist/rslib-runtime.js +44 -0
- package/dist/transformLoader.mjs +1 -0
- package/dist/transformRawLoader.mjs +4 -0
- package/dist-types/cli/commands.d.ts +28 -0
- package/dist-types/cli/index.d.ts +1 -0
- package/dist-types/cli/init.d.ts +7 -0
- package/dist-types/client/hmr.d.ts +3 -0
- package/dist-types/client/log.d.ts +13 -0
- package/dist-types/client/overlay.d.ts +1 -0
- package/dist-types/configChain.d.ts +154 -0
- package/dist-types/constants.d.ts +52 -0
- package/dist-types/createContext.d.ts +11 -0
- package/dist-types/createRsbuild.d.ts +5 -0
- package/dist-types/defaultConfig.d.ts +25 -0
- package/dist-types/helpers/compiler.d.ts +5 -0
- package/dist-types/helpers/exitHook.d.ts +3 -0
- package/dist-types/helpers/format.d.ts +2 -0
- package/dist-types/helpers/fs.d.ts +17 -0
- package/dist-types/helpers/index.d.ts +29 -0
- package/dist-types/helpers/path.d.ts +26 -0
- package/dist-types/helpers/stats.d.ts +18 -0
- package/dist-types/helpers/url.d.ts +11 -0
- package/dist-types/helpers/vendors.d.ts +29 -0
- package/dist-types/helpers/version.d.ts +7 -0
- package/dist-types/hooks.d.ts +44 -0
- package/dist-types/index.d.ts +22 -0
- package/dist-types/initPlugins.d.ts +6 -0
- package/dist-types/inspectConfig.d.ts +35 -0
- package/dist-types/loadConfig.d.ts +60 -0
- package/dist-types/loadEnv.d.ts +63 -0
- package/dist-types/loader/ignoreCssLoader.d.ts +3 -0
- package/dist-types/loader/transformLoader.d.ts +8 -0
- package/dist-types/loader/transformRawLoader.d.ts +3 -0
- package/dist-types/logger.d.ts +19 -0
- package/dist-types/mergeConfig.d.ts +2 -0
- package/dist-types/package.json +1 -0
- package/dist-types/pluginHelper.d.ts +12 -0
- package/dist-types/pluginManager.d.ts +21 -0
- package/dist-types/plugins/appIcon.d.ts +2 -0
- package/dist-types/plugins/asset.d.ts +3 -0
- package/dist-types/plugins/basic.d.ts +5 -0
- package/dist-types/plugins/bundleAnalyzer.d.ts +2 -0
- package/dist-types/plugins/cache.d.ts +2 -0
- package/dist-types/plugins/cleanOutput.d.ts +2 -0
- package/dist-types/plugins/css.d.ts +4 -0
- package/dist-types/plugins/define.d.ts +2 -0
- package/dist-types/plugins/entry.d.ts +2 -0
- package/dist-types/plugins/esm.d.ts +2 -0
- package/dist-types/plugins/externals.d.ts +2 -0
- package/dist-types/plugins/fileSize.d.ts +6 -0
- package/dist-types/plugins/html.d.ts +9 -0
- package/dist-types/plugins/inlineChunk.d.ts +6 -0
- package/dist-types/plugins/lazyCompilation.d.ts +2 -0
- package/dist-types/plugins/manifest.d.ts +2 -0
- package/dist-types/plugins/minimize.d.ts +10 -0
- package/dist-types/plugins/moduleFederation.d.ts +2 -0
- package/dist-types/plugins/moment.d.ts +2 -0
- package/dist-types/plugins/nodeAddons.d.ts +2 -0
- package/dist-types/plugins/nonce.d.ts +2 -0
- package/dist-types/plugins/output.d.ts +2 -0
- package/dist-types/plugins/performance.d.ts +5 -0
- package/dist-types/plugins/progress.d.ts +2 -0
- package/dist-types/plugins/resolve.d.ts +2 -0
- package/dist-types/plugins/resourceHints.d.ts +2 -0
- package/dist-types/plugins/rsdoctor.d.ts +2 -0
- package/dist-types/plugins/rspackProfile.d.ts +2 -0
- package/dist-types/plugins/server.d.ts +2 -0
- package/dist-types/plugins/sourceMap.d.ts +2 -0
- package/dist-types/plugins/splitChunks.d.ts +4 -0
- package/dist-types/plugins/sri.d.ts +2 -0
- package/dist-types/plugins/swc.d.ts +5 -0
- package/dist-types/plugins/target.d.ts +2 -0
- package/dist-types/plugins/wasm.d.ts +2 -0
- package/dist-types/provider/build.d.ts +4 -0
- package/dist-types/provider/createCompiler.d.ts +6 -0
- package/dist-types/provider/helpers.d.ts +12 -0
- package/dist-types/provider/initConfigs.d.ts +19 -0
- package/dist-types/provider/provider.d.ts +2 -0
- package/dist-types/provider/rspackConfig.d.ts +8 -0
- package/dist-types/restart.d.ts +18 -0
- package/dist-types/rspack-plugins/RsbuildHtmlPlugin.d.ts +38 -0
- package/dist-types/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +32 -0
- package/dist-types/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +28 -0
- package/dist-types/rspack-plugins/resource-hints/extractChunks.d.ts +23 -0
- package/dist-types/rspack-plugins/resource-hints/getResourceType.d.ts +22 -0
- package/dist-types/rspack.d.ts +2 -0
- package/dist-types/server/ansiHTML.d.ts +4 -0
- package/dist-types/server/assets-middleware/getFileFromUrl.d.ts +12 -0
- package/dist-types/server/assets-middleware/index.d.ts +37 -0
- package/dist-types/server/assets-middleware/middleware.d.ts +2 -0
- package/dist-types/server/assets-middleware/parseTokenList.d.ts +1 -0
- package/dist-types/server/assets-middleware/setupOutputFileSystem.d.ts +3 -0
- package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +15 -0
- package/dist-types/server/browserLogs.d.ts +9 -0
- package/dist-types/server/buildManager.d.ts +33 -0
- package/dist-types/server/cliShortcuts.d.ts +10 -0
- package/dist-types/server/devMiddlewares.d.ts +21 -0
- package/dist-types/server/devServer.d.ts +79 -0
- package/dist-types/server/environment.d.ts +8 -0
- package/dist-types/server/gracefulShutdown.d.ts +10 -0
- package/dist-types/server/gzipMiddleware.d.ts +2 -0
- package/dist-types/server/helper.d.ts +91 -0
- package/dist-types/server/historyApiFallback.d.ts +2 -0
- package/dist-types/server/hmrFallback.d.ts +1 -0
- package/dist-types/server/httpServer.d.ts +7 -0
- package/dist-types/server/middlewares.d.ts +33 -0
- package/dist-types/server/open.d.ts +10 -0
- package/dist-types/server/overlay.d.ts +3 -0
- package/dist-types/server/prodServer.d.ts +24 -0
- package/dist-types/server/proxy.d.ts +6 -0
- package/dist-types/server/runner/asModule.d.ts +2 -0
- package/dist-types/server/runner/basic.d.ts +29 -0
- package/dist-types/server/runner/cjs.d.ts +10 -0
- package/dist-types/server/runner/esm.d.ts +6 -0
- package/dist-types/server/runner/index.d.ts +4 -0
- package/dist-types/server/runner/type.d.ts +42 -0
- package/dist-types/server/socketServer.d.ts +81 -0
- package/dist-types/server/watchFiles.d.ts +14 -0
- package/dist-types/types/config.d.ts +1882 -0
- package/dist-types/types/context.d.ts +110 -0
- package/dist-types/types/hooks.d.ts +275 -0
- package/dist-types/types/index.d.ts +8 -0
- package/dist-types/types/plugin.d.ts +585 -0
- package/dist-types/types/rsbuild.d.ts +286 -0
- package/dist-types/types/rspack.d.ts +16 -0
- package/dist-types/types/thirdParty.d.ts +186 -0
- package/dist-types/types/utils.d.ts +19 -0
- package/package.json +114 -0
- package/static/openChrome.applescript +95 -0
- package/types.d.ts +349 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { logger } from "./59.js";
|
|
2
|
+
let createOverlay;
|
|
3
|
+
let clearOverlay;
|
|
4
|
+
const registerOverlay = (createFn, clearFn)=>{
|
|
5
|
+
createOverlay = createFn;
|
|
6
|
+
clearOverlay = clearFn;
|
|
7
|
+
};
|
|
8
|
+
function init(token, config, serverHost, serverPort, liveReload, browserLogs, logLevel) {
|
|
9
|
+
logger.level = logLevel;
|
|
10
|
+
const queuedMessages = [];
|
|
11
|
+
const clientErrors = [];
|
|
12
|
+
let lastHash;
|
|
13
|
+
let hasBuildErrors = false;
|
|
14
|
+
function formatURL(fallback) {
|
|
15
|
+
const { location } = self;
|
|
16
|
+
const hostname = (fallback ? serverHost : config.host) || location.hostname;
|
|
17
|
+
const port = (fallback ? serverPort : config.port) || location.port;
|
|
18
|
+
const protocol = config.protocol || ('https:' === location.protocol ? 'wss' : 'ws');
|
|
19
|
+
const pathname = config.path;
|
|
20
|
+
if ("u" > typeof URL) {
|
|
21
|
+
const url = new URL('http://localhost');
|
|
22
|
+
url.port = String(port);
|
|
23
|
+
url.hostname = hostname;
|
|
24
|
+
url.protocol = protocol;
|
|
25
|
+
url.pathname = pathname;
|
|
26
|
+
url.searchParams.append('token', token);
|
|
27
|
+
return url.toString();
|
|
28
|
+
}
|
|
29
|
+
const colon = -1 === protocol.indexOf(':') ? ':' : '';
|
|
30
|
+
return `${protocol}${colon}//${hostname}:${port}${pathname}?token=${token}`;
|
|
31
|
+
}
|
|
32
|
+
function clearBuildErrors() {
|
|
33
|
+
if (console.clear && hasBuildErrors) console.clear();
|
|
34
|
+
hasBuildErrors = false;
|
|
35
|
+
}
|
|
36
|
+
function handleSuccess() {
|
|
37
|
+
clearBuildErrors();
|
|
38
|
+
tryApplyUpdates();
|
|
39
|
+
}
|
|
40
|
+
function handleWarnings({ text }) {
|
|
41
|
+
clearBuildErrors();
|
|
42
|
+
for(let i = 0; i < text.length; i++){
|
|
43
|
+
if (5 === i) {
|
|
44
|
+
logger.warn('[rsbuild] Additional warnings detected. View complete log in terminal for details.');
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
logger.warn(text[i]);
|
|
48
|
+
}
|
|
49
|
+
tryApplyUpdates();
|
|
50
|
+
}
|
|
51
|
+
function handleErrors({ text, html }) {
|
|
52
|
+
clearBuildErrors();
|
|
53
|
+
hasBuildErrors = true;
|
|
54
|
+
for (const error of text)logger.error(error);
|
|
55
|
+
if (createOverlay) createOverlay('Build failed', html);
|
|
56
|
+
}
|
|
57
|
+
function handleResolvedClientError({ id, message }) {
|
|
58
|
+
if (!createOverlay || hasBuildErrors) return;
|
|
59
|
+
for (const item of clientErrors)if (item.id === id) item.message = message;
|
|
60
|
+
createOverlay('Runtime errors', clientErrors.map((item)=>item.message).filter(Boolean).join('\n\n'));
|
|
61
|
+
}
|
|
62
|
+
const shouldUpdate = ()=>lastHash !== __webpack_hash__;
|
|
63
|
+
const handleApplyUpdates = (err, updatedModules)=>{
|
|
64
|
+
const forcedReload = err || !updatedModules;
|
|
65
|
+
if (forcedReload) {
|
|
66
|
+
if (err) logger.error('[rsbuild] HMR update failed, performing full reload:', err);
|
|
67
|
+
reloadPage();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
tryApplyUpdates();
|
|
71
|
+
};
|
|
72
|
+
function tryApplyUpdates() {
|
|
73
|
+
if (!shouldUpdate()) return;
|
|
74
|
+
if (import.meta.webpackHot) {
|
|
75
|
+
if ('idle' !== import.meta.webpackHot.status()) return;
|
|
76
|
+
import.meta.webpackHot.check(true).then((updatedModules)=>{
|
|
77
|
+
handleApplyUpdates(null, updatedModules);
|
|
78
|
+
}, (err)=>{
|
|
79
|
+
handleApplyUpdates(err, null);
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
reloadPage();
|
|
84
|
+
}
|
|
85
|
+
let socket = null;
|
|
86
|
+
let reconnectCount = 0;
|
|
87
|
+
let pingIntervalId;
|
|
88
|
+
const isSocketReady = ()=>socket && socket.readyState === socket.OPEN;
|
|
89
|
+
const socketSend = (data)=>{
|
|
90
|
+
if (isSocketReady()) socket.send(JSON.stringify(data));
|
|
91
|
+
};
|
|
92
|
+
function onOpen() {
|
|
93
|
+
logger.info('[rsbuild] WebSocket connected.');
|
|
94
|
+
reconnectCount = 0;
|
|
95
|
+
pingIntervalId = setInterval(()=>{
|
|
96
|
+
socketSend({
|
|
97
|
+
type: 'ping'
|
|
98
|
+
});
|
|
99
|
+
}, 30000);
|
|
100
|
+
if (queuedMessages.length) {
|
|
101
|
+
queuedMessages.forEach(socketSend);
|
|
102
|
+
queuedMessages.length = 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function onMessage(e) {
|
|
106
|
+
const message = JSON.parse(e.data);
|
|
107
|
+
switch(message.type){
|
|
108
|
+
case 'hash':
|
|
109
|
+
lastHash = message.data;
|
|
110
|
+
if (clearOverlay && shouldUpdate()) clearOverlay();
|
|
111
|
+
break;
|
|
112
|
+
case 'ok':
|
|
113
|
+
handleSuccess();
|
|
114
|
+
break;
|
|
115
|
+
case 'static-changed':
|
|
116
|
+
case 'content-changed':
|
|
117
|
+
reloadPage();
|
|
118
|
+
break;
|
|
119
|
+
case 'warnings':
|
|
120
|
+
handleWarnings(message.data);
|
|
121
|
+
break;
|
|
122
|
+
case 'errors':
|
|
123
|
+
handleErrors(message.data);
|
|
124
|
+
break;
|
|
125
|
+
case 'resolved-client-error':
|
|
126
|
+
handleResolvedClientError(message.data);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function onClose() {
|
|
131
|
+
if (reconnectCount >= config.reconnect) {
|
|
132
|
+
if (config.reconnect > 0) logger.warn('[rsbuild] WebSocket connection failed after maximum retry attempts.');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (0 === reconnectCount) logger.info('[rsbuild] WebSocket connection lost. Reconnecting...');
|
|
136
|
+
removeListeners();
|
|
137
|
+
socket = null;
|
|
138
|
+
reconnectCount++;
|
|
139
|
+
setTimeout(connect, 1000 * 1.5 ** reconnectCount);
|
|
140
|
+
}
|
|
141
|
+
function onSocketError() {
|
|
142
|
+
if (formatURL() !== formatURL(true)) {
|
|
143
|
+
logger.error('[rsbuild] WebSocket connection failed. Trying direct connection fallback.');
|
|
144
|
+
removeListeners();
|
|
145
|
+
socket = null;
|
|
146
|
+
connect(true);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function sendError(message, stack) {
|
|
150
|
+
const id = `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
151
|
+
const messageInfo = {
|
|
152
|
+
type: 'client-error',
|
|
153
|
+
id,
|
|
154
|
+
message,
|
|
155
|
+
stack
|
|
156
|
+
};
|
|
157
|
+
clientErrors.push({
|
|
158
|
+
id
|
|
159
|
+
});
|
|
160
|
+
if (isSocketReady()) socketSend(messageInfo);
|
|
161
|
+
else queuedMessages.push(messageInfo);
|
|
162
|
+
}
|
|
163
|
+
function onUnhandledRejection({ reason }) {
|
|
164
|
+
let message;
|
|
165
|
+
let stack;
|
|
166
|
+
if (reason instanceof Error) {
|
|
167
|
+
message = reason.name ? `${reason.name}: ${reason.message}` : reason.message;
|
|
168
|
+
stack = reason.stack;
|
|
169
|
+
} else if ('string' == typeof reason) message = reason;
|
|
170
|
+
else try {
|
|
171
|
+
message = JSON.stringify(reason);
|
|
172
|
+
} catch (_) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
sendError(`Uncaught (in promise) ${message}`, stack);
|
|
176
|
+
}
|
|
177
|
+
function connect(fallback = false) {
|
|
178
|
+
if (0 === reconnectCount) logger.info('[rsbuild] WebSocket connecting...');
|
|
179
|
+
const socketUrl = formatURL(fallback);
|
|
180
|
+
socket = new WebSocket(socketUrl);
|
|
181
|
+
socket.addEventListener('open', onOpen);
|
|
182
|
+
socket.addEventListener('close', onClose);
|
|
183
|
+
socket.addEventListener('message', onMessage);
|
|
184
|
+
if (!fallback) socket.addEventListener('error', onSocketError);
|
|
185
|
+
}
|
|
186
|
+
function removeListeners() {
|
|
187
|
+
clearInterval(pingIntervalId);
|
|
188
|
+
if (socket) {
|
|
189
|
+
socket.removeEventListener('open', onOpen);
|
|
190
|
+
socket.removeEventListener('close', onClose);
|
|
191
|
+
socket.removeEventListener('message', onMessage);
|
|
192
|
+
socket.removeEventListener('error', onSocketError);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function reloadPage() {
|
|
196
|
+
if (liveReload) window.location.reload();
|
|
197
|
+
}
|
|
198
|
+
if (browserLogs && "u" > typeof window) {
|
|
199
|
+
window.addEventListener('error', ({ message, error })=>{
|
|
200
|
+
sendError(message, error instanceof Error ? error.stack : void 0);
|
|
201
|
+
});
|
|
202
|
+
window.addEventListener('unhandledrejection', onUnhandledRejection);
|
|
203
|
+
}
|
|
204
|
+
connect();
|
|
205
|
+
}
|
|
206
|
+
export { init, registerOverlay };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { registerOverlay } from "./hmr.js";
|
|
2
|
+
import { logger } from "./59.js";
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
5
|
+
value: value,
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
else obj[key] = value;
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
const { HTMLElement: HTMLElement = class {
|
|
14
|
+
}, customElements: customElements } = "u" > typeof window ? window : globalThis;
|
|
15
|
+
class ErrorOverlay extends HTMLElement {
|
|
16
|
+
constructor(html){
|
|
17
|
+
var _root_querySelector, _root_querySelector1;
|
|
18
|
+
super(), _define_property(this, "close", (immediate = false)=>{
|
|
19
|
+
const remove = ()=>{
|
|
20
|
+
var _this_parentNode;
|
|
21
|
+
return null == (_this_parentNode = this.parentNode) ? void 0 : _this_parentNode.removeChild(this);
|
|
22
|
+
};
|
|
23
|
+
if (this.animate && true !== immediate) this.animate([
|
|
24
|
+
{
|
|
25
|
+
opacity: 1
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
opacity: 0
|
|
29
|
+
}
|
|
30
|
+
], {
|
|
31
|
+
duration: 300,
|
|
32
|
+
easing: 'ease-out'
|
|
33
|
+
}).addEventListener('finish', remove);
|
|
34
|
+
else remove();
|
|
35
|
+
});
|
|
36
|
+
if (!this.attachShadow) return void logger.warn('[rsbuild] Error overlay disabled: Shadow DOM not supported in this browser.');
|
|
37
|
+
const root = this.attachShadow({
|
|
38
|
+
mode: 'open'
|
|
39
|
+
});
|
|
40
|
+
root.innerHTML = html;
|
|
41
|
+
null == (_root_querySelector = root.querySelector('.close')) || _root_querySelector.addEventListener('click', this.close);
|
|
42
|
+
this.addEventListener('click', this.close);
|
|
43
|
+
null == (_root_querySelector1 = root.querySelector('.container')) || _root_querySelector1.addEventListener('click', (e)=>{
|
|
44
|
+
if (e.target) {
|
|
45
|
+
const { file } = e.target.dataset;
|
|
46
|
+
if (file) fetch(`/__open-in-editor?file=${encodeURIComponent(file)}`);
|
|
47
|
+
}
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
});
|
|
50
|
+
const onEscKeydown = (e)=>{
|
|
51
|
+
if ('Escape' === e.key || 'Escape' === e.code) this.close();
|
|
52
|
+
document.removeEventListener('keydown', onEscKeydown);
|
|
53
|
+
};
|
|
54
|
+
document.addEventListener('keydown', onEscKeydown);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const overlayId = 'rsbuild-error-overlay';
|
|
58
|
+
if (customElements && !customElements.get(overlayId)) customElements.define(overlayId, ErrorOverlay);
|
|
59
|
+
function getOverlayHtml(title, content) {
|
|
60
|
+
return `
|
|
61
|
+
<style>
|
|
62
|
+
.root {
|
|
63
|
+
position: fixed;
|
|
64
|
+
z-index: 9999;
|
|
65
|
+
top: 0;
|
|
66
|
+
left: 0;
|
|
67
|
+
width: 100%;
|
|
68
|
+
height: 100%;
|
|
69
|
+
overflow-y: scroll;
|
|
70
|
+
margin: 0;
|
|
71
|
+
background: rgba(0, 0, 0, 0.66);
|
|
72
|
+
cursor: pointer;
|
|
73
|
+
}
|
|
74
|
+
.container {
|
|
75
|
+
font-family: Menlo, Consolas, monospace;
|
|
76
|
+
line-height: 1.6;
|
|
77
|
+
width: 960px;
|
|
78
|
+
max-width: 85%;
|
|
79
|
+
color: #d8d8d8;
|
|
80
|
+
margin: 32px auto;
|
|
81
|
+
padding: 32px 40px;
|
|
82
|
+
position: relative;
|
|
83
|
+
background: #181818;
|
|
84
|
+
border-radius: 24px;
|
|
85
|
+
box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
|
|
86
|
+
overflow: hidden;
|
|
87
|
+
direction: ltr;
|
|
88
|
+
text-align: left;
|
|
89
|
+
box-sizing: border-box;
|
|
90
|
+
cursor: default;
|
|
91
|
+
}
|
|
92
|
+
.title {
|
|
93
|
+
margin: 0 0 20px;
|
|
94
|
+
padding-bottom: 12px;
|
|
95
|
+
font-size: 17px;
|
|
96
|
+
font-weight: 600;
|
|
97
|
+
color: #fb6a6a;
|
|
98
|
+
border-bottom: 2px solid rgba(252,94,94,.66);
|
|
99
|
+
}
|
|
100
|
+
.content {
|
|
101
|
+
margin: 0;
|
|
102
|
+
font-size: 14px;
|
|
103
|
+
font-family: inherit;
|
|
104
|
+
white-space: pre-wrap;
|
|
105
|
+
word-break: break-all;
|
|
106
|
+
scrollbar-width: none;
|
|
107
|
+
}
|
|
108
|
+
.content::-webkit-scrollbar {
|
|
109
|
+
display: none;
|
|
110
|
+
}
|
|
111
|
+
.file-link,
|
|
112
|
+
.url-link,
|
|
113
|
+
.config-link {
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
text-decoration: underline;
|
|
116
|
+
text-underline-offset: 3px;
|
|
117
|
+
&:hover {
|
|
118
|
+
opacity: 0.8;
|
|
119
|
+
}
|
|
120
|
+
&:active {
|
|
121
|
+
opacity: 0.6;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
.file-link {
|
|
125
|
+
color: #61cfd8;
|
|
126
|
+
}
|
|
127
|
+
.url-link {
|
|
128
|
+
color: #eff986;
|
|
129
|
+
}
|
|
130
|
+
.config-link {
|
|
131
|
+
color: inherit;
|
|
132
|
+
text-decoration: none;
|
|
133
|
+
}
|
|
134
|
+
.close {
|
|
135
|
+
position: absolute;
|
|
136
|
+
top: 27px;
|
|
137
|
+
right: 32px;
|
|
138
|
+
width: 32px;
|
|
139
|
+
height: 32px;
|
|
140
|
+
cursor: pointer;
|
|
141
|
+
}
|
|
142
|
+
.close:hover {
|
|
143
|
+
opacity: 0.8;
|
|
144
|
+
}
|
|
145
|
+
.close:active {
|
|
146
|
+
opacity: 0.6;
|
|
147
|
+
}
|
|
148
|
+
.close:before,
|
|
149
|
+
.close:after {
|
|
150
|
+
position: absolute;
|
|
151
|
+
left: 16px;
|
|
152
|
+
top: 8px;
|
|
153
|
+
content: ' ';
|
|
154
|
+
height: 18px;
|
|
155
|
+
width: 2px;
|
|
156
|
+
border-radius: 4px;
|
|
157
|
+
background-color: #b8b8b8;
|
|
158
|
+
}
|
|
159
|
+
.close:before {
|
|
160
|
+
transform: rotate(45deg);
|
|
161
|
+
}
|
|
162
|
+
.close:after {
|
|
163
|
+
transform: rotate(-45deg);
|
|
164
|
+
}
|
|
165
|
+
.footer {
|
|
166
|
+
font-size: 12px;
|
|
167
|
+
color: #7e6a92;
|
|
168
|
+
margin-top: 20px;
|
|
169
|
+
padding-top: 12px;
|
|
170
|
+
border-top: 2px solid rgba(126,106,146,.6);
|
|
171
|
+
}
|
|
172
|
+
.footer p {
|
|
173
|
+
margin: 4px 0 0;
|
|
174
|
+
}
|
|
175
|
+
.footer span {
|
|
176
|
+
color: #a88dc3;
|
|
177
|
+
}
|
|
178
|
+
</style>
|
|
179
|
+
|
|
180
|
+
<div class="root">
|
|
181
|
+
<div class="container">
|
|
182
|
+
<div class="close"></div>
|
|
183
|
+
<p class="title">${title}</p>
|
|
184
|
+
<pre class="content">${content}</pre>
|
|
185
|
+
<footer class="footer">
|
|
186
|
+
<p><span>Fix error</span>, click outside, or press Esc to close the overlay.</p>
|
|
187
|
+
<p>Disable overlay by setting Rsbuild's <span><a class="config-link" target="_blank" rel="noopener noreferrer" href="https://rsbuild.rs/config/dev/client">dev.client.overlay</a></span> config to false.<p>
|
|
188
|
+
</footer>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
function createOverlay(title, content) {
|
|
194
|
+
clearOverlay();
|
|
195
|
+
document.body.appendChild(new ErrorOverlay(getOverlayHtml(title, content)));
|
|
196
|
+
}
|
|
197
|
+
function clearOverlay() {
|
|
198
|
+
document.querySelectorAll(overlayId).forEach((n)=>{
|
|
199
|
+
n.close(true);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if ("u" > typeof document) registerOverlay(createOverlay, clearOverlay);
|
|
203
|
+
else logger.info('[rsbuild] Error overlay unavailable: Running in non-browser environment. To suppress this message, set `dev.client.overlay: false` in your configuration.');
|