-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ea2d8f
commit 876154d
Showing
5 changed files
with
46 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/js-api/collectUsages.test.js → src/api/__tests__/collectUsages.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { collectUsages as _collectUsages } from '../collectUsages.js' | ||
import { BASE_CONFIG } from '../getConfig.js' | ||
import { Result } from '../utils/index.js' | ||
|
||
// name and list[0].dir are required | ||
const collectUsages = async (name, list) => { | ||
const tasks = list.map(x => | ||
_collectUsages({ | ||
config: { | ||
babelPlugins: x.babelPlugins || BASE_CONFIG.babelPlugins, | ||
batch: x.batch || BASE_CONFIG.batch, | ||
exclude: x.exclude | ||
? new Set([...BASE_CONFIG.exclude, ...x.exclude]) | ||
: BASE_CONFIG.exclude, | ||
extensions: x.extensions || BASE_CONFIG.extensions, | ||
dir: x.dir || BASE_CONFIG.dir, | ||
collectUsages: name | ||
} | ||
}) | ||
) | ||
|
||
const result = await Promise.all(tasks) | ||
|
||
const mergedUsages = result.reduce((acc, x) => { | ||
if (x.success) { | ||
acc = acc.concat([...x.value.usages]) | ||
} | ||
|
||
return acc | ||
}, []) | ||
|
||
return mergedUsages.length === 0 | ||
? Result.Err({ usages: new Set() }) | ||
: Result.Ok({ usages: new Set(mergedUsages) }) | ||
} | ||
|
||
export { collectUsages } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { collectUsages } from './collectUsages.js' | ||
export { findUnusedExports } from './findUnusedExports.js' |