Skip to content

Commit 6f64be2

Browse files
authored
fix bug for yarn update single (#7)
2 parents cd2b2e4 + 317b7b5 commit 6f64be2

File tree

10 files changed

+247
-194
lines changed

10 files changed

+247
-194
lines changed

TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
- [x] Update all packages
1212
- [x] Update single package
1313
- [x] Add health check command
14+
- [] Add tests
15+
- [] Add list of updated packages after update command
1416
- [] Support PyPi

lua/package-version/command.lua

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,19 @@ end
1717
M.register_commands = function(config)
1818
create_command("PackageVersionInstalled", function()
1919
strategy.installed(config)
20-
end, "Toggle instaled package version")
20+
end, "Toggle installed package version")
2121

2222
create_command("PackageVersionOutdated", function()
2323
strategy.outdated(config)
24-
end, "Togglge outdated package version")
24+
end, "Toggle outdated package version")
2525

2626
create_command("PackageVersionUpdateAll", function()
2727
strategy.update_all(config)
2828
end, "Update all packages")
2929

30-
create_command("PackageVersionUpdateOne", function()
30+
create_command("PackageVersionUpdateSingle", function()
3131
strategy.update_single(config)
32-
end, "Update singgle packages")
32+
end, "Update single package")
3333
end
3434

35-
-- M.register_autocmds = function()
36-
-- vim.api.nvim_create_augroup("InstlledGroup", { clear = true })
37-
--
38-
-- vim.api.nvim_create_autocmd({ "BufReadPost" }, {
39-
-- group = "InstlledGroup",
40-
-- pattern = "composer.json",
41-
-- callback = function()
42-
-- vim.api.nvim_command("PackageVersionInstalled")
43-
-- vim.api.nvim_command("PackageVersionInstalled")
44-
-- end,
45-
-- })
46-
-- end
4735
return M

lua/package-version/health.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ local executable_managers = function()
3535
else
3636
vim.health.warn(
3737
"Local Pnpm is not found in your system PATH.",
38-
"In case you are using Pnpm, or using it via docker, you can ignore this warning"
38+
"In case you are not using Pnpm, or using it via docker, you can ignore this warning"
3939
)
4040
end
4141

@@ -46,12 +46,12 @@ local executable_managers = function()
4646
else
4747
vim.health.warn(
4848
"Local Yarn is not found in your system PATH.",
49-
"In case you are using Yarn, or using it via docker, you can ignore this warning"
49+
"In case you are not using Yarn, or using it via docker, you can ignore this warning"
5050
)
5151
end
5252

