diff --git a/src/neovim.ts b/src/neovim.ts index a1b6d41..23f9932 100644 --- a/src/neovim.ts +++ b/src/neovim.ts @@ -9,27 +9,6 @@ import { makeTmpdir, Os, exeName, ensureError } from './utils'; import { exec, unzip } from './shell'; import type { Installed } from './install'; -function assetFileName(os: Os, version: string): string { - switch (os) { - case 'macos': - if (version === 'nightly') { - switch (process.arch) { - case 'arm64': - return 'nvim-macos-arm64.tar.gz'; - case 'x64': - return 'nvim-macos-x86_64.tar.gz'; - default: - throw Error(`Unsupported arch for Neovim ${version} on ${os}: ${process.arch}`); // Should be unreachable - } - } - return 'nvim-macos.tar.gz'; - case 'linux': - return 'nvim-linux64.tar.gz'; - case 'windows': - return 'nvim-win64.zip'; - } -} - interface Version { minor: number; patch: number; @@ -47,31 +26,53 @@ function parseVersion(v: string): Version | null { }; } -export function assetDirName(version: string, os: Os): string { +function assetFileName(os: Os, version: string): string { switch (os) { case 'macos': { - // Until v0.7.0 release, 'nvim-osx64' was the asset directory name on macOS. However it was changed to 'nvim-macos' - // from v0.7.1: https://github.com/neovim/neovim/pull/19029 const v = parseVersion(version); - if (v !== null && (v.minor < 7 || (v.minor === 7 && v.patch < 1))) { - return 'nvim-osx64'; + if (v !== null && v.minor < 10) { + return 'nvim-macos.tar.gz'; + } + switch (process.arch) { + case 'arm64': + return 'nvim-macos-arm64.tar.gz'; + case 'x64': + return 'nvim-macos-x86_64.tar.gz'; + default: + throw Error(`Unsupported arch for Neovim ${version} on ${os}: ${process.arch}`); // Should be unreachable } - // TODO: This 'nightly' check is temporary. - // Once the next version is released, nvim-macos-arm64.tar.gz and nvim-macos-x86_64.tar.gz will be released on 'stable' - // channel. We would need to check the version is 0.9.5 or earlier instead of checking the version is nightly. - if (version === 'nightly') { - // Until v0.9.5, the single asset nvim-macos.tar.gz was released. From v0.10.0, Neovim will provide + } + case 'linux': + return 'nvim-linux64.tar.gz'; + case 'windows': + return 'nvim-win64.zip'; + } +} + +export function assetDirName(version: string, os: Os): string { + switch (os) { + case 'macos': { + const v = parseVersion(version); + if (v !== null) { + // Until v0.7.0 release, 'nvim-osx64' was the asset directory name on macOS. However it was changed to + // 'nvim-macos' from v0.7.1: https://github.com/neovim/neovim/pull/19029 + if (v.minor < 7 || (v.minor === 7 && v.patch < 1)) { + return 'nvim-osx64'; + } + // Until v0.9.5, the single asset nvim-macos.tar.gz is released. From v0.10.0, Neovim provides // nvim-macos-arm64.tar.gz (for Apple Silicon) and nvim-macos-x86_64.tar.gz (for Intel Mac). (#30) - switch (process.arch) { - case 'arm64': - return 'nvim-macos-arm64'; - case 'x64': - return 'nvim-macos-x86_64'; - default: - throw Error(`Unsupported arch for Neovim ${version} on ${os}: ${process.arch}`); // Should be unreachable + if (v.minor < 10) { + return 'nvim-macos'; } } - return 'nvim-macos'; + switch (process.arch) { + case 'arm64': + return 'nvim-macos-arm64'; + case 'x64': + return 'nvim-macos-x86_64'; + default: + throw Error(`Unsupported arch for Neovim ${version} on ${os}: ${process.arch}`); // Should be unreachable + } } case 'linux': return 'nvim-linux64'; diff --git a/test/neovim.ts b/test/neovim.ts index 7183c09..67b17e5 100644 --- a/test/neovim.ts +++ b/test/neovim.ts @@ -134,20 +134,22 @@ describe('Neovim installation', function () { A.equal(assetDirName('v0.6.1', 'macos'), 'nvim-osx64'); }); - it('returns "nvim-macos" when Neovim version is 0.7.1 or later on macOS', function () { + it('returns "nvim-macos" when Neovim version is 0.7.1 or later and 0.9.5 or earlier on macOS', function () { A.equal(assetDirName('v0.7.1', 'macos'), 'nvim-macos'); - A.equal(assetDirName('v0.10.0', 'macos'), 'nvim-macos'); - A.equal(assetDirName('v1.0.0', 'macos'), 'nvim-macos'); - A.equal(assetDirName('stable', 'macos'), 'nvim-macos'); + A.equal(assetDirName('v0.8.0', 'macos'), 'nvim-macos'); + A.equal(assetDirName('v0.9.5', 'macos'), 'nvim-macos'); }); - it('returns "nvim-macos-arm64" or "nvim-macos-x86_64" based on the CPU arch when Neovim version is nightly on macOS', function () { + it('returns "nvim-macos-arm64" or "nvim-macos-x86_64" based on the CPU arch when Neovim version is 0.10.0 later on macOS', function () { const expected = process.arch === 'arm64' ? 'nvim-macos-arm64' : process.arch === 'x64' ? 'nvim-macos-x86_64' : 'nvim-macos'; + A.equal(assetDirName('v0.10.0', 'macos'), expected); + A.equal(assetDirName('v1.0.0', 'macos'), expected); + A.equal(assetDirName('stable', 'macos'), expected); A.equal(assetDirName('nightly', 'macos'), expected); }); });