{"id":17317135,"url":"https://github.com/1zumii/swc-plugin-transform-module-specifiers","last_synced_at":"2025-03-27T02:18:23.864Z","repository":{"id":230078183,"uuid":"730104764","full_name":"1zumii/swc-plugin-transform-module-specifiers","owner":"1zumii","description":"🛠️ A SWC plugin for transforming file extensions in import, export path.","archived":false,"fork":false,"pushed_at":"2024-04-11T12:55:07.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-25T10:06:19.192Z","etag":null,"topics":["swc","swc-plugin","tsconfig","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/swc-plugin-transform-module-specifiers","language":"Rust","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/1zumii.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":"2023-12-11T08:07:37.000Z","updated_at":"2024-04-10T09:16:39.000Z","dependencies_parsed_at":"2024-10-15T13:25:49.059Z","dependency_job_id":null,"html_url":"https://github.com/1zumii/swc-plugin-transform-module-specifiers","commit_stats":null,"previous_names":["1zumii/swc-plugin-transform-module-specifiers"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1zumii%2Fswc-plugin-transform-module-specifiers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1zumii%2Fswc-plugin-transform-module-specifiers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1zumii%2Fswc-plugin-transform-module-specifiers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1zumii%2Fswc-plugin-transform-module-specifiers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1zumii","download_url":"https://codeload.github.com/1zumii/swc-plugin-transform-module-specifiers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245767361,"owners_count":20668827,"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":["swc","swc-plugin","tsconfig","typescript"],"created_at":"2024-10-15T13:15:38.180Z","updated_at":"2025-03-27T02:18:23.846Z","avatar_url":"https://github.com/1zumii.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swc-plugin: transform-module-specifiers\n\ntransform module specifier in `import`, `export` statement, such as `ts` ➡️ `js`\n\n```ts\n// Before\nimport { v1, f2 } from \"./file3.ts\";\nexport { v4, f5 } from \"../file6.ts\";\n```\nwould be transformed to\n```js\n// after\nimport { v1, f2 } from \"./file3.js\";\nexport { v4, f5 } from \"../file6.js\";\n```\n\n## 🛠️ Config\n```shell\nnpm install -D swc-plugin-transform-module-specifiers\n```\n\n```json5\n// .swcrc\n{\n    \"plugins\": [\n        [\n            \"swc-plugin-transform-module-specifiers\",\n            {}\n        ]\n    ]\n}\n```\n\nby default, only transform `ts` to `js`. declare extension map in plugin's config to custom transform behavior\n```json\n{\n    \"mts\": \"mjs\",\n    \"tsx\": \"jsx\"\n}\n```\n\n## 🤔 Why this plugin? or what problem it solved\n\nif you are developing in a Node.js + TypeScript + ESM project, and transpile codes by tsc. you might come across: \n\n```ts\nimport { something } from \"./some-file.ts\";\n```\n\ntsc errors that:\n\n```\nAn import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.ts(5097)\n```\n\nbut it's wired to import `\"./some-file.js\"` in the source TS file, as the file doesn’t exist during dev time\n\nsolution for this is to change some options in `tsconfig.json`\n\n```json\n{\n    \"compilerOptions\": {\n        \"strict\": true,\n        \"module\": \"Node16\",\n        \"moduleResolution\": \"Node16\",\n        \"noEmit\": true,\n        \"allowImportingTsExtensions\": true,\n    }\n}\n```\n\nthe problem is, now you cannot produce any js code. Then turn to SWC to get these transpile work done, however SWC leaves import/export file extensions **untouched**.\n\nso here comes this plugin.\n\n### References\n- [TypeScript imitates the host’s module resolution, but with types](https://www.typescriptlang.org/docs/handbook/modules/theory.html#typescript-imitates-the-hosts-module-resolution-but-with-types)\n- [TypeScript 5.0: new mode bundler \u0026 ESM](https://dev.to/ayc0/typescript-50-new-mode-bundler-esm-1jic)\n- [The TSConfig Cheat Sheet](https://www.totaltypescript.com/tsconfig-cheat-sheet)\n\n\u003e [!NOTE]\n\u003e \n\u003e you might not need this plugin, if your project are using:\n\u003e - bundler\n\u003e   \n\u003e   set `tsconfig.json` (refer to above cheat sheet)\n\u003e   - `\"module\": \"Preserve\"`\n\u003e   - `\"moduleResolution\": \"Bundler\"`\n\u003e \n\u003e - runtime \n\u003e \n\u003e   that able to consume TS file directly","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1zumii%2Fswc-plugin-transform-module-specifiers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1zumii%2Fswc-plugin-transform-module-specifiers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1zumii%2Fswc-plugin-transform-module-specifiers/lists"}