You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please provide an option for combining only declaration files #192
This would be better handled a post-build step, or as a feature in a larger build system. The set of compiler switches is intentionally small since we'd rather have specific build tools handle more complex scenarios (see https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).
This would be better handled [by] a post-build step, or as a feature in a larger build system.
When there are sub-folders in the Visual Studio project, setting "Redirect JavaScript output to directory" recreates the folder structure under the output directory. In this situation it's not trivial to combine the declarations (because copy *.d.ts myDeclartions.d.ts is not recursive), and it's necessary to resort to a powershell script or similar. Admittedly, this is not a big deal but when dealing with a large number of projects this is yet another maintenance issue.
Here is a suggestion that circumvents having to add another compiler flag, and is also largely backward compatible. The --out flag can be extended slightly as follows, in order to permit combining only JavaScript, or declarations or both:
--outfoo.js// Only combine JavaScript output into a single file--outfoo.d.ts// Only combine declarations into a single file--outfoo.js|bar.d.ts// Combine both JavaScript and declarations
It's not that we want a small number of compiler flags, it's that we want a low complexity of the commadline interface to tsc.
We can come back to this if a large proportion of people need this or there's no way to do it in another tool; I don't think either of those are the case right now.
In other words, what tool should I use in Visual Studio to make this work? As I mentioned above, it's necessary to write a PowerShell script, which requires granting execution rights to PS1 scripts on every single workstation on which the code is compiled.
You could write an MSBuild task, .targets file, use a more complex build system like grunt, or have a post-build script that used something other than Powershell.
So, for the lack of any sound alternatives (integrating grunt for just this requirement seemed like overkill) we went ahead with the MSBuild option. The implementation turned out to be non-trivial. It was necessary to deal with the following issues:
Local references (added to ensure script ordering) in _references.d.ts had to be removed.
The external references in _references.d.ts had to be inserted first.
When a project contains both internal and external modules then it was necessary to exclude the external modules.
Since the clean command in Visual Studio does not remove custom generated files. it was necessary to add another task to remove the generated declarations file.
After solving all these problems unfortunately we happened upon a problem that is insolvable by the MSBuidl task: When compile-on-save is enabled, changes to code files does not result in the regeneration of the combined declarations file.
So my point is: Considering that every user who has this requirement has to carry out this non-trivial task, and even then not achieve the required result 100%, it makes sense for TypeScript to enable this (potentially trivial) flag.
Noel Abrahams (@NoelAbrahams) what is the limitation on using --out for js output as well?
We have always thought of the .d.ts and .js as group that are consumed together.
Mohamed Hegazy (@mhegazy), the reason we want the .js files to be listed individually is to make debugging easier in the browser. Chrome, for example, lists them like this:
The reason we want the declarations combined into a single file is to be able to reference all the types with a single <reference> tag.
Dan Quirk (@danquirk), there are two reasons why we didn't want to maintain a master reference file:
All types in the master.d.ts shouldn't necessarily be visible to all projects. We would like to restrict certain subsets to specific projects.
We wanted a simple workflow for adding new types: adding and building a class file should result in the type becoming visible to the code-base; A master reference file creates an additional maintenance step, both when adding a new type and also when renaming or deleting an existing one.
However, your suggestion got me thinking and there is in fact a solution to the problem I outlined above, namely
When compile-on-save is enabled, changes to code files does not result in the regeneration of the combined declarations file
Basically, instead of creating the combined declarations file as consisting of the _content_ of all the declarations files in the output directory, we instead create it by inserting <reference> tags for each file. This way, compile-on-save updates the link target and the changes get picked up by the VS plugin.
Activity
RyanCavanaugh commentedon Jul 28, 2014
This would be better handled a post-build step, or as a feature in a larger build system. The set of compiler switches is intentionally small since we'd rather have specific build tools handle more complex scenarios (see https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).
NoelAbrahams commentedon Aug 11, 2014
Ryan Cavanaugh (@RyanCavanaugh),
When there are sub-folders in the Visual Studio project, setting "Redirect JavaScript output to directory" recreates the folder structure under the output directory. In this situation it's not trivial to combine the declarations (because copy *.d.ts myDeclartions.d.ts is not recursive), and it's necessary to resort to a powershell script or similar. Admittedly, this is not a big deal but when dealing with a large number of projects this is yet another maintenance issue.
Here is a suggestion that circumvents having to add another compiler flag, and is also largely backward compatible. The
--outflag can be extended slightly as follows, in order to permit combining only JavaScript, or declarations or both:Please consider reopening this issue.
RyanCavanaugh commentedon Aug 11, 2014
It's not that we want a small number of compiler flags, it's that we want a low complexity of the commadline interface to tsc.
We can come back to this if a large proportion of people need this or there's no way to do it in another tool; I don't think either of those are the case right now.
NoelAbrahams commentedon Aug 12, 2014
Ryan Cavanaugh (@RyanCavanaugh), can you please elaborate why the following is not true:
In other words, what tool should I use in Visual Studio to make this work? As I mentioned above, it's necessary to write a PowerShell script, which requires granting execution rights to PS1 scripts on every single workstation on which the code is compiled.
RyanCavanaugh commentedon Aug 12, 2014
You could write an MSBuild task, .targets file, use a more complex build system like grunt, or have a post-build script that used something other than Powershell.
NoelAbrahams commentedon Aug 22, 2014
So, for the lack of any sound alternatives (integrating grunt for just this requirement seemed like overkill) we went ahead with the MSBuild option. The implementation turned out to be non-trivial. It was necessary to deal with the following issues:
_references.d.tshad to be removed._references.d.tshad to be inserted first.cleancommand in Visual Studio does not remove custom generated files. it was necessary to add another task to remove the generated declarations file.After solving all these problems unfortunately we happened upon a problem that is insolvable by the MSBuidl task: When
compile-on-saveis enabled, changes to code files does not result in the regeneration of the combined declarations file.So my point is: Considering that every user who has this requirement has to carry out this non-trivial task, and even then not achieve the required result 100%, it makes sense for TypeScript to enable this (potentially trivial) flag.
mhegazy commentedon Aug 23, 2014
Noel Abrahams (@NoelAbrahams) what is the limitation on using --out for js output as well?
We have always thought of the .d.ts and .js as group that are consumed together.
NoelAbrahams commentedon Aug 24, 2014
Mohamed Hegazy (@mhegazy), the reason we want the
.jsfiles to be listed individually is to make debugging easier in the browser. Chrome, for example, lists them like this:The reason we want the declarations combined into a single file is to be able to reference all the types with a single
<reference>tag.danquirk commentedon Aug 25, 2014
Couldn't you create a single file that is your master set of type references (ie references.d.ts or myTypes.d.ts) and reference that?
NoelAbrahams commentedon Aug 28, 2014
Dan Quirk (@danquirk), there are two reasons why we didn't want to maintain a master reference file:
However, your suggestion got me thinking and there is in fact a solution to the problem I outlined above, namely
Basically, instead of creating the combined declarations file as consisting of the _content_ of all the declarations files in the output directory, we instead create it by inserting
<reference>tags for each file. This way, compile-on-save updates the link target and the changes get picked up by the VS plugin.