Socket
Socket
Sign inDemoInstall

tsconfig-paths

Package Overview
Dependencies
3
Maintainers
13
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.14.1 to 4.0.0

14

CHANGELOG.md

@@ -10,2 +10,16 @@ # Change Log

## [4.0.0] - 2022-05-02
### Changed
- Ignore `--project`/`-P` CLI flag when explicit options are passed to `register`. See PR [#206](https://github.com/dividab/tsconfig-paths/pull/206).
- Tolerate an undefined `baseUrl` compiler option. See PR [#208](https://github.com/dividab/tsconfig-paths/pull/208).
### Added
- Add `cwd` option to `register` function that overrides where the `tsconfig.json` search begins. See PR [#205](https://github.com/dividab/tsconfig-paths/pull/205).
- Add support for `jsconfig.json`. See PR [#199](https://github.com/dividab/tsconfig-paths/pull/199). Thanks to [@F3n67u](https://github.com/F3n67u) for this PR!
- Let `paths` mappings be absolute paths. See PR [#184](https://github.com/dividab/tsconfig-paths/pull/184).
- Allow `baseUrl` in `tsconfig.json` to be an absolute path. See PR [#174](https://github.com/dividab/tsconfig-paths/pull/174). Thanks to [@nwalters512](https://github.com/nwalters512) for this PR!
## [3.14.1] - 2022-03-22

@@ -12,0 +26,0 @@

35

lib/__tests__/config-loader.test.js

@@ -17,5 +17,2 @@ "use strict";

var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, "/foo/bar");
// assert.equal(successResult.paths["asd"][0], "asd");
expect(successResult.resultType).toBe("success");

@@ -36,4 +33,2 @@ expect(successResult.absoluteBaseUrl).toBe("/foo/bar");

var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "bar/"));
expect(successResult.resultType).toBe("success");

@@ -46,4 +41,3 @@ expect(successResult.absoluteBaseUrl).toBe((0, path_1.join)("/baz", "bar/"));

cwd: "/baz",
// tslint:disable-next-line:no-any
tsConfigLoader: function (_) { return ({
tsConfigLoader: function () { return ({
tsConfigPath: "/baz/tsconfig.json",

@@ -55,13 +49,10 @@ baseUrl: "./src",

var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "src"));
expect(successResult.resultType).toBe("success");
expect(successResult.absoluteBaseUrl).toBe((0, path_1.join)("/baz", "src"));
});
it("should show an error message when baseUrl is missing", function () {
it("should tolerate a missing baseUrl", function () {
var result = (0, config_loader_1.configLoader)({
explicitParams: undefined,
cwd: "/baz",
// tslint:disable-next-line:no-any
tsConfigLoader: function (_) { return ({
tsConfigLoader: function () { return ({
tsConfigPath: "/baz/tsconfig.json",

@@ -73,6 +64,3 @@ baseUrl: undefined,

var failResult = result;
// assert.equal(failResult.resultType, "failed");
// assert.isTrue(failResult.message.indexOf("baseUrl") > -1);
expect(failResult.resultType).toBe("failed");
expect(failResult.message.indexOf("baseUrl") > -1).toBeTruthy();
expect(failResult.resultType).toBe("success");
});

@@ -87,8 +75,19 @@ it("should presume cwd to be a tsconfig file when loadConfig is called with absolute path to tsconfig.json", function () {

var successResult = result;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.configFileAbsolutePath, configFile);
expect(successResult.resultType).toBe("success");
expect(successResult.configFileAbsolutePath).toBe(configFile);
});
it("should allow an absolute baseUrl in tsconfig.json", function () {
var result = (0, config_loader_1.configLoader)({
explicitParams: undefined,
cwd: "/baz",
tsConfigLoader: function () { return ({
tsConfigPath: "/baz/tsconfig.json",
baseUrl: "/baz",
paths: {},
}); },
});
var successResult = result;
expect(successResult.absoluteBaseUrl).toEqual("/baz");
});
});
//# sourceMappingURL=config-loader.test.js.map

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

var result = Filesystem.fileExistsSync(fileThatExists);
// assert.equal(result, true);
expect(result).toBe(true);

@@ -16,3 +15,2 @@ });

var result = Filesystem.fileExistsSync(fileThatNotExists);
// assert.equal(result, false);
expect(result).toBe(false);

@@ -23,3 +21,2 @@ });

try {
// assert.equal(result, true);
expect(result).toBe(true);

@@ -36,3 +33,2 @@ done();

try {
// assert.equal(result, false);
expect(result).toBe(false);

@@ -48,5 +44,3 @@ done();

var result = Filesystem.readJsonFromDiskSync(fileThatExists);
// assert.isOk(result);
expect(result);
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");

@@ -57,5 +51,3 @@ });

try {
// assert.isOk(result); // Asserts that object is truthy.
expect(result).toBeTruthy();
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");

@@ -62,0 +54,0 @@ done();

@@ -8,23 +8,6 @@ "use strict";

var result = (0, mapping_entry_1.getAbsoluteMappingEntries)("/absolute/base/url", {
"*": ["/foo1", "/foo2"],
"longest/pre/fix/*": ["/foo2/bar"],
"*": ["/foo1", "./foo2"],
"longest/pre/fix/*": ["./foo2/bar"],
"pre/fix/*": ["/foo3"],
}, true);
// assert.deepEqual(result, [
// {
// pattern: "longest/pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo2", "bar")],
// },
// {
// pattern: "pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo3")],
// },
// {
// pattern: "*",
// paths: [
// join("/absolute", "base", "url", "foo1"),
// join("/absolute", "base", "url", "foo2"),
// ],
// },
// ]);
expect(result).toEqual([

@@ -37,10 +20,7 @@ {

pattern: "pre/fix/*",
paths: [(0, path_1.join)("/absolute", "base", "url", "foo3")],
paths: [(0, path_1.join)("/foo3")],
},
{
pattern: "*",
paths: [
(0, path_1.join)("/absolute", "base", "url", "foo1"),
(0, path_1.join)("/absolute", "base", "url", "foo2"),
],
paths: [(0, path_1.join)("/foo1"), (0, path_1.join)("/absolute", "base", "url", "foo2")],
},

@@ -51,8 +31,2 @@ ]);

var result = (0, mapping_entry_1.getAbsoluteMappingEntries)("/absolute/base/url", {}, true);
// assert.deepEqual(result, [
// {
// pattern: "*",
// paths: [join("/absolute", "base", "url", "*")],
// },
// ]);
expect(result).toEqual([

@@ -65,3 +39,2 @@ {

result = (0, mapping_entry_1.getAbsoluteMappingEntries)("/absolute/base/url", {}, false);
// assert.deepEqual(result, []);
expect(result).toEqual([]);

@@ -68,0 +41,0 @@ });

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

}, t.extensions, function (_err, result) {
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);

@@ -15,0 +14,0 @@ done();

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

var result = matchPath(t.requestedModule, function (_) { return t.packageJson; }, function (name) { return t.existingFiles.indexOf(name) !== -1; }, t.extensions);
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);

@@ -13,0 +12,0 @@ });

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

var result = (0, try_path_1.getPathsToTry)([".ts", "tsx"], abosolutePathMappings, "./requested-module");
// assert.deepEqual(result, undefined);
expect(result).toBeUndefined();

@@ -45,42 +44,2 @@ });

var result = (0, try_path_1.getPathsToTry)([".ts", ".tsx"], abosolutePathMappings, "longest/pre/fix/requested-module");
// assert.deepEqual(result, [
// // "longest/pre/fix/*"
// { type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.ts"),
// },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
// },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
// },
// // "*"
// { type: "file", path: join("/absolute", "base", "url", "foo1") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo1", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.tsx"),
// },
// ]);
expect(result).toEqual([

@@ -167,12 +126,2 @@ // "longest/pre/fix/*"

});
// describe("match-star", () => {
// it("should match star in last position", () => {
// const result = matchStar("lib/*", "lib/mylib");
// assert.equal(result, "mylib");
// });
// it("should match star in first position", () => {
// const result = matchStar("*/lib", "mylib/lib");
// assert.equal(result, "mylib");
// });
// });
//# sourceMappingURL=try-path.test.js.map

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

});
// assert.equal(result.tsConfigPath, "/foo/bar/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/bar/tsconfig.json");

@@ -34,3 +33,2 @@ });

});
// assert.isUndefined(result.tsConfigPath);
expect(result.tsConfigPath).toBeUndefined();

