diff --git a/codemagic.yaml b/codemagic.yaml index 16eb708c..9ac0d084 100644 --- a/codemagic.yaml +++ b/codemagic.yaml @@ -7,12 +7,12 @@ definitions: mac_m1_env_versions: &mac_m1_env_versions node: 16.19.0 - npm: 8 + npm: 8.16.0 xcode: 15.3 mac_intel_x64_env_versions: &mac_intel_x64_env_versions node: 16.19.0 - npm: 8 + npm: 8.16.0 xcode: 14.2 mac_m1_arm64_artifacts: &mac_m1_arm64_artifacts diff --git a/internals/scripts/CheckYarn.js b/internals/scripts/CheckYarn.js index aa5be8d1..cf8a24a9 100644 --- a/internals/scripts/CheckYarn.js +++ b/internals/scripts/CheckYarn.js @@ -1,3 +1,25 @@ +const { execSync } = require('child_process'); +const semver = require('semver'); + +const requiredVersionRange = '>=6.x <=8.16.0'; + +try { + const npmVersion = execSync('npm -v').toString().trim(); + + if (!semver.satisfies(npmVersion, requiredVersionRange)) { + console.error( + `Error: This project requires npm version ${requiredVersionRange}. You have version ${npmVersion}.\nPlease downgrade your npm, this is due to a bug in node-gyp. Github issue: https://github.com/ganeshrvel/openmtp/issues/367.\ncommand: npm install -g npm@8.16.0` + ); + process.exit(1); + } + + console.info(`Using compatible npm version: ${npmVersion}`); +} catch (error) { + console.error('Error checking npm version:', error); + + process.exit(1); +} + if (!/yarn\.js$/.test(process.env.npm_execpath || '')) { console.warn( "\u001b[33mYou don't seem to be using yarn. This could produce unexpected results.\u001b[39m" diff --git a/package.json b/package.json index 5933190c..fd0d2487 100644 --- a/package.json +++ b/package.json @@ -235,7 +235,7 @@ }, "devEngines": { "node": ">=16.x", - "npm": ">=6.x", + "npm": ">=6.x <=8.16.0", "yarn": ">=0.21.3" } }