{"id":23344239,"url":"https://github.com/jakobjingleheimer/correct-ts-specifiers","last_synced_at":"2025-04-10T02:22:28.144Z","repository":{"id":253327603,"uuid":"842660076","full_name":"JakobJingleheimer/correct-ts-specifiers","owner":"JakobJingleheimer","description":"correct erroneous file extensions in typescript import specifiers","archived":false,"fork":false,"pushed_at":"2024-11-21T20:16:26.000Z","size":111,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T03:53:10.723Z","etag":null,"topics":["ecma","importstatements","migration-tool","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/JakobJingleheimer.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":"2024-08-14T19:55:17.000Z","updated_at":"2024-12-06T18:31:46.000Z","dependencies_parsed_at":"2024-09-10T22:50:44.071Z","dependency_job_id":"77734b05-983b-4cd2-8f71-d70eec9ac4e6","html_url":"https://github.com/JakobJingleheimer/correct-ts-specifiers","commit_stats":null,"previous_names":["jakobjingleheimer/correct-ts-specifiers"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakobJingleheimer%2Fcorrect-ts-specifiers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakobJingleheimer%2Fcorrect-ts-specifiers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakobJingleheimer%2Fcorrect-ts-specifiers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakobJingleheimer%2Fcorrect-ts-specifiers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JakobJingleheimer","download_url":"https://codeload.github.com/JakobJingleheimer/correct-ts-specifiers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143216,"owners_count":21054733,"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":["ecma","importstatements","migration-tool","nodejs","typescript"],"created_at":"2024-12-21T06:20:11.174Z","updated_at":"2025-04-10T02:22:28.119Z","avatar_url":"https://github.com/JakobJingleheimer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Correct TypeScript Specifiers\n\n![tests](https://github.com/JakobJingleheimer/correct-ts-specifiers/actions/workflows/ci.yml/badge.svg)\n\nThis package transforms import specifiers in source-code from the broken state TypeScript's compiler (`tsc`) required (prior TypeScript v5.7 RC) into proper ones. This is useful when source-code is processed by standards-compliant software like Node.js. This is a one-and-done process, and the updated source-code should be committed to your version control (ex git); thereafter, source-code import statements should be authored compliant with the ECMAScript (JavaScript) standard.\n\n\u003e [!TIP]\n\u003e Those using `tsc` to compile will need to enable [`rewriteRelativeImportExtensions`](https://www.typescriptlang.org/tsconfig/#rewriteRelativeImportExtensions); using `tsc` for only type-checking (ex via a lint/test step like `npm run test:types`) needs [`allowImportingTsExtensions`](https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions) (and some additional compile options—see the cited documentation);\n\nThis package does not just blindly find \u0026 replace file extensions within specifiers: It confirms that the replacement specifier actually exists; in ambiguous cases (such as two files with the same basename in the same location but different relevant file extensions like `/tmp/foo.js` and `/tmp/foo.ts`), it logs an error, skips that specifier, and continues processing.\n\n\u003e [!CAUTION]\n\u003e This package does not confirm that imported modules contain the desired export(s). This _shouldn't_ actually ever result in a problem because ambiguous cases are skipped (so if there is a problem, it existed before the migration started). Merely running your source-code after the mirgration completes will confirm all is well (if there are problems, node will error, citing the problems).\n\n\u003e [!TIP]\n\u003e Node.js requires the `type` keyword be present on type imports. For own code, this package usually handles that. However, in some cases and for node modules, it does not. Robust tooling already exists that will automatically fix this, such as [`consistent-type-imports` via typescript-lint](https://typescript-eslint.io/rules/consistent-type-imports) and [`use-import-type` via biome](https://biomejs.dev/linter/rules/use-import-type/). If your source code needs that, first run this codemod and then one of those fixers.\n\n## Running\n\n\u003e [!CAUTION]\n\u003e This will change your source-code. Commit any unsaved changes before running this package.\n\n```sh\nnpx codemod@latest correct-ts-specifiers\n```\n\nIf you're using `tsconfig`'s `paths`, you will need a loader like [`@nodejs-loaders/alias`](https://github.com/JakobJingleheimer/nodejs-loaders/blob/main/packages/alias?tab=readme-ov-file)\n\n\n```sh\nnpm i @nodejs-loaders/alias\n\nNODE_OPTIONS=\"--loader=@nodejs-loaders/alias\" \\\nnpx codemod@latest correct-ts-specifiers\n```\n\n## Supported cases\n\n* no file extension → `.cts`, `.mts`, `.js`, `.ts`, `.d.cts`, `.d.mts`, or `.d.ts`\n* `.cjs` → `.cts`, `.mjs` → `.mts`, `.js` → `.ts`\n* `.js` → `.d.cts`, `.d.mts`, or `.d.ts`\n* [Package.json subimports](https://nodejs.org/api/packages.html#subpath-imports)\n* [tsconfig paths](https://www.typescriptlang.org/tsconfig/#paths) (requires a loader)\n* Commonjs-like directory specifiers\n\nBefore:\n\n```ts\nimport { URL } from 'node:url';\n\nimport { bar } from '@dep/bar';\nimport { foo } from 'foo';\n\nimport { Bird } from './Bird';          // a directory\nimport { Cat } from './Cat.ts';\nimport { Dog } from '…/Dog/index.mjs';  // tsconfig paths\nimport { baseUrl } from '#config.js';   // package.json imports\n\nexport { Zed } from './zed';\n\nexport const makeLink = (path: URL) =\u003e (new URL(path, baseUrl)).href;\n\nconst nil = await import('./nil.js');\n\nconst bird = new Bird('Tweety');\nconst cat = new Cat('Milo');\nconst dog = new Dog('Otis');\n```\n\nAfter:\n\n```ts\nimport { URL } from 'node:url';\n\nimport { bar } from '@dep/bar';\nimport { foo } from 'foo';\n\nimport { Bird } from './Bird/index.ts';\nimport { Cat } from './Cat.ts';\nimport { Dog } from '…/Dog/index.mts';  // tsconfig paths\nimport { baseUrl } from '#config.js';   // package.json imports\n\nexport type { Zed } from './zed.d.ts';\n\nexport const makeLink = (path: URL) =\u003e (new URL(path, baseUrl)).href;\n\nconst nil = await import('./nil.ts');\n\nconst bird = new Bird('Tweety');\nconst cat = new Cat('Milo');\nconst dog = new Dog('Otis');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakobjingleheimer%2Fcorrect-ts-specifiers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakobjingleheimer%2Fcorrect-ts-specifiers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakobjingleheimer%2Fcorrect-ts-specifiers/lists"}