@@ -59,3 +57,2 @@ });

});
// assert.equal(result.tsConfigPath, "/foo/baz/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/baz/tsconfig.json");

@@ -77,3 +74,2 @@ });

});
// assert.equal(result.baseUrl, "SOME_BASEURL");
expect(result.baseUrl).toBe("SOME_BASEURL");

@@ -95,3 +91,2 @@ });

});
// assert.equal(result.baseUrl, undefined);
expect(result.baseUrl).toBeUndefined();

@@ -103,15 +98,43 @@ });

var pathToTsconfig = (0, path_1.join)("/root", "dir1", "tsconfig.json");
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return path === pathToTsconfig; });
// assert.equal(res, pathToTsconfig);
var mockFiles = {
"/root/dir1": ["tsconfig.json"],
};
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return mockFiles[path] || []; });
expect(res).toBe(pathToTsconfig);
});
it("should find jsconfig in starting directory", function () {
var pathToJsconfig = (0, path_1.join)("/root", "dir1", "jsconfig.json");
var mockFiles = {
"/root/dir1": ["jsconfig.json"],
};
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return mockFiles[path] || []; });
expect(res).toBe(pathToJsconfig);
});
// see https://github.com/Microsoft/TypeScript/issues/15869#issuecomment-301845650
it("tsconfig.json take precedence over jsconfig.json when both exist", function () {
var pathToTsconfig = (0, path_1.join)("/root/dir1", "tsconfig.json");
var mockFiles = {
"/root/dir1": ["jsconfig.json", "tsconfig.json"],
};
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return mockFiles[path] || []; });
expect(res).toBe(pathToTsconfig);
});
it("should find tsconfig in parent directory", function () {
var pathToTsconfig = (0, path_1.join)("/root", "tsconfig.json");
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return path === pathToTsconfig; });
// assert.equal(res, pathToTsconfig);
var mockFiles = {
"/root": ["tsconfig.json"],
};
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return mockFiles[path] || []; });
expect(res).toBe(pathToTsconfig);
});
it("should find jsconfig in parent directory", function () {
var pathToTsconfig = (0, path_1.join)("/root", "jsconfig.json");
var mockFiles = {
"/root": ["jsconfig.json"],
};
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1"), function (path) { return mockFiles[path] || []; });
expect(res).toBe(pathToTsconfig);
});
it("should return undefined when reaching the top", function () {
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1", "kalle"), function () { return false; });
// assert.equal(res, undefined);
var res = (0, tsconfig_loader_1.walkForTsConfig)((0, path_1.join)("/root", "dir1", "kalle"), function () { return []; });
expect(res).toBeUndefined();

@@ -124,3 +147,2 @@ });

