-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Node JS API #372
Comments
Would love that, too! |
+1 |
The typescript compiler doesn't use external modules so no to "require"ed by default. But otherwise it's not hard. See : https://www.npmjs.org/package/typestring (which uses |
I know that but editing a module is not my option. There should be an export because this is a node module. |
I meant that you can I was additionally trying to explain explain how |
TypeScript is intentionally not an external module so that it can be used in places where there isn't a module loader (e.g. |
@RyanCavanaugh, Can i ask why is that ? You can just export module if the environment is node. |
Please clarify which part you'd like a "why" for. What are you proposing, specifically? |
@Subash This should help clarify : #309 (comment) |
Why not both? It' is pretty trivial to check the code is running as main file or is required as a module. Many modules on npm do it. |
👍 Probably the team wants the generated compiler to be "raw compiler output". So would need a similar feature in the emitter. |
It's just this little snippet: if (require.main === module) {
// handle process.argv
} else {
// be a module, export stuff
} Seems doable right? |
indeed. That wouldn't need any emitter change either. Here : if (require && module && (require.main === module)) {
// handle process.argv
ts.executeCommandLine(sys.args);
} else {
// be a module, export stuff
module.exports = ts;
} Also would need an update of @RyanCavanaugh would such a PR be welcome? |
Seems reasonable. |
if (require && module && (require.main === module)) {
// handle process.argv
ts.executeCommandLine(sys.args);
} else {
// be a module, export stuff
module.exports = ts;
} Will not work if its not started from nodejs (e.g. cscript). Will investigate a better option |
Wrap it in a node detection if/else? Check if require exists etc. IIRC there exists code for it in the IO part of the compiler. |
Wouldn't it be better to add this to if (typeof module !== "undefined") {
module.exports = ts;
} Then we have one file ( |
@ivogabe good point. I think that's the way to go. You get access to the service classes as well 👍 |
Services gonna be removed as far as I understand from #254. |
@RReverser No. Services were removed and are in the process of being rewritten |
@basarat Right now they don't seem to be removed - However, I don't really understand why do we need duplicated code in both services and compiler, that is synchronized only by using this |
@RReverser There is no duplicated code in the new workflow. From current var compilerSources = [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
"binder.ts",
"checker.ts",
"emitter.ts",
"commandLineParser.ts",
"tsc.ts",
"diagnosticInformationMap.generated.ts"
].map(function (f) {
return path.join(compilerDirectory, f);
});
var servicesSources = [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
"binder.ts",
"checker.ts",
"emitter.ts"
].map(function (f) {
return path.join(compilerDirectory, f);
}).concat([
"services.ts",
"shims.ts",
].map(function (f) {
return path.join(servicesDirectory, f);
})); The So the only code that matters for new languageService is in |
Agree with exposing the compiler, a simple approach could be to add: Which just appends: Patch here: Could be constrained to a more specific api, thoughts? |
@jbondc If I'm reading it right, your generated tsc_node.js will still try to parse the commandline and run the compiler when require'd, so it's not suitable for use in a script that does I think what you want to do is have tsc.js as-is, with Alternatively, do that replacement in tsc.js itself, don't create a new file tsc_node.js, and add |
@Arnavion Good catch, ya would need to remove ts.executeCommandLine(sys.args) from tsc.js and put it in bin/tsc @mhegazy My preference would be require("typescript") (compiler only) and require("typescriptServices") (more advanced, analyzing tokens,...) or it could be require("tsc") (compiler only) and require("typescript") (full bundle more advanced, analyzing tokens,...) |
Updated the patch, kept 'bin/tsc.js' intact not to break any existing behavior. Basically just removed that line in the build process and exporting this api: |
Any news, ETA? Will it be part of M1.3? |
Still working on the LS. we need to delete the old tree first then we can publish an API. |
Any news? Could you provide related issues? |
I noticed that v1.3 was released a month ago. Were compiler and language service APIs included in that release? |
@akfish According to https://github.com/Microsoft/TypeScript/wiki/Roadmap it is going to be in 1.4 |
@Arnavion Thanks for the information. |
Hi guys, @mhegazy and I have taken some initial steps on this in #1417. You'll find a new file produced by the build called You can sample it by checking out the branch of your choice and running
With that and our
While it's not yet set in stone, please give it a try and let us know what you think! We definitely want a good experience for anyone consuming this API. From here on, I think it might be appropriate to open a new issue for anything related to this API. Thanks! |
@DanielRosenwasser @mhegazy could you please provide the ability to get SyntaxTree from LanguageService? |
|
Just to verify, is there any LanguageServiceHost implementation other than LanguageServiceShimHostAdapter? |
@csnover You're meant to give your own implementation of LanguageServiceHost to ts.createLanguageService() , since its implementation (get filenames, get contents of files, etc.) will depend on the hosting application. If you want an example, see class TypeScriptLS in src/harness/harnessLanguageService.ts (that implements the shim interface) and how it's converted via the Adapter to the new interface. |
Is there an api that can be
require
ed from node to compile file. egThe text was updated successfully, but these errors were encountered: