|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Post-install script for Less.js package |
| 5 | + * |
| 6 | + * This script installs Playwright browsers only when: |
| 7 | + * 1. This is a development environment (not when installed as a dependency) |
| 8 | + * 2. We're in a monorepo context (parent package.json exists) |
| 9 | + * 3. Not running in CI or other automated environments |
| 10 | + */ |
| 11 | + |
| 12 | +const fs = require('fs'); |
| 13 | +const path = require('path'); |
| 14 | +const { execSync } = require('child_process'); |
| 15 | + |
| 16 | +// Check if we're in a development environment |
| 17 | +function isDevelopmentEnvironment() { |
| 18 | + // Skip if this is a global install or user config |
| 19 | + if (process.env.npm_config_user_config || process.env.npm_config_global) { |
| 20 | + return false; |
| 21 | + } |
| 22 | + |
| 23 | + // Skip in CI environments |
| 24 | + if (process.env.CI || process.env.GITHUB_ACTIONS || process.env.TRAVIS) { |
| 25 | + return false; |
| 26 | + } |
| 27 | + |
| 28 | + // Check if we're in a monorepo (parent package.json exists) |
| 29 | + const parentPackageJson = path.join(__dirname, '../../../package.json'); |
| 30 | + if (!fs.existsSync(parentPackageJson)) { |
| 31 | + return false; |
| 32 | + } |
| 33 | + |
| 34 | + // Check if this is the root of the monorepo |
| 35 | + const currentPackageJson = path.join(__dirname, '../package.json'); |
| 36 | + if (!fs.existsSync(currentPackageJson)) { |
| 37 | + return false; |
| 38 | + } |
| 39 | + |
| 40 | + return true; |
| 41 | +} |
| 42 | + |
| 43 | +// Install Playwright browsers |
| 44 | +function installPlaywrightBrowsers() { |
| 45 | + try { |
| 46 | + console.log('🎭 Installing Playwright browsers for development...'); |
| 47 | + execSync('pnpm exec playwright install', { |
| 48 | + stdio: 'inherit', |
| 49 | + cwd: path.join(__dirname, '..') |
| 50 | + }); |
| 51 | + console.log('✅ Playwright browsers installed successfully'); |
| 52 | + } catch (error) { |
| 53 | + console.warn('⚠️ Failed to install Playwright browsers:', error.message); |
| 54 | + console.warn(' You can install them manually with: pnpm exec playwright install'); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// Main execution |
| 59 | +if (isDevelopmentEnvironment()) { |
| 60 | + installPlaywrightBrowsers(); |
| 61 | +} |
0 commit comments