var res = (0, tsconfig_loader_1.loadTsconfig)("/root/dir1/tsconfig.json", function (path) { return path === "/root/dir1/tsconfig.json"; }, function (_) { return JSON.stringify(config); });
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);

@@ -131,3 +153,2 @@ });

var res = (0, tsconfig_loader_1.loadTsconfig)("/root/dir1/tsconfig.json", function (path) { return path === "/root/dir1/tsconfig.json"; }, function (_) { return "{\n // my comment\n \"compilerOptions\": { \n \"baseUrl\": \"hej\"\n }\n }"; });
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);

@@ -138,3 +159,2 @@ });

var res = (0, tsconfig_loader_1.loadTsconfig)("/root/dir1/tsconfig.json", function (path) { return path === "/root/dir1/tsconfig.json"; }, function (_) { return "{\n \"compilerOptions\": { \n \"baseUrl\": \"hej\",\n },\n }"; });
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);

@@ -165,10 +185,2 @@ });

});
// assert.deepEqual(res, {
// extends: "../base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({

@@ -206,10 +218,2 @@ extends: "../base-config.json",

});
// assert.deepEqual(res, {
// extends: "my-package/base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({

@@ -247,6 +251,2 @@ extends: "my-package/base-config.json",

});
// assert.deepEqual(res, {
// extends: "../second-config.json",
// compilerOptions: { baseUrl: join("..", "..") },
// });
expect(res).toEqual({

@@ -253,0 +253,0 @@ extends: "../second-config.json",

@@ -19,3 +19,3 @@ import * as TsConfigLoader2 from "./tsconfig-loader";

configFileAbsolutePath: string;
baseUrl: string;
baseUrl?: string;
absoluteBaseUrl: string;

@@ -22,0 +22,0 @@ paths: {

@@ -6,5 +6,4 @@ "use strict";

var path = require("path");
var options_1 = require("./options");
function loadConfig(cwd) {
if (cwd === void 0) { cwd = options_1.options.cwd; }
if (cwd === void 0) { cwd = process.cwd(); }
return configLoader({ cwd: cwd });

@@ -16,4 +15,3 @@ }

if (explicitParams) {
// tslint:disable-next-line:no-shadowed-variable
var absoluteBaseUrl_1 = path.isAbsolute(explicitParams.baseUrl)
var absoluteBaseUrl = path.isAbsolute(explicitParams.baseUrl)
? explicitParams.baseUrl

@@ -25,3 +23,3 @@ : path.join(cwd, explicitParams.baseUrl);

baseUrl: explicitParams.baseUrl,
absoluteBaseUrl: absoluteBaseUrl_1,
absoluteBaseUrl: absoluteBaseUrl,
paths: explicitParams.paths,

@@ -43,10 +41,2 @@ mainFields: explicitParams.mainFields,

}
if (!loadResult.baseUrl) {
return {
resultType: "failed",
message: "Missing baseUrl in compilerOptions",
};
}
var tsConfigDir = path.dirname(loadResult.tsConfigPath);
var absoluteBaseUrl = path.join(tsConfigDir, loadResult.baseUrl);
return {

@@ -56,4 +46,5 @@ resultType: "success",

baseUrl: loadResult.baseUrl,
absoluteBaseUrl: absoluteBaseUrl,
absoluteBaseUrl: path.resolve(path.dirname(loadResult.tsConfigPath), loadResult.baseUrl || ""),
paths: loadResult.paths || {},
addMatchAll: loadResult.baseUrl !== undefined,
};

@@ -60,0 +51,0 @@ }

@@ -28,2 +28,3 @@ /**

* Reads package.json from disk
*
* @param file Path to package.json

@@ -30,0 +31,0 @@ */

@@ -18,5 +18,6 @@ "use strict";

* Reads package.json from disk
*
* @param file Path to package.json
*/
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function readJsonFromDiskSync(packageJsonPath) {

@@ -26,2 +27,3 @@ if (!fs.existsSync(packageJsonPath)) {

}
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require(packageJsonPath);

@@ -31,3 +33,3 @@ }

function readJsonFromDiskAsync(path,
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback) {

@@ -34,0 +36,0 @@ fs.readFile(path, "utf8", function (err, result) {

@@ -13,2 +13,3 @@ export interface MappingEntry {

* sort by keys each time we use the mappings.
*
* @param absoluteBaseUrl

@@ -15,0 +16,0 @@ * @param paths

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

* sort by keys each time we use the mappings.
*
* @param absoluteBaseUrl

@@ -26,3 +27,3 @@ * @param paths

paths: paths[key].map(function (pathToResolve) {
return path.join(absoluteBaseUrl, pathToResolve);
return path.resolve(absoluteBaseUrl, pathToResolve);
}),

@@ -29,0 +30,0 @@ });

@@ -11,2 +11,3 @@ import * as Filesystem from "./filesystem";

* Creates a function that can resolve paths according to tsconfig paths property.
*
* @param absoluteBaseUrl Absolute version of baseUrl as specified in tsconfig.

@@ -23,2 +24,3 @@ * @param paths The paths as specified in tsconfig.

* 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.

@@ -25,0 +27,0 @@ * @param requestedModule The required module name.

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

* Creates a function that can resolve paths according to tsconfig paths property.
*
* @param absoluteBaseUrl Absolute version of baseUrl as specified in tsconfig.

@@ -28,2 +29,3 @@ * @param paths The paths as specified in tsconfig.

* 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.

@@ -30,0 +32,0 @@ * @param requestedModule The required module name.

import { ExplicitParams } from "./config-loader";
export interface RegisterParams extends ExplicitParams {
/**
* Defaults to `--project` CLI flag or `process.cwd()`
*/
cwd?: string;
}
/**

@@ -6,2 +12,2 @@ * Installs a custom module load function that can adhere to paths in tsconfig.

*/
export declare function register(explicitParams: ExplicitParams): () => void;
export declare function register(params?: RegisterParams): () => void;

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

var config_loader_1 = require("./config-loader");
var options_1 = require("./options");
var noOp = function () { return void 0; };

@@ -59,5 +58,25 @@ function getCoreModules(builtinModules) {

*/
function register(explicitParams) {
function register(params) {
var cwd;
var explicitParams;
if (params) {
cwd = params.cwd;
if (params.baseUrl || params.paths) {
explicitParams = params;
}
}
else {
// eslint-disable-next-line
var minimist = require("minimist");
var argv = minimist(process.argv.slice(2), {
// eslint-disable-next-line id-denylist
string: ["project"],
alias: {
project: ["P"],
},
});
cwd = argv.project;
}
var configLoaderResult = (0, config_loader_1.configLoader)({
cwd: options_1.options.cwd,
cwd: cwd !== null && cwd !== void 0 ? cwd : process.cwd(),
explicitParams: explicitParams,

@@ -71,7 +90,8 @@ });

// Patch node's module loading
// tslint:disable-next-line:no-require-imports variable-name
// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires
var Module = require("module");
// eslint-disable-next-line no-underscore-dangle
var originalResolveFilename = Module._resolveFilename;
var coreModules = getCoreModules(Module.builtinModules);
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any,no-underscore-dangle
Module._resolveFilename = function (request, _parent) {

@@ -83,7 +103,5 @@ var isCoreModule = coreModules.hasOwnProperty(request);

var modifiedArguments = __spreadArray([found], [].slice.call(arguments, 1), true); // Passes all arguments. Even those that is not specified above.
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, modifiedArguments);
}
}
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, arguments);

@@ -93,2 +111,3 @@ };

// Return node's module loading to original state.
// eslint-disable-next-line no-underscore-dangle
Module._resolveFilename = originalResolveFilename;

@@ -95,0 +114,0 @@ };

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

* Star must match at least one character to be considered a match.
*
* @param patttern for example "foo*"

@@ -67,0 +68,0 @@ * @param search for example "fooawesomebar"

@@ -27,3 +27,3 @@ /**

export declare function tsConfigLoader({ getEnv, cwd, loadSync, }: TsConfigLoaderParams): TsConfigLoaderResult;
export declare function walkForTsConfig(directory: string, existsSync?: (path: string) => boolean): string | undefined;
export declare function walkForTsConfig(directory: string, readdirSync?: (path: string) => string[]): string | undefined;
export declare function loadTsconfig(configFilePath: string, existsSync?: (path: string) => boolean, readFileSync?: (filename: string) => string): Tsconfig | undefined;

@@ -17,4 +17,5 @@ "use strict";

var fs = require("fs");
// tslint:disable:no-require-imports
// eslint-disable-next-line @typescript-eslint/no-require-imports
var JSON5 = require("json5");
// eslint-disable-next-line @typescript-eslint/no-require-imports
var StripBom = require("strip-bom");

@@ -62,9 +63,13 @@ function tsConfigLoader(_a) {

}
function walkForTsConfig(directory, existsSync) {
if (existsSync === void 0) { existsSync = fs.existsSync; }
var configPath = path.join(directory, "./tsconfig.json");
if (existsSync(configPath)) {
return configPath;
function walkForTsConfig(directory, readdirSync) {
if (readdirSync === void 0) { readdirSync = fs.readdirSync; }
var files = readdirSync(directory);
var filesToCheck = ["tsconfig.json", "jsconfig.json"];
for (var _i = 0, filesToCheck_1 = filesToCheck; _i < filesToCheck_1.length; _i++) {
var fileToCheck = filesToCheck_1[_i];
if (files.indexOf(fileToCheck) !== -1) {
return path.join(directory, fileToCheck);
}
}
var parentDirectory = path.join(directory, "../");
var parentDirectory = path.dirname(directory);
// If we reached the top

@@ -74,6 +79,8 @@ if (directory === parentDirectory) {

}
return walkForTsConfig(parentDirectory, existsSync);
return walkForTsConfig(parentDirectory, readdirSync);
}
exports.walkForTsConfig = walkForTsConfig;
function loadTsconfig(configFilePath, existsSync, readFileSync) {
function loadTsconfig(configFilePath,
// eslint-disable-next-line no-shadow
existsSync, readFileSync) {
if (existsSync === void 0) { existsSync = fs.existsSync; }

@@ -80,0 +87,0 @@ if (readFileSync === void 0) { readFileSync = function (filename) {

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

@@ -25,2 +25,8 @@ "main": "lib/index.js",

"@types/strip-json-comments": "^0.0.30",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.2.9",
"husky": "^4.2.5",

@@ -33,8 +39,6 @@ "jest": "^27.3.1",

"ts-node": "^10.7.0",
"tslint": "^5.8.0",
"typescript": "^4.5.2"
},
"dependencies": {
"@types/json5": "^0.0.29",
"json5": "^1.0.1",
"json5": "^2.2.1",
"minimist": "^1.2.6",

@@ -45,3 +49,3 @@ "strip-bom": "^3.0.0"

"start": "cd src && ts-node index.ts",
"example:node": "yarn build && cd ./example/node && ts-node -r ../register.js main.ts",
"example:node": "yarn build && cd ./example/node && ts-node -r ../../register.js main.ts",
"example:project": "yarn build && ts-node -r ./register.js -P ./example/project/tsconfig.json ./example/project/main.ts",

@@ -53,3 +57,3 @@ "example:api": "cd example/api && ts-node main.ts",

"build": "rimraf lib && tsc -p .",
"lint": "tslint './{src,tests}/**/*.ts{,x}'",
"lint": "eslint \"./{src,tests}/**/*.ts{,x}\" --ext .js,.ts,.tsx -f visualstudio",
"verify": "yarn build && yarn lint && yarn test-coverage",

@@ -60,3 +64,3 @@ "preversion": "yarn verify",

"lint-staged": {
"*.{ts,tsx}": "tslint",
"*.{ts,tsx}": "eslint",
"*.{ts,tsx,json,css}": [

@@ -63,0 +67,0 @@ "prettier --write",

@@ -9,7 +9,7 @@ # tsconfig-paths

Use this to load modules whose location is specified in the `paths` section of `tsconfig.json`. Both loading at run-time and via API are supported.
Use this to load modules whose location is specified in the `paths` section of `tsconfig.json` or `jsconfig.json`. Both loading at run-time and via API are supported.
Typescript by default mimics the Node.js runtime resolution strategy of modules. But it also allows the use of [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html) which allows arbitrary module paths (that doesn't start with "/" or ".") to be specified and mapped to physical paths in the filesystem. The typescript compiler can resolve these paths from `tsconfig` so it will compile OK. But if you then try to execute the compiled files with node (or ts-node), it will only look in the `node_modules` folders all the way up to the root of the filesystem and thus will not find the modules specified by `paths` in `tsconfig`.
If you require this package's `tsconfig-paths/register` module it will read the `paths` from `tsconfig.json` and convert node's module loading calls into to physical file paths that node can load.
If you require this package's `tsconfig-paths/register` module it will read the `paths` from `tsconfig.json` or `jsconfig.json` and convert node's module loading calls into to physical file paths that node can load.

@@ -152,2 +152,3 @@ ## How to install

addMatchAll?: boolean;
cwd?: string;
}

@@ -161,3 +162,3 @@

This function will patch the node's module loading so it will look for modules in paths specified by tsconfig.json.
This function will patch the node's module loading so it will look for modules in paths specified by `tsconfig.json` or `jsconfig.json`.
A function is returned for you to reinstate Node's original module loading.

@@ -186,3 +187,3 @@

This function loads the tsconfig.json. It will start searching from the specified `cwd` directory. Passing the tsconfig.json file directly instead of a directory also works.
This function loads the `tsconfig.json` or `jsconfig.json`. It will start searching from the specified `cwd` directory. Passing the `tsconfig.json` or `jsconfig.json` file directly instead of a directory also works.

@@ -189,0 +190,0 @@ ### createMatchPath

@@ -22,5 +22,2 @@ import {

const successResult = result as ConfigLoaderSuccessResult;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, "/foo/bar");
// assert.equal(successResult.paths["asd"][0], "asd");
expect(successResult.resultType).toBe("success");

@@ -43,4 +40,2 @@ expect(successResult.absoluteBaseUrl).toBe("/foo/bar");

const successResult = result as ConfigLoaderSuccessResult;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "bar/"));
expect(successResult.resultType).toBe("success");

@@ -54,4 +49,3 @@ expect(successResult.absoluteBaseUrl).toBe(join("/baz", "bar/"));

cwd: "/baz",
// tslint:disable-next-line:no-any
tsConfigLoader: (_: any) => ({
tsConfigLoader: () => ({
tsConfigPath: "/baz/tsconfig.json",

@@ -64,4 +58,2 @@ baseUrl: "./src",

const successResult = result as ConfigLoaderSuccessResult;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.absoluteBaseUrl, join("/baz", "src"));
expect(successResult.resultType).toBe("success");

@@ -71,8 +63,7 @@ expect(successResult.absoluteBaseUrl).toBe(join("/baz", "src"));

it("should show an error message when baseUrl is missing", () => {
it("should tolerate a missing baseUrl", () => {
const result = configLoader({
explicitParams: undefined,
cwd: "/baz",
// tslint:disable-next-line:no-any
tsConfigLoader: (_: any) => ({
tsConfigLoader: () => ({
tsConfigPath: "/baz/tsconfig.json",

@@ -85,6 +76,3 @@ baseUrl: undefined,

const failResult = result as ConfigLoaderFailResult;
// assert.equal(failResult.resultType, "failed");
// assert.isTrue(failResult.message.indexOf("baseUrl") > -1);
expect(failResult.resultType).toBe("failed");
expect(failResult.message.indexOf("baseUrl") > -1).toBeTruthy();
expect(failResult.resultType).toBe("success");
});

@@ -101,7 +89,20 @@

const successResult = result as ConfigLoaderSuccessResult;
// assert.equal(successResult.resultType, "success");
// assert.equal(successResult.configFileAbsolutePath, configFile);
expect(successResult.resultType).toBe("success");
expect(successResult.configFileAbsolutePath).toBe(configFile);
});
it("should allow an absolute baseUrl in tsconfig.json", () => {
const result = configLoader({
explicitParams: undefined,
cwd: "/baz",
tsConfigLoader: () => ({
tsConfigPath: "/baz/tsconfig.json",
baseUrl: "/baz",
paths: {},
}),
});
const successResult = result as ConfigLoaderSuccessResult;
expect(successResult.absoluteBaseUrl).toEqual("/baz");
});
});

@@ -10,3 +10,2 @@ import * as Filesystem from "../filesystem";

const result = Filesystem.fileExistsSync(fileThatExists);
// assert.equal(result, true);
expect(result).toBe(true);

@@ -17,3 +16,2 @@ });

const result = Filesystem.fileExistsSync(fileThatNotExists);
// assert.equal(result, false);
expect(result).toBe(false);

@@ -25,3 +23,2 @@ });

try {
// assert.equal(result, true);
expect(result).toBe(true);

@@ -38,3 +35,2 @@ done();

try {
// assert.equal(result, false);
expect(result).toBe(false);

@@ -50,5 +46,3 @@ done();

const result = Filesystem.readJsonFromDiskSync(fileThatExists);
// assert.isOk(result);
expect(result);
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");

@@ -60,5 +54,3 @@ });

try {
// assert.isOk(result); // Asserts that object is truthy.
expect(result).toBeTruthy();
// assert.equal(result.main, "lib/index.js");
expect(result.main).toBe("lib/index.js");

@@ -65,0 +57,0 @@ done();

@@ -9,4 +9,4 @@ import { getAbsoluteMappingEntries } from "../mapping-entry";

{
"*": ["/foo1", "/foo2"],
"longest/pre/fix/*": ["/foo2/bar"],
"*": ["/foo1", "./foo2"],
"longest/pre/fix/*": ["./foo2/bar"],
"pre/fix/*": ["/foo3"],

@@ -16,19 +16,2 @@ },

);
// assert.deepEqual(result, [
// {
// pattern: "longest/pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo2", "bar")],
// },
// {
// pattern: "pre/fix/*",
// paths: [join("/absolute", "base", "url", "foo3")],
// },
// {
// pattern: "*",
// paths: [
// join("/absolute", "base", "url", "foo1"),
// join("/absolute", "base", "url", "foo2"),
// ],
// },
// ]);
expect(result).toEqual([

@@ -41,10 +24,7 @@ {

pattern: "pre/fix/*",
paths: [join("/absolute", "base", "url", "foo3")],
paths: [join("/foo3")],
},
{
pattern: "*",
paths: [
join("/absolute", "base", "url", "foo1"),
join("/absolute", "base", "url", "foo2"),
],
paths: [join("/foo1"), join("/absolute", "base", "url", "foo2")],
},

@@ -56,8 +36,2 @@ ]);

let result = getAbsoluteMappingEntries("/absolute/base/url", {}, true);
// assert.deepEqual(result, [
// {
// pattern: "*",
// paths: [join("/absolute", "base", "url", "*")],
// },
// ]);
expect(result).toEqual([

@@ -71,5 +45,4 @@ {

result = getAbsoluteMappingEntries("/absolute/base/url", {}, false);
// assert.deepEqual(result, []);
expect(result).toEqual([]);
});
});

@@ -20,3 +20,2 @@ import { createMatchPathAsync } from "../match-path-async";

(_err, result) => {
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);

@@ -23,0 +22,0 @@ done();

@@ -19,3 +19,2 @@ import { createMatchPath } from "../match-path-sync";

);
// assert.equal(result, t.expectedPath);
expect(result).toBe(t.expectedPath);

@@ -22,0 +21,0 @@ })

@@ -29,3 +29,2 @@ import { getPathsToTry } from "../try-path";

);
// assert.deepEqual(result, undefined);
expect(result).toBeUndefined();

