Socket
Socket
Sign inDemoInstall

typescript-transform-paths

Package Overview
Dependencies
Maintainers
1
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 1.1.9 to 1.1.10

10

CHANGELOG.md

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

### [1.1.10](https://github.com/LeDDGroup/typescript-transform-paths/compare/v1.1.9...v1.1.10) (2019-08-20)
### Bug Fixes
* do not transform relative paths ([dd57089](https://github.com/LeDDGroup/typescript-transform-paths/commit/dd57089)), closes [#30](https://github.com/LeDDGroup/typescript-transform-paths/issues/30)
* resolve only if file exists ([e6c51e0](https://github.com/LeDDGroup/typescript-transform-paths/commit/e6c51e0))
### [1.1.9](https://github.com/LeDDGroup/typescript-transform-paths/compare/v1.1.8...v1.1.9) (2019-08-20)

@@ -7,0 +17,0 @@

37

lib/index.js

@@ -10,2 +10,3 @@ "use strict";

var url_1 = require("url");
var fs_1 = require("fs");
var transformer = function (_) { return function (context) { return function (sourceFile) {

@@ -17,2 +18,11 @@ var resolver = typeof context.getEmitResolver === "function"

var sourceDir = path_1.dirname(sourceFile.fileName);
var implicitExtensions = [".ts", ".d.ts"];
var allowJs = compilerOptions.allowJs === true;
var allowJsx = compilerOptions.jsx !== undefined &&
compilerOptions.jsx !== typescript_1.default.JsxEmit.None;
var allowJson = compilerOptions.resolveJsonModule === true;
allowJs && implicitExtensions.push(".js");
allowJsx && implicitExtensions.push(".tsx");
allowJs && allowJsx && implicitExtensions.push(".jsx");
allowJson && implicitExtensions.push(".json");
var isDeclarationFile = sourceFile.isDeclarationFile;

@@ -30,6 +40,25 @@ var _a = compilerOptions.baseUrl, baseUrl = _a === void 0 ? "" : _a, _b = compilerOptions.paths, paths = _b === void 0 ? {} : _b;

}
function isRelative(s) {
return s[0] === ".";
}
function isUrl(s) {
return url_1.parse(s).protocol !== null;
}
function fileExists(s) {
// if has extensions, file must exist
if (path_1.extname(s) !== "")
return fs_1.existsSync(s);
// else check for implicit extensions .ts, .dts, etc...
for (var _i = 0, implicitExtensions_1 = implicitExtensions; _i < implicitExtensions_1.length; _i++) {
var ext = implicitExtensions_1[_i];
if (fs_1.existsSync(s + ext))
return true;
}
return false;
}
function bindModuleToFile(moduleName) {
if (isRelative(moduleName)) {
// if it's relative path do not transform
return moduleName;
}
for (var _i = 0, binds_1 = binds; _i < binds_1.length; _i++) {

@@ -43,6 +72,10 @@ var _a = binds_1[_i], regexp = _a.regexp, path = _a.path;

}
var file = slash_1.default(path_1.relative(sourceDir, path_1.resolve(baseUrl, out)));
return file[0] === "." ? file : "./" + file;
var filepath = path_1.resolve(baseUrl, out);
if (!fileExists(filepath + "/index") && !fileExists(filepath))
continue;
var resolved = slash_1.default(path_1.relative(sourceDir, filepath));
return isRelative(resolved) ? resolved : "./" + resolved;
}
}
return undefined;
}

@@ -49,0 +82,0 @@ function visit(node) {

2

package.json
{
"name": "typescript-transform-paths",
"version": "1.1.9",
"version": "1.1.10",
"description": "Transforms absolute imports to relative",

@@ -5,0 +5,0 @@ "keywords": [

@@ -7,3 +7,3 @@ # typescript-transform-paths

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors)

@@ -85,2 +85,5 @@ Transforms absolute imports to relative from `paths` in your tsconfig.json

</tr>
<tr>
<td align="center"><a href="http://codepen.io/viT-1/"><img src="https://avatars1.githubusercontent.com/u/19496430?v=4" width="100px;" alt="Vitaly Pinchuk"/><br /><sub><b>Vitaly Pinchuk</b></sub></a><br /><a href="https://github.com/LeDDGroup/typescript-transform-paths/issues?q=author%3AviT-1" title="Bug reports">🐛</a></td>
</tr>
</table>

@@ -87,0 +90,0 @@

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