Skip to content

Radical (and random) reorganization of output file #3786

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

Closed
michaelaird opened this issue Jul 8, 2015 · 13 comments
Closed

Radical (and random) reorganization of output file #3786

michaelaird opened this issue Jul 8, 2015 · 13 comments
Labels
Bug A bug in TypeScript External Relates to another program, environment, or user action which we cannot control.

Comments

@michaelaird
Copy link

We have typescript set to combine output into a single file. we've noticed that, seemingly at random, a very small change in a source file will result in huge changes in the output file resulting from the order of classes being totally reorganized.

i realize that the .ts file should be treated as "output" but these massive changes make it difficult to track edits in source control.

Ideally, a tree of dependent classes, ordered alphabetically, would be generated and traversed to combine the output.

@RyanCavanaugh
Copy link
Member

The compiler doesn't re-order code at all.

One possibility of what's going on is that you're using tsconfig.json and not specifying a file list or using /// <reference> directives. In that case, the order of the files would (I think?) be the order returned by the file system, which is not guaranteed to be any particular order. If the files do have some ordering preference, you should specify what that ordering is (by listing the files in tsconfig.json, or providing reference directives).

Can you post more details about your build setup?

@michaelaird
Copy link
Author

Interesting. Maybe this is specific to building in Visual Studio.

I'm using TypeScript 1.5beta and Visual Studio 2015 RC. there's no tsconfig.json.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 9, 2015

In a Visual Studio project, files will be passed to the compiler in the order they appear in the project file. since editing the project file is not that user-friendly, you can add a file _references.ts at the root of your project, and specify the order of files you care about in /// <references>

To see how VS and the compiler get the files look at the build log (tools\options\projects and solution\Build and Run, then select "MSBuild project build output verbosity" to be "Normal", build and in your output window search for "tsc.exe" )

for more information about ordering see #1066 (comment)

@michaelaird
Copy link
Author

Thanks! i'll try the _references.ts solution and see how that works.

@michaelaird
Copy link
Author

So. The _references.ts file works great for ordering but the /// <references> lines get included in the combined output.

i don't think this is correct since the code referenced is already included (and this causes havoc for bundling solutions like Cassette that try to resolve those references)

@danquirk
Copy link
Member

danquirk commented Jul 9, 2015

/// references being preserved or not has always been a back and forth issue as some people had tools that relied on them hanging around, others relied on them not being around (I believe Cassette has been referenced before for this latter case). On the plus side it's easy to remove them manually in a post build step with a regex.

@michaelaird
Copy link
Author

Interesting. I wonder what the scenario would be for keeping /// <references comments to code that had been in-lined by combining the output into a single file?

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Aug 10, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Aug 10, 2015

Looks like the original issue has been answered. please reactivate if you are running into other issues.

@mhegazy mhegazy closed this as completed Aug 10, 2015
@michaelaird
Copy link
Author

So, we've moved to using gulp tasks and tsconfig based projects but the order of the concatenated file is still totally random. After dependencies have been resolved, the classes with no dependencies will randomly move around the combined output.

We commit the compiled JS to source control and this results in a lot of unnecessary commits. Sometimes a developer will compile, commit a JS file with one ordering, re-compile and get a different ordering.

After dependencies have been resolved, could you order classes alphabetically or something to ensure they stay in the roughly the same place in the combined output file?

@mhegazy
Copy link
Contributor

mhegazy commented Mar 5, 2016

The compiler does not order files. If you have a repro project that building it multiple times result in different order we need to look at it.

@michaelaird
Copy link
Author

@mhegazy I have a project where i can repro this. i'd prefer not to post it here. how can i send you the details?

@mhegazy
Copy link
Contributor

mhegazy commented Mar 10, 2016

mhegazy at Microsoft dot com

@michaelaird
Copy link
Author

@mhegazy helped me track down my issue. It was actually caused by gulp streams being randomly ordered. I added the gulp-natural-sort plugin to give consistent ordering and that seems to have solved it.

@mhegazy mhegazy added Bug A bug in TypeScript External Relates to another program, environment, or user action which we cannot control. and removed Question An issue which isn't directly actionable in code labels Mar 18, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants