Skip to content

Conversation

@Perryvw
Copy link
Member

@Perryvw Perryvw commented Apr 17, 2021

Add extra resolve step when emitting to resolve Lua files that might be referenced but not part of the project output. This includes Lua files placed independently in the source directory, and also lua files in node_modules.

Upon resolution, any require() calls will be resolved to search for the lua file they are including. If this file is not yet part of the output it is added. Require paths are rewritten so the lua output and requires match.

Lua files from node_modules are placed into lua_modules to avoid overwriting them when rewriting require paths.

To create libraries, a buildMode config setting is added,. If this setting is set to "library", files from external packages in node_modules are not included, and their requires are not rewritten. This will be done once the package is included and used in a client project.

Closes #909, closes #1005, fixes #976, closes, fixes #823, fixes #751, closes #432

Documentation to go with this functionality:
TypeScriptToLua/TypeScriptToLua.github.io#44

@Perryvw Perryvw marked this pull request as ready for review June 5, 2021 18:37
@Perryvw Perryvw requested review from lolleko and tomblind June 5, 2021 18:38
@Perryvw Perryvw changed the title WIP: Module resolution from node_modules Module resolution from node_modules Jun 6, 2021
@Perryvw Perryvw merged commit 691c9cc into master Jun 14, 2021
@Perryvw Perryvw deleted the feature/module-resolution branch June 14, 2021 16:51
sanikoyes pushed a commit to sanikoyes/TypeScriptToLua that referenced this pull request Sep 24, 2021
* Create test project with  node_modules

* testProject test util

* Fix typos in module resolution test

* Base case module resolution

* Replace requires in source maps too

* Fixed incorrect path behavior

* More tests

* add module resolution with sourceDir node_modules

* Get all module-resolution testcases to work

* Restrict resolver to only lua files

* All tests working

* Added more in-project dependency checks to sourceDir test

* Fixed problem with lua sibling files

* Also resolve JSON modules

* Add debug to resolution test to try to figure out why CI is failing

* fix test runner path preloading

* Revert "Add debug to resolution test to try to figure out why CI is failing"

This reverts commit 7b8bd80.

* Changed resolution failure from error to warning

* move json.lua from dist to src in benchmark

* Use commit version instead of master to compile benchmark scripts

* Added module resolution test project with lua sources

* Add library compilation mode

* renamed compilemode to buildmode

* clean up resolve

* Fix tests

* Removed old project test runner

* PR comments

* Remove file casing test

* Resolution + library mode combined test

* remove out path logic from printer

* Fixed bundle entry point require not being resolved correctly

* Add header to bundle

* Made couldNotResolveRequire an error instead of warning

* updated couldnotResolveRequire snapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants