Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add barrel-less as feature toggle in config #147

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/lib/config/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const defaultConfig: SheriffConfig = {
tagging: {},
depRules: {},
excludeRoot: false,
enableBarrelLess: false,
log: false,
entryFile: '',
isConfigFileMissing: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`parse Config > should read value 1`] = `
""use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = void 0;
exports.a = 1;
"
`;
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
import * as ts from 'typescript';
import { parseConfig } from './parse-config';
import { toFsPath } from '../file-info/fs-path';
import { TsConfig } from '../file-info/ts-config';
import getFs, { useVirtualFs } from '../fs/getFs';
import { MissingTaggingWithoutAutoTagging } from '../error/user-error';
import '../test/expect.extensions';
import { parseConfig } from '../parse-config';
import { toFsPath } from '../../file-info/fs-path';
import getFs, { useVirtualFs } from '../../fs/getFs';
import { MissingTaggingWithoutAutoTagging } from '../../error/user-error';
import '../../test/expect.extensions';

describe('parse Config', () => {
it('should read value', () => {
Expand All @@ -15,20 +14,20 @@ describe('parse Config', () => {
compilerOptions: { module: ts.ModuleKind.NodeNext },
});

const result = eval(outputText) as TsConfig;
expect(result).toBe(1);
expect(outputText).toMatchSnapshot();
});

it('should the sheriff config', () => {
const tsCode = parseConfig(
toFsPath(__dirname + '/../test/sheriff.config.ts'),
toFsPath(__dirname + '/../../test/sheriff.config.ts'),
);
expect(Object.keys(tsCode)).toEqual([
'version',
'autoTagging',
'tagging',
'depRules',
'excludeRoot',
'enableBarrelLess',
'log',
'entryFile',
'isConfigFileMissing',
Expand Down Expand Up @@ -67,6 +66,7 @@ export const config: SheriffConfig = {
autoTagging: true,
tagging: {},
depRules: { noTag: 'noTag' },
enableBarrelLess: false,
excludeRoot: false,
log: false,
isConfigFileMissing: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/lib/config/user-sheriff-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export interface UserSheriffConfig {
*/
excludeRoot?: boolean;

/**
* Enable the barrel-less mode. Set to false by default.
*/
enableBarrelLess?: boolean;

/**
* enable internal logging and save it to `sheriff.log`
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/modules/find-module-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export type ModulePathMap = Record<FsPath, boolean>
*
* If a module has a barrel file and an internal, it is of type barrel file.
*/
export function findModulePaths(projectDirs: FsPath[], moduleConfig: TagConfig, barrelFileName: string): ModulePathMap {
const modulesWithoutBarrel = findModulePathsWithoutBarrel(projectDirs, moduleConfig);
export function findModulePaths(projectDirs: FsPath[], moduleConfig: TagConfig, barrelFileName: string, enableBarrelLess: boolean): ModulePathMap {
const modulesWithoutBarrel = enableBarrelLess ? findModulePathsWithoutBarrel(projectDirs, moduleConfig) : [];
const modulesWithBarrel = findModulePathsWithBarrel(projectDirs, barrelFileName);
const modulePaths: ModulePathMap = {};

Expand Down
Loading