2.3.2 • Published 3 years ago
tsc-es2020-fix v2.3.2
tsc-es2020-fix
Make tsc-compiled es2020
bundles compatible with "type": "module"
requirements
⚠️ DEPRECATED The package was renamed
tsc-es2020-fix → tsc-esm-fix
The prev alias is no longer maintained
Motivation
This workaround is aimed to bypass a pair of tsc and ts-jest issues right here and right now.
- TS/issues/13422: tsc should add
.js
extensions for rel module paths. - ts-jest/issues/1174:
import.meta
is not allowed.
Hope one day this library will not be needed.
Features
- Finds and replaces
__dirname
and__filename
refs withimport.meta
. - Injects extentions to relative imports/re-exports statements.
import {foo} from './foo'
→import {foo} from './foo.js'
import {baz} from 'external/baz'
→import {baz} from 'external/baz.js'
- Pays attention to index files:
import {bar} from './bar'
→import {bar} from './bar/index.js'
- Follows
outDir
found in tsconfig.json. - Changes files extentions if specified by opts.
- Supports Windows-based runtimes.
Requirements
Node.js >= 14
Install
yarn add -D tsc-es2020-fix
Usage
tsc-es2020-fix [options]
import { fix } from 'tsc-es2020-fix'
await fix({
dirnameVar: true,
filenameVar: true,
ext: true
})
API
CLI
tsc-es2020-fix [opts]
Option | Description | Default |
---|---|---|
--tsconfig | Path to project's ts-config(s) | tsconfig.json |
--target | Entry points where compiled files are placed for modification | If not specified inherited from tsconfig.json compilerOptions.outDir |
--dirnameVar | Replace __dirname usages with import.meta | true |
--filenameVar | Replace __filename var references import.meta | true |
--ext | Append extension to relative imports/re-exports | .js |
--cwd | cwd | process.cwd() |
--out | Output dir. Defaults to cwd, so files will be overridden | |
--debug | Prints debug notes |
JS/TS
import { fix, IFixOptions } from 'tsc-es2020-fix'
const fixOptions: IFixOptions = {
tsconfig: 'tsconfig.build.json',
dirnameVar: true,
filenameVar: true,
ext: true
}
await fix(fixOptions)
export interface IFixOptions {
cwd: string
out?: string,
target?: string | string[]
tsconfig: string | string[]
dirnameVar: boolean
filenameVar: boolean
ext: boolean | string
}
License
2.3.2
3 years ago
2.3.1
3 years ago
2.3.0
3 years ago
1.1.2
3 years ago
2.2.1
3 years ago
2.2.0
3 years ago
2.2.2
3 years ago
2.2.1-beta.3
3 years ago
2.2.1-beta.2
3 years ago
2.2.1-beta.1
3 years ago
2.2.1-beta.0
3 years ago
2.1.0
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.0
3 years ago
1.0.0-beta.3
3 years ago
1.0.0-beta.2
3 years ago
1.0.0-beta.1
3 years ago
1.0.0-beta.0
3 years ago