From fb3dc40d5efab080c27f432bad0d10525da80071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Tue, 29 Jul 2025 17:12:25 +0200 Subject: [PATCH] add optional debug logging for entry file configurations --- packages/rspack/lib/config.js | 20 +++++++++++++--- packages/rspack/lib/dependencies.js | 36 +++++++++++++++++++++-------- packages/tools-core/lib/git.js | 28 ++++++++++++++-------- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/packages/rspack/lib/config.js b/packages/rspack/lib/config.js index a5f28d9200..df8ebf5a3b 100644 --- a/packages/rspack/lib/config.js +++ b/packages/rspack/lib/config.js @@ -12,8 +12,11 @@ const { isMeteorAppDevelopment, isMeteorAppRun, isMeteorAppBuild, + isMeteorAppDebug, } = require('meteor/tools-core/lib/meteor'); +const { logInfo } = require('meteor/tools-core/lib/log'); + const { RSPACK_BUILD_CONTEXT, FILE_ROLE, @@ -51,6 +54,10 @@ export function configureMeteorForRSPack() { const meteorAppIgnores = `${foldersToIgnore.join(' ')} ${filesToIgnore.join(' ')}`; setMeteorAppIgnore(meteorAppIgnores); + if (isMeteorAppDebug()) { + logInfo(`[i] Meteor app ignores: ${meteorAppIgnores}`); + } + const env = isMeteorAppDevelopment() ? { isDevelopment: true } : { isProduction: true }; @@ -78,13 +85,20 @@ export function configureMeteorForRSPack() { // Set entry points in environment variables if they exist setMeteorAppEntrypoints(appEntrypoints); + if (isMeteorAppDebug()) { + logInfo(`[i] App entrypoints: ${JSON.stringify(appEntrypoints, null, 2)}`); + } + // Ensure module files exist ensureModuleFilesExist(); // Write content to module files if (isMeteorAppRun()) { - setMeteorAppCustomScriptUrl( - `/__rspack__/${getBuildFilePath({ ...env, isMain: true, isClient: true, role: FILE_ROLE.output, onlyFilename: true })}`, - ); + const customScriptUrl = `/__rspack__/${getBuildFilePath({ ...env, isMain: true, isClient: true, role: FILE_ROLE.output, onlyFilename: true })}`; + setMeteorAppCustomScriptUrl(customScriptUrl); + + if (isMeteorAppDebug()) { + logInfo(`[i] App custom script: ${customScriptUrl}`); + } } } diff --git a/packages/rspack/lib/dependencies.js b/packages/rspack/lib/dependencies.js index 4590a8c5c3..05d2f64cff 100644 --- a/packages/rspack/lib/dependencies.js +++ b/packages/rspack/lib/dependencies.js @@ -11,6 +11,8 @@ const { const { logProgress, logSuccess, + logInfo, + logError, } = require('meteor/tools-core/lib/log'); const { getMeteorAppDir, @@ -65,10 +67,19 @@ async function ensureDependenciesInstalled(dependencies, globalStateKey, package const dependencyStrings = allDepsToInstall.map(dep => `${dep.name}@${dep.version}`); if (allDepsToInstall.length > 0) { - let success; - logProgress( - `${packageName} dependencies need to be installed. Installing ${joinWithAnd(dependencyStrings)}...`, - ); + let success = true; + + // Display a header for the installation process + logProgress(`┌─────────────────────────────────────────────────`); + logProgress(`│ ${packageName} Dependencies Installation`); + logProgress(`└─────────────────────────────────────────────────`); + + // Show what dependencies will be installed + logInfo(`The following ${packageName} dependencies need to be installed:`); + dependencyStrings.forEach(dep => { + logInfo(` • ${dep}`); + }); + // Install dev dependencies const devDepsToInstall = allDepsToInstall.filter(dep => dep.dev === true || dep.dev == null); if (devDepsToInstall.length > 0) { @@ -79,6 +90,7 @@ async function ensureDependenciesInstalled(dependencies, globalStateKey, package }); } + // Install regular dependencies const depsToInstall = allDepsToInstall.filter(dep => dep.dev === false); if (depsToInstall.length > 0) { const depsStrings = depsToInstall.map(dep => `${dep.name}@${dep.version}`); @@ -86,16 +98,22 @@ async function ensureDependenciesInstalled(dependencies, globalStateKey, package cwd: appDir, dev: false, }); + success = success && depsSuccess; } if (!success) { + logError(`\n┌─────────────────────────────────────────────────`); + logError(`│ ❌ ${packageName} Installation Failed`); + logError(`└─────────────────────────────────────────────────`); + logError(`Run: meteor npm install -D ${joinWithAnd(dependencyStrings)}`); + throw new Error( - `Failed to install ${packageName} dependencies. Please install them manually with: meteor npm install -D ${joinWithAnd(allDepsToInstall)}` + `Failed to install ${packageName} dependencies. Please install them manually with: meteor npm install -D ${joinWithAnd(dependencyStrings)}` ); } - logSuccess(`${packageName} dependencies installed successfully.`); + logSuccess(`✅ ${packageName} dependencies installed`); } // Mark as checked @@ -118,7 +136,7 @@ export async function ensureRSPackInstalled() { await ensureDependenciesInstalled( dependencies, GLOBAL_STATE_KEYS.RSPACK_INSTALLATION_CHECKED, - 'RSPack', + 'Rspack', ); } @@ -158,7 +176,7 @@ export async function ensureRSPackReactInstalled() { await ensureDependenciesInstalled( dependencies, GLOBAL_STATE_KEYS.RSPACK_REACT_INSTALLATION_CHECKED, - 'RSPack React' + 'Rspack React' ); } @@ -201,6 +219,6 @@ export async function ensureRSPackCoffeescriptInstalled() { await ensureDependenciesInstalled( dependencies, GLOBAL_STATE_KEYS.RSPACK_COFFEESCRIPT_INSTALLATION_CHECKED, - 'RSPack Coffeescript' + 'Rspack Coffeescript' ); } diff --git a/packages/tools-core/lib/git.js b/packages/tools-core/lib/git.js index 3e310e070c..71afcdb0e0 100644 --- a/packages/tools-core/lib/git.js +++ b/packages/tools-core/lib/git.js @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import { execSync } from 'child_process'; +import { logProgress, logSuccess, logInfo, logError } from './log'; /** * Checks if the given directory is a git repository @@ -37,10 +37,6 @@ export function gitignoreExists(dir) { * @returns {boolean} - True if .gitignore was created or already exists */ export function ensureGitignoreExists(dir, initialEntries = []) { - if (!isGitRepository(dir)) { - return false; - } - const gitignorePath = path.join(dir, '.gitignore'); if (!gitignoreExists(dir)) { @@ -88,10 +84,6 @@ export function getMissingGitignoreEntries(dir, entries) { * @returns {boolean} - True if entries were added successfully */ export function addGitignoreEntries(dir, entries, context = '') { - if (!isGitRepository(dir)) { - return false; - } - // Ensure .gitignore exists if (!ensureGitignoreExists(dir)) { return false; @@ -104,6 +96,17 @@ export function addGitignoreEntries(dir, entries, context = '') { return true; // All entries already exist } + // Display a header for the gitignore entries addition + logProgress(`┌─────────────────────────────────────────────────`); + logProgress(`│ Adding Gitignore Entries${context ? ` for ${context}` : ''}`); + logProgress(`└─────────────────────────────────────────────────`); + + // Show what entries will be added + logInfo(`The following entries will be added to .gitignore:`); + missingEntries.forEach(entry => { + logInfo(` • ${entry}`); + }); + try { const gitignorePath = path.join(dir, '.gitignore'); let content = ''; @@ -122,9 +125,14 @@ export function addGitignoreEntries(dir, entries, context = '') { } content += missingEntries.join('\n') + '\n'; fs.writeFileSync(gitignorePath, content, 'utf8'); + + logSuccess(`✅ Gitignore entries${context ? ` for ${context}` : ''} added`); return true; } catch (error) { - console.error(`Error adding entries to .gitignore file: ${error.message}`); + logError(`\n┌─────────────────────────────────────────────────`); + logError(`│ ❌ Failed to Add Gitignore Entries${context ? ` for ${context}` : ''}`); + logError(`└─────────────────────────────────────────────────`); + logError(`Error: ${error.message}`); return false; } }