import path from 'path'; import fs from 'fs'; import { checkForCssFiles } from './utils'; /** Функция проверки package.json */ export async function checkPackageJSON(project: string) { const projectDir = path.join(__dirname, '../../packages/react', project); const filePath = path.join(projectDir, 'package.json'); try { const data = fs.readFileSync(filePath, 'utf8'); const config = JSON.parse(data); if (config?.exports?.['.']) { config.exports['.'] = { ...(config.exports['.'] || {}), import: './index.mjs', require: './index.js', types: './index.d.ts', }; } else { config.exports = { '.': { import: './index.mjs', require: './index.js', types: './index.d.ts', }, }; } const hasCss = checkForCssFiles(projectDir); if (hasCss) { config.sideEffects = [ ...new Set([...(config.sideEffects || []), '**/*.css']), ]; config.devDependencies = { ...(config.devDependencies || {}), 'vite-plugin-lib-inject-css': '2.1.1', }; } const updatedConfig = JSON.stringify(config, null, 2) + '\n'; fs.writeFileSync(filePath, updatedConfig); console.log('package.json успешно обновлен'); } catch (error) { console.error('Ошибка при обновлении package.json:', error); } }