Skip to content

Commit

Permalink
added: usage impl
Browse files Browse the repository at this point in the history
  • Loading branch information
binjospookie committed Dec 27, 2023
1 parent 8a189af commit 49c84fc
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 23 deletions.
8 changes: 4 additions & 4 deletions bin/getExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { readFile, ObservableSet } from './utils/index.js'
/**
* @param {{
* config: {
* entry: string,
* babelPlugins: Set<string>,
* },
* entry: string
* babelPlugins: Set<string>
* }
* pkg: {
* path: string
* },
* }
* }}
*
* @returns {Promise<Set.<string>>}
Expand Down
10 changes: 5 additions & 5 deletions bin/getUnusedExports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const getRepoRoot = () =>
* babelPlugins: Set<string>
* batch: {
* default: number
* },
* },
* }
* }
* pkg: {
* name: string
* path: string
* },
* path?: string
* }
* }}
*
* @returns {Promise<Set.<string>>}
Expand All @@ -32,7 +32,7 @@ const getUnusedExports = async ({ config, pkg, cmd }) => {
const source = join(repoRoot, '**', '*.{ts,tsx}')
const ignore = [
...[...config.exclude].map(x => join('**', x, '**')),
join(pkg.path, '**')
pkg.path ? join(pkg.path, '**') : ''
]

let batch = []
Expand Down
2 changes: 1 addition & 1 deletion bin/getUnusedExports/processBatch/findImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pipeline } from 'node:stream/promises'

/**
* @param {{
* file: string,
* file: string
* tokens: Array<string>
* }}
*/
Expand Down
12 changes: 6 additions & 6 deletions bin/getUnusedExports/processBatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { traverse } from './traverse.js'
* @param {{
* cmd: {function(_: string): void}
* config: {
* babelPlugins: Set<string>,
* },
* files: Array<string>,
* babelPlugins: Set<string>
* }
* files: Array<string>
* pkg: {
* name: string,
* },
* tokens: Array<string>,
* name: string
* }
* tokens: Array<string>
* }}
*
*/
Expand Down
4 changes: 2 additions & 2 deletions bin/getUnusedExports/processBatch/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { readFile } from '../../utils/index.js'
* file: string
* pkg: {
* name: string
* },
* }
* config: {
* babelPlugins: Set<string>
* },
* }
* }}
*/
const traverse = async ({ file, pkg, config, cmd }) => {
Expand Down
11 changes: 11 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/usr/bin/env node

import { getConfig } from './getConfig.js'
import { getUnusedExports } from './getUnusedExports/index.js'
import { main } from './main.js'

const config = await getConfig()

if (config.collectUsages) {
const usages = new Set()

await getUnusedExports({
config,
pkg: { name: config.collectUsages, path: '' },
cmd: usages.add.bind(usages)
})

console.log(usages)

process.exit(0)
}

Expand Down
8 changes: 4 additions & 4 deletions bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { createStatusAPI, readJSON } from './utils/index.js'
/**
* @param {{
* config: {
* entry: string,
* exclude: Set<string>,
* babelPlugins: Set<string>,
* entry: string
* exclude: Set<string>
* babelPlugins: Set<string>
* batch: {
* default: number
* },
* }
* },
* }}
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pure-index",
"type": "module",
"version": "0.0.19",
"version": "0.0.22",
"description": "Utility for monorepos. It helps to find unused exports from packages.",
"main": "./bin/index.js",
"bin": "./bin/index.js",
Expand Down

0 comments on commit 49c84fc

Please sign in to comment.