diff --git a/autoload/dpp/util.vim b/autoload/dpp/util.vim index 204dd65..891c405 100644 --- a/autoload/dpp/util.vim +++ b/autoload/dpp/util.vim @@ -97,15 +97,12 @@ function dpp#util#_execute_hook(plugin, hook_name, hook) abort endif try - if a:hook->type() == v:t_string - let cmds = a:hook->split('\n') - if !(cmds->empty()) && cmds[0] =~# '^\s*vim9script' && exists(':vim9') - vim9 call execute(cmds[1 : ], '') - else - call execute(cmds, '') - endif + " NOTE: hook may contain \r in Windows + const cmds = a:hook->split('\r\?\n') + if !(cmds->empty()) && cmds[0] =~# '^\s*vim9script' && exists(':vim9') + vim9 call execute(cmds[1 : ], '') else - call call(a:hook, []) + call execute(cmds, '') endif let a:plugin.called[string(a:hook)] = v:true @@ -249,7 +246,7 @@ endfunction function dpp#util#_dos2unix(path) abort call writefile( \ readfile(a:path) - \ ->map({ _, val -> val->substitute("\r", '', 'g')}), + \ ->map({ _, val -> val->substitute('\r', '', 'g')}), \ a:path \ ) endfunction diff --git a/denops/dpp/dpp.ts b/denops/dpp/dpp.ts index ff56c67..0b82640 100644 --- a/denops/dpp/dpp.ts +++ b/denops/dpp/dpp.ts @@ -4,6 +4,7 @@ import { Denops, dirname, extname, + fn, is, join, vars, @@ -115,6 +116,8 @@ export class Dpp { name: string, configReturn: ConfigReturn, ) { + const hasWindows = await fn.has(denops, "win32"); + // Initialize plugins const protocols = await this.getProtocols(denops, options); const recordPlugins: Record = {}; @@ -375,7 +378,9 @@ export class Dpp { // Write state file const stateFile = `${basePath}/${name}/state.vim`; await Deno.writeTextFile(stateFile, stateLines.join("\n")); - await denops.call("dpp#util#_dos2unix", stateFile); + if (hasWindows) { + await denops.call("dpp#util#_dos2unix", stateFile); + } const cacheFile = `${basePath}/${name}/cache.vim`; const cacheLines = [ @@ -387,7 +392,9 @@ export class Dpp { ]), ]; await Deno.writeTextFile(cacheFile, cacheLines.join("\n")); - await denops.call("dpp#util#_dos2unix", cacheFile); + if (hasWindows) { + await denops.call("dpp#util#_dos2unix", cacheFile); + } //console.log(stateLines); //console.log(cacheLines); @@ -409,7 +416,9 @@ export class Dpp { } await Deno.writeTextFile(path, generatedFtplugins[path].join("\n")); - await denops.call("dpp#util#_dos2unix", path); + if (hasWindows) { + await denops.call("dpp#util#_dos2unix", path); + } } } diff --git a/denops/dpp/utils.ts b/denops/dpp/utils.ts index 1c67d39..1cb3538 100644 --- a/denops/dpp/utils.ts +++ b/denops/dpp/utils.ts @@ -34,7 +34,11 @@ export function convert2List(expr: T | T[] | undefined): T[] { return !expr ? [] : is.Array(expr) ? expr : [expr]; } -export async function isDirectory(path: string) { +export async function isDirectory(path: string | undefined) { + if (!path) { + return false; + } + // NOTE: Deno.stat() may be failed try { if ((await Deno.stat(path)).isDirectory) {