@@ -58,42 +57,2 @@ });

);
// assert.deepEqual(result, [
// // "longest/pre/fix/*"
// { type: "file", path: join("/absolute", "base", "url", "foo2", "bar") },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.ts"),
// },
// {
// type: "extension",
// path: join("/absolute", "base", "url", "foo2", "bar.tsx"),
// },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo2", "bar", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo2", "bar", "index.tsx"),
// },
// // "*"
// { type: "file", path: join("/absolute", "base", "url", "foo1") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.ts") },
// { type: "extension", path: join("/absolute", "base", "url", "foo1.tsx") },
// {
// type: "package",
// path: join("/absolute", "base", "url", "foo1", "package.json"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.ts"),
// },
// {
// type: "index",
// path: join("/absolute", "base", "url", "foo1", "index.tsx"),
// },
// ]);
expect(result).toEqual([

@@ -185,12 +144,1 @@ // "longest/pre/fix/*"

});
// describe("match-star", () => {
// it("should match star in last position", () => {
// const result = matchStar("lib/*", "lib/mylib");
// assert.equal(result, "mylib");
// });
// it("should match star in first position", () => {
// const result = matchStar("*/lib", "mylib/lib");
// assert.equal(result, "mylib");
// });
// });

@@ -22,3 +22,2 @@ import {

// assert.equal(result.tsConfigPath, "/foo/bar/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/bar/tsconfig.json");

@@ -40,3 +39,2 @@ });

