{"id":16759139,"url":"https://github.com/alcalzone/virtual-tsc","last_synced_at":"2025-07-02T13:39:49.992Z","repository":{"id":25865906,"uuid":"106698094","full_name":"AlCalzone/virtual-tsc","owner":"AlCalzone","description":"Provides means to compile TypeScript in memory","archived":false,"fork":false,"pushed_at":"2023-04-19T07:12:38.000Z","size":513,"stargazers_count":20,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-14T04:07:21.394Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlCalzone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-12T13:42:22.000Z","updated_at":"2022-08-05T09:34:40.000Z","dependencies_parsed_at":"2024-06-19T01:43:03.239Z","dependency_job_id":"9d2d6274-22b3-4599-a977-54cb39f8eeb3","html_url":"https://github.com/AlCalzone/virtual-tsc","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fvirtual-tsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fvirtual-tsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fvirtual-tsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlCalzone%2Fvirtual-tsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlCalzone","download_url":"https://codeload.github.com/AlCalzone/virtual-tsc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221820549,"owners_count":16886201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T04:07:25.177Z","updated_at":"2024-10-28T11:12:04.737Z","avatar_url":"https://github.com/AlCalzone.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# virtual-tsc\n\nProvides means to compile TypeScript code to JavaScript in memory. \nRequires `typescript` \u003e= v2.0 and `@types/node` as peer dependencies, where `@types/node` should match your NodeJS runtime.\n\n## Usage\n\n```TS\nimport { compile } from \"virtual-tsc\";\nimport * as ts from \"typescript\";\nconst result: CompileResult = compile(sourceCode: string, compilerOptions?: ts.CompilerOptions, declarations?);\n```\nwhere `CompileResult` looks as follows:\n```TS\nexport interface CompileResult {\n    success: boolean;\n    diagnostics: Diagnostic[];\n    result?: string;\n    declarations?: string;\n}\n\nexport interface Diagnostic {\n    type: \"error\" | \"warning\" | \"message\";\n    lineNr: number;\n    charNr: number;\n    sourceLine: string;\n    description: string;\n    annotatedSource: string;\n}\n```\n\n## Ambient declarations\n`declarations` is an object of the type:\n```JS\n{\n    \"filename1.d.ts\": \"file contents 1\",\n    // ...\n}\n```\nand is used to specify ambient declarations. Filenames must end in `.d.ts`. For instance you can declare a function `log` that exists in the global scope by providing a file like the following:\n```TS\nimport * as fs from \"fs\"; // dummy import\ndeclare global {\n    function log(text: string);\n}\n```\nTo support augmentation of the global scope (like in the above file), you must force TypeScript to treat the file as a module. This can be done by a dummy import of a core NodeJS module.\n\n## Faster compilation with the Language Service API\nAs of version 0.3.0, this library supports incremental compilation with the TypeScript Language Service API. In simple tests, compile times for recurring compilations could be **reduced by at least 99%**. The usage changes slightly:\n```TS\nimport { Server as TSServer } from \"virtual-tsc\";\n\n// Create a new instance of the compiler with optional compiler options\nconst tsserver = new TSServer(options?: ts.CompilerOptions);\n\n// optionally provide ambient declarations\ntsserver.provideAmbientDeclarations(declarations);\n\n// compile whenever the source file changes:\nconst result = tsserver.compile(\n\tfilename /* string */,\n\tsource /* string */\n);\n```\nBy providing a filename for the source, it is possible to compile multiple scripts on one instance of the compiler.\n\n## Error-tolerant compilation\n\nBy specifying `noEmitOnError: false` on the `compilerOptions` object, you can get a compiled result even if there were build errors. For example, the code\n```TS\nconst test: string = 1\n```\nthen compiles to the valid JavaScript\n```JS\nvar test = 1\n```\nbut you get the additional error message\n```JS\nconst test: string = 1\n      ^\nERROR: Type '1' is not assignable to type 'string'.\n```\n\n## Changelog\n\u003c!--\n\tPlaceholder for the next version (at the beginning of the line):\n\t### __WORK IN PROGRESS__\n--\u003e\n### 0.6.2 (2022-01-10)\n* (AlCalzone) Replaced corrupted `colors` dependency with `picocolors`\n\n### 0.6.1 (2020-07-05)\n* (AlCalzone) Allow `package.json` as ambient declarations, use \"\" as the current directory\n\n### 0.6.0 (2020-06-09)\n* (AlCalzone) Expose `setTypeScriptResolveOptions` to set the options for resolving TypeScript and its lib files.\n\n### 0.5.0 (2020-01-28)\n* (AlCalzone) Passing `false` as the 2nd parameter to the Server constructor disables logging.\n\n### 0.4.6 (2018-08-03)\n* (AlCalzone) Allow TypeScript v3+ as a peer dependency\n\n### 0.4.5 (2018-05-30)\n* (AlCalzone) Fixed performance issues when `declaration` and `noEmitOnError` are both `true`\n\n### 0.4.1 (2018-05-23)\n* (AlCalzone) Allow emitting only declaration files\n\n### 0.4.0 (2018-05-23)\n* (AlCalzone) Emit declaration files (*.d.ts), enabled by default\n\n### 0.3.4 (2017-11-26)\n* (AlCalzone) Added a custom logger output\n\n### 0.3.3 (2017-11-14)\n* (AlCalzone) Fixed lib resolution for the LanguageServiceAPI\n\n### 0.3.2 (2017-11-09)\n* (AlCalzone) Use the LanguageServiceAPI to speed up multiple compilations\n\n### 0.2.3 (2017-10-13)\n* (AlCalzone) Fixed module resolution on Linux\n* (AlCalzone) Added async compile method\n\n### 0.2.2 (2017-10-13)\n* (AlCalzone) support NodeJS 4\n\n### 0.2.1 (2017-10-13)\n* (AlCalzone) support output of builds with errors\n\n### 0.2.0 (2017-10-13)\n* (AlCalzone) support ambient declarations\n\n### 0.1.0 (2017-10-13)\n* (AlCalzone) initial release. \n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2017 AlCalzone \u003cd.griesel@gmx.net\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falcalzone%2Fvirtual-tsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falcalzone%2Fvirtual-tsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falcalzone%2Fvirtual-tsc/lists"}