Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #31: Problem when using a custom configFile name #32

Merged
merged 1 commit into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/tsconfig-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export function resolveConfigPath(
return absolutePath;
}

if (fs.statSync(cwd).isFile()) {
return path.resolve(cwd);
}

const configAbsolutePath = walkForTsConfig(cwd);
return configAbsolutePath ? path.resolve(configAbsolutePath) : undefined;
}
Expand Down
14 changes: 14 additions & 0 deletions test/config-loader-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert } from "chai";
import {
configLoader,
loadConfig,
ConfigLoaderFailResult,
ConfigLoaderSuccessResult
} from "../src/config-loader";
Expand Down Expand Up @@ -73,4 +74,17 @@ describe("config-loader", (): void => {
assert.equal(failResult.resultType, "failed");
assert.isTrue(failResult.message.indexOf("baseUrl") > -1);
});

it("should presume cwd to be a tsconfig file when loadConfig is called with absolute path to tsconfig.json", () => {
// using tsconfig-named.json to ensure that future changes to fix
// https://github.com/dividab/tsconfig-paths/issues/31
// do not pass this test case just because of a directory walk looking
// for tsconfig.json
const configFile = join(__dirname, "tsconfig-named.json");
const result = loadConfig(configFile);

const successResult = result as ConfigLoaderSuccessResult;
assert.equal(successResult.resultType, "success");
assert.equal(successResult.configFileAbsolutePath, configFile);
});
});
10 changes: 10 additions & 0 deletions test/tsconfig-named.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../base-tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"outDir": "./js_out"
}
}