diff --git a/src/transpilation/resolve.ts b/src/transpilation/resolve.ts index 558870f21..781da43c2 100644 --- a/src/transpilation/resolve.ts +++ b/src/transpilation/resolve.ts @@ -341,6 +341,9 @@ function replaceRequireInSourceMap( } function requirePathForFile(filePath: string, extension = ".lua"): string { + if (!extension.startsWith(".")) { + extension = `.${extension}`; + } if (filePath.endsWith(extension)) { return formatPathToLuaPath(filePath.substring(0, filePath.length - extension.length)); } else { diff --git a/test/transpile/module-resolution.spec.ts b/test/transpile/module-resolution.spec.ts index f95771687..7aa96001a 100644 --- a/test/transpile/module-resolution.spec.ts +++ b/test/transpile/module-resolution.spec.ts @@ -182,6 +182,14 @@ describe("module resolution with sourceDir", () => { .setOptions({ outDir: "tstl-out", extension: ".script" }) .expectToEqual(expectedResult); }); + + // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1394 + test("can resolve files with non-standard extension without separator (#1394)", () => { + util.testProject(path.join(projectPath, "tsconfig.json")) + .setMainFileName(path.join(projectPath, "src", "main.ts")) + .setOptions({ outDir: "tstl-out", extension: "script" }) + .expectToEqual(expectedResult); + }); }); describe("module resolution project with lua sources", () => { diff --git a/test/util.ts b/test/util.ts index c86d40453..1b41bb4a2 100644 --- a/test/util.ts +++ b/test/util.ts @@ -468,7 +468,10 @@ end)());`; } private injectLuaFile(state: LuaState, lua: Lua, lauxlib: LauxLib, fileName: string, fileContent: string) { - const extension = this.options.extension ?? ".lua"; + let extension = this.options.extension ?? ".lua"; + if (!extension.startsWith(".")) { + extension = `.${extension}`; + } const modName = fileName.endsWith(extension) ? formatPathToLuaPath(fileName.substring(0, fileName.length - extension.length)) : fileName;