utilsBundle.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.minimatch = exports.mime = exports.lockfile = exports.jpegjs = exports.getProxyForUrl = exports.debug = exports.colors = exports.SocksProxyAgent = exports.PNG = exports.HttpsProxyAgent = void 0;
  6. exports.ms = ms;
  7. exports.open = void 0;
  8. exports.parseStackTraceLine = parseStackTraceLine;
  9. exports.wsServer = exports.wsSender = exports.wsReceiver = exports.ws = exports.progress = exports.program = void 0;
  10. var _url = _interopRequireDefault(require("url"));
  11. var _path = _interopRequireDefault(require("path"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. /**
  14. * Copyright (c) Microsoft Corporation.
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License");
  17. * you may not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS,
  24. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. const colors = exports.colors = require('./utilsBundleImpl').colors;
  29. const debug = exports.debug = require('./utilsBundleImpl').debug;
  30. const getProxyForUrl = exports.getProxyForUrl = require('./utilsBundleImpl').getProxyForUrl;
  31. const HttpsProxyAgent = exports.HttpsProxyAgent = require('./utilsBundleImpl').HttpsProxyAgent;
  32. const jpegjs = exports.jpegjs = require('./utilsBundleImpl').jpegjs;
  33. const lockfile = exports.lockfile = require('./utilsBundleImpl').lockfile;
  34. const mime = exports.mime = require('./utilsBundleImpl').mime;
  35. const minimatch = exports.minimatch = require('./utilsBundleImpl').minimatch;
  36. const open = exports.open = require('./utilsBundleImpl').open;
  37. const PNG = exports.PNG = require('./utilsBundleImpl').PNG;
  38. const program = exports.program = require('./utilsBundleImpl').program;
  39. const progress = exports.progress = require('./utilsBundleImpl').progress;
  40. const SocksProxyAgent = exports.SocksProxyAgent = require('./utilsBundleImpl').SocksProxyAgent;
  41. const ws = exports.ws = require('./utilsBundleImpl').ws;
  42. const wsServer = exports.wsServer = require('./utilsBundleImpl').wsServer;
  43. const wsReceiver = exports.wsReceiver = require('./utilsBundleImpl').wsReceiver;
  44. const wsSender = exports.wsSender = require('./utilsBundleImpl').wsSender;
  45. const StackUtils = require('./utilsBundleImpl').StackUtils;
  46. const stackUtils = new StackUtils({
  47. internals: StackUtils.nodeInternals()
  48. });
  49. const nodeInternals = StackUtils.nodeInternals();
  50. const nodeMajorVersion = +process.versions.node.split('.')[0];
  51. function parseStackTraceLine(line) {
  52. var _frame$file, _frame$file2;
  53. if (!process.env.PWDEBUGIMPL && nodeMajorVersion < 16 && nodeInternals.some(internal => internal.test(line))) return null;
  54. const frame = stackUtils.parseLine(line);
  55. if (!frame) return null;
  56. if (!process.env.PWDEBUGIMPL && ((_frame$file = frame.file) !== null && _frame$file !== void 0 && _frame$file.startsWith('internal') || (_frame$file2 = frame.file) !== null && _frame$file2 !== void 0 && _frame$file2.startsWith('node:'))) return null;
  57. if (!frame.file) return null;
  58. // ESM files return file:// URLs, see here: https://github.com/tapjs/stack-utils/issues/60
  59. const file = frame.file.startsWith('file://') ? _url.default.fileURLToPath(frame.file) : _path.default.resolve(process.cwd(), frame.file);
  60. return {
  61. file,
  62. line: frame.line || 0,
  63. column: frame.column || 0,
  64. function: frame.function
  65. };
  66. }
  67. function ms(ms) {
  68. if (!isFinite(ms)) return '-';
  69. if (ms === 0) return '0ms';
  70. if (ms < 1000) return ms.toFixed(0) + 'ms';
  71. const seconds = ms / 1000;
  72. if (seconds < 60) return seconds.toFixed(1) + 's';
  73. const minutes = seconds / 60;
  74. if (minutes < 60) return minutes.toFixed(1) + 'm';
  75. const hours = minutes / 60;
  76. if (hours < 24) return hours.toFixed(1) + 'h';
  77. const days = hours / 24;
  78. return days.toFixed(1) + 'd';
  79. }