@rspack-canary/core 1.7.3-canary-58d41d16-20260115035302 → 1.7.3-canary-1138ed18-20260115124957

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/index.js CHANGED
@@ -4510,16 +4510,44 @@ Plugins which provide custom chunk loading types must call EnableChunkLoadingPlu
4510
4510
  }
4511
4511
  let lazyCompilationMiddlewareInternal = (compiler, activeModules, lazyCompilationPrefix)=>{
4512
4512
  let logger = compiler.getInfrastructureLogger('LazyCompilation');
4513
- return (req, res, next)=>{
4514
- if (!req.url?.startsWith(lazyCompilationPrefix)) return next?.();
4515
- let modules = req.url.slice(lazyCompilationPrefix.length).split('@').map(decodeURIComponent);
4516
- req.socket.setNoDelay(!0), res.setHeader('content-type', 'text/event-stream'), res.writeHead(200), res.write('\n');
4513
+ return async (req, res, next)=>{
4514
+ if (!req.url?.startsWith(lazyCompilationPrefix) || 'POST' !== req.method) return next?.();
4515
+ let modules = [];
4516
+ try {
4517
+ modules = await function(req) {
4518
+ if (void 0 !== req.body) {
4519
+ if (Array.isArray(req.body)) return Promise.resolve(req.body);
4520
+ if ('string' == typeof req.body) return Promise.resolve(req.body.split('\n').filter(Boolean));
4521
+ throw Error('Invalid body type');
4522
+ }
4523
+ return new Promise((resolve, reject)=>{
4524
+ if (req.aborted || req.destroyed) return void reject(Error('Request was aborted before body could be read'));
4525
+ let cleanup = ()=>{
4526
+ req.removeListener('data', onData), req.removeListener('end', onEnd), req.removeListener('error', onError), req.removeListener('close', onClose), req.removeListener('aborted', onAborted);
4527
+ }, chunks = [], onData = (chunk)=>{
4528
+ chunks.push(chunk);
4529
+ }, onEnd = ()=>{
4530
+ cleanup(), resolve(Buffer.concat(chunks).toString('utf8').split('\n').filter(Boolean));
4531
+ }, onError = (err)=>{
4532
+ cleanup(), reject(err);
4533
+ }, onClose = ()=>{
4534
+ cleanup(), reject(Error('Request was closed before body could be read'));
4535
+ }, onAborted = ()=>{
4536
+ cleanup(), reject(Error('Request was aborted before body could be read'));
4537
+ };
4538
+ req.on('data', onData), req.on('end', onEnd), req.on('error', onError), req.on('close', onClose), req.on('aborted', onAborted);
4539
+ });
4540
+ }(req);
4541
+ } catch (err) {
4542
+ logger.error('Failed to parse request body: ' + err), res.writeHead(400), res.end('Bad Request');
4543
+ return;
4544
+ }
4517
4545
  let moduleActivated = [];
4518
4546
  for (let key of modules){
4519
4547
  let activated = activeModules.has(key);
4520
4548
  activeModules.add(key), activated || (logger.log(`${key} is now in use and will be compiled.`), moduleActivated.push(key));
4521
4549
  }
4522
- moduleActivated.length && compiler.watching && compiler.watching.invalidate();
4550
+ moduleActivated.length && compiler.watching && compiler.watching.invalidate(), res.writeHead(200), res.write('\n'), res.end();
4523
4551
  };
4524
4552
  };
4525
4553
  class MangleExportsPlugin extends RspackBuiltinPlugin {
@@ -5854,7 +5882,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
5854
5882
  }, applyExperimentsDefaults = (experiments, { development })=>{
5855
5883
  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
5884
  }, applybundlerInfoDefaults = (rspackFuture, library)=>{
5857
- 'object' == typeof rspackFuture && (D(rspackFuture, 'bundlerInfo', {}), 'object' == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, 'version', "1.7.3-canary-58d41d16-20260115035302"), D(rspackFuture.bundlerInfo, 'bundler', 'rspack'), D(rspackFuture.bundlerInfo, 'force', !library)));
5885
+ 'object' == typeof rspackFuture && (D(rspackFuture, 'bundlerInfo', {}), 'object' == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, 'version', "1.7.3-canary-1138ed18-20260115124957"), D(rspackFuture.bundlerInfo, 'bundler', 'rspack'), D(rspackFuture.bundlerInfo, 'force', !library)));
5858
5886
  }, applySnapshotDefaults = (_snapshot, _env)=>{}, applyCssGeneratorOptionsDefaults = (generatorOptions, { targetProperties })=>{
5859
5887
  D(generatorOptions, 'exportsOnly', !targetProperties || !1 === targetProperties.document), D(generatorOptions, 'esModule', !0);
5860
5888
  }, applyModuleDefaults = (module1, { cache, asyncWebAssembly, css, targetProperties, mode, uniqueName, deferImport })=>{
@@ -7392,10 +7420,10 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
7392
7420
  hasWarnings() {
7393
7421
  return this.stats.some((stat)=>stat.hasWarnings());
7394
7422
  }
7395
- #createChildOptions(options = {}, context) {
7423
+ #createChildOptions(options, context) {
7396
7424
  let { children: childrenOptions, ...baseOptions } = 'string' == typeof options || 'boolean' == typeof options ? {
7397
7425
  preset: options
7398
- } : options, children = this.stats.map((stat, idx)=>{
7426
+ } : options ?? {}, children = this.stats.map((stat, idx)=>{
7399
7427
  let childOptions = Array.isArray(childrenOptions) ? childrenOptions[idx] : childrenOptions;
7400
7428
  return stat.compilation.createStatsOptions({
7401
7429
  ...baseOptions,
@@ -7422,7 +7450,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
7422
7450
  obj.children = this.stats.map((stat, idx)=>{
7423
7451
  let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
7424
7452
  return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
7425
- }), childOptions.version && (obj.rspackVersion = "1.7.3-canary-58d41d16-20260115035302", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
7453
+ }), childOptions.version && (obj.rspackVersion = "1.7.3-canary-1138ed18-20260115124957", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
7426
7454
  let mapError = (j, obj)=>({
7427
7455
  ...obj,
7428
7456
  compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
@@ -8678,7 +8706,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
8678
8706
  object.hash = context.getStatsCompilation(compilation).hash;
8679
8707
  },
8680
8708
  version: (object)=>{
8681
- object.version = "5.75.0", object.rspackVersion = "1.7.3-canary-58d41d16-20260115035302";
8709
+ object.version = "5.75.0", object.rspackVersion = "1.7.3-canary-1138ed18-20260115124957";
8682
8710
  },
8683
8711
  env: (object, _compilation, _context, { _env })=>{
8684
8712
  object.env = _env;
@@ -10403,7 +10431,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
10403
10431
  });
10404
10432
  }
10405
10433
  }
10406
- let CORE_VERSION = "1.7.3-canary-58d41d16-20260115035302", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
10434
+ let CORE_VERSION = "1.7.3-canary-1138ed18-20260115124957", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
10407
10435
 
10408
10436
  Help:
10409
10437
  Looks like you are using a custom binding (via environment variable 'RSPACK_BINDING=${process.env.RSPACK_BINDING}').
@@ -12657,7 +12685,7 @@ Help:
12657
12685
  let _options = JSON.stringify(options || {});
12658
12686
  return binding_default().transform(source, _options);
12659
12687
  }
12660
- let exports_rspackVersion = "1.7.3-canary-58d41d16-20260115035302", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
12688
+ let exports_rspackVersion = "1.7.3-canary-1138ed18-20260115124957", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
12661
12689
  getNormalizedRspackOptions: getNormalizedRspackOptions,
12662
12690
  applyRspackOptionsDefaults: applyRspackOptionsDefaults,
12663
12691
  getNormalizedWebpackOptions: getNormalizedRspackOptions,
@@ -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
- * @param {Error} err error
35
- */
36
- function errorHandler(err) {
37
- err.message =
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
- request.on('error', errorHandler);
46
- request.end();
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
- response.destroy();
102
+ errorHandlers.delete(onError);
103
+ compiling.delete(data);
104
+ sendActiveRequest();
49
105
  };
50
106
  };
@@ -1,47 +1,73 @@
1
- if (typeof EventSource !== 'function') {
1
+ if (typeof XMLHttpRequest === 'undefined') {
2
2
  throw new Error(
3
- "Environment doesn't support lazy compilation (requires EventSource)",
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
- var updateEventSource = function updateEventSource() {
14
- if (activeEventSource) activeEventSource.close();
15
- if (compiling.size) {
16
- activeEventSource = new EventSource(
17
- urlBase +
18
- Array.from(compiling, function (module) {
19
- return encodeURIComponent(module);
20
- }).join('@'),
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
- updateEventSource();
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
- updateEventSource();
96
+ sendActiveRequest();
71
97
  };
72
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/core",
3
- "version": "1.7.3-canary-58d41d16-20260115035302",
3
+ "version": "1.7.3-canary-1138ed18-20260115124957",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "The fast Rust-based web bundler with webpack-compatible API",
@@ -37,12 +37,12 @@
37
37
  "directory": "packages/rspack"
38
38
  },
39
39
  "devDependencies": {
40
- "@ast-grep/napi": "^0.40.4",
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.1",
43
+ "@rslib/core": "0.19.2",
44
44
  "@swc/types": "0.1.25",
45
- "@types/node": "^20.19.27",
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",
@@ -58,7 +58,7 @@
58
58
  "dependencies": {
59
59
  "@module-federation/runtime-tools": "0.0.0-feat-shared-treeshake-poc-20260114091859",
60
60
  "@rspack/lite-tapable": "1.1.0",
61
- "@rspack/binding": "npm:@rspack-canary/binding@1.7.3-canary-58d41d16-20260115035302"
61
+ "@rspack/binding": "npm:@rspack-canary/binding@1.7.3-canary-1138ed18-20260115124957"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@swc/helpers": ">=0.5.1"