pure-index
Advanced tools
Comparing version 1.0.0-next.3 to 1.0.0-next.4
import { findUnusedExports as _findUnusedExports } from '../findUnusedExports.js'; | ||
import { type Config } from '../getConfig/index.js'; | ||
import { type NonEmptyArray, ObservableSet } from '../shared/index.js'; | ||
type TaskResult = Awaited<ReturnType<typeof _findUnusedExports>>; | ||
@@ -13,2 +14,20 @@ type FailedTaks = Extract<TaskResult, { | ||
}; | ||
declare const SUCCESS: { | ||
readonly ok: true; | ||
readonly val: { | ||
exports: Set<void>; | ||
}; | ||
}; | ||
export declare const mergeUnusedExports: (list: NonEmptyArray<import("../shared/index.js").Result<{ | ||
exports: ObservableSet; | ||
}, { | ||
reason: "no_exports"; | ||
exports: ObservableSet; | ||
} | { | ||
reason: "no_imports"; | ||
exports: ObservableSet; | ||
} | { | ||
reason: "unused_exports"; | ||
exports: ObservableSet; | ||
}>>) => ExtractError<'unused_exports'> | typeof SUCCESS; | ||
type Params = { | ||
@@ -25,3 +44,3 @@ entry: string; | ||
}; | ||
declare const findUnusedExports: ({ entry, location }: Params, list: ListItem[]) => Promise<ExtractError<"unused_exports"> | { | ||
declare const findUnusedExports: ({ entry, location }: Params, list: ListItem[]) => Promise<{ | ||
readonly ok: true; | ||
@@ -31,3 +50,3 @@ readonly val: { | ||
}; | ||
} | ExtractError<"no_exports"> | ExtractError<"no_imports">>; | ||
} | ExtractError<"unused_exports"> | ExtractError<"no_exports"> | ExtractError<"no_imports">>; | ||
export { findUnusedExports }; |
import { join } from 'node:path'; | ||
import { findUnusedExports as _findUnusedExports } from '../findUnusedExports.js'; | ||
import { mergeConfig } from '../getConfig/index.js'; | ||
import { readJSON, Ok, Err } from '../shared/index.js'; | ||
const mergeUnusedExports = (list) => { | ||
const [head, ...tail] = list.reduce((acc, res) => { | ||
import { readJSON, Ok, Err, ObservableSet } from '../shared/index.js'; | ||
const SUCCESS = Ok({ exports: new Set() }); | ||
export const mergeUnusedExports = (list) => { | ||
const sets = list.reduce((acc, res) => { | ||
if (!res.ok) { | ||
@@ -12,13 +13,5 @@ acc.push(res.err.exports); | ||
}, []); | ||
if (tail.length) { | ||
return Err({ reason: 'unused_exports', exports: head }); | ||
} | ||
for (const set of tail) { | ||
for (const item of head) { | ||
if (!set.has(item)) { | ||
head.delete(item); | ||
} | ||
} | ||
} | ||
return Err({ reason: 'unused_exports', exports: head }); | ||
const smallestSet = sets.reduce((acc, set) => (set.size < acc.size ? set : acc), sets[0]); | ||
const unused = [...smallestSet].filter((exp) => sets.every((set) => set.has(exp))); | ||
return unused.length === 0 ? SUCCESS : Err({ reason: 'unused_exports', exports: new ObservableSet(unused) }); | ||
}; | ||
@@ -34,3 +27,3 @@ const findUnusedExports = async ({ entry, location = '' }, list) => { | ||
if (result.some((x) => x.ok)) { | ||
return Ok({ exports: new Set() }); | ||
return SUCCESS; | ||
} | ||
@@ -37,0 +30,0 @@ const [head] = result; |
import { extname } from 'node:path'; | ||
import { fdir } from 'fdir'; | ||
// @ts-expect-error doesn't matter | ||
import pm from 'picomatch'; | ||
// fixme: https://github.com/space307/pure-index/issues/10 | ||
const getFiles = async ({ config }) => { | ||
const exclude = new Set(config.exclude); | ||
const extensions = new Set(config.extensions); | ||
const isMatch = pm(config.exclude); | ||
const files = new fdir() | ||
.exclude((dirName) => exclude.has(dirName)) | ||
.exclude((_, dirPath) => isMatch(dirPath)) | ||
.filter((path) => extensions.has(extname(path))) | ||
@@ -10,0 +12,0 @@ .withBasePath() |
@@ -10,3 +10,3 @@ import { lilconfig } from 'lilconfig'; | ||
entry: join('src', 'index.ts'), | ||
exclude: ['node_modules'], | ||
exclude: ['**/node_modules/**'], | ||
extensions: ['.ts', '.tsx'], | ||
@@ -13,0 +13,0 @@ parserConfig: { |
@@ -83,3 +83,3 @@ import { existsSync } from 'node:fs'; | ||
} | ||
if (node.type === 'ExportAllDeclaration') { | ||
else if (node.type === 'ExportAllDeclaration') { | ||
printExportAllError(pkg); | ||
@@ -86,0 +86,0 @@ process.exit(1); |
{ | ||
"name": "pure-index", | ||
"type": "module", | ||
"version": "1.0.0-next.3", | ||
"version": "1.0.0-next.4", | ||
"description": "Pure Index is a tool for packages. It helps to clean your packages of unused exports with ease.", | ||
@@ -24,3 +24,4 @@ "main": "./dist/api/index.js", | ||
"meow": "13.1.0", | ||
"nanospinner": "1.1.0" | ||
"nanospinner": "1.1.0", | ||
"picomatch": "3.0.1" | ||
}, | ||
@@ -31,3 +32,3 @@ "engines": { | ||
"devDependencies": { | ||
"@types/node": "20.10.8", | ||
"@types/node": "20.11.0", | ||
"@vitest/coverage-v8": "1.1.3", | ||
@@ -34,0 +35,0 @@ "effector": "23.1.0", |
27857
680
6
+ Addedpicomatch@3.0.1
+ Addedpicomatch@3.0.1(transitive)