@rsbuild/core 1.6.9 → 1.6.11
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/compiled/memfs/index.js +123 -121
- package/compiled/memfs/package.json +1 -1
- package/compiled/rslog/index.js +12 -9
- package/compiled/rslog/package.json +1 -1
- 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/dist/0~open.js +1 -1
- package/dist/{506.js → 131.js} +130 -791
- package/dist/131.js.LICENSE.txt +26 -0
- package/dist/136.mjs +42 -0
- package/dist/client/hmr.js +172 -173
- package/dist/index.cjs +106 -780
- package/dist/index.cjs.LICENSE.txt +0 -21
- package/dist/index.js +1 -1
- package/dist/rslib-runtime.js +1 -1
- package/dist/transformLoader.mjs +1 -36
- package/dist/transformRawLoader.mjs +3 -36
- package/dist-types/client/hmr.d.ts +9 -0
- package/dist-types/constants.d.ts +1 -0
- package/dist-types/helpers/vendors.d.ts +1 -0
- package/dist-types/server/assets-middleware/index.d.ts +8 -0
- package/dist-types/server/socketServer.d.ts +4 -0
- package/package.json +4 -4
- package/dist/476.mjs +0 -8
- package/dist/506.js.LICENSE.txt +0 -47
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ee-first
|
|
3
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*!
|
|
8
|
+
* on-finished
|
|
9
|
+
* Copyright(c) 2013 Jonathan Ong
|
|
10
|
+
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
11
|
+
* MIT Licensed
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Autoload Config for PostCSS
|
|
16
|
+
*
|
|
17
|
+
* @author Michael Ciniawsky @michael-ciniawsky <michael.ciniawsky@gmail.com>
|
|
18
|
+
* @license MIT
|
|
19
|
+
*
|
|
20
|
+
* @module postcss-load-config
|
|
21
|
+
* @version 2.1.0
|
|
22
|
+
*
|
|
23
|
+
* @requires comsiconfig
|
|
24
|
+
* @requires ./options
|
|
25
|
+
* @requires ./plugins
|
|
26
|
+
*/
|
package/dist/136.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
let constants_dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
process.platform, join(constants_dirname), join(constants_dirname, '../static'), join(constants_dirname, 'client');
|
|
6
|
+
let COMPILED_PATH = join(constants_dirname, '../compiled'), vendors_require = createRequire(import.meta.url), requireCompiledPackage = (name)=>vendors_require(`${COMPILED_PATH}/${name}/index.js`);
|
|
7
|
+
requireCompiledPackage('picocolors');
|
|
8
|
+
let transformLoader = async function transform(source, map) {
|
|
9
|
+
let callback = this.async(), bypass = ()=>{
|
|
10
|
+
callback(null, source, map);
|
|
11
|
+
}, { id: transformId, getEnvironment } = this.getOptions();
|
|
12
|
+
if (!transformId) return void bypass();
|
|
13
|
+
let transform = this._compiler?.__rsbuildTransformer?.[transformId];
|
|
14
|
+
if (!transform) return void bypass();
|
|
15
|
+
try {
|
|
16
|
+
var generatedSourceMap;
|
|
17
|
+
let result = await transform({
|
|
18
|
+
code: source,
|
|
19
|
+
context: this.context,
|
|
20
|
+
resource: this.resource,
|
|
21
|
+
resourcePath: this.resourcePath,
|
|
22
|
+
resourceQuery: this.resourceQuery,
|
|
23
|
+
environment: getEnvironment(),
|
|
24
|
+
addDependency: this.addDependency.bind(this),
|
|
25
|
+
addMissingDependency: this.addMissingDependency.bind(this),
|
|
26
|
+
addContextDependency: this.addContextDependency.bind(this),
|
|
27
|
+
emitFile: this.emitFile.bind(this),
|
|
28
|
+
importModule: this.importModule.bind(this),
|
|
29
|
+
resolve: this.resolve.bind(this)
|
|
30
|
+
});
|
|
31
|
+
if (null == result) return void bypass();
|
|
32
|
+
if ('string' == typeof result || Buffer.isBuffer(result)) return void callback(null, result, map);
|
|
33
|
+
let mergedMap = (generatedSourceMap = result.map, map && generatedSourceMap ? requireCompiledPackage('@jridgewell/remapping')([
|
|
34
|
+
generatedSourceMap,
|
|
35
|
+
map
|
|
36
|
+
], ()=>null) : generatedSourceMap ?? map);
|
|
37
|
+
callback(null, result.code, mergedMap);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
error instanceof Error ? callback(error) : callback(Error(String(error)));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export default transformLoader;
|
package/dist/client/hmr.js
CHANGED
|
@@ -1,191 +1,190 @@
|
|
|
1
|
-
const config = RSBUILD_CLIENT_CONFIG;
|
|
2
|
-
const serverHost = RSBUILD_SERVER_HOST;
|
|
3
|
-
const serverPort = RSBUILD_SERVER_PORT;
|
|
4
|
-
const queuedMessages = [];
|
|
5
|
-
let lastHash;
|
|
6
|
-
let hasBuildErrors = false;
|
|
7
|
-
function formatURL(fallback) {
|
|
8
|
-
const { location } = self;
|
|
9
|
-
const hostname = (fallback ? serverHost : config.host) || location.hostname;
|
|
10
|
-
const port = (fallback ? serverPort : config.port) || location.port;
|
|
11
|
-
const protocol = config.protocol || ('https:' === location.protocol ? 'wss' : 'ws');
|
|
12
|
-
const pathname = config.path;
|
|
13
|
-
if ('undefined' != typeof URL) {
|
|
14
|
-
const url = new URL('http://localhost');
|
|
15
|
-
url.port = String(port);
|
|
16
|
-
url.hostname = hostname;
|
|
17
|
-
url.protocol = protocol;
|
|
18
|
-
url.pathname = pathname;
|
|
19
|
-
url.searchParams.append('token', RSBUILD_WEB_SOCKET_TOKEN);
|
|
20
|
-
return url.toString();
|
|
21
|
-
}
|
|
22
|
-
const colon = -1 === protocol.indexOf(':') ? ':' : '';
|
|
23
|
-
return `${protocol}${colon}//${hostname}:${port}${pathname}?token=${RSBUILD_WEB_SOCKET_TOKEN}`;
|
|
24
|
-
}
|
|
25
|
-
function clearBuildErrors() {
|
|
26
|
-
if (console.clear && hasBuildErrors) console.clear();
|
|
27
|
-
hasBuildErrors = false;
|
|
28
|
-
}
|
|
29
1
|
let createOverlay;
|
|
30
2
|
let clearOverlay;
|
|
31
3
|
const registerOverlay = (createFn, clearFn)=>{
|
|
32
4
|
createOverlay = createFn;
|
|
33
5
|
clearOverlay = clearFn;
|
|
34
6
|
};
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
7
|
+
function init({ token, config, serverHost, serverPort, liveReload, browserLogs }) {
|
|
8
|
+
const queuedMessages = [];
|
|
9
|
+
let lastHash;
|
|
10
|
+
let hasBuildErrors = false;
|
|
11
|
+
function formatURL(fallback) {
|
|
12
|
+
const { location } = self;
|
|
13
|
+
const hostname = (fallback ? serverHost : config.host) || location.hostname;
|
|
14
|
+
const port = (fallback ? serverPort : config.port) || location.port;
|
|
15
|
+
const protocol = config.protocol || ('https:' === location.protocol ? 'wss' : 'ws');
|
|
16
|
+
const pathname = config.path;
|
|
17
|
+
if ('undefined' != typeof URL) {
|
|
18
|
+
const url = new URL('http://localhost');
|
|
19
|
+
url.port = String(port);
|
|
20
|
+
url.hostname = hostname;
|
|
21
|
+
url.protocol = protocol;
|
|
22
|
+
url.pathname = pathname;
|
|
23
|
+
url.searchParams.append('token', token);
|
|
24
|
+
return url.toString();
|
|
45
25
|
}
|
|
46
|
-
|
|
26
|
+
const colon = -1 === protocol.indexOf(':') ? ':' : '';
|
|
27
|
+
return `${protocol}${colon}//${hostname}:${port}${pathname}?token=${token}`;
|
|
47
28
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
clearBuildErrors();
|
|
52
|
-
hasBuildErrors = true;
|
|
53
|
-
for (const error of text)console.error(error);
|
|
54
|
-
if (createOverlay) createOverlay(html);
|
|
55
|
-
}
|
|
56
|
-
const shouldUpdate = ()=>lastHash !== __webpack_hash__;
|
|
57
|
-
const handleApplyUpdates = (err, updatedModules)=>{
|
|
58
|
-
const forcedReload = err || !updatedModules;
|
|
59
|
-
if (forcedReload) {
|
|
60
|
-
if (err) console.error('[rsbuild] HMR update failed, performing full reload: ', err);
|
|
61
|
-
reloadPage();
|
|
62
|
-
return;
|
|
29
|
+
function clearBuildErrors() {
|
|
30
|
+
if (console.clear && hasBuildErrors) console.clear();
|
|
31
|
+
hasBuildErrors = false;
|
|
63
32
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!shouldUpdate()) return;
|
|
68
|
-
if (import.meta.webpackHot) {
|
|
69
|
-
if ('idle' !== import.meta.webpackHot.status()) return;
|
|
70
|
-
import.meta.webpackHot.check(true).then((updatedModules)=>{
|
|
71
|
-
handleApplyUpdates(null, updatedModules);
|
|
72
|
-
}, (err)=>{
|
|
73
|
-
handleApplyUpdates(err, null);
|
|
74
|
-
});
|
|
75
|
-
return;
|
|
33
|
+
function handleSuccess() {
|
|
34
|
+
clearBuildErrors();
|
|
35
|
+
tryApplyUpdates();
|
|
76
36
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
let
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
console.info('[rsbuild] WebSocket connected.');
|
|
88
|
-
reconnectCount = 0;
|
|
89
|
-
pingIntervalId = setInterval(()=>{
|
|
90
|
-
socketSend({
|
|
91
|
-
type: 'ping'
|
|
92
|
-
});
|
|
93
|
-
}, 30000);
|
|
94
|
-
if (queuedMessages.length) {
|
|
95
|
-
queuedMessages.forEach(socketSend);
|
|
96
|
-
queuedMessages.length = 0;
|
|
37
|
+
function handleWarnings({ text }) {
|
|
38
|
+
clearBuildErrors();
|
|
39
|
+
for(let i = 0; i < text.length; i++){
|
|
40
|
+
if (5 === i) {
|
|
41
|
+
console.warn('[rsbuild] Additional warnings detected. View complete log in terminal for details.');
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
console.warn(text[i]);
|
|
45
|
+
}
|
|
46
|
+
tryApplyUpdates();
|
|
97
47
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
case 'static-changed':
|
|
110
|
-
case 'content-changed':
|
|
48
|
+
function handleErrors({ text, html }) {
|
|
49
|
+
clearBuildErrors();
|
|
50
|
+
hasBuildErrors = true;
|
|
51
|
+
for (const error of text)console.error(error);
|
|
52
|
+
if (createOverlay) createOverlay(html);
|
|
53
|
+
}
|
|
54
|
+
const shouldUpdate = ()=>lastHash !== __webpack_hash__;
|
|
55
|
+
const handleApplyUpdates = (err, updatedModules)=>{
|
|
56
|
+
const forcedReload = err || !updatedModules;
|
|
57
|
+
if (forcedReload) {
|
|
58
|
+
if (err) console.error('[rsbuild] HMR update failed, performing full reload: ', err);
|
|
111
59
|
reloadPage();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
tryApplyUpdates();
|
|
63
|
+
};
|
|
64
|
+
function tryApplyUpdates() {
|
|
65
|
+
if (!shouldUpdate()) return;
|
|
66
|
+
if (import.meta.webpackHot) {
|
|
67
|
+
if ('idle' !== import.meta.webpackHot.status()) return;
|
|
68
|
+
import.meta.webpackHot.check(true).then((updatedModules)=>{
|
|
69
|
+
handleApplyUpdates(null, updatedModules);
|
|
70
|
+
}, (err)=>{
|
|
71
|
+
handleApplyUpdates(err, null);
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
reloadPage();
|
|
119
76
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
77
|
+
let socket = null;
|
|
78
|
+
let reconnectCount = 0;
|
|
79
|
+
let pingIntervalId;
|
|
80
|
+
const isSocketReady = ()=>socket && socket.readyState === socket.OPEN;
|
|
81
|
+
const socketSend = (data)=>{
|
|
82
|
+
if (isSocketReady()) socket.send(JSON.stringify(data));
|
|
83
|
+
};
|
|
84
|
+
function onOpen() {
|
|
85
|
+
console.info('[rsbuild] WebSocket connected.');
|
|
86
|
+
reconnectCount = 0;
|
|
87
|
+
pingIntervalId = setInterval(()=>{
|
|
88
|
+
socketSend({
|
|
89
|
+
type: 'ping'
|
|
90
|
+
});
|
|
91
|
+
}, 30000);
|
|
92
|
+
if (queuedMessages.length) {
|
|
93
|
+
queuedMessages.forEach(socketSend);
|
|
94
|
+
queuedMessages.length = 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function onMessage(e) {
|
|
98
|
+
const message = JSON.parse(e.data);
|
|
99
|
+
switch(message.type){
|
|
100
|
+
case 'hash':
|
|
101
|
+
lastHash = message.data;
|
|
102
|
+
if (clearOverlay && shouldUpdate()) clearOverlay();
|
|
103
|
+
break;
|
|
104
|
+
case 'ok':
|
|
105
|
+
handleSuccess();
|
|
106
|
+
break;
|
|
107
|
+
case 'static-changed':
|
|
108
|
+
case 'content-changed':
|
|
109
|
+
reloadPage();
|
|
110
|
+
break;
|
|
111
|
+
case 'warnings':
|
|
112
|
+
handleWarnings(message.data);
|
|
113
|
+
break;
|
|
114
|
+
case 'errors':
|
|
115
|
+
handleErrors(message.data);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function onClose() {
|
|
120
|
+
if (reconnectCount >= config.reconnect) {
|
|
121
|
+
if (config.reconnect > 0) console.warn('[rsbuild] WebSocket connection failed after maximum retry attempts.');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (0 === reconnectCount) console.info('[rsbuild] WebSocket connection lost. Reconnecting...');
|
|
135
125
|
removeListeners();
|
|
136
126
|
socket = null;
|
|
137
|
-
|
|
127
|
+
reconnectCount++;
|
|
128
|
+
setTimeout(connect, 1000 * 1.5 ** reconnectCount);
|
|
138
129
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (isSocketReady()) socketSend(messageInfo);
|
|
147
|
-
else queuedMessages.push(messageInfo);
|
|
148
|
-
}
|
|
149
|
-
function onUnhandledRejection({ reason }) {
|
|
150
|
-
let message;
|
|
151
|
-
let stack;
|
|
152
|
-
if (reason instanceof Error) {
|
|
153
|
-
message = reason.name ? `${reason.name}: ${reason.message}` : reason.message;
|
|
154
|
-
stack = reason.stack;
|
|
155
|
-
} else if ('string' == typeof reason) message = reason;
|
|
156
|
-
else try {
|
|
157
|
-
message = JSON.stringify(reason);
|
|
158
|
-
} catch (_) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
sendError(`Uncaught (in promise) ${message}`, stack);
|
|
162
|
-
}
|
|
163
|
-
function connect(fallback = false) {
|
|
164
|
-
if (0 === reconnectCount) console.info('[rsbuild] WebSocket connecting...');
|
|
165
|
-
const socketUrl = formatURL(fallback);
|
|
166
|
-
socket = new WebSocket(socketUrl);
|
|
167
|
-
socket.addEventListener('open', onOpen);
|
|
168
|
-
socket.addEventListener('close', onClose);
|
|
169
|
-
socket.addEventListener('message', onMessage);
|
|
170
|
-
if (!fallback) socket.addEventListener('error', onSocketError);
|
|
171
|
-
}
|
|
172
|
-
function removeListeners() {
|
|
173
|
-
clearInterval(pingIntervalId);
|
|
174
|
-
if (socket) {
|
|
175
|
-
socket.removeEventListener('open', onOpen);
|
|
176
|
-
socket.removeEventListener('close', onClose);
|
|
177
|
-
socket.removeEventListener('message', onMessage);
|
|
178
|
-
socket.removeEventListener('error', onSocketError);
|
|
130
|
+
function onSocketError() {
|
|
131
|
+
if (formatURL() !== formatURL(true)) {
|
|
132
|
+
console.error('[rsbuild] WebSocket connection failed. Trying direct connection fallback.');
|
|
133
|
+
removeListeners();
|
|
134
|
+
socket = null;
|
|
135
|
+
connect(true);
|
|
136
|
+
}
|
|
179
137
|
}
|
|
138
|
+
function sendError(message, stack) {
|
|
139
|
+
const messageInfo = {
|
|
140
|
+
type: 'client-error',
|
|
141
|
+
message,
|
|
142
|
+
stack
|
|
143
|
+
};
|
|
144
|
+
if (isSocketReady()) socketSend(messageInfo);
|
|
145
|
+
else queuedMessages.push(messageInfo);
|
|
146
|
+
}
|
|
147
|
+
function onUnhandledRejection({ reason }) {
|
|
148
|
+
let message;
|
|
149
|
+
let stack;
|
|
150
|
+
if (reason instanceof Error) {
|
|
151
|
+
message = reason.name ? `${reason.name}: ${reason.message}` : reason.message;
|
|
152
|
+
stack = reason.stack;
|
|
153
|
+
} else if ('string' == typeof reason) message = reason;
|
|
154
|
+
else try {
|
|
155
|
+
message = JSON.stringify(reason);
|
|
156
|
+
} catch (_) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
sendError(`Uncaught (in promise) ${message}`, stack);
|
|
160
|
+
}
|
|
161
|
+
function connect(fallback = false) {
|
|
162
|
+
if (0 === reconnectCount) console.info('[rsbuild] WebSocket connecting...');
|
|
163
|
+
const socketUrl = formatURL(fallback);
|
|
164
|
+
socket = new WebSocket(socketUrl);
|
|
165
|
+
socket.addEventListener('open', onOpen);
|
|
166
|
+
socket.addEventListener('close', onClose);
|
|
167
|
+
socket.addEventListener('message', onMessage);
|
|
168
|
+
if (!fallback) socket.addEventListener('error', onSocketError);
|
|
169
|
+
}
|
|
170
|
+
function removeListeners() {
|
|
171
|
+
clearInterval(pingIntervalId);
|
|
172
|
+
if (socket) {
|
|
173
|
+
socket.removeEventListener('open', onOpen);
|
|
174
|
+
socket.removeEventListener('close', onClose);
|
|
175
|
+
socket.removeEventListener('message', onMessage);
|
|
176
|
+
socket.removeEventListener('error', onSocketError);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function reloadPage() {
|
|
180
|
+
if (liveReload) window.location.reload();
|
|
181
|
+
}
|
|
182
|
+
if (browserLogs && 'undefined' != typeof window) {
|
|
183
|
+
window.addEventListener('error', ({ message, error })=>{
|
|
184
|
+
sendError(message, error instanceof Error ? error.stack : void 0);
|
|
185
|
+
});
|
|
186
|
+
window.addEventListener('unhandledrejection', onUnhandledRejection);
|
|
187
|
+
}
|
|
188
|
+
connect();
|
|
180
189
|
}
|
|
181
|
-
|
|
182
|
-
if (RSBUILD_DEV_LIVE_RELOAD) window.location.reload();
|
|
183
|
-
}
|
|
184
|
-
if (RSBUILD_DEV_BROWSER_LOGS && 'undefined' != typeof window) {
|
|
185
|
-
window.addEventListener('error', ({ message, error })=>{
|
|
186
|
-
sendError(message, error instanceof Error ? error.stack : void 0);
|
|
187
|
-
});
|
|
188
|
-
window.addEventListener('unhandledrejection', onUnhandledRejection);
|
|
189
|
-
}
|
|
190
|
-
connect();
|
|
191
|
-
export { registerOverlay };
|
|
190
|
+
export { init, registerOverlay };
|