From 3a160c3e22dcb90ecb0394c3003c117bdf0db280 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Tue, 3 Dec 2024 10:22:48 +0000 Subject: [PATCH] fix(rojo): move action map to top level and lazily evaluate --- src/generators/rojo/sourcemap.luau | 42 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/generators/rojo/sourcemap.luau b/src/generators/rojo/sourcemap.luau index 4d716b1..612e518 100644 --- a/src/generators/rojo/sourcemap.luau +++ b/src/generators/rojo/sourcemap.luau @@ -5,6 +5,28 @@ local stdio = require("@lune/stdio") local PLATFORM_SEP = if process.os == "windows" then "\\" else "/" +-- A mapping of things to do depending on the file present +local PATH_ACTION_MAP: { [string]: (dir: string) -> number? } = { + ["default.project.json"] = function(dir) + return process.spawn("rojo", { "sourcemap", dir }, { + cwd = process.cwd, + env = process.env, + stdio = "forward", + }).code + end, + + ["init.lua"] = function() + return stdio.write( + serde.encode("json", { filePaths = { "init.lua" } }, false) + ) + end, + ["init.luau"] = function() + return stdio.write( + serde.encode("json", { filePaths = { "init.luau" } }, false) + ) + end, +} + --- Writes a Rojo sourcemap for the project in the provided directory or the current --- working directory to standard output. @@ -12,25 +34,7 @@ local PLATFORM_SEP = if process.os == "windows" then "\\" else "/" --- * The current process lacks permissions to a file --- * Any I/O error occurs return function(packageDirectory: string?): boolean - packageDirectory = packageDirectory or process.cwd - - -- A mapping of things to do depending on the file present - local PATH_ACTION_MAP: { [string]: (dir: string) -> number? } = { - ["default.project.json"] = function(dir) - return process.spawn("rojo", { "sourcemap", dir }, { - cwd = process.cwd, - env = process.env, - stdio = "forward", - }).code - end, - - ["init.lua"] = stdio.write( - serde.encode("json", { filePaths = { "init.lua" } }, false) - ), - ["init.luau"] = stdio.write( - serde.encode("json", { filePaths = { "init.luau" } }, false) - ), - } + packageDirectory = packageDirectory or process.cwd -- We go through the action mappings in order of priority and check for the -- file predicates, if present, we execute the action and report our status