From f6506e814520716908944be0d2845b489feac353 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 29 Jun 2022 13:49:08 +0200 Subject: [PATCH] fix: warn when extend layers cannot be resolved --- src/loader.ts | 7 +++++-- test/fixture/config.ts | 3 ++- test/index.test.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/loader.ts b/src/loader.ts index 90d88c6..a9c23a4 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -9,7 +9,7 @@ import { DotenvOptions, setupDotenv } from './dotenv' export interface InputConfig extends Record {} export interface ConfigLayer { - config: T + config: T | null cwd?: string configFile?: string } @@ -137,6 +137,9 @@ async function extendConfig (config, opts: LoadConfigOptions) { for (const extendSource of extendSources) { const _config = await resolveConfig(extendSource, opts) if (!_config.config) { + // TODO: Use error in next major versions + // eslint-disable-next-line no-console + console.warn(`Cannot extend config from ${extendSource} in ${opts.cwd}`) continue } await extendConfig(_config.config, { ...opts, cwd: _config.cwd }) @@ -173,7 +176,7 @@ async function resolveConfig (source: string, opts: LoadConfigOptions): Promise< const isDir = !extname(source) const cwd = resolve(opts.cwd, isDir ? source : dirname(source)) if (isDir) { source = opts.configFile } - const res: ResolvedConfig = { config: {}, cwd } + const res: ResolvedConfig = { config: null, cwd } try { res.configFile = jiti.resolve(resolve(cwd, source), { paths: [cwd] }) } catch (_err) { } diff --git a/test/fixture/config.ts b/test/fixture/config.ts index f1852c7..f52feaf 100644 --- a/test/fixture/config.ts +++ b/test/fixture/config.ts @@ -1,7 +1,8 @@ export default { extends: [ './theme', - './config.dev' + './config.dev', + 'c12-npm-test' ], colors: { primary: 'user_primary' diff --git a/test/index.test.ts b/test/index.test.ts index 61d289c..a1cf306 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -68,6 +68,7 @@ describe('c12', () => { "extends": [ "./theme", "./config.dev", + "c12-npm-test", ], "overriden": false, },