diff --git a/.configrc b/.configrc new file mode 100644 index 0000000..bb3f791 --- /dev/null +++ b/.configrc @@ -0,0 +1 @@ +testConfig=true diff --git a/package.json b/package.json index f047eac..9e6f1fc 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 331f436..b0e25ed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,6 +10,7 @@ specifiers: jiti: ^1.15.0 mlly: ^0.5.14 pathe: ^0.3.7 + pkg-types: ^0.3.5 rc9: ^1.2.2 standard-version: ^9.5.0 typescript: ^4.8.2 @@ -23,6 +24,7 @@ dependencies: jiti: 1.15.0 mlly: 0.5.14 pathe: 0.3.7 + pkg-types: 0.3.5 rc9: 1.2.2 devDependencies: @@ -3059,7 +3061,7 @@ packages: dependencies: acorn: 8.8.0 pathe: 0.3.7 - pkg-types: 0.3.4 + pkg-types: 0.3.5 ufo: 0.8.5 /modify-values/1.0.1: @@ -3332,8 +3334,8 @@ packages: engines: {node: '>=4'} dev: true - /pkg-types/0.3.4: - resolution: {integrity: sha512-s214f/xkRpwlwVBToWq9Mu0XlU3HhZMYCnr2var8+jjbavBHh/VCh4pBLsJW29rJ//B1jb4HlpMIaNIMH+W2/w==} + /pkg-types/0.3.5: + resolution: {integrity: sha512-VkxCBFVgQhNHYk9subx+HOhZ4jzynH11ah63LZsprTKwPCWG9pfWBlkElWFbvkP9BVR0dP1jS9xPdhaHQNK74Q==} dependencies: jsonc-parser: 3.2.0 mlly: 0.5.14 @@ -3992,7 +3994,7 @@ packages: mlly: 0.5.14 mri: 1.2.0 pathe: 0.3.7 - pkg-types: 0.3.4 + pkg-types: 0.3.5 pretty-bytes: 6.0.0 rimraf: 3.0.2 rollup: 2.79.0 diff --git a/src/loader.ts b/src/loader.ts index 70cc3d3..1eedbf6 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -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' @@ -96,6 +97,10 @@ export async function loadConfig (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 })) } diff --git a/test/index.test.ts b/test/index.test.ts index 4650851..bcf6617 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -11,6 +11,7 @@ describe('c12', () => { const { config, layers } = await loadConfig({ cwd: r('./fixture'), dotenv: true, + globalRc: true, extend: { extendKey: ['theme', 'extends'] }, @@ -46,6 +47,7 @@ describe('c12', () => { "npmConfig": true, "overriden": true, "rcFile": true, + "testConfig": true, "virtual": true, } `) @@ -82,6 +84,7 @@ describe('c12', () => { { "config": { "rcFile": true, + "testConfig": true, }, "configFile": ".configrc", },