detect-node-version.js 814 B

12345678910111213141516171819202122232425262728
  1. function parseVersion(version) {
  2. return version.split('.').map(Number);
  3. }
  4. function compareVersions(v1, v2) {
  5. const v1Parts = parseVersion(v1);
  6. const v2Parts = parseVersion(v2);
  7. for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
  8. const v1Part = v1Parts[i] || 0;
  9. const v2Part = v2Parts[i] || 0;
  10. if (v1Part > v2Part) return 1;
  11. if (v1Part < v2Part) return -1;
  12. }
  13. return 0;
  14. }
  15. const currentVersion = process.version.substring(1);
  16. const targetVersion = "18.17.1";
  17. if (compareVersions(currentVersion, targetVersion) >= 0) {
  18. console.log(`Current Node.js version is ${currentVersion}, corepack is supported.`);
  19. } else {
  20. console.error(`Current Node.js version is ${currentVersion}, but corepack is unsupported. Required version: ^${targetVersion}.`);
  21. process.exit(1)
  22. }