Skip to content

Commit 83e18fe

Browse files
committed
feat: stop bundling plugin, closes #25
1 parent 962df75 commit 83e18fe

8 files changed

Lines changed: 108 additions & 234 deletions

File tree

spec/behavior_spec.lua

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ describe("luarocks-build-lls-addon", function()
256256

257257
it("works when there is a plugin included", function()
258258
setupProject("with-plugin")
259-
assert.are_equal("file", mode(path(LUA_DIR, "types.lua")))
259+
assert.are_equal("file", mode(path(INSTALL_DIR, "plugin.lua")))
260260
local luarc = json.read(".luarc.json")
261261
assert.are_same({
262262
runtime = {
263263
plugin = {
264264
FAKE_LOADER_SOURCE,
265-
path(LUA_DIR, "types.lua"),
265+
path(INSTALL_DIR, "plugin.lua"),
266266
},
267267
},
268268
}, luarc)
@@ -282,14 +282,14 @@ describe("luarocks-build-lls-addon", function()
282282
it("works when there is a library and plugin included", function()
283283
setupProject("with-lib-plugin")
284284
assert.are_equal("directory", mode(path(INSTALL_DIR, "library")))
285-
assert.are_equal("file", mode(path(LUA_DIR, "types.lua")))
285+
assert.are_equal("file", mode(path(INSTALL_DIR, "plugin.lua")))
286286
local luarc = json.read(".luarc.json")
287287
assert.are_same({
288288
workspace = { library = { path(INSTALL_DIR, "library") } },
289289
runtime = {
290290
plugin = {
291291
FAKE_LOADER_SOURCE,
292-
path(LUA_DIR, "types.lua"),
292+
path(INSTALL_DIR, "plugin.lua"),
293293
},
294294
},
295295
}, luarc)
@@ -298,14 +298,30 @@ describe("luarocks-build-lls-addon", function()
298298
it("works when there is a config and plugin included", function()
299299
setupProject("with-config-plugin")
300300
assert.are_equal("file", mode(path(INSTALL_DIR, "config.json")))
301-
assert.are_equal("file", mode(path(LUA_DIR, "types.lua")))
301+
assert.are_equal("file", mode(path(INSTALL_DIR, "plugin.lua")))
302302
local luarc = json.read(".luarc.json")
303303
assert.are_same({
304304
example = true,
305305
runtime = {
306306
plugin = {
307307
FAKE_LOADER_SOURCE,
308-
path(LUA_DIR, "types.lua"),
308+
path(INSTALL_DIR, "plugin.lua"),
309+
},
310+
},
311+
}, luarc)
312+
end)
313+
314+
it("works when there is a multi-file plugin included", function()
315+
setupProject("with-multi-file-plugin")
316+
assert.are_equal("file", mode(path(INSTALL_DIR, "plugin.lua")))
317+
assert.are_equal("directory", mode(path(INSTALL_DIR, "plugin")))
318+
assert.are_equal("file", mode(path(INSTALL_DIR, "plugin", "submodule.lua")))
319+
local luarc = json.read(".luarc.json")
320+
assert.are_same({
321+
runtime = {
322+
plugin = {
323+
FAKE_LOADER_SOURCE,
324+
path(INSTALL_DIR, "plugin.lua"),
309325
},
310326
},
311327
}, luarc)
@@ -315,15 +331,15 @@ describe("luarocks-build-lls-addon", function()
315331
setupProject("with-lib-config-plugin")
316332
assert.are_equal("directory", mode(path(INSTALL_DIR, "library")))
317333
assert.are_equal("file", mode(path(INSTALL_DIR, "config.json")))
318-
assert.are_equal("file", mode(path(LUA_DIR, "types.lua")))
334+
assert.are_equal("file", mode(path(INSTALL_DIR, "plugin.lua")))
319335
local luarc = json.read(".luarc.json")
320336
assert.are_same({
321337
workspace = { library = { path(INSTALL_DIR, "library") } },
322338
example = true,
323339
runtime = {
324340
plugin = {
325341
FAKE_LOADER_SOURCE,
326-
path(LUA_DIR, "types.lua"),
342+
path(INSTALL_DIR, "plugin.lua"),
327343
},
328344
},
329345
}, luarc)
@@ -394,15 +410,15 @@ describe("luarocks-build-lls-addon", function()
394410
local cd = lfs.currentdir()
395411
assert.are_equal("directory", mode(path(INSTALL_DIR, "library")))
396412
assert.is_nil(mode(path(INSTALL_DIR, "config.json")))
397-
assert.are_equal("file", mode(path(LUA_DIR, "types.lua")))
413+
assert.are_equal("file", mode(path(INSTALL_DIR, "plugin.lua")))
398414
local luarc = json.read(".luarc.json")
399415
assert.are_same({
400416
hover = { enable = true },
401417
workspace = { library = { path(cd, INSTALL_DIR, "library") } },
402418
runtime = {
403419
plugin = {
404420
FAKE_LOADER_SOURCE,
405-
path(cd, LUA_DIR, "types.lua"),
421+
path(cd, INSTALL_DIR, "plugin.lua"),
406422
},
407423
},
408424
}, luarc)

spec/bundle_spec.lua

Lines changed: 0 additions & 75 deletions
This file was deleted.

spec/lls-addon_spec.lua

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ describe("lls-addon", function()
7979
local CURRENT_DIR = path("fake", "path", "to", "types") --[[@as "fake/path/to/types"]]
8080
local ROCKS_DIR = path("fake", "path", "to", "rocks") --[[@as "fake/path/to/rocks"]]
8181

82-
local INSTALL_DIR = path("lua_modules", "lib", "luarocks", "rocks-5.4", PACKAGE, VERSION) --[[@as "lua_modules/lib/luarocks/rocks-5.4/test/0.1-1"]]
83-
local LUA_DIR = path("lua_modules", "share", "lua", "5.4") --[[@as "lua_modules/share/lua/5.5"]]
82+
---@param package string
83+
---@param version string
84+
---@return string
85+
local function installDir(package, version)
86+
return path("lua_modules", "lib", "luarocks", "rocks-5.4", package, version)
87+
end
88+
local INSTALL_DIR = installDir(PACKAGE, VERSION) --[[@as "lua_modules/lib/luarocks/rocks-5.4/test/0.1-1"]]
89+
local LUA_DIR = path("lua_modules", "share", "lua", "5.4") --[[@as "lua_modules/share/lua/5.4"]]
8490

8591
local LOADER_SOURCE = path("fake", "path", "to", "lls-addon-loader.lua")
8692
stub(llsAddon, "getLoaderSource", LOADER_SOURCE)
@@ -162,24 +168,52 @@ describe("lls-addon", function()
162168
action = "append",
163169
dedup = true,
164170
key = "runtime.plugin",
165-
value = path(ROCKS_DIR, LUA_DIR, "lls-addon-types.lua"),
171+
value = path(ROCKS_DIR, installDir("lls-addon-types", VERSION), "plugin.lua"),
166172
} --[[@as lls-addon.config-entry.append]],
167173
}, configEntries)
168174
assert.are_same({
169175
{
170-
type = "bundle",
171-
source = "plugin",
172-
destination = path(
173-
ROCKS_DIR,
174-
"lua_modules",
175-
"lib",
176-
"luarocks",
177-
"rocks-5.4",
178-
"lls-addon-types",
179-
VERSION,
180-
"lua",
181-
"lls-addon-types.lua"
182-
),
176+
type = "file",
177+
source = path(CURRENT_DIR, "plugin.lua"),
178+
destination = path(ROCKS_DIR, installDir("lls-addon-types", VERSION), "plugin.lua"),
179+
} --[[@as lls-addon.install-entry]],
180+
}, installEntries)
181+
end)
182+
183+
it("works when given a multi-file plugin", function()
184+
stubFs({
185+
-- key = handler / return value
186+
current_dir = CURRENT_DIR,
187+
is_file = pathEquals(path(CURRENT_DIR, "plugin.lua")),
188+
is_dir = pathEquals(path(CURRENT_DIR, "plugin")),
189+
})
190+
191+
local rockspec = makeRockspec({ package = "lls-addon-types" })
192+
local configEntries, installEntries = compileLuarc(rockspec, {})
193+
assert.are_same({
194+
{
195+
action = "prepend",
196+
dedup = true,
197+
key = "runtime.plugin",
198+
value = LOADER_SOURCE,
199+
} --[[@as lls-addon.config-entry.prepend]],
200+
{
201+
action = "append",
202+
dedup = true,
203+
key = "runtime.plugin",
204+
value = path(ROCKS_DIR, installDir("lls-addon-types", VERSION), "plugin.lua"),
205+
} --[[@as lls-addon.config-entry.append]],
206+
}, configEntries)
207+
assert.are_same({
208+
{
209+
type = "file",
210+
source = path(CURRENT_DIR, "plugin.lua"),
211+
destination = path(ROCKS_DIR, installDir("lls-addon-types", VERSION), "plugin.lua"),
212+
} --[[@as lls-addon.install-entry]],
213+
{
214+
type = "directory",
215+
source = path(CURRENT_DIR, "plugin"),
216+
destination = path(ROCKS_DIR, installDir("lls-addon-types", VERSION), "plugin"),
183217
} --[[@as lls-addon.install-entry]],
184218
}, installEntries)
185219
end)
@@ -359,7 +393,7 @@ describe("lls-addon", function()
359393
action = "append",
360394
dedup = true,
361395
key = "runtime.plugin",
362-
value = path(ROCKS_DIR, LUA_DIR, PACKAGE .. ".lua"),
396+
value = path(ROCKS_DIR, INSTALL_DIR, "plugin.lua"),
363397
},
364398
{
365399
action = "merge",
@@ -376,9 +410,9 @@ describe("lls-addon", function()
376410
destination = path(ROCKS_DIR, INSTALL_DIR, "library"),
377411
}, installEntries)
378412
assert.contains({
379-
type = "bundle",
380-
source = "plugin",
381-
destination = path(ROCKS_DIR, INSTALL_DIR, "lua", PACKAGE .. ".lua"),
413+
type = "file",
414+
source = path(CURRENT_DIR, "plugin.lua"),
415+
destination = path(ROCKS_DIR, INSTALL_DIR, "plugin.lua"),
382416
}, installEntries)
383417
end)
384418
end)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- does nothing
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- also does nothing
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
rockspec_format = "3.0"
2+
package = "types"
3+
version = "0.1-1"
4+
5+
source = {
6+
url = "",
7+
}
8+
9+
build = {
10+
type = "lls-addon",
11+
}

src/luarocks/build/lls-addon.lua

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ local dir = require("luarocks.dir")
33
local fs = require("luarocks.fs") --[[@as luarocks.fs]]
44
local path = require("luarocks.path") --[[@as luarocks.path]]
55

6-
local bundle = require("luarocks.build.lls-addon.bundle")
76
local json = require("luarocks.build.lls-addon.json-util")
87
local log = require("luarocks.build.lls-addon.log")
98
local tableUtil = require("luarocks.build.lls-addon.table-util")
@@ -253,7 +252,7 @@ end
253252
---| lls-addon.config-entry.merge
254253

255254
---@class lls-addon.install-entry
256-
---@field type "file" | "directory" | "bundle"
255+
---@field type "file" | "directory"
257256
---@field source string
258257
---@field destination string
259258

@@ -268,9 +267,6 @@ local function installFiles(installEntries)
268267
copyFile(source, destination)
269268
elseif type == "directory" then
270269
copyDirectory(source, destination)
271-
elseif type == "bundle" then
272-
-- assuming 'source' is just a filename
273-
bundle(source, destination)
274270
else
275271
-- luacov: disable
276272
error("Unreachable: unknown install entry type: " .. type)
@@ -314,19 +310,14 @@ local function compileLuarc(rockspec, env)
314310

315311
local pluginSource = dir.path(fs.current_dir(), "plugin.lua")
316312
if fs.is_file(pluginSource) then
317-
local luaDir = path.lua_dir(rockspec.package, rockspec.version)
318-
local deployLuaDir = path.deploy_lua_dir(assert(cfg.root_dir, "tree not set"))
319-
320313
local formattedLoaderSource = M.getLoaderSource()
321314

322-
local pluginDestinationName = rockspec.package .. ".lua"
323-
local pluginDestination = dir.path(luaDir, pluginDestinationName)
324-
local formattedPluginDestination = dir.path(deployLuaDir, pluginDestinationName)
315+
local pluginDestination = dir.path(installDir, "plugin.lua")
316+
local formattedPluginDestination = dir.path(formattedInstallDir, "plugin.lua")
325317
if parseFlag(env["ABSPATH"]) then
326318
log.info("LLSADDON_ABSPATH is truthy, keeping plugin path absolute.")
327319
else
328320
log.info("Attempt to make plugin paths relative to " .. projectDir)
329-
formattedPluginDestination = makeDirRelativeTo(formattedPluginDestination, projectDir)
330321
formattedLoaderSource = makeDirRelativeTo(formattedLoaderSource, projectDir)
331322
end
332323

@@ -348,10 +339,20 @@ local function compileLuarc(rockspec, env)
348339
} --[[@as lls-addon.config-entry.append]])
349340

350341
table.insert(installEntries, {
351-
type = "bundle",
352-
source = "plugin",
342+
type = "file",
343+
source = pluginSource,
353344
destination = pluginDestination,
354345
} --[[@as lls-addon.install-entry]])
346+
347+
local pluginFolderSource = dir.path(fs.current_dir(), "plugin")
348+
if fs.is_dir(pluginFolderSource) then
349+
local pluginFolderDestination = dir.path(installDir, "plugin")
350+
table.insert(installEntries, {
351+
type = "directory",
352+
source = pluginFolderSource,
353+
destination = pluginFolderDestination,
354+
} --[[@as lls-addon.install-entry]])
355+
end
355356
end
356357

357358
local rockspecSettings = rockspec.build["settings"]

0 commit comments

Comments
 (0)