next-info.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env node
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.nextInfo = void 0;
  7. var _os = _interopRequireDefault(require("os"));
  8. var _childProcess = _interopRequireDefault(require("child_process"));
  9. var _chalk = _interopRequireDefault(require("next/dist/compiled/chalk"));
  10. var _indexJs = _interopRequireDefault(require("next/dist/compiled/arg/index.js"));
  11. var _nodeFetch = _interopRequireDefault(require("next/dist/compiled/node-fetch"));
  12. var _utils = require("../server/lib/utils");
  13. var _isError = _interopRequireDefault(require("../lib/is-error"));
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {
  16. default: obj
  17. };
  18. }
  19. function getPackageVersion(packageName) {
  20. try {
  21. return require(`${packageName}/package.json`).version;
  22. } catch {
  23. return "N/A";
  24. }
  25. }
  26. function getBinaryVersion(binaryName) {
  27. try {
  28. return _childProcess.default.execFileSync(binaryName, [
  29. "--version"
  30. ]).toString().trim();
  31. } catch {
  32. return "N/A";
  33. }
  34. }
  35. const nextInfo = async (argv)=>{
  36. const validArgs = {
  37. // Types
  38. "--help": Boolean,
  39. // Aliases
  40. "-h": "--help"
  41. };
  42. let args;
  43. try {
  44. args = (0, _indexJs).default(validArgs, {
  45. argv
  46. });
  47. } catch (error) {
  48. if ((0, _isError).default(error) && error.code === "ARG_UNKNOWN_OPTION") {
  49. return (0, _utils).printAndExit(error.message, 1);
  50. }
  51. throw error;
  52. }
  53. if (args["--help"]) {
  54. console.log(`
  55. Description
  56. Prints relevant details about the current system which can be used to report Next.js bugs
  57. Usage
  58. $ next info
  59. Learn more: ${_chalk.default.cyan("https://nextjs.org/docs/api-reference/cli#info")}`);
  60. return;
  61. }
  62. const installedRelease = getPackageVersion("next");
  63. console.log(`
  64. Operating System:
  65. Platform: ${_os.default.platform()}
  66. Arch: ${_os.default.arch()}
  67. Version: ${_os.default.version()}
  68. Binaries:
  69. Node: ${process.versions.node}
  70. npm: ${getBinaryVersion("npm")}
  71. Yarn: ${getBinaryVersion("yarn")}
  72. pnpm: ${getBinaryVersion("pnpm")}
  73. Relevant packages:
  74. next: ${installedRelease}
  75. eslint-config-next: ${getPackageVersion("eslint-config-next")}
  76. react: ${getPackageVersion("react")}
  77. react-dom: ${getPackageVersion("react-dom")}
  78. `);
  79. try {
  80. const res = await (0, _nodeFetch).default("https://api.github.com/repos/vercel/next.js/releases");
  81. const releases = await res.json();
  82. const newestRelease = releases[0].tag_name.replace(/^v/, "");
  83. if (installedRelease !== newestRelease) {
  84. console.warn(`${_chalk.default.yellow(_chalk.default.bold("warn"))} - Latest canary version not detected, detected: "${installedRelease}", newest: "${newestRelease}".
  85. Please try the latest canary version (\`npm install next@canary\`) to confirm the issue still exists before creating a new issue.
  86. Read more - https://nextjs.org/docs/messages/opening-an-issue`);
  87. }
  88. } catch (e) {
  89. console.warn(`${_chalk.default.yellow(_chalk.default.bold("warn"))} - Failed to fetch latest canary version. (Reason: ${e.message}.)
  90. Detected "${installedRelease}". Visit https://github.com/vercel/next.js/releases.
  91. Make sure to try the latest canary version (eg.: \`npm install next@canary\`) to confirm the issue still exists before creating a new issue.
  92. Read more - https://nextjs.org/docs/messages/opening-an-issue`);
  93. }
  94. };
  95. exports.nextInfo = nextInfo;
  96. //# sourceMappingURL=next-info.js.map