Skip to content

Commit

Permalink
chore: v0.0.2 show bundled expo config plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
WookieFPV committed Jan 21, 2025
1 parent 46ce745 commit ea93f6b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 57 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,30 @@ npx list-config-plugins

```bash
> npx list-config-plugins
Config Plugin Overview
Config Plugin Overview:

Used packages:
Used Plugins:
🟩 expo-notifications
🟩 expo-screen-orientation
🟩 expo-splash-screen
🟩 react-native-compressor

Unused packages:
Bundled with Expo:
📦 expo-camera
📦 expo-dev-client
📦 expo-file-system

Unused Plugins:
🟥 @sentry/react-native
🟥 expo-camera
🟥 expo-dev-client
🟥 expo-file-system
```

## Features

- 🔍 Scans your project for available Expo config plugins
- ✅ Shows which plugins are currently in use
- 📦 Shows which plugins are automatically added by expo
- ❌ Identifies unused available plugins
- 📦 Supports all types of Expo configurations
- ⚙️ Supports all types of Expo configurations

## How It Works

Expand Down
70 changes: 49 additions & 21 deletions bun.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "list-config-plugins",
"version": "0.0.1",
"version": "0.0.2",
"description": "find available expo config plugins and see if their already used",
"author": {
"name": "WookieFPV (Lukas Müller)",
Expand All @@ -27,7 +27,7 @@
"typescript": "5.7.3"
},
"dependencies": {
"@expo/config": "10.0.8",
"cli-table3": "0.6.5"
"@expo/config": "^10.0.8",
"@expo/prebuild-config": "^8.0.25"
}
}
28 changes: 22 additions & 6 deletions src/detectionHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import fs from 'node:fs';
import type { ExpoCfg } from "./types";
import type { ExpoCfg, ExpoPlugin, UsageType } from "./types";
import { getLegacyExpoPlugins } from "@expo/prebuild-config";

const isPluginIncludedUsed = (pluginList: ExpoPlugin, pkg: string) =>
pluginList?.some(
(plugin) => {
if (typeof plugin === 'string' && plugin.startsWith(pkg)) return true
if (plugin[0] === pkg) return true
return plugin[0]?.startsWith(pkg);
}
) ?? false


export const getPluginImportType = (config: ExpoCfg, pkg: string): UsageType => {
const isManuallyIncluded = isPluginIncludedUsed(config.exp.plugins, pkg)
if (isManuallyIncluded) return "yes"

const isAutoIncluded = getLegacyExpoPlugins().some((plugin) => plugin.startsWith(pkg))
if (isAutoIncluded) return "auto"

return "no"
}

export const isPluginUsed = (config: ExpoCfg, pkg: string) =>
config.exp.plugins?.some(
(plugin) =>
(typeof plugin === 'string' && plugin.startsWith(pkg)) || plugin[0] === pkg || plugin[0]?.startsWith(pkg)
) ?? false;

export const hasConfigPlugin = (pkg: string) => fs.existsSync(`node_modules/${pkg}/app.plugin.js`);
45 changes: 28 additions & 17 deletions src/printData.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import Table from "cli-table3";
import type { PackageInfo } from "./types";
import type { PackageInfo, UsageType } from "./types";

export const printPackagesTable = (data: PackageInfo[]) => {
const table = new Table({head: ['used', 'package'], colAligns: ['center', 'left']});
table.push(...sortPackages(data).map(({name, used}) => [used ? '🟩 ' : '🟥 ', name]));
const sortPackages = (packages: PackageInfo[]) => {
const usedPackages = packages.filter((pkg) => pkg.used === "yes");
const autoPackages = packages.filter((pkg) => pkg.used === "auto")
const unusedPackages = packages.filter((pkg) => pkg.used === "no");
return [...usedPackages, ...autoPackages, ...unusedPackages];
}

console.log('Config Plugin Overview:');
console.log(table.toString())
const emojiMapping: Record<UsageType, string> = {
yes: "🟩",
auto: "📦",
no: "🟥"
}

const packageToString = (pkg: PackageInfo) => `${emojiMapping[pkg.used]} ${pkg.name}`

export const printPackagesRaw = (packages: PackageInfo[]) => {
console.log('\nConfig Plugin Overview');
console.log('Config Plugin Overview:');

const usedPackages = packages.filter((pkg) => pkg.used);
console.log('\nUsed packages:\n' + usedPackages.map((pkg) => `🟩 ${pkg.name}`).join('\n'));
const usedPackages = packages.filter((pkg) => pkg.used === "yes");
if (usedPackages.length) {
console.log('\nUsed Plugins:\n' + usedPackages.map((pkg) => packageToString(pkg)).join('\n'));
}

const autoPackages = packages.filter((pkg) => pkg.used === "auto");
if (autoPackages.length) {
console.log('\nBundled with Expo:\n' + autoPackages.map((pkg) => packageToString(pkg)).join('\n'));
}

const unusedPackages = packages.filter((pkg) => pkg.used === "no");
if (unusedPackages.length) {
console.log('\nUnused Plugins:\n' + unusedPackages.map((pkg) => packageToString(pkg)).join('\n'));
}

const unusedPackages = packages.filter((pkg) => !pkg.used);
console.log('\nUnused packages:\n' + unusedPackages.map((pkg) => `🟥 ${pkg.name}`).join('\n'));
};

const sortPackages = (packages: PackageInfo[]) => {
const usedPackages = packages.filter((pkg) => pkg.used);
const unusedPackages = packages.filter((pkg) => !pkg.used);
return [...usedPackages, ...unusedPackages];
}
4 changes: 2 additions & 2 deletions src/readPackages.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { hasConfigPlugin, isPluginUsed } from "./detectionHelpers.js";
import { hasConfigPlugin, getPluginImportType } from "./detectionHelpers.js";
import type { ExpoCfg } from "./types.js";

export const getPackagePluginList = (config: ExpoCfg,) => {
if (!config.pkg.dependencies) throw Error('No dependencies could be found by expo');
const deps = Object.keys(config.pkg.dependencies);
return deps.filter(hasConfigPlugin).map((name) => ({name, used: isPluginUsed(config, name)}));
return deps.filter(hasConfigPlugin).map((name) => ({name, used: getPluginImportType(config, name)}));
};
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getConfig } from "@expo/config";

export type PackageInfo = { name: string; used: boolean }
export type UsageType = "yes" | "auto" | "no"

export type PackageInfo = { name: string; used: UsageType }

export type ExpoCfg = ReturnType<typeof getConfig>

Expand Down

0 comments on commit ea93f6b

Please sign in to comment.