Skip to content

Commit

Permalink
fix: live tunnel arch issue (#4064)
Browse files Browse the repository at this point in the history
* fix(dev): use the correct binary for operating system architecture.

* fix: fixes an issue with downloading the wrong arch for system one

* chore: fix linux arch

* chore: pr feedback and handle ia32 architecture

* chore: remove querystring and use URL

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
lukasholzer and kodiakhq[bot] committed Jan 19, 2022
1 parent 7ec8cdc commit 41c2fdf
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 77 deletions.
19 changes: 4 additions & 15 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
/* eslint-disable promise/prefer-await-to-then,promise/prefer-await-to-callbacks,eslint-comments/disable-enable-pair */
const process = require('process')

const updateNotifier = require('update-notifier')
Expand All @@ -18,23 +17,13 @@ if (require.main === module) {
pkg,
updateCheckInterval: UPDATE_CHECK_INTERVAL,
}).notify()
} catch (error) {
} catch (error_) {
console.log('Error checking for updates:')
console.log(error)
console.log(error_)
}

/** @type {Error} */
let caughtError

const program = createMainCommand()

program.parseAsync(process.argv).catch((error) => {
caughtError = error
})

// long running commands like dev server cannot be caught by a post action hook
// they are running on the main command
process.on('exit', () => {
program.onEnd(caughtError)
})
// eslint-disable-next-line promise/prefer-await-to-then
program.parseAsync(process.argv).catch((error_) => program.onEnd(error_))
}
88 changes: 88 additions & 0 deletions npm-shrinkwrap.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
"mock-fs": "^5.1.2",
"mock-require": "^3.0.3",
"p-timeout": "^4.0.0",
"proxyquire": "^2.1.3",
"seedrandom": "^3.0.5",
"serialize-javascript": "^6.0.0",
"sinon": "^12.0.0",
Expand Down
14 changes: 8 additions & 6 deletions src/commands/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,14 @@ class BaseCommand extends Command {
debug(`${this.name()}:onEnd`)(`Status: ${status}`)
debug(`${this.name()}:onEnd`)(`Duration: ${duration}ms`)

await track('command', {
...payload,
command: this.name(),
duration,
status,
})
try {
await track('command', {
...payload,
command: this.name(),
duration,
status,
})
} catch {}

if (error_ !== undefined) {
error(error_ instanceof Error ? error_ : format(error_), { exit: false })
Expand Down
66 changes: 60 additions & 6 deletions src/lib/exec-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const process = require('process')

const { fetchLatest, fetchVersion, newerVersion, updateAvailable } = require('gh-release-fetch')
const isExe = require('isexe')
const terminalLink = require('terminal-link')

// cannot directly import from ../utils as it would create a circular dependency.
// the file `src/utils/live-tunnel.js` depends on this file
const { NETLIFYDEVWARN, log } = require('../utils/command-helpers')
const { NETLIFYDEVWARN, chalk, error, log } = require('../utils/command-helpers')
const execa = require('../utils/execa')

const isWindows = () => process.platform === 'win32'
Expand Down Expand Up @@ -62,27 +63,80 @@ const shouldFetchLatestVersion = async ({ binPath, execArgs, execName, latestVer
latestVersion,
})
return outdated
} catch (error) {
} catch (error_) {
if (exists) {
log(NETLIFYDEVWARN, `failed checking for new version of '${packageName}'. Using existing version`)
return false
}
throw error
throw error_
}
}

const getArch = () => {
switch (process.arch) {
case 'x64':
return 'amd64'
case 'ia32':
return '386'
default:
return process.arch
}
}

/**
* Tries to get the latest release from the github releases to download the binary.
* Is throwing an error if there is no binary that matches the system os or arch
* @param {object} config
* @param {string} config.destination
* @param {string} config.execName
* @param {string} config.destination
* @param {string} config.extension
* @param {string} config.packageName
* @param {string} [config.latestVersion ]
*/
const fetchLatestVersion = async ({ destination, execName, extension, latestVersion, packageName }) => {
const win = isWindows()
const arch = getArch()
const platform = win ? 'windows' : process.platform
const pkgName = `${execName}-${platform}-${arch}.${extension}`

const release = {
repository: getRepository({ packageName }),
package: `${execName}-${platform}-amd64.${extension}`,
package: pkgName,
destination,
extract: true,
}

const options = getOptions()
await (latestVersion ? fetchVersion({ ...release, version: latestVersion }, options) : fetchLatest(release, options))
const fetch = latestVersion
? fetchVersion({ ...release, version: latestVersion }, options)
: fetchLatest(release, options)

try {
await fetch
} catch (error_) {
if (typeof error_ === 'object' && 'statusCode' in error_ && error_.statusCode === 404) {
const createIssueLink = new URL('https://github.com/netlify/cli/issues/new')
createIssueLink.searchParams.set('assignees', '')
createIssueLink.searchParams.set('labels', 'type: bug')
createIssueLink.searchParams.set('template', 'bug_report.md')
createIssueLink.searchParams.set(
'title',
`${execName} is not supported on ${platform} with CPU architecture ${arch}`,
)

const issueLink = terminalLink('Create a new CLI issue', createIssueLink.href)

error(`The operating system ${chalk.cyan(platform)} with the CPU architecture ${chalk.cyan(
arch,
)} is currently not supported!
Please open up an issue on our CLI repository so that we can support it:
${issueLink}`)
}

error(error_)
}
}

module.exports = { getExecName, shouldFetchLatestVersion, fetchLatestVersion }
module.exports = { getArch, getExecName, shouldFetchLatestVersion, fetchLatestVersion }
Loading

1 comment on commit 41c2fdf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 355 MB

Please sign in to comment.