-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
//# sourceTypingsURL=... #4846
Comments
@g162h3 can you elaborate on your scenario? by "project" your mean a VS project? and by "js" you mean the generated js files from the ts sources? |
I meant the project in the most general sense. Let's consider two projects: bluebird and angular. Let's also assume that they are written in ts and that angular wants to use bluebird as the Promise/A+ polyfill. How does angular include bluebird? As far as I know, there is currently one way to do this: bluebird gets compiled into a js file and a d.ts file, then angular adds a reference to I'm suggesting to simplify this by allowing to reference js files from ts files: /// <reference path="libs/bluebird.js" />
namespace angular {
// ...
} angular and bluebird are just examples - I'm a developer of neither of these. |
The js file is a runtime dependency; the /// reference and the // #sourcetypingsurl are design time dependencies; so having one does not remove the need for the other. Can you elaborate on how this would be used and how referencing the is file would simplify the workflow? |
It can be used just like I've described: a .ts files will reference to a .js file which will make tsc include the .js file into the output and take typings from the file referred to by sourceTypingsURL. |
I think I understand the scenario, but you could also just pass the typings through |
It's possible to concatenate .js files with an extra build step, just like it's possible to not use the tsc's Another reason to make this work is async/await you're working on. Since Promise isn't available everywhere yet, people will have to use some polyfill, like bluebird. That polyfill needs to be added to the top of the .js file, breaking the source map. But if tsc allowed to reference .js files, this wouldn't be a problem. |
Most tooling that bundles/concatenate files rewrite the source maps. It is expected in fact.
Realistically you wouldn't concatenate bluebird to every file. That is what modules are for. If you need polyfills, you tend to load those once, either through a script import in your application or through your module loader, or as a final bundle/layer that is then loaded by your module loader. Adding them to the top of every file that is dependent on them is not a good design pattern. Ultimately, my opinion is these workflows and options are too complex for TypeScript to do well. There is discussion though around module bundling and I am sure they will emit valid source maps for whatever path they choose to follow. I don't see how adding |
Another example of where this would be useful. Let's say there is a library and a couple satellite projects that were created to test the library: the unit tests and the testbench. The folder structure looks as following:
All this is written with To build all this, tsc needs to be invoked 3 times: to build the library itself, to build the unit tests and to build the testbench. Every time tsc will be recompiling With what I'm proposing this 3x recompilation could be avoided by first compiling /// <reference path = "lib.js" />
test("some test", () => {
const x = lib.add(2, 3);
expect(x).toEqual(5);
}); In the world of C this corresponds to how obj files work: a shared library consists of Still not convincing? |
you can do this today with no additional references. just call the compiler with |
I am still not sure i understand what is the workflow that this proposal is solving, and can not be done today.. |
This proposal is all about making tsc concatenate js files: you're saying that I can do this myself, while I'm saying that this is a responsibility of tsc. We can imagine the following discussion if tsc didn't have the A: When I add a This sounds not very different from what we are debating about now. |
B: Or in the opposite order: compile ts files separately and then merge all the produced js files. Possible? Definitely. But would be extremely inconvenient as I couldn't just type |
tsc can not just concat the files. it has to parse them, transpile them, and emit them again. it has to respect your --removeComments your --target and your --module, if we do that also, we need to support reading the original sourceMaps and concatenating them, something that is not supported today. so the perf win would not be that significant in the example listed above, given that we are still having to locate, parse and type check the additional .d.ts as well. if what you care about is perf, the separate concat tool would be the best along with passing the .d.ts from your intermediate build target. I think really what you need is a build system. tsc can not handle all build needs, nor was it designed to do that; once you have more than a 1 build target, a build system is a good thing to have. for our code base, we use Jake, all other popular build systems like grunt, gulp, broccoli, etc.. have a concat task that respects sourcemaps. |
I'm actually suggesting to include the js file blindly, without parsing it. The idea is to look at such js+d.ts pairs as opaque binary obj files: when obj files are linked together, the linker sees the overall structure of the module (function names, variables and so on), but doesn't attempt to parse the assembly code in those functions. Whether it needs to respect The argument about The Readinf the lib's source map is critically important, though. Without that debugging will be a pain. |
The problem is that there are people who have different expectations of that the compiler should do with a .js file (see #2302). I think easing into TypeScript by using it as a downlevel compiler is the scenario that other tools cannot perform as easily, whereas in this scenario, concatenating has many other existing solutions. |
JS files are now supported in compilation using --allowJS (#4792). please give that a try reopen if there are issues. |
Let's say you develop a library in ts. The library is then included into js and ts projects. Would it make sense for the latter to allow including just the compiled js file, but still have the typings?
lib.js:
foo.ts:
/// <reference path="lib.js" /> ...
This would also allow to embed other js files without invalidating the source map.
The text was updated successfully, but these errors were encountered: