-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: v0.0.2 show bundled expo config plugins
- Loading branch information
Showing
7 changed files
with
117 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters