@sprucelabs/path-resolver
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -13,2 +13,3 @@ export interface IPathResolverOptions { | ||
cwd: string; | ||
baseDir: string; | ||
extensions: string[]; | ||
@@ -15,0 +16,0 @@ constructor(options: IPathResolverOptions); |
@@ -13,2 +13,3 @@ "use strict"; | ||
constructor(options) { | ||
var _a; | ||
this.replacePaths = {}; | ||
@@ -27,3 +28,3 @@ this.pathCache = {}; | ||
// We have to set these to at least something or ts will not pass lint | ||
this.cwd = cwd || (process && process.cwd()) || '/'; | ||
this.cwd = this.baseDir = cwd || (process && process.cwd()) || '/'; | ||
this.compilerOptions = {}; | ||
@@ -37,6 +38,12 @@ log_1.default.info('PathResolver setup for', this.extensions); | ||
do { | ||
const tsConfigPath = path.join(...pathParts, 'tsconfig.json'); | ||
const dir = path.join(...pathParts); | ||
const tsConfigPath = path.join(dir, 'tsconfig.json'); | ||
if (fs_1.default.existsSync(tsConfigPath)) { | ||
log_1.default.info(`Loading tsconfig from ${tsConfigPath}`); | ||
this.compilerOptions = require(tsConfigPath).compilerOptions; | ||
this.baseDir = | ||
this.compilerOptions.baseUrl && | ||
this.compilerOptions.baseUrl[0] === path.sep | ||
? this.compilerOptions.baseUrl | ||
: path.join(dir, (_a = this.compilerOptions.baseUrl) !== null && _a !== void 0 ? _a : '.'); | ||
found = true; | ||
@@ -86,6 +93,6 @@ break; | ||
if (typeof this.compilerOptions.outDir === 'string') { | ||
candidates.push(path.join(this.cwd, this.compilerOptions.outDir, request.replace(regex, candidatePath))); | ||
candidates.push(path.join(this.baseDir, this.compilerOptions.outDir, request.replace(regex, candidatePath))); | ||
} | ||
// Try relative to cwd | ||
candidates.push(path.join(this.cwd, request.replace(regex, candidatePath))); | ||
candidates.push(path.join(this.baseDir, request.replace(regex, candidatePath))); | ||
// Does this candidate exist? if so, mutate the request so core loads it correctly | ||
@@ -110,3 +117,3 @@ foundMatch = true; | ||
if (foundMatch) { | ||
log_1.default.crit(`Found a match for ${request} but no existing candidate: ${attemptedPaths.join('\n')}`); | ||
log_1.default.crit(`Found a match for ${request} but no candidates found: \n\n ${attemptedPaths.join('\n')}`); | ||
throw new Error(`Could not resolve ${request}, tried: \n\n ${attemptedPaths.join('\n')}`); | ||
@@ -113,0 +120,0 @@ } |
@@ -0,1 +1,3 @@ | ||
## [1.0.10](https://github.com/sprucelabsai/path-resolver/compare/v1.0.9...v1.0.10) (2020-04-14) | ||
## [1.0.9](https://github.com/sprucelabsai/path-resolver/compare/v1.0.8...v1.0.9) (2020-04-14) | ||
@@ -2,0 +4,0 @@ |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"main": "./build/index.js", | ||
@@ -12,0 +12,0 @@ "types": "./build/index.d.ts", |
Sorry, the diff of this file is not supported yet
17105
164