Skip to content

Commit

Permalink
chore: improve Monorepo package detection by using @rnx-kit/tools-wor…
Browse files Browse the repository at this point in the history
…kspaces for node_modules search, use stricli instead of commander to improve type safety for CLI, cursor improved my README.md
  • Loading branch information
WookieFPV committed Feb 14, 2025
1 parent 55dd87c commit 83b47de
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 98 deletions.
41 changes: 19 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
# list-config-plugins [![npm][npm-image]][npm-url]
# list-config-plugins [![npm][npm-image]][npm-url] ![npm][npm-dl-stats]

A CLI tool to find Expo config plugins available in your project dependencies.
A CLI tool to discover and manage Expo config plugins in your project dependencies.

## Overview
## 🚀 Overview

This package helps you manage your Expo config plugins by showing which dependencies have available plugins and whether they're currently being used in your project.\
Works on Expo & bare React-Native Apps (without Expo)
`list-config-plugins` helps you efficiently manage your Expo config plugins by identifying which dependencies have available expo config plugins and whether they are currently utilized in your project. It supports:

## Usage
- ✅ Expo Apps
- ✅ Bare React-Native Apps (without Expo)
- ✅ Monorepos

Simply run the package using npx in your App directory:
## 🎯 Usage

To get started, simply run the package in your app directory:

```bash
npx list-config-plugins
npx list-config-plugins@latest
```

### Example Output

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

