@rspack/dev-server 2.1.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,13 +5,14 @@ import node_http2 from "node:http2";
5
5
  import { EventEmitter } from "node:events";
6
6
  import "node:net";
7
7
  import "node:stream";
8
+ import { styleText } from "node:util";
8
9
  import { URL as external_node_url_URL } from "node:url";
9
10
  import { URL as external_url_URL } from "url";
10
11
  import "node:zlib";
11
12
  import "node:querystring";
12
- import { __webpack_require__ } from "./944.js";
13
+ import { __webpack_require__ } from "./619.js";
13
14
  import "./0~debug.js";
14
- import "./944.js";
15
+ import "./619.js";
15
16
  __webpack_require__.add({
16
17
  "./node_modules/.pnpm/braces@3.0.3/node_modules/braces/index.js" (module, __unused_rspack_exports, __webpack_require__) {
17
18
  const stringify = __webpack_require__("./node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/stringify.js");
@@ -2796,6 +2797,7 @@ __webpack_require__.add({
2796
2797
  }
2797
2798
  });
2798
2799
  const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
2800
+ const transferEncodingConnectionToken = /(^|,)\s*transfer-encoding\s*($|,)/i;
2799
2801
  const defaultAgents = {
2800
2802
  http: new node_http.Agent({
2801
2803
  keepAlive: true,
@@ -2809,6 +2811,16 @@ const defaultAgents = {
2809
2811
  })
2810
2812
  };
2811
2813
  const isSSL = /^https|wss/;
2814
+ function forceConnectionCloseForTransferEncoding(headers) {
2815
+ let carriesTransferEncoding = false;
2816
+ for(const key in headers)if (void 0 !== headers[key] && "transfer-encoding" === key.toLowerCase()) {
2817
+ carriesTransferEncoding = true;
2818
+ break;
2819
+ }
2820
+ const connection = headers.connection;
2821
+ const connectionMarksTransferEncoding = "string" == typeof connection && transferEncodingConnectionToken.test(connection);
2822
+ if (carriesTransferEncoding || connectionMarksTransferEncoding) headers.connection = "close";
2823
+ }
2812
2824
  const HTTP2_HEADER_BLACKLIST = [
2813
2825
  ":method",
2814
2826
  ":path",
@@ -2857,6 +2869,8 @@ function setupOutgoing(outgoing, options, req, forward) {
2857
2869
  outgoing.headers = outgoing.headers || {};
2858
2870
  if ("string" != typeof outgoing.headers.connection || !upgradeHeader.test(outgoing.headers.connection)) outgoing.headers.connection = "close";
2859
2871
  }
2872
+ outgoing.headers = outgoing.headers || {};
2873
+ forceConnectionCloseForTransferEncoding(outgoing.headers);
2860
2874
  const target = options[forward || "target"];
2861
2875
  const targetPath = target && false !== options.prependPath ? target.pathname || "" : "";
2862
2876
  const targetSearch = target instanceof URL && false !== options.prependPath ? target.search || "" : "";
@@ -2954,6 +2968,7 @@ const webOutgoingMiddleware = [
2954
2968
  defineProxyOutgoingMiddleware((req, res, proxyRes, options)=>{
2955
2969
  if ((options.hostRewrite || options.autoRewrite || options.protocolRewrite) && proxyRes.headers.location && redirectRegex.test(String(proxyRes.statusCode))) {
2956
2970
  const target = _toURL(options.target);
2971
+ const keepProtocolRelative = proxyRes.headers.location.startsWith("//") && !options.protocolRewrite;
2957
2972
  const u = new URL(proxyRes.headers.location, target);
2958
2973
  if (target.host !== u.host) return;
2959
2974
  if (options.hostRewrite) u.host = options.hostRewrite;
@@ -2962,7 +2977,7 @@ const webOutgoingMiddleware = [
2962
2977
  else if (req.headers.host) u.host = req.headers.host;
2963
2978
  }
2964
2979
  if (options.protocolRewrite) u.protocol = options.protocolRewrite;
2965
- proxyRes.headers.location = u.toString();
2980
+ proxyRes.headers.location = keepProtocolRelative ? u.href.slice(u.protocol.length) : u.href;
2966
2981
  }
2967
2982
  }),
2968
2983
  defineProxyOutgoingMiddleware((req, res, proxyRes, options)=>{
@@ -3012,7 +3027,7 @@ const nativeAgents = {
3012
3027
  http: node_http,
3013
3028
  https: node_https
3014
3029
  };
3015
- const redirectStatuses = new Set([
3030
+ const redirectStatuses = /* @__PURE__ */ new Set([
3016
3031
  301,
3017
3032
  302,
3018
3033
  303,
@@ -3021,10 +3036,7 @@ const redirectStatuses = new Set([
3021
3036
  ]);
3022
3037
  const webIncomingMiddleware = [
3023
3038
  defineProxyMiddleware((req)=>{
3024
- if (("DELETE" === req.method || "OPTIONS" === req.method) && !req.headers["content-length"]) {
3025
- req.headers["content-length"] = "0";
3026
- delete req.headers["transfer-encoding"];
3027
- }
3039
+ if (("DELETE" === req.method || "OPTIONS" === req.method) && !req.headers["content-length"] && !req.headers["transfer-encoding"]) req.headers["content-length"] = "0";
3028
3040
  }),
3029
3041
  defineProxyMiddleware((req, res, options)=>{
3030
3042
  if (options.timeout) req.socket.setTimeout(options.timeout, ()=>{
@@ -3127,6 +3139,7 @@ const webIncomingMiddleware = [
3127
3139
  delete redirectHeaders["content-type"];
3128
3140
  delete redirectHeaders["transfer-encoding"];
3129
3141
  }
3142
+ forceConnectionCloseForTransferEncoding(redirectHeaders);
3130
3143
  const redirectOpts = {
3131
3144
  hostname: location.hostname,
3132
3145
  port: location.port || (isHTTPS ? 443 : 80),
@@ -3374,32 +3387,41 @@ function _createProxyFn(type, server) {
3374
3387
  return callbackPromise;
3375
3388
  };
3376
3389
  }
3377
- new Set([
3378
- 301,
3379
- 302,
3380
- 303,
3381
- 307,
3382
- 308
3383
- ]);
3384
- var errors_ERRORS;
3385
- (function(ERRORS) {
3386
- ERRORS["ERR_CONFIG_FACTORY_TARGET_MISSING"] = "[HPM] Missing \"target\" option. Example: {target: \"http://www.example.org\"}";
3387
- ERRORS["ERR_CONTEXT_MATCHER_GENERIC"] = "[HPM] Invalid pathFilter. Expecting something like: \"/api\" or [\"/api\", \"/ajax\"]";
3388
- ERRORS["ERR_CONTEXT_MATCHER_INVALID_ARRAY"] = "[HPM] Invalid pathFilter. Plain paths (e.g. \"/api\") can not be mixed with globs (e.g. \"/api/**\"). Expecting something like: [\"/api\", \"/ajax\"] or [\"/api/**\", \"!**.html\"].";
3389
- ERRORS["ERR_PATH_REWRITER_CONFIG"] = "[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function";
3390
- })(errors_ERRORS || (errors_ERRORS = {}));
3390
+ class errors_HttpProxyMiddlewareError extends Error {
3391
+ code;
3392
+ constructor(message, code){
3393
+ super(message);
3394
+ this.code = code;
3395
+ this.name = this.constructor.name;
3396
+ if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
3397
+ }
3398
+ }
3391
3399
  function verifyConfig(options) {
3392
- if (!options.target && !options.router) throw new Error(errors_ERRORS.ERR_CONFIG_FACTORY_TARGET_MISSING);
3400
+ if (!options.target && !options.router) throw new errors_HttpProxyMiddlewareError('[HPM] Missing "target" option. Example: {target: "http://www.example.org"}', 'ERR_CONFIG_FACTORY_TARGET_MISSING');
3393
3401
  }
3394
- const src = __webpack_require__("./node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js");
3402
+ const src = __webpack_require__("./node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js");
3395
3403
  const Debug = src('http-proxy-middleware');
3396
3404
  function definePlugin(fn) {
3397
3405
  return fn;
3398
3406
  }
3399
3407
  const debug = Debug.extend('debug-proxy-errors-plugin');
3408
+ const BODY_PARSER_ERROR_MESSAGE = `[HPM] Connection reset (ECONNRESET) detected with non-empty "req.body" [ERR_HPM.GH40].
3409
+
3410
+ This usually means that the POST request body (req.body) was already parsed before reaching the proxy.
3411
+ When bodyParser runs first, it consumes the request stream, leaving the proxy unable to forward the body data to the target server.
3412
+
3413
+ How to fix this issue:
3414
+ - Option 1: Place the proxy middleware before the bodyParser middleware.
3415
+ - Option 2: Use 'fixRequestBody()' helper to fix this issue.
3416
+
3417
+ For more details, see: https://github.com/chimurai/http-proxy-middleware/issues/40\n`;
3418
+ function hasParsedBody(req) {
3419
+ return Boolean(req && 'POST' === req.method && 'body' in req && req.body);
3420
+ }
3400
3421
  const debugProxyErrorsPlugin = definePlugin((proxyServer, options)=>{
3401
3422
  proxyServer.on('error', (error, req, res, target)=>{
3402
3423
  debug(`httpxy error event: \n%O`, error);
3424
+ if ('ECONNRESET' === error.code && hasParsedBody(req)) console.error(styleText('red', BODY_PARSER_ERROR_MESSAGE));
3403
3425
  });
3404
3426
  proxyServer.on('proxyReq', (proxyReq, req, socket)=>{
3405
3427
  socket.on('error', (error)=>{
@@ -3573,13 +3595,13 @@ function matchPathFilter(pathFilter = '/', uri, req) {
3573
3595
  if (Array.isArray(pathFilter)) {
3574
3596
  if (pathFilter.every(isStringPath)) return matchMultiPath(pathFilter, uri);
3575
3597
  if (pathFilter.every(isGlobPath)) return matchMultiGlobPath(pathFilter, uri);
3576
- throw new Error(errors_ERRORS.ERR_CONTEXT_MATCHER_INVALID_ARRAY);
3598
+ throw new errors_HttpProxyMiddlewareError('[HPM] Invalid pathFilter. Plain paths (e.g. "/api") can not be mixed with globs (e.g. "/api/**"). Expecting something like: ["/api", "/ajax"] or ["/api/**", "!**.html"].', 'HPM_INVALID_PATH_FILTER_ARRAY_CONFIG');
3577
3599
  }
3578
3600
  if ('function' == typeof pathFilter) {
3579
3601
  const pathname = getUrlPathName(uri);
3580
3602
  return Boolean(pathFilter(pathname, req));
3581
3603
  }
3582
- throw new Error(errors_ERRORS.ERR_CONTEXT_MATCHER_GENERIC);
3604
+ throw new errors_HttpProxyMiddlewareError('[HPM] Invalid pathFilter. Expecting something like: "/api" or ["/api", "/ajax"]', 'HPM_INVALID_PATH_FILTER_CONFIG');
3583
3605
  }
3584
3606
  function matchSingleStringPath(pathFilter, uri) {
3585
3607
  const pathname = getUrlPathName(uri);
@@ -3641,7 +3663,7 @@ function isValidRewriteConfig(rewriteConfig) {
3641
3663
  if ('function' == typeof rewriteConfig) return true;
3642
3664
  if (isPlainObject(rewriteConfig)) return 0 !== Object.keys(rewriteConfig).length;
3643
3665
  if (null == rewriteConfig) return false;
3644
- throw new Error(errors_ERRORS.ERR_PATH_REWRITER_CONFIG);
3666
+ throw new errors_HttpProxyMiddlewareError('[HPM] Invalid pathRewrite config. Expecting object with pathRewrite config or a rewrite function', 'HPM_INVALID_PATH_REWRITER_CONFIG');
3645
3667
  }
3646
3668
  function parsePathRewriteRules(rewriteConfig) {
3647
3669
  const rules = [];
@@ -1,5 +1,5 @@
1
- import { __webpack_require__ } from "./944.js";
2
- import "./944.js";
1
+ import { __webpack_require__ } from "./619.js";
2
+ import "./619.js";
3
3
  __webpack_require__.add({
4
4
  "./node_modules/.pnpm/launch-editor@2.14.1/node_modules/launch-editor/editor-info/linux.js" (module) {
5
5
  module.exports = {
package/dist/0~open.js CHANGED
@@ -127,24 +127,64 @@ const wslDefaultBrowser = async ()=>{
127
127
  const psPath = await wsl_utils_powerShellPath();
128
128
  const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
129
129
  const { stdout } = await executePowerShell(command, {
130
- powerShellPath: psPath
130
+ powerShellPath: psPath,
131
+ cwd: node_path.dirname(psPath)
131
132
  });
132
133
  return stdout.trim();
133
134
  };
134
- const convertWslPathToWindows = async (path)=>{
135
- if (/^[a-z]+:\/\//i.test(path)) return path;
136
- try {
135
+ const isUrl = (path)=>/^[a-z]+:\/\//i.test(path);
136
+ const convertWslPathToWindows = async (paths)=>{
137
+ const isBatch = Array.isArray(paths);
138
+ const pathArray = isBatch ? paths : [
139
+ paths
140
+ ];
141
+ const indicesToConvert = [];
142
+ const pathsToConvert = [];
143
+ for (const [index, path] of pathArray.entries())if (!isUrl(path)) {
144
+ indicesToConvert.push(index);
145
+ pathsToConvert.push(path);
146
+ }
147
+ const results = [
148
+ ...pathArray
149
+ ];
150
+ if (pathsToConvert.length > 0) try {
137
151
  const { stdout } = await wsl_utils_execFile('wslpath', [
138
152
  '-aw',
139
- path
153
+ ...pathsToConvert
140
154
  ], {
141
155
  encoding: 'utf8'
142
156
  });
143
- return stdout.trim();
144
- } catch {
145
- return path;
146
- }
157
+ const convertedPaths = stdout.split(/\r?\n/).filter(Boolean);
158
+ for (const [index, originalIndex] of indicesToConvert.entries())results[originalIndex] = convertedPaths[index] ?? pathArray[originalIndex];
159
+ } catch {}
160
+ return isBatch ? results : results[0];
161
+ };
162
+ const powershell_utils_execFile = promisify(node_child_process.execFile);
163
+ const powershell_utils_powerShellPath = ()=>`${node_process.env.SYSTEMROOT || node_process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
164
+ const argumentsPrefix = [
165
+ '-NoProfile',
166
+ '-NonInteractive',
167
+ '-ExecutionPolicy',
168
+ 'Bypass',
169
+ '-EncodedCommand'
170
+ ];
171
+ const encodeCommand = (command)=>Buffer.from(command, 'utf16le').toString('base64');
172
+ const escapeArgument = (value)=>`'${String(value).replaceAll('\'', '\'\'')}'`;
173
+ const createArguments = (command)=>[
174
+ ...argumentsPrefix,
175
+ encodeCommand(command)
176
+ ];
177
+ const powershell_utils_executePowerShell = async (command, options = {})=>{
178
+ const { powerShellPath: psPath, ...execFileOptions } = options;
179
+ return powershell_utils_execFile(psPath ?? powershell_utils_powerShellPath(), createArguments(command), {
180
+ encoding: 'utf8',
181
+ ...execFileOptions
182
+ });
147
183
  };
184
+ powershell_utils_executePowerShell.argumentsPrefix = argumentsPrefix;
185
+ powershell_utils_executePowerShell.encodeCommand = encodeCommand;
186
+ powershell_utils_executePowerShell.escapeArgument = escapeArgument;
187
+ powershell_utils_executePowerShell.createArguments = createArguments;
148
188
  function defineLazyProperty(object, propertyName, valueGetter) {
149
189
  const define = (value)=>Object.defineProperty(object, propertyName, {
150
190
  value,
@@ -409,7 +449,7 @@ const baseOpen = async (options)=>{
409
449
  if (app) cliArguments.push('-a', app);
410
450
  } else if ('win32' === platform || shouldUseWindowsInWsl) {
411
451
  command = await wsl_utils_powerShellPath();
412
- cliArguments.push(...executePowerShell.argumentsPrefix);
452
+ cliArguments.push(...powershell_utils_executePowerShell.argumentsPrefix);
413
453
  if (!is_wsl) childProcessOptions.windowsVerbatimArguments = true;
414
454
  if (is_wsl && options.target) options.target = await convertWslPathToWindows(options.target);
415
455
  const encodedArguments = [
@@ -418,15 +458,16 @@ const baseOpen = async (options)=>{
418
458
  ];
419
459
  if (options.wait) encodedArguments.push('-Wait');
420
460
  if (app) {
421
- encodedArguments.push(executePowerShell.escapeArgument(app));
461
+ encodedArguments.push(powershell_utils_executePowerShell.escapeArgument(app));
422
462
  if (options.target) appArguments.push(options.target);
423
- } else if (options.target) encodedArguments.push(executePowerShell.escapeArgument(options.target));
463
+ } else if (options.target) encodedArguments.push(powershell_utils_executePowerShell.escapeArgument(options.target));
424
464
  if (appArguments.length > 0) {
425
- appArguments = appArguments.map((argument)=>executePowerShell.escapeArgument(argument));
465
+ appArguments = appArguments.map((argument)=>powershell_utils_executePowerShell.escapeArgument(argument));
426
466
  encodedArguments.push('-ArgumentList', appArguments.join(','));
427
467
  }
428
- options.target = executePowerShell.encodeCommand(encodedArguments.join(' '));
468
+ options.target = powershell_utils_executePowerShell.encodeCommand(encodedArguments.join(' '));
429
469
  if (!options.wait) childProcessOptions.stdio = 'ignore';
470
+ if (is_wsl) childProcessOptions.cwd = node_path.dirname(command);
430
471
  } else {
431
472
  if (app) command = app;
432
473
  else {
@@ -1,6 +1,6 @@
1
1
  /*! LICENSE: 0~serve-static.js.LICENSE.txt */
2
- import { __webpack_require__ } from "./944.js";
3
- import "./944.js";
2
+ import { __webpack_require__ } from "./619.js";
3
+ import "./619.js";
4
4
  import "./0~debug.js";
5
5
  __webpack_require__.add({
6
6
  "./node_modules/.pnpm/depd@2.0.0/node_modules/depd/index.js" (module, __unused_rspack_exports, __webpack_require__) {
@@ -987,14 +987,14 @@ __webpack_require__.add({
987
987
  return a.start - b.start;
988
988
  }
989
989
  },
990
- "./node_modules/.pnpm/send@1.2.1/node_modules/send/index.js" (module, __unused_rspack_exports, __webpack_require__) {
990
+ "./node_modules/.pnpm/send@1.2.1_supports-color@8.1.1/node_modules/send/index.js" (module, __unused_rspack_exports, __webpack_require__) {
991
991
  /*!
992
992
  * send
993
993
  * Copyright(c) 2012 TJ Holowaychuk
994
994
  * Copyright(c) 2014-2022 Douglas Christopher Wilson
995
995
  * MIT Licensed
996
996
  */ var createError = __webpack_require__("./node_modules/.pnpm/http-errors@2.0.1/node_modules/http-errors/index.js");
997
- var debug = __webpack_require__("./node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js")('send');
997
+ var debug = __webpack_require__("./node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js")('send');
998
998
  var encodeUrl = __webpack_require__("./node_modules/.pnpm/encodeurl@2.0.0/node_modules/encodeurl/index.js");
999
999
  var escapeHtml = __webpack_require__("./node_modules/.pnpm/escape-html@1.0.3/node_modules/escape-html/index.js");
1000
1000
  var etag = __webpack_require__("./node_modules/.pnpm/etag@1.8.1/node_modules/etag/index.js");
@@ -1418,7 +1418,7 @@ __webpack_require__.add({
1418
1418
  }
1419
1419
  }
1420
1420
  },
1421
- "./node_modules/.pnpm/serve-static@2.2.1/node_modules/serve-static/index.js" (module, __unused_rspack_exports, __webpack_require__) {
1421
+ "./node_modules/.pnpm/serve-static@2.2.1_supports-color@8.1.1/node_modules/serve-static/index.js" (module, __unused_rspack_exports, __webpack_require__) {
1422
1422
  /*!
1423
1423
  * serve-static
1424
1424
  * Copyright(c) 2010 Sencha Inc.
@@ -1429,7 +1429,7 @@ __webpack_require__.add({
1429
1429
  var escapeHtml = __webpack_require__("./node_modules/.pnpm/escape-html@1.0.3/node_modules/escape-html/index.js");
1430
1430
  var parseUrl = __webpack_require__("./node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js");
1431
1431
  var resolve = __webpack_require__("path").resolve;
1432
- var send = __webpack_require__("./node_modules/.pnpm/send@1.2.1/node_modules/send/index.js");
1432
+ var send = __webpack_require__("./node_modules/.pnpm/send@1.2.1_supports-color@8.1.1/node_modules/send/index.js");
1433
1433
  var url = __webpack_require__("url?b918");
1434
1434
  module.exports = serveStatic;
1435
1435
  function serveStatic(root, options) {
@@ -1592,4 +1592,4 @@ __webpack_require__.add({
1592
1592
  module.exports = /*#__PURE__*/ JSON.parse('{"100":"Continue","101":"Switching Protocols","102":"Processing","103":"Early Hints","200":"OK","201":"Created","202":"Accepted","203":"Non-Authoritative Information","204":"No Content","205":"Reset Content","206":"Partial Content","207":"Multi-Status","208":"Already Reported","226":"IM Used","300":"Multiple Choices","301":"Moved Permanently","302":"Found","303":"See Other","304":"Not Modified","305":"Use Proxy","307":"Temporary Redirect","308":"Permanent Redirect","400":"Bad Request","401":"Unauthorized","402":"Payment Required","403":"Forbidden","404":"Not Found","405":"Method Not Allowed","406":"Not Acceptable","407":"Proxy Authentication Required","408":"Request Timeout","409":"Conflict","410":"Gone","411":"Length Required","412":"Precondition Failed","413":"Payload Too Large","414":"URI Too Long","415":"Unsupported Media Type","416":"Range Not Satisfiable","417":"Expectation Failed","418":"I\'m a Teapot","421":"Misdirected Request","422":"Unprocessable Entity","423":"Locked","424":"Failed Dependency","425":"Too Early","426":"Upgrade Required","428":"Precondition Required","429":"Too Many Requests","431":"Request Header Fields Too Large","451":"Unavailable For Legal Reasons","500":"Internal Server Error","501":"Not Implemented","502":"Bad Gateway","503":"Service Unavailable","504":"Gateway Timeout","505":"HTTP Version Not Supported","506":"Variant Also Negotiates","507":"Insufficient Storage","508":"Loop Detected","509":"Bandwidth Limit Exceeded","510":"Not Extended","511":"Network Authentication Required"}');
1593
1593
  }
1594
1594
  });
1595
- __webpack_require__("./node_modules/.pnpm/serve-static@2.2.1/node_modules/serve-static/index.js");
1595
+ __webpack_require__("./node_modules/.pnpm/serve-static@2.2.1_supports-color@8.1.1/node_modules/serve-static/index.js");