Skip to content

fix dots in file/directory names breaking Lua require resolution (#1445)#1702

Merged
Perryvw merged 3 commits into
TypeScriptToLua:masterfrom
RealColdFry:fix/dots-in-module-paths
Apr 16, 2026
Merged

fix dots in file/directory names breaking Lua require resolution (#1445)#1702
Perryvw merged 3 commits into
TypeScriptToLua:masterfrom
RealColdFry:fix/dots-in-module-paths

Conversation

@RealColdFry
Copy link
Copy Markdown
Contributor

@RealColdFry RealColdFry commented Mar 30, 2026

Fixes #1445

Lua's require() uses dots as path separators, so a file at Foo.Bar/index.lua is unreachable via require("Foo.Bar.index") since Lua looks for Foo/Bar/index.lua. Expand dotted path segments into nested directories in the emit output, and emit a diagnostic when this expansion causes output path collisions.

…eScriptToLua#1445)

Lua's require() uses dots as path separators, so a file at Foo.Bar/index.lua
is unreachable via require("Foo.Bar.index") since Lua looks for Foo/Bar/index.lua.
Expand dotted path segments into nested directories in the emit output, and emit
a diagnostic when this expansion causes output path collisions.
@Perryvw
Copy link
Copy Markdown
Member

Perryvw commented Apr 1, 2026

While this is a possible solution, wouldn't it be simpler (and the output more reasonable) if we were to just find/replace periods with e.g. underscores in the output file names?

@RealColdFry
Copy link
Copy Markdown
Contributor Author

While this is a possible solution, wouldn't it be simpler (and the output more reasonable) if we were to just find/replace periods with e.g. underscores in the output file names?

Agreed, done

@RealColdFry RealColdFry marked this pull request as ready for review April 3, 2026 01:53
// regardless of output path. We check the output path directly instead.
test("dots in directory names are replaced with underscores in output", () => {
const { transpiledFiles } = util.testModule`
import { answer } from "./Foo.Bar";
Copy link
Copy Markdown
Member

@Perryvw Perryvw Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test where you're including a file like "Foo.Bar.ts", or maybe "foo.test.ts" since that was mentioned in the issue, rather than only directories with dots

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Perryvw Perryvw merged commit 2fc2e99 into TypeScriptToLua:master Apr 16, 2026
5 checks passed
@RealColdFry RealColdFry deleted the fix/dots-in-module-paths branch April 22, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dots in module path breaks Lua import in a non-bundle compilation

2 participants