pure-index
Advanced tools
Comparing version 0.0.54 to 0.0.55
@@ -13,2 +13,6 @@ import { findUnusedExports as _findUnusedExports } from '../findUnusedExports.js'; | ||
}; | ||
type Params = { | ||
entry: string; | ||
location?: string; | ||
}; | ||
type ListItem = { | ||
@@ -21,3 +25,3 @@ dir: Config['dir']; | ||
}; | ||
declare const findUnusedExports: (entry: string, list: ListItem[]) => Promise<ExtractError<"unused_exports"> | { | ||
declare const findUnusedExports: ({ entry, location }: Params, list: ListItem[]) => Promise<ExtractError<"unused_exports"> | { | ||
readonly ok: true; | ||
@@ -24,0 +28,0 @@ readonly val: { |
@@ -0,1 +1,2 @@ | ||
import { join } from 'node:path'; | ||
import { findUnusedExports as _findUnusedExports } from '../findUnusedExports.js'; | ||
@@ -23,5 +24,5 @@ import { mergeConfig } from '../getConfig/index.js'; | ||
}; | ||
const findUnusedExports = async (entry, list) => { | ||
const { name } = await readJSON('package.json'); | ||
const pkg = { name, path: entry }; | ||
const findUnusedExports = async ({ entry, location = '' }, list) => { | ||
const { name } = await readJSON(join(location, 'package.json')); | ||
const pkg = { name, path: join(location, entry) }; | ||
const tasks = list.map((x) => _findUnusedExports({ | ||
@@ -28,0 +29,0 @@ pkg, |
@@ -1,8 +0,6 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { type PathLike } from 'node:fs'; | ||
type Params = { | ||
path: PathLike; | ||
path: string; | ||
tokens: string[]; | ||
}; | ||
declare const findImport: ({ path, tokens }: Params) => Promise<unknown>; | ||
declare const findImport: ({ path, tokens }: Params) => Promise<Params['path'] | null>; | ||
export { findImport }; |
import { createReadStream } from 'node:fs'; | ||
import { Transform } from 'node:stream'; | ||
import { pipeline } from 'node:stream/promises'; | ||
const highWaterMark = 65536; // 64 * 1024 | ||
const findImport = ({ path, tokens }) => new Promise((resolve, reject) => { | ||
const transformStream = new Transform({ | ||
transform(chunk, _, callback) { | ||
if (chunk.includes(tokens[0]) || chunk.includes(tokens[1])) { | ||
this.push(chunk); | ||
resolve(true); | ||
this.destroy(); | ||
} | ||
else { | ||
callback(); | ||
} | ||
}, | ||
const readStream = createReadStream(path, { highWaterMark }); | ||
readStream.on('data', (chunk) => { | ||
if (tokens.some((token) => chunk.includes(token))) { | ||
readStream.destroy(); | ||
resolve(path); | ||
} | ||
}); | ||
pipeline(createReadStream(path), transformStream) | ||
.then(() => resolve(false)) | ||
.catch(reject); | ||
readStream.on('end', () => { | ||
resolve(null); | ||
}); | ||
readStream.on('error', reject); | ||
}); | ||
export { findImport }; |
@@ -1,3 +0,3 @@ | ||
import { type Cmd, type Pkg } from '../../shared/index.js'; | ||
import type { Config } from '../../getConfig/index.js'; | ||
import type { Cmd, Pkg } from '../../shared/index.js'; | ||
type Params = { | ||
@@ -4,0 +4,0 @@ cmd: Cmd; |
@@ -1,14 +0,11 @@ | ||
import { notNil } from '../../shared/index.js'; | ||
import { findImport } from './findImport.js'; | ||
import { traversal } from './traversal/index.js'; | ||
const processBatch = async ({ cmd, files, pkg, tokens, config }) => { | ||
const pathesPromise = files.map(async (path) => { | ||
const found = await findImport({ path, tokens }); | ||
return found ? path : null; | ||
const tasks = files.map(async (path) => { | ||
if (await findImport({ path, tokens })) { | ||
return traversal({ cmd, path, pkg, config }); | ||
} | ||
}); | ||
const filterPromise = (await Promise.all(pathesPromise)) | ||
.filter(notNil) | ||
.map((path) => traversal({ cmd, path, pkg, config })); | ||
await Promise.all(filterPromise); | ||
await Promise.all(tasks); | ||
}; | ||
export { processBatch }; |
@@ -0,4 +1,24 @@ | ||
import { existsSync } from 'node:fs'; | ||
import { parseFile } from '@swc/core'; | ||
import { ObservableSet } from '../shared/index.js'; | ||
import { ObservableSet, printError as _printError, Err } from '../shared/index.js'; | ||
const printError = (pkg) => { | ||
_printError({ | ||
text: ` | ||
Can't find ${pkg.name} index file ("${pkg.path}" provided) | ||
- if you do not have a .pure-index.json file: | ||
create one and specify "entry" | ||
https://space307.github.io/pure-index/reference/configuration | ||
- if you have a configuration file: | ||
use the pure-index command with the "--entry" flag. | ||
https://space307.github.io/pure-index/how-to/precisely-override-package-entry | ||
`, | ||
}); | ||
}; | ||
const getExports = async ({ pkg, config }) => { | ||
if (!existsSync(pkg.path)) { | ||
printError(pkg); | ||
throw new Error('invalid_entry'); | ||
} | ||
const result = new ObservableSet(); | ||
@@ -5,0 +25,0 @@ const ast = await parseFile(pkg.path, config.parserConfig); |
import type { ObservableSet } from './observableSet.js'; | ||
declare const notNil: <T>(x: T) => x is Exclude<T, null | undefined>; | ||
declare const readJSON: (filePath: string) => Promise<any>; | ||
@@ -24,3 +23,3 @@ declare const printSet: (x: Set<unknown>) => boolean; | ||
type Cmd = (_: string) => unknown; | ||
export { readJSON, printError, notNil, Ok, Err, printSet }; | ||
export { readJSON, printError, Ok, Err, printSet }; | ||
export { getRepoRoot } from './getRepoRoot.js'; | ||
@@ -27,0 +26,0 @@ export { ObservableSet } from './observableSet.js'; |
import { readFile } from 'node:fs/promises'; | ||
import pc from 'picocolors'; | ||
const { bgRed, bold } = pc; | ||
const isNil = (x) => x === null || x === undefined; | ||
const notNil = (x) => !isNil(x); | ||
const readJSON = async (filePath) => JSON.parse(await readFile(filePath, { encoding: 'utf-8' })); | ||
@@ -10,3 +8,3 @@ const printSet = (x) => process.stdout.write(`${JSON.stringify([...x], undefined, 2)} \n\n`); | ||
process.stdout.write(`\n${bold(bgRed(' Failed '))} ${opts.text}\n\n`); | ||
if (notNil(opts.set)) { | ||
if (opts.set) { | ||
printSet(opts.set); | ||
@@ -17,5 +15,5 @@ } | ||
const Err = (err) => ({ ok: false, err }); | ||
export { readJSON, printError, notNil, Ok, Err, printSet }; | ||
export { readJSON, printError, Ok, Err, printSet }; | ||
export { getRepoRoot } from './getRepoRoot.js'; | ||
export { ObservableSet } from './observableSet.js'; | ||
export { createSpinner } from 'nanospinner'; |
{ | ||
"name": "pure-index", | ||
"type": "module", | ||
"version": "0.0.54", | ||
"version": "0.0.55", | ||
"description": "Utility for monorepos. It helps to clean your packages of unused exports with ease", | ||
@@ -11,7 +11,7 @@ "main": "./dist/api/index.js", | ||
"license": "MIT", | ||
"files": ["dist"], | ||
"files": ["dist", "README.md", "CHANGELOG.md"], | ||
"private": false, | ||
"scripts": { | ||
"build": "rm -rf ./dist && tsc --project ./tsconfig.build.json && tsc-alias", | ||
"prepublishOnly": "npm run build", | ||
"prepublishOnly": "npm t && npm run build", | ||
"test": "vitest" | ||
@@ -23,3 +23,3 @@ }, | ||
"lilconfig": "3.0.0", | ||
"meow": "13.0.0", | ||
"meow": "13.1.0", | ||
"nanospinner": "1.1.0", | ||
@@ -33,3 +33,3 @@ "picomatch": "3.0.1" | ||
"@types/node": "20.10.6", | ||
"@vitest/coverage-v8": "1.1.1", | ||
"@vitest/coverage-v8": "1.1.3", | ||
"effector": "23.1.0", | ||
@@ -40,3 +40,3 @@ "prettier": "3.1.1", | ||
"vite-tsconfig-paths": "4.2.3", | ||
"vitest": "1.1.1" | ||
"vitest": "1.1.3" | ||
}, | ||
@@ -83,3 +83,5 @@ "repository": { | ||
"unused", | ||
"workspace" | ||
"workspace", | ||
"ease", | ||
"framework agnostic" | ||
], | ||
@@ -86,0 +88,0 @@ "volta": { |
# 🌿 Pure Index | ||
Pure Index is utility for packages. It helps to clean your packages of unused exports with ease. | ||
Pure Index is utility for packages. It helps to clean your packages of unused exports with ease.<br />And it's also very fast ⚡️ | ||
@@ -31,4 +31,24 @@ ## Motivation | ||
## Quick Start | ||
Pure Index can be used either through a [command line interface](https://space307.github.io/pure-index/intro/cli) with an optional [configuration file](https://space307.github.io/pure-index/reference/configuration), or else through its [JavaScript API](https://space307.github.io/pure-index/intro/js-api). | ||
1. Add the `check-exports` script in the `package.json` of each package that needs to be checked | ||
```diff | ||
"scripts": { | ||
+ "check-exports": "pure-index" | ||
} | ||
``` | ||
2. Run | ||
```sh | ||
npm run check-exports | ||
``` | ||
3. Depending on the project, you may need to [configure](https://space307.github.io/pure-index/reference/configuration) Pure Index. | ||
## Documentation | ||
For additional information, guides and api reference visit [our documentation site](https://space307.github.io/pure-index) |
25901
42
627
54
+ Addedmeow@13.1.0(transitive)
- Removedmeow@13.0.0(transitive)
Updatedmeow@13.1.0