Skip to content

Commit cf9c0d6

Browse files
authored
FIX: Js update fix (#412)
* fix: js update check * docs(api): update
1 parent 50fec11 commit cf9c0d6

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

docs/docs/usage/api.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ The queue of callbacks resets after this event is triggered.
1010

1111
```lua
1212
require('kulala.api').on("after_next_request", function(data)
13-
vim.print("Request completed")
14-
vim.print("Headers: " .. data.headers)
15-
vim.print("Body: " .. data.body)
16-
vim.print("Complete response: ", data.response)
13+
vim.inspect("Request completed")
14+
vim.inspect("Headers: " .. data.headers)
15+
vim.inspect("Body: " .. data.body)
16+
vim.inspect("Complete response: ", data.response)
1717
end)
1818
```
1919

@@ -23,10 +23,10 @@ Triggered after a request has been successfully completed.
2323

2424
```lua
2525
require('kulala.api').on("after_request", function(data)
26-
vim.print("Request completed")
27-
vim.print("Headers: " .. data.headers)
28-
vim.print("Body: " .. data.body)
29-
vim.print("Complete response: ", data.response)
26+
vim.inspect("Request completed")
27+
vim.inspect("Headers: " .. data.headers)
28+
vim.inspect("Body: " .. data.body)
29+
vim.inspect("Complete response: ", data.response)
3030
end)
3131
```
3232

lua/kulala/parser/scripts/engines/javascript/init.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ local FILE_MAPPING = {
2626

2727
local is_uptodate = function()
2828
local version = FS.read_file(BASE_FILE_VER) or 0
29-
return GLOBALS.VERSION == version
29+
return GLOBALS.VERSION == version and FS.file_exists(BASE_FILE_PRE) and FS.file_exists(BASE_FILE_POST)
3030
end
3131

3232
---@param wait boolean -- wait to complete
3333
M.install_dependencies = function(wait)
34-
if FS.file_exists(BASE_FILE_PRE) and FS.file_exists(BASE_FILE_POST) and is_uptodate() then return true end
34+
if is_uptodate() then return true end
3535

3636
Logger.warn("Javascript base files not found or are out of date.")
3737
Logger.info(

lua/kulala/utils/fs.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ end
6464
---Either returns the absolute path if the path is already absolute or
6565
---joins the path with the current buffer directory
6666
M.get_file_path = function(path)
67-
path = vim.fn.expand(path)
67+
local ex_path = vim.fn.expand(path, true)
68+
path = ex_path ~= "" and ex_path or path
6869

6970
if M.is_absolute_path(path) then return path end
7071
if path:sub(1, 2) == "./" or path:sub(1, 2) == ".\\" then path = path:sub(3) end
@@ -203,6 +204,7 @@ M.get_plugin_tmp_dir = function()
203204
local cache = vim.fn.stdpath("cache")
204205
---@cast cache string
205206
local dir = M.join_paths(cache, "kulala")
207+
206208
M.ensure_dir_exists(dir)
207209
return dir
208210
end
@@ -214,8 +216,6 @@ end
214216

215217
M.get_tmp_scripts_build_dir = function()
216218
local dir = M.join_paths(M.get_plugin_tmp_dir(), "scripts", "build")
217-
M.ensure_dir_exists(dir)
218-
219219
return dir
220220
end
221221

@@ -325,6 +325,8 @@ M.read_file = function(filename, is_binary)
325325
if not f then return end
326326

327327
local content = f:read("*a")
328+
if not content then return end
329+
328330
content = is_binary and content or content:gsub("\r\n", "\n")
329331
f:close()
330332

tests/functional/ui_spec.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,15 @@ describe("UI", function()
497497
wait_for_requests(1)
498498

499499
local win_config = vim.api.nvim_win_get_config(vim.fn.bufwinid(ui_buf))
500-
assert.is_same("right", win_config.split)
500+
assert.is_truthy(win_config.split)
501501
end)
502502

503503
it("opens results in float", function()
504504
kulala.run()
505505
wait_for_requests(1)
506506

507507
local win_config = vim.api.nvim_win_get_config(vim.fn.bufwinid(ui_buf))
508-
assert.is_same("editor", win_config.relative)
508+
assert.is_truthy(win_config.relative)
509509
end)
510510

511511
it("closes float and deletes buffer on 'q'", function()

0 commit comments

Comments
 (0)