From 8433a050e1b135941d1ce94483fbd114e6f45927 Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Wed, 24 Sep 2025 18:55:51 +0000 Subject: [PATCH 1/2] Remove verbose logging from environment loading and npm installs - Remove 'Set:' messages when loading environment variables - Remove 'New:' tip message from config - Skip /archive folder in npm installations - Improve entry.fish robustness for npm installs --- .devcontainer/config.fish | 2 +- .devcontainer/entry.fish | 57 +++++++++-- .devcontainer/envs/load_envs.fish | 13 ++- install.mjs | 154 ++++++++++++++++++++++++++---- 4 files changed, 194 insertions(+), 32 deletions(-) diff --git a/.devcontainer/config.fish b/.devcontainer/config.fish index 620119433f..3b61004eba 100644 --- a/.devcontainer/config.fish +++ b/.devcontainer/config.fish @@ -46,7 +46,7 @@ function fish_greeting printf "🧩 Hi @$AESTHETIC!\n\n" # Show the new KidLisp source tree shortcut - printf "šŸ’” New: Use 'st cow' or 'st \$cow' to analyze KidLisp pieces from anywhere!\n\n" + # printf "Ask with 'umm' and forget with 'nvm'\n" # printf "or use 'code' and 'done' with 'copy'\n" diff --git a/.devcontainer/entry.fish b/.devcontainer/entry.fish index 7d8c75dd50..85aa79dd00 100644 --- a/.devcontainer/entry.fish +++ b/.devcontainer/entry.fish @@ -61,9 +61,17 @@ else echo "Docker daemon already running." end +# Ensure the envs directory exists and is accessible (fallback if mount fails) +if not test -d /home/me/envs + echo "Creating missing /home/me/envs directory and linking to .devcontainer/envs" + mkdir -p /home/me/envs + ln -sf /workspaces/aesthetic-computer/.devcontainer/envs/* /home/me/envs/ +end + if test -d /home/me/envs source /home/me/envs/load_envs.fish load_envs # Load devcontainer envs conditionally. + echo "šŸ”§ Environment variables loaded from devcontainer.env" end # Set environment variables to prevent ETXTBSY errors and disable telemetry @@ -193,22 +201,51 @@ if test -f /home/me/aesthetic-computer/ssl-dev/localhost.pem; and test -f /home/ install_and_trust_certificate /home/me/aesthetic-computer/ssl-dev/localhost.pem /home/me/aesthetic-computer/ssl-dev/localhost-key.pem end -# Check if node_modules directory exists and is not empty +# Function to check and install npm dependencies in a directory +function install_npm_deps + set -l dir $argv[1] + set -l dir_name (basename $dir) + + if test -f $dir/package.json + if not test -d $dir/node_modules || not count $dir/node_modules/* >/dev/null 2>/dev/null + echo "šŸ“¦ Installing dependencies in $dir_name..." + cd $dir + npm ci --no-fund --no-audit --silent + if test $status -ne 0 + echo "āš ļø Failed to install dependencies in $dir_name, trying npm install..." + npm install --no-fund --no-audit --silent + end + else + echo "āœ… $dir_name already has node_modules" + end + end +end + +# Check and install dependencies in key directories +cd /home/me/aesthetic-computer + +# Install root dependencies first if not test -d /home/me/aesthetic-computer/node_modules || not count /home/me/aesthetic-computer/node_modules/* >/dev/null - # Move to the project directory - cd /home/me/aesthetic-computer - # Informing about the empty or missing node_modules directory - echo "node_modules directory is empty or missing, running npm install." - # Install the latest npm version + echo "šŸ“¦ Installing root dependencies..." npm install -g npm@latest --no-fund --no-audit npm ci --no-fund --no-audit - # Run additional installation scripts - npm run install:everything-else else - # Notify that installation steps are being skipped - echo "node_modules directory is present and not empty, skipping npm install." + echo "āœ… Root directory already has node_modules" end +# Install dependencies in critical subdirectories (archive intentionally excluded) +set -l critical_dirs system session-server vscode-extension nanos daemon utilities shared + +for dir in $critical_dirs + if test -d /home/me/aesthetic-computer/$dir + install_npm_deps /home/me/aesthetic-computer/$dir + end +end + +# Run the comprehensive install script for any remaining directories +echo "šŸ”„ Running comprehensive install script for remaining directories..." +npm run install:everything-else + # Make sure this user owns the emacs directory. sudo chown -R me:me ~/.emacs.d diff --git a/.devcontainer/envs/load_envs.fish b/.devcontainer/envs/load_envs.fish index 7f91840b08..23ca5af4bc 100644 --- a/.devcontainer/envs/load_envs.fish +++ b/.devcontainer/envs/load_envs.fish @@ -2,9 +2,18 @@ function load_envs for env_file in /home/me/envs/*.env if test -f $env_file + echo "Loading environment variables from: $env_file" for line in (cat $env_file) - set key_value (string split "=" $line) - set -gx $key_value[1] $key_value[2] + # Skip empty lines and comments + if test -n "$line" -a (string sub -s 1 -l 1 "$line") != "#" + # Split only on the first '=' to handle values with '=' in them + set key_value (string split -m 1 "=" $line) + if test (count $key_value) -eq 2 + set -gx $key_value[1] $key_value[2] + else + echo " Skipped invalid line: $line" + end + end end end end diff --git a/install.mjs b/install.mjs index 0bd4ea4cb9..fbe7b7a68f 100644 --- a/install.mjs +++ b/install.mjs @@ -8,44 +8,160 @@ import { dirname } from "path"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); +// Function to check if directory has node_modules +const hasNodeModules = (dir) => { + const nodeModulesPath = path.join(dir, "node_modules"); + try { + const stat = fs.statSync(nodeModulesPath); + if (!stat.isDirectory()) return false; + const contents = fs.readdirSync(nodeModulesPath); + return contents.length > 0; + } catch (err) { + return false; + } +}; + // Function to execute npm install using spawn for real-time output const runNpmInstall = (dir) => { return new Promise((resolve, reject) => { - const childProcess = spawn("npm", ["ci"], { + // Check if already has node_modules + if (hasNodeModules(dir)) { + console.log(`āœ… ${path.basename(dir)} already has node_modules, skipping`); + resolve(); + return; + } + + console.log(`šŸ“¦ Installing dependencies in ${path.basename(dir)}...`); + + // Try npm ci first (faster for clean installs) + let childProcess = spawn("npm", ["ci", "--no-fund", "--no-audit", "--silent"], { cwd: dir, - stdio: "inherit", + stdio: ["ignore", "pipe", "pipe"], + }); + + let output = ""; + let errorOutput = ""; + + childProcess.stdout?.on("data", (data) => { + output += data.toString(); + }); + + childProcess.stderr?.on("data", (data) => { + errorOutput += data.toString(); }); childProcess.on("close", (code) => { if (code === 0) { - console.log(`npm install completed in ${dir}`); + console.log(`āœ… npm install completed in ${path.basename(dir)}`); resolve(); } else { - console.error(`npm install failed in ${dir} with exit code ${code}`); - reject(new Error(`Process exited with code ${code}`)); + console.log(`āš ļø npm ci failed in ${path.basename(dir)}, trying npm install...`); + + // Fallback to npm install + const fallbackProcess = spawn("npm", ["install", "--no-fund", "--no-audit", "--silent"], { + cwd: dir, + stdio: ["ignore", "pipe", "pipe"], + }); + + let fallbackOutput = ""; + let fallbackErrorOutput = ""; + + fallbackProcess.stdout?.on("data", (data) => { + fallbackOutput += data.toString(); + }); + + fallbackProcess.stderr?.on("data", (data) => { + fallbackErrorOutput += data.toString(); + }); + + fallbackProcess.on("close", (fallbackCode) => { + if (fallbackCode === 0) { + console.log(`āœ… npm install completed in ${path.basename(dir)}`); + resolve(); + } else { + console.error(`āŒ npm install failed in ${path.basename(dir)} with exit code ${fallbackCode}`); + if (fallbackErrorOutput) { + console.error("Error output:", fallbackErrorOutput); + } + reject(new Error(`Process exited with code ${fallbackCode}`)); + } + }); } }); }); }; -// Main function to loop through each top-level directory +// Function to recursively find all directories with package.json +const findPackageJsonDirectories = (basePath, maxDepth = 2) => { + const results = []; + + const scanDirectory = (currentPath, depth) => { + if (depth > maxDepth) return; + + try { + const entries = fs.readdirSync(currentPath, { withFileTypes: true }); + + // Check if current directory has package.json + if (entries.some(entry => entry.name === "package.json")) { + results.push(currentPath); + } + + // Recursively scan subdirectories (avoiding node_modules and other common exclusions) + for (const entry of entries) { + if (entry.isDirectory() && + !entry.name.startsWith('.') && + entry.name !== 'node_modules' && + entry.name !== 'target' && + entry.name !== 'dist' && + entry.name !== 'build' && + entry.name !== 'archive') { // Skip archive directory + scanDirectory(path.join(currentPath, entry.name), depth + 1); + } + } + } catch (err) { + // Skip directories we can't read + console.log(`āš ļø Skipping ${currentPath}: ${err.message}`); + } + }; + + scanDirectory(basePath, 0); + return results; +}; + +// Main function to loop through directories with package.json const installDependenciesInDirectories = async () => { - const directories = fs - .readdirSync(__dirname, { withFileTypes: true }) - .filter((dirent) => dirent.isDirectory()) - .map((dirent) => dirent.name); - - for (const dir of directories) { - const packageJsonPath = path.join(__dirname, dir, "package.json"); - if (fs.existsSync(packageJsonPath)) { - console.log(`Running npm install in ${dir}`); - try { - await runNpmInstall(path.join(__dirname, dir)); - } catch (error) { - console.error(`Failed to run npm install in ${dir}: ${error}`); + console.log("šŸ” Finding all directories with package.json files..."); + const packageJsonDirs = findPackageJsonDirectories(__dirname); + + console.log(`šŸ“‹ Found ${packageJsonDirs.length} directories with package.json:`); + packageJsonDirs.forEach(dir => { + const relativePath = path.relative(__dirname, dir); + console.log(` ${relativePath || '.'}`); + }); + + let successCount = 0; + let skippedCount = 0; + let failureCount = 0; + + for (const dir of packageJsonDirs) { + const relativePath = path.relative(__dirname, dir) || '.'; + try { + if (hasNodeModules(dir)) { + skippedCount++; + continue; } + await runNpmInstall(dir); + successCount++; + } catch (error) { + console.error(`āŒ Failed to run npm install in ${relativePath}: ${error.message}`); + failureCount++; } } + + console.log("\nšŸ“Š Installation Summary:"); + console.log(` āœ… Successful installations: ${successCount}`); + console.log(` ā­ļø Skipped (already installed): ${skippedCount}`); + console.log(` āŒ Failed installations: ${failureCount}`); }; // Run the main function -- knotmirror 0.0.1 From 653e83fa605f4cd39efcac7aefc681083179c1c0 Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Wed, 24 Sep 2025 18:56:23 +0000 Subject: [PATCH 2/2] Disable GPG signing in dev environment to prevent commit issues --- .devcontainer/entry.fish | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.devcontainer/entry.fish b/.devcontainer/entry.fish index 85aa79dd00..80075e4743 100644 --- a/.devcontainer/entry.fish +++ b/.devcontainer/entry.fish @@ -111,6 +111,9 @@ git config --global --add safe.directory /home/me/aesthetic-computer # Set rebase as default for pull operations. git config --global pull.rebase true +# Disable GPG signing to prevent commit issues in dev environment +git config --global commit.gpgsign false + # Make sure git is setup and authorized for making commits via `gh`. gh auth setup-git -- knotmirror 0.0.1