Skip to content

Commit

Permalink
changed: search-dir to dir
Browse files Browse the repository at this point in the history
  • Loading branch information
binjospookie committed Dec 29, 2023
1 parent 199df9c commit 5cba59a
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 30 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Pure Index supports three ways to define config.
"entry": "index.ts",
"exclude": ["node_modules"],
"extensions": ["ts", "tsx"],
"searchDir": "my-path",
"dir": "my-path",
"babelPlugins": ["typescript"],
"batch": 100
}
Expand All @@ -71,7 +71,7 @@ Pure Index supports three ways to define config.
"entry": "index.ts",
"exclude": ["node_modules"],
"extensions": ["ts", "tsx"],
"searchDir": "my-path",
"dir": "my-path",
"babelPlugins": ["typescript"],
"batch": 100
}
Expand All @@ -84,7 +84,7 @@ module.exports = {
entry: 'index.ts',
exclude: ['node_modules'],
extensions: ['ts', 'tsx'],
searchDir: 'my-path',
dir: 'my-path',
babelPlugins: ['typescript'],
batch: 100
}
Expand All @@ -103,7 +103,7 @@ List of file extensions to be considered during the search. Default: `[ts,tsx]`
- `entry (String)` — path to the package index file. relative to the package directory.
- `extensions (Array<string>)` — list of file extensions to be considered during the search.
- `exclude (Array<string>)` — list of directories that will be excluded when searching for imports.
- `searchDir (String)` — path to the directory where imports should be searched for.
- `dir (String)` — path to the directory where imports should be searched for.
- `babelPlugins (Array<string>)` — list of babel plugins that will be used when parsing files.
- `batch (Number)` — number of files to be traversed in parallel. Changing the value may speed up or slow down the script. Choose the value yourself.

Expand Down Expand Up @@ -156,15 +156,15 @@ Allows to override the config values for package.

</details>

### `--search-dir, -s`
### `--dir, -d`

<details><summary><b>Show instructions</b></summary>

```diff
"scripts": {
"build": "webpack ./webpack.config.js",
- "check-exports": "pure-index",
+ "check-exports": "pure-index --search-dir /Users/user/another-repo",
+ "check-exports": "pure-index --dir /Users/user/another-repo",
"test": "vitest"
}
```
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/__snapshots__/search-dir.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`package-d 1`] = `
"
> check-exports
> node ../../../bin/index.js -s ../monorepo/app
> node ../../../bin/index.js -d ../monorepo/app
Failed Unused exports in package-d package found
Expand All @@ -18,7 +18,7 @@ exports[`package-d 1`] = `
exports[`package-d happy 1`] = `
"
> check-exports-happy
> node ../../../bin/index.js -s ../monorepo
> node ../../../bin/index.js -d ../monorepo
"
`;
Expand All @@ -31,7 +31,7 @@ exports[`package-d happy 2`] = `
exports[`package-d unhappy 1`] = `
"
> check-exports-unhappy
> node ../../../bin/index.js -s ../biba
> node ../../../bin/index.js -d ../biba
Failed Nothing is imported from package-d. Remove it.
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/getConfig/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('default value', async () => {
batch: 1,
babelPlugins: 'decorators-legacy,classPrivateProperties',
exclude: 'biba,boba,.cache,www/assets,__tests__',
searchDir: 'dir-from-cli'
dir: 'dir-from-cli'
}
}))
}))
Expand All @@ -35,7 +35,7 @@ test('default value', async () => {
'www/assets',
'__tests__'
]),
searchDir: 'dir-from-cli'
dir: 'dir-from-cli'
})

vi.resetAllMocks()
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/getConfig/config+cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('default value', async () => {
entry: 'src/index.ts',
exclude: ['build'],
extensions: ['js', 'jsx'],
searchDir: 'dir-from-cli'
dir: 'dir-from-cli'
}
})
})
Expand All @@ -28,7 +28,7 @@ test('default value', async () => {
batch: 1,
babelPlugins: 'decorators-legacy,classPrivateProperties',
exclude: 'biba,boba,.cache,www/assets,__tests__',
searchDir: 'dir-from-config'
dir: 'dir-from-config'
}
}))
}))
Expand All @@ -50,7 +50,7 @@ test('default value', async () => {
'www/assets',
'__tests__'
]),
searchDir: 'dir-from-cli'
dir: 'dir-from-cli'
})

vi.resetAllMocks()
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/getConfig/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export const CONFIG = {
entry: 'index.ts',
exclude: new Set(['node_modules']),
extensions: ['ts', 'tsx'],
searchDir: 'repo-root'
dir: 'repo-root'
}
4 changes: 2 additions & 2 deletions src/__tests__/getConfig/withconfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('default value', async () => {
entry: 'src/index.ts',
exclude: ['build'],
extensions: ['js', 'jsx'],
searchDir: 'dir-from-config'
dir: 'dir-from-config'
}
})
})
Expand All @@ -28,7 +28,7 @@ test('default value', async () => {
entry: 'src/index.ts',
extensions: ['js', 'jsx'],
exclude: new Set([...CONFIG.exclude, 'build']),
searchDir: 'dir-from-config'
dir: 'dir-from-config'
})

