Skip to content

Commit

Permalink
feat: add support for jsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeng.freeman authored and F3n67u committed Apr 16, 2022
1 parent e6bc77f commit 61ee5bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/__tests__/tsconfig-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ describe("walkForTsConfig", () => {
expect(res).toBe(pathToTsconfig);
});

it("should find jsconfig in starting directory", () => {
const pathToJsconfig = join("/root", "dir1", "jsconfig.json");
const res = walkForTsConfig(
join("/root", "dir1"),
(path) => path === pathToJsconfig
);
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToJsconfig);
});

it("should find tsconfig in parent directory", () => {
const pathToTsconfig = join("/root", "tsconfig.json");
const res = walkForTsConfig(
Expand All @@ -125,6 +135,16 @@ describe("walkForTsConfig", () => {
expect(res).toBe(pathToTsconfig);
});

it("should find jsconfig in parent directory", () => {
const pathToTsconfig = join("/root", "jsconfig.json");
const res = walkForTsConfig(
join("/root", "dir1"),
(path) => path === pathToTsconfig
);
// assert.equal(res, pathToTsconfig);
expect(res).toBe(pathToTsconfig);
});

it("should return undefined when reaching the top", () => {
const res = walkForTsConfig(join("/root", "dir1", "kalle"), () => false);
// assert.equal(res, undefined);
Expand Down
7 changes: 6 additions & 1 deletion src/tsconfig-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ export function walkForTsConfig(
// eslint-disable-next-line no-shadow
existsSync: (path: string) => boolean = fs.existsSync
): string | undefined {
const configPath = path.join(directory, "./tsconfig.json");
let configPath = path.join(directory, "./tsconfig.json");
if (existsSync(configPath)) {
return configPath;
}

configPath = path.join(directory, "./jsconfig.json");
if (existsSync(configPath)) {
return configPath;
}
Expand Down

0 comments on commit 61ee5bf

Please sign in to comment.