typescript-transform-paths
Advanced tools
Comparing version 2.0.4 to 2.1.0-beta
@@ -7,7 +7,6 @@ # Changelog | ||
* Refactored from requiring _both_ to _at least one_ tsConfig option: baseUrl, paths ([34e4963](https://github.com/LeDDGroup/typescript-transform-paths/commit/34e49639f7248e38475efd854670c11ea65fc76e)) | ||
- Fixes issue #39 | ||
- Adds support for new [TS 4.1 - paths without baseUrl](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#paths-without-baseurl) | ||
### Bug Fixes | ||
* General improvements ([39c69ae](https://github.com/LeDDGroup/typescript-transform-paths/commit/39c69ae0c8a0875199f3777500c7a37e4191dc93)) | ||
### [2.0.3](https://github.com/LeDDGroup/typescript-transform-paths/compare/v2.0.2...v2.0.3) (2020-11-17) | ||
@@ -14,0 +13,0 @@ |
{ | ||
"name": "typescript-transform-paths", | ||
"version": "2.0.4", | ||
"description": "Transforms absolute imports to relative", | ||
"version": "2.1.0-beta", | ||
"description": "Transforms module resolution paths using TypeScript path mapping", | ||
"keywords": [ | ||
@@ -11,6 +11,6 @@ "typescript", | ||
"path", | ||
"paths", | ||
"virtual directory", | ||
"import", | ||
"require", | ||
"relative", | ||
"absolute" | ||
"require" | ||
], | ||
@@ -31,20 +31,21 @@ "homepage": "https://github.com/LeDDGroup/typescript-transform-paths#readme", | ||
"files": [ | ||
"lib", | ||
"README.md" | ||
"dist", | ||
"README.md", | ||
"CHANGELOG.md" | ||
], | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "tests" | ||
}, | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"format": "prettier --write \"{tests,src}/**/*.{js,ts}\"", | ||
"compile": "tsc", | ||
"build": "yarn run clean && yarn run compile", | ||
"test": "jest", | ||
"release": "standard-version", | ||
"--------------": "", | ||
"prebuild": "rimraf lib", | ||
"install:tests": "cd tests/__fixtures/specific && npm install", | ||
"prepare": "npm run build && npm run install:tests" | ||
"format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"", | ||
"clean": "rimraf dist", | ||
"clean:all": "yarn run clean && rimraf node_modules test/node_modules test/.yarn-cache **/*.tsbuildinfo", | ||
"reset": "yarn run clean:all && yarn install", | ||
"-------------- ": "", | ||
"prebuild": "rimraf dist", | ||
"install:tests": "cd test && yarn install", | ||
"prepare": "yarn run install:tests" | ||
}, | ||
@@ -62,14 +63,15 @@ "jest": { | ||
"jest": "^24.8.0", | ||
"prettier": "^2.1.2", | ||
"rimraf": "^3.0.2", | ||
"standard-version": "^8.0.1", | ||
"ts-expose-internals": "^4.0.5", | ||
"ts-expose-internals": "^4.1.2", | ||
"ts-jest": "^24.0.2", | ||
"ts-node": "^8.10.2", | ||
"ts-patch": "^1.3.1", | ||
"ttypescript": "^1.5.6", | ||
"typescript": "^4.0.5", | ||
"prettier": "^2.1.2" | ||
"typescript": "^4.1.2" | ||
}, | ||
"prettier": { | ||
"printWidth": 120 | ||
"peerDependencies": { | ||
"typescript": ">=3.6.5" | ||
} | ||
} |
107
README.md
@@ -10,15 +10,11 @@ # typescript-transform-paths | ||
Transforms absolute imports to relative from `paths` in your tsconfig.json | ||
Transform module resolution paths in compiled output source to conform with `TypeScript` internal resolution via `tsconfig.json` settings (`paths`, `rootDirs`, `baseUrl`) | ||
## Install | ||
npm: | ||
```sh | ||
# NPM | ||
npm i -D typescript-transform-paths | ||
``` | ||
yarn: | ||
```sh | ||
# Yarn | ||
yarn add -D typescript-transform-paths | ||
@@ -31,3 +27,5 @@ ``` | ||
```json | ||
### Example Config | ||
```jsonc | ||
{ | ||
@@ -39,32 +37,30 @@ "compilerOptions": { | ||
}, | ||
"plugins": [{ "transform": "typescript-transform-paths" }] | ||
} | ||
} | ||
``` | ||
### Transforming declaration paths | ||
If you want to generate declaration (_.d.ts_) files with transformed paths you have to | ||
modify your _tsconfig.json_ file: | ||
```json | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"paths": { | ||
"@utils/*": ["utils/*"] | ||
}, | ||
"declaration": true, | ||
"plugins": [ | ||
// Tranform paths in output .js files | ||
{ "transform": "typescript-transform-paths" }, | ||
// Tranform paths in output .d.ts files | ||
{ "transform": "typescript-transform-paths", "afterDeclarations": true } | ||
] | ||
} | ||
} | ||
``` | ||
`core/index.ts` | ||
```tsx | ||
import { sum } from "@utils/sum"; | ||
sum(2, 3); | ||
``` | ||
See [issue4](https://github.com/LeDDGroup/typescript-transform-paths/issues/4#issuecomment-486380340) for more information. | ||
`core/index.js` (compiled output) | ||
```js | ||
// core/index.js | ||
var sum_1 = require("../utils/sum"); | ||
sum_1.sum(2, 3); | ||
``` | ||
### Virtual Directory Support | ||
### Virtual Directories | ||
TS allows defining | ||
[virtual directories](https://www.typescriptlang.org/docs/handbook/module-resolution.html#virtual-directories-with-rootdirs) | ||
via the `rootDirs` compiler option. To enable virtual directory mapping, use the `useRootDirs` plugin option. | ||
via the `rootDirs` compiler option. | ||
To enable virtual directory mapping, use the `useRootDirs` plugin option. | ||
@@ -80,3 +76,4 @@ ```jsonc | ||
"plugins": [ | ||
{ "transform": "typescript-transform-paths", useRootDirs: true }, | ||
{ "transform": "typescript-transform-paths", "useRootDirs": true }, | ||
{ "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true } | ||
] | ||
@@ -87,3 +84,3 @@ } | ||
#### Example output | ||
#### Example | ||
@@ -109,31 +106,2 @@ ``` | ||
## Example Config | ||
```jsonc | ||
// tsconfig.json | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "./", | ||
"paths": { | ||
"@utils/*": ["utils/*"] | ||
} | ||
} | ||
} | ||
``` | ||
```tsx | ||
// core/index.ts | ||
import { sum } from "@utils/sum"; | ||
sum(2, 3); | ||
``` | ||
Gets compiled to: | ||
```js | ||
// core/index.js | ||
var sum_1 = require("../utils/sum"); | ||
sum_1.sum(2, 3); | ||
``` | ||
## Articles | ||
@@ -143,11 +111,20 @@ | ||
## Contributting | ||
## Project Guidelines for Contributors | ||
- make sure to format code with prettier: | ||
- Package Manager: `yarn` (`yarn install`) | ||
- Commit messages: [Conventional Commit Specs](https://www.conventionalcommits.org/en/v1.0.0/) | ||
- Format before commit: `prettier` (`yarn run format`) | ||
- Releases: `standard-version` (`yarn run release`) | ||
```sh | ||
npm install --global prettier | ||
prettier --write src/index.ts | ||
``` | ||
## Maintainers | ||
<!-- prettier-ignore-start --> | ||
<!-- markdownlint-disable --> | ||
<table> | ||
<tr> | ||
<td align="center"><a href="https://github.com/nonara"><img src="https://avatars0.githubusercontent.com/u/1427565?v=4" width="100px;" alt=""/><br /><sub><b>Ron S.</b></sub></a></td> | ||
<td align="center"><a href="https://github.com/danielpza"><img src="https://avatars2.githubusercontent.com/u/17787042?v=4" width="100px;" alt=""/><br /><sub><b>Daniel Perez Alvarez</b></sub></a></td> | ||
</tr> | ||
</table> | ||
## Contributors | ||
@@ -154,0 +131,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136336
14
477
1
12
1
161
1