vi.resetAllMocks()
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/package-d/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "package-d",
"scripts": {
"check-exports": "node ../../../bin/index.js -s ../monorepo/app",
"check-exports-unhappy": "node ../../../bin/index.js -s ../biba",
"check-exports-happy": "node ../../../bin/index.js -s ../monorepo"
"check-exports": "node ../../../bin/index.js -d ../monorepo/app",
"check-exports-unhappy": "node ../../../bin/index.js -d ../biba",
"check-exports-happy": "node ../../../bin/index.js -d ../monorepo"
}
}
2 changes: 1 addition & 1 deletion src/collectUsages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createStatusAPI } from './utils/index.js'
* collectUsages: string
* exclude: Set<string>
* extensions: Array<string>
* searchDir: string
* dir: string
* },
* }}
*
Expand Down
4 changes: 2 additions & 2 deletions src/fileTraversal/getFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const formattedExtensions = list =>
* config: {
* exclude: Set<string>
* extensions: Array<string>
* searchDir: string
* dir: string
* }
* pkg: {
* name: string
Expand All @@ -36,7 +36,7 @@ const getFiles = async ({ config, pkg }) => {
.exclude(dirName => excludeRegExp.test(dirName))
.globWithOptions([source], { dot: false })
.withFullPaths()
.crawl(config.searchDir)
.crawl(config.dir)
.sync()

return files
Expand Down
2 changes: 1 addition & 1 deletion src/fileTraversal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getFiles } from './getFiles.js'
* batch: number
* exclude: Set<string>
* extensions: Array<string>
* searchDir: string
* dir: string
* }
* pkg: {
* name: string
Expand Down
10 changes: 5 additions & 5 deletions src/getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const BASE_CONFIG = {
batch: 100,
collectUsages: null,
entry: 'index.ts',
searchDir: null,
dir: null,
exclude: new Set(['node_modules']),
extensions: ['ts', 'tsx']
}
Expand All @@ -20,7 +20,7 @@ const cli = meow(
--entry, -e path to the package index file. relative to the package directory
--exclude, -i list of directories that will be excluded when searching for imports
--extensions, -x list of file extensions to be considered during the search
--search-dir, -s path to the directory where imports should be searched for
--dir, -d path to the directory where imports should be searched for
--babel-plugins, -p list of babel plugins that will be used when parsing files
--batch, -b number of files to be traversed in parallel
--collect-usages, -u outputs a list of all unique uses of the package
Expand All @@ -33,7 +33,7 @@ const cli = meow(
entry: { type: 'string', shortFlag: 'e' },
exclude: { type: 'string', shortFlag: 'i' },
extensions: { type: 'string', shortFlag: 'x' },
searchDir: { type: 'string', shortFlag: 's' },
dir: { type: 'string', shortFlag: 'd' },
babelPlugins: { type: 'string', shortFlag: 'p' },
batch: { type: 'number', shortFlag: 'b' },
collectUsages: { type: 'string', shortFlag: 'u' }
Expand All @@ -57,7 +57,7 @@ const getConfig = async () => {
entry = BASE_CONFIG.entry,
batch = BASE_CONFIG.batch,
extensions = BASE_CONFIG.extensions,
searchDir
dir
} = result.config

return result === null
Expand All @@ -75,7 +75,7 @@ const getConfig = async () => {
extensions: cli.flags.extensions
? cli.flags.extensions.split(',')
: extensions,
searchDir: cli.flags.searchDir || searchDir || getRepoRoot()
dir: cli.flags.dir || dir || getRepoRoot()
}
}

Expand Down
36 changes: 36 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { main } from './main.js'

/**
* @param {{
* config: {
* entry: string
* batch: number
* list: Array.<{
* babelPlugins: Array<string>
* exclude: Set<string>
* extensions
* dir
* }>
* },
* }}
*
* @returns {Promise<Array.<string>>}
*/
const find = ({ config }) => {
const unusedExports = new Set()

const tasks = config.list(x =>
main({
babelPlugins: x.babelPlugins,
batch: config.batch,
entry: config.entry,
exclude: x.exclude,
extensions: x.extensions,
dir: x.dir
})
)

const result = await Promise.all(tasks)
}

export { find }
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createStatusAPI, readJSON } from './utils/index.js'
* entry: string
* exclude: Set<string>
* extensions: Array<string>
* searchDir: string
* dir: string
* },
* }}
*
Expand Down

0 comments on commit 5cba59a

Please sign in to comment.