Skip to content

Commit

Permalink
feat: support loading rc from workspace dir in global mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 6, 2022
1 parent cf84cc9 commit 7365a9c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .configrc
@@ -0,0 +1 @@
testConfig=true
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -33,6 +33,7 @@
"jiti": "^1.15.0",
"mlly": "^0.5.14",
"pathe": "^0.3.7",
"pkg-types": "^0.3.5",
"rc9": "^1.2.2"
},
"devDependencies": {
Expand Down
10 changes: 6 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/loader.ts
Expand Up @@ -4,6 +4,7 @@ import { resolve, extname, dirname } from 'pathe'
import createJiti, { JITI } from 'jiti'
import * as rc9 from 'rc9'
import { defu } from 'defu'
import { findWorkspaceDir } from 'pkg-types'
import type { JITIOptions } from 'jiti/dist/types'
import { DotenvOptions, setupDotenv } from './dotenv'

Expand Down Expand Up @@ -96,6 +97,10 @@ export async function loadConfig<T extends InputConfig=InputConfig> (opts: LoadC
if (opts.rcFile) {
if (opts.globalRc) {
Object.assign(configRC, rc9.readUser({ name: opts.rcFile, dir: opts.cwd }))
const workspaceDir = await findWorkspaceDir(opts.cwd).catch(() => null)
if (workspaceDir) {
Object.assign(configRC, rc9.read({ name: opts.rcFile, dir: workspaceDir }))
}
}
Object.assign(configRC, rc9.read({ name: opts.rcFile, dir: opts.cwd }))
}
Expand Down
3 changes: 3 additions & 0 deletions test/index.test.ts
Expand Up @@ -11,6 +11,7 @@ describe('c12', () => {
const { config, layers } = await loadConfig({
cwd: r('./fixture'),
dotenv: true,
globalRc: true,
extend: {
extendKey: ['theme', 'extends']
},
Expand Down Expand Up @@ -46,6 +47,7 @@ describe('c12', () => {
"npmConfig": true,
"overriden": true,
"rcFile": true,
"testConfig": true,
"virtual": true,
}
`)
Expand Down Expand Up @@ -82,6 +84,7 @@ describe('c12', () => {
{
"config": {
"rcFile": true,
"testConfig": true,
},
"configFile": ".configrc",
},
Expand Down

0 comments on commit 7365a9c

Please sign in to comment.