Used Plugins:
Expand All @@ -37,25 +39,20 @@ Unused Plugins:
🟥 @sentry/react-native
```

## Features
## Features

- 🔍 Scans your project for available Expo config plugins
- 🟩 Shows which plugins are currently in use
- 📦 Shows which plugins are automatically added by expo
- 🟩 Displays currently used plugins
- 📦 Lists plugins automatically added by Expo
- 🟥 Identifies unused available plugins
- 🌐 Finds config plugins provided by [expo @config-plugins/](https://github.com/expo/config-plugins)
- ⚙️ Supports all types of React-Native & Expo configurations & Monorepos
- 🌐 Finds config plugins provided by [expo @config-plugins](https://github.com/expo/config-plugins)
- ⚙️ Supports all types of React-Native & Expo configurations, including Monorepos

## How It Works
## 🛠️ How It Works

1. Analyzes your project dependencies to identify packages with Expo config plugins.
2. Checks which config plugins are being used in your Expo configuration.

## Monorepo Support

Monorepos should work, this depends on where your config plugins are placed.
This package will search for config plugins in `./node_modules` and walk up the folder structure (`../node_modules`, `../../node_modules`, ...).
If your config plugins are there, it should work. (run with --debug to see where it is searching)
2. Checks which config plugins are actively used in your Expo configuration.

[npm-image]: https://img.shields.io/npm/v/list-config-plugins
[npm-url]: https://www.npmjs.com/package/list-config-plugins
[npm-dl-stats]: https://img.shields.io/npm/dm/list-config-plugins
59 changes: 46 additions & 13 deletions bun.lock

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "list-config-plugins",
"version": "1.1.1",
"version": "1.1.3",
"description": "find available expo config plugins and see if they are used",
"author": {
"name": "WookieFPV (Lukas Müller)",
Expand All @@ -15,9 +15,10 @@
"module": "index",
"type": "module",
"bin": {
"list-config-plugins": "./dist/bin.js"
"list-config-plugins": "dist/cli.js",
"__list-config-plugins_bash_complete": "dist/bash-complete.js"
},
"main": "dist/bin.js",
"main": "dist/cli.js",
"files": ["dist"],
"scripts": {
"build": "tsup",
Expand All @@ -31,13 +32,16 @@
"dependencies": {
"@expo/config": "*",
"@expo/prebuild-config": "*",
"commander": "^13.1.0"
"@rnx-kit/tools-workspaces": "0.2.0",
"@stricli/auto-complete": "1.1.1",
"@stricli/core": "1.1.1"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@changesets/cli": "2.27.12",
"@total-typescript/ts-reset": "0.6.1",
"@types/bun": "latest",
"tsup": "8.3.5",
"tsup": "8.3.6",
"typescript": "5.7.3"
}
}
16 changes: 0 additions & 16 deletions src/bin.ts

This file was deleted.

25 changes: 25 additions & 0 deletions src/cli/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { buildApplication, buildCommand } from "@stricli/core";
import { description, name, version } from "../../package.json";

const command = buildCommand({
loader: async () => import("./impl"),
parameters: {
flags: {
debug: {
kind: "boolean",
brief: "output debugging info",
default: false,
},
},
},
docs: {
brief: description,
},
});

export const app = buildApplication(command, {
name,
versionInfo: {
currentVersion: version,
},
});
18 changes: 18 additions & 0 deletions src/cli/bin/bash-complete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
import { proposeCompletions } from "@stricli/core";
import { app } from "../app";
import { buildContext } from "../context";

const inputs = process.argv.slice(3);
// biome-ignore lint/complexity/useLiteralKeys: <explanation>
if (process.env["COMP_LINE"]?.endsWith(" ")) {
inputs.push("");
}
await proposeCompletions(app, inputs, buildContext(process));
try {
for (const { completion } of await proposeCompletions(app, inputs, buildContext(process))) {
process.stdout.write(`${completion}\n`);
}
} catch {
// ignore
}
6 changes: 6 additions & 0 deletions src/cli/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
import { run } from "@stricli/core";
import { app } from "../app";
import { buildContext } from "../context";

await run(app, process.argv.slice(2), buildContext(process));
18 changes: 18 additions & 0 deletions src/cli/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import type { StricliAutoCompleteContext } from "@stricli/auto-complete";
import type { CommandContext } from "@stricli/core";

export interface LocalContext extends CommandContext, StricliAutoCompleteContext {
readonly process: NodeJS.Process;
}

export function buildContext(process: NodeJS.Process): LocalContext {
return {
process,
os,
fs,
path,
};
}
10 changes: 10 additions & 0 deletions src/cli/impl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { listConfigPlugins } from "../listConfigPlugins";
import type { LocalContext } from "./context";

export interface CommandFlags {
readonly debug: boolean;
}

export default async function (this: LocalContext, flags: CommandFlags): Promise<void> {
listConfigPlugins(flags);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "node:fs";
import { getLegacyExpoPlugins } from "@expo/prebuild-config";
import type { ExpoCfg, ExpoPlugin, UsageType } from "../types/types";
import { thirdPartyPluginPrefix, thirdPartyPlugins } from "./communityConfigPlugins";
import { nodeModulesFolders } from "./findNodeModules.js";
import type { ExpoCfg, ExpoPlugin, UsageType } from "./types";
import { nodeModulesFolders } from "./nodeModulesFolders";

const isPluginUsedStr = (pluginStr: string, pkg: string) => {
if (pluginStr.startsWith(pkg)) return true;
Expand Down
5 changes: 5 additions & 0 deletions src/configPlugin/nodeModulesFolders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { findWorkspacePackagesSync, findWorkspaceRootSync } from "@rnx-kit/tools-workspaces";

export const nodeModulesFolders = [findWorkspaceRootSync(), ...findWorkspacePackagesSync()]
.filter(Boolean)
.map((path) => `${path}/node_modules`);
9 changes: 5 additions & 4 deletions src/readPackages.ts → src/configPlugin/readPackages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getConfigPluginInfoText, thirdPartyPluginPrefix } from "./communityConfigPlugins";
import type { CommandFlags } from "../cli/impl";
import type { ExpoCfg, PackageInfo } from "../types/types.js";
import { getConfigPluginInfoText } from "./communityConfigPlugins";
import { getPluginImportType, hasConfigPlugin } from "./detectionHelpers.js";
import { nodeModulesFolders } from "./findNodeModules";
import type { CliOptions, ExpoCfg, PackageInfo } from "./types.js";
import { nodeModulesFolders } from "./nodeModulesFolders";

export const getPackagePluginList = (config: ExpoCfg, options: CliOptions): Array<PackageInfo> => {
export const getPackagePluginList = (config: ExpoCfg, options: CommandFlags): Array<PackageInfo> => {
if (!config.pkg.dependencies) throw Error("No dependencies could be found by expo");
const deps = Object.keys(config.pkg.dependencies);
if (options.debug) console.debug("List of dependencies:", JSON.stringify(deps, null, 2));
Expand Down
17 changes: 0 additions & 17 deletions src/findNodeModules.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/globals.d.ts

This file was deleted.

7 changes: 3 additions & 4 deletions src/listConfigPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { CommandFlags } from "./cli/impl";
import { getPackagePluginList } from "./configPlugin/readPackages.js";
import { printPackages } from "./printData.js";
import { readExpoConfig } from "./readExpoConfig.js";
import { getPackagePluginList } from "./readPackages.js";
import type { CliOptions } from "./types";

export const listConfigPlugins = (options: CliOptions) => {
export const listConfigPlugins = (options: CommandFlags) => {
const config = readExpoConfig(options);
if (!config) {
console.log(
Expand All @@ -13,7 +13,6 @@ export const listConfigPlugins = (options: CliOptions) => {
);
return;
}

const packages = getPackagePluginList(config, options);
printPackages(packages);
};
2 changes: 1 addition & 1 deletion src/printData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PackageInfo, UsageType } from "./types";
import type { PackageInfo, UsageType } from "./types/types";

const emojiMapping: Record<UsageType, string> = {
yes: "🟩",
Expand Down
4 changes: 2 additions & 2 deletions src/readExpoConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getConfig } from "@expo/config";
import type { CliOptions } from "./types";
import type { CommandFlags } from "./cli/impl";

export const readExpoConfig = (options: CliOptions) => {
export const readExpoConfig = (options: CommandFlags) => {
try {
return getConfig(process.cwd(), { skipSDKVersionRequirement: true });
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions src/types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "@total-typescript/ts-reset";

declare namespace NodeJS {
interface ProcessEnv {
COMP_LINE: string | undefined;
}
}
4 changes: 0 additions & 4 deletions src/types.ts → src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ export type PackageInfo = { name: string; usage: UsageType; info?: string };
export type ExpoCfg = ReturnType<typeof getConfig>;

export type ExpoPlugin = ExpoCfg["exp"]["plugins"];

export type CliOptions = {
debug: boolean;
};
7 changes: 1 addition & 6 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/bin.ts"],
entry: ["src/cli/bin/cli.ts", "src/cli/bin/bash-complete.ts"],
format: ["esm"],
dts: false,
define: {
__VERSION__: JSON.stringify(process.env.npm_package_version),
},
outDir: "dist",
clean: true,
});

0 comments on commit 83b47de

Please sign in to comment.