tsconfig-paths
Advanced tools
Comparing version 3.13.0 to 3.14.0
@@ -10,5 +10,11 @@ # Change Log | ||
## [3.14.0] - 2022-03-13 | ||
### Added | ||
- Support for path mapping starting with `/`. See PR [#180](https://github.com/dividab/tsconfig-paths/pull/180), issue [#113](https://github.com/dividab/tsconfig-paths/issues/113), and issue [#128](https://github.com/dividab/tsconfig-paths/issues/128). Thanks to [@benevbright](https://github.com/benevbright) for this fix! | ||
## [3.13.0] - 2022-03-03 | ||
### Fixed | ||
### Added | ||
@@ -15,0 +21,0 @@ - Include file extension in paths resolved from package.json "main" field. See PR [#135](https://github.com/dividab/tsconfig-paths/pull/135) and issue [#133](https://github.com/dividab/tsconfig-paths/issues/133). Thanks to [@katywings](https://github.com/katywings) for this fix! |
@@ -14,2 +14,12 @@ "use strict"; | ||
]; | ||
var abosolutePathMappingsStarstWithSlash = [ | ||
{ | ||
pattern: "/opt/*", | ||
paths: [(0, path_1.join)("/absolute", "src", "aws-layer")], | ||
}, | ||
{ | ||
pattern: "*", | ||
paths: [(0, path_1.join)("/absolute", "src")], | ||
}, | ||
]; | ||
it("should return no paths for relative requested module", function () { | ||
@@ -116,2 +126,41 @@ var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], abosolutePathMappings, "./requested-module"); | ||
}); | ||
it("should resolve paths starting with a slash", function () { | ||
var result = (0, try_path_1.getPathsToTry)([".ts"], abosolutePathMappingsStarstWithSlash, "/opt/utils"); | ||
expect(result).toEqual([ | ||
// "opt/*" | ||
{ | ||
path: (0, path_1.join)("/absolute", "src", "aws-layer"), | ||
type: "file", | ||
}, | ||
{ | ||
path: (0, path_1.join)("/absolute", "src", "aws-layer.ts"), | ||
type: "extension", | ||
}, | ||
{ | ||
path: (0, path_1.join)("/absolute", "src", "aws-layer", "package.json"), | ||
type: "package", | ||
}, | ||
{ | ||
path: (0, path_1.join)("/absolute", "src", "aws-layer", "index.ts"), | ||
type: "index", | ||
}, | ||
// "*" | ||
{ | ||
path: (0, path_1.join)("/absolute", "src"), | ||
type: "file", | ||
}, | ||
{ | ||
path: (0, path_1.join)("/absolute", "src.ts"), | ||
type: "extension", | ||
}, | ||
{ | ||
path: (0, path_1.join)("/absolute", "src", "package.json"), | ||
type: "package", | ||
}, | ||
{ | ||
path: (0, path_1.join)("/absolute", "src", "index.ts"), | ||
type: "index", | ||
}, | ||
]); | ||
}); | ||
}); | ||
@@ -118,0 +167,0 @@ // describe("match-star", () => { |
@@ -15,6 +15,3 @@ "use strict"; | ||
function getPathsToTry(extensions, absolutePathMappings, requestedModule) { | ||
if (!absolutePathMappings || | ||
!requestedModule || | ||
requestedModule[0] === "." || | ||
requestedModule[0] === path.sep) { | ||
if (!absolutePathMappings || !requestedModule || requestedModule[0] === ".") { | ||
return undefined; | ||
@@ -21,0 +18,0 @@ } |
{ | ||
"name": "tsconfig-paths", | ||
"version": "3.13.0", | ||
"version": "3.14.0", | ||
"description": "Load node modules according to tsconfig paths, in run-time or via API.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -13,2 +13,12 @@ import { getPathsToTry } from "../try-path"; | ||
]; | ||
const abosolutePathMappingsStarstWithSlash = [ | ||
{ | ||
pattern: "/opt/*", | ||
paths: [join("/absolute", "src", "aws-layer")], | ||
}, | ||
{ | ||
pattern: "*", | ||
paths: [join("/absolute", "src")], | ||
}, | ||
]; | ||
it("should return no paths for relative requested module", () => { | ||
@@ -129,2 +139,46 @@ const result = getPathsToTry( | ||
}); | ||
it("should resolve paths starting with a slash", () => { | ||
const result = getPathsToTry( | ||
[".ts"], | ||
abosolutePathMappingsStarstWithSlash, | ||
"/opt/utils" | ||
); | ||
expect(result).toEqual([ | ||
// "opt/*" | ||
{ | ||
path: join("/absolute", "src", "aws-layer"), | ||
type: "file", | ||
}, | ||
{ | ||
path: join("/absolute", "src", "aws-layer.ts"), | ||
type: "extension", | ||
}, | ||
{ | ||
path: join("/absolute", "src", "aws-layer", "package.json"), | ||
type: "package", | ||
}, | ||
{ | ||
path: join("/absolute", "src", "aws-layer", "index.ts"), | ||
type: "index", | ||
}, | ||
// "*" | ||
{ | ||
path: join("/absolute", "src"), | ||
type: "file", | ||
}, | ||
{ | ||
path: join("/absolute", "src.ts"), | ||
type: "extension", | ||
}, | ||
{ | ||
path: join("/absolute", "src", "package.json"), | ||
type: "package", | ||
}, | ||
{ | ||
path: join("/absolute", "src", "index.ts"), | ||
type: "index", | ||
}, | ||
]); | ||
}); | ||
}); | ||
@@ -131,0 +185,0 @@ |
@@ -23,8 +23,3 @@ import * as path from "path"; | ||
): ReadonlyArray<TryPath> | undefined { | ||
if ( | ||
!absolutePathMappings || | ||
!requestedModule || | ||
requestedModule[0] === "." || | ||
requestedModule[0] === path.sep | ||
) { | ||
if (!absolutePathMappings || !requestedModule || requestedModule[0] === ".") { | ||
return undefined; | ||
@@ -31,0 +26,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
202947
3657