v1.0.14
This tool transforms your local TypeScript code that gives you to rewrite file extension of module specifier automatically.
Attributes
Includes Deno configuration
Repository
Current version released
3 years ago
module-specifier-resolver
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.
use cases
- 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
transform example
a file tree as follows
root
├── foo.ts
├── bar.ts
└── cool
├── index.ts
└── cool.tsbefore
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'
after
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'
limitation
- Can’t resolve
pathsalias of TypeScript compiler options. - Can’t resolve
import()syntax, commonly calleddynamic import. - Plase 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 quatationorduble quatation,semicolonandindatationof original source code.
tools
Please install Deno.
command
remote
- dry run
deno run --unstable --allow-env --allow-read --allow-write https://deno.land/x/module_specifier_resolver@v1.0.14/bin.ts -b=./src -c=./tsconfig.json -d
- transform
deno run --unstable --allow-env --allow-read --allow-write https://deno.land/x/module_specifier_resolver@v1.0.14/bin.ts -b=./src -c=./tsconfig.json -r
local
deno task run-drydeno task run
arguments
| key | description | type | default |
|---|---|---|---|
| -b | local of base directory | string |
. |
| -c | local of base tsconfig.json |
string |
./tsconfig.json |
| -d | dry run | boolean |
false |
| -r | enable repl interface | boolean |
false |
tips
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, "noEmit": true } }
License
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)