Title: Dots in module path breaks Lua import in a non-bundle compilation · Issue #1445 · TypeScriptToLua/TypeScriptToLua · GitHub
Open Graph Title: Dots in module path breaks Lua import in a non-bundle compilation · Issue #1445 · TypeScriptToLua/TypeScriptToLua
X Title: Dots in module path breaks Lua import in a non-bundle compilation · Issue #1445 · TypeScriptToLua/TypeScriptToLua
Description: Abstract tstl fails to produce valid lua code from a subset of valid (accordingly to tstl docs) code if ts file names contain dots in paths. This problem may naturally arise, for example, when compiling from Purescript to JS and then fro...
Open Graph Description: Abstract tstl fails to produce valid lua code from a subset of valid (accordingly to tstl docs) code if ts file names contain dots in paths. This problem may naturally arise, for example, when comp...
X Description: Abstract tstl fails to produce valid lua code from a subset of valid (accordingly to tstl docs) code if ts file names contain dots in paths. This problem may naturally arise, for example, when comp...
Opengraph URL: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1445
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dots in module path breaks Lua import in a non-bundle compilation","articleBody":"### Abstract\r\n`tstl` fails to produce valid `lua` code from a subset of valid (accordingly to `tstl` docs) code if `ts` file names contain dots in paths.\r\n\r\nThis problem may naturally arise, for example, when compiling from Purescript to JS and then from JS to Lua using tstl.\r\n\r\nThe example is not the natural use case for tstl, however, the bug is the bug.\r\n### Example\r\nLet's say we have two files:\r\n`./src/Foo.Bar/index.ts`\r\n```ts\r\nexport const answer: number = 42;\r\n```\r\n`./src/Qux/index.ts`\r\n```ts\r\nimport {answer} from \"./Foo.Bar\";\r\nexport const printAnswer = () => print(answer)\r\n```\r\nSo `import {answer} from \"./Foo.Bar\";` will be compiled (in a non-bundle mode) to\r\n```lua\r\nlocal ____Foo_2EBar = require(\"Foo.Bar.index\")\r\nlocal answer = ____Foo_2EBar.answer\r\n```\r\nand `lua` will be searching at `./Foo/Bar/index.lua\"` for that module.\r\n\r\nThat will result an error:\r\n```\r\nlua: ./Qux/index.lua:3: module 'Foo.Bar.index' not found:\r\n no field package.preload['Foo.Bar.index']\r\n no file './Foo/Bar/index.lua'\r\n no file '/usr/local/share/lua/5.1/Foo/Bar/index.lua'\r\n no file '/usr/local/share/lua/5.1/Foo/Bar/index/init.lua'\r\n no file '/usr/local/lib/lua/5.1/Foo/Bar/index.lua'\r\n no file '/usr/local/lib/lua/5.1/Foo/Bar/index/init.lua'\r\n no file '/usr/share/lua/5.1/Foo/Bar/index.lua'\r\n no file '/usr/share/lua/5.1/Foo/Bar/index/init.lua'\r\n no file './Foo/Bar/index.so'\r\n no file '/usr/local/lib/lua/5.1/Foo/Bar/index.so'\r\n no file '/usr/lib/x86_64-linux-gnu/lua/5.1/Foo/Bar/index.so'\r\n no file '/usr/lib/lua/5.1/Foo/Bar/index.so'\r\n no file '/usr/local/lib/lua/5.1/loadall.so'\r\n no file './Foo.so'\r\n no file '/usr/local/lib/lua/5.1/Foo.so'\r\n no file '/usr/lib/x86_64-linux-gnu/lua/5.1/Foo.so'\r\n no file '/usr/lib/lua/5.1/Foo.so'\r\n no file '/usr/local/lib/lua/5.1/loadall.so'\r\nstack traceback:\r\n [C]: in function 'require'\r\n ./Qux/index.lua:3: in main chunk\r\n [C]: in function 'require'\r\n ./main.lua:3: in main chunk\r\n [C]: ?\r\n```\r\n### Soulution\r\nWhen compiled to a file `./dist/Foo.Bar.Baz/index.lua`, split it's name by dots (excluding extension) and put the file into directory `./Foo/Bar/Baz`.\r\nThis will fix module resolution for `lua`.\r\nSo basically the ts directory\r\n```ls\r\n.\r\n├── Foo/\r\n│ └── index.ts\r\n├── Foo.Bar/\r\n│ └── index.ts\r\n├── Foo.Bar.Baz/\r\n│ └── index.ts\r\n├── Qux/\r\n│ └── index.ts\r\n└── index.ts\r\n```\r\nshould be compiled into\r\n```ls\r\n.\r\n├── Foo/\r\n│ ├── index.lua\r\n│ └── Bar/\r\n│ └── index.lua\r\n│ └── Baz/\r\n│ └── index.lua\r\n├── Qux/\r\n│ └── index.lua\r\n└── index.lua\r\n```\r\ninstead of\r\n```ls\r\n.\r\n├── Foo/\r\n│ └── index.lua\r\n├── Foo.Bar/\r\n│ └── index.lua\r\n├── Foo.Bar.Baz/\r\n│ └── index.lua\r\n├── Qux/\r\n│ └── index.lua\r\n└── index.lua\r\n```","author":{"url":"https://github.com/Renegatto","@type":"Person","name":"Renegatto"},"datePublished":"2023-05-20T11:38:12Z","url":"https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1445"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:021b1a18-82d5-3b85-8cf7-607610dd36ed |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8BFC:928E2:7C6E8F:A82C92:6B00DF35 |
| html-safe-nonce | a34cbd9d87e6d77cdb62a42043e49f51ab29e353534fac6c96c0e4dfbcb210ad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QkZDOjkyOEUyOjdDNkU4RjpBODJDOTI6NkIwMERGMzUiLCJ2aXNpdG9yX2lkIjoiMTkxODE5MDkyODAwMzEyOTE0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | db0c0f330890fbbad5844202c86ecc1549ae419bd2759d076bd67379955d0902 |
| hovercard-subject-tag | issue:1718145253 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TypeScriptToLua/TypeScriptToLua/1445/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5b0d67e16c392cf70a4ecefac6fa62908d9592451ded70081f32515e6556be6c/TypeScriptToLua/TypeScriptToLua/issues/1445 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5b0d67e16c392cf70a4ecefac6fa62908d9592451ded70081f32515e6556be6c/TypeScriptToLua/TypeScriptToLua/issues/1445 |
| og:image:alt | Abstract tstl fails to produce valid lua code from a subset of valid (accordingly to tstl docs) code if ts file names contain dots in paths. This problem may naturally arise, for example, when comp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Renegatto |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/TypeScriptToLua/TypeScriptToLua git https://github.com/TypeScriptToLua/TypeScriptToLua.git |
| octolytics-dimension-user_id | 44121206 |
| octolytics-dimension-user_login | TypeScriptToLua |
| octolytics-dimension-repository_id | 115876595 |
| octolytics-dimension-repository_nwo | TypeScriptToLua/TypeScriptToLua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 115876595 |
| octolytics-dimension-repository_network_root_nwo | TypeScriptToLua/TypeScriptToLua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width