@rspack/dev-server 2.2.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.
package/client/overlay.js CHANGED
@@ -408,7 +408,11 @@ const createOverlay = (options)=>{
408
408
  });
409
409
  }, trustedTypesPolicyName);
410
410
  }
411
- let handleEscapeKey;
411
+ function handleEscapeKey(event) {
412
+ if ('Escape' === event.key || 'Esc' === event.key || 27 === event.keyCode) overlayService.send({
413
+ type: 'DISMISS'
414
+ });
415
+ }
412
416
  const hideOverlayWithEscCleanup = ()=>{
413
417
  window.removeEventListener('keydown', handleEscapeKey);
414
418
  hide();
@@ -417,11 +421,6 @@ const createOverlay = (options)=>{
417
421
  showOverlay: ({ level = 'error', messages, messageSource })=>show(level, messages, options.trustedTypesPolicyName, messageSource),
418
422
  hideOverlay: hideOverlayWithEscCleanup
419
423
  });
420
- handleEscapeKey = (event)=>{
421
- if ('Escape' === event.key || 'Esc' === event.key || 27 === event.keyCode) overlayService.send({
422
- type: 'DISMISS'
423
- });
424
- };
425
424
  window.addEventListener('keydown', handleEscapeKey);
426
425
  if (options.catchRuntimeError) {
427
426
  const handleError = (error, fallbackMessage)=>{
@@ -591,17 +591,17 @@ __nested_rspack_require_364__.add({
591
591
  return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
592
592
  }
593
593
  },
594
- "./node_modules/.pnpm/finalhandler@2.1.1/node_modules/finalhandler/index.js" (module, __unused_rspack_exports, __nested_rspack_require_23493_23512__) {
594
+ "./node_modules/.pnpm/finalhandler@2.1.1_supports-color@8.1.1/node_modules/finalhandler/index.js" (module, __unused_rspack_exports, __nested_rspack_require_23514_23533__) {
595
595
  /*!
596
596
  * finalhandler
597
597
  * Copyright(c) 2014-2022 Douglas Christopher Wilson
598
598
  * MIT Licensed
599
- */ var debug = __nested_rspack_require_23493_23512__("./node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js")('finalhandler');
600
- var encodeUrl = __nested_rspack_require_23493_23512__("./node_modules/.pnpm/encodeurl@2.0.0/node_modules/encodeurl/index.js");
601
- var escapeHtml = __nested_rspack_require_23493_23512__("./node_modules/.pnpm/escape-html@1.0.3/node_modules/escape-html/index.js");
602
- var onFinished = __nested_rspack_require_23493_23512__("./node_modules/.pnpm/on-finished@2.4.1/node_modules/on-finished/index.js");
603
- var parseUrl = __nested_rspack_require_23493_23512__("./node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js");
604
- var statuses = __nested_rspack_require_23493_23512__("./node_modules/.pnpm/statuses@2.0.2/node_modules/statuses/index.js");
599
+ */ var debug = __nested_rspack_require_23514_23533__("./node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js")('finalhandler');
600
+ var encodeUrl = __nested_rspack_require_23514_23533__("./node_modules/.pnpm/encodeurl@2.0.0/node_modules/encodeurl/index.js");
601
+ var escapeHtml = __nested_rspack_require_23514_23533__("./node_modules/.pnpm/escape-html@1.0.3/node_modules/escape-html/index.js");
602
+ var onFinished = __nested_rspack_require_23514_23533__("./node_modules/.pnpm/on-finished@2.4.1/node_modules/on-finished/index.js");
603
+ var parseUrl = __nested_rspack_require_23514_23533__("./node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js");
604
+ var statuses = __nested_rspack_require_23514_23533__("./node_modules/.pnpm/statuses@2.0.2/node_modules/statuses/index.js");
605
605
  var isFinished = onFinished.isFinished;
606
606
  function createHtmlDocument(message) {
607
607
  var body = escapeHtml(message).replaceAll('\n', '<br>').replaceAll(' ', ' &nbsp;');
@@ -781,7 +781,7 @@ __nested_rspack_require_364__.add({
781
781
  return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
782
782
  }
783
783
  },
784
- "./node_modules/.pnpm/on-finished@2.4.1/node_modules/on-finished/index.js" (module, __unused_rspack_exports, __nested_rspack_require_32097_32116__) {
784
+ "./node_modules/.pnpm/on-finished@2.4.1/node_modules/on-finished/index.js" (module, __unused_rspack_exports, __nested_rspack_require_32118_32137__) {
785
785
  /*!
786
786
  * on-finished
787
787
  * Copyright(c) 2013 Jonathan Ong
@@ -790,7 +790,7 @@ __nested_rspack_require_364__.add({
790
790
  */ module.exports = onFinished;
791
791
  module.exports.isFinished = isFinished;
792
792
  var asyncHooks = tryRequireAsyncHooks();
793
- var first = __nested_rspack_require_32097_32116__("./node_modules/.pnpm/ee-first@1.1.1/node_modules/ee-first/index.js");
793
+ var first = __nested_rspack_require_32118_32137__("./node_modules/.pnpm/ee-first@1.1.1/node_modules/ee-first/index.js");
794
794
  var defer = 'function' == typeof setImmediate ? setImmediate : function(fn) {
795
795
  process.nextTick(fn.bind.apply(fn, arguments));
796
796
  };
@@ -869,7 +869,7 @@ __nested_rspack_require_364__.add({
869
869
  }
870
870
  function tryRequireAsyncHooks() {
871
871
  try {
872
- return __nested_rspack_require_32097_32116__("async_hooks");
872
+ return __nested_rspack_require_32118_32137__("async_hooks");
873
873
  } catch (e) {
874
874
  return {};
875
875
  }
@@ -881,13 +881,13 @@ __nested_rspack_require_364__.add({
881
881
  return res.runInAsyncScope.bind(res, fn, null);
882
882
  }
883
883
  },
884
- "./node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js" (module, __unused_rspack_exports, __nested_rspack_require_36017_36036__) {
884
+ "./node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js" (module, __unused_rspack_exports, __nested_rspack_require_36038_36057__) {
885
885
  /*!
886
886
  * parseurl
887
887
  * Copyright(c) 2014 Jonathan Ong
888
888
  * Copyright(c) 2014-2017 Douglas Christopher Wilson
889
889
  * MIT Licensed
890
- */ var url = __nested_rspack_require_36017_36036__("url");
890
+ */ var url = __nested_rspack_require_36038_36057__("url");
891
891
  var parse = url.parse;
892
892
  var Url = url.Url;
893
893
  module.exports = parseurl;
@@ -947,13 +947,13 @@ __nested_rspack_require_364__.add({
947
947
  return 'object' == typeof parsedUrl && null !== parsedUrl && (void 0 === Url || parsedUrl instanceof Url) && parsedUrl._raw === url;
948
948
  }
949
949
  },
950
- "./node_modules/.pnpm/statuses@2.0.2/node_modules/statuses/index.js" (module, __unused_rspack_exports, __nested_rspack_require_38488_38507__) {
950
+ "./node_modules/.pnpm/statuses@2.0.2/node_modules/statuses/index.js" (module, __unused_rspack_exports, __nested_rspack_require_38509_38528__) {
951
951
  /*!
952
952
  * statuses
953
953
  * Copyright(c) 2014 Jonathan Ong
954
954
  * Copyright(c) 2016 Douglas Christopher Wilson
955
955
  * MIT Licensed
956
- */ var codes = __nested_rspack_require_38488_38507__("./node_modules/.pnpm/statuses@2.0.2/node_modules/statuses/codes.json");
956
+ */ var codes = __nested_rspack_require_38509_38528__("./node_modules/.pnpm/statuses@2.0.2/node_modules/statuses/codes.json");
957
957
  module.exports = status;
958
958
  status.message = codes;
959
959
  status.code = createMessageToStatusCodeMap(codes);
@@ -1008,10 +1008,10 @@ __nested_rspack_require_364__.add({
1008
1008
  return getStatusCode(code);
1009
1009
  }
1010
1010
  },
1011
- "./node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js" (module, __unused_rspack_exports, __nested_rspack_require_40780_40799__) {
1012
- const os = __nested_rspack_require_40780_40799__("os");
1013
- const tty = __nested_rspack_require_40780_40799__("tty");
1014
- const hasFlag = __nested_rspack_require_40780_40799__("./node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js");
1011
+ "./node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js" (module, __unused_rspack_exports, __nested_rspack_require_40801_40820__) {
1012
+ const os = __nested_rspack_require_40801_40820__("os");
1013
+ const tty = __nested_rspack_require_40801_40820__("tty");
1014
+ const hasFlag = __nested_rspack_require_40801_40820__("./node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js");
1015
1015
  const { env } = process;
1016
1016
  let flagForceColor;
1017
1017
  if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) flagForceColor = 0;
@@ -1115,7 +1115,7 @@ __nested_rspack_require_364__.add({
1115
1115
  });
1116
1116
  const src = __nested_rspack_require_364__("./node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js");
1117
1117
  var src_default = /*#__PURE__*/ __nested_rspack_require_364__.n(src);
1118
- const dist_finalhandler = __nested_rspack_require_364__("./node_modules/.pnpm/finalhandler@2.1.1/node_modules/finalhandler/index.js");
1118
+ const dist_finalhandler = __nested_rspack_require_364__("./node_modules/.pnpm/finalhandler@2.1.1_supports-color@8.1.1/node_modules/finalhandler/index.js");
1119
1119
  var finalhandler_default = /*#__PURE__*/ __nested_rspack_require_364__.n(dist_finalhandler);
1120
1120
  const dist_parseurl = __nested_rspack_require_364__("./node_modules/.pnpm/parseurl@1.3.3/node_modules/parseurl/index.js");
1121
1121
  var parseurl_default = /*#__PURE__*/ __nested_rspack_require_364__.n(dist_parseurl);
@@ -1219,13 +1219,29 @@ function call(handle, route, err, req, res, next) {
1219
1219
  const hasError = void 0 !== err;
1220
1220
  dist_debug('%s %s : %s', handle.name || '<anonymous>', route, req.originalUrl);
1221
1221
  try {
1222
- if (hasError && 4 === arity) return void handle(err, req, res, next);
1223
- if (!hasError && arity < 4) return void handle(req, res, next);
1222
+ if (hasError && 4 === arity) {
1223
+ const result = handle(err, req, res, next);
1224
+ handlePromise(result, next);
1225
+ return;
1226
+ }
1227
+ if (!hasError && arity < 4) {
1228
+ const result = handle(req, res, next);
1229
+ handlePromise(result, next);
1230
+ return;
1231
+ }
1224
1232
  } catch (caughtError) {
1225
1233
  error = caughtError;
1226
1234
  }
1227
1235
  next(error);
1228
1236
  }
1237
+ function isPromise(value) {
1238
+ return null !== value && ('object' == typeof value || 'function' == typeof value) && 'function' == typeof value.then;
1239
+ }
1240
+ function handlePromise(result, next) {
1241
+ if (isPromise(result)) result.then(null, (error)=>{
1242
+ next(error || new Error('Rejected promise'));
1243
+ });
1244
+ }
1229
1245
  function logerror(err) {
1230
1246
  if ('test' !== dist_env) {
1231
1247
  if (err instanceof Error) return void console.error(err.stack || err.toString());
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 {