diff --git a/.lune/csv_printer.luau b/.lune/csv_printer.luau index da2940b..2949598 100644 --- a/.lune/csv_printer.luau +++ b/.lune/csv_printer.luau @@ -4,6 +4,9 @@ local LINE_SEPARATOR = "\n" local COMMA_SEPARATOR = "," +local fs = require("@lune/fs") +local process = require("@lune/process") + local path = process.args[1] or ".lune/data/test.csv" assert(path ~= nil and #path > 0, "No input file path was given") diff --git a/.lune/hello_lune.luau b/.lune/hello_lune.luau index 8e49e46..04d860c 100644 --- a/.lune/hello_lune.luau +++ b/.lune/hello_lune.luau @@ -1,3 +1,9 @@ +local fs = require("@lune/fs") +local net = require("@lune/net") +local process = require("@lune/process") +local stdio = require("@lune/stdio") +local task = require("@lune/task") + --[[ EXAMPLE #1 diff --git a/.lune/http_server.luau b/.lune/http_server.luau index a3a484b..0d0b2d3 100644 --- a/.lune/http_server.luau +++ b/.lune/http_server.luau @@ -1,24 +1,28 @@ --> A basic http server that echoes the given request --> body at /ping and otherwise responds 404 "Not Found" +local net = require("@lune/net") +local process = require("@lune/process") +local task = require("@lune/task") + local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0 then assert(tonumber(process.env.PORT), "Failed to parse port from env") else 8080 -- Create our responder functions -local function pong(request: NetRequest): string +local function pong(request: net.ServeRequest): string return `Pong!\n{request.path}\n{request.body}` end -local function teapot(_request: NetRequest): NetResponse +local function teapot(_request: net.ServeRequest): net.ServeResponse return { status = 418, body = "🫖", } end -local function notFound(_request: NetRequest): NetResponse +local function notFound(_request: net.ServeRequest): net.ServeResponse return { status = 404, body = "Not Found", diff --git a/.lune/websocket_client.luau b/.lune/websocket_client.luau index fe6ae5b..8b394a7 100644 --- a/.lune/websocket_client.luau +++ b/.lune/websocket_client.luau @@ -1,5 +1,9 @@ --> A basic web socket client that communicates with an echo server +local net = require("@lune/net") +local process = require("@lune/process") +local task = require("@lune/task") + local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0 then assert(tonumber(process.env.PORT), "Failed to parse port from env") else 8080 diff --git a/.lune/websocket_server.luau b/.lune/websocket_server.luau index 3e85c9e..773d0be 100644 --- a/.lune/websocket_server.luau +++ b/.lune/websocket_server.luau @@ -1,5 +1,9 @@ --> A basic web socket server that echoes given messages +local net = require("@lune/net") +local process = require("@lune/process") +local task = require("@lune/task") + local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0 then assert(tonumber(process.env.PORT), "Failed to parse port from env") else 8080 diff --git a/.vscode/settings.json b/.vscode/settings.json index 19288c5..c2ba8dd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,15 @@ "luau-lsp.sourcemap.enabled": false, "luau-lsp.types.roblox": false, "luau-lsp.require.mode": "relativeToFile", + "luau-lsp.require.fileAliases": { + "@lune/fs": "./docs/typedefs/FS.luau", + "@lune/net": "./docs/typedefs/Net.luau", + "@lune/process": "./docs/typedefs/Process.luau", + "@lune/roblox": "./docs/typedefs/Roblox.luau", + "@lune/serde": "./docs/typedefs/Serde.luau", + "@lune/stdio": "./docs/typedefs/Stdio.luau", + "@lune/task": "./docs/typedefs/Task.luau" + }, // Luau - ignore type defs file in docs dir and dev scripts we use "luau-lsp.ignoreGlobs": [ "docs/*.d.luau", diff --git a/docs/typedefs/Roblox.luau b/docs/typedefs/Roblox.luau index c7b288b..aa392b4 100644 --- a/docs/typedefs/Roblox.luau +++ b/docs/typedefs/Roblox.luau @@ -1,3 +1,4 @@ +-- TODO: Autogenerate this somehow ... export type Instance = {} --[=[ diff --git a/tests/fs/dirs.luau b/tests/fs/dirs.luau index 7ad4594..3aba43c 100644 --- a/tests/fs/dirs.luau +++ b/tests/fs/dirs.luau @@ -1,3 +1,5 @@ +local fs = require("@lune/fs") + -- Write two inner dirs in the bir dir, a parent and a child fs.writeDir("bin/test_dir/test_inner") diff --git a/tests/fs/files.luau b/tests/fs/files.luau index 47c4653..95beebb 100644 --- a/tests/fs/files.luau +++ b/tests/fs/files.luau @@ -1,3 +1,6 @@ +local fs = require("@lune/fs") +local net = require("@lune/net") + -- Generate test data & make sure our bin dir exists local binary = "" diff --git a/tests/fs/move.luau b/tests/fs/move.luau index 21d47ab..25bd90c 100644 --- a/tests/fs/move.luau +++ b/tests/fs/move.luau @@ -1,3 +1,6 @@ +local fs = require("@lune/fs") +local net = require("@lune/net") + -- Generate test data & make sure our bin dir exists local binary = "" diff --git a/tests/globals/coroutine.luau b/tests/globals/coroutine.luau index f9b8f80..5780b78 100644 --- a/tests/globals/coroutine.luau +++ b/tests/globals/coroutine.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + -- Coroutines should return true, ret values OR false, error local function pass() diff --git a/tests/globals/pcall.luau b/tests/globals/pcall.luau index ceb1c69..7293879 100644 --- a/tests/globals/pcall.luau +++ b/tests/globals/pcall.luau @@ -1,3 +1,6 @@ +local net = require("@lune/net") +local task = require("@lune/task") + local PORT = 9090 -- NOTE: This must be different from -- net tests to let them run in parallel with this file diff --git a/tests/globals/type.luau b/tests/globals/type.luau index 273b53c..09d3ef8 100644 --- a/tests/globals/type.luau +++ b/tests/globals/type.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + local function f() end local thread1 = coroutine.create(f) diff --git a/tests/globals/typeof.luau b/tests/globals/typeof.luau index ac42c28..6cbf198 100644 --- a/tests/globals/typeof.luau +++ b/tests/globals/typeof.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + local function f() end local thread1 = coroutine.create(f) diff --git a/tests/net/request/query.luau b/tests/net/request/query.luau index d816ea3..6048caf 100644 --- a/tests/net/request/query.luau +++ b/tests/net/request/query.luau @@ -1,3 +1,5 @@ +local net = require("@lune/net") + local QUERY: { [string]: string } = { Key = "Value", Hello = "World", diff --git a/tests/net/request/util.luau b/tests/net/request/util.luau index ae020a2..e64d85c 100644 --- a/tests/net/request/util.luau +++ b/tests/net/request/util.luau @@ -1,3 +1,6 @@ +local net = require("@lune/net") +local stdio = require("@lune/stdio") + local util = {} function util.pass(method, url, message) diff --git a/tests/net/serve/requests.luau b/tests/net/serve/requests.luau index 317a6e9..c6042b7 100644 --- a/tests/net/serve/requests.luau +++ b/tests/net/serve/requests.luau @@ -1,3 +1,7 @@ +local net = require("@lune/net") +local task = require("@lune/task") +local process = require("@lune/process") + local PORT = 8080 local URL = `http://127.0.0.1:{PORT}` local RESPONSE = "Hello, lune!" diff --git a/tests/net/serve/websockets.luau b/tests/net/serve/websockets.luau index aa63903..339e674 100644 --- a/tests/net/serve/websockets.luau +++ b/tests/net/serve/websockets.luau @@ -1,3 +1,7 @@ +local net = require("@lune/net") +local task = require("@lune/task") +local process = require("@lune/process") + local PORT = 8081 local URL = `http://127.0.0.1:{PORT}` local WS_URL = `ws://127.0.0.1:{PORT}` diff --git a/tests/net/url/decode.luau b/tests/net/url/decode.luau index 7646894..01fb1b6 100644 --- a/tests/net/url/decode.luau +++ b/tests/net/url/decode.luau @@ -1,2 +1,4 @@ +local net = require("@lune/net") + local decoded = net.urlDecode("%F0%9F%9A%80%20This%20string%20will%20be%20decoded.") assert(decoded == "🚀 This string will be decoded.") diff --git a/tests/net/url/encode.luau b/tests/net/url/encode.luau index 6a2f049..230fbaf 100644 --- a/tests/net/url/encode.luau +++ b/tests/net/url/encode.luau @@ -1,2 +1,4 @@ +local net = require("@lune/net") + local encoded = net.urlEncode("🚀 This string will be encoded.") assert(encoded == "%F0%9F%9A%80%20This%20string%20will%20be%20encoded.") diff --git a/tests/process/args.luau b/tests/process/args.luau index 5ee7ef6..6a8bb45 100644 --- a/tests/process/args.luau +++ b/tests/process/args.luau @@ -1,3 +1,5 @@ +local process = require("@lune/process") + assert(#process.args > 0, "No process arguments found") assert(process.args[1] == "Foo", "Invalid first argument to process") diff --git a/tests/process/cwd.luau b/tests/process/cwd.luau index a41d42c..02bba4c 100644 --- a/tests/process/cwd.luau +++ b/tests/process/cwd.luau @@ -1,3 +1,5 @@ +local process = require("@lune/process") + assert(process.cwd ~= nil, "Process cwd is missing") assert(type(process.cwd) == "string", "Process cwd is not a string") diff --git a/tests/process/env.luau b/tests/process/env.luau index 1e1bd43..46a4425 100644 --- a/tests/process/env.luau +++ b/tests/process/env.luau @@ -1,3 +1,5 @@ +local process = require("@lune/process") + local randomKey = string.format("LUNE_TEST_%d", math.random(1, 999_999)) assert(process.env[randomKey] == nil, "Unset variable returned a non-nil value") diff --git a/tests/process/exit.luau b/tests/process/exit.luau index eec67ca..e5a8f33 100644 --- a/tests/process/exit.luau +++ b/tests/process/exit.luau @@ -1,3 +1,7 @@ +local fs = require("@lune/fs") +local task = require("@lune/task") +local process = require("@lune/process") + local function assert(condition, err) if not condition then task.spawn(error, err) diff --git a/tests/process/spawn.luau b/tests/process/spawn.luau index 2449a06..a698825 100644 --- a/tests/process/spawn.luau +++ b/tests/process/spawn.luau @@ -1,3 +1,6 @@ +local task = require("@lune/task") +local process = require("@lune/process") + -- Spawning a child process should work with options local result = process.spawn("ls", { diff --git a/tests/require/tests/async_concurrent.luau b/tests/require/tests/async_concurrent.luau index e0da822..79af3ff 100644 --- a/tests/require/tests/async_concurrent.luau +++ b/tests/require/tests/async_concurrent.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + local module1 local module2 diff --git a/tests/require/tests/async_sequential.luau b/tests/require/tests/async_sequential.luau index 5bedc3b..1d2b39f 100644 --- a/tests/require/tests/async_sequential.luau +++ b/tests/require/tests/async_sequential.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + local module1 = require("./modules/async") local module2 = require("./modules/async") diff --git a/tests/require/tests/builtins.luau b/tests/require/tests/builtins.luau index f1b84e7..36d0193 100644 --- a/tests/require/tests/builtins.luau +++ b/tests/require/tests/builtins.luau @@ -1,8 +1,8 @@ -local fs = require("@lune/fs") :: typeof(fs) -local net = require("@lune/net") :: typeof(net) -local process = require("@lune/process") :: typeof(process) -local stdio = require("@lune/stdio") :: typeof(stdio) -local task = require("@lune/task") :: typeof(task) +local fs = require("@lune/fs") +local net = require("@lune/net") +local process = require("@lune/process") +local stdio = require("@lune/stdio") +local task = require("@lune/task") assert(type(fs.move) == "function") assert(type(net.request) == "function") diff --git a/tests/require/tests/modules/async.luau b/tests/require/tests/modules/async.luau index 86bb775..c73d11c 100644 --- a/tests/require/tests/modules/async.luau +++ b/tests/require/tests/modules/async.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + task.wait(0.25) return { diff --git a/tests/roblox/files/readModelFile.luau b/tests/roblox/files/readModelFile.luau index 128059a..807a462 100644 --- a/tests/roblox/files/readModelFile.luau +++ b/tests/roblox/files/readModelFile.luau @@ -1,4 +1,4 @@ -local fs = require("@lune/fs") :: any +local fs = require("@lune/fs") local roblox = require("@lune/roblox") :: any local modelDirs = {} diff --git a/tests/roblox/files/readPlaceFile.luau b/tests/roblox/files/readPlaceFile.luau index 7f70c4c..2b05365 100644 --- a/tests/roblox/files/readPlaceFile.luau +++ b/tests/roblox/files/readPlaceFile.luau @@ -1,4 +1,4 @@ -local fs = require("@lune/fs") :: any +local fs = require("@lune/fs") local roblox = require("@lune/roblox") :: any local placeDirs = {} diff --git a/tests/serde/json/decode.luau b/tests/serde/json/decode.luau index 3472051..d5ec908 100644 --- a/tests/serde/json/decode.luau +++ b/tests/serde/json/decode.luau @@ -1,3 +1,6 @@ +local net = require("@lune/net") +local serde = require("@lune/serde") + type Response = { products: { { @@ -24,7 +27,7 @@ local response = net.request("https://dummyjson.com/products") assert(response.ok, "Dummy JSON api returned an error") assert(#response.body > 0, "Dummy JSON api returned empty body") -local data: Response = net.jsonDecode(response.body) +local data: Response = serde.decode("json", response.body) assert(type(data.limit) == "number", "Products limit was not a number") assert(type(data.products) == "table", "Products was not a table") diff --git a/tests/serde/json/encode.luau b/tests/serde/json/encode.luau index aa07142..6be3b5a 100644 --- a/tests/serde/json/encode.luau +++ b/tests/serde/json/encode.luau @@ -1,4 +1,4 @@ -local serde = require("@lune/serde") :: any +local serde = require("@lune/serde") local source = require("./source") local decoded = serde.decode("json", source.pretty) diff --git a/tests/serde/toml/decode.luau b/tests/serde/toml/decode.luau index 674eeea..2832587 100644 --- a/tests/serde/toml/decode.luau +++ b/tests/serde/toml/decode.luau @@ -1,4 +1,4 @@ -local serde = require("@lune/serde") :: any +local serde = require("@lune/serde") local source = require("./source") local toml = serde.decode("toml", source.encoded) diff --git a/tests/serde/toml/encode.luau b/tests/serde/toml/encode.luau index 986ae9b..6ddfedc 100644 --- a/tests/serde/toml/encode.luau +++ b/tests/serde/toml/encode.luau @@ -1,4 +1,4 @@ -local serde = require("@lune/serde") :: any +local serde = require("@lune/serde") local source = require("./source") local str = serde.encode("toml", source.decoded) diff --git a/tests/stdio/color.luau b/tests/stdio/color.luau index bed92a6..5433cec 100644 --- a/tests/stdio/color.luau +++ b/tests/stdio/color.luau @@ -1,3 +1,5 @@ +local stdio = require("@lune/stdio") + local COLORS_VALID = { "reset", "black", "red", "green", "yellow", "blue", "purple", "cyan", "white" } local COLORS_INVALID = { "", "gray", "grass", "red?", "super red", " ", "none" } diff --git a/tests/stdio/ewrite.luau b/tests/stdio/ewrite.luau index 92daa06..b6d3b3e 100644 --- a/tests/stdio/ewrite.luau +++ b/tests/stdio/ewrite.luau @@ -1,3 +1,6 @@ +local stdio = require("@lune/stdio") +local process = require("@lune/process") + stdio.ewrite("Hello, stderr!") process.exit(0) diff --git a/tests/stdio/format.luau b/tests/stdio/format.luau index f52da01..c4052f3 100644 --- a/tests/stdio/format.luau +++ b/tests/stdio/format.luau @@ -1,3 +1,5 @@ +local stdio = require("@lune/stdio") + assert( stdio.format("Hello", "world", "!") == "Hello world !", "Format should add a single space between arguments" diff --git a/tests/stdio/prompt.luau b/tests/stdio/prompt.luau index e8cc91e..3e63a83 100644 --- a/tests/stdio/prompt.luau +++ b/tests/stdio/prompt.luau @@ -1,3 +1,7 @@ +local task = require("@lune/task") +local stdio = require("@lune/stdio") +local process = require("@lune/process") + -- NOTE: This test is intentionally not included in the -- automated tests suite since it requires user input diff --git a/tests/stdio/style.luau b/tests/stdio/style.luau index 00eed7f..ae86fa3 100644 --- a/tests/stdio/style.luau +++ b/tests/stdio/style.luau @@ -1,3 +1,5 @@ +local stdio = require("@lune/stdio") + local STYLES_VALID = { "reset", "bold", "dim" } local STYLES_INVALID = { "", "*bold*", "dimm", "megabright", "cheerful", "sad", " " } diff --git a/tests/stdio/write.luau b/tests/stdio/write.luau index 4736933..a366083 100644 --- a/tests/stdio/write.luau +++ b/tests/stdio/write.luau @@ -1 +1,3 @@ +local stdio = require("@lune/stdio") + stdio.write("Hello, stdout!") diff --git a/tests/task/cancel.luau b/tests/task/cancel.luau index dfbd0ce..cd0e11c 100644 --- a/tests/task/cancel.luau +++ b/tests/task/cancel.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + -- Cancel should cancel any deferred or delayed threads local flag: boolean = false diff --git a/tests/task/defer.luau b/tests/task/defer.luau index c55e3ca..847efd2 100644 --- a/tests/task/defer.luau +++ b/tests/task/defer.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + -- Deferring a task should return the thread that can then be cancelled local thread = task.defer(function() end) diff --git a/tests/task/delay.luau b/tests/task/delay.luau index e4bcd00..c9d764d 100644 --- a/tests/task/delay.luau +++ b/tests/task/delay.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + -- Delaying a task should return the thread that can then be cancelled local thread = task.delay(0, function() end) diff --git a/tests/task/fcheck.luau b/tests/task/fcheck.luau index 08b6d6d..9275354 100644 --- a/tests/task/fcheck.luau +++ b/tests/task/fcheck.luau @@ -1,3 +1,5 @@ +local stdio = require("@lune/stdio") + return function(index: number, type: string, value: any) if typeof(value) ~= type then error( diff --git a/tests/task/spawn.luau b/tests/task/spawn.luau index 28ec35e..9acd94d 100644 --- a/tests/task/spawn.luau +++ b/tests/task/spawn.luau @@ -1,3 +1,5 @@ +local task = require("@lune/task") + -- Spawning a task should return the thread that can then be cancelled local thread = task.spawn(function() end) diff --git a/tests/task/wait.luau b/tests/task/wait.luau index 2023cd3..377f85b 100644 --- a/tests/task/wait.luau +++ b/tests/task/wait.luau @@ -1,3 +1,6 @@ +local task = require("@lune/task") +local stdio = require("@lune/stdio") + -- Wait should be accurate down to at least 10ms local EPSILON = 10 / 1_000