Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cosmiconfig/cosmiconfig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.0.1
Choose a base ref
...
head repository: cosmiconfig/cosmiconfig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.1.0
Choose a head ref
  • 9 commits
  • 8 files changed
  • 2 contributors

Commits on Oct 8, 2021

  1. Copy the full SHA
    780714d View commit details
  2. update README.md

    d-fischer committed Oct 8, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    821272d View commit details
  3. fix existing tests

    d-fischer committed Oct 8, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    385d473 View commit details
  4. add new tests

    d-fischer committed Oct 8, 2021
    Copy the full SHA
    44bc801 View commit details

Commits on Dec 9, 2021

  1. Copy the full SHA
    b23bb38 View commit details

Commits on Nov 12, 2022

  1. add changelog entry

    d-fischer committed Nov 12, 2022
    Copy the full SHA
    a4da8c1 View commit details
  2. Merge pull request #263 from d-fischer/config-subdir

    Add .config subdir to default searchPlaces
    d-fischer authored Nov 12, 2022
    Copy the full SHA
    829893b View commit details
  3. Changelog 7.1.0

    d-fischer committed Nov 12, 2022
    Copy the full SHA
    4ab669c View commit details
  4. 7.1.0

    d-fischer committed Nov 12, 2022
    Copy the full SHA
    18f1441 View commit details
Showing with 478 additions and 3 deletions.
  1. +4 −0 CHANGELOG.md
  2. +11 −2 README.md
  3. +1 −1 package.json
  4. +6 −0 src/index.ts
  5. +36 −0 test/caches.test.ts
  6. +30 −0 test/failed-directories.test.ts
  7. +6 −0 test/index.test.ts
  8. +384 −0 test/successful-directories.test.ts
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 7.1.0

- Added: additional default `searchPlaces` within a .config subdirectory (without leading dot in the file name)

## 7.0.1

- Fixed: If there was a directory that had the same name as a search place (e.g. "package.json"), we would try to read it as a file, which would cause an exception.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -13,13 +13,15 @@ By default, Cosmiconfig will start where you tell it to start and search up the
- a `package.json` property
- a JSON or YAML, extensionless "rc file"
- an "rc file" with the extensions `.json`, `.yaml`, `.yml`, `.js`, or `.cjs`
- any of the above two inside a `.config` subdirectory
- a `.config.js` or `.config.cjs` CommonJS module

For example, if your module's name is "myapp", cosmiconfig will search up the directory tree for configuration in the following places:

