// src/plugin/index.ts import fs from 'fs' import path from 'path' import { withDangerousMod, type ConfigPlugin } from '@expo/config-plugins' import { applyExclusion, type NitroChuckerPluginProps } from './applyExclusion' export function editPackageJson( projectRoot: string, props?: NitroChuckerPluginProps ): void { const pkgPath = path.join(projectRoot, 'package.json') const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) const next = applyExclusion(pkg, props) // Skip the write when nothing semantically changed (avoid prebuild churn). if (JSON.stringify(next) === JSON.stringify(pkg)) return fs.writeFileSync(pkgPath, JSON.stringify(next, null, 2) + '\n') } const withNitroChucker: ConfigPlugin = ( config, props ) => { // The edit targets the root package.json and is idempotent; run it on // whichever platform(s) prebuild so a single-platform prebuild still applies. for (const platform of ['ios', 'android'] as const) { config = withDangerousMod(config, [ platform, (cfg) => { editPackageJson(cfg.modRequest.projectRoot, props ?? undefined) return cfg }, ]) } return config } export default withNitroChucker