Skip to content

Commit

Permalink
refactor(config): consolidate defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Aug 14, 2023
1 parent 463c936 commit fa85cda
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -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: '✘',
Expand Down Expand Up @@ -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;
10 changes: 5 additions & 5 deletions src/get-package-json-files/get-patterns/get-patterns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});

Expand All @@ -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);
});
});

Expand All @@ -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);
});
});
4 changes: 2 additions & 2 deletions src/get-package-json-files/get-patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,7 +27,7 @@ export function getPatterns(config: Ctx['config']): Effect.Effect<Env, never, st
option,
O.map(addRootDir),
O.map(limitToPackageJson),
O.getOrElse(() => DEFAULT_SOURCES),
O.getOrElse(() => [...DEFAULT_CONFIG.source]),
),
),
);
Expand Down

0 comments on commit fa85cda

Please sign in to comment.