Skip to content

Commit

Permalink
removed: extra set
Browse files Browse the repository at this point in the history
  • Loading branch information
binjospookie committed Jan 2, 2024
1 parent cdc527b commit 5ff51db
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/api/collectUsages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const collectUsages = async (name: string, list: ListItem[]) => {
_collectUsages({
config: {
batch: x.batch || BASE_CONFIG.batch,
exclude: x.exclude ? new Set([...BASE_CONFIG.exclude, ...x.exclude]) : BASE_CONFIG.exclude,
exclude: x.exclude ? [...new Set([...BASE_CONFIG.exclude, ...x.exclude])] : BASE_CONFIG.exclude,
extensions: x.extensions || BASE_CONFIG.extensions,
dir: x.dir,
collectUsages: name,
Expand Down
2 changes: 1 addition & 1 deletion src/api/findUnusedExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const findUnusedExports = async (entry: string, list: ListItem[]) => {
pkg,
config: {
batch: x.batch || BASE_CONFIG.batch,
exclude: x.exclude ? new Set([...BASE_CONFIG.exclude, ...x.exclude]) : BASE_CONFIG.exclude,
exclude: x.exclude ? [...new Set([...BASE_CONFIG.exclude, ...x.exclude])] : BASE_CONFIG.exclude,
extensions: x.extensions || BASE_CONFIG.extensions,
dir: x.dir,
parserConfig: x.parserConfig || BASE_CONFIG.parserConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/fileTraversal/__tests__/getFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('getExports', async () => {
const files = await getFiles({
config: {
extensions: ['ts'],
exclude: new Set(['components']),
exclude: ['components'],
dir,
},
});
Expand Down
4 changes: 2 additions & 2 deletions src/fileTraversal/getFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type { Config } from '~/getConfig/index.js';
const formattedExtensions = (list: Config['extensions']) => list.join(',') + ',';

type Params = {
config: Pick<Config, 'extensions' | 'exclude' | 'dir'>;
config: Pick<Config, 'extensions' | 'dir' | 'exclude'>;
};

// fixme: https://github.com/space307/pure-index/issues/10
const getFiles = async ({ config }: Params) => {
const exclude = [...config.exclude]
const exclude = config.exclude
.map((item) => item.replace(/(^\/|\/$)/g, '').replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'))
.join('|');
const excludeRegExp = new RegExp(exclude);
Expand Down
2 changes: 1 addition & 1 deletion src/getConfig/__tests__/config+cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('default value', async () => {
collectUsages: 'package-a',
entry: 'src/main.js',
extensions: ['js', 'jsx'],
exclude: new Set(['node_modules', 'build']),
exclude: ['node_modules', 'build'],
dir: 'dir-from-config',
});

Expand Down
2 changes: 1 addition & 1 deletion src/getConfig/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('default value', async () => {
batch: 500,
entry: 'src/index.ts',
extensions: ['js', 'jsx'],
exclude: new Set([...BASE_CONFIG.exclude, 'build']),
exclude: [...BASE_CONFIG.exclude, 'build'],
dir: 'dir-from-config',
});

Expand Down
26 changes: 15 additions & 11 deletions src/getConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ import { getRepoRoot } from '~/shared/index.js';

import type { ParserConfig } from '@swc/core';

const BASE_CONFIG = {
type Config = {
batch: number;
collectUsages: string | null;
entry: string;
dir: string;
exclude: string[];
extensions: string[];
parserConfig: ParserConfig;
};

const BASE_CONFIG: Config = {
batch: 100,
collectUsages: null,
entry: 'index.ts',
dir: null,
exclude: new Set(['node_modules']),
dir: '',
exclude: ['node_modules'],
extensions: ['ts', 'tsx'],
parserConfig: {
syntax: 'typescript',
tsx: true,
} as ParserConfig,
};

type Config = Omit<typeof BASE_CONFIG, 'dir' | 'collectUsages' | 'parserConfig'> & {
dir: string;
collectUsages: string | null;
parserConfig: ParserConfig;
},
};

const getConfig = async (): Promise<Config> => {
Expand All @@ -42,7 +46,7 @@ const getConfig = async (): Promise<Config> => {
entry: cli.flags.entry || entry,
batch,
parserConfig,
exclude: new Set([...BASE_CONFIG.exclude, ...exclude]),
exclude: [...new Set([...BASE_CONFIG.exclude, ...exclude])],
collectUsages: cli.flags.collectUsages || BASE_CONFIG.collectUsages,
extensions,
dir: dir || getRepoRoot(),
Expand Down

0 comments on commit 5ff51db

Please sign in to comment.