grunt-ts icon indicating copy to clipboard operation
grunt-ts copied to clipboard

grunt-ts' watch doesn't perform like tsc's watch

Open fcamblor opened this issue 9 years ago • 3 comments
trafficstars

I have a tsconfig.json file with allowJs:true

In my grunt-ts configuration, I'm referencing it and using the passThrough:true option :

module.exports = {
    options: {
        verbose: true
    },
    dist: {
        tsconfig: {
            tsconfig: 'app/scripts/',
            passThrough: true
        }
    }
};

Anyway, when I run grunt ts:dist :

  • Compilation is triggered each time I change a .ts file
  • Compilation is not triggered when I change a .js file (despite the allowJs flag in tsconfig.json

However, when I run tsc --project app/scripts/ -w :

  • Compilation is triggered each time I change a .ts file
  • Compilation is triggered as well each time I change a .js file, denoting we have currently a different behaviour between grunt-ts and tsc

Does it sound normal to you ? I would have expected grunt-ts to rely on tsc rather than re-implement his own watching mechanism.

FYI, my whole tsconfig.json file :

{
    "compilerOptions": {
        "module": "amd",
        "target": "ES5",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "outFile": "../../.tmp/scripts/app.js",
        "sourceMap": true,
        "inlineSourceMap": false,
        "allowJs": true,
        "inlineSources": true
    }
}

fcamblor avatar Jun 22 '16 14:06 fcamblor

This is a good report. We implemented the grunt-ts watch feature well before tsc supported watch itself. How would you propose fixing it?

nycdotnet avatar Jun 22 '16 14:06 nycdotnet

Currently, I worked around it by removing my use of grunt-ts and using grunt-exec instead, and calling tsc --project app/scripts/ -w by hand

Afterall, since I exported my whole config into the tsconfig.json file, I don't need any grunt-ts addition to my build, tsc is enough for my case.

(not sure if it is what you expected to hear, but I need to keep it simple stupid here :-))

fcamblor avatar Jun 22 '16 15:06 fcamblor

It's certainly fine. Grunt is designed around "Do thing, stop, do next thing, stop" so watch has always been a bit awkward. At some point in the future I would like to consolidate watch and fast to work with the TypeScript language service, but this will take a lot of time. In the meantime, it may be sufficient to add tracking of .js files to the watch if allowJs is passed-in. I know our best use case is as part of a whole pipeline (build/minify/test/etc.) rather than watch.

ToDo: Add .js files (possibly .jsx/.tsx) to handleFileEvent in ts.ts.

nycdotnet avatar Jun 22 '16 16:06 nycdotnet