Skip to content

Smarter contatenation based on import. #2032

Closed

Description

@mconner

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.

Activity

  1. mhegazy commented on Feb 26, 2015

    @mhegazy
    Contributor

    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

  2. NoelAbrahams commented on Feb 26, 2015

    @NoelAbrahams

    Mohamed Hegazy (@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.

  3. mhegazy commented on Feb 26, 2015

    @mhegazy
    Contributor

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

  4. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions