![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
pure-index
Advanced tools
Readme
Pure Index is utility for monorepos. It helps to find unused exports from packages or get a list of all unique uses of any package.
There is a package a
which exports 2 functions
// "a" package index.ts file
export const T = () => true
export { myFn } from './myFn'
only 1 function from the package is used in the project
// some file
import { T } from 'a'
This means that package a
exports myFn
for nothing, so we can remove its export and possibly remove all the code.
As the code base develops, a large number of such unnecessary exports may accumulate in the monorepo. Pure Index allows you to find such exports.
npm install --save-dev pure-index
check-exports
script in the package.json
of each package that needs to be checked "scripts": {
"build": "webpack ./webpack.config.js",
+ "check-exports": "pure-index",
"test": "vitest"
}
Configure
Use flags if you need to override the config values for package
Pure Index supports three ways to define config.
.pure-index.json
config file:{
"entry": "index.ts",
"exclude": ["node_modules"],
"extensions": ["ts", "tsx"],
"dir": "my-path",
"babelPlugins": ["typescript"],
"batch": 100
}
pure-index
section in package.json
: "pure-index": {
"entry": "index.ts",
"exclude": ["node_modules"],
"extensions": ["ts", "tsx"],
"dir": "my-path",
"babelPlugins": ["typescript"],
"batch": 100
}
.pure-index.js
or .pure-index.cjs
config file:module.exports = {
entry: 'index.ts',
exclude: ['node_modules'],
extensions: ['ts', 'tsx'],
dir: 'my-path',
babelPlugins: ['typescript'],
batch: 100
}
Path to the package index file. relative to the package directory. Default: 'lol'
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.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.Allows to override the config values for package.
--entry, -e
"scripts": {
"build": "webpack ./webpack.config.js",
- "check-exports": "pure-index",
+ "check-exports": "pure-index --entry ./src/index.ts",
"test": "vitest"
}
--extensions, -x
"scripts": {
"build": "webpack ./webpack.config.js",
- "check-exports": "pure-index",
+ "check-exports": "pure-index --extensions js,jsx,ts,tsx",
"test": "vitest"
}
--exclude, -i
"scripts": {
"build": "webpack ./webpack.config.js",
- "check-exports": "pure-index",
+ "check-exports": "pure-index --exclude .cache,www/assets",
"test": "vitest"
}
--dir, -d
"scripts": {
"build": "webpack ./webpack.config.js",
- "check-exports": "pure-index",
+ "check-exports": "pure-index --dir /Users/user/another-repo",
"test": "vitest"
}
--babel-plugins, -p
"scripts": {
"build": "webpack ./webpack.config.js",
- "check-exports": "pure-index",
+ "check-exports": "pure-index --babel-plugins typescript,classPrivateProperties",
"test": "vitest"
}
--batch, -b
"scripts": {
"build": "webpack ./webpack.config.js",
- "check-exports": "pure-index",
+ "check-exports": "pure-index --batch 500",
"test": "vitest"
}
--collect-usages, -u
Outputs a list of all unique uses of the package.
npx pure-index --collect-usages my-package
npx pure-index -u my-package
npx pure-index --collect-usages react-spring
npx pure-index -u react-spring
Useful if the package index file contains export *
syntax. Or to search for all uses of an external package. More info
In fact, the task is to compare all exports and imports of the package. Anything not imported but exported are unused exports.
Pure Index when getting a list of exports does not parse export *
to find out what is exported from there. For projects with this syntax, it may result in an inability to use the library. But Pure Index can help with replacing export *
. Just run it with the --collect-usages flag and replace export *
with named exports.
FAQs
Pure Index is a tool for packages. It helps to clean your packages of unused exports with ease.
We found that pure-index demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.