v1.0.23
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
7 months ago
Dependencies
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.9
toNode.js
&TypeScript 5.0 ~
- From
Node.js
&TypeScript
toDeno
&TypeScript
in the near future
- From
transform example
a file tree as follows
root
├── foo.ts
├── bar.ts
└── cool
├── index.ts
└── cool.ts
before
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.ts
export const bar = 42
cool/index.ts
export { cool } from './cool'
cool/cool.ts
export const cool = 'this is cool'
after
foo.ts
import { bar } from './bar.ts' import { cool } from './cool/index.ts' console.log(bar) console.log(cool)
cool/index.ts
export { cool } from './cool.ts'
limitation
- Can’t resolve
paths
mapping 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
,comma
andindatation
of original source code.
tools
Please install Deno.
command
remote
- dry run
deno run --allow-env --allow-read --allow-write https://deno.land/x/module_specifier_resolver@v1.0.23/bin.ts -b=./src -c=./tsconfig.json -d
- transform
deno run --allow-env --allow-read --allow-write https://deno.land/x/module_specifier_resolver@v1.0.23/bin.ts -b=./src -c=./tsconfig.json -r
local
deno task run-dry
deno task run
arguments
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 |
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.json
example{ "compilerOptions": { "moduleResolution": "bundler", "allowImportingTsExtensions": true } }
License
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)