pure-index
Advanced tools
Comparing version 0.0.40 to 0.0.41
@@ -38,21 +38,21 @@ #!/usr/bin/env node | ||
if (!result.success) { | ||
spinner.error() | ||
if (result.success) { | ||
spinner.success() | ||
process.exit(0) | ||
} | ||
switch (result.error.reason) { | ||
case 'no_exports': | ||
printError(`Nothing is exported from ${pkg.name}. Remove it.`) | ||
break | ||
case 'no_imports': | ||
printError(`Nothing is imported from ${pkg.name}. Remove it.`) | ||
break | ||
case 'unused_exports': | ||
printError(`Unused exports in ${pkg.name} package found`) | ||
printSet(result.error.exports) | ||
} | ||
spinner.error() | ||
process.exit(1) | ||
switch (result.error.reason) { | ||
case 'no_exports': | ||
printError(`Nothing is exported from ${pkg.name}. Remove it.`) | ||
break | ||
case 'no_imports': | ||
printError(`Nothing is imported from ${pkg.name}. Remove it.`) | ||
break | ||
case 'unused_exports': | ||
printError(`Unused exports in ${pkg.name} package found`) | ||
printSet(result.error.exports) | ||
} | ||
spinner.success() | ||
process.exit(0) | ||
process.exit(1) |
{ | ||
"name": "pure-index", | ||
"type": "module", | ||
"version": "0.0.40", | ||
"version": "0.0.41", | ||
"description": "Utility for monorepos. It helps to find unused exports from packages or get a list of all unique uses of any package", | ||
"main": "./src/index.js", | ||
"main": "./src/api/index.js", | ||
"bin": "./bin/index.js", | ||
@@ -25,2 +25,3 @@ "author": "Viktor Pasynok", | ||
"devDependencies": { | ||
"@swc/core": "^1.3.101", | ||
"prettier": "3.1.1", | ||
@@ -27,0 +28,0 @@ "vitest": "1.1.0" |
@@ -5,17 +5,2 @@ import { getExports } from './getExports.js' | ||
/** | ||
* @param {{ | ||
* config: { | ||
* babelPlugins: Array<string> | ||
* batch: number | ||
* entry: string | ||
* exclude: Set<string> | ||
* extensions: Array<string> | ||
* dir: string | ||
* } | ||
* pkg: { | ||
* path: string | ||
* } | ||
* }} | ||
*/ | ||
const baseFlow = async ({ pkg, config, onEmpty }) => { | ||
@@ -32,3 +17,3 @@ const exports = await getExports({ config, pkg }) | ||
if (originalExportsSize === 0) { | ||
resolve(Result.Err({ reason: 'no_exports' })) | ||
resolve(Result.Err({ reason: 'no_exports', exports })) | ||
} | ||
@@ -39,6 +24,6 @@ | ||
if (exports.size === originalExportsSize) { | ||
resolve(Result.Err({ reason: 'no_imports' })) | ||
resolve(Result.Err({ reason: 'no_imports', exports })) | ||
} | ||
resolve(Result.Err({ exports, reason: 'unused_exports' })) | ||
resolve(Result.Err({ reason: 'unused_exports', exports })) | ||
}) | ||
@@ -45,0 +30,0 @@ } |
import { fileTraversal } from './fileTraversal/index.js' | ||
import { Result } from './utils/index.js' | ||
/** | ||
* @param {{ | ||
* config: { | ||
* babelPlugins: Array<string> | ||
* batch: number | ||
* collectUsages: string | ||
* exclude: Set<string> | ||
* extensions: Array<string> | ||
* dir: string | ||
* }, | ||
* }} | ||
*/ | ||
const collectUsages = async ({ config }) => { | ||
@@ -17,0 +5,0 @@ const pkg = { name: config.collectUsages, path: '' } |
@@ -7,17 +7,2 @@ import { join } from 'node:path' | ||
/** | ||
* @param {{ | ||
* config: { | ||
* exclude: Set<string> | ||
* extensions: Array<string> | ||
* dir: string | ||
* } | ||
* pkg: { | ||
* name: string | ||
* path?: string | ||
* } | ||
* }} | ||
* | ||
* @returns {Array<string>} | ||
*/ | ||
const getFiles = async ({ config, pkg }) => { | ||
@@ -24,0 +9,0 @@ if (pkg.path) { |
import { processBatch } from './processBatch/index.js' | ||
import { getFiles } from './getFiles.js' | ||
/** | ||
* @param {{ | ||
* cmd: {function(_: string): void} | ||
* config: { | ||
* babelPlugins: Array<string> | ||
* batch: number | ||
* exclude: Set<string> | ||
* extensions: Array<string> | ||
* dir: string | ||
* } | ||
* pkg: { | ||
* name: string | ||
* path?: string | ||
* } | ||
* }} | ||
* | ||
* @returns {Promise<Set.<string>>} | ||
*/ | ||
const fileTraversal = async ({ config, pkg, cmd }) => { | ||
@@ -23,0 +5,0 @@ const files = await getFiles({ config, pkg }) |
@@ -5,8 +5,2 @@ import { createReadStream } from 'node:fs' | ||
/** | ||
* @param {{ | ||
* file: string | ||
* tokens: Array<string> | ||
* }} | ||
*/ | ||
const findImport = ({ file, tokens }) => | ||
@@ -13,0 +7,0 @@ new Promise((resolve, reject) => { |
import { findImport } from './findImport.js' | ||
import { traversal } from './traversal.js' | ||
/** | ||
* @param {{ | ||
* files: Array<string> | ||
* cmd: {function(_: string): void} | ||
* config: { | ||
* babelPlugins: Array<string> | ||
* } | ||
* pkg: { | ||
* name: string | ||
* } | ||
* tokens: Array<string> | ||
* }} | ||
* | ||
*/ | ||
const processBatch = async ({ config, cmd, files, pkg, tokens }) => { | ||
@@ -19,0 +5,0 @@ const filesPromise = files.map(async file => { |
@@ -1,26 +0,15 @@ | ||
import { parse } from '@babel/parser' | ||
import { parse } from '@swc/core' | ||
import { readFile } from '../../utils/index.js' | ||
/** | ||
* @param {{ | ||
* file: string | ||
* cmd: {function(_: string): void} | ||
* config: { | ||
* babelPlugins: Array<string> | ||
* } | ||
* pkg: { | ||
* name: string | ||
* } | ||
* }} | ||
*/ | ||
const traversal = async ({ file, pkg, config, cmd }) => { | ||
const code = await readFile(file) | ||
const ast = parse(code, { | ||
sourceType: 'module', | ||
plugins: config.babelPlugins | ||
const ast = await parse(code, { | ||
syntax: 'typescript', // "ecmascript" | "typescript" | ||
comments: false, | ||
target: 'esnext' | ||
}) | ||
for (const node of ast.program.body) { | ||
for (const node of ast.body) { | ||
if (node.type === 'ImportDeclaration' && node.source.value === pkg.name) { | ||
@@ -27,0 +16,0 @@ for (const specifier of node.specifiers) { |
@@ -5,14 +5,2 @@ import parser from '@babel/parser' | ||
/** | ||
* @param {{ | ||
* config: { | ||
* babelPlugins: Array<string> | ||
* } | ||
* pkg: { | ||
* path: string | ||
* } | ||
* }} | ||
* | ||
* @returns {Promise<Set.<string>>} | ||
*/ | ||
const getExports = async ({ config, pkg }) => { | ||
@@ -19,0 +7,0 @@ const code = await readFile(pkg.path) |
@@ -9,3 +9,2 @@ class ObservableSet extends Set { | ||
super.add(value) | ||
this.checkSize() | ||
} | ||
@@ -12,0 +11,0 @@ |
47
33526
3
702