diff --git a/packages/host/src/patch.ts b/packages/host/src/patch.ts index ecc22d83..7e16bf92 100644 --- a/packages/host/src/patch.ts +++ b/packages/host/src/patch.ts @@ -47,6 +47,12 @@ export class SaveModule { if (entry.isFile()) { let savePath = SaveModule.moduleFilePath(relativePath, this.info.name); this.files.set(savePath, await fs.readFile(fsPath)); + if (relativePath == "module_exports.lua") { + this.files.set( + `modules/${this.info.name}.lua`, + Buffer.from(`return require("modules/${this.info.name}/module_exports")`, "utf-8") + ); + } } else if (entry.isDirectory()) { dirs.push([fsPath, relativePath]); diff --git a/test/file/modules/test/module_exports.lua b/test/file/modules/test/module_exports.lua new file mode 100644 index 00000000..cc421c57 --- /dev/null +++ b/test/file/modules/test/module_exports.lua @@ -0,0 +1 @@ +-- module_exports diff --git a/test/host/patch.js b/test/host/patch.js index 0ed2219c..6cfbb40c 100644 --- a/test/host/patch.js +++ b/test/host/patch.js @@ -28,6 +28,30 @@ describe("host/patch", function() { } }); }); + + describe("loadFiles()", function() { + const testModule = new patch.SaveModule(new lib.ModuleInfo("test", "1.0.0")); + const referenceFiles = new Map([ + ["modules/test/test.lua", "-- test\n"], + ["modules/test/module_exports.lua", "-- module_exports\n"], + ["locale/en/test.cfg", "module-test=A Test\n"], + ["locale/en/test-locale.cfg", "module-test-locale=Test Locale\n"], + ["modules/test.lua", "return require(\"modules/test/module_exports\")"], + ]); + before(async function() { + await testModule.loadFiles("test/file/modules/test"); + }); + it("Should read the contents of all files in a module", function() { + assert.equal(testModule.files.size, referenceFiles.size); + for (let [relativePath, contents] of referenceFiles) { + if (!testModule.files.has(relativePath)) { + assert.fail(`Module is missing file: ${relativePath}`); + } else { + assert.equal(testModule.files.get(relativePath).toString("utf-8"), contents); + } + } + }); + }); }); describe("generateLoader()", function() {