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: 6.0.0
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.0.0
Choose a head ref
  • 15 commits
  • 12 files changed
  • 4 contributors

Commits on Nov 2, 2019

  1. Fix typo

    David Clark committed Nov 2, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b185782 View commit details

Commits on Jan 19, 2020

  1. Upgrade remark-toc to fix TOC link bug (#230)

    David Clark authored Jan 19, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d94bd6c View commit details

Commits on Jul 12, 2020

  1. Fix TS complaint (#239)

    David Clark authored Jul 12, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9b30bde View commit details

Commits on Aug 1, 2020

  1. Copy the full SHA
    24702a0 View commit details
  2. Remove support for Node 8

    Add Node 14 to CI.
    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    af6d975 View commit details
  3. Update prod dependencies

    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    89c3d2e View commit details
  4. Update dev dependencies

    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4b12a72 View commit details
  5. Address linting problems

    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ba1d0e1 View commit details
  6. Readme Node version

    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    285289a View commit details
  7. Added cjs support (#238)

    Co-authored-by: Ricky Patel <rickyp@tesla.com>
    2 people authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f25f378 View commit details
  8. Prepare .cjs addition to searchPlaces

    David Clark authored and davidtheclark committed Aug 1, 2020
    Copy the full SHA
    1e6261c View commit details
  9. Fix typo

    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    965f6d0 View commit details
  10. Remove readme section about v5 docs

    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    abc031f View commit details
  11. Update Babel Node target

    David Clark authored and davidtheclark committed Aug 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    71289f8 View commit details
  12. 7.0.0

    David Clark committed Aug 1, 2020
    Copy the full SHA
    07e7637 View commit details
Showing with 170 additions and 67 deletions.
  1. +9 −4 .eslintrc.js
  2. +2 −2 .travis.yml
  3. +5 −0 CHANGELOG.md
  4. +13 −17 README.md
  5. +2 −2 appveyor.yml
  6. +30 −33 package.json
  7. +9 −5 src/index.ts
  8. +12 −0 test/caches.test.ts
  9. +11 −1 test/failed-directories.test.ts
  10. +7 −2 test/index.test.ts
  11. +69 −0 test/successful-directories.test.ts
  12. +1 −1 tsconfig.eslint.json
13 changes: 9 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,9 @@ module.exports = {
'eslint-config-davidtheclark-node',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
// This is making an annoying amount of unnecessary noise.
// If anybody would like to turn it back on, PR welcome.
// 'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
@@ -103,10 +105,13 @@ module.exports = {
* eslint-plugin-jest
*/
'jest/consistent-test-it': ['error', { fn: 'test' }],
'jest/no-empty-title': 'error',
'jest/valid-title': 'error',
'jest/no-test-callback': 'error',
'jest/prefer-todo': 'error',
'jest/require-tothrow-message': 'error',
'jest/require-to-throw-message': 'error',
// Many tests make assertions indirectly in a way the plugin
// does not understand.
'jest/expect-expect': 'off',
},
settings: {
node: {
@@ -127,7 +132,7 @@ module.exports = {
{
files: ['*.test.{js,ts}', '.*.test.{js,ts}'],
rules: {
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -5,13 +5,13 @@ cache: yarn
branches:
only:
- master
- v6
- v7
matrix:
include:
- node_js: '8'
- node_js: '10'
after_success: 'bash <(curl -s https://codecov.io/bash)'
- node_js: '12'
- node_js: '14'
install:
- yarn install --frozen-lockfile
script:
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 7.0.0

- **Breaking change:** Add `${moduleName}rc.cjs` and `${moduleName}.config.cjs` to the default `searchPlaces`, to support users of `"type": "module"` in recent versions of Node.
- **Breaking change:** Drop support for Node 8. Now requires Node 10+.

## 6.0.0

- **Breaking change:** The package now has named exports. See examples below.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,37 +12,31 @@ 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`, or `.js`.
- a `.config.js` CommonJS module
- an "rc file" with the extensions `.json`, `.yaml`, `.yml`, `.js`, or `.cjs`
- 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` file
- a `.myapprc.yaml`, `.myapprc.yml`, or `.myapprc.js` file
- a `myapp.config.js` file exporting a JS object
- a `.myapprc.json`, `.myapprc.yaml`, `.myapprc.yml`, `.myapprc.js`, or `.myapprc.cjs` file
- 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).

👀 **Looking for the v5 docs?**
v6 involves slight changes to Cosmiconfig's API, clarifying the difference between synchronous and asynchronous usage.
If you have trouble switching from v5 to v6, please file an issue.
If you are still using v5, those v5 docs are available [in the `5.x.x` tagged code](https://github.com/davidtheclark/cosmiconfig/tree/5.2.1).

## Table of contents

- [Installation](#installation)
- [Usage](#usage)
- [Result](#result)
- [Asynchronous API](#asynchronous-api)
- [cosmiconfig()](#cosmiconfig)
- [cosmiconfig()](#cosmiconfig-1)
- [explorer.search()](#explorersearch)
- [explorer.load()](#explorerload)
- [explorer.clearLoadCache()](#explorerclearloadcache)
- [explorer.clearSearchCache()](#explorerclearsearchcache)
- [explorer.clearCaches()](#explorerclearcaches)
- [Synchronsous API](#synchronsous-api)
- [Synchronous API](#synchronous-api)
- [cosmiconfigSync()](#cosmiconfigsync)
- [explorerSync.search()](#explorersyncsearch)
- [explorerSync.load()](#explorersyncload)
@@ -67,7 +61,7 @@ If you are still using v5, those v5 docs are available [in the `5.x.x` tagged co
npm install cosmiconfig
```

Tested in Node 8+.
Tested in Node 10+.

## Usage

@@ -148,9 +142,8 @@ Here's how your default [`search()`] will work:
- Starting from `process.cwd()` (or some other directory defined by the `searchFrom` argument to [`search()`]), look for configuration objects in the following places:
1. A `goldengrahams` property in a `package.json` file.
2. A `.goldengrahamsrc` file with JSON or YAML syntax.
3. A `.goldengrahamsrc.json` file.
4. A `.goldengrahamsrc.yaml`, `.goldengrahamsrc.yml`, or `.goldengrahamsrc.js` file.
5. A `goldengrahams.config.js` JS file exporting the object.
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.
- 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`]).
@@ -204,7 +197,7 @@ Clears the cache used in [`search()`].

Performs both [`clearLoadCache()`] and [`clearSearchCache()`].

## Synchronsous API
## Synchronous API

### cosmiconfigSync()

@@ -273,7 +266,9 @@ Each place is relative to the directory being searched, and the places are check
`.${moduleName}rc.yaml`,
`.${moduleName}rc.yml`,
`.${moduleName}rc.js`,
`.${moduleName}rc.cjs`,
`${moduleName}.config.js`,
`${moduleName}.config.cjs`,
]
```

@@ -348,6 +343,7 @@ const { defaultLoaders } = require('cosmiconfig');

console.log(Object.entries(defaultLoaders))
// [
// [ '.cjs', [Function: loadJs] ],
// [ '.js', [Function: loadJs] ],
// [ '.json', [Function: loadJson] ],
// [ '.yaml', [Function: loadYaml] ],
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
branches:
only:
- master
- v6
- v7

clone_depth: 5
version: '{build}'
@@ -14,9 +14,9 @@ cache:

environment:
matrix:
- nodejs_version: '8'
- nodejs_version: '10'
- nodejs_version: '12'
- nodejs_version: '14'

install:
# https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs
63 changes: 30 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmiconfig",
"version": "6.0.0",
"version": "7.0.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",
@@ -34,17 +34,14 @@
"lint-staged": {
"*.{js,ts}": [
"eslint --fix",
"prettier --write",
"git add"
"prettier --write"
],
"*.{json,yml,yaml}": [
"prettier --write",
"git add"
"prettier --write"
],
"*.md": [
"remark-preset-davidtheclark",
"remark-preset-davidtheclark --format",
"git add"
"remark-preset-davidtheclark --format"
]
},
"repository": {
@@ -101,7 +98,7 @@
"@babel/preset-env",
{
"targets": {
"node": "8.9"
"node": "10"
}
}
],
@@ -110,39 +107,39 @@
},
"dependencies": {
"@types/parse-json": "^4.0.0",
"import-fresh": "^3.1.0",
"import-fresh": "^3.2.1",
"parse-json": "^5.0.0",
"path-type": "^4.0.0",
"yaml": "^1.7.2"
"yaml": "^1.10.0"
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/preset-typescript": "^7.6.0",
"@types/jest": "^24.0.19",
"@types/node": "^12.11.5",
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^2.5.0",
"cross-env": "^6.0.3",
"@babel/cli": "^7.10.4",
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@types/jest": "^26.0.4",
"@types/node": "^14.0.22",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"@typescript-eslint/parser": "^3.6.0",
"cross-env": "^7.0.2",
"del": "^5.1.0",
"del-cli": "^3.0.0",
"eslint": "^6.5.1",
"del-cli": "^3.0.1",
"eslint": "^7.4.0",
"eslint-config-davidtheclark-node": "^0.2.2",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.20.0",
"eslint-plugin-node": "^10.0.0",
"husky": "^3.0.9",
"jest": "^24.9.0",
"lint-staged": "^9.4.2",
"make-dir": "^3.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.18.0",
"eslint-plugin-node": "^11.1.0",
"husky": "^4.2.5",
"jest": "^26.1.0",
"lint-staged": "^10.2.11",
"make-dir": "^3.1.0",
"parent-module": "^2.0.0",
"prettier": "^1.18.2",
"remark-preset-davidtheclark": "^0.10.0",
"typescript": "^3.6.4"
"prettier": "^2.0.5",
"remark-preset-davidtheclark": "^0.12.0",
"typescript": "^3.9.6"
},
"engines": {
"node": ">=8"
"node": ">=10"
}
}
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import os from 'os';
import { Explorer } from './Explorer';
import { ExplorerSync } from './ExplorerSync';
@@ -26,7 +27,7 @@ export type TransformSync = (
) => CosmiconfigResult;

interface OptionsBase {
packageProp?: string;
packageProp?: string | Array<string>;
searchPlaces?: Array<string>;
ignoreEmptySearchPlaces?: boolean;
stopDir?: string;
@@ -81,13 +82,18 @@ function cosmiconfigSync(moduleName: string, options: OptionsSync = {}) {

// do not allow mutation of default loaders. Make sure it is set inside options
const defaultLoaders = Object.freeze({
'.cjs': loaders.loadJs,
'.js': loaders.loadJs,
'.json': loaders.loadJson,
'.yaml': loaders.loadYaml,
'.yml': loaders.loadYaml,
noExt: loaders.loadYaml,
} as const);

const identity: TransformSync = function identity(x) {
return x;
};

function normalizeOptions(
moduleName: string,
options: OptionsSync,
@@ -109,7 +115,9 @@ function normalizeOptions(
`.${moduleName}rc.yaml`,
`.${moduleName}rc.yml`,
`.${moduleName}rc.js`,
`.${moduleName}rc.cjs`,
`${moduleName}.config.js`,
`${moduleName}.config.cjs`,
],
ignoreEmptySearchPlaces: true,
stopDir: os.homedir(),
@@ -130,8 +138,4 @@ function normalizeOptions(
return normalizedOptions;
}

const identity: TransformSync = function identity(x) {
return x;
};

export { cosmiconfig, cosmiconfigSync, defaultLoaders };
12 changes: 12 additions & 0 deletions test/caches.test.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,9 @@ describe('cache is not used initially', () => {
'a/b/c/d/e/.foorc.yaml',
'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/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
'a/b/c/d/.foorc',
]);
@@ -142,7 +144,9 @@ describe('cache is used when some directories in search are already visted', ()
'a/b/c/d/e/f/.foorc.yaml',
'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/foo.config.js',
'a/b/c/d/e/f/foo.config.cjs',
]);

expect(result).toEqual({
@@ -224,7 +228,9 @@ describe('cache is not used in a new cosmiconfig instance', () => {
'a/b/c/d/e/.foorc.yaml',
'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/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
'a/b/c/d/.foorc',
]);
@@ -340,7 +346,9 @@ describe('clears directory cache on calling clearSearchCache', () => {
'a/b/c/d/e/.foorc.yaml',
'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/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
'a/b/c/d/.foorc',
]);
@@ -386,7 +394,9 @@ describe('clears directory cache on calling clearCaches', () => {
'a/b/c/d/e/.foorc.yaml',
'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/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
'a/b/c/d/.foorc',
]);
@@ -448,7 +458,9 @@ describe('with cache disabled, does not cache directory results', () => {
'a/b/c/d/e/.foorc.yaml',
'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/foo.config.js',
'a/b/c/d/e/foo.config.cjs',
'a/b/c/d/package.json',
'a/b/c/d/.foorc',
]);
Loading