Skip to content

Commit

Permalink
fix: warn when extend layers cannot be resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 29, 2022
1 parent b1ec512 commit f6506e8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DotenvOptions, setupDotenv } from './dotenv'
export interface InputConfig extends Record<string, any> {}

export interface ConfigLayer<T extends InputConfig=InputConfig> {
config: T
config: T | null
cwd?: string
configFile?: string
}
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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) { }
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export default {
extends: [
'./theme',
'./config.dev'
'./config.dev',
'c12-npm-test'
],
colors: {
primary: 'user_primary'
Expand Down
1 change: 1 addition & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('c12', () => {
"extends": [
"./theme",
"./config.dev",
"c12-npm-test",
],
"overriden": false,
},
Expand Down

0 comments on commit f6506e8

Please sign in to comment.