-
Notifications
You must be signed in to change notification settings - Fork 122
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
Support tsconfig.json #202
Comments
+1, need this! |
+1 ! |
I've been thinking about this. There are a few different ideas I've had. They are not necessarily mutually exclusive. Idea 1: Provide Example for Idea 1: {
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true
}
}
// this would take the noImplicitAny setting from the tsconfig.json,
// but override the module setting.
ts: {
default : {
project: "./tsconfig.json",
options: {
module: "amd"
}
}
} Idea 2: Management of ts: {
default : {
project: "./tsconfig.json",
// What should happen here? Should we take the results of `src` expansion
// and update the `files` property in tsconfig.json?
src: ['./src/**/*.ts','./tests/**/*.ts']
}
} Should there perhaps be a new parameter in grunt-ts like I would hesitate to make this happen by default because Idea 3: Just call TSC and use the new Just some ideas. Would love feedback. |
I would lean towards your Idea 2 with updateTSConfig as I am using SublimeText TS which has quite limited |
👍 on idea 2. Recommend: ts: {
default : {
project: "./tsconfig.json",
// If specified overrides `files` setting in project. Otherwise just use `files` setting.
src: ['./src/**/*.ts','./tests/**/*.ts']
}
} People that are using |
Would really love to have this feature. |
+1 |
+1 |
1 similar comment
👍 |
OK folks - here's my design. I should have time to code this tomorrow and Friday, so please provide any comments soon. Thanks for your patience. Proposal for tsconfig.json SupportGrunt-ts supports using a tsconfig.json file. Here are some example Gruntfile initConfig sections: Use all settings from the specified grunt.initConfig({
ts: {
default: {
tsconfig: true // Value must be a string referencing a file path such as "./somefolder/tsconfig.json", OR a truthy value to use the 'tsconfig.json' in same folder as Gruntfile.js
}
}
}); If more control is desired, you may pass tsconfig as an object: grunt.initConfig({
ts: {
default: {
tsconfig: {
tsconfig: './SomeOtherFolder/tsconfig.json', // optional - if absent will default to 'tsconfig.json' in same folder as Gruntfile.js. If a folder is passed, will use tsconfig.json in that folder.
ignoreFiles: false, // optional - default is false. If true, will not inlcude files in `files` array from `tsconfig.json` in the compilation context.
ignoreSettings: false, // optional - default is false. If true, will ignore `compilerOptions` from `tsconfig.json` (instead using grunt-ts settings from Gruntfile.js)
overwriteFilesGlob: false, // optional - default is false. If true, will overwrite the contents of the `filesGlob` array with the contents of the `src` glob from grunt-ts.
updateFiles: true, // optional - default is true. Will maintain the `files` array based on the files found in `filesGlob`. (Note - If there is a `filesGlob` element, grunt-ts will only add/remove files that match it in the `files` array - not files found in any glob from `src`. This is relevant if `overwriteFilesGlob` is false (the default). )
passThrough: false // optional - default is false. If passThrough is set, grunt-ts will run TypeScript (tsc) with the specified tsconfig passing the `--project` option only (and anything in additionalFlags). This provides support for custom compilers with custom implementations of tsconfig.json.
}
}
}
}); Important notes:
General "Happy Path" processes providing support for using an editor like Notepad++ or Sublime that does NOT maintain the tsconfig.jsonBasic tsconfig: truegrunt.initConfig({
ts: {
default : {
tsconfig: true
}
}
);
Basic "passThrough"If passThrough is set, grunt-ts will run TypeScript (tsc) with the specified tsconfig passing the grunt.initConfig({
ts: {
default : {
tsconfig: {
passThrough: true
}
}
}
);
Scenario: tsconfig.json is set up for "dev", grunt-ts "release" task is set up for production. grunt.initConfig({
ts: {
options: {
tsconfig: true
}
release : {
options: {
removeComments: true
}
},
dev : {}
}
);
Scenario: tsconfig.json is set up for a common set of files, but we would like to selectively include different sets of files in the compilation context based on the build config. grunt.initConfig({
ts: {
options: {
tsconfig: true
}
bigBuild : {
src: './OtherStuffNotInThesmallBuild/**/*.ts'
},
smallBuild : {}
}
);
Support for
|
Looks good 👍 |
Hi just a thought. This may already be covered but I'm not sure after reading through the proposal. From what I've read you can have a tsconfig file and decide to use it or override settings when compiling using grunt-ts. I like the fact that in grunt you have the option of overriding settings based on a context (i.e. you could either have a dev or release config section in grunt-ts or you could have a property <%= my.property %> which can be overridden based on a flag passed to grunt for example. Since there can only be one primary tsconfig.json file could we have a flag that generates this file or updates it? i.e. grunt settings -> grunt-ts -> tsconfig.json That way my primary build config is in grunt and tsconfig is generated to work well with IDEs etc. People may have a watch that triggers grunt-ts on modification of ts files and this could refresh the tsconfig file so you're ide is in sync. Thoughts? |
It sounds like you're asking for an If so, I'll have to think about it. My thought about this feature is that the tsconfig.json should be set up to support your IDE/the TypeScript language service, and that grunt-ts should be for "full builds" or "special partial builds" only. If you're worried about having to repeat yourself, just put all of the appropriate config to make your IDE happy in the Please let me know if I'm missing the point. |
I think that the tsconfig.json should always override grunt-ts compiler setting. |
@nycdotnet Hi yeah I was thinking something along those lines. I was also thinking of the src files. E.g. Grunt-ts has a pattern of files to compile and one of those is similar to a vendor.d.ts file to take into account thirdparty modules I am importing. There should be no need for me to add /// now that tsconfig exists. This setting exists in my settings of my gruntfile which I can override by pointing to different settings files etc. I was hoping for a flag that would generate a tsconfig and keep it in sync with my grunt build (with this file in mind). e.g. from your description above: Grunt-ts will open and parse the ./tsconfig.json. If the tsconfig.json file does not exist it will be created with the defaults and a filesGlob that finds all .ts files excluding node_modules. If there is a parse error, compilation will be aborted with an error. What if you grunt-ts had a filesGlob pattern specified...could it use that instead of a default that finds all .ts files? This way they can specify a pattern in one place and it would apply to both (I know this happens if you have the settings in your tsconfig and have grunt-ts use that...is just that other grunt tasks also use this setting e.g. grunt-contrib-watch and that would get out of sync if you are changing the file pattern in tsconfig). |
I like that you can override with another |
@johnman This would be supported with the design above. I will add an explicit scenario to explain. |
OK added another scenario at the end. Sorry this has taken so long. There's a lot going on in my personal life at the moment - I hope this will be available in two or three weeks. |
I have created PR #275 for this which is still very much a work-in-progress. It's a significant refactoring that will fix several longstanding issues with grunt-ts options resolution, add many fast unit tests, and consolidate the Thanks for your patience, all. I will really appreciate your assistance with testing once the 5.0.0 beta is available. :-) |
Hi All, Well, the initial refactoring work took much longer than expected, but #275 now has all unit tests passing. It's up to 33 changed files with 3,333 additions and 1,710 deletions; granted a lot of these are refreshing definition files, but this is still a lot of new code. The good news is that grunt-ts should be a lot cleaner to work on now going forward and has way more tests and a good way to hook in fast unit tests that don't require actually running Grunt and TypeScript like before. I'm ready to get started on the tsconfig.json support and I'm assuming it should actually be the easy part as I got the old "vs" functionality working in just a few hours with the new optionsResolver system. Again thanks for your patience. I'm fairly confident that the beta should be out by the end of the week, but I will need your help to test everything. Thanks! |
@nycdotnet Thanks a lot!!! |
@nycdotnet, what's planned for the configuration overrides? will the tsconfig.json override the grunt-ts task configuration of the other way around? As mentioned before I think that the grunt-ts configuration should override the tsconfig configuration. this is really important because the tsconfig.json is very useful for the IDE and the grunt-ts for the build time. |
Yes the gruntfile will override the tsconfig so build time can be different than dev time. Full spec several posts back in this thread. See "Proposal for tsconfig.json Support". |
Quick update: I have the basic scenario essentially working and expect to release a beta later today. |
Hooray! grunt-ts 5.0.0-beta.1 now available on npm. PLEASE HELP BY TESTING Version 5 is a major refactoring in addition to the tsconfig.json support, so I will appreciate your assistance. Features not yet implemented: Please note that I don't think templates are going to fully work yet, though they should probably not be worse than at current. Thanks very much! |
I've published
Would you please test again? Thank you!! |
FYI: Any testing or feedback is appreciated. Thank you. |
Let's say my
and my
Am I doing something wrong if all the resulting |
I think you've specified it correctly. Are you using |
Nevermind - there is indeed an issue with pulling |
Yep I'm using the
It seems the Edit: Well... Thanks for caring about this! 😃 |
I believe |
Yep. It's fixed, @nycdotnet. 😃 |
Excellent! |
I tried
grunt-ts is not pass through configfile to tsc? |
Those options should all work except exclude. I'll look into it. Thank you. |
I seem to be having an issue getting this working on My gruntfile.js looks like this:
and my tsconfig is just empty JSON ( I get the following error when I try and compile:
Sorry if I'm making a simple mistake, I really would like to stop using reference files and move to the tsconfig structure. Thanks! |
Not a mistake - i just hadn't anticipated someone passing in an empty object in their tsconfig. Can you add a compiler options empty object and an empty files array (see above for samples - typing on my phone) and it should work with the grunt settings. Then you can start transitioning over. Note that the filesglob feature isn't implemented yet in this PR so you may have to manage files manually for now. |
@vvakame どうもありがとうございます。 I forgot that if files is missing that tsconfig.json compiles *.ts and *.tsx. I have added these rules to the specification:
I will implement them soon. Thank you again for the report. @AlexanderMattoni - your issue is resolved in my local code and will be fixed in the next beta. |
Hello again, All. I have resolved the issues reported by @vvakame and @AlexanderMattoni , and completed the implementation of the tsconfig support. I believe that it is now feature complete. There's a few little things I need to clean up and I still need to merge-in the docs, but I would greatly appreciate it if you would give I expect that this will be final next week barring any major issues. Thank you so much!! |
I'm having trouble with passthrough working:
tsconfig.json:
This works fine if I run tsc directly, and works okay if I remove passthrough and instead just pass true, but is extremely slow (tsc takes seconds, grunt ts:build takes a minute). I suspect it is not handling the exclude properly. Tested with tsc 1.6.2 and 5.0.0-beta.5" |
Thanks for the report. Can you run it grunt with the |
grunt ts:build --verbose (ts:{build:{tsconfig:true}})
When I tried the command line it output, it took ~2s. grunt ts:build --verbose (ts:{build:{tsconfig:{passThrough:true}}})
date;tsc;date
If I were to guess, it's not using the exclude section properly and it's going through all of my other files. |
Using grunt-ts 5.0.0-beta.5 with typescript version 1.6.2 I want grunt-ts to compile my typescript into 1 js file. I also want it to use the settings in my tsconfig.json file in which I set the location of my app and typings with filesGlob setting. I need the compliled js file to be put into a wwwroot publishing directory with sourcemaps back to my src directory. gruntfile.js
tsconfig.json
Couple of things is happening. One grunt-ts wants to modify my tsconfig.json with a files section. I don't really want this. Also I'm not getting the compiled-ts.js created . It is still generating multiple js files for each ts file. |
@eweiss1979 It appears that the TypeScript team implemented a breaking change in 1.6.2 for some reason and changed |
@escardin I've implemented an optimization that avoids adding directories to the glob that will be excluded as per the |
I've released I will work on closing out the remaining chores later today and hopefully will release 5.0.0 officially later today unless I hear of something bad. @eweiss1979 - FYI: The default behavior of grunt-ts is to maintain the |
@nycdotnet I asked the same question. I just chose to treat them the same way : microsoft/TypeScript#5107 (comment) the difference is I treat both relative to |
I saw that. Thanks Bas. Folks - I'm adding back in some warnings that were removed during the refactoring. I'll release as soon as that work is done barring any reports of problems. Thanks! |
@nycdotnet You did fix my issue, sorry for the delay. |
More about this coming change : microsoft/TypeScript#1667
Need ideas. Perhaps a
project
target option to point totsconfig.json
file will cause thesrc
/ other compiler options to be driven bytsconfig.json
?The text was updated successfully, but these errors were encountered: