Skip to content

Commit

Permalink
Merge branch 'issue-37' (fix #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jul 28, 2024
2 parents b4bfe30 + 4f5a280 commit dfc39c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
- name: Validate action result
run: node ./scripts/post_action_check.js "${{ matrix.neovim }}" "${{ matrix.version }}" "${{ steps.vim.outputs.executable }}"

# separate from stable-and-nightly since jobs.{id}.name.strategy.matrix.exclude seems not working
# Note: separate from stable-and-nightly since jobs.{id}.name.strategy.matrix.exclude seems not working
# Note: This is the last version which should not run `vim.exe -silent -register` on Windows (#37)
vim-v9_1_0626:
name: Vim v9.1.0626
strategy:
Expand Down
41 changes: 25 additions & 16 deletions src/vim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import { exec, unzip, Env } from './shell';
import { makeTmpdir, exeName, Os, ensureError } from './utils';
import type { Installed } from './install';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function versionIsOlderThan8_2_1119(version: string): boolean {
export function versionIsOlderThan(version: string, vmajor: number, vminor: number, vpatch: number): boolean {
// Note: Patch version may not exist on v7 or earlier
const majorStr = version.match(/^v(\d+)\./)?.[1];
if (!majorStr) {
return false; // Invalid case. Should be unreachable
}
const major = parseInt(majorStr, 10);

if (major !== 8) {
return major < 8;
if (major !== vmajor) {
return major < vmajor;
}

const m = version.match(/\.(\d+)\.(\d{4})$/); // Extract minor and patch versions
Expand All @@ -29,12 +28,12 @@ export function versionIsOlderThan8_2_1119(version: string): boolean {
}

const minor = parseInt(m[1], 10);
if (minor !== 2) {
return minor < 2;
if (minor !== vminor) {
return minor < vminor;
}

const patch = parseInt(m[2], 10);
return patch < 1119;
return patch < vpatch;
}

async function getXcode11DevDir(): Promise<string | null> {
Expand Down Expand Up @@ -70,7 +69,7 @@ export async function buildVim(version: string, os: Os, configureArgs: string |
}

const env: Env = {};
if (os === 'macos' && versionIsOlderThan8_2_1119(version)) {
if (os === 'macos' && versionIsOlderThan(version, 8, 2, 1119)) {
const dir = await getXcode11DevDir();
if (dir !== null) {
// Vim before v8.2.1119 cannot be built with Xcode 12 or later. It requires Xcode 11.
Expand Down Expand Up @@ -192,19 +191,29 @@ async function installVimAssetOnWindows(file: string, url: string, dirSuffix: st
return destDir;
}

export async function installVimOnWindows(tag: string, dirSuffix: string): Promise<Installed> {
export async function installVimOnWindows(tag: string, version: string): Promise<Installed> {
const ver = tag.slice(1); // Strip 'v' prefix
// e.g. https://github.com/vim/vim-win32-installer/releases/download/v8.2.0158/gvim_8.2.0158_x64.zip
const url = `https://github.com/vim/vim-win32-installer/releases/download/${tag}/gvim_${ver}_x64.zip`;
const file = `gvim_${ver}_x64.zip`;
const destDir = await installVimAssetOnWindows(file, url, dirSuffix);
return {
executable: exeName(false, 'windows'),
binDir: destDir,
};
const destDir = await installVimAssetOnWindows(file, url, version);
const executable = exeName(false, 'windows');

// From v9.1.0631, vim.exe and gvim.exe share the same core, so OLE is enabled even in vim.exe.
// This command registers the vim64.dll as a type library. Without the command, vim.exe will
// ask the registration with GUI dialog and the process looks hanging. (#37)
//
// See: https://github.com/vim/vim/issues/15372
if (version === 'stable' || version === 'nightly' || !versionIsOlderThan(version, 9, 1, 631)) {
const bin = path.join(destDir, executable);
await exec(bin, ['-silent', '-register']);
core.debug('Registered vim.exe as a type library');
}

return { executable, binDir: destDir };
}

export async function installNightlyVimOnWindows(dirSuffix: string): Promise<Installed> {
export async function installNightlyVimOnWindows(version: string): Promise<Installed> {
const latestTag = await detectLatestWindowsReleaseTag();
return installVimOnWindows(latestTag, dirSuffix);
return installVimOnWindows(latestTag, version);
}
6 changes: 3 additions & 3 deletions test/vim.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as A } from 'assert';
import * as path from 'path';
import mock = require('mock-require');
import { installVimOnWindows, detectLatestWindowsReleaseTag, versionIsOlderThan8_2_1119 } from '../src/vim';
import { installVimOnWindows, detectLatestWindowsReleaseTag, versionIsOlderThan } from '../src/vim';
import type { Installed } from '../src/install';
import type { Os } from '../src/utils';
import type { Config } from '../src/config';
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('buildVim()', function () {
});
});

describe('versionIsOlderThan8_2_1119()', function () {
describe('versionIsOlderThan()', function () {
const testCases: [string, boolean][] = [
// Equal
['v8.2.1119', false],
Expand All @@ -190,7 +190,7 @@ describe('versionIsOlderThan8_2_1119()', function () {
for (const tc of testCases) {
const [v, expected] = tc;
it(`${v} is ${expected ? 'older' : 'equal or newer than'} 8.2.1119`, function () {
A.equal(versionIsOlderThan8_2_1119(v), expected);
A.equal(versionIsOlderThan(v, 8, 2, 1119), expected);
});
}
});
Expand Down

0 comments on commit dfc39c1

Please sign in to comment.