From fa85cdaa9e929cb7ff7f675d24d44142d723e2ce Mon Sep 17 00:00:00 2001 From: Jamie Mason Date: Sun, 13 Aug 2023 14:47:28 +0100 Subject: [PATCH] refactor(config): consolidate defaults --- src/constants.ts | 5 +---- .../get-patterns/get-patterns.spec.ts | 10 +++++----- src/get-package-json-files/get-patterns/index.ts | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index c7cf59fa..faf42a52 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,9 +1,6 @@ /** Single source of truth, intended to aid testing or to override */ export const CWD = process.env.MOCK_CWD || process.cwd(); -/** Where to search for packages if none are provided by the user */ -export const DEFAULT_SOURCES = ['package.json', 'packages/*/package.json']; - /** Single source of truth for icons used in output */ export const ICON = { cross: '✘', @@ -43,6 +40,6 @@ export const DEFAULT_CONFIG = { 'scripts', ], sortFirst: ['name', 'description', 'version', 'author'], - source: DEFAULT_SOURCES, + source: ['package.json', 'packages/*/package.json'], versionGroups: [], } as const; diff --git a/src/get-package-json-files/get-patterns/get-patterns.spec.ts b/src/get-package-json-files/get-patterns/get-patterns.spec.ts index 7a1e0d6f..01d8fed9 100644 --- a/src/get-package-json-files/get-patterns/get-patterns.spec.ts +++ b/src/get-package-json-files/get-patterns/get-patterns.spec.ts @@ -3,7 +3,7 @@ import * as Effect from '@effect/io/Effect'; import { getPatterns } from '.'; import type { MockEnv } from '../../../test/mock-env'; import { createMockEnv } from '../../../test/mock-env'; -import { DEFAULT_SOURCES } from '../../constants'; +import { DEFAULT_CONFIG } from '../../constants'; import { createEnv } from '../../env/create-env'; import { EnvTag } from '../../env/tags'; import type { Ctx } from '../../get-context'; @@ -19,7 +19,7 @@ function runSync(config: Ctx['config'], mockedEffects: MockEnv) { it('returns default patterns when nothing is available', () => { const env = createMockEnv(); const result = runSync({ cli: {}, rcFile: {} }, env); - expect(result).toEqual(DEFAULT_SOURCES); + expect(result).toEqual(DEFAULT_CONFIG.source); }); it('CLI --source options take precedence', () => { @@ -48,7 +48,7 @@ describe('Yarn takes precedence after CLI --source options', () => { } }); const result = runSync({ cli: {}, rcFile: {} }, env); - expect(result).toEqual(DEFAULT_SOURCES); + expect(result).toEqual(DEFAULT_CONFIG.source); }); }); @@ -68,7 +68,7 @@ describe('Pnpm takes precedence after Yarn', () => { throw new Error('Reason does not matter to this test'); }); const result = runSync({ cli: {}, rcFile: {} }, env); - expect(result).toEqual(DEFAULT_SOURCES); + expect(result).toEqual(DEFAULT_CONFIG.source); }); }); @@ -92,6 +92,6 @@ describe('Lerna takes precedence after Pnpm', () => { } }); const result = runSync({ cli: {}, rcFile: {} }, env); - expect(result).toEqual(DEFAULT_SOURCES); + expect(result).toEqual(DEFAULT_CONFIG.source); }); }); diff --git a/src/get-package-json-files/get-patterns/index.ts b/src/get-package-json-files/get-patterns/index.ts index 52ec5eb5..d9fa276a 100644 --- a/src/get-package-json-files/get-patterns/index.ts +++ b/src/get-package-json-files/get-patterns/index.ts @@ -3,7 +3,7 @@ import * as O from '@effect/data/Option'; import * as Effect from '@effect/io/Effect'; import { isArrayOfStrings } from 'tightrope/guard/is-array-of-strings'; import { getSource } from '../../config/get-source'; -import { DEFAULT_SOURCES } from '../../constants'; +import { DEFAULT_CONFIG } from '../../constants'; import type { Env } from '../../env/create-env'; import type { Ctx } from '../../get-context'; import { getLernaPatterns } from './get-lerna-patterns'; @@ -27,7 +27,7 @@ export function getPatterns(config: Ctx['config']): Effect.Effect DEFAULT_SOURCES), + O.getOrElse(() => [...DEFAULT_CONFIG.source]), ), ), );