Socket
Socket
Sign inDemoInstall

tsconfig-paths

Package Overview
Dependencies
3
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.7.3 to 3.0.0

lib/filesystem.d.ts

6

.nycrc.json
{
"include": ["src/**/*.ts", "src/**/*.tsx"],
"include": ["src/**/*.{ts,tsx}"],
"exclude": ["src/register.ts"],
"extension": [".ts", ".tsx"],
"require": ["ts-node/register"],
"reporter": ["html", "lcov", "text"],
"sourceMap": true,
"instrument": true
"all": true
}

@@ -8,4 +8,13 @@ # Change Log

## [Unreleased]
- Nothing for now
## [3.0.0] - 2018-01-13
### Changed
- Remove parameter `absoluteSourceFileName: string` from `MatchPath` and `absolutePathMappings`. It was not used internally.
- `absolutePathMappings` now accepts a pre-sorted array of `MappingEntry`s instead of a dictionary.
### Added
- `createMatchPathAsync`, creates an async version of the `MatchPath` function. Can be used for example by webpack plugins.
- `matchFromAbsolutePathsAsync`, async version of `matchFromAbsolutePaths`.
## [2.7.3]

@@ -12,0 +21,0 @@ ### Fixed

@@ -1,3 +0,5 @@

export { createMatchPath, matchFromAbsolutePaths, MatchPath } from "./match-path";
export { createMatchPath, matchFromAbsolutePaths, MatchPath } from "./match-path-sync";
export { createMatchPathAsync, matchFromAbsolutePathsAsync, MatchPathAsync } from "./match-path-async";
export { register } from "./register";
export { loadConfig, ConfigLoaderResult, ConfigLoaderSuccessResult, ConfigLoaderFailResult } from "./config-loader";
export { ReadJsonSync, ReadJsonAsync, FileExistsSync, FileExistsAsync } from "./filesystem";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// register is used from register.js in root dir
var match_path_1 = require("./match-path");
exports.createMatchPath = match_path_1.createMatchPath;
exports.matchFromAbsolutePaths = match_path_1.matchFromAbsolutePaths;
var match_path_sync_1 = require("./match-path-sync");
exports.createMatchPath = match_path_sync_1.createMatchPath;
exports.matchFromAbsolutePaths = match_path_sync_1.matchFromAbsolutePaths;
var match_path_async_1 = require("./match-path-async");
exports.createMatchPathAsync = match_path_async_1.createMatchPathAsync;
exports.matchFromAbsolutePathsAsync = match_path_async_1.matchFromAbsolutePathsAsync;
var register_1 = require("./register");

@@ -8,0 +11,0 @@ exports.register = register_1.register;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var match_path_1 = require("./match-path");
var match_path_sync_1 = require("./match-path-sync");
var config_loader_1 = require("./config-loader");

