[EDIT] FILE: cosmiconfig.tar
README.md 0000755 00000046413 15074777051 0006053 0 ustar 00 # cosmiconfig [](https://travis-ci.org/davidtheclark/cosmiconfig) [](https://ci.appveyor.com/project/davidtheclark/cosmiconfig/branch/main) [](https://codecov.io/gh/davidtheclark/cosmiconfig) Cosmiconfig searches for and loads configuration for your program. It features smart defaults based on conventional expectations in the JavaScript ecosystem. But it's also flexible enough to search wherever you'd like to search, and load whatever you'd like to load. By default, Cosmiconfig will start where you tell it to start and search up the directory tree for the following: - 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). ## Table of contents - [Installation](#installation) - [Usage](#usage) - [Result](#result) - [Asynchronous API](#asynchronous-api) - [cosmiconfig()](#cosmiconfig-1) - [explorer.search()](#explorersearch) - [explorer.load()](#explorerload) - [explorer.clearLoadCache()](#explorerclearloadcache) - [explorer.clearSearchCache()](#explorerclearsearchcache) - [explorer.clearCaches()](#explorerclearcaches) - [Synchronous API](#synchronous-api) - [cosmiconfigSync()](#cosmiconfigsync) - [explorerSync.search()](#explorersyncsearch) - [explorerSync.load()](#explorersyncload) - [explorerSync.clearLoadCache()](#explorersyncclearloadcache) - [explorerSync.clearSearchCache()](#explorersyncclearsearchcache) - [explorerSync.clearCaches()](#explorersyncclearcaches) - [cosmiconfigOptions](#cosmiconfigoptions) - [searchPlaces](#searchplaces) - [loaders](#loaders) - [packageProp](#packageprop) - [stopDir](#stopdir) - [cache](#cache) - [transform](#transform) - [ignoreEmptySearchPlaces](#ignoreemptysearchplaces) - [Caching](#caching) - [Differences from rc](#differences-from-rc) - [Contributing & Development](#contributing--development) ## Installation ``` npm install cosmiconfig ``` Tested in Node 10+. ## Usage Create a Cosmiconfig explorer, then either `search` for or directly `load` a configuration file. ```js const { cosmiconfig, cosmiconfigSync } = require('cosmiconfig'); // ... const explorer = cosmiconfig(moduleName); // Search for a configuration by walking up directories. // See documentation for search, below. explorer.search() .then((result) => { // result.config is the parsed configuration object. // result.filepath is the path to the config file that was found. // result.isEmpty is true if there was nothing to parse in the config file. }) .catch((error) => { // Do something constructive. }); // Load a configuration directly when you know where it should be. // The result object is the same as for search. // See documentation for load, below. explorer.load(pathToConfig).then(..); // You can also search and load synchronously. const explorerSync = cosmiconfigSync(moduleName); const searchedFor = explorerSync.search(); const loaded = explorerSync.load(pathToConfig); ``` ## Result The result object you get from `search` or `load` has the following properties: - **config:** The parsed configuration object. `undefined` if the file is empty. - **filepath:** The path to the configuration file that was found. - **isEmpty:** `true` if the configuration file is empty. This property will not be present if the configuration file is not empty. ## Asynchronous API ### cosmiconfig() ```js const { cosmiconfig } = require('cosmiconfig'); const explorer = cosmiconfig(moduleName[, cosmiconfigOptions]) ``` Creates a cosmiconfig instance ("explorer") configured according to the arguments, and initializes its caches. #### moduleName Type: `string`. **Required.** Your module name. This is used to create the default [`searchPlaces`] and [`packageProp`]. If your [`searchPlaces`] value will include files, as it does by default (e.g. `${moduleName}rc`), your `moduleName` must consist of characters allowed in filenames. That means you should not copy scoped package names, such as `@my-org/my-package`, directly into `moduleName`. **[`cosmiconfigOptions`] are documented below.** You may not need them, and should first read about the functions you'll use. ### explorer.search() ```js explorer.search([searchFrom]).then(result => {..}) ``` Searches for a configuration file. Returns a Promise that resolves with a [result] or with `null`, if no configuration file is found. You can do the same thing synchronously with [`explorerSync.search()`]. Let's say your module name is `goldengrahams` so you initialized with `const explorer = cosmiconfig('goldengrahams');`. 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`, `.goldengrahamsrc.yaml`, `.goldengrahamsrc.yml`, `.goldengrahamsrc.js`, or `.goldengrahamsrc.cjs` file. 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`]). - If at any point a parsable configuration is found, the [`search()`] Promise resolves with its [result] \(or, with [`explorerSync.search()`], the [result] is returned). - If no configuration object is found, the [`search()`] Promise resolves with `null` (or, with [`explorerSync.search()`], `null` is returned). - If a configuration object is found *but is malformed* (causing a parsing error), the [`search()`] Promise rejects with that error (so you should `.catch()` it). (Or, with [`explorerSync.search()`], the error is thrown.) **If you know exactly where your configuration file should be, you can use [`load()`], instead.** **The search process is highly customizable.** Use the cosmiconfig options [`searchPlaces`] and [`loaders`] to precisely define where you want to look for configurations and how you want to load them. #### searchFrom Type: `string`. Default: `process.cwd()`. A filename. [`search()`] will start its search here. If the value is a directory, that's where the search starts. If it's a file, the search starts in that file's directory. ### explorer.load() ```js explorer.load(loadPath).then(result => {..}) ``` Loads a configuration file. Returns a Promise that resolves with a [result] or rejects with an error (if the file does not exist or cannot be loaded). Use `load` if you already know where the configuration file is and you just need to load it. ```js explorer.load('load/this/file.json'); // Tries to load load/this/file.json. ``` If you load a `package.json` file, the result will be derived from whatever property is specified as your [`packageProp`]. You can do the same thing synchronously with [`explorerSync.load()`]. ### explorer.clearLoadCache() Clears the cache used in [`load()`]. ### explorer.clearSearchCache() Clears the cache used in [`search()`]. ### explorer.clearCaches() Performs both [`clearLoadCache()`] and [`clearSearchCache()`]. ## Synchronous API ### cosmiconfigSync() ```js const { cosmiconfigSync } = require('cosmiconfig'); const explorerSync = cosmiconfigSync(moduleName[, cosmiconfigOptions]) ``` Creates a *synchronous* cosmiconfig instance ("explorerSync") configured according to the arguments, and initializes its caches. See [`cosmiconfig()`]. ### explorerSync.search() ```js const result = explorerSync.search([searchFrom]); ``` Synchronous version of [`explorer.search()`]. Returns a [result] or `null`. ### explorerSync.load() ```js const result = explorerSync.load(loadPath); ``` Synchronous version of [`explorer.load()`]. Returns a [result]. ### explorerSync.clearLoadCache() Clears the cache used in [`load()`]. ### explorerSync.clearSearchCache() Clears the cache used in [`search()`]. ### explorerSync.clearCaches() Performs both [`clearLoadCache()`] and [`clearSearchCache()`]. ## cosmiconfigOptions Type: `Object`. Possible options are documented below. ### searchPlaces Type: `Array<string>`. Default: See below. An array of places that [`search()`] will check in each directory as it moves up the directory tree. Each place is relative to the directory being searched, and the places are checked in the specified order. **Default `searchPlaces`:** ```js [ 'package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${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`, ] ``` Create your own array to search more, fewer, or altogether different places. Every item in `searchPlaces` needs to have a loader in [`loaders`] that corresponds to its extension. (Common extensions are covered by default loaders.) Read more about [`loaders`] below. `package.json` is a special value: When it is included in `searchPlaces`, Cosmiconfig will always parse it as JSON and load a property within it, not the whole file. That property is defined with the [`packageProp`] option, and defaults to your module name. Examples, with a module named `porgy`: ```js // Disallow extensions on rc files: [ 'package.json', '.porgyrc', 'porgy.config.js' ] // ESLint searches for configuration in these places: [ '.eslintrc.js', '.eslintrc.yaml', '.eslintrc.yml', '.eslintrc.json', '.eslintrc', 'package.json' ] // Babel looks in fewer places: [ 'package.json', '.babelrc' ] // Maybe you want to look for a wide variety of JS flavors: [ 'porgy.config.js', 'porgy.config.mjs', 'porgy.config.ts', 'porgy.config.coffee' ] // ^^ You will need to designate custom loaders to tell // Cosmiconfig how to handle these special JS flavors. // Look within a .config/ subdirectory of every searched directory: [ 'package.json', '.porgyrc', '.config/.porgyrc', '.porgyrc.json', '.config/.porgyrc.json' ] ``` ### loaders Type: `Object`. Default: See below. An object that maps extensions to the loader functions responsible for loading and parsing files with those extensions. Cosmiconfig exposes its default loaders on a named export `defaultLoaders`. **Default `loaders`:** ```js const { defaultLoaders } = require('cosmiconfig'); console.log(Object.entries(defaultLoaders)) // [ // [ '.cjs', [Function: loadJs] ], // [ '.js', [Function: loadJs] ], // [ '.json', [Function: loadJson] ], // [ '.yaml', [Function: loadYaml] ], // [ '.yml', [Function: loadYaml] ], // [ 'noExt', [Function: loadYaml] ] // ] ``` (YAML is a superset of JSON; which means YAML parsers can parse JSON; which is how extensionless files can be either YAML *or* JSON with only one parser.) **If you provide a `loaders` object, your object will be *merged* with the defaults.** So you can override one or two without having to override them all. **Keys in `loaders`** are extensions (starting with a period), or `noExt` to specify the loader for files *without* extensions, like `.myapprc`. **Values in `loaders`** are a loader function (described below) whose values are loader functions. **The most common use case for custom loaders value is to load extensionless `rc` files as strict JSON**, instead of JSON *or* YAML (the default). To accomplish that, provide the following `loaders` value: ```js { noExt: defaultLoaders['.json'] } ``` If you want to load files that are not handled by the loader functions Cosmiconfig exposes, you can write a custom loader function or use one from NPM if it exists. **Third-party loaders:** - [cosmiconfig-typescript-loader](https://github.com/codex-/cosmiconfig-typescript-loader) **Use cases for custom loader function:** - Allow configuration syntaxes that aren't handled by Cosmiconfig's defaults, like JSON5, INI, or XML. - Allow ES2015 modules from `.mjs` configuration files. - Parse JS files with Babel before deriving the configuration. **Custom loader functions** have the following signature: ```js // Sync (filepath: string, content: string) => Object | null // Async (filepath: string, content: string) => Object | null | Promise<Object | null> ``` Cosmiconfig reads the file when it checks whether the file exists, so it will provide you with both the file's path and its content. Do whatever you need to, and return either a configuration object or `null` (or, for async-only loaders, a Promise that resolves with one of those). `null` indicates that no real configuration was found and the search should continue. A few things to note: - If you use a custom loader, be aware of whether it's sync or async: you cannot use async customer loaders with the sync API ([`cosmiconfigSync()`]). - **Special JS syntax can also be handled by using a `require` hook**, because `defaultLoaders['.js']` just uses `require`. Whether you use custom loaders or a `require` hook is up to you. Examples: ```js // Allow JSON5 syntax: { '.json': json5Loader } // Allow a special configuration syntax of your own creation: { '.special': specialLoader } // Allow many flavors of JS, using custom loaders: { '.mjs': esmLoader, '.ts': typeScriptLoader, '.coffee': coffeeScriptLoader } // Allow many flavors of JS but rely on require hooks: { '.mjs': defaultLoaders['.js'], '.ts': defaultLoaders['.js'], '.coffee': defaultLoaders['.js'] } ``` ### packageProp Type: `string | Array<string>`. Default: `` `${moduleName}` ``. Name of the property in `package.json` to look for. Use a period-delimited string or an array of strings to describe a path to nested properties. For example, the value `'configs.myPackage'` or `['configs', 'myPackage']` will get you the `"myPackage"` value in a `package.json` like this: ```json { "configs": { "myPackage": {..} } } ``` If nested property names within the path include periods, you need to use an array of strings. For example, the value `['configs', 'foo.bar', 'baz']` will get you the `"baz"` value in a `package.json` like this: ```json { "configs": { "foo.bar": { "baz": {..} } } } ``` If a string includes period but corresponds to a top-level property name, it will not be interpreted as a period-delimited path. For example, the value `'one.two'` will get you the `"three"` value in a `package.json` like this: ```json { "one.two": "three", "one": { "two": "four" } } ``` ### stopDir Type: `string`. Default: Absolute path to your home directory. Directory where the search will stop. ### cache Type: `boolean`. Default: `true`. If `false`, no caches will be used. Read more about ["Caching"](#caching) below. ### transform Type: `(Result) => Promise<Result> | Result`. A function that transforms the parsed configuration. Receives the [result]. If using [`search()`] or [`load()`] \(which are async), the transform function can return the transformed result or return a Promise that resolves with the transformed result. If using `cosmiconfigSync`, [`search()`] or [`load()`], the function must be synchronous and return the transformed result. The reason you might use this option — instead of simply applying your transform function some other way — is that *the transformed result will be cached*. If your transformation involves additional filesystem I/O or other potentially slow processing, you can use this option to avoid repeating those steps every time a given configuration is searched or loaded. ### ignoreEmptySearchPlaces Type: `boolean`. Default: `true`. By default, if [`search()`] encounters an empty file (containing nothing but whitespace) in one of the [`searchPlaces`], it will ignore the empty file and move on. If you'd like to load empty configuration files, instead, set this option to `false`. Why might you want to load empty configuration files? If you want to throw an error, or if an empty configuration file means something to your program. ## Caching As of v2, cosmiconfig uses caching to reduce the need for repetitious reading of the filesystem or expensive transforms. Every new cosmiconfig instance (created with `cosmiconfig()`) has its own caches. To avoid or work around caching, you can do the following: - Set the `cosmiconfig` option [`cache`] to `false`. - Use the cache-clearing methods [`clearLoadCache()`], [`clearSearchCache()`], and [`clearCaches()`]. - Create separate instances of cosmiconfig (separate "explorers"). ## Differences from [rc](https://github.com/dominictarr/rc) [rc](https://github.com/dominictarr/rc) serves its focused purpose well. cosmiconfig differs in a few key ways — making it more useful for some projects, less useful for others: - Looks for configuration in some different places: in a `package.json` property, an rc file, a `.config.js` file, and rc files with extensions. - Built-in support for JSON, YAML, and CommonJS formats. - Stops at the first configuration found, instead of finding all that can be found up the directory tree and merging them automatically. - Options. - Asynchronous by default (though can be run synchronously). ## Contributing & Development Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. And please do participate! [result]: #result [`load()`]: #explorerload [`search()`]: #explorersearch [`clearloadcache()`]: #explorerclearloadcache [`clearsearchcache()`]: #explorerclearsearchcache [`cosmiconfig()`]: #cosmiconfig [`cosmiconfigSync()`]: #cosmiconfigsync [`clearcaches()`]: #explorerclearcaches [`packageprop`]: #packageprop [`cache`]: #cache [`stopdir`]: #stopdir [`searchplaces`]: #searchplaces [`loaders`]: #loaders [`cosmiconfigoptions`]: #cosmiconfigoptions [`explorerSync.search()`]: #explorersyncsearch [`explorerSync.load()`]: #explorersyncload [`explorer.search()`]: #explorersearch [`explorer.load()`]: #explorerload LICENSE 0000755 00000002067 15074777051 0005576 0 ustar 00 The MIT License (MIT) Copyright (c) 2015 David Clark Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package.json 0000755 00000007706 15074777051 0007064 0 ustar 00 { "name": "cosmiconfig", "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", "files": [ "dist" ], "scripts": { "clean": "del-cli --dot=true \"./dist/**/*\"", "build": "npm run clean && npm run build:compile && npm run build:types", "build:compile": "cross-env NODE_ENV=production babel src -d dist --verbose --extensions .js,.ts --ignore \"**/**/*.test.js\",\"**/**/*.test.ts\" --source-maps", "build:types": "cross-env NODE_ENV=production tsc --project tsconfig.types.json", "dev": "npm run clean && npm run build:compile -- --watch", "lint": "eslint --ext .js,.ts . && npm run lint:md", "lint:fix": "eslint --ext .js,.ts . --fix", "lint:md": "remark-preset-davidtheclark", "format": "prettier \"**/*.{js,ts,json,yml,yaml}\" --write", "format:md": "remark-preset-davidtheclark --format", "format:check": "prettier \"**/*.{js,ts,json,yml,yaml}\" --check", "typescript": "tsc", "test": "jest --coverage", "test:watch": "jest --watch", "check:all": "npm run test && npm run typescript && npm run lint && npm run format:check", "prepublishOnly": "npm run check:all && npm run build" }, "husky": { "hooks": { "pre-commit": "lint-staged && npm run typescript && npm run test", "pre-push": "npm run check:all" } }, "lint-staged": { "*.{js,ts}": [ "eslint --fix", "prettier --write" ], "*.{json,yml,yaml}": [ "prettier --write" ], "*.md": [ "remark-preset-davidtheclark", "remark-preset-davidtheclark --format" ] }, "repository": { "type": "git", "url": "git+https://github.com/davidtheclark/cosmiconfig.git" }, "keywords": [ "load", "configuration", "config" ], "author": "David Clark <david.dave.clark@gmail.com>", "contributors": [ "Bogdan Chadkin <trysound@yandex.ru>", "Suhas Karanth <sudo.suhas@gmail.com>" ], "license": "MIT", "bugs": { "url": "https://github.com/davidtheclark/cosmiconfig/issues" }, "homepage": "https://github.com/davidtheclark/cosmiconfig#readme", "prettier": { "trailingComma": "all", "arrowParens": "always", "singleQuote": true, "printWidth": 80, "tabWidth": 2 }, "jest": { "testEnvironment": "node", "collectCoverageFrom": [ "src/**/*.{js,ts}" ], "coverageReporters": [ "text", "html", "lcov" ], "coverageThreshold": { "global": { "branches": 100, "functions": 100, "lines": 100, "statements": 100 } }, "resetModules": true, "resetMocks": true, "restoreMocks": true }, "babel": { "presets": [ [ "@babel/preset-env", { "targets": { "node": "10" } } ], "@babel/preset-typescript" ] }, "dependencies": { "@types/parse-json": "^4.0.0", "import-fresh": "^3.2.1", "parse-json": "^5.0.0", "path-type": "^4.0.0", "yaml": "^1.10.0" }, "devDependencies": { "@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.1", "eslint": "^7.4.0", "eslint-config-davidtheclark-node": "^0.2.2", "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": "^2.0.5", "remark-preset-davidtheclark": "^0.12.0", "typescript": "^3.9.6" }, "engines": { "node": ">=10" } } dist/types.js 0000755 00000000161 15074777051 0007227 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); //# sourceMappingURL=types.js.map dist/loaders.js.map 0000755 00000005267 15074777051 0010304 0 ustar 00 {"version":3,"sources":["../src/loaders.ts"],"names":["importFresh","loadJs","filepath","undefined","require","result","parseJson","loadJson","content","error","message","yaml","loadYaml","parse","prettyErrors","loaders"],"mappings":";;;;;;;AAAA;AAQA,IAAIA,WAAJ;;AACA,MAAMC,MAAkB,GAAG,SAASA,MAAT,CAAgBC,QAAhB,EAA0B;AACnD,MAAIF,WAAW,KAAKG,SAApB,EAA+B;AAC7BH,IAAAA,WAAW,GAAGI,OAAO,CAAC,cAAD,CAArB;AACD;;AAED,QAAMC,MAAM,GAAGL,WAAW,CAACE,QAAD,CAA1B;AACA,SAAOG,MAAP;AACD,CAPD;;AASA,IAAIC,SAAJ;;AACA,MAAMC,QAAoB,GAAG,SAASA,QAAT,CAAkBL,QAAlB,EAA4BM,OAA5B,EAAqC;AAChE,MAAIF,SAAS,KAAKH,SAAlB,EAA6B;AAC3BG,IAAAA,SAAS,GAAGF,OAAO,CAAC,YAAD,CAAnB;AACD;;AAED,MAAI;AACF,UAAMC,MAAM,GAAGC,SAAS,CAACE,OAAD,CAAxB;AACA,WAAOH,MAAP;AACD,GAHD,CAGE,OAAOI,KAAP,EAAc;AACdA,IAAAA,KAAK,CAACC,OAAN,GAAiB,iBAAgBR,QAAS,MAAKO,KAAK,CAACC,OAAQ,EAA7D;AACA,UAAMD,KAAN;AACD;AACF,CAZD;;AAcA,IAAIE,IAAJ;;AACA,MAAMC,QAAoB,GAAG,SAASA,QAAT,CAAkBV,QAAlB,EAA4BM,OAA5B,EAAqC;AAChE,MAAIG,IAAI,KAAKR,SAAb,EAAwB;AACtBQ,IAAAA,IAAI,GAAGP,OAAO,CAAC,MAAD,CAAd;AACD;;AAED,MAAI;AACF,UAAMC,MAAM,GAAGM,IAAI,CAACE,KAAL,CAAWL,OAAX,EAAoB;AAAEM,MAAAA,YAAY,EAAE;AAAhB,KAApB,CAAf;AACA,WAAOT,MAAP;AACD,GAHD,CAGE,OAAOI,KAAP,EAAc;AACdA,IAAAA,KAAK,CAACC,OAAN,GAAiB,iBAAgBR,QAAS,MAAKO,KAAK,CAACC,OAAQ,EAA7D;AACA,UAAMD,KAAN;AACD;AACF,CAZD;;AAcA,MAAMM,OAAoB,GAAG;AAAEd,EAAAA,MAAF;AAAUM,EAAAA,QAAV;AAAoBK,EAAAA;AAApB,CAA7B","sourcesContent":["/* eslint-disable @typescript-eslint/no-require-imports */\n\nimport parseJsonType from 'parse-json';\nimport yamlType from 'yaml';\nimport importFreshType from 'import-fresh';\nimport { LoaderSync } from './index';\nimport { LoadersSync } from './types';\n\nlet importFresh: typeof importFreshType;\nconst loadJs: LoaderSync = function loadJs(filepath) {\n if (importFresh === undefined) {\n importFresh = require('import-fresh');\n }\n\n const result = importFresh(filepath);\n return result;\n};\n\nlet parseJson: typeof parseJsonType;\nconst loadJson: LoaderSync = function loadJson(filepath, content) {\n if (parseJson === undefined) {\n parseJson = require('parse-json');\n }\n\n try {\n const result = parseJson(content);\n return result;\n } catch (error) {\n error.message = `JSON Error in ${filepath}:\\n${error.message}`;\n throw error;\n }\n};\n\nlet yaml: typeof yamlType;\nconst loadYaml: LoaderSync = function loadYaml(filepath, content) {\n if (yaml === undefined) {\n yaml = require('yaml');\n }\n\n try {\n const result = yaml.parse(content, { prettyErrors: true });\n return result;\n } catch (error) {\n error.message = `YAML Error in ${filepath}:\\n${error.message}`;\n throw error;\n }\n};\n\nconst loaders: LoadersSync = { loadJs, loadJson, loadYaml };\n\nexport { loaders };\n"],"file":"loaders.js"} dist/loaders.d.ts.map 0000755 00000000330 15074777051 0010522 0 ustar 00 {"version":3,"file":"loaders.d.ts","sourceRoot":"","sources":["../src/loaders.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA0CtC,QAAA,MAAM,OAAO,EAAE,WAA4C,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,CAAC"} dist/getDirectory.js.map 0000755 00000002447 15074777051 0011314 0 ustar 00 {"version":3,"sources":["../src/getDirectory.ts"],"names":["getDirectory","filepath","filePathIsDirectory","directory","path","dirname","getDirectorySync"],"mappings":";;;;;;;;AAAA;;AACA;;;;AAEA,eAAeA,YAAf,CAA4BC,QAA5B,EAA+D;AAC7D,QAAMC,mBAAmB,GAAG,MAAM,2BAAYD,QAAZ,CAAlC;;AAEA,MAAIC,mBAAmB,KAAK,IAA5B,EAAkC;AAChC,WAAOD,QAAP;AACD;;AAED,QAAME,SAAS,GAAGC,cAAKC,OAAL,CAAaJ,QAAb,CAAlB;;AAEA,SAAOE,SAAP;AACD;;AAED,SAASG,gBAAT,CAA0BL,QAA1B,EAAoD;AAClD,QAAMC,mBAAmB,GAAG,+BAAgBD,QAAhB,CAA5B;;AAEA,MAAIC,mBAAmB,KAAK,IAA5B,EAAkC;AAChC,WAAOD,QAAP;AACD;;AAED,QAAME,SAAS,GAAGC,cAAKC,OAAL,CAAaJ,QAAb,CAAlB;;AAEA,SAAOE,SAAP;AACD","sourcesContent":["import path from 'path';\nimport { isDirectory, isDirectorySync } from 'path-type';\n\nasync function getDirectory(filepath: string): Promise<string> {\n const filePathIsDirectory = await isDirectory(filepath);\n\n if (filePathIsDirectory === true) {\n return filepath;\n }\n\n const directory = path.dirname(filepath);\n\n return directory;\n}\n\nfunction getDirectorySync(filepath: string): string {\n const filePathIsDirectory = isDirectorySync(filepath);\n\n if (filePathIsDirectory === true) {\n return filepath;\n }\n\n const directory = path.dirname(filepath);\n\n return directory;\n}\n\nexport { getDirectory, getDirectorySync };\n"],"file":"getDirectory.js"} dist/getDirectory.d.ts 0000755 00000000324 15074777051 0010764 0 ustar 00 declare function getDirectory(filepath: string): Promise<string>; declare function getDirectorySync(filepath: string): string; export { getDirectory, getDirectorySync }; //# sourceMappingURL=getDirectory.d.ts.map dist/Explorer.d.ts.map 0000755 00000000740 15074777051 0010676 0 ustar 00 {"version":3,"file":"Explorer.d.ts","sourceRoot":"","sources":["../src/Explorer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAqB,MAAM,SAAS,CAAC;AAEhF,cAAM,QAAS,SAAQ,YAAY,CAAC,eAAe,CAAC;gBAC/B,OAAO,EAAE,eAAe;IAI9B,MAAM,CACjB,UAAU,GAAE,MAAsB,GACjC,OAAO,CAAC,iBAAiB,CAAC;YAOf,mBAAmB;YAuBnB,eAAe;YAaf,eAAe;YAYf,eAAe;YAef,uBAAuB;IAUxB,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAyBhE;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"} dist/Explorer.d.ts 0000755 00000001046 15074777051 0010122 0 ustar 00 import { ExplorerBase } from './ExplorerBase'; import { CosmiconfigResult, ExplorerOptions } from './types'; declare class Explorer extends ExplorerBase<ExplorerOptions> { constructor(options: ExplorerOptions); search(searchFrom?: string): Promise<CosmiconfigResult>; private searchFromDirectory; private searchDirectory; private loadSearchPlace; private loadFileContent; private createCosmiconfigResult; load(filepath: string): Promise<CosmiconfigResult>; } export { Explorer }; //# sourceMappingURL=Explorer.d.ts.map dist/loaders.d.ts 0000755 00000000204 15074777051 0007746 0 ustar 00 import { LoadersSync } from './types'; declare const loaders: LoadersSync; export { loaders }; //# sourceMappingURL=loaders.d.ts.map dist/getDirectory.d.ts.map 0000755 00000000430 15074777051 0011536 0 ustar 00 {"version":3,"file":"getDirectory.d.ts","sourceRoot":"","sources":["../src/getDirectory.ts"],"names":[],"mappings":"AAGA,iBAAe,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU7D;AAED,iBAAS,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAUlD;AAED,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC"} dist/readFile.d.ts 0000755 00000000447 15074777051 0010041 0 ustar 00 interface Options { throwNotFound?: boolean; } declare function readFile(filepath: string, options?: Options): Promise<string | null>; declare function readFileSync(filepath: string, options?: Options): string | null; export { readFile, readFileSync }; //# sourceMappingURL=readFile.d.ts.map dist/readFile.js 0000755 00000002447 15074777051 0007607 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readFile = readFile; exports.readFileSync = readFileSync; var _fs = _interopRequireDefault(require("fs")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } async function fsReadFileAsync(pathname, encoding) { return new Promise((resolve, reject) => { _fs.default.readFile(pathname, encoding, (error, contents) => { if (error) { reject(error); return; } resolve(contents); }); }); } async function readFile(filepath, options = {}) { const throwNotFound = options.throwNotFound === true; try { const content = await fsReadFileAsync(filepath, 'utf8'); return content; } catch (error) { if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) { return null; } throw error; } } function readFileSync(filepath, options = {}) { const throwNotFound = options.throwNotFound === true; try { const content = _fs.default.readFileSync(filepath, 'utf8'); return content; } catch (error) { if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) { return null; } throw error; } } //# sourceMappingURL=readFile.js.map dist/index.d.ts.map 0000755 00000002270 15074777051 0010205 0 ustar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EAAE,OAAO,GAAE,WAAgB;;;;;;EAerE;AAGD,QAAA,MAAM,cAAc;;;;;;;EAOT,CAAC;AAwDZ,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC"} dist/ExplorerSync.d.ts.map 0000755 00000001014 15074777051 0011526 0 ustar 00 {"version":3,"file":"ExplorerSync.d.ts","sourceRoot":"","sources":["../src/ExplorerSync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EAEpB,MAAM,SAAS,CAAC;AAEjB,cAAM,YAAa,SAAQ,YAAY,CAAC,mBAAmB,CAAC;gBACvC,OAAO,EAAE,mBAAmB;IAIxC,UAAU,CAAC,UAAU,GAAE,MAAsB,GAAG,iBAAiB;IAOxE,OAAO,CAAC,uBAAuB;IAuB/B,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,2BAA2B;IAU5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB;CAsBrD;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"} dist/types.js.map 0000755 00000000131 15074777051 0010000 0 ustar 00 {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"} dist/Explorer.js 0000755 00000006127 15074777051 0007673 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Explorer = void 0; var _path = _interopRequireDefault(require("path")); var _ExplorerBase = require("./ExplorerBase"); var _readFile = require("./readFile"); var _cacheWrapper = require("./cacheWrapper"); var _getDirectory = require("./getDirectory"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class Explorer extends _ExplorerBase.ExplorerBase { constructor(options) { super(options); } async search(searchFrom = process.cwd()) { const startDirectory = await (0, _getDirectory.getDirectory)(searchFrom); const result = await this.searchFromDirectory(startDirectory); return result; } async searchFromDirectory(dir) { const absoluteDir = _path.default.resolve(process.cwd(), dir); const run = async () => { const result = await this.searchDirectory(absoluteDir); const nextDir = this.nextDirectoryToSearch(absoluteDir, result); if (nextDir) { return this.searchFromDirectory(nextDir); } const transformResult = await this.config.transform(result); return transformResult; }; if (this.searchCache) { return (0, _cacheWrapper.cacheWrapper)(this.searchCache, absoluteDir, run); } return run(); } async searchDirectory(dir) { for await (const place of this.config.searchPlaces) { const placeResult = await this.loadSearchPlace(dir, place); if (this.shouldSearchStopWithResult(placeResult) === true) { return placeResult; } } // config not found return null; } async loadSearchPlace(dir, place) { const filepath = _path.default.join(dir, place); const fileContents = await (0, _readFile.readFile)(filepath); const result = await this.createCosmiconfigResult(filepath, fileContents); return result; } async loadFileContent(filepath, content) { if (content === null) { return null; } if (content.trim() === '') { return undefined; } const loader = this.getLoaderEntryForFile(filepath); const loaderResult = await loader(filepath, content); return loaderResult; } async createCosmiconfigResult(filepath, content) { const fileContent = await this.loadFileContent(filepath, content); const result = this.loadedContentToCosmiconfigResult(filepath, fileContent); return result; } async load(filepath) { this.validateFilePath(filepath); const absoluteFilePath = _path.default.resolve(process.cwd(), filepath); const runLoad = async () => { const fileContents = await (0, _readFile.readFile)(absoluteFilePath, { throwNotFound: true }); const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents); const transformResult = await this.config.transform(result); return transformResult; }; if (this.loadCache) { return (0, _cacheWrapper.cacheWrapper)(this.loadCache, absoluteFilePath, runLoad); } return runLoad(); } } exports.Explorer = Explorer; //# sourceMappingURL=Explorer.js.map dist/ExplorerSync.d.ts 0000755 00000001110 15074777051 0010747 0 ustar 00 import { ExplorerBase } from './ExplorerBase'; import { CosmiconfigResult, ExplorerOptionsSync } from './types'; declare class ExplorerSync extends ExplorerBase<ExplorerOptionsSync> { constructor(options: ExplorerOptionsSync); searchSync(searchFrom?: string): CosmiconfigResult; private searchFromDirectorySync; private searchDirectorySync; private loadSearchPlaceSync; private loadFileContentSync; private createCosmiconfigResultSync; loadSync(filepath: string): CosmiconfigResult; } export { ExplorerSync }; //# sourceMappingURL=ExplorerSync.d.ts.map dist/index.js.map 0000755 00000015577 15074777051 0007767 0 ustar 00 {"version":3,"sources":["../src/index.ts"],"names":["cosmiconfig","moduleName","options","normalizedOptions","normalizeOptions","explorer","Explorer","search","bind","load","clearLoadCache","clearSearchCache","clearCaches","cosmiconfigSync","explorerSync","ExplorerSync","searchSync","loadSync","defaultLoaders","Object","freeze","loaders","loadJs","loadJson","loadYaml","noExt","identity","x","defaults","packageProp","searchPlaces","ignoreEmptySearchPlaces","stopDir","os","homedir","cache","transform"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AALA;AA8CA;AACA,SAASA,WAAT,CAAqBC,UAArB,EAAyCC,OAAgB,GAAG,EAA5D,EAAgE;AAC9D,QAAMC,iBAAkC,GAAGC,gBAAgB,CACzDH,UADyD,EAEzDC,OAFyD,CAA3D;AAKA,QAAMG,QAAQ,GAAG,IAAIC,kBAAJ,CAAaH,iBAAb,CAAjB;AAEA,SAAO;AACLI,IAAAA,MAAM,EAAEF,QAAQ,CAACE,MAAT,CAAgBC,IAAhB,CAAqBH,QAArB,CADH;AAELI,IAAAA,IAAI,EAAEJ,QAAQ,CAACI,IAAT,CAAcD,IAAd,CAAmBH,QAAnB,CAFD;AAGLK,IAAAA,cAAc,EAAEL,QAAQ,CAACK,cAAT,CAAwBF,IAAxB,CAA6BH,QAA7B,CAHX;AAILM,IAAAA,gBAAgB,EAAEN,QAAQ,CAACM,gBAAT,CAA0BH,IAA1B,CAA+BH,QAA/B,CAJb;AAKLO,IAAAA,WAAW,EAAEP,QAAQ,CAACO,WAAT,CAAqBJ,IAArB,CAA0BH,QAA1B;AALR,GAAP;AAOD,C,CAED;;;AACA,SAASQ,eAAT,CAAyBZ,UAAzB,EAA6CC,OAAoB,GAAG,EAApE,EAAwE;AACtE,QAAMC,iBAAsC,GAAGC,gBAAgB,CAC7DH,UAD6D,EAE7DC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AAUA,UAAW,SAVV,EAWX,WAAUA,UAAW,QAXV,EAYX,WAAUA,UAAW,OAZV,EAaX,WAAUA,UAAW,QAbV,EAcX,GAAEA,UAAW,YAdF,EAeX,GAAEA,UAAW,aAfF,CAFwC;AAmBtD8B,IAAAA,uBAAuB,EAAE,IAnB6B;AAoBtDC,IAAAA,OAAO,EAAEC,YAAGC,OAAH,EApB6C;AAqBtDC,IAAAA,KAAK,EAAE,IArB+C;AAsBtDC,IAAAA,SAAS,EAAEV,QAtB2C;AAuBtDL,IAAAA,OAAO,EAAEH;AAvB6C,GAAxD;AA0BA,QAAMf,iBAAwD,GAAG,EAC/D,GAAGyB,QAD4D;AAE/D,OAAG1B,OAF4D;AAG/DmB,IAAAA,OAAO,EAAE,EACP,GAAGO,QAAQ,CAACP,OADL;AAEP,SAAGnB,OAAO,CAACmB;AAFJ;AAHsD,GAAjE;AASA,SAAOlB,iBAAP;AACD","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport os from 'os';\nimport { Explorer } from './Explorer';\nimport { ExplorerSync } from './ExplorerSync';\nimport { loaders } from './loaders';\nimport {\n Config,\n CosmiconfigResult,\n ExplorerOptions,\n ExplorerOptionsSync,\n Loaders,\n LoadersSync,\n} from './types';\n\ntype LoaderResult = Config | null;\nexport type Loader =\n | ((filepath: string, content: string) => Promise<LoaderResult>)\n | LoaderSync;\nexport type LoaderSync = (filepath: string, content: string) => LoaderResult;\n\nexport type Transform =\n | ((CosmiconfigResult: CosmiconfigResult) => Promise<CosmiconfigResult>)\n | TransformSync;\n\nexport type TransformSync = (\n CosmiconfigResult: CosmiconfigResult,\n) => CosmiconfigResult;\n\ninterface OptionsBase {\n packageProp?: string | Array<string>;\n searchPlaces?: Array<string>;\n ignoreEmptySearchPlaces?: boolean;\n stopDir?: string;\n cache?: boolean;\n}\n\nexport interface Options extends OptionsBase {\n loaders?: Loaders;\n transform?: Transform;\n}\n\nexport interface OptionsSync extends OptionsBase {\n loaders?: LoadersSync;\n transform?: TransformSync;\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction cosmiconfig(moduleName: string, options: Options = {}) {\n const normalizedOptions: ExplorerOptions = normalizeOptions(\n moduleName,\n options,\n );\n\n const explorer = new Explorer(normalizedOptions);\n\n return {\n search: explorer.search.bind(explorer),\n load: explorer.load.bind(explorer),\n clearLoadCache: explorer.clearLoadCache.bind(explorer),\n clearSearchCache: explorer.clearSearchCache.bind(explorer),\n clearCaches: explorer.clearCaches.bind(explorer),\n } as const;\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction cosmiconfigSync(moduleName: string, options: OptionsSync = {}) {\n const normalizedOptions: ExplorerOptionsSync = normalizeOptions(\n moduleName,\n options,\n );\n\n const explorerSync = new ExplorerSync(normalizedOptions);\n\n return {\n search: explorerSync.searchSync.bind(explorerSync),\n load: explorerSync.loadSync.bind(explorerSync),\n clearLoadCache: explorerSync.clearLoadCache.bind(explorerSync),\n clearSearchCache: explorerSync.clearSearchCache.bind(explorerSync),\n clearCaches: explorerSync.clearCaches.bind(explorerSync),\n } as const;\n}\n\n// do not allow mutation of default loaders. Make sure it is set inside options\nconst defaultLoaders = Object.freeze({\n '.cjs': loaders.loadJs,\n '.js': loaders.loadJs,\n '.json': loaders.loadJson,\n '.yaml': loaders.loadYaml,\n '.yml': loaders.loadYaml,\n noExt: loaders.loadYaml,\n} as const);\n\nconst identity: TransformSync = function identity(x) {\n return x;\n};\n\nfunction normalizeOptions(\n moduleName: string,\n options: OptionsSync,\n): ExplorerOptionsSync;\nfunction normalizeOptions(\n moduleName: string,\n options: Options,\n): ExplorerOptions;\nfunction normalizeOptions(\n moduleName: string,\n options: Options | OptionsSync,\n): ExplorerOptions | ExplorerOptionsSync {\n const defaults: ExplorerOptions | ExplorerOptionsSync = {\n packageProp: moduleName,\n searchPlaces: [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.cjs`,\n `.config/${moduleName}rc`,\n `.config/${moduleName}rc.json`,\n `.config/${moduleName}rc.yaml`,\n `.config/${moduleName}rc.yml`,\n `.config/${moduleName}rc.js`,\n `.config/${moduleName}rc.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.cjs`,\n ],\n ignoreEmptySearchPlaces: true,\n stopDir: os.homedir(),\n cache: true,\n transform: identity,\n loaders: defaultLoaders,\n };\n\n const normalizedOptions: ExplorerOptions | ExplorerOptionsSync = {\n ...defaults,\n ...options,\n loaders: {\n ...defaults.loaders,\n ...options.loaders,\n },\n };\n\n return normalizedOptions;\n}\n\nexport { cosmiconfig, cosmiconfigSync, defaultLoaders };\n"],"file":"index.js"} dist/getDirectory.js 0000755 00000001604 15074777051 0010532 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDirectory = getDirectory; exports.getDirectorySync = getDirectorySync; var _path = _interopRequireDefault(require("path")); var _pathType = require("path-type"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } async function getDirectory(filepath) { const filePathIsDirectory = await (0, _pathType.isDirectory)(filepath); if (filePathIsDirectory === true) { return filepath; } const directory = _path.default.dirname(filepath); return directory; } function getDirectorySync(filepath) { const filePathIsDirectory = (0, _pathType.isDirectorySync)(filepath); if (filePathIsDirectory === true) { return filepath; } const directory = _path.default.dirname(filepath); return directory; } //# sourceMappingURL=getDirectory.js.map dist/loaders.js 0000755 00000002205 15074777051 0007515 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loaders = void 0; /* eslint-disable @typescript-eslint/no-require-imports */ let importFresh; const loadJs = function loadJs(filepath) { if (importFresh === undefined) { importFresh = require('import-fresh'); } const result = importFresh(filepath); return result; }; let parseJson; const loadJson = function loadJson(filepath, content) { if (parseJson === undefined) { parseJson = require('parse-json'); } try { const result = parseJson(content); return result; } catch (error) { error.message = `JSON Error in ${filepath}:\n${error.message}`; throw error; } }; let yaml; const loadYaml = function loadYaml(filepath, content) { if (yaml === undefined) { yaml = require('yaml'); } try { const result = yaml.parse(content, { prettyErrors: true }); return result; } catch (error) { error.message = `YAML Error in ${filepath}:\n${error.message}`; throw error; } }; const loaders = { loadJs, loadJson, loadYaml }; exports.loaders = loaders; //# sourceMappingURL=loaders.js.map dist/ExplorerBase.d.ts 0000755 00000002106 15074777051 0010713 0 ustar 00 import { CosmiconfigResult, ExplorerOptions, ExplorerOptionsSync, Cache, LoadedFileContent } from './types'; import { Loader } from './index'; declare class ExplorerBase<T extends ExplorerOptions | ExplorerOptionsSync> { protected readonly loadCache?: Cache; protected readonly searchCache?: Cache; protected readonly config: T; constructor(options: T); clearLoadCache(): void; clearSearchCache(): void; clearCaches(): void; private validateConfig; protected shouldSearchStopWithResult(result: CosmiconfigResult): boolean; protected nextDirectoryToSearch(currentDir: string, currentResult: CosmiconfigResult): string | null; private loadPackageProp; protected getLoaderEntryForFile(filepath: string): Loader; protected loadedContentToCosmiconfigResult(filepath: string, loadedContent: LoadedFileContent): CosmiconfigResult; protected validateFilePath(filepath: string): void; } declare function getExtensionDescription(filepath: string): string; export { ExplorerBase, getExtensionDescription }; //# sourceMappingURL=ExplorerBase.d.ts.map dist/index.d.ts 0000755 00000003604 15074777051 0007433 0 ustar 00 import { Config, CosmiconfigResult, Loaders, LoadersSync } from './types'; declare type LoaderResult = Config | null; export declare type Loader = ((filepath: string, content: string) => Promise<LoaderResult>) | LoaderSync; export declare type LoaderSync = (filepath: string, content: string) => LoaderResult; export declare type Transform = ((CosmiconfigResult: CosmiconfigResult) => Promise<CosmiconfigResult>) | TransformSync; export declare type TransformSync = (CosmiconfigResult: CosmiconfigResult) => CosmiconfigResult; interface OptionsBase { packageProp?: string | Array<string>; searchPlaces?: Array<string>; ignoreEmptySearchPlaces?: boolean; stopDir?: string; cache?: boolean; } export interface Options extends OptionsBase { loaders?: Loaders; transform?: Transform; } export interface OptionsSync extends OptionsBase { loaders?: LoadersSync; transform?: TransformSync; } declare function cosmiconfig(moduleName: string, options?: Options): { readonly search: (searchFrom?: string) => Promise<CosmiconfigResult>; readonly load: (filepath: string) => Promise<CosmiconfigResult>; readonly clearLoadCache: () => void; readonly clearSearchCache: () => void; readonly clearCaches: () => void; }; declare function cosmiconfigSync(moduleName: string, options?: OptionsSync): { readonly search: (searchFrom?: string) => CosmiconfigResult; readonly load: (filepath: string) => CosmiconfigResult; readonly clearLoadCache: () => void; readonly clearSearchCache: () => void; readonly clearCaches: () => void; }; declare const defaultLoaders: Readonly<{ readonly '.cjs': LoaderSync; readonly '.js': LoaderSync; readonly '.json': LoaderSync; readonly '.yaml': LoaderSync; readonly '.yml': LoaderSync; readonly noExt: LoaderSync; }>; export { cosmiconfig, cosmiconfigSync, defaultLoaders }; //# sourceMappingURL=index.d.ts.map dist/ExplorerBase.d.ts.map 0000755 00000001754 15074777051 0011477 0 ustar 00 {"version":3,"file":"ExplorerBase.d.ts","sourceRoot":"","sources":["../src/ExplorerBase.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,KAAK,EACL,iBAAiB,EAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,cAAM,YAAY,CAAC,CAAC,SAAS,eAAe,GAAG,mBAAmB;IAChE,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC;IACrC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;IACvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;gBAEV,OAAO,EAAE,CAAC;IAUtB,cAAc,IAAI,IAAI;IAMtB,gBAAgB,IAAI,IAAI;IAMxB,WAAW,IAAI,IAAI;IAK1B,OAAO,CAAC,cAAc;IAwBtB,SAAS,CAAC,0BAA0B,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;IAMxE,SAAS,CAAC,qBAAqB,CAC7B,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,iBAAiB,GAC/B,MAAM,GAAG,IAAI;IAWhB,OAAO,CAAC,eAAe;IASvB,SAAS,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAmBzD,SAAS,CAAC,gCAAgC,CACxC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,iBAAiB,GAC/B,iBAAiB;IAUpB,SAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAKnD;AAMD,iBAAS,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,CAAC"} dist/getPropertyByPath.d.ts.map 0000755 00000000455 15074777051 0012535 0 ustar 00 {"version":3,"file":"getPropertyByPath.d.ts","sourceRoot":"","sources":["../src/getPropertyByPath.ts"],"names":[],"mappings":"AAKA,iBAAS,iBAAiB,CACxB,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAClC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAC3B,OAAO,CAgBT;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"} dist/cacheWrapper.d.ts.map 0000755 00000000702 15074777051 0011500 0 ustar 00 {"version":3,"file":"cacheWrapper.d.ts","sourceRoot":"","sources":["../src/cacheWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnD,iBAAe,YAAY,CACzB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,GACnC,OAAO,CAAC,iBAAiB,CAAC,CAS5B;AAED,iBAAS,gBAAgB,CACvB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,iBAAiB,GAC1B,iBAAiB,CASnB;AAED,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC"} dist/types.d.ts.map 0000755 00000001254 15074777051 0010243 0 ustar 00 {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGnE,oBAAY,MAAM,GAAG,GAAG,CAAC;AAEzB,oBAAY,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,IAAI,CAAC;AAIT,MAAM,WAAW,eAAgB,SAAQ,QAAQ,CAAC,OAAO,CAAC;CAAG;AAC7D,MAAM,WAAW,mBAAoB,SAAQ,QAAQ,CAAC,WAAW,CAAC;CAAG;AAGrE,oBAAY,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAMnD,oBAAY,iBAAiB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAE1D,MAAM,WAAW,OAAO;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B"} dist/cacheWrapper.js.map 0000755 00000002667 15074777051 0011260 0 ustar 00 {"version":3,"sources":["../src/cacheWrapper.ts"],"names":["cacheWrapper","cache","key","fn","cached","get","undefined","result","set","cacheWrapperSync"],"mappings":";;;;;;;;AAEA,eAAeA,YAAf,CACEC,KADF,EAEEC,GAFF,EAGEC,EAHF,EAI8B;AAC5B,QAAMC,MAAM,GAAGH,KAAK,CAACI,GAAN,CAAUH,GAAV,CAAf;;AACA,MAAIE,MAAM,KAAKE,SAAf,EAA0B;AACxB,WAAOF,MAAP;AACD;;AAED,QAAMG,MAAM,GAAG,MAAMJ,EAAE,EAAvB;AACAF,EAAAA,KAAK,CAACO,GAAN,CAAUN,GAAV,EAAeK,MAAf;AACA,SAAOA,MAAP;AACD;;AAED,SAASE,gBAAT,CACER,KADF,EAEEC,GAFF,EAGEC,EAHF,EAIqB;AACnB,QAAMC,MAAM,GAAGH,KAAK,CAACI,GAAN,CAAUH,GAAV,CAAf;;AACA,MAAIE,MAAM,KAAKE,SAAf,EAA0B;AACxB,WAAOF,MAAP;AACD;;AAED,QAAMG,MAAM,GAAGJ,EAAE,EAAjB;AACAF,EAAAA,KAAK,CAACO,GAAN,CAAUN,GAAV,EAAeK,MAAf;AACA,SAAOA,MAAP;AACD","sourcesContent":["import { Cache, CosmiconfigResult } from './types';\n\nasync function cacheWrapper(\n cache: Cache,\n key: string,\n fn: () => Promise<CosmiconfigResult>,\n): Promise<CosmiconfigResult> {\n const cached = cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n\n const result = await fn();\n cache.set(key, result);\n return result;\n}\n\nfunction cacheWrapperSync(\n cache: Cache,\n key: string,\n fn: () => CosmiconfigResult,\n): CosmiconfigResult {\n const cached = cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n\n const result = fn();\n cache.set(key, result);\n return result;\n}\n\nexport { cacheWrapper, cacheWrapperSync };\n"],"file":"cacheWrapper.js"} dist/getPropertyByPath.d.ts 0000755 00000000301 15074777051 0011747 0 ustar 00 declare function getPropertyByPath(source: { [key: string]: unknown; }, path: string | Array<string>): unknown; export { getPropertyByPath }; //# sourceMappingURL=getPropertyByPath.d.ts.map dist/ExplorerSync.js 0000755 00000006101 15074777051 0010520 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExplorerSync = void 0; var _path = _interopRequireDefault(require("path")); var _ExplorerBase = require("./ExplorerBase"); var _readFile = require("./readFile"); var _cacheWrapper = require("./cacheWrapper"); var _getDirectory = require("./getDirectory"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class ExplorerSync extends _ExplorerBase.ExplorerBase { constructor(options) { super(options); } searchSync(searchFrom = process.cwd()) { const startDirectory = (0, _getDirectory.getDirectorySync)(searchFrom); const result = this.searchFromDirectorySync(startDirectory); return result; } searchFromDirectorySync(dir) { const absoluteDir = _path.default.resolve(process.cwd(), dir); const run = () => { const result = this.searchDirectorySync(absoluteDir); const nextDir = this.nextDirectoryToSearch(absoluteDir, result); if (nextDir) { return this.searchFromDirectorySync(nextDir); } const transformResult = this.config.transform(result); return transformResult; }; if (this.searchCache) { return (0, _cacheWrapper.cacheWrapperSync)(this.searchCache, absoluteDir, run); } return run(); } searchDirectorySync(dir) { for (const place of this.config.searchPlaces) { const placeResult = this.loadSearchPlaceSync(dir, place); if (this.shouldSearchStopWithResult(placeResult) === true) { return placeResult; } } // config not found return null; } loadSearchPlaceSync(dir, place) { const filepath = _path.default.join(dir, place); const content = (0, _readFile.readFileSync)(filepath); const result = this.createCosmiconfigResultSync(filepath, content); return result; } loadFileContentSync(filepath, content) { if (content === null) { return null; } if (content.trim() === '') { return undefined; } const loader = this.getLoaderEntryForFile(filepath); const loaderResult = loader(filepath, content); return loaderResult; } createCosmiconfigResultSync(filepath, content) { const fileContent = this.loadFileContentSync(filepath, content); const result = this.loadedContentToCosmiconfigResult(filepath, fileContent); return result; } loadSync(filepath) { this.validateFilePath(filepath); const absoluteFilePath = _path.default.resolve(process.cwd(), filepath); const runLoadSync = () => { const content = (0, _readFile.readFileSync)(absoluteFilePath, { throwNotFound: true }); const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content); const transformResult = this.config.transform(cosmiconfigResult); return transformResult; }; if (this.loadCache) { return (0, _cacheWrapper.cacheWrapperSync)(this.loadCache, absoluteFilePath, runLoadSync); } return runLoadSync(); } } exports.ExplorerSync = ExplorerSync; //# sourceMappingURL=ExplorerSync.js.map dist/cacheWrapper.js 0000755 00000001144 15074777051 0010471 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cacheWrapper = cacheWrapper; exports.cacheWrapperSync = cacheWrapperSync; async function cacheWrapper(cache, key, fn) { const cached = cache.get(key); if (cached !== undefined) { return cached; } const result = await fn(); cache.set(key, result); return result; } function cacheWrapperSync(cache, key, fn) { const cached = cache.get(key); if (cached !== undefined) { return cached; } const result = fn(); cache.set(key, result); return result; } //# sourceMappingURL=cacheWrapper.js.map dist/readFile.js.map 0000755 00000005175 15074777051 0010364 0 ustar 00 {"version":3,"sources":["../src/readFile.ts"],"names":["fsReadFileAsync","pathname","encoding","Promise","resolve","reject","fs","readFile","error","contents","filepath","options","throwNotFound","content","code","readFileSync"],"mappings":";;;;;;;;AAAA;;;;AAEA,eAAeA,eAAf,CACEC,QADF,EAEEC,QAFF,EAGmB;AACjB,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAA2B;AAC5CC,gBAAGC,QAAH,CAAYN,QAAZ,EAAsBC,QAAtB,EAAgC,CAACM,KAAD,EAAQC,QAAR,KAA2B;AACzD,UAAID,KAAJ,EAAW;AACTH,QAAAA,MAAM,CAACG,KAAD,CAAN;AACA;AACD;;AAEDJ,MAAAA,OAAO,CAACK,QAAD,CAAP;AACD,KAPD;AAQD,GATM,CAAP;AAUD;;AAMD,eAAeF,QAAf,CACEG,QADF,EAEEC,OAAgB,GAAG,EAFrB,EAG0B;AACxB,QAAMC,aAAa,GAAGD,OAAO,CAACC,aAAR,KAA0B,IAAhD;;AAEA,MAAI;AACF,UAAMC,OAAO,GAAG,MAAMb,eAAe,CAACU,QAAD,EAAW,MAAX,CAArC;AAEA,WAAOG,OAAP;AACD,GAJD,CAIE,OAAOL,KAAP,EAAc;AACd,QACEI,aAAa,KAAK,KAAlB,KACCJ,KAAK,CAACM,IAAN,KAAe,QAAf,IAA2BN,KAAK,CAACM,IAAN,KAAe,QAD3C,CADF,EAGE;AACA,aAAO,IAAP;AACD;;AAED,UAAMN,KAAN;AACD;AACF;;AAED,SAASO,YAAT,CAAsBL,QAAtB,EAAwCC,OAAgB,GAAG,EAA3D,EAA8E;AAC5E,QAAMC,aAAa,GAAGD,OAAO,CAACC,aAAR,KAA0B,IAAhD;;AAEA,MAAI;AACF,UAAMC,OAAO,GAAGP,YAAGS,YAAH,CAAgBL,QAAhB,EAA0B,MAA1B,CAAhB;;AAEA,WAAOG,OAAP;AACD,GAJD,CAIE,OAAOL,KAAP,EAAc;AACd,QACEI,aAAa,KAAK,KAAlB,KACCJ,KAAK,CAACM,IAAN,KAAe,QAAf,IAA2BN,KAAK,CAACM,IAAN,KAAe,QAD3C,CADF,EAGE;AACA,aAAO,IAAP;AACD;;AAED,UAAMN,KAAN;AACD;AACF","sourcesContent":["import fs from 'fs';\n\nasync function fsReadFileAsync(\n pathname: string,\n encoding: BufferEncoding,\n): Promise<string> {\n return new Promise((resolve, reject): void => {\n fs.readFile(pathname, encoding, (error, contents): void => {\n if (error) {\n reject(error);\n return;\n }\n\n resolve(contents);\n });\n });\n}\n\ninterface Options {\n throwNotFound?: boolean;\n}\n\nasync function readFile(\n filepath: string,\n options: Options = {},\n): Promise<string | null> {\n const throwNotFound = options.throwNotFound === true;\n\n try {\n const content = await fsReadFileAsync(filepath, 'utf8');\n\n return content;\n } catch (error) {\n if (\n throwNotFound === false &&\n (error.code === 'ENOENT' || error.code === 'EISDIR')\n ) {\n return null;\n }\n\n throw error;\n }\n}\n\nfunction readFileSync(filepath: string, options: Options = {}): string | null {\n const throwNotFound = options.throwNotFound === true;\n\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n\n return content;\n } catch (error) {\n if (\n throwNotFound === false &&\n (error.code === 'ENOENT' || error.code === 'EISDIR')\n ) {\n return null;\n }\n\n throw error;\n }\n}\n\nexport { readFile, readFileSync };\n"],"file":"readFile.js"} dist/ExplorerBase.js.map 0000755 00000016544 15074777051 0011246 0 ustar 00 {"version":3,"sources":["../src/ExplorerBase.ts"],"names":["ExplorerBase","constructor","options","cache","loadCache","Map","searchCache","config","validateConfig","clearLoadCache","clear","clearSearchCache","clearCaches","searchPlaces","forEach","place","loaderKey","path","extname","loader","loaders","Error","getExtensionDescription","shouldSearchStopWithResult","result","isEmpty","ignoreEmptySearchPlaces","nextDirectoryToSearch","currentDir","currentResult","nextDir","nextDirUp","stopDir","loadPackageProp","filepath","content","parsedContent","loadJson","packagePropValue","packageProp","getLoaderEntryForFile","basename","bind","loadedContentToCosmiconfigResult","loadedContent","undefined","validateFilePath","dir","dirname","ext"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;;;AAUA,MAAMA,YAAN,CAAoE;AAK3DC,EAAAA,WAAW,CAACC,OAAD,EAAa;AAC7B,QAAIA,OAAO,CAACC,KAAR,KAAkB,IAAtB,EAA4B;AAC1B,WAAKC,SAAL,GAAiB,IAAIC,GAAJ,EAAjB;AACA,WAAKC,WAAL,GAAmB,IAAID,GAAJ,EAAnB;AACD;;AAED,SAAKE,MAAL,GAAcL,OAAd;AACA,SAAKM,cAAL;AACD;;AAEMC,EAAAA,cAAc,GAAS;AAC5B,QAAI,KAAKL,SAAT,EAAoB;AAClB,WAAKA,SAAL,CAAeM,KAAf;AACD;AACF;;AAEMC,EAAAA,gBAAgB,GAAS;AAC9B,QAAI,KAAKL,WAAT,EAAsB;AACpB,WAAKA,WAAL,CAAiBI,KAAjB;AACD;AACF;;AAEME,EAAAA,WAAW,GAAS;AACzB,SAAKH,cAAL;AACA,SAAKE,gBAAL;AACD;;AAEOH,EAAAA,cAAc,GAAS;AAC7B,UAAMD,MAAM,GAAG,KAAKA,MAApB;AAEAA,IAAAA,MAAM,CAACM,YAAP,CAAoBC,OAApB,CAA6BC,KAAD,IAAiB;AAC3C,YAAMC,SAAS,GAAGC,cAAKC,OAAL,CAAaH,KAAb,KAAuB,OAAzC;AACA,YAAMI,MAAM,GAAGZ,MAAM,CAACa,OAAP,CAAeJ,SAAf,CAAf;;AACA,UAAI,CAACG,MAAL,EAAa;AACX,cAAM,IAAIE,KAAJ,CACH,2BA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B,CAAf;AACA,aAAOvB,MAAP;AACD;;AAED,UAAMH,SAAS,GAAGC,cAAKC,OAAL,CAAagB,QAAb,KAA0B,OAA5C;AAEA,UAAMf,MAAM,GAAG,KAAKZ,MAAL,CAAYa,OAAZ,CAAoBJ,SAApB,CAAf;;AAEA,QAAI,CAACG,MAAL,EAAa;AACX,YAAM,IAAIE,KAAJ,CACH,2BAA0BC,uBAAuB,CAACY,QAAD,CAAW,EADzD,CAAN;AAGD;;AAED,WAAOf,MAAP;AACD;;AAESwB,EAAAA,gCAAgC,CACxCT,QADwC,EAExCU,aAFwC,EAGrB;AACnB,QAAIA,aAAa,KAAK,IAAtB,EAA4B;AAC1B,aAAO,IAAP;AACD;;AACD,QAAIA,aAAa,KAAKC,SAAtB,EAAiC;AAC/B,aAAO;AAAEX,QAAAA,QAAF;AAAY3B,QAAAA,MAAM,EAAEsC,SAApB;AAA+BpB,QAAAA,OAAO,EAAE;AAAxC,OAAP;AACD;;AACD,WAAO;AAAElB,MAAAA,MAAM,EAAEqC,aAAV;AAAyBV,MAAAA;AAAzB,KAAP;AACD;;AAESY,EAAAA,gBAAgB,CAACZ,QAAD,EAAyB;AACjD,QAAI,CAACA,QAAL,EAAe;AACb,YAAM,IAAIb,KAAJ,CAAU,mCAAV,CAAN;AACD;AACF;;AAzHiE;;;;AA4HpE,SAASU,SAAT,CAAmBgB,GAAnB,EAAwC;AACtC,SAAO9B,cAAK+B,OAAL,CAAaD,GAAb,CAAP;AACD;;AAED,SAASzB,uBAAT,CAAiCY,QAAjC,EAA2D;AACzD,QAAMe,GAAG,GAAGhC,cAAKC,OAAL,CAAagB,QAAb,CAAZ;;AACA,SAAOe,GAAG,GAAI,cAAaA,GAAI,GAArB,GAA0B,0BAApC;AACD","sourcesContent":["import path from 'path';\nimport { loaders } from './loaders';\nimport { getPropertyByPath } from './getPropertyByPath';\nimport {\n CosmiconfigResult,\n ExplorerOptions,\n ExplorerOptionsSync,\n Cache,\n LoadedFileContent,\n} from './types';\nimport { Loader } from './index';\n\nclass ExplorerBase<T extends ExplorerOptions | ExplorerOptionsSync> {\n protected readonly loadCache?: Cache;\n protected readonly searchCache?: Cache;\n protected readonly config: T;\n\n public constructor(options: T) {\n if (options.cache === true) {\n this.loadCache = new Map();\n this.searchCache = new Map();\n }\n\n this.config = options;\n this.validateConfig();\n }\n\n public clearLoadCache(): void {\n if (this.loadCache) {\n this.loadCache.clear();\n }\n }\n\n public clearSearchCache(): void {\n if (this.searchCache) {\n this.searchCache.clear();\n }\n }\n\n public clearCaches(): void {\n this.clearLoadCache();\n this.clearSearchCache();\n }\n\n private validateConfig(): void {\n const config = this.config;\n\n config.searchPlaces.forEach((place): void => {\n const loaderKey = path.extname(place) || 'noExt';\n const loader = config.loaders[loaderKey];\n if (!loader) {\n throw new Error(\n `No loader specified for ${getExtensionDescription(\n place,\n )}, so searchPlaces item \"${place}\" is invalid`,\n );\n }\n\n if (typeof loader !== 'function') {\n throw new Error(\n `loader for ${getExtensionDescription(\n place,\n )} is not a function (type provided: \"${typeof loader}\"), so searchPlaces item \"${place}\" is invalid`,\n );\n }\n });\n }\n\n protected shouldSearchStopWithResult(result: CosmiconfigResult): boolean {\n if (result === null) return false;\n if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;\n return true;\n }\n\n protected nextDirectoryToSearch(\n currentDir: string,\n currentResult: CosmiconfigResult,\n ): string | null {\n if (this.shouldSearchStopWithResult(currentResult)) {\n return null;\n }\n const nextDir = nextDirUp(currentDir);\n if (nextDir === currentDir || currentDir === this.config.stopDir) {\n return null;\n }\n return nextDir;\n }\n\n private loadPackageProp(filepath: string, content: string): unknown {\n const parsedContent = loaders.loadJson(filepath, content);\n const packagePropValue = getPropertyByPath(\n parsedContent,\n this.config.packageProp,\n );\n return packagePropValue || null;\n }\n\n protected getLoaderEntryForFile(filepath: string): Loader {\n if (path.basename(filepath) === 'package.json') {\n const loader = this.loadPackageProp.bind(this);\n return loader;\n }\n\n const loaderKey = path.extname(filepath) || 'noExt';\n\n const loader = this.config.loaders[loaderKey];\n\n if (!loader) {\n throw new Error(\n `No loader specified for ${getExtensionDescription(filepath)}`,\n );\n }\n\n return loader;\n }\n\n protected loadedContentToCosmiconfigResult(\n filepath: string,\n loadedContent: LoadedFileContent,\n ): CosmiconfigResult {\n if (loadedContent === null) {\n return null;\n }\n if (loadedContent === undefined) {\n return { filepath, config: undefined, isEmpty: true };\n }\n return { config: loadedContent, filepath };\n }\n\n protected validateFilePath(filepath: string): void {\n if (!filepath) {\n throw new Error('load must pass a non-empty string');\n }\n }\n}\n\nfunction nextDirUp(dir: string): string {\n return path.dirname(dir);\n}\n\nfunction getExtensionDescription(filepath: string): string {\n const ext = path.extname(filepath);\n return ext ? `extension \"${ext}\"` : 'files without extensions';\n}\n\nexport { ExplorerBase, getExtensionDescription };\n"],"file":"ExplorerBase.js"} dist/cacheWrapper.d.ts 0000755 00000000563 15074777051 0010731 0 ustar 00 import { Cache, CosmiconfigResult } from './types'; declare function cacheWrapper(cache: Cache, key: string, fn: () => Promise<CosmiconfigResult>): Promise<CosmiconfigResult>; declare function cacheWrapperSync(cache: Cache, key: string, fn: () => CosmiconfigResult): CosmiconfigResult; export { cacheWrapper, cacheWrapperSync }; //# sourceMappingURL=cacheWrapper.d.ts.map dist/ExplorerSync.js.map 0000755 00000014674 15074777051 0011312 0 ustar 00 {"version":3,"sources":["../src/ExplorerSync.ts"],"names":["ExplorerSync","ExplorerBase","constructor","options","searchSync","searchFrom","process","cwd","startDirectory","result","searchFromDirectorySync","dir","absoluteDir","path","resolve","run","searchDirectorySync","nextDir","nextDirectoryToSearch","transformResult","config","transform","searchCache","place","searchPlaces","placeResult","loadSearchPlaceSync","shouldSearchStopWithResult","filepath","join","content","createCosmiconfigResultSync","loadFileContentSync","trim","undefined","loader","getLoaderEntryForFile","loaderResult","fileContent","loadedContentToCosmiconfigResult","loadSync","validateFilePath","absoluteFilePath","runLoadSync","throwNotFound","cosmiconfigResult","loadCache"],"mappings":";;;;;;;AAAA;;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E;AAAjB,OAA/B,CAAhB;AACA,YAAMC,iBAAiB,GAAG,KAAKd,2BAAL,CACxBW,gBADwB,EAExBZ,OAFwB,CAA1B;AAKA,YAAMX,eAAe,GAAG,KAAKC,MAAL,CAAYC,SAAZ,CAAsBwB,iBAAtB,CAAxB;AAEA,aAAO1B,eAAP;AACD,KAVD;;AAYA,QAAI,KAAK2B,SAAT,EAAoB;AAClB,aAAO,oCAAiB,KAAKA,SAAtB,EAAiCJ,gBAAjC,EAAmDC,WAAnD,CAAP;AACD;;AAED,WAAOA,WAAW,EAAlB;AACD;;AAxG0D","sourcesContent":["import path from 'path';\nimport { ExplorerBase } from './ExplorerBase';\nimport { readFileSync } from './readFile';\nimport { cacheWrapperSync } from './cacheWrapper';\nimport { getDirectorySync } from './getDirectory';\nimport {\n CosmiconfigResult,\n ExplorerOptionsSync,\n LoadedFileContent,\n} from './types';\n\nclass ExplorerSync extends ExplorerBase<ExplorerOptionsSync> {\n public constructor(options: ExplorerOptionsSync) {\n super(options);\n }\n\n public searchSync(searchFrom: string = process.cwd()): CosmiconfigResult {\n const startDirectory = getDirectorySync(searchFrom);\n const result = this.searchFromDirectorySync(startDirectory);\n\n return result;\n }\n\n private searchFromDirectorySync(dir: string): CosmiconfigResult {\n const absoluteDir = path.resolve(process.cwd(), dir);\n\n const run = (): CosmiconfigResult => {\n const result = this.searchDirectorySync(absoluteDir);\n const nextDir = this.nextDirectoryToSearch(absoluteDir, result);\n\n if (nextDir) {\n return this.searchFromDirectorySync(nextDir);\n }\n\n const transformResult = this.config.transform(result);\n\n return transformResult;\n };\n\n if (this.searchCache) {\n return cacheWrapperSync(this.searchCache, absoluteDir, run);\n }\n\n return run();\n }\n\n private searchDirectorySync(dir: string): CosmiconfigResult {\n for (const place of this.config.searchPlaces) {\n const placeResult = this.loadSearchPlaceSync(dir, place);\n\n if (this.shouldSearchStopWithResult(placeResult) === true) {\n return placeResult;\n }\n }\n\n // config not found\n return null;\n }\n\n private loadSearchPlaceSync(dir: string, place: string): CosmiconfigResult {\n const filepath = path.join(dir, place);\n const content = readFileSync(filepath);\n\n const result = this.createCosmiconfigResultSync(filepath, content);\n\n return result;\n }\n\n private loadFileContentSync(\n filepath: string,\n content: string | null,\n ): LoadedFileContent {\n if (content === null) {\n return null;\n }\n if (content.trim() === '') {\n return undefined;\n }\n const loader = this.getLoaderEntryForFile(filepath);\n const loaderResult = loader(filepath, content);\n\n return loaderResult;\n }\n\n private createCosmiconfigResultSync(\n filepath: string,\n content: string | null,\n ): CosmiconfigResult {\n const fileContent = this.loadFileContentSync(filepath, content);\n const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);\n\n return result;\n }\n\n public loadSync(filepath: string): CosmiconfigResult {\n this.validateFilePath(filepath);\n const absoluteFilePath = path.resolve(process.cwd(), filepath);\n\n const runLoadSync = (): CosmiconfigResult => {\n const content = readFileSync(absoluteFilePath, { throwNotFound: true });\n const cosmiconfigResult = this.createCosmiconfigResultSync(\n absoluteFilePath,\n content,\n );\n\n const transformResult = this.config.transform(cosmiconfigResult);\n\n return transformResult;\n };\n\n if (this.loadCache) {\n return cacheWrapperSync(this.loadCache, absoluteFilePath, runLoadSync);\n }\n\n return runLoadSync();\n }\n}\n\nexport { ExplorerSync };\n"],"file":"ExplorerSync.js"} dist/readFile.d.ts.map 0000755 00000000601 15074777051 0010605 0 ustar 00 {"version":3,"file":"readFile.d.ts","sourceRoot":"","sources":["../src/readFile.ts"],"names":[],"mappings":"AAkBA,UAAU,OAAO;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,iBAAe,QAAQ,CACrB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiBxB;AAED,iBAAS,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,OAAY,GAAG,MAAM,GAAG,IAAI,CAiB5E;AAED,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC"} dist/Explorer.js.map 0000755 00000015074 15074777051 0010450 0 ustar 00 {"version":3,"sources":["../src/Explorer.ts"],"names":["Explorer","ExplorerBase","constructor","options","search","searchFrom","process","cwd","startDirectory","result","searchFromDirectory","dir","absoluteDir","path","resolve","run","searchDirectory","nextDir","nextDirectoryToSearch","transformResult","config","transform","searchCache","place","searchPlaces","placeResult","loadSearchPlace","shouldSearchStopWithResult","filepath","join","fileContents","createCosmiconfigResult","loadFileContent","content","trim","undefined","loader","getLoaderEntryForFile","loaderResult","fileContent","loadedContentToCosmiconfigResult","load","validateFilePath","absoluteFilePath","runLoad","throwNotFound","loadCache"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAGA,MAAMA,QAAN,SAAuBC,0BAAvB,CAAqD;AAC5CC,EAAAA,WAAW,CAACC,OAAD,EAA2B;AAC3C,UAAMA,OAAN;AACD;;AAEkB,QAANC,MAAM,CACjBC,UAAkB,GAAGC,OAAO,CAACC,GAAR,EADJ,EAEW;AAC5B,UAAMC,cAAc,GAAG,MAAM,gCAAaH,UAAb,CAA7B;AACA,UAAMI,MAAM,GAAG,MAAM,KAAKC,mBAAL,CAAyBF,cAAzB,CAArB;AAEA,WAAOC,MAAP;AACD;;AAEgC,QAAnBC,mBAAmB,CAACC,GAAD,EAA0C;AACzE,UAAMC,WAAW,GAAGC,cAAKC,OAAL,CAAaR,OAAO,CAACC,GAAR,EAAb,EAA4BI,GAA5B,CAApB;;AAEA,UAAMI,GAAG,GAAG,YAAwC;AAClD,YAAMN,MAAM,GAAG,MAAM,KAAKO,eAAL,CAAqBJ,WAArB,CAArB;AACA,YAAMK,OAAO,GAAG,KAAKC,qBAAL,CAA2BN,WAA3B,EAAwCH,MAAxC,CAAhB;;AAEA,UAAIQ,OAAJ,EAAa;AACX,eAAO,KAAKP,mBAAL,CAAyBO,OAAzB,CAAP;AACD;;AAED,YAAME,eAAe,GAAG,MAAM,KAAKC,MAAL,CAAYC,SAAZ,CAAsBZ,MAAtB,C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W,GAAG,MAAM,KAAKP,eAAL,CAAqBJ,QAArB,EAA+BK,OAA/B,CAA1B;AACA,UAAMxB,MAAM,GAAG,KAAK+B,gCAAL,CAAsCZ,QAAtC,EAAgDW,WAAhD,CAAf;AAEA,WAAO9B,MAAP;AACD;;AAEgB,QAAJgC,IAAI,CAACb,QAAD,EAA+C;AAC9D,SAAKc,gBAAL,CAAsBd,QAAtB;;AACA,UAAMe,gBAAgB,GAAG9B,cAAKC,OAAL,CAAaR,OAAO,CAACC,GAAR,EAAb,EAA4BqB,QAA5B,CAAzB;;AAEA,UAAMgB,OAAO,GAAG,YAAwC;AACtD,YAAMd,YAAY,GAAG,MAAM,wBAASa,gBAAT,EAA2B;AACpDE,QAAAA,aAAa,EAAE;AADqC,OAA3B,CAA3B;AAIA,YAAMpC,MAAM,GAAG,MAAM,KAAKsB,uBAAL,CACnBY,gBADmB,EAEnBb,YAFmB,CAArB;AAKA,YAAMX,eAAe,GAAG,MAAM,KAAKC,MAAL,CAAYC,SAAZ,CAAsBZ,MAAtB,CAA9B;AAEA,aAAOU,eAAP;AACD,KAbD;;AAeA,QAAI,KAAK2B,SAAT,EAAoB;AAClB,aAAO,gCAAa,KAAKA,SAAlB,EAA6BH,gBAA7B,EAA+CC,OAA/C,CAAP;AACD;;AAED,WAAOA,OAAO,EAAd;AACD;;AA/GkD","sourcesContent":["import path from 'path';\nimport { ExplorerBase } from './ExplorerBase';\nimport { readFile } from './readFile';\nimport { cacheWrapper } from './cacheWrapper';\nimport { getDirectory } from './getDirectory';\nimport { CosmiconfigResult, ExplorerOptions, LoadedFileContent } from './types';\n\nclass Explorer extends ExplorerBase<ExplorerOptions> {\n public constructor(options: ExplorerOptions) {\n super(options);\n }\n\n public async search(\n searchFrom: string = process.cwd(),\n ): Promise<CosmiconfigResult> {\n const startDirectory = await getDirectory(searchFrom);\n const result = await this.searchFromDirectory(startDirectory);\n\n return result;\n }\n\n private async searchFromDirectory(dir: string): Promise<CosmiconfigResult> {\n const absoluteDir = path.resolve(process.cwd(), dir);\n\n const run = async (): Promise<CosmiconfigResult> => {\n const result = await this.searchDirectory(absoluteDir);\n const nextDir = this.nextDirectoryToSearch(absoluteDir, result);\n\n if (nextDir) {\n return this.searchFromDirectory(nextDir);\n }\n\n const transformResult = await this.config.transform(result);\n\n return transformResult;\n };\n\n if (this.searchCache) {\n return cacheWrapper(this.searchCache, absoluteDir, run);\n }\n\n return run();\n }\n\n private async searchDirectory(dir: string): Promise<CosmiconfigResult> {\n for await (const place of this.config.searchPlaces) {\n const placeResult = await this.loadSearchPlace(dir, place);\n\n if (this.shouldSearchStopWithResult(placeResult) === true) {\n return placeResult;\n }\n }\n\n // config not found\n return null;\n }\n\n private async loadSearchPlace(\n dir: string,\n place: string,\n ): Promise<CosmiconfigResult> {\n const filepath = path.join(dir, place);\n const fileContents = await readFile(filepath);\n\n const result = await this.createCosmiconfigResult(filepath, fileContents);\n\n return result;\n }\n\n private async loadFileContent(\n filepath: string,\n content: string | null,\n ): Promise<LoadedFileContent> {\n if (content === null) {\n return null;\n }\n if (content.trim() === '') {\n return undefined;\n }\n const loader = this.getLoaderEntryForFile(filepath);\n const loaderResult = await loader(filepath, content);\n return loaderResult;\n }\n\n private async createCosmiconfigResult(\n filepath: string,\n content: string | null,\n ): Promise<CosmiconfigResult> {\n const fileContent = await this.loadFileContent(filepath, content);\n const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);\n\n return result;\n }\n\n public async load(filepath: string): Promise<CosmiconfigResult> {\n this.validateFilePath(filepath);\n const absoluteFilePath = path.resolve(process.cwd(), filepath);\n\n const runLoad = async (): Promise<CosmiconfigResult> => {\n const fileContents = await readFile(absoluteFilePath, {\n throwNotFound: true,\n });\n\n const result = await this.createCosmiconfigResult(\n absoluteFilePath,\n fileContents,\n );\n\n const transformResult = await this.config.transform(result);\n\n return transformResult;\n };\n\n if (this.loadCache) {\n return cacheWrapper(this.loadCache, absoluteFilePath, runLoad);\n }\n\n return runLoad();\n }\n}\n\nexport { Explorer };\n"],"file":"Explorer.js"} dist/getPropertyByPath.js 0000755 00000001652 15074777051 0011525 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPropertyByPath = getPropertyByPath; // Resolves property names or property paths defined with period-delimited // strings or arrays of strings. Property names that are found on the source // object are used directly (even if they include a period). // Nested property names that include periods, within a path, are only // understood in array paths. function getPropertyByPath(source, path) { if (typeof path === 'string' && Object.prototype.hasOwnProperty.call(source, path)) { return source[path]; } const parsedPath = typeof path === 'string' ? path.split('.') : path; // eslint-disable-next-line @typescript-eslint/no-explicit-any return parsedPath.reduce((previous, key) => { if (previous === undefined) { return previous; } return previous[key]; }, source); } //# sourceMappingURL=getPropertyByPath.js.map dist/ExplorerBase.js 0000755 00000006561 15074777051 0010470 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExplorerBase = void 0; exports.getExtensionDescription = getExtensionDescription; var _path = _interopRequireDefault(require("path")); var _loaders = require("./loaders"); var _getPropertyByPath = require("./getPropertyByPath"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class ExplorerBase { constructor(options) { if (options.cache === true) { this.loadCache = new Map(); this.searchCache = new Map(); } this.config = options; this.validateConfig(); } clearLoadCache() { if (this.loadCache) { this.loadCache.clear(); } } clearSearchCache() { if (this.searchCache) { this.searchCache.clear(); } } clearCaches() { this.clearLoadCache(); this.clearSearchCache(); } validateConfig() { const config = this.config; config.searchPlaces.forEach(place => { const loaderKey = _path.default.extname(place) || 'noExt'; const loader = config.loaders[loaderKey]; if (!loader) { throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`); } if (typeof loader !== 'function') { throw new Error(`loader for ${getExtensionDescription(place)} is not a function (type provided: "${typeof loader}"), so searchPlaces item "${place}" is invalid`); } }); } shouldSearchStopWithResult(result) { if (result === null) return false; if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false; return true; } nextDirectoryToSearch(currentDir, currentResult) { if (this.shouldSearchStopWithResult(currentResult)) { return null; } const nextDir = nextDirUp(currentDir); if (nextDir === currentDir || currentDir === this.config.stopDir) { return null; } return nextDir; } loadPackageProp(filepath, content) { const parsedContent = _loaders.loaders.loadJson(filepath, content); const packagePropValue = (0, _getPropertyByPath.getPropertyByPath)(parsedContent, this.config.packageProp); return packagePropValue || null; } getLoaderEntryForFile(filepath) { if (_path.default.basename(filepath) === 'package.json') { const loader = this.loadPackageProp.bind(this); return loader; } const loaderKey = _path.default.extname(filepath) || 'noExt'; const loader = this.config.loaders[loaderKey]; if (!loader) { throw new Error(`No loader specified for ${getExtensionDescription(filepath)}`); } return loader; } loadedContentToCosmiconfigResult(filepath, loadedContent) { if (loadedContent === null) { return null; } if (loadedContent === undefined) { return { filepath, config: undefined, isEmpty: true }; } return { config: loadedContent, filepath }; } validateFilePath(filepath) { if (!filepath) { throw new Error('load must pass a non-empty string'); } } } exports.ExplorerBase = ExplorerBase; function nextDirUp(dir) { return _path.default.dirname(dir); } function getExtensionDescription(filepath) { const ext = _path.default.extname(filepath); return ext ? `extension "${ext}"` : 'files without extensions'; } //# sourceMappingURL=ExplorerBase.js.map dist/getPropertyByPath.js.map 0000755 00000003255 15074777051 0012302 0 ustar 00 {"version":3,"sources":["../src/getPropertyByPath.ts"],"names":["getPropertyByPath","source","path","Object","prototype","hasOwnProperty","call","parsedPath","split","reduce","previous","key","undefined"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAT,CACEC,MADF,EAEEC,IAFF,EAGW;AACT,MACE,OAAOA,IAAP,KAAgB,QAAhB,IACAC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCL,MAArC,EAA6CC,IAA7C,CAFF,EAGE;AACA,WAAOD,MAAM,CAACC,IAAD,CAAb;AACD;;AAED,QAAMK,UAAU,GAAG,OAAOL,IAAP,KAAgB,QAAhB,GAA2BA,IAAI,CAACM,KAAL,CAAW,GAAX,CAA3B,GAA6CN,IAAhE,CARS,CAST;;AACA,SAAOK,UAAU,CAACE,MAAX,CAAkB,CAACC,QAAD,EAAgBC,GAAhB,KAAiC;AACxD,QAAID,QAAQ,KAAKE,SAAjB,EAA4B;AAC1B,aAAOF,QAAP;AACD;;AACD,WAAOA,QAAQ,CAACC,GAAD,CAAf;AACD,GALM,EAKJV,MALI,CAAP;AAMD","sourcesContent":["// Resolves property names or property paths defined with period-delimited\n// strings or arrays of strings. Property names that are found on the source\n// object are used directly (even if they include a period).\n// Nested property names that include periods, within a path, are only\n// understood in array paths.\nfunction getPropertyByPath(\n source: { [key: string]: unknown },\n path: string | Array<string>,\n): unknown {\n if (\n typeof path === 'string' &&\n Object.prototype.hasOwnProperty.call(source, path)\n ) {\n return source[path];\n }\n\n const parsedPath = typeof path === 'string' ? path.split('.') : path;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return parsedPath.reduce((previous: any, key): unknown => {\n if (previous === undefined) {\n return previous;\n }\n return previous[key];\n }, source);\n}\n\nexport { getPropertyByPath };\n"],"file":"getPropertyByPath.js"} dist/types.d.ts 0000755 00000001173 15074777051 0007467 0 ustar 00 import { Loader, LoaderSync, Options, OptionsSync } from './index'; export declare type Config = any; export declare type CosmiconfigResult = { config: Config; filepath: string; isEmpty?: boolean; } | null; export interface ExplorerOptions extends Required<Options> { } export interface ExplorerOptionsSync extends Required<OptionsSync> { } export declare type Cache = Map<string, CosmiconfigResult>; export declare type LoadedFileContent = Config | null | undefined; export interface Loaders { [key: string]: Loader; } export interface LoadersSync { [key: string]: LoaderSync; } //# sourceMappingURL=types.d.ts.map dist/index.js 0000755 00000005666 15074777051 0007211 0 ustar 00 "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cosmiconfig = cosmiconfig; exports.cosmiconfigSync = cosmiconfigSync; exports.defaultLoaders = void 0; var _os = _interopRequireDefault(require("os")); var _Explorer = require("./Explorer"); var _ExplorerSync = require("./ExplorerSync"); var _loaders = require("./loaders"); var _types = require("./types"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type function cosmiconfig(moduleName, options = {}) { const normalizedOptions = normalizeOptions(moduleName, options); const explorer = new _Explorer.Explorer(normalizedOptions); return { search: explorer.search.bind(explorer), load: explorer.load.bind(explorer), clearLoadCache: explorer.clearLoadCache.bind(explorer), clearSearchCache: explorer.clearSearchCache.bind(explorer), clearCaches: explorer.clearCaches.bind(explorer) }; } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type function cosmiconfigSync(moduleName, options = {}) { const normalizedOptions = normalizeOptions(moduleName, options); const explorerSync = new _ExplorerSync.ExplorerSync(normalizedOptions); return { search: explorerSync.searchSync.bind(explorerSync), load: explorerSync.loadSync.bind(explorerSync), clearLoadCache: explorerSync.clearLoadCache.bind(explorerSync), clearSearchCache: explorerSync.clearSearchCache.bind(explorerSync), clearCaches: explorerSync.clearCaches.bind(explorerSync) }; } // do not allow mutation of default loaders. Make sure it is set inside options const defaultLoaders = Object.freeze({ '.cjs': _loaders.loaders.loadJs, '.js': _loaders.loaders.loadJs, '.json': _loaders.loaders.loadJson, '.yaml': _loaders.loaders.loadYaml, '.yml': _loaders.loaders.loadYaml, noExt: _loaders.loaders.loadYaml }); exports.defaultLoaders = defaultLoaders; const identity = function identity(x) { return x; }; function normalizeOptions(moduleName, options) { const defaults = { packageProp: moduleName, searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${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`], ignoreEmptySearchPlaces: true, stopDir: _os.default.homedir(), cache: true, transform: identity, loaders: defaultLoaders }; const normalizedOptions = { ...defaults, ...options, loaders: { ...defaults.loaders, ...options.loaders } }; return normalizedOptions; } //# sourceMappingURL=index.js.map
SAVE
CANCEL