diff --git a/fnl/hotpot/loader/record/module.fnl b/fnl/hotpot/loader/record/module.fnl index b4b55311..af96984a 100644 --- a/fnl/hotpot/loader/record/module.fnl +++ b/fnl/hotpot/loader/record/module.fnl @@ -15,8 +15,10 @@ src-path (vim.fs.normalize src-path) prefix-length (length prefix) extension-length (length extension) - true-modname (let [src-init? (not= nil (string.find src-path "/init%....$")) ;; TODO: x.tl will fail here - mod-init? (not= nil (string.find modname "%.init$"))] + ;; Expand `mod` into `mod.init` to match the source file if needed. + true-modname (let [src-init? (not= nil (string.find src-path (.. "/init%." extension "$"))) + mod-init? (or (= :init modname) + (not= nil (string.find modname "%.init$")))] (if (and src-init? (not mod-init?)) (.. modname ".init") modname)) diff --git a/lua/hotpot/loader/record/module.lua b/lua/hotpot/loader/record/module.lua index 1df8ddb1..34554001 100644 --- a/lua/hotpot/loader/record/module.lua +++ b/lua/hotpot/loader/record/module.lua @@ -20,8 +20,8 @@ local function new(modname, src_path, _2_) local extension_length = #extension local true_modname do - local src_init_3f = (nil ~= string.find(src_path0, "/init%....$")) - local mod_init_3f = (nil ~= string.find(modname, "%.init$")) + local src_init_3f = (nil ~= string.find(src_path0, ("/init%." .. extension .. "$"))) + local mod_init_3f = (("init" == modname) or (nil ~= string.find(modname, "%.init$"))) if (src_init_3f and not mod_init_3f) then true_modname = (modname .. ".init") else @@ -67,11 +67,9 @@ local function retarget(record, target) elseif (target == "cache") then record["lua-path"] = record["lua-cache-path"] return record - elseif true then + else local _ = target return error("target must be colocate or cache") - else - return nil end end local function _11_(_241) diff --git a/test/test-require-a-fnl-file.fnl b/test/test-require-a-fnl-file.fnl index 93ec4590..d124632e 100644 --- a/test/test-require-a-fnl-file.fnl +++ b/test/test-require-a-fnl-file.fnl @@ -23,8 +23,15 @@ (test-path :abc :abc) ;; basic (test-path :def :def/init) +(test-path :def.init :def/init) (test-path :xyz.init "xyz/init") -(test-path :abc.xyz.p-q-r :abc/xyz/p-q-r) ;; user issue 53, kebab files -(test-path :xc-init :xc-init) ;; user issue 53, kebab files + ;; user issue 53, kebab files +(test-path :abc.xyz.p-q-r :abc/xyz/p-q-r) +(test-path :xc-init :xc-init) +;; issues/129 +(test-path :init :init) +(test-path :fnl :fnl/init) +(test-path :some.code.fnl :some/code/fnl/init) +(test-path :some.code.fnl.init :some/code/fnl/init) (exit) diff --git a/test/test-require-a-fnl-file.lua b/test/test-require-a-fnl-file.lua index 00d027a2..a09c8816 100644 --- a/test/test-require-a-fnl-file.lua +++ b/test/test-require-a-fnl-file.lua @@ -56,11 +56,9 @@ local function test_path(modname, path) local _9_ = ... if (_9_ == true) then return true - elseif true then - local __75_auto = _9_ - return ... else - return nil + local __84_auto = _9_ + return ... end end local function _12_(...) @@ -68,20 +66,16 @@ local function test_path(modname, path) if (_11_ == "return {works = true}") then OK(string.format(("Outputs correct lua code" or ""))) return true - elseif true then + else local __1_auto = _11_ FAIL(string.format(("Outputs correct lua code" or ""))) return false - else - return nil end end return _8_(_12_(...)) - elseif true then - local __75_auto = _7_ - return ... else - return nil + local __84_auto = _7_ + return ... end end local function _16_(...) @@ -89,40 +83,39 @@ local function test_path(modname, path) if (_15_ == true) then OK(string.format(("Creates a lua file at %s" or ""), lua_path)) return true - elseif true then + else local __1_auto = _15_ FAIL(string.format(("Creates a lua file at %s" or ""), lua_path)) return false - else - return nil end end return _6_(_16_(...)) - elseif true then - local __75_auto = _5_ - return ... else - return nil + local __84_auto = _5_ + return ... end end local function _21_() local _19_, _20_ = pcall(require, modname) - if ((_19_ == true) and ((_G.type(_20_) == "table") and ((_20_).works == true))) then + if ((_19_ == true) and ((_G.type(_20_) == "table") and (_20_.works == true))) then OK(string.format(("Can require module %s %s" or ""), modname, fnl_path)) return true - elseif true then + else local __1_auto = _19_ FAIL(string.format(("Can require module %s %s" or ""), modname, fnl_path)) return false - else - return nil end end return _4_(_21_()) end test_path("abc", "abc") test_path("def", "def/init") +test_path("def.init", "def/init") test_path("xyz.init", "xyz/init") test_path("abc.xyz.p-q-r", "abc/xyz/p-q-r") test_path("xc-init", "xc-init") +test_path("init", "init") +test_path("fnl", "fnl/init") +test_path("some.code.fnl", "some/code/fnl/init") +test_path("some.code.fnl.init", "some/code/fnl/init") return exit() \ No newline at end of file