This tool transforms module specifier of TypeScript source code when it contains.
Because ECMAScript Modules(ESM) system doesn't allow to abbreviate file extension, so this tool aim to follows the system.
- You want to migrate your development enviroment like below.
- From
Node.js&TypeScript 4.7 ~ 4.9toNode.js&TypeScript 5.0 ~ - From
Node.js&TypeScripttoDeno&TypeScriptin the near future
- From
root
├── foo.ts
├── bar.ts
└── cool
├── index.ts
└── cool.ts-
foo.ts// If your TypeScript "compilerOptions" has set "moduleResolution": "nodenext", it will be like below. // import { bar } from './bar.js' import { bar } from './bar' import { cool } from './cool' console.log(bar) console.log(cool)
-
bar.tsexport const bar = 42
-
cool/index.tsexport { cool } from './cool'
-
cool/cool.tsexport const cool = 'this is cool'
-
foo.tsimport { bar } from './bar.ts' import { cool } from './cool/index.ts' console.log(bar) console.log(cool)
-
cool/index.tsexport { cool } from './cool.ts'
- Can't resolve
pathsmapping of TypeScriptcompilerOptions. - Please be careful if your code have the text
//_PRESERVE_NEWLINE_//which will be replace newline, because of that keeps original newline before tsc compiler optimize it. - Can't keep
single quatation,duble quatation,semicolon,commaandindatationof original source code.
Please install Deno.
- dry run
deno run --allow-env --allow-read --allow-write https://deno.land/x/[email protected]/bin.ts -b=./src -c=./tsconfig.json -d
- transform
deno run --allow-env --allow-read --allow-write https://deno.land/x/[email protected]/bin.ts -b=./src -c=./tsconfig.json -r
deno task run-drydeno task run
| key | description | type | default |
|---|---|---|---|
| -b | locale of base directory | string |
. |
| -c | locale of base tsconfig.json |
string |
./tsconfig.json |
| -d | dry run | boolean |
false |
| -r | enable repl interface | boolean |
false |
After you ran bin.ts, you should run npx tsc --noEmit and your bundler's build command due to check correctness of transformation by this tool.
tsconfig.jsonexample{ "compilerOptions": { "moduleResolution": "bundler", "allowImportingTsExtensions": true } }
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)