Skip to content

Commit

Permalink
fix: do not resolve stopDir when undefined
Browse files Browse the repository at this point in the history
Fixed: #317
  • Loading branch information
jrandolf committed Sep 2, 2023
1 parent 6476b36 commit 59082e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Explorer extends ExplorerBase<InternalOptions> {
}
}

const stopDir = path.resolve(this.config.stopDir);
const stopDir = this.config.stopDir && path.resolve(this.config.stopDir);
from = path.resolve(from);
const search = async (): Promise<CosmiconfigResult> => {
/* istanbul ignore if -- @preserve */
Expand Down
2 changes: 1 addition & 1 deletion src/ExplorerSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ExplorerSync extends ExplorerBase<InternalOptionsSync> {
}
}

const stopDir = path.resolve(this.config.stopDir);
const stopDir = this.config.stopDir && path.resolve(this.config.stopDir);
from = path.resolve(from);
const search = (): CosmiconfigResult => {
/* istanbul ignore if -- @preserve */
Expand Down
12 changes: 12 additions & 0 deletions test/successful-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,15 @@ describe('[#313] config search does not fail if there is a file named .config',
expect(result).toBeNull();
});
});

describe('[#317] `explorer.search(...)` should not crashes with `{stopDir: undefined}` option', () => {
test('sync', () => {
const result = cosmiconfigSync('tester', { stopDir: undefined }).search();
expect(result).toBeNull();
});

test('async', async () => {
const result = await cosmiconfig('tester', { stopDir: undefined }).search();
expect(result).toBeNull();
});
});

0 comments on commit 59082e2

Please sign in to comment.