- a `myapp` property in `package.json`
- a `.myapprc` file in JSON or YAML format
- a `.myapprc.json`, `.myapprc.yaml`, `.myapprc.yml`, `.myapprc.js`, or `.myapprc.cjs` file
- a `myapprc`, `myapprc.json`, `myapprc.yaml`, `myapprc.yml`, `myapprc.js` or `myapprc.cjs` file inside a `.config` subdirectory`
- a `myapp.config.js` or `myapp.config.cjs` CommonJS module exporting an object

Cosmiconfig continues to search up the directory tree, checking each of these places in each directory, until it finds some acceptable configuration (or hits the home directory).
@@ -143,7 +145,8 @@ Here's how your default [`search()`] will work:
1. A `goldengrahams` property in a `package.json` file.
2. A `.goldengrahamsrc` file with JSON or YAML syntax.
3. A `.goldengrahamsrc.json`, `.goldengrahamsrc.yaml`, `.goldengrahamsrc.yml`, `.goldengrahamsrc.js`, or `.goldengrahamsrc.cjs` file.
4. A `goldengrahams.config.js` or `goldengrahams.config.cjs` CommonJS module exporting the object.
4. A `goldengrahamsrc`, `goldengrahamsrc.json`, `goldengrahamsrc.yaml`, `goldengrahamsrc.yml`, `goldengrahamsrc.js`, or `goldengrahamsrc.cjs` file in the `.config` subdirectory.
5. A `goldengrahams.config.js` or `goldengrahams.config.cjs` CommonJS module exporting the object.
- If none of those searches reveal a configuration object, move up one directory level and try again.
So the search continues in `./`, `../`, `../../`, `../../../`, etc., checking the same places in each directory.
- Continue searching until arriving at your home directory (or some other directory defined by the cosmiconfig option [`stopDir`]).
@@ -267,6 +270,12 @@ Each place is relative to the directory being searched, and the places are check
`.${moduleName}rc.yml`,
`.${moduleName}rc.js`,
`.${moduleName}rc.cjs`,
`.config/${moduleName}rc`,
`.config/${moduleName}rc.json`,
`.config/${moduleName}rc.yaml`,
`.config/${moduleName}rc.yml`,
`.config/${moduleName}rc.js`,
`.config/${moduleName}rc.cjs`,
`${moduleName}.config.js`,
`${moduleName}.config.cjs`,
]
@@ -374,7 +383,7 @@ If you want to load files that are not handled by the loader functions Cosmiconf

**Third-party loaders:**

- [@endemolshinegroup/cosmiconfig-typescript-loader](https://github.com/EndemolShineGroup/cosmiconfig-typescript-loader)
- [cosmiconfig-typescript-loader](https://github.com/codex-/cosmiconfig-typescript-loader)

**Use cases for custom loader function:**

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmiconfig",
"version": "7.0.1",
"version": "7.1.0",
"description": "Find and load configuration from a package.json property, rc file, or CommonJS module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -116,6 +116,12 @@ function normalizeOptions(
`.${moduleName}rc.yml`,
`.${moduleName}rc.js`,
`.${moduleName}rc.cjs`,
`.config/${moduleName}rc`,
`.config/${moduleName}rc.json`,
`.config/${moduleName}rc.yaml`,
`.config/${moduleName}rc.yml`,
`.config/${moduleName}rc.js`,
`.config/${moduleName}rc.cjs`,
`${moduleName}.config.js`,
`${moduleName}.config.cjs`,
],
36 changes: 36 additions & 0 deletions test/caches.test.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,12 @@ describe('cache is not used initially', () => {
'a/b/c/d/e/.foorc.yml',
'a/b/c/d/e/.foorc.js',
'a/b/c/d/e/.foorc.cjs',
'a/b/c/d/e/.config/foorc',
'a/b/c/d/e/.config/foorc.json',
'a/b/c/d/e/.config/foorc.yaml',
'a/b/c/d/e/.config/foorc.yml',
'a/b/c/d/e/.config/foorc.js',
'a/b/c/d/e/.config/foorc.cjs',
'a/b/c/d/e/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
@@ -145,6 +151,12 @@ describe('cache is used when some directories in search are already visted', ()
'a/b/c/d/e/f/.foorc.yml',
'a/b/c/d/e/f/.foorc.js',
'a/b/c/d/e/f/.foorc.cjs',
'a/b/c/d/e/f/.config/foorc',
'a/b/c/d/e/f/.config/foorc.json',
'a/b/c/d/e/f/.config/foorc.yaml',
'a/b/c/d/e/f/.config/foorc.yml',
'a/b/c/d/e/f/.config/foorc.js',
'a/b/c/d/e/f/.config/foorc.cjs',
'a/b/c/d/e/f/foo.config.js',
'a/b/c/d/e/f/foo.config.cjs',
]);
@@ -229,6 +241,12 @@ describe('cache is not used in a new cosmiconfig instance', () => {
'a/b/c/d/e/.foorc.yml',
'a/b/c/d/e/.foorc.js',
'a/b/c/d/e/.foorc.cjs',
'a/b/c/d/e/.config/foorc',
'a/b/c/d/e/.config/foorc.json',
'a/b/c/d/e/.config/foorc.yaml',
'a/b/c/d/e/.config/foorc.yml',
'a/b/c/d/e/.config/foorc.js',
'a/b/c/d/e/.config/foorc.cjs',
'a/b/c/d/e/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
@@ -347,6 +365,12 @@ describe('clears directory cache on calling clearSearchCache', () => {
'a/b/c/d/e/.foorc.yml',
'a/b/c/d/e/.foorc.js',
'a/b/c/d/e/.foorc.cjs',
'a/b/c/d/e/.config/foorc',
'a/b/c/d/e/.config/foorc.json',
'a/b/c/d/e/.config/foorc.yaml',
'a/b/c/d/e/.config/foorc.yml',
'a/b/c/d/e/.config/foorc.js',
'a/b/c/d/e/.config/foorc.cjs',
'a/b/c/d/e/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
@@ -395,6 +419,12 @@ describe('clears directory cache on calling clearCaches', () => {
'a/b/c/d/e/.foorc.yml',
'a/b/c/d/e/.foorc.js',
'a/b/c/d/e/.foorc.cjs',
'a/b/c/d/e/.config/foorc',
'a/b/c/d/e/.config/foorc.json',
'a/b/c/d/e/.config/foorc.yaml',
'a/b/c/d/e/.config/foorc.yml',
'a/b/c/d/e/.config/foorc.js',
'a/b/c/d/e/.config/foorc.cjs',
'a/b/c/d/e/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
@@ -459,6 +489,12 @@ describe('with cache disabled, does not cache directory results', () => {
'a/b/c/d/e/.foorc.yml',
'a/b/c/d/e/.foorc.js',
'a/b/c/d/e/.foorc.cjs',
'a/b/c/d/e/.config/foorc',
'a/b/c/d/e/.config/foorc.json',
'a/b/c/d/e/.config/foorc.yaml',
'a/b/c/d/e/.config/foorc.yml',
'a/b/c/d/e/.config/foorc.js',
'a/b/c/d/e/.config/foorc.cjs',
'a/b/c/d/e/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
30 changes: 30 additions & 0 deletions test/failed-directories.test.ts
Original file line number Diff line number Diff line change
@@ -36,6 +36,12 @@ describe('gives up if it cannot find the file', () => {
'a/b/.foorc.yml',
'a/b/.foorc.js',
'a/b/.foorc.cjs',
'a/b/.config/foorc',
'a/b/.config/foorc.json',
'a/b/.config/foorc.yaml',
'a/b/.config/foorc.yml',
'a/b/.config/foorc.js',
'a/b/.config/foorc.cjs',
'a/b/foo.config.js',
'a/b/foo.config.cjs',
'a/package.json',
@@ -45,6 +51,12 @@ describe('gives up if it cannot find the file', () => {
'a/.foorc.yml',
'a/.foorc.js',
'a/.foorc.cjs',
'a/.config/foorc',
'a/.config/foorc.json',
'a/.config/foorc.yaml',
'a/.config/foorc.yml',
'a/.config/foorc.js',
'a/.config/foorc.cjs',
'a/foo.config.js',
'a/foo.config.cjs',
'package.json',
@@ -54,6 +66,12 @@ describe('gives up if it cannot find the file', () => {
'.foorc.yml',
'.foorc.js',
'.foorc.cjs',
'.config/foorc',
'.config/foorc.json',
'.config/foorc.yaml',
'.config/foorc.yml',
'.config/foorc.js',
'.config/foorc.cjs',
'foo.config.js',
'foo.config.cjs',
]);
@@ -92,6 +110,12 @@ describe('stops at stopDir and gives up', () => {
'a/b/.foorc.yml',
'a/b/.foorc.js',
'a/b/.foorc.cjs',
'a/b/.config/foorc',
'a/b/.config/foorc.json',
'a/b/.config/foorc.yaml',
'a/b/.config/foorc.yml',
'a/b/.config/foorc.js',
'a/b/.config/foorc.cjs',
'a/b/foo.config.js',
'a/b/foo.config.cjs',
'a/package.json',
@@ -101,6 +125,12 @@ describe('stops at stopDir and gives up', () => {
'a/.foorc.yml',
'a/.foorc.js',
'a/.foorc.cjs',
'a/.config/foorc',
'a/.config/foorc.json',
'a/.config/foorc.yaml',
'a/.config/foorc.yml',
'a/.config/foorc.js',
'a/.config/foorc.cjs',
'a/foo.config.js',
'a/foo.config.cjs',
]);
6 changes: 6 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -100,6 +100,12 @@ describe('cosmiconfig', () => {
`.${moduleName}rc.yml`,
`.${moduleName}rc.js`,
`.${moduleName}rc.cjs`,
`.config/${moduleName}rc`,
`.config/${moduleName}rc.json`,
`.config/${moduleName}rc.yaml`,
`.config/${moduleName}rc.yml`,
`.config/${moduleName}rc.js`,
`.config/${moduleName}rc.cjs`,
`${moduleName}.config.js`,
`${moduleName}.config.cjs`,
],
384 changes: 384 additions & 0 deletions test/successful-directories.test.ts

Large diffs are not rendered by default.