Skip to content

Commit

Permalink
Merge pull request #3482 from Shopify/remove-semver
Browse files Browse the repository at this point in the history
Remove semver and upgrade cloudflared
  • Loading branch information
isaacroldan authored Feb 26, 2024
2 parents 167d025 + 04afd54 commit f9ff722
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/plugin-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
},
"dependencies": {
"@oclif/core": "3.15.1",
"@shopify/cli-kit": "3.56.0",
"semver": "7.5.4"
"@shopify/cli-kit": "3.56.0"
},
"devDependencies": {
"vite": "^4.4.9",
Expand Down
23 changes: 19 additions & 4 deletions packages/plugin-cloudflare/scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {pipeline} from 'stream'
import {execSync, execFileSync} from 'child_process'
import {createHash} from 'node:crypto'
import {chmodSync, existsSync, mkdirSync, renameSync, unlinkSync, createWriteStream, readFileSync} from 'fs'
import semver from 'semver'

const CLOUDFLARE_VERSION = '2023.5.1'
const CLOUDFLARE_REPO = `https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARE_VERSION}/`
const EXPECTED_CLOUDFLARE_VERSION = '2024.2.1'
const CLOUDFLARE_REPO = `https://github.com/cloudflare/cloudflared/releases/download/${EXPECTED_CLOUDFLARE_VERSION}/`

const LINUX_URL = {
arm64: 'cloudflared-linux-arm64',
Expand Down Expand Up @@ -52,6 +51,8 @@ function getBinPathTarget() {
}

export default async function install() {
// Don't install cloudflare if the SHOPIFY_CLI_IGNORE_CLOUDFLARED environment variable is set
if (process.env.SHOPIFY_CLI_IGNORE_CLOUDFLARED) return
const [major, minor, patch] = process.versions.node.split('.').map(Number)
// Fetch API is not available for <18. Added this check because our release process uses node 16.
if (major < 18) return
Expand All @@ -69,7 +70,7 @@ export default async function install() {
try {
const versionArray = execFileSync(binTarget, ['--version'], {encoding: 'utf8'}).split(' ')
const versionNumber = versionArray.length > 2 ? versionArray[2] : '0.0.0'
const needsUpdate = semver.gt(CLOUDFLARE_VERSION, versionNumber)
const needsUpdate = versionIsGreaterThan(EXPECTED_CLOUDFLARE_VERSION, versionNumber)
if (!needsUpdate) {
console.log('cloudflared already installed, skipping')
return
Expand All @@ -90,6 +91,20 @@ export default async function install() {
}
}

function versionIsGreaterThan(versionA, versionB) {
const [majorA, minorA, patchA] = versionA.split('.').map(Number)
const [majorB, minorB, patchB] = versionB.split('.').map(Number)

// Compare major versions
if (majorA !== majorB) return majorA > majorB

// If major versions are equal, compare minor versions
if (minorA !== minorB) return minorA > minorB

// If minor versions are also equal, compare patch versions
return patchA > patchB
}

async function installLinux(file, binTarget) {
await downloadFile(file, binTarget)
chmodSync(binTarget, '755')
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9ff722

Please sign in to comment.