add optional debug logging for entry file configurations

This commit is contained in:
Nacho Codoñer
2025-07-29 17:12:25 +02:00
parent f7f0be8174
commit fb3dc40d5e
3 changed files with 62 additions and 22 deletions

View File

@@ -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}`);
}
}
}

View File

@@ -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'
);
}

View File

@@ -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;
}
}