// assert.isUndefined(result.tsConfigPath);
expect(result.tsConfigPath).toBeUndefined();

@@ -67,3 +65,2 @@ });

// assert.equal(result.tsConfigPath, "/foo/baz/tsconfig.json");
expect(result.tsConfigPath).toBe("/foo/baz/tsconfig.json");

@@ -86,3 +83,2 @@ });

// assert.equal(result.baseUrl, "SOME_BASEURL");
expect(result.baseUrl).toBe("SOME_BASEURL");

@@ -106,3 +102,2 @@ });

// assert.equal(result.baseUrl, undefined);
expect(result.baseUrl).toBeUndefined();

@@ -115,23 +110,63 @@ });

const pathToTsconfig = join("/root", "dir1", "tsconfig.json");
const mockFiles: Record<string, string[]> = {
"/root/dir1": ["tsconfig.json"],
};
const res = walkForTsConfig(
join("/root", "dir1"),
(path) => path === pathToTsconfig
(path) => mockFiles[path] || []
);
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToTsconfig);
});
it("should find jsconfig in starting directory", () => {
const pathToJsconfig = join("/root", "dir1", "jsconfig.json");
const mockFiles: Record<string, string[]> = {
"/root/dir1": ["jsconfig.json"],
};
const res = walkForTsConfig(
join("/root", "dir1"),
(path) => mockFiles[path] || []
);
expect(res).toBe(pathToJsconfig);
});
// see https://github.com/Microsoft/TypeScript/issues/15869#issuecomment-301845650
it("tsconfig.json take precedence over jsconfig.json when both exist", () => {
const pathToTsconfig = join("/root/dir1", "tsconfig.json");
const mockFiles: Record<string, string[]> = {
"/root/dir1": ["jsconfig.json", "tsconfig.json"],
};
const res = walkForTsConfig(
join("/root", "dir1"),
(path) => mockFiles[path] || []
);
expect(res).toBe(pathToTsconfig);
});
it("should find tsconfig in parent directory", () => {
const pathToTsconfig = join("/root", "tsconfig.json");
const mockFiles: Record<string, string[]> = {
"/root": ["tsconfig.json"],
};
const res = walkForTsConfig(
join("/root", "dir1"),
(path) => path === pathToTsconfig
(path) => mockFiles[path] || []
);
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToTsconfig);
});
it("should find jsconfig in parent directory", () => {
const pathToTsconfig = join("/root", "jsconfig.json");
const mockFiles: Record<string, string[]> = {
"/root": ["jsconfig.json"],
};
const res = walkForTsConfig(
join("/root", "dir1"),
(path) => mockFiles[path] || []
);
expect(res).toBe(pathToTsconfig);
});
it("should return undefined when reaching the top", () => {
const res = walkForTsConfig(join("/root", "dir1", "kalle"), () => false);
// assert.equal(res, undefined);
const res = walkForTsConfig(join("/root", "dir1", "kalle"), () => []);
expect(res).toBeUndefined();

@@ -149,3 +184,2 @@ });

);
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);

