Skip to content

Implement '--watch' for tsc.exe #2375

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
urbanhop opened this issue Mar 16, 2015 · 24 comments
Closed

Implement '--watch' for tsc.exe #2375

urbanhop opened this issue Mar 16, 2015 · 24 comments
Labels
Unactionable There isn't something we can do with this issue Visual Studio Integration with Visual Studio

Comments

@urbanhop
Copy link

error TS5001: The current host does not support the '--watch' option.

I got the really cool watch option working using the typescript spirce cde. but wouldn it be cool to have it working with tsc?

@danquirk danquirk added the Suggestion An idea for TypeScript label Mar 16, 2015
@DanielRosenwasser DanielRosenwasser changed the title Implement the -w feature for tsc or describe how to use it Implement '--watch' for tsc.exe Apr 21, 2015
@gintsgints
Copy link

So watch does not work on windows?

  • for making it work on .win too.

@DanielRosenwasser
Copy link
Member

Just to be clear, --watch does work on Windows if you're using node.js/io.js, but the tsc.exe program distributed with VS does not support it; you still have Compile on Save for similar functionality anyhow.

@urbanhop
Copy link
Author

As Daniel says, and as I wrote: "The current host" does not support the watch. I use node now as a host and come along well. So for me this is not an issue anymore and I think others will be fine as well with node as a host.

@gintsgints
Copy link

I realy do not get what means - "node as a host"

@urbanhop
Copy link
Author

javascript code needs some program that executes it. That is either a browser or node.js or something else, like tsc.exe.

The typescript compiler is tsc.js and you can use it for example by running

tsc.exe
node tsc.js

IN the first case, tsc.exe is a javascript runner, or in other words a "host" for tsc.js . In the second case, node.js is the runner, or "host". Besides executing the js code, the host provides some services like file-watching to the js code. And here is the missing piece: tsc.exe does not implement file watching, while node.js does. So using

node tsc.js -w  mycode.ts

you get file watching while

tsc.exe -w  mycode.ts

will throw

error TS5001: The current host does not support the '--watch' option.

@CyrusNajmabadi
Copy link
Contributor

I'm not sure why this was closed. Supporting --watch for our tsc.exe host would both be possible and desirable. Right now the limiting factor is that our tsc.exe host is a bit of ugly C++, that uses some ancient COM interfaces for Chakra that we haven't spent much effort on. Our options are:

  1. Implement --watch functionality in that C++ code. Given an appropriate C++ file watcher, this shouldn't be too difficult.
  2. Move to a managed code host and use the rich .Net functionality here. This would be a lot of work, but it would be nice to have a cleaner and more welcoming host for people to work in.
  3. Move to a more modern, native, Chakra host API (i.e. jsrt, and then expose file watching through that as well.

Ideally, we would open source these efforts as well.

@urbanhop
Copy link
Author

i closed it, because i opened it and found a workaround.
but appreciate your efforts for a watching tsc.exe.

@gintsgints
Copy link

So workaround for winodws is to search tsc.js and make cmd file to start it with node. :)

@DanielRosenwasser
Copy link
Member

So workaround for winodws is to search tsc.js and make cmd file to start it with node. :)

No, if you're going to use node, we'd recommend you install TypeScript via npm and make sure that node's tsc comes before Visual Studio's tsc in your PATH.

@urbanhop
Copy link
Author

@DanielRosenwasser : right, this is clean and portable
@gintsgints; yes, this is what I ended up with. since I have several tsc verisons, i brutally hard coded the path getting this ts.cmd:

rem usage: ts app
node X:\typescript\bin\tsc.js -w --sourcemap %1.ts --out js\%1.js

@DanielRosenwasser
Copy link
Member

@urbanhop hope you won't mind, I modified your script to be in a code block so it's a little more readable.

@urbanhop
Copy link
Author

thx!

@fjanon
Copy link

fjanon commented May 29, 2015

Please add to the "tsc --watch" doc that it is not supported on straight windows hosts but works on node on windows. That would save everyone's time.
Thanks

@fjanon
Copy link

fjanon commented May 29, 2015

Would it be possible to get a cmd file that watches the .ts files and recompiles them?
Thanks

@DanielRosenwasser
Copy link
Member

@fjanon not really, we'd be better off adapting the host to take on this functionality.

@mihailik
Copy link
Contributor

mihailik commented Jun 5, 2015

How about this approach around this line:
https://github.com/Microsoft/TypeScript/blob/master/src/compiler/sys.ts#L324

        declare hostSystemSupport: ts.System;

        if (typeof hostSystemSupport !== 'undefined') {
          return hostSystemSupport;
        }
        else if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
            return getWScriptSystem();
        }
        else if (typeof module !== "undefined" && module.exports) {
            return getNodeSystem();
        }
        else {
            return undefined; // Unsupported host
        }

So rather than faking WSH or node (both rich and complex apis), your Chakra host will implement exactly what tsc needs in the first place.

And as a side effect it will open the door for easy hosting of tsc in other weird and wonderful scenarios.

@jamesxv7
Copy link

jamesxv7 commented Aug 7, 2015

Correct me if I'm wrong but if I create a new .ts file into the folder been watched by the --watch option of the tsc compiler, I need to execute again the tsc --watch command in the bash or terminal? It is this behavior by design? This occurs on Mac and also on Windows.

Will be possible to add into the --watch options the functionality to not be necessary to re execute the command each time a new file is added to the project (or folder)?

@mhegazy
Copy link
Contributor

mhegazy commented Aug 7, 2015

currently the compiler only adds watches to files. the problem is node does not provide a native directory watcher capabilities. we would have to either do it based on file watchers, which would not scale, or include a timestamp based implementation. we are open to suggestions here if any one has better ideas on how to get this to work.

I do not think this is related to this issue. this issue is to enable --watch for tsc.exe. we should file a different issue for the directory watcher in --w.

@jamesxv7
Copy link

jamesxv7 commented Aug 7, 2015

I agree with you @mhegazy, that was my impression when I start writing the comment. I will continue the discussion in other issue. Thanks for the feedback and the information about Node.js.

@mindplay-dk
Copy link

This has been implemented, I think this issue can be closed?

@mhegazy
Copy link
Contributor

mhegazy commented Dec 6, 2016

This has been implemented, I think this issue can be closed?

no. this has not been implemented.

@saturn72
Copy link

This is the solution which works for me. see

@jsmunroe
Copy link

jsmunroe commented Dec 31, 2018

Can someone explain to me if tsc.exe does not support --watch, why does Visual Studio Code have a tsc --watch -p build task? Also, tsc doesn't run code. I have no idea what you guys are talking about there. It compiles typescript into javascript. Personally, I'm writing typescript to run in the browser. I don't need node. I just want VS Code to build javascript from my tsconfig.json when I save a typescript file. I'm new to VS Code, but this is a really simple thing for a program to solve. Building it manually works just fine.

Sorry, but I'm really frustrated and finding this command line stuff to be a bit unnecessary.

@DanielRosenwasser
Copy link
Member

Since tsc.exe is being discontinued (new versions of Visual Studio and NuGet will be shipping with tsc.js and expect Node to be installed), I think it's appropriate to close this issue. Users will now be able to install Node and get the expected --watch functionality.

@DanielRosenwasser DanielRosenwasser added Unactionable There isn't something we can do with this issue and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Dec 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unactionable There isn't something we can do with this issue Visual Studio Integration with Visual Studio
Projects
None yet
Development

No branches or pull requests