@rspack/core 1.7.2 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Compiler } from '../Compiler';
|
|
2
2
|
import { type ModuleFederationManifestPluginOptions } from './ModuleFederationManifestPlugin';
|
|
3
3
|
import type { ModuleFederationPluginV1Options } from './ModuleFederationPluginV1';
|
|
4
|
+
import { type ModuleFederationRuntimeExperimentsOptions } from './ModuleFederationRuntimePlugin';
|
|
4
5
|
export interface ModuleFederationPluginOptions extends Omit<ModuleFederationPluginV1Options, 'enhanced'> {
|
|
5
6
|
runtimePlugins?: RuntimePlugins;
|
|
6
7
|
implementation?: string;
|
|
7
8
|
shareStrategy?: 'version-first' | 'loaded-first';
|
|
8
9
|
manifest?: boolean | Omit<ModuleFederationManifestPluginOptions, 'remoteAliasMap' | 'globalName' | 'name' | 'exposes' | 'shared'>;
|
|
10
|
+
experiments?: ModuleFederationRuntimeExperimentsOptions;
|
|
9
11
|
}
|
|
10
12
|
export type RuntimePlugins = string[] | [string, Record<string, unknown>][];
|
|
11
13
|
export declare class ModuleFederationPlugin {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
export interface ModuleFederationRuntimeExperimentsOptions {
|
|
2
|
+
asyncStartup?: boolean;
|
|
3
|
+
}
|
|
1
4
|
export interface ModuleFederationRuntimeOptions {
|
|
2
5
|
entryRuntime?: string;
|
|
6
|
+
experiments?: ModuleFederationRuntimeExperimentsOptions;
|
|
3
7
|
}
|
|
4
8
|
export declare const ModuleFederationRuntimePlugin: {
|
|
5
9
|
new (options?: ModuleFederationRuntimeOptions | undefined): {
|
package/dist/index.js
CHANGED
|
@@ -731,6 +731,17 @@ for(var __rspack_i in (()=>{
|
|
|
731
731
|
compilation: this.compilation,
|
|
732
732
|
getStatsCompilation: (compilation)=>{
|
|
733
733
|
if (statsCompilationMap.has(compilation)) return statsCompilationMap.get(compilation);
|
|
734
|
+
if (this.compilation !== this.compilation.compiler._lastCompilation) return {
|
|
735
|
+
assets: [],
|
|
736
|
+
assetsByChunkName: [],
|
|
737
|
+
chunks: [],
|
|
738
|
+
entrypoints: [],
|
|
739
|
+
errors: [],
|
|
740
|
+
hash: 'XXXX',
|
|
741
|
+
modules: [],
|
|
742
|
+
namedChunkGroups: [],
|
|
743
|
+
warnings: []
|
|
744
|
+
};
|
|
734
745
|
let innerStats = this.#getInnerByCompilation(compilation);
|
|
735
746
|
options.warnings = !1;
|
|
736
747
|
let innerStatsCompilation = innerStats.toJson(options);
|
|
@@ -746,6 +757,17 @@ for(var __rspack_i in (()=>{
|
|
|
746
757
|
compilation: this.compilation,
|
|
747
758
|
getStatsCompilation: (compilation)=>{
|
|
748
759
|
if (statsCompilationMap.has(compilation)) return statsCompilationMap.get(compilation);
|
|
760
|
+
if (this.compilation !== this.compilation.compiler._lastCompilation) return {
|
|
761
|
+
assets: [],
|
|
762
|
+
assetsByChunkName: [],
|
|
763
|
+
chunks: [],
|
|
764
|
+
entrypoints: [],
|
|
765
|
+
errors: [],
|
|
766
|
+
hash: 'XXXX',
|
|
767
|
+
modules: [],
|
|
768
|
+
namedChunkGroups: [],
|
|
769
|
+
warnings: []
|
|
770
|
+
};
|
|
749
771
|
let innerStatsCompilation = this.#getInnerByCompilation(compilation).toJson(options);
|
|
750
772
|
return statsCompilationMap.set(compilation, innerStatsCompilation), innerStatsCompilation;
|
|
751
773
|
},
|
|
@@ -4510,16 +4532,44 @@ Plugins which provide custom chunk loading types must call EnableChunkLoadingPlu
|
|
|
4510
4532
|
}
|
|
4511
4533
|
let lazyCompilationMiddlewareInternal = (compiler, activeModules, lazyCompilationPrefix)=>{
|
|
4512
4534
|
let logger = compiler.getInfrastructureLogger('LazyCompilation');
|
|
4513
|
-
return (req, res, next)=>{
|
|
4514
|
-
if (!req.url?.startsWith(lazyCompilationPrefix)) return next?.();
|
|
4515
|
-
let modules =
|
|
4516
|
-
|
|
4535
|
+
return async (req, res, next)=>{
|
|
4536
|
+
if (!req.url?.startsWith(lazyCompilationPrefix) || 'POST' !== req.method) return next?.();
|
|
4537
|
+
let modules = [];
|
|
4538
|
+
try {
|
|
4539
|
+
modules = await function(req) {
|
|
4540
|
+
if (void 0 !== req.body) {
|
|
4541
|
+
if (Array.isArray(req.body)) return Promise.resolve(req.body);
|
|
4542
|
+
if ('string' == typeof req.body) return Promise.resolve(req.body.split('\n').filter(Boolean));
|
|
4543
|
+
throw Error('Invalid body type');
|
|
4544
|
+
}
|
|
4545
|
+
return new Promise((resolve, reject)=>{
|
|
4546
|
+
if (req.aborted || req.destroyed) return void reject(Error('Request was aborted before body could be read'));
|
|
4547
|
+
let cleanup = ()=>{
|
|
4548
|
+
req.removeListener('data', onData), req.removeListener('end', onEnd), req.removeListener('error', onError), req.removeListener('close', onClose), req.removeListener('aborted', onAborted);
|
|
4549
|
+
}, chunks = [], onData = (chunk)=>{
|
|
4550
|
+
chunks.push(chunk);
|
|
4551
|
+
}, onEnd = ()=>{
|
|
4552
|
+
cleanup(), resolve(Buffer.concat(chunks).toString('utf8').split('\n').filter(Boolean));
|
|
4553
|
+
}, onError = (err)=>{
|
|
4554
|
+
cleanup(), reject(err);
|
|
4555
|
+
}, onClose = ()=>{
|
|
4556
|
+
cleanup(), reject(Error('Request was closed before body could be read'));
|
|
4557
|
+
}, onAborted = ()=>{
|
|
4558
|
+
cleanup(), reject(Error('Request was aborted before body could be read'));
|
|
4559
|
+
};
|
|
4560
|
+
req.on('data', onData), req.on('end', onEnd), req.on('error', onError), req.on('close', onClose), req.on('aborted', onAborted);
|
|
4561
|
+
});
|
|
4562
|
+
}(req);
|
|
4563
|
+
} catch (err) {
|
|
4564
|
+
logger.error('Failed to parse request body: ' + err), res.writeHead(400), res.end('Bad Request');
|
|
4565
|
+
return;
|
|
4566
|
+
}
|
|
4517
4567
|
let moduleActivated = [];
|
|
4518
4568
|
for (let key of modules){
|
|
4519
4569
|
let activated = activeModules.has(key);
|
|
4520
4570
|
activeModules.add(key), activated || (logger.log(`${key} is now in use and will be compiled.`), moduleActivated.push(key));
|
|
4521
4571
|
}
|
|
4522
|
-
moduleActivated.length && compiler.watching && compiler.watching.invalidate();
|
|
4572
|
+
moduleActivated.length && compiler.watching && compiler.watching.invalidate(), res.writeHead(200), res.write('\n'), res.end();
|
|
4523
4573
|
};
|
|
4524
4574
|
};
|
|
4525
4575
|
class MangleExportsPlugin extends RspackBuiltinPlugin {
|
|
@@ -5854,7 +5904,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
5854
5904
|
}, applyExperimentsDefaults = (experiments, { development })=>{
|
|
5855
5905
|
F(experiments, 'cache', ()=>development), D(experiments, 'futureDefaults', !1), D(experiments, 'lazyCompilation', !1), D(experiments, 'asyncWebAssembly', experiments.futureDefaults), D(experiments, 'css', !!experiments.futureDefaults || void 0), D(experiments, 'topLevelAwait', !0), D(experiments, 'deferImport', !1), D(experiments, 'buildHttp', void 0), experiments.buildHttp && 'object' == typeof experiments.buildHttp && D(experiments.buildHttp, 'upgrade', !1), D(experiments, 'incremental', {}), 'object' == typeof experiments.incremental && (D(experiments.incremental, 'silent', !0), D(experiments.incremental, 'make', !0), D(experiments.incremental, 'inferAsyncModules', !0), D(experiments.incremental, 'providedExports', !0), D(experiments.incremental, 'dependenciesDiagnostics', !0), D(experiments.incremental, 'sideEffects', !0), D(experiments.incremental, 'buildChunkGraph', !1), D(experiments.incremental, 'moduleIds', !0), D(experiments.incremental, 'chunkIds', !0), D(experiments.incremental, 'modulesHashes', !0), D(experiments.incremental, 'modulesCodegen', !0), D(experiments.incremental, 'modulesRuntimeRequirements', !0), D(experiments.incremental, 'chunksRuntimeRequirements', !0), D(experiments.incremental, 'chunksHashes', !0), D(experiments.incremental, 'chunksRender', !0), D(experiments.incremental, 'emitAssets', !0)), D(experiments, 'rspackFuture', {}), D(experiments, 'parallelLoader', !1), D(experiments, 'useInputFileSystem', !1), D(experiments, 'inlineConst', !0), D(experiments, 'inlineEnum', !1), D(experiments, 'typeReexportsPresence', !1), D(experiments, 'lazyBarrel', !0);
|
|
5856
5906
|
}, applybundlerInfoDefaults = (rspackFuture, library)=>{
|
|
5857
|
-
'object' == typeof rspackFuture && (D(rspackFuture, 'bundlerInfo', {}), 'object' == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, 'version', "1.7.
|
|
5907
|
+
'object' == typeof rspackFuture && (D(rspackFuture, 'bundlerInfo', {}), 'object' == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, 'version', "1.7.4"), D(rspackFuture.bundlerInfo, 'bundler', 'rspack'), D(rspackFuture.bundlerInfo, 'force', !library)));
|
|
5858
5908
|
}, applySnapshotDefaults = (_snapshot, _env)=>{}, applyCssGeneratorOptionsDefaults = (generatorOptions, { targetProperties })=>{
|
|
5859
5909
|
D(generatorOptions, 'exportsOnly', !targetProperties || !1 === targetProperties.document), D(generatorOptions, 'esModule', !0);
|
|
5860
5910
|
}, applyModuleDefaults = (module1, { cache, asyncWebAssembly, css, targetProperties, mode, uniqueName, deferImport })=>{
|
|
@@ -7392,10 +7442,10 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
7392
7442
|
hasWarnings() {
|
|
7393
7443
|
return this.stats.some((stat)=>stat.hasWarnings());
|
|
7394
7444
|
}
|
|
7395
|
-
#createChildOptions(options
|
|
7445
|
+
#createChildOptions(options, context) {
|
|
7396
7446
|
let { children: childrenOptions, ...baseOptions } = 'string' == typeof options || 'boolean' == typeof options ? {
|
|
7397
7447
|
preset: options
|
|
7398
|
-
} : options, children = this.stats.map((stat, idx)=>{
|
|
7448
|
+
} : options ?? {}, children = this.stats.map((stat, idx)=>{
|
|
7399
7449
|
let childOptions = Array.isArray(childrenOptions) ? childrenOptions[idx] : childrenOptions;
|
|
7400
7450
|
return stat.compilation.createStatsOptions({
|
|
7401
7451
|
...baseOptions,
|
|
@@ -7422,7 +7472,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
7422
7472
|
obj.children = this.stats.map((stat, idx)=>{
|
|
7423
7473
|
let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
|
|
7424
7474
|
return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
|
|
7425
|
-
}), childOptions.version && (obj.rspackVersion = "1.7.
|
|
7475
|
+
}), childOptions.version && (obj.rspackVersion = "1.7.4", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
|
|
7426
7476
|
let mapError = (j, obj)=>({
|
|
7427
7477
|
...obj,
|
|
7428
7478
|
compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
|
|
@@ -8581,15 +8631,21 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
8581
8631
|
if (context.makePathsRelative || (context.makePathsRelative = makePathsRelative.bindContextCache(compilation.compiler.context, compilation.compiler.root)), !context.cachedGetErrors) {
|
|
8582
8632
|
let map = new WeakMap();
|
|
8583
8633
|
context.cachedGetErrors = (compilation)=>{
|
|
8584
|
-
|
|
8585
|
-
|
|
8634
|
+
if (compilation.compiler._lastCompilation !== compilation) return [];
|
|
8635
|
+
let cache = map.get(compilation);
|
|
8636
|
+
if (cache) return cache;
|
|
8637
|
+
let errors = statsCompilation.errors;
|
|
8638
|
+
return map.set(compilation, errors), errors;
|
|
8586
8639
|
};
|
|
8587
8640
|
}
|
|
8588
8641
|
if (!context.cachedGetWarnings) {
|
|
8589
8642
|
let map = new WeakMap();
|
|
8590
8643
|
context.cachedGetWarnings = (compilation)=>{
|
|
8591
|
-
|
|
8592
|
-
|
|
8644
|
+
if (compilation.compiler._lastCompilation !== compilation) return [];
|
|
8645
|
+
let cache = map.get(compilation);
|
|
8646
|
+
if (cache) return cache;
|
|
8647
|
+
let warnings = compilation.__internal_getInner().createStatsWarnings(compilation.getWarnings(), !!options.colors);
|
|
8648
|
+
return map.set(compilation, warnings), warnings;
|
|
8593
8649
|
};
|
|
8594
8650
|
}
|
|
8595
8651
|
compilation.name && (object.name = compilation.name);
|
|
@@ -8678,7 +8734,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
8678
8734
|
object.hash = context.getStatsCompilation(compilation).hash;
|
|
8679
8735
|
},
|
|
8680
8736
|
version: (object)=>{
|
|
8681
|
-
object.version = "5.75.0", object.rspackVersion = "1.7.
|
|
8737
|
+
object.version = "5.75.0", object.rspackVersion = "1.7.4";
|
|
8682
8738
|
},
|
|
8683
8739
|
env: (object, _compilation, _context, { _env })=>{
|
|
8684
8740
|
object.env = _env;
|
|
@@ -10403,7 +10459,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
10403
10459
|
});
|
|
10404
10460
|
}
|
|
10405
10461
|
}
|
|
10406
|
-
let CORE_VERSION = "1.7.
|
|
10462
|
+
let CORE_VERSION = "1.7.4", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
|
|
10407
10463
|
|
|
10408
10464
|
Help:
|
|
10409
10465
|
Looks like you are using a custom binding (via environment variable 'RSPACK_BINDING=${process.env.RSPACK_BINDING}').
|
|
@@ -12172,12 +12228,16 @@ Help:
|
|
|
12172
12228
|
};
|
|
12173
12229
|
}
|
|
12174
12230
|
raw(compiler) {
|
|
12175
|
-
let { remoteType, remotes } = this._options, remoteExternals = {};
|
|
12231
|
+
let { remoteType, remotes } = this._options, remoteExternals = {}, importExternals = {};
|
|
12176
12232
|
for (let [key, config] of remotes){
|
|
12177
12233
|
let i = 0;
|
|
12178
|
-
for (let external of config.external)
|
|
12234
|
+
for (let external of config.external){
|
|
12235
|
+
if (external.startsWith('internal ')) continue;
|
|
12236
|
+
let request = `webpack/container/reference/${key}${i ? `/fallback-${i}` : ''}`;
|
|
12237
|
+
('module' === remoteType || 'module-import' === remoteType) && external.startsWith('.') ? importExternals[request] = external : remoteExternals[request] = external, i++;
|
|
12238
|
+
}
|
|
12179
12239
|
}
|
|
12180
|
-
new ExternalsPlugin(remoteType, remoteExternals, !0).apply(compiler), new ShareRuntimePlugin(this._options.enhanced).apply(compiler);
|
|
12240
|
+
new ExternalsPlugin(remoteType, remoteExternals, !0).apply(compiler), Object.keys(importExternals).length > 0 && new ExternalsPlugin('import', importExternals, !0).apply(compiler), new ShareRuntimePlugin(this._options.enhanced).apply(compiler);
|
|
12181
12241
|
let rawOptions = {
|
|
12182
12242
|
remoteType: this._options.remoteType,
|
|
12183
12243
|
remotes: this._options.remotes.map(([key, r])=>({
|
|
@@ -12197,7 +12257,7 @@ Help:
|
|
|
12197
12257
|
let _options = JSON.stringify(options || {});
|
|
12198
12258
|
return binding_default().transform(source, _options);
|
|
12199
12259
|
}
|
|
12200
|
-
let exports_rspackVersion = "1.7.
|
|
12260
|
+
let exports_rspackVersion = "1.7.4", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
|
|
12201
12261
|
getNormalizedRspackOptions: getNormalizedRspackOptions,
|
|
12202
12262
|
applyRspackOptionsDefaults: applyRspackOptionsDefaults,
|
|
12203
12263
|
getNormalizedWebpackOptions: getNormalizedRspackOptions,
|
|
@@ -12258,34 +12318,49 @@ Help:
|
|
|
12258
12318
|
bundlerRuntime: bundlerRuntimePath,
|
|
12259
12319
|
runtime: runtimePath
|
|
12260
12320
|
});
|
|
12261
|
-
|
|
12321
|
+
compiler.options.resolve.alias = {
|
|
12262
12322
|
'@module-federation/runtime-tools': paths.runtimeTools,
|
|
12263
12323
|
'@module-federation/runtime': paths.runtime,
|
|
12264
12324
|
...compiler.options.resolve.alias
|
|
12265
|
-
}
|
|
12266
|
-
|
|
12267
|
-
|
|
12268
|
-
|
|
12269
|
-
|
|
12270
|
-
|
|
12271
|
-
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
|
|
12276
|
-
|
|
12277
|
-
|
|
12278
|
-
|
|
12279
|
-
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12325
|
+
};
|
|
12326
|
+
let entryRuntime = function(paths, options, compiler) {
|
|
12327
|
+
let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [];
|
|
12328
|
+
for(let i = 0; i < runtimePlugins.length; i++){
|
|
12329
|
+
let runtimePluginVar = `__module_federation_runtime_plugin_${i}__`, pluginSpec = runtimePlugins[i], pluginPath = Array.isArray(pluginSpec) ? pluginSpec[0] : pluginSpec, pluginParams = Array.isArray(pluginSpec) ? pluginSpec[1] : void 0;
|
|
12330
|
+
runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
|
|
12331
|
+
let paramsCode = void 0 === pluginParams ? 'undefined' : JSON.stringify(pluginParams);
|
|
12332
|
+
runtimePluginVars.push(`{ plugin: ${runtimePluginVar}, params: ${paramsCode} }`);
|
|
12333
|
+
}
|
|
12334
|
+
let content = [
|
|
12335
|
+
`import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
|
|
12336
|
+
...runtimePluginImports,
|
|
12337
|
+
`const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(', ')}].filter(({ plugin }) => plugin).map(({ plugin, params }) => plugin(params))`,
|
|
12338
|
+
`const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
|
|
12339
|
+
`const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
|
|
12340
|
+
`const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? 'version-first')}`,
|
|
12341
|
+
compiler.webpack.Template.getFunctionContent(__webpack_require__("./moduleFederationDefaultRuntime.js"))
|
|
12342
|
+
].join(';');
|
|
12343
|
+
return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
|
|
12344
|
+
}(paths, this._options, compiler), asyncStartup = this._options.experiments?.asyncStartup ?? !1;
|
|
12345
|
+
new ModuleFederationRuntimePlugin({
|
|
12346
|
+
entryRuntime,
|
|
12347
|
+
experiments: {
|
|
12348
|
+
asyncStartup
|
|
12349
|
+
}
|
|
12350
|
+
}).apply(compiler);
|
|
12351
|
+
let v1Options = {
|
|
12352
|
+
name: this._options.name,
|
|
12353
|
+
exposes: this._options.exposes,
|
|
12354
|
+
filename: this._options.filename,
|
|
12355
|
+
library: this._options.library,
|
|
12356
|
+
remoteType: this._options.remoteType,
|
|
12357
|
+
remotes: this._options.remotes,
|
|
12358
|
+
runtime: this._options.runtime,
|
|
12359
|
+
shareScope: this._options.shareScope,
|
|
12360
|
+
shared: this._options.shared,
|
|
12287
12361
|
enhanced: !0
|
|
12288
|
-
}
|
|
12362
|
+
};
|
|
12363
|
+
if (new webpack.container.ModuleFederationPluginV1(v1Options).apply(compiler), this._options.manifest) {
|
|
12289
12364
|
let manifestOptions = !0 === this._options.manifest ? {} : {
|
|
12290
12365
|
...this._options.manifest
|
|
12291
12366
|
}, containerName = manifestOptions.name ?? this._options.name, globalName = manifestOptions.globalName ?? function(library) {
|
|
@@ -1,4 +1,79 @@
|
|
|
1
1
|
var urlBase = decodeURIComponent(__resourceQuery.slice(1));
|
|
2
|
+
var compiling = new Set();
|
|
3
|
+
var errorHandlers = new Set();
|
|
4
|
+
|
|
5
|
+
/** @type {import("http").ClientRequest | undefined} */
|
|
6
|
+
var pendingRequest;
|
|
7
|
+
/** @type {boolean} */
|
|
8
|
+
var hasPendingUpdate = false;
|
|
9
|
+
|
|
10
|
+
function sendRequest() {
|
|
11
|
+
if (compiling.size === 0) {
|
|
12
|
+
hasPendingUpdate = false;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var modules = Array.from(compiling);
|
|
17
|
+
var data = modules.join('\n');
|
|
18
|
+
|
|
19
|
+
var httpModule = urlBase.startsWith('https')
|
|
20
|
+
? require('https')
|
|
21
|
+
: require('http');
|
|
22
|
+
|
|
23
|
+
var request = httpModule.request(
|
|
24
|
+
urlBase,
|
|
25
|
+
{
|
|
26
|
+
method: 'POST',
|
|
27
|
+
agent: false,
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'text/plain',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
function (res) {
|
|
33
|
+
pendingRequest = undefined;
|
|
34
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
35
|
+
var error = new Error(
|
|
36
|
+
'Problem communicating active modules to the server: HTTP ' +
|
|
37
|
+
res.statusCode,
|
|
38
|
+
);
|
|
39
|
+
errorHandlers.forEach(function (onError) {
|
|
40
|
+
onError(error);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// Consume response data to free up memory
|
|
44
|
+
res.resume();
|
|
45
|
+
if (hasPendingUpdate) {
|
|
46
|
+
hasPendingUpdate = false;
|
|
47
|
+
sendRequest();
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
pendingRequest = request;
|
|
53
|
+
|
|
54
|
+
request.on('error', function (err) {
|
|
55
|
+
pendingRequest = undefined;
|
|
56
|
+
var error = new Error(
|
|
57
|
+
'Problem communicating active modules to the server: ' + err.message,
|
|
58
|
+
);
|
|
59
|
+
errorHandlers.forEach(function (onError) {
|
|
60
|
+
onError(error);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
request.write(data);
|
|
65
|
+
request.end();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function sendActiveRequest() {
|
|
69
|
+
hasPendingUpdate = true;
|
|
70
|
+
|
|
71
|
+
// If no request is pending, start one
|
|
72
|
+
if (!pendingRequest) {
|
|
73
|
+
hasPendingUpdate = false;
|
|
74
|
+
sendRequest();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
2
77
|
|
|
3
78
|
/**
|
|
4
79
|
* @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
|
|
@@ -9,42 +84,23 @@ exports.activate = function (options) {
|
|
|
9
84
|
var onError = options.onError;
|
|
10
85
|
var active = options.active;
|
|
11
86
|
var module = options.module;
|
|
12
|
-
/** @type {import("http").IncomingMessage} */
|
|
13
|
-
var response;
|
|
14
|
-
var request = (
|
|
15
|
-
urlBase.startsWith('https') ? require('https') : require('http')
|
|
16
|
-
).request(
|
|
17
|
-
urlBase + encodeURIComponent(data),
|
|
18
|
-
{
|
|
19
|
-
agent: false,
|
|
20
|
-
headers: { accept: 'text/event-stream' },
|
|
21
|
-
},
|
|
22
|
-
function (res) {
|
|
23
|
-
response = res;
|
|
24
|
-
response.on('error', errorHandler);
|
|
25
|
-
if (!active && !module.hot) {
|
|
26
|
-
console.log(
|
|
27
|
-
'Hot Module Replacement is not enabled. Waiting for process restart...',
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
);
|
|
32
87
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
'Problem communicating active modules to the server' +
|
|
39
|
-
(err.message ? ': ' + err.message : '') +
|
|
40
|
-
'\nRequest: ' +
|
|
41
|
-
urlBase +
|
|
42
|
-
data;
|
|
43
|
-
onError(err);
|
|
88
|
+
errorHandlers.add(onError);
|
|
89
|
+
|
|
90
|
+
if (!compiling.has(data)) {
|
|
91
|
+
compiling.add(data);
|
|
92
|
+
sendActiveRequest();
|
|
44
93
|
}
|
|
45
|
-
|
|
46
|
-
|
|
94
|
+
|
|
95
|
+
if (!active && !module.hot) {
|
|
96
|
+
console.log(
|
|
97
|
+
'Hot Module Replacement is not enabled. Waiting for process restart...',
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
47
101
|
return function () {
|
|
48
|
-
|
|
102
|
+
errorHandlers.delete(onError);
|
|
103
|
+
compiling.delete(data);
|
|
104
|
+
sendActiveRequest();
|
|
49
105
|
};
|
|
50
106
|
};
|
|
@@ -1,47 +1,73 @@
|
|
|
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
|
|
@@ -55,7 +81,7 @@ exports.activate = function (options) {
|
|
|
55
81
|
|
|
56
82
|
if (!compiling.has(data)) {
|
|
57
83
|
compiling.add(data);
|
|
58
|
-
|
|
84
|
+
sendActiveRequest();
|
|
59
85
|
}
|
|
60
86
|
|
|
61
87
|
if (!active && !module.hot) {
|
|
@@ -67,6 +93,6 @@ exports.activate = function (options) {
|
|
|
67
93
|
return function () {
|
|
68
94
|
errorHandlers.delete(onError);
|
|
69
95
|
compiling.delete(data);
|
|
70
|
-
|
|
96
|
+
sendActiveRequest();
|
|
71
97
|
};
|
|
72
98
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/core",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"webpackVersion": "5.75.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "The fast Rust-based web bundler with webpack-compatible API",
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
"directory": "packages/rspack"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@ast-grep/napi": "^0.40.
|
|
40
|
+
"@ast-grep/napi": "^0.40.5",
|
|
41
41
|
"@napi-rs/wasm-runtime": "1.0.7",
|
|
42
42
|
"@rsbuild/plugin-node-polyfill": "^1.4.2",
|
|
43
|
-
"@rslib/core": "0.19.
|
|
43
|
+
"@rslib/core": "0.19.2",
|
|
44
44
|
"@swc/types": "0.1.25",
|
|
45
|
-
"@types/node": "^20.19.
|
|
45
|
+
"@types/node": "^20.19.29",
|
|
46
46
|
"@types/watchpack": "^2.4.5",
|
|
47
47
|
"browserslist-load-config": "^1.0.1",
|
|
48
48
|
"enhanced-resolve": "5.18.4",
|
|
49
49
|
"glob-to-regexp": "^0.4.1",
|
|
50
|
-
"memfs": "4.
|
|
50
|
+
"memfs": "4.53.0",
|
|
51
51
|
"prebundle": "^1.6.0",
|
|
52
52
|
"tinypool": "^1.1.1",
|
|
53
53
|
"tsx": "^4.21.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@module-federation/runtime-tools": "0.22.0",
|
|
60
60
|
"@rspack/lite-tapable": "1.1.0",
|
|
61
|
-
"@rspack/binding": "1.7.
|
|
61
|
+
"@rspack/binding": "1.7.4"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"@swc/helpers": ">=0.5.1"
|