Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Busybox wget support #1829

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lua/mason-core/fetch.lua
Original file line number Diff line number Diff line change
@@ -75,19 +75,23 @@ local function fetch(url, opts)
end

local function wget()
local headers =
_.sort_by(_.identity, _.map(_.compose(_.format "--header=%s", _.join ": "), _.to_pairs(opts.headers)))
local headers = {}
for k, v in pairs(opts.headers) do
table.insert(headers, "--header")
table.insert(headers, k .. ": " .. v)
end

return spawn.wget {
headers,
"-nv",
"-o",
"/dev/null",
"-O",
opts.out_file or "-",
("--timeout=%s"):format(TIMEOUT_SECONDS),
("--method=%s"):format(opts.method),
opts.data and {
("--body-data=%s"):format(opts.data) or vim.NIL,
"-T",
TIMEOUT_SECONDS,
opts.data and opts.method == "POST" and {
"--post-data",
opts.data,
} or vim.NIL,
url,
}
2 changes: 1 addition & 1 deletion lua/mason/health.lua
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ local function check_core_utils()
check { name = "unzip", cmd = "unzip", args = { "-v" }, relaxed = true }

-- wget is used interchangeably with curl, but with lower priority, so we mark wget as relaxed
check { cmd = "wget", args = { "--version" }, name = "wget", relaxed = true }
check { cmd = "wget", args = { "--help" }, name = "wget", relaxed = true }
check { cmd = "curl", args = { "--version" }, name = "curl" }
check {
cmd = "gzip",
19 changes: 10 additions & 9 deletions tests/mason-core/fetch_spec.lua
Original file line number Diff line number Diff line change
@@ -22,18 +22,19 @@ describe("fetch", function()
assert.spy(spawn.curl).was_called(1)
assert.spy(spawn.wget).was_called_with {
{
("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
"--header",
("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
version.VERSION
),
"--header=X-Custom-Header: here",
"--header",
"X-Custom-Header: here",
},
"-nv",
"-o",
"/dev/null",
"-O",
"-",
"--timeout=30",
"--method=GET",
"-T",
30,
vim.NIL, -- body-data
"https://api.github.com",
}
@@ -86,17 +87,17 @@ describe("fetch", function()

assert.spy(spawn.wget).was_called_with {
{
("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
"--header",
("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
version.VERSION
),
},
"-nv",
"-o",
"/dev/null",
"-O",
"/test.json",
"--timeout=30",
"--method=GET",
"-T",
30,
vim.NIL, -- body-data
"https://api.github.com/data",
}