Skip to content

Out file support#648

Closed
hazzard993 wants to merge 42 commits intoTypeScriptToLua:masterfrom
hazzard993:out-file
Closed

Out file support#648
hazzard993 wants to merge 42 commits intoTypeScriptToLua:masterfrom
hazzard993:out-file

Conversation

@hazzard993
Copy link
Copy Markdown
Contributor

@hazzard993 hazzard993 commented Jul 1, 2019

Closes #357

Tried out supporting the --outFile option and seemed to make some good progress.

  • Modules are placed in the output file in the correct order
  • Modules are registered in tstlpackage.preload
  • LuaLibs can be used
  • outFiles do not depend on require and package to exist in the target Lua environment
  • outFiles can deal with cyclic imports

The new option luaEntry can be used to specify what file will be executed when running the outFile. The exports of that TypeScript file are what the outFile as a whole will return.

Any other high or low level considerations regarding a single output file would be appreciated on this PR.

@ark120202
Copy link
Copy Markdown
Contributor

outFile in TS has 2 modes:

First one is a file concatenation. It is enabled when module is anything except system or amd. What it's doing is simply joining all files, without any wrappers or something like that. Because of that everything declared in files is available in all other files (what @tomblind said in a comment above). However, it doesn't allow imports and exports in all files in the project.

The second mode is bundling. It's enabled when module is system or amd. In this mode all files are wrapped in a function that registers modules, but not executes.This mode should be used with some runtime (for example https://requirejs.org/). Loading output compiled with this mode won't execute any module, so user has to call something like require(["entrypointModule"]) manually.

Currently this PR mixes both of these ways, which won't work in a lot of cases I can think of.

package.preload may be used there, but there could be environments without package.

Might have to think about giving the --module option a default value as a value has to be picked but whatever it is it currently has no effect on the output.

I don't think we should change any options implicitly, because if it's not specified in config it won't work with language service anyway.

@ark120202 ark120202 closed this Jul 2, 2019
@ark120202
Copy link
Copy Markdown
Contributor

Sorry, closed it accidentally

@ark120202 ark120202 reopened this Jul 2, 2019
@ledniy
Copy link
Copy Markdown

ledniy commented Oct 5, 2019

Any progress on that? I would like to use it for single output file

@hazzard993
Copy link
Copy Markdown
Contributor Author

I'll look into this some more today

@hazzard993
Copy link
Copy Markdown
Contributor Author

I'm leaving source map tracebacks for bundles out of scope for this PR as I'm not too sure how to proceed with it and this PR is pretty old but does allow --outFile support.

I've added --luaModuleSystem ("none" or "require") as a new option which allows users to generate code that can be used in environments without package or require if they want to output a single file.

@hazzard993 hazzard993 marked this pull request as ready for review October 7, 2019 03:41
Copy link
Copy Markdown
Contributor

@ark120202 ark120202 left a comment

Choose a reason for hiding this comment

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

I think we should have a diagnostic when luaEntry is specified without outFile, but I'm fine if we'll leave it to other PR, since we are missing a lot of other option checks anyway.

@Perryvw Perryvw mentioned this pull request Nov 17, 2019
@Perryvw
Copy link
Copy Markdown
Member

Perryvw commented Nov 30, 2019

Bundling implemented by #750 instead.

@Perryvw Perryvw closed this Nov 30, 2019
@hazzard993 hazzard993 deleted the out-file branch December 1, 2019 02:13
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.

Single file target

5 participants