Socket
Socket
Sign inDemoInstall

typescript-transform-paths

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-transform-paths - npm Package Compare versions

Comparing version 3.2.1 to 3.3.0

dist/index.d.ts

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [3.3.0](https://github.com/LeDDGroup/typescript-transform-paths/compare/v3.2.1...v3.3.0) (2021-08-10)
### Features
* Added typescript-transform-paths/register script ([8c36b09](https://github.com/LeDDGroup/typescript-transform-paths/commit/8c36b098a837d1ed04c04a8fb8a39a03eb0bbadf))
### [3.2.1](https://github.com/LeDDGroup/typescript-transform-paths/compare/v3.2.0...v3.2.1) (2021-08-05)

@@ -7,0 +14,0 @@

3

dist/index.js

@@ -6,3 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.register = void 0;
const transformer_1 = __importDefault(require("./transformer"));
exports.default = transformer_1.default;
var register_1 = require("./register");
Object.defineProperty(exports, "register", { enumerable: true, get: function () { return register_1.register; } });

@@ -0,0 +0,0 @@ "use strict";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// endregion

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

47

package.json
{
"name": "typescript-transform-paths",
"version": "3.2.1",
"description": "Transforms module resolution paths using TypeScript path mapping",
"version": "3.3.0",
"description": "Transforms module resolution paths using TypeScript path mapping and/or custom paths",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"compile": "tsc",
"build": "yarn run clean && yarn run compile",
"test": "jest",
"release": "standard-version",
"--------------": "",
"format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"",
"clean": "rimraf dist **/*.tsbuildinfo",
"clean:all": "yarn run clean && rimraf node_modules test/node_modules test/.yarn-cache",
"reset": "yarn run clean:all && yarn install",
"-------------- ": "",
"prebuild": "rimraf dist",
"install:tests": "cd test && yarn install && cd projects/extras && yarn install",
"prepare": "yarn run install:tests"
},
"keywords": [

@@ -32,27 +49,5 @@ "typescript",

"README.md",
"CHANGELOG.md"
"CHANGELOG.md",
"register.js"
],
"main": "dist/index.js",
"scripts": {
"compile": "tsc",
"build": "yarn run clean && yarn run compile",
"test": "jest",
"release": "standard-version",
"--------------": "",
"format": "prettier --write \"{src,test}/**/{*.js,!(*.d).ts}\"",
"clean": "rimraf dist **/*.tsbuildinfo",
"clean:all": "yarn run clean && rimraf node_modules test/node_modules test/.yarn-cache",
"reset": "yarn run clean:all && yarn install",
"-------------- ": "",
"prebuild": "rimraf dist",
"install:tests": "cd test && yarn install",
"prepare": "yarn run install:tests"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testMatch": [
"**/tests/transformer.test.ts"
]
},
"devDependencies": {

@@ -59,0 +54,0 @@ "@types/jest": "^26.0.24",

@@ -9,6 +9,8 @@ # typescript-transform-paths

Transform module resolution paths in compiled output source to conform with `TypeScript` internal resolution via `tsconfig.json` settings (`paths`, `rootDirs`, `baseUrl`)
Transform compiled source module resolution paths using TypeScript's `paths` config, and/or custom resolution paths.
## Install
## Setup Steps
### 1. Install
```sh

@@ -18,7 +20,7 @@ <yarn|npm|pnpm> add -D typescript-transform-paths

## Usage with [ts-patch](https://github.com/nonara/ts-patch) or [ttypescript](https://github.com/cevek/ttypescript/)
### 2. Configure
Add it to _plugins_ in your _tsconfig.json_
### Example Config
#### Example Config

@@ -33,3 +35,3 @@ ```jsonc

},
// Note: To transform paths in both .js and .d.ts files, be sure to add both lines to plugins
// Note: To transform paths for both the output .js and .d.ts files, you need both of the below entries
"plugins": [

@@ -45,15 +47,30 @@ // Transform paths in output .js files

```
#### Example result
`core/index.ts`
```tsx
// The following transforms path to '../utils/sum'
import { sum } from "@utils/sum";
sum(2, 3);
```
`core/index.js` (compiled output)
```js
// core/index.js
var sum_1 = require("../utils/sum");
sum_1.sum(2, 3);
```
### 3. Usage
- **To compile with `tsc`** — Use [ts-patch](https://github.com/nonara/ts-patch)
- **To use with ts-node** — Add `typescript-trasnsform-paths/register` to `require` config.
`tsconfig.json`
```jsonc
{
"ts-node": {
"transpileOnly": true,
"require": [ "typescript-transform-paths/register" ],
},
"compilerOptions" { /* ... */ }
}
```
- **To use with node** — Use the register script: `node -r typescript-transform-paths/register src/index.ts`
## Virtual Directories

@@ -152,38 +169,2 @@ TS allows defining

## `ts-node` & TS Compiler API Usage
### Note
Most people using `ts-node` can achieve what they want without the transformer, by using [tsconfig-paths](https://github.com/dividab/tsconfig-paths#readme]) (ie. `ts-node -r tsconfig-paths`)
### Others
If you'd still like to use the transformer, it is now possible to do so programmatically, with or without a `Program` instance. This can be done via `ts-node` or the compiler API using `ts.transform()`.
Here is an example of how to register `ts-node` with the transformer:
```ts
import transformer, { TsTransformPathsConfig } from 'typescript-transform-paths';
import { register } from 'ts-node';
import ts from 'typescript';
const pluginConfig: TsTransformPathsConfig = {
useRootDirs: false
};
// Use this code if using transpileOnly
register({
transpileOnly: true,
transformers: {
before: [ transformer(/* Program */ undefined, pluginConfig) ]
}
});
// Use this if not using transpileOnly
register({
transformers: (program: ts.Program) => { before: [ transformer(program, pluginConfig) ] }
});
```
For TS compiler API usage example, have a look at the logic in [specific.test.ts](https://github.com/LeDDGroup/typescript-transform-paths/blob/master/test/tests/transformer/specific.test.ts) for `manual` mode.
## Articles

@@ -190,0 +171,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc