{"id":20068667,"url":"https://github.com/radarsu/ts-import","last_synced_at":"2025-04-04T20:14:37.550Z","repository":{"id":42681638,"uuid":"277555976","full_name":"radarsu/ts-import","owner":"radarsu","description":"Importing TypeScript files dynamically into JavaScript requires additional compilation step, which is troublesome to write for many. Popular typescript-require package seems to be obsolete and doesn't allow much customization.","archived":false,"fork":false,"pushed_at":"2025-02-19T11:44:28.000Z","size":29,"stargazers_count":53,"open_issues_count":6,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T19:11:18.581Z","etag":null,"topics":["compile","dynamic","import","require","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/radarsu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-07-06T13:55:14.000Z","updated_at":"2025-02-19T11:44:31.000Z","dependencies_parsed_at":"2024-06-18T15:15:07.712Z","dependency_job_id":"2abc83fa-79b2-4275-bdc9-49e20d4ac6b3","html_url":"https://github.com/radarsu/ts-import","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"42aaa97f7910d77ab9370d7b6da673300a8c9a6e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radarsu%2Fts-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radarsu%2Fts-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radarsu%2Fts-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radarsu%2Fts-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radarsu","download_url":"https://codeload.github.com/radarsu/ts-import/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242680,"owners_count":20907134,"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":["compile","dynamic","import","require","typescript"],"created_at":"2024-11-13T14:08:05.316Z","updated_at":"2025-04-04T20:14:37.526Z","avatar_url":"https://github.com/radarsu.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n    \u003ch1\u003ets-import\u003c/h1\u003e\n    \u003cdiv\u003eImporting TypeScript files dynamically into JavaScript requires additional compilation step, which is troublesome to write for many. Popular `typescript-require` package seems to be obsolete and doesn't allow much customization. Typed alternative to https://github.com/theblacksmith/typescript-require written in TypeScript.\u003c/div\u003e\n\u003c/p\u003e\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/radarsu)\n\n## Table of contents\n\n- [Table of contents](#table-of-contents)\n- [Features](#features)\n- [Install](#install)\n- [Usage](#usage)\n  - [allowConfigurationWithComments](#allowconfigurationwithcomments)\n\n## Features\n\n-   **Asynchronous and synchronous version** - uses **import** for async and **require** for sync.\n-   **Caches JavaScript** files into directory inside **.cache/ts-import**.\n-   **Fast** - I've benchmarked ways to compare detecting file changes with **fs** module and checking mtimeMs turned out to be fastest (https://jsperf.com/fs-stat-mtime-vs-mtimems). Also, compilation in versions 3+ is approximately 10x faster than in version 2.\n-   **Few dependencies** - uses only `comment-parser` and my tiny utility package `options-defaults`.\n-   **Highly flexible and configurable** - all compilerOptions are available under transpileOptions parameter.\n-   **No interference** - doesn't interfere with native import, require etc. changing their behavior or impacting their performance.\n\n## Install\n\n`npm i ts-import@4` - CJS\n`npm i ts-import@5` - ESM\n\n## Usage\n\n```ts\nimport * as tsImport from 'ts-import';\n\nconst main = async () =\u003e {\n    const filePath = `/home/user/file.ts`;\n    const asyncResult = await tsImport.load(filePath, {\n        // allowConfigurationWithComments: false,\n    });\n\n    // Only available in version 4.\n    const syncResult = tsImport.loadSync(filePath);\n};\n\nvoid main();\n```\n\n### allowConfigurationWithComments\n\nYou can define if file should be imported in the default `transpile` mode or `compile` mode by placing a comment on top of the specific file.\n\nCompile mode is slower, but allows the specified file to be part of a complex program - it can import other files etc.\n\n```ts\n/**\n * @tsImport\n * { \"mode\": \"compile\" }\n */\n\nimport { getOtherVariable } from './get-other-variable';\n\nconst result = getOtherVariable();\n\nexport { result };\n```","funding_links":["https://www.buymeacoffee.com/radarsu"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradarsu%2Fts-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradarsu%2Fts-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradarsu%2Fts-import/lists"}