@rspack/core 1.7.2 → 2.0.0-alpha.0
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/dist/ChunkGraph.d.ts +1 -1
- package/dist/Compilation.d.ts +27 -27
- package/dist/Compiler.d.ts +19 -17
- package/dist/ContextModuleFactory.d.ts +1 -1
- package/dist/Diagnostics.d.ts +1 -1
- package/dist/ExecuteModulePlugin.d.ts +1 -1
- package/dist/ExportsInfo.d.ts +1 -1
- package/dist/FileSystem.d.ts +1 -1
- package/dist/Module.d.ts +2 -2
- package/dist/ModuleGraph.d.ts +2 -2
- package/dist/MultiCompiler.d.ts +7 -7
- package/dist/MultiStats.d.ts +3 -3
- package/dist/MultiWatching.d.ts +2 -2
- package/dist/NativeWatchFileSystem.d.ts +1 -1
- package/dist/NormalModule.d.ts +3 -3
- package/dist/NormalModuleFactory.d.ts +3 -3
- package/dist/Resolver.d.ts +1 -1
- package/dist/ResolverFactory.d.ts +2 -2
- package/dist/RuntimeGlobals.d.ts +2 -2
- package/dist/RuntimeModule.d.ts +3 -3
- package/dist/Stats.d.ts +4 -4
- package/dist/VirtualModulesPlugin.d.ts +1 -1
- package/dist/Watching.d.ts +4 -4
- package/dist/builtin-loader/lightningcss/index.d.ts +11 -14
- package/dist/builtin-loader/lightningcss/target.d.ts +4 -0
- package/dist/builtin-loader/swc/index.d.ts +5 -5
- package/dist/builtin-loader/swc/types.d.ts +2 -8
- package/dist/builtin-plugin/APIPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +3 -3
- package/dist/builtin-plugin/AssetModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/BannerPlugin.d.ts +3 -3
- package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CaseSensitivePlugin.d.ts +3 -3
- package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CircularDependencyRspackPlugin.d.ts +4 -4
- package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ContextReplacementPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CopyRspackPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CssChunkingPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CssModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DataUriPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DefinePlugin.d.ts +3 -3
- package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/DllEntryPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DllReferenceAgencyPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +3 -3
- package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +2 -2
- package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +2 -2
- package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +3 -3
- package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/EntryPlugin.d.ts +4 -4
- package/dist/builtin-plugin/EsmLibraryPlugin.d.ts +3 -1
- package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +3 -3
- package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ExternalsPlugin.d.ts +2 -2
- package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FileUriPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FlagAllModulesAsUsedPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +1 -1
- package/dist/builtin-plugin/HotModuleReplacementPlugin.d.ts +2 -2
- package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +3 -3
- package/dist/builtin-plugin/HttpUriPlugin.d.ts +2 -2
- package/dist/builtin-plugin/IgnorePlugin.d.ts +3 -3
- package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/InlineExportsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +4 -4
- package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +2 -2
- package/dist/builtin-plugin/JsonModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/LibManifestPlugin.d.ts +3 -3
- package/dist/builtin-plugin/LightningCssMinimizerRspackPlugin.d.ts +7 -11
- package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +3 -3
- package/dist/builtin-plugin/MangleExportsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +1 -1
- package/dist/builtin-plugin/ModuleInfoHeaderPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +1 -1
- package/dist/builtin-plugin/NoEmitOnErrorsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NodeTargetPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NormalModuleReplacementPlugin.d.ts +4 -4
- package/dist/builtin-plugin/OccurrenceChunkIdsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ProgressPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ProvidePlugin.d.ts +3 -3
- package/dist/builtin-plugin/RealContentHashPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RemoveDuplicateModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RsdoctorPlugin.d.ts +4 -8
- package/dist/builtin-plugin/RslibPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RstestPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RuntimePlugin.d.ts +6 -10
- package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +3 -3
- package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +3 -3
- package/dist/builtin-plugin/SplitChunksPlugin.d.ts +3 -3
- package/dist/builtin-plugin/SubresourceIntegrityPlugin.d.ts +2 -2
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +6 -5
- package/dist/builtin-plugin/URLPlugin.d.ts +3 -3
- package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +2 -2
- package/dist/builtin-plugin/WorkerPlugin.d.ts +3 -3
- package/dist/builtin-plugin/base.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/index.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/loader.d.ts +1 -1
- package/dist/builtin-plugin/css-extract/utils.d.ts +1 -1
- package/dist/builtin-plugin/html-plugin/hooks.d.ts +2 -2
- package/dist/builtin-plugin/html-plugin/index.d.ts +2 -2
- package/dist/builtin-plugin/html-plugin/options.d.ts +1 -6
- package/dist/builtin-plugin/html-plugin/plugin.d.ts +5 -9
- package/dist/builtin-plugin/html-plugin/taps.d.ts +1 -1
- package/dist/builtin-plugin/index.d.ts +84 -84
- package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +4 -4
- package/dist/builtin-plugin/lazy-compilation/middleware.d.ts +2 -2
- package/dist/config/adapter.d.ts +4 -4
- package/dist/config/adapterRuleUse.d.ts +10 -9
- package/dist/config/browserslistTargetHandler.d.ts +1 -1
- package/dist/config/defaults.d.ts +5 -3
- package/dist/config/devServer.d.ts +3 -3
- package/dist/config/index.d.ts +5 -5
- package/dist/config/normalization.d.ts +8 -36
- package/dist/config/target.d.ts +14 -11
- package/dist/config/types.d.ts +85 -162
- package/dist/container/ContainerPlugin.d.ts +3 -3
- package/dist/container/ContainerReferencePlugin.d.ts +3 -3
- package/dist/container/ModuleFederationManifestPlugin.d.ts +2 -2
- package/dist/container/ModuleFederationPlugin.d.ts +5 -3
- package/dist/container/ModuleFederationPluginV1.d.ts +5 -5
- package/dist/container/ModuleFederationRuntimePlugin.d.ts +7 -3
- package/dist/container/index.d.ts +4 -4
- package/dist/cssExtractHmr.js +2 -27
- package/dist/cssExtractLoader.js +18 -60
- package/dist/exports.d.ts +69 -82
- package/dist/index.d.ts +3 -3
- package/dist/index.js +11667 -11683
- package/dist/lib/AbstractMethodError.d.ts +1 -1
- package/dist/lib/Cache.d.ts +1 -1
- package/dist/lib/CacheFacade.d.ts +3 -3
- package/dist/lib/DllPlugin.d.ts +2 -2
- package/dist/lib/DllReferencePlugin.d.ts +3 -3
- package/dist/lib/EntryOptionPlugin.d.ts +2 -2
- package/dist/lib/EnvironmentPlugin.d.ts +1 -1
- package/dist/lib/HookWebpackError.d.ts +1 -1
- package/dist/lib/IgnoreWarningsPlugin.d.ts +1 -1
- package/dist/lib/LoaderOptionsPlugin.d.ts +2 -2
- package/dist/lib/LoaderTargetPlugin.d.ts +2 -2
- package/dist/lib/WebpackError.d.ts +2 -2
- package/dist/lib/cache/MemoryCachePlugin.d.ts +1 -1
- package/dist/lib/cache/getLazyHashedEtag.d.ts +1 -1
- package/dist/lib/cache/mergeEtags.d.ts +1 -1
- package/dist/loader-runner/ModuleError.d.ts +1 -1
- package/dist/loader-runner/index.d.ts +1 -1
- package/dist/loader-runner/loadLoader.d.ts +2 -2
- package/dist/loader-runner/utils.d.ts +3 -3
- package/dist/loader-runner/worker.d.ts +1 -1
- package/dist/logging/createConsoleLogger.d.ts +2 -2
- package/dist/moduleFederationDefaultRuntime.js +1 -1
- package/dist/node/NodeEnvironmentPlugin.d.ts +2 -2
- package/dist/node/NodeTemplatePlugin.d.ts +1 -1
- package/dist/node/NodeWatchFileSystem.d.ts +1 -1
- package/dist/node/nodeConsole.d.ts +1 -1
- package/dist/rslib-runtime.js +29 -0
- package/dist/rspack.d.ts +5 -5
- package/dist/rspackOptionsApply.d.ts +1 -1
- package/dist/runtime/moduleFederationDefaultRuntime.d.ts +1 -2
- package/dist/sharing/ConsumeSharedPlugin.d.ts +2 -2
- package/dist/sharing/ProvideSharedPlugin.d.ts +2 -2
- package/dist/sharing/SharePlugin.d.ts +1 -1
- package/dist/sharing/ShareRuntimePlugin.d.ts +2 -2
- package/dist/stats/DefaultStatsFactoryPlugin.d.ts +1 -1
- package/dist/stats/DefaultStatsPresetPlugin.d.ts +1 -1
- package/dist/stats/DefaultStatsPrinterPlugin.d.ts +1 -1
- package/dist/stats/StatsFactory.d.ts +2 -2
- package/dist/stats/StatsPrinter.d.ts +1 -1
- package/dist/stats/statsFactoryUtils.d.ts +3 -6
- package/dist/taps/compilation.d.ts +1 -1
- package/dist/taps/compiler.d.ts +1 -1
- package/dist/taps/contextModuleFactory.d.ts +1 -1
- package/dist/taps/index.d.ts +6 -6
- package/dist/taps/javascriptModules.d.ts +1 -1
- package/dist/taps/normalModuleFactory.d.ts +1 -1
- package/dist/taps/types.d.ts +1 -1
- package/dist/trace/traceHookPlugin.d.ts +1 -1
- package/dist/util/createHash.d.ts +1 -1
- package/dist/util/fs.d.ts +1 -1
- package/dist/util/hash/md4.d.ts +1 -1
- package/dist/util/hash/xxhash64.d.ts +1 -1
- package/dist/util/index.d.ts +1 -1
- package/dist/util/targetsVersion.d.ts +2 -0
- package/dist/util/validateConfig.d.ts +1 -1
- package/dist/worker.js +846 -918
- package/hot/dev-server.js +12 -9
- package/hot/emitter.js +5 -1
- package/hot/lazy-compilation-node.js +94 -35
- package/hot/lazy-compilation-web.js +63 -38
- package/hot/log-apply-result.js +8 -5
- package/hot/log.js +17 -7
- package/hot/only-dev-server.js +13 -10
- package/hot/poll.js +11 -8
- package/hot/signal.js +13 -9
- package/package.json +14 -10
- package/compiled/browserslist-load-config/index.d.ts +0 -21
- package/compiled/browserslist-load-config/index.js +0 -252
- package/compiled/browserslist-load-config/license +0 -21
- package/compiled/browserslist-load-config/package.json +0 -1
- package/dist/builtin-loader/index.d.ts +0 -1
package/hot/dev-server.js
CHANGED
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
5
|
/* globals __webpack_hash__ */
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
import { log, formatError } from './log.js';
|
|
8
|
+
import { emitter as hotEmitter } from './emitter.js';
|
|
9
|
+
import { logApplyResult } from './log-apply-result.js';
|
|
10
|
+
|
|
11
|
+
if (import.meta.webpackHot) {
|
|
7
12
|
/** @type {undefined|string} */
|
|
8
13
|
var lastHash;
|
|
9
14
|
var upToDate = function upToDate() {
|
|
10
15
|
return /** @type {string} */ (lastHash).indexOf(__webpack_hash__) >= 0;
|
|
11
16
|
};
|
|
12
|
-
var log = require('./log');
|
|
13
17
|
var check = function check() {
|
|
14
|
-
|
|
18
|
+
import.meta.webpackHot
|
|
15
19
|
.check(true)
|
|
16
20
|
.then(function (updatedModules) {
|
|
17
21
|
if (!updatedModules) {
|
|
@@ -36,14 +40,14 @@ if (module.hot) {
|
|
|
36
40
|
check();
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
logApplyResult(updatedModules, updatedModules);
|
|
40
44
|
|
|
41
45
|
if (upToDate()) {
|
|
42
46
|
log('info', '[HMR] App is up to date.');
|
|
43
47
|
}
|
|
44
48
|
})
|
|
45
49
|
.catch(function (err) {
|
|
46
|
-
var status =
|
|
50
|
+
var status = import.meta.webpackHot.status();
|
|
47
51
|
if (['abort', 'fail'].indexOf(status) >= 0) {
|
|
48
52
|
log(
|
|
49
53
|
'warning',
|
|
@@ -52,19 +56,18 @@ if (module.hot) {
|
|
|
52
56
|
? 'Need to do a full reload!'
|
|
53
57
|
: 'Please reload manually!'),
|
|
54
58
|
);
|
|
55
|
-
log('warning', '[HMR] ' +
|
|
59
|
+
log('warning', '[HMR] ' + formatError(err));
|
|
56
60
|
if (typeof window !== 'undefined') {
|
|
57
61
|
window.location.reload();
|
|
58
62
|
}
|
|
59
63
|
} else {
|
|
60
|
-
log('warning', '[HMR] Update failed: ' +
|
|
64
|
+
log('warning', '[HMR] Update failed: ' + formatError(err));
|
|
61
65
|
}
|
|
62
66
|
});
|
|
63
67
|
};
|
|
64
|
-
var hotEmitter = require('./emitter');
|
|
65
68
|
hotEmitter.on('webpackHotUpdate', function (currentHash) {
|
|
66
69
|
lastHash = currentHash;
|
|
67
|
-
if (!upToDate() &&
|
|
70
|
+
if (!upToDate() && import.meta.webpackHot.status() === 'idle') {
|
|
68
71
|
log('info', '[HMR] Checking for updates on the server...');
|
|
69
72
|
check();
|
|
70
73
|
}
|
package/hot/emitter.js
CHANGED
|
@@ -18,4 +18,8 @@ EventEmitter.prototype.emit = function (eventName) {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
var emitter = new EventEmitter();
|
|
22
|
+
|
|
23
|
+
// TODO: remove default export when rspack-dev-server refactored
|
|
24
|
+
export default emitter;
|
|
25
|
+
export { emitter };
|
|
@@ -1,50 +1,109 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
|
|
1
3
|
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
|
4
|
+
var require = createRequire(import.meta.url);
|
|
5
|
+
var compiling = new Set();
|
|
6
|
+
var errorHandlers = new Set();
|
|
2
7
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
/** @type {import("http").ClientRequest | undefined} */
|
|
9
|
+
var pendingRequest;
|
|
10
|
+
/** @type {boolean} */
|
|
11
|
+
var hasPendingUpdate = false;
|
|
12
|
+
|
|
13
|
+
function sendRequest() {
|
|
14
|
+
if (compiling.size === 0) {
|
|
15
|
+
hasPendingUpdate = false;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var modules = Array.from(compiling);
|
|
20
|
+
var data = modules.join('\n');
|
|
21
|
+
|
|
22
|
+
var httpModule = urlBase.startsWith('https')
|
|
23
|
+
? require('https')
|
|
24
|
+
: require('http');
|
|
25
|
+
|
|
26
|
+
var request = httpModule.request(
|
|
27
|
+
urlBase,
|
|
18
28
|
{
|
|
29
|
+
method: 'POST',
|
|
19
30
|
agent: false,
|
|
20
|
-
headers: {
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'text/plain',
|
|
33
|
+
},
|
|
21
34
|
},
|
|
22
35
|
function (res) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
pendingRequest = undefined;
|
|
37
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
38
|
+
var error = new Error(
|
|
39
|
+
'Problem communicating active modules to the server: HTTP ' +
|
|
40
|
+
res.statusCode,
|
|
28
41
|
);
|
|
42
|
+
errorHandlers.forEach(function (onError) {
|
|
43
|
+
onError(error);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Consume response data to free up memory
|
|
47
|
+
res.resume();
|
|
48
|
+
if (hasPendingUpdate) {
|
|
49
|
+
hasPendingUpdate = false;
|
|
50
|
+
sendRequest();
|
|
29
51
|
}
|
|
30
52
|
},
|
|
31
53
|
);
|
|
32
54
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
'Problem communicating active modules to the server' +
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
request.
|
|
55
|
+
pendingRequest = request;
|
|
56
|
+
|
|
57
|
+
request.on('error', function (err) {
|
|
58
|
+
pendingRequest = undefined;
|
|
59
|
+
var error = new Error(
|
|
60
|
+
'Problem communicating active modules to the server: ' + err.message,
|
|
61
|
+
);
|
|
62
|
+
errorHandlers.forEach(function (onError) {
|
|
63
|
+
onError(error);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
request.write(data);
|
|
46
68
|
request.end();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function sendActiveRequest() {
|
|
72
|
+
hasPendingUpdate = true;
|
|
73
|
+
|
|
74
|
+
// If no request is pending, start one
|
|
75
|
+
if (!pendingRequest) {
|
|
76
|
+
hasPendingUpdate = false;
|
|
77
|
+
sendRequest();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
|
|
83
|
+
* @returns {() => void} function to destroy response
|
|
84
|
+
*/
|
|
85
|
+
export const activate = function (options) {
|
|
86
|
+
var data = options.data;
|
|
87
|
+
var onError = options.onError;
|
|
88
|
+
var active = options.active;
|
|
89
|
+
var module = options.module;
|
|
90
|
+
|
|
91
|
+
errorHandlers.add(onError);
|
|
92
|
+
|
|
93
|
+
if (!compiling.has(data)) {
|
|
94
|
+
compiling.add(data);
|
|
95
|
+
sendActiveRequest();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!active && !module.hot) {
|
|
99
|
+
console.log(
|
|
100
|
+
'Hot Module Replacement is not enabled. Waiting for process restart...',
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
47
104
|
return function () {
|
|
48
|
-
|
|
105
|
+
errorHandlers.delete(onError);
|
|
106
|
+
compiling.delete(data);
|
|
107
|
+
sendActiveRequest();
|
|
49
108
|
};
|
|
50
109
|
};
|
|
@@ -1,64 +1,89 @@
|
|
|
1
|
-
if (typeof
|
|
1
|
+
if (typeof XMLHttpRequest === 'undefined') {
|
|
2
2
|
throw new Error(
|
|
3
|
-
"Environment doesn't support lazy compilation (requires
|
|
3
|
+
"Environment doesn't support lazy compilation (requires XMLHttpRequest)",
|
|
4
4
|
);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
|
8
|
-
/** @type {EventSource | undefined} */
|
|
9
|
-
var activeEventSource;
|
|
10
8
|
var compiling = new Set();
|
|
11
9
|
var errorHandlers = new Set();
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @this {EventSource}
|
|
24
|
-
* @param {Event & { message?: string, filename?: string, lineno?: number, colno?: number, error?: Error }} event event
|
|
25
|
-
*/
|
|
26
|
-
activeEventSource.onerror = function (event) {
|
|
27
|
-
errorHandlers.forEach(function (onError) {
|
|
28
|
-
onError(
|
|
29
|
-
new Error(
|
|
30
|
-
'Problem communicating active modules to the server' +
|
|
31
|
-
(event.message ? `: ${event.message} ` : '') +
|
|
32
|
-
(event.filename ? `: ${event.filename} ` : '') +
|
|
33
|
-
(event.lineno ? `: ${event.lineno} ` : '') +
|
|
34
|
-
(event.colno ? `: ${event.colno} ` : '') +
|
|
35
|
-
(event.error ? `: ${event.error}` : ''),
|
|
36
|
-
),
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
} else {
|
|
41
|
-
activeEventSource = undefined;
|
|
11
|
+
/** @type {XMLHttpRequest | undefined} */
|
|
12
|
+
var pendingXhr;
|
|
13
|
+
/** @type {boolean} */
|
|
14
|
+
var hasPendingUpdate = false;
|
|
15
|
+
|
|
16
|
+
var sendRequest = function sendRequest() {
|
|
17
|
+
if (compiling.size === 0) {
|
|
18
|
+
hasPendingUpdate = false;
|
|
19
|
+
return;
|
|
42
20
|
}
|
|
21
|
+
|
|
22
|
+
var modules = Array.from(compiling);
|
|
23
|
+
var data = modules.join('\n');
|
|
24
|
+
|
|
25
|
+
var xhr = new XMLHttpRequest();
|
|
26
|
+
pendingXhr = xhr;
|
|
27
|
+
xhr.open('POST', urlBase, true);
|
|
28
|
+
// text/plain Content-Type is simple request header
|
|
29
|
+
xhr.setRequestHeader('Content-Type', 'text/plain');
|
|
30
|
+
|
|
31
|
+
xhr.onreadystatechange = function () {
|
|
32
|
+
if (xhr.readyState === 4) {
|
|
33
|
+
pendingXhr = undefined;
|
|
34
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
35
|
+
var error = new Error(
|
|
36
|
+
'Problem communicating active modules to the server: HTTP ' +
|
|
37
|
+
xhr.status,
|
|
38
|
+
);
|
|
39
|
+
errorHandlers.forEach(function (onError) {
|
|
40
|
+
onError(error);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (hasPendingUpdate) {
|
|
44
|
+
hasPendingUpdate = false;
|
|
45
|
+
sendRequest();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
xhr.onerror = function () {
|
|
51
|
+
pendingXhr = undefined;
|
|
52
|
+
var error = new Error('Problem communicating active modules to the server');
|
|
53
|
+
errorHandlers.forEach(function (onError) {
|
|
54
|
+
onError(error);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
xhr.send(data);
|
|
43
59
|
};
|
|
44
60
|
|
|
61
|
+
function sendActiveRequest() {
|
|
62
|
+
hasPendingUpdate = true;
|
|
63
|
+
|
|
64
|
+
// If no request is pending, start one
|
|
65
|
+
if (!pendingXhr) {
|
|
66
|
+
hasPendingUpdate = false;
|
|
67
|
+
sendRequest();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
45
71
|
/**
|
|
46
72
|
* @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
|
|
47
73
|
* @returns {() => void} function to destroy response
|
|
48
74
|
*/
|
|
49
|
-
|
|
75
|
+
export const activate = function (options) {
|
|
50
76
|
var data = options.data;
|
|
51
77
|
var onError = options.onError;
|
|
52
78
|
var active = options.active;
|
|
53
|
-
var module = options.module;
|
|
54
79
|
errorHandlers.add(onError);
|
|
55
80
|
|
|
56
81
|
if (!compiling.has(data)) {
|
|
57
82
|
compiling.add(data);
|
|
58
|
-
|
|
83
|
+
sendActiveRequest();
|
|
59
84
|
}
|
|
60
85
|
|
|
61
|
-
if (!active && !
|
|
86
|
+
if (!active && !import.meta.webpackHot) {
|
|
62
87
|
console.log(
|
|
63
88
|
'Hot Module Replacement is not enabled. Waiting for process restart...',
|
|
64
89
|
);
|
|
@@ -67,6 +92,6 @@ exports.activate = function (options) {
|
|
|
67
92
|
return function () {
|
|
68
93
|
errorHandlers.delete(onError);
|
|
69
94
|
compiling.delete(data);
|
|
70
|
-
|
|
95
|
+
sendActiveRequest();
|
|
71
96
|
};
|
|
72
97
|
};
|
package/hot/log-apply-result.js
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { log, groupCollapsed, groupEnd } from './log.js';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* @param {(string | number)[]} updatedModules updated modules
|
|
8
10
|
* @param {(string | number)[] | null} renewedModules renewed modules
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
function logApplyResult(updatedModules, renewedModules) {
|
|
11
13
|
var unacceptedModules = updatedModules.filter(function (moduleId) {
|
|
12
14
|
return renewedModules && renewedModules.indexOf(moduleId) < 0;
|
|
13
15
|
});
|
|
14
|
-
var log = require('./log');
|
|
15
16
|
|
|
16
17
|
if (unacceptedModules.length > 0) {
|
|
17
18
|
log(
|
|
@@ -30,9 +31,9 @@ module.exports = function (updatedModules, renewedModules) {
|
|
|
30
31
|
renewedModules.forEach(function (moduleId) {
|
|
31
32
|
if (typeof moduleId === 'string' && moduleId.indexOf('!') !== -1) {
|
|
32
33
|
var parts = moduleId.split('!');
|
|
33
|
-
|
|
34
|
+
groupCollapsed('info', '[HMR] - ' + parts.pop());
|
|
34
35
|
log('info', '[HMR] - ' + moduleId);
|
|
35
|
-
|
|
36
|
+
groupEnd('info');
|
|
36
37
|
} else {
|
|
37
38
|
log('info', '[HMR] - ' + moduleId);
|
|
38
39
|
}
|
|
@@ -46,4 +47,6 @@ module.exports = function (updatedModules, renewedModules) {
|
|
|
46
47
|
'[HMR] Consider using the optimization.moduleIds: "named" for module names.',
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
|
-
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { logApplyResult };
|
package/hot/log.js
CHANGED
|
@@ -33,7 +33,7 @@ function logGroup(logFn) {
|
|
|
33
33
|
* @param {LogLevel} level log level
|
|
34
34
|
* @param {string|Error} msg message
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
function log(level, msg) {
|
|
37
37
|
if (shouldLog(level)) {
|
|
38
38
|
if (level === 'info') {
|
|
39
39
|
console.log(msg);
|
|
@@ -43,22 +43,22 @@ module.exports = function (level, msg) {
|
|
|
43
43
|
console.error(msg);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|
|
47
47
|
|
|
48
48
|
var group = console.group || dummy;
|
|
49
49
|
var groupCollapsed = console.groupCollapsed || dummy;
|
|
50
50
|
var groupEnd = console.groupEnd || dummy;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
export var group = logGroup(group);
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
export var groupCollapsed = logGroup(groupCollapsed);
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
export var groupEnd = logGroup(groupEnd);
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* @param {LogLevel} level log level
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
export var setLogLevel = function (level) {
|
|
62
62
|
logLevel = level;
|
|
63
63
|
};
|
|
64
64
|
|
|
@@ -66,7 +66,7 @@ module.exports.setLogLevel = function (level) {
|
|
|
66
66
|
* @param {Error} err error
|
|
67
67
|
* @returns {string} formatted error
|
|
68
68
|
*/
|
|
69
|
-
|
|
69
|
+
export var formatError = function (err) {
|
|
70
70
|
var message = err.message;
|
|
71
71
|
var stack = err.stack;
|
|
72
72
|
if (!stack) {
|
|
@@ -77,3 +77,13 @@ module.exports.formatError = function (err) {
|
|
|
77
77
|
return stack;
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
+
|
|
81
|
+
log.group = group;
|
|
82
|
+
log.groupCollapsed = groupCollapsed;
|
|
83
|
+
log.groupEnd = groupEnd;
|
|
84
|
+
log.setLogLevel = setLogLevel;
|
|
85
|
+
log.formatError = formatError;
|
|
86
|
+
|
|
87
|
+
// TODO: remove default export when rspack-dev-server refactored
|
|
88
|
+
export default log;
|
|
89
|
+
export { log };
|
package/hot/only-dev-server.js
CHANGED
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
5
|
/*globals __webpack_hash__ */
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
import { log, formatError } from './log.js';
|
|
8
|
+
import { emitter as hotEmitter } from './emitter.js';
|
|
9
|
+
import { logApplyResult } from './log-apply-result.js';
|
|
10
|
+
|
|
11
|
+
if (import.meta.webpackHot) {
|
|
7
12
|
/** @type {undefined|string} */
|
|
8
13
|
var lastHash;
|
|
9
14
|
var upToDate = function upToDate() {
|
|
10
15
|
return /** @type {string} */ (lastHash).indexOf(__webpack_hash__) >= 0;
|
|
11
16
|
};
|
|
12
|
-
var log = require('./log');
|
|
13
17
|
var check = function check() {
|
|
14
|
-
|
|
18
|
+
import.meta.webpackHot
|
|
15
19
|
.check()
|
|
16
20
|
.then(function (updatedModules) {
|
|
17
21
|
if (!updatedModules) {
|
|
@@ -23,7 +27,7 @@ if (module.hot) {
|
|
|
23
27
|
return;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
return
|
|
30
|
+
return import.meta.webpackHot
|
|
27
31
|
.apply({
|
|
28
32
|
ignoreUnaccepted: true,
|
|
29
33
|
ignoreDeclined: true,
|
|
@@ -59,7 +63,7 @@ if (module.hot) {
|
|
|
59
63
|
check();
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
logApplyResult(updatedModules, renewedModules);
|
|
63
67
|
|
|
64
68
|
if (upToDate()) {
|
|
65
69
|
log('info', '[HMR] App is up to date.');
|
|
@@ -67,23 +71,22 @@ if (module.hot) {
|
|
|
67
71
|
});
|
|
68
72
|
})
|
|
69
73
|
.catch(function (err) {
|
|
70
|
-
var status =
|
|
74
|
+
var status = import.meta.webpackHot.status();
|
|
71
75
|
if (['abort', 'fail'].indexOf(status) >= 0) {
|
|
72
76
|
log(
|
|
73
77
|
'warning',
|
|
74
78
|
'[HMR] Cannot check for update. Need to do a full reload!',
|
|
75
79
|
);
|
|
76
|
-
log('warning', '[HMR] ' +
|
|
80
|
+
log('warning', '[HMR] ' + formatError(err));
|
|
77
81
|
} else {
|
|
78
|
-
log('warning', '[HMR] Update check failed: ' +
|
|
82
|
+
log('warning', '[HMR] Update check failed: ' + formatError(err));
|
|
79
83
|
}
|
|
80
84
|
});
|
|
81
85
|
};
|
|
82
|
-
var hotEmitter = require('./emitter');
|
|
83
86
|
hotEmitter.on('webpackHotUpdate', function (currentHash) {
|
|
84
87
|
lastHash = currentHash;
|
|
85
88
|
if (!upToDate()) {
|
|
86
|
-
var status =
|
|
89
|
+
var status = import.meta.webpackHot.status();
|
|
87
90
|
if (status === 'idle') {
|
|
88
91
|
log('info', '[HMR] Checking for updates on the server...');
|
|
89
92
|
check();
|
package/hot/poll.js
CHANGED
|
@@ -3,33 +3,36 @@
|
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
5
|
/*globals __resourceQuery */
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
import { log, formatError } from './log.js';
|
|
8
|
+
import { logApplyResult } from './log-apply-result.js';
|
|
9
|
+
|
|
10
|
+
if (import.meta.webpackHot) {
|
|
7
11
|
var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
|
|
8
|
-
var log = require('./log');
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* @param {boolean=} fromUpdate true when called from update
|
|
12
15
|
*/
|
|
13
16
|
var checkForUpdate = function checkForUpdate(fromUpdate) {
|
|
14
|
-
if (
|
|
15
|
-
|
|
17
|
+
if (import.meta.webpackHot.status() === 'idle') {
|
|
18
|
+
import.meta.webpackHot
|
|
16
19
|
.check(true)
|
|
17
20
|
.then(function (updatedModules) {
|
|
18
21
|
if (!updatedModules) {
|
|
19
22
|
if (fromUpdate) log('info', '[HMR] Update applied.');
|
|
20
23
|
return;
|
|
21
24
|
}
|
|
22
|
-
|
|
25
|
+
logApplyResult(updatedModules, updatedModules);
|
|
23
26
|
checkForUpdate(true);
|
|
24
27
|
})
|
|
25
28
|
.catch(function (err) {
|
|
26
|
-
var status =
|
|
29
|
+
var status = import.meta.webpackHot.status();
|
|
27
30
|
if (['abort', 'fail'].indexOf(status) >= 0) {
|
|
28
31
|
log('warning', '[HMR] Cannot apply update.');
|
|
29
|
-
log('warning', '[HMR] ' +
|
|
32
|
+
log('warning', '[HMR] ' + formatError(err));
|
|
30
33
|
log('warning', '[HMR] You need to restart the application!');
|
|
31
34
|
} else {
|
|
32
|
-
log('warning', '[HMR] Update failed: ' +
|
|
35
|
+
log('warning', '[HMR] Update failed: ' + formatError(err));
|
|
33
36
|
}
|
|
34
37
|
});
|
|
35
38
|
}
|
package/hot/signal.js
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
5
|
/*globals __resourceQuery */
|
|
6
|
-
if (module.hot) {
|
|
7
|
-
var log = require('./log');
|
|
8
6
|
|
|
7
|
+
import { log, formatError } from './log.js';
|
|
8
|
+
import { logApplyResult } from './log-apply-result.js';
|
|
9
|
+
|
|
10
|
+
if (import.meta.webpackHot) {
|
|
9
11
|
/**
|
|
10
12
|
* @param {boolean=} fromUpdate true when called from update
|
|
11
13
|
*/
|
|
12
14
|
var checkForUpdate = function checkForUpdate(fromUpdate) {
|
|
13
|
-
|
|
15
|
+
import.meta.webpackHot
|
|
14
16
|
.check()
|
|
15
17
|
.then(function (updatedModules) {
|
|
16
18
|
if (!updatedModules) {
|
|
@@ -19,7 +21,7 @@ if (module.hot) {
|
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
return
|
|
24
|
+
return import.meta.webpackHot
|
|
23
25
|
.apply({
|
|
24
26
|
ignoreUnaccepted: true,
|
|
25
27
|
onUnaccepted: function (data) {
|
|
@@ -31,17 +33,17 @@ if (module.hot) {
|
|
|
31
33
|
},
|
|
32
34
|
})
|
|
33
35
|
.then(function (renewedModules) {
|
|
34
|
-
|
|
36
|
+
logApplyResult(updatedModules, renewedModules);
|
|
35
37
|
|
|
36
38
|
checkForUpdate(true);
|
|
37
39
|
return null;
|
|
38
40
|
});
|
|
39
41
|
})
|
|
40
42
|
.catch(function (err) {
|
|
41
|
-
var status =
|
|
43
|
+
var status = import.meta.webpackHot.status();
|
|
42
44
|
if (['abort', 'fail'].indexOf(status) >= 0) {
|
|
43
45
|
log('warning', '[HMR] Cannot apply update.');
|
|
44
|
-
log('warning', '[HMR] ' +
|
|
46
|
+
log('warning', '[HMR] ' + formatError(err));
|
|
45
47
|
log('warning', '[HMR] You need to restart the application!');
|
|
46
48
|
} else {
|
|
47
49
|
log('warning', '[HMR] Update failed: ' + (err.stack || err.message));
|
|
@@ -50,10 +52,12 @@ if (module.hot) {
|
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
process.on(__resourceQuery.slice(1) || 'SIGUSR2', function () {
|
|
53
|
-
if (
|
|
55
|
+
if (import.meta.webpackHot.status() !== 'idle') {
|
|
54
56
|
log(
|
|
55
57
|
'warning',
|
|
56
|
-
'[HMR] Got signal but currently in ' +
|
|
58
|
+
'[HMR] Got signal but currently in ' +
|
|
59
|
+
import.meta.webpackHot.status() +
|
|
60
|
+
' state.',
|
|
57
61
|
);
|
|
58
62
|
log('warning', '[HMR] Need to be in idle state to start hot update.');
|
|
59
63
|
return;
|