@@ -17,3 +17,3 @@ /**

}
var matchPath = match_path_1.createMatchPath(configLoaderResult.absoluteBaseUrl, configLoaderResult.paths);
var matchPath = match_path_sync_1.createMatchPath(configLoaderResult.absoluteBaseUrl, configLoaderResult.paths);
// Patch node's module loading

@@ -24,4 +24,4 @@ // tslint:disable-next-line:no-require-imports variable-name

// tslint:disable-next-line:no-any
Module._resolveFilename = function (request, parent) {
var found = matchPath(parent, request);
Module._resolveFilename = function (request, _parent) {
var found = matchPath(request);
if (found) {

@@ -28,0 +28,0 @@ var modifiedArguments = [found].concat([].slice.call(arguments, 1)); // Passes all arguments. Even those that is not specified above.

{
"name": "tsconfig-paths",
"version": "2.7.3",
"version": "3.0.0",
"description": "Load node modules according to tsconfig paths, in run-time or via API.",

@@ -22,3 +22,3 @@ "main": "lib/index.js",

"mocha": "^4.1.0",
"nyc": "^10.1.2",
"nyc": "^11.4.1",
"prettier": "1.7.4",

@@ -59,2 +59,2 @@ "shelljs": "^0.7.5",

}
}
}

@@ -5,3 +5,3 @@ # tsconfig-paths

[![travis build][travis-image]][travis-url]
[![codecov coverage][codecov-image]][codecov-url]
[![coveralls coverage][coveralls-image]][coveralls-url]
[![MIT license][license-image]][license-url]

@@ -98,2 +98,20 @@ [![code style: prettier][prettier-image]][prettier-url]

```typescript
/**
* Function that can match a path
*/
export interface MatchPath {
(
requestedModule: string,
readJson?: Filesystem.ReadJsonSync,
fileExists?: (name: string) => boolean,
extensions?: ReadonlyArray<string>
): string | undefined;
}
/**
* Creates a function that can resolve paths according to tsconfig paths property.
* @param tsConfigPath The paths where tsconfig.json is located.
* @param baseUrl The baseUrl specified in tsconfig.
* @param paths The paths specified in tsconfig.
*/
export function createMatchPath(

@@ -103,10 +121,2 @@ absoluteBaseUrl: string,

): MatchPath
export type MatchPath = (
absoluteSourceFileName: string,
requestedModule: string,
readPackageJson?: (packageJsonPath: string) => any,
fileExists?: (name: string) => boolean,
extensions?: ReadonlyArray<string>
) => string | undefined;
```

@@ -119,16 +129,30 @@

```typescript
/**
* Finds a path from tsconfig that matches a module load request.
* @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.
* @param requestedModule The required module name.
* @param readJson Function that can read json from a path (useful for testing).
* @param fileExists Function that checks for existance of a file at a path (useful for testing).
* @param extensions File extensions to probe for (useful for testing).
* @returns the found path, or undefined if no path was found.
*/
export function matchFromAbsolutePaths(
absolutePathMappings: { [key: string]: Array<string> },
absoluteSourceFileName: string,
absolutePathMappings: ReadonlyArray<MappingEntry.MappingEntry>,
requestedModule: string,
readPackageJson: (packageJsonPath: string) => any = (
packageJsonPath: string
) => readPackage(packageJsonPath),
fileExists = fs.existsSync,
extensions = Object.keys(require.extensions)
): string | undefined {
readJson: Filesystem.ReadJsonSync = Filesystem.readJsonFromDiskSync,
fileExists: Filesystem.FileExistsSync = Filesystem.fileExistsSync,
extensions: Array<string> = Object.keys(require.extensions)
): string | undefined
```
The absolutePathMappings paramater has the same structure as paths in tsconfig but all paths needs to be resolved to absolute paths. This function is lower level and requries that the paths as already been resolved to absolute form.
This function is lower level and requries that the paths as already been resolved to absolute form and sorted in correct order into an array.
### createMatchPathAsync
This is the async version of `createMatchPath`. It has the same signature but with a callback parameter for the result.
### matchFromAbsolutePathsAsync
This is the async version of `matchFromAbsolutePaths`. It has the same signature but with a callback parameter for the result.
[version-image]: https://img.shields.io/npm/v/tsconfig-paths.svg?style=flat

@@ -138,4 +162,4 @@ [version-url]: https://www.npmjs.com/package/tsconfig-paths

[travis-url]: https://travis-ci.org/dividab/tsconfig-paths
[codecov-image]: https://img.shields.io/codecov/c/github/dividab/tsconfig-paths/master.svg?style=flat
[codecov-url]: https://codecov.io/gh/dividab/tsconfig-paths/branch/master
[coveralls-image]: https://coveralls.io/repos/github/dividab/tsconfig-paths/badge.svg?style=flat
[coveralls-url]: https://coveralls.io/github/dividab/tsconfig-paths
[license-image]: https://img.shields.io/github/license/dividab/tsconfig-paths.svg?style=flat

@@ -142,0 +166,0 @@ [license-url]: https://opensource.org/licenses/MIT

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc