I found that although the include property can specify glob style files, but the emitted file is in alphabetical order with reference directive considered, it is not consistent with the order provided in the include.
I see the result with listEmittedFiles option, and the include is something like this:
"include": [
"src/core/**/*.ts",
"src/utils/**/*.ts",
"src/**/*.ts"
]
Is this a bug?
TypeScript does not do output file ordering : https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html Its just a raw concat. Consider using modules please :rose:
@basarat As the document says:
"The order of concatenation is determined by the list of files passed to the compiler on the command line along with triple-slash references and imports"
I mean the config parser doesn't pass the files to compiler orderly as in include property.
And in the source code, I found in matchFileNames function an intentionally sort of input files by alphabet.
+1
outFile does support ordering via the files property in the tsconfig file.
I know outFile is not recommended practise but while its supported it would be useful to have include effect the ordering otherwise having to use the files to specify ordering on a per file basis can be painful!
You can try this project : https://github.com/domchen/typescript-plus .
I started using typescript in my project since version 0.9. It is really great except for the lack of some features, one of them that I need most is automatically reordering source files.
Normally when you pass the --outFile option, the compiler will concatenate and emit output to a single file. But the order of concatenation is determined by the list of files passed to the compiler on the command line (or in the tsconfig.json file) along with triple-slash references and imports. That forces you to sort the input files in the correct order manually. It is ok with only a few source files, but it becomes a disaster when you have countless source files.
Since the official team has not provided this feature yet, I decided to do it myself. I recently created this project: typescript-plus, which could automatically reordering the source files by analyzing their dependencies in source code. If typescript team is interested in this feature some day, I will be happy to help integrating it back to the original typescript project. For now, I will keep updating the typescript-plus project.
You can install it by:
npm install -g typescript-plus
It is basicly the same to the original compiler on usage:
tsc-plus [input files] [options]
To enable the source files reordering, please pass --reorderFiles to the command-line tool or add "reorderFiles": true to the compilerOptions in tsconfig.json file
With the reorderFiles swith on, the tsc-plus compiler will automatically reorder the source files by analyzing their dependencies in code. Then you can get the correct concatenation order in the generated file without doing any extra effort. I have tested this feature in many real-world projects, it works very well. If it does not work in you project, please feel free to open an issue and send me the test case.
For more information, please see the README.
@domchen sounds like a great addition — did you consider creating a PR to include it in TypeScript?
@nbransby why did you say outFile is not recommended practise ? Is it something official?
Yes I believe so, recommended practise is to output to separate files then use a minifier
Most helpful comment
You can try this project : https://github.com/domchen/typescript-plus .
I started using typescript in my project since version 0.9. It is really great except for the lack of some features, one of them that I need most is automatically reordering source files.
Normally when you pass the --outFile option, the compiler will concatenate and emit output to a single file. But the order of concatenation is determined by the list of files passed to the compiler on the command line (or in the tsconfig.json file) along with triple-slash references and imports. That forces you to sort the input files in the correct order manually. It is ok with only a few source files, but it becomes a disaster when you have countless source files.
Since the official team has not provided this feature yet, I decided to do it myself. I recently created this project: typescript-plus, which could automatically reordering the source files by analyzing their dependencies in source code. If typescript team is interested in this feature some day, I will be happy to help integrating it back to the original typescript project. For now, I will keep updating the typescript-plus project.
You can install it by:
npm install -g typescript-plusIt is basicly the same to the original compiler on usage:
tsc-plus [input files] [options]To enable the source files reordering, please pass --reorderFiles to the command-line tool or add "reorderFiles": true to the compilerOptions in tsconfig.json file
With the reorderFiles swith on, the tsc-plus compiler will automatically reorder the source files by analyzing their dependencies in code. Then you can get the correct concatenation order in the generated file without doing any extra effort. I have tested this feature in many real-world projects, it works very well. If it does not work in you project, please feel free to open an issue and send me the test case.
For more information, please see the README.