5353
if count_of_available_managers == 0 then
54-
vim.health.error("No package managers found localay", {
54+
vim.health.error("No package managers found locally", {
5555
"You have to install at least one of the supported package managers: Composer, Npm, Pnpm, Yarn.",
5656
"Or you can use via docker by setting up the docker configuration.",
5757
})
@@ -66,14 +66,14 @@ function M.check()
6666
vim.health.info("Depends on on your project you'll not have to have all package managers.")
6767

6868
if vim.fn.executable("docker") == 1 then
69-
vim.health.ok("Docker is not installed.")
69+
vim.health.ok("Docker is installed.")
7070

7171
local docker = plugin.config.docker
7272

7373
if not docker then
7474
vim.health.warn(
7575
"Docker configuration is not set.",
76-
"In case you have plugin manager installed localy you can ignore this warning"
76+
"In case you have plugin manager installed locally you can ignore this warning"
7777
)
7878

7979
executable_managers()
@@ -85,7 +85,7 @@ function M.check()
8585
else
8686
vim.health.warn(
8787
"Composer Docker container name is not set.",
88-
"If you are not using composer, or you are using localy, you can ignore this warning"
88+
"If you are not using composer, or you are using locally, you can ignore this warning"
8989
)
9090
end
9191

@@ -96,7 +96,7 @@ function M.check()
9696
else
9797
vim.health.warn(
9898
"Npm Docker container name is not set.",
99-
"If you are not using npm, or you are using localy, you can ignore this warning"
99+
"If you are not using npm, or you are using locally, you can ignore this warning"
100100
)
101101
end
102102

@@ -107,7 +107,7 @@ function M.check()
107107
else
108108
vim.health.warn(
109109
"Pnpm Docker container name is not set.",
110-
"If you are not using pnpm, or you are using localy, you can ignore this warning"
110+
"If you are not using pnpm, or you are using locally, you can ignore this warning"
111111
)
112112
end
113113

@@ -118,14 +118,14 @@ function M.check()
118118
else
119119
vim.health.warn(
120120
"Yarn Docker container name is not set.",
121-
"If you are not using yarn, or you are using localy, you can ignore this warning"
121+
"If you are not using yarn, or you are using locally, you can ignore this warning"
122122
)
123123
end
124124

125125
if count_of_containers == 0 then
126-
vim.health.error("Docke config is detected without any container set.", {
126+
vim.health.error("Docker config is detected without any container set.", {
127127
"You have to set at least one of the supported package manager container names: composer_container_name, npm_container_name, pnpm_container_name, yarn_container_name",
128-
"In case you wanna use from local, you have to remove docker config entirelly",
128+
"In case you wanna use from local, you have to remove docker config entirely",
129129
})
130130

131131
executable_managers()

lua/package-version/package-manager/composer.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ M.installed = function(package_config)
6464

6565
local on_exit = function(job_id, code, event)
6666
if code ~= 0 then
67-
logger.error("Command 'composer outdated' failed with code: " .. code)
67+
logger.error("Command 'composer show' failed with code: " .. code)
68+
69+
spinner.hide()
70+
is_installed_command_running = false
6871

6972
return
7073
end
@@ -138,7 +141,7 @@ M.installed = function(package_config)
138141
end
139142

140143
---@param package_config? PackageVersionConfig
141-
M.outated = function(package_config)
144+
M.outdated = function(package_config)
142145
if is_outdated_command_running then
143146
logger.warning("Composer outdated command is already running.")
144147

@@ -169,6 +172,9 @@ M.outated = function(package_config)
169172
if code ~= 0 then
170173
logger.error("Command 'composer outdated' failed with code: " .. code)
171174

175+
spinner.hide()
176+
is_outdated_command_running = false
177+
172178
return
173179
end
174180

@@ -275,7 +281,7 @@ M.update_all = function(package_config)
275281
return
276282
end
277283

278-
spinner.hide("Composer packages updated sucessuflly!")
284+
spinner.hide("Composer packages updated successfully!")
279285

280286
is_update_all_command_running = false
281287
end
@@ -335,7 +341,7 @@ M.update_single = function(package_config)
335341
if is_package_up_to_date then
336342
spinner.hide("Package " .. package_name .. " is already up to date!")
337343
else
338-
spinner.hide("Package " .. package_name .. " updated sucessuflly!")
344+
spinner.hide("Package " .. package_name .. " updated successfully!")
339345
end
340346

341347
is_update_single_command_running = false

lua/package-version/package-manager/npm.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ M.installed = function(package_config)
5858
local installed = {}
5959

6060
local on_exit = function(code)
61-
-- if code ~= 0 then
62-
-- logger.error("Command NPM installed' failed with code: " .. code)
63-
--
64-
-- return
65-
-- end
61+
if code ~= 0 then
62+
logger.error("Command 'npm list' failed with code: " .. code)
63+
64+
spinner.hide()
65+
is_installed_command_running = false
66+
67+
return
68+
end
6669

6770
local json_str = table.concat(installed, "\n")
6871

@@ -150,7 +153,17 @@ M.outdated = function(package_config)
150153

151154
local outdated = {}
152155

153-
local on_exit = function()
156+
local on_exit = function(code)
157+
-- npm outdated returns exit code 1 when outdated packages exist, which is expected
158+
if code ~= 0 and code ~= 1 then
159+
logger.error("Command 'npm outdated' failed with code: " .. code)
160+
161+
spinner.hide()
162+
is_outdated_command_running = false
163+
164+
return
165+
end
166+
154167
local json_str = table.concat(outdated, "\n")
155168

156169
local ok
@@ -263,7 +276,7 @@ M.update_all = function(package_config)
263276
return
264277
end
265278

266-
spinner.hide("NPM packages updated sucessuflly!")
279+
spinner.hide("NPM packages updated successfully!")
267280

268281
is_update_all_command_running = false
269282
end
@@ -337,7 +350,7 @@ M.update_single = function(package_config)
337350
if result.changed == 0 then
338351
spinner.hide("Package " .. package_name .. " is already up to date!")
339352
else
340-
spinner.hide("Package " .. package_name .. " updated sucessuflly!")
353+
spinner.hide("Package " .. package_name .. " updated successfully!")
341354
end
342355

343356
is_update_single_command_running = false

lua/package-version/package-manager/pnpm.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ M.installed = function(package_config)
5959

6060
local on_exit = function(job_id, code, event)
6161
if code ~= 0 then
62-
logger.error("Command PNPM installed' failed with code: " .. code)
62+
logger.error("Command 'pnpm list' failed with code: " .. code)
63+
64+
spinner.hide()
65+
is_installed_command_running = false
6366

6467
return
6568
end
@@ -155,6 +158,16 @@ M.outdated = function(package_config)
155158
local outdated = {}
156159

157160
local on_exit = function(job_id, code, event)
161+
-- pnpm outdated returns exit code 1 when outdated packages exist, which is expected
162+
if code ~= 0 and code ~= 1 then
163+
logger.error("Command 'pnpm outdated' failed with code: " .. code)
164+
165+
spinner.hide()
166+
is_outdated_command_running = false
167+
168+
return
169+
end
170+
158171
local json_str = table.concat(outdated, "\n")
159172

160173
local ok
@@ -270,7 +283,7 @@ M.update_all = function(package_config)
270283
return
271284
end
272285

273-
spinner.hide("PNPM packages updated sucessuflly!")
286+
spinner.hide("PNPM packages updated successfully!")
274287

275288
is_update_all_command_running = false
276289
end
@@ -329,7 +342,7 @@ M.update_single = function(package_config)
329342
if is_package_up_to_date then
330343
spinner.hide("Package " .. package_name .. " is already up to date!")
331344
else
332-
spinner.hide("Package " .. package_name .. " updated sucessuflly!")
345+
spinner.hide("Package " .. package_name .. " updated successfully!")
333346
end
334347

335348
is_update_single_command_running = false

0 commit comments

Comments
 (0)