@@ -166,3 +200,2 @@ });

);
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);

@@ -182,3 +215,2 @@ });

);
// assert.deepEqual(res, config);
expect(res).toStrictEqual(config);

@@ -215,10 +247,2 @@ });

// assert.deepEqual(res, {
// extends: "../base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({

@@ -268,10 +292,2 @@ extends: "../base-config.json",

// assert.deepEqual(res, {
// extends: "my-package/base-config.json",
// compilerOptions: {
// baseUrl: "kalle",
// paths: { foo: ["bar2"] },
// strict: true,
// },
// });
expect(res).toEqual({

@@ -314,6 +330,2 @@ extends: "my-package/base-config.json",

// assert.deepEqual(res, {
// extends: "../second-config.json",
// compilerOptions: { baseUrl: join("..", "..") },
// });
expect(res).toEqual({

@@ -320,0 +332,0 @@ extends: "../second-config.json",

import * as TsConfigLoader2 from "./tsconfig-loader";
import * as path from "path";
import { options } from "./options";

@@ -25,3 +24,3 @@ export interface ExplicitParams {

configFileAbsolutePath: string;
baseUrl: string;
baseUrl?: string;
absoluteBaseUrl: string;

@@ -42,4 +41,4 @@ paths: { [key: string]: Array<string> };

export function loadConfig(cwd: string = options.cwd): ConfigLoaderResult {
return configLoader({ cwd: cwd });
export function loadConfig(cwd: string = process.cwd()): ConfigLoaderResult {
return configLoader({ cwd });
}

@@ -53,3 +52,2 @@

if (explicitParams) {
// tslint:disable-next-line:no-shadowed-variable
const absoluteBaseUrl = path.isAbsolute(explicitParams.baseUrl)

@@ -83,12 +81,2 @@ ? explicitParams.baseUrl

if (!loadResult.baseUrl) {
return {
resultType: "failed",
message: "Missing baseUrl in compilerOptions",
};
}
const tsConfigDir = path.dirname(loadResult.tsConfigPath);
const absoluteBaseUrl = path.join(tsConfigDir, loadResult.baseUrl);
return {

@@ -98,5 +86,9 @@ resultType: "success",

baseUrl: loadResult.baseUrl,
absoluteBaseUrl,
absoluteBaseUrl: path.resolve(
path.dirname(loadResult.tsConfigPath),
loadResult.baseUrl || ""
),
paths: loadResult.paths || {},
addMatchAll: loadResult.baseUrl !== undefined,
};
}

@@ -14,3 +14,3 @@ import * as fs from "fs";

export interface ReadJsonSync {
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(packageJsonPath: string): any | undefined;

@@ -28,3 +28,3 @@ }

export interface ReadJsonAsyncCallback {
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(err?: Error, content?: any): void;

@@ -49,5 +49,6 @@ }

* Reads package.json from disk
*
* @param file Path to package.json
*/
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function readJsonFromDiskSync(packageJsonPath: string): any | undefined {

@@ -57,2 +58,3 @@ if (!fs.existsSync(packageJsonPath)) {

}
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require(packageJsonPath);

@@ -63,3 +65,3 @@ }

path: string,
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback: (err?: Error, content?: any) => void

@@ -66,0 +68,0 @@ ): void {

@@ -17,2 +17,3 @@ import * as path from "path";

* sort by keys each time we use the mappings.
*
* @param absoluteBaseUrl

@@ -36,3 +37,3 @@ * @param paths

paths: paths[key].map((pathToResolve) =>
path.join(absoluteBaseUrl, pathToResolve)
path.resolve(absoluteBaseUrl, pathToResolve)
),

@@ -39,0 +40,0 @@ });

@@ -20,2 +20,3 @@ import * as path from "path";

export interface MatchPathAsyncCallback {
// eslint-disable-next-line no-shadow
(err?: Error, path?: string): void;

@@ -101,3 +102,3 @@ }

const tryNext = () =>
const tryNext = (): void =>
findFirstExistingMainFieldMappedFile(

@@ -104,0 +105,0 @@ packageJson,

@@ -20,2 +20,3 @@ import * as path from "path";

* Creates a function that can resolve paths according to tsconfig paths property.
*
* @param absoluteBaseUrl Absolute version of baseUrl as specified in tsconfig.

@@ -57,2 +58,3 @@ * @param paths The paths as specified in tsconfig.

* 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.

@@ -59,0 +61,0 @@ * @param requestedModule The required module name.

import { createMatchPath } from "./match-path-sync";
import { configLoader, ExplicitParams } from "./config-loader";
import { options } from "./options";

@@ -48,2 +47,9 @@ const noOp = (): void => void 0;

export interface RegisterParams extends ExplicitParams {
/**
* Defaults to `--project` CLI flag or `process.cwd()`
*/
cwd?: string;
}
/**

@@ -53,5 +59,25 @@ * Installs a custom module load function that can adhere to paths in tsconfig.

*/
export function register(explicitParams: ExplicitParams): () => void {
export function register(params?: RegisterParams): () => void {
let cwd: string | undefined;
let explicitParams: ExplicitParams | undefined;
if (params) {
cwd = params.cwd;
if (params.baseUrl || params.paths) {
explicitParams = params;
}
} else {
// eslint-disable-next-line
const minimist = require("minimist");
const argv = minimist(process.argv.slice(2), {
// eslint-disable-next-line id-denylist
string: ["project"],
alias: {
project: ["P"],
},
});
cwd = argv.project;
}
const configLoaderResult = configLoader({
cwd: options.cwd,
cwd: cwd ?? process.cwd(),
explicitParams,

@@ -76,7 +102,8 @@ });

// Patch node's module loading
// tslint:disable-next-line:no-require-imports variable-name
// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires
const Module = require("module");
// eslint-disable-next-line no-underscore-dangle
const originalResolveFilename = Module._resolveFilename;
const coreModules = getCoreModules(Module.builtinModules);
// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any,no-underscore-dangle
Module._resolveFilename = function (request: string, _parent: any): string {

@@ -88,7 +115,5 @@ const isCoreModule = coreModules.hasOwnProperty(request);

const modifiedArguments = [found, ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above.
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, modifiedArguments);
}
}
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, arguments);

@@ -99,4 +124,5 @@ };

// Return node's module loading to original state.
// eslint-disable-next-line no-underscore-dangle
Module._resolveFilename = originalResolveFilename;
};
}

@@ -78,2 +78,3 @@ import * as path from "path";

* Star must match at least one character to be considered a match.
*
* @param patttern for example "foo*"

@@ -80,0 +81,0 @@ * @param search for example "fooawesomebar"

import * as path from "path";
import * as fs from "fs";
// tslint:disable:no-require-imports
// eslint-disable-next-line @typescript-eslint/no-require-imports
import JSON5 = require("json5");
// eslint-disable-next-line @typescript-eslint/no-require-imports
import StripBom = require("strip-bom");
// tslint:enable:no-require-imports

@@ -93,13 +93,15 @@ /**

}
export function walkForTsConfig(
directory: string,
existsSync: (path: string) => boolean = fs.existsSync
readdirSync: (path: string) => string[] = fs.readdirSync
): string | undefined {
const configPath = path.join(directory, "./tsconfig.json");
if (existsSync(configPath)) {
return configPath;
const files = readdirSync(directory);
const filesToCheck = ["tsconfig.json", "jsconfig.json"];
for (const fileToCheck of filesToCheck) {
if (files.indexOf(fileToCheck) !== -1) {
return path.join(directory, fileToCheck);
}
}
const parentDirectory = path.join(directory, "../");
const parentDirectory = path.dirname(directory);

@@ -111,3 +113,3 @@ // If we reached the top

return walkForTsConfig(parentDirectory, existsSync);
return walkForTsConfig(parentDirectory, readdirSync);
}

@@ -117,2 +119,3 @@

configFilePath: string,
// eslint-disable-next-line no-shadow
existsSync: (path: string) => boolean = fs.existsSync,

@@ -119,0 +122,0 @@ readFileSync: (filename: string) => string = (filename: string) =>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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