lint-staged
Advanced tools
Comparing version 12.1.1 to 12.1.2
@@ -61,9 +61,5 @@ import debug from 'debug' | ||
debugLog('Loading config using `lilconfig`') | ||
const inputConfig = configObject || (await loadConfig(configPath, logger)) | ||
const resolved = configObject | ||
? { config: configObject, filepath: '(input)' } | ||
: await loadConfig(configPath) | ||
if (!resolved) { | ||
if (!inputConfig) { | ||
logger.error(`${ConfigNotFoundError.message}.`) | ||
@@ -73,6 +69,4 @@ throw ConfigNotFoundError | ||
debugLog('Successfully loaded config from `%s`:\n%O', resolved.filepath, resolved.config) | ||
const config = validateConfig(inputConfig, logger) | ||
const config = validateConfig(resolved.config, logger) | ||
if (debug) { | ||
@@ -79,0 +73,0 @@ // Log using logger to be able to test through `consolemock`. |
@@ -0,4 +1,9 @@ | ||
import { pathToFileURL } from 'url' | ||
import debug from 'debug' | ||
import { lilconfig } from 'lilconfig' | ||
import YAML from 'yaml' | ||
const debugLog = debug('lint-staged:loadConfig') | ||
/** | ||
@@ -23,12 +28,8 @@ * The list of files `lint-staged` will read configuration | ||
/** exported for tests */ | ||
export const dynamicImport = (path) => | ||
import(path) | ||
.then((module) => module.default) | ||
.catch((error) => { | ||
console.error(error) | ||
throw error | ||
}) | ||
export const dynamicImport = (path) => import(pathToFileURL(path)).then((module) => module.default) | ||
const jsonParse = (path, content) => JSON.parse(content) | ||
const yamlParse = (path, content) => YAML.parse(content) | ||
/** | ||
@@ -45,5 +46,5 @@ * `lilconfig` doesn't support yaml files by default, | ||
'.cjs': dynamicImport, | ||
'.yaml': YAML.parse, | ||
'.yml': YAML.parse, | ||
noExt: YAML.parse, | ||
'.yaml': yamlParse, | ||
'.yml': yamlParse, | ||
noExt: yamlParse, | ||
} | ||
@@ -61,12 +62,28 @@ | ||
* @param {string} [configPath] | ||
* @param {Logger} [logger] | ||
*/ | ||
export const loadConfig = async (configPath) => { | ||
const explorer = lilconfig('lint-staged', { searchPlaces, loaders }) | ||
const result = await (configPath ? explorer.load(resolveConfig(configPath)) : explorer.search()) | ||
if (!result) return null | ||
export const loadConfig = async (configPath, logger) => { | ||
try { | ||
if (configPath) { | ||
debugLog('Loading configuration from `%s`...', configPath) | ||
} else { | ||
debugLog('Searching for configuration...') | ||
} | ||
const { config, filepath } = result | ||
const explorer = lilconfig('lint-staged', { searchPlaces, loaders }) | ||
// config is a promise when using the `dynamicImport` loader | ||
return { config: await config, filepath } | ||
const result = await (configPath ? explorer.load(resolveConfig(configPath)) : explorer.search()) | ||
if (!result) return null | ||
// config is a promise when using the `dynamicImport` loader | ||
const config = await result.config | ||
debugLog('Successfully loaded config from `%s`:\n%O', result.filepath, config) | ||
return config | ||
} catch (error) { | ||
debugLog('Failed to load configuration from `%s`', configPath) | ||
logger.error(error) | ||
return null | ||
} | ||
} |
{ | ||
"name": "lint-staged", | ||
"version": "12.1.1", | ||
"version": "12.1.2", | ||
"description": "Lint files staged by git", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
88610
1527
17