Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarter contatenation based on import. #2032

Closed
mconner opened this issue Feb 13, 2015 · 3 comments
Closed

Smarter contatenation based on import. #2032

mconner opened this issue Feb 13, 2015 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@mconner
Copy link

mconner commented Feb 13, 2015

I'm compiling a number of .ts files and using the --out option to concatenate them into a single .js file. I've got some files in different folders, and using internal modules. Without <reference path=... to reference the .js, the compiler still finds the files just fine:

module dashboard {
   'use strict';
   import Widget = dashboard.widget.Widget;
   ... 
   var contentUrl = widget.getTemplateURL();

However, when it concatenates, It may place them in the wrong order (though it seems like files in the same folder are in the right order). Since it is basing that only on the reference path, which I did not include. As a result, I may get undefined when importing Widget. If the compiler is compiling a set of files, could it not use the import and module names to order the files appropriately? This would eliminate the need for the reference path, unless the thing being referenced is not part of the compile.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 26, 2015

We have followed an axiom not to reorder user code. So the compiler will honor input order. issue #21 is tracking issuing an error if the order is guaranteed to fail at run time, e.g. extends for an undefined class.

The order of files in output is defined by order of files passed to the compiler on the command line. then by following any /// tags that are included in these files and any import statements..

To manage order you have a few options:

  1. Passing dependencies first on the command line when calling the compiler
  2. Add /// references declaring dependency between your files -- some users create an index.ts/_references.ts file that is just a list of /// references declaring the project order, also note that _references.ts is honored by MSBuild and VS
  3. Add a tsconfig.json file in your project directory with a property "files" that specify your order -- see PR Support for tsconfig.json files #1692 for more details

You can find more information about ordering files in the output in this issue #1066

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Feb 26, 2015
@NoelAbrahams
Copy link

@mhegazy,

Add a tsconfig.json file in your project directory with a property "files" that specify your order -- see PR #1692 for more details

This is another reason for supporting globs or similar (as mentioned in the previous issue #1516 (comment)).

The minute we add one file to files in order to specify the ordering we are obliged to add _all_ the files in the project.

The solution of using a mix of ///<reference> and tsconfig is not very appealing. I mean we have a situation where A: "This is not compiling" B: "Did you check tsconfig?" A: "Yes" B: "Also check if /// exist".

That's just confusing.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 26, 2015

@NoelAbrahams i agree globs is a useful addition, i have filed #2154 for it.

@mhegazy mhegazy closed this as completed Apr 21, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants